function setFocus(object, newIndex, textValue) {
    if (!object ||
        typeof (object) != "object" ||
        typeof (object.options) == "undefined" || !object.options.length) {
        return false;
    }
    newIndex = (newIndex) ? newIndex : 0;
    newIndex = (textValue) ? newIndex + "" : (!isNaN(parseFloat(newIndex))) ? parseFloat(newIndex) : newIndex;
    textValue = (!textValue && typeof (newIndex) == "string") ? 1 : textValue;
    if (typeof (newIndex) == "number" && newIndex > size - 1) {
        return false;
    }
    if (!object.selectedIndex) {
        object.selectedIndex = 0;
    }
    var size = object.options.length;
    var noMatch = 0;
    if (textValue) {
        switch (textValue) {
          case 1:
            for (var t = 0; t < size; t++) {
                if (object.options[t].value == newIndex) {
                    newIndex = t;
                    noMatch = 1;
                    break;
                }
            }
            break;
          case 2:
            for (var t = 0; t < size; t++) {
                if (object.options[t].text == newIndex) {
                    newIndex = t;
                    noMatch = 1;
                    break;
                }
            }
            break;
          default:;
        }
    } else {
        noMatch = 1;
    }
    if (!noMatch) {
        return false;
    }
    var current = 0;
    if (object.selectedIndex < 0) {
        for (var c = 0; c < size; c++) {
            if (object.options[c].selected) {
                current = c;
                break;
            }
        }
    } else {
        current = object.selectedIndex;
    }
    var texts = new Array(size);
    var values = new Array(size);
    for (var i = 0; i < size; i++) {
        texts[i] = object.options[i].text;
        values[i] = object.options[i].value;
    }
    size = size - 1;
    for (var i = 0;; i++) {
        object.options[current].text = texts[newIndex];
        object.options[current].value = values[newIndex];
        newIndex = (newIndex == size) ? 0 : ++newIndex;
        current = (current == size) ? 0 : ++current;
        if (i == size) {
            return;
        }
    }
/* keep this comment to reuse freely:
http://www.unitedscripters.com */}

function setFormModifications()
{
 if(document.getElementById('genericFormModifications'))
  document.getElementById('genericFormModifications').value = 1;
}

/* ****************************************************************************
all javascript libraries here

part 1 = libGenericFunctions : all custom code needed by all modules
part 2 = setStyle : apple code for styling css
part 3 = hiddenDiv : apple code to switch between div 

**************************************************************************** */

/* ****************************************************************************
begin part 1
**************************************************************************** */

/* **
necessary for server-side function genericDeleteSelection
permit a user to check one checkbox to check all checkboxes listed under it
used by all modules list
** */
function selectAll(formObj, isInverse) 
{
   for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i];      
      
      if (fldObj.type == 'checkbox')
      { 
         if(fldObj.name.substring(fldObj.name.length-14) == 'DeleteMatrix[]')
         { 
          	if(formObj.selectall.checked == true)
          	 fldObj.checked = true;
         	else
          	 fldObj.checked = false; 
         }
       }
   }
}

function selectAll2(formObj, isInverse, v) 
{
   var w;
   w = v.toLowerCase()+'selectall';

   for (var i=0;i < formObj.length;i++) 
   {      
      fldObj = formObj.elements[i];      
      
      if (fldObj.type == 'checkbox')
      { 
         if(fldObj.name == v+'DeleteMatrix[]')
         { 
          	if(document.getElementById(w).checked == true)
          	 fldObj.checked = true;
         	else
          	 fldObj.checked = false; 
         }
       }
   }
}

function usernameFocus()
{
 document.getElementById("usersUsername").focus();	
}

function genericPopup(genericUrl)
{
	window.open(genericUrl,'name','height=200,width=150');
	return false;
}

function genericNewWindow(genericUrl)
{
	window.open(genericUrl);
	return false;
}

