var _agent=new Object();
var _pprUnloaded=false;

/////////////////////////////////////////////////////////////////////////////////
function _atLeast(a0,a1) {
    return(!a0||(a0==_agent.kind))&&(!a1||(a1<=_agent.version));
}

/////////////////////////////////////////////////////////////////////////////////
function _atMost(a0,a1){
    return(a0==_agent.kind)&&(a1>=_agent.version);
}

/////////////////////////////////////////////////////////////////////////////////
function _agentInit(){
    var a0=navigator.userAgent.toLowerCase();
    var a1=parseFloat(navigator.appVersion);
    var a2=false;
    var a3=false;
    var a4=false;
    var a5=false;
    var a6="unknown";
    var a7=false;
    
    if(a0.indexOf("msie")!=-1){
        a3=true;    
        var a8=a0.match(/msie (.*);/);
        a1=parseFloat(a8[1]);
        a6="ie";
    } else if(a0.indexOf("opera")!=-1){
        a2=true
        a6="opera";
    } else if((a0.indexOf('mozilla')!=-1)&& (a0.indexOf('spoofer')==-1)&& (a0.indexOf('compatible')==-1)){
        if(a1>=5.0){
            a5=true;
            a6="mozilla"
        } else {
            a4=true;
            a6="nn";
        }
    }

    if(a0.indexOf('win')!=-1)
        a7=true;

    _agent.isIE=a3;
    _agent.isNav=a4;
    _agent.isOpera=a2;
    _agent.isMozilla=a5;
    _agent.version=a1
    _agent.kind=a6;
    _agent.isWindows=a7;
    _agent.atLeast=_atLeast;
    _agent.atMost=_atMost;
}

/////////////////////////////////////////////////////////////////////////////////
_agentInit();

var _ieFeatures= {
    channelmode:1,
    copyhistory:1,
    directories:1,
    fullscreen:1,
    height:1,
    location:1,
    menubar:1,
    resizable:1,
    scrollbars:1,
    status:1,
    titlebar:1,
    toolbar:1,
    width:1,
    left:1,
    top:1};

var _nnFeatures={
    alwayslowered:1,
    alwaysraised:1,
    copyhistory:1,
    dependent:1,
    directories:1,
    height:1,
    hotkeys:1,
    innerheight:1,
    innerwidth:1,
    location:1,
    menubar:1,
    outerwidth:1,
    outerheight:1,
    resizable:1,
    scrollbars:1,
    status:1,
    titlebar:1,
    toolbar:1,
    width:1,
    width:1,
    left:1,
    top:1,
    "z-lock":1};

var _modelessFeatureOverrides={};
var _modalFeatureOverrides={};
var _featureDefaults={document: {
                        channelmode:false,
                        copyhistory:true,
                        dependent:false,
                        directories:true,
                        fullscreen:false,
                        hotkeys:false,
                        location:true,
                        menubar:true,
                        resizable:true,
                        scrollbars:true,
                        status:true,
                        toolbar:true
                    },dialog:{
                        channelmode:false,
                        copyhistory:false,
                        dependent:true,
                        directories:false,
                        fullscreen:false,
                        hotkeys:true,
                        location:false,
                        menubar:false,
                        resizable:true,
                        scrollbars:true,
                        status:true
                        }
                    };

var _booleanFeatures={
    alwayslowered:1,
    alwaysraised:1,
    channelmode:1,
    copyhistory:1,
    dependent:1,
    directories:1,
    fullscreen:1,
    hotkeys:1,
    location:1,
    menubar:1,
    resizable:1,
    scrollbars:1,
    status:1,
    titlebar:1,
    toolbar:1,
    "z-lock":1};

/////////////////////////////////////////////////////////////////////////////////
function _onModalClickNN(a0) {
    if(_getValidModalDependent(self)) {
        return false;
    } else {
        self.routeEvent(a0);
        return true;
    }
}

/////////////////////////////////////////////////////////////////////////////////
var _mozClickEH=new Object();
/////////////////////////////////////////////////////////////////////////////////
function _onModalClickMoz(a0){
    dump(a0);
}

/////////////////////////////////////////////////////////////////////////////////
_mozClickEH["handleEvent"]=_onModalClickMoz;
/////////////////////////////////////////////////////////////////////////////////
function _onModalFocus(){
    var a0=self.document.body;
    var a1=_getValidModalDependent(self);
    var a2=_agent.atLeast("ie",5)&&_agent.isWindows;
    if(a1){
        if(!_agent.isMozilla)
        a1.focus();
        if(a2){
            a0.setCapture();
        }
    } else {
        if(a2) {
            a0.releaseCapture();
        }
    }
}

