function isMouseLeaveOrEnter(e, handler)
{
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler); // && typeof reltg != 'undefined'
}

/*ajout romain questionnaire satisfaction*/

function ecrire_cookie(nom, valeur) {
	
//nouvel objet date
var aujourdhui = new Date() ;
 
//nouvel objet date
var expdate = new Date() ;
 
//plus 2 semaines à partir d'aujourd'hui
expdate.setTime( aujourdhui.getTime() + ( 14*24*60*60*1000 ) )
 
//creation du cookie
document.cookie = nom + "=" + escape(valeur) + ";expires=" + expdate.toGMTString() ;

}
  

function lire_cookie(nom) {
        deb = document.cookie.indexOf(nom + "=")
        if (deb >= 0) {
            deb += nom.length + 1
            fin = document.cookie.indexOf(";",deb)
            if (fin < 0) fin = document.cookie.length
            return unescape(document.cookie.substring(deb,fin))
            }
        return ""
        }

function affiche_questionnaire(nom_de_la_page, nom_interne_de_la_fenetre) {
v_enquete_ouverte=lire_cookie("enquete_ouverte");
if (v_enquete_ouverte!="oui"){
	ecrire_cookie("enquete_ouverte", "oui");
	window.open (nom_de_la_page, nom_interne_de_la_fenetre, config='height=516, width=820, left=60, top=60, toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=0, status=0');
}
}

function affiche_questionnaire2(nom_de_la_page, nom_interne_de_la_fenetre) {
	window.open (nom_de_la_page, nom_interne_de_la_fenetre, config='height=516, width=820, left=60, top=60, toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=0, status=0');
}

/*fin ajout romain*/


window.onload=function(){

	/*
	if(!NiftyCheck()) return;
	Rounded("div#header_panier","bl br","#FFF", "#CF2533", "smooth");
	Rounded("div#header_panier_center","bl br","transparent", "#CF2533");
	*/
	
	if(document.getElementById('contenu_principal')!=null){
		contenuHeight = document.getElementById('contenu_principal').offsetHeight;
	}
	if(document.getElementById('menu_principal')!=null){
		menuHeight = document.getElementById('menu_principal').offsetHeight;
	}
	if(document.getElementById('contenu_principal')!=null && document.getElementById('menu_principal')!=null){
		bsideHeight = contenuHeight - menuHeight - 10;
	}
	
	if(document.getElementById('menu_bside')){
		bsideOffsetHeight = document.getElementById('menu_bside').offsetHeight;
		
		if( bsideOffsetHeight < bsideHeight){
			document.getElementById('menu_bside').style.height = bsideHeight + "px";
		}
	}
	
	if( ('undefined'!=typeof afficheStatus || 'boolean'==typeof(afficheStatus)) && true==afficheStatus ) {
		
		affichePopUpRetour();
	}
	
		
	initialize();
/*
	var adress= document.getElementById("adress").innerHTML;
		
	showAddress(adress);
*/
}

var map = null;
    var geocoder = null;

    function initialize() {
      if ('undefined'!=typeof GBrowserIsCompatible && GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        var longitude=document.getElementById("longitude").innerHTML;
        var latitude=document.getElementById("latitude").innerHTML;
        var texte=document.getElementById("adress").innerHTML;
        
        map.setCenter(new GLatLng(longitude, latitude), 13);
        map.openInfoWindow(map.getCenter(),
            document.createTextNode(texte));
        var mapControl = new GMapTypeControl();
			map.addControl(mapControl);
			map.addControl(new GSmallMapControl());
        geocoder = new GClientGeocoder();
      }
    }
    
// résolution par l'adresse
/*  
function showAddress(address) {
      
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
                            
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
       );
    }
}   
*/
    
    

/* 
 * Panier
 */


