// JavaScript Document

function txt_init(tb) {
	tb.initVal = tb.value;
	tb.onfocus = function(){txt_focus(tb);};
	tb.onblur = function(){txt_blur(tb);};
}

function txt_focus(tb) {
	if (tb.value == tb.initVal) {
		tb.value = "";
	}
}

function txt_blur(tb) {
	var newVal = tb.value;
	if (newVal=="" || newVal==tb.initVal) {
		tb.value = tb.initVal;
	}
}

function send_form_login(f){
	var erro="";
	if (f.login.value == "") 			erro += "Digite seu e-mail.\n";
	if (!checkMail(f.login.value)) 		erro += "Digite um e-mail válido.\n";
	if (f.senha.value == "") 			erro += "Digite a senha.\n";
	if (erro!="") { alert("Corrija o(s) erro(s) abaixo :\n\n"+erro); 
	} else {
		Loginbox.prototype.submitLogin('../cadastro/login.php',f.name);
	}
}

	function checkMail(mail) {
		return (mail != "" 
			&& mail.indexOf("@") == mail.lastIndexOf("@")
			&& mail.indexOf("@") > 0
			&& mail.lastIndexOf(".") > mail.indexOf("@")
			&& mail.lastIndexOf(" ") == -1
		);
	}
	
	function e_data(str) { // valida data
		var strArr = str.split("/");
		var ret
		return (strArr.length == 3
			&& !isNaN(strArr[0])
			&& Number(strArr[0]) >= 1
			&& Number(strArr[0]) <= 31
			&& !isNaN(strArr[1])
			&& Number(strArr[1]) >= 1
			&& Number(strArr[1]) <= 12
			&& !isNaN(strArr[2])
			&& Number(strArr[2]) >= 1900
			&& Number(strArr[2]) <= 2020 //mudar em 2020
		);
	}
	
	function preenche_combo_cidades(uf) {
		jQuery('select[name="cidade"]').attr("disabled", "disabled");
		jQuery('select[name="cidade"]').html("<option>(Aguarde, carregando...)</option>");
		jQuery.post('select_cidades.php', { uf : uf }, function(data) {
			jQuery('select[name="cidade"]').html(data);
			jQuery('select[name="cidade"]').removeAttr("disabled");
		} );
	}
