﻿derive(ActionOpen, ActionHidden);
function ActionOpen() {

    this._Ref = null;

    override(this, 'Init')
    this.Init = function() {
        this.ActionHidden_Init(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7]);
        if(Designer_obj) {
            this.Property_Add(10, 'Control de lista', 'CtrlList', 'CtrlList', 'CtrlList');
            this.Property_Add(11, 'Lista global', 'Text', 'GlobalList', 'GlobalList');
            this.Property_Add(12, 'Acci&oacute;n', 'Combo', 'Action', 'Action', 'Insert,Update');
            this.Property_Add(13, 'Formulario 1', 'DataSourceAll', 'FormID1', 'FormID1');
            this.Property_Add(14, 'Formulario 2', 'DataSourceAll', 'FormID2', 'FormID2');
            this.Property_Add(15, 'Formulario 3', 'DataSourceAll', 'FormID3', 'FormID3');
            this.Property_Add(16, 'Formulario 4', 'DataSourceAll', 'FormID4', 'FormID4');
            this.Property_Add(17, 'Ventana', 'Combo', 'Window', 'Window', 'Popup,Self');
            this.Property_Add(18, 'Control llave', 'CtrlInput', 'CtrlKey', 'CtrlKey');
            this.Property_Add(19, 'Pasar Param.', 'Checkbox', 'PassParam', 'PassParam');
            this.Property_Add(20, 'Ctrls a pasar', 'TextMultiLine', 'CtrlToPass', 'CtrlToPass');
            this.Property_Add(21, 'Cate.Niv 1', 'Text', 'CateLevel1', 'CateLevel1');
            this.Property_Add(22, 'Cate.Niv 2', 'Text', 'CateLevel2', 'CateLevel2');
            this.Property_Add(24, 'Pal.clave', 'Text', 'Keyword', 'Keyword');
        }
    }

    this.OnExecute = function(aRef) {
        if (this.get_PassParam() == '1' || this.get_PassParam() == 'True') {
            this._Ref = aRef;
            this.Render("Exec");
            return false;
        } else {
            var lUrl = '';
            if (this.get_CtrlToPass() != '') {
                var lArr = this.get_CtrlToPass().split(',');
                if (lArr.length > 0)
                    Page_obj.ProcIntervalExpression(0);
                for (var i = 0; i < lArr.length; i++) {
                    var lRefUrl = window[lArr[i] + '_obj'];
                    if (lRefUrl != null && lRefUrl.get_Text)
                        lUrl += '&' + lRefUrl.get_Ident() + '=' + lRefUrl.get_Text();
                    else {
                        var lArrPart = lArr[i].split('=');
                        if (lArrPart.length > 1) {
                            lRefUrl = window[lArrPart[1] + '_obj'];
                            if (lRefUrl != null && lRefUrl.get_Text)
                                lUrl += '&' + lArrPart[0] + '=' + lRefUrl.get_Text();
                            else
                                lUrl += '&' + lArrPart[0] + '=' + lArrPart[1];
                        } else
                            lUrl += '&' + lArr[i];
                    }
                }
            }
            if (Form_CallExec && this.get_DataSource() != '') {
                //alert(this.get_CateLevel1());
                if (this.get_CateLevel1() != '') {
                    if (window[this.get_CateLevel1() + '_obj'] != null && window[this.get_CateLevel1() + '_obj'].get_Text)
                        lValue = window[this.get_CateLevel1() + '_obj'].get_Text();
                    else
                        lValue = this.get_CateLevel1();
                    if (lValue != '' && lValue != 'Empty')
                        Util_obj.CreateCookie('ActiveCateLevel1', lValue, 300);
                    else
                        Util_obj.DeleteCookie('ActiveCateLevel1');
                }
                if (this.get_CateLevel2() != '') {
                    if (window[this.get_CateLevel2() + '_obj'] != null && window[this.get_CateLevel2() + '_obj'].get_Text)
                        lValue = window[this.get_CateLevel2() + '_obj'].get_Text();
                    else
                        lValue = this.get_CateLevel2();
                    if (lValue != '' && lValue != 'Empty')
                        Util_obj.CreateCookie('ActiveCateLevel2', lValue, 300);
                    else
                        Util_obj.DeleteCookie('ActiveCateLevel2');
                }
                if (this.get_Keyword() != '') {
                    if (window[this.get_Keyword() + '_obj'] != null && window[this.get_Keyword() + '_obj'].get_Text)
                        lValue = window[this.get_Keyword() + '_obj'].get_Text();
                    else
                        lValue = this.get_Keyword();
                    if (lValue != '' && lValue != 'Empty')
                        Util_obj.CreateCookie('ActiveKeyword', lValue, 300);
                    else
                        Util_obj.DeleteCookie('ActiveKeyword');
                }
                var lKey = null;
                if (this.get_Action() == 'Update') {
                    if (this.get_CtrlKey() != '')
                        lKey = window[this.get_CtrlKey() + '_obj'] && window[this.get_CtrlKey() + '_obj'].get_Text ? window[this.get_CtrlKey() + '_obj'].get_Text() : null;
                    if (lKey == null)
                        lKey = window[this.get_CtrlList() + '_obj'] && window[this.get_CtrlList() + '_obj'].get_Text ? window[this.get_CtrlList() + '_obj'].get_Text() : null;
                    lKey = lKey.split('|')[0];
                    if (lKey && (Key_obj.get_Text() != this.get_DataSource() || KeyReg_obj.get_Text() != lKey)) {
                        if (this.get_Window() == '' || this.get_Window() == 'Popup')
                            Form_CallExec(aRef, this.get_Action(), lKey, this.get_DataSource(), this.get_CtrlList(), 1, 0, lUrl);
                        else if (parent && parent.document.getElementById('frm_Design') != null)
                            parent.document.getElementById('frm_Design').src = '/Modern/Executer.aspx?Key=' + this.get_DataSource() + '&KeyReg=' + lKey + '&Status=' + this.get_Action() + '&Now=' + (new Date()).toString().replace(/\s/g, '') + '&ToRender=' + '&Lang=' + parent.document.getElementById('TXTIdioma').value.substr(0, 2).toLowerCase() + lUrl;
                        else
                            location.href = '/Modern/Executer.aspx?Key=' + this.get_DataSource() + '&KeyReg=' + lKey + '&Status=' + this.get_Action() + '&Now=' + (new Date()).toString().replace(/\s/g, '') + '&ToRender=' + lUrl;
                    }
                } else if (Key_obj.get_Text() != this.get_DataSource() || KeyReg_obj.get_Text() != '' || lUrl != '') {
                    if (this.get_Window() == '' || this.get_Window() == 'Popup')
                        Form_CallExec(aRef, this.get_Action(), null, this.get_DataSource(), this.get_CtrlList(), 1, 0, lUrl);
                    else if (parent && parent.document.getElementById('frm_Design') != null)
                        parent.document.getElementById('frm_Design').src = '/Modern/Executer.aspx?Key=' + this.get_DataSource() + '&KeyReg=' + lKey + '&Status=' + this.get_Action() + '&Now=' + (new Date()).toString().replace(/\s/g, '') + '&ToRender=' + '&Lang=' + parent.document.getElementById('TXTIdioma').value.substr(0, 2).toLowerCase() + lUrl;
                    else
                        location.href = '/Modern/Executer.aspx?Key=' + this.get_DataSource() + '&KeyReg=' + lKey + '&Status=' + this.get_Action() + '&Now=' + (new Date()).toString().replace(/\s/g, '') + '&ToRender=' + lUrl;
                }
            }
        }
        return true;
    }
    
    this.OpenForm = function() {
        if(Form_CallExec && this.get_DataSource() != '') {
            var lKey = null;
            if(this.get_Action() == 'Update') {
                if(this.get_CtrlKey() != '')
                    lKey = window[this.get_CtrlKey() + '_obj'] && window[this.get_CtrlKey() + '_obj'].get_Text ? window[this.get_CtrlKey() + '_obj'].get_Text() : null;
                if(lKey == null)
                    lKey = window[this.get_CtrlList() + '_obj'] && window[this.get_CtrlList() + '_obj'].get_Text ? window[this.get_CtrlList() + '_obj'].get_Text() : null;
                if(lKey && (Key_obj.get_Text() != this.get_DataSource() || KeyReg_obj.get_Text() != lKey)) {
                    if(this.get_Window() == '' || this.get_Window() == 'Popup')
                        Form_CallExec(this._Ref,this.get_Action(),lKey,this.get_DataSource(),this.get_CtrlList(), 1, 1);
                    else if (parent && parent.document.getElementById('frm_Design') != null)
                        parent.document.getElementById('frm_Design').src = '/Modern/Executer.aspx?Key=' + this.get_DataSource() + '&KeyReg=' + lKey + '&Status=' + this.get_Action() + '&Now=' + (new Date()).toString().replace(/\s/g,'') + '&ToRender=&Step=1' + '&Lang=' + parent.document.getElementById('TXTIdioma').value;
                    else
                        location.href = '/Modern/Executer.aspx?Key=' + this.get_DataSource() + '&KeyReg=' + lKey + '&Status=' + this.get_Action() + '&Now=' + (new Date()).toString().replace(/\s/g,'') + '&ToRender=&Step=1';
                }
            } else if(Key_obj.get_Text() != this.get_DataSource() || KeyReg_obj.get_Text() != '') {
                if(this.get_Window() == '' || this.get_Window() == 'Popup')
                    Form_CallExec(this._Ref,this.get_Action(),null,this.get_DataSource(),this.get_CtrlList(), 1, 1);
                else if (parent && parent.document.getElementById('frm_Design') != null)
                    parent.document.getElementById('frm_Design').src = '/Modern/Executer.aspx?Key=' + this.get_DataSource() + '&KeyReg=' + lKey + '&Status=' + this.get_Action() + '&Now=' + (new Date()).toString().replace(/\s/g,'') + '&ToRender=&Step=1' + '&Lang=' + parent.document.getElementById('TXTIdioma').value;
                else
                    location.href = '/Modern/Executer.aspx?Key=' + this.get_DataSource() + '&KeyReg=' + lKey + '&Status=' + this.get_Action() + '&Now=' + (new Date()).toString().replace(/\s/g,'') + '&ToRender=&Step=1';
            }
        }
    }

    this.get_CtrlList = function() {
        if(Designer_obj)
            return this.get_Param(0);
        return this.get_Attr('t20');
    }
    this.set_CtrlList = function(aValue) {
        this.set_Attr('t20', aValue);
        this.set_Param(0, aValue);
    }
    
    this.get_GlobalList = function() {
        if(Designer_obj)
            return this.get_Param(5);
    }
    this.set_GlobalList = function(aValue) {
        this.set_Param(5, aValue);
    }

    this.get_Action = function() {
        if(Designer_obj)
            return this.get_Param(1);
        return this.get_Attr('t21');
    }
    this.set_Action = function(aValue) {
        this.set_Attr('t21', aValue);
        this.set_Param(1, aValue);
    }

    this.get_DataSource = function() {
        return this.get_Attr('t22');
    }
    this.set_DataSource = function(aValue) {
        this.set_Attr('t22', aValue);
    }

    this.get_FormID = function() {
        return this.get_Param(2);
    }
    this.set_FormID = function(aValue) {
        this.set_Param(2, aValue);
    }

    this.get_FormID1 = function() {
        return this.get_Param(2).split(',')[0];
    }
    this.set_FormID1 = function(aValue) {
        var lStr = aValue;
        var lValueTmp = this.get_FormID2();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        lValueTmp = this.get_FormID3();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        lValueTmp = this.get_FormID4();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        this.set_Param(2, lStr);
    }

    this.get_FormID2 = function() {
        var lArr = this.get_Param(2).split(',');
        return lArr.length > 1 ? lArr[1] : '';
    }
    this.set_FormID2 = function(aValue) {
        var lStr = this.get_FormID1();
        var lValueTmp = aValue;
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        lValueTmp = this.get_FormID3();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        lValueTmp = this.get_FormID4();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        this.set_Param(2, lStr);
    }

    this.get_FormID3 = function() {
        var lArr = this.get_Param(2).split(',');
        return lArr.length > 2 ? lArr[2] : '';
    }
    this.set_FormID3 = function(aValue) {
        var lStr = this.get_FormID1();
        var lValueTmp = this.get_FormID2();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        lValueTmp = aValue;
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        lValueTmp = this.get_FormID4();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        this.set_Param(2, lStr);
    }

    this.get_FormID4 = function() {
        var lArr = this.get_Param(2).split(',');
        return lArr.length > 3 ? lArr[3] : '';
    }
    this.set_FormID4 = function(aValue) {
        var lStr = this.get_FormID1();
        var lValueTmp = this.get_FormID2();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        lValueTmp = this.get_FormID3();
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        lValueTmp = aValue;
        if(lValueTmp != '')
            lStr += (lStr == '' ? '' : ',') + lValueTmp;
        this.set_Param(2, lStr);
    }

    this.get_Window = function() {
        if(Designer_obj)
            return this.get_Param(3);
        return this.get_Attr('t23');
    }
    this.set_Window = function(aValue) {
        this.set_Attr('t23', aValue);
        this.set_Param(3, aValue);
    }

    this.get_CtrlKey = function() {
        if(Designer_obj)
            return this.get_Param(4);
        return this.get_Attr('t24');
    }
    this.set_CtrlKey = function(aValue) {
        this.set_Attr('t24', aValue);
        this.set_Param(4, aValue);
    }

    this.get_PassParam = function() {
        if(Designer_obj)
            return this.get_Param(6);
        return this.get_Attr('t25');
    }
    this.set_PassParam = function(aValue) {
        this.set_Attr('t25', aValue);
        this.set_Param(6, aValue);
    }

    this.get_CtrlToPass = function() {
        if(Designer_obj)
            return this.get_Param(7);
        return this.get_Attr('t26');
    }
    this.set_CtrlToPass = function(aValue) {
        if(Designer_obj)
            this.set_Param(7, aValue);
        else
            this.set_Attr('t26', aValue);
    }

    this.get_CateLevel1 = function() {
        if (Designer_obj)
            return this.get_Param(8) ? this.get_Param(8) : '';
        else
            return this.get_Attr('t27');
    }
    this.set_CateLevel1 = function(aValue) {
        this.set_Param(8, aValue);
    }

    this.get_CateLevel2 = function() {
        if (Designer_obj)
            return this.get_Param(9) ? this.get_Param(9) : '';
        else
            return this.get_Attr('t28');
    }
    this.set_CateLevel2 = function(aValue) {
        this.set_Param(9, aValue);
    }

    this.get_Keyword = function() {
        if (Designer_obj)
            return this.get_Param(10) ? this.get_Param(10) : '';
        else
            return this.get_Attr('t29');
    }
    this.set_Keyword = function(aValue) {
        this.set_Param(10, aValue);
    }
}