function PanierContainerEvent(evt) {
	this.event = evt;
	this.type = evt.type;
	this.target = evt.target || evt.srcElement;
	if (null!=this.target && this.target.nodeType == 3 && this.target.parentNode) this.target = this.target.parentNode;
	var ppty;
	var tmp = {
		'pgX': evt.pageX || evt.clientX + document.documentElement.scrollLeft,
		'pgY': evt.pageY || evt.clientY + document.documentElement.scrollTop
	};for(ppty in tmp) this[ppty] = tmp[ppty];

	tmp = {
		'clX': evt.pageX ? evt.pageX - window.pageXOffset : evt.clientX,
		'clY': evt.pageY ? evt.pageY - window.pageYOffset : evt.clientY
	};for(ppty in tmp) this[ppty] = tmp[ppty];
	tmp = null;
	switch(this.type){
		case 'mouseover': this.relatedTarget = evt.relatedTarget || evt.fromElement; break;
		case 'mouseout': this.relatedTarget = evt.relatedTarget || evt.toElement; break;
	}
	if (this.relatedTarget && this.relatedTarget.nodeType == 3) this.relatedTarget = this.relatedTarget.parentNode;
}

function getPosition(element,overflown){
	overflown = overflown || [];
	var el = element, left = 0, top = 0;
	do {
		left += el.offsetLeft || 0;
		top += el.offsetTop || 0;
		el = el.offsetParent;
	} while (el);

	for( var i=0; i<overflown.length; i++) {
		left -= overflown[i].scrollLeft || 0;
		top  -= overflown[i].scrollTop || 0;
	}
	return {'x': left, 'y': top};
}

function getBoundingClientRect(element){
	function _getBoundingClientRect(el) {
		var ret = getPosition(el);
		var ret = {
			'left':ret.x,
			'right':ret.x+element.offsetWidth,
			'top':ret.y,
			'bottom':ret.y+element.offsetHeight
		}
		return ret;
	}
    if (typeof arguments.callee.offset != "number"){
        var temp = document.createElement("div");
        temp.style.cssText = "position:absolute;top:0px;left:0px";
        document.body.appendChild(temp);
        if( temp.getBoundingClientRect ) arguments.callee.offset = -temp.getBoundingClientRect().top;
        else arguments.callee.offset = -(_getBoundingClientRect(temp)).top
        document.body.removeChild(temp);
        temp = null;
    }

    var rect;
    if( element.getBoundingClientRect ) {
        rect = element.getBoundingClientRect();
    } else {
        rect = _getBoundingClientRect(element);
    }
    var offset = arguments.callee.offset;

    return {
        left: rect.left + offset,
        right: rect.right + offset,
        top: rect.top + offset,
        bottom: rect.bottom + offset
    };
}

function isAncestor(o) {
	var ret = false;
	if( o==this.parentNode ) {
		ret = true;
	} else {
		var pn = this;
		while( (pn=pn.parentNode) && 'html'!=pn.nodeName.toLowerCase() ) {
			if( o==pn ) {
				ret = true;
				break;
			}
		}
	}
	return ret;
}

function expand() {
	if( undefined!=this.isStretching && this.isStretching ) return;
	if(!this.shadow ) {
		this.shadow = this.cloneNode(true);
		this.shadow.id = this.id+'_shadowed';
		this.shadow.style.display = 'block';
		this.shadow.style.position = 'absolute';
		this.shadow.style.left = '-1000px';
		this.shadow.style.top = '0px';
		this.shadow.style.width = '210px';
		this.shadow.style.height = 'auto';
		this.shadow.style.overflow = 'auto';
		this.shadow.onmouseover = null;
		this.shadow.onmouseout = null;
		document.body.appendChild(this.shadow);
		this.stretchedHeight = getBoundingClientRect(this).bottom-getBoundingClientRect(this).top;
		this.style.height = this.stretchedHeight+'px';
		this.expandedHeight = getBoundingClientRect(this.shadow).bottom-getBoundingClientRect(this.shadow).top;
		
		document.body.removeChild(this.shadow);
		this.isExpanding = true;
		this.timer = setInterval('expand.call(document.getElementById("'+this.id+'"))',15);
	}
	if(this.expandedHeight>parseInt(this.style.height)) {
		var open = Math.max(1,Math.ceil((this.expandedHeight-parseInt(this.style.height))/5));
		this.style.height = (parseInt(this.style.height)+open)+'px';
	} else {
		clearInterval(this.timer);
		this.timer = null;
		this.shadow = null;
		this.isExpanding = false;
		this.rect = getBoundingClientRect(this);
	}
}

