// start roll over functions
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];}
}
//end roll over functions

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function verifyDelete(someURL){
 var where_to= confirm("Are you sure you want to delete this?");
 if (where_to== true)
 {
   window.location=someURL;
 }
 else
 {
  }
}

function validateLoanApplication(theForm)
{
	var selIndex;
	var selValue;
	
	if (theForm.fullName.value == "")
	{
		alert("Please enter your name.");
		theForm.fullName.focus();
		return (false);
	}
	if (theForm.address.value == "")
	{
		alert("Please enter your address.");
		theForm.address.focus();
		return (false);
	}
	if (theForm.city.value == "")
	{
		alert("Please enter your city.");
		theForm.city.focus();
		return (false);
	}
	if (theForm.county.value == "")
	{
		alert("Please enter your county.");
		theForm.county.focus();
		return (false);
	}
	if (theForm.stateCode.value == "")
	{
		alert("Please enter your state.");
		theForm.stateCode.focus();
		return (false);
	}
	if (theForm.zipCode.value == "")
	{
		alert("Please enter your zip code.");
		theForm.zipCode.focus();
		return (false);
	}
	if (theForm.homePhone.value == "")
	{
		alert("Please enter your home phone.");
		theForm.homePhone.focus();
		return (false);
	}
	if (theForm.email.value == "")
	{
		alert("Please enter your email address.");
		theForm.email.focus();
		return (false);
	}
	/*
	if (theForm.driversLicense.value == "")
	{
		alert("Please enter your driver\'s license number.");
		theForm.driversLicense.focus();
		return (false);
	}
	*/
	if (theForm.driversLicense.length < 14 && theForm.driversLicense.length >= 1)
	{
		alert("Your drivers license number must contain at least 14 characters.");
		theForm.driversLicense.focus();
		return (false);
	}
	if (theForm.livedYears.value == "")
	{
		alert("Please enter the number of years at current address.");
		theForm.livedYears.focus();
		return (false);
	}
	if (theForm.livedMonths.value == "")
	{
		alert("Please enter the number of months at current address.");
		theForm.livedMonths.focus();
		return (false);
	}
	if (theForm.previousYears.value == "")
	{
		alert("Please enter the number of years at previous address.");
		theForm.previousYears.focus();
		return (false);
	}
	if (theForm.previousMonths.value == "")
	{
		alert("Please enter the number of months at previous address.");
		theForm.previousMonths.focus();
		return (false);
	}
	
	//currentAddressOwnership
	if (theForm.currentAddressOwnership[0].checked == false && theForm.currentAddressOwnership[1].checked == false && theForm.currentAddressOwnership[2].checked == false)
	{
		alert("Please select your current residency ownership level. ");
		theForm.currentAddressOwnership[0].focus();
		return (false);
	}
	
	//hearFromUs
	selIndex = theForm.hearFromUs.selectedIndex;
	selValue = theForm.hearFromUs.options[selIndex].value;
	if (selValue == "") 
	{
		alert("Please select how you heard of us.");
		theForm.hearFromUs.focus();
		return (false);
	}		
	
	if (theForm.birthDate.value == "")
	{
		alert("Please enter your birth date.");
		theForm.birthDate.focus();
		return (false);
	}
	
	//maritalStatus
	if (theForm.maritalStatus[0].checked == false && theForm.maritalStatus[1].checked == false)
	{
		alert("Please select your marital status. ");
		theForm.maritalStatus[0].focus();
		return (false);
	}
	
	if (theForm.ssn.value == "")
	{
		alert("Please enter your social security number.");
		theForm.ssn.focus();
		return (false);
	}
	
	//validate SSN
	if (!validSSN(theForm.ssn.value)){
		alert("Please enter a valid social security number - XXX-XX-XXXX.");
		theForm.ssn.focus();
		return (false);			
	}
	
	if (theForm.employer.value == "")
	{
		alert("Please enter the name of your employer.");
		theForm.employer.focus();
		return (false);
	}
	if (theForm.employerPhone.value == "")
	{
		alert("Please enter the name of your employer.");
		theForm.employerPhone.focus();
		return (false);
	}
	if (theForm.employerHireDate.value == "")
	{
		alert("Please enter the date of your hire.");
		theForm.employerHireDate.focus();
		return (false);
	}
	if (theForm.employerWorkShift.value == "")
	{
		alert("Please enter your work shift.");
		theForm.employerWorkShift.focus();
		return (false);
	}
	if (theForm.employerNextPayDate.value == "")
	{
		alert("Please enter your next payroll date.");
		theForm.employerNextPayDate.focus();
		return (false);
	}
	if (theForm.employerLastPayDate.value == "")
	{
		alert("Please enter your last payroll date.");
		theForm.employerLastPayDate.focus();
		return (false);
	}
	if (theForm.employerSupervisor.value == "")
	{
		alert("Please enter your supervisor's name.");
		theForm.employerSupervisor.focus();
		return (false);
	}
	
	if (theForm.employerSupervisorPhone.value == "")
	{
		alert("Please enter your supervisor's phone number.");
		theForm.employerSupervisorPhone.focus();
		return (false);
	}
	
	if (theForm.employerJobTitle.value == "")
	{
		alert("Please enter your job title.");
		theForm.employerJobTitle.focus();
		return (false);
	}
	
	//employerWagesGarnished
	if (theForm.employerWagesGarnished[0].checked == false && theForm.employerWagesGarnished[1].checked == false)
	{
		alert("Please select Yes or No to indicate if you currently have wages garnished. ");
		theForm.employerWagesGarnished[0].focus();
		return (false);
	}
	
	if (theForm.employerGrossSalary.value == "")
	{
		alert("Please enter your gross salary.");
		theForm.employerGrossSalary.focus();
		return (false);
	}
	
	//employerPayrollFrequency
	selIndex = theForm.employerPayrollFrequency.selectedIndex;
	selValue = theForm.employerPayrollFrequency.options[selIndex].value;
	if (selValue == "") 
	{
		alert("Please select your payroll frequency.");
		theForm.employerPayrollFrequency.focus();
		return (false);
	}	
	
	
	//employerEmployment
	if (theForm.employerEmployment[0].checked == false && theForm.employerEmployment[1].checked == false)
	{
		alert("Please select if you are employed Full Time or Part Time. ");
		theForm.employerEmployment[0].focus();
		return (false);
	}
	
	//employerDirectDeposit
	if (theForm.employerDirectDeposit[0].checked == false && theForm.employerDirectDeposit[1].checked == false && theForm.employerDirectDeposit[2].checked == false && theForm.employerDirectDeposit[3].checked == false)
	{
		alert("Please select a direct deposit choice. ");
		theForm.employerDirectDeposit[0].focus();
		return (false);
	}
	
	if (theForm.financialInstitutionName.value == "")
	{
		alert("Please enter your financial institution's name.");
		theForm.financialInstitutionName.focus();
		return (false);
	}
	if (theForm.financialRoutingNumber.value == "")
	{
		alert("Please enter your routing number.");
		theForm.financialRoutingNumber.focus();
		return (false);
	}
	if (theForm.financialAccountNumber.value == "")
	{
		alert("Please enter your account number.");
		theForm.financialAccountNumber.focus();
		return (false);
	}
	if (theForm.financialNumCheckingTrans.value == "")
	{
		alert("Please enter the number of checking transactions you have per month.");
		theForm.financialNumCheckingTrans.focus();
		return (false);
	}
	if (theForm.financialEndingCheckingBalance.value == "")
	{
		alert("Please enter your ending checking account balance.");
		theForm.financialEndingCheckingBalance.focus();
		return (false);
	}
	if (theForm.financialNumMonthlyOverdrafts.value == "")
	{
		alert("Please enter the number of monthly overdrafts.");
		theForm.financialNumMonthlyOverdrafts.focus();
		return (false);
	}
	if (theForm.financialLoanAmountRequested.value == "")
	{
		alert("Please enter the loan amount you are asking for.");
		theForm.financialLoanAmountRequested.focus();
		return (false);
	}
	
	//financialFileBankruptcy
	if (theForm.financialFileBankruptcy[0].checked == false && theForm.financialFileBankruptcy[1].checked == false)
	{
		alert("Please select if you have ever filed bankruptcy.");
		theForm.financialFileBankruptcy[0].focus();
		return (false);
	}
	
	//financialDischargeDate
	if (theForm.financialInBankruptcy[0].checked == true && theForm.financialDischargeDate.value == "")
	{
		alert("Please enter a discharge date.");
		theForm.financialDischargeDate.focus();
		return (false);
	}
	
	//financialInBankruptcy
	if (theForm.financialInBankruptcy[0].checked == false && theForm.financialInBankruptcy[1].checked == false)
	{
		alert("Please indicate if you are currently in bankruptcy.");
		theForm.financialInBankruptcy[0].focus();
		return (false);
	}
	
	
	if (theForm.referenceName.value == "")
	{
		alert("Please enter a reference name.");
		theForm.referenceName.focus();
		return (false);
	}
	if (theForm.referencePhone.value == "")
	{
		alert("Please enter a reference phone number.");
		theForm.referencePhone.focus();
		return (false);
	}
	if (theForm.referenceRelationship.value == "")
	{
		alert("Please enter your reference\'s relationship to you.");
		theForm.referenceRelationship.focus();
		return (false);
	}
	if (theForm.referenceAddress.value == "")
	{
		alert("Please enter your reference\'s street address.");
		theForm.referenceAddress.focus();
		return (false);
	}
	if (theForm.referenceCity.value == "")
	{
		alert("Please enter the city of your reference\'s mailing address.");
		theForm.referenceCity.focus();
		return (false);
	}
	if (theForm.referenceState.value == "")
	{
		alert("Please enter the two letter state abbreviation in your reference\'s mailing address.");
		theForm.referenceState.focus();
		return (false);
	}
	if (theForm.referenceZip.value == "")
	{
		alert("Please enter your the five digit ZIP code in your reference\'s mailing address.");
		theForm.referenceZip.focus();
		return (false);
	}
	
	//validate second reference	
	if (theForm.referenceName2.value == "")
	{
		alert("Please enter a reference name.");
		theForm.referenceName2.focus();
		return (false);
	}
	if (theForm.referencePhone2.value == "")
	{
		alert("Please enter a reference phone number.");
		theForm.referencePhone2.focus();
		return (false);
	}
	if (theForm.referenceRelationship2.value == "")
	{
		alert("Please enter your reference\'s relationship to you.");
		theForm.referenceRelationship2.focus();
		return (false);
	}
	if (theForm.referenceAddress2.value == "")
	{
		alert("Please enter your reference\'s street address.");
		theForm.referenceAddress2.focus();
		return (false);
	}
	if (theForm.referenceCity2.value == "")
	{
		alert("Please enter the city of your reference\'s mailing address.");
		theForm.referenceCity2.focus();
		return (false);
	}
	if (theForm.referenceState2.value == "")
	{
		alert("Please enter the two letter state abbreviation in your reference\'s mailing address.");
		theForm.referenceState2.focus();
		return (false);
	}
	if (theForm.referenceZip2.value == "")
	{
		alert("Please enter your the five digit ZIP code in your reference\'s mailing address.");
		theForm.referenceZip2.focus();
		return (false);
	}
	
}

function validSSN(ssn) {
	var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
	var numDashes = ssn.split('-').length - 1;
	if (matchArr == null || numDashes == 1) {
		//alert('Invalid SSN. Must be 9 digits or in the form NNN-NN-NNNN.');
		//msg = "does not appear to be valid";
		return false;
	}
	else 
		if (parseInt(matchArr[1],10)==0) {
			//alert("Invalid SSN: SSN's can't start with 000.");
			//msg = "does not appear to be valid";
			return false;
		}
		else {
			//msg = "appears to be valid";
			//alert(ssn + "\r\n\r\n" + msg + " Social Security Number.");
			return true;
	  	}
}

