function getVersionIE() {
	var rv = 99999; // value failure
	var detect = navigator.userAgent.toLowerCase();
	if(!(navigator && navigator.userAgent && navigator.userAgent.toLowerCase)) {
		return false;
	} else {
		if(detect.indexOf('msie') + 1) {
			if (navigator.appName == 'Microsoft Internet Explorer') {
				var ua = navigator.userAgent;
				var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
				if (re.exec(ua) != null) {
					rv = parseFloat( RegExp.$1 );
				}
			}
			return rv;
		}
	}
	return rv;
} 

function include(fileName) {
	if (document.getElementsByTagName) {
 		var script = document.createElement("script");
 		script.type = "text/javascript";
 		script.src = fileName;
 		var head = document.getElementsByTagName("HEAD");
 		if (head) {
 			head[0].appendChild(script);
 		}
 	}
}
function reloadJs(){
	var i,a,s;
	a=document.getElementsByTagName('script');
	for(i=0;i<a.length;i++){
		s=a[i];
		if(s.type.toLowerCase().indexOf('text/javascript')>=0&&s.src){
			var h=s.src.replace(/(&|%5C?)reload=\d+/,'');
			s.src=h+(h.indexOf('?')>=0?'&':'?')+'reload='+getUniqueId();
		}
	}
}



function initSiteWeb(){
	if (window.oninit)oninit();
}


function initAlbumPhoto(){
	var tabObj=new Array();
	var photoPrinc=document.getElementById("img_fiche_photoPrincipale");
	var fenetre=0;
	
	
	
	for (var i=1;i<=20;i++){
		var objPhoto=document.getElementById("img_fiche_photoAlbum"+i);
		if (objPhoto)tabObj.push($(objPhoto));
		
	}
	for (var i=0;i<tabObj.length;i++){
		tabObj[i].fade(0.8);
		tabObj[i].onmouseover=function(evt){
			photoPrinc.src2=photoPrinc.src;
			photoPrinc.src=this.src;
			this.fade(1);
			
		}
		tabObj[i].onmouseout=function(evt){
			this.fade(0.8);
			photoPrinc.src=photoPrinc.src2;
		}
		
		var larg=parseInt(tabObj[i].getStyle("width"));
		if (larg>fenetre)fenetre=larg;
		
	}
	
	var divPrinc=$(document.getElementById("div_fiche_album"));
	if (!divPrinc)return;	

	var btPrec=$(document.getElementById("spanFiche_album_prev"));
	var btSuiv=$(document.getElementById("spanFiche_album_next"));
	var ulPrinc=$(document.getElementById("lst_fiche_photos_suppl"));
	
	ulPrinc.style.position="absolute";
	var wVisu=divPrinc.getStyle("width");
	var fenetresVisu=Math.round(parseInt(wVisu)/fenetre)-1;
	var butee=(fenetre*tabObj.length*-1)+(fenetresVisu*fenetre);
	var pas=fenetre*2;
	var animation = new Fx.Tween(ulPrinc, {duration: 800});
	
	btSuiv.onmousedown=function(){
		var pos=ulPrinc.offsetLeft-pas;
		if (pos<=butee)pos=butee;
		animation.start('left', pos);
	}
	btPrec.onmousedown=function(){
		var pos=ulPrinc.offsetLeft+pas;
		if (pos>=0)pos=0;
		animation.start('left', pos);
	}

}

function getUniqueId(){
	return ((new Date()).getTime() + "" + Math.floor(Math.random() * 1000000)).substr(0, 18)
}

function afficheNbRepInDivByForm(nomFrm,nomDiv){

	var objFrm=document.getElementById(nomFrm);
	if (!objFrm)return;
	var tabChp=getTabChmpForm(objFrm);
	
	for (var i=0;i<tabChp.length;i++){
		tabChp[i].onchange=function(evt){
			var url="/lib/ajax/traiteRequete.php";
			var vars="getNbInListCurr=ok";
			
			for (var i=0;i<tabChp.length;i++){
				vars+="&"+tabChp[i].name+"="+tabChp[i].value;
			}
			affUrlInDiv(nomDiv,url,vars);
		}
	}

	var url="/lib/ajax/traiteRequete.php";
	var vars="getNbInListCurr=ok";
	for (var i=0;i<tabChp.length;i++){
		vars+="&"+tabChp[i].name+"="+tabChp[i].value;
	}
	affUrlInDiv(nomDiv,url,vars);

}