function stretch() {
	if( undefined!=this.isExpanding && this.isExpanding ) return;
	if( this.stretchedHeight<parseInt(this.style.height) ) {
		this.isStretching = true;
		if(!this.timer) this.timer = setInterval('stretch.call(document.getElementById("'+this.id+'"))',15);
		var close = Math.max(1,Math.ceil((parseInt(this.style.height)-this.stretchedHeight)/2));
		this.style.height = (parseInt(this.style.height)-close)+'px';
	} else {
		
		this.style.overflow = 'hidden';
		this.style.height   = '0px';
		this.style.display  = 'none';
		
		clearInterval(this.timer);
		this.timer = null;
		this.isStretching = false;
	}
}

function affichePanier(e){
	e  = (null==e?false:(e||window.event))
	var el = document.getElementById('header_panier_center');
	if( e ) {
		e = new PanierContainerEvent(e);
		el.rect = getBoundingClientRect(el.parentNode);
		if( e.pgX>el.rect.left && e.pgX<(el.rect.left+el.offsetWidth) ) {
			return
		}
	}
	if( el ) {
		el.style.height='0px';
		el.style.overflow='hidden';
		el.style.display='block';
		expand.call(el);
	}
}


function isAncestor(o) {
	var ret = false;
	if( o==this.parentNode ) {
		ret = true;
	} else {
		var pn = this;
		while( (pn=pn.parentNode) && 'html'!=pn.nodeName.toLowerCase() ) {
			if( o==pn ) {
				ret = true;
				break;
			}
		}
	}
	return ret;
}



function cachePanier(e){
	e  = (null==e?false:(e||window.event))
	var el = document.getElementById('header_panier_center');
	if( e ) {
		e = new PanierContainerEvent(e);
		if(e.relatedTarget && !e.relatedTarget.isAncestor ) {
			e.relatedTarget.isAncestor = isAncestor;
		}

		if( e.relatedTarget /*&&  e.relatedTarget.isAncestor(el.parentNode)*/ && e.pgX>el.rect.left && e.pgX<(el.rect.left+el.offsetWidth) && e.pgY<el.offsetHeight && e.pgY>5 ) {
			return
		}
	}
	if( el ) {
		stretch.call(el);
	}
}

/* EOPanier */



/* ojo/ -|081215 popin patch */
function add65Event( obj, type, fn ) { 
	if ( obj.attachEvent ) { 
		obj.attachEvent( 'on'+type, fn ); 
	} else {
		obj.addEventListener( type, fn, false ); 
	}
} 

function remove65Event( obj, type, fn ) { 
	if ( obj.detachEvent ) { 
		obj.detachEvent( 'on'+type, fn ); 
	} else {
		obj.removeEventListener( type, fn, false ); 
	}
}

function maximize(el) {
	pttfci();
	if(!el.getPosition) ElGoodies.enrich(el);
	el.style.height   = gwh()+'px';
	el.style.width    = '100%';
	el.style.display  = 'block';
	if(window.ActiveXObject && !window.XMLHttpRequest) {
		el.style.width   = (document.documentElement.offsetWidth+document.documentElement.scrollLeft)+'px';
	}
	setTimeout('fciAdjustCurtain()',100);
}

function gwhSetHeight() {
	var curtain = document.getElementById('BgPopup');
	if( curtain && 'block'==curtain.style.display.toLowerCase() ) {
		curtain.style.height = gwh()+'px';
		if(window.ActiveXObject && !window.XMLHttpRequest) {
			curtain.style.width  = gww()+'px';
		}
	}
}
function gwh() {
	return Math.max((window.innerHeight?window.innerHeight:0),(document.getElementsByTagName('body'))[0].offsetHeight,(document.getElementsByTagName('html'))[0].offsetHeight);
}
function gww() {
	return Math.max((window.innerWidth?window.innerWidth:0),(document.getElementsByTagName('body'))[0].offsetWidth,(document.getElementsByTagName('html'))[0].offsetWidth);
}

