var
  cHome                 = '0',
  ciSiteBuilder         = '1',
  ciStoreBuilder        = '2',
  ciTrafficBuilder      = '3',
  ciAffiliateBuilder    = '4',
  ciRevenueBuilder      = '5',
  cAccountManager       = '6',
  cEmailManager         = '7',
  cDomainManager        = '8',
  cBusinessCenter       = '9',
  cDataManager          = '10',
  cReportManager        = '11',
  cTemplateWizard       = '12',
  cDocumentSettings     = '13',
  cHelpContents         = '14',
  cEmployeeManager      = '15',
  cSalesContactsManager = '16',
  cNetworkManager       = '17',
  cSupportManager       = '18',
  cMarketingManager     = '19',
  cPartnerManager       = '20',

  HelpIndex_NodeIDBad = '-1';

if (typeof(SharedURL) != 'undefined')
{
  var PopupLoadMsgBody =
    '<table style="height:100%" width="100%" bgcolor="#f2f2f2" style="border:#999999 1px solid">' +
    '<tr><td style="vertical-align:middle" align="center">' +
      '<table align="center" cellpadding="10" style="background-color: #ffffff; border: #999999 3px double; font-weight: bold; font-size: 16px; font-family: Tahoma, Verdana, Arial; color:#999999">' +
      '<tr><td style="vertical-align:middle"><img src="' + SharedURL + 'Images/Loading_ani.gif" align="absmiddle"></td><td style="vertical-align:middle"><center>Please be patient while this page is loading...</center></td></tr>' +
      '</table>' +
    '</td></tr>' +
    '</table>';
  var PopupLoadMsg =
    '<html><head><title>Please wait while this page is loading...</title>' +
    '<meta http-equiv=content-type content="text/html; charset=windows-1252">' +
    '</head>' +
    '<body scroll="no" bgcolor="white" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0">' +
    PopupLoadMsgBody +
    '</body>' +
    '</html>';
}

function ajaxElementLoad(AElementIDorName, AURL, AOnComplete, AOnError)
{
  var LAJAX = new cAJAX(true);
  LAJAX.onComplete = [window, 'ajaxElementLoadComplete', {idOrName: AElementIDorName, onComplete: AOnComplete}];
  LAJAX.onError = AOnError;
  LAJAX.get(AURL);
}

window.ajaxElementLoadComplete = function (ATransport, AContext)
{
  var LElement = ElementGet(AContext.idOrName);
  if (!LElement)
    return;
  LElement.innerHTML = ATransport.responseText;
  EventRaise(AContext.onComplete, []);
};

function CaptchaGenerateNew()
{
  var
    LInput = document.getElementsByName('CaptchaCode')[0],
    LResponse = eval((new cAJAX(false)).get('default.asp?' + SIDQ + 'CaptchaGenerateNew=1&TS=' + (new Date()).valueOf()).responseText);
  LInput.value = LResponse[0];
  setTimeout('document.getElementById(\'imgCaptcha\').src = \'' + LResponse[1] + '\'', 0);
}

function CB_CheckAll(AcbItem, AHighLight, AcbItemNameEx)
{
  var LcbAll = ElementGet('cbAll' + ((AcbItemNameEx) ? '_' + AcbItemNameEx : ''));
  if (AcbItem)
  {
    if (LcbAll.checked && !AcbItem.checked) {
      LcbAll.checked = false;
    if (LcbAll.styled_element)
      LcbAll.styled_element.paint();
    }
    if (AHighLight)
      HighLight(AcbItem);
  }
  else
  {
    var LPKVs = document.getElementsByName(((AcbItemNameEx) ? AcbItemNameEx : '') + 'PKV');
    for (var i = 0; i < LPKVs.length; i++)
      if (!LPKVs[i].disabled)
      {
        if (LPKVs[i].checked != LcbAll.checked)
          LPKVs[i].click();
        if (AHighLight)
          HighLight(LPKVs[i]);
      }
  }
}

var ContextMenuParams;

function CM_EvalArgumentProcess(AArgID)
{
  eval(ContextMenuParams[AArgID]);
}

