
sysDebug("start popup");

document.write("<div id=\"thepopup\" class=\"popup\"></div>");

var inMove=0;

var inComming=0;

function isParent(child,parent)
{
	while(child)
	{
		if (child==parent)
			return 1;
		child = child.parentElement;
	}
	return 0;
}

function convertHTMLToAscii(_str)
{
 _str = _str.replace(/&lt;/g,"<");
 // _str = _str.replace(/&gt;/,">");

  return _str;
 }


function showPopup(title,str,event)
{
	if (inMove)
		return;
		
	if (!inComming)
		inComming=event.srcElement;

	sysDebug("showPopup");
			
	str2 = "<table width=\" 100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td style='background-color:blue; color:white;'><center>";
	str2 += convertHTMLToAscii(title);
	str2 += "</center></td><tr><td  style='background-color:darkgray'>";
	str2 += convertHTMLToAscii(str);
	str2 += "</td></tr></table>";
	
	sysWriteInnerHTML("thepopup",str2);
	movePopup(event);
	
	sysSetVisibility("thepopup","visible");
	sysSetMouseMoveEvent(movePopup);
}

function hidePopup(event)
{

	sysDebug("hidePopup");	
	
	if (isParent(event.toElement,inComming))
	{
		sysDebug("CHILD!");
		return;
	}
	inComming=0;
	
	sysSetVisibility("thepopup","hidden");
	sysSetMouseMoveEvent(null);
}

function movePopup(e)
{
	sysSetPosition("thepopup",sysGetMouseX(e)+16,sysGetMouseY(e)-16);

}

function addNav()
{
	var disabled=1;
	if ( (action=="master") || (action=="person") || (action=="ancestors") )
		disabled=0;
	
	document.write('<div class="popper" id="nav" ondrag="return false" onselectstart="return false">');
	document.write("<table width='100%' cellspacing=\"0\" cellpadding=\"0\">");
	document.write("<tr style=\"height:8px\"><td width=\"8\"><img src=\"pic/fill-ul.gif\"></td><td  width=\"100%\" style=\"background:url('pic/fill-upper.gif')\"></td><td width=\"8\"><img src=\"pic/fill-ur.gif\"/></td></tr>");

	document.write("<tr><td width=\"8\" style=\"background:url('pic/fill-left.gif')\"></td>");
	document.write("<td style='cursor:move' onmousedown='mouseClick(event);'><table width=\"100%\" style='background-color:white;'>");
	
	if (lan=="fr")
		document.write("<tr><td><font size=2><center>Site généalogique de<br /> la famille <b><a href='http://"+server+"'>GOGUEL</a></b></center></font></td></tr>")
	else
		document.write("<tr><td><font size=2><center>The&nbsp;<b><a href='http://"+server+"'>GOGUEL</a></b>&nbsp;family<br />genealogy&nbsp;page!</center></font></td></tr>");
	
	
	
	
	document.write("<tr height=200px><td><form id=\"theform\"");
	if (disabled)
		document.write(" disabled=\"disabled\"");
	document.write( "><p><i>Change&nbsp;View:</i><br /><br />");
	document.write('<input style=\"cursor:hand\" type="radio" name="iRadio" onactivate="theform.iLevel.disabled=true">Main Tree</input><br />');
	document.write("<input  style=\"cursor:hand\" type=\"radio\" name=\"iRadio\" onactivate=\"theform.iLevel.disabled=false\" >Ancestor&nbsp;");
	
	document.write('<select id="iLevel" size="1" disabled="disabled">');
	for(i=1;i<17;i++)document.write('<option value=' +i+ '>'+i);
	document.write('</select>');
	//document.write('&nbsp;<INPUT TYPE=checkbox name="iStretch">Stretch</INPUT>');
	document.write('<br />');
	document.write('<INPUT  style=\"cursor:hand\" type=radio name="iRadio" onactivate="theform.iLevel.disabled=true">Detail<br />');
	document.write('<INPUT  style=\"cursor:hand\" type=radio name="iRadio" onactivate="theform.iLevel.disabled=true">Parent<br />');
	
	document.write('<br /><br />');
	document.write('<center><Input type=button value="Display" onClick="changeView()"></center>');
	document.write("</form>");
//	document.write('<br /><center><a href="javascript:refresh()">(refresh cache)</a></center>');
	
	document.write("</td></tr>");
	document.write("<tr><td align=\"center\">");
	document.write ('<a href="javascript:moveTo('+"'',0,"+level+","+stretch+","+chrono+');">Home</a><br />');
     document.write ('<a href="javascript:moveTo('+"'indexpage',"+principal+","+level+","+stretch+","+chrono+');">Index</a><br />');
     document.write ('<a href="javascript:moveTo('+"'document',"+principal+","+level+","+stretch+","+chrono+');">Documents</a><br />');
     document.write ('<a href="javascript:moveTo('+"'chronologie',"+principal+","+level+","+stretch+","+chrono+');">Chronology</a><br />');

	document.write("</td></tr></table>");
	document.write("</td><td width=\"8\" style=\"background:url('pic/fill-right.gif')\"></td></tr>");

	document.write("<tr style=\"height:8px\"><td width=\"8\"><img src=\"pic/fill-ll.gif\"></td><td  width=\"100%\" style=\"background:url('pic/fill-lower.gif')\"></td><td width=\"8\"><img src=\"pic/fill-lr.gif\"/></td></tr>");
      document.write("</table></div>");

	if (!disabled)
	{
		if (action=="master")
			theform.iRadio[0].checked=true;
		else
		if (action=="ancestors")
		{
			theform.iRadio[1].checked=true;
			theform.iLevel.disabled=false;
		}
		else
		if (action=="person")
			theform.iRadio[2].checked=true;
		else
		if (action=="parent")
			theform.iRadio[3].checked=true;
			
				
		theform.iLevel.value=level;
	}	
	//iStretch.checked=stretch;
	//iChrono.checked=chrono;
}


