/***************************
	(C) 2005 by Charleshan www.Denninger.nl
	http://www.paranoid.demon.nl
	Free for all users, but leave in this header.
		Started:	06-09-2005
		Last change:	05-12-2005
	==========================
	v1.0B	08-09-2005	Release - Based on a script found @ http://www.webreference.com/js/column8/counter.html
	v1.0	05-12-2005	Converted into an .js scriptfile.
****************************/

function setCookie(name,value,expires,path,domain,secure) {
	/****************************
	name		= Name of the cookie.
	value		= Value of the cookie.
	[expires]	= Expiration date of the cookie		(defaults to end of current session).
	[path]		= Path for which the cookie is valid	(defaults to path of calling document).
	[domain]	= Domain for which the cookie is valid	(defaults to domain of calling document).
	[secure]	= Boolean value indicating if the cookie transmission requires a secure transmission.
	* An argument defaults when it is assigned null as a placeholder.
	* A null placeholder is not required for trailing omitted arguments.
	****************************/
	var curCookie=name+"="+escape(value)+
		((expires)?"; expires="+expires.toGMTString():"")+
		((path)	?"; path="+path:"")+
		((domain)	?"; domain="+domain:"")+
		((secure)	?"; secure":"");
	document.cookie=curCookie;
}

function getCookie(name) {
	/****************************
	name	= Name of the desired cookie return string containing value of specified cookie or null if cookie does not exist.
	****************************/
    var dc=document.cookie;
    var prefix=name+"=";
    var begin=dc.indexOf("; "+prefix);
    if (begin==-1) {
	begin=dc.indexOf(prefix);
	if (begin!=0) return null;
    } else begin+=2;
    var end=document.cookie.indexOf(";",begin);
    if (end==-1) end=dc.length;
    return unescape(dc.substring(begin+prefix.length,end));
}

function deleteCookie(name, path, domain) {
	/****************************
	name	= Name of the cookie.
	[path]	= Path of the cookie (must be same as path used to create cookie).
	[domain]	= Domain of the cookie (must be same as domain used to create cookie).
	* path and domain default if assigned null or omitted if no explicit argument proceeds.
	****************************/
	if (getCookie(name)) {
		document.cookie=name+"="+
		((path)	?"; path="+path:"")+
		((domain)	?"; domain="+domain:"")+
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function fixDate(date) {
	/****************************
	date	= Any instance of the Date object.
	* hand all instances of the Date object to this function for "repairs".
	****************************/
	var base=new Date(0);
	var skew=base.getTime();
	if (skew>0) date.setTime(date.getTime()-skew);
}

