// Reading cookies
function setCookie(name, value)
{
        var argv = setCookie.arguments;
        var argc = setCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;

        document.cookie = name + "=" + escape(value) +
                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}

// Getting cookies
function getCookie(name)
{
        var prefix = name + "=";
        var cookieStartIndex = document.cookie.indexOf(prefix);
        if (cookieStartIndex == -1)
                return null;
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length;
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

// Delete cookies
function deleteCookie(name, path, domain)
{
        if (getCookie(name)) {
                document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";
                             }
}

function CheckLimit(form)
{
	var length = form.descr.value.length;

	if (length > 255)
	{
		form.descr.value = form.descr.value.substring(0, 255);
		alert("This field is limited by 255 characters.");
		form.descr.focus();
	}
}				

function IsInCookie(CookieName, Value)
{
	var CookieValue = "";
	var CookieArray = new Array();

	if (getCookie(CookieName))
	{
		CookieValue = getCookie(CookieName);
		CookieArray = CookieValue.split(",");
		for(i=0; i<CookieArray.length; i++)
			if (CookieArray[i]==Value)
				return true;
	}
	
	return false;
}