function gwwp() {
	var e = window, a = 'inner';
	if(!window.hasOwnProperty) window.hasOwnProperty = ElGoodies.hasOwnProperty;
	if (!window.hasOwnProperty('innerWidth')) {
		a = 'client';
		e = document.documentElement || document.body;
	}
	return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }
}

function ttfci() {
	//alert(document.body.watch)
	var ret = [];
	var imgColl = document.getElementsByTagName('img');
	var curImg,o;
	for( var i=0; i<imgColl.length; i++) {
		curImg = imgColl[i];
		if(/.*fermer\....$/i.test(curImg.src)) {
			o = curImg;
			while(o.parentNode && 'body'!=o.parentNode.nodeName.toLowerCase()) {
				if('div'==o.parentNode.nodeName.toLowerCase()) {
					ElGoodies.enrich(o.parentNode);
					if('absolute'==o.parentNode.getComputedStyle('position').toLowerCase() && 'none'==o.parentNode.getComputedStyle('display').toLowerCase()) {
						if('undefined'!= typeof o.parentNode) ret[ret.length] = o.parentNode;
						imgColl[i].setAttribute('closeWhat',o.parentNode);
						imgColl[i].onclick = function() {
							window['lastClosedPopin'] = this.closeWhat;
						}
					}
				}
				o = o.parentNode;
			}
		}
	}
	return ret;
}

function pttfci() {
	if('undefined'==typeof window['ttfciCollection']) {
		window['ttfciCollection'] = ttfci();
	}
	for( var i=0; i<window['ttfciCollection'].length; i++) {
		/*window['ttfciCollection'][i].style.top = (180+scrollTop())+'px';*/
		window['ttfciCollection'][i].style.top = (60+scrollTop())+'px';
	}
}

function fciAdjustCurtain() {
	for( var i=0; i<window['ttfciCollection'].length; i++) {
		if( 'block'==window['ttfciCollection'][i].style.display ) {
			var curtain = document.getElementById('BgPopup');
			var oPos    = getBoundingClientRect(window['ttfciCollection'][i]);
			curtain.style.height = Math.max((curtain.offsetHeight),oPos.bottom+20)+'px';
			break;
		}
	}
}

var lastClosedPopin = null;
add65Event( window, 'resize', gwhSetHeight );
/* ojo/ 081215 popin patch-| */

function affichePopIn(nom_popup){
	maximize(document.getElementById('BgPopup'));
	document.getElementById(nom_popup).style.display='block';

	
	// on enleve les select
	var x = document.getElementsByTagName("select");
	for (i = 0; i < x.length; i++) {
	   x[i].style.display = "none";
	}
	
	return false;
}

function cachePopIn(nom_popup){
	if( !nom_popup ) nom_popup = 'contenu_popup';
	document.getElementById(nom_popup).style.display='none';
	document.getElementById('BgPopup').style.display='none';
	
	// on remet les select
	var x = document.getElementsByTagName("select");
	for (i = 0; i < x.length; i++) {
	   x[i].style.display = "";
	}
	return false;
}
var cachePopUp = function(nom_popup) {
	return cachePopIn(nom_popup);
}


function afficheRetourGratuit(){
	maximize(document.getElementById('BgPopup'));
	var rgp = document.getElementById('retour_gratuit_popin');
	if(null!=rgp) {
		rgp.style.marginTop = '0';
		rgp.style.display='block';
		rgp.style.top = (60+scrollTop())+'px';
	}

	// on enleve les select
	var x = document.getElementsByTagName("select");
	for (i = 0; i < x.length; i++) {
	   x[i].style.display = "none";
	}
	return false;
}

function cacheRetourGratuit(){
	document.getElementById('retour_gratuit_popin').style.display='none';
	document.getElementById('BgPopup').style.display='none';

	// on remet les select
	var x = document.getElementsByTagName("select");
	for (i = 0; i < x.length; i++) {
	   x[i].style.display = "block";
	}
	return false;
}

function scrollTop(){
	body=document.body
	d=document.documentElement
	if (body && body.scrollTop) return body.scrollTop
	if (d && d.scrollTop) return d.scrollTop
	if (window.pageYOffset) return window.pageYOffset
	return 0
}

