<!--

function popUp(url, width, height, menubar, name, top, left) 
{
	var strName
	if(!top)
	{
		if(height)
			top = (screen.height / 2 - height / 2);
		else
			top = 50;
	}
	if(!left)
	{
		if(width)
			left = (screen.width / 2 - width / 2);
		else
			left = 100;
	}
	if(name) strName = name; else strName = "popup";
	
	var body;
	var topWin;
	
	if (url.indexOf("?") == -1 && (url.substring(url.length-4).toUpperCase() == ".JPG" || url.substring(url.length-4).toUpperCase() == ".GIF"))
	{
		body = "Javascript: document.write(\"<html><head><style>body{overflow:auto;}</style></head><body><img src='" + url + "'></body></html>\")";
		if(menubar)
			topWin = window.open(body,strName,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);	
		else			
			topWin = window.open(body,strName,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);				
	}
	else if(menubar)
		topWin = window.open(url,strName,'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);					
	else
		topWin = window.open(url,strName,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);				
		
	if(topWin)
		topWin.focus();
}

function copyValueToField(sourceField, iscombo, destField, cbField)
{
    var checked = false;
    
    if (document.forms[0].elements[cbField] != undefined)
    {
        checked = document.forms[0].elements[cbField].checked;
    }
    else
    {
        checked = document.forms[0].elements[cbField + "_0"].checked
    }
    
	if(checked == true)
	{
		if(document.forms[0].elements[destField] != null)
		{
			if(iscombo == false)
			{
				document.forms[0].elements[destField].value = document.forms[0].elements[sourceField].value;
			}
			else
			{
				for(var i=0;i<document.forms[0].elements[sourceField].options.length;i++)
				{
					if(document.forms[0].elements[sourceField].options[i].selected == true)
					{
						document.forms[0].elements[destField].options[i].selected = true;
						break;
					}
				}
					
			}
		}
	}
}

function copyValuesToFields(billingPrefix, shippingPrefix, checkBoxId, shippingDiv, isShowAddressForm)
{
	var form = document.forms[0];
	var billingPageName = "";
	var shippingPageName = "";
	var checked = false;
    
    if (document.forms[0].elements[checkBoxId] != undefined)
    {
        checked = document.forms[0].elements[checkBoxId].checked;
    }
    else
    {
        checked = document.forms[0].elements[checkBoxId + "_0"].checked
    }
    
    // if "ShowShippingAddressForm" in web.config value is false
    if (isShowAddressForm == "False" && checked)
        //document.forms[0].elements[checkBoxId + "_0"] != undefined && document.forms[0].elements[checkBoxId + "_0"].checked)
    {
        $(shippingDiv).style.visibility = "hidden";
    }
    
    // empty shipping address fields when Another Address selected.
    //if (document.forms[0].elements[checkBoxId + "_1"] != undefined && document.forms[0].elements[checkBoxId + "_1"].checked)
    if (checked == false)
    {
        $(shippingDiv).style.visibility = "visible";
		for (j=0; j<form.elements.length; j++)
		{
			shippingPageName = form.elements[j];
			if (shippingPageName.name.indexOf(shippingPrefix) > -1)
			{
				shippingPageName.value = "";
			}
		}
		
		return;
    }
	
	//if (checked == false) return;

	for (i=0; i<form.elements.length; i++)
	{
		billingPageName = form.elements[i];
		if (billingPageName.name.indexOf(billingPrefix) > -1)
		{
		    shippingPageName = form.elements[billingPageName.name.replace(billingPrefix, shippingPrefix)];
		    if (shippingPageName != undefined)
		    {
		        shippingPageName.value = billingPageName.value;
		    }
		}
	}
}

// Show a error message when billing and shipping addresses are different country.
function CheckCanadianShippingAddress(billToAddress, shipToAddress)
{
    var bill = document.forms[0].elements[billToAddress];
    var ship = document.forms[0].elements[shipToAddress];
    
    if (bill.options[bill.selectedIndex].value.length > 0 &&
        ship.options[ship.selectedIndex].value.length > 0 &&
        bill.options[bill.selectedIndex].value.split(",")[1] != ship.options[ship.selectedIndex].value.split(",")[1])
    {
        $('errorMessageForCanadianAddress').innerHTML = "<font class='errormessagelist'>For customers desiring to ship to Canada - Billing and Shipping addresses must be Canadian.<br/><br/></font>";
        cmCreateFormErrorTag(CoremetricsPageId, $('errorMessageForCanadianAddress').innerHTML.stripTags());
        $('errorMessageForAddress').innerHTML = "";
    }
    else
    {
        $('errorMessageForCanadianAddress').innerHTML = "";
        $('errorMessageForAddress').innerHTML = "";
    }
}

function SelectNewCC(fieldName)
{
	if (document.forms[0].elements[fieldName] != null)
	{
		document.forms[0].elements[fieldName].checked = true;
	}
}

function CheckBMLPromotion (raFieldName, cbFieldName)
{
	if (document.forms[0].elements[cbFieldName] != null && document.forms[0].elements[cbFieldName].disabled == false)
	{
		document.forms[0].elements[cbFieldName].checked = true;
	}
}

function addToQuantity(fieldName)
{
	if (! isNaN(document.forms[0].elements[fieldName].value))
		document.forms[0].elements[fieldName].value = parseInt(document.forms[0].elements[fieldName].value) + 1;
}

function deleteFromQuantity(fieldName)
{
	if (! isNaN(document.forms[0].elements[fieldName].value) && parseInt(document.forms[0].elements[fieldName].value) > 1)
		document.forms[0].elements[fieldName].value = parseInt(document.forms[0].elements[fieldName].value) - 1;
}

function searchProducts(fieldName, url)
{
    // If the FootSmart namespace exist, then have it prepare for a new search
    DeleteCookie('LastCUrl');
    if (typeof(FootSmart) != 'undefined')
	{
        FootSmart.PrepareNewSearch();
	}
	
	if (document.forms[0].elements[fieldName] != null && document.forms[0].elements[fieldName].value != "" && 
		trim(document.forms[0].elements[fieldName].value) != "keyword or item #")
	{
		var SearchTerm = escape(document.forms[0].elements[fieldName].value);
		SearchTerm = SearchTerm.replace(/%u2019/g, "%27");  // replace a fancy apostrophe from MS-WORD with a regular apostrophe.
		SearchTerm = SearchTerm.replace(/%5C/g, ""); // remove all '\'
		SearchTerm = SearchTerm.replace(/\//g, "");   // remove all '/'
		SearchTerm = SearchTerm.replace(/\*/g, "");  // remove all * 
		SearchTerm = SearchTerm.replace(/%5E/g, "");  // remove all ^
		SearchTerm = SearchTerm.replace(/^%20+/, "");  // remove all leading spaces
		SearchTerm = SearchTerm.replace(/%20+$/, "");  // remove all trailing spaces
	    
	    if (window.location.search.toLowerCase().indexOf("src=blog") > 0)
	    {   
	        SearchTerm = "*^*" + SearchTerm;
	    }
	
		//Used by Blog since the header is in an iframe
//		if(window.top != window)
//        { 
//    	  parent.location = url + "?searchterm=" + SearchTerm;
//    	}

		if(SearchTerm.length >0)
		{
			if (url != null && url.length > 0)
			{
				parent.location = url + "?searchterm=" + SearchTerm;
			}
			else
			{
				if (document.URL.indexOf("https:") == -1)
					parent.location = "SearchReturns.aspx?searchterm=" + SearchTerm;	
				else
					parent.location = "http://www.footsmart.com/SearchReturns.aspx?searchterm=" + SearchTerm;
			}
		}						
	}
}

function KeyPressFunction(buttonType, e, url)
{
	var eKey;
	
	if(document.all) 
		eKey = window.event.keyCode; 
	else
		eKey = e.which; 
	
	if (eKey == 13) 
	{ 
		if (buttonType == "Login")
		{
			document.forms[0].loginButton.click(); 
			event.returnValue = false;
		}
		else if (buttonType == "siteHeader_addEmailGo")
		{
			var someButton = document.getElementById(buttonType);
			someButton.focus();
			someButton.click();
		}
		else
		{
			if (url != null)
			{
				document.forms[0].action = "javascript:searchProducts('" + buttonType + "', '" + url + "');";
			}
			else
			{
				document.forms[0].action = "javascript:searchProducts('" + buttonType + "');";
			}

			document.forms[0].submit();
		}
	}
}

function LoginKeyPress(keyName, e)
{
	if (e.keyCode == 13) 
	{
		var btnLogin = document.getElementById(keyName);
		btnLogin.focus();
		btnLogin.click();
	}
}

/*
function imageClickSubmit(useName)
{
	var form = document.forms[0];
	var xName = useName + ".x";
	var yName = useName + ".y";
	if(!form.elements[xName] && !form.elements[yName])
	{
		var el = document.createElement("INPUT");
		el.type="hidden";
		el.name=xName;
		el.id=xName;
		el.value="5"; // whatever
		form.appendChild(el);
		el = document.createElement("INPUT");
		el.type="hidden";
		el.name=yName;
		el.id=yName;
		el.value="8"; // idem
		form.appendChild(el);
		form.submit();
	}
	return true;
} */

function SwitchMenu(objId){
	if(document.getElementById)
	{
		var el = document.getElementById('sub'+objId);		
		var smc = document.getElementById("cont"); // Side menu content
		if(smc != 'undefined' && smc != null) {
		    var ar = smc.getElementsByTagName("DIV");
		    if(el != 'undefined' && el != null){
		        // Hide all open navs first
			    for (var i=0; i<ar.length; i++)
			    {
				    if(ar[i].className == "submenu")
				    {
					    ar[i].style.display = "none";
				    }
			    }
    			
			    // RWilliams
			    if(el.style.display == "none"){
			        el.style.display = "block";
			    }
    			
			    //
			    ChangeClass('menu'+objId,'menuSelected');
    			
			    // RWilliams - 08/21/2009: Save the menu id that just got expanded
		        SetCookie("pmnuid", objId);
		    }	
		}
	}
}

function ChangeClass(menu, newClass) { 
	if (document.getElementById) { 
	 	document.getElementById(menu).className = newClass;
	} 
} 

function ResetDropDowns(dropDownName) {
	var i;
	for(i=0;i<document.forms[0].length;i++) {
		if(document.forms[0].elements[i].type == "select-one") {
			if(document.forms[0].elements[i].name != dropDownName)
				document.forms[0].elements[i].selectedIndex = 0;
		}
	}
}

function GetCookie (name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;  
	while (i < clen) 
	{
		var j = i + alen;

		if (document.cookie.substring(i, j).toUpperCase() == arg.toUpperCase())
		{
			return unescape(getCookieVal(j));
		}

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) break;
	}

	return null;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie (name, value, dateOffset, OffsetInterval, cookieDomain) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = "/";

	nDate = new Date();				
	if(dateOffset!=null)
	{				
		nDate = dateAdd(nDate, OffsetInterval, dateOffset);
	}
		
	document.cookie = name + "=" + escape (value) + "; path=" + path + ((cookieDomain) ? "; domain=" + cookieDomain : "") +
		((expires == null) ? "" : ("; expires=" + nDate.toUTCString()));

}

function DeleteCookie (name) {
	var days = -1;
	var value = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function dateAdd( start, interval, number ) 
{
	// get the milliseconds for this Date object. 
	var buffer = Date.parse( start ) ;
	// what kind of add to do? 
	switch (interval.charAt(0))
	{
		case 'd': case 'D': 
			number *= 24 ; // days to hours
			// fall through! 
		case 'h': case 'H':
			number *= 60 ; // hours to minutes
			// fall through! 
		case 'm': case 'M':
			number *= 60 ; // minutes to seconds
			// fall through! 
		case 's': case 'S':
			number *= 1000 ; // seconds to milliseconds
			break ;
		default:				       						
			return null ;
	}
	return new Date( buffer + number ) ;
}

function GetSourceByReferrer(docRef)
{
	var srccode = '';

	if(docRef.indexOf("google") != -1)
		srccode = "YNGONB";
	else if(docRef.indexOf("yahoo") != -1)
		srccode = "YNYHNB";
	else if(docRef.indexOf("msn") != -1)		// msn
		srccode = "YNMSNB";
	else if(docRef.indexOf("live.com") != -1)	// live.com and msn are synonymous
		srccode = "YNMSNB";
	else if(docRef.indexOf("ask") != -1)
		srccode = "YNASNB";		
	else
		srccode = "IFS";

	// alert('docRef: ' + docRef + '\nsrccode: ' + srccode + '\nDetermineSourceBranding(): ' + DetermineSourceBranding(docRef, srccode));

	return DetermineSourceBranding(docRef, srccode);
}

function DetermineSourceBranding(docRef, srccode)
{
	var updatedSourceCode = srccode;
	
	if(srccode != "IFS")
	{
		var footMatch = /foot|Foot/g.test(docRef);
		var feetMatch = /feet|Feet/g.test(docRef);
		var smartMatch = /smart|Smart/g.test(docRef);
		var benchMatch = /bench|Bench/g.test(docRef);
		var markMatch = /mark|Mark/g.test(docRef);

		if(((footMatch || feetMatch) && smartMatch) || (benchMatch && markMatch))
		{
			updatedSourceCode = srccode.substring(0,4) + 'B';
		}
		//else
		//{
			//updatedSourceCode += 'NB';
		//}

		/*

		alert('' +
			'updatedSourceCode: ' + updatedSourceCode + '\n\n' + 
			'footMatch: ' + footMatch + '\n' +
			'feetMatch: ' + feetMatch + '\n' +
			'smartMatch: ' + smartMatch + '\n' +
			'benchMatch: ' + benchMatch + '\n' +
			'markMatch: ' + markMatch +
			'');

		*/
	}

	return updatedSourceCode;
}

function SourceCodeClientSideSet()
{
	// Prepare For SearchIgnite
	HandleSearchIgniteUrl();

	// Do other stuff
	QueryString_Parse();
	var cookieVal = GetCookie('FootSmart_Source');

	if(QueryString("srccode") != "" && QueryString("srccode") != null)
	{
		srcCode = QueryString("srccode");
		SetCookie('FootSmart_Source',srcCode,null,null);
		SetCookie('Original_Source',srcCode,null,null);
		SetCookie('sourcetype',srcCode,null,null);
		DeleteCookie('promotion_deleted');
	}
	else if (cookieVal == null || cookieVal == "")
	{
		var ns = GetSourceByReferrer(document.referrer);
		SetCookie('FootSmart_Source',ns,null,null);
		SetCookie('Original_Source',ns,null,null);
		SetCookie('sourcetype',ns,null,null);
	}
}

function HandleSearchIgniteUrl()
{
	// Is it a search ignite url?
	var oSourceCode = GetCookie('Original_Source');
	var qSourceCode = QueryString('srccode');
	
	if(qSourceCode != "" && qSourceCode != null)
	{
		if(qSourceCode == oSourceCode
			&& QueryString("sessguid")!="" && QueryString("sessguid")!=null
			&& QueryString("userguid")!="" && QueryString("userguid")!=null
			&& QueryString("permguid")!="" && QueryString("permguid")!=null)
		{
			SetCookie('si-sessguid', QueryString("sessguid"), null, null, null);
			SetCookie('si-userguid', QueryString("userguid"), null, null, null);
			SetCookie('si-permguid', QueryString("permguid"), null, null, null);
		}else{
			// Wipe Clean
			DeleteCookie('si-sessguid');
			DeleteCookie('si-userguid');
			DeleteCookie('si-permguid');
					
			// 
			if(QueryString("sessguid")!="" && QueryString("sessguid")!=null
				&& QueryString("userguid")!="" && QueryString("userguid")!=null
				&& QueryString("permguid")!="" && QueryString("permguid")!=null)
			{	
				// Save Again
				SetCookie('si-sessguid', QueryString("sessguid"), null, null, null);
				SetCookie('si-userguid', QueryString("userguid"), null, null, null);
				SetCookie('si-permguid', QueryString("permguid"), null, null, null);
			}
		}
	}
}

function ChangeSourceCodeClick(modifier)
{
	var cookieVal = GetCookie('FootSmart_Source');
	if(cookieVal!=null && cookieVal!="")
	{
		cookieVal = cookieVal.substring(0, cookieVal.length - 1) + modifier; 
		SetCookie('FootSmart_Source',cookieVal,null,null);
		SetCookie('sourcetype',cookieVal,null,null);
	}	
}

function QueryString(key)
{
	var value = null;
	
	if(QueryString != null && QueryString.keys) 
	{
	    for (var i=0;i<QueryString.keys.length;i++)
	    {
		    if (QueryString.keys[i].toUpperCase() == key.toUpperCase())
		    {
			    value = unescape(QueryString.values[i]);
			    break;
		    }
	    }
	}

	return value;
}

function QueryString_Parse(pa)
{	
	if (pa == null) pa = window.location.search;

	var query = pa.substring(1);
	var pairs = query.split("&");
	QueryString.keys = new Array();
	QueryString.values = new Array();
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}
}

function getLeft(arg) {
	xPos = arg.offsetLeft;
	ParentPos = arg.offsetParent;
	while (ParentPos != null) 
	{
		xPos += ParentPos.offsetLeft;
		ParentPos = ParentPos.offsetParent;
	}
	return xPos;
}

function getTop(arg) {
	yPos = arg.offsetTop;
	ParentPos = arg.offsetParent;
	while (ParentPos != null) 
	{
		yPos += ParentPos.offsetTop;
		ParentPos = ParentPos.offsetParent;
	}
	return yPos;
}

function rtrim(argvalue) 
{
	while (1) 
	{
	if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
		break;
		argvalue = argvalue.substring(0, argvalue.length - 1);
	}	
	return argvalue;
}
	
	
function ltrim(argvalue) 
{
	while (1) 
	{
		if (argvalue.substring(0, 1) != " ")
			break;
			argvalue = argvalue.substring(1, argvalue.length);
	}

	return argvalue;
}

function trim(argvalue) 
{
	var tmpstr = ltrim(argvalue);
	return rtrim(tmpstr);
}

function SecureRedirectExitPopupCheck()
{
	var IsSecure = GetCookie("IsSecure");
	if(IsSecure==null || IsSecure=="")
		SetCookie("IsSecure","0",null,null);
	if(PageName.Name =="ORDERREGISTRATION" || PageName.Name=="ORDERADDRESSINFORMATION" || PageName.Name=="ORDERSHIPPINGMETHOD" || PageName.Name =="ORDERREVIEW")					
		SetCookie("IsSecure","1",null,null);				
	else
		SetCookie("IsSecure","0",null,null);										
}

function EmailTracking()
{QueryString_Parse();var tId = QueryString("fs_t");if(tId!=null){var eImg=new Image();eImg.src="http://www.footsmart.com/Email/GeneralTracking.asp?fs_t=" + QueryString("fs_t") + "&fs_l=" + QueryString("fs_l");}}

// JAC - 1/22/2010 - Disable the Atlas One pixel
//function SetAtlasOnePoint()
//{
//	QueryString_Parse();var gtse=QueryString("gtse");var gtse_upper=QueryString("GTSE");var gcid=QueryString("gcid");var gcid_upper=QueryString("GCID");
//	if((gtse_upper!=null&&gtse_upper!=""&&gtse_upper!=0)||(gtse!=null&&gtse!=""&&gtse!=0)||(gcid!=null&&gcid!=""&&gcid!=0)||(gcid_upper!=null&&gcid_upper!=""&&gcid_upper!=0))
//	{SetCookie("FootSmart_AtlasOnePoint",1,7,'d');
//	var CartId = GetCookie('ASP.NET_SessionId');
//	if (CartId == null)
//	{
//		var localcId = GenerateRandomStr(32);
//		SetCookie('ASP.NET_SessionId',localcId, 7, 'd');
//		CartId = localcId;
//	}
//	var nImg = new Image();
//	nImg.src = "http://track.roiservice.com/track/pixel.gif.aspx?roiid=933771107377119&desc=landingPage&sid=" + CartId;
//	}
//}

function FindAndSetFocusOnControl(name)
{
	var obj = null;
	
	if (document.getElementById)
	{
		obj = document.getElementById(name);
		if (obj != null) obj.focus();
	}
	else if (document.all)
	{
		obj = document.all[name];
		if (obj != null) obj.focus();
	}
	else if (document.layers)
	{
		obj = document.layers[name];
		if (obj != null) obj.focus();
	}	
}

// Display banners.
function loadImage(imgName) 
{
	if (document.images[imgName])
	{
		var index = getRandomNumber();
		randomNumber = index;
		if(document.images[imgName])
		{
			document.images[imgName].src = bannerArray[index];
			document.images[imgName].alt = bannerAltArray[index];
			document.images[imgName].height = bannerHeightArray[index];
			document.images[imgName].width = bannerWidthArray[index];
		}		
	}
}

function loadImageUrl()
{
	if (bannerUrlArray[randomNumber] != '')
	{
		if (document.forms[0].productCategoryIdHidden != null)
		{
			SetCookie("CM_Category", document.forms[0].productCategoryIdHidden.value, null, null);
		}
		document.location.href = bannerUrlArray[randomNumber];
	}
}

function getRandomNumber()
{
	var randscript = -1;
	var howMany = bannerArray.length-1;
	if (bannerArray.length > 0)
	{
		while (randscript < 0 || randscript > howMany || isNaN(randscript))
		{
			randscript = parseInt(Math.random()*(howMany+1));
		}
	}
	return randscript;
}

function ViewTemporarilyOutOfStock()
{
	popUp("TemporarilyOutOfStockPopup.aspx",400,250);
}

function setPriceDisplay(langString, onSearchPage, url)
{
	var cookieVal = GetCookie("pricedisp");
	var isCanadian = false;

	//see what the current cookie value is
	if(cookieVal != null)
	{
		if(cookieVal == "ca")
			isCanadian = true;
		else
			isCanadian = false;
	}
	else
	{
		if(langString.indexOf("-CA") != -1)
			isCanadian = true
	}
	
	//if Canadian, set to US prices, otherwise set to Canadian prices
	if(isCanadian)
		cookieVal = "us";
	else
		cookieVal = "ca";
	
	SetCookie("pricedisp", cookieVal, null, null);
	
	if (onSearchPage != null && onSearchPage == "true")
	{
	    // go get a search result
	    // Hwa Son 7/1/2008
	    QueryString_Parse();
		var page = QueryString("page");
		if (page != null && page.length > 0)
		{
		    SubmitData("Action=4&Page=" + page);
		}
		else
		{
		    SubmitData("Action=4&Page=0");
		}
	}
	else
	{		
	    //refresh the browser
	    if (url != null && url.length > 0)
	    {
		    window.location = url;
	    }
	    else
	    {
		    window.location = window.location;
	    }
    }
}

function ClearDefault(el) {
  if (el.defaultValue==el.value) el.value = "";
}

function addbookmark()
{
	bookmarkurl="http://www.footsmart.com/"
	bookmarktitle="FootSmart :: Comfortable Walking Shoes & Foot Pain Products for Heel Pain, Back Support & Foot Problems, Comfort Footwear"
	if (document.all)
	{
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
	}
	else
	{
	    window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
	}
}

// for the address pick list.
function ChangeAddress()
{
	var form = document.forms[0];
	var pageName = "";
	var addr;
	
	for (var k=0; k<form.elements.length; k++)
	{
		pageName = form.elements[k];
		if (pageName.name.toLowerCase().indexOf("ddpicklist") > -1)
		{
			addr = pageName.options[pageName.options.selectedIndex].value.split('|');
		}
		if (pageName.name.indexOf("sameShippingCheckbox") > -1 || pageName.name.indexOf("shippingAddressChoice") > -1)
		{
			if (pageName.checked)
			{
				CopyValue(form, addr, "billToAddress");
			}
			CopyValue(document.forms[0], addr, "shipToAddress");
		}
	}
	
	var redMessage = document.getElementById("redMessage");
	var greenMessage = document.getElementById("greenMessage");
	
	//if (redMessage != null)
	//	redMessage.style.display = "none";
	if (greenMessage != null)
	{
		cmCreateFormErrorTag(CoremetricsPageId, greenMessage.innerHTML.stripTags());
		greenMessage.style.display = "block";
	}

	return true;
}

function CopyValue(form, addr, prefix)
{
	var j=0;
	for (var i=0; i<form.elements.length; i++)
	{
		if (form.elements[i].name.indexOf(prefix) > -1)
		{
			if (form.elements[i].name.indexOf("streetTextBox") > -1)
			{
				form.elements[i].value = addr[0];
			}
			if (form.elements[i].name.indexOf("suiteTextBox") > -1)
			{
				form.elements[i].value = addr[1];
			}
			if (form.elements[i].name.indexOf("cityTextBox") > -1)
			{
				form.elements[i].value = addr[2];
			}
			if (form.elements[i].name.indexOf("stateProvinceDropDownList") > -1)
			{
				for (j=0; j<form.elements[i].options.length; j++)
				{
					if (form.elements[i].options[j].value == addr[3])
					{
						form.elements[i].options[j].selected = true;
						break;
					}
				}
			}
			if (form.elements[i].name.indexOf("zipTextBox") > -1)
			{
				form.elements[i].value = addr[4];
			}
		}
	}
	return;
}

function ChangeAddressForCatalogRequest()
{
	var form = document.forms[0];
	var pageName = "";
	var addr;
	
	for (var k=0; k<form.elements.length; k++)
	{
		pageName = form.elements[k];
		if (pageName.name.toLowerCase().indexOf("ddpicklist") > -1)
		{
			addr = pageName.options[pageName.options.selectedIndex].value.split('|');
		}
		
		if (pageName.name.indexOf("streetTextBox") > -1)
		{
			pageName.value = addr[0];
		}
		if (pageName.name.indexOf("suiteTextBox") > -1)
		{
			pageName.value = addr[1];
		}
		if (pageName.name.indexOf("cityTextBox") > -1)
		{
			pageName.value = addr[2];
		}
		if (pageName.name.indexOf("stateProvinceDropDownList") > -1)
		{
			for (j=0; j<pageName.options.length; j++)
			{
				if (pageName.options[j].value == addr[3])
				{
					pageName.options[j].selected = true;
					break;
				}
			}
		}
		if (pageName.name.indexOf("zipTextBox") > -1)
		{
			pageName.value = addr[4];
		}
	}
	
	return true;
}

/// To send manual Coremetrics tags
/// Hwa Son  1/3/2008
/// being Used for ShopByAilment and HealthFact user controls.
function OnChangeHealthFacts(dd, href)
{
	ResetDropDowns(dd.name);
	
	QueryString_Parse(href);
	//cmCreateManualImpressionTag(GlobalCoremetricsPageId, QueryString("cm_sp"), null);
	cmCreateManualLinkClickTag(href);
	
	// pass the control name in order to congregate all of the link click counts from the object.
	cmCreateManualLinkClickTag("/" + dd.id);
	
	window.location = href;
}

/// Hwa Son 6/12/2008
/// For the search pages.
function ContentSwitch(div1Name, div2Name, tableName)
{
    var div1 = document.getElementById(div1Name);
    div1.style.visibility = "visible";
    
    var div2 = document.getElementById(div2Name);
    div2.style.visibility = "hidden";

    var tblCondition = document.getElementById(tableName);
    
    if (tblCondition != null)
    {
        tblCondition.style.height = div1.offsetHeight;
    }
}

function cleanTextField(evt)
{
	var emailField = document.getElementById('textNewsletterSignup');
    if (evt == 'onfocus' && emailField.value == 'Enter Email Address'){emailField.value = '';}
	if (evt == "onblur" && emailField.value == ''){emailField.value = 'Enter Email Address';}
}

function newsSignUp()
{
	var link = 'NewsLetterSignUp.aspx?cm_sp=Newsletter-_-SignUp-_-Bottom';
	var emailField = document.getElementById('textNewsletterSignup');

	if(emailField.value != 'Enter Email Address' && emailField.value.length > 0)
	{
		link += '&signupaddr=' + emailField.value;
	}
  
    if (!checkEmail(emailField.value)) {
        alert("Please provide a valid email address");
    }
    else 
    {
        //This is not in a frame
        if(window.top == window)
        { 
    	    document.location.href = link;
    	}
    	else
    	{
    	    //top.location.href = link;
    	    parent.location.href = link;
    	}
    	
    }
}

function checkEmail(emailaddress) 
{
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(emailaddress)) 
    {
        return false;
    }
    else {return true;}
}

