
/*  
This file contains functions used by pages which host UIWebFormController
*/

var FuncPtr = null;
var HostPageIncludeDomainInPopup;

function createHiddenElement(id) {
    var elm = document.createElement("input");
    elm.setAttribute("type", "hidden");
    elm.setAttribute("id", id);
    elm.setAttribute("name", id);
    document.forms[0].appendChild(elm);
    return elm
}

function PostMessage(piMsgID, psMsgData, psWebForm, psSender, pbPostBack) {

    var mainPopUpMsgID = document.getElementById("MainPopUpMsgID");
    if (!mainPopUpMsgID) {
        mainPopUpMsgID = createHiddenElement("MainPopUpMsgID");
    }
    mainPopUpMsgID.setAttribute("value", piMsgID);

    var mainPopUpMsgData = document.getElementById("MainPopUpMsgData");
    if (!mainPopUpMsgData) {
        mainPopUpMsgData = createHiddenElement("MainPopUpMsgData");
    }
    mainPopUpMsgData.setAttribute("value", psMsgData);

    var mainPopUpTempWebForm = document.getElementById("MainPopUpTempWebForm");
    if (!mainPopUpTempWebForm) {
        mainPopUpTempWebForm = createHiddenElement("MainPopUpTempWebForm");
    }
    mainPopUpTempWebForm.setAttribute("value", psWebForm);

    var mainPopUpSender = document.getElementById("MainPopUpSender");
    if (!mainPopUpSender) {
        mainPopUpSender = createHiddenElement("MainPopUpSender");
    }
    mainPopUpSender.setAttribute("value", psSender);
    
    if (FuncPtr != null) {
        FuncPtr();
        FuncPtr = null;
    }

    if (pbPostBack == true)
        __doPostBack("", "");
}

function OpenPopUp(psPopUpURL, pWinSizeX, pWinSizeY, pScrollBars, pMenuBar, pModal) {
    var winSizeY = 730;
    var winSizeX = 560;
    var bScrollBars = 0;
    var bMenuBar = 0;
    var bModal = true;

    if (pWinSizeX != null)
        winSizeX = pWinSizeX;

    if (pWinSizeY != null)
        winSizeY = pWinSizeY;

    if (pScrollBars != null) {
        if (pScrollBars)
            bScrollBars = 1;
    }

    if (pMenuBar != null) {
        if (pMenuBar)
            bMenuBar = 1;
    }

    if (pModal != null)
        bModal = pModal;

    //remember to include createWinPosModal in GenericFunctions.js when checking in.
    //  Currently the following check is necessary, as the combination of Modal and IE7 doesn't work
    //    with a PostBack...with IE5 / IE6 setting target=_self handles that problem...not with IE7
    //     hence letting the window open as a regular window rather than a modal window when IE7.
    var version = 0
    if (navigator.appVersion.indexOf("MSIE") != -1) {
        temp = navigator.appVersion.split("MSIE")
        version = parseFloat(temp[1])
    }

    if (bModal && version < 7.0) {
        window.showModalDialog(psPopUpURL, window, "status:0;scroll:" + bScrollBars + ";resizable:0;" + createWinPosModal(winSizeY, winSizeX));
    } else {
        window.open(psPopUpURL, "winLookup" + Math.round((Math.random() * 100)), "toolbar=0,menubar=" + bMenuBar.toString() + ",scrollbars=" + bScrollBars.toString() + ",resizable=0," + createWinPos(winSizeY, winSizeX));
    }

    //document.body.style.cursor="default";
}

//does not work properly
function ShowPopUpDialog(psPopUpURL, pWinSizeX, pWinSizeY, pScrollBars, pMenuBar, pModal) {
    sPopUpURL = psPopUpURL;
    WinSizeX = pWinSizeX;
    WinSizeY = pWinSizeY;
    ScrollBars = pScrollBars;
    MenuBar = pMenuBar;
    Modal = pModal;

    //document.body.style.cursor="wait";

    setTimeout("OpenPopUp(sPopUpURL, WinSizeX, WinSizeY, ScrollBars, MenuBar, Modal )", 10);
}

function TriggerPopUp(psWebForm, psUserForm, psPopUpParams, pbPostBack, pFuncPtr, pWinSizeX, pWinSizeY, pScrollBars, pMenuBar, pModal, pWaitPage) {
    FuncPtr = pFuncPtr;
    if (pWaitPage == null)
        pWaitPage = true;

    var sUrl = SMPRootVar + "/MasterPage/PopUpHost.aspx?" + psPopUpParams + "&WebForm=" + psWebForm + "&UserForm=" + psUserForm + "&PostBack=" + pbPostBack + "&WaitPage=" + pWaitPage;
    if (HostPageIncludeDomainInPopup)
        sUrl = sUrl + "&Domain=" + window.document.domain;

    OpenPopUp(sUrl, pWinSizeX, pWinSizeY, pScrollBars, pMenuBar, pModal);
    return false;
}

function LoadModule(psAppModule, psUserForm) {
    this.AppModule = psAppModule;
    this.UserForm = psUserForm;
    this.ReturnFunction = null;

    this.ReturnForm = "";
    this.Params = "";
    this.WinSizeX = 200;
    this.WinSizeY = 200;
    this.ScrollBars = false;
    this.MenuBar = false;
    this.Modal = true;
    this.PostBack = false;
    this.WaitPage = true;
    this.Title = "";
    this.WaitTitle = "";

    this.Show = Module_ShowPopUp;
}

function Module_ShowPopUp() {
    var sPre = SMPRootVar;

    //att Wrong path... TFS 7215
    var version = 0
    if (navigator.appVersion.indexOf("MSIE") != -1) {
        temp = navigator.appVersion.split("MSIE")
        version = parseFloat(temp[1])
    }

    if ((version >= 7.0) && (this.Title == "Feature Property" || this.Title == "Property Notes"))
        sPre = "../..";

    FuncPtr = this.ReturnFunction;
    var sUrl = sPre + "/MasterPage/PopUpHost.aspx?" + this.Params + "&WebForm=" + this.ReturnForm + "&UserForm=" + this.UserForm + "&AppModule=" + this.AppModule + "&PostBack=" + this.PostBack + "&WaitPage=" + this.WaitPage + "&Title=" + this.Title + "&WaitTitle=" + this.WaitTitle;
    if (HostPageIncludeDomainInPopup)
        sUrl = sUrl + "&Domain=" + window.document.domain;

    OpenPopUp(sUrl, this.WinSizeX, this.WinSizeY, this.ScrollBars, this.MenuBar, this.Modal);
}
