function isEmail(email) {
	var re = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/;
	
	if (!re.test(email))
		return false;
		
	return true;
}

function isTelephone(telNum){
	var re = /^[2-9]\d{2}-\d{3}-\d{4}$/;
	//Matching Text		800-555-5555|||333-444-5555|||212-666-1234
	//Non-Matching Text	000-000-0000|||123-456-7890|||2126661234
	if (!re.test(telNum))
		return false;
		
	return true;
}

function estDecimal(nbDec){
	var re = /^[0-9]+(\.[0-9][0-9])?$/;
	//Matching Text		1.50|||49|||0.50
	//Non-Matching Text	1.5|||$1.333|||this $5.12
	
	if (!re.test(nbDec))
		return false;
		
	return true;
}

function estUneDate(une_date){
	//Match une date sous le format jj-mm-aaaa
    var re = /(((0[1-9]|[12][0-9]|3[01])([-])(0[13578]|10|12)([-])(\d{4}))|(([0][1-9]|[12][0-9]|30)([-])(0[469]|11)([-])(\d{4}))|((0[1-9]|1[0-9]|2[0-8])([-])(02)([-])(\d{4}))|((29)([-])(02)([-])([02468][048]00))|((29)([-])(02)([-])([13579][26]00))|((29)([-])(02)([-])([0-9][0-9][0][48]))|((29)([-])(02)([-])([0-9][0-9][2468][048]))|((29)([-])(02)([-])([0-9][0-9][13579][26])))/
    if (!re.test(une_date))
		return false;
		
	return true;
}

function isCodePostal(codePostal){
	var re = /^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$/;
	//Matches:  	M1R 4B0|||L0R 1B1|||L0R1B9
	//Non-Matches: 	W1R 4B0|||L0R 1D1|||LOR1B9
	if (!re.test(codePostal.toUpperCase()))
		return false;
		
	return true;
}

function ouvrirFenetre(unFichier, uneLargeur, uneHauteur, scroll){
	var top = (screen.height - uneHauteur) / 2;
	if(top < 0){
		top = 0;
	}		
	
	var left = (screen.width - uneLargeur) / 2;
	if(left < 0){
		left = 0;
	}		
	
	var pos = "top=" + top + ", left=" + left + ", width=" + uneLargeur + ", height=" + uneHauteur;
	
	var w = null;
	if(scroll){
		w = window.open(unFichier,"pop1","width=" + uneLargeur + ",height=" + uneHauteur + ",directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no," + pos);
		w.document.close();
		w.focus();
	}
	else{
		w = window.open(unFichier,"pop1","width=" + uneLargeur + ",height=" + uneHauteur + ",directories=no,location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no," + pos);
		w.document.close();
		w.focus();
	}
}

function ouvrirFenetreDetail(unFichier, uneLargeur, uneHauteur, scroll){
	var top = (screen.height - uneHauteur) / 2;
	if(top < 0){
		top = 0;
	}		
	
	var left = (screen.width - uneLargeur) / 2;
	if(left < 0){
		left = 0;
	}		
	
	var pos = "top=" + top + ", left=" + left + ", width=" + uneLargeur + ", height=" + uneHauteur;
	
	var w = null;
	if(scroll){
		w = window.open(unFichier,"pop1","width=" + uneLargeur + ",height=" + uneHauteur + ",directories=no,location=yes,menubar=yes,resizable=no,scrollbars=yes,toolbar=no," + pos);
		w.focus();
	}
	else{
		w = window.open(unFichier,"pop1","width=" + uneLargeur + ",height=" + uneHauteur + ",directories=no,location=yes,menubar=yes,resizable=no,scrollbars=no,toolbar=no," + pos);
		w.focus();
	}
}

function setErrStyle(unID){
	var idObj = new String();
	idObj = unID;
	document.getElementById(idObj).style.backgroundColor = "#FF7F7F";
}

function ajusterFont(){
	var fontSize = lireCookie("font_size_param");
	if(fontSize != null){
		setFontSize(fontSize);
	}
}
function setFontSize(param){
	switch(param){
		case '1':
			document.getElementById("div_data").style.fontSize = ".9em";
			ecrireCookie("font_size_param", "1");
			document.getElementById("img_txt_size_1").src = "images/txt_1_over.gif";
			document.getElementById("img_txt_size_2").src = "images/txt_2.gif";
			document.getElementById("img_txt_size_3").src = "images/txt_3.gif";
			break;
		case '2':
			document.getElementById("div_data").style.fontSize = "1.1em";
			ecrireCookie("font_size_param", "2");
			document.getElementById("img_txt_size_1").src = "images/txt_1.gif";
			document.getElementById("img_txt_size_2").src = "images/txt_2_over.gif";
			document.getElementById("img_txt_size_3").src = "images/txt_3.gif";
			break;
		case '3':
			document.getElementById("div_data").style.fontSize = "1.3em";
			ecrireCookie("font_size_param", "3");
			document.getElementById("img_txt_size_1").src = "images/txt_1.gif";
			document.getElementById("img_txt_size_2").src = "images/txt_2.gif";
			document.getElementById("img_txt_size_3").src = "images/txt_3_over.gif";
			break;
	}
	
}