// Generic Session Cookie
// Created on 1/7/2009 By Hwa Son
// To use for all of client side session cookies.
// It has to be a name=value pair with ; at the end. (example: CookieName=CookieValue;)

// Please add here if you have a new name value pair to this cookie, so a name won't be used for a different use.
// Hwa Son on 1/7/2009: FootSmart_PopUp=BuyUp;
function GetGenericSessionCookie(name)
{
    var cookieName = "FSGeneric";
    var cookie = GetCookie(cookieName);
    var retValue = "";
    var pair;

    if (cookie == null || cookie.length == 0) return retValue;
    
    var cookieValues = cookie.split(";");
    for (var i = 0; i<cookieValues.length; i++)
    {
        pair = cookieValues[i].split("=");
        
        if (pair.length == 2 && pair[0].toLowerCase() == name.toLowerCase())
        {
            retValue = pair[1];
            break;
        }
    }
    
    return retValue;
}

function SetGenericSessionCookie(name, value)
{
    var cookieName = "FSGeneric";
    var cookie = GetCookie(cookieName);
    if (cookie == null || cookie == "")
    {
        cookie = "";
    }
    else
    {
        var existingValue = GetGenericSessionCookie(name);
        if (existingValue.length > 0)
        {
            RemoveGenericSessionCookie(name);
            cookie = GetCookie(cookieName);
        }
    }
    
    SetCookie(cookieName, cookie + name + "=" + value + ";");
}

