
//This function clears the specified textbox
function clearDefault(box, defaultValue)
{ 
    if (defaultValue==box.value)
    {
        box.value = "";
        box.style.color = 'black';
    }
}

//This function fills the selected textbox with the specified text
function fillBox(box, fillValue)
{
    if (box.value== "")
    {
        box.value = fillValue;
        box.style.color = 'gray';
    }
}


//This function limits the number of selected items a listbox can have
function checkLimit(control)
{
  //Get total no. of links
  var optsLength = control.options.length;
  var totalSelected = 0;
  //Loop through links and add one to totalSelected if the link is selected
  for(var i=0;i<optsLength;i++)
  { 
     if(control.options[i].selected)
     {
        totalSelected = totalSelected + 1;
     }
  }
  
  if(totalSelected <= 4)
  {
  }
  else
  {
     //Drop first selected link
     var firstSelected = control.selectedIndex;
     control.options[firstSelected].selected = false;
  }
}

//This function checks the Y offset position of the specified element and if it exceeds the supplied value, applies a different CSS class to it
//This is for the three column layout
function getScrollXY(divID, YOffset) {

  //Firstly, get the current scrolling offsets. The method of doing so not browser independent, as you can see!
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  
  //This is site specific
  var currDiv = document.getElementById(divID);
  var leftDivHeight = document.getElementById('left_content').offsetHeight;
  var containerDivHeight = document.getElementById(divID).offsetHeight;
  if (scrOfY >= YOffset)
  { 
    currDiv.setAttribute("class", "containerFixed");
    currDiv.setAttribute("className", "containerFixed");
  }
  //Adding the height of the category container here because it's subtracted from the left_content height when it's position is set to fixed
  else if((scrOfY + containerDivHeight) <= YOffset)
  {
     currDiv.setAttribute("class", "containerRelative");
     currDiv.setAttribute("className", "containerRelative");
  }
  return [ scrOfX, scrOfY ];
}

//This function checks the Y offset position of the specified element and if it exceeds the supplied value, applies a different CSS class to it
//This is for the two column layout
function getScrollXYTwoCol(divID, YOffset) {
  //Firstly, get the current scrolling offsets. The method of doing so not browser independent, as you can see!
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

  //This is site specific
  var currDiv = document.getElementById(divID);
  var leftDivHeight = document.getElementById('left_content').offsetHeight;
  var containerDivHeight = document.getElementById(divID).offsetHeight;
  if (scrOfY >= YOffset)
  { 
    currDiv.setAttribute("class", "containerFixed");
    currDiv.setAttribute("className", "containerFixed");
  }
  //Adding the height of the category container here because it's subtracted from the left_content height when it's position is set to fixed
  else if(scrOfY <= YOffset)
  {
     currDiv.setAttribute("class", "containerRelative");
     currDiv.setAttribute("className", "containerRelative");
  }
  return [ scrOfX, scrOfY ];
}

//This function checks the Y offset position of the specified element and if it exceeds the supplied value, applies a different CSS class to it
//This is for the scrolling of the content page image
function getScrollXYContentImage(divID, YOffset) {
  //Do not run image scrolling script if we're on the homepage
  var sPath = window.location.pathname;
  //var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
  var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
  if(sPage!="default.aspx" && sPage!="link.html")
  { 
      //Firstly, get the current scrolling offsets. The method of doing so not browser independent, as you can see!
      var scrOfX = 0, scrOfY = 0;
      if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
      }
      
      //This is site specific
      var currDiv = document.getElementById(divID);
      var leftDivHeight = document.getElementById('left_content').offsetHeight;
      //Check if the supplied div exists
      var o = testForObject(divID);
      if (o)
      {   
          var containerDivHeight = document.getElementById(divID).offsetHeight;
          if (scrOfY >= YOffset)
          { 
            currDiv.setAttribute("class", "containerFixed");
            currDiv.setAttribute("className", "containerFixed");
          }
          //Adding the height of the category container here because it's subtracted from the left_content height when it's position is set to fixed
          else if(scrOfY <= YOffset)
          {
             currDiv.setAttribute("class", "containerRelative");
             currDiv.setAttribute("className", "containerRelative");
          }
          return [ scrOfX, scrOfY ];
     }
     else
     {
        //Do Nothing if the supplied div does not exist
     }
  }
}

/*This function tests for the existence of the supplied object*/
function testForObject(Id, Tag)
{
  var o = document.getElementById(Id);
  if (o)
  {
    if (Tag)
    {
      if (o.tagName.toLowerCase() == Tag.toLowerCase())
      {
        return o;
      }
    }
    else
    {
      return o;
    }
  }
  return null;
}
