/*
Page:           meter_rating.js
Created:        Sep'25 2008
Last Mod:       Sep'25 2008
Handles actions and requests for Meter rating
--------------------------------------------------------- 
Created : Arulkumar.V
--------------------------------------------------------- */

var xmlhttp
var globalVar;
var clubid;
var dayid;


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 getValue(movieName){
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName])
		  return document.embeds[movieName]; 
	}
	else {// if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		return document.getElementById(movieName);
		//return document.embeds[movieName]; 
	}
}

function getMeterValue(data) {
	
	//var theDiv = document.getElementById('glassrating'); // the UL
	
	// switch UL with a loading div
	//theDiv.innerHTML = '<div class="loading"></div>';
	clubid = document.getElementById('hid_club_id').value; 
	dayid = document.getElementById('hid_day_id').value;
	//alert('ajax_includes/ajax_meter_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
   
	//xmlhttp.open('get', 'http://192.168.1.113/nicf/v2/ajax_includes/ajax_meter_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
	xmlhttp.open('get', 'http://www.nightclubfinder.co.uk/ajax_includes/ajax_meter_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
	//xmlhttp.open('get', 'http://192.168.1.113/nicf/v2/ajax_includes/ajax_meter_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
    xmlhttp.onreadystatechange = meterRatingResponse; 
    xmlhttp.send(null);
}

function meterRatingResponse() {
   if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){       	
	        response = xmlhttp.responseText;
			
			update = response.split('|');
			if(update[1]=='vote'){
				alert('Already Voted');
				setMeterValuefn(update[0],0);
				document.getElementById('getMeterValueDelete').style.display='block';
			}else if(update[1]=='login'){
				document.getElementById('loginMsg').style.display='block';	
				setMeterValuefn(update[0],1);
			}else{
				document.getElementById('getMeterValueDelete').style.display='block';
				setMeterValuefn(update[0],0);
			}
			
		}
    }
}
function getMeterDeleteValue() {
	//var theDiv = document.getElementById('glassrating'); // the UL
	
	// switch UL with a loading div
	//theDiv.innerHTML = '<div class="loading"></div>';
	clubid = document.getElementById('hid_club_id').value; 
	dayid = document.getElementById('hid_day_id').value;
	//alert('ajax_includes/ajax_meter_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
   
	//xmlhttp.open('get', 'http://192.168.1.113/nicf/v2/ajax_includes/ajax-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=METER');
xmlhttp.open('get', 'http://www.nightclubfinder.co.uk/ajax_includes/ajax-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=METER');
	//xmlhttp.open('get', 'http://192.168.1.113/nicf/v2/ajax_includes/ajax-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=METER');
    xmlhttp.onreadystatechange = meterRatingResponseDelete; 
    xmlhttp.send(null);
}

function meterRatingResponseDelete() {
   if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){       	
	        response = xmlhttp.responseText;
			
			document.getElementById('getMeterValueDelete').style.display='none';
			setMeterValuefn(response,1);
		}
    }
}
function setMeterValuefn(data,flag)
{
	var flashHolder = getValue("meterSwf_"+clubid+"_"+dayid);
	flashHolder.setMeterValue(data,flag);
}

