
/*
 * Function is run when the DOM is ready.
 */
$(function() {
	$("#loading_icon").hide();
	$("#whizzoo").keyup( lookUpWhizzoo );
	//$("#tags").keyup( lookUpTag );
	//$("#whizzoo").onclick( function(){$("#smart_box").fadeOut();} );
	$("#smart_box").hide();
	var strLen = $('#whizzoo').val().length;
	$("#char_count").html(250-strLen);
	/*$('#tags').Autocomplete(
	{
		source: '/whizzoo.php',
		delay: 500,
		fx: {
			type: 'slide',
			duration: 400
		},
		autofill: true,
		helperClass: 'autocompleter',
		selectClass: 'selectAutocompleter',
		minchars: 2,
		onSelect : setTag,
		onShow : fadeInSuggestion,
		onHide : fadeOutSuggestion
	});
	*/
});

/*
 * The submit function for our AJAX form
function submitWhizzoo(){
	$("#loading_icon").show();
	$.ajax({
		url: 'whizzoo.php',
		type: 'POST',
		data: { whizzoo: $('#whizzoo').val() },
		dataType: 'html',
		error: function(msg){
			$("#loading_icon").hide();
			//alert('Sorry, there was a '+msg.status+' error ... ' + msg.responseXML);
		},
		success: function(html){
			$('#whizzoo_content').html(html);
			alert("Your vote has been counted!");
			//$('#sign_up').html(html);
			$.ajax({
				url: 'whizzoo.php',
				type: 'POST',
				data: { draw_last: 5 },
				dataType: 'html',
				//timeout: 1000,
				error: function(msg){
					$("#loading_icon").hide();
					//alert('Sorry, there was a '+msg.status+' error ... ' + msg.responseXML);
				},
				success: function(html){
					$('#whizzoo_content').html(html);
					$("#loading_icon").hide();
				}
			});
		}
	});
}
 */
 
function setWhizzoo(whizzoo)
{
	$('#whizzoo').val(whizzoo);
	var strLen = whizzoo.length;
	$("#char_count").html(250-strLen);
	$("#smart_box").fadeOut();
}

function fadeInSuggestion(suggestionBox, suggestionIframe) 
{
	$(suggestionBox).fadeTo(300,0.8);
};
function fadeOutSuggestion(suggestionBox, suggestionIframe) 
{
	$(suggestionBox).fadeTo(300,0);
};

var cityCode = function(data) {
	$('#city').html(data.value);
	$('#district').html(data.district);
	$('#population').html(data.population);
};

function setTag(tag)
{
	$("#smart_box").fadeOut();
	$('#tags').html($('#tags').val()+" " + tag.value);
}

function closeBox()
{
	$("#smart_box").fadeOut();
}

function lookUpTag()
{
	$("#loading_icon").show();
	$("#smart_box").html("<span style='float:left;'><img src='/images/loading.gif'/></span>" +
		"<a href='javascript:closeBox()' style='float:right;'>close</a>");
	$("#smart_box").fadeIn();
	$("#smart_box").html("<img src=\"/images/loading.gif\"/> loading...");
	$.ajax({
		url: 'whizzoo.php',
		type: 'POST',
		data: { tag_guess: $('#tags').val()  },
		dataType: 'html',
		error: function(msg){
			$("#smart_box").html('Sorry, there was a '+msg.status+' error ... ' + msg.responseXML);
			$("#loading_icon").hide();
		},
		success: function(html){
			$("#smart_box").html("<a href='javascript:closeBox()' style='float:right;'>close</a>" +html);
			$("#loading_icon").hide();
		}
	});
	
}
function lookUpWhizzoo()
{
	var strLen = $('#whizzoo').val().length;
	if(strLen < 1) return ;
	if(strLen>250) return ;
	$("#char_count").html(250-strLen);
	
	$("#loading_icon").show();
	$("#smart_box").html("<span style='float:left;'><img src='/images/loading.gif'/></span>" +
		"<a href='javascript:closeBox()' style='float:right;'>close</a>");
	$("#smart_box").fadeIn();
	$("#smart_box").html("<img src=\"/images/loading.gif\"/> loading...");
	$.ajax({
		url: 'whizzoo.php',
		type: 'POST',
		data: { whizzoo_guess: $('#whizzoo').val()  },
		dataType: 'html',
		error: function(msg){
			$("#smart_box").html('Sorry, there was a '+msg.status+' error ... ' + msg.responseXML);
			$("#loading_icon").hide();
		},
		success: function(html){
			$("#smart_box").html("<a href='javascript:closeBox()' style='float:right;'>close</a>" +html);
			$("#loading_icon").hide();
		}
	});
	
}

function whizzooVote(whizzooUid){
	$("#loading_icon").show();
	$("#whizzoo_content").html("loading...");
	
	$.ajax({
		url: 'whizzoo.php',
		type: 'POST',
		data: { whizzoo_uid: whizzooUid },
		dataType: 'html',
		error: function(msg){
			$("#whizzoo_content").html('Sorry, there was a '+msg.status+' error ... ' + msg.responseXML);
			$("#loading_icon").hide();
		},
		success: function(html){
			$("#whizzoo_content").html(html);
			$("#loading_icon").hide();
		}
	});
}
function removeWhizzoo(whizzooUid){
	$("#loading_icon").show();
	$("#whizzoo_content").html("loading...");
	
	$.ajax({
		url: 'whizzoo.php',
		type: 'POST',
		data: { remove_whizzoo_uid: whizzooUid },
		dataType: 'html',
		error: function(msg){
			$("#whizzoo_content").html('Sorry, there was a '+msg.status+' error ... ' + msg.responseXML);
			$("#loading_icon").hide();
		},
		success: function(html){
			$("#whizzoo_content").html(html);
			$("#loading_icon").hide();
		}
	});
}
function reportWhizzoo(whizzooUid){
	$("#loading_icon").show();
	$("#whizzoo_content").html("loading...");
	
	$.ajax({
		url: 'whizzoo.php',
		type: 'POST',
		data: { report_whizzoo_uid: whizzooUid },
		dataType: 'html',
		error: function(msg){
			$("#whizzoo_content").html('Sorry, there was a '+msg.status+' error ... ' + msg.responseXML);
			$("#loading_icon").hide();
		},
		success: function(html){
			$("#whizzoo_content").html(html);
			$("#loading_icon").hide();
		}
	});
}