function CM_MailToProcess(AArgID)
{
  document.location = 'mailto:' + ContextMenuParams[AArgID];
}

function CM_MerchantAdminProcess(AArgID)
{
  window.openNew(ContextMenuParams[AArgID], window.top.document.body.clientWidth + 10, window.top.document.body.clientHeight + 100);
}

function CM_MerchantBrowseProcess(AArgID)
{
  window.openNew(ContextMenuParams[AArgID], window.top.document.body.clientWidth + 10, window.top.document.body.clientHeight + 100);
}

function CM_MerchantiMallProcess(AArgID)
{
  window.openNew(ContextMenuParams[AArgID], window.top.document.body.clientWidth + 10, window.top.document.body.clientHeight + 100);
}

function CM_OrderPaymentInfoProcess(AArgID)
{
  PaymentsShow(ContextMenuParams[AArgID]);
}

function ContactSupportLoad()
{
  HelpCenterLoad('', SCRM_CaseDetails);
}

function ContextMenuHide()
{
  if (ElementGet('divContextMenu'))
    ElementGet('divContextMenu').style.display = 'none';
  if (ElementGet('divLayoutMenu'))
    ElementGet('divLayoutMenu').style.display = 'none';
}

function ContextMenuItemHighlight(AItem, AMouseOver)
{
  AItem.style.borderStyle = (AMouseOver ? 'inset' : 'solid');
  AItem.style.backgroundColor = (AMouseOver ? '#DDDDDD' : '#EEEEEE');
}

function ContextMenuShow(ATitle, AParams, AEvent)
{
  ContextMenuParams = AParams;

  for (var i = 0; i < ContextMenuParams.length; i++)
    ElementGet('CM_Item' + i).style.display = ContextMenuParams[i] == '' ? 'none' : '';

  ElementGet('tdCMTitle').innerHTML = '<b>' + ATitle + '</b>';

  with (ElementGet('divContextMenu'))
  {
    style.display = 'block';
    style.left = ((document.body.clientWidth - AEvent.clientX) < ElementGet('tblContextMenu').clientWidth ? AEvent.clientX - ElementGet('tblContextMenu').clientWidth : AEvent.clientX);
    style.top = ((document.body.clientHeight - AEvent.clientY) < ElementGet('tblContextMenu').clientHeight ? AEvent.clientY - ElementGet('tblContextMenu').clientHeight : AEvent.clientY);
  }

  if (navigator.userAgent.indexOf('MSIE') < 0)
    AEvent.preventDefault();
  else
    AEvent.returnValue = false;
}

function CVVHelpShow(AScrollBars, AResizable, AStatus)
{
  Popup(WSA_URLGet(SMSC_StaticPageCleanBody, '', ['Page', 'CVVHelp.htm']), 365, 370, AScrollBars, AResizable, AStatus);
}

function DashboardInitPage()
{
  var LDashboard = document.getElementById("dashboard");
  if (LDashboard)
  {
    var LTds = LDashboard.getElementsByTagName("td");
    for (var i = 0; i < LTds.length; i++)
    {
      if (LTds[i].className == "header")
      {
        var a = LTds[i].getElementsByTagName("a").item(0);
        if (a)
        {
          a.onclick = DashboardHandleHeaderClick;
          if (a.id == 'ExpandOnInit')
            a.onclick();
        }
      }
    }
  }
  var LLinks = document.getElementsByTagName("a");
  for (var i = 0; i < LLinks.length; i++)
  {
    if (LLinks[i].className == "arrow")
    {
      LLinks[i].onclick = function ()
      {
        var LTR = this.parentNode.parentNode;
        LTR = LTR.nextSibling;
        while (LTR.tagName != "TR")
          LTR = LTR.nextSibling;
        var LTable = LTR.getElementsByTagName("table").item(0);
        if (this.className.indexOf("open") == -1)
        {
          this.className = this.className + " open";
          LTable.style.display = (document.all ? "block" : "table");
        }
        else
        {
          this.className = this.className.replace(" open", "");
          LTable.style.display = "";
        }
        return false;
      }
    }
  }
}

