// JavaScript Document
function GetCookie(cookieName) {
    if(document.cookie) {
      var index = document.cookie.indexOf(cookieName);
	 
      if (index != -1) {
        var countbegin = (document.cookie.indexOf(cookieName+"=", index) + 1);
        var countend = document.cookie.indexOf(";", index);
        if (countend == -1) {
          countend = document.cookie.length;
        }
        return document.cookie.substring(countbegin + cookieName.length, countend);
      }
    }
    return null;
  }
	
	function init_rating(gameid){
	
	  game_id = gameid;
	  document.cookie = "Game=1";
	  cookies_enabled = GetCookie("Game")
	  rating_msg_div = document.getElementById("rating_msg")
  
	  if (document.images){
		  img_obj1 = new Image();
		  img_obj2 = new Image();
		  img_red = "/images/rating_star_red.gif";
		  img_white = "/images/rating_star_white.gif";
		  img_obj1.src = img_red;
		  img_obj2.src = img_white;
		}
		star1 = document.getElementById("str1")
		star2 = document.getElementById("str2")
		star3 = document.getElementById("str3")
		star4 = document.getElementById("str4")
		star5 = document.getElementById("str5")
	  }
	  
	function setColor(star, myRating){
    switch (myRating){
      case "1":
        star1.src=img_red;
        star2.src=img_white;
        star3.src=img_white;
        star4.src=img_white;
        star5.src=img_white;
        break;
      case "2":
        star1.src=img_red;
        star2.src=img_red;
        star3.src=img_white;
        star4.src=img_white;
        star5.src=img_white;
        break;
      case "3":
        star1.src=img_red;
        star2.src=img_red;
        star3.src=img_red;
        star4.src=img_white;
        star5.src=img_white;
        break;
      case "4":
        star1.src=img_red;
        star2.src=img_red;
        star3.src=img_red;
        star4.src=img_red;
        star5.src=img_white;
        break;
      case "5":
        star1.src=img_red;
        star2.src=img_red;
        star3.src=img_red;
        star4.src=img_red;
        star5.src=img_red;
        break;
      default :
        star1.src=img_white;
        star2.src=img_white;
        star3.src=img_white;
        star4.src=img_white;
        star5.src=img_white;
    }
  }

  function resetColor(star, myRating){
        star1.src=img_white;
        star2.src=img_white;
        star3.src=img_white;
        star4.src=img_white;
        star5.src=img_white;
  }
  
 function sendRating(star, myRating){

  if (cookies_enabled == 0){
    alert("To be able to rate this article, please enable your browser to accept HTTP cookies.");
    exit;
  }

   rating_msg_div.innerHTML="Please wait...";
   

     if (window.ActiveXObject) {
        HttpSendRating = new ActiveXObject("Microsoft.XMLHTTP");
     }
     else {
        HttpSendRating = new XMLHttpRequest;
     }

    SendMyRatingUrl = encodeURI("/rating.asp?game_id="+game_id+"&rating="+myRating);

    HttpSendRating.open("get", SendMyRatingUrl, true);
    HttpSendRating.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    HttpSendRating.onreadystatechange = HandleHttpSendMyRating;
    HttpSendRating.send(null);
  }

  function HandleHttpSendMyRating() {
  
    if (HttpSendRating.readyState == 4) {
		if (HttpSendRating.status == 200) {
		  document.cookie=game_id+"=1";
	
		  latest_rating=HttpSendRating.responseText
	
		  rating_msg_div.innerHTML="";
		 
		  if(latest_rating!=null){
			rating_msg_div.innerHTML=latest_rating;
			
		  }
		}
		else {
			rating_msg_div.innerHTML = "Data not available currently"
		}
    }
      
  }

  function getexpirydate(nodays){
    var UTCstring;
    Today = new Date();
    nomilli=Date.parse(Today);
    Today.setTime(nomilli+nodays*24*60*60*1000);
    UTCstring = Today.toUTCString();
    return UTCstring;
  } 