
//********************tooltip functions***************

function postooltip(object){

//define universal reference to "staticcontent"
var crossobj=document.all? document.all.staticcontent : document.getElementById(object)

//define reference to the body object in IE
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body


//define universal dsoc left point
var dsocleft=document.all? iebody.scrollLeft : pageXOffset
//define universal dsoc top point
var dsoctop=document.all? iebody.scrollTop : pageYOffset

//if the user is using IE 4+ or Firefox/ NS6+
document.getElementById(object).style.left=parseInt(dsocleft)+5+"px"
document.getElementById(object).style.top=dsoctop+5+"px"
}


function showTooltip (object)

{

postooltip(object);
  show(object);
  
}

function hideTooltip (object)

{

  hide(object);
  
}



//form scripts
//********************FormValidator***************
//called by forms on submission to validate forms


function FormValidator(which){
//alert(which)
var validFieldIDValue=""
var pass=false
var formflag=true //final status for the form control determine rather to submit the form
	for (i=0;i<which.length;i++){ //loop thro the controls of the form
	var tempobj=which.elements[i]
	//alert(tempobj.name)
	//if the name of the tag starts with the word Validate
	//it contains the validation for the same field ID
	//excluding the Valid text
	if (tempobj.name.substring(0,8)=="validate"){
		
		
		var validFieldID=tempobj.name.replace("validate","") //determine  the ID of the field to validate
		var validFieldIDType=document.getElementById(validFieldID).type //get  the TYPE of the field to validate
		var validFunct=tempobj.value //get  the VALUE of the field to validate
		//alert("loop"+validFieldIDType)
		if (validFieldIDType=="radio"||validFieldIDType=="checkbox") //if the control is of TYPE checkbox or radio do this
			{

				//the groups of controls in radio or checkboxe groups
				//must be accessed from the names because that ties them together

				var validFieldIDName=document.getElementById(validFieldID).name //get the name of the group of controls

				//alert("found " + validFieldIDName + "|" +validFieldIDType)
				validFieldIDValue=""
				for (j=0;j<document.getElementsByName(validFieldIDName).length;j++) //loop thru the controls with this name
				{
					if (document.getElementsByName(validFieldIDName)[j].checked==true) //if find a control that is checked stop the loop
						{
						validFieldIDValue="found" //set the value to found when an checked element is found
						break // stop the loop
						}
					else
						{
						validFieldIDValue="" //element was not checked set the value to ""
						continue // continue to loop and look for a checked element
						}


				}
			}

		else //else if not a checkbox or radio
			{
			validFieldIDValue=document.getElementById(validFieldID).value //  get the value of the field to validate
			}
		 // determine if the value of the control passes validation
		 pass=fieldValidator(validFunct,validFieldIDValue)
		 //fieldValidator returns false for a failed validation




		if (!pass){
		//if pass not equel to true
		show("Err" + validFieldID) //display the error div
		pass=false
		formflag=false
		}
		else
		{

		hide("Err" + validFieldID) //hide the error div
		}






	}



}
if (formflag){

//if the formflag is true
return true // submit the form
}
else //if the formflag is false
alert("One or more of the required form fields are not completed. Please complete them, then submit again!")
return false //dont submit the form
}

//****************end of checkValid********************************


//****************FieldValidator********************************
//called by FormValidator to validate the various types of fields
//a true value returned indicates the field has passed
//fieldtype=the type of validation to process
//field value = the value to check the validation against

function fieldValidator(fieldtype,fieldvalue){
var testresult=true
switch(fieldtype){
case "noVal":
testresult=true
break
case "numVal":
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(fieldvalue))
		{
		testresult=true
		}
	else
		{
		testresult=false
		}





break
case "txtVal":
testresult=true
break



case "dateVal":
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
	//var testresult=false
	if (!validformat.test(fieldvalue))
		testresult=false
		//alert("Invalid Date Format. Please correct and submit again.")
	else{ //Detailed check for valid date ranges
		var monthfield=fieldvalue.split("/")[0]
		var dayfield=fieldvalue.split("/")[1]
		var yearfield=fieldvalue.split("/")[2]
		var dayobj = new Date(yearfield, monthfield-1, dayfield)

		if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			//alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
			testresult=false
		else
			testresult=true
		}
break

case "selectVal":
{
//alert(fieldvalue)
var noselection="---select an option---"
if (fieldvalue=="---select an option---"){
testresult=false
}
else
{
testresult=true
}

break
}

case "requiredVal":
{
//alert("requiredValfieldvalue" + "|" + fieldvalue + "|")
var noentry=""
if (fieldvalue==null){
testresult=false
}
else if(fieldvalue=="")
{
testresult=false
}
else
{
testresult=true
}

break
}



case "maxchrVal":
var maxlength=50
if (fieldvalue.length>maxlength){
testresult=false
}
else
{
testresult=true
}

break
case "emailVal":
var str=fieldvalue
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresult=true
else{

testresult=false

}
break



}
return testresult
}

