function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function createBlanket(){
	v_parent = document.getElementsByTagName('body')[0]; 
	v_div_enfant = document.createElement("div");
	v_div_enfant.setAttribute("id","blanket");
	v_div_enfant.setAttribute("style","display:none;background-image: url(http://www.versio.fr/js/kmtBox/overlay_dark.png); ;position:absolute;z-index: 9001;top:0px;left:0px;width:100%");
	v_parent.appendChild(v_div_enfant);
	
	v_div_enfant = document.createElement("div");
	v_div_enfant.setAttribute("id","html_float");
	v_div_enfant.setAttribute("style","display:none;background:url(http://www.versio.fr/clients/tmo/lorraine/bg.gif);position:absolute;width:579px;height:469px;z-index: 9002;border-radius:15px");
	v_parent.appendChild(v_div_enfant);
		
	
	
	
}

function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-234;//150 is half popup's height
	//popUpDiv.style.top = popUpDiv_height + 'px';
	popUpDiv.style.top =  '200px';
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-290;//300 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
	createBlanket();
	blanket_size(windowname);
	window_pos(windowname);
	document.getElementById(windowname).innerHTML = getPopContent();
	toggle('blanket');
	toggle(windowname);		
}
function getCookieVal(offset){
	var endstr=document.cookie.indexOf (';', offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom){
	var arg=nom+'=';
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(' ',i)+1;
		if (i==0) break;

	}
	return null;
}
function EcrireCookie(nom, valeur){
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;

	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+'='+escape(valeur)+
	((expires==null) ? '' : ('; expires='+expires.toGMTString()))+
	((path==null) ? '' : ('; path='+path))+
	((domain==null) ? '' : ('; domain='+domain))+
	((secure==true) ? '; secure' : '');
}

function showPopIn(id){	
	if(LireCookie(id)==null || LireCookie(id) < 3){	
		popup(id);
		if(LireCookie(id)!=null)
			EcrireCookie(id,parseInt(LireCookie(id))+1);
		else
			EcrireCookie(id,1);
	}
}

function getPopContent(){
	html="<style>";
	html+=".pop{font-family:arial,helvetica;padding:50px 20px 0 70px ;font-size:12px}";
	html+=".pop a{color:#0d51a0;text-decoration:none;}";
	html+=".close_div{position:absolute;margin-top:-90px;text-align:right;}";
	html+=".close_div a{text-decoration:none;font-size:12px;font-weight:bolder;color:#ffffff;}";
	html+="</style>";
	html+="<div class=\"pop\"><div class=\"texte\"><h1>Sondage</h1>";
	html+="<p>Dans son souci constant d'apporter les bonnes informations à ses usagers et d'adapter les canaux d'information à l'évolution des usages,		 le Conseil Régional de Lorraine organise une enquête en ligne pour améliorer ce/son site Internet et souhaite obtenir votre opinion sur quelques points.Auriez-vous 5 minutes à consacrer à notre questionnaire à la fin de votre visite?</p>";	html+="<a href=\"http://tmo.cawi.fr/cawi-P6067W4\"><b>>> Oui, je souhaite participer</b></a><br><br> <a href=\"javascript:void(0)\" onclick=\"popup('html_float')\"><b>>> Non, je ne souhaite pas participer</b></a><br>";
	html+="</div></div>";
	return html;
}

showPopIn('html_float');
