function fcnFieldOnWithClear(a_objTextBox, a_strClearMessage)
{
  if (a_objTextBox.value == a_strClearMessage)
    a_objTextBox.value = '';

  fcnFieldOn(a_objTextBox);
}

function fcnShowHazMat(a_blnShow, a_objHazMatControl)
{
  if (a_blnShow)
    a_objHazMatControl.style.display = "block";
  else
    a_objHazMatControl.style.display = "none";
}

var g_objWindowsT = new Object();

function fcnOpenNewWindow(a_strURL, a_strTarget, a_intWidth, a_intHeight, a_blnScrolling, a_blnRefresh)
{
  var strScrolling = "no";
  var strPar = "";

  if (a_blnScrolling)
    var strScrolling = "yes";

  if (a_intWidth == 0 || a_intHeight == 0)
    strPar = "history=no,location=no,scrollbars=" + strScrolling;
  else
    strPar = "history=no,location=no,scrollbars=" + strScrolling + ",width=" + new Number(a_intWidth) + ",height=" + new Number(a_intHeight);

  if (g_objWindowsT[a_strTarget])
  {
    if(g_objWindowsT[a_strTarget].closed || a_blnRefresh)
      g_objWindowsT[a_strTarget] = window.open(a_strURL, a_strTarget, strPar);

    g_objWindowsT[a_strTarget].focus();
  }
  else
  {
    g_objWindowsT[a_strTarget] = window.open(a_strURL, a_strTarget, strPar);
    g_objWindowsT[a_strTarget].focus();
  }
}

function fcnGetCookie(strName)
{
  var dc = document.cookie;
  var strPrefix = strName + "=";
  var intBegin = dc.indexOf("; " + strPrefix);

  if (intBegin == -1)
  {
    intBegin = dc.indexOf(strPrefix);
    if (intBegin != 0)
      return null;
  }
  else
    intBegin += 2;

  var intEnd = document.cookie.indexOf(";", intBegin);

  if (intEnd == -1)
    intEnd = dc.length;

  return unescape(dc.substring(intBegin + strPrefix.length, intEnd));
}

function fcnSetCookie(strName, strValue, strExpires, strPath, strDomain, blnIsSecure)
{
  document.cookie = strName + "=" + escape(strValue) +
    ((strExpires) ? "; expires=" + strExpires.toGMTString() : "") +
    ((strPath) ? "; path=" + strPath : "") +
    ((strDomain) ? "; domain=" + strDomain : "") +
    ((blnIsSecure) ? "; secure" : "");
}

function fcnMakeRequest(a_strUrl)
{
  http_request = false;

  //Mozilla, Safari,...
  if (window.XMLHttpRequest)
  {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType)
      http_request.overrideMimeType('text/xml');
  }
  //IE.
  else if (window.ActiveXObject)
  {
    try
    {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {}
    }
  }

  if (!http_request)
    return false;

  http_request.onreadystatechange = fcnAlertContents;
  http_request.open('GET', a_strUrl, true);
  http_request.send(null);
  return true;
}

function fcnAlertContents()
{
  if (http_request.readyState == 4)
  {
    if (http_request.status != 200)
      alert('There was a problem with the request.');
  }
}

function fcnViewPage(a_intPageID, a_intTotalPages, a_strGridID)
{
  for (var intIndex = 1; intIndex <= a_intTotalPages; intIndex++)
  {
    if (a_intPageID == intIndex)
    {
      document.getElementById(a_strGridID + '_page_' + intIndex).style.display = 'block';
      document.getElementById(a_strGridID + '_row_' + intIndex).className = 'product_row top';
      document.getElementById(a_strGridID + '_link_' + intIndex).className = 'selected';
      document.getElementById(a_strGridID + '_linkbottom_' + intIndex).className = 'selected';
    }
    else if (a_intPageID == null)
    {
      document.getElementById(a_strGridID + '_page_' + intIndex).style.display = 'block';
      if (intIndex == 1)
        document.getElementById(a_strGridID + '_row_' + intIndex).className = 'product_row top';
      else
        document.getElementById(a_strGridID + '_row_' + intIndex).className = 'product_row';
      document.getElementById(a_strGridID + '_link_' + intIndex).className = '';
      document.getElementById(a_strGridID + '_linkbottom_' + intIndex).className = '';
      document.getElementById(a_strGridID + '_link_all').className = 'selected';
      document.getElementById(a_strGridID + '_linkbottom_all').className = 'selected';
    }
    else
    {
      document.getElementById(a_strGridID + '_page_' + intIndex).style.display = 'none';
      document.getElementById(a_strGridID + '_row_' + intIndex).className = 'product_row';
      document.getElementById(a_strGridID + '_link_' + intIndex).className = '';
      document.getElementById(a_strGridID + '_linkbottom_' + intIndex).className = '';
    }
  }

  if (a_intPageID != null)
  {
    document.getElementById(a_strGridID + '_link_all').className = '';
    document.getElementById(a_strGridID + '_linkbottom_all').className = '';
  }
}

function fcnTabSwitch(a_strClientID, a_intTabIndex, a_intMaxTabs)
{
  var strControlID = '';
  var strHiddenIndexControlID = '';

  for (var intIndex = 0; intIndex < a_intMaxTabs; intIndex++)
  {
    strControlID = intIndex + '_' + a_strClientID;
    strHiddenIndexControlID = 'hdnTabIndex_' + a_strClientID;

    if (document.getElementById('tab_' + strControlID) == null)
    {
    }
    else if (a_intTabIndex == intIndex)
    {
      document.getElementById('tab_' + strControlID).className = 'selected';
      document.getElementById('tab_content_' + strControlID).style.display = 'block';
      document.getElementById(strHiddenIndexControlID).value = intIndex;
    }
    else
    {
      document.getElementById('tab_' + strControlID).className = '';
      document.getElementById('tab_content_' + strControlID).style.display = 'none';
    }
  }
}

var g_blnSubmitted = false;
function fcnStopDoubleClick(a_objButton, event, a_strValidationGroup)
{
  var blnIsValid = true;

  if (typeof(Page_ClientValidate) == 'function')
    blnIsValid = Page_ClientValidate(a_strValidationGroup);

  if (blnIsValid)
  {
    if (g_blnSubmitted)
    {
      try
      {
        event.cancelBubble = true;

        if (event.stopPropagation)
          event.stopPropagation();
      }
      catch (e)
      {}
      return;
    }

    g_blnSubmitted = true;
    a_objButton.innerHTML = 'Please Wait...';
  }
}

function IsSilverlightInstalled()
{
  var strIsSilverlightInstalled = "false";

  try
  {
    //Check on IE.
    try
    {
      var slControl = new ActiveXObject('AgControl.AgControl');
      strIsSilverlightInstalled = "true";
    }
    catch (e)
    {
      //either not installed or not IE. Check Firefox
      if (navigator.plugins["Silverlight Plug-In"])
        strIsSilverlightInstalled = "false";
    }
  }
  catch (e)
  {
    //we don't want to leak exceptions. However, you may want
    //to add exception tracking code here.
  }

  return strIsSilverlightInstalled;
}