function centerPopup(element) {
	var height=document.getElementById(element).offsetHeight;//hauteur de l'élément à positionner
	var width=document.getElementById(element).offsetWidth;//largeur de l'élément à positionner
	myParent=document.getElementById(element).parentNode;
	var pHeight=myParent.offsetHeight;//Hauteur de l'élément parent	
	var pWidth=myParent.offsetWidth;//Largeur de l'élément parent
	var sTop=scrollTop();//Hauteur de défilement de l'élément parent
	var sLeft=myParent.scrollLeft;//Longueur de défilement de l'élément parent
	
	var posY = sTop+100;
	//var posY=(pHeight/2)-(height/2)+sTop;//Calcul de la position en Y
	document.getElementById(element).style.top=posY+"px";
	
	//var posX=(pWidth/2)-(width/2)+sLeft;//Calcul de la position en X
	//document.getElementById(element).style.left=posX+"px";
}

function affichage_popup(nom_de_la_page, nom_interne_de_la_fenetre) {

	var wpop = window.open(
		nom_de_la_page,
		"nom_interne_de_la_fenetre",
		"toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=500,height=593"
	);
	wpop.focus();

}


window.location.getSfURL = function(methodName,qString) {
	qString = qString||{};
	var pathname   = '/';
	var moduleName = null;
	if(methodName.indexOf('::')) {
		var tmp = methodName.split('::');
		methodName = tmp.pop();
		moduleName = tmp.pop();
		tmp = null;
	}
	var tmp = window.location.pathname.substr(1).split('/');
	tmp.length = 3;
	if(null!==moduleName) tmp[1] = moduleName;
	tmp[2] = methodName;
	for( var k in qString ) {
		tmp[tmp.length] = encodeURIComponent(k)+'/'+encodeURIComponent(qString[k]);
	}
	return '/'+tmp.join('/');
}


function setSelectStateHandling() {
	var selCountries        = document.getElementById('country1');
	var selStates           = document.getElementById('TrStates');
	var oSel                = selStates.getElementsByTagName('select')[0];
	oSel.style.width        = selCountries.offsetWidth+'px';
	selStates.style.display = (-1<',41,241,'.indexOf(','+selCountries.options[selCountries.selectedIndex].value+',')?'':'none');
	if('none'==selStates.style.display) {
		oSel.selectedIndex      = -1;
		oSel.value              = '';
	}
	selCountries.ojo_xhr    = new OjO_Xhr(selCountries);
	selCountries.ojo_xhr.setCallback('onquerysuccess', function(req) {
		var k;
		var oSel = document.getElementById('TrStates').getElementsByTagName('select')[0];
		oSel.length = 0;
		var data = eval('('+req.responseText+')');
		for(k in data) {
			oSel.options[oSel.options.length] = new Option(data[k],k);
		}
		oSel.selectedIndex = -1;
		oSel.value = '';
	});
	selCountries.ojo_xhr.setCallback('onqueryfailure', function(req) {
		var oSel = document.getElementById('TrStates').getElementsByTagName('select')[0];
		oSel.length = 0;
		oSel.selectedIndex = -1;
		oSel.value = '';
		alert('A ' + req.status + ' error occured.')
	});

	selCountries.updateStateList = function() {
		if('undefined'!=this.ojo_xhr) {
			this.ojo_xhr.query(
					{}, 
					window.location.getSfURL('mon_compte::state_list_for_country',{'c':this.value}), 
					'GET', 
					{}, 
					30
				);
		}
	}

	var handleCountryChanged = function() {
		var evt       = OjO_EventUtil.getEvent();
		var self      = evt.target;
		var selStates = document.getElementById('TrStates');
		var oSel      = selStates.getElementsByTagName('select')[0];
		var opt = self.options[self.selectedIndex];
		
		if(-1<',41,241,'.indexOf(','+opt.value+',')) {
			selStates.style.display = '';
			self.updateStateList();
			oSel.focus();
		} else {
			oSel.value = '';
			oSel.selectedIndex = 0;
			selStates.style.display = 'none';
		}
	};
	OjO_EventUtil.addEventHandler(selCountries, 'change', handleCountryChanged);

}

