var random_number="ord="+(Math.round(Math.random()*10000000000))+"?";
if (document.images) esi = new Image;
NS6 = (document.getElementById&&!document.all);
IE = (document.all);	
IE7 = (document.all && navigator.appVersion.toLowerCase().indexOf('msie 7.0')!=-1);				
NS = (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=="4");
MAC = (navigator.userAgent.indexOf("Mac") != -1);
var nav="";
if (navigator.appName.indexOf("Microsoft") != -1) nav = "Mic"; else nav = "Net"; 
if(NS) document.write('<link rel="stylesheet" href="/x/css/mappy2NS2.css?v=25">');
function popup2(url, titre, taille) {popup_mappy(url, titre, taille);}
function popup(url, titre, taille) {return popup_mappy(url, titre, taille);}
function pop_print(url) {p = popup_mappy(url, 'print', 'resizable,menubar');p.focus();}
function popup_mappy(url, titre, taille) {var re=new RegExp('http', 'gi'); var urlprefix=mappy_server+'/sid'+mappy_sid;var urltotal='';if (url.search(re)>-1 || url.substring(0,1)=='/') urltotal=url; else urltotal=urlprefix+url;return window.open(urltotal,titre,'status=no,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,resizable=no,dependent=yes,alwaysRaised=yes,hotkeys=no,' + taille);}
function findDOM(objectID) {if (NS6) {return (document.getElementById(objectID));} else if(IE) {return (document.all[objectID]);} else if(NS) {return (document.images[objectID]);}}
function over(cell) {if(NS6||IE) findDOM(cell).style.background='#88E1FF';}
function out(cell) {if(NS6||IE) findDOM(cell).style.background='#FFFFFF';}
function map_Load() {
	//findDOM('message_div').innerHTML += "map load:"+arguments[0]+"<br/>";	
	}
