function checknum(string) {

    if (!string) return false;
    var Chars = "0123456789";

    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == -1) {
			alert('Only numbers are allowed in this field.');
			string="";
			return false;
          } //if
    } //for
    return true;
} // function checknum


//----------------------function checkEmpty(what)---------------------
// this func is basically a reminder to users that the field pass into it
// is required. it does not force the user to enter a value.

function checkEmpty(what) {
	msg="";
	
	if (!what.value) strmsg="This field is Required!";
	
	if (what.value.length==0) 
		strmsg="This field is Required!";
	else
		return true;
	
	if (strmsg != "") {
		alert(strmsg+'\n\nPlease try again.');
		what.focus();
		return false;
		}
	//else
		//{ return true; }

} // func checkEmpty



function keyhandler(e) {
    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;
}

    
//----------------- Input Masks -----------------------------------
// not in use as of 2/2/01
// functions work in IE 4.x & 5.x but not in NN 4.x

function keyhandler(e) {
    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;
}



//------------------function KeyPress--------------------------------
function KeyPress(what,e,max,action) {
		
	if (document.layers) document.captureEvents(Event.KEYPRESS); 

	document.onkeypress = keyhandler;

    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;
    
    //window.status = 'keyval=' + Key;

		    if (document.layers) {
		        if (e.target.value.length >= max) {
		            eval(action);
		            }
				}
		    else if (document.all) {
		        if (what.value.length > (max-1)) {
					//alert('action');
					eval(action);
				}
		    }
		}


