/**
 * Variable to store XMLHTTP object.
 */
var objXmlHttp = null;


/**
 * Function to check whether the XMLHTTP object is created or not.
 * 
 * @return	boolean	true if object is created.
 * 					false if object is not created.
 */
function isCreated() {
	
	if ( !objXmlHttp ) {
		if ( (objXmlHttp == false) || (objXmlHttp == null)) {
			return false;
		}
	}
	return true;
}

/**
 * Function to create the XMLHTTP object to handle the AJAX functionality.
 *
 * @return 	XMLHTTP 	object on success.
 * 			boolean 	false on failure.
 */
function createObject() { 

	if ( isCreated() ) {
		objXmlHttp = null;
	}

	if ( !isCreated() ) {
		try {
			// For Opera 8.0+, Mozilla, Firefox, Safari
			objXmlHttp = new XMLHttpRequest();
		}
		catch(e) {
			// For Internet Explorers
			try {
				// Internet Explorer 5.5+
				objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try {
					// Internet Explorer upto 5.5
					objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) {
					// property is not supported.
					objXmlHttp = false;
				}
			}
		}
	}
}

var  element1;
var id;
function sndReq(vote,id_num,ip_num,pageUrl) {
	id = id_num;
	createObject();
    
    
	var ratingscripturl=pageUrl+"/rate_this.php";
   // var ratingscripturl="http://192.168.1.202/jyoti/askoptions.com/rate_this.php";
    
	element1 = document.getElementById('products'+id);
    element1.innerHTML = '<div style="height: 20px;"><em>Loading ...</em></div>';
	var parameters="vote="+vote+"&id="+id_num+"&ip="+ip_num;
	objXmlHttp.open('GET', ratingscripturl+"?"+parameters);
    objXmlHttp.onreadystatechange = handleResponse;
	
	objXmlHttp.send(null);

}

function handleResponse() {

   if(objXmlHttp.readyState == 4){

		if (objXmlHttp.status == 200){
       	
        var response = objXmlHttp.responseText;
			
			if( response.indexOf("|") != -1 ) {
			rateText	= response.split("|");
			
			changeText( rateText[0], rateText[1] );
			
			}
		}
    }
	else{
		//alert("here1"+objXmlHttp.readyState);
	}
}

function changeText( div2show, text ) {
	
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
	if (parseInt(navigator.appVersion) >=5) {DOM=1};
	// Grab the content from the requested "div" and show it in the "container"

    if (DOM) {
	    element1 = document.getElementById('products'+id);
		element1.innerHTML = text;
    }
    else if(IE) {
        document.all['products'+id].innerHTML=text;

    }
}

