// aids.js
// JavaScript for the AIDS counter on the Africa's Right to Health Campaign page
/* Copyright (c) 2003 Africa Action */

// -----------------------------------------------------------------------------------
// returns a div/layer object given its ID.  Returns direct handle to
// object even on Netscape.
function getDocElem(doc, id)
{
	if (is.ie)
		return doc.all(id)
	else if (is.ns5)
		return doc.getElementById(id);
	else
		return eval("doc." + id);
}


// sets the text contents of an container object (probably a DIV/LAYER)
function aaSetText(id, newText)
{
	elem =  getDocElem(document, id);
	if (elem)
	{
		if (is.dom)
		{
			if (elem.innerHTML != newText)
				elem.innerHTML = newText;
		}
		else
		{
			// open document of layer and rewrite text
			elem.document.write(newText);
			elem.document.close();
		}
	}
}

function aaWriteTextContainer(id, str)
{
	// dynamic text not implemented for Netscape 4.x, so we don't have to put it
	// in a layer, which would normally be required.
	document.writeln('<font size=5><span ID="' + id + '">' + str + '</span></font>');
}


// 2.4 million Africans died of AIDS in 
// 2003.  This works out at 6575 per day, or 274 per hour, or 4.6 per 
// minute.  We would like the counter on the campaign page to start 
// fresh every night at midnight Eastern time.
// Based on the 2003 mortality statistics 
// from the UNAIDS/WHO in the AIDS Epidemic Update, December 2003 (http://www.unaids.org)."
function aaGetCount()
{
	var now = new Date();
	var seconds = (now.getHours() * 3600) + (now.getMinutes() * 60) + now.getSeconds();	
	return Math.floor((6575 * seconds) / (60 * 60 * 24));
}

function aaUpdateCount()
{
	if (is.dom)
		aaSetText("aidscount", aaGetCount());
}

// recompute every 3 seconds.  the number will really only update about every 12 seconds though.
var counter = setInterval('aaUpdateCount()', 3000);


