<!--
var r={
  'commas':/[^\d\,]/g,		//this only allows numbers and commas to be entered into input text	(for money values)
  'numbers':/[^\d]/g,		//this only allows numbers to be entered into input text (for interest rates)
  'dashes':/[^\d\-]/g}		//this only allows numbers and dashes to be entered into input text	for phone numbers and zips)
function valid(o,w){
  o.value = o.value.replace(r[w],''); 
  }

function validate_form() {
//set variables to values from the form
CC_DEBT_AMT = document.getElementById("CC_DEBT_AMT").value;
CC_DEBT_AMT = CC_DEBT_AMT.replace(/\,/g,"");	//get rid of commas input by the user
CC_DEBT_PYMT_AGING = document.getElementById("CC_DEBT_PYMT_AGING").value;
FNAME = document.getElementById("FNAME").value;
LNAME = document.getElementById("LNAME").value;
ADDRESS = document.getElementById("ADDRESS").value;
CITY = document.getElementById("CITY").value;
STATE = document.getElementById("STATE").selectedIndex;
ZIP = document.getElementById("ZIP").value;
EMAIL = document.getElementById("EMAIL").value;
PRI_PHONE1 = document.getElementById("PRI_PHONE1").value;
PRI_PHONE2 = document.getElementById("PRI_PHONE2").value;
PRI_PHONE3 = document.getElementById("PRI_PHONE3").value;
SEC_PHONE1 = document.getElementById("SEC_PHONE1").value;
SEC_PHONE2 = document.getElementById("SEC_PHONE2").value;
SEC_PHONE3 = document.getElementById("SEC_PHONE3").value;
PREF_CALLTIME = document.getElementById("PREF_CALLTIME").selectedIndex;
AGREEMENT= document.getElementById("AGREEMENT").checked;
//combine multiple-field inputs into one value
PRI_PHONE = PRI_PHONE1+PRI_PHONE2+PRI_PHONE3;
SEC_PHONE = SEC_PHONE1+SEC_PHONE2+SEC_PHONE3;
CALLBACKNUMBER = PRI_PHONE;
 
//check to make sure the form is properly filled out
if ((CC_DEBT_AMT < 5000) || (CC_DEBT_AMT > 101000)){
 hideAllErrors();
 document.getElementById("CC_DEBT_AMTerror").style.display = "block";
 document.getElementById("CC_DEBT_AMT").select();
 document.getElementById("CC_DEBT_AMT").focus();
 return false;  } 
else if ((CC_DEBT_PYMT_AGING > 180) || (CC_DEBT_PYMT_AGING == "")) {
 hideAllErrors();
 document.getElementById("CC_DEBT_PYMT_AGINGerror").style.display = "block";
 document.getElementById("CC_DEBT_PYMT_AGING").select();
 document.getElementById("CC_DEBT_PYMT_AGING").focus();
 return false;  } 
else if (FNAME == "") {
 hideAllErrors();
 document.getElementById("FNAMEerror").style.display = "block";
 document.getElementById("FNAME").select();
 document.getElementById("FNAME").focus();
 return false;  }
else if (LNAME == "") {
 hideAllErrors();
 document.getElementById("LNAMEerror").style.display = "block";
 document.getElementById("LNAME").select();
 document.getElementById("LNAME").focus();
 return false; }
else if (ADDRESS == "") {
 hideAllErrors();
 document.getElementById("ADDRESSerror").style.display = "block";
 document.getElementById("ADDRESS").select();
 document.getElementById("ADDRESS").focus();
 return false; }
else if (CITY == "") {
 hideAllErrors();
 document.getElementById("CITYerror").style.display = "block";
 document.getElementById("CITY").select();
 document.getElementById("CITY").focus();
 return false; } 
else if (STATE == 0) {
 hideAllErrors();
 document.getElementById("STATEerror").style.display = "block";
 setTimeout('window.scrollTo(0,200)',1);
 return false; }
else if (ZIP == "") {
 hideAllErrors();
 document.getElementById("ZIPerror").style.display = "block";
 document.getElementById("ZIP").select();
 document.getElementById("ZIP").focus(); 
 return false; }
else if (EMAIL == "") {
 hideAllErrors();
 document.getElementById("EMAILerror").style.display = "block";
 document.getElementById("EMAIL").select();
 document.getElementById("EMAIL").focus();
 return false; } 
else if (PRI_PHONE1 == "") {
 hideAllErrors();
 document.getElementById("PRI_PHONEerror").style.display = "block";
 document.getElementById("PRI_PHONE1").select();
 document.getElementById("PRI_PHONE1").focus();
 return false;  } 
else if (PRI_PHONE2 == "") {
 hideAllErrors();
 document.getElementById("PRI_PHONEerror").style.display = "block";
 document.getElementById("PRI_PHONE2").select();
 document.getElementById("PRI_PHONE2").focus();
 return false;  } 
else if (PRI_PHONE3 == "") {
 hideAllErrors();
 document.getElementById("PRI_PHONEerror").style.display = "block";
 document.getElementById("PRI_PHONE3").select();
 document.getElementById("PRI_PHONE3").focus();
 return false;  } 
else if (SEC_PHONE1 == "") {
 hideAllErrors();
 document.getElementById("SEC_PHONEerror").style.display = "block";
 document.getElementById("SEC_PHONE1").select();
 document.getElementById("SEC_PHONE1").focus();
 return false;  } 
else if (SEC_PHONE2 == "") {
 hideAllErrors();
 document.getElementById("SEC_PHONEerror").style.display = "block";
 document.getElementById("SEC_PHONE2").select();
 document.getElementById("SEC_PHONE2").focus();
 return false;  } 
else if (SEC_PHONE3 == "") {
 hideAllErrors();
 document.getElementById("SEC_PHONEerror").style.display = "block";
 document.getElementById("SEC_PHONE3").select();
 document.getElementById("SEC_PHONE3").focus();
 return false;  } 
else if (PREF_CALLTIME == 0) {
 hideAllErrors();
 document.getElementById("PREF_CALLTIMEerror").style.display = "block";
 setTimeout('window.scrollTo(0,400)',1);
 return false; }
else if (AGREEMENT == 0) {
 alert ("You must agree to terms before submitting.");
 return false;  } 
else	{ 
    var pri_phone = document.getElementById("PRI_PHONE");
    pri_phone.value = PRI_PHONE;
    var sec_phone = document.getElementById("SEC_PHONE");
    sec_phone.value = SEC_PHONE;
    return true; }
}
//hide errors so user is not overwhelmed with multiple errors 
function hideAllErrors() {
	document.getElementById("CC_DEBT_AMTerror").style.display = "none";
	document.getElementById("CC_DEBT_PYMT_AGINGerror").style.display = "none";
	document.getElementById("ADDRESSerror").style.display = "none";
	document.getElementById("CITYerror").style.display = "none";
	document.getElementById("FNAMEerror").style.display = "none";
	document.getElementById("LNAMEerror").style.display = "none";
	document.getElementById("STATEerror").style.display = "none"; 
	document.getElementById("EMAILerror").style.display = "none";
	document.getElementById("PRI_PHONEerror").style.display = "none";
	document.getElementById("SEC_PHONEerror").style.display = "none";
	document.getElementById("ZIPerror").style.display = "none"; 
	document.getElementById("PREF_CALLTIMEerror").style.display = "none"; 
	
  } 
//-->

