/*
 * lib_rate.js	:	Rating an item (i.e. photo, link, etc.)
 *
*/

function rate_reset(type, type2, type3, refid)
{
	var container = getElement('omchat_rate_container'+type+'_'+refid);
	container.innerHTML = '<img src="/CMS/images/icon_loading.gif" alt="" />';

	xmlhttp_request('/CMS/php/xml_rate_reset.php', 'type='+type+'&type2='+type2+'&type3='+type3+'&refid='+refid, 'POST', rate_processxml, xmlhttp_error, true, true);
}

function rate(em, type, type2, type3, refid)
{
	if( em.selectedIndex == 0 ) return;

	var container = getElement('omchat_rate_container'+type+'_'+refid);
	container.innerHTML = '<img src="/CMS/images/icon_loading.gif" alt="" />';

	xmlhttp_request('/CMS/php/xml_user_rate.php', 'type='+type+'&type2='+type2+'&type3='+type3+'&refid='+refid+'&rating='+(em.selectedIndex-1), 'POST', rate_processxml, xmlhttp_error, true, true);
}

function rate_processxml(xml)
{
	/*
	 * XML output format
	 *
	 *	<?xml version="1.0" ?>
	 *	<items>
     *		<item>
     *			<html></html>
     *			<type></type>
     *			<refid></refid>
	 *		</item>
	 *	</items>
	*/

	// get the items in the xml document
	var items = xml.documentElement.getElementsByTagName('item');
	
	var html = getNodeValue(items.item(0), 'html');
	var type = getNodeValue(items.item(0), 'type');
	var refid = getNodeValue(items.item(0), 'refid');

	var container = getElement('omchat_rate_container'+type+'_'+refid);
	container.innerHTML = html;
}