function openBannerWindow(url,width,height) {
  var bannerWindow = window.open(url,'','scrollbars=yes,menubar=yes,height='+height+',width='+width+',resizable=yes,toolbar=no,location=yes,status=yes');
}

function isValid(type, str) {
  if (type.toLowerCase() === "email") {
    var reEmail = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    if (!reEmail.test(str)) return false;
    return true;
  } else if (type.toLowerCase() === "telephone") {
    var rePhoneNumber = new RegExp(/^(\+\d)*\s*(\(?\d{3}\)?\s*)*-?\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/);
    if (!rePhoneNumber.test(str)) return false;
    return true;
  }
};

function setEmailMarketingAjax($) {
  $("form#email-marketing-form").submit(function() {
    if(!isValid("email", this.email.value)) { alert("Please enter a valid email"); return false; }
    this.event.value = "emailmarketing.contact.add.ajax";
    $.post("index.cfm", $(this).serializeArray(), function(data){
      $(data).find("success").each(function() {
        alert($(this).text());
        $("#email-marketing-form input[type=text]").val($("#email-marketing-form input[type=text]").attr("title"));
      });
    });
    return false;
  });
}

function setContactFormSubmit($) {
  $("form#contact-form").submit(function() {
    if(!isValid("email", this.email.value)) { alert("Please enter a valid email"); return false; }
    if(this.recaptcha_response_field.value == "") { alert("Invalid reCaptcha"); return false; }
    return true;
  });
}

function setAutoContactFormAjax($) {
  $("form#auto-contact-form").submit(function() {
    if(this.firstName.value == "" || this.firstName.value == this.firstName.title) { alert("Please enter your first name"); return false; }
    if(this.lastName.value == "" || this.lastName.value == this.lastName.title) { alert("Please enter your last name"); return false; }
    if(!isValid("email", this.email.value)) { alert("Please enter a valid email"); return false; }
    if(!isValid("telephone", this.phone.value)) { alert("Please enter a valid phone number"); return false; }
    if(this.message.value == "" || this.message.value == this.message.title) { alert("Please enter your comment"); return false; }
    this.event.value = "auto.contact.action.ajax";
    $.post("index.cfm", $(this).serializeArray(), function(data){
      $(data).find("success").each(function() {
        alert($(this).text());
        $("form#auto-contact-form").each(function() {
          this.firstName.value = this.firstName.title;
          this.lastName.value = this.lastName.title;
          this.email.value = this.email.title;
          this.phone.value = this.phone.title;
          this.message.value = this.message.title;
        });
      });
    });
    return false;
  });
}

(function($) {
  $(function() {
    $("input[type=text][title],textarea[title]").each(function() { $(this).val($(this).attr("title")); if($.trim($(this).val()) == "") $(this).val($(this).attr("title")); $(this).focus(function() { if($(this).val() == $(this).attr("title")) $(this).val(""); }).blur(function() { if($.trim($(this).val()) == "") $(this).val($(this).attr("title")); }); });
    $("a[href][rel*=external]").attr("target", "_blank");
    $(".fade-hover").hoverIntent(function() { $(this).fadeTo("fast", 0.5); }, function() { $(this).fadeTo("fast", 1.0); });
    $(".lo").hoverIntent(function() { $(this).removeClass("lo").addClass("hi"); }, function() { $(this).removeClass("hi").addClass("lo"); });
    $("#nav .lo").hoverIntent({
      sensitivity: 7, interval: 100, timeout: 500,
      over: function() { $(this).removeClass("lo").addClass("hi").find("ul").show("slide", {direction: "up"}); },
      out: function() { $(this).removeClass("hi").addClass("lo").find("ul").hide("slide", {direction: "up"}); }
    });
    $("#nav ul").fadeTo("fast", 0.9);
    
    setEmailMarketingAjax($);
    setContactFormSubmit($);
    setAutoContactFormAjax($);
    
    //flash
    $("#home-flash-rotation .replace").flash({ swf: "flash/flash_main.swf", width: '900px', height: '340px', params: {wmode: "opaque"} });
    
    //auto
    $("#auto-thumbs a").hoverIntent(function() { $("#auto-img").attr("src", $(this).attr("href")); }, function() {});
    
    $('a').click(function () {leaveTest = true})
    
    //ie_6 fixes
    $(".ie_6 #sidebar .pod + .pod").css("border-top", "1px solid black");
    $(".ie_6 #nav .wrapper-2 ul").each(function() { $(this).after('<iframe style="height: '+$(this).outerHeight()+'px;"></iframe>'); });
  });
})(jQuery);

var leaveTest = false

function loadCoupon()
{
	if(!(leaveTest)) window.open('index.cfm?event=coupon','_blank','width=600,height=470,resizable=false,scrollbars=false,menubar=false,toolbar=false,status=false');
}