function hasAttribute(element,attribute,val) {
        var has=element.getAttribute(attribute);
        if (has == val)
        {
            return false;
        }
        else {
            return false;
        }
}

function formValidation(id) {
    var oForm = id;
    var doSubmit = true;
    for(var i=0; i<oForm.length; i++){
        var oE = oForm[i]
        if(eval(oE.getAttribute('required'))){
            if(oE.type=="text"||oE.type=="hidden"){
                if(oE.value == ""){ setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
            else if(oE.type=="password"){
                if(oE.value == ""){ setError(oE, 0); doSubmit = false; }
                else { 
                    if (!valid_pass())
                    { setError(oE, 0); doSubmit = false; }
                    else {setError(oE, 1); }
                }
            }
            else if(oE.type=="textarea"){
                if(oE.value == ""){ setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
            else if(oE.type=="checkbox"||oE.type=="radio"){
                var aE = oForm[oE.name];
                var checked = false;
                if(aE.length){
                    for(var j=0; j<aE.length; j++){
                        checked = (checked||aE[j].checked);
                    }
                }
                else { checked = aE.checked; }
                if(!checked) { setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
            else if(oE.type=="select-one"){
                if(oE.selectedIndex==0){ setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
            else if(oE.type=="select-multiple"){
                if(oE.selectedIndex==-1){ setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
        }
        if(eval(oE.getAttribute('emailcheck'))){
            var isOK = true;
            var aEmail = oE.value.split("@");
            if(aEmail.length!=2) { isOK = false; }
            else {
                if(aEmail[0].length<1) { isOK = false; }
                else {
                    aEmail = aEmail[1].split(".");
                    if(aEmail.length<2) { isOK = false; }
                    else{
                        for(var z=0; z<aEmail.length; z++){
                            if(aEmail[z].length<2) { isOK = false; }
                        }
                    }
                }
            }
            
            if(!isOK) { setError(oE, 0); doSubmit = false; }
            else { setError(oE, 1); }
        }
        if(eval(oE.getAttribute('telephonecheck'))) {
            var isOK = true;
            var aTel = oE.value.split(" ");
            if(oE.value == "" || oE.value.length != 14) { isOK = false; }
            else { if (aTel.length>5) { isOK = false; }
                else { 
            for(var k=1; k<aTel.length; k++) {
                var premier = aTel[k].substr(0,1);
                var deux = aTel[k].substr(1,1);
                if (isNaN(premier) == true || isNaN(deux) == true)
                    {isOK = false;}
                }
              }
            }
          if(!isOK) { setError(oE, 0); doSubmit = false; }
            else { setError(oE, 1); }
        }

        if(eval(oE.getAttribute('passecheck'))){
            var isOK = true;
            if(oE.value.length<4 || oE.value.length>9) { isOK = false; }

          if(!isOK) { setError(oE, 0); doSubmit = false; }
            else { setError(oE, 1); }
          }

        if(eval(oE.getAttribute('passwordcheck'))){
            var isOK = true;
            if(oE.value.length<4 || oE.value == "Password") { isOK = false; }
          if(!isOK) { setError(oE, 0); doSubmit = false; }
            else { setError(oE, 1); }
          }
        }
    if (doSubmit) {
        return oForm.submit();
    }
}

function setError(oFld, ok){
    document.getElementById(oFld.getAttribute('txtspan')).className = ok?null:"required";
}

function openMap(url){
     window.open(url,'map','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=500,height=550');
     return false;
}

/*
function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=200,left = 312,top = 184');");
}
*/


function valide_checkbox (id, num) {
    if (document.getElementById(id).checked==true) 
        document.getElementById('niveau').value = num; 
    for(var i=0;i<=6;i++) {
        if (document.getElementById('niveau['+i+']').checked == true)
            var j = 1;
    }
    if (j != 1) 
        document.getElementById('niveau').value='';
}

