function toggleBox(name) {
	var box = getElt(name);
	show(box);
	showSideBar();
}

function closeBox(elt) {
	var box = elt.parentNode.parentNode;
	hideBox(box);
}

function showSideBar() {
	var sidebar = getElt('sidebar');
	show(sidebar);
	sidebar.style.width="30%";
	var content = getElt('content');
	content.style.width="70%";
}

function hideSideBar() {
	var sidebar = getElt('sidebar');
	hide(sidebar);
	sidebar.style.width="0%";
	var content = getElt('content');
	content.style.width="100%";
}

function show(elt) {
	elt.style.display = 'block';
}

function hide(elt) {
	elt.style.display = 'none';
}

function hideBox(box) {
	hide(box);
	if (allHidden(box.parentNode)) hideSideBar();
}

//sends back true if all children of the elt are display:none
function allHidden(elt) {
	var kids = elt.childNodes;
    for(var i = 0; i < kids.length; i++) {
    	if (kids[i].tagName == 'DIV') {
    	//should work but the style from stylesheet are not assigned
    	//display attribute is not present although set to none
	    	//if (kids[i].style.display != 'none') return false;
	    	//we add a test wether the attribute display exists or is undefined
	    	if ((kids[i].style.display) && (kids[i].style.display != 'none')) return false;
	    }
    }
    return true;
}

//cross browser stuff
function getElt(name) {
	//IE
	if (document.all) {
		return document.all[name];
	//NS4+
	} else if (document.layers) {
		return document.layers[name];
	//NS6+
	} else if (document.getElementById) {
		return document.getElementById(name);
	} 
}

/*
Ultimate Age calculator script- By JavaScript Kit (http://www.javascriptkit.com)
Over 200+ free scripts here!
Credit must stay intact for use
adapted by P@ for my own use
*/
var one_day=1000*60*60*24


function displayage(yr, mon, day, unit, decimal, round){
	var one_day=1000*60*60*24
	var one_month=1000*60*60*24*30
	var one_year=1000*60*60*24*30*12
	
	today=new Date()
	var pastdate=new Date(yr, mon-1, day)
	
	var countunit=unit
	var decimals=decimal
	var rounding=round
	
	finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year
	decimals=(decimals<=0)? 1 : decimals*10
	
	if (unit!="years"){
		if (rounding=="rounddown")
			return (Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)
		else
			return (Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)
		}
	else {
		yearspast=today.getFullYear()-yr-1
		tail=(today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0
		pastdate.setFullYear(today.getFullYear())
		pastdate2=new Date(today.getFullYear()-1, mon-1, day)
		tail=(tail==1)? tail+Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals : Math.floor((today.getTime()-pastdate2.getTime())/(finalunit)*decimals)/decimals
		return (yearspast+tail+" "+countunit)
	}
}

//Sample usage
//displayage (year, month, day, unit, decimals, rounding)
//Unit can be "years", "months", or "days"
//Decimals specifies demical places to round to (ie: 2)
//Rounding can be "roundup" or "rounddown"

//displayage(1997, 11, 24, "years", 0, "rounddown")

//my old age function
function AgeInDays(day,month,year) {
	// computes my age today
	dMyBirthDay = new Date(year,month,day);
	dToday = new Date();
	// my birthday day this year
	iMyAge=Math.ceil((dToday.getTime() - dMyBirthDay.getTime())/(1000*60*60*24))-1;
	return iMyAge;
}

function ageAutom(day,month,year) {
	dMyBirthDay = new Date(year,month,day);
	dToday = new Date();
	iMyAge=Math.ceil((dToday.getTime() - dMyBirthDay.getTime())/(one_day))-1;
	if (iMyAge < 30) {
		document.write(displayage(year, month, day, "days", 0, "rounddown"))
		return
	}
	if (iMyAge < 365) {
		document.write(displayage(year, month, day, "months", 0, "rounddown"))
		return
	}
	document.write(displayage(year, month, day, "years", 1, "rounddown"))
}
