$(document).ready(function() {
// So Clean
});

function get_sub(vale)
{
if(vale != -1)
{
	$.ajax({
	   type: "GET",
	   url: "load_sub_cat.php",
	   data: "val="+vale,
		success: function(data){
		  $("#subcat").html(data);
	   }
	 });
}
}
////////////////////////////////////////////

function load_main_data(val)
{
if(val != -1)
{
$("#main_body_loader").html('<center><img src="images/ajax-loader.gif" /></center>')	
	$.ajax({
	   type: "GET",
	   url: "load_main_data.php",
	   data: "val="+val,
		success: function(data){
		  $("#main_body_loader").html(data);
	   }
	 });
}
}
///////////////////////////////////////////
function team_one(ids)
{
	var first = $("#team_one_"+ids).html();
	var second = $("#team_draw_"+ids).html();	
	var third = $("#team_two_"+ids).html();	
	$("#team_one_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
	$("#team_draw_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
	$("#team_two_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
$.ajax({
	   type: "POST",
		url: "cast_votes.php",
	   data: "team=one&id="+ids,
		success: function(data){
		if(data == -1)
		{
			$("#team_one_"+ids).html(first);
			$("#team_draw_"+ids).html(second);
			$("#team_two_"+ids).html(third);
			alert("Already voted");
		}
		else
		{
			$("#team_one_class_"+ids).addClass("greenactive");
			var results = data.split(",");	
			$("#team_one_"+ids).html(results[0]);
			$("#team_draw_"+ids).html(results[1]);
			$("#team_two_"+ids).html(results[2]);
		}
   }
	 });
}
//////////////////////////////////////////
function team_draw(vale)
{
	var ids = vale;
	if(vale == 'na')
		alert("You can not vote this option for this event please vote for Team One of Team Two");
	else
	{
	
	var first = $("#team_one_"+ids).html();
	var second = $("#team_draw_"+ids).html();	
	var third = $("#team_two_"+ids).html();	
	$("#team_one_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
	$("#team_draw_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
	$("#team_two_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
$.ajax({
	   type: "POST",
		url: "cast_votes.php",
	   data: "team=draw&id="+ids,
		success: function(data){
		if(data == -1)
		{
			$("#team_one_"+ids).html(first);
			$("#team_draw_"+ids).html(second);
			$("#team_two_"+ids).html(third);
			alert("Already voted");
		}
		else
		{
			$("#team_draw_class_"+ids).addClass("greenredactive");
			var results = data.split(",");	
			$("#team_one_"+ids).html(results[0]);
			$("#team_draw_"+ids).html(results[1]);
			$("#team_two_"+ids).html(results[2]);
		}
   }
	 });
	}
	
}
/////////////////////////////////////////
function team_two(ids)
{
	var first = $("#team_one_"+ids).html();
	var second = $("#team_draw_"+ids).html();	
	var third = $("#team_two_"+ids).html();	
	$("#team_one_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
	$("#team_draw_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
	$("#team_two_"+ids).html('<img src="images/ajax-small.gif"  style="padding-top:5px;" />');
$.ajax({
	   type: "POST",
		url: "cast_votes.php",
	   data: "team=two&id="+ids,
		success: function(data){
		if(data == -1)
		{
			$("#team_one_"+ids).html(first);
			$("#team_draw_"+ids).html(second);
			$("#team_two_"+ids).html(third);
			alert("Already voted");
		}
		else
		{
			$("#team_two_class_"+ids).addClass("redactive");
			var results = data.split(",");	
			$("#team_one_"+ids).html(results[0]);
			$("#team_draw_"+ids).html(results[1]);
			$("#team_two_"+ids).html(results[2]);
		}
   }
	 });
}
