function clearDefault(el)
{
   if (el.value == el.defaultValue)
   {
      el.value = "";
   }
}
function resetDefault(el)
{
   if (el.value == "")
   {
      el.value = el.defaultValue;
   }
}
function FireKeyDownEvent(myevent, buttonToClick)
{
   if (myevent.keyCode == 13)
   {
      document.getElementById(buttonToClick).click();
      myevent.returnValue = false;
   }
}

function leftTrim(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    return sString;
}

function rightTrim(sString) 
{
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function showHideCheckBoxes(formCheckBox)
{
    compHref = getObj("compareHref");
    compSpan = getObj("compareSpan");
    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 URLDecode(psEncodeString) 
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " ")); 
}

var originalInnerHTML = "";
var originalImageSrc = "";
var originalLargeImageSrc = "";
function swapInnerHTML(str, objName)
{
    var divObj = getObj(objName);
    str = str.replace(/\&/g, "&amp;");
    divObj.innerHTML = str;
}
function hardSwapInnerHTML(str, objName)
{
    var divObj = getObj(objName);
    originalInnerHTML = divObj.innerHTML;
    str = str.replace(/\&/g, "&amp;");
    divObj.innerHTML = str;
}
function resetInnerHTML(str, objName)
{
    var divObj = getObj(objName);
    if (originalInnerHTML != "")
    {
      str = originalInnerHTML;
    }
    str = str.replace(/\&/g, "&amp;");
    divObj.innerHTML = str;
}
function swapImage(imgSrc, objName)
{
    var imgObj = getObj(objName);
    imgObj.src = imgSrc;
    
}
function hardSwapImage(imgSrc, objName)
{
    var imgObj = getObj(objName);
    originalImageSrc = imgObj.src;
    imgObj.src = imgSrc;
}
function resetImage(imgSrc, objName)
{
    var imgObj = getObj(objName);
    if (originalImageSrc != "")
    {
      imgSrc = originalImageSrc;
    }
    imgObj.src = imgSrc;
}
function swapLargeImage(imgSrc, objName)
{
    var imgObj = getObj(objName);
    imgObj.src = imgSrc;
    
}
function hardSwapLargeImage(imgSrc, objName)
{
    var imgObj = getObj(objName);
    originalLargeImageSrc = imgObj.src;
    imgObj.src = imgSrc;
}
function resetLargeImage(imgSrc, objName)
{
    var imgObj = getObj(objName);
    if (originalLargeImageSrc != "")
    {
      imgSrc = originalLargeImageSrc;
    }
    imgObj.src = imgSrc;
}

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;
    }
}

var MouseX;
var MouseY;
var IE = document.all?true:false;
function getMouseXY(e) 
{
   if (IE) // grab the x-y pos.s if browser is IE 
   { 
       tempX = event.clientX + document.body.scrollLeft;
       tempY = event.clientY + document.body.scrollTop;
   }
   else // grab the x-y pos.s if browser is NS 
   {  
       tempX = e.pageX;
       tempY = e.pageY;
   }  
   if (tempX < 0){tempX = 0;}
   if (tempY < 0){tempY = 0;}  
   
   MouseX = tempX;
   MouseY = tempY;
}

function toggleDivVisibility(divId)
{
    var divObj = getObj(divId);
    var isVisible = (divObj.style.visibility == "visible") ? true : false;
    if (isVisible) divObj.style.visibility = "hidden";
    else divObj.style.visibility = "visible";
}

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";
    var linkObj = getObj("link5");
    if (linkObj != null) linkObj.style.textDecoration = "underline";
    var linkObj = getObj("link6");
    if (linkObj != null) linkObj.style.textDecoration = "underline";
    var linkObj = getObj("link7");
    if (linkObj != null) linkObj.style.textDecoration = "underline";
    var linkObj = getObj("link8");
    if (linkObj != null) linkObj.style.textDecoration = "underline";
    linkObj = getObj(id);
    if (linkObj != null) linkObj.style.textDecoration = "none";
}

// resizes Iframe according to content
function resizeMe(obj){ 
    docHeight = mainContent.document.body.scrollHeight;
    docWidth = mainContent.document.body.scrollWidth;
    obj.style.height = docHeight + 'px';
    obj.style.width = docWidth + 'px';
 } 

function showProductDetails()
{
   var collapsed = document.getElementById("productDetailsCollapsed");
   collapsed.style.display = "none";
   var expanded = document.getElementById("productDetailsExpanded");
   expanded.style.display = "block";
}

function hideProductDetails()
{
   var collapsed = document.getElementById("productDetailsCollapsed");
   collapsed.style.display = "block";
   var expanded = document.getElementById("productDetailsExpanded");
   expanded.style.display = "none";
}