function keyfilter(what,e,max,formid) {
	var obid=eval("document.Personalform." + formid);
												  
	{
	if (document.layers) document.captureEvents(Event.KEYPRESS); 

	document.onkeypress = keyhandler;

    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;
    
    window.status = 'keyval=' + Key;

		    //if (document.layers) {
		      //  if (e.target.value.length >= max)
		        //   eval(action);
		    //}
		    //else if (document.all) {
		      //  if (what.value.length > (max-1))
		        //    eval(action);
		    //}


if (formid == "NewSSN") formid="SSN";
if (formid == "HomePhone" || formid == "WorkPhone") formid="Phone";
if (formid == "NewMI") formid="MI";
if (formid == "NewDOB" || formid == "DisabledDate")  formid="Date";


// ----------- SWITCH ------------------

switch (formid) {
	
	case "SSN": {
	 
		if (what.value=="   -  -    ") {
			what.value="";
		}

	if (what.value.length == 13) {
		e.cancelBubble = false;
		e.returnValue = false;
		return false;
	} // if obid
   		
   
	if (Key >=48 && Key <=57) {

   		// extract only numbers, reformat with dashes, return

		str="";
		tmpstr="";
		var allowed = "0123456789";
		
		for (var i=0; i < what.value.length; i++) {
			if (allowed.indexOf(what.value.charAt(i)) != -1){
				tmpstr=tmpstr + what.value.charAt(i);		
			} // if
		} // for
			
	e.cancelBubble = false;
	e.returnValue = true;
	
		for (var i=0; i < tmpstr.length; i++) {
			if (i == 3 || i == 5) {
				str = str + "-";
				str = str + tmpstr.charAt(i);
			}
			else {
				str = str + tmpstr.charAt(i);
			}
		}
	
	what.value=str;
	return false;

	} // if ((Key>=48
else {

	if (Key == 8 || Key == 36 || Key == 46 || Key == 37 || Key == 39) {

		e.cancelBubble = false;
		e.returnValue = true;
	
		return false;
	} // if key==8 ==36
			
		// extract only numbers, reformat with dashes, return
		str="";
		tmpstr="";
		var allowed = "0123456789";
		
		for (i=0; i < what.value.length; i++) {
			if (allowed.indexOf(what.value.charAt(i)) != -1){
				tmpstr=tmpstr + what.value.charAt(i);
			}
		} // for

		for (i=0; i < tmpstr.length; i++) {
			if (i == 3 || i == 5) {
				str = str + "-";
				str = str + tmpstr.charAt(i);
		}
		else	{
			str = str + tmpstr.charAt(i);
		}
		} // for i

		what.value = str;
        e.cancelBubble = false;
        e.returnValue = true;
		
		return true;
	
    } // elseif

    	break;

	} // case NewSSN





// INPUT MASK FOR NewMI

	case "MI": {

		if (Key>=65 && Key <=122) {

				what.value=what.value.toUpperCase();			
				
				//if (Key >= 97 && Key <=122) val=Key-65; else val=Key;
				
				//what.value = String.fromCharCode(val);
				
				e.cancelBubble = false;
				e.returnValue = false;
				return true;
		}
		else
		{
			e.cancelBubble = true;
			e.returnValue = false;
			return false;
		} // if key>=65&&<=122

	break;
	
	} // case NewMI




// ----------- Phone Mask ---------------------

	case "Phone": {
	
		if (obid.value=="(   )   -    ") {
			obid.value="";
		}

	if (obid.value.length == 13) {
		window.event.cancelBubble = false;
		window.event.returnValue = true;
		return false;
	} // if obid
  
	if (Key >=48 && Key <=57) {
	

   		// extract only numbers, reformat with dashes, return

		str="";
		tmpstr="";
		var allowed = "0123456789";
		
		for (var i=0; i < obid.value.length; i++) {
			if (allowed.indexOf(obid.value.charAt(i)) != -1){
				tmpstr=tmpstr + obid.value.charAt(i);		
			} // if
		} // for
			
	window.event.cancelBubble = false;
	window.event.returnValue = true;
	
		for (var i=0; i < tmpstr.length; i++) {
			
			switch (i) {
				case 0: 
					str=str+"(";
					str=str+tmpstr.charAt(i);
					break;
				
				case 3:
					str=str+")";
					str=str+tmpstr.charAt(i);
					break;
				
				case 6: 
					str=str+"-";
					str=str+tmpstr.charAt(i); 
					break; 
				
				default:
					str=str+tmpstr.charAt(i);
					break;
				
			} // switch (i)
			
		} // for i
		
	
	obid.value=str;
	
	return false;

	} // if ((Key>=48
else {

	if (Key == 8 || Key == 36 || Key == 46 || Key == 37 || Key == 39) {
	
		//obid.value = obid.value.substring(0, obid.value.length-1);
		window.event.cancelBubble = false;
		window.event.returnValue = true;
	
		return false;
	} // if key==8 ==36
			
		// extract only numbers, reformat with dashes, return
		str="";
		tmpstr="";
		var allowed = "0123456789";
		
		for (i=0; i < obid.value.length; i++) {
			if (allowed.indexOf(obid.value.charAt(i)) != -1){
				tmpstr=tmpstr + obid.value.charAt(i);
			}
		} // for

		for (var i=0; i < tmpstr.length; i++) {
			
			switch (i) {
				case 0: 
					str=str+"(";
					str=str+tmpstr.charAt(i);
					break;
				
				case 3:
					str=str+")";
					str=str+tmpstr.charAt(i);
					break;
				
				case 6: 
					str=str+"-";
					str=str+tmpstr.charAt(i); 
					break; 
				
				default:
					str=str+tmpstr.charAt(i);
					break;
				
			} // switch (i)
			
		} // for i

		obid.value = str;
        window.event.cancelBubble = false;
        window.event.returnValue = false;
		
		return false;
	
    } // elseif

	break;
	
} // case Phone
	



// ----------- Date Mask ---------------------

	case "Date": {
	
		if (obid.value=="  /  /    ") {
			obid.value="";
		}

	if (obid.value.length == 10) {
		window.event.cancelBubble = false;
		window.event.returnValue = true;
		return false;
	} // if obid
  
	if (Key >=48 && Key <=57) {

   		// extract only numbers, reformat with dashes, return

		str="";
		tmpstr="";
		var allowed = "0123456789";
		
		for (var i=0; i < obid.value.length; i++) {
			if (allowed.indexOf(obid.value.charAt(i)) != -1){
				tmpstr=tmpstr + obid.value.charAt(i);		
			} // if
		} // for
			
	window.event.cancelBubble = false;
	window.event.returnValue = true;
	
		for (var i=0; i < tmpstr.length; i++) {
			
			switch (i) {
				case 2: 
					str=str+"/";
					str=str+tmpstr.charAt(i);
					break;
				
				case 4:
					str=str+"/";
					str=str+tmpstr.charAt(i);
					break;
				
				default:
					str=str+tmpstr.charAt(i);
					break;
				
			} // switch (i)
			
		} // for i
		
	
	obid.value=str;
	
	return false;

	} // if ((Key>=48
else {

	if (Key == 8 || Key == 36 || Key == 46 || Key == 37 || Key == 39) {
	
		//obid.value = obid.value.substring(0, obid.value.length-1);
		window.event.cancelBubble = false;
		window.event.returnValue = true;
	
		return false;
	} // if key==8 ==36
			
		// extract only numbers, reformat with dashes, return
		str="";
		tmpstr="";
		var allowed = "0123456789";
		
		for (i=0; i < obid.value.length; i++) {
			if (allowed.indexOf(obid.value.charAt(i)) != -1){
				tmpstr=tmpstr + obid.value.charAt(i);
			}
		} // for

		for (var i=0; i < tmpstr.length; i++) {
			
			switch (i) {
				case 2: 
					str=str+"/";
					str=str+tmpstr.charAt(i);
					break;
				
				case 4:
					str=str+"/";
					str=str+tmpstr.charAt(i);
					break;
				
				default:
					str=str+tmpstr.charAt(i);
					break;
				
			} // switch (i)
			
		} // for i
		
		obid.value = str;
        window.event.cancelBubble = false;
        window.event.returnValue = false;
		
		return false;
	
    } // elseif

	break;
	
} // case Date
	





} // SWITCH

// --------------- END SWITCH -----------------





}
} // function keyfilter


