 

function nexttab(thisone, maxlength, nextfieldname) 
{
  if ( thisone.value.length == maxlength ) 
  { 
   eval('document.' + thisone.form.name + '.' + nextfieldname + '.focus()'); 
  } 
}

if ( document.layers ) 
{ 
   document.captureEvents( Event.KEYUP ); 
   document.onkeyup = nexttab; 
}
 

function highlightTextField(field) {
		field.style.borderColor = '#99CC00';
		field.style.borderStyle = 'solid';
		field.style.borderWidth = '1px;';
}

function unHighlightTextField(field) {
		field.style.borderColor = '#FFFFFF';
		field.style.borderStyle = 'solid';
		field.style.borderWidth = '1px;';
}

function highlightSelectField(field) {
		field.style.backgroundColor = '#99CC00';
		field.style.color = 'black';
}

function validateMortgageApplication(form) {
	var ErrorMsg = '';
	var FirstErrorField = '';

	if(form.ContactFirstName.value == '') {
		ErrorMsg = ErrorMsg + '- First Name\n';
		highlightTextField(form.ContactFirstName);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactFirstName';
		}
	}


	if(form.ContactLastName.value == '') {
		ErrorMsg = ErrorMsg + '- Last Name\n';
		highlightTextField(form.ContactLastName);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactLastName';
		}
	}

	if(form.ContactAddress1.value == '') {
		ErrorMsg = ErrorMsg + '- Address\n';
		highlightTextField(form.ContactAddress1);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactAddress1';
		}
	}

	if(form.ContactCity.value == '') {
		ErrorMsg = ErrorMsg + '- City\n';
		highlightTextField(form.ContactCity);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactCity';
		}
	}

	if(form.ContactStateOrProvince.selectedIndex == 0) {
		ErrorMsg = ErrorMsg + '- State\n';
		//highlightSelectField(form.ContactStateOrProvince);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactStateOrProvince';
		}
	}

	if((form.ContactPostalCode.value.length != 5) || isNaN(form.ContactPostalCode.value)) {
		ErrorMsg = ErrorMsg + '- Zip Code\n';
		highlightTextField(form.ContactPostalCode);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactPostalCode';
		}
	}

	if(	((form.ContactHomePhoneNPA.value.length != 3) || isNaN(form.ContactHomePhoneNPA.value)) ||
		((form.ContactHomePhonePrefix.value.length != 3) || isNaN(form.ContactHomePhonePrefix.value)) ||
		((form.ContactHomePhoneSuffix.value.length != 4) || isNaN(form.ContactHomePhoneSuffix.value)) ) {
		ErrorMsg = ErrorMsg + '- Home Phone\n';
		if((form.ContactHomePhoneNPA.value.length != 3) || isNaN(form.ContactHomePhoneNPA.value)) {highlightTextField(form.ContactHomePhoneNPA);}
		if((form.ContactHomePhonePrefix.value.length != 3) || isNaN(form.ContactHomePhonePrefix.value)) {highlightTextField(form.ContactHomePhonePrefix);}
		if((form.ContactHomePhoneSuffix.value.length != 4) || isNaN(form.ContactHomePhoneSuffix.value)) {highlightTextField(form.ContactHomePhoneSuffix);}
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactHomePhoneNPA';
		}
	}

	if (	((form.ContactWorkPhoneNPA.value.length != 3) || isNaN(form.ContactWorkPhoneNPA.value)) ||
		((form.ContactWorkPhonePrefix.value.length != 3) || isNaN(form.ContactWorkPhonePrefix.value)) ||
		((form.ContactWorkPhoneSuffix.value.length != 4) || isNaN(form.ContactWorkPhoneSuffix.value)) ) {
		ErrorMsg = ErrorMsg + '- Work Phone\n';
		if((form.ContactWorkPhoneNPA.value.length != 3) || isNaN(form.ContactWorkPhoneNPA.value)) {highlightTextField(form.ContactWorkPhoneNPA);}
		if((form.ContactWorkPhonePrefix.value.length != 3) || isNaN(form.ContactWorkPhonePrefix.value)) {highlightTextField(form.ContactWorkPhonePrefix);}
		if((form.ContactWorkPhoneSuffix.value.length != 4) || isNaN(form.ContactWorkPhoneSuffix.value)) {highlightTextField(form.ContactWorkPhoneSuffix);}
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactWorkPhoneNPA';
		}
	}

	if(form.ContactEmail.value == '') {
		ErrorMsg = ErrorMsg + '- Email\n';
		highlightTextField(form.ContactEmail);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.ContactEmail';
		}
	}

	if(form.BestContactTimeID.selectedIndex == 0) {
		ErrorMsg = ErrorMsg + '- Best Contact Time\n';
		//highlightSelectField(form.BestContactTimeID);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.BestContactTimeID';
		}
	}

	if(form.CreditRatingID.selectedIndex == 0) {
		ErrorMsg = ErrorMsg + '- Credit Rating\n';
		//highlightSelectField(form.CreditRatingID);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.CreditRatingID';
		}
	}

	if(form.PropertyValue.selectedIndex == 117) {
		ErrorMsg = ErrorMsg + '- Home Value\n';
		//highlightSelectField(form.PropertyValue);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.PropertyValue';
		}
	}

	if(form.PropertyTypeID.selectedIndex == 0) {
		ErrorMsg = ErrorMsg + '- Type of House\n';
		//highlightSelectField(form.PropertyTypeID);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.PropertyTypeID';
		}
	}

	if(form.Mortgage1Balance.selectedIndex == 133) {
		ErrorMsg = ErrorMsg + '- 1st Mortgage Balance\n';
		//highlightSelectField(form.Mortgage1Balance);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.Mortgage1Balance';
		}
	}

	if(form.Mortgage1Rate.selectedIndex == 28) {
		ErrorMsg = ErrorMsg + '- Current Interest Rate\n';
		//highlightSelectField(form.Mortgage1Rate);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.Mortgage1Rate';
		}
	}

	if(form.RequestedLoanAmountMin.selectedIndex == 131) {
		ErrorMsg = ErrorMsg + '- Loan Amount Desired\n';
		//highlightSelectField(form.RequestedLoanAmountMin);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.RequestedLoanAmountMin';
		}
	}

	if(form.RequestedLoanPurposeID.selectedIndex == 0) {
		ErrorMsg = ErrorMsg + '- Loan Purpose\n';
		//highlightSelectField(form.RequestedLoanPurposeID);
		if(FirstErrorField == '') {
			FirstErrorField = 'form.RequestedLoanPurposeID';
		}
	}

	if(ErrorMsg != '') {
		eval(FirstErrorField + '.focus();');
		alert('Please complete ALL the following fields to continue:\n' + ErrorMsg);
		return false;
	} else {
		return true;
	}
}