

var defaultBG="ffffff";
var defaultFG="7f7755";
var defaultLen=2;
var defaultRad=20;

var popup=null;
var backDiv=null;

function popupBoxUrl(url,width,bg,fg,len,radius){
	ajax(url,null,false,function(result){
		//alert(result);
		var contentDiv=appendNode(document.getElementsByTagName("body")[0],"div");
		contentDiv.innerHTML=result;
		popupBoxDiv(contentDiv,bg,fg,len,radius);
	});	
}

function popupBox(divName,bg,fg,len,radius){
	popupBoxDiv(ed(divName),bg,fg,len,radius);
}

function popupMsg(msg,bg,fg,len,radius){
	var div=document.createElement("div");
	div.innerHTML=msg;
	div.innerHTML+="<br><a class='imagesmall next16' href='javascript:popup.close()'>OK</a>";
	popupBoxDiv(div,bg,fg,len,radius);
}


function popupConfirm(msg,onyes,onno,bg,fg,len,radius){
	window.onyes=function(){};
	window.onno=function(){};
	if(onyes!=null)
		window.onyes=onyes;
	if(onno!=null)
		window.onno=onno;
	var div=document.createElement("div");
	div.style.width="400px";
	div.innerHTML=msg;
	div.innerHTML+="<br><a class='imagesmall next16' href='javascript:onyes();popup.close()'>OUI</a>  ";
	div.innerHTML+="<a class='imagesmall delete16' href='javascript:onno();popup.close()'>NON</a>";
	popupBoxDiv(div,bg,fg,len,radius);
}

function popupBoxDiv(thediv,bg,fg,len,radius){
		
	if(popup!=null){
		popup.close();
		return;
	}
	
	var size=getWindowDims();//getWindowSize();
	
	
	backDiv=appendNode(document.getElementsByTagName("body")[0],"div");
	backDiv.style.top=0;
	backDiv.style.left=0;
	var wz=getWindowSize();
	backDiv.style.width="100%";//wz.width+"px";//"3000px";//size.width+"px";
	backDiv.style.height="300%";//wz.height+"px";//"3000px";
	backDiv.style.zIndex=99;
	backDiv.style.position="absolute";
	backDiv.style.backgroundColor="black";
	transparency(backDiv,0.3);
	
	
	var div=appendNode(document.getElementsByTagName("body")[0],"div");
	
	//BUG marche pas en mode callback
	var callback=function(){
	div.innerHTML=thediv.innerHTML;
	thediv.innerHTML="";//remove old node
	
	var layout=function(){
	div.style.position="absolute";
	div.style.width=thediv.style.width;//400px";
	div.style.zIndex=100;
	
	div.style.top=(size.yMiddle-div.offsetHeight/2)+"px";//(size.top+(size.height-div.offsetHeight)/2)+"px";
	div.style.left=(size.xMiddle-div.offsetWidth/2)+"px";//(size.left+(size.width-div.offsetWidth)/2)+"px";		

	}
	
	layout();
	simpleConnect(window,"onresize",layout);
	
	popup=div;
	popup.close=function(){
		//alert("close");
		//restore node
		thediv.innerHTML=popup.innerHTML;
		removeNode(popup);
		removeNode(backDiv);
		popup=null;
		backDiv=null;
	}
	//return popup;
	};
	roundBoxDiv(thediv,null, bg, fg, len, radius);
	callback();
	
	
}
function roundBox(divName,callback,bg,fg,len,radius){
	
	var div=ed(divName);	
	
	roundBoxDiv(div,callback,bg,fg,len,radius);
}