function affichageCatEtSousCat(valeur){
	var i;
	var date = new Date;
	date.setMonth(date.getMonth()+1);

	ecrireCookie("aff_cat_param", valeur, date);
	switch(valeur){
		case '1':
			document.getElementById("tbl_affichage_cat").className = "affichageSimple";
			document.getElementById("lien_top").style.display = "none";
			break;
		case '2':
			document.getElementById("tbl_affichage_cat").className = "";
			document.getElementById("lien_top").style.display = "block";
			break;
	}
	for(i=0;i<=document.Form1.ddl_choix_affichage.length-1;i++){
		if(document.Form1.ddl_choix_affichage[i].value==valeur)
			document.Form1.ddl_choix_affichage[i].selected = true;
	}
}

function alertMessage(msgFR,msgEN){
	switch(document.Form1.param_h_lang.value){
		case "fr":
			alert(msgFR);
			break;
		case "en":
			alert(msgEN);
			break;
	}
}

function setTxt(fr,en){
	switch(document.Form1.param_h_lang.value){
		case "fr":
			return fr;
			break;
		case "en":
			return en;
			break;
		default: return fr;
	}
}

function ecrireCookie(nom, valeur){
	var argv=ecrireCookie.arguments;
	var argc=ecrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function getCookieVal(offset){
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
/*
La fonction LireCookie, retourne la valeur du cookie demandé, 
en utilisant la fonction getCookieVal. Si ce cookie n'existe pas, 
la fonction LireCookie retourne la valeur null.
*/
function lireCookie(nom){
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
	var j=i+alen;
	if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
	i=document.cookie.indexOf(" ",i)+1;
	if (i==0) break;

	}
	return null;
}

function check_login(){
	document.Form1.h_check_login.value = "1";
	document.Form1.submit();
}

function logout(){
	document.Form1.h_logout.value = "1";
	document.Form1.h_lancerRecherche.value = "";
	document.Form1.submit();
}

function recherche(){
	if(document.Form1.moteur_recherche_ddl_province.value==-1 || document.Form1.moteur_recherche_ddl_ville.value==-1){
		alertMessage("Vous devez s\351lectionner une ville et une province.","Please select a city and province.");
	}else{
		document.Form1.h_lancerRecherche.value = "1";
		document.Form1.param_h_categorie.value = "-1";
		document.Form1.param_h_souscategorie.value = "-1";
		document.Form1.param_h_top.value = "-1";
		document.Form1.submit();
	}
}
function rechercheParCat(catID,sousCatID){
	if(document.Form1.moteur_recherche_ddl_province.value!=-1 && document.Form1.moteur_recherche_ddl_ville.value!=-1){
		document.Form1.param_h_categorie.value = catID;
		document.Form1.param_h_souscategorie.value = sousCatID;
		document.Form1.h_lancerRecherche.value = "1";
		document.Form1.param_h_top.value = "-1";
		document.Form1.submit();
	}else{
		alertMessage("Vous devez s\351lectionner une ville et une province.","Please select a city and province.");
	}
}
function rechercheRecentes(){
	if(document.Form1.moteur_recherche_ddl_province.value!=-1 && document.Form1.moteur_recherche_ddl_ville.value!=-1){
		document.Form1.param_h_top.value = "30";
		document.Form1.param_h_categorie.value = "-1";
		document.Form1.param_h_souscategorie.value = "-1";
		document.Form1.h_lancerRecherche.value = "1";
		document.Form1.submit();
	}else{
		alertMessage("Vous devez s\351lectionner une ville et une province.","Please select a city and province.");
	}
}

function rechercheCartes(catID,sousCatID){
	if(document.Form1.moteur_recherche_ddl_province.value!=-1 && document.Form1.moteur_recherche_ddl_ville.value!=-1){
		document.Form1.param_h_categorie.value = catID;
		document.Form1.param_h_souscategorie.value = sousCatID;
		//document.Form1.h_lancerRecherche.value = "1";
		//document.Form1.submit();
		document.location = 'cartes_affaires.aspx?cID='+catID;
	}else{
		alertMessage("Vous devez s\351lectionner une ville et une province.","Please select a city and province.");
	}
}

/* Validation du formulaire de contact du fichier contact.aspx */
function validerContactForm(){
	if(document.Form1.tb_nom.value==""){
		alertMessage("Vous devez inscrire votre nom.","Please insert your name.");
		document.Form1.tb_nom.focus();
		return false;
	}
	if(!isEmail(document.Form1.tb_courriel.value)){
		alertMessage("Vous devez inscrire un adresse de courriel valide.","ANGLAIS");
		document.Form1.tb_courriel.focus();
		return false;
	}
	if(document.Form1.tb_sujet.value==""){
		alertMessage("Vous devez inscrire le sujet de votre message.","ANGLAIS");
		document.Form1.tb_sujet.focus();
		return false;
	}
	if(document.Form1.tb_msg.value==""){
		alertMessage("Vous devez inscrire votre message.","ANGLAIS");
		document.Form1.tb_msg.focus();
		return false;
	}
	return true;
}

/* Validation du formulaire d'inscription d'un membre du fichier devenir_membre.aspx */
function validerMembreForm(){
	if(document.Form1.ddl_province_id.value=="-1"){
		alertMessage("Vous devez choisir une province.","Please select your province.");
		document.Form1.ddl_province_id.focus();
		return false;
	}
	if(document.Form1.ddl_ville_id.value=="-1"){
		alertMessage("Vous devez choisir une ville.","Please select your city.");
		document.Form1.ddl_ville_id.focus();
		return false;
	}
	if(document.Form1.tb_adresse.value==""){
		alertMessage("Vous devez inscrire votre adresse.","Please insert your address.");
		document.Form1.tb_adresse.focus();
		return false;
	}
	if(!isCodePostal(document.Form1.tb_code_postal.value)){
		alertMessage("Vous devez inscrire un code postal valide.","The format of your postal code is not valid.");
		document.Form1.tb_code_postal.focus();
		return false;
	}
	if(document.Form1.tb_prenom.value==""){
		alertMessage("Vous devez inscrire votre pr\351nom.","Please insert your first name.");
		document.Form1.tb_prenom.focus();
		return false;
	}
	if(document.Form1.tb_nom.value==""){
		alertMessage("Vous devez inscrire votre nom.","Please insert your last name.");
		document.Form1.tb_nom.focus();
		return false;
	}
	if(!isEmail(document.Form1.tb_courriel.value)){
		alertMessage("Vous devez inscrire un adresse de courriel valide.","The e-mail format is not valid.");
		document.Form1.tb_courriel.focus();
		return false;
	}
	if(document.Form1.ddl_type_inscription.value=="-1"){
		alertMessage("Vous devez s\351lectionner un type d'inscription.","Please select a registration type.");
		document.Form1.ddl_type_inscription.focus();
		return false;
	}
	if(document.Form1.tb_nom_usager.value==""){
		alertMessage("Vous devez inscrire un nom d'usager.","Please insert a user name.");
		document.Form1.tb_nom_usager.focus();
		return false;
	}
	if(document.Form1.tb_mdp.value==""){
		alertMessage("Vous devez inscrire un mot de passe.","Please insert a password.");
		document.Form1.tb_mdp.focus();
		return false;
	}
	if(document.Form1.tb_mdp.value!=document.Form1.tb_confirmation_mdp.value){
		alertMessage("La confirmation de votre mot de passe n'est pas valide.","Your password confirmation is invalid.");
		document.Form1.tb_confirmation_mdp.focus();
		return false;
	}
	return true;
}

function afficherAnnonce(id){
	//ouvrirFenetre("annonce.aspx?aid="+id,850,600,true);
	var uneHauteur = 625;
	var top = (screen.height - uneHauteur) / 2;
	if(top < 0){
		top = 0;
	}		
	var uneLargeur = 850;
	var left = (screen.width - uneLargeur) / 2;
	if(left < 0){
		left = 0;
	}		
	var pos = "top=" + top + ", left=" + left + ", width=" + uneLargeur + ", height=" + uneHauteur;
	var w = null;
	w = window.open("annonce.aspx?aid="+id,"popAnnonce","width=" + uneLargeur + ",height=" + uneHauteur + ",directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no," + pos);
	w.focus();
}

function msgNonDiponible(lang){
	var msg = "";
	if(lang=="fr"){
		msg = "Vous ne pouvez pas renouveler cette annonce car vous n\'avez plus de parution de disponible dans ce forfait.";
        msg = msg + "\nUne annonce peut \352tre renouvel\351 tant qu\'il reste des parutions de disponible au forfait.";
        msg = msg + "\nVous pouvez placer une nouvelle annonce dans un autre forfait.";
	}else{
		msg = "You may not re-new this Ad as you do not have any publication available for this Package deal.";
		msg = msg + "\nAn Ad may be re-new as long as there is publication available on your package deal.";
		msg = msg + "\nYou may place new Ad in another package deal.";
	}
	alert(msg);
}

function enCoursDeTelechargement(){
	document.getElementById("div_telechargement_en_cours").className = "div_affiche";
}