			/* libraire upg */
			var upgLib = {
				emptyFunction: function() { return false; },

				setOpacity: function(obj, o) {
					obj.style.opacity=(o/100);
					obj.style.filter='alpha(opacity='+o+');';
				},

				getTopPos: function(obj) {
					var r = obj.offsetTop;
					while((obj = obj.offsetParent) != null) r += obj.offsetTop;
					return r;
				},
				getLeftPos: function(obj) {
					var r = obj.offsetLeft;
					while((obj = obj.offsetParent) != null) r += obj.offsetLeft;
					return r; 
				},
				addCSS: function (css) {
					var style = document.createElement('style');
					style.type = 'text/css';
					if (style.styleSheet) {
						style.styleSheet.cssText = css;
					} else {
						style.appendChild(document.createTextNode(css));
					}
				   var b  = document.getElementsByTagName("body").item(0);
				   b.appendChild(style);
				},
				isOpera: navigator.userAgent.toLowerCase().indexOf('opera')>=0,
				disallowPNG: (navigator.appVersion.indexOf('MSIE') != -1) && !this.isOpera
			};

			var screenMask = {
				scrmask: false,
				init: function() {
					this.scrmask = document.createElement('div');
					this.scrmask.id = 'scrmask';
					var b = document.getElementsByTagName("body").item(0)
					b.appendChild(this.scrmask);
					if(upgLib.disallowPNG) upgLib.addCSS('* html #scrmask, * html #popup { background-image: none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/images/site/transparent.png", sizingMethod="scale"); }');
				},
				show: function() { this.scrmask.style.display = 'block'; },
				hide: function() { this.scrmask.style.display = 'none'; },
				height: function(x) { this.scrmask.style.height = x; }
			}; 

			var upgPopup = {
				div: false,
				divC: false,
				close: false,
				title: false,
				content: false,
				move: false,
				moveX: 0,
				moveY: 0,

				init: function() {
					var _this = this;
					this.div = document.createElement('div');
					this.div.id = 'popup';

					var divC = document.createElement('div');
					divC.id = 'popupC';
					this.div.appendChild(divC);
					this.divC = divC;

					this.close = document.createElement('a');
					this.close.href = '#';
					this.close.innerHTML = '&nbsp;';
					this.close.id='closePopup';
					this.close.title = 'Fermer';
					this.close.onclick = function() { _this.hide(); return false; };
					divC.appendChild(this.close);
					
					this.title = document.createElement('div');
					this.title.id = 'popupTitle';
					divC.appendChild(this.title);

					this.content = document.createElement('div');
					this.content.id = 'popupContent';
					divC.appendChild(this.content);
					
					var b = document.getElementsByTagName("body").item(0);
					b.appendChild(this.div);

					// Move
					/*
					this.title.onmousedown = function() { 
						upgPopup.move = true; 
						upgPopup.moveX = mouseX - upgLib.getLeftPos(upgPopup.div);
						upgPopup.moveY = mouseY - upgLib.getTopPos(upgPopup.div);
						upgLib.setOpacity(upgPopup.divC, 70);
					};
					this.title.onmouseup = function() { 
						upgPopup.move = false; 
						upgLib.setOpacity(upgPopup.divC, 100);
					};
					var mm = document.body.onmousemove;

					document.body.onmousemove = function(e) {
						mm(e); 
						try	{
							if(upgPopup && upgPopup.move) {
								upgPopup.div.style.top = (mouseY-upgPopup.moveY) + 'px';
								upgPopup.div.style.left = (mouseX-upgPopup.moveX) + 'px';
							}
						} catch (e) {}
					};
					*/
				},

				setTitle: function(t, c) {
					this.title.innerHTML = t ? t : 'upg';
					this.div.className = c ? c : 'upg';
				},
				setWidth: function(w) {
					this.div.style.width = w+'px';
				},
				show: function(nc) {
					this.hideSelect(true);
					this.div.style.visibility = 'hidden';
					this.div.style.display = 'block';
					this.close.style.display = (nc==true)?'none':'block';
					this.resize();
					this.div.style.visibility = 'visible';
					screenMask.show();
				},
				hide: function() {
					this.clear();
					this.hideSelect(false);
					this.div.style.display = 'none';
					screenMask.hide();
				},
				resize: function() {
					var arrayPageSize = getPageSize();
					var arrayPageScroll = getPageScroll();
					this.div.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 15 - this.div.offsetHeight) / 2) - 10 + 'px');
					this.div.style.left = (((arrayPageSize[0] - this.div.offsetWidth) / 2) + 'px');
					screenMask.height(arrayPageSize[1] + 'px');
				},
				clear: function() {
					var f = null;
					while(f = this.content.firstChild) this.content.removeChild(f);
				},
				hideSelect: function(v) {
					var selects = document.getElementsByTagName("select");
					for (i = 0; i != selects.length; i++) {
						selects[i].style.visibility = v?'hidden':'visible';
					}
				}
			}; 

			/* A SUPPR */

			/*
			* Alertes
			*/
			var upgAlert = {
				buttondiv: null,
				okButton: null,
				cancelButton: null,
				onOK: upgLib.emptyFunction,

				resetFunction: function() { this.onOK = upgLib.emptyFunction; },

				alert: function(msg, title, type) {
					this.resetFunction(); 
					this.confirm(msg, title, type || 'alert', true);
				},

				confirm: function(msg, title, type, justOK) {
					upgPopup.setTitle(title, type);
					upgPopup.content.innerHTML = msg;
					upgPopup.setWidth(410);
					upgPopup.content.appendChild(this.buttondiv);
					
					if (justOK) {
						this.okButton.src = '/images/site/ok.jpg';
						this.okButton.style.left = '0px';
					}

					this.cancelButton.style.display = (justOK)?'none':'inline';
					upgPopup.show(true);
				},

				init: function() {
					var _this = this;
					this.buttondiv = document.createElement('div');
					this.buttondiv.className = 'input';
					
					/*
					var ok = this.okButton = document.createElement('input');
	 				ok.type='button';
					ok.className='btnmain';
					ok.value = 'Oui';
					ok.onclick = function() { upgPopup.hide(); _this.onOK(); };
					*/
					var ok = this.okButton = document.createElement('img');
	 				ok.src='/images/site/yes.jpg';
					ok.style.cursor='pointer';
					ok.style.position='relative';
					ok.style.left='-10px';
					ok.onclick = function() { upgPopup.hide(); _this.onOK(); };
					this.buttondiv.appendChild(ok);

					/*
					var cancel = this.cancelButton = document.createElement('input');
					cancel.type='button';
					cancel.value = 'Non';
					cancel.onclick = function() { upgPopup.hide(); };
					*/
					var cancel = this.cancelButton = document.createElement('img');
	 				cancel.src='/images/site/no.jpg';
					cancel.style.cursor='pointer';
					cancel.style.position='relative';
					cancel.style.left='10px';
					cancel.onclick = function() { upgPopup.hide(); };
					this.buttondiv.appendChild(cancel);
				}

			}; 

			/* 
			* AutoScrolling
			*/
			var Scroll = {
				timer: false,
				dest: false,
				inc: false,
				current: false,
				goToId: function(n) {
					this.goTo($(n));
				},
				goTo: function(e, prec) {
					this.current = getPageScroll()[1];
					this.dest = upgLib.getTopPos(e);
					this.start(prec);
				},
				top: function() {
					this.dest = 0;
					this.current = getPageScroll()[1];
					this.start();
					return false;
				},
				start: function(prec) {
					var p = getPageSize();
					if(this.dest < 0) this.dest = 0;
					if(this.dest > (p[1]-p[3])) this.dest = (p[1]-p[3]);
					this.dest += prec || 0;
					// Calcul de la vitesse
					this.inc = Math.round((this.dest - this.current)/20); 
					// Pas trop lentement
					if(this.inc > -10 && this.inc < 10) this.inc = (this.inc>0)?10:-10;
					var _this = this;
					this.timer = setInterval(function() { _this.step(); }, 10);
				},
				step: function() {
					if((this.inc > 0 && this.current >= this.dest-9) || (this.inc < 0 && this.current <= this.dest+9)) clearInterval(this.timer); 
					else { self.scrollBy(0,this.inc); this.current += this.inc; }
				}
			};

			/* 
			* AutoScrolling
			*/
			var Scroll = {
				timer: false,
				dest: false,
				inc: false,
				current: false,
				goToId: function(n) {
					this.goTo(document.getElementById(n));
				},
				goTo: function(e, prec) {
					this.current = getPageScroll()[1];
					this.dest = upgLib.getTopPos(e);
					this.start(prec);
				},
				top: function() {
					this.dest = 0;
					this.current = getPageScroll()[1];
					this.start();
					return false;
				},
				start: function(prec) {
					var p = getPageSize();
					if(this.dest < 0) this.dest = 0;
					if(this.dest > (p[1]-p[3])) this.dest = (p[1]-p[3]);
					this.dest += prec || 0;
					// Calcul de la vitesse
					this.inc = Math.round((this.dest - this.current)/20); 
					// Pas trop lentement
					if(this.inc > -10 && this.inc < 10) this.inc = (this.inc>0)?10:-10;
					var _this = this;
					this.timer = setInterval(function() { _this.step(); }, 10);
				},
				step: function() {
					if((this.inc > 0 && this.current >= this.dest-9) || (this.inc < 0 && this.current <= this.dest+9)) clearInterval(this.timer); 
					else { self.scrollBy(0,this.inc); this.current += this.inc; }
				}
			};	

