function gotoFunction() {
	self.location = document.dropdown_form.dropdown_list.options[document.dropdown_form.dropdown_list.selectedIndex].value;
}
function reset() {
	document.dropdown_form.reset()
}

function URLEncode(clearString) {
	var output = '';
	var x = 0;
	clearString = clearString.toString();
	var regex = /(^[a-zA-Z0-9_.]*)/;
	while (x < clearString.length) {
		var match = regex.exec(clearString.substr(x));
		if (match != null && match.length > 1 && match[1] != '') {
			output += match[1];
			x += match[1].length;
		} else {
			if (clearString[x] == ' ')
				output += '+';
			else {
				var charCode = clearString.charCodeAt(x);
				var hexVal = charCode.toString(16);
				output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
			}
			x++;
		}
	}
	return output;
}

function keywordSubmit() {
	if (document.keywordSearch.keyword.value != 'Enter Keyword') {
	document.keywordSearch.submit();
	}
}
	
function keywordURLIISubmit(URLIIEnabled) {
	if (document.keywordSearch.keyword.value != 'Enter Keyword') {
		if (URLIIEnabled.toLowerCase() == 'true')	
			{ document.keywordSearch.keyword.value = URLEncode(document.keywordSearch.keyword.value); }
		document.keywordSearch.submit();
		}
}
function prodNumSubmit() {
	if (document.prodNumberSearch.txtItemSku.value != 'Enter Product #') {
	document.prodNumberSearch.submit();
	}
}
window.onloadListeners=new Array();
window.addOnLoadListener=function(listener){
	window.onloadListeners[window.onloadListeners.length]=listener;
}
window.onload=function(){
	for(var i=0;i<window.onloadListeners.length;i++){
		var func=window.onloadListeners[i];
		if(func) func.call();
	}
}
function createCookie(name,value,days)
{
	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 readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}
function addclass(obj, className)
{
	if(!obj.className) return;
	if (! containsclass(obj, className))
		obj.className += " " + className;
		
	debugMsg("added class " + obj.className);
}

function removeclass(obj, className)
{
	if(!obj.className) return;
	var clzs = obj.className.split(" ");
	var nc = "";
	for (var i = 0; i < clzs.length; i++)
	{
		if (className != clzs[i])
		{
			if (nc.length > 0) nc += " ";
			nc += clzs[i];
		}
	}
	obj.className = nc;
}
function containsclass(obj, className)
{
	if(!obj.className) return false;
	var clzs = obj.className.split(" ");
	for (var i = 0; i < clzs.length; i++)
	{
		if (className == clzs[i])
			return true;
	}		
	return false;
}

function openBMLWindow(url,height) {
        var iwidth=500, iheight=height;
        popUpWin =window.open(url,'NewWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width='+(iwidth+15)+',height='+(iheight+40));
}

/*****************************************************
	shipping/billing address functions
*****************************************************/

function isUSCountry(country) {
	return (country == "US" || isUSTerritory(country));
}

function indexForDropdownValue(obj, value) {
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].value == value) return i;
	}
	return null;
}


function checkContigState(country,state, doCheck){
		if (doCheck == 1)
		{
			if (country.value != 'US')
				{ document.getElementById("LoyaltyShipMessage").style.display		= ""; }
			else if (country.value == 'US' && state.value == '')	
				{ document.getElementById("LoyaltyShipMessage").style.display		= "none"; }
			else if (country.value == 'US' && isUSContigState(state.value))	
				{ document.getElementById("LoyaltyShipMessage").style.display		= "none"; }
			else 
				{ document.getElementById("LoyaltyShipMessage").style.display		= "";}	
		}
				
}
		
function syncCountryStateValues(country, state, blnCountryChanged) {
	var intSelectedIndexValue = 0;
	var intChangedObjectValue = 0;
	
	if (blnCountryChanged) {
		intChangedObjectValue = country.value;
		intSelectedIndexValue = indexForDropdownValue(state, intChangedObjectValue);
	} else {
		intChangedObjectValue = state.value;
		intSelectedIndexValue = indexForDropdownValue(country, intChangedObjectValue);
	}
	
	if (isUSTerritory(intChangedObjectValue)) {
		if (blnCountryChanged)
			state.selectedIndex = intSelectedIndexValue;
		else
			country.selectedIndex = intSelectedIndexValue;
			
	} else {
		if (blnCountryChanged)
			state.selectedIndex = 0;
		else
			country.selectedIndex = indexForDropdownValue(country, 'US');
	}
}

