/***************************************************************************
 *                            articles_util.js
 *                       ---------------------
 *   begin              :  Feb 10, 2009
 *   copyright          : (C) 2005 LifeForm Inc.
 *   email              : info@lifeforminc.com
 *
 *
 ***************************************************************************/
/***************************************************************************
 *
 *   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.
 *
 ***************************************************************************/

var xmlHttp

// this function is called from php script
function rateArticle(str)
{ 
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	document.getElementById("ajax_images").innerHTML='';
	document.getElementById("rate_article").innerHTML='';
	
	var url=str

	// the function is stored in the property to be called automatically
	xmlHttp.onreadystatechange=stateChanged 
	// To send off a request to the server, we use the open() method and the send() method
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged() 
{ 
	// 4 means 'The request is complete'. This means that we can get our data
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		// new picture will be sent back
		document.getElementById("ajax_rate_image").innerHTML=xmlHttp.responseText 
		// increase number of voters
		if( xmlHttp.responseText != '' ) document.getElementById("ajax_voters").innerHTML++;
	} 
}

// gets XMLHttpRequest Object
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}