function microsoftKeyPress() {
    if (window.event.keyCode == 27)
        window.close();
}

//------------------ validates the data entered into forms on the employee page------------------------

function phoneno(formid){
	var obid=eval("document.Personalform." + formid);
		{
		
	//if (obid.value=="(   )   -    ") {
	//	obid.value="";
	//	return(true);	
	//}
	
	if (obid.value.length>0){
//		if (obid.value.indexOf("\(")!=-1 || obid.value.indexOf("\)")!=-1||obid.value.indexOf("\-")!=-1)
//			{
//			alert ("Please use numbers only when entering phone numbers");
//			obid.select();obid.focus();
//			}
		if (obid.value.length>0 && obid.value.length<10)
			{
			alert ("Please enter at least a 10 digit phone number.")
			//obid.select();
			obid.focus();
			}
		}	
	}
}

function email(formid){
	var obid=eval("document.Personalform." + formid);
		{
	//	var lng=obid.value.length;
	if (obid.value.length>0){
		 if (obid.value.indexOf("\@")==-1 || obid.value.indexOf("\.")==-1)
			{
			//setfocus(formid);
			alert ("Please enter a valid email address in the form: yourname@company.com");
			//obid.select();
			obid.focus();
			return(false);
			}
		if (obid.value.length>0 && obid.value.length<6)
			{
			//setfocus(formid);
			alert ("Please enter at least a 6 character email address.")
			//obid.select();
			obid.focus();
			return(false);
			}		
	else
		return true;

	} //if
	//return (false);
	}
}