function syncInternationalStates() {
	try {
		document.getElementById("usCountryState").style.display		= "none";
		document.getElementById("caCountryState").style.display		= "none";		
		document.getElementById("otherCountryState").style.display	= "none";	
		
		var country = document.getElementById("countrySelect").value;
		if (country == "CA") {
			document.getElementById("caCountryState").style.display = "";
		}
		else if (isUSCountry(country)) {
			document.getElementById("usCountryState").style.display = "";
		}
		else {
			document.getElementById("otherCountryState").style.display = "";
		}
	}
	catch (e) {
		document.getElementById("usCountryState").style.display = "";
	}
}

function syncStateAndZipOnSubmitAction() {
	try {
		var country = document.getElementById("countrySelect").value;
		
		// canada
		if (country == "CA") {
			if (document.getElementById("caCountryState").style.display == "none") {
				syncInternationalStates();
				return false;
			}
			document.getElementById("zip_int").value = document.getElementById("zip_int_canada").value;
			document.getElementById("state_int").value = document.getElementById("state_int_canada").value;
			document.getElementById("zip_dom").value = "";
			document.getElementById("state_dom").selectedIndex = 0;
		}
		// us & us territories
		else if (isUSCountry(country)) {
			if (document.getElementById("usCountryState").style.display == "none") {
				syncInternationalStates();
				return false;
			}
			document.getElementById("zip_int").value = "";
			document.getElementById("state_int").value = "";
		}
		// all other countries
		else {
			if (document.getElementById("otherCountryState").style.display == "none") {
				syncInternationalStates();
				return false;
			}
			document.getElementById("zip_int").value = document.getElementById("zip_int_non_canada").value;
			document.getElementById("state_int").value = document.getElementById("countrySelect").value;
			document.getElementById("zip_dom").value = "";	
			document.getElementById("state_dom").selectedIndex = 0;
		}
	}
	catch (e) {}
	return true;
}

function getFocusSearchURL(fobj, fieldDelim, valDelim)
{
   var str = "";
   var valueArr = null;
   var val = "";
   var cmd = "";
   
   if (!fieldDelim) 
   	fieldDelim = "&";

   if (!valDelim) 
   	valDelim = "=";
     
   for(var i = 0;i < fobj.elements.length;i++)
   {
       switch(fobj.elements[i].type)
       {
           case "text":
           case "password":
           case "textarea":
           case "hidden":
                str += fobj.elements[i].name + valDelim + escapeFormValue(fobj.elements[i].value) + fieldDelim;
                 break;

           case "radio":
		   case "checkbox":
       			if (fobj.elements[i].checked)
               		str += fobj.elements[i].name + valDelim + escapeFormValue(fobj.elements[i].value) + fieldDelim;
		        break;

           case "select-one":
                str += fobj.elements[i].name + valDelim + escapeFormValue(fobj.elements[i].options[fobj.elements[i].selectedIndex].value) + fieldDelim;
                break;

           case "select-multiple":
           		for (var j = 0; j < fobj.elements[i].options.length; j++)
           			if (fobj.elements[i].options[j].selected)
	               		str += fobj.elements[i].name + valDelim + escapeFormValue(fobj.elements[i].options[j].value) + fieldDelim;
		        break;
       }
   }
   str = str.substr(0,(str.length - 1));
   return str;
}

function escapeFormValue(val){
 	return	escape(val).replace('&', '%26').replace('=', '%3D')
}

// Function to detect enter button hit in the quantity box of productdetail.
// We don't want the form to submit.
function checkEnter(e)
    {
    	var key = window.event ? e.keyCode : e.which;
    	
    	if (key == 13)
        {
           return false;
        }
    }

//Enter-listener
if (document.layers)
  document.captureEvents(Event.KEYDOWN);
  document.onkeydown =
    function (evt) { 
      var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
      if (keyCode == 13)   //13 = the code for pressing ENTER
 
      {
         if (document.form) {
		 document.form.submit();
 	}
      }
    }


function viewBannerEvent(eventID, keep_days){
	var bannerid = readCookie('CHOSEN_BANNER_ID');
	if (bannerid == null)
	{
		createCookie("CHOSEN_BANNER_ID", eventID, keep_days);
		cmCreateConversionEventTag(eventID, 1, 'A/B Global Banner', 0);
	}
	else if (bannerid != eventID)
	{
		eraseCookie("CHOSEN_BANNER");
		eraseCookie("CHOSEN_BANNER_ID");
	}
	
}

/*
 * BEGIN: Email/Mobile Signup functions
 */

