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($) {
  $(function() {
    $("input[type=text][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"); });
    
    setEmailMarketingAjax($);
  });
})(jQuery);