String.prototype.addslashes = function(){return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');}
String.prototype.trim = function () {return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");};
/*Renvoi l'index si trouver dans l'Array*/
Array.prototype.contains = function(arg){
            tmp = -1;
            if(!this instanceof Array) return tmp;  
            for(var i=0;i<this.length;i++){  
                        if(typeof(this[i])=='object' && this[i].equal && this[i].equal(arg)){return i;}
                        else if(this instanceof Array && String(this[i]) == String(arg)){return i;}  
            }
            return tmp;
}

///////////////////////////////////////////jQuery Extend
jQuery.fn.extend({
	   findPos : function() {
						var obj = $(this).get(0);
						var curleft = obj.offsetLeft || 0;
						var curtop = obj.offsetTop || 0;
						while (obj = obj.offsetParent) {
								curleft += obj.offsetLeft
								curtop += obj.offsetTop
						}
						return {x:curleft,y:curtop};
	   }
 });

/////////////////////////////////////////
//////////////////////////////////////////POSITION SOURIS
if(window.Event) { 
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = ns; 
}else{ 
	document.onmousemove=ie; 
} 
function ns(e) { 
	mousey = e.pageY; 
	mousex = e.pageX; 
	correcty = 0;
	correctx = 0;
} 
function ie() { 
	mousey = window.event ? window.event.clientY : 0;
	mousex = window.event ? window.event.clientX : 0; 
	correcty = document.documentElement.scrollTop;
	correctx = document.documentElement.scrollLeft;
} 

///////////////////////////////BULLE D'INFO
function hideInfo(id_div, cl_css){	
	var el = jQuery('#'+((id_div!=null && id_div!='')?id_div:'div_info')).html('').hide();	
	if(cl_css!=null && cl_css!='')el.removeClass(cl_css);
	el.width('200px');	
}
function moveInfo(e, id_div, esp_v, esp_h){	
	var el = jQuery('#'+((id_div!=null && id_div!='')?id_div:'div_info'))[0];
	if(el && el.innerHTML != ''){
		el.style.display = 'inline';	
		var esp_h = (esp_h!=null)?esp_h:-20;
		var esp_v = (esp_v!=null)?esp_v:20;
		el.style.top = (mousey+correcty+(esp_v))+'px';
		el.style.left = (mousex+correctx+(esp_h))+'px';		
	}
}
function fillInfo(text, id_div, cl_css, _width){
	if(text!=''){
		var el = jQuery('#'+((id_div!=null && id_div!='')?id_div:'div_info')).html(text);		
		if(typeof cl_css!='undefined' && cl_css!='')el.addClass(cl_css);
		if(typeof _width!='undefined' && _width!='')el[0].style.width=_width+'px'; else el.width('auto');		
	}
}
function moveInfo_amb(e){
	var el = jQuery('#div_info')[0];	
	if(el && el.innerHTML != ''){
		el.style.display = 'block';	
		var esp = el.offsetHeight+10;
		el.style.top = (mousey+correcty+10)+'px';
		el.style.left = (mousex+correctx+10)+'px';	
	}
}
function moveInfo_traffic(e){
	var el = jQuery('#div_info2')[0];
	if(el){
		el.style.display = 'block';	
		var esp = el.offsetHeight+10;
		el.style.top = (mousey+correcty+10)+'px';
		el.style.left = (mousex+correctx+10)+'px';		
	}
}

String.prototype.padLeft = function(strChar, intLength)
{
 var str = this + '';
 while (str.length != intLength) {
  str = strChar + str;
 }
 return str;
}
/*
class permetant d'executer plusieurs fonctions iteralement sur demande ou sur des evenements d'objet
	pas fini, mais fonctionnel pour les fonctions de base = "addFnct",  "addEvent", "exe", "removeFnct"
*/
var Delegate = function(){
		var ar = new Array();
		var evt = new Array();
		
		//ajoute une fonction au delege
		//fnct : la function a executer
		//ar_args :  tableau contenant les arguments de la function (fnct)
		this.addFnct = function(fnct,ar_args){
			if(typeof(fnct)!='function')throw new Error("Delegate : c'est pas une fonction ça!");
			if(ar.contains(fnct)!=-1) return false;
			ar.push((fnct)?fnct:function(){});
			ar.push((ar_args)?ar_args:[]);			
			this.implEvent();
		}		
		//actuelement supprime toutes les fonctions du delege, a revoir pour supprimer une fnct precis
		this.removeFnct = function(fnct){
			if(!fnct){this.implEvent(true);ar.length = 0;return;}
			//if(n = ar.contains(fnct)!=-1)ar.splice(n,2);//a revoir
			//this.implEvent();
		}		
		//ajoute un evenement au delege
		//el : l'element du dom auquel on va ajouter l'evenement
		//ev : l'evenement a ajouter ATTENTION ne pas mettre 'on' devant juste 'click' ou 'focus' ect...
		this.addEvent = function(el,ev){			
			if(el && typeof(el)!='object')throw new Error("Delegate event : c'est pas un object(élément) ça!");
			if(ev && typeof(ev)!='string') return false;
			var n1=evt.contains(el);
			var n2=evt.contains(ev);
			if(n1==n2-1) return false;
			evt.push(el);
			evt.push(ev);	
			this.implEvent();			
		}		
		//actuelement supprime tous les evenements du delege, a revoir pour supprimer un event precis
		this.removeEvent = function(ev){
			if(!ev){this.implEvent(true);evt.length = 0;ar.length = 0;return;}
			//if(n = evt.contains(ev)!=-1)evt.splice(n,2);//a revoir
			//this.implEvent();			
		}
		//implemente toutes les fonction à tous les evenements des elements
		this.implEvent = function(_sup){			
			for(var i=0;i<evt.length;i++){
				var el = evt[i];
				var ev = evt[++i];
				for(var j=0;j<ar.length;j+=2){
					if(el.addEventListener){
						if(!_sup)el.addEventListener(ev, ar[j], false); else{el.removeEventListener(ev, ar[j], false);}
					}else if (el.attachEvent){
						el.detachEvent("on"+ev, ar[j]);						
						if(!_sup){el.attachEvent("on"+ev, ar[j]);}
					}					
				}					
			}
		}
		//executer les fonctions			
		this.exe = function(){
			
			
			for(var i=0;i<ar.length;i++){
				ar[i].apply(null,ar[++i]);
			}				
		}
		//trace les fonctions (string)
		this.getContentFnctString = function(){
			var str='';
			for(var i=0;i<ar.length;i+=2){
				str+=ar[i]+"\n";
			}	
			return str;
		}	
		//trace les evenement (string)
		this.getContentEventString = function(){
			var str='';
			for(var i=0;i<evt.length;i+=2){
				str+= evt[i]+" -- "+evt[i+1]+'\n';
			}	
			return str;
		}			
		this.toString = function(){return "contenu fnct:"+(ar.length/2)+"   "+(this.getContentFnctString())+"\n  contenu event:"+(evt.length/2)+"   "+(this.getContentEventString());}
}

//////////////////////////////////////////
//edite une url (si le parametre à changer n'existe pas il est ajouté)
// url : l'url a qui contien le parametre  a changer
// param : object  parametre a rechercher dans l'url et a changer ex: {param:new_val}
// val : la nouvelle valeur du parametre
// act : action mappy (optionnel)
function changeUrl(url, params, act){					
	//action		
	if(act && act!=''){
		reg_act = new RegExp('\(/[^/.]*\\?)',"gi"); 
		reg_act.exec(url);
		url = url.replace(reg_act,'/'+act+'?');
	}
	//params
	for(var p in params){	
		reg_par = new RegExp("("+p+"=[^;|&amp;.]*)(;|&amp;)*","gi"); 
		reg_par.exec(url);	
		//alert(RegExp.$1+RegExp.$2);
		if(url.match(reg_par)){	
			url = url.replace(reg_par,p+'='+encodeURI(params[p])+RegExp.$2);					
		}else{
			url +=((url.indexOf('?')==-1)?'?':';')+p+'='+encodeURI(params[p]);
		}		
	}
	return url;
}
//////////////////////////////////////////CALENDRIER MAPPY
///Creer une instance apres le chargement du body nommer la "calendrier" (obligatoire)
///appeler sur le clic(ou autre) de l'element choisi, calendrier.showCalendar() avec les parametres qui vont bien (voir showCalendar()) c'est tout
///si la date est a afficher dans des listes deroulantes (jours mois années), "implementSelect()" peut les initialisers et "MajSelectJour()" met a jour la liste des jours, qui change suivant le mois selectionné ou l'année selectionnée
///ne pas oublier les styles css 
function Calendar(lang)
{	
	this.elem;
	this.elem_txt;
	this.one_elem_txt;
	this.cal;
	this.frame;
	this.edit;
	this.vu_cal = false;
	this.months;
	this.daysInMonth;
	this.bulle_eff;
	this.bulle_format;
	this.txt_today;
	this.div_cal;
	this.tableCal;
	this.an_deb=1900;	
	this.an_fin=2050;	
	this.aujourdhui = new Date();
	this.format=null;
	this.restriction_date;
	this.test=-1;
	
	var getNewDate = function (newDate)
	{	
		if(newDate){
			tab_tmp = newDate.split(',');
			this.now = new Date(Number(tab_tmp[2]),Number(tab_tmp[1])-1,Number(tab_tmp[0]));
		} else {
			this.now = new Date();
		}
		this.year = this.now.getFullYear(); 
		this.month = this.now.getMonth();
		
		this.day = this.now.getDate();
	}
	this.date_now = new getNewDate();	
	
	Date.prototype.dateNotTime = function(){
		return  new Date(this.getFullYear(), this.getMonth(), this.getDate());
	}
	
	/// lang: string fr=francais ou autre=anglais	
	this.init = function(lang){	
		this.daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		if(lang == 'fr'){
			 this.months = new Array("Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre");			 
			 this.days_str = new Array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi");
			 this.bulle_eff = 'Efface la zone de texte';
			 this.bulle_format = 'Choix du format de date';
			 this.txt_today = 'Aujourd\'hui';
		}else if(lang == 'es'){
			 this.months = new Array ('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
			 this.days_str = new Array ('Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado');      
			 this.bulle_eff = 'Despejar el área de texto';    
			 this.bulle_format = 'Opcion del formato de la fecha';      
			 this.txt_today = 'Hoy';
		}else{
			 this.months = new Array ('January', 'February', 'Mars', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
			 this.days_str = new Array ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');      
			 this.bulle_eff = 'Clear the text area';    
			 this.bulle_format = 'Choice of the format of date';      
			 this.txt_today = 'Today'; 
		}	
		var table = this.getTableCal(); 
		this.div_cal = document.createElement('div');		
		this.div_cal.innerHTML = table;	
	}
	
	
	this.getTableCal = function (){
		return '<iframe id="frame" frameborder="0" style="display:none;position:absolute;top:0px;left:0px;z-index:1000"></iframe>'+
				'<table  id="calendrier" class="cal_cadre" border="0" cellPadding="0" cellSpacing="2"  style="display:none;position:absolute;z-index:1010">'+
		 			'<tr><td colSpan="7"  valign="middle" align="center" width="220">'+
						'<table id="tabselect" width="100%" border="0" cellPadding="0" cellSpacing="0"><tr>'+
							'<td style="width:60%"><select style="width:100%" id="cal_month" onchange="calendrier.newCalendar()"> '+this.opt_mois()+'</select></td>'+
							'<td align="left"><select id="cal_year" onchange="calendrier.newCalendar()">'+this.opt_annee(this.an_deb,this.an_fin)+'</select></td>'+
							'<td align="right" valign="top"><input type="image" src="'+base_url_static+'/x/v2/i/cal_ferme.gif" name="ferme" alt="fermer" style="width:12px;height:12px" onclick="calendrier.HideCalendar();return false;"/>'+
							'</td></tr>'+
						'</table>'+
					  '</td></tr>'+
					  '<tr class="cal_today" >'+this.td_jours()+'</tr>'+
					  '<tbody id="cal_dayList" vAlign="center" >'+this.lst_jours()+'</tbody>'+
					  '<tbody><tr><td class="cal_days" colSpan="7" id="todayday" onclick="calendrier.getTodayDay()"></td></tr></tbody>'+
					   '<tr><td colSpan="7"><table id="edition" width="100%"  border="0" cellPadding="0" cellSpacing="0" ><tr><td style="font-size:9px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:300" >'+this.bulle_format+' : <br/><select style="width:200px;text-transform: none;" id="cal_format" title="'+this.bulle_format+'" ><option title="'+this.bulle_format+'"  value="1">'+this.forme_date(this.date_now.now,1)+'</option><option title="'+this.bulle_format+'"   value="2">'+this.forme_date(this.date_now.now,2)+'</option><option title="'+this.bulle_format+'"   value="3">'+this.forme_date(this.date_now.now,3)+'</option></select></td>'+
					   '<td valign="bottom" align="center" ><img vspace="5px" style="cursor:pointer" id="eff" title="'+this.bulle_eff+'" src="'+base_url_static+'/x/v2/i/eff.gif" name="eff" alt="effacer"  onclick="calendrier.efface()"/></td></tr><table></td></tr>'+
				'</table>';
	}
	

	/// el: id de l'element cliquer (icone, img etc..)
	/// el_txt: id des ou de l'element de sortie. Deux solutions:  1. c'est un element simple (type=text) et la date pourra etre afficher sous different format par defaut(ex jeudi 10 septembre 2006 ou 10/09/2006)... 2. ce sont des id de listes deroulantes (SELECT) ou des champs textes envoyé le parametre dans l'ordre (id_jour, id_mois, id_année) le format ne peut evidement pas être choisi.
	/// deb: number : l'année de debut 
	/// fin: number : l'année de fin
	/// edit: (non obligatoire) boolean true=edition possible du format de sortie de la date dans un champ texte simple(outil visible)  si false alors (outil invisible)  
	/// restriction: contrain la sélection, à une date ulterieur ou antérieur ou egale à la date du jour si 'restriction = 0', sinon si 'restriction > 0 ou < 0' la date de debut de restriction sera décalée d'autan de jour 
		this.showCalendar = function(el,el_txt,deb,fin,edit,format,restriction){		
			////inititialisation variables	
			this.format = (format)?format:null;
			
			this.elem_txt = new Array();
			this.edit = edit;			
			var tab_date = new Array(), tab_idx = new Array();
			
			
			if(deb)this.an_deb = deb;
			if(fin)this.an_fin = fin;
			
			if(typeof(restriction)!="undefined"){
				this.test=0;				
				this.restriction_date = new Date().dateNotTime();	
				this.restriction_date.setDate(this.restriction_date.getDate()+restriction);
			}else{this.restriction_date=restriction;}
						
			if(!document.getElementById('calendrier'))document.body.appendChild(this.div_cal);
			
			this.frame = document.getElementById('frame');
			this.cal = document.getElementById('calendrier');	
			this.elem = document.getElementById(el);						
					
			if(el_txt.indexOf(',')==-1){					
				this.elem_txt[0] = document.getElementById(el_txt);		
				this.one_elem_txt = this.elem_txt[0];
			}else{	
				var tab_tmp = el_txt.split(',');
				for(var i=0;i<tab_tmp.length;i++){
					this.elem_txt[i]=document.getElementById(tab_tmp[i]);						
				}				
									
				for(var i=0;i<this.elem_txt.length && this.elem_txt.length>1;i++){					
					if(this.elem_txt[i].attributes.getNamedItem('TYPE')!=null && this.elem_txt[i].getAttribute('type').toUpperCase() == 'TEXT'){						
						
						break;
					}else if(this.elem_txt[i].tagName.toUpperCase() == 'SELECT'){
						//if(this.elem_txt[i].value != '')tab_date[i] = this.elem_txt[i].value;
						tab_idx[i] = this.elem_txt[i].selectedIndex;						
					}
				}	
			}
			this.date_now = new getNewDate();	
			this.opt_annee(this.an_deb,this.an_fin,document.getElementById('cal_year'));	
			document.getElementById('cal_year').selectedIndex = this.getIndexSelect(document.getElementById('cal_year'),this.date_now.year);
			document.getElementById('cal_month').selectedIndex = this.date_now.month;	
			document.getElementById('edition').style.display=(this.elem_txt.length == 1 && edit)?'block':'none';
			
			this.newCalendar();
			this.PosCalendar();				
			
			if(this.vu_cal = !this.vu_cal){
				this.frame.style.display = "block";
				this.cal.style.display = "block";
				this.frame.style.height = this.cal.offsetHeight+'px';				
				this.frame.style.width = this.cal.offsetWidth+'px';
			}else{ 
				this.HideCalendar();
			}
	}
	
	this.getIndexSelect = function (select, val)
	{	
		var tmp=0;
		for(var i=0;i<select.options.length;i++){
				if(select.options[i].value == val){
				tmp = select.options[i].index;
				break;
			} 	
		}
		return tmp;
	}
	
	this.HideCalendar = function ()
	{		
		this.frame.style.display = "none";
		this.cal.style.display="none";		
		this.vu_cal=false;
	}	

	this.newCalendar = function () 
	{
		var newCal;
		var day = -1;
		var daily = 0;
		var parseYear = parseInt(document.getElementById('cal_year')[document.getElementById('cal_year').selectedIndex].text); 
		newCal = new Date(parseYear , document.getElementById('cal_month').selectedIndex, 1);
		var startDay = newCal.getDay();	
		
		if(typeof(this.restriction_date)=="object" && this.test==0){
			newCal = this.restriction_date;	
			this.test=1;
		}else{			
			if(typeof(this.restriction_date)=="object" ){
				if(this.restriction_date.getFullYear() == newCal.getFullYear() && this.restriction_date.getMonth() == newCal.getMonth())newCal = this.restriction_date;
			}				
		}
		
		var intDaysInMonth = this.getDays(newCal.getMonth(), newCal.getFullYear());
		var d = new Date().dateNotTime();
		if ((d.getFullYear() == newCal.getFullYear() ) && (d.getMonth() == newCal.getMonth())) day = d.getDate();
		this.tableCal = document.getElementById('cal_dayList');
		
		document.getElementById('cal_month').value= newCal.getMonth();		
		document.getElementById('todayday').onmouseover = null;
		 document.getElementById('todayday').onclick = "";	
		 document.getElementById('todayday').style.color ='#CCCCCC';
		 document.getElementById('todayday').style.cursor ='default';
		
		for (var intWeek = 0; intWeek < this.tableCal.rows.length;  intWeek++)
		{
		   for (var intDay = 0;intDay < this.tableCal.rows[intWeek].cells.length;intDay++)
		   {
				var cell = this.tableCal.rows[intWeek].cells[intDay];
				if ((intDay == startDay) && (0 == daily)) daily = 1;
				cell.style.color = (day == daily) ? "red" : "";
				document.getElementById('todayday').innerHTML= this.txt_today+'<br/>'+this.forme_date(this.aujourdhui,1);					
				
				if(this.restriction_date <=  new Date().dateNotTime() || typeof(this.restriction_date)!="object")
				{				
					document.getElementById('todayday').style.color ='black';
					document.getElementById('todayday').onmouseover = this.mouseover;
					document.getElementById('todayday').onmouseout = this.mouseout; 
					document.getElementById('todayday').style.cursor ='pointer';
					var t = this;
					document.getElementById('todayday').onclick = function(){t.getTodayDay();};					
				}
				
				if(daily > 0 && daily <= intDaysInMonth){	
					cell.className = 'cal_days';
					cell.onclick = this.getDateCal;
					cell.onmouseover = this.mouseover;
					cell.onmouseout = this.mouseout; 
					cell.style.cursor ='pointer';
					cell.innerHTML = daily++;
					if(typeof(this.restriction_date)=="object" && (newCal < this.restriction_date || daily <= newCal.getDate()) ){					 
						 if(day == daily-1){
							 cell.style.color ='#CC6600';						
						 }else cell.style.color ='#CCCCCC';
						cell.onmouseover = null;
						cell.onmouseout = null;
						cell.style.cursor ='default';
						cell.onclick = "";					
					}
				}else{			
					cell.className = '';
					cell.onmouseover = null;
					cell.onmouseout = null; 					
					cell.innerHTML = "";
				}
				
				
			}
		}	
		this.frame.style.height = this.cal.offsetHeight+'px';
	}
			   
	this.mouseover = function (e){
		var la_td = (nav == "Net")?e.target:event.srcElement;	
		la_td.className = 'cal_daysbis';
	}
	this.mouseout = function (e){
		var la_td = (nav == "Net")?e.target:event.srcElement;	
		la_td.className = 'cal_days';
	}    
	
	this.PosCalendar = function ()
	{	
		var py = mousey;
		var px = mousex;
		var _py = py+(( (py+330) > window.screen.height)?-150:20)+correcty+'px';
		var _px = px-(( (px+180) > window.screen.width)?180:80)+correctx+'px';	
		this.frame.style.left  = _px;
		this.frame.style.top = _py;
		this.cal.style.left  = _px;
		this.cal.style.top = _py;		
	}				
	
	this.getDays = function (month, year) 
	{
		if (1 == month)
			return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28;
		else
			return this.daysInMonth[month];
	}

	this.getTodayDay = function ()
	{
		this.affichageDate(this.aujourdhui.getFullYear(),this.aujourdhui.getMonth(),this.aujourdhui.getDate());		
		this.HideCalendar();
	}
	
	this.getDateCal = function(e) 
	{		
		var la_td = (nav == "Net")?e.target:event.srcElement;		
		if (la_td.tagName.toUpperCase() == "TD"){			
			if (la_td.innerHTML != "")
			{ 
				var mn = document.getElementById('cal_month').selectedIndex+1;
				var Year = document.getElementById('cal_year')[document.getElementById('cal_year').selectedIndex].text;
				calendrier.affichageDate(Year,mn-1,la_td.innerHTML);
				calendrier.HideCalendar();
			}
		}
		
	}
	
	this.affichageDate = function (y,m,d){	
		var tmp = [d,m,y];
		if(this.elem_txt.length == 1){			
			var format_dat = (this.format)?this.format:document.getElementById('cal_format').selectedIndex+1;			
			if(this.format){
				this.elem_txt[0].value='';
				this.elem_txt[0].value = this.forme_date(new Date(y,m,d),format_dat);
			}else{
				this.elem_txt[0].value = (this.elem_txt[0].value+' '+this.forme_date(new Date(y,m,d),format_dat)).substr(0,(this.elem_txt[0].getAttribute('maxlength')!=null)?this.elem_txt[0].getAttribute('maxlength'):65635); 				
			}			
		}else if(this.elem_txt.length > 1){
			for(var i=0;i<this.elem_txt.length;i++){
				if(this.elem_txt[i].attributes.getNamedItem('TYPE')!=null && this.elem_txt[i].getAttribute('type').toUpperCase() == 'TEXT'){	
					this.elem_txt[i].value = (i==1)?this.months[tmp[i]]:tmp[i];	
				}else if(this.elem_txt[i].tagName.toUpperCase() == 'SELECT'){						
					for(var j=0;j<this.elem_txt[i].options.length;j++){
						if(this.elem_txt[i][j].value == tmp[i]){
							this.elem_txt[i].selectedIndex =  this.elem_txt[i][j].index;
							break;
						}
					}
					this.majSelectJour(this.elem_txt[0].id,m,y);
				}				
			}
			
		}else{return null;}
	}
	
	this.forme_date = function (dat,format){
		var tmp='';	
		var es = (lang=='es')?'de ':'';
		switch(format){
			case 1: 
			tmp = this.days_str[dat.getDay()]+" "+es+dat.getDate()+" "+es+this.months[dat.getMonth()]+" "+dat.getFullYear();	
		break;
			case 2: 
			tmp = dat.getDate().toString().padLeft('0', 2)+"/"+(dat.getMonth()+1).toString().padLeft('0', 2)+"/"+dat.getFullYear();		
		break;
			case 3: 
			tmp = dat.toDateString();
		break;
			case 4: 
			tmp = dat.getDate().toString().padLeft('0', 2)+"-"+(dat.getMonth()+1).toString().padLeft('0', 2)+"-"+dat.getFullYear();	
		break;
			case 5: 
			tmp = dat.getFullYear()+"-"+(dat.getMonth()+1).toString().padLeft('0', 2)+"-"+dat.getDate().toString().padLeft('0', 2);	
		break;
			case 6: 
			tmp = this.days_str[dat.getDay()];
		break;
		}
		return tmp;
	}
		
	this.opt_jours = function (a, m, j,elem_select){
		
		var tmp='';
		var nbj = this.getDays(m, a);		
		if(arguments[3]){		
			elem_select.innerHTML='';			
			for (var i = 1; i < nbj+1; i++){				
				var op = document.createElement("option");
				op.innerHTML = i;
				op.value = i;
				op.selected=(i == j);							
				elem_select.appendChild(op);
			}
		}else{
			for (var i = 1; i < nbj+1; i++)
			tmp += '<option value="'+i+'"' + ((i == j)?'Selected':'') + '>' +i+'</option>';	
		}
		return tmp;
	}
	
	
	this.opt_mois = function (elem_select){
		var tmp='';
		
		if(arguments[0]){			
			for (var intLoop = 0; intLoop < this.months.length; intLoop++){
				var op = document.createElement("option");
				op.innerHTML = this.months[intLoop];
				op.value = intLoop;
				op.selected=(this.date_now.month == intLoop);
				elem_select.appendChild(op);
			}
		}else{
			for (var intLoop = 0; intLoop < this.months.length; intLoop++)
			tmp += '<option value="'+(intLoop)+'"' +	(this.date_now.month == intLoop ? 'Selected' : '') + '>'+this.months[intLoop]+'</option>';	
		}
		return tmp;
	}
	
	this.opt_annee = function (deb, fin, elem_select){
		var tmp='';
		if(arguments[2]){			
			elem_select.innerHTML='';
			for (var intLoop = deb; intLoop < fin+1; intLoop++){
				var op = document.createElement("option");
				op.innerHTML = intLoop;
				op.value = intLoop;				
				op.selected=(this.date_now.year == intLoop);				
				elem_select.appendChild(op);
			}
		}else{
			for (var intLoop = deb; intLoop < fin+1; intLoop++)
			tmp += '<option value="'+intLoop+'"' + (this.date_now.year == intLoop ? 'Selected' : '') + '>'+intLoop+'</option>';	
		}
		return tmp;
	}
	
	this.td_jours = function (){
		var tmp='';
		for (var intLoop = 0; intLoop < this.days_str.length; intLoop++)
		tmp += '<td>' + this.days_str[intLoop].substr(0,3) + '</td>';
		return tmp;
	}
	
	this.lst_jours = function (){
		var tmp='';
		for (var intWeeks = 0; intWeeks < 6; intWeeks++){
			tmp += '<tr>';
			for (var intDays = 0; intDays < this.days_str.length; intDays++)tmp += '<td ></td>';
			tmp += '</tr>';
		}
		return tmp;
	}
	
	this.efface = function (){
		this.elem_txt[0].value = '';
	}

	this.checkClick = function(e,el_txt){		
		if(!calendrier || !calendrier.elem || !calendrier.elem.id)return;
		var el = (nav == "Net")?e.target:event.srcElement;	
		if(el.offsetParent && calendrier.one_elem_txt.name && el.name!=calendrier.one_elem_txt.name && el.id != calendrier.elem.id && el.id != 'eff' && el.id != 'cal_format' && el.id != 'cal_month' && el.id != 'cal_year' && el.tagName != 'OPTION' && el.offsetParent.id != 'calendrier')calendrier.HideCalendar();
		
	}
	
	///Initialise les 3 listes <select> (des jours, mois , et années)
	///id_delect : liste des id des 3 selects a implementer dans l'ordre ex: 'jour, mois, annee'	
	/// deb: number : l'année de debut 
	/// fin: number : l'année de fin
	/// date_init: date initialisant les selects ('j,m,a')
	this.implementSelect = function(id_select,deb,fin,date_init)
	{		
		var an_deb = (deb)?deb:1900;
		var an_fin = (fin)?fin:2050;
		elem_sel = id_select.split(',');
		this.date_now = (date_init)?new getNewDate(date_init):new getNewDate();	
		for(var i=0;i<elem_sel.length && document.getElementById(elem_sel[i]);i++){			
			switch(i){
				case 0:						
					this.opt_jours(this.date_now.year, this.date_now.month, this.date_now.day,document.getElementById(elem_sel[i]));	
				break;
				case 1:
					this.opt_mois(document.getElementById(elem_sel[i]));					
				break;
				case 2:
					this.opt_annee(an_deb,an_fin,document.getElementById(elem_sel[i]));
				break;
			}
		}
	}
	
	///Met à jour la liste des jours suivant la selection de l'année ou du mois, a placer sur le onChange du select mois et année
	///id_select_jour: id du select listant les jours 
	///m: value du select mois
	///a: value du select année	
	this.majSelectJour = function(id_select_jour, m, a)
	{			
		this.opt_jours(a, m, document.getElementById(id_select_jour).value,document.getElementById(id_select_jour));
	}
	
	this.init((lang == null || lang=='')?'en':lang);
	document.onclick = this.checkClick;	
}
/////////// FIN CALENDRIER



////// popup
function popupCenter(add,winName,popup_width,popup_height,features) {
        var fn = window.open(add,winName,'width='+popup_width+',height='+popup_height+',top='+(screen.height-popup_height)/2+',left='+(screen.width-popup_width)/2+','+features+'');
        fn.focus();
}

//////////////////////////////////////////recherche et selectionne l'option d'un select de la valeur correspondante
function selectionneOption(sel, val) {
      for (var i=0; i<sel.length;i++) {		
         if (sel.options[i].value == val) {            
             sel.options[i].selected = true;
			 break;
         }
      }
}

///////recherche et selectionne le bt radio de la valeur correspondante
function selectionneRadio(rad, val) {
      for (var i=0; i<rad.length;i++) {		
         if (rad[i].value == val) {            
             rad[i].checked = true;
			 break;
         }
      }
}

//////recherche et renvoie la valeur de bt radio
function checkRadio(radio) {
      for (var i=0; i<radio.length;i++) {
         if (radio[i].checked) {            
           return radio[i].value;
         }
      }
	  return "";
}

//////remplace tous les caractères 'str_old' de 'string' par 'str_new'
function replaceAll(string, str_old, str_new){
	var reg = new RegExp(str_old,"g");	
	return string.replace(reg,str_new);
}

//////supprimer les espaces devant et derriere txt
function trim(txt){
	var txt=txt;
	var reg=new RegExp("^( )*|( )*$", "g");
	return txt.replace(reg,'');
}	

//////supprimer les balises html 
function supBaliseHtml(txt){
	var reg=new RegExp('<[^>]*>', "g");
	return txt.replace(reg,'');
}	

///
function defilBand(div1, div2){	
	var g = $('#'+div1)[0];
	var c = $('#'+div2).width();						
	if(g!=null){		
		var m = g.offsetWidth;			
		g.style.left = "0px";			
		if(m > c)setTimeout(function(){meescr_v2(g,c,m,0,true);}, 3000);
	}
}
function meescr_v2(g,c,m,cu,mg) {
	var dist = 0;
	var change = false;		
	if(mg) {
		dist = cu - (c - m);
	} else {
		dist = 0 - cu;
	}
	if(dist < 1)change = true; 	
	dist = Math.sqrt(dist / 5);	
	if(mg) {
		cu -= dist;
		g.style.left = Math.floor(cu) + "px";
	} else {
		cu += dist;
		g.style.left = Math.floor(cu) + "px";
	}	
	if(change) {
		mg = !mg;
		setTimeout(function(){meescr_v2(g,c,m,cu, mg);}, 1500);
	}else{
		setTimeout(function(){meescr_v2(g,c,m,cu, mg);}, 50);
	}
}	

var mgright=true;
var cur = 0;
function meescr() {
	var dist = 0;
	var change = false;		
	if(mgright) {
		dist = cur - (cs - ms);
	} else {
		dist = 0 - cur;
	}
	if(dist < 1)change = true; 	
	dist = Math.sqrt(dist / 5);	
	if(mgright) {
		cur -= dist;
		gmt.style.left = Math.floor(cur) + "px";
	} else {
		cur += dist;
		gmt.style.left = Math.floor(cur) + "px";
	}	
	if(change) {
		mgright = !mgright;
		setTimeout("meescr();", 2000);
	}else{
		setTimeout("meescr();", 50);
	}
}	
//

function escapeDoubleQuotes( s ) {
var str = String( s );
return str.replace( /"/g, '&quot;' );
}

function raffraichi_lien(id_ifr) {	
	if($('#'+id_ifr)[0]) $('#'+id_ifr)[0].src = $('#'+id_ifr)[0].src;
}
/*	
function lienSponsor(){	

	if( zSr != null ) {		
		$('#framerlink_spon').show();		
		var k,l=0;		
		if(zSr.length>6 && zSr.length>6){
			for( k=6; k < zSr.length; k += 6 ) {
				document.write('<div style="margin:5px 5px ;font-family:verdana;font-size:10px;border-bottom:1px solid #dddddd">');
				document.write('<a href="'+zSr[k+2]+'" target="_blank" style="font-weight:bold;color:#4dac26" title="'+escapeDoubleQuotes(zSr[k] + ' - ' + zSr[k+4])+'">'+zSr[k+3]+'</a><br/>' );
				document.write('<a href="'+zSr[k+2]+'" target="_blank" title="'+escapeDoubleQuotes(zSr[k] + ' - ' + zSr[k+4])+'">'+zSr[k] + '</a><br/>' );
				document.write('<a href="'+zSr[k+2]+'" target="_blank" class="new_lien_a"  title="'+escapeDoubleQuotes(zSr[k+4])+'">' + zSr[k+4] +'  >></a><br/><br/>' );
				document.write('</div>');
			}
			return true
		}else{
			$('#framerlink_spon').hide();
			return false;
		}
	}	
}



//var mapkey=[{title: 'Numerique', keywords: 'webcam, ecran plasma, enceinte, appareil photo, lecteur dvd'},{title: 'Beauté', keywords: 'soin visage, massage, spa, produit beaute, stress'}];
function lstHotSpot(str_ville, page_r, inline){	
	var css, sep = '';	
	if(inline){ css = ";display:inline"; sep='&nbsp;&bull;&nbsp;';}	
	
	if( mapkey != null ) {	 
		for(var k=0; k < mapkey.length; k++) {	
			document.write('<ul style="margin:0 0 0 15px;padding:0;list-style-image: url(/x/v2/i/Interface/carre_o.gif);list-style-position: outside;"><li style="font-family:Verdana, Arial, Helvetica, sans-serif;padding:0px;margin:0;color:#0E4076;font-weight:bold;font-size:10px" >'+mapkey[k]['title']+'</li></ul>');			
			var tab_tmp = mapkey[k]['keywords'].split(',');
			document.write('<ul style="margin:0 0 0 18px;padding:0;list-style-position: outside;list-style-type: disc;">');
			for(var i=0;i<tab_tmp.length;i++){	
				document.write('<li  style="'+css+'">'+sep);
				document.write('<a  class="lien_spons" href="Z?out=2;xsl=hotspot;hot='+encodeURI(trim(tab_tmp[i]))+';ville='+encodeURI(str_ville)+';page_r='+page_r+'" class="lien_lst_hot" title="'+tab_tmp[i]+'">'+trim(tab_tmp[i])+'</a>' );
				document.write('</li>');
			}					
			document.write('</ul><br/>');
		}
	}
}


*/
function lienHotSpot(){	
	if( zSr != null && zSr.length>6) {
	if($('#framer2lst_hot'))$('#framer2lst_hot').show();
	var k,l=0;
		for( k=6; k < zSr.length; k += 6 ) {													
			document.write('<div  style="margin:0 5px ;font-family:verdana;font-size:10px;border-bottom:1px solid #dddddd">');
			document.write('<a href="'+zSr[k+2]+'" target="_blank" style="font-weight:bold;color:#4dac26" title="'+escapeDoubleQuotes(zSr[k] + ' - ' + zSr[k+4])+'">'+zSr[k+3]+'</a><br/>' );
			document.write('<a href="'+zSr[k+2]+'" target="_blank" title="'+escapeDoubleQuotes(zSr[k] + ' - ' + zSr[k+4])+'">'+zSr[k]+'</a><br/>' );
			document.write('<a href="'+zSr[k+2]+'" target="_blank" class="new_lien_a"  title="'+escapeDoubleQuotes(zSr[k+4])+'">'+zSr[k+4]+'>></a><br/><br/>' );
			document.write('</div><br/>');
		}
	}else{
		if($('#framer2lst_hot'))$('#framer2lst_hot').hide();
	}
}

function mLgd() {
	popup('S?ssl=x1&amp;raw_file=v2/legende&amp;out=2&amp;xsl=8', 'legende', 'width=500,height=430,scrollbars=no');
}

function enableIGN(){}
function disableIGN(){}
function enableCityMap(){}
function disableCityMap(){}

function checkFormMatch(f, page_stat){
	if(f.gc.value=='')f.gc.value='1';
	if(f.tr.value=='')f.tr.value='2';
	xt_med('C', '14', 'match.com::'+page_stat, 'S');
}
function checkAge(f){
	if(Number(f.uage.value) < Number(f.lage.value))f.uage.value=f.lage.value;										
}
/*
Dans quel cas ids est il utilisé?
il est maintenant utilisé, renvoi le nom ou ids
*/
function get_me_pois(nom,ids){
	var partenaires = {mcdo:'4230',bnp:'4298',accor:'1434',total:'4338',lastminute:'4546'}
	if(ids && ids!='') for(var prop in partenaires){if(partenaires[prop]==ids)return prop;}	
	if(nom && nom!='') return partenaires[nom];
}
/*
function = crée un clignotant sur le fond d'un element html
el [ElementHTML]= element html
interval [entier]= frequence du clignotant
duree [entier]= durée clignotant (si le numeric est 'paire' la fin du clignotant s'arrete sur la couleur de fond d'origine)
color [string](#FFFFFF)= couleur du fond clignotant 
*/
function flashError(el,interval,duree,color){	
	var tmp,cpt=0;	
	var bg = el.style.background;
	tmp = setInterval(function(e){if(cpt++>duree)clearInterval(tmp);el.style.background=(cpt%2!=0)?color:bg;},interval,el);	
}
/*
Créer un tableau multi-dimensionel  à partir d'un tableu simple et d'un entier.
numb:entier
theArray: tableau uni-dimensionel
*/
function arraySlicer(numb, theArray){
	var slicedArray = [];
	var index = -numb;
	while((index+=numb)<theArray.length){
    	    slicedArray.push(theArray.slice(index, index+numb));
	};
	return slicedArray;
}
function sortByOrdre(a,b){
    return a.ordre - b.ordre ;
}
/********************************************************************
Le code ci après permet de créer un marsque sur un div cible.
Lors de son instanciation, le marsque s'adapte  à la taille du div qu'il doit masquer.
Le div cible prend une classe masked qui rend sa position relative.

Pour créer un masque, utiliser la fonction create_masker(target), target étant un objet JQuery.
kill_masker détruit le masque et l'instance de l'objet masque.

Attention, l'objet n'est pas encore un singleton, ne l'instancier qu'une seule fois.
*********************************************************************/
mappy_masker = function(jq_el, html){
	var target_el = jq_el;
	if($(".masker").length==0){
		var h = target_el[0].offsetHeight;
		var w = target_el[0].offsetWidth;
		target_el.addClass("masked");
		setMask = function(){
			target_el.prepend("<div class=\"masker\" style=\"width:"+w+"px; height:"+h+"px\"><div onclick=\"kill_masker()\" class=\"masker_fermer\">x fermer</div>"+html+"</div>");
		}
		setMask();
	}
	return {
		w:w,
		h:h,
		remove_mask:function(){// Retire la class à la cible, retire le noeud masque de la cible.
			var div_masker = $(".masker");
			target_el.removeClass("masked");
			target_el[0].removeChild(div_masker[0]);
		},
		resize_mask:function(w, h){// Si la taille du div cible change , on peut utiliser cette méthode pour chnager la taille du masque.
			var temp_div = $(".masker");
			temp_div.width(w);
			temp_div.height(h);
		}
	}
}
function kill_masker(){// on détruit le noeud masque et l'objet mask pour éviter les fuites de mémoire.
	mappyMask.remove_mask();
	delete mappyMask;
}
function create_masker(target){
	mappyMask = new mappy_masker(target);
}

/*****DIV de chargement*/


function showDivLoad(id_el){	
	if(!$('#'+id_el)[0])return false;	
	var el=$('#'+id_el);
	var h=el.height();
	var w=el.width();
	var dl=null;	
	if($('#'+id_el+'_divloader')[0]){
		dl=$('#'+id_el+'_divloader').show();
		if(IE && !IE7)dl.find('#'+id_el+'_divloaderfond').height(h+"px").width(w+"px");
		//if(!IE)dl.find('img').css("filter","").src("/x/v2/i/Interface/loader.png");
		return true;
	}
	
	dl=$('<div id="'+id_el+'_divloader"  class="divloader" >'+
				'<div id="'+id_el+'_divloaderfond" class="divloaderfond"></div>'+
				'<div id="'+id_el+'_divloaderlogo" class="divloaderlogo" >'+
					'<object id="logo_loader" width="40" height="40" swmodifyreport="TRUE" menu="FALSE" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">'+
					'<param value="/x/v2/i/swf/loader_logo.swf" name="src"/>'+
					'<param value="always" name="allowScriptAccess"/>'+
					'<param value="autohigh" name="quality"/>'+
					'<param value="true" name="loop"/>'+
					'<param value="true" name="play"/>'+
					'<param value="false" name="menu"/>'+
					'<param value="transparent" name="wmode"/>'+
					'<embed width="40" height="40" allowscriptaccess="always" wmode="transparent" quality="autohigh" loop="true" play="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave" swmodifyreport="TRUE" menu="FALSE" src="'+base_url_static+'/x/v2/i/swf/loader_logo.swf"/>'+
					'</object>'+
				'</div>'+
		'</div>');	
	el.append(dl.show());
	if(IE && !IE7)setTimeout(function(){$('#'+id_el+'_divloaderfond').height(h+'px').width(w+'px');$('#'+id_el+'_divloader').height(h+'px').width(w+'px');},50);
	//if(!IE)dl.find('img').css("filter","").src("/x/v2/i/Interface/loader.png");		
				
	return true;
}


function hideDivLoad(id_el){
	if(!$('#'+id_el)[0])return false;		
	$('#'+id_el+'_divloader').hide();
}

/**********************/








/***************1.0.13.js**************/
function regAdr(wn,tn,sn,pc,cc,dom) {
	wn = String(wn).trim();
	tn = String(tn).trim();
	sn = String(sn).trim();
	pc = String(pc).trim();
	cc = String(cc).trim();
	var old_cookies = document.cookie;
	var curPos = 0;
	var odate = new Date();
	odate.setTime(odate.getTime()-(24*60*60*1000*100));
	var d = new Date();
	d.setTime(d.getTime()+(24*60*60*1000*100));
	while(curPos != -1) {
		curPos = old_cookies.indexOf("adr", curPos);
		if(curPos != -1) {
			ePos = old_cookies.indexOf("=", curPos + 3);
			if(ePos > curPos) {
				nI = old_cookies.substring(curPos + 3, ePos);
				cnt++;
			}
			curPos = ePos;
			ePos = old_cookies.indexOf(";", curPos + 1);
			if(ePos == -1) ePos = old_cookies.length;
			if(ePos > curPos) {
				value = old_cookies.substring(curPos + 1, ePos);
				sCk("adr" + nI + "=null", odate, "/", dom);
				sCk("adr" + nI + "=" + value, d, "/user-addresses", dom);
			}
			curPos = ePos;
		}
	}
	var c = cookieAddresses;
	var found = "";
	var curPos = 0;
	var fA = "";
	var nI = "0";
	var cnt = 0;
	var free = new Array(11);
	for(i=0;i<11;i++) free[i] = true;
	while(curPos != -1) {
		curPos = c.indexOf("adr", curPos);
		if(curPos != -1) {
			ePos = c.indexOf("=", curPos + 3);
			if(ePos > curPos) {
				nI = c.substring(curPos + 3, ePos);
				free[eval(nI)] = false;
				cnt++;
				if(fA.length == 0) fA = nI;
			}
			curPos = ePos;
			ePos = c.indexOf(";", curPos + 1);
			if(ePos == -1) ePos = c.length;
			if(ePos > curPos) {
				value = c.substring(curPos + 1, ePos);
				var oa = value.split("|");
				if(oa.length == 5 && wn == oa[0] && tn == oa[1] && sn == oa[2] && pc == oa[3] && cc == oa[4]) {found=nI;}
			}
			curPos = ePos;
		}
	}
	if(found.length == 0) {
		if(cnt > 10) {
			var odate = new Date();
			odate.setTime(odate.getTime()-(24*60*60*1000*100));
			sCk("adr" + fA + "=null", odate, "/user-addresses", dom);
		}
	} else {
		var odate = new Date();
		odate.setTime(odate.getTime()-(24*60*60*1000*100));
		sCk("adr" + found + "=null", odate, "/user-addresses", dom);
	}
	var d = new Date();
	d.setTime(d.getTime()+(24*60*60*1000*100));
	if(cnt > 10) {
		nI = fA;
	} else {
		for(i=0;i<11;i++) {if(free[i]) break;}
		nI = i;
	}
	sCk("adr" + nI + "=" + wn + "|" + tn + "|" + sn + "|" + pc + "|" + cc, d, "/user-addresses", dom);
}
function createDropDown(d,f,init){
	var tmp='';
	var val="";
	for(var i=d;i<=f;i++){
		if(String(i).length==1){
			val = String("0"+i);
		} else {
			val = i;
		};
		tmp += '<option value="'+(i)+'"' +	(init == i ? 'Selected' : '') + '>'+val+'</option>';
	}
	return tmp;
}
function sCk(s,d,p,dom) {
	if(dom && dom.length > 0) dom = "domain=" + dom + ";"; else dom = "";
	document.cookie = s + ";expires=" + d.toGMTString() + ";path=" + p + ";" + dom;
}
function sCk2(s,p,dom) {if(dom && dom.length > 0) dom = "domain=" + dom + ";"; else dom = "";document.cookie = s + ";path=" + p + ";" + dom;}
function regMM(uid,s,dom) {var d=new Date();if(s)d.setTime(d.getTime()+(30*24*60*60*1000));else d.setTime(d.getTime()-(30*24*60*60*1000));sCk('mmuid='+uid, d, '/user-addresses', dom);if(!s) sCk('mmsuid='+uid, d, '/', dom); else sCk2('mmsuid='+uid, '/', dom);}
/*
recupere, le cookie 'v' et renvoi sa valeur sinon vide
	//v = nom du cookie
*/
function rc(v) {
	var ck=""+document.cookie;
	var ind=ck.indexOf(v);
	if(ind==-1 || v=="") return ""; 
	var ind1=ck.indexOf(';',ind);
	if(ind1==-1) ind1=ck.length; 
	return unescape(ck.substring(ind+v.length+1,ind1));
}

function mm_disconnect(h,dom) {
	ck=new Array();
	if(h==1){ 
		document.location=mappy_server+'/sid'+mappy_sid+'X?out=302&xsl=mappymoi&act=clear&mmuid=&login=&email=&url=' +escape('D?out=2');
	} else {
		var img=new Image();img.src=mappy_server+'/sid'+mappy_sid+'X?out=0&xsl=mappymoi&act=clear&mmuid=&login=&email=&r'+Math.floor(Math.random()*10000000);
		findDOM('mm_email').value=findDOM('mm_email').attributes["default"].value;
		findDOM('mm_password').value=findDOM('mm_password').attributes["default"].value;	
		findDOM('mm_connex').className='form';
		//alert(islogged);
		islogged=0;
	}
	regMM('0',false,dom);
}
function mm_connect(f,dom) {
	if(checkDefault(f)){
		if(f.index.value==1 || String(document.location).indexOf("www.mappy.com")!=-1)
			return true; 
		else 
			findDOM('ilog').src=mappy_server+'/sid'+mappy_sid+'X?out=2&xsl=mm_autologin_html&act=login&login='+f.email.value+'&password='+f.password.value; 
		return false;
	}
}
function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id)
}

function resizeIframe(frameid){
var f = document.getElementById(frameid);
if(f.getAttribute('max_height'))
	mh = f.getAttribute('max_height');
else
	mh = 1000;
var h = "";
if (f.contentDocument) {
    h = f.contentDocument.documentElement.offsetHeight;
} else if (f.contentWindow) {
    h = f.contentWindow.document.body.scrollHeight;
    w = f.contentWindow.document.body.scrollWidth;
} else {
    return;
}
f.setAttribute("height",Math.min(mh,h));
f.style.height=Math.min(mh,h) + "px";
if(f.addEventListener)
f.addEventListener("load", readjustIframe, false)
else if (f.attachEvent){
f.detachEvent("onload", readjustIframe)
f.attachEvent("onload", readjustIframe)
}
}

function readjustPub(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot) resizePub(iframeroot.id)
}

function resizeTotem(pubid){
	if($('#'+pubid)[0])$('#'+pubid).height("300px");
}

function resizePubV2(pubid,type){	
	var f = window.frames[pubid];
	var h = "";
	var w = "";	
	switch (type) {
		case 'top':
			h=90;
			w=728;
		break;
		case 'middle':
			h=250;
			w=300;
		break;	
	} 
	
	if(f.document.body.innerHTML.indexOf('empty.gif')==-1){
		document.getElementById(pubid).style.height=h+"px";
		document.getElementById(pubid).style.width=w+"px";	
	}
	/*
	if(f.addEventListener)
		f.addEventListener("load", readjustPubV2, false);
	else if (f.attachEvent){
		f.detachEvent("onload", readjustPubV2);
		f.attachEvent("onload", readjustPubV2);
	}
	*/
}

function readjustPubV2(loadevt) {
	var crossevt=(window.event)? event : loadevt;
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement;
	//alert(iframeroot.id);
	if (iframeroot) resizePubV2(iframeroot.id);
}

function resizePub(pubid){
	
	var f = document.getElementById(pubid);
	var h = "";
	if (f.contentDocument) {
		h = f.contentDocument.documentElement.offsetHeight;
	} else if (f.contentWindow) {
		h = f.contentWindow.document.body.scrollHeight;
	} else {
		return;
	}
	
	fCnt = document.getElementById('mFrmCnt');
	if(h>=80) {
		fCnt.className='mega';
		fCnt.style.height="90px";
		fCnt.style.width="728px";
		fCnt.style.marginTop="0px";
		fCnt.style.marginRight="0px";
		fCnt.style.marginBottom="10px";
		fCnt.style.marginLeft="270px";
		f.style.height="90px";
		f.style.width="728px";
	} else if(h>=50) {
		fCnt.className='normal';
		fCnt.style.height="60px";
		fCnt.style.width="468px";
		fCnt.style.marginTop="15px";
		fCnt.style.marginRight="160px";
		fCnt.style.marginBottom="15px";
		fCnt.style.marginLeft="270px";
		f.style.height="60px";
		f.style.width="468px";
	} else {
		fCnt.className='';
		fCnt.style.height="30px";
		fCnt.style.width="0px";
		fCnt.style.marginTop="0px";
		fCnt.style.marginRight="0px";
		fCnt.style.marginBottom="0px";
		fCnt.style.marginLeft="0px";
		f.style.height="0px";
		f.style.width="0px";
	
	}
	if(f.addEventListener)
		f.addEventListener("load", readjustPub, false)
	else if (f.attachEvent){
		f.detachEvent("onload", readjustPub)
		f.attachEvent("onload", readjustPub)
	}
}

function showSpLinks(){
	if(document.getElementById('mSp_Links')){
		document.getElementById('mSp_Links').style.display='block';
	}		
}

function resizeMe(frameid, max_height, esp_sup){	
	var ifrm=document.getElementById(frameid);
	var esp_sup = (esp_sup)?esp_sup:0;
	if (ifrm && !window.opera){
		ifrm.style.display="block";
		if(window.opera){
			ifrm.height = max_height;
		}else if(ifrm.contentDocument && ifrm.contentDocument.body.offsetHeight){
			  h = Math.min(((max_height)?max_height:ifrm.contentDocument.body.offsetHeight),ifrm.contentDocument.body.offsetHeight)+esp_sup;
			  ifrm.height = h;
			  ifrm.style.height = h+'px';
		}else if(ifrm.Document && ifrm.Document.body && ifrm.Document.body.scrollHeight){
			 h = Math.min(((max_height)?max_height:ifrm.Document.body.scrollHeight),ifrm.Document.body.scrollHeight);
			 ifrm.height = h;
			 ifrm.style.height = h+'px';
		}
	}
}

function readAdr(cookieAddresses) {
	oS = new Array();
	oV = new Array();	
	var c = cookieAddresses;	
	var cP = 0;
	var fA = "";
	var nI = "0";
	while(cP != -1) {
		cP = c.indexOf("adr", cP);
		if(cP != -1) {
			eP = c.indexOf("=", cP + 3);
			cP = eP;
			eP = c.indexOf(";", cP + 1);
			if(eP == -1) eP = c.length;
			if(eP > cP) {
				value = c.substring(cP + 1, eP);
				var oa = value.split("|");
				if(oa.length == 5) {
					dS = '';
					if(oa[0].length > 0) dS = oa[0] + ", ";
					if(oa[1].length > 0) dS += oa[1];
					if(oa[3].length > 0) dS += " (" + oa[3] + ")";
					if(oa[2].length > 0) dS += ", " + oa[2];
					oS.push(dS);
					oV.push(oa);
				}
			}
			cP = eP;
		}
	}
	return new Array(oS.reverse(),oV.reverse());
}

function getCookieMappy(n_cook) {
	var cc= '';
	if(typeof cookieAddresses != 'undefined' && cookieAddresses!=''){
		var coo = cookieAddresses+';';	
		var idx = coo.indexOf(n_cook+"=");
		if(idx!=-1){
			cc = coo.substring(idx+((n_cook+"=").length),coo.indexOf(';', (idx+((n_cook+"=").length)-1)));
		}
	}	
	return cc;	
}

function adInit(){

var offx=1,offy=1;
var elt=findDOM('mPubContent');
var pub=findDOM('mPubIContent');
if(elt && elt.offsetParent) {
	pub.style.top=elt.offsetTop+elt.offsetParent.offsetTop+1+"px";
	pub.style.left=elt.offsetLeft+elt.offsetParent.offsetLeft+1+"px";
	pub.style.display='block';

}
/**/
var eltPM=findDOM('mPMPubHP');
var pubPM=findDOM('mPMIContent');
if(eltPM) {pubPM.style.top=eltPM.offsetTop+eltPM.offsetParent.offsetTop+"px";pubPM.style.left=eltPM.offsetLeft+eltPM.offsetParent.offsetLeft+"px";pubPM.style.display="";}
}
function active(elt) {var s=elt.className;elt.className=s.replace("nf", "wf");if(elt.attributes["default"]) if(elt.value==elt.attributes["default"].value){elt.value="";}}
function check(elt) {if(elt.value.length==0){var s=elt.className;elt.className=s.replace("wf", "nf");if(elt.attributes["default"]) elt.value=elt.attributes["default"].value;}}
function checkDefault(form) {for(i=0;i<form.elements.length;i++) {if(form.elements[i].attributes["default"] && form.elements[i].attributes["default"].value && form.elements[i].value == form.elements[i].attributes["default"].value) {form.elements[i].value='';}}return true;}
//var Mappy = new Object();
var FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver;
	this.align = "middle";
	this.params = new Object();
	this.variables = new Object();
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";	
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
}

var FOP = FlashObject.prototype;
FOP.addParam = function(name, value) { this.params[name] = value; }
FOP.getParams = function() { return this.params; }

FOP.getParam = function(name) { return this.params[name]; }

FOP.addVariable = function(name, value) { this.variables[name] = value; }

FOP.getVariable = function(name) { return this.variables[name]; }

FOP.getVariables = function() { return this.variables; }

FOP.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    return (paramTags == "") ? false:paramTags;
}

