// POPUP WINDOW FUNCTIONS, PLEASE WAIT ANIMATED GIF FUNCTION
function pop(URL)      { var day = new Date(); var id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=700,height=590');"); }
function popsmall(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=520,height=300');"); }
function poptiny(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=300,height=170');"); }
function popnormal(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=700,height=500');"); }

// DIV HIDE/DISPLAY WITH VALUE SETTINGS
function setTV()
  {
    if (!document.app.cbchk.checked == false) { document.app.cbchk.checked = true;  document.getElementById('cb').style.display = ""; }
    else                                      { document.app.cbchk.checked = false; document.getElementById('cb').style.display = "none"; }
    return true;
  }

// FINANCE FORM - PREFILL COBUYER ADDRESS INFO
function prefillcobuyer()
  {
     if (document.app.sameas.checked)
       {
          document.app.caddress.value = document.app.baddress.value;
          document.app.ccity.value    = document.app.bcity.value;
          document.app.cstate.value   = document.app.bstate.value;
          document.app.czip.value     = document.app.bzip.value;
          document.app.ccounty.value  = document.app.bcounty.value;

          document.app.ccounty.value  = document.app.bcounty.value;
          document.app.chomea.value   = document.app.bhomea.value;
          document.app.chomeb.value   = document.app.bhomeb.value;
          document.app.chomec.value   = document.app.bhomec.value;
       }
     else
       {
          document.app.caddress.value = "";
          document.app.ccity.value    = "";
          document.app.cstate.value   = "";
          document.app.czip.value     = "";
          document.app.ccounty.value  = "";
          document.app.chomea.value   = "";
          document.app.chomeb.value   = "";
          document.app.chomec.value   = "";

       }
  }

function checkForm(type)
{
  var why = "";

  if (document.app.bfname.value == '') { why =  "First Name is Required.\n";   alert(why); document.app.bfname.focus(); return false; }
  if (document.app.blname.value == '') { why =  "Last Name is Required.\n";    alert(why); document.app.blname.focus(); return false; }
  if (document.app.bhomea.value == '') { why =  "Phone Number is Required.\n"; alert(why); document.app.bhomea.focus(); return false; }
  if (document.app.bhomeb.value == '') { why =  "Phone Number is Required.\n"; alert(why); document.app.bhomeb.focus(); return false; }
  if (document.app.bhomec.value == '') { why =  "Phone Number is Required.\n"; alert(why); document.app.bhomec.focus(); return false; }
  if (document.app.bemail.value == '') { why =  "Email is Required.\n";        alert(why); document.app.bemail.focus(); return false; }

  var RegEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (!document.app.bemail.value.match(RegEmail)) { why = "You must supply a valid email address.\n"; alert(why); document.app.bemail.focus(); return false; }

  if(type == 'quote') {
     if (document.app.dcode.selectedIndex == 0) { why =  "Please Select a Dealership.\n";        alert(why); document.app.dcode.focus(); return false; }
   }

  if(type == 'form') {
     if (document.app.bssna.value == '') { why =  "SSN is Required.\n";        alert(why); document.app.bssna.focus(); return false; }
     if (document.app.bssnb.value == '') { why =  "SSN is Required.\n";        alert(why); document.app.bssnb.focus(); return false; }
     if (document.app.bssnc.value == '') { why =  "SSN is Required.\n";        alert(why); document.app.bssnc.focus(); return false; }
   }

  if ((type == 'info') || (type =='quote')) {
      if (document.app.comments.value == '') { why =  "Comments are Required.\n"; alert(why); document.app.comments.focus(); return false; }
  }

  if ((type == 'parts') || (type =='appt' )) {
      if (document.app.year.value == 'Year')   { why =  "Vehicle Year Required.\n"; alert(why);  document.app.year.focus();  return false; }
      if (document.app.make.value == 'Make')   { why =  "Vehicle Make Required.\n"; alert(why);  document.app.make.focus();  return false; }
      if (document.app.model.value == 'Model') { why =  "Vehicle Model Required.\n"; alert(why); document.app.model.focus(); return false; }
  }
  return true;
}

function validEmail()
{
  var RegEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var why = "";
  if (document.app.nemail.value == '') { why =  "Email is Required.\n";        alert(why); document.app.nemail.focus(); return false; }
  if (!document.app.nemail.value.match(RegEmail)) { why = "You must supply a valid email address.\n"; alert(why); document.app.nemail.focus(); return false; }
  return true;
}
