// JavaScript Document

function openCalculo(ps)
{
	//alert(ps);
	AbreSistema("http://www.ecad.org.br/CanaldoUsuario/ViewController/publico/simulacao.aspx?csf="+ps);
}


function PlayCompositor(ps)
{
	w = window.open("http://www.ecad.org.br/documentos/Eventos/30Anos/Depoimento.aspx?video=video"+ps, "", "width=560,height=345,scrollbars=no");
	w.moveTo((screen.width-560)/2, (screen.height-345)/2);
}

function EscreveFlash(piWid, piHei, psSrc, psId)
{
	var strSwf;
	
	strSwf = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" id="+psId+" width="+piWid+" height="+piHei+">";
	strSwf += "<param name=\"movie\" value="+psSrc+" />";
	strSwf += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
	strSwf += "<param name=\"quality\" value=\"high\">";
	strSwf += "<param name=\"wmode\" value=\"transparent\">";
	strSwf += "<embed id="+psId+" name="+psId+" allowScriptAccess=\"sameDomain\" swLiveConnect=\"true\" src="+psSrc+" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width="+piWid+" height="+piHei+"></embed></object>";
	
	this.document.write(strSwf);
}


function AbreBanner()
{
	w= open("../../documentos/campanhas/carnaval2006/index.htm","","width=750,height=500,status=yes,menubar=yes,scrollbars=yes,resizable=yes");
}

function AbreSistema(ps)
{
	
	if(navigator.userAgent.indexOf("Firefox") != -1){
		w= open(ps,"","width=750,height=520,status=yes,menubar=yes");
		w.moveTo((screen.width-750)/2,(screen.height-520)/2);
	} 
	if(navigator.userAgent.indexOf("MSIE") != -1){
		w= open(ps,"","width=750,height=520,status=yes,menubar=yes");
		w.moveTo((screen.width-750)/2,(screen.height-520)/2);
	} 
	
	
}
function setImagem (ps){
	document.all.DisplayImg.style.display = "block";
	document.all.DisplayImg.innerHTML = "<img src="+ ps +" />";
}
function AbreClipping(pEndereco)
{
  w= open(pEndereco,"","status=yes,menubar=no,scrollbars=yes,width=1,height=1,top=0,left=0");
}

function RedimensionaClipping()
{
	var largura=opener.screen.width;
    var altura=opener.screen.height;

    var obj = document.images[0];

    if (obj != null)
    {
        if (navigator.appName == 'Netscape')
        {
            adjWidth = obj.width+90;
            adjHeight = obj.height+80;
        }
        else
        {
            adjWidth = obj.width+90;
            adjHeight = obj.height+65;
        }

        if(adjHeight>altura-30)
        {
            adjHeight=altura-80;
        }

        self.moveTo(0,0);
        self.resizeTo(adjWidth, adjHeight);
        document.all.dvTitulo.style.display = "none";
    }
    else
    {
        self.moveTo(0,0);
        self.resizeTo(550, 450);
        document.all.dvTitulo.style.display = "block";
    }

    return
}


function AbreImagem(ps)
{
		winImg = open("","","width=800,height=500,scrollbars=yes,resizable=yes");
		winImg.document.write("<html><body topmargin=\"0\" leftmargin=\"0\" bottommargin=\"0\" rightmargin=\"0\"><center><img src=\""+ps+"\" /></center></body></html>");
}

function AbreImagemResize(ps)
{
		winImg = open("verImagem.aspx?pathImagem="+ps, "verImg", "width=10,height=10,scrollbars=yes,resizable=no");
		winImg.focus();

//		winImg
//		verImagem.asp?pathImagem=../../documentos/folhetos/layouts/BareseRestaurantes.jpg
	/*	winImg.document.write("<html>\n<head>\n<script src=\"../../_js/script.js\"></script>\n</head>\n<body topmargin=\"0\" leftmargin=\"0\" bottommargin=\"0\" rightmargin=\"0\" onLoad=\"teste()\">\n<script event=\"onload\" for=\"window\">\nRedimensionaClipping();\n</script>\n<a onclick=\"RedimensionaClipping()\">teste</a><img src=\""+ps+"\" />\n</body>\n</html>");*/
		//winImg.document.onload = RedimensionaClipping();
}



function mapaDisplay(ps, pNome, pExibirMapa)
{
	if(ps=="block")
	{
		document.all[pExibirMapa].style.display = "none";
	}
	if(ps=="none")
	{
		document.all[pExibirMapa].style.display = "block";
	}
	document.all[pNome].style.display = ps;
}

function changeDiv(pB)
{
	if(pB=="false")
    {
		if(document.all["_ctl1:_ctl0:cbxGrupoTop10"])
		{
			document.all["_ctl1:_ctl0:cbxGrupoTop10"].style.visibility = "visible";
		}

		document.all.conteudoDireita.style.zIndex = 20;
		document.all.conteudoTopo.style.zIndex = 10;
	} 
	
	if(pB=="true")
    {
		if(document.all["_ctl1:_ctl0:cbxGrupoTop10"])
		{
			document.all["_ctl1:_ctl0:cbxGrupoTop10"].style.visibility = "hidden";
		}

		document.all.conteudoDireita.style.zIndex = 10;
		document.all.conteudoTopo.style.zIndex = 20;
	}

	//alert(pB+"::"+document.all.conteudoDireita.style.zIndex);
}
function AjustaEsq()
{
	if(document.body.scrollTop > 261)
    {
        //document.all.conteudoEsquerda.style.top = document.body.scrollTop;
        document.all["conteudoEsquerda"].style.top = document.body.scrollTop;
	}
}

