<!--
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 and periods 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],''); 
  }
//validate that applicant has not previously consolidated his/her loans
function validate_consolidation(){
 if (document.LOAN.PREV_LOAN_CONSOLIDATION[0].checked == true) {
	document.getElementById("PREV_LOAN_CONSOLIDATIONerror2").style.display = "block";
	setTimeout('window.scrollTo(0,0)',1);
	return true; }
 if (document.LOAN.PREV_LOAN_CONSOLIDATION[1].checked == true) {
	document.getElementById("PREV_LOAN_CONSOLIDATIONerror2").style.display = "none";
	setTimeout('window.scrollTo(0,0)',1);
	return true; } } 
//validate that student has graduated or will be graduated in 6 months
function validate_graduation(){
 if (document.LOAN.GRADUATED_GRADUATING_IN_6[0].checked == true) {
	document.getElementById("GRADUATED_GRADUATING_IN_6error2").style.display = "none";
	setTimeout('window.scrollTo(0,0)',1);
	return true; }
 if (document.LOAN.GRADUATED_GRADUATING_IN_6[1].checked == true) {
	document.getElementById("GRADUATED_GRADUATING_IN_6error2").style.display = "block";
	setTimeout('window.scrollTo(0,0)',1);
	return true; } } 
//validate that applicant has not defaulted on loans
function validate_default(){
 if (document.LOAN.LOANS_DEFAULT[0].checked == true) {
	document.getElementById("LOANS_DEFAULTerror2").style.display = "block";
	setTimeout('window.scrollTo(0,0)',1);
	return true; }
 if (document.LOAN.LOANS_DEFAULT[1].checked == true) {
	document.getElementById("LOANS_DEFAULTerror2").style.display = "none";
	setTimeout('window.scrollTo(0,0)',1);
	return true; } } 


function validate_form() {
//set variables to the values input in the form
TOTAL_STUD_LOAN = document.getElementById("TOTAL_STUD_LOAN").value;
TOTAL_STUD_LOAN = TOTAL_STUD_LOAN.replace(/\,/g,"");	//get rid of commas input by the user
SSN1 = document.getElementById("SSN1").value;
SSN2 = document.getElementById("SSN2").value;
SSN3 = document.getElementById("SSN3").value;
SSN = SSN1+SSN2+SSN3;
ADDRESS = document.getElementById("ADDRESS").value;
CITY = document.getElementById("CITY").value;
FNAME = document.getElementById("FNAME").value;
LNAME = document.getElementById("LNAME").value;
STATE = document.getElementById("STATE").selectedIndex;
EMAIL = document.getElementById("EMAIL").value;
PRI_PHONE = document.getElementById("PRI_PHONE").value;
ZIP = document.getElementById("ZIP").value;
AGREEMENT= document.getElementById("AGREEMENT").checked;
 
 //check to make sure the form is properly filled out
 if ((document.LOAN.GRADUATED_GRADUATING_IN_6[0].checked == false ) && (document.LOAN.GRADUATED_GRADUATING_IN_6[1].checked == false)) {
 hideAllErrors();
 document.getElementById("GRADUATED_GRADUATING_IN_6error").style.display = "block";
 setTimeout('window.scrollTo(0,0)',1);
  return false; }

else if ((document.LOAN.PREV_LOAN_CONSOLIDATION[0].checked == false ) && (document.LOAN.PREV_LOAN_CONSOLIDATION[1].checked == false)) {
 hideAllErrors();
 document.getElementById("PREV_LOAN_CONSOLIDATIONerror").style.display = "block";
 setTimeout('window.scrollTo(0,0)',1);
  return false; }

else if (TOTAL_STUD_LOAN < 10000) {
 hideAllErrors();
document.getElementById("TOTAL_STUD_LOANerror").style.display = "block";
setTimeout('window.scrollTo(0,0)',1);
  return false; } 

else if (( document.LOAN.LOANS_DEFAULT[0].checked == false ) && (document.LOAN.LOANS_DEFAULT[1].checked == false)) {
 hideAllErrors();
 document.getElementById("LOANS_DEFAULTerror").style.display = "block";
 setTimeout('window.scrollTo(0,0)',1);
  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,400)',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 (SSN1 == "") {
   hideAllErrors();
document.getElementById("SSNerror").style.display = "block";
document.getElementById("SSN1").select();
document.getElementById("SSN1").focus(); 
   return false; }

     else if (SSN2 == "") {
   hideAllErrors();
document.getElementById("SSNerror").style.display = "block";
document.getElementById("SSN2").select();
document.getElementById("SSN2").focus(); 
   return false; }

     else if (SSN3 == "") {
   hideAllErrors();
document.getElementById("SSNerror").style.display = "block";
document.getElementById("SSN3").select();
document.getElementById("SSN3").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_PHONE == "") {
    hideAllErrors();
document.getElementById("PRI_PHONEerror").style.display = "block";
document.getElementById("PRI_PHONE").select();
document.getElementById("PRI_PHONE").focus();
  return false;  } 
  
   else if (AGREEMENT == 0) {
alert ("You must agree to terms before submitting.");
  return false;  }  
  else	{ return true; }
}
//hide errors so user is not overwhelmed with multiple errors 
function hideAllErrors() {
	document.getElementById("GRADUATED_GRADUATING_IN_6error").style.display = "none";
	document.getElementById("PREV_LOAN_CONSOLIDATIONerror").style.display = "none";
	document.getElementById("TOTAL_STUD_LOANerror").style.display = "none";
	document.getElementById("LOANS_DEFAULTerror").style.display = "none";
	document.getElementById("SSNerror").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("ZIPerror").style.display = "none"; 
  } 
//-->
