  var xmlHttpRating; 
  var div = document.getElementById('fxajaxvote1');

	function innerhtml(id, cont) {
		if (getID(id)) getID(id).innerHTML = cont;
	}
	
	/* private getID() method */
	function getID(obj){
		return document.getElementById(obj)
	}	
  
  function fxAjaxVote(rating, id){ 
    xmlHttpRating=GetXmlHttpObjectRating();
    if (xmlHttpRating==null) {
      alert ("Your browser does not support AJAX.");
      return;
    } 
    innerhtml('fxajaxvote1','<img src="/common/imgs/fxLoading.gif" border="0" align="absmiddle" />');
    
    xmlHttpRating.onreadystatechange = stateChangedRating;
    xmlHttpRating.open("GET", "/common/php/fxAjaxRatings.php?task=vote&user_rating="+rating+"&cid="+id+"&userid="+'0', true);
    xmlHttpRating.send(null);
  }
  
  function stateChangedRating() { 
    if (xmlHttpRating.readyState==4){ 
      
			setTimeout(function(){
    		var response = xmlHttpRating.responseText.split('|');      		
				var ratings;
				var i;
        //document.getElementById('fxajaxvote1').innerHTML='('+(response[1])+')';
		    innerhtml('fxajaxvote1','(' + response[1] + ')');
		    ratings = response[2];
		    for (i=1; i<=5; i++) {		       
           if (ratings >= 1) {
              document.getElementById('omy_rating_' +  i).className = 'rated';
              document.getElementById('omy_rating_' +  i).style.background = "url('http://www.omy.sg/global/common/imgs/rate.png')";              
           } else if (ratings < 1 && ratings > 0) {
              document.getElementById('omy_rating_' +  i).className = 'rate_half';
              document.getElementById('omy_rating_' +  i).style.background = "url('http://www.omy.sg/global/common/imgs/rate_half.png')";   
           } else {
              document.getElementById('omy_rating_' +  i).className = 'ratethis';
              document.getElementById('omy_rating_' +  i).style.background  = "url('http://www.omy.sg/global/common/imgs/rate_grey.png')";
           }       
           ratings--;
        }
			},1500);
    }
  }
  
  function GetXmlHttpObjectRating(){
    var xmlHttpRating=null;
    try {
      // Firefox, Opera 8.0+, Safari
      xmlHttpRating=new XMLHttpRequest();
    }
    catch (e){
      // Internet Explorer
      try {
        xmlHttpRating=new ActiveXObject("Msxml2.xmlHttpRating");
      }
      catch (e){
        xmlHttpRating=new ActiveXObject("Microsoft.xmlHttpRating");
        }
      }
    return xmlHttpRating;
  }


