// POPUP WINDOW FUNCTIONS
function pop(URL)      { var day = new Date(); var id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=1,resizable=1,width=700,height=600');"); }
function popfull(URL)  { var day = new Date(); var id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=500');"); }

// TOGLE DIV ELEMENT VISIBILITY
function toggle(divid)
  {
     var divobj = document.getElementById(divid);
     if (divobj.style.display == "") { divobj.style.display = "none"; }
     else                            { divobj.style.display = ""; }
     return true;
  }

// FORM VALIDATION FUNCTIONS
function checkApp1 ()
  {
     var why = "";
     // required fields
     if (document.app.fname.value       == '') { why =  "First Name is Required.\n";         alert(why);  document.app.fname.focus()     ; return false; }
     if (document.app.lname.value       == '') { why =  "Last Name is Required.\n";          alert(why);  document.app.lname.focus()     ; return false; }
     if (document.app.jobtitle.value    == '') { why =  "Occupation is Required.\n";         alert(why);  document.app.jobtitle.focus()  ; return false; }
     if (document.app.income.value      == '') { why =  "Monthly Income is Required.\n";     alert(why);  document.app.income.focus()    ; return false; }
     if (document.app.timeonjoba.value  == '') { why =  "Years on Job is Required.\n";       alert(why);  document.app.timeonjoba.focus(); return false; }
     if (document.app.timeonjobb.value  == '') { why =  "Months on Job is Required.\n";      alert(why);  document.app.timeonjobb.focus(); return false; }
     if (document.app.doba.value        == '') { why =  "Birth Month is Required.\n";        alert(why);  document.app.doba.focus()      ; return false; }
     if (document.app.dobb.value        == '') { why =  "Birth Day is Required.\n";          alert(why);  document.app.dobb.focus()      ; return false; }
     if (document.app.dobc.value        == '') { why =  "Birth Year is Required.\n";         alert(why);  document.app.dobc.focus()      ; return false; }
     if (document.app.email.value       == '') { why =  "Email is Required.\n";              alert(why);  document.app.email.focus()     ; return false; }
     var RegEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     if (!document.app.email.value.match(RegEmail)) { why = "Invalid Email Address.\n"; alert(why); document.app.email.focus(); return false; }
     if (document.app.ssna.value        == '') { why =  "SSN is Required.\n";                alert(why);  document.app.ssna.focus()      ; return false; }
     if (document.app.ssnb.value        == '') { why =  "SSN is Required.\n";                alert(why);  document.app.ssnb.focus()      ; return false; }
     if (document.app.ssnc.value        == '') { why =  "SSN is Required.\n";                alert(why);  document.app.ssnc.focus()      ; return false; }
     toggle('app1');
     toggle('app2');
     return true;
  }

function prevApp () 
  {
     toggle('app1');
     toggle('app2');
     return true;
  }

function checkApp2 ()
  {
     var why = "";
     // required fields
     if (document.app.address.value     == '') { why =  "Street Name is Required.\n";        alert(why);  document.app.address.focus()   ; return false; }
     if (document.app.city.value        == '') { why =  "City is Required.\n";               alert(why);  document.app.city.focus()      ; return false; }
     if (document.app.state.value       == '') { why =  "State is Required.\n";              alert(why);  document.app.state.focus()     ; return false; }
     if (document.app.zip.value         == '') { why =  "Zip is Required.\n";                alert(why);  document.app.zip.focus()       ; return false; }
     if (document.app.home.value        == '') { why =  "Home Phone Number is Required.\n";  alert(why);  document.app.home.focus()      ; return false; }
     // read privacy policy?
     if (document.app.confirm.checked == false) { why =  "Please Verify that you have read the privacy policy.\n";  alert(why);  document.app.confirm.focus()      ; return false; }
     // submit the form
     document.app.submit();
     return true;
  }

function checkAppraisal1 ()
  {
     var why = "";
     // required fields
     if (document.app.year.value      == '')        { why =  "Year is Required.\n";      alert(why);  document.app.year.focus();      return false; }
     if (document.app.make.value      == '')        { why =  "Make is Required.\n";      alert(why);  document.app.make.focus();      return false; }
     if (document.app.model.value     == '')        { why =  "Model is Required.\n";     alert(why);  document.app.model.focus();     return false; }
     if (document.app.engine.selectedIndex == 0)    { why =  "Engine is Required.\n";    alert(why);  document.app.engine.focus();    return false; }
     if (document.app.trans.selectedIndex == 0)     { why =  "Trans is Required.\n";     alert(why);  document.app.trans.focus();     return false; }
     if (document.app.mileage.value   == '')        { why =  "Mileage is Required.\n";   alert(why);  document.app.mileage.focus();   return false; }
     if (document.app.condition.selectedIndex == 0) { why =  "Condition is Required.\n"; alert(why);  document.app.condition.focus(); return false; }
     if (document.app.vin.value       == '')        { why =  "VIN is Required.\n";       alert(why);  document.app.vin.focus();       return false; }
     toggle('appraisal1');
     toggle('appraisal2');
     return true;
  }
  
function prevAppraisal () 
  {
     toggle('appraisal1');
     toggle('appraisal2');
     return true;
  }

function checkAppraisal2 ()
  {
     var why = "";
     // required fields
     if (document.app.fname.value       == '') { why =  "First Name is Required.\n";         alert(why);  document.app.fname.focus()     ; return false; }
     if (document.app.lname.value       == '') { why =  "Last Name is Required.\n";          alert(why);  document.app.lname.focus()     ; return false; }
     if (document.app.address.value     == '') { why =  "Street Name is Required.\n";        alert(why);  document.app.address.focus()   ; return false; }
     if (document.app.city.value        == '') { why =  "City is Required.\n";               alert(why);  document.app.city.focus()      ; return false; }
     if (document.app.state.value       == '') { why =  "State is Required.\n";              alert(why);  document.app.state.focus()     ; return false; }
     if (document.app.zip.value         == '') { why =  "Zip is Required.\n";                alert(why);  document.app.zip.focus()       ; return false; }
     var RegEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     if (!document.app.email.value.match(RegEmail)) { why = "Invalid Email Address.\n"; alert(why); document.app.email.focus(); return false; }
     if (document.app.home.value        == '') { why =  "Home Phone Number is Required.\n";  alert(why);  document.app.home.focus()      ; return false; }
     // submit the form
     document.app.submit();
     return true;
  }

function checkCoup ()
  {
     var why = "";
     // required fields
     if (document.app.fname.value       == '') { why =  "First Name is Required.\n";         alert(why);  document.app.fname.focus(); return false; }
     if (document.app.lname.value       == '') { why =  "Last Name is Required.\n";          alert(why);  document.app.lname.focus(); return false; }
     if (document.app.email.value       == '') { why =  "Email is Required.\n";              alert(why);  document.app.email.focus(); return false; }
     if (document.app.phone.value       == '') { why =  "Phone Number is Required.\n";       alert(why);  document.app.phone.focus(); return false; }
     // valid email address?
     var RegEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     if (!document.app.email.value.match(RegEmail)) { why = "Invalid Email Address.\n"; alert(why); document.app.email.focus(); return false; }
  }
