

/*
Page:           rating.js
Created:        Aug 2006
Last Mod:       Mar 11 2007
Handles actions and requests for rating bars.	
--------------------------------------------------------- 
ryan masuga, masugadesign.com
ryan@masugadesign.com 
Licensed under a Creative Commons Attribution 3.0 License.
http://creativecommons.org/licenses/by/3.0/
See readme.txt for full credit details.


--------------------------------------------------------- */

var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlhttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlhttp=false
	 }
	}
	function myXMLHttpRequest() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}


function changeText2(div2show,loader_div,text,totalcomment_div,totalcomment) {
	
	 if(loader_div != ''){
	 document.getElementById(loader_div).style.display='none';
	 }
	 
	 if(totalcomment_div != ''){
		
	 document.getElementById(totalcomment_div).style.display='none';
	 //alert(document.getElementById(comment_respnce).style.display)
	 document.getElementById("coment_respnce").style.display='block';
	  
	 document.getElementById("coment_respnce").innerHTML = totalcomment;
	 
	 }
	 
	 document.getElementById(div2show).style.display = 'block';
	 document.getElementById(div2show).innerHTML = '';
	
    // 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) {
        var viewer = document.getElementById(div2show);
		viewer.innerHTML = text;
		
    }  else if(IE) {
		document.all[div2show].innerHTML = text;
		
    }
}

function changeText(div2show,loader_div,text ) {
	
	 if(loader_div != ''){
	 document.getElementById(loader_div).style.display='none';
	 }
	 
	 
	 document.getElementById(div2show).style.display = 'block';
	 document.getElementById(div2show).innerHTML = '';
	
    // 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) {
        var viewer = document.getElementById(div2show);
		viewer.innerHTML = text;
		
    }  else if(IE) {
		document.all[div2show].innerHTML = text;
		
    }
}

function handleResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
		
		var update = new Array();
        if(response.indexOf('|') != -1) {
            update = response.split('|');
			
			changeText(update[0], update[1], update[2]);
        }
		}
    }
}

function handleResponse1() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
	
		var update = new Array();
        if(response.indexOf('|') != -1) {
            update = response.split('|');
			changeText(update[1], "", update[0]);
        }
		}
    }
}

function handleResponse2() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
	
		var update = new Array();
        if(response.indexOf('|') != -1) {
            update = response.split('|');
			changeText2(update[0], update[1], update[2],update[3],update[4]);
        }
		}
    }
}



function sndReq(provider_id,rating_value,ip_address,comment) {

	var theUL = document.getElementById("loader_div"); // the UL
	// switch UL with a loading div
	theUL.innerHTML = '<div class="loading"></div>';
	
	//hide comment div
	document.getElementById("rc_div").style.display='none'; // the UL
	
    xmlhttp.open('get', 'rpc.php?provider_id='+provider_id+'&rating_value='+rating_value+'&ip_address='+ip_address+'&comment='+comment);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
}

/* =============================================================== */

function addrc(){
	
	var provider_id = document.getElementById("provider_id").value;
	var ip_address = document.getElementById("ip_address").value;
	var comment = document.getElementById("comment").value;

	var radioLength = document.comment_rating.rating.length;
	
	for(var i = 0; i < radioLength; i++) 
	{	
		if(document.comment_rating.rating[i].checked == true)
		{
			var rating_value = document.comment_rating.rating[i].value;
		}
	}
	
	sndReq(provider_id,rating_value,ip_address,comment); return false;		
	
}


function rating_status(){
	var theUL = document.getElementById("rating_status"); // the UL
	// switch UL with a loading div
	theUL.innerHTML = '';
	theUL.innerHTML = '<div class="loading"></div>';
	
	xmlhttp.open('get', 'rpc_ajex.php');
    xmlhttp.onreadystatechange = handleResponse1;
    xmlhttp.send(null);	
	
	}

function rating_status1(provider_id,b_area,b_county,package_id){
	
	document.getElementById("rating_status1").style.display='none';
	var theUL = document.getElementById("loader_div1"); // the UL
	// switch UL with a loading div
	theUL.innerHTML = '';
	theUL.innerHTML = '<div class="loading"></div>';
	
	xmlhttp.open('get', 'rpc_ajex1.php?provider_id='+provider_id+'&b_area='+b_area+'&b_county='+b_county+'&package_id='+package_id);
    xmlhttp.onreadystatechange = handleResponse2;
    xmlhttp.send(null);	
	
	}
