window.onload =initAll;
function initAll(){
document.getElementById('nombre').onblur=nombreValidate;
document.getElementById('apellido').onblur=apellidoValidate;
document.getElementById('empresa').onblur=empresaValidate;
document.getElementById('nif').onblur=nifValidate;
document.getElementById('direccion').onblur=direccionValidate;
document.getElementById('cp').onblur=cpValidate;
document.getElementById('localidad').onblur=localidadValidate;
document.getElementById('provincia').onblur=provinciaValidate;
document.getElementById('comunidad').onblur=comunidadValidate;
document.getElementById('telefonofijo').onblur=telefonofijoValidate;
document.getElementById('telefonomovil').onblur=telefonomovilValidate;
document.getElementById('correoelectronico').onblur=correoelectronicoValidate;
document.getElementById('profesion').onblur=profesionValidate;
document.getElementById('aportematerial').onblur=aportematerialValidate;
document.getElementById('aportepuntual').onblur=aportepuntualValidate;
document.getElementById('aporteregular').onblur=aporteregularValidate;
document.getElementById('formaregular').onblur=formaregularValidate;
document.getElementById('formaotra').onblur=formaotraValidate;
document.getElementById('cuentabancaria_01').onblur=cuentabancariaValidate_01;
document.getElementById('cuentabancaria_02').onblur=cuentabancariaValidate_02;
document.getElementById('cuentabancaria_03').onblur=cuentabancariaValidate_03;
document.getElementById('cuentabancaria_04').onblur=cuentabancariaValidate_04;
document.getElementById('entidadbancaria').onblur=entidadbancariaValidate;

document.getElementById('aporteregular').onclick=showAporteRegular;
document.getElementById('formaregular').onchange=showFormaOtra;
showAporteRegular();
showFormaOtra();

document.getElementById('sendInfo').onclick=validateAll;
}

function nombreValidate(){validate(/[A-Za-z0-9]{1,64}/,'nombre','Indique un Nombre');return validationValue;}
function apellidoValidate(){validate(/[A-Za-z0-9]{1,64}/,'apellido','Indique un Apellido');return validationValue;}
function empresaValidate(){validate(/[A-Za-z0-9]{0,64}/,'empresa','Indique el nombre de Empresa');}
function nifValidate(){validate(/^[A-Z0-9]{1,9}$/,'nif','Indique un Número de Identificación Fiscal');}
function direccionValidate(){validate(/[A-Za-z0-9]{1,64}/,'direccion','Indique una dirección válida');}
function cpValidate(){validate(/^[0-9]{1,5}$/,'cp','Indique un CP válido');}
function localidadValidate(){validate(/[A-Za-z0-9]{1,64}/,'localidad','Indique su Localidad');}
function provinciaValidate(){validate(/[A-Za-z0-9]{1,64}/,'provincia','Seleccione su Provincia');}
function comunidadValidate(){validate(/[A-Za-z0-9]{1,64}/,'comunidad','Indique su comunidad');}
function telefonofijoValidate(){validate(/^[0-9]{0,9}$/,'telefonofijo','Escriba todos los números sin espacios');}
function telefonomovilValidate(){validate(/^[0-9]{0,12}$/,'telefonomovil','Escriba todos los números sin espacios');}
function correoelectronicoValidate(){validate(/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/,'correoelectronico','Inidique una dirección de correo válida');}
function profesionValidate(){validate(/[A-Za-z0-9]{0,64}/,'profesion','Indique su profesion');}
function aportematerialValidate(){validate(/^[01]{0,1}$/,'aportematerial','');}
function aportepuntualValidate(){validate(/^[01]{0,1}$/,'aportepuntual','');}
function aporteregularValidate(){validate(/^[01]{0,1}$/,'aporteregular','');}
function formaregularValidate(){validate(/[A-Za-z0-9]{0,9}/,'formaregular','');}
function formaotraValidate(){validate(/^[0-9]{0,9}$/,'formaotra','Introduzca una cifra a donar'); }
function cuentabancariaValidate_01(){validate(/^([0-9]{4}){0,4}$/,'cuentabancaria_01','');}
function cuentabancariaValidate_02(){validate(/^([0-9]{4}){0,4}$/,'cuentabancaria_02','');}
function cuentabancariaValidate_03(){validate(/^([0-9]{2}){0,2}$/,'cuentabancaria_03','');}
function cuentabancariaValidate_04(){validate(/^([0-9]{10}){0,10}$/,'cuentabancaria_04','');}
function entidadbancariaValidate(){validate(/[A-Za-z0-9]{0,9}/,'entidadbancaria','');}

function showAporteRegular(){
    itemValue=document.getElementById('aporteregular').checked;
    if(itemValue==true){
        document.getElementById('aporteregulardata').className='showObject';
    }else if(itemValue==false){
        document.getElementById('aporteregulardata').className='hiddenObject';
    }
}

function showFormaOtra(){
    itemValue=document.getElementById('formaregular').value;
    if(itemValue=='otratrimestral' || itemValue=='otraanual'){
        document.getElementById('formaotraspan').className='showObject';
    }else {
        document.getElementById('formaotraspan').className='hiddenObject';
    }
}

function validateAll(){
    var validationAll=new Array();
    validationAll[0]=nombreValidate();
    validationAll[1]=apellidoValidate();
    validationAll[2]=empresaValidate();
    validationAll[3]=nifValidate();
    validationAll[4]=direccionValidate();
    validationAll[5]=cpValidate();
    validationAll[6]=localidadValidate();
    validationAll[7]=provinciaValidate();
    validationAll[8]=comunidadValidate();
    validationAll[9]=telefonofijoValidate();
    validationAll[10]=telefonomovilValidate();
    validationAll[11]=correoelectronicoValidate();
    validationAll[12]=profesionValidate();
    validationAll[13]=aportematerialValidate();
    validationAll[14]=aportepuntualValidate();
    validationAll[15]=aporteregularValidate();
    validationAll[16]=formaregularValidate();
    validationAll[17]=cuentaBancariaValidate_01();
    validationAll[18]=cuentaBancariaValidate_02();
    validationAll[19]=cuentaBancariaValidate_03();
    validationAll[20]=cuentaBancariaValidate_04();
    validationAll[21]=entidadbancariaValidate();

    if(validationAll[0]=='false' || validationAll[1]=='false' || validationAll[2]=='false' || validationAll[3]=='false' || validationAll[4]=='false' || validationAll[5]=='false' || validationAll[6]=='false' || validationAll[7]=='false' || validationAll[8]=='false' || validationAll[9]=='false' || validationAll[10]=='false' || validationAll[11]=='false' || validationAll[12]=='false' || validationAll[13]=='false' || validationAll[14]=='false' || validationAll[15]=='false' || validationAll[16]=='false' || validationAll[17]=='false' || validationAll[18]=='false' || validationAll[19]=='false' || validationAll[20]=='false' || validationAll[21]=='false'){
        return false;
    }else{
        return true;
    }
}


function validate(regexValue,itemName,alertMsg){
    itemValue=document.getElementById(itemName).value;
    alertItem='error_'+itemName;
    alertObject=document.getElementById(alertItem);
    validationValue='false';
    if(!itemValue.match(regexValue)){
        validationValue='false';
        alertObject.className='error_alert';
        alertObject.innerHTML=alertMsg;
    }else{
        validationValue='true';
        alertObject.className='hit_alert';
        alertObject.innerHTML='';
    }
    return validationValue;
}


