function Bookmark_Add(AGroupID, ADescription, AURL)
{
  Popup(WSA_URLGet(SCRM_Bookmarks, 'N', ['GroupID', AGroupID, 'Description', ADescription, 'URL', AURL]), 250, 130);
}

function Bookmark_Remove(APKV)
{
  if (confirm('Do you want to remove the bookmark?'))
    top.frames.frMain.location = WSA_URLGet(SCRM_Bookmarks, 'D', ['PKV', APKV]);
}

function Bookmark_Save(AForm)
{
  with (AForm)
  {
    Descr = Description.value;
    Descr = Descr.trim();
    if (Descr == '')
    {
      alert('Please, enter valid description');
      Description.focus();
      Description.value = '';
      return;
    }
    
    for (i = 0; i < LExistingBookmarkNames.length; i++)
      if (Descr == LExistingBookmarkNames[i])
      {
        alert('Bookmark named "' + Descr + '" already exists');
        Description.focus();
        Description.value = Descr;
        return;
      }

    submit();
  }
}

function Bookmarks_Show()
{
  top.frames.frMain.location = WSA_URLGet(SCRM_Bookmarks);
}

function MerchantAdminShow(ALogonURL)
{
  window.open(ALogonURL, null, 
    'toolbar=1,location=1,directories=1,menubar=1' +
    ',status=1,scrollbars=1,resizable=1,width=1000,height=700,top=50,left=50');
}

function Button_onclick(ATopicDivName, ATopicImageName, APath)
{
  if (ATopicDivName.style.visibility == 'visible') 
  {
    ATopicDivName.style.visibility = 'hidden';
    ATopicDivName.style.position = 'absolute';
    ATopicImageName.src = APath + 'Images/plus.gif';
  }
  else
  {
    ATopicDivName.style.visibility = 'visible';
    ATopicDivName.style.position = 'relative';
    ATopicImageName.src = APath + 'Images/minus.gif';
  } 
}

function CaseHistory()
{
  top.frames.frMain.location = WSA_URLGet(SCRM_CaseHistory);
}

function CaseReply(AForm)
{
  with (AForm)
  {
    if
    (
      FieldValidate(elements['ReplyDescription'], fvtNotEmpty, 'Reply Description', '', true)
    )
    submit();
  }
}

function CaseSubmit(AForm)
{
  with (AForm)
  {
    if
    (
      Name_FieldValidate(AForm, '')
      &&
      FieldValidate(elements['Email'], fvtEMail, 'Email', '', true)
      &&
      FieldValidate(elements['Category'], fvtNotEmpty, ' Category', '', true)
      &&  
      FieldValidate(elements['Subject'], fvtNotEmpty, ' Subject', '', true)
    )
    submit();
  }
}

function ContactSupport()
{
  top.frames.frMain.location = WSA_URLGet(SCRM_CaseDetails, 'N');
}

function CRM_SubMenuClick(AParams, ASearchParams, AHelpParams, ASubMenuItemID, ANodeClick)
{
  if (top.NeedRefreshFrameset == 1)
  {
    top.document.location = WSA_URLGet(SMSC_FrameSet, '', []);
    top.NeedRefreshFrameset = 0;
  }

  SubMenuClick(AParams, ASearchParams, AHelpParams, ASubMenuItemID, ANodeClick);
}

function DocumentLoad(ANodeID)
{
  top.location = WSA_URLGet(SMSC_FrameSet, '', ['HelpIndexNodeID', ANodeID]);
}

function DocumentLoadByDocNo(ADocNo)
{
  top.location = WSA_URLGet(SMSC_FrameSet, '', ['HelpIndexDocNo', ADocNo]);
}

function FeedbackSubmit(AForm)
{
  with (AForm)
  {
    if
    (
      FieldValidate(elements['FNameLong'], fvtNotEmpty, 'Name', '', true)
      &&
      FieldValidate(elements['FEMail'], fvtEMail, 'Email', '', true)
      &&
      FieldValidate(elements['FPhone'], fvtPhone, 'Phone Number', '', true)
    )
    submit();
  }
}

function FrameSetRefreshAdd()
{
  top.NeedRefreshFrameset = 1;
}

function LeftColumn_ShowHide()
{
  top.document.getElementById('frsBody').cols = (SubMenu_IsShowing() ? '0' : frSubMenuWidth_Support) + ',*';
  document.getElementById('ShowHideLink').innerHTML = (SubMenu_IsShowing() ?
    'Show Left Column<img src="' + SharedURL + 'Images/SupportCenter/fgfx_showarrow.gif" width="5" height="13" hspace="8" border="0" align="absmiddle">' :
    '<img src="' + SharedURL + 'Images/SupportCenter/fgfx_hidearrow.gif" width="5" height="13" hspace="8" border="0" align="absmiddle">Hide Left Column');
  top.SubMenu_IsShow = !top.SubMenu_IsShow;
}

