// $Id: StartTool.js,v 1.32 2007-07-24 07:17:13 thchuong Exp $
/******************** WINDOWSIFICATION ********************************/
/*  CATGLOBE CATGLOBE CATGLOBE CATGLOBE CATGLOBE CATGLOBE CATGLOBE    */
/******************** WINDOWSIFICATION ********************************/
var menuDiv = null;

var igmenu_toolsMenu_Menu = ["toolsMenu", 2, 3, "", "HoverItem_VerticalMenu", "TopSelect_VerticalMenu", "/ig_common/images/ig_menuTri.gif", false, "300", "100", "NotSet", "#D3D3D3", "5", "200", "1000", "", "", "DisableItem_HorizontalAndPopupAndVerticalMenu", "ItemStyle_HorizontalAndPopupAndVerticalMenu", "/ig_common/images/ig_menuBlueUp.gif", "/ig_common/images/ig_menuBlueUp_disabled.gif", "/ig_common/images/ig_menuBlueDown.gif", "/ig_common/images/ig_menuBlueDown_disabled.gif", false, true, "", "", true, false];
var igmenu_toolsMenu_Events = [["", 0], ["", 0], ["toolsMenu_Clicked", 0], ["", 0], ["", 0]];

//Hover effect doesn't work properly on FireFox, this function is supposed to corrrect that problem
function toolsMenu_InitializeMenu(MenuId)
{
   var menu = igmenu_getMenuById(MenuId);
   ig_csom.getElementById = function(id)
   {
      return document.getElementById(id);
   }

   // apply a hack to the show child menu item: bring it up above the menuFrame
   menu.originalDisplaySubMenu = menu.displaySubMenu;
   menu.displaySubMenu = function(s, p, v) {
    //fix FF4/chrome problem
    if (typeof (s.runtimeStyle) == "undefined")
     s.runtimeStyle = {};
    s.style.zIndex = document.getElementById("menuFrame").style.zIndex + 1;
    menu.originalDisplaySubMenu(s, p, v);
    if (s.firstChild != null && s.firstChild.style != null && s.firstChild.style.width == "") {
     s.firstChild.style.width = s.style.width;
     if (s.firstChild.firstChild != null)
      s.firstChild.firstChild.style.width = s.style.width;
    }
   }
}

function hideToolsMenu()
{
   if (menuDiv != null && menuDiv.style.visibility == "visible")
   {
      menuDiv.style.visibility = "hidden";
      menuDiv.style.display = "none";

      toggleDropDownList("visible");
   }
}

function populateToolsMenu(data, menuid)
{
   document.body.scrollLeft = 0;
   document.body.scrollTop = 0;

   var mzIndex = -1;
   if (typeof (getMaxzIndex) == "function")
      mzIndex = getMaxzIndex();
   if (mzIndex == -1)
      mzIndex = 1000000;

   if (menuDiv == null)
   {
      menuDiv = document.createElement("div");
      document.body.appendChild(menuDiv);
      menuDiv.style.position = "absolute";
      menuDiv.style.top = "0px";
      menuDiv.style.left = "0px";
      menuDiv.style.visibility = "hidden";
      menuDiv.style.width = "100%";
      menuDiv.id = "menuFrame";

      menuDiv.innerHTML = data;
      igmenu_initMenu(menuid);
      toolsMenu_InitializeMenu(menuid);
      $(menuDiv).click(hideToolsMenu);
   }
   else if (menuDiv.style.display == "")
      return;

   menuDiv.style.height = document.body.clientHeight + "px";
   menuDiv.style.zIndex = mzIndex + 50;

   var mainMenu = document.getElementById(menuid + "_MainM");

   if (cg_shared.IsIE)
      mainMenu.rows[0].cells[0].style.padding = "0 0 0 0";

   if (mainMenu.offsetWidth < 250)
      mainMenu.style.width = 250;
   if (cg_shared.IsIE)
   {
      menuDiv.style.posLeft = document.body.scrollLeft;
      menuDiv.style.posTop = document.body.scrollTop;
   }
   else
   {
      menuDiv.style.left = document.body.scrollLeft;
      menuDiv.style.top = document.body.scrollTop;
   }

   menuDiv.style.visibility = "visible";
   menuDiv.style.display = "";

   var menu = null;

   if (cg_shared.IsIE)
   {
      menu = menuDiv.childNodes[0];
      menu.style.posBottom = menuDiv.style.posBottom;
   }
   else
   {
      menu = menuDiv.childNodes[1];
      menu.style.top = menuDiv.offsetHeight - menu.offsetHeight;
   }

   menu.style.position = "absolute";
   menuDiv.focus();

   var count = 0;
   while (++count)
   {
      var menuitem = document.getElementById(menuid + "_" + count);
      if (menuitem)
      {
         var item = menuitem.cells[0];
         var textDivs = item.getElementsByTagName("DIV");
         if (textDivs.length > 0)
         {
            item.getElementsByTagName("DIV")[0].style.marginTop = 8;
            item.getElementsByTagName("DIV")[0].style.paddingLeft = 15;

            var imgs = item.getElementsByTagName("IMG");
            if (imgs.length > 1)
               imgs[1].style.marginTop = 10;
         }
      }
      else
         break;
   }

   toggleDropDownList("hidden");
}

