var Container2 = {
	
	// Changes a tab.
	change_tab:function(container_id,tab_id) {
		
		// Gets the tab IDs.
		var tab_ids = Container2.get_tab_ids(container_id);
		
		// Loops through the tab IDs.
		for(var counter=tab_ids.length-1; counter>=0; --counter) {
		
			// Some ID stuff we need below.
			var partial_id = '_'+container_id+'_'+tab_ids[counter];
			var element_tab = $('tab'+partial_id);
			var element_content = $('content'+partial_id);
		
			// Turns the tab off.
			element_tab.removeClassName('on');
			element_content.hide();
			
			// If this is the tab the user is changing to.
			if(tab_ids[counter]==tab_id) {
				
				// Turns the tab on.
				element_tab.addClassName('on');
				element_content.show();
			}
		}
	},
	
	// Closes a pop-up container.
	close_popup:function() {
		
		// Clears everything in the "popups" <div>.
		$('popups').update('');
	},
	
	// True or False: Should we close the pop-up?
	confirm_close:function(container_id,confirm_message) {
		return (!Container2.is_marked(container_id) || confirm(confirm_message));
	},
	
	// Focuses on a field.
	focus_on_field:function(field_id,container_id,tab_id,try_popup) {
		
		// Makes sure the field is not undefined.
		if(field_id!=undefined) {
			
			// Temporarily holds the container ID.
			var temp_container_id = container_id;
			
			// If we're trying to focus on a field in a pop-up, the container ID will be preceded with "popup_".
			if(try_popup) container_id = 'popup_'+container_id;
			
			// Textbox.
			if($('field_textbox_'+container_id+'_'+tab_id+'_'+field_id)) {
				$('field_textbox_'+container_id+'_'+tab_id+'_'+field_id).focus();
				$('field_textbox_'+container_id+'_'+tab_id+'_'+field_id).select();
			}
			
			// Select box.
			else if($('field_select_'+container_id+'_'+tab_id+'_'+field_id)) {
				$('field_select_'+container_id+'_'+tab_id+'_'+field_id).focus();
			}
			
			// Date/Datetime select boxes.
			else if($('field_datetime_'+container_id+'_'+tab_id+'_'+field_id+'_month')) {
				$('field_datetime_'+container_id+'_'+tab_id+'_'+field_id+'_month').focus();
			}
			
			// If we're currently trying to focus on a pop-up field.
			else if(try_popup) {
				
				// Try again, this time for non-pop-ups.
				Container2.focus_on_field(field_id,temp_container_id,tab_id,false);	
			}
		}
	},
	
	// Returns ",variable:value", for Ajax.
	get_parameter_string:function(field_id,field_value) {
		
		// In case the value is undefined or blank.
		if(field_value==undefined || !field_value) field_value = '';
		
		// If there's a value, make sure the quotes are escaped and line breaks are removed.
		else {
			field_value = (''+field_value).replace(/[\n\r]/g,'\\n').replace(/'/g,"\\'");
		}
		
		// Returns a portion of the parameter string.
		return (field_id!='' ? ","+field_id+":'"+field_value+"'" : '');
	},
	
	// Returns an array of IDs for a container's tabs.
	get_tab_ids:function(container_id) {
		
		// The array to return.
		var return_array = new Array();
		
		// Gets the tab elements.
		var elements = $$('#tabs_'+container_id+' li');
		
		// Loops through the elements.
		for(var counter=elements.length-1; counter>=0; --counter) {
		
			// Adds the ID to the return array.
			return_array[return_array.length] = elements[counter].id.substr(5+container_id.length);
		}
		
		// Returns the array.
		return return_array;
	},
	
	// True or False: Is the container already marked?
	is_marked:function(container_id) {
		
		// Will return false by default.
		var return_value = false;
		
		// We must have a container to work with. 
		if(container_id!=undefined) {
	
			// In case we're working with a pop-up.
			if($('popup_'+container_id)) container_id = 'popup_'+container_id;
			
			// Gets the tab IDs.
			var tab_ids = Container2.get_tab_ids(container_id);
	
			// Loops through the elements.
			for(var counter=tab_ids.length-1; counter>=0; --counter) {
	
				// Gets the tab ID.
				var tab_id = tab_ids[counter];
				
				// If the tab exists.
				if($('tab_'+container_id+'_'+tab_id)) {
					
					// Gets the element we'll be checking.
					var element = $('tab_'+container_id+'_'+tab_id).firstDescendant();
			
					// The point of separation between the text and the asterisk.
					var separation_point = 1;
						
					// If the element exists and there's an asterisk at the beginning.
					if(element && element.innerHTML.substr(0,separation_point)=='*') {
						
						// Function will return true.
						return_value = true;
					}
				}
			}
			
			// Makes sure the container title exists.
			if($('title_'+container_id)) {
			
				// Gets the element we'll be checking.
				var element = $('title_'+container_id);
				
				// The point of separation between the text and the asterisk.
				var separation_point = element.innerHTML.length - 1;
				
				// If there's an asterisk at the end.
				if(element.innerHTML.substr(separation_point)=='*') {
					
					// Function will return true.
					return_value = true;
				}
			}
		}
		
		// Returns true if the container is already marked.
		return return_value;
	},
	
	// Loads the CAPTCHA.
	load_captcha:function() {
		if($('recaptcha_widget')) {
			Recaptcha.create('6LeBmgUAAAAAAIy74VyfjfYCWbNi7i62-e_nkKAm','field_recaptcha',{
				theme: 'custom',
				custom_theme_widget: 'recaptcha_widget'
			});
		}
	},
	
	// Shows the login container.
	login:function() {
		Container.show_popup('login');
	},
	
	// Marks and unmarks changes to a form container.
	mark_changes:function(do_mark,container_id,tab_id) {
	
		// We must have a container to work with. 
		if(container_id!=undefined) {
	
			// In case we're working with a pop-up.
			if($('popup_'+container_id)) container_id = 'popup_'+container_id;
	
			// The tab ID is 0 by default.
			if(tab_id==undefined) tab_id = 0;
	
			// If the container has tabs, make sure the tab exists.
			if(Container2.get_tab_ids(container_id).length>0 && $('tab_'+container_id+'_'+tab_id)) {
				
				// Gets the element we'll be changing.
				var element = $('tab_'+container_id+'_'+tab_id).firstDescendant();
				
				// Makes sure the element exists.
				if(element) {
					
					// The point of separation between the text and the asterisk.
					var separation_point = 1;
					
					// Is the text already marked?
					var is_marked = (element.innerHTML.substr(0,separation_point)=='*');
					
					// If we're marking something that hasn't already been marked, add the asterisk to the beginning.
					if(do_mark && !is_marked) element.innerHTML = '*' + element.innerHTML;
					
					// If we're unmarking something that was previously marked, remove the asterisk.
					else if(!do_mark && is_marked) element.innerHTML = element.innerHTML.substring(separation_point);
				}
			}
			
			// Makes sure the container title exists.
			else if($('title_'+container_id)) {
			
				// Gets the element we'll be changing.
				var element = $('title_'+container_id);
				
				// The point of separation between the text and the asterisk.
				var separation_point = element.innerHTML.length - 1;
				
				// Is the text already marked?
				var is_marked = (element.innerHTML.substr(separation_point)=='*');
			
				// If we're marking something that hasn't already been marked, add the asterisk to the end.
				if(do_mark && !is_marked) element.innerHTML += '*';
				
				// If we're unmarking something that was previously marked, remove the asterisk.
				else if(!do_mark && is_marked) element.innerHTML = element.innerHTML.substring(0,separation_point);
			}
		}
	},
	
	// Removes all non-integer values from an element.
	remove_invalid_chars:function(element_id,value,valid_chars) {
		if(valid_chars!=undefined && valid_chars!='') {
			var valid_string = Shortcut.get_valid_chars(value,valid_chars);
			if(value!=valid_string) $(element_id).value = valid_string;
		}
	},
	
	// Reads a date/datetime field and returns the seconds elapsed since midnight on 1/1/1970.
	process_datetime:function(container_id,tab_id,field_id) {
	
		// Gets the IDs of the fields contianing the values.
		var month_id = 'field_datetime_'+container_id+'_'+tab_id+'_'+field_id+'_month';
		var day_id = 'field_datetime_'+container_id+'_'+tab_id+'_'+field_id+'_day';
		var year_id = 'field_datetime_'+container_id+'_'+tab_id+'_'+field_id+'_year';
		var hour_id = 'field_datetime_'+container_id+'_'+tab_id+'_'+field_id+'_hour';
		var minute_id = 'field_datetime_'+container_id+'_'+tab_id+'_'+field_id+'_minute';
	
		// Gets the values of the fields.
		var month_value = ($(month_id) ? $(month_id).value : 0);
		var day_value = ($(day_id) ? $(day_id).value : 0);
		var year_value = ($(year_id) ? $(year_id).value : 0);
		var hour_value = ($(hour_id) ? $(hour_id).value : 0);
		var minute_value = ($(minute_id) ? $(minute_id).value : 0);
		
		// Sets the date.
		var datetime = new Date(year_value,month_value-1,day_value,hour_value,minute_value,0,0);
		
		// The seconds that have elapsed between midnight of 1/1/1970 and the set date.
		var seconds_elapsed = parseInt(datetime.valueOf()/1000);
		
		// Returns the seconds elapsed.
		return seconds_elapsed;
	},
	
	// Refreshes a container.
	refresh_container:function() {
		
		// Parameters for the Ajax at the bottom of this function.
		var parameters = "control:'container2',action:'get_container',xsrf:xsrf";
		
		// Loops through the arguments.)
		for(var counter=0; counter<arguments.length; counter++) {
			
			// Gets the parameter ID.
			if(counter==0) var param_id = 'class_name';
			else if(counter==1) var param_id = 'class_id';
			else if(counter==2) var param_id = 'container_id';
			else var param_id = 'var'+(counter-3);
			
			// Gets part of the parameter string.
			parameters += Container2.get_parameter_string(param_id,arguments[counter]);
		}
		
		// The Ajax.
		eval("new Ajax.Request(engineURL,{method:'post',parameters:{"+parameters+"},onComplete:function(transport) { Container2.refresh_container_process(eval('('+Container2.remove_notices(transport.responseText)+')')); }});");
	},
	
	// Refreshes a pagination container.
	refresh_container_pagination:function(container_id) {
		
		// If the refresh code is stored in a hidden field.
		if(container_id!=undefined && $('field_hidden_'+container_id+'_0_refresh_code')) {
			
			// Executes the refresh code.
			eval($('field_hidden_'+container_id+'_0_refresh_code').value);
		}
	},
	
	// Processes the responseText from refresh_container().
	refresh_container_process:function(json_object,target_container_id) {
		
		// There was no error.
		if(json_object.error==false) {
		
			// In case no target container ID was specified.
			if(target_container_id==undefined) target_container_id = json_object.id;
		
			// Makes sure the container exists.
			if($(target_container_id)) {
				
				// Refreshes the container.
				$(target_container_id).replace(json_object.html);
			}
		}
	},
	
	// Refreshes multiple containers using a JSON-encoded array.
	refresh_containers:function(json_string) {
		
		// Makes sure the string is not undefined.
		if(json_string!=undefined) {
			
			// Converts the JSON string into an object.
			var json_object = eval('('+json_string+')');
			
			// Loops through each key in json_object.
			for(key in json_object) {
				
				// If the key exists.
				if(json_object.hasOwnProperty(key)){
					
					// If the container exists, update its HTML.
					if($(key)) $(key).replace(json_object[key]);
				}
			}
		}
	},
	
	// Removes notices so the code doesn't stop.
	remove_notices:function(json_object) {
		return json_object.substr(json_object.indexOf('{'));
	},
	
	// Replaces one container with another container.
	replace_container:function() {
		
		// Parameters for the Ajax at the bottom of this function.
		var parameters = "control:'container2',action:'get_container',xsrf:xsrf";
		
		// Use an undefined target container ID as default..
		var target_container_id = arguments[0];
		
		// Loops through the arguments.)
		for(var counter=1; counter<arguments.length; counter++) {
			
			// Gets the parameter ID.
			if(counter==1) var param_id = 'class_name';
			else if(counter==2) var param_id = 'class_id';
			else if(counter==3) var param_id = 'container_id';
			else var param_id = 'var'+(counter-4);
			
			// Gets part of the parameter string.
			parameters += Container2.get_parameter_string(param_id,arguments[counter]);
		}
		
		// The Ajax.
		eval("new Ajax.Request(engineURL,{method:'post',parameters:{"+parameters+"},onComplete:function(transport) { Container2.refresh_container_process(eval('('+Container2.remove_notices(transport.responseText)+')'),target_container_id); }});");
	},
	
	// Shows an error message.
	show_error:function(message,container_id,tab_id,focus_field,show_label) {
		if(show_label) message = '<b>Error:</b> ' + message;
		Container2.show_message(message,container_id,tab_id,focus_field,'error');
	},
	
	// Shows an info message.
	show_info:function(message,container_id,tab_id,focus_field,show_label) {
		if(show_label) message = '<b>Attention:</b> ' + message;
		Container2.show_message(message,container_id,tab_id,focus_field,'info');
	},
	
	// Shows a "loading" pop-up container.
	show_loading_popup:function() {
		Container.show_loading_popup();
	},
	
	// Shows a message.
	show_message:function(message,container_id,tab_id,focus_field,type) {
		
		// Makes sure there's a message to show.
		if(message!=undefined) {
			
			// Type is "info" by default.
			if(type!='error') type = 'info';
			
			// Uses a default tab ID of 0.
			if(tab_id==undefined) tab_id = 0;
			
			// The ID of the message <div> (for the popup).
			var message_div_id = 'message_popup_'+container_id+'_'+tab_id;
			
			// The <div> doesn't exist in the pop-up. Assume non-pop-up.
			if(!$(message_div_id)) message_div_id = 'message_'+container_id+'_'+tab_id;
			
			// Makes sure the message <div> exists.
			if($(message_div_id)) {
				
				// Removes the classes.
				$(message_div_id).removeClassName('error');
				$(message_div_id).removeClassName('info');
				
				// Adds the class.
				$(message_div_id).addClassName(type);
				
				// Shows the message.
				$(message_div_id).show();
				$$('#'+message_div_id+' p')[0].update(message);
			}
			
			// Focuses on the specified field.
			Container2.focus_on_field(focus_field,container_id,tab_id,true);
		}
	},
	
	// Shows a popup.
	show_popup:function() {
		
		// Parameters for the Ajax at the bottom of this function.
		var parameters = "control:'container2',action:'get_popup',xsrf:xsrf";
		
		// Loops through the arguments.
		for(var counter=0; counter<arguments.length; counter++) {
			
			// Gets the parameter ID.
			if(counter==0) var param_id = 'class_name';
			else if(counter==1) var param_id = 'class_id';
			else if(counter==2) var param_id = 'container_id';
			else var param_id = 'var'+(counter-3);
			
			// Gets part of the parameter string.
			parameters += Container2.get_parameter_string(param_id,arguments[counter]);
		}
		
		// Shows the loading pop-up.
		Container2.show_loading_popup();
		
		// The Ajax.
		//eval("new Ajax.Request(engineURL,{method:'post',parameters:{"+parameters+"},onComplete:function(transport) { Container2.show_popup_process(eval('('+transport.responseText+')')); }});");
		eval("new Ajax.Request(engineURL,{method:'post',parameters:{"+parameters+"},onComplete:function(transport) { Container2.show_popup_process(eval('('+Container2.remove_notices(transport.responseText)+')')); }});");
	},
	
	// Processes the responseText from show_popup().
	show_popup_process:function(json_object) {
		
		// There was no error.
		if(json_object.error==false) {
		
			// Show the pop-up.
			Container.render_popup(json_object.id,'<div id="popup_cover"></div>'+json_object.html);
		}
		
		// If the user is not logged-in.
		else if(json_object.error=='login') {
			
			// Show the login pop-up.
			Container2.login();
		}
	},
	
	// Sorts the items in a list.
	sort_list:function(element) {
		
		// Gets a string that describes the order.
		var serialized = Sortable.serialize(element);
		
		// The serialized string, split.
		var split_once = serialized.split('&');
		
		// An array that will keep track of the sort order.
		var sort_order = new Array();
		
		// Will hold the ID of the list.
		var list_id = false;
		
		// Loops through the elements.
		for(var counter=0; counter<split_once.length; counter++) {
		
			// This is used to get the information after the "=", which specifies the position.
			var split_twice = split_once[counter].split('=');
		
			// Set the list ID to the variable, if we haven't already done so.
			if(!list_id) list_id = split_twice[0];
		
			// Saves the order to the array.
			sort_order[sort_order.length] = split_twice[1];
		}
		
		// Makes sure we have a list ID. If not, there must not be any items being sorted.
		if(list_id) {

			// Gets the defined ID of the sortable.
			var sortable_id = $('field_hidden_'+(list_id.replace('_list[]','_id').substr(9))).value;
			
			// Gets a comma-separated list of the items, in order.
			var sortable_order = sort_order.join(',');
			
			// Gets the class name.
			var hidden_id = $('field_hidden_'+(list_id.replace('_list[]','_hidden_id').substr(9))).value;
			var class_name = $('field_hidden_'+hidden_id+'_class_name').value;
			
			// The Ajax.
			new Ajax.Request('/ajax.php', { method:'post',
				parameters:{ control:'container2', action:'sort_items', class_name:class_name, sort_id:sortable_id, sort_order:sortable_order, xsrf:xsrf },
			onComplete:function(transport) {
				eval(transport.responseText);
			}});
		}
	},
	
	// Submits a form.
	submit_form:function(container_id,tab_id) {
		
		// Parameters for the Ajax at the bottom of this function.
		var parameters = "control:'container2',action:'submit_form',xsrf:xsrf";
		
		// An array of radio field IDs.
		var radios = new Array();
		
		// Makes sure the tab exists.
		if($('content_'+container_id+'_'+tab_id)) {
			
			// Gets all elements for the tab.
			var elements = $('content_'+container_id+'_'+tab_id).descendants();
			
			// Loops through the elements.
			for(var counter=elements.length-1; counter>=0; --counter) {
			
				// The full ID of the element.
				var element_id = elements[counter].id;
			
				// Splits up the element's ID to get necessary information.
				var split_id = element_id.split('_');
			
				// This identifies the element as a field.
				if(split_id[0]=='field') {
					
					// The type of the field.
					var field_type = split_id[1];
					
					// Gets the field ID.
					var before = 'field_'+field_type+'_'+container_id+'_'+tab_id+'_';
					var after = (field_type=='datetime' ? '_'+split_id[split_id.length-1] : '');
					var field_id = element_id.substring(before.length,element_id.length-after.length);
					
					// This identifies the field as a datetime.
					if(field_type=='datetime') {
					
						// This makes sure we only do this once per datetime group.
						if(split_id[split_id.length-1]=='month') {
							
							// Gets the value from multiple fields.
							var field_value = Container2.process_datetime(container_id,tab_id,field_id);
							
							// Gets part of the parameter string.
							parameters += Container2.get_parameter_string(field_id,field_value);
						}
					}
					
					// Radio buttons.
					else if(field_type=='radio') {
						
						// Adds the field ID to the array.
						radios[radios.length] = elements[counter].name;
					}
					
					// These field values are hidden.
					else if(field_type=='cbvalue') {}
					
					// Other fields.
					else {
						
						// Gets the value of the field.
						var field_value = elements[counter].value;
						
						// Intboxes must be an integer.
						if(field_type=='intbox') {
							field_value = parseInt(field_value);
							if(isNaN(field_value)) field_value = '';
						}
						
						// Checkboxes must be 0 or 1.
						else if(field_type=='checkbox') {
							field_id = field_id.substr($(element_id).name.length+1); 
							field_value = ($(element_id).checked ? '1' : '0');
							var cbvalue_element = 'field_cbvalue'+element_id.substr(14);
							if(field_value==1 && $(cbvalue_element)) field_value = $(cbvalue_element).value;
						}
						
						// Gets part of the parameter string.
						parameters += Container2.get_parameter_string(field_id,field_value);
					}
				}
			}
		}
		
		// Removes duplicate values from the array.
		radios = radios.uniq();
		
		// The portion of the radio element ID before the field ID.
		var radio_before = 'field_radio_'+container_id+'_'+tab_id+'_';
		
		// Loops through the radio fields.
		for(var counter1=radios.length-1; counter1>=0; --counter1) {
			
			// The field name for this radio button group.
			var field_id = radios[counter1];
			
			// No value by default.
			var field_value = '';
			
			// Gets all radio elements for the tab.
			var elements = $$('#content_'+container_id+'_'+tab_id+' input[name="'+field_id+'"]');
			
			// Loops through the elements.
			for(var counter2=elements.length-1; counter2>=0; --counter2) {
				
				// If the radio button is checked, this sets the value.
				if(elements[counter2].checked) field_value = elements[counter2].value;
			}
			
			// Gets part of the parameter string.
			parameters += Container2.get_parameter_string(field_id,field_value);
		}
		
		// If there's a CAPTCHA field.
		if($('field_recaptcha')) {
			
			// Gets part of the parameter string.
			parameters += Container2.get_parameter_string('recaptcha_response',$('recaptcha_response_field').value);
			parameters += Container2.get_parameter_string('recaptcha_challenge',$('recaptcha_challenge_field').value);
		}
		
		// The ID of the tab.
		parameters += Container2.get_parameter_string('tab_id',tab_id);
		
		// The Ajax.
		eval("new Ajax.Request(engineURL,{method:'post',parameters:{"+parameters+"},onComplete:function(transport) { Container2.submit_form_process(eval('('+transport.responseText+')')); }});");
	},
	
	// Processes the responseText from submit_form().
	submit_form_process:function(json_object) {
		
		// Evaluates JavaScript.
		eval(json_object.javascript);
	},
	
	// Toggles content.
	toggle_content:function(container_id,toggle_id) {
		
		// The two elements we're working with.
		var togglee = $('togglee_'+container_id+'_'+toggle_id);
		var toggler = $('toggler_'+container_id+'_'+toggle_id);
		
		// Toggles the content's visibility.
		togglee.toggle();
		
		// If the content is now invisible.
		if(toggler.hasClassName('on')) {
			
			// Remove the "on" CSS class.
			toggler.removeClassName('on');
		}
		
		// If the content is now visible.
		else {
			
			// Add the "on" CSS class.
			toggler.addClassName('on');
		}
		
	},
	
	// Updates the "state" field when the "country" selection is changed.
	update_states:function(container_id,tab_id,country) {
		
		// The ID of the "state" field.
		var state_id = 'field_select_'+container_id+'_'+tab_id+'_state';
		
		// Makes sure the "state" field exists before doing anything.
		if($(state_id)) {
		
			// The Ajax.
			new Ajax.Request(engineURL, { method:'get',
				parameters:{ control:'container2', action:'get_states', country:country },
			onComplete:function(transport) {
				
				// Converts the JSON string into an object.
				var json_object = eval('('+transport.responseText+')');
				
				// Removes everything but the "Select State" option.
				$(state_id).options.length = 1;
				
				// Loops through each key in json_object.
				for(key in json_object) {
					
					// If the key exists.
					if(json_object.hasOwnProperty(key)){
						
						// Adds the option to the "state" field.
						$(state_id).options[$(state_id).options.length] = new Option(json_object[key],key);
					}
				}
			}});
		}
	},
	
	////////////////////////////
	//   CHECKBOX FUNCTIONS   //
	////////////////////////////
	
	// Checks or unchecks all checkboxes within a particular element.
	check_all:function(element_id,do_check) {
		
		// Makes sure the element exists.
		if($(element_id)) {
			
			// Gets the input elements.
			var elements = $$('#'+element_id+' input');
		
			// Loops through the elements.
			for(var counter=elements.length-1; counter>=0; --counter) {
			
				// If the current element is a checkbox.
				if(elements[counter].type=='checkbox') {
					
					// If variable is undefined, reverse the check.
					if(do_check==undefined) elements[counter].checked = !elements[counter].checked;
					
					// Otherwise, do what the variable says.
					else elements[counter].checked = (do_check ? true : false);
				}
			}
		}
	},
	
	// Counts the number of checked checkbox in a specified element.
	count_checked:function(group_id,checkbox_name,id_to_update) {
		
		// The counter.
		var count = 0;
		
		// Makes sure the group exists.
		if(group_id!=undefined && $(group_id)) {
			
			// Gets the input elements.
			var elements = $$('#'+group_id+' input');
			
			// In case no checkbox name was given.
			if(checkbox_name==undefined) checkbox_name = false;
			
			// Loops through the elements.
			for(var counter=elements.length-1; counter>=0; --counter) {
			
				// The input element must be a checkbox.
				if(elements[counter].type=='checkbox') {
					
					// If we're looking for a particular checkbox name, make sure we have a match.
					if(!checkbox_name || elements[counter].name==checkbox_name) {
						
						// If the checkbox is checked, increment the counter.
						if(elements[counter].checked) count++;
					}
				}
				
			}
		}
		
		// If there's an element to update.
		if(id_to_update!=undefined && $(id_to_update)) $(id_to_update).update(count);
		
		// Returns the count.
		return count;
	},
	
	////////////////////////////
	//   REPORTING/FLAGGING   //
	////////////////////////////
	
	// Reports something.
	report:function(type,type_id) {
		Container2.show_popup('Report',0,'report',type,type_id);
	},
	
	// Reports a blog post.
	report_blog:function(post_id) {
		Container2.report('blog',post_id);
	},
	
	// Reports a feedback comment.
	report_feedback:function(comment_id) {
		Container2.report('feedback',comment_id);
	},
	
	// Reports media.
	report_media:function(media_id) {
		Container2.report('media',media_id);
	},
	
	// Reports a user.
	report_user:function(user_id) {
		Container2.report('user',user_id);
	},
	
	///////////////////////////////////
	//   SUBSCRIBING/UNSUBSCRIBING   //
	///////////////////////////////////
	
	// Subscribes.
	subscribe:function(type,type_id,subscribe) {
		
		// Makes sure the variable is defined.
		if(subscribe==undefined) subscribe = true;
		
		// Gets the action.
		var action = (subscribe ? 'subscribe' : 'unsubscribe');
		
		// The Ajax.
		new Ajax.Request('/ajax.php', { method:'post',
			parameters:{ class_name:'Subscriber', action:action, type:type, type_id:type_id, xsrf:xsrf },
		onComplete:function(transport) {
			
			// Blogs.
			if(type=='blog') {
				if(typeof(Blog2)=='object') {
					Blog2.update_subscribe_button(); // Updates the action button container.
					Blog2.update_statistics(); // Updates the statistics container.
				}
			}
		}});
	},
	
	// Unsubscribes.
	unsubscribe:function(type,type_id) {
		Container2.subscribe(type,type_id,false);
	},
	
	//////////////////////////
	//   SENDING MESSAGES   //
	//////////////////////////
	
	// Used when selecting multiple recipients.
	check_recipient_limit:function(current_count,limit) {
		var return_value = true;
		if(current_count>limit) {
			return_value = false;
			Container2.show_error('You can only send this message to <strong>'+limit+'</strong> recipients.','compose',0,false,true);
		}
		return return_value;
	},
	
	// Opens the "Send Message" container.
	send_message:function(to,subject,message,from) {
		if(from==undefined && typeof(Messages2)=='object' && Messages2.current_user!=undefined) from = Messages2.current_user;
		Container2.show_popup('Messages2',from,'compose',0,to,subject,message);
	},
	
	/////////////////////////
	//   EVENTS/CALENDAR   //
	/////////////////////////
	
	// Deletes an event.
	delete_event:function(event_id,close_popup) {
		
		// Confirm deletion.
		if(event_id!=undefined && event_id>0 && confirm('Are you sure you want to delete this event?')) {
			
			// Closes the pop-up, if necessary.
			if(close_popup!=undefined && close_popup) Container2.close_popup();
			
			// The Ajax.
			new Ajax.Request('/ajax.php', { method:'post',
				parameters:{ class_name:'Events2', action:'delete', event_id:event_id, xsrf:xsrf },
			onComplete:function(transport) {
				
				// Response text will be the number of events deleted. Should be exactly 1.
				if(transport.responseText=='1') {
					
					// Refreshes all containers that show events.
					Container2.refresh_events_containers();
				}
			}});
		}
	},
	
	// Refreshes all containers that show events.
	refresh_events_containers:function() {
		
		// If there's a calendar on the page.
		if($('calendar')) {
		
			// Gets the month and year.
			var prefix = 'field_hidden_calendar_0_';
			var month = ($(prefix+'month') ? $(prefix+'month').value : 0);
			var year = ($(prefix+'year') ? $(prefix+'year').value : 0);
		
			// Refreshes the calendar.
			Container2.refresh_container('Events2',0,'calendar',month,year);
		}
		
		// Refreshes the events container on the EPK.
		Container2.refresh_container('EPK2','edit','events');
	},
	
	//////////////////////////
	//   OTHER CONTAINERS   //
	//////////////////////////
	
	// Deletes a comment from a feedback container.
	delete_feedback:function(comment_id,type,id,page) {
		
		// Makes sure we have all the necessary variables.
		if(comment_id!=undefined && type!=undefined && id!=undefined && confirm('Are you sure you want to delete this comment?')) {
			
			// The Ajax.
			new Ajax.Request('/ajax.php', { method:'post',
				parameters:{ class_name:'Feedback2', action:'delete_comment', comment_id:comment_id, xsrf:xsrf },
			onComplete:function(transport) {
				
				// By default, go to page 1.
				if(page==undefined) page = 1;
			
				// Refreshes the feedback container.
				Container2.refresh_container_pagination('feedback_'+id);
			}});
		}
	},

	// Edits settings.
	edit_settings:function(tab_name,user_id) {
		Container2.show_popup('Settings2',user_id,'settings',tab_name);
	},
	
	// Loads the invite container.
	invite:function(type,type_id) {
		Container2.show_popup('Invite2',0,'start',type,type_id);	
	},
	
	// Allows admins to send mail.
	send_mail:function(vars) {
		
		// Makes sure vars is not undefined.
		if(vars!=undefined) {
			
			// Shows an alert message.
			Container2.show_alert('Your message is currently being sent to the specified users. This might take a little while, depending on the number of recipients.','Sending...');
			
			// Opens a pop-up window.
			window.open('http://beta.lafango.com/admin/mailpopup','name','height=400,width=600');
			
			// The Ajax.
			new Ajax.Request('/ajax.php', { method:'post',
				parameters:{ class_name:'Mailer2', action:'send_mail', vars:vars, xsrf:xsrf },
			onComplete:function(transport) {
				// no need to do anything in here...
			}});
		}
	},
	
	// Shows an alert pop-up container.
	show_alert:function(message,title,button) {
		Container.show_alert(message,title,button);
	}
};