var ie=false, ie7=false, ie6=false, ns=(navigator.appName.indexOf("Netscape")!=-1)||window.opera;
if(!ns){
	ie=true;
	if(parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE")+5) )>=7){ie7=true;}else{ie6=true;}
	}
var count_popDHTML=0;
function getCookie(name){
	var start=document.cookie.indexOf(name+'=');
	var len=start+name.length+1;
	if((!start)&&(name!=document.cookie.substring(0,name.length))){return null;}
	if(start==-1)return null;
	var end=document.cookie.indexOf(";",len);
	if(end==-1)end=document.cookie.length;
	return unescape(document.cookie.substring(len,end));
	}
function include(destination){
	var e=window.document.createElement('script');
	e.setAttribute('type','text/javascript');
	e.setAttribute('src',destination);
	window.document.body.appendChild(e);
	}
function getWindowXY(){
	var x=0,y=0;
	if(typeof(window.innerWidth)=='number'){x=window.innerWidth;y=window.innerHeight;}
	else if(document.documentElement && document.documentElement.clientWidth){x=document.documentElement.clientWidth;y=document.documentElement.clientHeight;}
	else if(document.body && document.body.clientWidth){x=document.body.clientWidth;y=document.body.clientHeight;}
	return [x,y];
	}
function getDocumentXY(){
	var x=0,y=0;
	if(typeof(window.innerHeight)=='number'&&window.scrollMaxY){x=window.innerWidth+window.scrollMaxX-10;y=window.innerHeight+window.scrollMaxY-10;}
	else if(document.body.scrollHeight>document.body.offsetHeight){x=document.body.scrollWidth;y=document.body.scrollHeight;}
	else if(document.documentElement){x=document.body.offsetWidth+document.documentElement.scrollLeft;y=document.body.offsetHeight+document.documentElement.scrollTop;}
	else{x=document.body.offsetWidth+document.body.offsetLeft;y=document.body.offsetHeight+document.body.offsetTop;}
	return [x,y];
	}
function getScrollXY(){
	var x=0,y=0;
	if(typeof(window.pageYOffset)=='number'){x=window.pageXOffset;y=window.pageYOffset;}
	else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){x=document.body.scrollLeft;y=document.body.scrollTop;}
	else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){x=document.documentElement.scrollLeft;y=document.documentElement.scrollTop;}
	return [x,y];
	}
function getObjXY(obj){ // bug: pos absolue 
	var curleft=0,curtop=0;
	if(obj.offsetParent){
		do{curleft+=obj.offsetLeft;curtop+=obj.offsetTop;
		}while(obj=obj.offsetParent);
		}
	return [curleft,curtop];
	}
function getMousePos(e){
	var x=0,y=0;
	if(!e){var e=window.event;}
	if(e.pageX||e.pageY){x=e.pageX;y=e.pageY;}
	if(e.clientX||e.clientY){x=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;y=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}
	return [x,y];
	}
function cancelDefaultBehavior(e){
	if(!e&&window.event){var e=window.event;e.returnValue=false;}
	else if(e&&e.preventDefault){e.preventDefault();}
	return false;
	}
function addEvent(obj,etype,func){ 
	if(obj&&obj.addEventListener)obj.addEventListener(etype,func,false);
	else if(obj.attachEvent){obj["e"+etype+func]=func;obj.attachEvent("on"+etype,function(){obj["e"+etype+func]();});}
	}