var mouseX, mouseY;
function mouseMove(e) {
	// On mémorise les pisitions 
	mouseX = (!document.all) ? e.pageX : event.x+document.body.scrollLeft;
	mouseY = (!document.all) ? e.pageY : event.y+document.body.scrollTop;
}


function getPageScroll(){
	var yScroll;
	var xScroll;
	if (self.pageYOffset) {
		xScroll = self.pageXOffset;
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}

function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
		if(window.scrollMaxY > 0 ) { windowWidth -= 17; }
		if(window.scrollMaxX > 0 ) { windowHeight -= 17; }
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

/* ajax */
function Ajax() {
	this.failed = false;
	this.xmlhttp = null;
	this.method = 'GET';
	this.URLString = null;
	this.timer = null;
	this.nocache = 0;

	this.resetFunction();
}

Ajax.prototype = {
	resetFunction: function() {
		this.onloading = function() { return false; };
		this.onsuccess = function() { return false; };
		this.createAJAX();
	},

	createAJAX: function() {
		this.failed = false;
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}
		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
		
	},

	timerRequest: function(file, time, options) {
		var _this = this;
		this.timer = setInterval(function() { _this.request(file, options); }, time);
	},

	stopTimer: function() {
		clearInterval(this.timer);
	},

	request: function(file, options) {
		if(options) {
			this.onsuccess = options.onsuccess || this.onsuccess;
			this.method = options.method || this.method;
			this.nocache = options.nocache || this.nocache;
		}
		if(!this.failed) {
			if (this.xmlhttp) {
				var self = this;
				if (this.nocache) file += ((file.indexOf('?')==-1)?'?':'&')+"rnd=" + Math.random();
				if (this.method == "GET") {
					this.xmlhttp.open(this.method, file, true);
				} else {
					this.xmlhttp.open(this.method, file, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
						
					} catch (e) { }
				}
				
				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
						case 2:
						case 3:
							self.onloading();
							break;
						case 4:
							self.failed = false;
							self.responseText = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.onsuccess(self.xmlhttp);
					}
				};
				this.failed = true;
				this.xmlhttp.send(this.URLString);
			}
		}

	}
};

