function Initialize(szType) {
	var szForm = document.frmMain;
	SetFocus(document.frmMain.txtNameLast);
}

function SetFocus(szField) {
	szField.focus();
}

function CopyPresentToGuaran() {
	var szForm = document.frmMain

	szForm.txtGuaranAddress.value = szForm.txtPresentAddress.value;
	szForm.txtGuaranAddress2.value = szForm.txtPresentAddress2.value;
	szForm.txtGuaranCity.value = szForm.txtPresentCity.value;
	szForm.txtGuaranState.value = szForm.txtPresentState.value;
	szForm.txtGuaranZip.value = szForm.txtPresentZip.value;
	szForm.txtGuaranCountry.value = szForm.txtPresentCountry.value;
}

function VerifyInfo(waiverValidation) {
	var szForm = document.frmMain;

	if (CheckValueEntered(szForm.txtNameLast, 25, "Last Name", "Please enter the Last Name information.")==1)
		return false;

	if (CheckValueEntered(szForm.txtNameFirst, 25, "First Name", "Please enter the First Name information.")==1)
		return false;

	if (CheckValueEntered(szForm.txtPresentAddress, 50, "Present Street Address", "Please enter the Present Street Address information.")==1)
		return false;

	if (szForm.txtPresentAddress2.value!="") {
		if (CheckValueEntered(szForm.txtPresentAddress2, 50, "Present Street Address 2", "You must enter no more than 50 characters for Present Street Address 2.")==1)
			return false;
	}

	if (CheckValueEntered(szForm.txtPresentCity, 25, "Present City", "Please enter the Present City information.")==1)
		return false;

	if (CheckValueEntered(szForm.txtPresentState, 2, "Present State", "You must enter no more than 2 characters for Present State.")==1)
		return false;

	if (CheckValueEntered(szForm.txtPresentZip, 10, "Present Zipcode", "You must enter no more than 10 characters for Present Zipcode.")==1)
		return false;

	if (szForm.txtPresentCountry.value!="") {
		if (CheckValueEntered(szForm.txtPresentCountry, 25, "Present Country", "You must enter no more than 25 characters for Present Country.")==1)
			return false;
	}
	
//	if (CheckValueEntered(szForm.txtDriverLicense, 20, "Driver License", "Please enter your Driver License.")==1)
//		return false;
		
//	if (CheckValueEntered(szForm.txtDriverLicenseState, 2, "Driver License State", "Please enter your Driver License State.")==1)
//		return false;

	if (szForm.txtPhone.value!="") {
		if (CheckValueEntered(szForm.txtPhone, 20, "Telephone", "You must enter 1 through 20 characters for telephone.")==1)
			return false;
	}

	if (szForm.txtEmail.value!="") {
		if (CheckValueEntered(szForm.txtEmail, 255, "E-mail", "You must enter no more than 255 characters for E-mail.")==1)
			return false;
	}

	if (CheckValueDate(szForm.txtDOB, 10, "Date of Birth", "Please enter the Date of Birth information.", false)==1)
		return false;

//if (!waiverValidation) {
//	if (CheckValueEntered(szForm.txtSSN, 11, "SS #", "You must enter no more than 11 characters for SS #.")==1)
//		return false;
//}
		
	if (CheckValueEntered(szForm.txtPhone, 20, "Phone #", "You must enter your phone number.")==1)
		return false;
		
	if (CheckValueEntered(szForm.txtEmail, 255, "Email", "You must enter your e-mail address.")==1)
		return false;
	
	if (szForm.txtAppUniversity.value!="") {
		if (CheckValueEntered(szForm.txtAppUniversity, 40, "College or University", "You must enter your college or university choice.")==1)
			return false;
	}

	if (CheckValueEntered(szForm.txtGuaranNameLast, 25, "Guarantor Last Name", "Please enter the Guarantor Last Name information.")==1)
		return false;

	if (CheckValueEntered(szForm.txtGuaranNameFirst, 25, "Guarantor First Name", "Please enter the Guarantor First Name information.")==1)
		return false;

	if (CheckValueEntered(szForm.txtGuaranAddress, 50, "Guarantor Street Address", "Please enter the Guarantor Street Address information.")==1)
		return false;

	if (szForm.txtGuaranAddress2.value!="") {
		if (CheckValueEntered(szForm.txtGuaranAddress2, 50, "Guarantor Street Address 2", "You must enter no more than 50 characters for Guarantor Street Address 2.")==1)
			return false;
	}

	if (CheckValueEntered(szForm.txtGuaranCity, 25, "Guarantor City", "Please enter the Guarantor City information.")==1)
		return false;

	if (CheckValueEntered(szForm.txtGuaranState, 2, "Guarantor State", "You must enter no more than 2 characters for Guarantor State.")==1)
		return false;

	if (CheckValueEntered(szForm.txtGuaranZip, 10, "Guarantor Zipcode", "You must enter no more than 10 characters for Guarantor Zipcode.")==1)
		return false;

	if (szForm.txtGuaranCountry.value!="") {
		if (CheckValueEntered(szForm.txtGuaranCountry, 25, "Guarantor Country", "You must enter no more than 25 characters for Guarantor Country.")==1)
			return false;
	}

if (!waiverValidation) {
	if (CheckValueEntered(szForm.txtGuaranSSN, 11, "Guarantor SS #", "You must enter no more than 11 characters for Guarantor SS #.")==1)
		return false;
}

	if (CheckValueDate(szForm.txtGuaranDOB, 10, "Guarantor Date of Birth", "Please enter the Guarantor Date of Birth information.", true)==1)
		return false;

	if (CheckValueEntered(szForm.txtGuaranPhone, 20, "Guarantor Telephone", "You must enter no more than 20 characters for Guarantor Telephone.")==1)
		return false;

	if (CheckValueEntered(szForm.txtGuaranEmail, 255, "Guarantor E-mail", "You must enter no more than 255 characters for Guarantor E-mail.")==1)
		return false;

	if (CheckValueEntered(szForm.txtGuaranEmployer, 50, "Guarantor Employer", "Please enter the Guarantor\'s Employer.", true)==1)
		return false;
		
	if (CheckValueEntered(szForm.txtGuaranIncome, 6, "Guarantor Monthly Gross Income", "Please enter the Guarantor\'s Monthly Gross Income.", true)==1)
		return false;

if (!waiverValidation) {
	if (CheckValueEntered(szForm.txtChkBank, 35, "Bank (Checking)", "You must enter no more than 35 characters for Bank (Checking).")==1)
		return false;


	if (CheckValueEntered(szForm.txtChkAcct, 20, "Checking Acct. No.", "You must enter no more than 20 characters for Checking Acct. No.")==1)
		return false;

	if (CheckValueEntered(szForm.txtSavBank, 35, "Bank (Savings)", "You must enter no more than 35 characters for Bank (Savings).")==1)
		return false;

	if (CheckValueEntered(szForm.txtSavAcct, 20, "Savings Acct. No.", "You must enter no more than 20 characters for Savings Acct. No.")==1)
		return false;
}

	if (szForm.chkAgree.checked!=true) {
		window.alert("You must check \"I Agree\" to proceed.");
		szForm.chkAgree.focus();
		return false;
	}
	
	szForm.cmdSubmit.value = 'Processing...';
	szForm.cmdSubmit.disabled = true;
	szForm.cmdSubmit.readOnly = true;
	
	return true;
}


