/***************************************************************************************************************************/
/* Funções Globais...                                                                                                      */
/***************************************************************************************************************************/
function PopUp(url, nome, largura, altura, sroll)
{
	var esq     = (screen.width - largura) / 2;
	var top    = (screen.height - altura) / 2;
	var janela = window.open(''+ url +'',''+ nome +'','width=' + largura + ',height=' + altura + ',top=' + top + ',left=' + esq + ',scrollbars='+ sroll +'');
	if (janela == null)
	{
		window.alert('POPUP BLOQUEADA.\n\nIdentificamos que você possui um bloqueador de popup, configure-o\npara aceitar popups de nosso site.\n\nObrigado!');
	}
}

function validaEmail(email)
{
	var exp = /^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$/;
	if (!exp.test(email))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function validarBusca()
{
	if (document.formbusca.palavra.value == '')
	{
		window.alert('Por favor, digite pelo menos uma palavra que você deseja buscar.');
		document.formbusca.palavra.focus();
		return false;
	}
}

function keyNumero(evento, obj) // onkeypress="javascript: return keyNumero(event, this)"
{
	var tecla = (window.Event) ? evento.which : evento.keyCode;
	var str   = obj.value;

	if ((tecla < 48 || tecla > 58) && (tecla != 13))
	{
		return false;
	}

	return true;
}
function isNumber(myfield, e) // onKeyPress="javascript:return isNumber(this, event);"
{
	var key;
	var keychar;

	if (myfield.length == 0)
		myfield.value = 0;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
		return true;
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else
		return false;
}

function mascaraEntrada(campo, mascara, e) // onkeypress="javascript: return mascaraEntrada(this, '##/##/####', event);"
{
	var tecla = (window.Event) ? e.which : e.keyCode;
	var valorCampo = campo.value;
	var seps = ".-,:;/";
	var estaMascara = mascara.substring(valorCampo.length, valorCampo.length + 1);
	var proxMascara = mascara.substring(valorCampo.length + 1, valorCampo.length + 2);
	var ret = false;
	if ( tecla == 8 || tecla == 9 || tecla == 13 || tecla == 0 ) { return true; } // BackSpace, TAB ou ENTER
	if ( tecla > 47 && tecla < 58 && ( estaMascara == "#" || estaMascara == "?" ) == true ) { ret = true; } // Números
	if ( tecla > 96 && tecla < 123 && ( estaMascara == "@" || estaMascara == "?" ) == true ) { ret = true; } // Letras
	if ( tecla > 64 && tecla < 91 && ( estaMascara == "@" || estaMascara == "?" ) == true ) { eet = true; }
	if ( ret == true )
	{
		campo.value = campo.value + String.fromCharCode(tecla);
		if ( seps.indexOf(proxMascara) > -1 )
		{
			campo.value = campo.value + proxMascara;
		}
	}
	return false;
}
function FormataTelefone(obj,tammax,teclapres) {
	var campo = eval("obj");
	var tecla = teclapres.keyCode;
	if ( tecla == 8 || tecla ==13 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) )
		vr = campo.value;
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		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){ return false }
		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) ){
		 		campo.value = '('+ vr.substr( 0, 2 ) + ')' + vr.substr( 2, tam - 2 ) ; }
		}
	else{
		return false;
	}	
}
/***************************************************************************************************************************/
/* Funções da Página: contato.asp                                                                                     */
/***************************************************************************************************************************/
function validarContato()
{
	if (document.formcontato.nome.value == '')
	{
		window.alert('Por favor, digite seu nome.');
		document.formcontato.nome.focus();
		return false;
	}
	if (document.formcontato.social.value == '')
	{
		window.alert('Por favor, digite o nome da sua empresa.');
		document.formcontato.social.focus();
		return false;
	}
	if (document.formcontato.endereco.value == '')
	{
		window.alert('Por favor, digite o seu endereço.');
		document.formcontato.endereco.focus();
		return false;
	}
	if (document.formcontato.cidade.value == '')
	{
		window.alert('Por favor, digite o nome da sua cidade.');
		document.formcontato.cidade.focus();
		return false;
	}
	if (document.formcontato.estado.value == '')
	{
		window.alert('Por favor, selecione o estado.');
		document.formcontato.estado.focus();
		return false;
	}
	if (document.formcontato.telefone.value == '')
	{
		window.alert('Por favor, selecione o estado.');
		document.formcontato.telefone.focus();
		return false;
	}
	if (validaEmail(document.formcontato.email.value) == false)
	{
		window.alert('Por favor, digite seu e-mail corretamente.');
		document.formcontato.email.focus();
		return false;
	}
	 if (document.formcontato.mensagem.value == '')
	{
		window.alert('Por favor, digite a mensagem.');
		document.formcontato.mensagem.focus();
		return false;
	}
}
/***************************************************************************************************************************/
/* Funções validar o login                                                                                    */
/***************************************************************************************************************************/
function ValidarLogin()
{
	if (document.restrito.login.value == '')
	{
		window.alert('Por favor, digite seu login.');
		document.restrito.login.focus();
		return false;
	}
	if (document.restrito.senha.value == '')
	{
		window.alert('Por favor, digite sua senha.');
		document.restrito.senha.focus();
		return false;
	}
}
/***************************************************************************************************************************/
/* Funções validar newsltter                                                                                  */
/***************************************************************************************************************************/
function ValidarNews()
{
	if (document.formulario.nome.value == '')
	{
		window.alert('Por favor, preencha o campo nome.');
		document.formulario.nome.focus();
		return false;
	}
	if (validaEmail(document.formulario.email.value) == false)
	{
		window.alert('Por favor, digite seu e-mail corretamente.');
		document.formulario.email.focus();
		return false;
	}
}