// JavaScript Document

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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_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];}
}

function Url(Url)
{
	location.href = Url;
}

function mouseOvr(src, clrOver)
{
	src.style.cursor = 'hand';
	src.bgColor = clrOver;
}

function mouseOut(src, clrOver)
{
	src.bgColor = clrOver;
}

function formata_data( x, tecla)
{
	separador = "/";
			
	tecla = tecla.keyCode;
			
	valor = x.value.split('');
	formatado = "";
			
	i = 0;
			
	while( i < valor.length)
	{
		caractere = valor[i];
		numeros = /^\d+$/;
		
		if(numeros.test(caractere) || caractere == separador)
		{
			formatado += String(caractere);
		}
		
		if((formatado.length == 2 || formatado.length == 5 ) && tecla != 8 )
		{
			formatado += separador; i++;
		}
							
		i++;
	}
			
	x.value = formatado;
}

function formata_cep( x, tecla)
{
	separador = "-";
			
	tecla = tecla.keyCode;
			
	valor = x.value.split('');
	formatado = "";
			
	i = 0;
			
	while( i < valor.length)
	{
		caractere = valor[i];
		numeros = /^\d+$/;
		
		if(numeros.test(caractere) || caractere == separador)
		{
			formatado += String(caractere);
		}
		
		if((formatado.length == 5 ) && tecla != 8 )
		{
			formatado += separador; i++;
		}
							
		i++;
	}
			
	x.value = formatado;
}

function formata_tel( x, tecla)
{
	separador = "-";
			
	tecla = tecla.keyCode;
			
	valor = x.value.split('');
	formatado = "";
			
	i = 0;
			
	while( i < valor.length)
	{
		caractere = valor[i];
		numeros = /^\d+$/;
		
		if(numeros.test(caractere) || caractere == separador)
		{
			formatado += String(caractere);
		}
		
		if((formatado.length == 4 ) && tecla != 8 )
		{
			formatado += separador; i++;
		}
							
		i++;
	}
			
	x.value = formatado;
}

function formata_cpf( x, tecla)
{
	separador = ".";
	separador1 = "-";	
			
	tecla = tecla.keyCode;
			
	valor = x.value.split('');
	formatado = "";
			
	i = 0;
			
	while( i < valor.length)
	{
		caractere = valor[i];
		numeros = /^\d+$/;
		
		if(numeros.test(caractere) || caractere == separador)
		{
			formatado += String(caractere);
		}
		
		if(( formatado.length == 3 || formatado.length == 7 ) && tecla != 11 )
		{
			formatado += separador; i++;
		}
		
		if(( formatado.length == 11 ) && tecla != 11 )
		{
			formatado += separador1; i++;
		}		
							
		i++;
	}
			
	x.value = formatado;
}

function formata_cnpj( x, tecla)
{
	separador = ".";
	separador1 = "/";	
	separador2 = "-";		
			
	tecla = tecla.keyCode;
			
	valor = x.value.split('');
	formatado = "";
			
	i = 0;
			
	while( i < valor.length)
	{
		caractere = valor[i];
		numeros = /^\d+$/;
		
		if(numeros.test(caractere) || caractere == separador)
		{
			formatado += String(caractere);
		}
		
		if(( formatado.length == 2 || formatado.length == 6 ) && tecla != 11 )
		{
			formatado += separador; i++;
		}
		
		if(( formatado.length == 10 ) && tecla != 11 )
		{
			formatado += separador1; i++;
		}
		
		if(( formatado.length == 15 ) && tecla != 11 )
		{
			formatado += separador2; i++;
		}		
							
		i++;
	}
			
	x.value = formatado;
}

function NumerosKeyPress(tecla)
{
  if(typeof(tecla) == 'undefined')
  
  var tecla = window.event; 
  var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);

	if (codigo == '13' || codigo == '27' || codigo == '46' || codigo == '8' || codigo == '37' || codigo == '39')
	{
    return true;
	}
	else if (codigo < '48' || codigo > '58')
	{
    return false;
	}  
}

function NumerosKeyPressQtd(tecla)
{
  if(typeof(tecla) == 'undefined')
  
  var tecla = window.event; 
  var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);

	if (codigo == '44')
	{
		return true;
	}
	else if (codigo == '13' || codigo == '27')
	{
    return true;
	}
	else if (codigo < '48' || codigo > '58')
	{
    return false;
	}  
}

