function addToFavorites(anchor){if (window.external){window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));}}
function bookmarksite(title, url){if (document.all){window.external.AddFavorite(url, title);}else if (window.sidebar){window.sidebar.addPanel(title, url, "");}else{messageAlert('<br /><br />Désolé, votre navigateur ne prend pas en charge cette fonctionnalité !');}}
function noScroll(init) {var isDHTML=0;var isID=0;var isAll=0;var isLayers=0;if(document.getElementById){isID=1;isDHTML=1;}else{if(document.all){isAll=1;isDHTML=1;}else{browserVersion=parseInt(navigator.appVersion);if((navigator.appName.indexOf('Netscape')!=-1)&&(browserVersion==4)){isLayers=1;isDHTML=1;}}}if(isLayers){return true;}else{if(isAll){document.body.scroll="auto";}else{if(isID){document.body.scroll="auto";}};}}
function verifMail(theForm,theMail,thefocus){
	theObject=eval("document."+theForm+"."+theMail+"");longueur = theObject.value.length;position = theObject.value.indexOf("@");left_str = theObject.value.substring(0,position);	right_str = theObject.value.substring(position+1,longueur);	left_len = left_str.length;	right_len = right_str.length;right_longueur = right_str.length;	right_position = right_str.lastIndexOf(".");	l_right_str = right_str.substring(0,right_position);	r_right_str = right_str.substring(right_position+1,right_longueur);	l_right_len = l_right_str.length;	r_right_len = r_right_str.length;var Mod1 = /[#|,\/'éèà`~&"{(\[\\ç^)\]=}¨^$£¤%ù*µ!§:;?<> ]/i;var Mod2 = /[#|,\/'éèà`~&"{(\[\\ç^)\]=}¨^$£¤%ù*µ!§:;?<> ]/g;
	if (Mod1.test(theObject.value) == true){if(thefocus){theObject.focus()};return false;}	
	if (Mod2.test(theObject.value) == true){if(thefocus){theObject.focus()};return false;}	
	if (theObject.value.indexOf("@")==-1){if(thefocus){theObject.focus();}return false;}
	if ((left_len==0) || (right_len==0)){if(thefocus){theObject.focus();}return false;}
	if (right_str.indexOf(".")==-1){if(thefocus){theObject.focus();}return false;}
	if ((r_right_len < 2)||(r_right_len > 4)){if(thefocus){theObject.focus();}return false;}
	if (l_right_len==0){if(thefocus){theObject.focus();}return false;}
	return true;
}
function verifNewsMail(obj,theMail){
	myAlert.temp=5;
	testMail = verifMail(obj.name,theMail.name);
	if(theMail.value==""){
		theMail.focus();
		messageAlert('<br /><br />Vous devez saisir un email correct !',theMail.id);
		return false;
	}
	if(testMail == false){
		theMail.focus();
		messageAlert('<br /><br />Le mail entr&eacute; n&#039;est pas valide !',theMail.id);
		return false;
	}
	return true;
}
function verifLogin(obj){
	login = (!obj.login_p)?"login":obj.login_p.name;
	pass = (!obj.pass_p)?"pass":obj.pass_p.name;
    testMail = verifMail(obj.id,login);
	if(obj.elements[login].value==""){
		obj.elements[login].focus();
		messageAlert('<br /><br />Vous devez saisir un email correct !',obj.elements[login].id);
		return false;
	}
	if(testMail == false){
		obj.elements[login].focus();
		messageAlert('<br /><br />Le mail entr&eacute; n&#039;est pas valide !',obj.elements[login].id);
		return false;
	}
	if(obj.elements[pass].value==""){
		obj.elements[pass].focus();
		messageAlert('<br /><br />Vous devez saisir un mot de passe !',obj.elements[pass].id);
		return false;
	}
	return true	
}


function trim(s){return s.replace(/^\s+|\s+$/g, "");}
function isInteger(s){var n=trim(s);return n.length > 0 && !(/[^0-9]/).test(n);}
function isFloat(s){var n=trim(s);return n.length>0 && !(/[^0-9.]/).test(n) && (/\.\d/).test(n);}
function verifFormnews(obj){testMail = verifMail(obj.name,'mail_user');if(testMail == false){alert('Votre mail n\'est pas correct');obj.mail_user.focus();return false;}else{return true;}}
function verifFormSearch(obj){if(trim(obj.insearch.value).length < 4 || trim(obj.insearch.value)=="Recherchez votre vin"){obj.insearch.focus();messageAlert('<br /><br />Vous devez mettre au moins 4 caractères !!!<br /><br />Affiner la recherche en utilisant le signe +,<br />exemple : grand+cru','insearch');return false;}return true;}
function divInfoClose(nomdiv) {thediv = eval("document.getElementById('"+nomdiv+"')");thediv.style.display='none';}
function popupcentree(page,nom,largeur,hauteur,options){var top=(screen.height-hauteur)/2;var left=(screen.width-largeur)/2;var thepopup = window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);}
function cm_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
	}else if(this.moz) this.ns6 = 1
	else if(this.ie){
		this.ie4 = !this.dom && document.all
  	this.ie5 = (this.agent.indexOf("msie 5")>-1)
  	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
  this.usedom= this.ns6||this.op7//Use dom creation
  this.reuse = this.ie||this.op7||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""
	return this
}
var bw=new cm_bwcheck()
// Retourne true si le texte ne contient que des chiffres
function IsNumeric(text){var sValidChars="0123456789";var sChar="";for (i=0;i<text.length;i++){sChar = text.charAt(i);if (sValidChars.indexOf(sChar)==-1)return false;}return true;}
function IsTel(num_tel,inter){if(inter){var regex=new RegExp(/^(\(?\+?0{0,2}(\.|-| ){0,1}\)?( )?[0-9]{0,3})(\.|-| ){0,1}(0?)(1|2|3|4|5|6|8|9)(\.|-| ){0,1}[0-9]{2}(\.|-| ){0,1}[0-9]{2}(\.|-| ){0,1}[0-9]{2}(\.|-| ){0,1}[0-9]{2}$/gi);}else{var regex=new RegExp(/^(01|02|03|04|05|06|08|09)(\.|-| ){0,1}[0-9]{2}(\.|-| ){0,1}[0-9]{2}(\.|-| ){0,1}[0-9]{2}(\.|-| ){0,1}[0-9]{2}$/gi);}return regex.test(num_tel)}
// Retourne true si les texte représente une date valide       	
function IsDate(text){if(text=="")return false;var e=new RegExp("^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$");if (!e.test(text))return false;var j=parseInt(text.split("/")[0], 10);var m=parseInt(text.split("/")[1], 10);var a=parseInt(text.split("/")[2], 10);var fev=(a%4 == 0 && a%100 !=0 || a%400 == 0)? 29: 28;var nbJours=new Array(31,fev,31,30,31,30,31,31,30,31,30,31);return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );}
// Vérifie que le texte est un nom valide
function IsName(text){var re= /^[A-Za-zÀ-ÿ]+([\-\'\s]?[A-Za-zÀ-ÿ]+)*$/;return re.test(text);}
// Vérifie que le texte est un email valide
function IsEmail(text){var re= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+$/;return re.test(text);}
// Vérifie la taille de la chaine (test si min ou max est >= 0)
function IsSized(text, min, max){return ((min >= 0)? (text.length >= min): true)&& ((max >= 0)? (text.length <= max): true);}
function IsPassWord(text){var re= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+$/;return re.test(text);}
function IsMoney(str){if (typeof(str)=='undefined'){return false;}	var expr1= /(?!^0*$)(?!^0*\.0*$)^\d{1,10}(\.\d{1,2})?$/;if(!expr1.test(str)){return false;}return true;}
function ValInMinMax(value,min,max,nume){
	if(nume){if(!(IsNumeric(value))){return false;}}
    if((!(IsNumeric(min)))||(!(IsNumeric(max)))){return false;}
	if ((typeof(min)!='undefined')||(typeof(max)!='undefined')){
		if((typeof(min)!='undefined')&&(typeof(max)!='undefined')){
			if ((!isNaN(min))&&(!isNaN(max)))
				if (min>max) return false;
				if (value.length>max) return false;
				if (value.length<min) return false;
		}else{
			if(typeof(min)!='undefined'){
				if (!isNaN(min)) if (value.length<min) return false;
			}
		}
	}
	return true;
}
function TextInMin(str, min){if((typeof(str)=='undefined')||(typeof(min)=='undefined')){return false;}if((!(str.length=max))){return false;}return true;}
function TextInMinMax(str, min, max){if((typeof(str)=='undefined')||(typeof(min)=='undefined')||(typeof(max)=='undefined')){return false;}if((!(str.length=max))){return false;}return true;}

function verifsearchfiltre(obj){
    var tab_sel=obj.getElementsByTagName('select');
    var l=tab_sel.length;
    var retour = false;
     var cpt = 0;
    for(i=0;i<l;i++){
    	if(tab_sel[i][tab_sel[i].selectedIndex].value!=-1){
        	retour = true;
            cpt++;
        }
        if(cpt>3){
        	messageAlert('<br /><br />Vous ne pouvez s&eacute;lectionner que 3 filtres au maximum.');
            return false;
        }
    }
	if(!retour) messageAlert('<br /><br />Vous devez s&eacute;lectionner au moins un filtre');
    return retour;
}
