checkPointsCookie();

var jsReady = false;
	function isReady() {
	return jsReady;
}

function pageInit() {
	jsReady = true;
	//document.forms["form1"].output.value += "\n" + "JavaScript is ready.\n";
	//alert ("This is a Javascript Alert")
}

function checkPointsCookie() {
	//alert("check for points called");
	var acookie = CheckCookie("ulcpnt");
	if (acookie) { 
		//alert("there is a cookie do NOTHING");
	} else {
		createCookie("ulcpnt","0",1);
		//var mytotalpoints;
		//mytotalpoints = parseInt(acookie) + this_many;
		//alert("the cookie ulcpnt exists === " + mytotalpoints);
	}
}
function FlashPointsIncoming(this_many)  {
	// called from second button over... 
	var acookie = CheckCookie("ulcpnt");
	if (acookie.length == 0) { 
		//alert("your cookie named ulcpnt does not exist so I will create one now")
		createCookie("ulcpnt",this_many,1);
		//alert("should create a cookie now with " + this_many);
		// go ahead and create one then with this many points
	} else {
		// ok then lets take the value and add it on here  parseInt('123.45')
		var mytotalpoints;
		mytotalpoints = parseInt(acookie) + this_many;
		//var mytotalpoints = pareseInt(acookie.value) + this_many;
		//alert("the cookie ulcpnt  exists and will now be equal to " + mytotalpoints);
		createCookie("ulcpnt",mytotalpoints,1);
	}
}
//////////////////////// returns the value of a cookie with name n ////////////////////////
function CheckCookie(n) {
	var cookiecontent = new String();
	if(document.cookie.length > 0) {
		var cookiename = n+ '=';
		var cookiebegin = document.cookie.indexOf(cookiename);
		var cookieend = 0;
		if(cookiebegin > -1) {
			cookiebegin += cookiename.length;
			cookieend = document.cookie.indexOf(";",cookiebegin);
			if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
			cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
	}
	return unescape(cookiecontent);
} // function CheckCookie()

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
function sendToActionScript(value) {
	// no longer needed for our use... only used in the "forms below"
	thisMovie("ExternalInterfaceExample").sendToActionScript(value);
	//thisMovie("ExternalInterfaceExample").sendToActionScript(value);
}
function sendToJavaScript(value) {
	// alert ("This is a Javascript Alert")
	document.forms["form1"].output.value += "ActionScript says: " + value + "\n";
	// here we need to send out a value for the cookie to grab and add on... 
}
function createCookie(name,value,days) {
	// currently sending in 10 from the button on the flash movie here, expiring in seven days.
	//sendToActionScript(6);
	//alert("kk");
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		// if (c.indexOf(nameEQ) == 0) sendToActionScript(c.substring(nameEQ.length,c.length));
		if (c.indexOf(nameEQ) == 0) return (c.substring(nameEQ.length,c.length));
	}
}