var defaultFontSize = 100;
var maximumFontSize = 300;
var currentFontSize = defaultFontSize;

function resetFontSize() {
	resetSize = defaultFontSize - currentFontSize;
	changeFontSize(resetSize);
}

function changeFontSize(sizeDifference) {
	currentFontSize = currentFontSize + sizeDifference;

	if(currentFontSize > maximumFontSize) { alert('Você já chegou ao tamanho máximo!'); currentFontSize = 300;  }
	else if(currentFontSize < 60) { alert('Você já chegou ao tamanho mínimo!'); currentFontSize = 60;  }

	setFontSize(currentFontSize);
}

function setFontSize(fontSize)
{ 
	
	document.getElementById('et_conteudo').style.fontSize = fontSize + '%'; 

}


function mudarFonte(x) {
	
	if (x == "A") { changeFontSize(10); }
	else if (x == "D") { changeFontSize(-10); }
	else { resetFontSize(); }
}


// Retira os espaços em branco do início e fim do campo (ex: onblur="this.value=this.value.trim();").
String.prototype.trim = function()
{
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
// Fim da retira espaços.
function open_revista(url){
window.open(url,'revista','fullscreen=yes' )
}
// outro modo de tirar espaços
function trim(s) {
  return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

//Cria objeto AJAX ##################################################################################
function createXMLHTTP() 
{
			var ajax;
			try 
			{
					   ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e) 
			{
					   try 
					   {
								   ajax = new ActiveXObject("Msxml2.XMLHTTP");
								   alert(ajax);
					   }
					   catch(ex) 
					   {
								   try 
								   {
											   ajax = new XMLHttpRequest();
								   }
								   catch(exc) 
								   {
												alert("Esse browser não tem recursos para uso do Ajax");
												ajax = null;
								   }
					   }
					   return ajax;
			}


			   var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
																		  "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
																		  "Microsoft.XMLHTTP"];
			   for (var i=0; i < arrSignatures.length; i++) 
			   {
								   try 
								   {
											   var oRequest = new ActiveXObject(arrSignatures[i]);
											   return oRequest;
								   } 
								   catch (oError) 
								   {
						   }
			   }
			
						  throw new Error("MSXML is not installed on your system.");
}
// Fim objeto AJAX ############################################################################################

function mascara_global(mascara, valor){

	if(mascara == '###.###.###-##|##.###.###/####-##'){
		if(valor.length>14){
			return mascara_global('##.###.###/####-##', valor);
		}else{
			return mascara_global('###.###.###-##', valor);
		}
	}
	
	tvalor = "";
	ret = "";
	caracter = "#";
	separador = "|";
	mascara_utilizar = "";
	valor= trim(valor);
	
	if (valor == "")return valor;
	temp = mascara.split(separador);
	dif = 1000;
	
	valorm = valor;
	

	//tirando mascara do valor já existente
	for (i=0;i<valor.length;i++){
		if (!isNaN(valor.substr(i,1))){
			tvalor = tvalor + valor.substr(i,1);
		}
	}
	valor = tvalor;
	
	//formatar mascara dinamica
	for (i = 0; i<temp.length;i++){
		mult = "";
		validar = 0;
		for (j=0;j<temp[i].length;j++){
			if (temp[i].substr(j,1) == "]"){
				temp[i] = temp[i].substr(j+1);
				break;
			}
			if (validar == 1)mult = mult + temp[i].substr(j,1);
			if (temp[i].substr(j,1) == "[")validar = 1;
		}
		for (j=0;j<valor.length;j++){
			temp[i] = mult + temp[i];
		}
	}
	
	//verificar qual mascara utilizar
	if (temp.length == 1){
		mascara_utilizar = temp[0];
		mascara_limpa = "";
		for (j=0;j<mascara_utilizar.length;j++){
			if (mascara_utilizar.substr(j,1) == caracter){
				mascara_limpa = mascara_limpa + caracter;
			}
		}
		tam = mascara_limpa.length;
	}else{
		//limpar caracteres diferente do caracter da máscara
		for (i=0;i<temp.length;i++){
			mascara_limpa = "";
			for (j=0;j<temp[i].length;j++){
				if (temp[i].substr(j,1) == caracter){
					mascara_limpa = mascara_limpa + caracter;
				}
			}
			if (valor.length > mascara_limpa.length){
				if (dif > (valor.length - mascara_limpa.length)){
					dif = valor.length - mascara_limpa.length;
					mascara_utilizar = temp[i];
					tam = mascara_limpa.length;
				}
			}else if (valor.length < mascara_limpa.length){
				if (dif > (mascara_limpa.length - valor.length)){
					dif = mascara_limpa.length - valor.length;
					mascara_utilizar = temp[i];
					tam = mascara_limpa.length;
				}
			}else{
				mascara_utilizar = temp[i];
				tam = mascara_limpa.length;
				break;
			}
		}
	}
	
	//validar tamanho da mascara de acordo com o tamanho do valor
	if (valor.length > tam){
		valor = valor.substr(0,tam);
	}else if (valor.length < tam){
		masct = "";
		j = valor.length;
		for (i = mascara_utilizar.length-1;i>=0;i--){
			if (j == 0) break;
			if (mascara_utilizar.substr(i,1) == caracter){
				j--;
			}
			masct = mascara_utilizar.substr(i,1) + masct;
		}
		mascara_utilizar = masct;
	}
	
	//mascarar
	j = mascara_utilizar.length -1;
	for (i = valor.length - 1;i>=0;i--){
		if (mascara_utilizar.substr(j,1) != caracter){
			ret = mascara_utilizar.substr(j,1) + ret;
			j--;
		}
		ret = valor.substr(i,1) + ret;
		j--;
	}
	return ret;
}

/* *********************************************************************************************************
 * FUNÇÃO         = String retiraCaracteresSeparacao(Str)
 * OBJETIVO       =
 * Retira caracteres de separação de uma String, ("/", "-", ".", ",", ";", "|", " ", "\", ":", "(", ")").
 * EXEMPLO DE USO = "12122001" = retiraCaracteresSeparacao("12-12.2001");
********************************************************************************************************* */
function retiraCaracteresSeparacao(Str) {
  var s = "";
  var espaco = "X X";
  Str = trim(Str);
  for (i = 0; i < Str.length ; i++) {
    if (Str.charAt(i) != "/" && Str.charAt(i) != "-" && Str.charAt(i) != "."  && Str.charAt(i) != "," &&
        Str.charAt(i) != ";" && Str.charAt(i) != "|" && Str.charAt(i) != espaco.charAt(1) && Str.charAt(i) != "\\" &&
        Str.charAt(i) != ":" && Str.charAt(i) != "(" && Str.charAt(i) != ")"){
      s = s + Str.charAt(i);
    }
  }
  return s;
}


function Verifica_CPF(campo) {
	var CPF = campo.value; // Recebe o valor digitado no campo
	
	// Aqui começa a checagem do CPF
	var POSICAO, I, SOMA, DV, DV_INFORMADO;
	var DIGITO = new Array(10);
	DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado
	
	// Desemembra o número do CPF na array DIGITO
	for (I=0; I<=8; I++) {
	  DIGITO[I] = CPF.substr( I, 1);
	}
	
	// Calcula o valor do 10º dígito da verificação
	POSICAO = 10;
	SOMA = 0;
	   for (I=0; I<=8; I++) {
		  SOMA = SOMA + DIGITO[I] * POSICAO;
		  POSICAO = POSICAO - 1;
	   }
	DIGITO[9] = SOMA % 11;
	   if (DIGITO[9] < 2) {
			DIGITO[9] = 0;
	}
	   else{
		   DIGITO[9] = 11 - DIGITO[9];
	}
	
	// Calcula o valor do 11º dígito da verificação
	POSICAO = 11;
	SOMA = 0;
	   for (I=0; I<=9; I++) {
		  SOMA = SOMA + DIGITO[I] * POSICAO;
		  POSICAO = POSICAO - 1;
	   }
	DIGITO[10] = SOMA % 11;
	   if (DIGITO[10] < 2) {
			DIGITO[10] = 0;
	   }
	   else {
			DIGITO[10] = 11 - DIGITO[10];
	   }
	
	// Verifica se os valores dos dígitos verificadores conferem
	DV = DIGITO[9] * 10 + DIGITO[10];
	   if (DV != DV_INFORMADO) {
	   	  alert("CPF inválido!");
		  campo.focus();
		  campo.select();
		  return false;
	   } else {
	      return true;
	   }
	}

//#########################################################
function validaCNPJ(campo) {
	//CNPJ = document.validacao.CNPJID.value;
	CNPJ = campo.value;
	erro = new String;
	/*if (CNPJ.length < 18) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
		if (erro.length == 0) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
	}*/
	
	//substituir os caracteres que nao sao numeros
	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = CNPJ.substring(0,2);
		x += CNPJ.substring(3,6);
		x += CNPJ.substring(7,10);
		x += CNPJ.substring(11,15);
		x += CNPJ.substring(16,18);
		CNPJ = x;	
	} else {
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace("-","");
		CNPJ = CNPJ.replace("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";	
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++){
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	b = 0;
	for (y=0; y<13; y++) {
		b += (a[y] * c[y]); 
	}
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
		//erro +="Digito verificador com problema!";
		erro +="CNPJ inválido!";
	}
	if (erro.length > 0){
		alert(erro);
		campo.focus();
		campo.select();
		return false;
	/*} else {
		alert("CNPJ valido!");*/
	}
	return true;
}


/*
Função para validar CPF e CNPJ
ex: Valida_CPF_CNPJ(this, 1 ou 2) física ou jurídica
*/
function Valida_CPF_CNPJ(campo,tipo) {
	if (campo.value != "") {
		if (tipo == 1) {
			return Verifica_CPF(campo);
		} else {
			return validaCNPJ(campo);
		}
		
	} else {
		return true;
	}
}

function abrir3(URL,apelido) {
  // var www = URL + ende
   var width = 625;
   var height = 400;

   var left = 99;
   var top = 01;

   window.open(URL,apelido, 'width='+width+', height='+height+', top='+top+', left='+left+', toolbar=no, location=no, directories=no, menubar=no, scrollbars=yes, resizable=no, fullscreen=no');
}

function abrir2(URL,apelido) {
  // var www = URL + ende
   var width = 625;
   var height = 500;

   var left = 99;
   var top = 01;
   var nome = document.form_pessoa.nome.value;

   window.open(URL+nome,apelido, 'width='+width+', height='+height+', top='+top+', left='+left+', toolbar=no, location=no, directories=no, menubar=no, scrollbars=yes, resizable=no, fullscreen=no');

}

function Sele(nome,id,tp){
	if (nome != "" && id != "" ){
	//alert (tp);
		//window.opener.document.form_pessoa.nome.value = "";
		//window.opener.document.form_pessoa.id.value = "";
		//window.opener.document.form_pessoa.nome.value += nome;	
		//window.opener.document.form_pessoa.id.value += id;
		window.open('cad_cliente.php?id='+ id +'&tp='+ tp,'principal');
		window.close();
	}
	else{
		alert("Falta parâmetro!");
	}
}

function confirma(url,apelido){ 

	if (confirm("Você deseja realmente exculir esse registro")){
		window.open(url,apelido);
	}
	else{
		return false;
	}

}

/*---------------------------------------------------------------------*/
/*
Função que limita a quantidade de caracteres numa TextArea.
No parâmetro "campo", deve ser passado "NomeFormulário.NomeCampo".
No parâmetro "max", deve ser passado o limite desejado.
*/
function LimitaArea(campo,max) { 
	if (campo.value.length >= max && event.keyCode != 8) 
	{
		alert("O máximo de caracteres é " + max + "."); 
		event.keyCode = 0;
		campo.focus;
		return false;
   } 
	else return true;
}

/* ------------------------------------------------------------------
Função para formatar CEP."65000-000"
Parâmetros:
cep = this.value
campo = this
ex: onKeyUp="mascara_cep(this.value,this)"
------------------------------------------------------------------ */
function mascara_cep(cep,campo)
{
	var temp1 = '';
	var temp2 = '';
	var tecla = event.keyCode;
	if (tecla == 8){
	return true;
	}
	var num = '';
	num = num + cep;
	if (num.length == 5) {
	campo.value = num + '-';
	}
	
	if (num.length == 9) {
		num = num.replace('-','');
		temp1 = num.substring(0,5);
		temp2 = num.substring(5,num.length);
		campo.value = temp1 + '-' + temp2;
		campo.value = campo.value.substring(0,9);
	}
}

/* ------------------------------------------------------------------
Função para formatar hora."10:00"
Parâmetros:
hora = this.value
campo = this
ex: onKeyUp="mascara_hora(this.value,this)"
------------------------------------------------------------------ */
function mascara_hora(hora,campo)
{
	var temp1 = '';
	var temp2 = '';
	if (document.all) { // Internet Explorer
		var tecla = event.keyCode;
	}
	else if(document.layers) { // Nestcape
		var tecla = e.which;
	}
	if (tecla == 8) {
		return true;
	}
	var num = '';
	num = num + hora;
	if (num.length == 2) {
		num = num.substring(0,2) + ':' + num.substring(2,num.length);
		campo.value = num;
	}
	if (num.length == 5) {
		num = num.replace(':','');
		temp1 = num.substring(0,2);
		temp2 = num.substring(2,num.length);
		//num = '';
		//num = temp1 + temp2;
		campo.value = temp1 + ':' + temp2;
		campo.value = campo.value.substring(0,5);
	}
	if (num.length > 5) {
		event.keyCode = 0;
		campo.value = num.substring(0,num.length - 1)
	}
}

/* ------------------------------------------------------------------
Função para formatar fone."9999-9999"
Parâmetros:
fone = this.value
campo = this
ex: onKeyUp="mascara_fone(this.value,this)"
------------------------------------------------------------------ */
function mascara_fone(fone,campo)
{
	var temp1 = '';
	var temp2 = '';
	if (document.all) { // Internet Explorer
		var tecla = event.keyCode;
	}
	else if(document.layers) { // Nestcape
		var tecla = e.which;
	}
	//var tecla = event.keyCode;
	if (tecla == 8) {
		return true;
	}
	var num = '';
	num = num + fone;
	/*if (num.length == 1) {
	campo.value = '(' + num;
	}
	if (num.length == 3) {
	num = num + ')';
	campo.value = num;
	}*/
	if (num.length == 4) {
		num = num.substring(0,4) + '-' + num.substring(4,num.length);
		campo.value = num;
	}
	/*if (num.length == 9) {
		num = num.replace('-','');
		temp1 = num.substring(0,8);
		temp2 = num.substring(8,num.length);
		//num = '';
		//num = temp1 + temp2;
		campo.value = temp1 + '-' + temp2
	}*/
	if (num.length > 9) {
		event.keyCode = 0;
		campo.value = num.substring(0,num.length - 1)
	}
}

/*---------------------------------------------------------------------*/
/* Função que só permite digitar valores numéricos. */
function SoNumero(e)
{
	if (document.all) { // Internet Explorer
		var tecla = event.keyCode;
	}
	else if(document.layers) { // Nestcape
		var tecla = e.which;
	}
	
	if (tecla > 47 && tecla < 58) { // numeros de 0 a 9
		return true;
	}
	else
		{
			if (tecla != 8) // backspace
				event.keyCode = 0;
				//return false;
			else
				return true;
		}
}

/***************************************************************************************************
Função para validar URL.
Parâmetros:
obj = this
ex: validaURL(this)
****************************************************************************************************/
function validaURL(obj) {
    if(!isValidURL(obj.value) && obj.value != ''){
		alert("URL não é válida!");
		obj.focus();
		obj.select();
		return false;
	} else {
		return true;
	}
}

function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}