function RemoveGenericSessionCookie(name)
{
    var cookieName = "FSGeneric";
    var cookie = GetCookie(cookieName);
    var pair;
    var i=0;

    if (cookie == null || cookie.length == 0) return;
    
    var cookieValues = cookie.split(";");
    
    if (cookieValues.length > 0)
    {
        cookie = "";
        for (i = 0; i<cookieValues.length; i++)
        {
            pair = cookieValues[i].split("=");
            if (pair.length == 2 && pair[0].toLowerCase() != name.toLowerCase())
            {
                cookie += cookieValues[i] + ";";
            }
        }
        SetCookie(cookieName, cookie, null, null);
    }
    else
    {
        DeleteCookie(cookieName);
    }
    
    return;
}

function GetBrowserSizeWidth()
{
    var width = 0;

    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape")
        {
            width = window.innerWidth;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1)
        {
            width = document.body.offsetWidth;
        }
    }
    return width;
}

function GetBrowserSizeHeight()
{
    var height = 0;

    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape")
        {
            height = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1)
        {
            height = document.body.offsetHeight;
        }
    }

    return height;
}

// For links on the search page.
// re-form query strings and reload page.
function SubmitData(sDataParams, answerText)
{
	var sData = "";

	if (!SubstringExists(sDataParams,"SH=")) {
	    var SH = document.forms[0].elements['searchResults_iptSH'].value;

	    // RWilliams - Quick patch to fix back button issue and pricing change
	    // If there is no SH then we need to do a whole new search
	    // If we don't have a search handle just do a new search - FootSmart.Destroy();
	    if(SH == null || SH.length <= 0){
	        window.location.reload();
	        return;		        
        }
	        
		sData = "SH=" + SH + "&";			
    }
		
	if (!SubstringExists(sDataParams,"SI=")) 
		sData += "SI=" + document.forms[0].elements['searchResults_iptSI'].value + "&";
		
	if (!SubstringExists(sDataParams,"LAP=")) 
		sData += "LAP=" + document.forms[0].elements['searchResults_iptLAP'].value + "&";
	
	sData += sDataParams;
	
	// add a cid query string
	// Hwa Son 3/12/2009
	var params = $H(sData.toQueryParams());
    if(params.get('cid') != undefined && params.get('cid').length > 0)
    {
        if (answerText != null && answerText.length > 0)
        {
            var aWord = answerText.split(" ");
            var cid = params.get('cid');
            var newCid = "";
            
            // remove the search count part
            if (aWord.length > 1)
            {
                for (i=0; i<aWord.length-1; i++)
                {
                    newCid += aWord[i];
                }
            }

            // extract special characters except .(dot)
            newCid = newCid.replace(/([^a-zA-Z0-9\.])+/g, "");
           
            params.set('cid', cid + newCid);
        }
        else
        {
            params.unset('cid');
        }
    }
    sData = params.toQueryString();

	if (CoremetricsPageId == "Search Box")
    	window.location="SearchReturns.aspx?" + sData;
    else if (CoremetricsPageId == "Product Brand Search")
    	window.location="SearchReturnsBrands.aspx?" + sData;
    else window.location = "?" + sData;
    //window.location = "?" + sData;
}

