var XHR = null;

$(document).ready(function() {
    
    //hook up subscribebtn / txtbox events
    $("#SubscribeBtn").attr("href", "javascript:void(0);").click(function() {
        SubscribeToUpdates($("#txtSubscribe").val());
    });

    $("#txtSubscribe").keyup(function(e) {
        if (e.keyCode == 13) {
            SubscribeToUpdates(this.value);
        }
    });
    
    //add logos to top five visited pages
    $(".mostviewed span ol li a").each(function(){
    	var $this = $(this);
    	if($this.attr("href").toLowerCase().indexOf("traulsen") > -1){
    		$this.parent().parent().prepend("<span>Traulsen</span>");
    	}
    	else{
		if($this.attr("href").toLowerCase().indexOf("baxter") > -1){
			$this.parent().parent().prepend("<span>Baxter</span>");
		}
		else{
			$this.parent().parent().prepend("<span>Hobart</span>");
		}
    	}
    	
    });
});


function SubscribeToUpdates(Email) {
    if (Email != "") {
        if (IsValidEmail(Email)) {
            if (XHR != null) {
                XHR.abort();
            }
            
            $("#SubscribeError").html("<img src='/images/global/ajax-loadersm.gif'/>");

            XHR = $.ajax({
                type: "GET",
                url: "/SubscribeToUpdates.aspx",
                data: { Email: Email, FormID: 232 },
                dataType: "html",
                cache: false,
                success: function(result) {
                    $("#subscribeform").hide();
                    $("#ThankYouSubscribing").show();
                }
            });
        }
        else {
            $("#SubscribeError").html("Invalid E-mail Address");
        }
    }
}