/*	###########################################################################
		cookies.js
		cookie handling script
		
		(c)1999-2006 Frank Sattler, www.webarts.org
		No commercial use without prior permission of the author
	###########################################################################	*/

function setCookie(str_Name, str_Value, str_Domain, str_Path, date_Expires, boolean_IsSecure) {
	// initialise cookie string
	var str_Cookie			= '';
	var result				= false;
	if (str_Name == '') {															// if name parameter is empty, inform the user
		// alert('No cookie name was given!');
	} else {
		str_Cookie			= str_Name + '=' + escape(str_Value);					// if everything went smoothly, assemble name and value,

		if (str_Domain != '')														// add the domain if given,
			str_Cookie		+= '; domain=' + str_Domain;

		if (str_Path != '')															// add the path if given,
			str_Cookie		+= '; path=' + str_Path;
	
		if (date_Expires != '')														// add the date if given,
			str_Cookie		+= ';expires=' + date_Expires.toGMTString();

		if (boolean_IsSecure)														// and indicate secure status if necessary.
			str_Cookie		+= ';secure';
	
		document.cookie		= str_Cookie;											// Finally, set the cookie
		result				= true;													// and return.
	}
	return result;																	// and return the result.
}



function getCookie(str_Name) {
	var str_AllCookies 		= document.cookie;										// Get the string containing all cookies.
	var result				= '';
	str_Name				+= '=';													// Add an equal sign to the name (for search).
	var int_StartPos		= str_AllCookies.indexOf(str_Name);						// Search for cookie name in the cookie string.

	if (int_StartPos == -1) {
		// alert('Cookie not found!');													// If it wasn't found, inform the user
	} else {
		int_StartPos		+= str_Name.length;										// If the cookie name was found in the string, calculate the start position of the value
		var int_EndPos		= str_AllCookies.indexOf(';', int_StartPos);			// and find the end by looking for a semi-colon.

		if (int_EndPos == -1)	// If a semicolon wasn't found,
			int_EndPos		= str_AllCookies.length;								// the cookie we're looking for is the last one in the string.

		str_Value			= str_AllCookies.substring(int_StartPos, int_EndPos);	// Finally, get the substring that contains the cookie value,

		result				= unescape(str_Value);									// unescape result
	}
	return result;																	// and return.
}

