function init()
	{
	var objDate  = new Date();
	var intMonth = objDate.getMonth();
	var intDay   = objDate.getDate();
	
	intDay = intDay - 1;
	document.frmApply.selAvailableMonth.selectedIndex = intMonth;
	showDays();
	document.frmApply.selAvailableDay.selectedIndex = intDay;
	
	document.frmApply.txtFirstName.focus();

	objForm = document.frmApply;
	}
		
function validate()
	{
  	objForm = document.frmApply;

  	var blnTF = true;
	
	var aryValue = new Array;
//  aryValue[n]  = (test)                                                                       ? true : false; //
	aryValue[0]  = (objForm.txtFirstName.value)                                                 ? true : false;
	aryValue[1]  = (objForm.txtLastName.value)                                                  ? true : false;
	aryValue[2]  = ((objForm.txtAddress1.value) || (objForm.txtAddress2.value))                 ? true : false;
	aryValue[3]  = (objForm.txtCity.value)                                                      ? true : false;
	aryValue[4]  = (objForm.selState.selectedIndex)                                             ? true : false;
	aryValue[5]  = (objForm.txtZip.value)                                                       ? true : false;
	aryValue[6]  = (validZip(0))                                                                ? true : false;
	aryValue[7]  = (objForm.txtPhone.value)                                                     ? true : false;
	aryValue[8]  = ((objForm.rdoOfAge[0].checked) || (objForm.rdoOfAge[1].checked))             ? true : false;
	aryValue[9]  = ((objForm.chkFullTime.checked) || (objForm.chkPartTime.checked))             ? true : false;

	aryValue[10]  = ((objForm.rdoPrevApplied[0].checked) || (objForm.rdoPrevApplied[1].checked)) ? true : false;
	aryValue[11] = (((objForm.rdoPrevApplied[0].checked)&&(objForm.txtWhenAndWhere.value != ""))||(objForm.rdoPrevApplied[1].checked)) ? true : false;

	aryValue[12] = (objForm.txtPosistionDesired.value)                                          ? true : false;
	aryValue[13] = true

	aryValue[14] = true
	aryValue[15] = true

	aryValue[16] = ((objForm.rdoCriminal[0].checked) || (objForm.rdoCriminal[1].checked)) ? true : false;
	aryValue[17] = (((objForm.rdoCriminal[0].checked)&&(objForm.txtCriminalExplain.value != ""))||(objForm.rdoCriminal[1].checked)) ? true : false;
	
	aryValue[18] = (objForm.txtSignature.value)     ? true : false;
	aryValue[19] = (objForm.txtSignatureDate.value) ? true : false;

	var aryLabel = new Array;
//  aryLabel[n]  = "String to be inserted into alert box message"; //
	aryLabel[0]  = "First Name";
	aryLabel[1]  = "Last Name";
	aryLabel[2]  = "Present Mailing Address";
	aryLabel[3]  = "City";
	aryLabel[4]  = "State";
	aryLabel[5]  = "Zip Code";
	aryLabel[6]  = "Zip Code";
	aryLabel[7]  = "Home Phone";
	aryLabel[8]  = "Are you at least 18 years of age?";
	aryLabel[9]  = "Do you wish to work";
	aryLabel[10]  = "Have you previously applied for employment with us?";
	aryLabel[11] = "If yes (you have previously applied), when and where?";
	aryLabel[12] = "Position Desired";
	aryLabel[13] = "If yes (you have previously been employed), when and where?";
	aryLabel[14] = "Are any of your relatives employed with [INSERT COMPANY NAME HERE]?";
	aryLabel[15] = "If yes (relatives are employed), where?";
	aryLabel[16] = "Have you ever been convicted of a criminal offense?";
	aryLabel[17] = "If yes (you have been convicted), explain";
	aryLabel[18] = "Name";
	aryLabel[19] = "Date Today";

	var aryField = new Array;
//  aryField[n]  = object that receives focus on a break in for loop //
	aryField[0]  = objForm.txtFirstName;
	aryField[1]  = objForm.txtLastName;
	aryField[2]  = objForm.txtAddress1;
	aryField[3]  = objForm.txtCity;
	aryField[4]  = objForm.selState;
	aryField[5]  = objForm.txtZip;
	aryField[6]  = objForm.txtZip;
	aryField[7]  = objForm.txtPhone;
	aryField[8]  = objForm.rdoOfAge[0];
	aryField[9]  = objForm.chkFullTime;
	aryField[10]  = objForm.rdoPrevApplied[0];
	aryField[11] = objForm.txtWhenAndWhere;
	aryField[12] = objForm.txtPosistionDesired;
	aryField[13] = ""
	aryField[14] = ""
	aryField[15] = ""
	aryField[16] = objForm.rdoCriminal[0];
	aryField[17] = objForm.txtCriminalExplain;
	aryField[18] = objForm.txtSignature;
	aryField[19] = objForm.txtSignatureDate;
	
	var aryAssoc = new Array;
	aryAssoc[0] = aryLabel;
	aryAssoc[1] = aryValue;
	aryAssoc[2] = aryField;
	
	//validate fields
	for(i=0; i<aryField.length; i++)
		{
		if(!aryAssoc[1][i])      //(aryValue[n] == true)
			{
			alert("Please fill in the field labeled \"" + aryAssoc[0][i]+ "\" before submitting this form.");
			blnTF = false;
			break;
			}
		}

	if(!blnTF)
		{
		aryAssoc[2][i].focus();
		return false;
		}

	//Check Days/Hours for Part Timers
	if(objForm.chkPartTime.checked)
		{
		if((!objForm.txtSunHrs.value) &&
		   (!objForm.txtMonHrs.value) &&
		   (!objForm.txtTueHrs.value) &&
		   (!objForm.txtWedHrs.value) &&
		   (!objForm.txtThuHrs.value) &&
		   (!objForm.txtFriHrs.value) &&
		   (!objForm.txtSatHrs.value))
			{
			alert('You have indicated that you are available to work part time hours.\n' +
			      'Please specify the hours that you would be available.');
			objForm.txtSunHrs.focus();
			return false;
			}
		}
	return true;
	}

