/*
	Fonction: afficher une pop up dhtml
	Auteur: Morgan "2nice4u.net" <its2nice4u@hotmail.fr>
	Date de création: 14/05/07
	Dernière modification: 19/05/07
*/

zdx=1;

function createDiv(x, y, w, h, bgcolor, id)
{
// création d'une div
	var v=document.createElement("div");
	v.setAttribute("id", id); 
	v.style.visibility="visible";
	v.style.backgroundColor=bgcolor;
	v.style.left=x+"px";
	v.style.top=y+"px";
	v.style.position="absolute";
	v.style.width=w+"px";
	v.style.height=h+"px";
	
	return v;
}

function closeDiv(id)
{
	document.getElementById(id).style.display="none";
}

function createCookie(nom, valeur)
{
	var argv=createCookie.arguments;
	var argc=createCookie.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 getValeurCookie(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	
	if (endstr==-1)
		endstr=document.cookie.length;
		
	return unescape(document.cookie.substring(offset, endstr)); 
}

function readCookie(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 getValeurCookie(j);
			
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0)
			break;	
	}
	
	return null; 
}

function popUp(x, y, id)
{
// création de la pop up
	var nbAffichages=1;
	
	if (readCookie("nbaffichages")==null)
		createCookie("nbaffichages", nbAffichages);
	else
	{
		nbAffichages=readCookie("nbaffichages");
		nbAffichages++;
		createCookie("nbaffichages", nbAffichages);
	}

	var limiteNbAffichages=2;
	
	if (nbAffichages<=limiteNbAffichages)
	{
		var w=500;
		var h=350;
		var bgcolor="#A3C7FE";
		var bordercolor="#003BE0";
		var contenu='<table width="100%" height="100%" border="0" style="border-left:2px solid '+bordercolor+'; border-right:2px solid '+bordercolor+'; border-bottom:2px solid '+bordercolor+';"><tr><td height="96%"><iframe src="http://www.2nice4u.net/topsites_pop.php?in='+id+'" width="100%" height="100%" name="pop" border="0" style="border:none; background-color:#A3C7FE; padding:0px; width:100%; height:100%;"></iframe></td></tr></table>';
		var height_haut_pop=30;
		
		var haut_pop=new createDiv (0, 0, w, height_haut_pop, bgcolor, "haut_pop");
		haut_pop.innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
		'<tr>'+
		'<td><a href="http://www.2nice4u.net/topsites.php?in='+id+'" target="_blank"><img src="http://www.2nice4u.net/images/design/pop_top.png" width="470" height="30" border="0" /></a></td>'+
		'<td><a href="#" onClick="closeDiv(\'pop\')"><img src="http://www.2nice4u.net/images/design/pop_close.png" width="30" height="30" border="0" /></a></td>'+
		'</tr>'+
		'</table>';
		var contenu_pop=new createDiv (0, height_haut_pop, w, h-height_haut_pop, bgcolor, "contenu_pop");
		contenu_pop.innerHTML=contenu;
		var pop=new createDiv (x, y, w, h, bgcolor, "pop");
		pop.style.overflow="hidden";
		pop.style.borderWidth="0px";
		pop.style.padding="0px";
		pop.style.zIndex=++zdx;
		pop.appendChild(haut_pop);
		pop.appendChild(contenu_pop);
		document.body.appendChild(pop);
	}
}