function checkemail(email) {

  if (email.length > 50)
  {
//    theForm.Homeemail.focus();
    alert("Please enter at most 50 characters in the \"Email\" field.");
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-@.-_";
  var checkStr = email;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }

   if (email.length > 0 && email.length < 6)
  {
    //theForm.Homeemail.focus();
    alert("Please enter at least 6 characters in the \"Email\" field.\n\nExample: yourname@company.com");
    return (false);
  }

  if (email.length > 0 && (email.indexOf("\@")==-1 || email.indexOf("\.")==-1))
	allValid=false;

  if (!allValid)
  {
    //setfocus('Homeemail');
    //theForm.Homeemail.focus();
alert("The form cannot be submitted.\n\nPlease enter only letter, digit and \"@.-_\" characters in the \"Email\" field.\n\nExample: yourname@company.com");
    
    return (false);
  }
return;


} // func checkemail


function ssnchk(formid){
	var obid=eval("document.Personalform." + formid);
		{
		
//	if (obid.value=="      -    -    ") {
//		return(true);
//	}
	
	if (obid.value.length>0){	
		if ((obid.value.indexOf("\-")!=3 || obid.value.lastIndexOf("\-")!=6) || obid.value.length < 11)
			{
			alert ("Please enter a valid Social Security Number in the form: 999-99-9999");
			
			//obid.select();
			obid.focus();
			return(false);
			}
		}
	
	if (obid.value.length==0 && document.Personalform.frmname.value=="addemployee") {
		alert('SSN is a required field.');

		//obid.select();
		//obid.focus();
		return(false);
		}
	return (true);
	}
}

//------------------datecheck(MM,DD,YYYY,formid)---------------------


function datecheck(MM,DD,YYYY,formid,fieldname,failfocus,warnfocus) {
	var obid=eval("document.Personalform." + formid); // original hidden value
	var focuson=eval("document.Personalform." + failfocus); // part of field to focus on if test fails

	var msg="";

	var newdate = MM + '/' + DD + '/' + YYYY

	var t = Date.parse(serverdate)

	var currentdate = new Date(t);

	var currentyear=currentdate.getFullYear();
	var currentmonth=currentdate.getMonth();
	var currentday=currentdate.getDate();
   	
	//alert('MM/DD/YYYY = '+MM+'/'+DD+'/'+YYYY+'\n\nCurrentdate='+currentmonth+'/'+currentday+'/'+currentyear+'\n\n'+currentdate);
		
	if (YYYY < 1900) msg=msg+"Invalid Year: Must be greater than 1899.\n";
	if (YYYY > currentyear) msg=msg+"Invalid Year: Cannot be greater than "+currentyear+".\n";
		
	if (DD < 1 || DD > 31) msg=msg+'Invalid Day: Must be between 1 and 31\n';
	if (MM < 1 || MM > 12) msg=msg+'Invalid Month: Must between 1 and 12\n';

	if (YYYY == currentyear) {
		if (MM > currentmonth+1)
			msg=msg+'Invalid Month: Cannot be greater than current month\n';

		if (MM == currentmonth+1 && DD > currentday) msg=msg+'Invalid Day: Cannot be greater than current day\n';
	}
		
	if (msg !="") allValid=false;

	if (!allValid)
			{
		  			alert (msg+"\nPlease enter a valid date in the form: MM/DD/YYYY");
					focuson.focus();
					return(false);
			}
	
	obid.value = newdate;
	
	if (allValid) {
		if (obid.value.length>0 && (document.Personalform.frmname.value=="employee" || document.Personalform.frmname.value=="dependent"))
			{
			if (!warnuser(failfocus, warnfocus,"Changing the Date of Birth (DOB) MAY affect your benefits enrollment.\nYour enrollment will be considered as pending until\napproval of this change by HR.\n\nClick OK if you want to change your date of birth."))
				return false;
			}
	} // if allValid
	return true;
} // end datecheck