function encodeHTML(html){
   	 var encodedHtml = escape(html);
   	 encodedHtml = encodedHtml.replace(/\//g,"%2F");
   	 encodedHtml = encodedHtml.replace(/\?/g,"%3F");
   	 encodedHtml = encodedHtml.replace(/=/g,"%3D");
   	 encodedHtml = encodedHtml.replace(/&/g,"%26");
  	 encodedHtml = encodedHtml.replace(/@/g,"%40");
   	 return encodedHtml;
}


function creeObjHttpRequest(){		
	var xhr_local=null;	
	if(window.XMLHttpRequest) // Firefox et autres
   		xhr_local = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
			xhr_local = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			xhr_local = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xhr_local;			
}		

function go(c){
	if(!c.data.replace(/\s/g,""))
		c.parentNode.removeChild(c);
}
	
function clean(d){
	var bal=d.getElementsByTagName("*");
	for(i=0;i<bal.length;i++){
		a=bal[i].previousSibling;
		if(a && a.nodeType==3)
			go(a);
		b=bal[i].nextSibling;
		if(b && b.nodeType==3)
			go(b);
	}
	return d;
}

function getInfoSession(nomvar){
	var vars="";

	if (!nomvar)nomvar="SESSID";
	var sess=getQueryStringVal("PHPSESSID");
	tabSess = sess.split("#");
	sess = tabSess[0];
	if (sess)vars+="&"+nomvar+"="+sess;
	else{
		vars="";
		var info=document.cookie;	
	}
	return vars;
}

function setVarEnSessionAjx(tag,val){
	var adr="/lib/ajax/miseEnSession.php";
	var xhr_local=creeObjHttpRequest();
	
	var sending=getInfoSession()+"&tag="+tag+"&val="+val		
	xhr_local.onreadystatechange = function(){
		if(xhr_local && xhr_local.readyState == 4){
			reponse = xhr_local.responseText;
		}
	}
	xhr_local.open("POST",adr,true);
	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(sending);
}	


function setClassForObj(obj,classe){
	if (obj){
		obj.setAttribute("class",classe);
		obj.setAttribute("className",classe);
	}
}


function getHtmlMessageFromForm(formToTransform){
	var form=formToTransform.cloneNode(true);
	form=transformChmpFormToSpan(form);
	return form.innerHTML;
}

function checkFormMotMagique(frm,frmMotMagique){
	var frmSubmit=true;
	if(frmMotMagique.motmagique.value){
		var message="Vous avez saisi un code promotion, merci de le valider avant de passer &agrave; l'&eacute;tape suivante.";
		alertAMalibu(message);
		frmSubmit=false;
	}
	if(frmSubmit) frm.submit();
}

function checkFormMotMagiqueByLien(frmMotMagique){
	if(frmMotMagique.motmagique.value){
		var message="Vous avez saisi un code promotion, merci de le valider avant de passer &agrave; l'&eacute;tape suivante.";
		alertAMalibu(message);
		return false;
	}
	else {
		return true;
	}
}

function envoiMailByAjaxByForm(nomIdForm,nomIdRetourMsg,transformFormulaire){
	var adr="/lib/ajax/envoiMail.php";
	var xhr_local=creeObjHttpRequest();
  	var sending="";
  	var message="";
  	
  	var form=document.getElementById(nomIdForm);
  	
  	
  	if (form){
  		if (form.destinataire)sending+="&destinataire="+escape(form.destinataire.value);
  		if (form.expediteur)sending+="&expediteur="+escape(form.expediteur.value);
  		if (form.sujet)sending+="&sujet="+escape(form.sujet.value);
  		if (form.enteteMessage)sending+="&enteteMessage="+escape(form.enteteMessage.value);
  		if (form.piedMessage)sending+="&piedMessage="+escape(form.piedMessage.value);
  		
  		if (form.msgEnvoiOK)sending+="&msgEnvoiOK="+escape(form.msgEnvoiOK.value);
  		if (form.msgEnvoiKO)sending+="&msgEnvoiKO="+escape(form.msgEnvoiKO.value);
 
 		sending+="&urlCurr="+document.location;
 
   		if (transformFormulaire){
  			message=getHtmlMessageFromForm(form);
  		}else{
	  		if (form.message)message=form.message.value;
	  		if (form.messages){
	  			for (var i=0;i<form.messages.length;i++){
	   				message+=form.messages[i].value;
	  			}
	  		}
	  	}
	  	sending+="&message="+escape(message);
  	}else return;
  	  	
	var html="<div id=divMsgEnvoiRetour><img src='/config_v3/imgs_defaut/roue_grise.gif' /></div>";

  	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
			var reponse = xhr_local.responseText;
			var divReponse=document.getElementById("divMsgEnvoiRetour");
			divReponse.innerHTML=unescape(reponse);
		}
	}
	var divMsg=document.getElementById(nomIdRetourMsg);
	if (divMsg)divMsg.innerHTML=html;
	else form.innerHTML=html;
	
	xhr_local.open("POST",adr,true);
 	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(sending);
	
}

