// JavaScript Document

	function Tecla(e){
		var tecla;
		if(window.event) {
			// for IE, e.keyCode or window.event.keyCode can be used
			tecla = e.keyCode; 
		}
		else if(e.which) {
			// netscape or firefox
			tecla = e.which; 
		}
		else {
			// no event, so pass through
			return true;
		}
	
		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;
		if(window.event) {
			// for IE, e.keyCode or window.event.keyCode can be used
			tecla = teclapres.keyCode; //e.keyCode; 
		}
		else if(e.which) {
			// netscape or firefox
			tecla = teclapres.which;//e.which; 
		}

		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.fcn_empresa.value == ''){
			alert('Informe a Empresa!');
			document.formcontato.fcn_empresa.focus();
			return false;
		}
		if(document.formcontato.fcn_nome.value == ''){
			alert('Informe o Nome!');
			document.formcontato.fcn_nome.focus();
			return false;
		}
		if(document.formcontato.fcn_email.value == ''){
			alert('Informe o E-mail!');
			document.formcontato.fcn_email.focus();
			return false;
		}
		else{
			if (!Validar_Email(document.formcontato.fcn_email.value)) {
				document.formcontato.fcn_email.focus();
				alert("Informe um E-mail válido!");
				return false;
			}
		}
		if(document.formcontato.fcn_telefone.value == ''){
			alert('Informe o Telefone!');
			document.formcontato.fcn_telefone.focus();
			return false;
		}
		if(document.formcontato.fcn_cidade.value == ''){
			alert('Informe a Cidade!');
			document.formcontato.fcn_cidade.focus();
			return false;
		}
		if(document.formcontato.fcn_estado.value == ''){
			alert('Informe o Estado!');
			document.formcontato.fcn_estado.focus();
			return false;
		}
		if(document.formcontato.fcn_assunto.value == ''){
			alert('Informe o Assunto!');
			document.formcontato.fcn_assunto.focus();
			return false;
		}	
		if(document.formcontato.fcn_comentario.value == ''){
			alert('Informe a sua Mensagem!');
			document.formcontato.fcn_comentario.focus();
			return false;
		}	
	}
	
function Valida_Restrito(){
		if(document.formrestrito.fres_login.value == ''){
			alert('Informe o seu LOGIN!');
			document.formrestrito.fres_login.focus();
			return false;
		}
		if(document.formrestrito.fres_senha.value == ''){
			alert('Informe a sua SENHA!');
			document.formrestrito.fres_senha.focus();
			return false;
	}
}

	function countChars(num_chars, obj_mostrador, obj_texto, msg) {
		campo=obj_texto.value;
		obj_mostrador.value=campo.length;
		if (campo.length>parseInt(num_chars)) {
			alert(msg+" "+num_chars);
			obj_texto.value=campo.substring(0,parseInt(num_chars));
			obj_mostrador.value=num_chars;
			return false;
		}
		return true;
	}
	
	function verifica_dados() {
	var msg = "";
	var obj_focus = "";
	obj = document.contato.empresa;		    label = "Empresa"; 			if (obj.value == "") { msg = msg + "\n* "+ label +""; obj_focus = obj;}
	obj = document.contato.nome;			label = "Nome"; 			if (obj.value == "") { msg = msg + "\n* "+ label +""; if (obj_focus == "") {obj_focus = obj;}}
	obj = document.contato.cargo;		    label = "Cargo"; 			if (obj.value == "") { msg = msg + "\n* "+ label +""; if (obj_focus == "") {obj_focus = obj;}}
	obj = document.contato.DDDtelefone;	    label = "DDD do telefone"; 	if (obj.value == "") { msg = msg + "\n* "+ label +""; if (obj_focus == "") {obj_focus = obj;}} 
	obj = document.contato.telefone;		label = "Telefone"; 		if (obj.value == "") { msg = msg + "\n* "+ label +""; if (obj_focus == "") {obj_focus = obj;}} 
	obj = document.contato.email; 		    label = "E-mail"; 			if (obj.value == "") { msg = msg + "\n* "+ label +""; if (obj_focus == "") {obj_focus = obj;}}
	
	if (msg != "") {
		alert("Faltou preencher os seguintes campos obrigatórios:\n"+ msg);
		obj_focus.focus();
		return false;
	} else {
		obj = document.contato.email;
		if ( !(valida_email(obj)) ){
			alert("E-mail inválido!");
			obj.focus();
			return false;
		}
		return true;
	}
	return false;

}