﻿/// <reference path="WebControls/RGC_DialogBox.js" />
//<![CDATA[
/**********************************************************
This page is an include to use in the ClientSide to call, change and 
do all the Things you can.
The source of all the properties and method is in:
http://www.obout.com/window/document_window_serverside.aspx

By ARuizNa
*/
function fnModalDialog(Url, Width, Height, UrlMode, doPostBack, screenMode, btnAsyncName) {
    /********************************************************************************************/
    /* Url = url that are going to be open                                                      */
    /* Width & Height = Browser width and height (without px). Default 500 x 400                */
    /* UrlMode = root type 'root' || 'OldIIS' || 'explicit' ( absolut and/or relative)          */
    /* doPostBack = True : Do a PostBack when return from the Dialog                            */
    /* screenMode = ModalDialog type                                                            */
    /*              [null | 0 ] = resizable: no ||                                              */
    /*              1 = resizable: yes ||                                                       */
    /* btnAsyncName = Button`s name who call an AsyncPostback.  
    /********************************************************************************************/
    var MDWidth, MDHeight, MDUrl
    if (!isNaN(Number(Width))) {
        //if (!isNaN(Number(Width.split("px").join("")))) {
        MDWidth = Number(Width)
        //}
    } (MDWidth != "" ? MDWidth = MDWidth : MDWidth = 700);
    if (!isNaN(Number(Height))) {
        MDHeight = Number(Height)
    } (MDHeight != "" ? MDHeight = MDHeight : MDHeight = 550);

    if (Url.split(" ").join("") != '') {
        if (UrlMode) {
            if (UrlMode == 'OldIIS') {
                MDUrl = window.location.protocol.toLowerCase() + '//' +
                            window.location.hostname.toLowerCase() + ':8080/' + Url +
                            "?ins_nro=1&emp_nro=" + $("#lblEmpresa").text() +
                            "&usuario=" + $("#lblUserName").text() +
                            "&zon_nro=" + $("#lblZona").text() +
                            "&j_jerarquia=" + $("#lblRol").text() +
                            "&p_zona_nro=" + $("#lblZona").text();
            } else {
                if (UrlMode == 'explicit') MDUrl = Url;
                else {
                    if (UrlMode == 'root') MDUrl = window.location.protocol.toLowerCase() + '//' +
                            window.location.hostname.toLowerCase() + ':' + window.location.port + '/' + 
                            (window.location.pathname.toLowerCase().split("/rgc/").length > 1 ? "/rgc/" + Url :  Url );
                }
            }
        }
    } else {
        $("#divDialog").html("<center><div> No se puede abrir la pagina solicitada debido a un error interno. Por favor solicitar soporte tecnico.</div><input type='button' value='Cerrar' onclick='Dialog.Close()'/></center>")
        return;
    }
    var oData = new Object();
    var strDlgOptions = 'center: yes; status: no; help: no; scroll: yes; unadorned: yes';
    if (!screenMode || screenMode == 0) strDlgOptions += ', dialogHeight: ' + MDHeight + 'px; dialogWidth: ' + MDWidth + 'px; resizable: no';
    else {
        if (screenMode == 1) strDlgOptions += ', dialogHeight: ' + MDHeight + 'px; dialogWidth: ' + MDWidth + 'px; resizable: yes';
    }
    var strPendiente = window.showModalDialog(MDUrl, oData, strDlgOptions);

    if (doPostBack) {
        $get("btnAsyncPostBack").click();
    }
}

function defaultlocation() {
    //el split es por si se pasan datos con el metodo get de HTML en una pagina asp.
    var str = window.location.href.split('?');
    return str[0].substr(0, str[0].lastIndexOf("/") + 1);
}