$(document).ready(function() {
	$("#email_signup_form").keydown(function(event) {
		if (event.keyCode == 13) {
			var co_cd = $("#co_cd").val();
			openSignupemail('email', co_cd);
		}
	});
	$("#mobile_signup_form").keydown(function(event) {
		if (event.keyCode == 13) {
			var co_cd = $("#co_cd").val();
			openSignupemail('mobile', co_cd);
		}
	});
});


function openEmailSignUp(email, co_cd) {
	var url = "";
	switch (co_cd) {
		case "56":
			url = "http://afl.p0.com/afl_emailclub.jsp";
			break;
		case "20":
			if (email.trim() == "" || email == "Enter Your Email Address") {
				url = "http://champs.p0.com/champs_emailclub1.jsp";
			}
			else {
				url = "http://champs.p0.com/champs_emailclub2.jsp?e=" + email;
			}
			break;
		case "21":
			if (email.trim() == "" || email == "Enter Your Email Address") {
				url = "http://footlocker.p0.com/footlocker_emailclub.jsp";
			}
			else {
				url = "http://footlocker.p0.com/footlocker_emailclub.jsp?e=" + email;
			}
			break;		
		case "23":
			url = "http://ladyfootlocker.p0.com/ladyfootlocker_emailclub.jsp";
			break;	
		case "34":
			if (email.trim() == "" || email == "Enter Your Email Address" ) {
				url = "http://footaction.p0.com/footaction_emailclub1.jsp";
			}
			else {
				url = "http://footaction.p0.com/footaction_emailclub2.jsp?e=" + email;
			}			
			break;	
		case "30":
			url = "http://ryka.p0.com/ryka_emailclub.jsp";
			break;		
		case "36":
			if (email.trim() == "" || email == "Email Address" ) {
				url = "http://sparq.p0.com/sparq_emailclub1.jsp";
			}
			else {
				url = "http://sparq.p0.com/sparq_emailclub2.jsp?e=" + email;
			}
			break;		
		case "35":
			url = "http://espn.p0.com/espnshop_emailclub.jsp";
			break;		
		case "04":
			if (email.trim() == "" || email == "Enter Your Email Address" ) {
				url = "http://finalscore.p0.com/finalscore_emailclub1.jsp";
			}
			else {
				url = "http://finalscore.p0.com/finalscore_emailclub2.jsp?e=" + email;
			}
			break;		
		case "01":
			if (email.trim() == "" || email == "Enter Your Email Address") {
				url = "http://eastbay.p0.com/eastbay_emailclub1.jsp";
			}
			else {
				url = "http://eastbay.p0.com/eastbay_emailclub2.jsp?e=" + email;
			}			
			break;
		case "61":
			if (email.trim() == "" || email == "EMAIL SIGN UP") {
				url = "http://ccs.p0.com/ccs_emailclub.jsp";
			}
			else {
				url = "http://ccs.p0.com/ccs_emailclub2.jsp?e=" + email;
			}			
			break;
	}

	var popupWin = window.open(url,'SignupEmail','height=550,width=640,fullscreen=no,menubar=no,location=no,resizable=yes,scrollbars=yes,titlebar=yes,toolbar=no');
}

/* eastbay email/phone signup functions */

function dofocus(obj){
	if (document.getElementById(obj).value == 'Enter' || document.getElementById(obj).value == 'Mobile' || document.getElementById(obj).value == 'Number')
	{
		document.getElementById(obj).value = '';
	} 
	else
	{	return false; }	
}
function validateMobile(obj,len,next_field){
	if (isNaN(document.getElementById(obj).value) == true)
	{
		document.getElementById(obj).value = ''; 
		alert('The Mobile number should be numeric');
		document.getElementById(obj).focus();
	}
	else if (document.getElementById(obj).value.length == len)
	{
		if (document.getElementById(next_field) != null)
			document.getElementById(next_field).focus();
	}
	else if (document.getElementById(obj).value.length > len)
	{
		document.getElementById(obj).value = ''; 
		alert('This number should be ' + len + ' long');
		document.getElementById(obj).focus();
	}
}

