/*
Page:           music_rating.js
Created:        Sep'25 2008
Last Mod:       Oct'16 2008
Handles actions and requests for Music 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 musicMainRoomRating(BASE_URL,club_id,day_id,musicid,room) {
	
	if(musicid != "0"){
		clubid = club_id;
		dayid = day_id;
		
		//alert("music_"+room+"_div_"+clubid+'_'+dayid);
		//var theDiv = document.getElementById("music_"+room+"_div_"+clubid+'_'+dayid);	
		// switch UL with a loading div
		//theDiv.innerHTML = '<div class="loading"></div>';
		//alert('ajax_includes/ajax_music_rating.php?clubid='+clubid+'&dayid='+dayid+'&musicid='+musicid+'&room='+room);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax_music_rating.php?clubid='+clubid+'&dayid='+dayid+'&musicid='+musicid+'&room='+room);
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		xmlhttp.onreadystatechange = mainRoomResponse;
		xmlhttp.send(null);
	}
}
function musicMainRoomRatingFull(BASE_URL,club_id,day_id,musicid,room) {
	if(musicid != "0"){
		clubid = club_id;
		dayid = day_id;
		//alert(musicid);
		//alert("music_"+room+"_div_"+clubid+'_'+dayid);
		//var theDiv = document.getElementById("music_"+room+"_div_"+clubid+'_'+dayid);	
		// switch UL with a loading div
		//theDiv.innerHTML = '<div class="loading"></div>';
		//alert('ajax_includes/ajax_music_rating.php?clubid='+clubid+'&dayid='+dayid+'&musicid='+musicid+'&room='+room);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax_music_rating.php?clubid='+clubid+'&dayid='+dayid+'&musicid='+musicid+'&room='+room);
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		xmlhttp.onreadystatechange = mainRoomResponseFull;
		xmlhttp.send(null);
	}
}
function musicOtherRoomRatingFull(BASE_URL,club_id,day_id,musicid,room) {
	if(musicid != "0"){
		clubid = club_id;
		dayid = day_id;
		//alert(musicid);
		//alert("music_"+room+"_div_"+clubid+'_'+dayid);
		//var theDiv = document.getElementById("music_"+room+"_div_"+clubid+'_'+dayid);	
		// switch UL with a loading div
		//theDiv.innerHTML = '<div class="loading"></div>';
		//alert('ajax_includes/ajax_music_rating.php?clubid='+clubid+'&dayid='+dayid+'&musicid='+musicid+'&room='+room);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax_music_rating.php?clubid='+clubid+'&dayid='+dayid+'&musicid='+musicid+'&room='+room);
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		xmlhttp.onreadystatechange = otherRoomResponseFull;
		xmlhttp.send(null);
	}
}


//function handleResponse(clubid,dayid,commentid) {
function mainRoomResponse() {
  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) {
				musics = response.split('$');
				//alert(musics);        
				for(i=1; i<	musics.length; ++i){				
					if(response.indexOf('|') != -1) {
						update = musics[i].split('|');
						//alert(update[0]+' | '+update[1]);        
						document.getElementById(update[0]).innerHTML = update[1]+'%';
					}
				}
			}
		}else{
			alert('Already voted');	
		}
		//alert(clubid)
		//alert(document.getElementById('selmusic_main_room_'+clubid+'_'+dayid).selectedIndex);
		//return response;
		document.getElementById('selmusic_main_room_'+clubid+'_'+dayid).selectedIndex = 0;
		document.getElementById('selmusic_other_room_'+clubid+'_'+dayid).selectedIndex = 0;
		}
    }
}
function mainRoomResponseFull() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
        var response = xmlhttp.responseText;
			values = response.split('@');
			/*alert(values[0]);
			alert(values[1]);*/
			if(values[0] == "login"){
				document.getElementById('loginMsg').style.display='block';
	   		 }else if(values[0] != "voted"){
				 	
					document.getElementById('MainName').innerHTML = values[0];
					document.getElementById('MainRatings').innerHTML = values[1];
					document.getElementById('selmusic_main_room_Delete').style.display='block';
			}else{
				    alert('Already voted');	
			}
		}
    }
}
function otherRoomResponseFull() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
        var response = xmlhttp.responseText;
		
			values = response.split('@');
			/*alert(values[0]);
			alert(values[1]);*/
			if(values[0] == "login"){
				document.getElementById('loginMsg').style.display='block';
	    	}else if(values[0] != "voted"){
					document.getElementById('OtherName').innerHTML = values[0];
					document.getElementById('OtherRatings').innerHTML = values[1];
					document.getElementById('selmusic_other_room_Delete').style.display='block';
			}else{
				    alert('Already voted');	
			}
		}
    }
}

function musicMainRoomRatingDelete(BASE_URL,club_id,day_id) {
	
	
		clubid = club_id;
		dayid = day_id;
		
		//alert("music_"+room+"_div_"+clubid+'_'+dayid);
		//var theDiv = document.getElementById("music_"+room+"_div_"+clubid+'_'+dayid);	
		// switch UL with a loading div
		//theDiv.innerHTML = '<div class="loading"></div>';
		//alert('ajax_includes/ajax_music_rating.php?clubid='+clubid+'&dayid='+dayid+'&musicid='+musicid+'&room='+room);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=MUSIC&room=MR');
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		xmlhttp.onreadystatechange = mainRoomDeleteResponse;
		xmlhttp.send(null);
	
}
function mainRoomDeleteResponse() {
 if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
        var response = xmlhttp.responseText;
			values = response.split('@');
			/*alert(values[0]);
			alert(values[1]);*/
			if(values[0] == "login"){
				document.getElementById('loginMsg').style.display='block';
	   		 }else if(values[0] != "voted"){
					document.getElementById('MainName').innerHTML = values[0];
					document.getElementById('MainRatings').innerHTML = values[1];
			}else{
				    alert('Already voted');	
			}
		}
    }
}


function musicOthernRoomRatingDelete(BASE_URL,club_id,day_id) {
	
	
		clubid = club_id;
		dayid = day_id;
		
		//alert("music_"+room+"_div_"+clubid+'_'+dayid);
		//var theDiv = document.getElementById("music_"+room+"_div_"+clubid+'_'+dayid);	
		// switch UL with a loading div
		//theDiv.innerHTML = '<div class="loading"></div>';
		//alert('ajax_includes/ajax_music_rating.php?clubid='+clubid+'&dayid='+dayid+'&musicid='+musicid+'&room='+room);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=MUSIC&room=OR');
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		xmlhttp.onreadystatechange = otherRoomDeleteResponse;
		xmlhttp.send(null);
	
}
function otherRoomDeleteResponse() {
 if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
        var response = xmlhttp.responseText;
			values = response.split('@');
			/*alert(values[0]);
			alert(values[1]);*/
			if(values[0] == "login"){
				document.getElementById('loginMsg').style.display='block';
	   		 }else if(values[0] != "voted"){
					document.getElementById('OtherName').innerHTML = values[0];
					document.getElementById('OtherRatings').innerHTML = values[1];
			}else{
				    alert('Already voted');	
			}
		}
    }
}
