/*
	Script: Star Rating Functions (Philippine Travel Stories)
	Author: Jake M. Lazado
	Date: 13 January 2009
	Version: 1.0.1j
	Functions:
		{OBJECT} function AJAX(); << AJAX Object
		AJAX.sendRating(post_id,rating); << Sends and requests data from "rating.responder.php"
		setStars(div_id,rating); << Sets or resets the stars.
*/
var JX = new AJAX();
var PATH  = "http://philippinetravelstories.philippinehotelreservations.com/wp-content/themes/travelstories/Rating Engine/.CLASS/";

function AJAX() {
	this.AJAX = new function() {
											var jx;
											try {
												jx = new XMLHttpRequest();
											} catch(Ex) {
												try {
													jx = new ActiveXObject("Msxml2.XMLHTTP");
												} catch(Ex) {
													try { 
														jx = new ActiveXObject("Microsoft.XMLHTTP"); 
													} 
													catch(Ex) { 
														jx = null;
														alert(Ex);
													}
												}
											}
											return jx;
										}
	this.sendRating = sendRating;
}//End of OBJECT::AJAX


function sendRating(post_id, rating) {
	var IP    = document.getElementById(post_id).getElementsByTagName("input")[1].value; 
	var query = PATH + "Updater.php?IP="+ IP +"&post="+ post_id +"&rating="+ rating +"&k="+ Math.random();
	try {
		JX.AJAX.onreadystatechange = function() {
			if(JX.AJAX.readyState == 4) {
				document.getElementById(post_id).innerHTML = JX.AJAX.responseText;
			} else {
				document.getElementById(post_id).innerHTML = "Please Wait. Saving...";
			}
		}
		JX.AJAX.open("GET",query);
		JX.AJAX.send(null);
	} catch(Ex) {
		alert("Send Rating Error: " + Ex);
	}
}

function setStars(div_id,rating) {
	try {
		for(i = 0; i < 5; i++) { 
			if(i < rating) {
				document.getElementById(div_id).getElementsByTagName("img")[i].src = "http://philippinetravelstories.philippinehotelreservations.com/wp-content/themes/travelstories/Rating Engine/star_orange.png";
			} else {
				document.getElementById(div_id).getElementsByTagName("img")[i].src = "http://philippinetravelstories.philippinehotelreservations.com/wp-content/themes/travelstories/Rating Engine/star_gray.png";
			}
		}
	} catch(Ex) {
		/*
			This alert is for debugging use only. 
			Please remove during deployment. Thanks. -- Dyeykh
		*/
		//alert("function::setStars Error: " + Ex);
	}
}









