//SCRIPT ABRE POPUP
function abrirprint(pagina, largura, altura) {
	var esquerda = 2000;
	var topo = 2000;
	//abre a nova janela, já com a sua devida posição
	window.open(pagina,'', 'status=yes,height=' + altura + ', width=' + largura + ', top=' + topo + ', left=' + esquerda + ''); 
}

//SCRIPT ABRE POPUP
function abrirpopup(pagina,largura,altura) {
	var esquerda = (screen.width - largura) / 2;
	var topo = (screen.height - altura) / 2;

	//abre a nova janela, já com a sua devida posição
	window.open(pagina,'','status=yes,height=' + altura + ', width=' + largura + ', top='+topo+', left='+esquerda+''); 
}

//SCRIPT ABRE IMAGEM
function PopupPic(sPicURL) {
	var server = self.location;
	var path = (server.toString().indexOf("server") == -1) ? "/site/principal/" : "/servidor/BTTelecom/site/principal/";

	if(arguments.length > 1)
	{
		window.open(path + "popup.htm?url=" + sPicURL + "&legenda=" + escape(arguments[1]), "", "resizable=1,HEIGHT=200,WIDTH=200");
	} else {
		window.open(path + "popup.htm?url=" + sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200");
	}
}

//SCRIPT LIMPA INPUT PREENCHIDO
function limpainput(obj) {
	obj.value = "";
}

function generateAjax() {
	try {
		objAjax = new XMLHttpRequest();
	} catch(ee) {
		try {
			objAjax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				objAjax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				objAjax = false;
			}
		}
	}
	return objAjax;
}

function show(id) {
	var obj = document.getElementById(id);
	if(obj != null) {
		obj.style.visibility = "visible";
	}
}

function hide(id) {
	var obj = document.getElementById(id);
	if(obj != null) {
		obj.style.visibility = "hidden";
	}
}

//Formata o telefone xx-xxxx-xxxx
function FormataFone(obj) {
	if(obj != null) {
		if( (obj.value.length == 2) || (obj.value.length == 7) ) {
			obj.value = obj.value + "-";
		}
	}
}

//Formata o telefone xx-xxxx-xxxx
function FormataFoneSemDDD(obj) {
	if(obj != null) {
		if(obj.value.length == 4) {
			obj.value = obj.value + "-";
		}
	}
}
//Formata o CEP xxxxx-xxx
function FormataCEP(obj) {
	if(obj != null) {
		if(obj.value.length == 5) {
			obj.value = obj.value + "-";
		}
	}
}
//Formata o CPF xxx.xxx.xxx-xx
function FormataCPF(obj) {
	if(obj != null) {
		switch(obj.value.length) {
			case 3:
			case 7:
				obj.value = obj.value + ".";
				break;
			case 11:
				obj.value = obj.value + "-";
				break;
		}
	}
}

//Formata uma data xx/xx/xxxx
function FormataData(obj) {
	if(obj != null) {
		switch(obj.value.length) {
			case 2:
			case 5:
				obj.value = obj.value + "/";
				break;
		}
	}
}

function verificaValor(id1, id2) {
	var objCampo1 = document.getElementById(id1);
	var objCampo2 = document.getElementById(id2);
	if( (objCampo1 != null) && (objCampo2 != null) ) {
		if(objCampo1.value.toString() == objCampo2.value.toString()) {
			return true;
		} else {
			return false;
		}
	} else {
		alert("Campos de verificação não encontrados!")	;
		return false;
	}
}

