/*
Page:           drink_price_rating.js
Created:        Sep'25 2008
Last Mod:       Oct'16 2008
Handles actions and requests for Drink Price rating
--------------------------------------------------------- 
Created : Arulkumar.V
--------------------------------------------------------- */

var xmlhttp;
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 for Drink Price Rating
function drinkPrice_Rating(BASE_URL,club_id,day_id,drinkid,drinkname) {
	if(drinkid != "0"){
		clubid = club_id;
		dayid = day_id;
		
		document.getElementById(drinkname).innerHTML = '<div class="loading"></div>';
		//alert("drink_"+drinkname+"_div_"+clubid+'_'+dayid);
		//var theDiv = document.getElementById("drink_"+drinkname+"_div_"+clubid+'_'+dayid);	
		// switch UL with a loading div
		//theDiv.innerHTML = '<div class="loading"></div>';
		//alert('ajax_includes/ajax_drink_price_rating.php?clubid='+clubid+'&dayid='+dayid+'&drinkid='+drinkid+'&drinkname='+drinkname);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax_drink_price_rating.php?clubid='+clubid+'&dayid='+dayid+'&drinkid='+drinkid+'&drinkname='+drinkname);
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		document.getElementById(drinkname).innerHTML ='';
		xmlhttp.onreadystatechange = drinkPriceResponse;
		xmlhttp.send(null);
	}
}

//function handleResponse(clubid,dayid,commentid) {
function drinkPriceResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
        var response = xmlhttp.responseText;
		//alert(response);
		//alert('up'+clubid+dayid+commentid);
		/*if(response.indexOf('|') != -1) {
            update = response.split('|');
            alert(update[0]+' | '+update[1]);
			document.getElementById(update[0]).innerHTML = update[1]+'%';
		}*/
		if(response == "login"){
				document.getElementById('loginMsg').style.display='block';
		}else if(response != "voted"){				
			if(response.indexOf('|') != -1) {
				update = response.split('|');
				//alert(update[0]+' | '+update[1]);
				
				document.getElementById(update[0]).innerHTML = update[1];
				document.getElementById(update[2]).innerHTML = update[3];
				
				document.getElementById(update[4]).selectedIndex =0;
				document.getElementById(update[4]).disabled = true;
				document.getElementById(update[4]+'_Delete').style.display='block';
					
			}
		}else{
			alert('Already voted');
		}
		
		//alert(clubid)
		//alert(document.getElementById('seldrink_main_drinkname_'+clubid+'_'+dayid).selectedIndex);
		//return response;
		/*document.getElementById('seldrink_main_drinkname_'+clubid+'_'+dayid).selectedIndex = 0;
		document.getElementById('seldrink_other_drinkname_'+clubid+'_'+dayid).selectedIndex = 0;*/
		}
    }
}

function drinkPrice_RatingDelete(BASE_URL,club_id,day_id,drinkname) {
	
		clubid = club_id;
		dayid = day_id;
		
		document.getElementById(drinkname).innerHTML = '<div class="loading"></div>';
		//alert("drink_"+drinkname+"_div_"+clubid+'_'+dayid);
		//var theDiv = document.getElementById("drink_"+drinkname+"_div_"+clubid+'_'+dayid);	
		// switch UL with a loading div
		//theDiv.innerHTML = '<div class="loading"></div>';
		//alert('ajax_includes/ajax_drink_price_rating.php?clubid='+clubid+'&dayid='+dayid+'&drinkid='+drinkid+'&drinkname='+drinkname);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=DRINK&drinkname='+drinkname);
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		document.getElementById(drinkname).innerHTML ='';
		xmlhttp.onreadystatechange = drinkPriceDeleteResponse;
		xmlhttp.send(null);
	
}

//function handleResponse(clubid,dayid,commentid) {
function drinkPriceDeleteResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
        var response = xmlhttp.responseText;
		
		//alert('up'+clubid+dayid+commentid);
		/*if(response.indexOf('|') != -1) {
            update = response.split('|');
            alert(update[0]+' | '+update[1]);
			document.getElementById(update[0]).innerHTML = update[1]+'%';
		}*/
		if(response == "login"){
				document.getElementById('loginMsg').style.display='block';
		}else if(response != "voted"){				
			if(response.indexOf('|') != -1) {
				update = response.split('|');
				//alert(update[0]+' | '+update[1]);
				
				document.getElementById(update[0]).innerHTML = update[1];
				document.getElementById(update[2]).innerHTML = update[3];
				document.getElementById(update[4]).disabled = false;
				document.getElementById(update[4]+'_Delete').style.display='none';	
			}
		}else{
			alert('Already voted');
		}
			
		//alert(clubid)
		//alert(document.getElementById('seldrink_main_drinkname_'+clubid+'_'+dayid).selectedIndex);
		//return response;
		/*document.getElementById('seldrink_main_drinkname_'+clubid+'_'+dayid).selectedIndex = 0;
		document.getElementById('seldrink_other_drinkname_'+clubid+'_'+dayid).selectedIndex = 0;*/
		}
    }
}