function MudaFormParaGet()
{
    document.forms[0].method = "GET";
}
//////////////////////

// Hook for Internet Explorer.

///////////////////////
function Mascaras(formato, objeto)
{
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
    {
		//var campo = document.getElementById(objeto);
        campo = objeto;

		if (formato == 'DATA')
        {
			separador = '/';
			conjunto1 = 2;
			conjunto2 = 5;
            tamanhomax = 10;

            if (campo.value.length == tamanhomax)
            {
                window.event.keyCode = 0;
            }
            else
            {
		    	if (campo.value.length == conjunto1)
			    	campo.value = campo.value + separador;

    			if (campo.value.length == conjunto2)
	    			campo.value = campo.value + separador;
            }
		}

		if (formato == 'HORA')
        {
			separador = ':';
			conjunto1 = 2;
			if (campo.value.length == conjunto1)
				campo.value = campo.value + separador;
		}

		if (formato == 'CEP')
        {
			separador = '-';
			conjunto1 = 5;
            tamanhomax = 9;

            if (campo.value.length == tamanhomax)
            {
                window.event.keyCode = 0;
            }
            else
            {
			    if (campo.value.length == conjunto1)
				    campo.value = campo.value + separador;

            }
		}

		if (formato == 'TELEFONE')
        {
			separador = '-';
			conjunto1 = 4;
            tamanhomax = 9;

            if (campo.value.length == tamanhomax)
            {
                window.event.keyCode = 0;
            }
            else
            {
    			if (campo.value.length == conjunto1)
	    			campo.value = campo.value + separador;
            }
		}

		if (formato == 'CPF')
        {
			separador = '.';
			separador1 = '-';
			conjunto1 = 3;
			conjunto2 = 7;
			conjunto3 = 11;
            tamanhomax = 14;

            if (campo.value.length == tamanhomax)
            {
                window.event.keyCode = 0;
            }
            else
            {
    			if (campo.value.length == conjunto1)
	    			campo.value = campo.value + separador;

		        if (campo.value.length == conjunto2)
				    campo.value = campo.value + separador;

    			if (campo.value.length == conjunto3)
	    			campo.value = campo.value + separador1;
            }
		}

		if (formato == 'CNPJ')
        {
			separador = '.';
			separador1 = '/';
            separador2 = '-';
			conjunto1 = 2;
			conjunto2 = 6;
			conjunto3 = 10;
            conjunto4 = 15;
            tamanhomax = 18;

            if (campo.value.length == tamanhomax)
            {
                window.event.keyCode = 0;
            }
            else
            {    
    			if (campo.value.length == conjunto1)
	    			campo.value = campo.value + separador;

		    	if (campo.value.length == conjunto2)
			    	campo.value = campo.value + separador;

    			if (campo.value.length == conjunto3)
	    			campo.value = campo.value + separador1;

		    	if (campo.value.length == conjunto4)
			    	campo.value = campo.value + separador2;
            }
		}
	}
    else
		window.event.keyCode = 0;
}

//SCRIPT QUE SÓ ACEITA CAMPO NUMÉRICO
function campoNumerico(campo)
{
    var valorAuxiliar = '';
    var valor;
    var digitosValidos;
    digitosValidos = '0123456789';
    valor = campo.value;
    for (i=0;i<valor.length;i++)
    {
       if(digitosValidos.indexOf(valor.charAt(i))>=0)
       {
            valorAuxiliar += valor.charAt(i);
       }
    }

    campo.value=valorAuxiliar;
}

//Esta função será chamada no evento onKeyUp do objeto.
function FormataValor(campo,tammax)
{
    var valorAuxiliar = "";
    digitosValidos = "0123456789" ;

    //recupera o valor do objeto
    valor = campo.value;

    //retira digitos não numericos
    for (i=0;i<valor.length;i++)
    {
        if(digitosValidos.indexOf(valor.charAt(i))>=0)
        {
             valorAuxiliar += valor.charAt(i);
        }
    }

    //verifica tamanho (tamanho máximo vindo do método)
    if(tammax > 0 && tammax < valorAuxiliar.length)
    {
        valorAuxiliar = valorAuxiliar.substring(0,tammax);
    }

    //retira zeros desnecessários ao início do número
    while (valorAuxiliar.length > 3 && valorAuxiliar.charAt(0) == "0")
    {
       valorAuxiliar = valorAuxiliar.substring(1);
    }

    valor = valorAuxiliar;
    digitosNumericos = valor.length;

    //insere pontos decimais
    for(i = 1;i<=(digitosNumericos/3);i++)
    {
        valor = valor.substring(0,digitosNumericos + 1 - 3*i) +
        (i==1?',':'.') +
        valor.substring(digitosNumericos + 1 - 3*i);
    }

    campo.value = valor;
}

function ConfiguraDivBusca(pNomeDiv, pTip)
{
    document.all[pNomeDiv].style.display = pTip;
}

function MessageBox(pMensagem)
{
    alert(pMensagem);
}