function openSignupemail(type, co_cd) {
	var delim = '?';
    var seperator = '=';
	var apmSand = '&';
	if (type == 'email')
	{ 
		var v = document.getElementById("email").value;
		openEmailSignUp(v, co_cd);
	}
	else if (type == 'mobile')	
	{
		var v = document.getElementById("Mobile_Number_1").value;
		var w = document.getElementById("Mobile_Number_2").value;
		var x = document.getElementById("Mobile_Number_3").value;
		var u = "";
		switch (co_cd) {
			case "01":
				u = 'http://ww2.eastbay.com/2008/ebs112707a/ebs030308a.html' + delim + 'Mobile_Number_1' + seperator + v + apmSand + 'Mobile_Number_2' + seperator + w + apmSand + 'Mobile_Number_3' + seperator + x ;
				break;
			case "20":
				u = 'http://ww2.champssports.com/2008/ch061108a/ch061108a_mobile.html?Mobile_Number_1=' + v + '&Mobile_Number_2=' + w + '&Mobile_Number_3=' + x;
				break;
			case "21":
				if (v.trim() == "" || v == "Enter" || w.trim() =="" || w == "Mobile" || x.trim() == "" || x == "Number") 
				{
					u = 'http://ww2.footlocker.com/2008/fl081408a/fl081408a_mobile.html'
				}
				else {
					u = 'http://ww2.footlocker.com/2008/fl081408a/fl081408a_mobile.html' + delim + 'Mobile_Number_1' + seperator + v + apmSand + 'Mobile_Number_2' + seperator + w + apmSand + 'Mobile_Number_3' + seperator + x ;
				}
				break;
			case "35":
				u = 'http://ww2.espnshop.com/2008/espn010408b/';
				break;
		}
		//alert(u);
		popupWin = window.open(u,'SignupMobile','height=550,width=640,fullscreen=no,menubar=no,location=no,resizable=yes,scrollbars=yes,titlebar=yes,toolbar=no');		
	}
}

/*
function openEBSignupemail(type) {
	var delim = '?';
    var seperator = '=';
	var apmSand = '&';
	if (type == 'email')
	{ 
		var v = document.email_signup_form.email.value;
		openEmailSignUp(v, '01'); // hardcoded eastbay company code
	}
	else if (type == 'mobile')	
	{
		var v = document.email_signup_form.enter.value;
		var w = document.email_signup_form.mobile.value;
		var x = document.email_signup_form.number.value;
		var u = 'http://ww2.eastbay.com/2008/ebs112707a/ebs030308a.html' + delim + 'Mobile_Number_1' + seperator + v + apmSand + 'Mobile_Number_2' + seperator + w + apmSand + 'Mobile_Number_3' + seperator + x ;
		popupWin = window.open(u,'SignupMobile','height=550,width=640,fullscreen=no,menubar=no,location=no,resizable=yes,scrollbars=yes,titlebar=yes,toolbar=no');		
	}
}

function openMobileSignUp() {
	var Mobile_Number_1 = document.getElementById("Mobile_Number_1").value;
	var Mobile_Number_2 = document.getElementById("Mobile_Number_2").value;
	var Mobile_Number_3 = document.getElementById("Mobile_Number_3").value;
	var url = 'http://ww2.champssports.com/2008/ch061108a/ch061108a_mobile.html?Mobile_Number_1=' + Mobile_Number_1 + '&Mobile_Number_2=' + Mobile_Number_2 + '&Mobile_Number_3=' + Mobile_Number_3;
	popupWin = window.open(url,'SignupMobile','height=550,width=640,fullscreen=no,menubar=no,location=no,resizable=yes,scrollbars=yes,titlebar=yes,toolbar=no');		
}
*/

/*
 * END: Email/Mobile Signup functions
 */

function openSponsor(url)
{
	window.open(url, 'Sponsor', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=1000,height=1000');
}

function openPopUpWindow(url, width, height) {
	if (!width) width = 640;
	if (!height) height = 430;
	var popupWin = window.open(url,'','height=' + height + ',width=' + width + ',fullscreen=no,menubar=no,location=no,resizable=yes,scrollbars=yes,titlebar=yes,toolbar=no');
}

/* utility functions */
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

function getViewpointTop() {
	return window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop;
}
function getViewpointHeight() {
	return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
}

function initMenu(showfirst) {
	var title;
	var imgid;
     //$("#menu ul").hide();
	if (showfirst == undefined || showfirst) {
		$("#menu ul:first").show();
		title = $("#menu li a").attr("title")
		imgid = "#" + title;
		$(imgid).attr({ 
					src: down_pic,
					title: "open_arrow" 
					});
	}
	$("#menu li a").click(function() {
		$(this).next().toggle();
		title = $(this).attr("title");
		if ($.trim(title) != "") {
			imgid = "#" + title;
			if ($(imgid).attr("title") == "open_arrow") {
				$(imgid).attr({ 
							src: right_pic,
							title: "close_arrow"
							});
			}
			else {
				$(imgid).attr({ 
							src: down_pic,
							title: "open_arrow"
							});
			}
		}
     });  
}