﻿function AbrirJanelaDlg(sUrl, objDialogParametro, nWidth, nHeight, bCentralizado, bScroll, nLeft, nTop){
    var sParametro = "";
    var bw = new DetectorBrowser();		 
	 if(!bw.ie7){
	   nHeight = parseInt(nHeight) + 20;
	   nWidth = parseInt(nWidth)+10;
	 }
	 
	
    if (window.showModalDialog) {
        sParametro = "help:0; status:0;unadorned:1;";
        if (nHeight){ sParametro += "dialogHeight:" + nHeight + "px;"; } else { sParametro += "dialogHeight:350px;"; }
        if (nWidth){ sParametro += "dialogWidth:" + nWidth + "px;"; } else { sParametro += "dialogWidth:500px;"; }                        
        if (bCentralizado){ sParametro += "center:1;"; } else { sParametro += "center:0;"; }
        if(nLeft){ sParametro += "dialogLeft:" + nLeft +";";}
        if(nTop){ sParametro += "dialogTop:" + nTop +";";}
        if (bScroll){ sParametro += "scroll:1"; } else { sParametro += "scroll:0;"; }
        return window.showModalDialog(sUrl, objDialogParametro,sParametro);
    } else {
        sParametro = "toolbar=no, directories=no, status=no, menubar=no, resizable=no, modal=yes, dependent=yes, dialog=yes";
        if (nHeight){ sParametro += ",height=" + nHeight; } else { sParametro += ",height=350"; }
        if (nWidth){ sParametro += ",width=" + nWidth; } else { sParametro += ",width=500"; }
        if (bScroll){ sParametro += ",scrollbars=yes"; } else { sParametro += ",scrollbars=no"; }        
        if (bCentralizado) {
            sParametro += "screenY="+((screen.availHeight-nHeight)/2)+",";
            sParametro += "screenX="+((screen.availWidth-nWidth)/2);
        }
        if(nLeft){ sParametro += ",screenX="+nLeft;}
        if(nTop){ sParametro += ",screenY="+nTop;}
        
        return window.open(sUrl, "Dialog", sParametro);
    }
}

function Janela(sUrl, nLargura, nAltura, bCentralizado, bScroll, sNomeJanela, bMaximizado, bRedimencionavel){    
	 var bw = new DetectorBrowser();
	 if(!bw.ie7){
	   nAltura = Number(nAltura) + 20;
	   nLargura = Number(nLargura) + 10;
	 }
	 
    var sParametros = '';
    sParametros += 'location=no,directories=no,status=yes,menubar=no,toolbar=no,';

    if (nLargura == true) {
        bMaximizado = true;
        bRedimencionavel = true;
        bScroll = true;
    }

    if (bRedimencionavel) {
        sParametros += 'resizable=yes,';
    } else {
       sParametros += 'resizable=no,';
    }
    
    if (bMaximizado) {
        sParametros += 'width=' + (screen.availWidth -10) + ', height=' + (screen.availHeight - 20) + ', top=0, left=0';
    } 
    else 
    {
        sParametros += 'width=' + nLargura + ', height=' + nAltura;
        if (bCentralizado){
            nPosLeft = (screen.width) ? (screen.width - nLargura) / 2 : 100;
		    nPosTop  = (screen.height) ? (screen.height - nAltura) / 2 - 50 : 100;
    		
		    sParametros += ', top=' + nPosTop + ', left=' + nPosLeft;
        } 
    }
    
    
    if (bScroll){ 
        sParametros += ', scrollbars=1';
    } else { 
        sParametros += ', scrollbars=0';
    }
    
    if (sNomeJanela == "" || sNomeJanela == null)
    {
        sNomeJanela = "WBCPOPUP";
    }
	var NovaJanela = window.open(sUrl, sNomeJanela, sParametros);
	NovaJanela.focus();
	
	/*
	if (bMaximizado) {
        NovaJanela.moveTo(0,0);
        NovaJanela.resizeTo(screen.availWidth, screen.availHeight);	    
    }
    */
    return NovaJanela;
}


function DetectorBrowser(){
	this.ver    = navigator.appVersion
	this.agent  = navigator.userAgent
	this.dom    = document.getElementById?1:0
	this.opera5 = this.agent.indexOf("Opera 5")>-1
	this.ie4    = (document.all && !this.dom && !this.opera5)                 ? 1 : 0;
	this.ie5    = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5) ? 1 : 0; 
	this.ie6    = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5) ? 1 : 0;
	this.ie7    = (this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5) ? 1 : 0;
	this.ie     = (this.ie4||this.ie5||this.ie6||this.ie7)
	this.mac    = this.agent.indexOf("Mac")>-1
	this.ns4    = (document.layers && !this.dom)        ? 1 : 0;
	this.ns6    = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0; 
	this.bw     = (this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

function SelecionaTodasLinhasChk(obj, objProcurar){
    if (objProcurar) {
        if (objProcurar.length != null) {
	        for (i=0; i < objProcurar.length ;i++){
	            if (!objProcurar[i].disabled) {
	                objProcurar[i].checked = (obj.checked);
	                SelecionaLinhaChk(objProcurar[i]);
		        }
	        }
	    } else {
            if (!objProcurar.disabled) {
                objProcurar.checked = (obj.checked);
                SelecionaLinhaChk(objProcurar);
            }
	    }
	}
}


function SelecionaLinhaChk(obj, bEstiloSecundario){
	if (obj.type == "checkbox"){
		if(! obj.checked) {
			DeselecionaLinha(obj, bEstiloSecundario);
		} else {			
			SelecionaLinha(obj);
		}
	}
}


function SelecionaLinha(obj)
{
	o = ProcurarPai(obj,"TR");
	if (o) 
	{
		var x=0;
		while (x < o.cells.length)
		{
		   //AplicarEstilo(o.cells[x],"tdItemListaOn");
			x++;
		}	
	}
}

function DeselecionaLinha(obj, bEstiloSecundario)
{
	o = ProcurarPai(obj,"TR");
	if (o) 
	{
		var x=0;
		while (x < o.cells.length-1)
		{
//		   if (bEstiloSecundario == null)
//			   AplicarEstilo(o.cells[x],"tdItemLista");
//			else
//			   AplicarEstilo(o.cells[x],"tdItemListaSemBorda");
			x++;
		}
		//AplicarEstilo(o.cells[x],"tdItemListaFim");
	}
}

function ProcurarPai(obj, sElemento){
	var o = obj;
	while (o.tagName != sElemento)
	{
		o = o.parentNode;
		if (o == null) return; 	
	}			
	return o;
}

function AplicarEstilo(obj, Estilo){
	obj.className = Estilo;
}

