var thisPage = "";

function setCurrent(page)
{
	img_press(page);
	thisPage = page;
}

function img_act(imgName)
{
    if (document.images)
    {
        imgOn = eval(imgName + "on.src");
		imgPress = eval(imgName + "press.src");
		imgSrc = document [imgName].src;
		if (imgSrc != imgPress && imgName != thisPage){
			document [imgName].src = imgOn;
		}
        
    }
}

function img_inact(imgName)
{
    if (document.images && imgName != thisPage)
    {
        imgOff = eval(imgName + "off.src");
        document [imgName].src = imgOff;
    }
}

function img_press(imgName)
{
    // if (document.images && imgName != thisPage)
    if (document.images && imgName != "")
    {
        imgPress = eval(imgName + "press.src");
        document [imgName].src = imgPress;
    }
}

function message (text)    
{
    if (document.images)
    {
        window.status = text;
    }
}

function remove ()    
{
    if (document.images)
    {
    window.status = "";
    }
}

// larger view for products

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
	}
    }
function toggleDisplay(divId, iState)
{
	var obj;
	if (document.all)
	{
		obj = document.all[divId];
	}
	else
	{
		obj = document.getElementById(divId);
	}	
	
	if (obj.style.display == "none")
	{	
		obj.style.display = "inline";
	}
	else
	{	
		obj.style.display = "none";
	}
}


var fabricId;
function toggleFabricsBox(e) // 1 visible, 0 hidden
{
    iState = 1;
    szDivID = "fabric_div";
    var fabricDelStr = document.forms[0].elements["fabric_" + fabricId].value;
    var fabricFieldsArr = fabricDelStr.split("||");
    var fabricDivContentId = "fabric_div_content";
    var obj;
    
    if(document.layers)	   //NN4+
    {
       obj = document.layers[szDivID]
       obj.visibility = iState ? "show" : "hide";
       fabricDiv = document.layers[fabricDivContentId];
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
        fabricDiv = document.getElementById(fabricDivContentId);
    }
    else if(document.all)	// IE 4
    {
        obj = document.all[szDivID];
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
        fabricDiv = document.all[fabricDivContentId];
    }
    
    
    fabricDiv.innerHTML = "<span class=\"eleven-data-bold\">" + fabricFieldsArr[0] + "</span><br/>" + "<span class=\"ten-data\">" + fabricFieldsArr[1] + "<span class=\"ten-data\"><br/><br/>" + fabricFieldsArr[2] + "</span>";
    fabricId = "";
}

n = 1; // number of hidden layers 
function show(a)
{ 
    for(i=1;i<=n;i++)
    { 
        document.getElementById('t'+i).style.display = 'none'; 
    } 
    document.getElementById('t'+a).style.display = 'block'; 
}

n = 1; // number of hidden layers 
function hide(a)
{ 
    for(i=1;i<=n;i++)
    { 
        document.getElementById('t'+i).style.display = 'inline'; 
    } 
    document.getElementById('t'+a).style.display = 'none'; 
}

function showSizes(divStr,sizes)
{
    szDiv = document.getElementById(divStr);
    szDiv.innerHTML = sizes;
}

function hideSizes(divStr)
{
	szDiv = document.getElementById(divStr);
	szDiv.innerHTML = '';
}

function altNavTextEffect(link, url, bul)
{
	if (link.style)
	{	
		link.style.color = "#ffcc00";
		document.images[bul].src = "images/additionalNav_bullet_on.gif";
		document.location = url;
	}
}

function ResetAthleteImage(imageSrc)
{
	document.images["athlete"].src = "images/athleteImages/" + imageSrc;
}

function popUp1(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=620,height=420,left = 237,top = 184');");
}

var chosenProductIdsHidden;

function getNextUnchosen()
{
	var unchosenIndex = 0;
	var isChosen = false;
	for(i = 0; i < 4;i++)
	{
	  if((chosenIds[0] != null)&&(chosenIds[i] == 0))
	  {
		if(!isChosen)
		{
			unchosenIndex = i;
			isChosen = true;
		}
	  }
	}
	return unchosenIndex;
}

function showHideCheckBoxes(formCheckBox)
{
	compHref = getObj("compareHref");
	compSpan = getObj("compareSpan");
	chosenProductIdsHidden = document.getElementById("ctl00_ctl00_ctl00_MainContent_MainContent_MainContent_ProductChooser1_chosenProductIdsHidden");
	//chosenProductIdsHidden = document.getElementById("ctl00_MainContent_ProductChooser1_chosenProductIdsHidden");
	//chosenProductsIdsTextBox = document.getElementById("ctl00_MainContent_ProductChooser1_chosenProductIdsTextBox");
	var hiddenStr;
	frm = document.getElementById("aspnetForm");
  
	if(formCheckBox.checked)
	{
		id = 0;
		if(chosenIds[0] != null)
		{
			id = getNextUnchosen();
		}
		
		chosenIds[id] = formCheckBox.value;
	}
	else
	{
		 for(i = 0;i < 4;i++)
		 {
			if(chosenIds[i] == formCheckBox.value)
			{
				chosenIds[i] = 0;
			}
		 }
	}
	
	checkedCheckBoxCount = getCheckedCount();
	
	if(checkedCheckBoxCount > 1)
	{
 //	 compHref.disabled = '';
	  compHref.style.display = "inline";
	  compSpan.style.display = "none";
	  compHref.href = '#';
	  
	}
	else
	{
 //	  compHref.disabled = 'disabled';
	   compHref.style.display = "none";
	   compSpan.style.display = "inline";
	   compHref.href = document.location.toString();
	}
	
	if(checkedCheckBoxCount == 4)
	{
		for(i = 0; i < frm.elements.length; i++)
		{
			if(frm.elements[i].type == "checkbox")
			{
				if(!frm.elements[i].checked)
				{
					
					frm.elements[i].disabled = 'disabled';
				}
			}
		}
	}
	else
	{
		for(i = 0; i < frm.elements.length; i++)
		{
			if(frm.elements[i].type == "checkbox")
			{
				frm.elements[i].style.display = 'inline';
				frm.elements[i].disabled = ''; 
			}
		}
	}
	
	hiddenStr = chosenIds.join(",");
	
	chosenProductIdsHidden.value = hiddenStr;
	//chosenProductsIdsTextBox.value = hiddenStr;
}