function datechk(formid,failid){
	var obid=eval("document.Personalform." + formid);
	var obidfail=eval("document.Personalform." + failid); // used to clear MM & focus to MM in needed
//	var obidfail2=eval("document.Personalform." + failid2);	// used to clear DD
//	var obidfail3=eval("document.Personalform." + failid3); // used to clear YYYY
		{

	if (obid.value.length==0) return(true);
	
	var msg="";
	var allValid = true;
	var t = Date.parse(obid.value);
      

	if (obid.value.length==0 && document.Personalform.frmname.value=="addemployee") {
		alert('The Date field is required.');
		
		obidfail.focus();
		//obid.select();

		return(false);
		
		}
	
	if (obid.value.length>0 && obid.value.length<10)
		{
			//alert ("Please enter a valid date in the form: 07/04/1976");
			//obid.select();obid.focus();
			//return(false);
			allValid = false;
		}
		
		var ndx=obid.value.indexOf("/")
		var ndx2=obid.value.lastIndexOf("/")
	
	if (obid.value.length>0){	
		if ( ndx==ndx2 || (ndx==-1 && ndx2==-1) )
			{
			//alert ("Please enter a valid date in the form: 07/04/1976");
			
			//obid.select();obid.focus();
			//return(false);
			allValid = false;
			}
		}

	
	if (allValid) {
		
		month=obid.value.substring(0,2);
		day=obid.value.substring(3,5);
		year=obid.value.substring(6,10);

		var newdate = new Date(month,day,year);

		var t = Date.parse(serverdate)

		var currentdate = new Date(t);
		
		var currentyear=currentdate.getFullYear();
		var currentmonth=currentdate.getMonth();
		var currentday=currentdate.getDate();
   	
		//alert('MM/DD/YYYY = '+month+'/'+day+'/'+year+'\n\nCurrentdate='+currentmonth+'/'+currentday+'/'+currentyear+'\n\n'+currentdate);
		
		if (year < 1900) msg=msg+"Invalid Year: Must be greater than 1899.\n";
		if (year > currentyear) msg=msg+"Invalid Year: Cannot be greater than "+currentyear+".\n";
		
		if (day < 1 || day > 31) msg=msg+'Invalid Day: Must be between 1 and 31\n';
		if (month < 1 || month > 12) msg=msg+'Invalid Month: Must between 1 and 12\n';

		if (year == currentyear) {
			if (month > currentmonth+1)
				msg=msg+'Invalid Month: Cannot be greater than current month\n';

			if (month == currentmonth+1 && day > currentday) msg=msg+'Invalid Day: Cannot be greater than current day\n';
		}

	}
		
	if (msg !="") allValid=false;

	if (!allValid)
			{
		  	if (msg!="")
		  		alert (msg+"\nPlease enter a valid date in the form: MM/DD/YYYY");
		  			
			//obid.select();
			obidfail.focus();
			return(false);
			}


	if (formid != "NewDOB")  {
		return(true);
	}

	if (allValid) {
		if (obid.value.length>0 && (document.Personalform.frmname.value=="employee" || document.Personalform.frmname.value=="dependent"))
			{
			//msg="Changing the Date of Birth (DOB) MAY affect your benefits enrollment.\nYour enrollment will be considered as pending until\napproval of this change by HR.\n\nClick OK if you want to change your date of birth.";
			
			//if (confirm(msg)) {
				//document.Personalform.BirthState.focus();
				return(true);
				//}
			//else {
				//obid.value="";
				
				//obidfail.value="";
				//obidfail2.value="";
				//obidfail3.value="";
				
				//obidfail.focus();
				//return(false);
			//}
		
	} // allValid


	} // if allValid
	}
}






function hight(formid){
	var obid=eval("document.Personalform." + formid);
		{
	if (obid.value.length>0){
		if (isNaN(obid.value) || obid.value>12 || obid.value<0)
			{
			alert ("Please enter a number less than 13 in the \"Height - Inches\" field.");
			//obid.select();
			obid.focus();
			return(false);
			}
		}	
	return (true);
	}
}