function CheckSelection(szField, szMessage) {
	if (szField.value=="None") {
		window.alert(szMessage);
		szField.focus();
		return(1);
	}
	else {
		return(0);
	}
}


function CheckValueEntered(szField, nMaxLength, szFieldName, szMessage) {
	var bConf;
	var szConfirmText;

	if (szField.value=="") {
		window.alert(szMessage);
		szField.focus();
		return(1);
	}
	else {
		if (szField.value.length > nMaxLength) {
			szConfirmText = "Field '" + szFieldName + "' must be truncated at " + nMaxLength + " characters.  Choose 'OK' to truncate.";
			bConf = confirm(szConfirmText);
			if (bConf) {
				szField.value = szField.value.substr(0, nMaxLength);
				return(0);
			}
			else {
				szField.focus();
				return(1);
			}
		}
		else {
			return(0);
		}
	}
}


function CheckValueNumeric(szField, nMaxLength, szFieldName, szMessage, bBlankAllowed) {
	var nTestNumber;
	var re;

	if (szField.value=="") {
		if (bBlankAllowed) {
			return(0);
		}
		else {
			window.alert(szMessage);
			szField.focus();
			return(1);
		}
	}
	
	re = "$";
	szField.value = szField.value.replace(re, "");
	re = /e/g;
	szField.value = szField.value.replace(re, "");
	re = /E/g;
	szField.value = szField.value.replace(re, "");
	re = /,/g;
	szField.value = szField.value.replace(re, "");
	nTestNumber = new Number(szField.value);
	if (isNaN(nTestNumber)) {
		window.alert(szMessage);
		szField.focus();
		return(1);
	}
	else {
		if (szField.value.length > nMaxLength) {
			szConfirmText = "Field '" + szFieldName + "' must be truncated at " + nMaxLength + " characters.  Choose 'OK' to truncate.";
			bConf = confirm(szConfirmText);
			if (bConf) {
				szField.value = szField.value.substr(0, nMaxLength);
				return(0);
			}
			else {
				szField.focus();
				return(1);
			}
		}
		else {
			return(0);
		}
	}
}