function fnOpenDataRWindow(idWind, url, Title, Width, Height, html, Mode, UrlMode, Buttons, OnClosefnString) {
    /********************************************************************************************/
    /* idWind = Es para identificar si ya existe ese ojeto y no crear uno nuevo                 */
    /* url = es donde se especifica la url que va a ser abierta en la nueva pantalla            */
    /* (si la misma no empieza con App_Custom o no es absoluta asume que es del sistema viejo)  */
    /* Title = es el titulo que se mostrara en el header del windows a abrir. Default:RGC Activa*/
    /* Width & Height = hancho y alto de la pantalla (sin px). Default 500 x 400                */
    /* html = En funcion que no tenga url es el codigo que se va a ingresar en el window a abrir*/
    /* Mode = 'maximize' || 'normal'                                                            */
    /* UrlMode = tipo de ruta 'root' || 'OldIIS' || 'explicit' ( absoluto y/ó relativo)         */
    /* Buttons = Objeto JSON que corresponde a la conf de buttons de el JQuery Dialog           */
    /********************************************************************************************/
    //debugger;
    if (!idWind) { alert("It is necesary an id to open the new Windows"); return; }
    var OWUrl, OWWidth, OWHeight, OWTitle, OWHtml;
    if (typeof(url) == "string" && url.split(" ").join("") != '') {
        if (typeof(UrlMode) == "string") {
            if (UrlMode == 'OldIIS') {
                OWUrl = window.location.protocol.toLowerCase() + '//' +
                            window.location.hostname.toLowerCase() + ':8080/' + url +
                            "?ins_nro=1&emp_nro=" + $("#lblEmpresa").text() +
                            "&usuario=" + $("#lblUserName").text() +
                            "&zon_nro=" + $("#lblZona").text() +
                            "&j_jerarquia=" + $("#lblRol").text() +
                            "&p_zona_nro=" + $("#lblZona").text();
            } else {
                if (UrlMode == 'explicit') OWUrl = url;
                else {
                    if (UrlMode == 'root') OWUrl = window.location.protocol.toLowerCase() + '//' +
                            window.location.hostname.toLowerCase() + ':' + window.location.port + '/' +
                            (window.location.pathname.toLowerCase().split("/rgc/").length > 1 ? "/rgc/" + url : url); ;
                }
            }
        } else OWUrl = url;
    } else {
        OWHtml = (html.indexOf("<") != 1 ? html: "RGC - ACTIVA");
    }
    if (!isNaN(Number(Width))) {
        //if (!isNaN(Number(Width.split("px").join("")))) {
        OWWidth = Number(Width)
        //}
    } (OWWidth != "" ? OWWidth = OWWidth : OWWidth = 800);
    if (!isNaN(Number(Height))) {
        OWHeight = Number(Height)
    } (OWHeight != "" ? OWHeight = OWHeight : OWHeight = 500);

    if (Title == null || Title == "undefined" || Title.split(" ").join("") == "") OWTitle = "RGC-Activa";
    else OWTitle = Title;
    var NewOWD = DialogMngr.GetDialog(idWind);
    //DialogMngr.Create(idDiv, onDialogClosefn, Titulo, Mensaje, Img, initParams, BoolDisplay)
    var ToExecOnClose =  (typeof (OnClosefnString) == "string" ? OnClosefnString + ";" : "") + "fnCloseAWindow('" + idWind + "');";
    if (!NewOWD) NewOWD = DialogMngr.Create(idWind, ToExecOnClose, OWTitle, null, null, null, false)
    //z-index: 1009; position: absolute; filter: alpha(opacity=50); WIDTH: 1579px; display: block; height: 467px; top: 0px; left: 0px; opacity: 0.5; mozopacity: 0.5;

    if (Mode) {
        if (Mode == 'maximize') {
            NewOWD.Maximize();
        }
        else {
            NewOWD.Width(OWWidth);
            NewOWD.Height(OWHeight);
        }
    }
    NewOWD.bringToFront();
    if (typeof (OWUrl) == "string") NewOWD.IFrameMssg(null, OWUrl, null, true);
    else NewOWD.SetDialog(OWTitle, OWHtml, null, Buttons, true, null);
    //$(".blueFilterDivLayer").css({ "filer": "alpha(opacity=50)", "opacity": "0.5", "mozopacity": "0.5" });
}

function fnCleanWindows() {
    //debugger;
    /*var window_list = oWindowManager.getWindows();
    var Url = window.location.protocol.toLowerCase() + '//' +
    window.location.hostname.toLowerCase() + ':' + window.location.port + '/App_Customs/BlankPage.aspx';*/
    for (var i = 0; i < DialogMngr.listDlg.length; ++i) {
        eval("DialogMngr." + DialogMngr.listDlg[i] + ".Destroy(Url)");
    }
}

function fnCloseAWindow(idWind) {
    if (!idWind) { alert("It is necesary an id to close a Windows"); return; }
    var NewOWD = DialogMngr.GetDialog(idWind);
    if (!NewOWD) {
        alert("It was not possible to find te windows you want to close.");
        return;
    } else {
        DialogMngr.Destroy(idWind);
    }
}
//]]>