$(window).bind("scroll", null, hideToolsMenu);
$(window).bind("mouseup", null, hideToolsMenu);

/******************** WINDOWSIFICATION ********************************/

var phonebookDlg;
function openPhoneBook(hostpath, url)
{
   if ((phonebookDlg) && (phonebookDlg.isVisible()))
      return;

   phonebookDlg = new CatDialog(window, '', null, null, '', 400, 333, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   phonebookDlg.setUrl(hostpath + url);
   phonebookDlg.setTitle(null);
   phonebookDlg.maximize();
   phonebookDlg.setContentPadding(0);
   phonebookDlg.moveCenter();
   phonebookDlg.show(true);

}

//this method is invoked when my setting is chosen
var mySettingDlg;
function CatMenu_OpenMySetting(hostpath)
{
   if ((mySettingDlg) && (mySettingDlg.isVisible()))
      return;

   mySettingDlg = new CatDialog(window, '', null, null, '', 400, 333, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   mySettingDlg.setUrl(hostpath + "HomeModule/MySettings.aspx");
   if (cg_shared.IsIE)
      mySettingDlg.setSize(document.body.offsetWidth - 100, document.body.offsetHeight - 200);
   else
      mySettingDlg.setSize(document.body.clientWidth - 100, document.body.clientHeight - 200);
   mySettingDlg.setContentPadding(0);
   mySettingDlg.moveCenter();
   mySettingDlg.show(true);
}

//this method is invoked when mass access update is chosen
var massAccessUpdateDlg;
function CatMenu_OpenMassAccessUpdate(hostpath)
{
   if ((massAccessUpdateDlg) && (massAccessUpdateDlg.isVisible()))
      return;

   massAccessUpdateDlg = new CatDialog(window, '', null, null, '', 590, 530, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   massAccessUpdateDlg.setUrl(hostpath + "SecurityModule/MassAccessWizard/MassAccessUpdate.aspx");
   // massAccessUpdateDlg.setTitle("Mass Access Update");
   massAccessUpdateDlg.setSize(590, 450);
   massAccessUpdateDlg.setContentPadding(0);
   massAccessUpdateDlg.moveCenter();
   massAccessUpdateDlg.show(true);
}

//this method is invoked when mass preference settings is chosen
var massPreferenceSettingsDlg;
function CatMenu_OpenMassPreferenceSettings(hostpath)
{
   if ((massPreferenceSettingsDlg) && (massPreferenceSettingsDlg.isVisible()))
      return;

   massPreferenceSettingsDlg = new CatDialog(window, '', null, null, '', 590, 530, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   massPreferenceSettingsDlg.setUrl(hostpath + "SecurityModule/MassPreferenceWizard/MassPreferenceWizard.aspx");
   massPreferenceSettingsDlg.setSize(590, 440);
   massPreferenceSettingsDlg.setContentPadding(0);
   massPreferenceSettingsDlg.moveCenter();
   massPreferenceSettingsDlg.show(true);
}

//this method is invoked when recycle bin is chosen
var recycleBinDlg;
function CatMenu_OpenRecycleBin(hostpath)
{
   if ((recycleBinDlg) && (recycleBinDlg.isVisible()))
      return;

   recycleBinDlg = new CatDialog(window, '', null, null, '', 590, 530, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   //viet hack (opening recycle bin too slow): (default) we will open recycle bin with type = Asset
   recycleBinDlg.setUrl(hostpath + "RecycleBin/RecycleBinPage.aspx?type=Asset");
   recycleBinDlg.setSize(800, 400);
   recycleBinDlg.maximize();
   recycleBinDlg.setContentPadding(0);
   recycleBinDlg.moveCenter();
   recycleBinDlg.show(true);
}

//this method is invoked when Data Import Wizard is chosen
var dlgDataImportWizard;
function CatMenu_OpenDataImportWizard(hostpath, moduleInfo)
{
   if ((dlgDataImportWizard) && (dlgDataImportWizard.isVisible()))
      return;

   dlgDataImportWizard = new CatDialog(window, '', null, null, '', 500, 600, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, false, false, true, false, -1);
   dlgDataImportWizard.setUrl(hostpath + "DataModule/DataImport2/DataImportWizard.aspx?" + moduleInfo);
   dlgDataImportWizard.setTitle("Data Import Wizard");
   dlgDataImportWizard.isResizable = false;
   dlgDataImportWizard.showResizeIcon(false);
   dlgDataImportWizard.show(true);
   dlgDataImportWizard.setSize(600, 500);
   dlgDataImportWizard.moveCenter();
}

//this method is invoked when Data Export Wizard is chosen
var dlgDataExportWizard;
function CatMenu_OpenDataExportWizard(hostpath, moduleInfo)
{
   if ((dlgDataExportWizard) && (dlgDataExportWizard.isVisible()))
      return;

   dlgDataExportWizard = new CatDialog(window, '', null, null, '', 612, 803, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   dlgDataExportWizard.setUrl(hostpath + "DataModule/DataExport/DataExportWizard.aspx?" + moduleInfo);
   dlgDataExportWizard.setTitle("Data Export Wizard");
   dlgDataExportWizard.moveCenter();
   dlgDataExportWizard.maximize();
   dlgDataExportWizard.show(true);

}
//this method is invoked when DCS Data Export Wizard is chosen
var dlgDCSDataExportWizard;
function CatMenu_OpenDCSDataExportWizard(hostpath, moduleInfo)
{
   if ((dlgDCSDataExportWizard) && (dlgDCSDataExportWizard.isVisible()))
      return;

   dlgDCSDataExportWizard = openDialog('', hostpath + "DataModule/DCSDataExport/Wizard.aspx?Id=0", true);
   dlgDCSDataExportWizard.setSize(800, 600);
   dlgDCSDataExportWizard.moveCenter();
}


//this method is invoked when xxxx is chosen

function lookupid(hostpath)
{
   var lookupDlg = findDialog("lookup");
   if ((dlgDCSDataExportWizard) && (dlgDCSDataExportWizard.isVisible()))
      return;

   if (!lookupDlg)
   {
      lookupDlg = new CatDialog(window, '', null, null, '', 120, document.body.offsetWidth - 450, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
      lookupDlg.setId("lookup");
      lookupDlg.setUrl(hostpath + "SecurityModule/lookupresourceid.aspx");
   }
   else
   {
      if (lookupDlg.isVisible())
         return;
      lookupDlg.getInnerWindow().location.reload(false);
   }

   lookupDlg.move(15, 10);
   lookupDlg.setModal(false);

   lookupDlg.isResizable = false;
   // lookupDlg.isMovable = false;
   lookupDlg.showMaxButton(false);
   lookupDlg.showMinButton(false);
   lookupDlg.show(true);
   return lookupDlg;
}

//this method is invoked when navigation access is chosen
var NavigationAccessDlg;
function CatMenu_OpenNavigationAccess(hostpath)
{
   if ((NavigationAccessDlg) && (NavigationAccessDlg.isVisible()))
      return;

   NavigationAccessDlg = new CatDialog(window, '', null, null, '', 590, 530, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   NavigationAccessDlg.setUrl(hostpath + "SecurityModule/Navigation/NavigationAccessOverview.aspx");
   NavigationAccessDlg.maximize();
   NavigationAccessDlg.setContentPadding(0);
   NavigationAccessDlg.moveCenter();
   NavigationAccessDlg.show(true);
}

// this method is invoked when questionnaire statistics is choosen

var dlgQuestionnaireStatistics;
function CatMenu_OpenQuestionnaireStatistics(hostpath)
{
   if ((dlgQuestionnaireStatistics) && (dlgQuestionnaireStatistics.isVisible()))
      return;

   dlgQuestionnaireStatistics = new CatDialog(window, '', null, null, '', 600, 800, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   dlgQuestionnaireStatistics.setUrl(hostpath + "QuestionnaireModule/QuestionnaireStatistics/QuestionnaireStatisticsForm.aspx");
   dlgQuestionnaireStatistics.setTitle("Questionnaire Statistics");
   dlgQuestionnaireStatistics.moveCenter();
   dlgQuestionnaireStatistics.maximize();
   dlgQuestionnaireStatistics.show(true);


}
// this method is invoked when used minutes Report is choosen
var dlgUsedMinuteReport;
function CatMenu_OpenUsedMinuteReport(hostpath)
{
   if ((dlgUsedMinuteReport) && (dlgUsedMinuteReport.isVisible()))
      return;

   dlgUsedMinuteReport = new CatDialog(window, '', null, null, '', 500, 450, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, true, true, true, false, -1);
   dlgUsedMinuteReport.setUrl(hostpath + "QuestionnaireModule/QuestionnaireStatistics/UsedMinuteReport.aspx");
   dlgUsedMinuteReport.setTitle("Overview of Used Interview Minutes");
   dlgUsedMinuteReport.moveCenter();
   //dlgUsedMinuteReport.setSize(400, 600);
   //dlgUsedMinuteReport.maximize();
   dlgUsedMinuteReport.show(true);


}
//this method is invoked when Cost And Revenue Entry is selected
var QuickEntryEditorDlg;
function CatMenu_OpenQuickEntryEditor()
{
   if (QuickEntryEditorDlg)
   {
      if (QuickEntryEditorDlg.isVisible())
         return;
   }

   QuickEntryEditorDlg = openDialog(virtualAppHost, virtualAppHost + "Common/Resources/Cost/QuickEntryEditor.aspx", true);
   QuickEntryEditorDlg.setSize(800, 600);
   QuickEntryEditorDlg.moveCenter();
}

//this method is invoked when Language And Culture Management is selected.
var OpenLanguageAndCultureManagementDlg = null;
function System_OpenLanguageAndCultureManagement()
{
   if (OpenLanguageAndCultureManagementDlg)
   {
      if (OpenLanguageAndCultureManagementDlg.isVisible())
         return;
   }

   OpenLanguageAndCultureManagementDlg = openDialog(virtualAppHost, virtualAppHost + "SecurityModule/Localization/Management.aspx", true);
   OpenLanguageAndCultureManagementDlg.setSize(800, 600);
   OpenLanguageAndCultureManagementDlg.moveCenter();
}

function toolsMenu_Clicked(menuID, itemID)
{
   var item = igmenu_getItemById(itemID);
   if (item.getTargetUrl() != "" && item.getTargetUrl() != "#" && item.getItems().length == 0)
      hideToolsMenu();
   else
      return true;
}

function OpenFieldworkManagement(url)
{
   window.open(url, '_blank', 'left=150,top=100,width=1000,height=750,scrollbars=yes,status=yes,resizable=yes');
}

//this method is invoked when Apology Message Settings is chosen
var dlgApologyMsgSetting;
function CatMenu_OpenVoIPFailureMessageSetting(hostpath)
{
   if ((dlgApologyMsgSetting) && (dlgApologyMsgSetting.isVisible()))
      return;

   dlgApologyMsgSetting = new CatDialog(window, '', null, null, '', 600, 500, hostpath + '/Images/Common/CatDialog', 'SteelBlue2_', 'SteelBlue', 'Transparent', null, '', '', false, true, false, true, true, false, false, false, false, false, false, false, true, false, -1);
   dlgApologyMsgSetting.setUrl(hostpath + "TelephonyModule/ApologyMessage.aspx");
   dlgApologyMsgSetting.setTitle("VoIP failure Message");
   dlgApologyMsgSetting.setSize(450, 600);
   dlgApologyMsgSetting.moveCenter();
   dlgApologyMsgSetting.isResizable = false;
   dlgApologyMsgSetting.showResizeIcon(false);
   dlgApologyMsgSetting.show(true);
}

function OpenImportBlacklistedEmails()
{
   ///<summary>Open the import blacklisted emails dialog.</summary>
   var dlg = openDialog(virtualAppHost, virtualAppHost + "CommunicatorModule/Cati/ImportBlackEmails.aspx?", true);
   dlg.papa = window;
   dlg.setSize(650, 450);
   dlg.showMaxButton(false);
   dlg.showMinButton(false);
   dlg.showResizeIcon(false);
   dlg.moveCenter();
}