function NumerosKeyPressPorcento(tecla)
{
  if(typeof(tecla) == 'undefined')
  
  var tecla = window.event; 
  var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);

	if (codigo == '44')
	{
		return true;
	}
	else if (codigo == '13' || codigo == '27')
	{
    return true;
	}
	else if (codigo < '48' || codigo > '58')
	{
    return false;
	}  
}

function NumerosKeyDown()
{
  if (event.ctrlKey)
  {
    return false;
	}
	
	return true;
}

function Proximo(Qtd,objeto, obeto1)
{
	campo = eval (objeto);
	
	if (campo.value.length == Qtd)
	{
		obeto1.focus();
	}	
}

function TestaCampoFile()
{
	if (event.keyCode == '13')
	{
		return false;
	}
	else if (event.keyCode < '57' || event.keyCode > '58') 
	{
		return false;
	}
}

//MÁSCARA DE MOEDA
//Modo de usar:
//onkeypress="reais(this,event)" onkeydown="backspace(this,event)" 

documentall = document.all;

function formatamoney(c) 
{
	var t = this; if(c == undefined) c = 2; 
	var p, d = (t=t.split("."))[1].substr(0, c);
	for(p = (t=t[0]).length; (p-=3) >= 1;) 
	{
		t = t.substr(0,p) + "." + t.substr(p);
	}
	
	return t+","+d+Array(c+1-d.length).join(0);
}

String.prototype.formatCurrency = formatamoney

function demaskvalue(valor, currency)
{

	// Se currency é false, retorna o valor sem apenas com os números. Se é true, os dois últimos caracteres são considerados as 
	// casas decimais
	var val2 = '';
	var strCheck = '0123456789';
	var len = valor.length;
	if (len== 0)
	{
		return 0.00;
	}

	if (currency ==true)
	{ 
		// Elimina os zeros à esquerda 
		// a variável <i> passa a ser a localização do primeiro caractere após os zeros e 
		// val2 contém os caracteres (descontando os zeros à esquerda)

		for(var i = 0; i < len; i++)
		if ((valor.charAt(i) != '0') && (valor.charAt(i) != ',')) break;

		for(; i < len; i++)
		{
			if (strCheck.indexOf(valor.charAt(i))!=-1) val2+= valor.charAt(i);
		}

		if(val2.length==0) return "0.00";
		if (val2.length==1)return "0.0" + val2;
		if (val2.length==2)return "0." + val2;

		var parte1 = val2.substring(0,val2.length-2);
		var parte2 = val2.substring(val2.length-2);
		var returnvalue = parte1 + "." + parte2;

		return returnvalue;
	}
	else
	{
		// currency é false: retornamos os valores COM os zeros à esquerda, 
		// sem considerar os últimos 2 algarismos como casas decimais 
		val3 ="";
		for(var k=0; k < len; k++)
		{
			if (strCheck.indexOf(valor.charAt(k))!=-1) val3+= valor.charAt(k);
		} 
		
		return val3;
	}
}

function FormataReais(fld, milSep, decSep, e) {
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 == 8 ) return true;
//backspace - estamos tratando disso em outra função no keydown
if (whichCode == 0 ) return true;
if (whichCode == 9 ) return true; //tecla tab
if (whichCode == 13) return true; //tecla enter
if (whichCode == 16) return true; //shift internet explorer
if (whichCode == 17) return true; //control no internet explorer
if (whichCode == 27 ) return true; //tecla esc
if (whichCode == 34 ) return true; //tecla end
if (whichCode == 35 ) return true;//tecla end
if (whichCode == 36 ) return true; //tecla home


//O trecho abaixo previne a ação padrão nos navegadores. Não estamos inserindo o caractere normalmente, mas via script


if (e.preventDefault){ //standart browsers
e.preventDefault()
}else{ // internet explorer
e.returnValue = false
}

var key = String.fromCharCode(whichCode); // Valor para o código da Chave
if (strCheck.indexOf(key) == -1) return false; // Chave inválida


//Concatenamos ao value o keycode de key, se esse for um número

fld.value += key;

var len = fld.value.length;
var bodeaux = demaskvalue(fld.value,true).formatCurrency();
fld.value=bodeaux;


//Essa parte da função tão somente move o cursor para o final no opera. Atualmente não existe como movê-lo no konqueror.

