function checkKey(reg,e)
{
	var nKey = e.which;
	var sKey = String.fromCharCode(nKey);
	if(nKey == 0 || nKey == 8 || nKey == 13)
		return true;
		
	var re = new RegExp(reg);
	return (sKey.match(re) == null);
}

function showMap()
{
	swfobject.embedSWF("swf/map.swf", "fl_map", "790", "380", "9.0.0", "swf/expressInstall.swf", {},{wmode:'transparent',base:'swf/'});
}


function setMenuSection(section)
{
	$(document).ready(function(){
		$("#header .menu>a").removeClass("selected");
		$("#header .menu>a[href=/"+section+"]").addClass("selected");
		
		$("#footer .menu div>a").removeClass("selected");
		$("#footer .menu div>a[href=/"+section+"]").addClass("selected");
	});
}

function setZipCodeSearch(productName)
{
	$(document).ready(function(){
		if($(".zip_code_box").length > 0)
		{
			var sVal = $(".zip_code_box .zip_text").val();
			var re = new RegExp(/\d/g);
			if(sVal.match(re) == null || sVal.length != 5)
				$(".zip_code_box .zip_button").addClass("disabled");
			$(".zip_code_box .zip_text").attr("maxlength","5");
			$(".zip_code_box .zip_text").keyup(function(){
				if($(this).val().length == 5)
					$(this).parents(".zip_code_box").find(".zip_button").removeClass("disabled");
				else if(!$(this).parents(".zip_code_box").find(".zip_button").hasClass("disabled"))
					$(this).parents(".zip_code_box").find(".zip_button").addClass("disabled");
			});
			$(".zip_code_box .zip_text").keypress(function(e){
				if(e.which == 13)
				{
					$(this).parents(".zip_code_box").find('.zip_button').click();
					return true;
				}
				return checkKey(/\D/,e);
			});
			$('.zip_code_box .zip_text').focus(function(){
				var textDefault = $(this).parents(".zip_code_box").find(".defaultValue").html();
				if($(this).val() == textDefault){
					$(this).val("");
				}
			});
			$('.zip_code_box .zip_text').blur(function() {
				var textDefault = $(this).parents(".zip_code_box").find(".defaultValue").html();
				if ($(this).val() == '') {
					$(this).val(textDefault);
				}
			});
			$('.zip_code_box .zip_button').click(function() {
				var textDefault = $(this).parents(".zip_code_box").find(".defaultValue").html();
				var val = $(this).parents(".zip_code_box").find(".zip_text").first().val();
				if(val.length < 5 || val == textDefault) return false;
				val = (val != "" && val != textDefault)?("?ZipCode="+val):"";
				if(productName != null) val = val + ((val.indexOf("?") < 0)?"?":"&") + "product="+productName;
				//dcsMultiTrack('DCS.dcssip','www.kleenex.com','DCS.dcsuri','/ProductLocator.aspx','WT.ti','ProductLocator','WT.dl','40','WT.si_n','KLE_conv8','WT.si_x','1','WT.si_cs','');
				location.href= "ProductLocator.aspx"+val;
				return false;
			});
		}
	});
}
/** Set Content and SubContent Groups **/
function getContentGroup(isLanding)
{
	links = $("#navigation a");
	if(links.length > 0)
	{		
		return (links.length > 2 || isLanding)?$(links[1]).html():$(links[0]).html();
	}
	else
	{
		return "home"
	}
}
function getSubContentGroup(isLanding)
{
	links = $("#navigation a");
	if(links.length > 2)
	{	
		var sGroup = $(links[2]).html();
		if(links.length > 3)
			sGroup += ": "+$(links[3]).html();
		return sGroup;
	}
	else if(!isLanding && links.length > 1)
	{
		return $(links[1]).html();
	}
	else
	{
		return "landing";
	}
}
function setWTTags(oTags)
{
	var sContent = null;
	var sSubContent = null;
	if(oTags != null)
	{
		if(oTags.content) sContent = oTags.content;
		if(oTags.subcontent) sSubcontent = oTags.subcontent;
	}
	if(sContent == null) sContent = getContentGroup(oTags != null && oTags.isLanding);
	if(sSubContent == null) sSubContent = getSubContentGroup(oTags != null && oTags.isLanding);
	
	sContent = sContent.toLowerCase();
	sSubContent = sSubContent.toLowerCase();
	if($("meta[name=WT.cg_n]").attr("content") == "") $("meta[name=WT.cg_n]").attr("content",sContent);
	if($("meta[name=WT.cg_s]").attr("content") == "") $("meta[name=WT.cg_s]").attr("content",sSubContent);
	
	if(sContent == "products" && sSubContent != "landing")
	{
		$("meta[name=WT.pn_sku]").attr("content",sSubContent);
		$("meta[name=WT.pi]").attr("content",sSubContent);
	}
}
function getLinkName(shref)
{
	if(shref == null || shref == "" || shref[0] == "#" || shref.indexOf("javascript") >= 0) return null;
	if(shref == "/") return "home";
	var sLinkName = null;
	var ahref = shref.split("/");
	if(ahref.length > 1)
	{
		if(ahref[ahref.length-1] != "")
			sLinkName = ahref[ahref.length-1];
		else 
			sLinkName = ahref[ahref.length-2];
	}
	else sLinkName = ahref[0];
	
	ahref = sLinkName.split(".");
	if(ahref > 1) sLinkName = ahref[ahref.length-2];
	else sLinkName = ahref[0];
	
	return sLinkName;
}
function doTrackLinks()
{
	var sLinkType = "Body";
	if($(this).parents("#header").length > 0) sLinkType = "TopNav";
	else if($(this).parents("#footer").length > 0) sLinkType = "BottomNav";
	
	var sLinkName = getLinkName($(this).attr("href"));
	if(sLinkName != null && sLinkName != "")
	{	
		dcsMultiTrack('DCS.dcssip','www.kleenex.com','DCS.dcsuri','/LinkTracking.aspx','WT.ti','LinkTracking','WT.dl','40','WT.z_ll',sLinkType,'WT.z_ln',sLinkName);
	}
}
$(document).ready(function(){
	$("a").bind("click",doTrackLinks);
});

