function palavrachave(){
	location.href = 'palavrachave.php?str=' + document.getElementById('txtpalavrachave').value;
}
function formataCEP(formato, keypress, objeto)
{
//onKeyPress="formataCEP('CEP', window.event.keyCode, this);"
campo = eval(objeto);
if (formato=='CEP')
	{
	caracteres = '01234567890';
	separacoes = 1;
	separacao1 = '-';
	conjuntos = 2;
	conjunto1 = 5;
	conjunto2 = 3;
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
	(conjunto1 + conjunto2 + 1))
		{
		if (campo.value.length == conjunto1) 
		   campo.value = campo.value + separacao1;
		}
	else 
		event.returnValue = false;
	}
}


function trim(valorTrim){
	var len = valorTrim.length;
	for(var x=0; x<len; x++) if(valorTrim.charCodeAt(x)!=32 && valorTrim.charCodeAt(x)!=10 && valorTrim.charCodeAt(x)!=13) break;
	valorTrim = valorTrim.substring(x,len);
	len = valorTrim.length;
	for(x=len-1; x>0; x--) if(valorTrim.charCodeAt(x)!=32 && valorTrim.charCodeAt(x)!=10 && valorTrim.charCodeAt(x)!=13) break;
	valorTrim = valorTrim.substring(0,x+1);
	return valorTrim;
}
function getFocus(formulario, campo){
	eval("document." + formulario + "." + campo + ".focus()")
}
function camposVazios(formulario){
	//se retornar false quer dizer que o formulário não possui nenhum campo em branco
	var i, temp;
	var args = camposVazios.arguments;
	var nomeCampo = false;
	
	for(i=1; i<args.length; i++){
		if(eval("trim(document." + formulario + "." + args[i] + ".value)")=="" ){
			nomeCampo = args[i];
			break;
		}
	}
	return nomeCampo;
}
function blockChar(args){
	//coloque os caracteres que deseja bloquear no argumento da função
	//ex: blockChar('0123456789') -- Bloqueia os numeros
	//se quiser bloquear pelo codigo ASC coloque outros parametros na frente do primeiro;
	//ex: blockChar('', 13, 85, 94)
	for(var i=0; i<args.length;  i++){
		if (window.event.keyCode == args.charCodeAt(i)){
			event.returnValue = false;
			break;
		}
	}//end for

	if(blockChar.arguments.length > 1){
		for(var i=1; i<blockChar.arguments.length; i++){
			if (!isNaN(blockChar.arguments[i]) && window.event.keyCode == blockChar.arguments[i]){
				event.returnValue = false;
				break;
			}
		}//end for
	}// end if
}//eend function

function soNumeros(){
	if (window.event.keyCode < 48 || window.event.keyCode > 57)
	event.returnValue = false;
}

function popup(caminho,nome,largura,altura,rolagem) 
{
//	var esquerda = 0;
//	var cima = 0;
//	var largura = screen.width - 10;
//	var altura = screen.height - 70;
	var esquerda = (screen.width - largura) / 2;
	var cima = (screen.height - altura) / 2 -50;
	window.open(caminho,nome,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + rolagem + ',resizable=yes,copyhistory=no,top=' + cima + ',left=' + esquerda + ',width=' + largura + ',height=' + altura);
//popup('lrm_default.cfm','logisticaMaster','750','550','yes');
}

function showHideLayers() { //v2.0
  var i, visStr, args, theObj;
  args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
    visStr   = args[i+2];
    if (navigator.appName == 'Netscape' && document.layers != null) {
      theObj = eval(args[i]);
      if (theObj) theObj.visibility = visStr;
    } else if (document.all != null) { //IE
      if (visStr == 'show') visStr = 'visible'; //convert vals
      if (visStr == 'hide') visStr = 'hidden';
      theObj = eval(args[i+1]);
      if (theObj) theObj.style.visibility = visStr;
  } }
}


