$(document).ready(
		function() {
			
			$('#tabs1 div').hide(); // Hide all divs
			$('#tabs1 div:first').show(); // Show the first div
			$('#tabs1 ul li:first').addClass('active'); // Set the class for active state
			$('#tabs1 ul li a.tablink').click(
					function() { // When link is clicked
						$('#tabs1 ul li').removeClass('active'); // Remove active class from links
						$(this).parent().addClass('active'); //Set parent of clicked link class to active
						var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
						$('#tabs1 div').hide(); // Hide all divs
						$(currentTab).show(); // Show div with id equal to variable currentTab
						return false;
					}
			);

			$('#tabs2 span').hide(); // Hide all divs
			$('#tabs2 span:first').show(); // Show the first div
			$('#tabs2 ul li:first').addClass('active'); // Set the class for active state
			$('#tabs2 ul li a.tablink').click(
					function() { // When link is clicked
						$('#tabs2 ul li').removeClass('active'); // Remove active class from links
						$(this).parent().addClass('active'); //Set parent of clicked link class to active
						var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
						$('#tabs2 span').hide(); // Hide all divs
						$(currentTab).show(); // Show div with id equal to variable currentTab
						$(currentTab).siblings.show();
						return false;
					}
			);
			
			$('#supporter_btn').click(function() {
				// Get the user to input captcha
				var ccode = prompt('Please enter the text seen in the image');
				if(ccode == '')
					return false;
				
				var party_id = $("input#party_id").val();
				$('#supporter_notice').html("<span style='background: url(\"/images/loading.gif\") no-repeat top left; padding-left:20px'> Please wait...</span>")
				.hide()
				.fadeIn(500);
				$.ajax({
					type: "POST",
					url: "/modules/ajax/party_supporter.php",
					data: "party_id=" + party_id + "&ccode=" + ccode,
					success: function(msg) {
						$('#supporter_notice').html(msg)
						.hide()
						.fadeIn(1500);
						$('#captcha_box').hide();
					}
				});
			});
			
			$('#poll_div input').click(function()
			{
				// Check for val
				val = $(this).val();
				if(val == '')
						return false;
				
				// Set to temp view
				$('#poll_div').html("<span style='background: url(\"/images/loading.gif\") no-repeat top left; padding-left:20px'> Please wait...</span>")
				.hide()
				.fadeIn(500);
				
				// Get active poll
				var pollid = document.getElementById('poll_id').value;
				
				// Do Ajax
				$.ajax({
					type: "POST",
					url: "/modules/ajax/vote.php",
					data: "pollid="+pollid+"&vote="+val,
					success: function(msg) {
						$('#poll_div').html(msg)
						.hide()
						.fadeIn(1500);
					}
				});
			});
		}
);


function showDetail(province)
{
	$('#detailArea').html("<span style='background: url(\"/images/loading.gif\") no-repeat top left; padding-left:20px'> Please wait...</span>")
	.hide()
	.fadeIn(500);

	$.ajax({
		type: "POST",
		url: "/modules/ajax/results.php",
		data: "prov="+province,
		success: function(msg) {
			$('#detailArea').html(msg)
			.hide()
			.fadeIn(1500);
			
			$('#tabs2 span').hide(); // Hide all divs
			$('#tabs2 span:first').show(); // Show the first div
			$('#tabs2 ul li:first').addClass('active'); // Set the class for active state
			$('#tabs2 ul li a.tablink').click(
					function() { // When link is clicked
						$('#tabs2 ul li').removeClass('active'); // Remove active class from links
						$(this).parent().addClass('active'); //Set parent of clicked link class to active
						var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
						$('#tabs2 span').hide(); // Hide all divs
						$(currentTab).show(); // Show div with id equal to variable currentTab
						$(currentTab).siblings.show();
						return false;
					}
			);			
		}
	});
}


//NOTE: the month entered must be one less than current month. ie; 0=January, 11=December
//NOTE: the hour is in 24 hour format. 0=12am, 15=3pm etc
//format: dateFuture = new Date(year,month-1,day,hour,min,sec)
//example: dateFuture = new Date(2003,03,26,14,15,00) = April 26, 2003 - 2:15:00 pm
function GetCount()
{
	dateNow = new Date();									//grab current date
	amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
	delete dateNow;

	// time is already past
	if(amount < 0) {
		document.getElementById('countdowntimer').innerHTML="Now!";

	// date is still good
	} else {
		days=0;
		hours=0;
		mins=0;
		secs=0;
		out="";

		//kill the "milliseconds" so just secs
		amount = Math.floor(amount/1000);

		//days
		days=Math.floor(amount/86400);
		amount=amount%86400;

		//hours
		hours=Math.floor(amount/3600);
		amount=amount%3600;

		//minutes
		mins=Math.floor(amount/60);
		amount=amount%60;

		//seconds
		secs=Math.floor(amount);

		str_days = days.toString();
		if (str_days.length < 2)
			str_days = "0" + str_days; 
 	
		str_hours = hours.toString();
		if (str_hours.length < 2)
			str_hours = "0" + str_hours; 

		str_mins = mins.toString();
		if (str_mins.length < 2)
			str_mins = "0" + str_mins; 

		str_secs = secs.toString();
		if (str_secs.length < 2)
			str_secs = "0" + str_secs; 

		out += "<span id='timerlarge'>";
		if(days != 0)
			out +="<span class='timernum'>"+ str_days  +"</span> days ";
		if(days != 0 || hours != 0)
			out +="<span class='timernum'>"+  str_hours +"</span> hours ";
		if(days != 0 || hours != 0 || mins != 0)
			out += "<span class='timernum'>"+ str_mins +"</span> minutes ";

		document.getElementById('countdowntimer').innerHTML=out;

		setTimeout("GetCount()", 1000);
	}
}