//New Cookie code for short-duration cookies
//make sure the cookie name is in the game name as "cookiename", should be the same as the canonical game name
//Now with tasty cookies!

var hascookie = false;

function getCookieVal (offset) {
	hascookie = true;
 var endstr = document.cookie.indexOf (";", offset);
 if (endstr == -1)
  endstr = document.cookie.length;
 return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
 var arg = name + "=";
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0;
 while (i < clen) {
  var j = i + alen;
  if (document.cookie.substring(i, j) == arg)
   return getCookieVal (j);
  i = document.cookie.indexOf(" ", i) + 1;
  if (i == 0) break;
 }
 return null;
}

function SetCookie (name,value,expires,path,domain,secure) {
 document.cookie = name + "=" + escape (value) +
  ((expires) ? "; expires=" + expires.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");
}


var expdate = new Date();
expdate.setTime (expdate.getTime() + (30 * 60 * 1000));

var thisdomain = ".net4tv.com";
var thispath = "/";


function cookie_setup() {
	//place_cookie();
	highscores = GetCookie(cookiename);
	if (!hascookie) {
		place_cookie();

	}
	else {
	//alert("has cookie: " + highscores);
	scoretable = highscores.split('|');
	high_score = parseInt(scoretable[0]);
	total_score = parseInt(scoretable[1]);
	level = parseInt(scoretable[2]);
	todays_high = parseInt(scoretable[3]);
	soundoff = parseInt(scoretable[4]);
	}
}

function place_cookie() {
  		highscores = high_score + "|" + total_score + "|1|" + todays_high+"|"+ soundoff;
  		//SetCookie(cookiename,highscores,expdate,thispath);
  		SetCookie(cookiename,highscores,null,thispath);
  		//alert("placed cookie: " + highscores);
  	}

function clearCookie() {
	expdate.setTime (expdate.getTime() - (30 * 24 * 60 * 60 * 1000));
	SetCookie(cookiename,0,expdate);
		alert("Cookies are cleared!");
}



//END cookie code