//********************modaware style events*********************
//function changeBG changes the background color of an object

function changeStyle(targetObject,targetStyle,targetValue) {

 var el=document.getElementById(targetObject);
   
   switch (targetStyle){
   case "background-color":
   	el.style.backgroundColor=targetValue;
   	break
   case "border-top-style":
   	el.style.borderTopStyle=targetValue;
   	break
  case "border-bottom-style":
     	el.style.borderBottomStyle=targetValue;
     	break
  case "border-left-style":
     	el.style.borderLeftStyle=targetValue;
     	break
  case "border-right-style":
     	el.style.borderRightStyle=targetValue;
     	break
    
  case "border-color":
   	el.style.borderColor=targetValue;
   	break
   case "border-width":
   	el.style.borderWidth=targetValue;
   	break
   
   case "text-align":
      	el.style.textAlign=targetValue;
   	break
   case "text-decoration":
         el.style.textDecoration=targetValue;
      	break
   
   case "font-family":
        el.style.fontFamily=targetValue;
        break
   
   case "font-size":
         el.style.fontSize=targetValue;
         break
   
   case "font-style":
         el.style.fontStyle=targetValue;
         break
         
    case "font-weight":
	 el.style.fontWeight=targetValue;
         break
         
    case "Color":
	 el.style.color=targetValue;
         break
   }
   }








//function show shows a hidden div tag when passed the ID of the object

function show(object) {
 
 var el=document.getElementById(object);
   el.style.visibility='visible';

}


//*************end show********************************


//function hide hides a visible div tag when passed the ID of the object

function hide(object) {
   var el=document.getElementById(object);
    el.style.visibility='hidden';
}

function delayHide(object) {
   var delay_hide=500
   var hideIt='hidden'
   var el=document.getElementById(object);
   delayhide=setTimeout('hide("'+object+'")',delay_hide);
}

function clear_delayhide(){
if (window.delayhide)
clearTimeout(delayhide)
}

function lockShow(object) {
 show(object)
 clear_delayhide()
 //var el=document.getElementById(object);
   //el.style.visibility='visible';

}

//*************end hide********************************

//***************showGroup*********************//

function showGrp(pList) {
var List;
var i;

List = pList.split("|");


for (i=0;i<List.length;i++)
		{
			show(List[i]);
		}
	
		
}


//***************HideGroup*********************//

function delayHideGrp(pList) {
var List;
var i;

List = pList.split("|");


for (i=0;i<List.length;i++)
		{
			delayHide(List[i]);
		}
	
		
}
//***************lockShowGroup*********************//

function lockShowGrp(pList) {
var List;
var i;

List = pList.split("|");


for (i=0;i<List.length;i++)
		{
			lockShow(List[i]);
		}
	
		
}
//***************AJAX*********************//

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function showData(object,objectMethod,strData) {
   var el=document.getElementById(object);
  if (objectMethod == "innerHTML")
  	{
  	el.innerHTML=strData;
  	}
  	
  if (objectMethod == "value")
    	{
    	el.value=strData;
  	}
  
}



function showAjax(objID,objMethod,servCmd,servScript)
{

var ajaxObjID=objID;
var ajaxObjMethod=objMethod;

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

var url="ServeMod"+servScript+".asp?cmd="+servCmd;

xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() {
  if (xmlHttp.readyState==4) {
  showData(ajaxObjID,ajaxObjMethod,xmlHttp.responseText); 
   
  }
 }
 xmlHttp.send(null);

}
//***************EndAJAX*********************//

 
  
