/*
Page:           glass_rating.js
Created:        Sep'25 2008
Last Mod:       Sep'25 2008
Handles actions and requests for Glass 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 getGlassValue55()
{
	var flashHolder = getValue("glassSwf"); 	  
	//alert(flashHolder);
	d= flashHolder.getGlassValue();
	alert(d);
}
function getGlassValue(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;
	globalVar = "glass_"+clubid+"_"+dayid;
	//alert('ajax_includes/ajax_glass_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
   
	xmlhttp.open('get', 'http://www.nightclubfinder.co.uk/ajax_includes/ajax_glass_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
	//xmlhttp.open('get', 'http://192.168.1.113/nicf/v2/ajax_includes/ajax_glass_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
	//xmlhttp.open('get', 'http://www.nightclubfinder.co.uk/ajax_includes/ajax_glass_rating.php?clubid='+clubid+'&dayid='+dayid+'&value='+data);
    xmlhttp.onreadystatechange = glassRatingResponse; 
	
		
    xmlhttp.send(null);
	
	return(document.getElementById(globalVar).value);
}

function glassRatingResponse() {
   if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){       	
	        response = xmlhttp.responseText;
			
			update = response.split('|');
			
			if(update[1]=='vote'){
				alert('Already Voted');
				setGlassValuefn(update[0],0);
				document.getElementById('getGlassValueDelete').style.display='block';	
			}else if(update[1]=='login'){
				document.getElementById('loginMsg').style.display='block';	
				setGlassValuefn(update[0],1);
			}else{
				document.getElementById('getGlassValueDelete').style.display='block';	
				setGlassValuefn(update[0],0);
			}
			
			//document.getElementById(globalVar).value = response;		
			//alert(response);
			//return(response);
		}
    }
}
function getGlassDeleteValue() {
	//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://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-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=GLASS');
	xmlhttp.open('get', 'http://www.nightclubfinder.co.uk/ajax_includes/ajax-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=GLASS');
    xmlhttp.onreadystatechange = glassRatingResponseDelete; 
    xmlhttp.send(null);
}

function glassRatingResponseDelete() {
   if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){       	
	        response = xmlhttp.responseText;
			
			document.getElementById('getGlassValueDelete').style.display='none';
			
			setGlassValuefn(response,1);
		}
    }
}
function setGlassValuefn(data,flag)
{
	//alert("set = "+data);
	/*alert("club"+clubid);
	alert("day"+dayid);*/
	//var flashHolder = document["glassSwf_"+clubid+"_"+dayid];
	/*var flashHolder = document["glassSwf_8_1"];
	//var flashHolder = getValue("glassSwf_8_1"); 
    flashHolder.setGlassValue(100);*/
	
	//var flashHolder = document["glassSwf_8_1"];
    /*flashHolder.data = 55;
	alert(flashHolder.data);*/
	var flashHolder =  getValue("glassSwf_"+clubid+"_"+dayid);
	flashHolder.setGlassValue(data,flag);
}

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) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all[div2show].innerHTML = text;
    }
}


