//*****************************************************************************
//* function function updateLoader(){
//* Paramethers: none
//* Description: Updates a global variable that indicates that all the frames
//*				 has been loaded
//*****************************************************************************
function LoadA3WorkArea() {
    countFrames++;

    if (countFrames == maxcountFrames) {
        var keyBoard = keyBoardExplorer();
        var screenResol = screenResolution();
        //WorkArea.location.href = "HomePage.aspx?PageID=0&KeyBoard=" + keyBoard + "&screen=" + screenResol
        WorkArea.location.href = "HomePage.aspx?PageID=0&KeyBoard=" + keyBoard + "&screen=" + screenResol +
					"&FlashVersion=" + getFlashVersion() + "&" + document.location.search.replace("?", "");

        if (typeof (Tasks) != "undefined") {
            window.top.frames["Tasks"].location.reload();
            //Tasks.location.reload();
        }
        if (typeof (Shadow) != "undefined") {
            window.top.frames["Shadow"].location.reload();
            //Shadow.location.reload();
        }
        if (typeof (Header) != "undefined") {
            //window.setTimeout("Header.location.reload()",200);
            window.top.frames["Header"].location.reload();
            //Header.location.reload();
        }
        if (typeof (ActionsFooter) != "undefined") {
            window.top.frames["ActionsFooter"].location.reload();
            //ActionsFooter.location.reload();
        }
    }
    if (typeof (finalcountFrames) != "undefined") {
        if (countFrames == finalcountFrames) {
            if (typeof (WorkArea) != "undefined") {
                window.top.frames["WorkArea"].location.reload();
                //WorkArea.location.reload();
            }
        }
    }
}

//*****************************************************************************
//* function screenResolution(){
//* Paramethers: none
//* Description: get screen resolution
//*****************************************************************************
function screenResolution() { return screen.width + "x" + screen.height; }

//*****************************************************************************
//* function keyBoardExplorer(){
//* Paramethers: none
//* Description: get explorer language
//*****************************************************************************
function keyBoardExplorer() { return window.navigator.browserLanguage; }

//*****************************************************************************
//* function screenResolution(){
//* Paramethers: idInput - object that receives focus
//* Description: set focus in the input field
//*****************************************************************************
function setFocus(idInput) {
    var obj = document.getElementById(idInput);
    
    obj.focus();
}

function LoadA3ModalWorkArea() {
    if (window.dialogArguments[5] == "modal") {
        if (window.dialogArguments[4] != null) {
            window.top.frames["WorkArea"].location.href = "A3ModalTmp.aspx";
            SetValues();
        }
        else {
            window.top.frames["WorkArea"].location.href = window.dialogArguments[1];
        }
    }
    else {
        window.top.frames["WorkArea"].location.href = window.dialogArguments[1];
    }

    ShowComboRelatedTasks();
    WorkArea.focus();
}

function LoadFrame() {
    countFrames++;

    if (window.top.frames["Principal"]) {
        if (window.top.frames["Principal"].cols.indexOf("0") == -1) {
            if (window.location.href.indexOf("hif=true") != -1) {
                window.top.frames["Principal"].cols = "0, *";
                window.top.frames["FrameWork"].rows = "49, 100%, 30";
            }
        }
    }
    if (countFrames == maxcountFrames) { LoadA3ModalWorkArea(); }
}

function SetValues() {
    if (window.top.frames["WorkArea"].document.readyState == "complete" || window.top.frames["WorkArea"].A3ExcelComplete == true) {
        window.top.frames["WorkArea"].document.forms[0].hPage.value = window.dialogArguments[1];
        if (window.dialogArguments[4] != null) {
            var orderCFG = window.dialogArguments[4];

            window.top.frames["WorkArea"].document.forms[0].hSelected.value = orderCFG[0];
            window.top.frames["WorkArea"].document.forms[0].hColOrder.value = orderCFG[1];
            window.top.frames["WorkArea"].document.forms[0].htypeOrder.value = orderCFG[2];
            window.top.frames["WorkArea"].document.forms[0].hTypeSelection.value = window.dialogArguments[3];
        }
        window.top.frames["WorkArea"].document.forms[0].submit();
    }
    else { window.setTimeout(SetValues, 10); }
}

function ShowComboRelatedTasks() {
    var bState = false;

    if (!window.top.frames["WorkArea"].window.parent.frames["RelatedTasks"]) return;
    if (window.top.frames["WorkArea"].window.parent.frames["RelatedTasks"].document.readyState == "complete" &&
		window.top.frames["WorkArea"].window.parent.frames["RelatedTasks"].ShowModalComboRelatedTask) {
        if (window.dialogArguments[6] == 0)
            bState = true;
        else
            bState = false;

        window.top.frames["WorkArea"].window.parent.frames["RelatedTasks"].ShowModalComboRelatedTask(bState);
    }
    else {
        window.setTimeout(ShowComboRelatedTasks, 10);
    }
}

function FocusToControl() {
    if ((document.getElementById("CC") != null) && (document.getElementById("CC").value == 0))
        document.getElementById("CC").focus();
    else
        document.getElementById('UserID').focus();
}

function window_onunload() {
    var sPath = document.frames["WorkArea"];

    if (sPath == null) { sPath = "login"; }
    else { sPath = sPath.location.pathname; }

    if (sPath.toLowerCase().indexOf("login") == -1) {
        if (window.XMLHttpRequest) {
            request = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            request = new ActiveXObject("Msxml2.XMLHTTP");
            if (!request) { request = new ActiveXObject("Microsoft.XMLHTTP"); }
        }
        var sURL = "A3DataNavigator.ashx?";

        sURL += "clientcode=" + getCookie("ClientCode");
        if (top.activeuserid) { initReq("GET", sURL + "&activeuser=" + top.activeuserid, true, ""); }
    }
}

function initReq(reqType, sURL, bool, respHandle) {
    try {
        request.onreadystatechage = respHandle;
        request.open(reqType, sURL, bool);
        if (reqType.toLowerCase() == "post") {
            request.setRequestHeader("Content-Type", "application/x-ww-form-urlencoded; charset=UTF-8");
            request.send();
        }
        else { request.send(null); }
    }
    catch (errv) { }
}

function getCookie(sName) {
    var start = document.cookie.indexOf(sName + "=");
    var len = start + sName.length + 1;

    if ((!start) && (sName != document.cookie.substring(0, sName.length)))
        return null;
    if (start == -1)
        return null;

    var end = document.cookie.indexOf(";", len);

    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

function getFlashVersion() {
    /*IE Browser*/
    try {
        try {
            var flsh = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");

            try {
                flsh.AllowScriptAccess = "always";
            }
            catch (ex) { return "6.0.0"; }
        }
        catch (ex) { }

        return new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
    }
    catch (ex) {
        /*Other Browsers*/
        try {
            if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPugin) {
                return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
            }
        }
        catch (ex) { }
    }

    return "";
}

window.onunload = window_onunload;