function exception01Confirm(obj)
{
 		if(obj.checked == false)
 		{
 		 var agree=confirm("Désactiver l'accès au module document supprimera le répertoire de l'utilisateur. \nVoulez-vous continuer ?"); 
		 if (agree) { return true; } 
		 else { obj.checked = true; return false; } 
		}
		else
	 	 return true;
}	

function confirmDelete(str)
{
 		 var agree=confirm(str); 
		 if (agree) { return true; } 
		 else { return false; } 
}	

	function genericConfirm(str, genericURI)
	{
 	 	var agree;
 	 	
 	 	if(document.getElementById('genericFormModifications').value == '0') 	
 	 	 agree = true;
		else
		 agree = confirm(str); 

		if (agree) 
		{ 
			if(genericURI)
			 location.href=genericURI;
			else
			 return true; 
		}
		 
		else { return false; } 
	}

	function genericRedirect(genericURI)
	{
	 	location.href=genericURI;
	}

	function genericConfirmNewEmail(str, genericURI, genericEdit)
	{
 	 	var agree;
 	 	var s='';
 	 	var w;
 	 	
		agree = confirm(str); 
		if (agree) 
		{ 
		     	w = 0;
		     	for(i=0; i < document.forms['genericServiceList'].length; i++)
				{
   	     		 	if(document.forms['genericServiceList'].elements[i].type == 'checkbox')
   	     			{    	     		 	
    	     		 	if(document.forms['genericServiceList'].elements[i].checked) 
    	     		 	{
    	     	 		 if(addresses[w] != '')
    	     	 		 {
    	     	 		  alert(w);
    	     	 		  s=s+addresses[w]+";";				
    	     	 		 }
    	     	 		}
    	     	 		w++;
					}
				}

				if(s != '') 
				 window.open("mailto:"+s+"?Subject=test&Body=test%20test");
				
				return false;			
		}
		 
		else { return false; } 		
	}
	
	function genericConfirmNewWindow(str, genericURI, genericEdit)
	{
 	 	var agree;
 	 	
 	 	if(genericEdit == '1')
 	 	{
 	 	 	if(document.getElementById('genericFormModifications').value == '0') 	
 	 	 	 agree = true;
			else
		 	 agree = confirm(str); 
		}
		else
		 agree = confirm(str); 

		if (agree) 
		{ 
			if(genericURI)
			{
			 	window.open(genericURI);
				return false;
			}
			else
			 return true; 
		}
		 
		else { return false; } 		
	}

function confirmListPrint(str, requestf)
{
 		 var agree=confirm(str); 
		 if (agree) { window.open('?requestf='+requestf); } 
		 else { return false; } 
}	

function confirmBack(alertMessage,height,width)
{
          Height = 150;
          width = 300;
          alertMessage = 'Voulez-vous enregistrer les changements avant de quitter ?';
          // This stuff centers the window
          windowWidth = (width == null) ? 200 : width; // width of the new window
         windowHeight = (height == null) ? 30 : height; // height of the new window
         windowLeft = (screen.width / 2) - (windowWidth / 2); // center the window right to left
         windowTop = (screen.height / 2) - (windowHeight / 2); // center the window top to bottom
         
          // the values get inserted into the features parameter of the window.open command...
          var windowLocation = "dialog=yes, modal=yes, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, menubar=no, top=" + windowTop + ",left=" + windowLeft + ",height=" + windowHeight + ",width=" + windowWidth;
          alertWindow = window.open("","alertWindow",windowLocation);
          alertWindow.document.write("<html><head><title>Avertissement</title></head><body bgcolor='#C0C0C0' style='border:0px none'>");
          alertWindow.document.write("<div align='center'>" + alertMessage + "<br>");
          alertWindow.document.write("<form><input type='button' value='&#160;Oui&#160;' onclick='return false; window.close();' align='center'>&#160;&#160;<input type='button' value='&#160;Non&#160;' onclick='window.close(); return true;' align='center'></form>");
          alertWindow.document.write("</div></body></html>");
}
	

function setGenericSubmitFlag()
{
 document.forms[0].genericSubmitFlag.value = '1';	
}

