var XHR;
var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

$(document).ready(function() {
    // Add GA cross-domain linking code to all <a> tags linking to Hobart & Traulsen
    $("a").each(function() {
        var href = $(this).attr("href");
        if (href && (href.indexOf("http://www.hobartcorp.com") > -1 || href.indexOf("http://www.traulsen.com") > -1)) {
            $(this).attr("onclick", "pageTracker._link('" + href + "'); return false;");
        }
        if(href && href.indexOf(".pdf") > -1){
          $(this).click(function(){
            pageTracker._trackEvent("PDF", "Download", href);
          });
        }
    });
    
    //hook up search box / button
    $("#txtSearch").keypress(function(e) {
      if (e.which == 13) {
        window.location.href = "/search-results/?k=" + $("#txtSearch").val();
      }
    });
    
    $("#btnSearch").click(function(e){
      e.preventDefault();
      window.location.href = "/search-results/?k=" + $("#txtSearch").val();
    });
    
    
});

function IsValidEmail(str) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)) {
        return (true)
    }
    return (false)
}

function GetQueryStringValue(Key) {
    var QStrArray = document.location.search.substring(1).split("&");
    for (var i = 0; i < QStrArray.length; i++) {
        var tempArray = QStrArray[i].split("=");
        if (tempArray[0] == Key) {
            return tempArray[1];
        }
    }

    return "";
}

function playLightboxVideo(ekid) {
    $.ajax({ url: "/ajaxcontent/LightboxVideo.aspx",
        type: "GET",
        data: { id: ekid },
        success: function(data) {
            $("<div id='lb'>").html($("#lightbox", data)).appendTo("body:first");
            sizeLightboxVideo();
            $("#lightboxBG").width(Math.max($("body:first").width(), $(window).width())).height(Math.max($("body:first").height(), $(window).height()));
            $("#lightboxBG").fadeIn("fast", function() {
                $("#lightboxBorder").fadeIn("fast");
                $("#lightboxContainer").fadeIn("fast");
            });
            $(window).bind("resize", function() {
                setTimeout('$("#lightboxBG").width($(window).width()).height($(window).height());', 100);
            });
        }
    });
}

function showLightboxForm(ekid) {
  $("#lb").remove();
    $.ajax({ url: "/ajaxcontent/LightboxForm.aspx",
        type: "GET",
        data: { id: ekid },
        success: function(data) {

            $("#head_container").css("z-index", "0").css("top", "-1000px");
            $("<div id='lb'>").html($("#lightbox", data)).appendTo("body:first");

            $.getScript("/js/" + $("#jsfile", data).html());

            var lightBoxWidth = $("#lightboxContainer").width();
            $("#lightboxContainer").css("margin-left", -(lightBoxWidth / 2 + 20));
            $("#lightboxBorder").width(lightBoxWidth + 60).css("margin-left", -((lightBoxWidth + 60) / 2)).css("top", "91px");

            $("#lightboxBG").width(Math.max($("body:first").width(), $(window).width())).height(Math.max($("body:first").height(), $(window).height()));

            $("#lightboxBorder").height($("#lightboxContainer").height() + 46);
            $("#lightboxBG").fadeIn("fast", function() {
                $("#lightboxBorder").fadeIn("fast");
                $("#lightboxContainer").fadeIn("fast");
            });
            $(window).bind("resize", function() {
                setTimeout('$("#lightboxBG").width($(window).width()).height($(window).height());', 100);
            });
        }
    });
}

function closeLightboxVideo() {
    $("#lightboxContainer").fadeOut("fast");
    
    $("#lightboxBorder").fadeOut("fast", function() {
        $("#lightboxBG").fadeOut("fast", function() {
        $("#head_container").css("top", "0");
            $("#lb").remove();
        });
    });
}