FOP.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs()) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        if (this.getParamTags()) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    return flashHTML;	
}

FOP.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) { 
    	variablePairs.push(name + "=" + escape(this.getVariable(name))); 
    }
    return (variablePairs.length > 0) ? variablePairs.join("&"):false;
}

FOP.write = function(elementId, altText) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else if (altText) {
			if (elementId) {
				document.getElementById(elementId).innerHTML = altText;
			} else {
				document.write(altTxt);
			}
		}
	}		
}

FOP.write_eval = function(elementId, evalFunction) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else if(evalFunction) {
			eval(evalFunction);
		}
	}		
}



//Nous utilisons ce flash pour éviter les conflits avec les js partenaire qui utiliseraient aussi des objets flashObject.
// Cette classe est amenée à remplacer définbitivement celle définie plus haut.
var MappyFlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver;
	this.align = "middle";
	this.params = new Object();
	this.variables = new Object();
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";	
	if (c) this.color = this.addParam('bgcolor', c);	
	this.addParam('quality', 'high');
	this.doDetect = getQueryParamValue('detectflash');
}


//heritage des props de FlashObject
var FOPoi = MappyFlashObject.prototype;
$.extend(FOPoi, FOP);

var _flVersion = -1;
function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			var y = x.description;
   			flashversion = y.charAt(y.indexOf('.')-1);
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	_flVersion = flashversion;
	return flashversion;
}