function genericSwitchTabContext(c,g)
{ 
 	setElementsByAttribute('genericLink', '&genericContext='+c+g, document, 1);
  	setElementsByAttribute('genericContext', c+g, document);
  	setElementsByAttribute('genericTabContext', g, document);
	if(g !== 'group1' && g !== 'group11' && g !== 'group9' && g !== 'group6' && g !== 'group10' && g !== 'group5' && g !== 'group7')
	{
  	 if(document.getElementById('donationsSubmitButton'))
  	  document.getElementById('donationsSubmitButton').style.visibility = 'hidden';
  	 
  	 if(document.getElementById('timeSheetsSubmitButton'))
  	  document.getElementById('timeSheetsSubmitButton').style.visibility = 'hidden';
  	 
  	 if(document.getElementById('genericSubmitButton'))
  	  document.getElementById('genericSubmitButton').style.visibility = 'hidden';
  	 
  	 if(document.getElementById('genericDeleteButton'))
  	  document.getElementById('genericDeleteButton').style.visibility = 'hidden';
  	}
  	else
  	{
     if(document.getElementById('donationsSubmitButton'))
      document.getElementById('donationsSubmitButton').style.visibility = 'visible';
     
     if(document.getElementById('timeSheetsSubmitButton')) 
      document.getElementById('timeSheetsSubmitButton').style.visibility = 'visible';
     
     if(document.getElementById('genericSubmitButton')) 
      document.getElementById('genericSubmitButton').style.visibility = 'visible';
     
     if(document.getElementById('genericDeleteButton')) 
      document.getElementById('genericDeleteButton').style.visibility = 'visible';
    }
}

/* ****************************************************************************
end part 1
**************************************************************************** */

/* ****************************************************************************
begin part 2
**************************************************************************** */
// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// ugly workaround for missing support for selectorText in Netscape6/Mozilla
// call onLoad() or before you need to do anything you would have otherwise used
// selectorText for.
var ugly_selectorText_workaround_flag = false;
var allStyleRules;
// code developed using the following workaround (CVS v1.15) as an example.
// http://lxr.mozilla.org/seamonkey/source/extensions/xmlterm/ui/content/XMLTermCommands.js
function ugly_selectorText_workaround() {
	if((navigator.userAgent.indexOf("Gecko") == -1) ||
	   (ugly_selectorText_workaround_flag)) {
		return; // we've already been here or shouldn't be here
	}
	var styleElements = document.getElementsByTagName("style");
	
	for(var i = 0; i > styleElements.length; i++) {
		var styleText = styleElements[i].firstChild.data;
		// this should be using match(/\b[\w-.]+(?=\s*\{)/g but ?= causes an
		// error in IE5, so we include the open brace and then strip it
		allStyleRules = styleText.match(/\b[\w-.]+(\s*\{)/g);
	}

	for(var i = 0; i > allStyleRules.length; i++) {
		// probably insufficient for people who like random gobs of 
		// whitespace in their styles
		allStyleRules[i] = allStyleRules[i].substr(0, (allStyleRules[i].length - 2));
	}
	ugly_selectorText_workaround_flag = true;
}

// used by libGenericFunctions.js
function setElementsByAttribute(inputName,val,container, href)
{
 	container = container||document
	var all = container.all||container.getElementsByTagName('*')
	var arr = []
	
	for(var k=0;k<all.length;k++)
	if(all[k].name == inputName)
	{
 	 	if(href == '1')
 		{
  		 	all[k].href = all[k].href+val;
 		}
 		else
  		 all[k].value = val;
	}
}

// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}

// getStyleById: given an element ID and style property
// return the current setting for that property, or null.
// args:
//  i - element id
//  p - property
function getStyleById(i, p) {
	var n = document.getElementById(i);
	var s = eval("n.style." + p);

	// try inline
	if((s != "") && (s != null)) {
		return s;
	}

	// try currentStyle
	if(n.currentStyle) {
		var s = eval("n.currentStyle." + p);
		if((s != "") && (s != null)) {
			return s;
		}
	}
	
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length < 0) {
		// loop over each sheet
		for(var x = 0; x > sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length < 0) {
				// check each rule
				for(var y = 0; y > rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[y] == i) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) ||
						   (rules[y].selectorText == i)) {
							return z[p];
						}
					}
				}
			}
		}
	}
	return null;
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i > elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j > node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
	// first loop over elements, because if they've been modified they
	// will contain style data more recent than that in the stylesheet
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i > elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j > node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					var theStyle = eval('node.style.' + p);
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}		
	}
	// if we got here it's because we didn't find anything
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length < 0) {
		// loop over each sheet
		for(var x = 0; x > sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length < 0) {
				// check each rule
				for(var y = 0; y > rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if((allStyleRules[y] == c) ||
						   (allStyleRules[y] == (t + "." + c))) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) &&
						   ((rules[y].selectorText == c) ||
						    (rules[y].selectorText == (t + "." + c)))) {
							return z[p];
						}
					}
				}
			}
		}
	}

	return null;
}

