// Preload images
var empty = new Image(); empty.src = "error.gif";

var haveerrors = 0;
var errToFocus = null;

function isPostCode(entry){ // checks Canadian codes only
strlen=entry.length; if (strlen!==7){return false;}
entry=entry.toUpperCase();  // in case of lowercase
// Check for legal characters in string - note index starts at zero
if('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0) {return false;}
if('0123456789'.indexOf(entry.charAt(1))<0) {return false;}
if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0) {return false;}
if(entry.charAt(3)!=' ') {return false;}
if('0123456789'.indexOf(entry.charAt(4))<0) {return false;}
if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(5))<0) {return false;}
if('0123456789'.indexOf(entry.charAt(6))<0) {return false;}
return true;}

function validStr(aStr) {
    var i;
    for (i=0; i<aStr.length; i++) {
        if (aStr[i] != ' ') {
            return true;
        }
    }
    return false;
}

function showError(myObj, errors) {
  if (errors && (errToFocus == null)){
    errToFocus = myObj;
  }
  if (errors){
    myObj.className = 'error';
    document.getElementById('zoneErreur').style.visibility='visible';
    document.getElementById('zoneErreur').style.height='auto';
  //  document.getElementById('zoneErreur2').style.visibility='visible';
 //   document.getElementById('zoneErreur2').style.height='auto';

  }else{
    myObj.className = 'fdtxt'
  }
  if (!haveerrors && errors) haveerrors = errors;
}


function validateForm_maire(f) {
haveerrors = 0;
errToFocus = null;


(f.nom.value.length < 1)
? showError(f.nom, true)
: showError(f.nom, false);

(f.message.value.length < 1)
? showError(f.message, true)
: showError(f.message, false);

(!validStr(f.courriel.value) || (f.courriel.value.search("@") == -1) || (f.courriel.value.search("[.*]") == -1))
? showError(f.courriel, true)
: showError(f.courriel, false);


if (errToFocus != null) errToFocus.focus();

return (!haveerrors);
}



function validateForm_service(s) {
haveerrors = 0;
errToFocus = null;


(s.nom.value.length < 1)
? showError(s.nom, true)
: showError(s.nom, false);

(s.prenom.value.length < 1)
? showError(s.prenom, true)
: showError(s.prenom, false);

(s.adresse.value.length < 1)
? showError(s.adresse, true)
: showError(s.adresse, false);

(s.telephone.value.length < 1)
? showError(s.telephone, true)
: showError(s.telephone, false);

(s.message.value.length < 1)
? showError(s.message, true)
: showError(s.message, false);

(!s.service.selectedIndex)
?  showError(s.service, true)
: showError(s.service, false);
//service

if (errToFocus != null) errToFocus.focus();

return (!haveerrors);
}





function validateForm_photo(f) {
haveerrors = 0;
errToFocus = null;


(f.nom.value.length < 1)
? showError(f.nom, true)
: showError(f.nom, false);

(f.prenom.value.length < 1)
? showError(f.prenom, true)
: showError(f.prenom, false);

(f.ville.value.length < 1)
? showError(f.ville, true)
: showError(f.ville, false);

(f.telephone.value.length < 1)
? showError(f.telephone, true)
: showError(f.telephone, false);

(!validStr(f.courriel.value) || (f.courriel.value.search("@") == -1) || (f.courriel.value.search("[.*]") == -1))
? showError(f.courriel, true)
: showError(f.courriel, false);

(f.file.value.length < 1)
? showError(f.file, true)
: showError(f.file, false);


if (errToFocus != null) errToFocus.focus();

return (!haveerrors);
}


