


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 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+10;
		this.style.height = this.stretchedHeight+'px';
		this.expandedHeight = getBoundingClientRect(this.shadow).bottom-getBoundingClientRect(this.shadow).top+10;
		
		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;
		//setTimeout('stretch.call(document.getElementById("'+this.id+'"))',3000);
		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 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';
	}
}

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 = "block";
	}
	return false;
}
var cachePopUp = function(nom_popup) {
	return cachePopIn(nom_popup);
}


function afficheRetourGratuit(){
	document.getElementById('retour_gratuit_popin').style.display='block';
	document.getElementById('BgPopup').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 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');

	selCountries.updateStateList = function() {
		var c = null; 
		if(window.XMLHttpRequest) c = new XMLHttpRequest(); 
		else if(window.ActiveXObject && !window.opera) c = new ActiveXObject("Microsoft.XMLHTTP");
		c.onreadystatechange = function() {
			if(4==this.readyState) {
				if(200==this.status) {
					var k;
					var oSel = document.getElementById('TrStates').getElementsByTagName('select')[0];
					oSel.length = 0;
					var data = eval('('+this.responseText+')');
					for(k in data) {
						oSel.options[oSel.options.length] = new Option(data[k],k);
					}
					oSel.selectedIndex = -1;
					oSel.value = '';
				} else {
					alert('Something got wrong.');
				}
			}
		}
		c.open("GET", window.location.getSfURL('mon_compte::state_list_for_country',{'c':selCountries.value}), true); 
		c.setRequestHeader("X_REQUESTED_WITH", "XMLHttpRequest");
		c.send(null); 
	}

	selCountries.onchange = function(evt) {
		var selStates = document.getElementById('TrStates');
		var oSel      = selStates.getElementsByTagName('select')[0];
		var opt = this.options[this.selectedIndex];
		if(-1<',41,241,'.indexOf(','+opt.value+',')) {
			selStates.style.display = '';
			this.updateStateList();
			oSel.focus();
		} else {
			oSel.value = '';
			oSel.selectedIndex = 0;
			selStates.style.display = 'none';
		}
	}
}

