// JavaScript Document
/* Scripts para validação de formularios de CONTATO, PRE-RESERVA, INDICAÇÃO */
	String.prototype.trim = function() {
		return this.replace(/^\s+/, '').replace(/\s+$/, '');
	};

	/*function Tecla(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
				return false;
			else
				return true;
		}
	
	}
*/
	function Formatar_Telefone(objeto,tammax,teclapres)
	{
		var tecla = teclapres.keyCode;
		vr = objeto.value;
		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 <= 4 ) { 
				objeto.value = vr ;
			}
			if ( (tam > 4) && (tam <= 8) ) {
				objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;
			}
			if ( (tam >= 9) && (tam <= 10) ) {
				objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;			
			}
		}		
	}

	function Validar_Email(email)
	{
		if(email.length < 6) {
			return false;
		}
		var x = 0;
		for (var c=0;c<email.length;c++) {
			if (email.substring(c,c+1) == '@') {
				x = c;
			}
		}
		var y = 0;
		if (x > 0) {
			for (c=x;c<email.length;c++) {
				if (email.substring(c,c+1)=='.') {
					y = c;
					var valida = 1;
				}
			}
			if (y > 0) {
				var dominio = '';
				for (c=x;c<y;c++) {
					dominio = dominio + email.substring(1,c);
				}
			}
		}
		else {
			return false;
		}					
		if (y <= x+2){
			return false;
		}				
		if (valida == 1){
			return true;
		}
	}


	

	

	function Valida_Contato(){
		if(document.formcontato.nome.value == ''){
			alert('Informe o Nome!');
			document.formcontato.nome.focus();
			return false;
		}
		if(document.formcontato.email.value == ''){
			alert('Informe o E-mail!');
			document.formcontato.email.focus();
			return false;
		}
		else{
			if (!Validar_Email(document.formcontato.email.value)) {
				document.formcontato.email.focus();
				alert("Informe um E-mail válido!");
				return false;
			}
		}
	
		if(document.formcontato.telefone.value == ''){
			alert('Informe o Telefone!');
			document.formcontato.telefone.focus();
			return false;
		}	
		if(document.formcontato.area.value == ''){
			alert('Informe a Área!');
			document.formcontato.area.focus();
			return false;
		}
		if(!ValidarEnvio()){
			alert('Informe a forma de contato!');
			document.formcontato.receber[0].focus();
			return false;
		}
		if(document.formcontato.mensagem.value == ''){
			alert('Informe a sua Mensagem!');
			document.formcontato.mensagem.focus();
			return false;
		}
	}




		function ValidarEnvio(){			
			var check=-1;
			for (i=0; i<2; i++){
				if (document.formcontato.receber[i].checked){
					check = i;
				}
			}
			return (check==-1)? false: true;
		}


	function Valida_Cadastro(){
		if(document.formcadastro.nome.value == ''){
			alert('Informe o Nome!');
			document.formcadastro.nome.focus();
			return false;
		}
		if(document.formcadastro.email.value == ''){
			alert('Informe o E-mail!');
			document.formcadastro.email.focus();
			return false;
		}
		
	}

			






