<!--

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

function getRating(snowflakeID) {	
  rateReq.url = '/AddStory.php';
  rateReq.successCallback = writeRating;
  rateReq.post("sID=" + encodeURI(snowflakeID) + "&agree=" + encodeURI(agree) + "&disagree=" + encodeURI(disagree));
}

function sendRate(agree, disagree, snowflakeID) {
  if(!readCookie(snowflakeID + 'freeclassicgames')) 
	{
    rateReq.url = '/Voting.php';
    rateReq.successCallback = writeRating;
    rateReq.post("sID=" + encodeURI(snowflakeID) + "&agree=" + encodeURI(agree) + "&disagree=" + encodeURI(disagree));
    createCookie(snowflakeID + 'snowflake', 'voted', 14);
  } else {
	  alert("You've already voted for this Snowflake");
  }
}

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(';');
		if(response[0] == 1)
		{
		  writeTxt((Number(response[1]) + 1), 'agree_' + response[2]);
		}
		else
		{
		  writeTxt((Number(response[1]) + 1), 'disagree_' + response[2]);
		}
  } else {
		displaytxt = 'There was an issue recording your vote.  An administrator will look into it.';
		alert(displaytxt);
	}
}

function sendStory() {
	storyReq.url = '/AddStory.php';
  storyReq.successCallback = writeStory;
  storyReq.post("nickName=" + encodeURI(document.getElementById("nickName").value) + "&story=" + encodeURI(document.getElementById("story").value) + "&emailAddress=" + document.getElementById("emailAddress").value);
}

function writeStory(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(';');
		alert('Thank you, your story will be reviewed shortly.');
		$('#newSnowflake').hide('fast');
		document.all.nickName.value = "";
		document.all.story.value = "Dear Snowflake,";
		document.all.emailAddress.value = "";
  } else {
		displaytxt = 'There was an issue adding your story.  An administrator will look into it.';
		alert(displaytxt);
	}
}



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';
  }
}

// -->

