/*Basic swap img methods and find object methods*/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*
Timer by Algorithm
  http://www.codingforums.com/archive/index.php/t-10531.html
 */
 function Timer(){
  this.obj = (arguments.length)?arguments[0]:window;
  return this;
 }
 
 // The set functions should be called with:
 // - The name of the object method (as a string) (required)
 // - The millisecond delay (required)
 // - Any number of extra arguments, which will all be
 // passed to the method when it is evaluated.
 
 Timer.prototype.setInterval = function(func, msec){
  var i = Timer.getNew();
  var t = Timer.buildCall(this.obj, i, arguments);
  Timer.set[i].timer = window.setInterval(t,msec);
  return i;
 }
 Timer.prototype.setTimeout = function(func, msec){
  var i = Timer.getNew();
  Timer.buildCall(this.obj, i, arguments);
  Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
  return i;
 }
 
 // The clear functions should be called with
 // the return value from the equivalent set function.
 Timer.prototype.clearInterval = function(i){
  if(!Timer.set[i]) return;
  window.clearInterval(Timer.set[i].timer);
  Timer.set[i] = null;
 }
 Timer.prototype.clearTimeout = function(i){
  if(!Timer.set[i]) return;
  window.clearTimeout(Timer.set[i].timer);
  Timer.set[i] = null;
 }
 
 // Private data
 Timer.set = new Array();
 Timer.buildCall = function(obj, i, args){
  var t = "";
  Timer.set[i] = new Array();
  if(obj != window){
   Timer.set[i].obj = obj;
   t = "Timer.set["+i+"].obj.";
  }
  t += args[0]+"(";
  if(args.length > 2){
   Timer.set[i][0] = args[2];
   t += "Timer.set["+i+"][0]";
   for(var j=1; (j+2)<args.length; j++){
    Timer.set[i][j] = args[j+2];
    t += ", Timer.set["+i+"]["+j+"]";
   }
  }
  t += ");";
  Timer.set[i].call = t;
  return t;
 }
 Timer.callOnce = function(i){
  if(!Timer.set[i]) return;
  eval(Timer.set[i].call);
  Timer.set[i] = null;
 }
 Timer.getNew = function(){
  var i = 0;
  while(Timer.set[i]) i++;
  return i;
 }
 
 
function $() {
    var elements = new Array();
 
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
 
        if (typeof element == 'string')
            element = document.getElementById(element);
 
        if (arguments.length == 1)
            return element;
 
        elements.push(element);
    }
 
    return elements;
}
 
function loadPicture(element) {
 tmp = ('../library/images/'+element+".jpg");
 document.images['banner'].src=tmp;
}
 
 
 
function getElementsByClass(searchClass,node,tag) {
 var classElements = new Array();
 if ( node == null )
  node = document;
 if ( tag == null )
  tag = '*';
 var els = node.getElementsByTagName(tag);
 var elsLen = els.length;
 var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
 for (i = 0, j = 0; i < elsLen; i++) {
  if ( pattern.test(els[i].className) ) {
   classElements[j] = els[i];
   j++;
  }
 }
 return classElements;
}
 
function toggleheading(element) {
 var e = $(element);
 tmp = getElementsByClass("leftNav");
 for (i=0;i<tmp.length;i++){
  tmp[i].style.display = 'none';
 }
 if(e.style.display == 'block' ) {
  e.style.display = 'none';
 } else {
  e.style.display = 'block';
 }
}
 
 
function function1(element){
 tmp = getElementsByClass("leftNav");
 for (i=0;i<tmp.length;i++){
  tmp[i].style.display = 'none';
 }
}

//Add more fields dynamically.
function addField(field,area,limit) {
	if(!document.getElementById) return; //Prevent older browsers from getting any further.
	var field_area = document.getElementById(area);
	var all_inputs = field_area.getElementsByTagName("input"); //Get all the input fields in the given area.
	//Find the count of the last element of the list. It will be in the format '<field><number>'. If the 
	//		field given in the argument is 'friend_' the last id will be 'friend_4'.
	var last_item = all_inputs.length - 1;
	var last = all_inputs[last_item].id;
	var count = Number(last.split("_")[1]) + 1;
	var i = field_area.getElementsByTagName("li").length + 1;
	
	//If the maximum number of elements have been reached, exit the function.
	//  If the given limit is lower than 0, infinite number of fields can be created.
	if(count > limit && limit > 0) return;
 	
	if(document.createElement) { //W3C Dom method.
		field_area.innerHTML += 
		"<li><input name='"+("EmployeeInitials"+"_"+i)+"' id='"+(field+count)+"' type='text' size='3' maxlength='5'/>&nbsp;<input name='"+("Age"+"_"+i)+"' id='"+(field+count)+"' type='text' size='2' maxlength='2'/>&nbsp;<input name='"+("Sex"+"_"+i)+"' id='"+(field+count)+"' type='text' size='2' maxlength='1'/>&nbsp;<input name='"+("SpouseAge"+"_"+i)+"' id='"+(field+count)+"' type='text' size='2' maxlength='3'/>&nbsp;<input name='"+("numChildren"+"_"+i)+"' id='"+(field+count)+"' type='text' size='10' maxlength='3'/>&nbsp;<input name='"+("Location"+"_"+i)+"' id='"+(field+count)+"' type='text' size='10' maxlength='50'/></li>";
		
	} else { //Older Method
		field_area.innerHTML += 
		"<li><input name='"+("EmployeeInitials"+"_"+i)+"' id='"+(field+count)+"' type='text' size='3' maxlength='5'/>&nbsp;<input name='"+("Age"+"_"+i)+"' id='"+(field+count)+"' type='text' size='2' maxlength='2'/>&nbsp;<input name='"+("Sex"+"_"+i)+"' id='"+(field+count)+"' type='text' size='2' maxlength='1'/>&nbsp;<input name='"+("SpouseAge"+"_"+i)+"' id='"+(field+count)+"' type='text' size='2' maxlength='3'/>&nbsp;<input name='"+("numChildren"+"_"+i)+"' id='"+(field+count)+"' type='text' size='10' maxlength='3'/>&nbsp;<input name='"+("Location"+"_"+i)+"' id='"+(field+count)+"' type='text' size='10' maxlength='50'/></li>";
	}
}
