// JavaScript Document

function checkEmail() 
{ 
    var flag; 
    var erros;
    var str;
    var pattern;
    
    erros = '';
    str   = DriverForm.email.value;
 
    if (str!='')
    {
    pattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/; 
    flag = pattern.test(str); 
    if(!flag) 
        erros = 'The email is not valid.\n'; 
    }
 
    return erros; 
} 
 
function valid_fields()
{
    var erros  = '';
    var erros1 = '';
 
    var email   = DriverForm.email.value;
    var email2  = DriverForm.email2.value;

    if (DriverForm.nome_condutor.value == '')
        erros+="   Driver's name\n";

    erros1+=checkEmail();
 
    if (DriverForm.email.value == '')
        erros+='   Email\n';

    if (email.toLowerCase() != email2.toLowerCase())
        erros1+='Email and email confirmation do not match.\n';
 
    if (DriverForm.telefone.value == '')
        erros+='   Telephone\n';
 
    if (DriverForm.pais.value == '')
        erros+='   Country\n';
 
    if (erros!='')
        erros = 'The next fields are required:\n' + erros;
 
    if (erros1 !='')
        erros1+='\n';    

    erros = erros1 + erros;
 
    if (erros!='')
       alert (erros);       
    else
       document.DriverForm.submit();
}

function valid_terms()
{
    var erros = ''; 

    if (!LAYOUTFORM.terms.checked)
        erros = 'Please read our terms and conditions before proceeding\n';
 
    if (erros!='')
       alert (erros);       
    else
       document.LAYOUTFORM.submit();
}


function valid_terms_chronopay()
{
    var erros = ''; 

    if (!LAYOUTFORM.terms.checked)
        erros = 'Please read our terms and conditions before proceeding\n';
 
    if (erros!='')
       alert (erros);       
    else
       document.LayoutChronopayForm.submit();
}
