
$.extend({
	loadVeil: function() {
		var new_position = $('#dvCopyrights').offset();
		//$("#veil").css( { "height": ($(document).height()) + "px", "width": "100%" } );
		//$("#veil").css( { "height": ($(window).height()) + "px", "width": "100%" } );
		$("#veil").css( { "height": (new_position.top + 83) + "px", "width": "100%" } );
		$("#veil").show();
	},
	hideVeil: function() {
		$("#veil").css( { "height": "1px", "width": "1px" } );
		$("#veil").hide();
	},
	
	jumpTo: function(compid) {
		var new_position = $('#' + compid).offset();
		window.scrollTo(new_position.left,new_position.top);
	},
	// TOP NAV
	remCartItem: function(btn) {
		//alert($(btn).attr("RecID"))
		window.location = "/cart-process.asp?prc=rmv&id=" + $(btn).attr("RecID")
	}, 
	SignInSuccess: function(cartid) {
		 window.location = "/myaccount.asp?cartid=" + cartid
	},
	
	initLnkTopNav: function(id) {
		var hdnMenuPop = "#MenuTopNav" + id
		var hdnMenuLink = "#lnkTopNav" + id
		$(hdnMenuPop).mouseover(function(e) {
			$(hdnMenuLink).css({"background": "#330000","border": "2px #FFFFFF solid"});
		});
		$(hdnMenuPop).mouseout(function(e) {
			$(hdnMenuLink).css({"background": "none","border": "2px solid transparent"});
		});
		$(hdnMenuLink).mouseover(function(e) {
			$(hdnMenuLink).css({"background": "#330000","border": "2px #FFFFFF solid"});
		});
		$(hdnMenuLink).mouseout(function(e) {
			$(hdnMenuLink).css({"background": "none","border": "2px solid transparent"});
		});
	},
	
	initLnkLeftNav: function(id) {
		var hdnMenuPop = "#Menu" + id
		var hdnMenuLink = "#lnkLeftNav" + id
		$(hdnMenuPop).mouseover(function(e) {
			$(hdnMenuLink).css('background', 'url(/images/grafx/bg_topnav_red.jpg) bottom left');
		});
		$(hdnMenuPop).mouseout(function(e) {
			//if (hdnMenuLink == "#lnkLeftNavBelts") {
			//	$(hdnMenuLink).css('background', ' url(/images/grafx/15off.png) bottom left');
			//} else {
				$(hdnMenuLink).css('background', 'none');
			//}
		});
		$(hdnMenuLink).mouseover(function(e) {
			$(hdnMenuLink).css('background', 'url(/images/grafx/bg_topnav_red.jpg) bottom left');
		});
		$(hdnMenuLink).mouseout(function(e) {
			//if (hdnMenuLink == "#lnkLeftNavBelts") {
			//	$(hdnMenuLink).css('background', ' url(/images/grafx/15off.png) bottom left');
			//} else {
				$(hdnMenuLink).css('background', 'none');
			//}
		});
	
	},
	initTopNav: function(lnk) {
        var hide = false;
		var pos, width, top, left
		var LinkId = "#" + lnk
		var PopUpContainer = $(LinkId).attr("PopUpID")
		var PopUpAlign = $(LinkId).attr("DivAlign")
				
		// Shows the CART ITEMS DIV on hover with a fade in
		$(LinkId).hover(function(){
			if (hide) clearTimeout(hide);
			
			var LinkDiv = $(this).attr("LinkDiv")
			var position = $(this).position();
			
			top = $("#" + LinkDiv).height();
			
			if (PopUpAlign == "r") {
				left = position.left + $('#' + LinkDiv).width() - $('#' + PopUpContainer).width();
				//left = left - parseInt($(this).css("borderLeftWidth"), 10)
				//left = left - parseInt($(this).css("borderRightWidth"), 10)
			} else {
				left = position.left
			}
			
		//	 $("#dvMsg").text(PopUpAlign) 
			$("#" + PopUpContainer).css( { "left": (left) + "px", "top": (top) +  "px" } );
			$("#" + PopUpContainer).fadeIn("fast")	//$("#" + hiddenDiv + "Pop").show();
			$(this).addClass("active");
		}, function() {
            // Fades out the DIV and removes the 'active' class from the main nav menu item
			//hide = setTimeout(function() {$("#hidden-div").fadeOut("fast");});
			//hide = setTimeout(function() {$("#" + PopUpContainer).hide();});
			hide = setTimeout(function() {$("#" + PopUpContainer).fadeOut();});

			$(this).removeClass("active");
        });
				
		// Ensures the DIV displays when your mouse moves away from the main nav menu item
        $("#" + PopUpContainer).hover(function(){
            if (hide) clearTimeout(hide);
            $(LinkId).addClass("active");
        }, function() {
            // If your mouse moves out of the displayed hidden DIV, the DIv fades out and removes the 'active' class
		//	hide = setTimeout(function() {$("#hidden-div").fadeOut("fast");});
			//hide = setTimeout(function() {$("#" + PopUpContainer).hide();});
			hide = setTimeout(function() {$("#" + PopUpContainer).hide();});

			$("#" + PopUpContainer).stop().hide();
			$(LinkId).removeClass("active");
        });
	},
	doSearch: function() {
		if ((jQuery.trim($("#searchterm").val()) == "") || (jQuery.trim($("#searchterm").val()) == "Keyword or Item #")) {
			$("#lblTopNavSearch").text('Please enter keyword');
			return false;
		} else {
			return true;
		}
	},
	isEmail: function(s) {
		var i = 1;
		var sLength = s.length;

		// look for @
		while ((i < sLength) && (s.charAt(i) != "@"))
		{ i++
		}

		if ((i >= sLength) || (s.charAt(i) != "@")) return false;
		else i += 2;

		// look for .
		while ((i < sLength) && (s.charAt(i) != "."))
		{ i++
		}

		// there must be at least one character after the .
		if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
		else return true;

	},
	CoppaTerms: function() {
		// HOMEPAGE NEWSLETTER
		var a;
		var msgHTML;
		var divWidth = 300;
		var divHeight = 200;

		if(!document.getElementById('PopCoppaTerms')) {
			a = document.createElement('DIV');
			a.id = 'PopCoppaTerms';
			document.body.appendChild(a);
		}
		a = document.getElementById('PopCoppaTerms');
		$.loadVeil();
		
		var pTop, pLeft
		pLeft = $(window).scrollLeft() + (($(window).width() - divWidth)/2);
		pTop = $(window).scrollTop() + (($(window).height() - divHeight)/2);

		$("#PopCoppaTerms").css( { "left": (pLeft) + "px", "top": (pTop) +  "px" } );
		$("#PopCoppaTerms").show();

	}, 
	CoppaClose: function() {
		// HOMEPAGE NEWSLETTER
		var veil = document.getElementById('veil');
		if(veil.style.display == 'block') veil.style.display = 'none';

		if(!document.getElementById('dvPoPDiv')) {
			a = document.createElement('DIV');
			a.id = 'dvPoPDiv';
			document.body.appendChild(a);
		}
		a = document.getElementById('PopCoppaTerms');
		a.style.display = 'none';
	},
	CoppaSubmit: function() {
		// HOMEPAGE NEWSLETTER
		$('#slcDobMonth').val($('#slcCppDobMonth').val())
		$('#slcDobDay').val($('#slcCppDobDay').val())
		$('#slcDobYear').val($('#slcCppDobYear').val())
		$("#frmNewsletter").submit();
	}
});