function str_pad(input,pad_length,pad_string,pad_type){
	
	var novaStr="";
	if(input.length >= pad_length){
		
		return input.substr(0,pad_length)

	}else{
		for(var i=input.length; i<pad_length; i++) novaStr = novaStr + pad_string;
	
	/*incrementa a esquerda da estring*/
		if(pad_type == 'E'){
				return novaStr + input;

		/*incrementa a direita da estring*/	
		}else{
				return input + novaStr;
		}
	}
}

	
function ValidarCNPJ(obj){
	c = eval("document." + obj);
	EntraCNPJ = trim(c.value);
	VetCNPJ = new Array(16);
	var TempCNPJ, DG1, DG2;
	var Tot1, Tot2;
	var I, X;
	var Peso1 = "543298765432";
	var Peso2 = "6543298765432";

	TempCNPJ = EntraCNPJ;
	TempCNPJ = TempCNPJ.replace('.','');
	TempCNPJ = TempCNPJ.replace('.','');
	TempCNPJ = TempCNPJ.replace('/','');
	TempCNPJ = TempCNPJ.replace('-','');
	
	while (TempCNPJ.length < 14){
		TempCNPJ = '0' + TempCNPJ;
	}
	if (TempCNPJ == 11111111111111 || TempCNPJ == 22222222222222 || TempCNPJ == 33333333333333 || TempCNPJ == 44444444444444 || TempCNPJ == 55555555555555 || TempCNPJ == 66666666666666 || TempCNPJ == 77777777777777 || TempCNPJ == 88888888888888 || TempCNPJ == 99999999999999 || TempCNPJ == 00000000000000){ return false; } 
	for (I=1;I<=14;I++){
		VetCNPJ[I] = TempCNPJ.substr(I-1,1);
	}
	Tot1 = 0;
	Tot2 = 0;

	for (I=1;I<=12;I++){ // to 3 step -1
		Tot1 = Tot1 + VetCNPJ[I] * parseInt(Peso1.substr(I - 1,1),10);
	}
	for (I=1;I<=13;I++){
		Tot2 = Tot2 + VetCNPJ[I] * parseInt(Peso2.substr(I - 1,1),10);
	}
	DG1 = Tot1 % 11;
	DG2 = Tot2 % 11;
	if (DG1 == 0 || DG1 == 1){
		DG1 = 0;
	}else{
		DG1 = 11 - DG1;
	}
	if (DG2 == 0 || DG2 == 1){
		DG2 = 0;
	}else{
		DG2 = 11 - DG2;
	}
	if (parseInt(DG1,10) == parseInt(VetCNPJ[13],10) && parseInt(DG2,10) == parseInt(VetCNPJ[14],10) && Tot1 > 0 && Tot2 > 0){
		return true;
		 //ValidaCNPJ = TRUE
	}else{
		return false;
		//ValidaCNPJ = FALSE
	}
}

function validarMail(c) 
{
	c = eval("document." + c);
	email = trim(c.value);
	 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
 	   {
			return true;
       }
	 else
	   { 
	      return false;
	   }
}
function Hoje(){
	
	var objData = new Date();
	var dia = new String(objData.getDate());
	var mes = new String(objData.getMonth() +1);
	var ano = new String(objData.getFullYear());
	if(parseInt(dia.length) == 1){
		dia = "0" + dia;
	}
	if(parseInt(mes.length) == 1){

		mes = "0" + mes;
	}

	return dia + "/" + mes + "/" + ano;

	
}

function comparaData(data1, data2){
	//------------------------------
	// Uso: comparaData("10/01/2002", "10/03/2002");
	// data1 e data2 no formato "dd/mm/aaaa"
	// se retornar 1 "data1" é maior
	// se retornar 2 "data2" é maior
	// se retornar 0 "data1" é igual a "data2"
	//------------------------------
	var dataDiff = transformaData(data2) - transformaData(data1);
	var maiorData, dataSaida;

	if(dataDiff > 0){dataSaida = 2;}
	else if(dataDiff < 0){dataSaida = 1;}
	else {dataSaida = 0;}

	return dataSaida;
}