function DashboardHandleHeaderClick()
{
  var c = this.parentNode;
  while (c.tagName != "TABLE")
    c = c.parentNode;
  c = c.nextSibling;
  while (c.tagName != "DIV")
    c = c.nextSibling;
  if (c.className.indexOf("shadow") == 0)
  {
    var d = c.getElementsByTagName("div").item(0);
    if (d)
    {
      d.style.display = (d.style.display == "block" ? "" : "block");
      this.className = (d.style.display == "block" ? "over" : "");
    }
  }
  return false;
}

function EMailFriendShow()
{
  Popup('default.asp?' + SIDQ + 'S=' + SMSC_EMailFriend, 447, 412, 1, 0, 1);
}

function ForgotPasswordSubmit(AName)
{
  with (document.frmForgotPword)
  {
    MerchantName.value = frmPword.MerchantName.value;
    if (
      FieldValidate(document.frmPword.elements['MerchantName'], fvtNotEmpty, (AName ? AName : 'Merchant Name'), '', true)
      &&
      FieldValidate(elements['ForgotPasswordEmail'], fvtEMail, 'Email', '', true)
    )
    {
      submit();
    }
  }
}

function ForgotPasswordSubmitNetscape(AForm)
{
  AForm.MerchantName.value = top.MerchantName;
  if (AForm.MerchantName.value == 'undefined' || AForm.MerchantName.value == '')
  {
    alert('Please enter Account ID');
    return;
  }
  AForm.submit();
}

function FilterApply(AParams, AForm, ASubMenuID, AComponentID)
{
  top.frHeader.location = 'default.asp?' + SIDQ + 'S=' + SMSC_Header + (AComponentID ? '&C_=' + AComponentID : '');
  top.frSubMenu.location = 'default.asp?' + SIDQ + AParams + '&A=FF' + '&SMID=' + (ASubMenuID ? ASubMenuID : top.SMID) + (AComponentID ? '&C_=' + AComponentID : '') + (AForm ? '&FormSubmit=' + AForm : '');
  top.frSubMenuTabs.location = 'default.asp?' + SIDQ + 'S=' + SMSC_SubMenuTabs + '&A=Search' + (AComponentID ? '&C_=' + AComponentID : '');
}

function Form_ElementsSet(AFormName, AElementsValueAOS)
{
  if ((!AFormName) || (!AElementsValueAOS) || (AElementsValueAOS.length == 0) || ((AElementsValueAOS.length % 2) != 0))
    return;

  var LForm = null;
  var LForms = document.forms;
  for (var i = 0; i < LForms.length; i++)
    if (LForms[i].name == AFormName)
    {
      LForm = LForms[i];
      break;
    }

  if (!LForm)
    return;

  var LElementNames = [];
  var LElementValues = [];
  for (var i = 0; i < (AElementsValueAOS.length / 2); i++)
  {
    LElementNames[i] = AElementsValueAOS[2 * i];
    LElementValues[i] = AElementsValueAOS[2 * i + 1];
  }

  var LElements = LForm.elements;
  for (var i = 0; i < LElements.length; i++)
  {
    var LElement = LElements[i];
    var LIndex = LElementNames.indexOf(LElement.name);
    if (LIndex != -1)
      LElement.value = LElementValues[LIndex];
  }
}

function HighLight(E)
{
  var LE = E;
  while (LE && LE.tagName != 'TR')
    LE = LE.parentNode;

  if (LE)
    LE.className = (E.checked ? 'HighLight' : '');
}

function HelpCenterLoad(AHelpIndexNodeID, ASection)
{
  window.openNew(WSA_URLGet(SMSC_SubMenu, 'H',
  [
    'HelpIndexNodeID',  (AHelpIndexNodeID ? AHelpIndexNodeID : HelpIndex_NodeIDBad),
    'MainFrameSection', (ASection ? ASection : SMSC_HelpContents)
  ]), window.screen.width - 10, window.screen.height - 10);
}

function LayoutChange(ALayoutID)
{
  with (ElementGet('frmLayout'))
  {
    LayoutID.value = ALayoutID;
    submit();
  }
}

