﻿function Dialog(aDialogId, aAlias) {

    this.DialogId = aDialogId;
    this._Form = '';
    this._Alias = aAlias;
    this._Width = 0;
    this._Height = 0;
    this._Interval = null;

    this._DialogSizes = {
        Inscription: { Width: 526, Height: 207 + (gBrowser.is_Msie7() ? 6 : 0) }, 
        InscriptionClassified: { Width: 536, Height: 447 + (gBrowser.is_Msie7() ? 6 : 0) },
        InscriptionClassifiedUpdate: { Width: 536, Height: 247 + (gBrowser.is_Msie7() ? 6 : 0) },
        InscriptionUpdate: { Width: 526, Height: 407 + (gBrowser.is_Msie7() ? 6 : 0) },
        Connect: { Width: 308, Height: 210 },
        ForgetPassword: { Width: 382, Height: 150 },
        Contact: { Width: 476, Height: 525 + (gBrowser.is_Msie7() ? 2 : 0) },
        ClientSendEMail: { Width: 476, Height: 525 + (gBrowser.is_Msie7() ? 2 : 0) },
        Demo: { Width: 540, Height: 272 },
        OrderSite: { Width: 526, Height: 358 + (gBrowser.is_Msie7() ? 23 : 0) },
        DemoInfo: { Width: 700, Height: 480 },
        InscriptionInfo: { Width: 700, Height: 480 },
        OrderSiteInfo: { Width: 700, Height: 480 },
        Clients: { Width: 754, Height: 536 + (!gBrowser.is_Msie() ? 1 : (gBrowser.is_Msie7() ? -7 : 0)) },
        Cours: { Width: 754, Height: 549 + (!gBrowser.is_Msie() ? 1 : (gBrowser.is_Msie7() ? -7 : 0)) },
        Products: { Width: 754, Height: 549 + (!gBrowser.is_Msie() ? 1 : (gBrowser.is_Msie7() ? -7 : 0)) },
        FormClients: { Width: 526, Height: 407 + (!gBrowser.is_Msie() ? 0 : (gBrowser.is_Msie7() ? 6 : 0)) },
        FormClientSchool: { Width: 760, Height: 480 },
        FormClientsUpdate: { Width: 536, Height: 407 + (!gBrowser.is_Msie() ? 0 : (gBrowser.is_Msie7() ? 6 : 0)) },
        InscriptionClient: { Width: 536, Height: 547 + (!gBrowser.is_Msie() ? 0 : (gBrowser.is_Msie7() ? 6 : 0)) },
        Invoices: { Width: 704, Height: 536 + (!gBrowser.is_Msie() ? 1 : (gBrowser.is_Msie7() ? -7 : 0)) },
        FormInvoicePrint: { Width: 676, Height: 480 + (!gBrowser.is_Msie() ? 1 : (gBrowser.is_Msie7() ? 6 : 0)) },
        FormClientsEMail: { Width: 676, Height: 297 },
        InscriptionDirectory: { Width: 526, Height: 407 + (gBrowser.is_Msie7() ? 6 : 0) },
        InscriptionDirectoryUpdate: { Width: 526, Height: 407 + (gBrowser.is_Msie7() ? 6 : 0) },
        DesignEnter: { Width: 728, Height: 432 },
        FormCours: { Width: 796, Height: 495 },
        FormProfesor: { Width: 776, Height: 495 },
        FormLocal: { Width: 676, Height: 375 },
        FormAgenda: { Width: 740, Height: 525 },
        FormAgendaEmpleado: { Width: 740, Height: 320 },
        FormAgendaDet: { Width: 480, Height: 175 },
        FormEvent: { Width: 796, Height: 535 },
        FormEventImg: { Width: 696, Height: 490 },
        FormNewsLetter: { Width: 940, Height: 585 },
        FormInscrip: { Width: 760, Height: 480 },
        FormSecc: { Width: 326, Height: 235 },
        FormProdCat: { Width: 476, Height: 235 },
        FormProd: { Width: 476, Height: 235 },
        PrintInscrip: {Width: 850, Height: 500},
        FormListInscrip: {Width: 900, Height: 580},
        FormListPrice: {Width: 900, Height: 460},
        FormPrice: { Width: 676, Height: 310 },
        FormEmpleado: {Width: 646, Height: 375}
    }

    this.Load = function() {
        var lref = document.getElementById(this.DialogId + '_iframe');
        lref.scrolling = 'no';
        this._Interval = setInterval('gDialog.Sincronize()', 300);
    }

    this.Show = function(aForm, aCaption, aNoHead, aUrl, aNoClose) {
        if (aForm)
            this.set_Form(aForm);
        if(!aUrl)
            aUrl = '';
        if (document.getElementById('TXTEmpresa') != null) {
            if (document.getElementById('SelKey') != null)
                window[this.DialogId].setContentUrl(this._Alias + '/DialogForms/' + this._Form + '.aspx?time=' + (new Date()) + '&IdEmpresa=' + document.getElementById('TXTEmpresa').value + '&SelKey=' + document.getElementById('SelKey').value + aUrl);
            else
                window[this.DialogId].setContentUrl(this._Alias + '/DialogForms/' + this._Form + '.aspx?time=' + (new Date()) + '&IdEmpresa=' + document.getElementById('TXTEmpresa').value + aUrl);
        } else {
            if (document.getElementById('SelKey') != null)
                window[this.DialogId].setContentUrl(this._Alias + '/DialogForms/' + this._Form + '.aspx?time=' + (new Date()) + (document.getElementById('PartLeft1_MyCategory') ? '&MyCategory=' + document.getElementById('PartLeft1_MyCategory').value : '') + (document.getElementById('PartLeft1_MyIndustry') ? '&MyIndustry=' + document.getElementById('PartLeft1_MyIndustry').value : '') + '&SelKey=' + document.getElementById('SelKey').value + aUrl);
            else
                window[this.DialogId].setContentUrl(this._Alias + '/DialogForms/' + this._Form + '.aspx?time=' + (new Date()) + (document.getElementById('PartLeft1_MyCategory') ? '&MyCategory=' + document.getElementById('PartLeft1_MyCategory').value : '') + (document.getElementById('PartLeft1_MyIndustry') ? '&MyIndustry=' + document.getElementById('PartLeft1_MyIndustry').value : '') + aUrl);
        }
        var lref = document.getElementById('CtrlDialog1_Dialog1_headerDiv');
        if(lref) {
            lref.parentNode.parentNode.style.display = aNoHead ? 'none' : '';
        }
        lref = document.getElementById('CtrlDialog1_Dialog1_close');
        if(lref) {
            lref.style.display = aNoClose ? 'none' : '';
        }
        if (this._DialogSizes[aForm]) {
            this.set_Size(this._DialogSizes[aForm].Width, this._DialogSizes[aForm].Height + (gBrowser.is_Msie7() ? 6 : 0));
            //window[this.DialogId].resize(this._DialogSizes[aForm].Width, this._DialogSizes[aForm].Height);
        }
        lobj = window[this.DialogId]; //['alk']();
        /*for (att in lobj)
        alert(att + ' = ' + lobj[att]);*/
        window[this.DialogId].show(true, aCaption);
    }

    this.Close = function() {
        window[this.DialogId].close();
    }

    this.set_Form = function(aValue) {
        this._Form = aValue;
    }

    this.DoAction = function(aParam1, aParam2, aParam3, aParam4, aParam5, aParam6) {
        if (this['On' + this._Form]) {
            this['On' + this._Form](aParam1, aParam2, aParam3, aParam4, aParam5, aParam6);
        }
        this.Close();
    }

    this.set_Size = function(aWidth, aHeight) {
        this._Height = aHeight;
        this._Width = aWidth;
        window[this.DialogId].resize(aWidth, aHeight);
        window[this.DialogId].move(window.eo_cn / 2 - aWidth / 2 + (gBrowser.is_Msie7() ? 9 : 1), window.eo_co / 2 - aHeight / 2 + (gBrowser.is_Msie7() ? 6 : 0)); //+ (gBrowser.is_Msie7() ? 17 : 9) + (gBrowser.is_Msie7() ? 31 : 17)
    }

    this.Sincronize = function() {
        var lref = document.getElementById(this.DialogId + '_iframe');
        var ldiv = lref.contentWindow.document.getElementById('divMain');
        if (ldiv && this._Height != ldiv.offsetHeight + 95) {
            if (ldiv.offsetHeight > 500)
                ldiv.style.height = '500px';
            //alert((ldiv.offsetHeight + 95) + ' _ ' + this._Height);
            this.set_Size(this._Width, ldiv.offsetHeight + 95);
        }
    }
    
    this.set_Caption = function(aValue) {
        window[this.DialogId].setCaption(aValue);
    }

    this.Load();
}
