function EmailCheck() {
//Test for Member
var missinginfo = "";
if (IsLengthBetween(document.form.txtEmail.value,-1,31) == false) {
        missinginfo += "\n     Maximum character Limit For Email Exceeded ";
        missinginfo += "\n     Please call 713-673-3333 to complete application ";
        alert (missinginfo);
	}
}

function IsValidLength(sTestVal, iLen) {
	sVal = sTestVal.toString();
	if (sVal.length < iLen) return false
	return true; 
}

var iCCounter = 0;
function xIsCurrency(sTestVal, sPolarity) {
	//if (sPolarity == 'false') bPolarity = false; else bPolarity = true;
	bPolarity = true;
	sVal = sTestVal.toString();
	if (sVal.length < 1) return !bPolarity;
	var ar = ""; var sChar = "";
	for(i = 0; i < sVal.length; i++) {
		iChar = sVal.charCodeAt(i);
		sChar += sVal.charAt(i) + "(" + iChar.toString() + "), ";
		iCCounter++;
		if (iChar < 46 && iChar > 57) {
			alert(iChar);
			return !sPolarity; 
		}
	}
		if (iCCounter <  5) {
			alert(iChar);
			return true;
		}
	return false;
}

function IsDate(sTestVal, sPolarity) {
	//document.form.txtDOB
	sVal = sTestVal.toString();
	if (sVal.length > 0) return true;
	return false; 	
}


function IsPhone(sTestVal, sPolarity) {
	if (sVal.length < 1) return false;
	return true;
}

function IsSSN(sTestVal, sPolarity) {
	if (sVal.length < 1) return false;
	return true;
}

function IsLengthBetween(sTestVal,iStart,iEnd) {
	var s1 = sTestVal.toString(); 
	if (s1.length > iStart && s1.length <= iEnd) return true;
	return false; 
}


function IsCurrency(sTestVal, sPolarity) {
	if (sPolarity == 'false') bPolarity = false; else bPolarity = true;
	//bPolarity = true;
	sVal = sTestVal.toString();
	if (sVal.length < 1) return !bPolarity;
	var ar = "";
	for(i = 0; i < sVal.length; i++) {
		iChar = sVal.charCodeAt(i);
		if (iChar != 63 ||  ( iChar < 46 || iChar > 57)) {
//			alert(iChar);
			return !bPolarity; 
		}
	}
	return bPolarity;
//	alert(ar);
// 46(.) , 48 - 57
}

function IsNumber(sTestVal, sPolarity) {
	//if (sPolarity == 'false') bPolarity = false; else bPolarity = true;
	bPolarity = true;
	sVal = sTestVal.toString();
	if (sVal.length < 1) return !bPolarity;
	var ar = "";
	for(i = 0; i < sVal.length; i++) {
		iChar = sVal.charCodeAt(i);
		if (iChar < 46 || iChar > 57) return !bPolarity; 
	}
	return bPolarity;
//	alert(ar);
// 46(.) , 48 - 57
}

function IsEmpty(sTestVal, sPolarity) {
	if (sPolarity == 'false') bPolarity = false; else bPolarity = true;
	sVal = sTestVal.toString();
	if (sVal.length < 1) return !bPolarity;
	return bPolarity;
}

function VerifyData(){
if (document.form.txtEmail.value != document.form.txtVerEmail.value)
         {      
                         document.form.txtVerEmail.value = "";  
                         document.form.txtEmail.value = "";              
             alert("Your email address does not match - please re-enter");
             document.form.txtEmail.focus();
                         document.form.txtEmail.select();
             
                return false;
                
                        }
                else
                    return true;
                    }
                    
function NotesCheck() {
//Test for Notes length
var missinginfo = "";   
if (IsLengthBetween(document.form.txtNotes.value,-1,100) == false) {
        missinginfo += "\n     Maximum character limit for Comments exceeded, ";
        missinginfo += "\n     only 100 will be accepted on this application. ";
        alert (missinginfo);
}
}