function validZip(bln)
	{
  	objForm = document.frmApply;

	if(objForm.txtZip.value != "")
		{
		var valid = "0123456789"
		var ok = "yes";
		var temp;
		var field;
		field = objForm.txtZip.value
		for(var i=0; i < field.length; i++)
			{
			temp = "" + field.substring(i, i+1);
			if(valid.indexOf(temp) == "-1") ok = "no";
			}
		if(ok == "no")
			{
			if(bln)
				{
				alert("Invalid Zip code!  Only numbers are accepted!");
				objForm.txtZip.focus();
				objForm.txtZip.select();
				}
			return false;
			}
		if(field.length < 5)
			{
			if(bln)
				{
				alert("Zip Codes have 5 digits. Please enter your entire Zip Code.");
				objForm.txtZip.focus();
				objForm.txtZip.select();
				}
			return false;
			}
		return true;
		}
	}	
	
function validPhone(obj,bln)
	{
  	objForm = document.frmApply;

	var valid = "0123456789-";
	var strChar;
	var strMsg = "";
	if(bln)
		{
		strMsg = "\nNOTE:\n            This is not a required field.\n            You can leave this field blank, if you choose.";
		}
	for(var i=0; i < obj.value.length; i++)
		{
		strChar = "" + obj.value.substring(i, i+1);
		if(valid.indexOf(strChar) == "-1")
			{
			obj.value = obj.value.substr(0, i) + obj.value.substring(i+1, obj.value.length);
			i = i - 1;
			}
		}
	if(obj.value.length < 12)
		{
		if((obj.value.length > 4) && (obj.value.indexOf("-") != 3))
			{
			obj.value = obj.value.substr(0,3) + "-" + obj.value.substr(3,obj.value.length);
			}
		if(obj.value.length > 8)
			{
			var strEnd;
			strEnd = obj.value.substring(4,obj.value.length);
			if((strEnd.length > 4) && (strEnd.indexOf("-") != 3))
				{
				strEnd = strEnd.substr(0,3) + "-" + strEnd.substr(3,strEnd.length);
				obj.value = obj.value.substr(0,4) + strEnd;
				}
			}
		if(obj.value.length < 12)
			{
			alert('The phone number you have entered does not have enough digits.\nPlease enter the phone number as: ###-###-####' + strMsg);
			obj.focus();
			obj.select();
			return false;
			}
		}
	var re = /\d{3}-\d{3}-\d{4}\b/;
	if(!re.test(obj.value))
		{
		alert('The phone number you have entered appears to be in the wrong format.\nPlease enter the phone number as: ###-###-####' + strMsg);
		obj.focus();
		obj.select();
		return false;
		}
	return true;
	}
	