function envoiMailByAjax(dest,exp,cc,sujet,body,nomIdRetourMsg,msgEnvoiOK,msgEnvoiKO){
	var adr="/lib/ajax/envoiMail.php";
	var xhr_local=creeObjHttpRequest();
  	var sending="";
  	
	if (dest)sending+="&destinataire="+escape(dest);
	if (cc)sending+="&copie="+escape(cc);
	if (exp)sending+="&expediteur="+escape(exp);
	if (sujet)sending+="&sujet="+escape(sujet);
	if (body)sending+="&message="+escape(body);
   		
	if (msgEnvoiOK)sending+="&msgEnvoiOK="+escape(msgEnvoiOK);
	if (msgEnvoiKO)sending+="&msgEnvoiKO="+escape(msgEnvoiKO);
 
  	  	
	var html="<div id=divMsgEnvoiRetour><img src='/config_v3/imgs_defaut/roue_grise.gif' /></div>";

  	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
			var reponse = xhr_local.responseText;
			var divReponse=document.getElementById("divMsgEnvoiRetour");
			divReponse.innerHTML=unescape(reponse);
		}
	}
	var divMsg=document.getElementById(nomIdRetourMsg);
	if (divMsg)divMsg.innerHTML=html;
		
	xhr_local.open("POST",adr,true);
 	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(sending);
	
}