if (fld.createTextRange) {
var range = fld.createTextRange();
range.collapse(false);
range.select();
}
else if (fld.setSelectionRange) {
fld.focus();
var length = fld.value.length;
fld.setSelectionRange(length, length);
}
return false;

}

function reais(obj,event)
{

	var whichCode = (window.Event) ? event.which : event.keyCode;

	//Executa a formatação após o backspace nos navegadores !document.all
	if (whichCode == 8 && !documentall)
	{ 

		//Previne a ação padrão nos navegadores
		if (event.preventDefault)
		{
			//standart browsers
			event.preventDefault();
		}
		else
		{
			// internet explorer
			event.returnValue = false;
		}

		var valor = obj.value;
		var x = valor.substring(0,valor.length-1);
		obj.value= demaskvalue(x,true).formatCurrency();
		return false;
	}

	//Executa o Formata Reais e faz o format currency novamente após o backspace
	FormataReais(obj,'.',',',event);
}


function backspace(obj,event)
{

	//Essa função basicamente altera o backspace nos input com máscara reais para os navegadores IE e opera.
	//O IE não detecta o keycode 8 no evento keypress, por isso, tratamos no keydown.
	//Como o opera suporta o infame document.all, tratamos dele na mesma parte do código.

	var whichCode = (window.Event) ? event.which : event.keyCode;
	
	if (whichCode == 8 && documentall)
	{ 
		var valor = obj.value;
		var x = valor.substring(0,valor.length-1);
		var y = demaskvalue(x,true).formatCurrency();

		obj.value =""; //necessário para o opera
		obj.value += y;

		if (event.preventDefault)
		{
			//standart browsers
			event.preventDefault();
		}
		else
		{
			// internet explorer
			event.returnValue = false;
		}

		return false;

	}
}

function EnviaContato() 
{
	if (document.FormContato.edt_Nome.value == "")
	{
		document.FormContato.edt_Nome.style.backgroundColor = "#eeeeee";
		document.getElementById('DivMensagem').innerHTML = 'Campo <strong>Nome</strong> em branco ...';
		document.FormContato.edt_Nome.focus();
		return;				
	}
	else
	{
		document.FormContato.edt_Nome.style.backgroundColor = "#ffffff";
		document.getElementById('DivMensagem').innerHTML = '';		
	}
	
	if (document.FormContato.edt_Email.value == "")
	{
		document.FormContato.edt_Email.style.backgroundColor = "#eeeeee";
		document.getElementById('DivMensagem').innerHTML = 'Campo <strong>Email</strong> em branco ...';
		document.FormContato.edt_Email.focus();
		return;				
	}
	else
	{
		document.FormContato.edt_Email.style.backgroundColor = "#ffffff";
		document.getElementById('DivMensagem').innerHTML = '';		
	}	
	
	if ((document.FormContato.edt_Email.value == "") || 
		  (document.FormContato.edt_Email.value.length > 0 && 
		  (document.FormContato.edt_Email.value.indexOf("@",0) == - 1 || 
		   document.FormContato.edt_Email.value.indexOf(".",0) == - 1)))
	{
		document.FormContato.edt_Email.style.backgroundColor = "#eeeeee";
		document.getElementById('DivMensagem').innerHTML = '<strong>Email</strong> informado incorreto ...';
		document.FormContato.edt_Email.focus();
		return;				
	}
	else
	{
		document.FormContato.edt_Email.style.backgroundColor = "#ffffff";
		document.getElementById('DivMensagem').innerHTML = '';		
	}
	
	if (document.FormContato.edt_Mensagem.value == "")
	{
		document.FormContato.edt_Mensagem.style.backgroundColor = "#eeeeee";
		document.getElementById('DivMensagem').innerHTML = 'Campo <strong>Mensagem</strong> em branco ...';
		document.FormContato.edt_Mensagem.focus();
		return;				
	}
	else
	{
		document.FormContato.edt_Mensagem.style.backgroundColor = "#ffffff";
		document.getElementById('DivMensagem').innerHTML = '';		
	}
	
	with(document.FormContato)
	{
		document.FormContato.Rotina.value = "EnviarContato";
		method = "post";
		action = "Contato.asp";
		submit();
	}
}

