// Use this function to retrieve a cookie.
function getCookie(name){
var cname = name + "=";               
var dc = document.cookie;             
    if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
        if (begin != -1) {           
        begin += cname.length;       
        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
return null;
}

// Use this function to save a cookie.
function setCookie(name, value, expires) {
	var cookieinfo= name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
	document.cookie = cookieinfo;
}

// Use this function to delete a cookie.
function delCookie(name) {
	document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

// Checks a memeber is logged in. If not then default to current page else to success var
function checkMember (success) {
	var thiscookie = (getCookie('uname')!=null)? getCookie('uname') : false;

	if (!thiscookie) {
		spawn('../mod_perl/generatelogin.mpl?text=You+need+a+Britshorts+user+account+to+access+this+content.', 'filmpop', 480, 360, 100, 100);
	}
		else {
			document.location=success;
		}
}

// Returns the username
function getUsername () {
	var thiscookie = (getCookie('uname')!=null)? getCookie('uname') : false;
	return (thiscookie);
}