/*
<b>CanSetCookies() </b>
written by Matt Pressnall 10/24/03

<b>What does it do?</b>
Lets you know if a user can set cookies on their local computer -- only works if they have JS turned on.  Duh.

<b>How do I use it?</b>
&lt;script src="/js/standardFunctionality/CanSetCookies.js"&gt;&lt;/script&gt;
&lt;SCRIPT LANGUAGE="JavaScript"&gt;
var canSetCookies = CanSetCookies();
&lt;/SCRIPT&gt;
It will return true if it's true or false if it is false.
*/


function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function CanSetCookies(){

	var appname = navigator.appName;
	// test for IE and then check if it can set cookies cuz IE reports it always can even if it can't
	if(appname == "Microsoft Internet Explorer"){
		var today = new Date();
		var zero_date = new Date(0,0,0);
		today.setTime(today.getTime() - zero_date.getTime());
		
		var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
		var expires_date = new Date(todays_date.getTime());
		
		Set_Cookie("CanSetCookie","true",expires_date);
		var canSetCookie = Get_Cookie("CanSetCookie");
		Delete_Cookie('CanSetCookie');
		return canSetCookie;
	// other browsers, just ask them nicely and they tell you
	} else {
		var canSetCookie=(navigator.cookieEnabled)? true : false

		if (typeof navigator.cookieEnabled=="undefined" && !canSetCookie){ 
			document.cookie="testcookie"
			canSetCookie=(document.cookie.indexOf("testcookie")!=-1)? true : false
		}
		return canSetCookie;
	}
}