function SubstringExists(sLookIn, sLookFor)
{
	return (sLookIn.toUpperCase().indexOf(sLookFor.toUpperCase()) >= 0)
}

// JLH - 12/10/2009 these functions are to support the productPurchaseTool functions
// and howToMeasure

function hideProductPurchaseTool() {
    document.getElementById('divHowToMeasure').style.visibility = "hidden";
}
function showProductPurchaseTool() {
    var left = (document.body.clientWidth-460) / 2;                
    document.getElementById('divHowToMeasure').style.left = left;
    document.getElementById('divHowToMeasure').style.visibility = "visible";

    coremetrics.ConversionEventTagWithAttributes(2, "How To Measure");
    cmCreatePageviewTag('How To Measure Pop-Up', null, 'Popup', null);
}
function pptReturnSizeWidthColor(colorId, sizeId, widthId, colorSwatch) {
    
    //setProductSizeWidthColor(colorId, sizeId, widthId, colorSwatch);
    if ($('topProductBuyDetail_ddSizeId')) {
            setProductSize(sizeId, 'topProductBuyDetail_ddSizeId');
            $('topProductBuyDetail_ddSizeId').simulate('change');
        }
    if ($('topProductBuyDetail_kitSize_0')) {
            setProductSize(sizeId, 'topProductBuyDetail_kitSize_0');
            $('topProductBuyDetail_kitSize_0').simulate('change');
        }
    if ($('topProductBuyDetail_kitSize_1')) {
            setProductSize(sizeId, 'topProductBuyDetail_kitSize_1');
            $('topProductBuyDetail_kitSize_1').simulate('change');
        }
    if ($('topProductBuyDetail_kitSize_2')) {
            setProductSize(sizeId, 'topProductBuyDetail_kitSize_2');
            $('topProductBuyDetail_kitSize_2').simulate('change');
        }

    hideProductPurchaseTool();
}

//-->