// 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 true;
    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 true;
    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 true;
    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";
//Assunto
if (isWhitespace(document.formmail.assunto.value))
str = str + " - preencha o campo 'Assunto'\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 = "send_mail.php";
document.formmail.submit();
}
}