function createNodeTree(node,container){
	if(node.nodeType==1){
		var newNode;
		if(ie&&node.nodeName=='input'){// fix IE bug
			tmp='';
			for(var j=0;j<node.attributes.length;j++){att=node.attributes[j];tmp+=att.name+'="'+att.value+'"';}
			newNode=document.createElement('<input '+tmp+' />');
			}else{
			newNode=document.createElement(node.nodeName);
			for(var j=0;j<node.attributes.length;j++){
				att=node.attributes[j];
				if(att&&att.name&&att.value){
					if(att.name=='class')newNode.className=att.value;
					else newNode.setAttribute(att.name,att.value);
					}
				}
			if(node.nodeName=='a'&&newNode.getAttribute('href')&&newNode.getAttribute('href').indexOf('#profil_')==0){
				var tmpsidfix=newNode.getAttribute('href').split('_');
				tmpsidfix=tmpsidfix[1].replace(/[^0-9]/g,'');
				if(tmpsidfix!='')newNode.setAttribute('href','/profil/index.php?p='+tmpsidfix+'&'+SESSION);
				}
			if(node.hasChildNodes()){
				for(var i=0;i<node.childNodes.length;i++){curNode=node.childNodes[i];createNodeTree(curNode,newNode);}
				}
			}
		container.appendChild(newNode);
		}else if(node.nodeType==3&&node.data){
		var newNode=document.createTextNode(node.data);
		container.appendChild(newNode);
		}
	}
function popDHTML(id, content, w, h, mask){
	var el=document.getElementById(id); tmp=getWindowXY(); xWin=tmp[0]; yWin=tmp[1];
	var m=document.getElementById('popmask');
	if(!m && mask){
		tmp=getDocumentXY();xDoc=tmp[0];yDoc=tmp[1];
		m=window.document.createElement('div');
		m.setAttribute('id','popmask');
		if(yWin>yDoc){ yPop=yWin; }else{ yPop=yDoc; }
		yPop+=10;
		m.style.height=yPop+"px";m.style.right="0px";
		window.document.body.appendChild(m);
		if(ie6){
//			document.body.style.overflow="hidden";
			sels=document.getElementsByTagName('select');
			for(var i=0; i<sels.length; i++){sels[i].className+=' under';}
			}
		}
	if(el){
		e=el;
		e.style.height = 'auto';
		e.style.width = 'auto';
		}else{
		var e=window.document.createElement('div');
		e.setAttribute('id',id);
		popclass='popDHTML';
		e.className=popclass;
		if(mask){e.mask=1;count_popDHTML++;}
		}
	if(content){
		while(e.hasChildNodes()){e.removeChild(e.firstChild);}
		if(typeof content=='function'){content(e);}
		else if(content.hasChildNodes){content=content.cloneNode(true);e.appendChild(content);}
		else{var box=document.createElement('div');box.appendChild(document.createTextNode(content));e.appendChild(box);}

		var closelink=document.createElement('img');
		closelink.setAttribute('alt','fermer');
		closelink.className="close png";
//		closelink.setAttribute('src','/img/btn_fermer.png');
		closelink.setAttribute('src','/img/blank.gif');
		addEvent(closelink,'click',function(){delPopDHTML(id);});
		e.appendChild(closelink);

		window.document.body.appendChild(e);
		initLinks(e);
		initDynamicTabs(e);
		initOverLabel(e);
		initHints(e);
		}
	if(w>0){ e.style.width=w+"px"; }else{ w=0; }
	if(h=='auto'){
		if(e.offsetHeight && e.offsetHeight>10){
			//if(el)h=e.offsetHeight;
			//else 
			h=e.offsetHeight+100;
			}else{
			h=100;
			}
		if(e.firstChild && e.firstChild.style){e.firstChild.style.marginTop='50px';}
		}
	if(h>0){ e.style.height=h+"px"; }else{ h=0; }
	xPop=(xWin-w)/2;
	yPop=(yWin-h)/2;
	if(ie6){tmp=getScrollXY();xScr=tmp[0];yScr=tmp[1];xPop+=xScr;yPop+=yScr;}
	e.style.left=(xPop-5)+"px";
	e.style.top=yPop+"px";
	if(id=='popPic'){addEvent(document,'keydown',escPopPic);}
	}
function delPopDHTML(id){
//	if(ie6) document.body.style.overflow='auto';
	var el=document.getElementById(id);
	var m=document.getElementById('popmask');
	if(el && el.mask) count_popDHTML--;
	if(window.document.body){
		if(el){ window.document.body.removeChild(el); }
		if(m && count_popDHTML==0){
			window.document.body.removeChild(m);
			sels=document.getElementsByTagName('select');
			for(var i=0; i<sels.length; i++){sels[i].className=sels[i].className.replace(/[ ]under/g,'');}
			}
		}
	}
