
$(function(){
	var loader=$('#loader');
	var polls=$('#polls');
	loader.fadeIn();
	$.get('/php/polls.php', '', function(data, status){
		polls.html(data);
		animateResults(polls);
		polls.find('#viewresult').click(function(){
			loader.fadeIn();
			$.get('/php/polls.php', 'result=1', function(data,status){
				polls.fadeOut(1000, function(){
					$(this).html(data);
					animateResults(this);
				});
				loader.fadeOut();
			});
			return false;
		}).end()
		.find('#pollform').submit(function(){
			var selected_val=$(this).find('input[name=poll]:checked').val();
			if(selected_val!=''){
				loader.fadeIn();
				$.post('/php/polls.php', $(this).serialize(), function(data, status){
					$('#forms').fadeOut(100, function(){
						$(this).html(data);
						animateResults(this);
						loader.fadeOut();
					});
				});
			}
			return false;
		});
		loader.fadeOut();
	});
	
	function animateResults(data){
		$(data).find('.bar').hide().end().fadeIn('slow', function(){
							$(this).find('.bar').each(function(){
								var bar_width=$(this).css('width');
								$(this).css('width', '0').animate({ width: bar_width }, 0);
					 });
			 });
	   }
	
});


		
function createObject() {
	var req;
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert('Problem creating the XMLHttpRequest object');
	}
	return req;

}

var http = createObject();

function board() {
	var textOut = http.responseText;
	document.getElementById('id'+cid).innerHTML = textOut;
}

function useHttpResponse() {
  if (http.readyState == 4) {
	setTimeout("board()",1000);
  }
}

function up(id) {
	cid = id;
	var newLoad = '<img src="/theme/global/images/loading.gif" alt="" />';
	document.getElementById('id'+cid).innerHTML = newLoad;
	http.open('get', '/php/moderation.php?&action=up&id='+cid+'&rand='+Math.random(), true);
	
	http.onreadystatechange = useHttpResponse;
	http.send(null);
}

function down(id) {
	cid = id;
	var newLoad = '<img src="/theme/global/images/loading.gif" alt="" />';
	document.getElementById('id'+cid).innerHTML = newLoad;
	http.open('get', '/php/moderation.php?&action=down&id='+cid+'&rand='+Math.random(), true);
	
	http.onreadystatechange = useHttpResponse;
	http.send(null);
}



function undelete(id) {
	cid = id;
	var newLoad = '<img src="/theme/global/images/loading.gif" alt="" />';
	document.getElementById('id'+cid).innerHTML = newLoad;
	http.open('get', '/php/moderation.php?action=delete&id='+cid+'&rand='+Math.random(), true);
	
	http.onreadystatechange = useHttpResponse;
	http.send(null);
}


function orgsdelete(id) {
	cid = id;
	var newLoad = '<img src="/theme/global/images/loading.gif" alt="" />';
	document.getElementById('id'+cid).innerHTML = newLoad;
	http.open('get', '/php/moderation.php?action=orgsdelete&id='+cid+'&rand='+Math.random(), true);
	
	http.onreadystatechange = useHttpResponse;
	http.send(null);
}
