/**
 * 
 */
function sfHover()
{
	$("#nav > ul > li").hover(
		function () {
			$(this).addClass("sfhover");
		}, 
		function () {
			$(this).removeClass("sfhover");
		}
	);
}

/**
 * 
 */
function initAjaxProgress()
{
	try {
		var pageHeight=(document.documentElement&&document.documentElement.scrollHeight)?document.documentElement.scrollHeight:(document.body.scrollHeight>document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
		var pageWidth=$(window).width();
		var bg=document.getElementById('ajaxProgressBg');
		bg.style.height=(pageHeight+1000)+'px';
		bg.style.width=pageWidth+'px';
		reposAjaxProgress();
		window.onscroll=reposAjaxProgress;
		window.onresize=reposAjaxProgress;
	} catch(e) {
		showError(e);
	}
}

/**
 * 
 */
function reposAjaxProgress()
{
	var div=document.getElementById('ajaxProgress');
	var st=document.body.scrollTop;
	if (st==0) {
		if (window.pageYOffset) {
			st=window.pageYOffset;
		} else {
			st=(document.body.parentElement)?document.body.parentElement.scrollTop:0;
		}
	}
	div.style.top=150+st+"px";
	document.getElementById("ajaxProgressBg").style.left = "0px";
}

/**
 * 
 */
function joinEmail()
{
	var address = $(".frmJoin .txtInput").val();
	if (address == "Enter Email Address" || address == "" || !validateEmail(address)) {
		alert("Please enter a valid e-mail address.");
	} else {
		window.open("http://visitor.constantcontact.com/d.jsp?ea=" + address + "&go=Join&m=1101657251422&p=oi","_blank");
		try {
			var vt = visitorType();
			var c = getCookie("SWFA.TV");
			if (c != "" && Number(c) > 1) {
				vt += " : " + c;
			}
			pageTracker._trackEvent("Email Optin", "SWFA", vt, 1);
		} catch(e) {
			showError(e);
		}
	}
}

/**
 * 
 */
function validateEmail(s)
{
	var regexp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return regexp.test(s);
}

/**
 * 
 */
function trapFormKeySubmitEvent(element,event)
{
	if (event.keyCode == 13) {
		return false;
	} else {
		return true;
	}
}

/**
 * 
 */
function ajaxUpdateEndRequestHandler(sender,e)
{
	$.Lightbox.reinitialize();
}

/**
 * 
 */
function TreePanel_onNodeSelect(sender,eventArgs)
{
	try {
		var node = eventArgs.get_node();
		pageTracker._trackEvent("Category Nav", node.Text, visitorType(), 1);
	} catch(e) {
		showError(e);
	}
}

/**
 * 
 */
function TreePanel_Load(sender,eventArgs)
{
	try {
		$(".CatTreeView > div:visible:last").css("background-image", "none");
	} catch(e) {
		showError(e);
	}
}

/**
 * 
 */
function visitorType()
{
	var type;
	var c = getCookie("SWFA.C");
	var fv = getCookie("SWFA.FV");
	var lv = getCookie("SWFA.LV");
	if (c != "") {
		type = c;
	} else if (fv != "" && lv != "") {
		type = (fv == lv) ? "New" : "Returning";
	} else {
		type = "New";
	}
	return type;
}

/**
 * 
 */
function gaDeleteBasketItem(category, sku)
{
	var deleteItem = confirm("Are you sure you want to remove this item from your basket?");
	if (deleteItem) {
		pageTracker._trackEvent("Delete Item", category, sku, 1);
	}
	return deleteItem;
}

/**
 * 
 */
function gaMoveToWishlist(category, sku)
{
	pageTracker._trackEvent("Wishlist", category, sku, 1);
}

/**
 * 
 */
function gaClearBasket(total)
{
	var choice = confirm("Are you sure you want to clear your basket?");
	if (choice) {
		pageTracker._trackEvent("Clear Cart", visitorType(), "Amount in Cart - " + total, 1);
	}
	return choice;
}

/**
 * 
 */
function gaShippingCalculation()
{
	try {
		var zip = $(".txtShipEstimateZip").val();
		if (zip != undefined && zip != "") {
			pageTracker._trackEvent("Shipping Estimate", zip, visitorType(), 1);
		}
	} catch(e) {
		showError(e);
	}
}

/**
 * 
 */
function showError(e)
{
	if (DEBUG) {
		var s = new String();
		s += "JavaScript Error:\n";
		for (var item in e) {
			s += item + ": " + e[item] + "\n";
		}
		alert(s);
	}
}

/**
 * 
 */
function getCookie(name)
{
	if (document.cookie.length > 0) {
		var idxStart = document.cookie.indexOf(name + "=");
		if (idxStart!=-1) {
			idxStart = idxStart + name.length + 1;
			idxEnd = document.cookie.indexOf(";", idxStart);
			if (idxEnd == -1) {
				idxEnd = document.cookie.length;
			}
			return unescape(document.cookie.substring(idxStart, idxEnd));
		}
	} else {
		return"";
	}
}

/**
 * 
 */
function emailOptIn(){}

/**
 * 
 */
function validatePhotoContestAgreement(source, args)
{
	args.IsValid = $(".cbPhotoContestAgreement input:checked").length;
}

/**
 * 
 */
function PopupWindow(src, w, h)
{
	try {
		var left = (screen.width / 2) - (w / 2);
		var top = (screen.height / 2) - (h / 2);
		window.open(src, null, "width="+w+",height="+h+",left=" + left + ",top=" + top + "status=yes,toolbar=no,menubar=no,location=no");
		return false;
	} catch(e) {
		return true;
	}
}

/**
 * 
 */
function showTellFriendMessage(e1) {
    var link = $(e1);
    var target = "#tafMessage";
    $(e1).hide();
    $(target).show();
    setTimeout("$('"+target+" textarea').focus()", 100);
    return false;
}

var DEBUG = false;
var strSealURL = "weblogos.dnb.com";
var sealID = "41A44EDC-EFF8-46B2-ACA4-D4C9697EE558";
var strDuns = "053662094";
var strRWSPath = "smallbusiness.dnb.com";
var strCountry = "US";
var increment = "true";
var strLang = "EN";

$(document).ready(function(){
	$(".specifications a").each(function(){ this.onclick = null; });
	$(".specifications a").lightbox();
	$("img").bind("contextmenu", function(e) { return false; });
	initAjaxProgress();
	if (window.attachEvent){ sfHover(); }
	
	$(".txtSearch").focus(function(){if(this.value=="Product Search"){this.value="";}});
	$(".txtSearch").blur(function(){if(this.value==""){this.value="Product Search";}});
	
	$(".frmJoin .email").focus(function(){if(this.value=="Enter Email Address"){this.value="";}});
	$(".frmJoin .email").blur(function(){if(this.value==""){this.value="Enter Email Address";}});
	
	$("#nav > ul > li").each(function(index){var menuButton=jQuery(this);var menu=menuButton.find("ul");if(menu.length>0){if(menu.width()<menuButton.width()){menu.css("width",menuButton.width()+"px");}}});
	
	$(".tabbednav .tabs").tabs();
	$("a[rel='external']").each(function(index){jQuery(this).attr("target","_blank");});
	
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ajaxUpdateEndRequestHandler);



    // Toggle product reviews
    $(".review-toggle").bind("click", function () {
        var p = $(this).parent();
        var r = p.find(".review")[0];
        var t = p.find(".review-toggle")[0];
        var e = p.find(".review-ellipses")[0];
        if ($(r).hasClass("hidden")) {
			$(p).removeClass("compact");
            $(r).removeClass("hidden");
            $(e).addClass("hidden");
            $(t).text("Less");
        } else {
			$(p).addClass("compact");
            $(r).addClass("hidden");
            $(e).removeClass("hidden");
            $(t).text("More");
        }
    });

});

