// JavaScript Document

function valida_email(strEmail) 
{
	prim = strEmail.value.indexOf("@")
	
	if(strEmail.value != "")
	{
		if(prim < 2) {
			return false;
		}
		else if(strEmail.value.indexOf("@",prim + 1) != -1) {
			return false;
		}
		else if(strEmail.value.indexOf(".") < 1) {
			return false;
		}
		else if(strEmail.value.indexOf(" ") != -1) {
			return false;
		}
		else if(strEmail.value.indexOf(".@") > 0) {
			return false;
		}
		else if(strEmail.value.indexOf("@.") > 0) {
			return false;
		}
		else if(strEmail.value.indexOf(".com.br.") > 0) {
			return false;
		}
		else if(strEmail.value.indexOf("/") > 0) {
			return false;
		}
		else if(strEmail.value.indexOf("[") > 0) {
			return false;
		}
		else if(strEmail.value.indexOf("]") > 0) {
			return false;
		}
		else if(strEmail.value.indexOf("(") > 0) {
			return false;
		}
		else if(strEmail.value.indexOf(")") > 0) {
			return false;
		}
		else if(strEmail.value.indexOf("..") > 0) {
			return false;
		}
	}
	
	return true;
}
function changeClass(id, newClass) {
	target = document.getElementById(id);
	target.className = newClass;
}

// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec) {
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	
	keychar = String.fromCharCode(key);
	
// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) {
		return true;
	}
// numbers
	else if ((("0123456789").indexOf(keychar) > -1)) {
		return true;
	}

// decimal point jump
	else if (dec && (keychar == ".")) {
		myfield.form.elements[dec].focus();
		return false;
   	} else {
		return false;
	}
}


 //Verifica qual o browser do visitante e armazena na variável púbica clientNavigator,
 //Caso Internet Explorer(IE) outros (Other)
 if (navigator.appName.indexOf('Microsoft') != -1){
 	clientNavigator = "IE";
 }else{
 	clientNavigator = "Other";
 }

 function Ajusta_Data(input, evt)
 {
	 
	if (numbersonly(input.name,evt)) {
	
		//Ajusta máscara de Data e só permite digitação de números
		if (input.value.length == 2 || input.value.length == 5)
		{
			if(clientNavigator == "IE")
			{
				input.value += "/";
			}
			else
			{
				if(evt.keyCode == 0)
				{
					input.value += "/";
				}
			}
		}
		return true;
	} else return false;
}

function Verifica_Data(data, obrigatorio)
{
	//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não
	var data = document.getElementById(data);
 	var strdata = data.value;
 	if((obrigatorio == 1) || (obrigatorio == 0 && strdata != "")){
 		//Verifica a quantidade de digitos informada esta correta.
 		if (strdata.length != 10){
 			alert("Formato da data não é válido. Formato correto: - dd/mm/aaaa.");
 			data.focus();
 			return false
 		}
 		//Verifica máscara da data
 		if ("/" != strdata.substr(2,1) || "/" != strdata.substr(5,1)){
 			alert("Formato da data não é válido. Formato correto: - dd/mm/aaaa.");
 			data.focus();
 			return false
 		}
 		dia = strdata.substr(0,2)
 		mes = strdata.substr(3,2);
 		ano = strdata.substr(6,4);
 		//Verifica o dia
 		if (isNaN(dia) || dia > 31 || dia < 1){
 			alert("Formato do dia não é válido.");
 			data.focus();
 			return false
 		}
 		if (mes == 4 || mes == 6 || mes == 9 || mes == 11){
 			if (dia == "31"){
 				alert("O mês informado não possui 31 dias.");
 				data.focus();
 				return false
 			}
 		}
 		if (mes == "02"){
 			bissexto = ano % 4;
 			if (bissexto == 0){
 				if (dia > 29){
 					alert("O mês informado possui somente 29 dias.");
 					data.focus();
 					return false
 				}
 			}else{
 				if (dia > 28){
 					alert("O mês informado possui somente 28 dias.");
 					data.focus();
 					return false
 				}
 			}
 		}
 	//Verifica o mês
 		if (isNaN(mes) || mes > 12 || mes < 1){
 			alert("Formato do mês não é válido.");
 			data.focus();
 			return false
 		}
 		//Verifica o ano
 		if (isNaN(ano)){
 			alert("Formato do ano não é válido.");
 			data.focus();
 			return false
 		}
 	}
 }