function getCheckedCount()
{
    var count = 0;
    for(i = 0; i < 4; i++)
    {
       if(chosenIds[i] > 0)
       {
            count++;
       }
    }
    return count;
}

function submitForm(urlStr)
{
	chosenProductIdsHidden = document.getElementById("ctl00_ctl00_ctl00_MainContent_MainContent_MainContent_ProductChooser1_chosenProductIdsHidden");
	//chosenProductIdsHidden = document.getElementById("ctl00_MainContent_ProductChooser1_chosenProductIdsHidden");
	//alert("urlStr:" + urlStr + "&chosenProducts=" + chosenProductIdsHidden.value );
	document.location = urlStr + "&chosenProducts=" + chosenProductIdsHidden.value ;
}

function compareProducts(top, cat)
{
	if(checkedCheckBoxCount > 0)
	{
		chosenProductIdsHidden = document.getElementById("ctl00_ctl00_ctl00_MainContent_MainContent_MainContent_ProductChooser1_chosenProductIdsHidden");
		//chosenProductIdsHidden = document.getElementById("ctl00_MainContent_ProductChooser1_chosenProductIdsHidden");
		var idsArray = chosenProductIdsHidden.value.split(",");
		var idStr = "";
		for(i = 0; i < idsArray.length; i++)
		{
			if(idsArray[i] > 0)
			{
				if(i != 0)
				{
					idStr += ",";
				}
				idStr += idsArray[i].toString();
			}
		}
		var strRedirect = "CompareProducts.aspx?top=" + top + "&cat=" + cat + "&chosenProducts=" + idStr;
		
		// for debugging:
		// CompareProducts.aspx?top=1241&cat=1277&chosenProducts=2464,2732,2471
		document.location.href = strRedirect; // strRedirect;
	    document.location.href = strRedirect; // strRedirect;
	}
}

function getObj(id)
{
	if(document.layers)	   //NN4+
	{
	   if (document.layers[id])
		  return document.layers[id];
	   else
		  return null;  
	}
	else if (document.getElementById)	  //gecko(NN6) + IE 5+
	{
		if (document.getElementById(id)) 
			return document.getElementById(id);
		else
			return null;
	}
	else if (document.all)	// IE 4
	{
		if (document.all[id].style) 
			return document.all[id].style;
		else
			return null;
	}
}

function removeUnderlining(id)
{
	linkObj = getObj(id);
	if (linkObj != null) linkObj.style.textDecoration = "none";
	else
	 alert("none");
}

function processAthletesUnderlining(id)
{
	// link id's are link1, link2, link3, link4
	var linkObj = getObj("link1");
	if (linkObj != null) linkObj.style.textDecoration = "underline";
	
	var linkObj = getObj("link2");
	if (linkObj != null) linkObj.style.textDecoration = "underline";
	
	var linkObj = getObj("link3");
	if (linkObj != null) linkObj.style.textDecoration = "underline";
	
	var linkObj = getObj("link4");
	if (linkObj != null) linkObj.style.textDecoration = "underline";
	
	linkObj = getObj(id);
	if (linkObj != null) linkObj.style.textDecoration = "none";
}

function getQueryVariable(variable) 
{ 
	var query = window.location.search.substring(1); 
	var vars = query.split("&"); 
	for (var i=0;i<vars.length;i++) 
	{ 
		var pair = vars[i].split("="); 
		if (pair[0] == variable) 
		{ 
		return pair[1]; 
		} 
	} 
}

function removeComparedProduct(oCheck)
{
	var len = oCheck.name.length;
	var prodId = oCheck.name.substring(5, len);
	var urlStr = document.location.toString();
	var prodIdArr = getQueryVariable("chosenProducts").split(",");
	var chosenProducts = "chosenProducts=";
	
	for (var i=0; i < prodIdArr.length; i++)
	{
		if (prodIdArr[i] != prodId)
		{  
			chosenProducts += (prodIdArr[i] + ",");
		}
	}
	
	len = chosenProducts.length;
	
	
	
	document.location = "CompareProducts.aspx?top=" + getQueryVariable("top") + "&cat=" + getQueryVariable("cat") + "&" + chosenProducts.substring(0, len-1);
}

function checkKeycode(e) {
	var keycode;
	if (window.event)
	{
		keycode = window.event.keyCode;
	}
	else if (e)
	{
		keycode = e.which;
	}
	return(keycode);
}