function transformaData(data){// data no formato dd/mm/aaaa
	data = trim(data);
	argDia = parseInt(data.substring(0,2), 10);
	argMes = parseInt(data.substring(3,5), 10) - 1;
	argAno = parseInt(data.substring(6,10),10);
	data = new Date(argAno, argMes, argDia);
	return data;
}

function isDate(data){
	data = trim(data);
	if(data != ""){
		dia = parseInt(data.substring(0,2), 10);
		mes = parseInt(data.substring(3,5), 10);
		ano = parseInt(data.substring(6,10),10);
		//Verifica se o tamanho da string é 10 
		if(data.length < 10 || (mes < 1 || mes > 12) || (dia > 31 || dia < 1)) 
			return false;
		var quantDias;
		if(mes==4 || mes==6 || mes==9 || mes==11)//mes com 30 dias
			quantDias = 30;
		else if(mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12)//mes com 31	
			quantDias = 31;
		else if(mes==2){ //mes com 28
			if((ano % 4 == 0) && (ano % 100 != 0 || ano % 400 ==0)) quantDias = 29; //verifica se é bissexto
			else quantDias = 28;
		}
		if(dia > quantDias || dia < 1) return false;
	}
	return true;
}

function validarNumeroObjeto(objeto){
	objeto = trim(objeto);
	if(objeto.length != 13) return false;

	var valor1 = objeto.substring(0,2);
	var valor2 = objeto.substring(2,11);
	var valor3 = objeto.substring(11,13);

	// Verificar os 2 primeiros e os 2 ultimos digitos
	for(i=0; i<2; i++){
		if((! isNaN(valor1.charAt(i))) || (! isNaN(valor3.charAt(i))) ) return false;
	}
	//verificar os digitos do meio do numero do objeto
	var i = 0
	while (i < valor2.length){
    	if(isNaN(valor2.charAt(i)) || valor2.charCodeAt(i)==32 ) return false;
		i++;
	}
	return true;
}

function FormataValor(campo,tammax,teclapres) 
 {
 	//uso:
	//<input type="Text" name="fat_vr_bruto" maxlength="17" onKeyDown="FormataValor(this,17,event)">

	var tecla = teclapres.keyCode;
	vr = campo.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		campo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}			
}