function EnviaBuscaBr() 
{
	if (document.FormBusca.edt_Busca.value == "" || document.FormBusca.edt_Busca.value.length < 3 || document.FormBusca.edt_Busca.value == "Digite mais de 3 letras")
	{
		document.FormBusca.edt_Busca.style.backgroundColor = "#eeeeee";
		document.FormBusca.edt_Busca.value = 'Digite mais de 3 letras';
		return;				
	}
	else
	{
		document.FormBusca.edt_Busca.style.backgroundColor = "#ffffff";
	}
	
	with(document.FormBusca)
	{
		document.FormBusca.Rotina.value = "EnviarBusca";
		method = "post";
		action = "ResultadoBusca.asp";
		submit();
	}
	
}

function EnviaBuscaEn() 
{
	if (document.FormBusca.edt_Busca.value == "" || document.FormBusca.edt_Busca.value.length < 3 || document.FormBusca.edt_Busca.value == "Enter more than 3 letters")
	{
		document.FormBusca.edt_Busca.style.backgroundColor = "#eeeeee";
		document.FormBusca.edt_Busca.value = 'Enter more than 3 letters';
		return;				
	}
	else
	{
		document.FormBusca.edt_Busca.style.backgroundColor = "#ffffff";
	}
	
	with(document.FormBusca)
	{
		document.FormBusca.Rotina.value = "EnviarBusca";
		method = "post";
		action = "ResultadoBusca.asp";
		submit();
	}
	
}

function EnviaBuscaEs() 
{
	if (document.FormBusca.edt_Busca.value == "" || document.FormBusca.edt_Busca.value.length < 3 || document.FormBusca.edt_Busca.value == "Introducir mas de 3 letras")
	{
		document.FormBusca.edt_Busca.style.backgroundColor = "#eeeeee";
		document.FormBusca.edt_Busca.value = 'Introducir mas de 3 letras';
		return;				
	}
	else
	{
		document.FormBusca.edt_Busca.style.backgroundColor = "#ffffff";
	}
	
	with(document.FormBusca)
	{
		document.FormBusca.Rotina.value = "EnviarBusca";
		method = "post";
		action = "ResultadoBusca.asp";
		submit();
	}
	
}

function EnviaRecebaNovidades() 
{	
	if (document.FormLateral.edt_NovidadesNome.value == "")
	{
		document.FormLateral.edt_NovidadesNome.style.backgroundColor = "#d8dcb4";
		document.getElementById('DivMensagemLateral').innerHTML = 'Campo <strong>Nome</strong> em branco ...';
		document.FormLateral.edt_NovidadesNome.focus();
		return;				
	}
	else
	{
		document.FormLateral.edt_NovidadesNome.style.backgroundColor = "#e4e6d0";
		document.getElementById('DivMensagemLateral').innerHTML = '';		
	}
	
	if (document.FormLateral.edt_NovidadesEmail.value == "")
	{
		document.FormLateral.edt_NovidadesEmail.style.backgroundColor = "#d8dcb4";
		document.getElementById('DivMensagemLateral').innerHTML = 'Campo <strong>E-mail</strong> em branco ...';
		document.FormLateral.edt_NovidadesEmail.focus();
		return;				
	}
	else
	{
		document.FormLateral.edt_NovidadesEmail.style.backgroundColor = "#e4e6d0";
		document.getElementById('DivMensagemLateral').innerHTML = '';		
	}	
	
	if ((document.FormLateral.edt_NovidadesEmail.value == "") || 
		  (document.FormLateral.edt_NovidadesEmail.value.length > 0 && 
		  (document.FormLateral.edt_NovidadesEmail.value.indexOf("@",0) == - 1 || 
		   document.FormLateral.edt_NovidadesEmail.value.indexOf(".",0) == - 1)))
	{
		document.FormLateral.edt_NovidadesEmail.style.backgroundColor = "#d8dcb4";
		document.getElementById('DivMensagemLateral').innerHTML = '<strong>E-mail</strong> informado incorreto ...';
		document.FormLateral.edt_NovidadesEmail.focus();
		return;				
	}
	else
	{
		document.FormLateral.edt_NovidadesEmail.style.backgroundColor = "#e4e6d0";
		document.getElementById('DivMensagemLateral').innerHTML = '';		
	}
	
	with(document.FormLateral)
	{
		method = "post";
		action = "RecebaNovidades.asp";
		submit();
	}
}

function Nothing() 
{
}