var installPlaceholderEmu = function(cbFunction, errMsg) {
	if(1==this.nodeType && 'input'==this.nodeName.toLowerCase() && 'text'==this.type.toLowerCase()) {
		OjO_EventUtil.addEventHandler(this, 'focus', placeholderEmu);
		OjO_EventUtil.addEventHandler(this, 'blur', placeholderEmu);
		this.placeholderText = this.value;
		if('function'== typeof cbFunction) {
			this.inputValidator = cbFunction;
		} else {
			this.inputValidator = function() { return true; }
		}
		if('string'== typeof errMsg) {
			this.errorText = unescape(errMsg);
		} else {
			this.errorText = '';
		}
	} else {
		throw "Target element should be INPUT type text";
	}
}

var placeholderEmu = function(e) {
	var evt = OjO_EventUtil.getEvent();
	var self  = evt.target;
	if('focus'==evt.type) {
		if(self.value==self.placeholderText) self.value = '';
	} else if('blur'==evt.type) {
		if(!self.inputValidator()) {
			var typofObj = typeof self.errMsg;
			if('undefined'==typofObj || null==typofObj) {
				self.value = self.placeholderText;
				//elementErrAlert.call(self)
				//self.value = self.errorText+' ';
				//self.errMsg = {init:false, timer: null, restoreColor: self.style.color};
				//self.errMsg.timer = setInterval(function(){scrollInputValue.call(self, self.placeholderText, '#CF2533');}, 100);
			}
		}
	}
}

var elementErrAlert = function() {
	var msg = '';
	if(0<arguments.length) {
		msg = arguments[0];
	} else if('string'==typeof this.errorText) {
		msg = this.errorText;
	}
	if(''!=msg) {
		if(/\%[0-9A-F]{2}/i.test(msg)) {
			msg = unescape(msg)
		}
		var curtain = document.getElementById('BgPopup');
		if(curtain) {
			var x = document.getElementsByTagName("select");
			for (var i = 0; i < x.length; i++) { x.item(i).style.display = 'none'; }
			maximize(curtain);
		}
		alert(msg);
		if(curtain) {
			curtain.style.display = 'none';
			for (var i = 0; i < x.length; i++) { x.item(i).style.display = ''; }
		}
	}
}

var scrollInputValue = function(restoreMesg, errColor) {
	var typofObj = typeof this.errMsg;
	if('undefined'!=typofObj && null!=typofObj) {
		if(!this.errMsg.init) {
			if('string' == typeof errColor) {
				this.style.color = errColor;
			}
			this.errMsg.init = true;
		} else {
			if(''==this.value) {
				clearTimeout(this.errMsg.timer);
				var restoreColor = this.errMsg.restoreColor;
				this.errMsg.timer = null;
				this.errMsg = null;
				try {
					delete this.errMsg;
				} catch(e) {
					this.errMsg = undefined;
				}
				this.style.color = restoreColor; 
				this.value = restoreMesg;
			} else {
				this.value = this.value.substr(1);
			}
		}
	}
}

/* 'Newsletter Please' component */
function checkNlpForm() {
	var ret = false;
	if(!this.elements[0].value.trim().isMailAddr()) {
		elementErrAlert.call(this.elements[0]);
	} else {
		ret = true;
	}
	return ret;
}

function checkLoginForm() {
	var ret = false;
	var inputz = {mail: null, password: null};
	for(var i=0; i<this.elements.length; i++) {
		if(inputz.hasOwnProperty(this.elements[i].name)) {
			inputz[this.elements[i].name] = this.elements[i];
		}
	}
	if(null!=inputz.mail && null!=inputz.password) {
		var mailOk = inputz.mail.value.trim().isMailAddr();
		var passwdOk = (''!=inputz.password.value.trim());
		ret = (mailOk && passwdOk);
		if(!ret) {
			if(!mailOk) {
				elementErrAlert.call(inputz.mail);
			} else if(!passwdOk) {
				elementErrAlert.call(inputz.password);
			}
		}
	} else {
		alert('System error: unable to find fields to validate.');
	}
	return ret;
}

