

function nameDefined(c,n) {
 var s=removeBlanks(c);
 var pairs=s.split(";");
 for(var i=0;i<pairs.length;++i)
 {
 var pairSplit=pairs[i].split("=");
 if(pairSplit[0]==n) return true;
 }
 return false;
}

function removeBlanks(s) {
   var temp="";
   for(var i=0;i<s.length;++i) {
      var c=s.charAt(i);
      if(c!=" ") temp += c;
   }
   return temp;
}

function getCookieValue(c,n) {
   var s=removeBlanks(c);
   var pairs=s.split(";");
   for(var i=0;i<pairs.length;++i) {
      var pairSplit=pairs[i].split("=");
      if(pairSplit[0]==n) return pairSplit[1];
   }
   return "";
}


function tryVote( gameid )
{
	if( !navigator.cookieEnabled ){
		alert( "Please enable the cookies in your browser in order to vote." );
		return;
	}
	var bPass = false;
	var s = "";
	var cookie=document.cookie
	var tvalue = "";
	s += gameid;
	if(nameDefined(cookie,s)) {
		tvalue=getCookieValue(cookie,s);
		var curdate = new Date();
		if( (curdate.getTime() - tvalue) < (24*60*60*1000)  ){
			alert( "You can vote only once a day for each product.\nThank you." );
		} else {
			bPass = true;
		}
	} else {
		bPass = true;
	}
	if( bPass ){
		var futdate = new Date();
		var newCookie=gameid+"="+futdate.getTime().toString()+";";
		var expdate = new Date();
		var cookieExpires = new Date();
		cookieExpires.setTime (expdate.getTime() + 1 * (24 * 60 * 60 * 1000)); //+1 day
		newCookie += "expires="+cookieExpires.toGMTString()+";";
		newCookie += "name="+gameid.toString()+";";
		window.document.cookie=newCookie;
		window.document.forms["votefrm"].submit();
		alert( "Your vote is accepted.\nThank you." );
	}
}
