<!--

function MM_findObj(n, d) { //v3.0 waztech.com
	var p,i,x;
	//alert("form element name="+n);
	if (!d) d=document;
	if ( (p=n.indexOf("?") ) > 0 && parent.frames.length ) // if there are frames
	{	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);	}
	
	if (!(x=d[n]) && d.all)  x=d.all[n]; 
	/* if Internet Explorer (d.all) and you can't find the object 
	in the root of the document tree, crawl through the forms collection */

	for (i=0; !x && i<d.forms.length; i++) x=d.forms[i][n];
	/* loop through all forms on the page to find the element */
	
	/* if netscape (with layers), loop through all layers, call the function again, referencing the document of each layer  */
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	
	// return the object reference
	//alert("found name="+x.name);
	return x;
}



function MM_validateForm() 
{ //v6 waztech.com
  var i,p,di,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments,objForm;
//if the first element in the form is a multiple item, i.e. a radio button array, you have to get the form from the first array element.
if (MM_findObj(args[0]).length > 0 )
	{ //get the first array element and find the form
	objForm=MM_findObj(args[0])[0].form;
	}
	else
	{// just get the form from the single element
	objForm=MM_findObj(args[0]).form;
	}




  for (i=0; i<(args.length-2); i+=3) 
  { 	test=args[i+2];
  		
  		val=MM_findObj(args[i]); 
		//debug
		if (val.length > 0 )
		{	//alert("val[0].name="+val[0].name); 
		}
		else
		{	//alert("val.name="+val.name); 
		}
		
		// ****** special test for elements of an array (select lists, radios, checkboxes, etc)
		//alert("val.length="+val.length);
		if (val.length > 0 )  
		{	 //alert('length > 0'); 
			// use an array access to get the element names, checked,
			//  and values

			anyChecked = -1;
			//for (vi=0; vi < val.length; vi++)
			for (vi=val.length-1; vi > -1; vi--)
				{	//alert("loop="+vi+":val="+val[vi].selected);
					//alert("loop="+vi+":val="+val[vi].checked);
				if (val[vi].checked || val[vi].selected)
					{ anyChecked = vi; }		
				}
			
			if (anyChecked == -1) 
				{ 	//alert('none checked');
					//alert(val.name+' <> '+val.vname);
					if (val.name==null) 
					{	if (val[0].vname != null) {nm=val[0].vname;} else {nm=val[0].name;}
					}
					else
					{ // use the element name without the index
					if (val.vname != null) {nm=val.vname;} else {nm=val.name;}
					} // end test if element has index
					
					if (test.charAt(0) == 'R') {errors += '- '+nm+' : please make a selection.\n'; }
				}// end test if none checked
		}
		
		else // for elements that do not have more than one value in an array
		{
		
		
		// ****** validation checks
		if (val) 
		{  //alert(val.vname +' <> '+val.name);
			if(val.vname != null) {nm=val.vname;} else {nm=val.name;} 
			
			if (!val.checked && (val.type.indexOf('radio')!=-1 || val.type.indexOf('checkbox')!=-1) )
				{ errors+='- '+nm+' must be selected.\n'; }
			
			if ((val=val.value)!="") 
			{	if (test.indexOf('isEmail')!=-1) 
				{ p=val.indexOf('@'); di=val.lastIndexOf('.');
					if ( p<1 || p==(val.length-1) || di<p || di==p+1 || di>=val.length-2 )
					{ errors+='- '+nm+' must contain a valid e-mail address.\n'; }
				}
			else if (test!='R') 
			{	num = parseFloat(val);
		        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
		        if (test.indexOf('inRange') != -1) 
				{	p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1);
					if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
				}
			}
		}
		else if (test.charAt(0) == 'R') errors += '- '+nm+' cannot be blank.\n'; 
		}
		
		
		}// end check if element array (radio)

  }// loop to next form element to validate

  if (errors) 
  	{ 	alert('Please make these changes in the form:\n'+errors); 
		document.MM_returnValue = false;
	}
	else
	{	//alert(objForm);
		//alert(objForm.length);
		disableForm(objForm);
		document.MM_returnValue = true;
	}

}

/* this function will disable the form button, so it can't be clicked on after the form is submitted */
function disableForm(theform) 
	{	if (document.all || document.getElementById) 
		{	//alert(theform);
			//alert(theform.name);
			//alert(theform.length);
			for (i = 0; i < theform.length; i++) 
			{	var tempobj = theform.elements[i];
				if (tempobj.type.toLowerCase() == "submit") tempobj.disabled = true;
			}
		}
		else // show alert if we can't find the submit button.
		{ setTimeout("alert('The information is being sent. Thank you.');", 3000); }
	return true;
	}
// end function




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_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];}
}



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_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function Help(url) {
	window.open('http://www.waztech.com/IntranetManual/' + url, 'helpframe', "height=400,width=600,status=no,directories=no,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,screenY=0,screenX=300,top=0,left=300");
}


// counts number of characters in textarea fields 
// and display it in read only form field, trim it if too long
function textCounter(field,maxlimit) 
{ var counter_field = field.name + '_Counter';
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
	if ( document.all[counter_field] )
{document.all[counter_field].value = maxlimit - field.value.length;}

}// end function

//-->

