// JavaScript Document
var whitespace = " \t\n\r";

function isEmpty(s)
{
return ((s == null) || (s.length == 0));
}
function isWhitespace(s)
{ var i;
if (isEmpty(s)) return true;
for (i = 0; i < s.length; i++){
var c = s.charAt(i);
if (whitespace.indexOf(c) == -1) return false;
}
return true;
}
function isEmail(s)
{ if (isEmpty(s))
return false;
if (isWhitespace(s)) return false;
var i = 1;
var sLength = s.length;
while ((i < sLength) && (s.charAt(i) != "@")){
i++;
}
if ((i >= sLength) || (s.charAt(i) != "@")) return false;
else i += 2;
while ((i < sLength) && (s.charAt(i) != ".")){
i++;
}
if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
else return true;
}
function ValidaCep(cep){
    if (isEmpty(cep)) return false;
    else {
    if (cep.length == 8) {
	exp = /[1-9]\d{7}/
	if(!exp.test(cep)) 
	return false;
	else return true;
    } else return false;
    } // 1º else
} // function

function ValidaTelefone(tel){
    if (isEmpty(tel)) return false;
    else {
    if ((tel.length == 7) || (tel.length == 8)) {
	exp = /[2-9]\d{6,7}/
	if(!exp.test(tel)) 
	return false;
	else return true;
    } else return false;
    } // 1º else
} // function


function ValidaDDD(ddd){
    if (isEmpty(ddd)) return false;
    else {
    exp = /[1-9]{2}/
    if(!exp.test(ddd))
	return false;
else return true;
    }
}


function Confirma(){
var str = "";
//nome
if (isWhitespace(document.formmail.nome.value))
str = str + " - preencha o campo 'Nome'\n";
//email
if (!isEmail(document.formmail.email.value))
str = str + " - preencha o campo 'E-mail' corretamente\n";
//Cidade
if (isWhitespace(document.formmail.cidade.value))
str = str + " - preencha o campo 'Cidade'\n";
//cep
if (!ValidaCep(document.formmail.cep.value))
str = str + " - preencha o campo 'cep' corretamente\n";
//telefone
if (!ValidaDDD(document.formmail.ddd.value) || !ValidaTelefone(document.formmail.tel.value))
str = str + " - preencha o campo 'Telefone' corretamente\n";
//celular
if (!ValidaDDD(document.formmail.ddd2.value) || !ValidaTelefone(document.formmail.tel2.value))
str = str + " - preencha o campo 'Celular' corretamente\n";
//Endereco
if (isEmpty(document.formmail.endereco.value))
str = str + " - preencha o campo 'Endereco' corretamente\n";
if (isEmpty(document.formmail.num.value))
str = str + " - preencha o campo 'Numero' corretamente\n";

if (str == "") {
return true;
} else {
alert("Por favor, procure corrigir o(s) seguinte(s) erro(s):\n" + str + "e tente enviar este formulario novamente.");
return false;
}
}
function enviar()
{
if (Confirma()){
document.formmail.action = "cadastro.php";
document.formmail.submit();
}
}

function Confirma2(){
	var str = "";
	//modalidade
	if (isWhitespace(document.formmail.mode.value))
		str = str + " - preencha o campo 'Modalidade de Inscricao'\n";

	if ( (!document.getElementById("1").checked) && (!document.getElementById("2").checked) && 
			(!document.getElementById("3").checked) && (!document.getElementById("4").checked) &&
			(!document.getElementById("5").checked) && (!document.getElementById("6").checked) &&
			(!document.getElementById("7").checked) && (!document.getElementById("8").checked) &&
			(!document.getElementById("9").checked) && (!document.getElementById("10").checked) )
		str = str + " - preencha o campo 'Escolha o(s) curso(s)'\n";

	if (str == "") {
		return true;
	}
	else {
		alert("Por favor, procure corrigir o(s) seguinte(s) erro(s):\n" + str + "e tente enviar este formulario novamente.");
		return false;
	}
}
function enviar2(){
	if (Confirma2()){
		document.formmail.action = "cadastro.php";
		document.formmail.submit();
	}
}