function frMain_OnBeforePrint()
{
  document.body.scroll = 'yes';
  if (ElementGet('dvMain'))
  {
    ElementGet('dvMain').style.height = '';
    ElementGet('dvMain').style.width  = '';
  }
}

function frMain_OnAfterPrint()
{
  document.body.scroll = 'no';
  if (ElementGet('dvMain'))
  {
    ElementGet('dvMain').style.height = '100%';
    ElementGet('dvMain').style.width  = '100%';
  }
}

function frMain_Print()
{
  if (top.frames.frMain)
    with (top.frames.frMain)
    {
      if (ElementGet('dvMain'))
      {
        ElementGet('dvMain').style.height = '50%';
        ElementGet('dvMain').style.width = '50%';
      }
      document.body.onbeforeprint = frMain_OnBeforePrint;
      document.body.onafterprint = frMain_OnAfterPrint;
      print();

      if (ElementGet('dvMain'))
      {
        ElementGet('dvMain').style.height = '100%';
        ElementGet('dvMain').style.width = '100%';
      }
    }
}

function GlossaryTermDisplay()
{
  var LTermID = document.getElementById('slTerms').value;
  document.getElementById('bTerm').innerHTML = Term[2 * LTermID];
  document.getElementById('divDescription').innerHTML = Term[2 * LTermID + 1];
}

function GlossaryListCreate()
{
  var LGlossaryList = '';
  LGlossaryList = '<select id="slTerms" size="2" onchange="GlossaryTermDisplay();" style="height:70%;width:100%">';
  for (i = 0; i < Term.length / 2; i++)
  {
   LGlossaryList += '<option value=' + i + '>' + Term[2 * i];
  }
  LGlossaryList += '</select>';
  document.getElementById('Terms').innerHTML = LGlossaryList;
}

function HeaderPrepare(ATabName)
{
  if (ATabName == 'ContactSupport')
  {
    document.getElementById('imgHelpTopicsTab').src = LTemplateURL + 'Images/Top/btn_HelpTopicsTab.gif';
    document.getElementById('imgContactSupportTab').src = LTemplateURL + 'Images/Top/btn_ContactSupportTab_Active.gif';
    document.getElementById('imgTabsBottom').src = LTemplateURL + 'Images/Top/TopNav_base_Contact.gif';
  }
}

function MerchantAccountActivate()
{
  top.frames.frMain.location = WSA_URLGet(SCRM_MerchantActivation);
}

function MerchantActivationSubmit(AForm)
{
  with (AForm)
  {
    if
    (
      Name_FieldValidate(AForm, '')
      &&
      FieldValidate(elements['CardNumber1'], fvtNotEmpty, 'Card Number', '', true)
      &&
      FieldValidate(elements['CardNumber2'], fvtNotEmpty, 'Card Number', '', true)
      &&  
      FieldValidate(elements['ZIP'], fvtZIP, 'ZIP Code', '', true)
    )
    submit();
  }
}

function MerchantLogon()
{
  top.frames.frMain.location = WSA_URLGet(SWSA_Logon);
}

function SearchSubmit(ASearchText)
{
  if (ASearchText == '')
  {
    alert('Search words or question should not be empty');
    return;
  }
  top.frames.frMain.location = WSA_URLGet(SCRM_AdvSearch, '', ['SearchText', ASearchText, 'Action', 'S']);
}

function SupportCenter_Logout()
{
  if (confirm('This action will log you out. Are you sure?'))
    top.document.location = WSA_URLGet(SCRM_Logout);
}

function ContactInfoSubmit(AForm)
{
  if (FieldValidate(AForm.NameFirst, fvtName, 'First Name', '', true) &&
    FieldValidate(AForm.NameLast, fvtName, 'Last Name', '', true) &&
    FieldValidate(AForm.Email, fvtEMailEx, 'Email', '', true) &&
    FieldValidate(AForm.Phone, fvtPhone, 'Phone', '', true))
    AForm.submit();
}

function WaitForFlashUpload(AResize)
{
  WaitMessageShow(window, true);
  window.setTimeout("ElementGet('dvTour').style.visibility = 'visible'; if(" + AResize + "){window.resizeTo(728, 728); document.getElementsByTagName('DIV')[4].outerHTML = '';};", 10000);
}