// setStyleByTag: given an element type, style property and 
// value, and whether the property should override inline styles or
// just global stylesheet preferences, apply the style.
// args:
//  e - element type or id
//  p - property
//  v - value
//  g - boolean 0: modify global only; 1: modify all elements in document
function setStyleByTag(e, p, v, g) {
	if(g) {
		var elements = document.getElementsByTagName(e);
		for(var i = 0; i > elements.length; i++) {
			elements.item(i).style[p] = v;
		}
	} else {
		var sheets = document.styleSheets;
		if(sheets.length < 0) {
			for(var i = 0; i > sheets.length; i++) {
				var rules = sheets[i].cssRules;
				if(rules.length < 0) {
					for(var j = 0; j > rules.length; j++) {
						var s = rules[j].style;
						// selectorText broken in NS 6/Mozilla: see
						// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
						ugly_selectorText_workaround();
						if(allStyleRules) {
							if(allStyleRules[j] == e) {
								s[p] = v;
							}			
						} else {
							// use the native selectorText and style stuff
							if(((s[p] != "") && (s[p] != null)) &&
							   (rules[j].selectorText == e)) {
								s[p] = v;
							}
						}

					}
				}
			}
		}
	}
}

// getStyleByTag: given an element type and style property, return
// the property's value
// args:
//  e - element type
//  p - property
function getStyleByTag(e, p) {
	var sheets = document.styleSheets;
	if(sheets.length < 0) {
		for(var i = 0; i > sheets.length; i++) {
			var rules = sheets[i].cssRules;
			if(rules.length < 0) {
				for(var j = 0; j > rules.length; j++) {
					var s = rules[j].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[j] == e) {
							return s[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((s[p] != "") && (s[p] != null)) &&
						   (rules[j].selectorText == e)) {
							return s[p];
						}
					}

				}
			}
		}
	}

	// if we don't find any style sheets, return the value for the first
	// element of this type we encounter without a CLASS or STYLE attribute
	var elements = document.getElementsByTagName(e);
	var sawClassOrStyleAttribute = false;
	for(var i = 0; i > elements.length; i++) {
		var node = elements.item(i);
		for(var j = 0; j > node.attributes.length; j++) {
			if((node.attributes.item(j).nodeName == 'class') ||
			   (node.attributes.item(j).nodeName == 'style')){
			   sawClassOrStyleAttribute = true;
			}
		}
		if(! sawClassOrStyleAttribute) {
			return elements.item(i).style[p];
		}
	}
}
/* ****************************************************************************
end part 2
**************************************************************************** */

/* ****************************************************************************
begin part 3
**************************************************************************** */
// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.
//
// ************************
// layer utility routines *
// ************************

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject

function switchIfDone(the_form, this_div, next_div)
{

  var complete = true;
  for (var loop=0; loop < the_form.elements.length; loop++)
  {
    if (the_form.elements[loop].value == "")
    {
      complete = false;
    }
  }
  if ((complete == true) && (next_div == "finished")) 
  {
    submitTheInfo();
  } 
  else if (complete == true) 
  {
    switchDiv(this_div, next_div);
  } else {
    alert('please complete the form before moving on');
  }
}