function hightF(formid){
	var obid=eval("document.Personalform." + formid);
		{
	if (obid.value.length>0){
		if (isNaN(obid.value) || obid.value>9 || obid.value<0)
			{
			alert ("Please enter a number between 1 and 9 in the \"Height - Feet\" field.");
			//obid.select();
			obid.focus();
			return(false);
			}
		}	
	}
}





function wght(formid){
	var obid=eval("document.Personalform." + formid);
		{
	if (obid.value.length>0){
		if (isNaN(obid.value))
			{
			alert ("Please enter a number in the Weight field.");
			//obid.select();
			obid.focus();
			return(false);
			}
			else
			{
			if (obid.value==0 || obid.value<0)
				{
				alert ("The Weight field must not contain zero or a negative value.");
				//obid.select();
				obid.focus();
				//return(false);
				}
			}
		}	
	}
}





//------------------ function to warn users of changes to sensitive information ------------------------

function warnuser(formid,nextfid,mess){
	var obid=eval("document.Personalform." + formid);
	var nextobid=eval("document.Personalform." + nextfid);

	if (confirm(mess))
	{
	//	nextobid.select();
		nextobid.focus();

	}
	else {
		obid.value="";
		//obid.select();
		obid.focus();	
		}
}


		function showbla(bla) {
			//document.writeln ('bla='+bla);
			var nmst=bla;
		}

//------------------- function which changes FAMILY STATUS based on MARITAL STATUS ------
//------------------- & number of dependents & existence of spouse

    function updmaritalstatus(selidx,formid,chgformid,chgformidtxt) {

	var obid=eval("document.Personalform." + formid);
	var chgobid=eval("document.Personalform." + chgformid);

	var chgobidtxt=eval("document.Personalform.NewMaritalStatustext");

	{


	// check 1st to see if Family status is not length of zero
	
	if (obid.value=="" && document.Personalform.frmname.value=="addemployee") { 
		alert('Family Status is a required field.');
		
		//obid.focus();
		
		return(false);
		}

		
	if (selidx ==1 || selidx ==2 || selidx ==3)
		{
		chgobidtxt.value="Single";
		chgobid.value="S";
		}
	if (selidx ==4 || selidx==5)
		{
		chgobidtxt.value="Married";
		chgobid.value="M";
		}
	if (selidx==0 || selidx=="")
		{
		chgobidtxt.value="";
		chgobid.value="";
		}
	return (true);
	}
}

// FUNCTIONS NOT USED IN MARCH 2001 VERSION
// FUNCTIONS USED IN EMPLOYEE.ASP & DEPENDENT.ASP & ADDDEPENDENT.ASP
// to show/hide forms elements to simulate a wizard using one form
function showemployeename () {

	hideDS(Addsp,addbar,'B');
	hideDS(PIsp,pibar,'B');
	hideDS(DepStat,statbar,'Y');
	showDS(Depdd,depddbar,'B');
}

function showhomeaddress () {

	showDS(Addsp,addbar,'B');
	hideDS(PIsp,pibar,'B');
	hideDS(DepStat,statbar,'Y');
	hideDS(Depdd,depddbar,'B');
}

function showmailingaddress () {

	hideDS(Addsp,addbar,'B');
	showDS(PIsp,pibar,'B');
	hideDS(DepStat,statbar,'Y');
	hideDS(Depdd,depddbar,'B');
}

function showpersonalinformation () {

	hideDS(Addsp,addbar,'B');
	hideDS(PIsp,pibar,'B');
	showDS(DepStat,statbar,'Y');
	hideDS(Depdd,depddbar,'B');
}


// FUNCTIONS NOT USED IN MARCH 2001 VERSION
// functions used in ADDEMPLOYEE.ASP
// to show/hide forms elements to simulate a wizard using one form
// page parameter is used to specify which page/frame/slide to show
// exmaple: page=1 is the Empinfo <div> tag in addemployee.asp.