function LayoutMenuShow(AEvent)
{
  with (ElementGet('divLayoutMenu').style)
  {
    top = AEvent.clientY;
    left = AEvent.clientX;
    display = 'block';
  }

  AEvent.cancelBubble = true;
}

//-- START rollover images support code
function MM_swapImgRestore()
{ //v3.0
  try
  {
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }
  catch (E)
  {
    // ignoring error as in some cases we can not get document for some reason
  }
}

function MM_preloadImages()
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image(); d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d)
{ //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage()
{ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array(); for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-- END rollover images support code

function OptInValidate(AForm)
{
  with (AForm)
    return (
      FieldValidate(FEMail, fvtEMail, 'EMail', '', true)
/*
      &&
      FieldValidateEx(FInfo[0], CB_CheckedCountGet(FInfo) != 0,
        'Please select at least one category.')
*/
    );
}

function SinglePKVGet(AForm, ADefault, ARecordCaption)
{
  var Result = ADefault;
  var LIDs = CB_CheckedValuesGet(AForm.PKV);
  switch (LIDs.length)
  {
  case 0:
    alert('No ' + ARecordCaption + '(s) selected.');
    break;
  case 1:
    Result = LIDs[0];
    break;
  default:
    alert('Please, select only one ' + ARecordCaption);
  }
  return Result;
}

function SMItemClick(AParams, ASMID)
{
  if (AParams.slice(0, 11) == 'javascript:')
  {
    if (document.forms[0] && document.forms[0].SMID)
      document.forms[0].SMID.value = ASMID;
    eval(AParams.slice(11));
  }
  else
    document.location = WSA_URLGet2(AParams, ['SMID', ASMID]);
}

function SubMenu_SectionChange(AControl, ASearch)
{
  if (AControl.value != '')
  {
    var LSubMenuValues = AControl.value.replace(/;/g, '=');
    if (ASearch == true)
    {
      var LSMID = AControl.options[AControl.selectedIndex].text.split('-');
      if (LSMID.length > 1)
      {
        LSMID = LSMID[1].replace(/&nbsp;/g, ' ').charsetLimit(CS_Letters);
      }
      else
        LSMID = LSMID[0].replace(/&nbsp;/g, ' ').charsetLimit(CS_Letters);
      top.frames.frSubMenu.location = 'default.asp?' + SIDQ + LSubMenuValues + '&SMID=' + LSMID;
    }
    else
    {
      top.count++;
      top.QuickTips_SMIDs[top.QuickTips_SMIDs.length] = '&SMID=' + SMID.value + '&C_=' + C_.value;
      top.frames.frSubMenu.location = 'default.asp?' + SIDQ + 'S=' + SMSC_SubMenu + '&A=H' + LSubMenuValues;
    }
  }
}

function SubMenu_SectionFormOnSubmit(AAction)
{
  var LSubMenuSection = ElementGet('SubMenu_Section');
  var LSubMenuValues = LSubMenuSection.value.replace(/;/g, '=');
  var LComponent = LSubMenuValues.substring(LSubMenuValues.lastIndexOf('&C_=') + 4, LSubMenuValues.length);
  var LSMID = LSubMenuSection.options[LSubMenuSection.selectedIndex].text.split('-');
  if (LSMID.length > 1)
  {
    top.LSMID = LSMID[1].replace(/&nbsp;/g, ' ').charsetLimit(CS_Letters);
  }
  else
    top.LSMID = LSMID[0].replace(/&nbsp;/g, ' ').charsetLimit(CS_Letters);
  top.SubMenu_Search = LSubMenuValues;
  WaitMessageShow(top.frames.frMain);
  if (LComponent != top.SubMenu_Component)
  {
    top.SubMenu_Component = LComponent;
    top.frames.frHeader.location = WSA_URLGet(SMSC_Header, '', ['C_', top.SubMenu_Component]);
    top.frames.frSubMenuTabs.location = WSA_URLGet(SMSC_SubMenuTabs, AAction, ['C_', top.SubMenu_Component]);
  }
}

function SMGroupItemClick(AID)
{
  if (AID != '')
  {
    var i = 1;
    do
    {
      var LMenuTR = document.getElementById(AID + '|' + parseInt(i) + '|1');
      var LMenuTR2 = document.getElementById(AID + '|' + parseInt(i) + '|2');
      if (LMenuTR)
      {
        var LVisible = (LMenuTR.style.visibility == 'visible');
        LMenuTR.style.visibility = LVisible ? 'hidden' : 'visible';
        LMenuTR.style.display = LVisible ? 'none' : '';
        LMenuTR2.style.visibility = LVisible ? 'hidden' : 'visible';
        LMenuTR2.style.display = LVisible ? 'none' : '';
      }
      i++;
    }
    while (LMenuTR);
  }
}

function WaitMessageShow(AFrameOrWindow, AUseDIV)
{
  var LWaitMessageBody, LWaitMessage;
  if (typeof(PopupLoadMsg) == 'undefined')
  {
    LWaitMessageBody = [
      '<table width="100%" height="100%">',
      '<tr><td valign="center" align="center">',
      '<font size="4"><b>Loading, please wait . . .</b></font>',
      '<br><br><br><br></td>',
      '</tr>',
      '</table>'
    ].join('');
    LWaitMessage = [
      '<body scroll="no" bgcolor="white" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0">',
      LWaitMessageBody,
      '</body>'
    ].join('');
  }
  else
  {
    LWaitMessage = PopupLoadMsg;
    LWaitMessageBody = PopupLoadMsgBody;
  }
  try
  {
    var LDoc = (!AFrameOrWindow) ? document : AFrameOrWindow.document;
    if (AUseDIV)
    {
      var LDIV = LDoc.createElement('DIV');
      with (LDIV)
      {
        style.position = 'absolute';
        style.left = 0;
        style.top = 0;
        style.width = LDoc.body.offsetWidth;
        style.height = LDoc.body.offsetHeight;
        style.backgroundColor = 'white';
        style.zIndex = 9999999;
        innerHTML = LWaitMessageBody;
      }
      var LComboBoxes = LDoc.getElementsByTagName('SELECT');
      for (var i = 0; i < LComboBoxes.length; i++)
        LComboBoxes[i].style.display = 'none';
      LDoc.body.appendChild(LDIV);
    }
    else
      try
      {
        LDoc.open();
        LDoc.write(LWaitMessage);
        LDoc.close();
      } catch (E)
      {
        // ignoring error as we can not replace content (due to different domain for ex.)
      }
  } catch (E)
  {
    // ignoring error as we can not access to document (due to opener is secure but popup is not for ex.)
  }
}

var ActionBar_WindowOnResizeOld;
var ActionBar_ScrollStep = 70;

function ActionBarArrowsUpdate(AtblActionBarWrapper, AtblActionBar)
{
  var LtdScrollButtonLeft = document.getElementById('tdScrollButtonLeft');
  var LtdScrollButtonRight = document.getElementById('tdScrollButtonRight');

  if (AtblActionBar.clientWidth > AtblActionBarWrapper.clientWidth)
  {
    LtdScrollButtonLeft.style.display = 'inline';
    LtdScrollButtonRight.style.display = 'inline';

    document.getElementById('imgScrollButtonLeft').src = SharedURL + 'Images/ActionBar/arrowleft_' + (parseInt(AtblActionBar.style.left) == AtblActionBarWrapper.clientWidth - AtblActionBar.clientWidth ? 'passive' : 'active') + '.gif';
    document.getElementById('imgScrollButtonRight').src = SharedURL + 'Images/ActionBar/arrowright_' + (parseInt(AtblActionBar.style.left) == 0 ? 'passive' : 'active') + '.gif';
  }
  else
  {
    LtdScrollButtonLeft.style.display = 'none';
    LtdScrollButtonRight.style.display = 'none';
  }
}

function ActionBarScroll(AStep)
{
  var LtblActionBarWrapper = document.getElementById('tblActionBarWrapper');
  var LtblActionBar = document.getElementById('tblActionBar');

  var LStep = AStep * ActionBar_ScrollStep;
  var LNewPosition = parseInt(LtblActionBar.style.left) + LStep;

  if (LtblActionBarWrapper.clientWidth < LtblActionBar.clientWidth)
  {
    var LMaxLeftPosition = LtblActionBarWrapper.clientWidth - LtblActionBar.clientWidth;
    if (LNewPosition < LMaxLeftPosition)
      LNewPosition = LMaxLeftPosition;
  }
  else
    LNewPosition = 0;

  if (LNewPosition > 0)
    LNewPosition = 0;

  LtblActionBar.style.left = LNewPosition + 'px';
  ActionBarArrowsUpdate(LtblActionBarWrapper, LtblActionBar);
}

function ActionBar_Resize()
{
  if (ActionBar_WindowOnResizeOld)
    ActionBar_WindowOnResizeOld();

  ActionBarScroll(0);
}

function ActionBar_WindowOnResizeInit()
{
  var LScrollingAvailable = false;
  var LMSIEPos = navigator.userAgent.indexOf('MSIE');
  if (LMSIEPos >= 0)
  {
    var LMSIEVersion = parseInt(navigator.userAgent.slice(LMSIEPos + 5, LMSIEPos + 8));
    if (LMSIEVersion >= 5.0)
      LScrollingAvailable = true;
  }

  if (navigator.userAgent.indexOf('Firefox') >= 0)
    LScrollingAvailable = true;

  if (LScrollingAvailable)
    if (document.getElementById('tblActionBar'))
    {
      ActionBar_WindowOnResizeOld = window.onresize;
      window.onresize = ActionBar_Resize;
      ActionBar_Resize();
    }
/*  ActionBar_Resize();
  if (navigator.userAgent.indexOf('MSIE') < 0)
    setTimeout('ActionBar_Resize()', 0);*/
}

function DocumentBody_AttachEvent(AEventName, AHandlerName)
{
  try
  {
    document.body.attachEvent('on' + AEventName, AHandlerName);
  }
  catch (E)
  {
    document.body.addEventListener(AEventName, AHandlerName, false);
  }
}

function DTP_Clear(AForm, AElementName, ASkip)
{
  if (ASkip)
    return;

  var Result;
  Result = DatePickerCreate(ElementGet(AElementName), '', dpoDate | dpoOptional);
  Result.dateSet((new Date()));
  Result.childGet('cbEnabled').checked = false;
  Result.enabledSet(false);
  return Result;
}

function getAbsTop(AElem)
{
  if (!AElem)
    return 0;
  else
  if (AElem.offsetParent.nodeName == "BODY")
    return (AElem.offsetTop - AElem.scrollTop);
  else
    return (AElem.offsetTop - AElem.scrollTop + getAbsTop(AElem.offsetParent));
}

function getAbsLeft(AElem)
{
  if (!AElem)
    return 0;
  else
  if (AElem.offsetParent.nodeName == "BODY")
    return AElem.offsetLeft;
  else
    return (AElem.offsetLeft + getAbsLeft(AElem.offsetParent));
}

function hideSelectBoxes(AObject, ALeftAdjustement)
{
  if (!AObject)
    return;
  if (!AObject.sboxes)
    AObject.sboxes = [];
  var ol = getAbsLeft(AObject);
  var ot = getAbsTop(AObject);
  var ow = AObject.offsetWidth;
  var oh = AObject.offsetHeight;
  var sboxes = document.getElementsByTagName("select");

  for (var i = 0; i < sboxes.length; i++)
  {
    var node = sboxes[i].parentNode;
    while (node != AObject && node.tagName != "BODY")
      node = node.parentNode;
    var skip = (node == AObject);
    if (skip)
      continue;
    var t = getAbsTop(sboxes[i]);
    var l = getAbsLeft(sboxes[i]);
    if (ALeftAdjustement)
      l = l - ALeftAdjustement;
    var w = sboxes[i].offsetWidth;
    var h = sboxes[i].offsetHeight;
    var ver = false;
    if (t > ot && t < (ot + oh))
      ver = true;
    else if ((t + h) > ot && (t + h) < (ot + oh))
      ver = true;
    var hor = false;
    if (l > ol && l < (ol + ow))
      hor = true;
    else if ((l + w) > ol && (l + w) < (ol + ow))
      hor = true;
    else if (l < ol && (l + w) > ol)
      hor = true;
    if (ver && hor && sboxes[i].style.visibility != "hidden")
      AObject.sboxes[AObject.sboxes.length] = sboxes[i];
  }
  for (var i = 0; i < AObject.sboxes.length; i++)
    AObject.sboxes[i].style.visibility = "hidden";
}

function showSelectBoxes(AObject)
{
  if (!AObject)
    return;
  if (!AObject.sboxes)
    return;
  for (var i = 0; i < AObject.sboxes.length; i++)
    AObject.sboxes[i].style.visibility = "";
  AObject.sboxes = [];
}

function GoogleAnalyticsTrackerPrepare(AAccount)
{
  var LpageTracker = _gat._getTracker(AAccount);

  LpageTracker._initData();
  LpageTracker._trackPageview();
}

// input hints

var HINT_COLOR = '#AAAAAA';
var TEXT_COLOR = '#000000';

function cHints()
{
  this.init = cHints_init;
  this.onsubmit = cHints_onsubmit;
}

function cHints_init()
{
  var LElements = document.getElementsByTagName('INPUT');
  for(var i = 0; i < LElements.length; i++)
  {
    var LElement = LElements[i];
    if ((LElement.title != '') && (LElement.style.display == ''))
    {
      LElement.onfocus = cHintElement_onfocus;
      LElement.onblur = cHintElement_onblur;

      if (LElement.type == 'password')
      {
        LElement.passwordInputHandle = e_passwordInputHandle;
        if (document.all)
          passwordInputStubCreate(LElement);
        LElement = LElement.passwordInputHandle((LElement.value != '') || LElement.editmode);
      }

      if (((LElement.value == '') || (LElement.value == LElement.title)) && (!LElement.editmode))
      {
        LElement.value = LElement.title;
        LElement.style.color = HINT_COLOR;
        LElement.editmode = false;
        LElement.modified = false;
      }
      else
      {
        LElement.style.color = TEXT_COLOR;
        LElement.modified = true;
      }
    }
  }
}

function cHintElement_onfocus()
{
  var LObj = this;
  LObj.editmode = true;
  if ((LObj.type != 'password') && LObj.passwordInputHandle)
  {
    LObj = LObj.passwordInputHandle(true);
    if (document.all)
    {
      LObj.focus();
      return;
    }
    else
      LObj.modified = false;
  }

  if(LObj.modified)
    return;

  LObj.value = '';
  LObj.style.color = TEXT_COLOR;
  LObj.select();
}

function cHintElement_onblur()
{
  this.editmode = false;
  this.modified = (this.value != '');

  if (!this.modified)
  {
    if (this.type == 'password')
    {
      this.passwordInputHandle(false).onblur();
      return;
    }

    this.value = this.title;
    this.style.color = HINT_COLOR;
  }
}

function cHints_onsubmit()
{
  var LElements = document.getElementsByTagName('INPUT');
  for (var i = 0; i < LElements.length; i++)
  {
    var LElement = LElements[i];
    if (LElement.style.display == '')
    {
      if ((LElement.type == 'password') && (LElement.onblur) || (LElement.editmode))
        LElement.onblur();
      if ((LElement.title != '') && (!LElement.modified))
        LElement.value = '';
    }
  }
}

function passwordInputStubCreate(AObj)
{
  if (ElementGet(AObj.name + '_Stub'))
    return;

  var LInput = document.createElement('<INPUT TYPE="text" name="' + AObj.name + '_Stub">');
  LInput.className = AObj.className;
  LInput.disabled = AObj.disabled;
  LInput.maxlength = AObj.maxlength;
  LInput.style.color = AObj.style.color;
  LInput.style.width = AObj.style.width;
  LInput.tabIndex = AObj.tabIndex;
  LInput.title = AObj.title;
  LInput.onblur = AObj.onblur;
  LInput.onfocus = AObj.onfocus;
  LInput.passwordInputHandle = AObj.passwordInputHandle;

  AObj.parentNode.appendChild(LInput);
}

function e_passwordInputHandle(AIsPassword)
{
  var LType = (AIsPassword ? 'password' : 'text');
  if (document.all)
  {
    var LName = this.name.replace('_Stub', '');
    var LTextInput = ElementGet(LName + '_Stub');
    var LPasswordInput = ElementGet(LName);

    LTextInput.style.display = (AIsPassword ? 'none' : '');
    LPasswordInput.style.display = (AIsPassword ? '' : 'none');

    var LResult = (AIsPassword ? LPasswordInput : LTextInput);
    LResult.modified = this.modified;
    LResult.editmode = this.editmode;

    return LResult;
  }
  else
  {
    this.type = LType;
    return this;
  }
}

// popup hits handling

function HintDisplay(AObj, AShow)
{  
  var LHW = ElementGet('HintWindow');
  if (!LHW)
  {
    LHW = document.createElement('div');
    LHW.id = 'HintWindow';
    LHW.style.border = '1px solid #E0E0E0';
    LHW.style.display = 'none';
    LHW.style.position = 'absolute';
    LHW.style.backgroundColor = '#FFFFCF';
    LHW.style.padding = '4 6 4 6';
    document.body.appendChild(LHW);
  }

  if (AShow)
  {
    var LdvMain = ElementGet('dvMain');
    LHW.innerHTML = AObj.alt.replace(/</mg, '&lt;').replace(/\r\n/mg, '<br>');
    LHW.style.top = getAbsTop(AObj) + AObj.width - (!document.all && LdvMain?LdvMain.scrollTop:0);
    LHW.style.left = getAbsLeft(AObj) + AObj.height;
  }

  LHW.style.display = (AShow?'':'none');
}

function StyleSheetAppend(AName, APath, AWnd)
{
  var LWnd = (AWnd?AWnd:window);
  var links = LWnd.document.getElementsByTagName('LINK');
  for (var i = 0; i < links.lenght; i++)
    if (links[i].title == AName)
      return false;

  var link  = LWnd.document.createElement('LINK');
  link.rel  = 'stylesheet';
  link.title= AName;
  link.href = APath;
  LWnd.document.getElementsByTagName('HTML')[0].appendChild(link);

  return true;
}
// Staff Dropdovn //
var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id, d) {
    var h = document.getElementById(id + '-ddheader');
    var c = document.getElementById(id + '-ddcontent');
    clearInterval(c.timer);
    if (d == 1) {
        clearTimeout(h.timer);
        if (c.maxh && c.maxh <= c.offsetHeight) { return }
        else if (!c.maxh) {
            c.style.display = 'block';
            c.style.height = 'auto';
            c.maxh = c.offsetHeight;
            c.style.height = '0px';
        }
        c.timer = setInterval(function () { ddSlide(c, 1) }, DDTIMER);
    } else {
        h.timer = setTimeout(function () { ddCollapse(c) }, 50);
    }
}

// collapse the menu //
function ddCollapse(c) {
    c.timer = setInterval(function () { ddSlide(c, -1) }, DDTIMER);
    document.getElementById('CommonSearchField').style.display = ""
    document.getElementById('CommonSearchField').style.marginTop = "-2px"
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id) {
    var h = document.getElementById(id + '-ddheader');
    var c = document.getElementById(id + '-ddcontent');
    clearTimeout(h.timer);
    clearInterval(c.timer);
    if (c.offsetHeight < c.maxh) {
        c.timer = setInterval(function () { ddSlide(c, 1) }, DDTIMER);
        document.getElementById('CommonSearchField').style.display = "none"
    }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c, d) {
    var currh = c.offsetHeight;
    var dist;
    if (d == 1) {
        dist = (Math.round((c.maxh - currh) / DDSPEED));
    } else {
        dist = (Math.round(currh / DDSPEED));
    }
    if (dist <= 1 && d == 1) {
        dist = 1;
    }
    c.style.height = currh + (dist * d) + 'px';
    c.style.opacity = currh / c.maxh;
    c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
    if ((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)) {
        clearInterval(c.timer);
    }
}