function VerifyZip(objFld){
        if (IsValidLength(objFld.value,5) == false) {
                alert("Zip Code must be 5 numbers")
        }else{
        if (IsNumber(objFld.value) == false) {
                alert("Zip Code must be numeric")
        }
        }
}

function checkAppType() {
        //Coapplicant Information
        if (document.form.optAppType[0].checked)// && document.form.txtCAccountNum.value != "")
        {
        alert("Please note: You have checked Individual AppType only!  All Co-Applicant fields will be ignored.")
        }
}


function CheckAddress() {
//Test for Member

        if (document.form.optAdd[0].checked) {
                if (IsEmpty(document.form.txtCAdd1.value,'false')) {
                        document.form.txtCAdd1.value = document.form.txtAdd1.value
                        document.form.txtCAdd2.value = document.form.txtAdd2.value
                        document.form.txtCCity.value = document.form.txtCity.value
                        document.form.txtCState.selectedIndex = document.form.txtState.selectedIndex
                        document.form.txtCZip.value = document.form.txtZip.value
                        document.form.txtCHPhone.value = document.form.txtHPhone.value
                        document.form.txtCTOAYr.value = document.form.txtTOAYr.value
                        //document.form.txtCTOAMth.value = document.form.txtTOAMth.value
                        if (document.form.optResStatus[0].checked) {
                                document.form.optCResStatus[0].checked = true
                        }
                        if (document.form.optResStatus[1].checked) {
                                document.form.optCResStatus[1].checked = true
                        }

                        if (document.form.optResStatus[2].checked) {
                                document.form.optCResStatus[2].checked = true
                        }

                        document.form.txtCHomePay.value = document.form.txtHomePay.value
                        document.form.txtCHomeValue.value = document.form.txtHomeValue.value
                        document.form.txtCHomeMortBal.value = document.form.txtHomeMortBal.value

                }


        }
}

function checkCOFields(){


}