function setCookie (name,value,expires,path,domain,secure) {
    document.cookie = name + '=' + escape (value) +
	((expires) ? '; expires=' + expires.toGMTString() : '') +
    ((path) ? '; path=' + path : '') +	((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
}

function getCookie(name){
	if (document.cookie.length>0){
		deb=document.cookie.indexOf(name + '=');
		if (deb!=-1) { 
	   		deb=deb + name.length+1; 
	  		fin=document.cookie.indexOf(';',deb);
	   		if (fin==-1) fin=document.cookie.length;
	   		return unescape(document.cookie.substring(deb,fin));
	   	} 
  	}
	return '';
}

function getQueryStringVal(lQuery){

	var lDoc=String(document.location);
	var lSignet = "";
	var n1 = lDoc.indexOf("?");

	if (n1 > 0) {
		var n2 = lDoc.indexOf("?" + lQuery + "=",n1);
		if (n2 < n1)
			n2 = lDoc.indexOf("&" + lQuery + "=",n1);
 		if (n2 >= n1){
 			n2 = n2 + ("?" + lQuery + "=").length;
 			var n3 = lDoc.indexOf("&",n2+1);
 			if (n3 > n2)
 				lSignet = lDoc.substring(n2, n3);
 			else
 				lSignet = lDoc.substring(n2);
 		}
 	}
	return lSignet;
} 

function getTabValInQueryString(){
	var loc=String(document.location);
	var n1 = loc.indexOf("?");
	
	var tabOut=new Array();
	if (n1<0)return tabOut;

	var qs=loc.substring(n1+1);
	var vars=qs.split("&");
	
	
	for (var i=0;i<vars.length;i++){
		tabOut.push(vars[i].split("="));
	}
	return tabOut;		
}



function checkForm(frm){
	
	var frmSubmit=true;
	
	var tabChkInput=getTabChmpForm(frm);
	
	for(var i = 0; i < tabChkInput.length; i++){
    	var attr=tabChkInput[i].attributes;
    	for(var j = 0; j < attr.length; j++){
    		if(attr[j].nodeName=="modecheck"){
    			checkByInput(tabChkInput[i],attr[j].nodeValue,tabChkInput[i].chpInputControl);
    			if(tabChkInput[i].retourVerif!="OK") frmSubmit=false;
    		}
    	}
	}
	
	if(frmSubmit) frm.submit();
	
}


function checkByInput(chpInput,mode,chpInputControl){
    if (!chpInput)return;
    if (!mode)return;
    

    var adr="/lib/ajax/checkForm.php";
    var xhr_local=creeObjHttpRequest();
    var sending="mode="+mode+"&value="+chpInput.value;
    if (chpInputControl){
    	chpInput.chpInputControl=chpInputControl;
    	if(chpInputControl.value) sending+="&valueControle="+chpInputControl.value;
    	else sending+="&valueControle="+chpInputControl;
    }
    
    chpInput.modecheck=mode;
   
	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
			var reponse = clean(xhr_local.responseXML.documentElement);
			var retour=reponse.childNodes[0].childNodes[0].nodeValue;
			chpInput.retourVerif=retour;
			
			if (retour!="OK"){
				if(chpInput.type=="password") chpInput.type="text";
				chpInput.styleModifie=true;
				chpInput.styleFontColorAvant=chpInput.style.color;
				chpInput.styleFontWeightAvant=chpInput.style.fontWeight;
				chpInput.styleFontFamilyAvant=chpInput.style.fontFamily;
				chpInput.styleFontSizeAvant=chpInput.style.fontSize;
				
				chpInput.style.color="red";
				chpInput.style.fontWeight="bold";
				chpInput.style.fontFamily="Arial";
				chpInput.style.fontSize="8pt";
				chpInput.value = reponse.childNodes[1].childNodes[0].nodeValue;
			}
        }
    }
   
    xhr_local.open("POST",adr,true);
    xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhr_local.send(sending);
}

function viderChp(chpInput){
	if(chpInput.styleModifie){
		chpInput.style.color=chpInput.styleFontColorAvant;
		chpInput.style.fontWeight=chpInput.styleFontWeightAvant;
		chpInput.style.fontFamily=chpInput.styleFontFamilyAvant;
		chpInput.style.fontSize=chpInput.styleFontSizeAvant;
		chpInput.styleAvant=null;
	}
	
	var msg = chpInput.value.substring(2);
	var idx_debmsg=msg.indexOf("--");
	if (idx_debmsg>0){
		var reste = msg.substring(idx_debmsg+2);
		chpInput.value = reste;
	}
}

function bloqueTouche(e) {
	var DisableCtrlKeys = Array(67,86);
	var ie = window.event;
	if (ie){
		e = window.event;
	}
	if(e.ctrlKey) { //Touche Ctrl enfoncée
		for (i=0;i<DisableCtrlKeys.length;i++) {
			if(e.keyCode == DisableCtrlKeys[i]) {
				if ((ie && e.srcElement.id=='eMailConfirm')||(e.target && e.target.id=='eMailConfirm')) {
					if (ie) {
						e.keyCode=0;
						e.returnValue = false;
					}
					return false;
				}
			}
		}
	}
			
	/* Si un jour on veut bloquer des touches sans CTRL */
	/*for (i=0;i<DisableKeys.length;i++){
		if (e.keyCode == DisableKeys[i]) {
			if (ie) {
				e.keyCode=0;
				e.returnValue = false;
			}
			return false;
		}
	}*/
			
}
document.onkeydown=bloqueTouche;