function showframe (page) {

	// first, hide all elements
	hideAE(empinfo); hideAE(homea); hideAE(worka); hideAE(persinfo);
	hideAE(EmpStat); hideAE(Comp);
	
	switch (page) {
		case 1:
			showAE(empinfo);
			break
		
		case 2:
			showAE(homea);
			break
		
		case 3:
			showAE(worka);
			break
		
		case 4:
			showAE(persinfo);
			break
		
		case 5:
			showAE(EmpStat);
			break
		
		case 6:
			showAE(Comp);
			break

	} //switch
} //func showframe



function nosubmit() {
	if (document.layers) document.captureEvents(Event.KEYPRESS); 
    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;
    
//    window.status = 'keyval=' + Key;

//		if (window.event.ctrlKey) {
			if (window.event.keyCode == 13) {
				alert('! CR');
				return false;
			}
//		}
}	// nosubmit


function copyaddress() {
    // change values
	
	var address=document.addeditresource.address.value;
	var city=document.addeditresource.city.value;
	var zip=document.addeditresource.zip.value;
	
	//original values are in variables set in employee.asp
	

	if (address.length==0){document.addeditresource.mailingaddress.value=h_address;}
	else {document.addeditresource.mailingaddress.value=address;}
	
	if (city.length==0){document.addeditresource.mailingcity.value=h_city;}
	else {document.addeditresource.mailingcity.value=city;}
	

	if (zip.length==0){document.addeditresource.mailingzip.value=h_zip;}
	else {document.addeditresource.mailingzip.value=zip;}


	return false;
	
} //copyaddress

function copy4map() {
    // change values
	
	var address=document.addeditresource.address.value;
	var city=document.addeditresource.city.value;

	
	//original values are in variables set in calling page
	

	if (address.length==0){document.addeditresource.mapaddress.value=h_address;}
	else {document.addeditresource.mapaddress.value=address;}
	
	if (city.length==0){document.addeditresource.mapcity.value=h_city;}
	else {document.addeditresource.mapcity.value=city;}
	

	return false;
	
} //copyaddress

function y2k(number) {
	return (number < 1000) ? number + 1900 : number;
}

function isValidDate (myDate,sep) {

	var reason = "";

{

// checks if date passed is in valid dd/mm/yyyy format

    if (myDate.length == 10) {
        if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {
            var date  = myDate.substring(0,2);
            var month = myDate.substring(3,5);
            var year  = myDate.substring(6,10);

            var test = new Date(year,month-1,date);

            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
                reason = '';
                return true;
            }
            else {
                reason = 'valid format but an invalid date';
                return false;
            } // if year==y2k

        } // if mydate.substring - if
        
                
        else {
            reason = 'invalid spearators';
            return false;
        } // if mydate.substring - else
        
    }
    else {
        reason = 'invalid length';
        return false;
    } // if mydate.length
    
}
} // function isvalidDate



function tellMeIfInvalid(myDate) {
    if (isValidDate(myDate,'/')) {
		alert(myDate + ' = valid date<BR>');
		return true;
		}
    else {
        alert(myDate + ' = ' + reason + '<BR>');
        return false;
        }
} // function tellme




// ----------------- getnumbers(str) --------------------
// Returns only numbers in the string passed in, strips everything else
function getnumbers(str) {

var checkOK = "0123456789";
  var checkStr = "";
  
  for (i = 0;  i < str.length;  i++)
  {
    ch = str.charAt(i);
    for (j = 0;  j < 10;  j++)
      if (ch == checkOK.charAt(j))
        checkStr=checkStr+ch
   }

	return (checkStr);

} // func getnumbers



// --------------- format SSN --------------------------
function formatSSN (ssn,formid) {

	if (ssn.length==0)
		return "";
		
	var checkSSN=getnumbers(ssn);
	if (checkSSN.length < 9 || checkSSN.length > 9)
		allValid=false;
	else
		allValid=true;

	var obid=eval("document.Personalform." + formid);

	if (!allValid)
		{
		alert('SSN is invalid!\n\nPlease re-enter the SSN before submitting the form.\n\nSocial Security Number (SSN) requires 9 numbers.');
		obid.focus();
		}

	checkSSN=checkSSN.substring(0,3)+"-"+checkSSN.substring(3,5)+"-"+checkSSN.substring(5,9);
	return checkSSN;		 

} //func formatSSN

