/*	mjas.js	
    time writer and cookie handler  */

function write_time()
{
	var day_name = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var month_name = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

	var cdate = new Date();
	var year = cdate.getYear();
	if ( year < 1900 )	{
		year +=1900;
	}
	var hour = cdate.getHours();
	if ( hour > 11 )	{
		hour -= 12;
		ap = "PM";
	}
	else  {
	 	ap = "AM";
	}
	if ( hour == 0 )	{
	 	hour = 12;
	}
	var minute = cdate.getMinutes();
	if ( minute < 10 )	{
		minute = "0" + minute;
	}
	document.write( day_name[ cdate.getDay() ] + ", " + cdate.getDate() + " " + month_name[ cdate.getMonth() ] + " " + year );
	document.write( ": " + hour + ":" + minute + " " + ap );
}

/*	All cookie functions assume that cookies are set using setCookie, and that
	the setting code does not use '; ' inside a field	*/

/*	Call setCookie with 'name' and 'value' strings (required), a GMT date (for
	persistence), and - optionally - 2 special strings and a Boolean	*/

function setCookie( name, value, expireDate, path, domain, is_secure )	{
	document.cookie = name + "=" + escape( value ) +
		(( expireDate ) ? "; expires=" + expireDate : "" ) +
		(( path ) ? "; path=" + path : "" ) +
		(( domain ) ? "; domain=" + domain : "" ) +
		(( is_secure ) ? "; secure" : "");
}

/*	To get a string reply, call getValue. For a number, call getNumber. Both
	functions should be called with a string (often in inverted commas...)	*/

function getValue( name )	{
	var cookies = document.cookie.split('; ');
	for ( var i = 0; i < cookies.length; i++ )	{
		var cookieName = cookies[ i ].split('=')[ 0 ];
		if ( cookieName == name )	{
			return unescape( cookies[ i ].split('=')[ 1 ] );
		} 
	}
	return "";
}

function getNumber( name )	{
	var c = parseInt( getValue( name ));
	if ( isNaN( c ))	{
		return 0;
	}
	return c;	
}

/*	Functions to delete a single cookie, or all of them	*/

function deleteCookie( name )	{
	var expireDate = new Date;
	expireDate.setDate( expireDate.getDate() - 1 );                           
	var cookies = document.cookie.split('; ');
	for ( var i = 0; i < cookies.length; i++ )	{
		var cookieName = cookies[ i ].split('=')[ 0 ];
		if ( cookieName == name )	{
			document.cookie = cookieName + "=; expires=" + expireDate.toGMTString();
		}
	}
}

function deleteCookies()	{
	var expireDate = new Date;
	expireDate.setDate( expireDate.getDate() - 1 );                           
	var cookies = document.cookie.split('; ');
	for ( var i = 0; i < cookies.length; i++ )	{
		var cookieName = cookies[ i ].split('=')[ 0 ];
		document.cookie = cookieName + "=; expires=" + expireDate.toGMTString();
	}
}

/*	A couple of functions for odd jobs	*/

function cookieTotal()	{
	if ( document.cookie == "" )	{
		return 0;
	}
	var cookies = document.cookie.split('; ');
	return cookies.length;
}

// getName called with a number, from 0 up
function getName( num )	{
	if ( document.cookie == "" )	{
		return "";
	}
	var cookies = document.cookie.split('; ');
	if ( cookies.length >= num )	{
		return cookies[ num ].split('=')[ 0 ];
	}
	return "";
}

/*	EOF	*/
