// JavaScript Document
//<input name="cep" type="text" id="cep" onkeypress="return formataCampo(event,this,'####-###');" size="10" maxlength="9">
function formataCampo(e,src,mask) {

	var _TXT = (e.which) ? e.which : e.keyCode;
	
    if(_TXT > 47 && _TXT < 58) {
	var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
	if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); }
		return true;
	} else {
		if ((_TXT != 8) && (_TXT != 0)) { return false; }
		else { return true; }
    }
}

function verificaDDD(componente){
	if(componente.value.length == 2){
		document.cadastro.telefone.focus();
	}
}

function mostraDiv(id){
	if (document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display = 'block';
	} else {		
		document.getElementById(id).style.display = 'none';
	}
	return true;
}

function remover_espacos(str){
	r = "";
	for(i = 0; i < str.length; i++){
		if(str.charAt(i) != ' '){
			r += str.charAt(i);
		}
	}
	return r;
}
function ajaxInit() {
	var xmlHttp; 
	try { 
	  // Firefox, Opera 8.0+, Safari 
	  xmlHttp=new XMLHttpRequest(); 
	} 
	catch (e) { 
	  // Internet Explorer 
	  try { 
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	  } 
	  catch (e) { 
		try { 
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (e) { 
		  alert("Your browser does not support ajax!"); 
		  return false; 
		} 
	  } 
	}
	return xmlHttp;
}

function valida_form() {

	var Form;
	Form = document.contato;

	if (Form.email.value.length == 0) {
		alert("O preenchimento do email é obrigatório!");
		Form.email.focus();
		return false;
	}

	if (Form.nome.value.length == 0) {
		alert("O preenchimento do nome é obrigatório!");
		Form.nome.focus();
		return false;
	}
	if (Form.mensagem.value.length == 0) {
		alert("O preenchimento da mensagem é obrigatório!");
		Form.nome.focus();
		return false;
	}

	// define a list of invalid characters
    invalidCharsList = " /:,;~#";

	if ( Form.email.value.indexOf('@',0)==-1 || Form.email.value.indexOf('@',0)== 0 || Form.email.value.indexOf('.',0)==-1) {
		alert("O endereço de e-mail parece ser inválido!");
		Form.email.select();
		Form.email.focus();
		return (false);
	}

	for (i = 0; i < invalidCharsList.length; i++) {
		errorChar = invalidCharsList.charAt(i);
		if (Form.email.value.indexOf(errorChar,0) != -1) {
			Form.email.select();
			Form.email.focus();
			return (false);
		}

	}

	//verifica
	x = verifica(Form.senha.value);
	if (x.length <= 5) {
	alert("É necessário 6 dígitos para continuar!");
        Form.senha.focus();
        return false;
	}

	function verifica(X){
		var Digitos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		var temp = "";
		var digito = "";
		for (var i=0; i<X.length; i++){
			digito = X.charAt(i);
			if (Digitos.indexOf(digito)>=0){temp=temp+digito}
		}
		return temp
	}
	
	return true;

}