function getRelatedLabel(id){
	var input=document.getElementById(id);
	if(!input){ return null; }
	var rel;
	var p=input.parentNode;
	if(p.nodeName.toLowerCase()=='label' && (p.htmlFor || p.getAttribute('for'))==id){
		rel=p;
		}else{
		var col=document.getElementsByTagName('label');
		for(var i=0; i<col.length; i++){
			if((col[i].htmlFor || col[i].getAttribute('for'))==id){
				return col[i];
				}
			}
		}
	}
function hideOverLabel(){
	if(!this)return;
	if(this.nodeName.toLowerCase()=='label')this.className+=' hide';
	else{
		var label=getRelatedLabel(this.id);
		if(label)label.className+=' hide';
		}
	}
function showOverLabel(){
	if(!this||this.value!='')return;
	var label=getRelatedLabel(this.id);
	if(label)label.className=label.className.replace(/[ ]*hide/g,'');
	}
function initOverLabel(source){
	var labels=source.getElementsByTagName('label');
	for(var i=0; i<labels.length; i++){
		if(labels[i].className.indexOf('over')!=-1){
			var id=labels[i].htmlFor || labels[i].getAttribute('for');
			if(id){
				var rel_el=document.getElementById(id);
				if(rel_el){
					if(rel_el.value!='')labels[i].className+=' hide';
					addEvent(labels[i],'click',hideOverLabel);
					addEvent(rel_el,'focus',hideOverLabel);
					addEvent(rel_el,'keydown',hideOverLabel);
					addEvent(rel_el,'blur',showOverLabel);
					}
				}
			}
		}
	}
function initHints(source){
	var obj=source.getElementsByTagName('*');
	for(var i=0; i<obj.length; i++){
		if(obj[i].className && obj[i].className.indexOf('hintit')!=-1){
			addEvent(obj[i],'mouseover',showHint);
			addEvent(obj[i],'mouseout',hideHint);
			}
		}
	}
function showHint(e){
	if(this.title=='') return;
	availXY=getDocumentXY();
	pop=document.createElement('div');
	pop.setAttribute('id','pophint');
	pop.className='box';
	pop.appendChild(document.createTextNode(this.title));
	window.document.body.appendChild(pop);
	objXY=getMousePos(e);
	x=objXY[0]+50;
	y=objXY[1];
	if((x+pop.offsetWidth)>availXY[0] && (y+pop.offsetHeight+50)>availXY[1]){// x invalide; y invalide
		pop.style.top=(y-pop.offsetHeight-10)+'px';
		pop.style.left=(availXY[0]-pop.offsetWidth-10)+'px';
		}else if((x+pop.offsetWidth)>availXY[0]){// x invalide
		pop.style.top=(y+50)+'px';
		pop.style.left=(availXY[0]-pop.offsetWidth-10)+'px';
		}else if((y+pop.offsetHeight)>availXY[1]){// y invalide
		pop.style.top=(y-pop.offsetHeight-10)+'px';
		pop.style.left=(x-this.offsetWidth-10)+'px';
		}else{
		pop.style.top=y+'px';
		pop.style.left=x+'px';
		}
	this.tmptitle=this.title;
	this.title='';
	}
function hideHint(){
	pop=document.getElementById('pophint');
	if(pop) pop.parentNode.removeChild(pop);
	if(typeof this.tmptitle != 'undefined' && this.tmptitle!=''){
		this.title=this.tmptitle;
		this.tmptitle='';
		}
	}