/////////////////////////////////////////////////////////////////////////////////
function openWindow(win, page, target, propWin, indModal, winType, depend){
    if(win) {
        if(indModal == (void 0)) {
            indModal = false;
        }

        if(!winType) {
            winType = (indModal) ? "dialog" : "document";
        }
        
        if(!target) {
            target = "_blank";
        }

        var featDef = _featureDefaults[winType];
        
        if(featDef == (void 0)){
            winType = "document";
            featDef = _featureDefaults[winType];
        }
        
        var featOver = (indModal) ? _modalFeatureOverrides : _modelessFeatureOverrides;
        var agentFeat = (_agent.isIE) ? _ieFeatures : _nnFeatures;
        var props = "";
        
        for (featureName in agentFeat) {
            var featName = featOver[featureName];
            
            if (featName == (void 0)) {
                if (propWin)
                    featName = propWin[featureName];
                    if(featName == (void 0)){
                        featName = featDef[featureName];
                    }
                }
                
                if(featName != (void 0)) {
                    var indFeat = _booleanFeatures[featureName] != (void 0);
                    if(featName || !indFeat) {
                        props += featureName;
                        if (!indFeat) {
                            props += "=" + featName;
                        }
                        props += ",";
                    }
                }
            }

            if (props.length!=0) {
                props = props.substring(0, props.length-1);
            }

            if (depend) {
                _setDependent(win, target, depend);
            }

            var agentVersion = _agent.atMost("ie", 4.99);
            var indFilter = false;
            var winBody = win.document.body;
             
            if (indModal && !agentVersion) {
                if (_agent.atLeast("ie", 4)) {
                    winBody.style.filter = "alpha(opacity=50)";
                    indFilter = true;
                }

                if((_agent.atLeast("ie", 5) && _agent.isWindows)){
                    winBody.setCapture();
                } else if (_agent.isNav) {
                    win.captureEvents(Event.CLICK);
                    win.onclick = _onModalClickNN;
                } else if(_agent.isMozilla) {
                    winBody.addEventListener(Event.CLICK, _mozClickEH,true);
                }

                win.onfocus = _onModalFocus;
            }

            var popup = win.open(page,target,props);
            
            if(indModal&&!agentVersion){
                _setDependent(win, "modalWindow" , popup);
            }
            
            popup.focus();
            
            if(indFilter){
                win.setTimeout("_clearAlphaFilter()" , 1000);
            }
        
        return popup;
    } else {
        return null;
    }
}

/////////////////////////////////////////////////////////////////////////////////
function _setDependent(a0,a1,a2) {
    var a3=_getDependents(a0,true);
    if(a3) {
        a3[a1]=a2;
    }
}

/////////////////////////////////////////////////////////////////////////////////
function _getModalDependent(a0) {
    return _getDependent(a0,"modalWindow");
}

/////////////////////////////////////////////////////////////////////////////////
function _getValidModalDependent(a0) {
    var a1=_getModalDependent(a0);
    if(a1) {
        if(a1.closed){
            _setDependent(a0,"modalWindow",(void 0));
            a1=(void 0);
        }
    }
    return a1;
}

/////////////////////////////////////////////////////////////////////////////////
function _isModalDependent(a0,a1){
    return(a1==_getModalDependent(a0));
}

/////////////////////////////////////////////////////////////////////////////////
function _clearAlphaFilter() {
    if(_getValidModalDependent(self)!=null) {
        self.setTimeout("_clearAlphaFilter()",500);
    } else {
        self.document.body.style.filter=null;
    }
}

/////////////////////////////////////////////////////////////////////////////////
function _getDependent(a0,a1) {
    var a2=_getDependents(a0);
    var a3;
    if(a2) {
        a3=a2[a1];
    }
    return a3;
}

/////////////////////////////////////////////////////////////////////////////////
function _getDependents(a0,a1) {
    var a2;
    if(a0) {
        a2=a0["_dependents"];
        if(a2==(void 0)) {
            if(a1) {
                a2=new Object();
                a0["_dependents"]=a2;
            }
        }
    }
    return a2;
}


/* Chamada calendário */
function chamaCalendarioModal(id,base_path) {
    data_id = id;					
    wnd = openWindow(self, base_path+'\\inc\\calendario.html', 'popup1', {top:250,left:300,width:140,height:150,scrollbars:false,resizable:false,titlebar:true,dependent:true,status:false}, true, 'dialog', 0);
    //wnd = open('inc\\calendario.html','', 'scrollbars=no,resizable=no,titlebar=yes,dependent=yes,width=140,height=150,top=250,left=300');
}

/* Chamada das lovs */
function chamaLovModal() {
    wnd = openWindow(self, 'inc\\LovValores.html', 'popup2', {width:425,height:350,top:120,left:200}, true, 'dialog', 0);
    //wnd = open('inc\\LovCliente.html','', 'scrollbars=yes,resizable=yes,width=425,height=350,top=120,left=200');
}