
function openPopup(e){
	if(parent.frames.length>1){
		var url = e.href;
		var newUrl = url.replace('.html','.shtml');
		window.open(newUrl,'contact', 'height=130, width=435, top=100, left=100, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=no, status=no');
	} else {
		openPopin(e);
	}
}


var popinTpl = '<div id="popinWrap">' +
		'<div id="popinTop">' +
		'<a href="#" onClick="closePopin()" rel="closePopin"><img src="/imagerie/commun/close_popin.gif" alt="Close" /></a>' +
		'</div>' +
		'<div id="popinContent"></div>' +
		'<div id="popinBottom"></div>'+
		'</div>';
		
		
function closePopin() {
	if(document.getElementById('popin')){
		var d = document.body;
		var olddiv = document.getElementById('popin');
		d.removeChild(olddiv);
	}
}

function sendData(data, page, div)
	{  
	if(document.all)
		{
		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
		}
	else
		{
		var XhrObj = new XMLHttpRequest();
		}
	var content = document.getElementById(div);
	XhrObj.open("GET", page);
	XhrObj.onreadystatechange = function() 
		{
		if (XhrObj.readyState == 4 && XhrObj.status == 200)
			{
			if(navigator.appName=='Netscape' && navigator.appVersion.indexOf("Safari",0)<0)
				{
				content.innerHTML = XhrObj.responseText;
				var allscript = content.getElementsByTagName('script');
				for(var i=0;i< allscript.length;i++){window.eval(allscript[i].text);}
				}
			else
				{
				var tmp = XhrObj.responseText;
				//tmp=utf8_decode(utf8_decode(tmp));
				document.getElementById(div).innerHTML= tmp;
				y_exec_scripts(document.getElementById(div));
				
				function y_exec_scripts(obj)
					{
					scripts = obj.getElementsByTagName("script");
					var nbScripts = scripts.length;
					for(i=0;i<nbScripts;i++)
					eval(scripts[i].innerHTML);
					}
				}
			} 
		}	
		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		XhrObj.send(data); 
	return false;
	}
	
function openPopin(e){
	var div = document.createElement("div");
	div.setAttribute('id','popin');
	div.innerHTML = popinTpl;
	document.body.appendChild(div);
	url = e.href;
	sendData('',url,'popinContent');
}

function goToUrl(e){
	var content = '<iframe src="' + e.href + '" width="435" id="popinFrame" name="popinFrame" scrolling="no" frameborder="0"></iframe>';
	if(!document.getElementById('popup')){
		document.getElementById('popinContent').innerHTML = content;
		document.getElementById('popinWrap').style.top = 40+'px';
		return false;
	} else {
		var popin = document.getElementById('popin');
		popin.innerHTML = content;
		popin.style.paddingLeft = 0;
		popin.style.paddingTop = 0;
		window.resizeTo(455, 840);
	}
}