var url = "/includes/ajax.php";
var xmlhttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
        xmlhttp = false;
    }
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
  try {
    xmlhttp = new XMLHttpRequest();
  } catch (e) {
    xmlhttp=false;
  }
}
if (!xmlhttp && window.createRequest)
{
  try {
    xmlhttp = window.createRequest();
  } catch (e) {
	  xmlhttp=false;
  }
}

var star_off = new Image();
var star_on = new Image();
var star_on_voting = new Image();
star_off.src = "/images/icons/rating_star_off.gif";
star_on.src = "/images/icons/rating_star_on.gif";
star_on_voting.src = "/images/icons/rating_star_on_voting.gif";

function light_off(img, idx, start) 
{
  var stars = img.parentNode.childNodes;
  for(x=0; x<=idx; x++)
  {
    if(x < start) // if the star was lit, keep it lit
    {
      stars[x].src = star_on.src;
    }
    else // if the star was not lit, turn it off
    {
      stars[x].src = star_off.src;
    }
  }
}

function light_on(img, idx) 
{
  var stars = img.parentNode.childNodes;
  for(x=0; x<=idx; x++)
  {
    stars[x].src = star_on_voting.src;
  }
}

function rate_article(img, articleid, score)
{
  var params = 'function=rate_article&id='+articleid+'&score='+score;
  xmlhttp.open("POST", url, true);
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", params.length);
  xmlhttp.setRequestHeader("Connection", "close");
  xmlhttp.send(params);

  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      var new_rating = xmlhttp.responseText;
      if(new_rating != '')
      {
        img.parentNode.innerHTML = xmlhttp.responseText;
      }
    }
  }
}

function submit_comment()
{
    var url = "/journal/addcomment.php";
    var postedby = document.getElementById('postedby').value;
    var commentsbox = document.getElementById('commentsbox').value;
    var imgverify = document.getElementById('imgverify').value;
    var articleid = document.getElementById('articleid').value;
    var action = document.getElementById('action').value;
    var params = 'id='+articleid+'&postedby='+postedby+'&commentsbox='+commentsbox+'&imgverify='+imgverify+'&action='+action;

    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(params);

    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            //document.getElementById('comments_block').innerHTML = xmlhttp.responseText;
		        alert(xmlhttp.responseText);
        }
    }
}