
	function browseCats( page, cat, div )
	{
		var url = "/ajax/ajax.browse_categories.php";
		var params = "entrant=" + page + "&cat_id=" + cat;
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function browseCatGroups( page, cat, div )
	{
		var url = "/ajax/ajax.view_cat_groups.php";
		var params = "entrant=" + page + "&cat_id=" + cat;
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
		
	function dispalyRecentPosts( group_id, type )
	{
		var div = "message_list";
		var url = "/ajax/ajax.recent_messages.php";
		var params = "group_id=" + group_id + "&type=" + type;
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function submitVote()
	{
		var options = document.getElementsByName( 'vote' );
		var voted   = false;
		for( var i = 0; i < options.length; i++ )
		{
			if( options[i].checked )
				voted = true;
		}
		
		if( !voted )
		{
			alert('You must choose an option to vote');
			return false;
		}
		
		var url 	= '/ajax/ajax.submit_vote.php';
		var div 	= 'poll_results';
		var params 	= $('poll_form').serialize();
		
		var ajax = new Ajax.Updater( 
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function groupPhotoUploadComplete( file )
	{
		var div 	= 'photo_thumb';
		var url 	= '/ajax/ajax.display_uploaded_thumb.php';
		var params  = "";
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function ajaxLoadGallery( id, div )
	{
		var url 	= '/ajax/ajax.load_gallery.php';
		var params  = "gallery_id=" + id;
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function browseFlaggedPosts(page, div, id)
	{
		var url = "/ajax/ajax.view_all_flagged_posts.php";
		var params = "entrant=" + page + "&group_id=" + id;
		
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function browseFlaggedMembers(page, div, id)
	{
		var url = "/ajax/ajax.browse_flagged_members.php";
		var params = "entrant=" + page + "&id=" + id;
		
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function browseAdmins(page, div, id)
	{
		var url = "/ajax/ajax.browse_admins.php";
		var params = "entrant=" + page + "&id=" + id;
		
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function browseOwners(page, div, id)
	{
		var url = "/ajax/ajax.browse_owners.php";
		var params = "entrant=" + page + "&id=" + id;
		
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function browseApplicants(page, div, id)
	{
		var url = "/ajax/ajax.browse_applicants.php";
		var params = "entrant=" + page + "&id=" + id;
		
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function writeFlaggedPostsValues(id, desc, group_id, page, is_active, type)	{
		var url = "/ajax/ajax.mark_deactivated_post.php?id="+id+"&description="+desc+"&group_id="+group_id+"&type="+type;
		
		var ajax = new Ajax.Request(
			url,
			{
				method: 'get',
				evalScripts: true
			}
		);
		if(is_active)
			alert("This post has been successfully deactivated. This post is no longer available anywhere on Parents R People.\n\nIf you deactivated this post in error, you can reactivate it at any time.");
		else
			alert("This post has been reactivated successfully.");

		browseFlaggedPosts(page, 'flag_group_posts', group_id);
	}
	
	function getRemovePosts(newVar, group_id, page){
		
		var answer = confirm("ARE YOU SURE you wish to permanently delete this post?\n\nThis action cannot be undone!")
			if (answer){
				writeRemovePost(newVar.id, group_id, page);
			}
	}
	
	function writeRemovePost(id, group_id, page)
	{
		var url = "/ajax/ajax.mark_remove_post.php?id="+id+"&group_id="+group_id;
		
		var ajax = new Ajax.Request(
			url,
			{
				method: 'get',
				evalScripts: true
			}
		);
	
		alert("This post has been successfully deleted.");

		browseFlaggedPosts(page, 'flag_group_posts', group_id);
	}
	
	function writeFlaggedMembersValues(id, desc, group_id, page, flagged, name)
	{
		var url = "/ajax/ajax.mark_flagged_member.php?id="+id+"&description="+desc+"&group_id="+group_id;
		
		var ajax = new Ajax.Request(
			url,
			{
				method: 'get',
				evalScripts: true
			}
		);
		if(!flagged)
			alert(name+" has been flagged for removal successfully!\n\nA Parents R People admin will review the flag and take the appropriate actions. Thank you!");
		else
			alert(name+"'s flag has been removed successfully!\n\n No review will be made on this member by the Parents R People admins.");
		browseFlaggedMembers(page, 'flag_users', group_id);
	}
	
	function getFlaggedPosts(newVar, group_id, page, is_active,type){
		if(is_active && newVar.value==''){
			alert("Please enter a short description explaining why you're deactivating this post.");
		}
		else if(is_active){
			var answer = confirm("Are you sure you wish to deactivate this post?")
			if (answer){
				writeFlaggedPostsValues(newVar.id, newVar.value, group_id, page, is_active,type);
			}
		}
		else if(!is_active) {
			var answer = confirm("Are you sure you wish to reactivate this post and make it visible again?")
			if (answer){
				writeFlaggedPostsValues(newVar.id, '', group_id, page, is_active,type);
			}
		}
	}
	
	function removeFlag(id, group_id, page, type){
		var answer = confirm("Are you sure this content is appropriate and you wish to remove the flag from this post?");
			if (answer){
								
				var url = "/ajax/ajax.remove_post_flag.php?id="+id+"&group_id="+group_id+"&type="+type;
		
				var ajax = new Ajax.Request(
					url,
					{
					method: 'get',
					evalScripts: true
					}
				);
		
			alert("The flag has been removed successfully!");
			
			browseFlaggedPosts(page, 'flag_group_posts', group_id);
		
			}
	}
	
	function getFlaggedMember(newVar, flagged, group_id, name, page, admin){
		var id;
		if(newVar.id=='text'){
			id = newVar.name.substring(newVar.name.indexOf("[")+1,newVar.name.indexOf("]"));
			id = parseFloat(id);
			
			if(!admin) {
				if(newVar.value == '' && !flagged){
					alert("Please enter a short description explaining your reason for flagging "+name+".");
				}
				else if(newVar.value !== '' && !flagged){
					var answer = confirm("Are you sure you wish to flag \""+name+"\" for removal?")
					if (answer){
						writeFlaggedMembersValues(id, newVar.value, group_id, page, flagged, name);
					}
				}
				else {
					var answer = confirm("Are you sure you wish to remove the flag on \""+name+"\"?")
					if (answer){
						writeFlaggedMembersValues(id, '', group_id, page, flagged, name);
					}
				}
			}
			else {
				alert("You can not flag a group admin/owner for removal.\n\nTo remove an admin from the group, the group owner must first remove administrative rights from him/her.");
			}
		}
	}
			
	function acceptGroupApplication(member_id,group_id)
	{
		var url = "/ajax/ajax.group_accept_applicant.php";
		var params = "member=" + member_id + "&group=" + group_id;
		var div = "browse_applicants";
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	function rejectGroupApplication(member_id,group_id)
	{
		var url = "/ajax/ajax.group_reject_applicant.php";
		var params = "member=" + member_id + "&group=" + group_id;
		var div = "browse_applicants";
		
		var ajax = new Ajax.Updater(
			div,
			url,
			{
				parameters: params,
				method: 'post',
				evalScripts: true
			}
		);
	}
	
	
	function writeAdminValues(id, group_id, page, user_status, self_status, name)
	{
		var url = "/ajax/ajax.mark_new_admin.php?id="+id+"&group_id="+group_id;
		
		var ajax = new Ajax.Request(
			url,
			{
				method: 'get',
				evalScripts: true
			}
		);
		
		if(user_status == 'admin')
			alert(name+" has been successfully demoted and is no longer an administrator!");
		else if(self_status == 'owner')
			alert(name+" has been successfully promoted and now has administrator rights.\n\nYou can demote this new admin at any time.");
		else
			alert(name+" has been successfully promoted and now has administrator rights.\n\nIf this was done by accident, please contact the group owner immediately.");
			
		browseAdmins(page, 'appoint_admins', group_id);
	}
	
	function writeNewOwner(id, group_id, name, page, self_id)
	{
		var url = "/ajax/ajax.mark_new_owner.php?id="+id+"&group_id="+group_id+"&self_id="+self_id;
		
		var ajax = new Ajax.Request(
			url,
			{
				method: 'get',
				evalScripts: true
			}
		);

		alert("You have appointed "+name+" as new group owner.\n\nYou will now be redirected to the group homepage.");
		window.location = 'group_info.php?id='+group_id;
	}
	
	function getCheckedOwner(user_id, group_id, name, checkbox, page, self_id) {
		var answer = confirm("WARNING: Are you sure you want to remove yourself as group owner and appoint "+name+" as the new group owner?\n\nThis action cannot be undone. (Unless "+name+" gives his new ownership back to you...)");
		if (answer){
			var yes = prompt("Are you absolutely SURE you want to no longer be the group owner, and want to give \"group owner\" status to "+name+"?\n\nIf so, please type 'YES' in the box below.");
				if (yes.toLowerCase() == 'yes'){
					writeNewOwner(user_id, group_id, name, page, self_id);
				}
				else{
					checkbox.checked=checkbox.defaultChecked;
				}
		}
		else{
			checkbox.checked=checkbox.defaultChecked;
		}
	}
	
	function getCheckedAdmin(user_id, group_id, user_status, self_status, name, checkbox, page, self_id){
		if((user_status=='owner' && self_status == 'owner') || (user_id == self_id)){
			alert("You cannot remove yourself as Admin!");
			checkbox.checked=checkbox.defaultChecked;
		}
		else if(user_status=='owner' && self_status == 'admin'){
			alert("You cannot demote the Group Owner!");
			checkbox.checked=checkbox.defaultChecked;
		}
		else if(user_status=='admin' && self_status == 'admin'){
			alert("You cannot demote a fellow Admin!");
			checkbox.checked=checkbox.defaultChecked;
		}
		else if(user_status=='admin' && self_status == 'owner'){
			var answer = confirm("WARNING: Are you sure you want to strip administrative rights and demote \""+name+"\" back to a regular user?");
			if (answer){
				writeAdminValues(user_id, group_id, page, user_status, self_status, name);
			}
			else{
				checkbox.checked=checkbox.defaultChecked;
			}
		}
		else if(user_status=='' && self_status == 'admin'){
			alert("Only the Group Owner can promote a new group administrator.");
			checkbox.checked=checkbox.defaultChecked;
		}
		else if(user_status=='' && self_status == 'owner'){
			var answer = confirm("WARNING: Are you sure you want to promote \""+name+"\" to Group Administrator?\n\nThis will give "+name+" administrative rights and only you, the Group Owner, can demote this new admin back to regular status!");
			if (answer) {
				writeAdminValues(user_id, group_id, page, user_status, self_status, name);
			}
			else {
				checkbox.checked=checkbox.defaultChecked;
			}
		}
	}
	
	function showCat(catname, id) {
		var allDivs=new Array("edit_group_details","flag_group_posts","flag_users","appoint_admins","change_ownership","browse_applicants");
		
		for (i=0;i<=5;i++)
		{
			document.getElementById(allDivs[i]).style.display="none";
			document.getElementById(allDivs[i]).style.visibility="hidden";	
		}
	
		document.getElementById(catname).style.display="block";
		document.getElementById(catname).style.visibility="visible";

		switch(catname) {
		case "edit_group_details":
		break;
		case "flag_group_posts":
		browseFlaggedPosts(1,catname,id);
		break;
		case "flag_users":
		browseFlaggedMembers(1,catname,id);
		break;
		case "appoint_admins":
		browseAdmins(1,catname,id);
		break;
		case "change_ownership":
		browseOwners(1,catname,id);
		break;
		case "browse_applicants":
		browseApplicants(1,catname,id);
		break;
		default:
		}
	}
	
	/*
	
	//deprecated (now uses ajax)
	
	function confirmFlagPosts(){
		var count = 0;
		var check = true;
		for(x=0; x<document.flag_posts.elements["checkbox"].length; x++){
        	if(document.flag_posts.elements["checkbox"][x].checked==true){
        		if(document.flag_posts.elements["text"][x].value == ''){
        			alert("Please enter a short description explaining your reason for flagging this post for removal.");
        			document.flag_posts.elements["text"][x].focus();
        			check = false;
        			break;
        		}
        		count++;
        	}
   		}
   		
   		if(check){
   		
	   		if(count==0){
	   			alert("You have not selected any posts for removal!");
	   		}
	   		else{
	   			if(count==1){
	   				var answer = confirm("Are you sure you wish to flag this post for removal?\n\nWarning: This action cannot be undone!")
	   			}
	   			else {
	   				var answer = confirm("Are you sure you wish to flag these "+count+" checked posts for removal?\n\nWarning: This action cannot be undone!")
	   			}
	   			
				if (answer){
					document.flag_posts.submit();
				}
				else{
					//nothing
				}
	   		}
	   		
   		}
	}
	
	*/
	