<!--

function requestFailed(httpRequest) {
  alert('Sorry, your request failed: try closing the browser and starting again.');
}

function getRating(game) {
  game = game.toLowerCase();  game = game.replace(/ /g,"");
	
  rateReq.url = '/getRatings.php';
  rateReq.successCallback = writeRating;
  rateReq.post("s=0" + "&gID=" + encodeURI(game));
  if(readCookie(game + 'freeclassicgames'))
    writeTxt('You already voted.', 'thanks');
  else
    writeTxt('Rate this game!', 'thanks');
}

function sendRate(value, game) {

  game = game.toLowerCase();  game = game.replace(/ /g,"");
  if(!readCookie(game + 'freeclassicgames')) 
	{
    rateReq.url = '../../getRatings.php';
    rateReq.successCallback = writeRating;
    rateReq.post("s=" + encodeURI(value) + "&gID=" + encodeURI(game));
    createCookie(game + 'freeclassicgames', 'voted', 14);
	  writeTxt('Thanks for voting!', 'thanks');
  } else {
	  writeTxt('You already voted!', 'thanks');
  }
}

function writeRating(httpRequest) {

	displaytxt = 'Your browser doesn\'t support this javascript, please upgrade to see this correctly';
  var response = httpRequest.responseText;
	if(response != 'e') {
		response = response.split(';');
		document.getElementById('current-rating').style.width = response[0] + 'px';  
		displaytxt = '(' + response[2] + ' votes, average: ' + response[1] + ' out of 10)';
  } else {
		displaytxt = 'The ratings are down for maintenance';
		writeTxt('Try again later', 'thanks');
	}
  writeTxt(displaytxt, 'details');
}

function writeTxt(displayText, id) {
  var txtnode = document.getElementById(id);
  txtnode.innerHTML = displayText;
}
/*function writeTxt(apnd, displayText, id) {
  var txtnode = document.getElementById(id);
   if(txtnode.lastChild != null && !apnd) {
     txtnode.removeChild(txtnode.lastChild);
  } else if(txtnode.lastChild != null && apnd) {
      var x = document.createElement('br');
	  txtnode.appendChild(x);
  }
  var x = document.createTextNode(displayText);
  txtnode.appendChild(x);
}*/

function createCookie(name, value, days) {
  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) return(true);//return(c.substring(nameEQ.length, c.length));
  }
  return(false);
}

/* used for the search box */
function clearTxtBox(box) {
  if(box.value == box.defaultValue) {
    box.value = '';
  }
}

function populateTxtBox(box) {
  if( box.value == '') {
  	box.value = 'Enter game name';
  }
}

// -->
