/*
***********************************************************
* cadastro - 21NOVEMBRO2004 Version 1.0
* Desenvolvido por Paulo Augusto - Música da Cidade
***********************************************************
*/

function SubmitFormInclui()
{
	if (document.form.vcf_Nome.value == "") 
	{
		window.alert("Você deve preencher o campo [Nome:]!");
			document.form.vcf_Nome.focus();
			return false;
	}
	if (document.form.vcf_ddd.value == "") 
	{
		window.alert("Você deve preencher o campo [DDD:]!");
			document.form.vcf_ddd.focus();
			return false;
	}
	if (document.form.vcf_Telefone.value == "") 
	{
		window.alert("Você deve preencher o campo [Telefone:]!");
			document.form.vcf_Telefone.focus();
			return false;
	}
	if (document.form.vcf_CPF.value == "") {
		window.alert("Você deve digitar o seu CPF");
		document.form.vcf_CPF.focus();
		return false;
	} else {
		if (!verificaCPF(document.form.vcf_CPF.value)) {
			window.alert("CPF com formato invalido");
			document.form.vcf_CPF.focus();
			return false;
		}
	}
	if (document.form.vcf_email.value == "") {
		window.alert("Você deve digitar o seu [E-mail:]");
		document.form.vcf_email.focus();
		return false;
	} else {
		if (!verificaEmail(document.form.vcf_email.value)) {
			window.alert("[E-mail] com formato invalid!!");
			document.form.vcf_email.focus();
			return false;
		}
	}
	if (document.form.vcf_senha.value == "") 
	{
		window.alert("Você deve preencher o campo [Senha:]!");
			document.form.vcf_senha.focus();
			return false;
	}
	if (document.form.vcf_senha2.value == "") 
	{
		window.alert("Você deve preencher o campo de confirmação da [Senha:]!");
			document.form.vcf_senha2.focus();
			return false;
	}	
	if (document.form.vcf_senha.value != document.form.vcf_senha2.value) 
	{
		window.alert("A Confirmação é diferente da Senha, digite novamente.");
			document.form.vcf_senha.focus();
			return false;
	}
	
	if (confirm("Tem certeza que os dados estão corretos?") == true)
	{
		//document.form.submit();
		return true;
	}
	else return false;
}



function FormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}
	
/************************************************
* function warnInvalid
* Gera um alert para o usuário e volta o foco para
* o campo que está com problema
* Input: theField - campo do formulário com problema
*        warnText - texto a ser mostrado no alert
************************************************/

function warnInvalid (theField, warnText)
{   theField.focus()
    theField.select()
	alert(warnText)
    return false
}

function checkField(s) {
	if ((s.indexOf("&")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0) )
		return false;
	return true;
}

// Verifica se uma string tem vogais acentuadas
function vogalAcentuada(s) {
	ls = s.toLowerCase();
	if ((ls.indexOf("á")>=0) || (ls.indexOf("à")>=0) || (ls.indexOf("ã")>=0) || (ls.indexOf("â")>=0) || (ls.indexOf("é")>=0) || (ls.indexOf("í")>=0) || (ls.indexOf("ó")>=0) || (ls.indexOf("õ")>=0) || (ls.indexOf("ô")>=0) || (ls.indexOf("ú")>=0) || (ls.indexOf("ü")>=0))
		return true;
}

/************************************************
* function verificaEmail
* Verifica se um email é válido
* Input: email a ser verificado
************************************************/

function verificaEmail(email) {
	var s = new String(email);
	// { } ( ) < > [ ] | \ /
	if ((s.indexOf("{")>=0) || (s.indexOf("}")>=0) || (s.indexOf("(")>=0) || (s.indexOf(")")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("[")>=0) || (s.indexOf("]")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0) )
		return false;
	if (vogalAcentuada(email))
		return false;
	// & * $ % ? ! ^ ~ ` ' "
	if ((s.indexOf("&")>=0) || (s.indexOf("*")>=0) || (s.indexOf("$")>=0) || (s.indexOf("%")>=0) || (s.indexOf("?")>=0) || (s.indexOf("!")>=0) || (s.indexOf("^")>=0) || (s.indexOf("~")>=0) || (s.indexOf("`")>=0) || (s.indexOf("'")>=0) )
		return false;
	// , ; : = #
	if ((s.indexOf(",")>=0) || (s.indexOf(";")>=0) || (s.indexOf(":")>=0) || (s.indexOf("=")>=0) || (s.indexOf("#")>=0) )
		return false;
	// procura se existe apenas um @
	if ( (s.indexOf("@") < 0) || (s.indexOf("@") != s.lastIndexOf("@")) )
		return false;
	// verifica se tem pelo menos um ponto após o @
	if (s.lastIndexOf(".") < s.indexOf("@"))
		return false;
	return true;
}

function verificaCEP(cep) {
	s = new String(cep);
	if ((s.length > 9) || (s.length < 5))
		return false;
	if (!isInteger(cep))
		return false;
	return true;
}

/************************************************
* function isInteger
* Verifica se um campo é inteiro, inclui dígitos de 0 a 9, vírgula, ponto, espaços e -
* Input: campo a ser verificado
************************************************/

function isInteger(s){
	var i;
	if (isEmpty(s))
		return false;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!isNumber(c)) return false;
	}
	return true;
}


/************************************************
* function verificaCPF
* Verifica se um CPF é válido
* Input: cpf a ser verificado
************************************************/

function verificaCPF(cpf)
{
	if(cpf == "") {
		return true;
	}
	var dac = "", inicio = 2, fim = 10, soma, digito, i, j
	for (j=1;j<=2;j++) {
		soma = 0
		for (i=inicio;i<=fim;i++) {
			soma += parseInt(cpf.substring(i-j-1,i-j))*(fim+1+j-i)
		}
		if (j == 2) { soma += 2*digito }
		digito = (10*soma) % 11
		if (digito == 10) { digito = 0 }
		dac += digito
		inicio = 3
		fim = 11
	}
	return (dac == cpf.substring(cpf.length-2,cpf.length))
}