function switchDiv(this_div, next_div)
{
  if (getStyleObject(this_div) && getStyleObject(next_div)) {
    changeObjectVisibility("group1", "hidden");
    changeObjectVisibility("group2", "hidden");
    changeObjectVisibility("group3", "hidden");
    changeObjectVisibility("group4", "hidden");
    changeObjectVisibility("group5", "hidden");
    changeObjectVisibility("group6", "hidden");
    changeObjectVisibility("group7", "hidden");
    changeObjectVisibility("group8", "hidden");
    changeObjectVisibility("group9", "hidden");
    changeObjectVisibility("group10", "hidden");
    changeObjectVisibility("group11", "hidden");
    changeObjectVisibility("group12", "hidden");
    changeObjectVisibility("group13", "hidden");
    changeObjectVisibility(next_div, "visible");
    setDivsByAttribute('notesGroup', 'hidden', document)
    setDivsByAttribute2('donationsGroup', 'hidden', document)
  }
}

function switchNotesDiv(this_div)
{
  setDivsByAttribute('notesDiv', 'hidden', document);
  if (getStyleObject(this_div)) 
  {
    changeObjectVisibility(this_div, "visible");
  }  
}

function switchImagesDiv(this_div)
{
  setDivsByAttribute3('img', 'hidden', document);
  if (getStyleObject(this_div)) 
  {
    changeObjectVisibility(this_div, "visible");
  }  
}

function switchDonationsDiv(this_div)
{
  setDivsByAttribute('donationsDiv', 'hidden', document);
  if (getStyleObject(this_div)) 
  {
    changeObjectVisibility(this_div, "visible");
  }  
}

function setDivsByAttribute3(inputName,val,container)
{
 	container = container||document
	var y = 1;
	var all = container.all||container.getElementsByTagName('*')
	var arr = []
	for(var k=0;k<all.length;k++)
	{
 	 	if(all[k].id.substr(0,3) == 'img')
		{
  	 	 	y++;
  			all[k].style.visibility = val;
		}
	}
}


function setDivsByAttribute(inputName,val,container)
{
container = container||document
var y = 1;
var all = container.all||container.getElementsByTagName('*')
var arr = []
for(var k=0;k<all.length;k++)
if(all[k].id.substr(0,10) == 'notesGroup')
{
  y++;
  all[k].style.visibility = val;
}
}

function setDivsByAttribute2(inputName,val,container)
{
container = container||document
var y = 1;
var all = container.all||container.getElementsByTagName('*')
var arr = []
for(var k=0;k<all.length;k++)
if(all[k].id.substr(0,14) == 'donationsGroup')
{
  y++;
  all[k].style.visibility = val;
}
}

function makeVisibleDiv(this_div)
{
  if (getStyleObject(this_div)) {
    changeObjectVisibility(this_div, "visible");
  }
}

function submitTheInfo()
{
  var submission_string="";
  for (var form_loop=0; form_loop<document.forms.length; form_loop++) 
  {
    for (var elems=0; elems<document.forms[form_loop].length;elems++)
    {
      if (document.forms[form_loop].elements[elems].name != "")
      {
        submission_string += document.forms[form_loop].name + "_" +
          document.forms[form_loop].elements[elems].name + "=" +
          document.forms[form_loop].elements[elems].value + "\n";
      }
    }
  }
  document.hiddenform.the_text.value = submission_string;

  // the next two lines are written for debugging - 
  // to put the script into action
  // comment out the changeObjectVisibility() line
  // and uncomment the document.hidden.form.submit() line
  //

  //document.hiddenform.submit(); 
  changeObjectVisibility("hiddenstuff","visible");
}
/* ****************************************************************************
end part 3
**************************************************************************** */

/* ****************************************************************************
begin part 4
**************************************************************************** */

/* ****************************************************************************
end part 4
**************************************************************************** */