function url(bg,fg,len,radius,mode){
	return "rcimages/"+mode+"-"+bg+"-"+fg+"-"+len+"-"+radius+".png";
}
function roundBoxDiv(div,callback,bg,fg,len,radius){
	
	//test if round was called
	if(div.getAttribute("round")=="true")
		return;
	div.setAttribute("round","true");
	
	if(fg==null)
		fg=defaultFG;
	if(bg==null)
		bg=defaultBG;
	if(len==null)
		len=defaultLen;
	if(radius==null)
		radius=defaultRad;
	
	//var url="rcimages?bg="+bg+"&fg="+fg+"&len="+len+"&radius="+radius;
	//var ul=url("")
	var ul="rcimages/UL"+"-"+bg+"-"+fg+"-"+len+"-"+radius+".png";
	var ur="rcimages/UR"+"-"+bg+"-"+fg+"-"+len+"-"+radius+".png";
	var dr="rcimages/DR"+"-"+bg+"-"+fg+"-"+len+"-"+radius+".png";
	var dl="rcimages/DL"+"-"+bg+"-"+fg+"-"+len+"-"+radius+".png";
		
	//alert("pop3");
	var openpopup=function(){
		var wi=div.style.width;
		var inner=div.innerHTML;
		
		var inner2=	"<table width='"+wi+"' border='0' cellspacing='0' cellpadding='0' >"+
					"<tr>"+
					"<td width='"+radius+"'><img src='"+ul+"' width='"+radius+"' height='"+radius+"'></td>"+
					"<td style='border-top:"+len+"px solid #"+fg+";background-color:#"+bg+"'>&nbsp;</td>"+
					"<td width='"+radius+"'><img src='"+ur+"' width='"+radius+"' height='"+radius+"'></td>"+
					"</tr>"+
					"<tr>"+
					"<td style='border-left:"+len+"px solid #"+fg+";background-color:#"+bg+"'>&nbsp;</td>"+
					"<td style='background-color:#"+bg+"'>";
		inner2=inner2+inner;
		inner2=inner2+"	</td>"+
						"<td style='border-right:"+len+"px solid #"+fg+";background-color:#"+bg+"'>&nbsp;</td>"+
						"</tr>"+
						"<tr>"+
						"<td width='"+radius+"'><img src='"+dl+"' width='"+radius+"' height='"+radius+"'></td>"+
						"<td style='border-bottom:"+len+"px solid #"+fg+";background-color:#"+bg+"'>&nbsp;</td>"+
						"<td width='"+radius+"'><img src='"+dr+"' width='"+radius+"' height='"+radius+"'></td>"+
						"</tr>"+
						"</table>"	;
		div.innerHTML=inner2;
		if(callback!=null)
			callback();
	}
	//alert("open");
	//preload(openpopup,ul,ur,dl,dr);
	openpopup();
}
/*
function roundBoxOld(divName){
	var div=e(divName);
	var wi=div.style.width;
	var inner=div.innerHTML;
	
	var inner2=	"<table width='"+wi+"' border='0' cellspacing='0' cellpadding='0' >"+
				"<tr>"+
				"<td width='20'><img src='css/images/nw.gif' width='20' height='20'></td>"+
				"<td style='background-color:white'><!-- Blank top section --></td>"+
				"<td width='20'><img src='css/images/ne.gif' width='20' height='20'></td>"+
				"</tr>"+
				"<tr>"+
				"<td style='background-color:white'><!-- Blank left section --></td>"+
				"<td style='background-color:white'>";
	inner2=inner2+inner;
	inner2=inner2+"	</td>"+
					"<td style='background-color:white'></td>"+
					"</tr>"+
					"<tr>"+
					"<td width='20'><img src='css/images/sw.gif' width='20' height='20'></td>"+
					"<td style='background-color:white'>"+
					"<!--Blank bottom section -->"+
					"</td>"+
					"<td width='20'><img src='css/images/se.gif' width='20' height='20'></td>"+
					"</tr>"+
					"</table>"	;
	div.innerHTML=inner2;
	
}*/

//install tooltips
function toolTipInstall(toolBox,toolControls){
	
	e(toolControls).onmousemove=function(ev){
		
		var id=ev.target.getAttribute("tooltip");
		
		if(id!=null){
			//console.debug(id);
			e(toolBox).innerHTML=e(id).innerHTML;
			roundBox(toolBox);
			e(toolBox).style.visibility="true";
		}			
	}	
}

//il doit y avoir un div avec l'id toolTipBox (et qui contiendra le tooltip)
var timeout=null;
var timeLen=0;
function showTip(tooltip){
	if(timeout!=null)
		clearTimeout(timeout);
	timeout=setTimeout(function(){
		var id=tooltip;
		var toolBox="toolTipBox";
		ed(toolBox).innerHTML=ed(id).innerHTML;
		timeout=null;
	},timeLen);
	
	//roundBox(toolBox);
	//e(toolBox).style.visibility="true";
	
}


