//functions for setting, getting, and deleting cookies

function setCookie(NameOfCookie, value, expiredays) {
// Three variables are used to set the new cookie. 
// The name of the cookie, the value to be stored,
// and finaly the number of days till the cookie expires.
// The first lines in the function converts 
// the number of days to a valid date.
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
// The next line stores the cookie, simply by assigning 
// the values to the "document.cookie"-object.
// Note the date is converted to Greenwich Meantime using
// the "toGMTstring()"-function.
	document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function getCookie(NameOfCookie) {
	if (document.cookie.length > 0) { 
		begin = document.cookie.indexOf(NameOfCookie+"="); 
		if (begin != -1) { 
			// Our cookie was set. 
			// The value stored in the cookie is returned from the function.
			begin += NameOfCookie.length+1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));       } 
		}
	// Our cookie was not set. 
	// The value "null" is returned from the function.
	return null;  
}

function delCookie (NameOfCookie) {
// The function simply checks if the cookie is set.
// If so the expiredate is set to Jan. 1st 1970.
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function getFieldValue(strFieldName) {
    var strFieldValue;
    var objRegExp = new RegExp(strFieldName + "=([^&]+)","gi");

    if (objRegExp.test(location.search))
        strFieldValue = unescape(RegExp.$1);
    else strFieldValue="";

    return strFieldValue;
}
