﻿function PageLogCompleteHandler(purlPageLog)
{
}

var contactOptions;

function abt_init() {
   contactOptions = new RadioField("contact_option", dealer_contactoption);
}

function showThankYou() {
   dhtmlmodal.open();
   var b = document.getElementById("ThankYouBox");
   b.style.visibility = "hidden";
   b.style.display = "";
   b.style.left = ((dhtmlwindow.docwidth - b.offsetWidth) / 2) + "px";
   b.style.top = "100px";
   b.style.visibility = "visible";
}
function hideThankYou() {
   var b = document.getElementById("ThankYouBox");
   b.style.display = "none";
   dhtmlmodal.closeveil();
}

function displayFieldError(field, errorPrompt) {
   field.Object.Element.style.backgroundColor = errorColor;
   field.Object.Element.style.color = "White";
   if (errorPrompt)
      window.alert(errorPrompt + ".");
   field.Object.focus();
}
function displayEmailError() {
   displayFieldError(dealer_email, "Please enter an email address");
}
function displayPhoneError() {
   displayFieldError(dealer_phone, "Please enter a a phone number");
}

function checkDealerEmail(oEvent, noErrorDisplay) {
   if (dealer_email.getText().length <= 0) {
      oEvent.cancel = true;
      if (!noErrorDisplay)
         displayEmailError();
      return (false);
   }
   return (true);
}

function checkDealerPhone(oEvent, noErrorDisplay) {
   if (dealer_phone.getText().length <= 0) {
      oEvent.cancel = true;
      if (!noErrorDisplay)
         displayPhoneError();
      return (false);
   }
   return (true);
}

var errorColor = "#a61e34";
function Submit_Click(oButton, oEvent) {
   try {
      var selectedOption = contactOptions.getSelected();

      if (selectedOption == null) {
         contactOptions.setError("White", errorColor);
         oEvent.cancel = true;
         window.alert("Please select a contact option.");
         return;
      }

      contactOptions.updateLink();

      if (first_name.getText().length <= 0) {
         first_name.Object.Element.style.backgroundColor = errorColor;
         first_name.Object.Element.style.color = "White";
         window.alert("Please enter your first name.");
         first_name.Object.focus();
         oEvent.cancel = true;
         return;
      }

      if (last_name.getText().length <= 0) {
         last_name.Object.Element.style.backgroundColor = errorColor;
         last_name.Object.Element.style.color = "White";
         window.alert("Please enter your last name.");
         last_name.Object.focus();
         oEvent.cancel = true;
         return;
      }

      if ((dealer_email.getText().length <= 0)
          && (dealer_phone.getText().length <= 0)) {
         dealer_email.Object.Element.style.backgroundColor = errorColor;
         dealer_email.Object.Element.style.color = "White";
         dealer_phone.Object.Element.style.backgroundColor = errorColor;
         dealer_phone.Object.Element.style.color = "White";
         window.alert("Please enter a phone number and/or an email address.");
         dealer_email.Object.focus();
         oEvent.cancel = true;
      }
   }
   catch (error) {
      window.alert("Submit_Click error: " + error.message);
      oEvent.cancel = true;
   }
}
function openabtl_new() {
   emailwindow = dhtmlmodal.open('EmailBox', 'iframe', 'modalfiles/abtl_new.htm', 'Autobytel New Car Internet Marketing Program', 'width=800px,height=610px,center=1,resize=0,scrolling=0')
   emailwindow.onclose = function() { //Define custom code to run when window is closed
      var theform = this.contentDoc.forms[0] //Access first form inside iframe just for your reference
      var theemail = this.contentDoc.getElementById("emailfield") //Access form field with id="emailfield" inside iframe
      if (theemail.value.indexOf("@") == -1) { //crude check for invalid email
         alert("Please enter a valid email address")
         return false //cancel closing of modal window
      }
      else { //else if this is a valid email
         document.getElementById("youremail").innerHTML = theemail.value //Assign the email to a span on the page
         return true //allow closing of window
      }
   }
}  //End "openabtl_new" function
function openabtl_used() {
   emailwindow = dhtmlmodal.open('EmailBox', 'iframe', 'modalfiles/abtl_used.htm', 'Autobytel Used Car Internet Marketing Program', 'width=800px,height=610px,center=1,resize=0,scrolling=0')
   emailwindow.onclose = function() { //Define custom code to run when window is closed
      var theform = this.contentDoc.forms[0] //Access first form inside iframe just for your reference
      var theemail = this.contentDoc.getElementById("emailfield") //Access form field with id="emailfield" inside iframe
      if (theemail.value.indexOf("@") == -1) { //crude check for invalid email
         alert("Please enter a valid email address")
         return false //cancel closing of modal window
      }
      else { //else if this is a valid email
         document.getElementById("youremail").innerHTML = theemail.value //Assign the email to a span on the page
         return true //allow closing of window
      }
   }
}  //End "openabtl_used" function
function openabtl_leadcall() {
   emailwindow = dhtmlmodal.open('EmailBox', 'iframe', 'modalfiles/abtl_leadcall.htm', 'Autobytel LeadCall', 'width=800px,height=610px,center=1,resize=0,scrolling=0')
   emailwindow.onclose = function() { //Define custom code to run when window is closed
      var theform = this.contentDoc.forms[0] //Access first form inside iframe just for your reference
      var theemail = this.contentDoc.getElementById("emailfield") //Access form field with id="emailfield" inside iframe
      if (theemail.value.indexOf("@") == -1) { //crude check for invalid email
         alert("Please enter a valid email address")
         return false //cancel closing of modal window
      }
      else { //else if this is a valid email
         document.getElementById("youremail").innerHTML = theemail.value //Assign the email to a span on the page
         return true //allow closing of window
      }
   }
}  //End "openabtl_leadcall" function
function opennewsletter() {
   emailwindow = dhtmlmodal.open('EmailBox', 'iframe', 'modalfiles/newsletter.htm', 'Autobytel LeadCall', 'width=800px,height=440px,center=1,resize=0,scrolling=0')

   emailwindow.onclose = function() { //Define custom code to run when window is closed
      var theform = this.contentDoc.forms[0] //Access first form inside iframe just for your reference
      var theemail = this.contentDoc.getElementById("emailfield") //Access form field with id="emailfield" inside iframe
      if (theemail.value.indexOf("@") == -1) { //crude check for invalid email
         alert("Please enter a valid email address")
         return false //cancel closing of modal window
      }
      else { //else if this is a valid email
         document.getElementById("youremail").innerHTML = theemail.value //Assign the email to a span on the page
         return true //allow closing of window
      }
   }
}  //End "opennewsletter" function