function checkFields() {
var missinginfo = "";
var eDoc = document.forms("form"); if (!eDoc) return false;

//Required Fields use the IsEmpty Function with stop of false
if (IsNumber(document.form.txtMemberId.value) == false) {
missinginfo += "\n     *  Member Number must be numeric";
} 
if (IsEmpty(document.form.cmbLoanType[document.form.cmbLoanType.selectedIndex].text,'false')) {
missinginfo += "\n     *  Type Of Loan is missing";
}
if (IsEmpty(document.form.txtLoanAmt.value,'false')) {
missinginfo += "\n     *  Loan Amount is missing";
}
if (IsEmpty(document.form.txtFName.value,'false')) {
missinginfo += "\n     *  First Name is missing";
}
if (IsEmpty(document.form.txtLName.value, 'false')) {
missinginfo += "\n     *  Last Name is missing";
}
if (IsEmpty(document.form.txtDOB.value,'false')) {
missinginfo += "\n     *  Date Of Birth is missing";
}
if (IsEmpty(document.form.txtSSNum.value,'false')) {
missinginfo += "\n     *  Social Security Number is missing";
}
if (IsEmpty(document.form.txtDLNum.value,'false')) {
missinginfo += "\n     *  Drivers License Number is missing";
}
if (IsEmpty(document.form.cmbDLState[document.form.cmbDLState.selectedIndex].text,'false')) {
missinginfo += "\n     *  Drivers License State is missing";
}
if (IsEmpty(document.form.txtHPhone.value,'false')) {
missinginfo += "\n     *  Home Phone Number is missing";
}
if (IsEmpty(document.form.txtWPhone.value,'false')) {
missinginfo += "\n     *  Work Phone Number is missing";
}
if (IsEmpty(document.form.txtEmail.value,'false')) {
missinginfo += "\n     *  Email Address is missing";
}
if (IsEmpty(document.form.txtVerEmail.value,'false')) {
missinginfo += "\n     *  Verify Email Address is missing";
}
if (IsEmpty(document.form.txtAdd1.value,'false')) {
missinginfo += "\n     *  Address is missing";
}
if (IsEmpty(document.form.txtCity.value,'false')) {
missinginfo += "\n     *  City is missing";
}
if (IsEmpty(document.form.txtState[document.form.txtState.selectedIndex].text,'false')) {
missinginfo += "\n     *  State is missing";
}
if (IsEmpty(document.form.txtZip.value,'false')) {
missinginfo += "\n     *  Zip is missing";
}
if (IsValidLength(document.form.txtZip.value,5) == false) {
missinginfo += "\n     *  Zip Code must be 5 numbers";
}


if (IsEmpty(document.form.txtTOAYr.value,'false')) {
        //if (IsEmpty(document.form.txtTOAMth.value,'false')) {
                missinginfo += "\n     *  Time At Address is missing";
        //}
}


if (IsEmpty(document.form.txtEmployer.value,'false')) {
missinginfo += "\n     *  Employer is missing";
}

if (IsEmpty(document.form.txtTOJYr.value,'false')) {
        //if (IsEmpty(document.form.txtTOJMth.value,'false')) {
                missinginfo += "\n     *  Time On Job is missing";
        //}
}

if (IsEmpty(document.form.txtIncome1.value,'false')) {
missinginfo += "\n     *  Gross Monthly Income is missing";
}

//Test Currency Fields
if (IsCurrency(document.form.txtLoanAmt,'false') == false) {
missinginfo += "\n     *  Desired Loan Amount must be numeric";
}
if (IsCurrency(document.form.txtIncome1,'false') == false) {
missinginfo += "\n     *  Gross Income must be numeric";
}
if (IsCurrency(document.form.txtOthInc1,'false') == false) {
missinginfo += "\n     *  Other Income must be numeric";
}
if (IsCurrency(document.form.txtHomePay,'false') == false) {
missinginfo += "\n     *  Housing Cost must be numeric";
}
if (IsCurrency(document.form.txtHomeMortBal,'false') == false) {
missinginfo += "\n     *  Mortgage Balance must be numeric";
}
if (IsCurrency(document.form.txtHomeValue,'false') == false) {
missinginfo += "\n     *  Housing Value must be numeric";
}
if (IsCurrency(document.form.txtCarPay,'false') == false) {
missinginfo += "\n     *  Car Payment must be numeric";
}
if (IsCurrency(document.form.txtAlmPay,'false') == false) {
missinginfo += "\n     *  Alimony Payment must be numeric";
}
if (IsCurrency(document.form.txtOtherPay,'false') == false) {
missinginfo += "\n     *  Other Payments must be numeric";
}
if (IsCurrency(document.form.txtPurPrice,'false') == false) {
missinginfo += "\n     *  Purchase Price must be numeric";
}
if (IsCurrency(document.form.txtDownPay,'false') == false) {
missinginfo += "\n     *  Down Payment must be numeric";
}
if (IsCurrency(document.form.txtTradeIn,'false') == false) {
missinginfo += "\n     *  Current Payment must be numeric";
}

//Test Number Fields

if (IsNumber(document.form.txtTOAYr.value) == false) {
missinginfo += "\n     *  Time At Address Years must be numeric";
}
//if (IsNumber(document.form.txtTOAMth.value) == false) {
//missinginfo += "\n     *  Time At Address Months must be numeric";
//}

if (IsNumber(document.form.txtTOJYr.value) == false) {
missinginfo += "\n     *  Time On Job (Years) must be numeric";
}
//if (IsNumber(document.form.txtTOJMth.value) == false) {
//missinginfo += "\n     *  Time On Job (Months) must be numeric";
//}
if (IsNumber(document.form.txtPTOJYr.value) == false) {
missinginfo += "\n     *  Time On Previous Job (Years) must be numeric";
}
//if (IsNumber(document.form.txtPTOJMth.value) == false) {
//missinginfo += "\n     *  Time On Previous Job (Months) must be numeric";
//}
//if (IsNumber(document.form.txtYear.value) == false) {
//missinginfo += "\n     *  Year Of Vehicle must be numeric";
//}
//Test Dates
if (IsDate(document.form.txtDOB,'false') == false) {
missinginfo += "\n     *  Date Of Birth must be formatted exp.04/23/1961";
}
//Test Phone Numbers
if (IsPhone(document.form.txtHPhone,'false') == false) {
missinginfo += "\n     *  Home Phone must be formatted exp.444-444-4444 ";
}
if (IsPhone(document.form.txtWPhone,'false') == false) {
missinginfo += "\n     *  Work Phone must be formatted exp.444-444-4444 ";
}


//Test Social Security Numbers
if (IsSSN(document.form.txtSSNum,'false') == false) {
missinginfo += "\n     *  Social Security Number must be formatted exp.999-99-9999";
}


if (IsLengthBetween(document.form.txtEmail.value,-1,31) == false) {
        missinginfo += "\n     *  Maximum character Limit For Email Exceeded ";
        missinginfo += "\n        Please call 713-673-3333 to complete application ";
}




if (IsEmpty(document.form.txtReqRef1.value,'false')) {
missinginfo += "\n     *  1st Reference is missing";
}
if (IsEmpty(document.form.txtReqRefAdd1.value,'false')) {
missinginfo += "\n     *  1st Reference Address is missing";
}
if (IsEmpty(document.form.txtReqRefPhone1.value,'false')) {
missinginfo += "\n     *  1st Reference Phone is missing";
}

if (IsEmpty(document.form.txtReqRef2.value,'false')) {
missinginfo += "\n     *  2nd Reference is missing";
}
if (IsEmpty(document.form.txtReqRefAdd2.value,'false')) {
missinginfo += "\n     *  2nd Reference Address is missing";
}
if (IsEmpty(document.form.txtReqRefPhone2.value,'false')) {
missinginfo += "\n     *  2nd Reference Phone is missing";
}



if (document.form.optAppType[1].checked || document.form.optAppType[2].checked ){
//if (document.form.chkCoApplicant.checked == true) {


        if (IsEmpty(document.form.txtCFName.value,'false')) {
        missinginfo += "\n     *  Co-Applicant First Name is missing";
        }
        if (IsEmpty(document.form.txtCLName.value, 'false')) {
        missinginfo += "\n     *  Co-Applicant Last Name is missing";
        }
        if (IsEmpty(document.form.txtCDOB.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Date Of Birth is missing";
        }
        if (IsEmpty(document.form.txtCSSNum.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Social Security Number is missing";
        }
        if (IsEmpty(document.form.txtCDLNum.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Drivers License Number is missing";
        }
        if (IsEmpty(document.form.txtCDLState[document.form.txtCDLState.selectedIndex].text,'false')) {
        missinginfo += "\n     *  Co-Applicant Drivers License State is missing";
        }
        if (IsEmpty(document.form.txtCHPhone.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Home Phone Number is missing";
        }
        if (IsEmpty(document.form.txtCWPhone.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Work Phone Number is missing (If retired or homemaker, please enter home number)";
        }

        if (IsEmpty(document.form.txtCAdd1.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Address is missing";
        }
        if (IsEmpty(document.form.txtCCity.value,'false')) {
        missinginfo += "\n     *  Co-Applicant City is missing";
        }
        if (IsEmpty(document.form.txtCState[document.form.txtCState.selectedIndex].text,'false')) {
        missinginfo += "\n     *  Co-Applicant State is missing";
        }
        if (IsEmpty(document.form.txtCZip.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Zip is missing";
        }
        if (IsValidLength(document.form.txtCZip.value,5) == false) {
        missinginfo += "\n     *  Co-Applicant Zip Code must be 5 numbers";
        }

        if (IsEmpty(document.form.txtCTOAYr.value,'false')) {
                //if (IsEmpty(document.form.txtTOAMth.value,'false')) {
                        missinginfo += "\n     *  Co-Applicant Time At Address is missing";
                //}
        }

        if (IsEmpty(document.form.txtCHomePay.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Monthly Housing Cost is missing";
        }

        //Test For Home Owner Information
        if (document.form.optCResStatus[0].checked) {
                if (IsEmpty(document.form.txtCHomeMortBal.value,'false')) {
                missinginfo += "\n     *  Co-Applicant you must input your remaining Mortgage Balance (if your home is paid for, please enter $1)";
                }
                }
        if (document.form.optCResStatus[0].checked) {   
                if (IsEmpty(document.form.txtCHomeValue.value,'false')) {
                missinginfo += "\n     *  Co-Applicant you must input your Home Value";
                }
                }


        if (IsEmpty(document.form.txtCEmployer.value,'false')) {
        missinginfo += "\n     *  Co-Applicant Employer is missing";
        }
        if (IsEmpty(document.form.txtCTOJYr.value,'false')) {
                //if (IsEmpty(document.form.txtTOJMth.value,'false')) {
                        missinginfo += "\n     *  Co-Applicant Time On Job is missing";
                //}
        }
        //check co-signer info


        if (IsSSN(document.form.txtCSSNum,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Social Security Number must be formatted exp.999-99-9999";
        }
        if (IsPhone(document.form.txtCHPhone,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Home Phone must be formatted exp.444-444-4444 ";
        }
        if (IsPhone(document.form.txtCWPhone,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Work Phone must be formatted exp.444-444-4444 ";
        }
        if (IsDate(document.form.txtCDOB,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Date Of Birth must be formatted exp.02/12/1954";
        }
        if (IsNumber(document.form.txtCTOAYr.value) == false) {
        missinginfo += "\n     *  Co-Applicant Time At Address Years must be numeric";
        }
        //if (IsNumber(document.form.txtCTOAMth.value) == false) {
        //missinginfo += "\n     *  Co-Applicant Time At Address Months must be numeric";
        //}
        if (IsNumber(document.form.txtCTOJYr.value) == false) {
        missinginfo += "\n     *  Co-Applicant Time On Job (Years) must be numeric";
        }
        //if (IsNumber(document.form.txtCTOJMth.value) == false) {
        //missinginfo += "\n     *  Co-Applicant Time On Job (Months) must be numeric";
        //}
        if (IsNumber(document.form.txtCPTOJYr.value) == false) {
        missinginfo += "\n     *  Co-Applicant Time On Previous Job (Years) must be numeric";
        }
        //if (IsNumber(document.form.txtCPTOJMth.value) == false) {
        //missinginfo += "\n     *  Co-Applicant Time On Previous Job (Months) must be numeric";
        //}
        
        if (IsCurrency(document.form.txtCIncome1,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Gross Income must be numeric";
        }
        
        if (IsCurrency(document.form.txtCOthInc1,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Other Income must be numeric";
        }
        
        if (IsCurrency(document.form.txtCOtherPay,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Other Payments must be numeric";
        }
        if (IsCurrency(document.form.txtCHomePay,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Monthly Housing Cost must be numeric";
        }
        if (IsCurrency(document.form.txtCHomeMortBal,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Mortgage Balance must be numeric";
        }
        if (IsCurrency(document.form.txtCHomeValue,'false') == false) {
        missinginfo += "\n     *  Co-Applicant Housing Value must be numeric";
        }

}

//put loan type description
document.form.txtLoanTypeDesc.value = document.form.cmbLoanType[document.form.cmbLoanType.selectedIndex].text

if (missinginfo != "") {
missinginfo ="______________________________________________________\n" +
"The following are problems with your application:\n" +
missinginfo + "\n___________________________________________________" +
"\nPlease correct and submit again!";
alert(missinginfo);
return false;
	} else {
	alert('Verification Complete. Now Print out this Smartap and Fax it to us.');
	return true;
	}
}

function open_window(url) {
mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=450,height=450');
}


