/*
 * Ajax calls for trials
 * 
 */
ADMIN_URL='http://www.bcg.org.au/members/';

function add_collation(trial_id,input){
	if (input.checked==true){
		$.ajax({	
	   		type: "POST",
	   		url: ADMIN_URL+"trial_list_ajax.php",
   			data: "action=add_to_collation&trial_id="+trial_id
 		});
	} else if (input.checked==false){
		$.ajax({	
	   		type: "POST",
	   		url: ADMIN_URL+"trial_list_ajax.php",
   			data: "action=remove_from_collation&trial_id="+trial_id
 		});
	} 
	
}

function delete_trial(trial_id){
	$.ajax({	
   		type: "POST",
   		url: ADMIN_URL+"trial_list_ajax.php",
		data: "action=delete_from_collation&trial_id="+trial_id,
		success: function(){
			window.location.reload();
		}
	});

}

function clear_page(offset){
	$.ajax({	
   		type: "POST",
   		url: ADMIN_URL+"trial_list_ajax.php",
		data: "action=clear_page&offset="+offset,
		success: function(html){
			var checked_boxes = document.getElementsByName('collate');
			for (i = 0; i < checked_boxes.length; i++){
				checked_boxes[i].checked = false ;
			}
			$("#update_results").html(html);
   		    $("#update_results").fadeIn("slow");
	    	setTimeout(function(){$("#update_results").fadeOut("slow")},5000);					
		}
	});

}

function check_page(offset){
	$.ajax({	
   		type: "POST",
   		url: ADMIN_URL+"trial_list_ajax.php",
		data: "action=check_page&offset="+offset,
		success: function(html){
			var checked_boxes = document.getElementsByName('collate');
			for (i = 0; i < checked_boxes.length; i++){
				checked_boxes[i].checked = true ;
			}
			$("#update_results").html(html);
   		    $("#update_results").fadeIn("slow");
	    	setTimeout(function(){$("#update_results").fadeOut("slow")},5000);
	    		   				
		}
	});

}

function clear_all(){
	$.ajax({	
   		type: "POST",
   		url: ADMIN_URL+"trial_list_ajax.php",
		data: "action=clear_all",
		success: function(html){
		var checked_boxes = document.getElementsByName('collate');
		for (i = 0; i < checked_boxes.length; i++){
			checked_boxes[i].checked = false ;
		}
		$("#update_results").html(html);
	    $("#update_results").fadeIn("slow");
    	setTimeout(function(){$("#update_results").fadeOut("slow")},5000);
		
		}
	
	});

}