function switchDynamicTab(e){ // li TITLE=id
	if(!this){ return; }
	cancelDefaultBehavior(e);
	var ul=this;
	while(ul && ul.className.indexOf('tabs')==-1){ul=ul.parentNode;}
	if(ul && ul.className.indexOf('tabs')!=-1){
		var p=this.parentNode;
		var selected;
		while(p){
			if(p.nodeName.toLowerCase()=='li'){selected=p.title;break;}
			else{p=p.parentNode;}
			}
		var li=ul.getElementsByTagName('li');
		for(var i=0; i<li.length; i++){
			li[i].className=li[i].className.replace(/[ ]*selected/g,'');
			if(li[i]==p)li[i].className+=' selected';
			}
		var tabs=ul.parentNode.getElementsByTagName('div');
		for(var i=0; i<tabs.length; i++){
			tabs[i].className=tabs[i].className.replace(/[ ]*tabscontent_selected/g,'');
			if(tabs[i].id==selected)tabs[i].className+=' tabscontent_selected';
			}
		}
	}
function initDynamicTabs(source){
	var uls=source.getElementsByTagName('ul');
	for(var i=0; i<uls.length; i++){
		if(uls[i].className.indexOf('tabs')!=-1 && uls[i].className.indexOf('dynamic')!=-1){
			var links=uls[i].getElementsByTagName('a');
			for(var j=0; j<links.length; j++){addEvent(links[j],'click',switchDynamicTab);}
			}
		}
	}
function correctFooterPos(){
	var footer=document.getElementById('footer');
	if(!footer) return;
	var winXY=getWindowXY();
	var docXY=getDocumentXY();
	if(winXY[1]>=docXY[1] && winXY[1]>0 && docXY[1]>0){
		footer.style.position='absolute';
		footer.style.bottom='0';
		}else{
		footer.style.position='';
		footer.style.bottom='';
		}
	}
function smoothScroll(origY,destY,dir){
	if(typeof 'dir'== undefined || dir!='up') dir='down';
	var speed=14;
	if(ie6) speed=Math.floor(speed/2);

	if(dir=='up') origY=origY-Math.floor((origY-destY)/speed);
	else origY=origY+Math.floor((destY-origY)/speed);
	if( (dir=='down' && origY>=destY) || (dir=='up' && origY<=destY) ){
		window.scrollTo(0,destY);
		}else{
		var tmp=getScrollXY();
		var oldY=tmp[1];
		window.scrollTo(0,origY);
		tmp=getScrollXY();
		var newY=tmp[1];
		if(oldY==newY) window.scrollTo(0,destY);
		else setTimeout('smoothScroll('+origY+','+destY+',"'+dir+'")',speed);
		}
	}

function initLinks(source){
	var lnks=source.getElementsByTagName('a');
	for(var i=0; i<lnks.length; i++){
		if(lnks[i].id=='lnkadvantages' || lnks[i].className.indexOf('lnkadvantages')!=-1){
			addEvent(lnks[i],'click',get_abo_avantages);
			}
		if(lnks[i].className.indexOf('opentop')!=-1) lnks[i].setAttribute('target','_top');
		else if(lnks[i].className.indexOf('opensecure')!=-1) lnks[i].setAttribute('target','_blank');
		else if(lnks[i].className.indexOf('openciemain')!=-1) lnks[i].setAttribute('target','ciemain');
		else if(lnks[i].className.indexOf('opennew')!=-1) lnks[i].setAttribute('target','_blank');
		if(hash && hash.length && hash==lnks[i].name){
			tmp=getObjXY(lnks[i]);
			y=tmp[1]-10;
			if(y>0) setTimeout('smoothScroll(0,'+y+')',200);
			}
		if(lnks[i].href.indexOf('#')>=1 && document.location.host==lnks[i].host && document.location.pathname!=lnks[i].pathname){
			lnks[i].href=lnks[i].href.replace(/#/,'#ss');
			}
		}
	}
// Ajustements d'interface GENERAL
function progEnhance(){
	initLinks(document);
	initDynamicTabs(document);
	initOverLabel(document);
	initHints(document);
	correctFooterPos();
	addEvent(window,'resize',correctFooterPos);
	}
var hash;
if(window.location.hash.length>1){
	hash=window.location.hash.replace(/^#ss/,'');
	hash=hash.replace(/^#/,'');
	window.scrollTo(0,0);
	}
addEvent(window,'load',progEnhance);