function checaCPF(id) {
	var obj = document.getElementById(id);
	if(obj != null) {
		var CPF = obj.value.toString().replace(/\D/g,'');
		if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
			CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
			CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
			CPF == "88888888888" || CPF == "99999999999") {
			//alert("Preencha o CPF corretamente");
			//obj.focus();
			return false;
		}
		soma = 0;
		for (i=0; i < 9; i ++)
			soma += parseInt(CPF.charAt(i)) * (10 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
			resto = 0;
		if (resto != parseInt(CPF.charAt(9)))
		{		
			//alert("Preencha o CPF corretamente");
			//obj.focus();
			return false;
		}
		soma = 0;
		for (i = 0; i < 10; i ++)
			soma += parseInt(CPF.charAt(i)) * (11 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
			resto = 0;
		if (resto != parseInt(CPF.charAt(10)))
		{
			//alert("Preencha o CPF corretamente");
			//obj.focus();
			return false;		
		}
		else{
			return true;	
		}
	} else {
		return false;
	}
}

// SCRIPTS MM
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(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 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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//VERIFICA SE O FORMATO É E-MAIL
function isMail(form, campo) {
	var re = new RegExp;
	strMail = eval('document.' + form +  '.' + campo + '.value');
	re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var arr = re.exec(strMail);
	if (arr == null) {    
    	return false;
	} else {
   		return true;
	}
}

//PERMITE SÓ NÚMEROS
//PADRÃO : onKeypress="return permiteSoNumeros(event);"
function permiteSoNumeros(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    var caract = new RegExp(/^[0-9 ]+$/i);

	if((keyCode != 36) && (keyCode != 8) && (keyCode != 13)) {
   		var caract = caract.test(String.fromCharCode(keyCode));
	}	
    //------------------------
   	if(!caract) {
       	keyCode = 0;
		return false;
	}
}

//VERIFICA UMA DATA NO PADRÃO:
//00/00/0000 ou 0/0/00
function verificaData(valor) {
	reDate = /^((0?[1-9]|[12]\d{1,2})\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
	if (reDate.test(valor)) {
		return true;
	} else if (valor != null && valor != "") {
		return false;
	}
}

//Monta a data no padrão dd/mm/aaaa
function digitaData(Campo, e) {
	var tecla = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	vr = Campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2 && tam < 5 )
			Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

//VERIFICA SE O VALOR É INTEIRAMENTE NUMÉRICO
function verificaIsNum(valor) {
	p = valor;
	p = p.replace("(", "");
	p = p.replace(")", "");
	p = p.replace("-", "");
	p = p.replace("-", "");

	if(isNaN(p) == true) {
		return false;
	} else {
		return true;
	}
}

//FAZ O MOUSEOVER NA TR E COLOCA O LINK NELA
function over_tr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}

function out_tr(src,clrIn) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}

function go(loc) {
	window.location.href = loc;
}

//FUNÇÕES DE PAGINAÇÃO
function decrementa(nameForm, nameField) {
	var form = eval("document." + nameForm);
	if(form == null)
	{
		alert("Função decrementa não encontrou o formulário");
	} else {
		var field = eval("document." + nameForm + "." + nameField);
		if(field == null)
		{
			alert("Função decrementa não encontrou o campo que contém a página atual");
		} else {
			if(verificaIsNum(field.value))
			{
				if(field.value > 1)
				{
					field.value = parseInt(field.value) - 1;
					form.submit();
				} else {
					return false;
				}
			} else {
				return false;
			}
		}
	}
}
	
function incrementa(nameForm, nameField, totalPaginas) {
	var form = eval("document." + nameForm);
	if(form == null)
	{
		alert("Função incrementa não encontrou o formulário");
	} else {
		var field = eval("document." + nameForm + "." + nameField);
		if(field == null)
		{
			alert("Função incrementa não encontrou o campo que contém a página atual");
		} else {
			if( (verificaIsNum(field.value)) && (verificaIsNum(totalPaginas)) )
			{
				if(parseFloat(field.value) < totalPaginas)
				{
					field.value = parseFloat(field.value) + 1;
					form.submit();
				} else {
					return false;
				}
			} else {
				return false;
			}
		}
	}
}

//Compara duas datas
function comparaData(form, data1, data2)
{
	DataInicial = eval('document.' + form + '.' + data1 + '.value' );
	DataFinal = eval('document.' + form + '.' + data2 + '.value' );
	DataInicial = DataInicial.split("/");
	DataFinal = DataFinal.split("/");
	DataInicial = new Date(DataInicial[2],DataInicial[1],DataInicial[0]);
	DataFinal = new Date(DataFinal[2],DataFinal[1],DataFinal[0]);
	
	if(DataInicial > DataFinal)
	{	
		return false;
	}	
	else
	{	
		return true;
	}
}

function addOption(selectId, txt, val) {
	var objOption = new Option(txt, val);

	document.getElementById(selectId).options.add(objOption);
}

//FORMATA MONETÁRIOS
function FmascTempoReal(ConteudoCampo)
{
	if(((event.keyCode) > 47) && ((event.keyCode) < 58))
	{
		NumDig = ConteudoCampo.value;
		TamDig = NumDig.length;
		Contador = 0;
		if(TamDig > 1)
		{
			numer = "";
			for(i = TamDig; (i >= 0); i--)
			{
				if((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
				{
					Contador++;
					if((Contador == 2) && ((TamDig -i) < 4))
					{
						numer = "," + numer;
						Contador = 0;
					}
					else if (Contador == 3)
					{
						numer = "." + numer;
						Contador = 0;
					}
					numer = NumDig.substr(i, 1) + numer;
				}
			}
			ConteudoCampo.value = numer;
		};
		return(true)
	}
   else return(false)
}

/* Função para formatar o valor */
function FtrataBackSpace(dado)
{
	NumDig = dado.value;
	TamDig = NumDig.length;
	TamDig--;
	Contador = 0;
	if((TamDig >= 0) && (event.keyCode == 8))
	{
		numer = "";
		for (i = TamDig; (i >= 0); i--)
		{
			if((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
			{
				Contador++;
				if((Contador == 4) && ((TamDig -i) < 5))
				{
					numer = "," + numer;
					Contador = 0;
				}
				else if ((Contador == 3) && ((numer.length) > 4))
				{
					numer = "." + numer;
					Contador = 0;
				}
				numer = NumDig.substr(i, 1) + numer;
			}
		}
		dado.value = numer;
	};
}

function FormatNumber(dado) {
	if (dado.length > 0) {
		dado.value = ValorFloatToFmt(FloatToSrt(ValorFmtToFloat(dado.value)))
	}		
}

function ValorFmtToFloat(input)
{
	var inputlength = input.length;
	input = input.toLowerCase();
	var number = "";
	for (i = 0; i < inputlength; i++)
	{
		var character = input.charAt(i);   
		switch(character)
		{
			case '0': number += "0"; break;
			case '1': number += "1"; break;
			case '2': number += "2"; break;
			case '3': number += "3"; break;
			case '4': number += "4"; break;
			case '5': number += "5"; break;
			case '6': number += "6"; break;
			case '7': number += "7"; break;
			case '8': number += "8"; break;
			case '9': number += "9"; break;
		}
	}
	var numberAux = number.substring(0, number.length - 2);
	if(numberAux == "")
	{
		numberAux += "0";
	}	
	numberAux += ".";	
	numberAux += number.substring(number.length - 2, number.length);	
	number = numberAux;
	var valor;
	//var valor =0;
	valor = parseFloat(number);
	//valor = eval(number);
	return valor;
}

function FloatToSrt(Num)
{
	var valorStr = "";
	var pospt = 0;
	valorStr += Num;	
	if(Num <= .99)
	{
		valorStr = valorStr.replace("0", "");
		valorStr = "0" + valorStr;		
	}	
	for (var n = 1 ; n <= valorStr.length ; n++) 
	{
		if (valorStr.substring(n-1, n) == ".") 
		{
			pospt = n;
			break;
		}
	}

	if (pospt == 0)		
	{
		valorStr += ".00";		
	}
	else if(pospt > 0)
	{
		var fracao = valorStr.substring(pospt, valorStr.length);
		if(fracao.length == 1)
		{
			valorStr += "0";			
		}
	}
	return valorStr;
}

function ValorFloatToFmt(Num)
{
	var numer;
	var i;	
	var TamDig = Num.length;
	var Contador = 0;
	if (TamDig > 1)
	{
 		numer = "";
   		for (i = TamDig; (i >= 0); i--)
   		{
			if ((parseInt(Num.substr(i,1))>=0) && (parseInt(Num.substr(i, 1))<=9))
			{
				Contador++;
				if ((Contador == 3) && ((TamDig -i) < 5))
				{
					numer = "," + numer;
					Contador = 0;
				}
				else if (Contador == 3)
				{
					numer = "." + numer;
					Contador = 0;					
				}
				numer = Num.substr(i, 1) + numer;
			}
		}       
	}    
	return numer;   
}

function busca() {
	if(document.frmBusca.txtPalavraChave.value == 'Digite uma palavra-chave') {
		return false;
	} else {
		return true;
	}
}

function cadatroNewsletter() {
	if(document.frmNewsletter.txtNome.value == "Informe seu nome") {
		return false;
	} else {
		return true;
	}
}
-->
