/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var formErrors = new Array();

function isValidInt(userInput, errorMsg, isReq){
    var mask=/^\d+$/;
    if (isReq == false && userInput.value == "") return true;
    if (mask.test(userInput.value)) return true;
    formErrors[formErrors.length] = errorMsg;
    return false;
}

function isValidChar(userInput, errorMsg, isReq){
    var mask=/^[\w\-]+$/;
    if (isReq == false && userInput.value == "") return true;
    if (mask.test(userInput.value)) return true;
    formErrors[formErrors.length] = errorMsg;
    return false;
}

function isValidEmail(userInput, errorMsg, isReq){
    var mask=/^\w[\w\-\.]+\@\w[\w\-]+(\.[\w\-]+)+$/;
    if (isReq == false && userInput.value == "") return true;
    if (mask.test(userInput.value)) return true;
    formErrors[formErrors.length] = errorMsg;
    return false;
}

function isValidAny(userInput, errorMsg, isReq){
    if (isReq == true && userInput.value == "") {
        formErrors[formErrors.length] = errorMsg;
        return false;
    }
    return true;
}


function valid_apoiante(){
    var bool = true;
    isValidAny(document.getElementById('nome'), 'nome_err', true);
    isValidAny(document.getElementById('apelido'), 'apelido_err', true);
    isValidAny(document.getElementById('ocupacao'), 'ocupacao_err', true);
    isValidAny(document.getElementById('telemovel'), 'telemovel_err', true);
    isValidAny(document.getElementById('anti_spam'), 'anti_spam_err', true);
    isValidEmail(document.getElementById('email'), 'email_err', true);
    if (formErrors.length > 0){
        for (var i=0; i<formErrors.length; i++){
            document.getElementById(formErrors[i]).style.color="red";
        }
        bool =  false;
    }
    return bool;
}
function valid_voluntario(){
    var bool = true;
    isValidAny(document.getElementById('nome'), 'nome_err', true);
    isValidAny(document.getElementById('idade'), 'idade_err', true);
    isValidAny(document.getElementById('telemovel'), 'telemovel_err', true);
    isValidEmail(document.getElementById('email'), 'email_err', true);
    isValidAny(document.getElementById('disponibilidade'), 'disponibilidade_err', true);
    isValidAny(document.getElementById('anti_spam'), 'anti_spam_err', true);
    if (formErrors.length > 0){
        for (var i=0; i<formErrors.length; i++){
            document.getElementById(formErrors[i]).style.color="red";
        }
        bool =  false;
    }
    return bool;
}
function valid_contactar(){
    var bool = true;
    isValidAny(document.getElementById('nome'), 'nome_err', true);
    isValidEmail(document.getElementById('email'), 'email_err', true);
    isValidAny(document.getElementById('mensagem'), 'mensagem_err', true);
    isValidAny(document.getElementById('anti_spam'), 'anti_spam_err', true);
    if (formErrors.length > 0){
        for (var i=0; i<formErrors.length; i++){
            document.getElementById(formErrors[i]).style.color="red";
        }
        bool =  false;
    }
    return bool;
}
function valid_recomendar(){
    var bool = true;
    isValidAny(document.getElementById('nome'), 'nome_err', true);
    isValidEmail(document.getElementById('email'), 'email_err', true);
    isValidAny(document.getElementById('nome_amigo'), 'nome_amigo_err', true);
    isValidEmail(document.getElementById('email_amigo'), 'email_amigo_err', true);
    isValidAny(document.getElementById('mensagem'), 'mensagem_err', true);
    isValidAny(document.getElementById('anti_spam'), 'anti_spam_err', true);
    if (formErrors.length > 0){
        for (var i=0; i<formErrors.length; i++){
            document.getElementById(formErrors[i]).style.color="red";
        }
        bool =  false;
    }
    return bool;
}
function valid_news(){
    var bool = true;
    isValidEmail(document.getElementById('news'), 'news_err', true);
    if (formErrors.length > 0){
        for (var i=0; i<formErrors.length; i++){
            document.getElementById(formErrors[i]).style.color="red";
        }
        bool =  false;
    }
    return bool;
}
function clearErr(id){
    var toClean = id+"_err";
    document.getElementById(toClean).style.color = "black";
    if (formErrors.length > 0){
        for (var i=0; i<formErrors.length; i++){
            if (formErrors[i] == toClean) {
                formErrors.splice(i, 1);
            }
        }
    }
}
function submitform(form)
{
  document.form_news.submit();
}