function detectFlash(ver) {	return (_flVersion > -1) ? (_flVersion >= ver) ? true:false : (getFlashVersion() >= ver) ? true:false; }

// get value of query string param
function getQueryParamValue(param) {
	var q = document.location.search || document.location.href.split("#")[1];
	if (q) {
		var detectIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
		if (q.length > 1 && detectIndex > -1) {
			return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
		} else {
			return "";
		}
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}


function showP(num) {if(typeof(flashProxy)!="undefined" && typeof(flashProxy.uid)!="undefined"){flashProxy.call("mapref.goToPuce", num);}}
function fP(c){if(typeof(flashProxy)!="undefined" && typeof(flashProxy.uid)!="undefined"){flashProxy.call(c);}}

function find_meteo_vars(xml, tc) {
	var picto = "";
	var temp = "";
	$("meteo/PREV", xml).each(function(e) {
		if(picto == "" && $("ZONE", this).text() == tc) {
			picto = $("PICTO", this).text();
			temp = $("T", this).text();
		}
	});
	return {picto:picto, temp:temp};
}
function setVille (tc, slot){
	//document.ambIti["tc"+slot].value=tc;
	document.ambiguite["tc"+slot].value=tc;
	//document.ambIti["a10"+slot].value="";
	document.ambiguite["a10"+slot].value="";
	//alert("tc"+slot+": "+tc);
	
}
function setLieuDit (tc, slot){
	//alert("ok lieu dit");
	//document.ambIti["tc"+slot].value="";
	//document.ambIti["a10"+slot].value=tc;
	
	document.ambiguite["tc"+slot].value="";
	document.ambiguite["a10"+slot].value=tc;
	//alert("a10"+slot+": "+tc);/**/

}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
	Classe qui nous permet de gérer les appels de fonction au chargement de la page.		
	L'intéret de cette classe est que l'on peut collecter des appels de fonctions de n'importe où, sans avoir à toucher à la balise onload et onunload du body du controlleur de la page.
	Cette fonction ressemble un peu à à la fonction ready de jquery a la différence qu'il est directement appelé  par l'évènement onload ou unonload du body de la page.
*/
function window_event_manager(){
	// notre todo list.
	var array_calls = new Array();
	return {
		addRequest:function(fnct,ar_args){
			array_calls.push((fnct)?fnct:function(){});
			array_calls.push((ar_args)?ar_args:[]);
		},
		send_requests:function(){
			// on execute a chaque fois le premier élément du tableau puis on le retire de notre todo list.
			var test_array = array_calls;
			while(array_calls.length>0){
				array_calls[0].apply(null,array_calls[1]);
				array_calls.shift();
				array_calls.shift();
			}
		},
		get_nb_calls:function(){
			return array_calls.length/2;
		},
		clear_calls:function(){
			return array_calls.length=0;
		}
	}
}

function send_window_event_requests(){
	// on vérifie que l'objet exist sinon on ne fait rien.
	if(typeof(w_event_mgr)=='object'){
		w_event_mgr.send_requests();
	} else {
		throw new Error("w_event_mgr abstent");
	}
}

function get_nb_onload_rqst(){
	// on vérifie que l'objet exist sinon on ne fait rien.
	if(typeof(w_event_mgr)=='object'){
		return w_event_mgr.get_nb_calls();
	}
}

var w_event_mgr = new window_event_manager();

///////////////////////////////////////////class controlent la liste des pages visitees

var PageVisited = {	
		no_add:new Array('hp','plan','iti','plan_fiche','perso_poi','meteo')
		,		
		loadPageVisited:function () {//retourne un json contenant les pages visitees (provenant du cookie)
			if(!rc("PV") || rc("PV")==';'){
				var obj = {'lst':new Array('hp',mappy_server+'/sid'+mappy_sid+'Z?out=2&xsl=hp&fb='+((mappy_server.indexOf('mappy.com')!=-1)?'http://www.mappy.com':mappy_server))};
			}else{
				var obj = $.parseJSON(rc("PV"));
			}
			return obj;
		}
		,	
		savePageVisited:function (obj,page,url) {//obj.lst.contains(xsl)!=-1   xsl,encodeURIComponent('/z?out=2&xsl='+xsl)	
			this.addPageVisited(obj,page,url);			
			sCk2("PV=" + $.toJSON(obj), "/");
			sCk2("PV=" + $.toJSON(obj), "/" ,((mappy_server.indexOf('mappy.com')!=-1)?'mappy.com':''));
			return obj;			
		}
		,		
		addPageVisited:function (obj,page,url) {			
			var id_page = this.getPageIdTrad((typeof page=='undefined' || page=='')?xsl:page);
			if(page!='' && lst_nom_page_visit[id_page]){							
				var url = (typeof url=='undefined' || url=='')?encodeURIComponent(document.location.href.replace(/;/gi,"&")):encodeURIComponent(url.replace(/;/gi,"&"));			
				var idx = obj.lst.contains(id_page);
				if(idx !=-1)obj.lst.splice(idx,2);
				obj.lst.push(id_page);
				obj.lst.push(url);
			}
		}
		,
		getPageIdTrad:function (n_xsl) {
			if(n_xsl=='2' || n_xsl=='iti')return 'iti';			
			if(n_xsl=='1'|| n_xsl=='plan')return 'plan';			
			if(n_xsl=='8'){
				reg = new RegExp("raw_file=v2/([a-z0-9]*)","g"); 
				reg.exec(document.location.search);	
				if(document.location.search.match(reg)) return '8_'+RegExp.$1;					
			}			
			if(n_xsl=='mappymoi'){
				reg = new RegExp("mms=([a-z0-9]*)","g"); 
				reg.exec(document.location.search);	
				if(document.location.search.match(reg) && (RegExp.$1=='90041' || RegExp.$1=='90041s')) return 'mappymoi_'+RegExp.$1;
			}
			return n_xsl;
		}
		,		
		clear:function () {			
			sCk2("PV=", "/");
			sCk2("PV=", "/" ,((mappy_server.indexOf('mappy.com')!=-1)?'mappy.com':''));
		}
			
			
}


