
function GetCCookie( ParentName, Name, DefaultValue ) {
	var CCookie = GetCookie( ParentName )	
	var start = CCookie.indexOf(Name + "=")
	if ( start >= 0 )  {
		start += Name.length + 1
		var end = CCookie.indexOf(";", start)
		if ( !(end >= 0) ) end = CCookie.length
		return unescape(CCookie.substring(start,end))
	}
	else if ( DefaultValue != void(0) )
		return DefaultValue
	return ""
}
// Create or update a cookie given it's name and value.
// The name and value are required
function SetCCookie( ParentName, Name, Value, Expires, Path, Domain ) {
	var ParentValue = GetCookie(ParentName),
		docCookie = Name + "=" + Value + ";"
	if ( ParentValue ) {
		var end, pos = ParentValue.indexOf(Name + "=")
		if ( pos >= 0 ) {
			end = ParentValue.indexOf(";", pos + 1) + 1
			docCookie = ParentValue.substring(0,pos) + docCookie + ParentValue.substring(end)
		}
		else
			docCookie += ParentValue
	}
// Finally, attempt to save the cookie
	docCookie = ParentName + "=" + escape(docCookie) + MakeCookieAttrStr(Expires, Path, Domain)
	if ( docCookie.length > 1024 )
		alert("Cookie " + ParentName + " is too large to save with " + Name + " sub cookie!")
	else
		self.document.cookie = docCookie
}

function GetCookie( Name )  { // Return the value of a cookie by name
	var allcookies = self.document.cookie
	var pos = allcookies.indexOf(Name + "=")
	if ( !(pos >= 0) ) return ""
	var start = pos + Name.length + 1
	var end = allcookies.indexOf(";", start)
	if ( !(end >= 0) ) end = allcookies.length
	return unescape(allcookies.substring(start,end))
}
// Create or update a cookie given it's name and value.
// The name and value are required
function SetCookie( CookieName, Value, Expires, Path, Domain ) {
	self.document.cookie = CookieName + "=" + escape(Value) + MakeCookieAttrStr(Expires, Path, Domain)
}

function DeleteCookie( CookieName, Path, Domain ) {
	Path? (Path = ";path=" + Path) : Path = ""
	Domain? (Domain = ";domain=" + Domain) : Domain = ""
	self.document.cookie = CookieName + "=;expires=Fri, 01-Jan-1971 12:00:00 GMT" + Domain + Path	
}

function MakeCookieAttrStr(Expires, Path, Domain) {
	var curDate
	if ( !Expires ) { // Make stored cookie
		curDate = new Date()
		curDate.setMonth(curDate.getMonth()+60) // Set for 5 years off current year
		Expires = ";expires=" + curDate.toGMTString()
	}
	else if ( Expires == true ) // Make session cookie
		Expires = ""
	else // Set reasonble expire date for stored cookie
		Expires = ";expires=" + Expires
	Path? (Path = ";path=" + Path) : Path = ""
	Domain? (Domain = ";domain=" + Domain) : Domain = ""	
	return Expires + Domain + Path
}

function DeleteCCookie( ParentName, Name, Path, Domain ) {
	var ParentValue = GetCookie(ParentName)		
	if ( ParentValue ) {
		var end, pos = ParentValue.indexOf(Name + "=")
		if ( pos >= 0 ) {
			end = ParentValue.indexOf(";", pos + 1) + 1
			docCookie = ParentValue.substring(0,pos) + ParentValue.substring(end)
			self.document.cookie = ParentName + "=" + escape(docCookie)
		}
	}
}
// Returns a GMT Date string based on your
// specified Y,M,D plus the current system date.
function GetExpDate( Years, Months, Days ) {
	var expDate = new Date()
	if ( Years ) expDate.setMonth(expDate.getMonth() + 12 * Years)
	if ( Months ) expDate.setMonth(expDate.getMonth() + Months)
	if ( Days ) expDate.setDate(expDate.getDate() + Days)
	return expDate.toGMTString()
}
