/*
Page:           dominant_rating.js
Created:        Sep'25 2008
Last Mod:       Sep'25 2008
Handles actions and requests for Guys/Girls rating
--------------------------------------------------------- 
Created : Thamizharasan.M
--------------------------------------------------------- */

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 dominant_Rating(BASE_URL,club_id,day_id,dominant) {
	if(dominant != "0"){
		clubid = club_id;
		dayid = day_id;

		//alert('ajax_includes/ajax_dominant_rating.php?clubid='+clubid+'&dayid='+dayid+'&dominantid='+dominant);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax_dominant_rating.php?clubid='+clubid+'&dayid='+dayid+'&dominantid='+dominant);
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		xmlhttp.onreadystatechange = dominantResponse;
		xmlhttp.send(null);
	}
}

//function handleResponse(clubid,dayid,commentid) {
function dominantResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
			var response = xmlhttp.responseText;
			//alert(response); 
			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('dominant').innerHTML = response;
				document.getElementById('sel_dominant').disabled = true;
				document.getElementById('sel_dominant').selectedIndex =0;
				document.getElementById('sel_dominant_Delete').style.display='block';
			}else{
				alert('Already voted');
			}	
			/*document.getElementById('sel_dominant_'+clubid+'_'+dayid).selectedIndex = 0;
			document.getElementById('sel_dominant_'+clubid+'_'+dayid).selectedIndex = 0;*/
		}
    }
}
function dominant_RatingDelete(BASE_URL,club_id,day_id) {
	
		clubid = club_id;
		dayid = day_id;

		//alert('ajax_includes/ajax_dominant_rating.php?clubid='+clubid+'&dayid='+dayid+'&dominantid='+dominant);
		xmlhttp.open('get', BASE_URL+'ajax_includes/ajax-votes-delete.php?clubid='+clubid+'&dayid='+dayid+'&deletetype=DOMINANT');
		//xmlhttp.onreadystatechange = handleResponse(clubid,dayid,commentid) ;
		xmlhttp.onreadystatechange = dominantResponseDelete;
		xmlhttp.send(null);
	
}

//function handleResponse(clubid,dayid,commentid) {
function dominantResponseDelete() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
			var response = xmlhttp.responseText;
			//alert(response); 
			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('dominant').innerHTML = response;
				document.getElementById('sel_dominant').disabled = true;
			}	
			document.getElementById('sel_dominant').disabled = false;
			document.getElementById('sel_dominant_Delete').style.display='none';
			/*document.getElementById('sel_dominant_'+clubid+'_'+dayid).selectedIndex = 0;
			document.getElementById('sel_dominant_'+clubid+'_'+dayid).selectedIndex = 0;*/
		}
    }
}

