	/*
	Plugin Name: Comment Karma
	Plugin URI: http://cyber-knowledge.net/blog/2006/10/15/wordpress-plugin-rate-your-comments-comment-karma/
	Description: Allows you to rate comments up or down.
	Author: Alex Bailey and Kirk
	Author URI: http://cyber-knowledge.net
	Version: 1.1
	*/ 

	/*
	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 createXMLHttpRequest(){
    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.";
        alert("Your browser does not support the XMLHttpRequest Object!");
    }
    return xmlhttp;
}

var xhr = createXMLHttpRequest();

function favorite_review(id, action, path, t_prefix, marker, page){
    xhr.open('post', 'http\://'+ path +'favorite_review_process.php?id='+ id +'&action='+ action +'&path='+ path +'&prefix='+ t_prefix+'&marker='+marker+'&page='+page);
    xhr.onreadystatechange = handleResponse_selfpromo;
    xhr.send('var=1');
}

function handleResponse_selfpromo(){
    if(xhr.readyState == 4){
        var response = xhr.responseText.split('|');
        if(response[0].replace(/^\s+|\s+$/g, '') == 'done'){
            if(response[1].replace(/^\s+|\s+$/g, '')){
                //Toggle the link text and the action
                if (response[2].replace(/^\s+|\s+$/g, '') == 'mark') {
                  document.getElementById("favorite_review-"+response[1].replace(/^\s+|\s+$/g, '')).innerHTML = "<img src='"+ response[7].replace(/^\s+|\s+$/g, '') +"/wp-content/themes/2.0/images/delete.gif'>&nbsp;<strong>Remove review from My Favorites</strong>";
                  document.getElementById("favorite_review-"+response[1].replace(/^\s+|\s+$/g, '')).href = "javascript:favorite_review('"+response[1].replace(/^\s+|\s+$/g, '')+"', 'unmark', '"+response[3].replace(/^\s+|\s+$/g, '')+"', '"+response[4].replace(/^\s+|\s+$/g, '')+"', '"+response[5].replace(/^\s+|\s+$/g, '') + "', '"+ response[6].replace(/^\s+|\s+$/g, '') +"');";
                  //var myFx = new Fx.Style("comment-"+response[1].replace(/^\s+|\s+$/g, ''), 'opacity', {duration:0}).start(1,0.5);
                } else if (response[2].replace(/^\s+|\s+$/g, '') == 'unmark') {
                  document.getElementById("favorite_review-"+response[1].replace(/^\s+|\s+$/g, '')).innerHTML = "<img src='"+ response[7].replace(/^\s+|\s+$/g, '') +"/wp-content/themes/2.0/images/add.gif'>&nbsp;<strong>Add review to My Favorites</strong>";
                  document.getElementById("favorite_review-"+response[1].replace(/^\s+|\s+$/g, '')).href = "javascript:favorite_review('"+response[1].replace(/^\s+|\s+$/g, '')+"', 'mark', '"+response[3].replace(/^\s+|\s+$/g, '')+"', '"+response[4].replace(/^\s+|\s+$/g, '')+"', '"+response[5].replace(/^\s+|\s+$/g, '') + "', '"+ response[6].replace(/^\s+|\s+$/g, '')  +"');";
                }
            } else {
                alert("?");
            }
        }
        else if(response[0].replace(/^\s+|\s+$/g, '') == 'error')
        {
            var error = 'Error: '+response[1].replace(/^\s+|\s+$/g, '');
            //alert(error);
        } else {
        	alert("Response: "+response[0].replace(/^\s+|\s+$/g, ''));
          //alert("Karma not changed, please try again later.");
        }
    }
}
