
function tr(x,y,t)
{
	if (x=='0') {
		alert(x);
	}
	return '<img src="'+t+'_images/blank.gif" width='+x+' height='+y+' border=0><br>';
}

function iif(condition,iftrue,iffalse)
{
	if (condition) {
		return iftrue;
	} else {
		return iffalse;
	}
}


function change(year)
{
	for (i=0; i < timeline.length; i++) {
	

		//year loop - looks for y
		if (timeline.charAt(i)=='#') {
			tyear=timeline.substring(i+1, i+5);i=i+6,pos=i;
			if ((year)>=(tyear)) {	
				//alert(year+'>='+tyear);
			}
		} //year loop
		
		//next year
		if ((year)>=(tyear)) {
			//action - triggered by comma
			if (timeline.charAt(i)==',') {
				//found item, going back from comma to end of last chunk found (pos)
				person=timeline.substring(pos,pos+5);
				type=timeline.substring(pos+5,pos+6);
				file=timeline.substring(pos+6,i);
				
				pos=i+1; //set pos for next item
				
				
				//birth
				if (type=='B') {type='n'+person;style('n'+person,'display','none');}
				if (type=='b') {type='n'+person;style('n'+person,'display','block');document.images['t'+person].src=('_images/blank.gif');}
				//edit date
				if (type=='Z') {type='z'+person;style(type,'display','block');}
				//death
				if (type=='D') {type='d'+person;style(type,'display','none');}
				if (type=='d') {type='d'+person;style(type,'display','block');}
				//change thumbnail
				if (type=='t') {type='t'+person;document.images[type].src=('thumbnails/'+file);}
				
				//marriages
				if (type=='M') {type='m'+person;style(type,'display','none');}
				if (type=='m') {type='m'+person;style(type,'display','block');}
				//edit date
				if (type=='X') {type='x'+person;style(type,'display','block');}
				//separation
				if (type=='N') {type='r'+person;style(type,'display','none');}
				if (type=='n') {type='r'+person;style(type,'display','block');}
				
			}//item loop
			
		}//next year
		
	}//each character
}


function style(whichLayer,element,value)
{	//block or none
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		var attribute = style2.element;
		style2[element] = value;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2[element] =  value;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2[element] =  value;
	}
}


function rearrange(child,direction) {
	var moved = Number(document.data[('childMoved'+child)].value);
	var position = Number(document.data[('childFinal'+child)].value);
	var siblings = Number(document.data['siblings'].value);
	
	//direction governs whether things are moving left or right, older or younger - reversed for the overlapping sibling
	if (direction=='left') {direction=-1;} else {direction=1;}
	
	//new position in order, from 0 down
	var newposition = position+direction;
	
	//skip if positions not possible 
	if (newposition<1) {return;} 
	if (newposition>siblings) {return;} 
	
	var width =172;
	var ms=60;
	
	//move the indicated sibling
	move1=Number(Number(document.data[('childMoved'+child)].value)*width);
	document.data[('childMoved'+child)].value=moved+direction;
	move2=Number(Number(document.data[('childMoved'+child)].value)*width);
	
	//find and move overlapping sibling in opposite direction
	for (i = 1; i < (siblings+1); i++) {
		if (Number(document.data[('childFinal'+i)].value)==newposition) {
			document.data[('childFinal'+i)].value=position;
			
			movei=Number(Number(document.data[('childMoved'+i)].value)*width);
			document.data[('childMoved'+i)].value=Number(document.data[('childMoved'+i)].value)-direction;
			movej=Number(Number(document.data[('childMoved'+i)].value)*width);
			
			var t1=("moveChild("+child+","+Number(move1+(direction*width)/5)+");");
			setTimeout(t1,ms);
			var ti=("moveChild("+i+","+Number(movei-(direction*width)/5)+");");
			setTimeout(ti,ms);
			
			
			var t1=("moveChild("+child+","+Number(move1+(direction*width)/8)+");");
			setTimeout(t1,ms*0.5);
			var ti=("moveChild("+i+","+Number(movei-(direction*width)/8)+");");
			setTimeout(ti,ms*0.5);
			
			var t1=("moveChild("+child+","+Number(move1+(direction*width)/3)+");");
			setTimeout(t1,ms*2);
			var ti=("moveChild("+i+","+Number(movei-(direction*width)/3)+");");
			setTimeout(ti,ms*2);
			
			var t1=("moveChild("+child+","+Number(move1+(direction*width)*2/3)+");");
			setTimeout(t1,ms*3);
			var ti=("moveChild("+i+","+Number(movei-(direction*width)*2/3)+");");
			setTimeout(ti,ms*3);
			
			var t1=("moveChild("+child+","+Number(move1+(direction*width)*4/5)+");");
			setTimeout(t1,ms*4);
			var ti=("moveChild("+i+","+Number(movei-(direction*width)*4/5)+");");
			setTimeout(ti,ms*4);
			
			var t1=("moveChild("+child+","+Number(move1+(direction*width)*7/8)+");");
			setTimeout(t1,ms*4.5);
			var ti=("moveChild("+i+","+Number(movei-(direction*width)*7/8)+");");
			setTimeout(ti,ms*4.5);
			
			var t1=("moveChild("+child+","+Number(move1+(direction*width))+");");
			setTimeout(t1,ms*5);
			var ti=("moveChild("+i+","+Number(movei-(direction*width))+");");
			setTimeout(ti,ms*5);
		}
	}
	//has to be after loop, to only find the old overlap
	document.data[('childFinal'+child)].value=newposition;
}