/***************************************************************************************************
Função para validar email.
Parâmetros:
nform = this
ex: checaemail(this)
****************************************************************************************************/
function checaemail(nform) {
	if (nform.value == "") {
		//alert("Informe seu e-mail.");
		//nform.focus();
		//nform.select();
		return false;
	} else {
		prim = nform.value.indexOf("@")
		if(prim < 2) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("hotmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
		if(nform.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.focus();
			nform.select();
			return false;
		}
	}
		return true;
}

/*------------------------------------------------------------------------
Validar Data javaScript 2
No evento onblur do input e so vc chamar a função completaData data.
ex: completaData(campo)
------------------------------------------------------------------------*/
function completaData(ObjData) { 
var data = ''; 
var dia = ''; 
var mes = ''; 
var ano = ''; 

data = ObjData.value; 

if (data != '') { 
dia = data.substring(0, data.indexOf("/")); 
ano = data.substring(data.lastIndexOf("/") + 1, data.length); 
mes = data.substring(data.indexOf("/") + 1, data.lastIndexOf("/")) 

dia = dia - 0; 
mes = mes - 0; 

dia = dia < 10 ? "0" + dia: dia; 
mes = mes < 10 ? "0" + mes: mes; 

if(Number(ano) >= 50 && Number(ano) <= 99){ 
ano = "19" + ano; 
} 
else{ 
ano = ano.length < 4 ? "20" + ano: ano; 
} 

ObjData.value = dia + "/" + mes + "/" + ano; 
if (!ValidaDatas(ObjData.value)) { 
ObjData.value = ""; 
alert("Data inválida."); 
ObjData.focus(); 
} 
} 
} 

/*Valida datas*/
function ValidaDatas(strData) 
{ 
var dia, mes, ano, MaxDia; 
if (strData == '') return false; 

dia = strData.substring(0, 2); 
mes = strData.substring(3, 5); 
ano = strData.substring(6, strData.length); 

if(mes <= 12 && mes >= 1){ 
if(strData.length == 10){ 
MaxDia = MaxDiasMes(mes, ano); 
if(dia > MaxDia) return false; 
} 
else{ 
return false; 
} 
} 
else { 
return false; 
} 
return true; 
} 

/*Completa a função ValidaDatas*/
function MaxDiasMes(mes, ano){ 
var DiasMes = new Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
mes = mes - 0; 
ano = ano - 0; 
if (mes >= 1 && mes <= 12) { 
if (mes == 2) 
return (ano % 4) == 0 ? 29: 28; 
else return DiasMes[mes]; 
} 
} 

