function abreJanela(caminho,janela,parametros){
	MM_openBrWindow(caminho,janela,parametros);
	janelaNova.focus();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  janelaNova=window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Verifica estilo para IE e NE 
estiloCerto=(document.getElementById)?'ie.css':((document.all)?'ie.css':'ns.css');
document.write('<link rel="stylesheet" href="../../css/'+estiloCerto+'" type="text/css">')

function solvisita(URL) {
   var width = 450;
   var height = 500;
   var left = 50;
   var top = 20;
   window.open(URL,'Informacoes', 'width='+width+', height='+height+', top='+top+', left='+left+', status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}


if (document.images)
{   a = new Image(140, 20);
    a.src = "../Imagens/Controles/PageHeader/btn_pessoa_juridica.gif";
    b = new Image(140, 20);
    b.src = "../Imagens/Controles/PageHeader/btn_pessoa_fisica.gif"; 
}

p = 1;

function troca_pessoa(){
    if (p == 1) {
        window.parent.frm_top.location.href="home/topo_pj.aspx";
        document.getElementById('pgTrocaPessoa').title = "Pessoa Fisíca";
		document.images['pessoa'].src=b.src;
        p = 0;
    } else {
        window.parent.frm_top.location.href="home/topo.aspx";
        document.getElementById('pgTrocaPessoa').title = "Pessoa Jurídica";
		document.images['pessoa'].src=a.src;
        p = 1;
    }
}

function abrepop(){
    var pop= abreJanela('popups/PopPlataformas.aspx','oquee','width=680,height=318');
}

function abrepop(){
//var pop= abreJanela('../popups/pop_bradescopp.asp','oquee','width=680,height=318');
}

function ProcuraObjeto(n, d) 
{ 
	var p,i,x;  
	if(!d) d=document; 
	
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	
	if(!(x=d[n])&&d.all) x=d.all[n]; 
	
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=ProcuraObjeto(n,d.layers[i].document);
	
	if(!x && document.getElementById) x=parent.mid.document.getElementById(n); return x;
}

function controle() 
{
	var i,p,v,obj,args=controle.arguments;
	
	for (i=0; i<(args.length-2); i+=3) 
	if ((obj=ProcuraObjeto(args[i]))!=null) 
	{ 
		v=args[i+2];
		
		if (obj.style) 
		{ 
			obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; 
		}
		
		obj.visibility=v; 
	}
}

function lyrVisual(id,estado)
{
	if (navigator.appName == "Netscape") {		
		opcao = (estado) ? "show" : "hide";			
		controle(id,'',opcao);	

	}
	else{
		opcao = (estado) ? "visible" : "hidden";
		parent.mid.document.all[oldId].style.visibility = "hidden";
		parent.mid.document.all[id].style.pixelTop = parent.mid.document.body.scrollTop;
		parent.mid.document.all[id].style.visibility = opcao;
		oldId = id.toString()
	}
}

function mOut(src,clrIn)
{
	if (!src.contains(event.toElement)) {
	  src.style.cursor = 'default';
	  src.bgColor = clrIn;
	}
}

function lyrVisualPJ(id,estado)
{
	if (navigator.appName == "Netscape") {		
		opcao = (estado) ? "show" : "hide";			
		controle(id,'',opcao);		
	}
	else{
		opcao = (estado) ? "visible" : "hidden";
		parent.mid.document.all[oldId].style.visibility = "hidden";
		parent.mid.document.all[id].style.pixelTop = parent.mid.document.body.scrollTop;
		parent.mid.document.all[id].style.visibility = opcao;
		oldId = id.toString();
	}
}

function mOutPJ(src,clrIn)
{
	if (!src.contains(event.toElement)) {
	  src.style.cursor = 'default';
	  src.bgColor = clrIn;
	}
}

function onMouseOut()
{
	parent.lyrVisual('Layer1',0)
}

function campanha_recarga_bala()
{
	window.open('http://www.bradesco.com.br/html/hotsite/recarga_direta/rec_bala.htm','bradesco','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=706,height=460,top=10,left=10');
}

	function JSFX_FloatTopDiv()
	{
		var startX = 3,
		startY = 0;
		var ns = (navigator.appName.indexOf("Netscape") != -1);
		var d = document;
		function ml(id)
		{
			if (d.getElementById) {
				var el = d.getElementById(id);
			} else {
				if (d.all) {
					d.all[id];
				} else {
					d.layers[id];
				}
			}
			if(d.layers)el.style=el;

			el.sP=function(x,y){this.style.left=x;this.style.top=y;};
			el.x = startX;
			el.y = startY;

			return el;
		}
		window.stayTopLeft=function()
		{
			if (ns) {
				var pY = pageYOffset;
			} else {
				var pY = document.body.scrollTop;
			}
			
			var strPos = 0;
			var strPosLimit = 0;
			var strHeightWin = 0;
			var strHeightWinLimit = 0;
			var strHeightImg = 0;
			var strHeightBottom = 40;
			var tmp = 0;

			strPosLimit = strHeightImg + strHeightBottom;
			strHeightWin = document.body.scrollHeight;
			strHeightWinLimit = strHeightWin - strPosLimit;
			
			//alert(strHeightWinLimit + "\n" + strHeightWin);
			//tmp = document.body.scrollTop;

			if ((pY >= strPos) && (pY <= strHeightWinLimit))
			{
				ftlObj.y += (pY + startY - ftlObj.y)/8;
				ftlObj.y -= strPos/8;
			} else {
				if (pY >= strPos)
				{
					if (pY >= strHeightWinLimit)//((py - strHeightWinLimit) < strHeightImg)
					{
						
					} else {
						ftlObj.y = startY;
					}
				} else {
					ftlObj.y += (pY + startY - ftlObj.y)/8;
					ftlObj.y -= pY/8;
				}
			}

			ftlObj.sP(ftlObj.x, ftlObj.y);
			setTimeout("stayTopLeft()", 10);
		}
		ftlObj = ml("divStayTopLeft");
		stayTopLeft();
	}	
function Decimal(caracter) 
{
	if(document.all) 
	{ // Internet Explorer
		var tecla = event.keyCode;
	}
	else
	{
		if(document.layers) 
		{ // Nestcape
			var tecla = caracter.which;
		}
	}
    //alert(tecla);
	if(tecla > 47 && tecla < 58 || tecla == 44 || tecla == 45|| tecla == 46) 
	{ // numeros de 0 a 9 ou , ou - ou .
	
		return true;
	}
	else 
	{
		if (tecla != 8) 
		{ // backspace
			return false;
		}
		else 
		{
			return true;
		}
	}
}

// MASCARAS
/*
    onkeypress="mascara(this,soNumeros)"
    onkeypress="mascara(this,telefone)" maxlength="14"
    onkeypress="mascara(this,cpf)" maxlength="14"
    onkeypress="mascara(this,cep)" maxlength="9" 
*/

function mascara(o,f)
{
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara()
{
    v_obj.value=v_fun(v_obj.value)
}

function soNumeros(v){
    v = v.replace(/\D/g,"")
    return v;
}

function cep(v){
    v = v.replace(/\D/g,"")                //Remove tudo o que não é dígito
    v = v.replace(/(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function data(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos

    return v
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function cnpj(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1.$2")       //Coloca um ponto entre o segundo e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1/$2")       //Coloca uma barra entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{4})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o quarto e o quinto dígitos
    return v
}

/**
 * @author Márcio d'Ávila
 * @version 1.01, 2004
 *
 * PROTÓTIPOS:
 * método String.lpad(int pSize, char pCharPad)
 * método String.trim()
 *
 * String unformatNumber(String pNum)
 * String formatCpfCnpj(String pCpfCnpj, boolean pUseSepar, boolean pIsCnpj)
 * String dvCpfCnpj(String pEfetivo, boolean pIsCnpj)
 * boolean isCpf(String pCpf)
 * boolean isCnpj(String pCnpj)
 * boolean isCpfCnpj(String pCpfCnpj)
 */


var NUM_DIGITOS_CPF  = 11;
var NUM_DIGITOS_CNPJ = 14;
var NUM_DGT_CNPJ_BASE = 8;


/**
 * Adiciona método lpad() à classe String.
 * Preenche a String à esquerda com o caractere fornecido,
 * até que ela atinja o tamanho especificado.
 */
String.prototype.lpad = function(pSize, pCharPad)
{
	var str = this;
	var dif = pSize - str.length;
	var ch = String(pCharPad).charAt(0);
	for (; dif>0; dif--) str = ch + str;
	return (str);
} //String.lpad


/**
 * Adiciona método trim() à classe String.
 * Elimina brancos no início e fim da String.
 */
String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
} //String.trim


/**
 * Elimina caracteres de formatação e zeros à esquerda da string
 * de número fornecida.
 * @param String pNum
 *      String de número fornecida para ser desformatada.
 * @return String de número desformatada.
 */
function unformatNumber(pNum)
{
	return String(pNum).replace(/\D/g, "").replace(/^0+/, "");
} //unformatNumber


/**
 * Formata a string fornecida como CNPJ ou CPF, adicionando zeros
 * à esquerda se necessário e caracteres separadores, conforme solicitado.
 * @param String pCpfCnpj
 *      String fornecida para ser formatada.
 * @param boolean pUseSepar
 *      Indica se devem ser usados caracteres separadores (. - /).
 * @param boolean pIsCnpj
 *      Indica se a string fornecida é um CNPJ.
 *      Caso contrário, é CPF. Default = false (CPF).
 * @return String de CPF ou CNPJ devidamente formatada.
 */
function formatCpfCnpj(pCpfCnpj, pUseSepar, pIsCnpj)
{
	if (pIsCnpj==null) pIsCnpj = false;
	if (pUseSepar==null) pUseSepar = true;
	var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
	var numero = unformatNumber(pCpfCnpj);

	numero = numero.lpad(maxDigitos, '0');
	if (!pUseSepar) return numero;

	if (pIsCnpj)
	{
		reCnpj = /(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/;
		numero = numero.replace(reCnpj, "$1.$2.$3/$4-$5");
	}
	else
	{
		reCpf  = /(\d{3})(\d{3})(\d{3})(\d{2})$/;
		numero = numero.replace(reCpf, "$1.$2.$3-$4");
	}
	return numero;
} //formatCpfCnpj


/**
 * Calcula os 2 dígitos verificadores para o número-efetivo pEfetivo de
 * CNPJ (12 dígitos) ou CPF (9 dígitos) fornecido. pIsCnpj é booleano e
 * informa se o número-efetivo fornecido é CNPJ (default = false).
 * @param String pEfetivo
 *      String do número-efetivo (SEM dígitos verificadores) de CNPJ ou CPF.
 * @param boolean pIsCnpj
 *      Indica se a string fornecida é de um CNPJ.
 *      Caso contrário, é CPF. Default = false (CPF).
 * @return String com os dois dígitos verificadores.
 */
function dvCpfCnpj(pEfetivo, pIsCnpj)
{
	if (pIsCnpj==null) pIsCnpj = false;
	var i, j, k, soma, dv;
	var cicloPeso = pIsCnpj? NUM_DGT_CNPJ_BASE: NUM_DIGITOS_CPF;
	var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
	var calculado = formatCpfCnpj(pEfetivo, false, pIsCnpj);
	calculado = calculado.substring(2, maxDigitos);
	var result = "";

	for (j = 1; j <= 2; j++)
	{
		k = 2;
		soma = 0;
		for (i = calculado.length-1; i >= 0; i--)
		{
			soma += (calculado.charAt(i) - '0') * k;
			k = (k-1) % cicloPeso + 2;
		}
		dv = 11 - soma % 11;
		if (dv > 9) dv = 0;
		calculado += dv;
		result += dv
	}

	return result;
} //dvCpfCnpj


/**
 * Testa se a String pCpf fornecida é um CPF válido.
 * Qualquer formatação que não seja algarismos é desconsiderada.
 * @param String pCpf
 *      String fornecida para ser testada.
 * @return <code>true</code> se a String fornecida for um CPF válido.
 */
function isCpf(pCpf)
{
	var numero = formatCpfCnpj(pCpf, false, false);
	var base = numero.substring(0, numero.length - 2);
	var digitos = dvCpfCnpj(base, false);
	var algUnico, i;

	// Valida dígitos verificadores
	if (numero != base + digitos) return false;

	/* Não serão considerados válidos os seguintes CPF:
	 * 000.000.000-00, 111.111.111-11, 222.222.222-22, 333.333.333-33, 444.444.444-44,
	 * 555.555.555-55, 666.666.666-66, 777.777.777-77, 888.888.888-88, 999.999.999-99.
	 */
	algUnico = true;
	for (i=1; i<NUM_DIGITOS_CPF; i++)
	{
		algUnico = algUnico && (numero.charAt(i-1) == numero.charAt(i));
	}
	//alert((!algUnico));
	return (!algUnico);
} //isCpf


/**
 * Testa se a String pCnpj fornecida é um CNPJ válido.
 * Qualquer formatação que não seja algarismos é desconsiderada.
 * @param String pCnpj
 *      String fornecida para ser testada.
 * @return <code>true</code> se a String fornecida for um CNPJ válido.
 */
function isCnpj(pCnpj)
{
	var numero = formatCpfCnpj(pCnpj, false, true);
	var base = numero.substring(0, NUM_DGT_CNPJ_BASE);
	var ordem = numero.substring(NUM_DGT_CNPJ_BASE, 12);
	var digitos = dvCpfCnpj(base + ordem, true);
	var algUnico;
    
    //alert('teste');
    
	// Valida dígitos verificadores
	if (numero != base + ordem + digitos) return false;

	/* Não serão considerados válidos os CNPJ com os seguintes números BÁSICOS:
	 * 11.111.111, 22.222.222, 33.333.333, 44.444.444, 55.555.555,
	 * 66.666.666, 77.777.777, 88.888.888, 99.999.999.
	 */
	algUnico = numero.charAt(0) != '0';
	for (i=1; i<NUM_DGT_CNPJ_BASE; i++)
	{
		algUnico = algUnico && (numero.charAt(i-1) == numero.charAt(i));
	}
	
	if (algUnico) return false;

	/* Não será considerado válido CNPJ com número de ORDEM igual a 0000.
	 * Não será considerado válido CNPJ com número de ORDEM maior do que 0300
	 * e com as três primeiras posições do número BÁSICO com 000 (zeros).
	 * Esta crítica não será feita quando o no BÁSICO do CNPJ for igual a 00.000.000.
	 */

	if (ordem == "0000") return false;
	
	return (base == "00000000"
		|| parseInt(ordem, 10) <= 300 || base.substring(0, 3) != "000");
} //isCnpj


/**
 * Testa se a String pCpfCnpj fornecida é um CPF ou CNPJ válido.
 * Se a String tiver uma quantidade de dígitos igual ou inferior
 * a 11, valida como CPF. Se for maior que 11, valida como CNPJ.
 * Qualquer formatação que não seja algarismos é desconsiderada.
 * @param String pCpfCnpj
 *      String fornecida para ser testada.
 * @return <code>true</code> se a String fornecida for um CPF ou CNPJ válido.
 */
function isCpfCnpj(pCpfCnpj)
{
	var numero = pCpfCnpj.replace(/\D/g, "");
	if (numero.length > NUM_DIGITOS_CPF)
		return isCnpj(pCpfCnpj)
	else
		return isCpf(pCpfCnpj);
} //isCpfCnpj



