	/*
   Plugin Name: Comment Rating
	Plugin URI: http://wealthynetizen.com/wordpress-plugin-comment-rating/
	Description: Allows visitors to rate the comments on your blog in a Like vs. Dislike fashion.  Clickable images and ratings are automatically inserted into each comment.  Comments disliked too much by readers will be hidden in a click-to-show link. 
	Author: Bob King
	Author URI: http://wealthynetizen.com
	Version: 2.3.2
	*/ 

	/*
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
	*/

function ghcLikeCreateXMLHttpRequest(){
    var xmlhttp = null;
    try {
        // Moz supports XMLHttpRequest. IE uses ActiveX.
        // browser detction is bad. object detection works for any browser
        xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
        // browser doesn’t support ajax. handle however you want
        //document.getElementById("errormsg").innerHTML = "Your browser doesnt support XMLHttpRequest.";
        // This won't help ordinary users.  Turned off
        // alert("Your browser does not support the XMLHttpRequest Object!");
    }
    return xmlhttp;
}

var ghcLikeXhr = ghcLikeCreateXMLHttpRequest();

function ghcLike(id, action, path) {
    ghcLikeXhr.open('get', 'http\://'+ path +'ghc-process-like.php?id='+ id +'&action='+ action +'&path='+ path);
    ghcLikeXhr.onreadystatechange = ghcLikeResponse;
    ghcLikeXhr.send(null);
}

function ghcLikeResponse()
{
	if (ghcLikeXhr.readyState == 4) {
		var response = ghcLikeXhr.responseText.split('|');
		
		if (response[0] == 'done') {
			document.getElementById("star-count-"+response[1]).innerHTML = response[3];
			var theElement = document.getElementById("star-banner-"+response[1]);			
			var theClass = theElement.getAttribute("class");
			if (response[2] == "on") {
				theClass = theClass.replace(' deselected', ' selected');
			}
			else if (response[2] == "off") {
				theClass = theClass.replace(' selected', ' deselected');
			}
			theElement.setAttribute("class", theClass);
		}
	}
}