// --------------- format Phone ------------------------
function formatPhone (phone) {

	if (phone.length==0)
		return "";

	var checkphone=getnumbers(phone);

	if (checkphone.length != 0)
		if (checkphone.length < 10 || checkphone.length > 10)
			alert('Telephone Numbers must be 10 numbers in length,\nincluding the Area Code.\n\nExample: 206-555-1212');
//	else

	checkphone="("+checkphone.substring(0,3)+") "+checkphone.substring(3,6)+"-"+checkphone.substring(6,10);
	return checkphone;		 

} //func formatPhone


// --------------- format Date --------------------------
function formatDate (date,warn,formid) {

	if (warn=="")
		warn=false;
		
	if (date.length==0)
		return "";

	// check to see if anything but numbers are in date string
	var checkOK = "0123456789";
	var numsonly=true;
	var isnumber;

	for (i = 0;  i < date.length;  i++)
	{
	  ch = date.charAt(i);
	  isnumber=false;
	  for (j = 0;  j < 10;  j++)
	    if (ch == checkOK.charAt(j))
	      {isnumber=true; break;}
	      
	if (!isnumber)
		{numsonly=false; break;}
	 } //for i=0
	
	if (!numsonly) // check for proper date structure: 00/00/0000
	{
	  var checkOK = "0123456789";
	  var checkStr = "";
	  var count=0;
	  var addchar="";
	  var eop=false;
	  
	  for (i = 0;  i < date.length;  i++)
	  {
	    ch = date.charAt(i);
	    isnumber=false;
	    
	    for (j = 0;  j < 11;  j++)
	      if (ch == checkOK.charAt(j))
	        {isnumber=true;break;}
		
		if (isnumber) // number found, add it to addchar
			{addchar=addchar+ch;count++;}
		  else // no number found, must be separator, precede it with a zero
			if (count==1)
				{addchar="0"+addchar;eop=true;}
			else
				if (count > 1)
					{eop=true;}

		//alert('addchar='+addchar+'\n\ncount='+count+'\n\neop='+eop+'\n\ncheckStr.length='+checkStr.length);
		
		if (eop || count==4) // if end of part, add it to checkStr
			{checkStr=checkStr+addchar; addchar=""; eop=false; count=0;}
		
		//alert('checkStr='+checkStr);
	   } // for
	 var checkdate=checkStr;
	  //alert('checkdate='+checkdate);
	 } 
	 else
	 var checkdate=date;
	// !numsonly

	 
	// if other characters exist, make all months, days contain two digits
	// example: month of 1 (jan.) should read 01   i.e. 01/22/1980	not 1/22/1980
	
	if (checkdate.length < 8)
		allValid=false;
	else
		allValid=true;

	if (!allValid && warn)
		{
		alert('Date is invalid!\n\nPlease re-enter the Date before submitting the form.\n\nDate fields MUST be in the format: MM/DD/YYYY');
		//var obid=eval("document.Personalform." + formid);
		this.focus();
		}

	checkdate=checkdate.substring(0,2)+"/"+checkdate.substring(2,4)+"/"+checkdate.substring(4,8);
		
	return checkdate;
	//	return date;
	
} //func formatDate



// -------------------- dblockedAlert(theForm) --------------------
// warns user if the db has been locked

function dblockedAlert(theForm) {
	if (theForm.dblocked.value == "True")
		alert(" *** Database is Locked ***\n\nAny changes you request here will not be recorded\nuntil the database is unlocked by the Administrator.\n\nPlease contact your Administrator for more information.");

} // func dblockedAlert