function moveChild(number,px){
     style ('child'+number,'left',px+'px');
}


function familyLinkChange(link)
{//setImage(whichLayer,imageName)
	return ' OnMouseOver="document.link'+link+'.src=(\'_images/familyMarriageSmall_highlight.gif\')"  OnMouseOut="document.link'+link+'.src=(\'_images/familyMarriageSmall_active.gif\')"';
	//return ' OnMouseOver="setImage(\'m'+link+'\',\'/_images/familyMarriageSmall_highlight.gif\');" OnMouseOut="document.m'+link+'.src=(\'/_images/familyMarriageSmall_active.gif\')"';
}
function familyLink(link)
{//assumes in root directory, for links to images
	if (link>0) {
		//linkText='-'+(100000+link);
		//linkText=linkText.substr(2,6);
		//alert(linkText);
		//window.document.write('<div id="m'+link+'">');
		window.document.write('<a href="family.php?r='+link+'"'+familyLinkChange(link)+'>');
		window.document.write('<img name="link'+link+'" alt="link" src="_images/familyMarriageSmall_active.gif" WIDTH="130px" HEIGHT="16px" BORDER=0>');
		window.document.write('</a>');
		//window.document.write('</div>');
	} else {
		window.document.write('<img src="_images/familyMarriageSmall.gif" WIDTH="130px" HEIGHT="16px" BORDER=0>');
	}
}



function setDays(name) {
// script adapted from original by Arash Ramin (http://www.digitalroom.net)

	var y = document.data[('year'+name)].options[document.data[('year'+name)].selectedIndex].value;
	var m = document.data[('month'+name)].selectedIndex;
	var d = document.data[('day'+name)].options[document.data[('day'+name)].selectedIndex].value;
  
	// find number of days in current month
	if ( (m == 4) || (m == 6) || (m == 9) || (m == 11) ) {
		days = 30;
	}
	else if (m == 2) {
	// check for leapyear - Any year divisible by 4, except those divisible by 100 (but NOT 400)
    if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
      days = 29
    else
      days = 28
  }
  else {
    days = 31;
  }




  // if (days in new month > current days) then we must add the extra days
  if (days > (document.data[('day'+name)].length)) {
    for (i = (document.data[('day'+name)].length); i < (days+1); i++) {
      document.data[('day'+name)].length = days+1;
      document.data[('day'+name)].options[i].text = i;
      document.data[('day'+name)].options[i].value = i;
    }
	//document.dateForm.result.value='+='+days;
  }

  
	// if (days in new month < current days) then we must delete the extra days
	if ((days+1) < document.data[('day'+name)].length) {
		document.data[('day'+name)].length = (days+1);
		if (document.data[('day'+name)].selectedIndex == -1) {
      		document.data[('day'+name)].selectedIndex = -1;
		}
	}
    
	//if month not set, unset the day, and remove days choice
	if (m==0) {
		document.data[('day'+name)].options.length = 1;
	}
	
}






function show(id) {
	$(id).style.display='block';
}
function hide(id) {
	$(id).style.display='none';
}

function toggleDisplay(id) {
	if ($(id).style.display=='block')
	{
		$(id).style.display='none';
	} else {
		$(id).style.display='block';
	}
}







/* adapted from http://www.netlobo.com/div_hiding.html */
function rollDisplay(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		var ms=40;
		if (style2.display=="block") {
			style2.height = '100%';
			for (var h= 50;h>0;h--) {
			
				var t1=("roller("+whichLayer+","+h+");");
				setTimeout(t1,h);
				//style2.height = p+'px';
			}
		} else {	
			style2.height = '0%';
			style2.display = "block";
			for (var h=0;h<50;h++) {
				//style2.height = (h)+'px';
				var t1=("roller("+whichLayer+","+h+");");
				setTimeout(t1,h);
			}
			//style2.height = '100%';
		}
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = (style2.display=="block") ? "none" : "block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = (style2.display=="block") ? "none" : "block";
	}
}

		//	var t1=("moveChild("+child+","+Number(move1+(direction*width))+");");
		//	setTimeout(t1,ms*5);
			
function roller(id,px) {
  	style (id,'height',px+'px');
}

















function setMapHeight()
{
	var theWidth = getBrowserWidth();
	var theHeight = getBrowserHeight();

	//alert (theWidth+' '+theHeight);
	
	
	var theMap = document.getElementById("map");
	
	//theFrame.style.width = (theWidth-110)+"px";
	theMap.style.height = (theHeight-107)+"px";
	
	return true;
}




function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
}



function getBrowserHeight()
{
	if (window.innerHeight)
	{
		return window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight != 0)
	{
		return document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		return document.body.clientHeight;
	}
	
	return 0;
}






function lookup(id,link_up,link_down,t) {
	var lookup = $('lookup');
	//alert(link_up+t+link_down);
	$('lookupText').setHTML('looking up connection details...');
 	new Ajax(t+'lookup.php?n='+id+'&r='+link_up+'&r2='+link_down,{method:'get',update:'lookupText'}).request();
	
	lookup.setStyle('display','block');
	new Fx.Style('lookupBackground', 'opacity').set(0.7);
	new Fx.Styles(lookup).start({'height':[1,200],'opacity':[0,1]});
	
	//alert(id+'#'+link_up+t+link_down);
}

function lookupHide() {
	var lookup = $('lookup');
	
	new Fx.Styles(lookup).start({'height':[200,1],'opacity':[1,0]});
	lookup.setStyle('display','none');
	$('lookupText').setHTML('','');
}