function moveNav(e)
{
	sysDebug("moveNav");
	sysSetPosition("nav",sysGetScrollLeft(e)+absx,sysGetScrollTop(e)+absy);

}

function changeView()
{
    if (theform.iRadio[0].checked)
		action="master";
	else 
	if (theform.iRadio[1].checked)
		action="ancestors";
	else
	if (theform.iRadio[2].checked)
		action="person";
	else
	if (theform.iRadio[3].checked)
		action="parent";
	
	/*	
	if (iStretch.checked)
		s=1;
	else
		s=0;
	
	
	if (iChrono.checked)
		c=1;
	else
		c=0;
		*/	
	moveTo(action,principal,theform.iLevel.value);
}

function refresh()
{
	moveTo(action+"&refresh=1",principal,level,stretch,chrono);
}

function moveTo(_action,_principal,_level) //,_stretch,_chrono)
{
	setCookie("absx",absx);
	setCookie("absy",absy);
	setCookie("level",_level);
	if (_action=="")
		window.location = thefile
	else
	{
		if (_action=="ancestors")
			l = "&amp;level="+_level;
		else
			l= "";
		if (!_principal) _principal=1;
		window.location = thefile+"&amp;action="+_action+"&amp;principal="+_principal+l;
	}
}

// ****************** MOVE ********************

var deltax=0;
var deltay=0;

function get_mousemove(e)
{

//	sysDebug("mouseMove");
	
 var x = sysGetMouseX(e);
 var y = sysGetMouseY(e);
 sysSetPosition( "nav",x+deltax,y+deltay );
 
 absx =sysGetWindowX("nav") - document.body.scrollLeft;
 absy =sysGetWindowY("nav") -  document.body.scrollTop;
		
	return false;

}

function mouseClick(ev)
{
	sysDebug("mouseClick");
		
	var e = sysRetrieveEvent(ev);	
		
	var x = sysGetMouseX(e);
	
	var y = sysGetMouseY(e);
   	
 
	var pi = "nav";
		
	deltax = sysGetWindowX(pi) - x ;
	deltay = sysGetWindowY(pi) - y ;

	sysSetMouseMoveEvent( get_mousemove );
	sysDebug("to mouseMove ");
	inMove=1;
	return false;

}

function mouseUp()
{
	sysDebug("mouseUp");
	if (inMove)
	{
 		sysSetMouseMoveEvent( null );
 		setCookie("absx",absx);
		setCookie("absy",absy);
		inMove=0;
	}
	
}
/*
function addCounter()
{
	document.write('<a href="http://www.compteur.com" target="_top"><IMG border="0" SRC="http://www.compteur.com/cgi-bin/compteur.cpt?ID=141542&num=1"></a>');
}
*/

function submitGuestBook(_link,_name,_email,_comment,_host)
{

	_name = ascii2html(_name);
	_comment = ascii2html(_comment);
	_link += "&email="+_email+"&thename="+_name+"&comment="+_comment+"&thehost="+_host;
	
	moveTo(_link);	
}

   var hexChars = "0123456789ABCDEF";

function Dec2Hex (Dec) { var a = Dec % 16; var b = (Dec - a)/16; hex = "" + hexChars.charAt(b) + hexChars.charAt(a); return hex; }



function ascii2html(s) 
{
 if (!s) return ;

 return s.replace ( /(\w|\W)/g, 

   function (s, n) 
   {
     c=n.charCodeAt(0);
     return (c==10?'%0A':c==13?'%0D':c==34?'%22':c==39?'%27':c==38?'%26':(c>127?'%'+Dec2Hex(c)+'':n));
   }    
 );
}

function showGuestForm()
{
	h = document.getElementById("theguestform");
	if (h)
	{
		h.style.visibility='visible';
		h.style.position='';
	}
}

//sysSetScrollEvent(moveNav);

function mailto(user,domain)
{
 email=user+"@"+domain;
 window.location="mailto:"+email;
 }

sysDebug("popup activated!");

