// 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_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.typep[0].checked) && (!f.typep[1].checked))
? showError(f.typep, true)
: showError(f.typep, false);

((f.typep[0].checked) && (f.file.value.length < 1))
? showError(f.file, true)
: showError(f.file, false);

((f.typep[1].checked) && (f.lien_embeded.value.length < 1))
? showError(f.lien_embeded, true)
: showError(f.lien_embeded, false);

((f.typep[1].checked) && (f.title_vid.value.length < 1))
? showError(f.title_vid, true)
: showError(f.title_vid, false);



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

return (!haveerrors);
}


function visibilite2(thingId, bVal)
{
var targetElement;
targetElement = document.getElementById(thingId) ;
if (bVal){
  targetElement.style.display = "" ;
} else {
  targetElement.style.display = "none" ;
}
}


function validateForm_bulletin(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);

(!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);
}