function validEmail(emailStr)
	{
  	objForm = document.frmApply;

	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)
	if(matchArray==null)
		{
		alert("Email address seems incorrect (check @ and .'s)\nNOTE:\n            This is not a required field.\n            You can leave this field blank, if you choose.")
		objForm.txtEmail.focus();
		objForm.txtEmail.select();
		return false
		}

	var user=matchArray[1]
	var domain=matchArray[2]
	if(user.match(userPat)==null)
		{
		alert("The username doesn't seem to be valid.\nNOTE:\n            This is not a required field.\n            You can leave this field blank, if you choose.")
		objForm.txtEmail.focus();
		objForm.txtEmail.select();
		return false
		}

	var IPArray=domain.match(ipDomainPat)
	if(IPArray!=null)
		{
		for(var i=1;i<=4;i++)
			{
			if(IPArray[i]>255)
				{
				alert("Destination IP address is invalid!\nNOTE:\n            This is not a required field.\n            You can leave this field blank, if you choose.")
				objForm.txtEmail.focus();
				objForm.txtEmail.select();
				return false
				}
			}
		return true
		}

	var domainArray=domain.match(domainPat)
	if(domainArray==null)
		{
		alert("The domain name doesn't seem to be valid.\nNOTE:\n            This is not a required field.\n            You can leave this field blank, if you choose.")
		objForm.txtEmail.focus();
		objForm.txtEmail.select();
		return false
		}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if(domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
		{
		alert("The address must end in a three-letter domain, or two letter country.\nNOTE:\n            This is not a required field.\n            You can leave this field blank, if you choose.")
		objForm.txtEmail.focus();
		objForm.txtEmail.select();
		return false
		}

	if(len<2)
		{
		alert("This address is missing a hostname!\nNOTE:\n            This is not a required field.\n            You can leave this field blank, if you choose.")
		objForm.txtEmail.focus();
		objForm.txtEmail.select();
		return false
		}

	return true;
	}



function showDays()
	{
	var objForm     = document.frmApply;
	var intMonth    = objForm.selAvailableMonth.options[objForm.selAvailableMonth.selectedIndex].value;
	var intYear     = objForm.selAvailableYear.options[objForm.selAvailableYear.selectedIndex].value;
	var blnLeapYear = false;
	
	if((intMonth==4) || (intMonth==6) || (intMonth==9) || (intMonth==11))
		{
		i=0;
		while(objForm.selAvailableDay.options.length>0)
			{
			objForm.selAvailableDay.options[i]=null;
			}
		for(i=1; i<31; i++)
			{
			if(i<10) d = "0"+i; else d = i;
			objForm.selAvailableDay.options[i-1]=new Option(d,d);
			}
		}
	else
	if(intMonth==2)
		{
		i=0;
		while(objForm.selAvailableDay.options.length>0)
			{
			objForm.selAvailableDay.options[i]=null;
			}

		if(((intYear % 4 == 0) && (intYear % 100 != 0)) || (intYear % 400 == 0))
			{
			for(i=1; i<30; i++)
				{
				if(i<10) d = "0"+i; else d=i;
				objForm.selAvailableDay.options[i-1]=new Option(d,d);
				}
			}
		else
			{
			for(i=1; i<29; i++)
				{
				if(i<10) d = "0"+i; else d=i;
				objForm.selAvailableDay.options[i-1]=new Option(d,d);
				}
			}
		}
	else
		{
		i=0;
		while(objForm.selAvailableDay.options.length>0)
			{
			objForm.selAvailableDay.options[i]=null;
			}
		for(i=1; i<32; i++)
			{
			if(i<10) d = "0"+i; else d = i;
			objForm.selAvailableDay.options[i-1]=new Option(d,d);
			}
		}
	objForm.selAvailableDay.options.selectedIndex=0;
	}