function FormataData(nomecampo,teclapres) {
//	onKeydown="FormataData('nome_campo',event);"
	var tecla = teclapres.keyCode;
	vr = document.form1[nomecampo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form1[nomecampo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form1[nomecampo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

function addfav(){
	if (document.all)
		window.external.AddFavorite(document.location.href, "Anúncio Certo")
}

function addBookmark(url, titulo)
{
	//Parâmetros: 
	//url: Endereço a ser adicionado
	//titulo: Título que aparecerá nos Favoritos
	if (document.all)
		window.external.AddFavorite(url, titulo)
}

function validarCep(cep)
{
	c = cep;

	if(c.length == 0)
		return false;

	c = c.replace("-","");
	c = c.replace(".","");
	if(c.length != 8 || isNaN(c))
		return false;
	else
		return true;
}
function criaMascara(_RefObjeto, _Modelo){

var valorAtual = _RefObjeto.value;
var valorNumerico = '';
var nIndexModelo = 0;
var nIndexString = 0;
var valorFinal = '';
var adicionarValor = true;
 

// limpa a string valor atual para verificar
// se todos os caracteres são números
for (i=0;i<_Modelo.length;i++){
  if (_Modelo.substr(i,1) != '#'){
    valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
}}
 
// verifica se todos os caracteres são números
for (i=0;i<valorAtual.length;i++){
  if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
    valorNumerico = valorNumerico + valorAtual.substr(i,1);
}}
 
// aplica a máscara ao campo informado usando
// o modelo de máscara informado no script
for (i=0;i<_Modelo.length;i++){
 
  if (_Modelo.substr(i,1) == '#'){
    if (valorNumerico.substr(nIndexModelo,1) != ''){
      valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
      nIndexModelo++;nIndexString++;
    }
      else {
        adicionarValor = false;
  }}
 
    else {
      if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
      valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
      nIndexString++;
    }}
}
 
_RefObjeto.value = valorFinal
 
}


function criaMascaraV(_RefObjeto, _Modelo){

var valorAtual = _RefObjeto.value;
var valorNumerico = '';
var nIndexModelo = 0;
var nIndexString = 0;
var valorFinal = '';
var adicionarValor = true;
 

// limpa a string valor atual para verificar
// se todos os caracteres são números
for (i=0;i<_Modelo.length;i++){
  if (_Modelo.substr(i,1) != '#'){
    valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
}}
 
// verifica se todos os caracteres são números
for (i=0;i<valorAtual.length;i++){
  if (!isNaN(parseFloat(valorAtual.substr(i,1))) || valorAtual.substr(i,1) == "." || valorAtual.substr(i,1) == "," ){
		if (valorAtual.substr(i,1) == ","){
			valorNumerico = valorNumerico + ".";
		}else{
			valorNumerico = valorNumerico + valorAtual.substr(i,1);
		}
}}
 
// aplica a máscara ao campo informado usando
// o modelo de máscara informado no script
for (i=0;i<_Modelo.length;i++){
 
  if (_Modelo.substr(i,1) == '#'){
    if (valorNumerico.substr(nIndexModelo,1) != ''){
      valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
      nIndexModelo++;nIndexString++;
    }
      else {
        adicionarValor = false;
  }}
 
    else {
      if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
      valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
      nIndexString++;
    }}
}
 
_RefObjeto.value = valorFinal
 
}

function CriaMascaraMoeda(fld, milSep, decSep, e,maximo) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;

if(whichCode == 0) {fld.value = ""; return true;}
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
if (len <= maximo) { 
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += '.';
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}	
	string = fld.value

	for (i=1;i<string.lenght;i++){
		string = string.replace('.','.');
	}
	fld.value = string;
	return false;
	}
	return false;
}

