function printPage()
{
  if(window.location.href.indexOf('pf=1') != -1)
  {
    if(window.print)
      window.print();
  }
  return false;
}

function ShowHideElement(elementId)
{
  element = document.getElementById (elementId);
  if (element.className == "showMe")
    element.className = "hideMe";
  else if (element.className == "hideMe")
    element.className = "showMe";
  else if (element.className == "category showMe")
    element.className = "category hideMe";
  else if (element.className == "category hideMe")
    element.className = "category showMe";
}

function imagePopUp(img) 
{
  html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
         + '<html><head><title>Enlarged Image</title>'
         + '<script type="text/javascript">function resize(){picW = document.images["image"].width + 10; picH = document.images["image"].height + 70; window.resizeTo(picW,picH);   } </script>' 
         + '</head><body style="margin: 0px;" onload="resize();">'
         + '<a href="#" onclick="self.close(); return false;">' 
         + '<img src="' + img + '" border="0" name="image" alt=""/>' 
         + '</a>'
         //+ 'onload="window.resizeTo(document.image.width,(document.image.height*1.3))’>'
         + '</body></html>'; 
  popup=window.open("","image","toolbar=0,location=0, directories=0,menuBar=0, scrollbars=0,resizable=1"); 
  popup.document.open(); 
  popup.document.write(html); 
  //popup.document.focus(); 
  popup.document.close() 
}

function ToggleArrow(e, aid, hiddenid)
{
  aelement = document.getElementById(aid);
  hiddenElement = document.getElementById(hiddenid);
  if (hiddenElement.className == "showMe")
  {
    aelement.style.backgroundImage = 'url(/images/DownArrow.jpg)';
  }
  else if(hiddenElement.className == "hideMe")
  {
    aelement.style.backgroundImage = 'url(/images/RightArrow.jpg)';
  }
  else if (hiddenElement.className == "category showMe")
  {
    aelement.style.backgroundImage = 'url(/images/DownArrow.jpg)';
  }
  else if (hiddenElement.className == "category hideMe")
  {
    aelement.style.backgroundImage = 'url(/images/RightArrow.jpg)';
  }
}
// ******************************************
// * this CRclickButton will make a click event if it is a CR *
// ******************************************

function CRClickButton(buttonID, e)
{
 if (e) //firefox etc.
 {
  if(e.keyCode==13)
  {
    var button = document.getElementById(buttonID);
    if (button != null)
      button.click();
    else
      trace("Button with id:" + buttonID + " not found");
    e.cancelBubble = true;
    e.returnValue = false;
    return false
  }
 }
 else if (window.event) //IE etc.
 {
  if(window.event.keyCode==13)
  {
    var button = document.getElementById(buttonID);
    if (button != null)
      button.click();
    else
      trace("Button with id:" + buttonID + " not found");
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    return false
  }
 }
 return true;
}

// modeInputId: The input tag.
// doAllLabelId: The label rendered on the page
function ShowHideProducts(modeInputId,doAllLabelId,showAllText, hideAllText)
{
  var modeInput = document.getElementById(modeInputId);
  var doAllLabel = document.getElementById(doAllLabelId);
  
  
  var divs = document.getElementsByTagName("div");

  //var ids = "";  
  
  for (i=0; i<divs.length; i++)
  {
    if(divs[i].className == "category showMe" || divs[i].className == "category hideMe")
    {
      if (modeInput.value == 'hide')
      {
        divs[i].className = "category showMe";  
      }
      else
      {
        //never collapse categories
        //if (!divs[i].id.startsWith("RenderCategory"))
          divs[i].className = "category hideMe";
      }
    
      //ids += divs[i].id + "\r\n";
    }
  }
  
  //alert(ids);
  
  
  if (modeInput.value == 'hide')
  {
    doAllLabel.innerHTML = hideAllText;
    modeInput.value = 'show';
  }
  else
  {
    doAllLabel.innerHTML = showAllText;
    modeInput.value = 'hide';
  }
  return;
}
function ShowProducts()
{
  var divs = document.getElementsByTagName("div");

  //var ids = "";  
  
  for (i=0; i<divs.length; i++)
  {
    if(divs[i].className == "category hideMe")
    {
        divs[i].className = "category showMe";  
    }
    if(divs[i].className == "CategoryName")
    {
       divs[i].style.backgroundImage = 'url(/images/DownArrow.jpg)';
    }
  }
}
function HideProducts()
{
  var divs = document.getElementsByTagName("div");

  for (i=0; i<divs.length; i++)
  {
    if(divs[i].className == "category showMe")
    {
        divs[i].className = "category hideMe";  
    }
    else if(divs[i].className == "showMe")
    {
        divs[i].className = "hideMe";  
    }
    if(divs[i].className == "CategoryName")
    {
       divs[i].style.backgroundImage = 'url(/images/RightArrow.jpg)';
    }
    if(divs[i].className == "ProductName")
    {
       divs[i].style.backgroundImage = 'url(/images/RightArrow.jpg)';
    }    
  }
}
/*
JavaScript uses prototype-based object-orientation. This means that it’s possible to add functions to any object (including the built-in ones such as Array and String) by using that object’s “prototype”. For example:
taken from http://surguy.net/rediscovering-javascript.html
*/

String.prototype.startsWith = function(s) { return this.indexOf(s)==0; }