function $(elmt) {
	return document.getElementById(elmt);
}

/* récupérer une div par son nom de class */
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|s)" + className + "(s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i ];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

/* charger une fonction au démarrage */
function addLoadEvent(func) {	
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
    	window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function gotoScroll(l) {
	Scroll.goToId(l); //,-80);
}

function initialisation() {
	screenMask.init();
	upgPopup.init();
	upgAlert.init();
	// document.body.onmousemove = mouseMove;	
}

function toggle(id) {
	if (act_height(id)==0) blinddown(id);
	else blindup(id);
}

function act_height(id) {
	/*
	height = $(id).clientHeight;
	if (height==0) {
		height=$(id).offsetHeight;
	}
	
	return height;
	*/
	return height=$(id).offsetHeight;
}

function blinddown(id,speed,func) {
	if(!speed) speed=200;
	acth=act_height(id);
	if (acth==0) {
		maxh=max_height(id);
		$(id).style.display="block";
		$(id).style.height="0px";
		var v;
		v=Math.ceil(speed/maxh);
		for(i=1;i<=maxh;i++) {
			anim("$('"+id+"').style.height='"+i+"px'",v*i);
			if ((i==maxh) && (func)) anim(func,v*i);
		}
	}
}

function reinitialisation(id) {
	$(id).style.display='none';
}

function blindup(id,speed,func) {
	if(!speed) speed=200;
	acth=act_height(id);
	maxh=max_height(id);
	if(acth==maxh) {
		$(id).style.display="block";
		var v;
		v=Math.ceil(speed/acth);
		for(i=0;i<=acth;i++) {
			newh=acth-i;
			anim("$('"+id+"').style.height='"+newh+"px'",v*i);
			if ((i==acth) && (func)) anim(func,v*i);
		}
	}
}

function anim(func,time){
	return window.setTimeout(func,time);
}

function max_height(id) {
	var ids=$(id).style;
	ids.overflow="hidden";
	if(act_height(id)!=0) {
		return act_height(id);
	} else {
		origdisp=ids.display;
		origheight=ids.height;
		origpos=ids.position;
		origvis=ids.visibility;
		ids.visibility="hidden";
		ids.height="";
		ids.display="block";
		ids.position="absolute";
		height=act_height(id);
		ids.display=origdisp;
		ids.height=origheight;
		ids.position=origpos;
		ids.visibility=origvis;
		return height;
	}
}

function popin(t) {

	this.xhttpd = new Ajax();
	this.xhttpd.URLString = 'type='+t;
	this.xhttpd.request('/ajax/popin.php', {method: 'POST'});
	this.xhttpd.onsuccess = function(response) {
		var xml = response.responseXML;
		var popin = xml.getElementsByTagName('popin');

		var title = '';
		var content = '';
		title = popin[0].getElementsByTagName("title")[0].firstChild.nodeValue;
		content = popin[0].getElementsByTagName("content")[0].firstChild.nodeValue;

		var loginform = document.createElement('div');
		loginform.innerHTML = content;
		
		upgPopup.setWidth(800);
		upgPopup.setTitle(title);
		upgPopup.content.appendChild(loginform);
		upgPopup.show();
		
		
	};
}



function showBookmarkLink()
{
   if (window.external || window.sidebar) 
   {
      document.write('<div class="favori" onmouseover ="BulleWrite(\'Ajouter le site aux favoris\',10,10);"><img src="images/antennistes/favoris.png" alt="Telecharger" onclick="favori(\'Carnet du Web\', \'http://\'+ window.location.hostname); return false;" /></div>');
      //document.write('<a href = "#" onclick="bookmarksite(); return false;" class="bookmark_link">AJOUTER A VOS FAVORIS</a>');
   } 
   else 
   {
      document.write('');
   }
} 

function favori(phrase,lien)
{

   if (window.sidebar)
   {
   //window.sidebar.addPanel(phrase, lien,"");
	   
   upgAlert.alert('Pour ajouter la page aux favoris, deux possibilités:<br /><ul><li>Utilisez le raccourci ctrl+D</li><li>Cliquez sur l\'étoile dans la barre d\'adresse</li></ul>', 'Ajouter aux favoris', 'erreur');
   }
   else if( document.all )
   {
   window.external.AddFavorite(lien, phrase);
   }
   else
        {
   upgAlert.alert('Pour ajouter la page aux favoris, utilisez le système fourni par votre navigateur', 'Ajouter aux favoris', 'erreur');
   return true;
   }
}

function showCouponLink(liste)
{
	var a = liste.split(',');
	var ul = '<ul>';
	for (val in a){
		ul += '<li><a href="/coupon/'+a[val]+'">'+a[val]+'</a></li>';
	}
	ul += '</ul>';
	upgAlert.alert('Faites un click droit / Enregistrer sous pour télécharger un coupon'+ ul, 'Liste des coupons', 'erreur');
	
	return false;
}

function setCookie(name,value,day) {
    var expDate = new Date()
    expDate.setTime(expDate.getTime() + (day * 24 * 3600 * 1000))
    document.cookie = name + "=" + escape(value)
        + ";expires=" + expDate.toGMTString();
}

function getCookie(nom) {
	
	var oRegex = new RegExp("(?:; )?" + nom + "=([^;]*);?");
	 
    if (oRegex.test(document.cookie)) {
            return decodeURIComponent(RegExp["$1"]);
    } else {
            return null;
    }
}

addLoadEvent(initialisation);