function CheckValueDate(szField, nMaxLength, szFieldName, szMessage, bBlankAllowed) {
	var dteTestDate = new Date(szField.value);
	var nTestNumber;
	var szWork;
	
	if (szField.value=="") {
		if (bBlankAllowed) {
			return(0);
		}
		else {
			window.alert(szMessage);
			szField.focus();
			return(1);
		}
	}

	if (szField.value.length > nMaxLength) {
		szConfirmText = "Field '" + szFieldName + "' must be truncated at " + nMaxLength + " characters.  Choose 'OK' to truncate.";
		bConf = confirm(szConfirmText);
		if (bConf) {
			szField.value = szField.value.substr(0, nMaxLength);
		}
		else {
			szField.focus();
			return(1);
		}
	}

	if (isNaN(dteTestDate)) {
		window.alert(szMessage);
		szField.focus();
		return(1);
	}
	else {
		nTestNumber = dteTestDate.getFullYear();
		//if (nTestNumber < 1990) {
		//	nTestNumber += 100;
		//	dteTestDate.setFullYear(nTestNumber);
		//}	
		szWork = (dteTestDate.getMonth() + 1) + "/" + dteTestDate.getDate() + "/" + dteTestDate.getFullYear();
		szField.value = szWork;
		return(0);
	}
}


function CheckRadioChecked(szField, szMessage) {
	var bChecked 
	
	bChecked = false;
	for (var i=0; i<szField.length; i++) {
		if (szField[i].checked)
			bChecked = true;
	}
	
	if (bChecked==false) {
		window.alert(szMessage);
		szField[0].focus();
		return(1);
	}
	else {
		return(0);
	}
}


function CheckValueTime(szField, nMaxLength, szFieldName, szMessage, bBlankAllowed) {
	var re;
	var szMatch;

	if (szField.value=="") {
		if (bBlankAllowed) {
			return(0);
		}
		else {
			window.alert(szMessage);
			szField.focus();
			return(1);
		}
	}

	if (szField.value.length > nMaxLength) {
		szConfirmText = "Field '" + szFieldName + "' must be truncated at " + nMaxLength + " characters.  Choose 'OK' to truncate.";
		bConf = confirm(szConfirmText);
		if (bConf) {
			szField.value = szField.value.substr(0, nMaxLength);
		}
		else {
			szField.focus();
			return(1);
		}
	}

	szField.value = trim(szField.value);

	re = new RegExp("^((([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[0-9]|1[0-9]|2[0-3])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?))$");
	szMatch = szField.value.match(re);
	if (szMatch==null) {
		window.alert(szMessage);
		szField.focus();
		return(1);
	}

	return(0);
}


// CheckValueWorkTime() - Validates that input in is the "HHH:MM" or "HHH" format (Hours must 
// contain at lease 1 digit).
//
function CheckValueWorkTime(szField, nMaxLength, szFieldName, szMessage, bBlankAllowed) {
	var re;
	var szMatch;

	if (szField.value=="") {
		if (bBlankAllowed) {
			return(0);
		}
		else {
			window.alert(szMessage);
			szField.focus();
			return(1);
		}
	}

	if (szField.value.length > nMaxLength) {
		szConfirmText = "Field '" + szFieldName + "' must be truncated at " + nMaxLength + " characters.  Choose 'OK' to truncate.";
		bConf = confirm(szConfirmText);
		if (bConf) {
			szField.value = szField.value.substr(0, nMaxLength);
		}
		else {
			szField.focus();
			return(1);
		}
	}

	szField.value = trim(szField.value);

	re = new RegExp("(^([0-9]|[0-9][0-9]|[0-9][0-9][0-9]):([0-5][0-9])$)|(^([0-9]|[0-9][0-9]|[0-9][0-9][0-9])$)");
	szMatch = szField.value.match(re);
	if (szMatch==null) {
		window.alert(szMessage);
		szField.focus();
		return(1);
	}

	return(0);
}


function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }

   var retValue = inputString;
   var ch = retValue.substring(0, 1);

   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }

   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }

   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }

   return retValue; // Return the trimmed string back to the user

} // Ends the "trim" function


// remove "$" and "," from Gross Income Gox
function filterNum(str)  {
	re = /^\$|,/g;
	document.frmMain.txtGuaranIncome.value = str.replace(re, "");
}