function vazio(c){
 c = eval("document."+c);
 if(trim(c.value)==""){
  //alert(c.lang);
  //c.focus();
  return false;
 }else{
  return true;
 }
}
function CPF(EntraCPF){
	
	VetCPF = new Array(12);
	var TempCPF, DG1, DG2;
	var Tot1, Tot2;
	var I, X;
	TempCPF = EntraCPF;
	TempCPF = TempCPF.replace('.','');
	TempCPF = TempCPF.replace('.','');
	TempCPF = TempCPF.replace('-','');
	
	while (TempCPF.length < 11){
		TempCPF = '0' + TempCPF;
		}
	if (TempCPF == 11111111111 || TempCPF == 22222222222 || TempCPF == 33333333333 || TempCPF == 44444444444 || TempCPF == 55555555555 || TempCPF == 66666666666 || TempCPF == 77777777777 || TempCPF == 88888888888 || TempCPF == 99999999999 || TempCPF == 00000000000){ return false; } 
	for (I=1;I<12;I++){
		VetCPF[I] = TempCPF.substr(I-1,1);
		}
	Tot1 = 0;
	Tot2 = 0;
	X = 1;
	for (I=10;I>=2;I--){ // to 3 step -1
		Tot1 = Tot1 + VetCPF[X] * I;
		X++;
		}
	X = 1;
	for (I=11;I>=2;I--){
		Tot2 = Tot2 + VetCPF[X] * I;
		X++;
		}
	DG1 = Tot1 % 11;
	DG2 = Tot2 % 11;
	if (DG1 == 0 || DG1 == 1){
		DG1 = 0;
		}
	else{
		DG1 = 11 - DG1;
		}
	if (DG2 == 0 || DG2 == 1){
		DG2 = 0;
		}
	else{
		DG2 = 11 - DG2;
		}
	if (parseInt(DG1,10) == parseInt(VetCPF[10],10) && parseInt(DG2,10) == parseInt(VetCPF[11],10) && Tot1 > 0 && Tot2 > 0){
		return true;
		} //ValidaCPF = TRUE
	else{
		return false;
		}//ValidaCPF = FALSE
}
function CNPJ(EntraCNPJ){
	
	VetCNPJ = new Array(16);
	var TempCNPJ, DG1, DG2;
	var Tot1, Tot2;
	var I, X;
	var Peso1 = "543298765432";
	var Peso2 = "6543298765432";

	TempCNPJ = EntraCNPJ;
	TempCNPJ = TempCNPJ.replace('.','');
	TempCNPJ = TempCNPJ.replace('.','');
	TempCNPJ = TempCNPJ.replace('/','');
	TempCNPJ = TempCNPJ.replace('-','');
	
	while (TempCNPJ.length < 14){
		TempCNPJ = '0' + TempCNPJ;
		}
	if (TempCNPJ == 11111111111111 || TempCNPJ == 22222222222222 || TempCNPJ == 33333333333333 || TempCNPJ == 44444444444444 || TempCNPJ == 55555555555555 || TempCNPJ == 66666666666666 || TempCNPJ == 77777777777777 || TempCNPJ == 88888888888888 || TempCNPJ == 99999999999999 || TempCNPJ == 00000000000000){ return false; } 
	for (I=1;I<=14;I++){
		VetCNPJ[I] = TempCNPJ.substr(I-1,1);
		}
	Tot1 = 0;
	Tot2 = 0;

	for (I=1;I<=12;I++){ // to 3 step -1
		Tot1 = Tot1 + VetCNPJ[I] * parseInt(Peso1.substr(I - 1,1),10);
		}
	for (I=1;I<=13;I++){
		Tot2 = Tot2 + VetCNPJ[I] * parseInt(Peso2.substr(I - 1,1),10);
		}
	DG1 = Tot1 % 11;
	DG2 = Tot2 % 11;
	if (DG1 == 0 || DG1 == 1){
		DG1 = 0;
		}
	else{
		DG1 = 11 - DG1;
		}
	if (DG2 == 0 || DG2 == 1){
		DG2 = 0;
		}
	else{
		DG2 = 11 - DG2;
		}
	if (parseInt(DG1,10) == parseInt(VetCNPJ[13],10) && parseInt(DG2,10) == parseInt(VetCNPJ[14],10) && Tot1 > 0 && Tot2 > 0){
		return true;
		} //ValidaCNPJ = TRUE
	else{
		return false;
		}//ValidaCNPJ = FALSE
}
function EMAIL(email){	
	email = email;
	regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
//	regex = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if (email.search(regex) == -1){
		return false;
	}else{ 
		return true;
	}
}


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+'.'+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') +  num + ',' + cents);
}

function pega_datahora(){
		
		var hoje = new Date();
		var dia = hoje.getDate();
		var dias = hoje.getDay();
		var mes = hoje.getMonth();
		var ano = hoje.getYear();

		var hora = hoje.getHours();
		var minuto = hoje.getMinutes();	
		var segundo = hoje.getSeconds();
		var milisegundos = hoje.getMilliseconds();
		if (dia < 10){
			dia = "0" + dia;
		}	
		if (mes < 10){
			mes = "0" + mes;
		}	
		if (ano < 2000){
			ano = "19" + ano;
		}	
		var strdatahora = ano + "" + mes + "" + dia + "" + hora + "" + minuto + "" + segundo + "" + milisegundos;	
		return strdatahora;
	
	}
//  End -->

