var engineURL = '/ajax.php';

var Container = {
	
	///////////////////////////////////
	//   CUSTOMIZE POP-UP BEHAVIOR   //
	///////////////////////////////////
	
	// Checks for errors in the pop-up form. Post-submit MUST precede pre-submit. For pre-load errors, see show_popup() function.
	popup_errors:function(response,container_id,tab_id) {
		
		// Variables.
		var popup_id = Container.get_popup_id(container_id);
		var content_id = Container.get_content_id(container_id,tab_id);
		var error_message = false;
		var focus_field = false;
		
		// The "Create New Blog Entry" and "Edit Blog Entry" containers.
		if(popup_id=='blog_post') {
			
			// Just a variable to avoid rewriting the same code.
			var action = false;
			
			// Post-submit
			if(response=='notext') action = 'text';
			else if(response=='notitle') action = 'title';
			
			// Pre-submit
			else if(Container.lacks_value(content_id+'_text')) action = 'text';
			else if(Container.lacks_value(content_id+'_title')) action = 'title';
			
			// Responses to the action.
			if(action=='text') {
				error_message = 'You must type something in order to post to your blog.';
				focus_field = 'text';
			}
			else if(action=='title') {
				error_message = 'You must give your blog entry a title.';
				focus_field = 'title';
			}
		}
		
		// The "Contact Us" container.
		else if(popup_id=='contact_us') {
			
			// Pre-submit
			if(Container.lacks_value(content_id+'_message')) {
				error_message = 'You did not enter any text in the message body.';
				focus_field = 'message';
			}
			else if(!$(content_id+'_user_id')) {
				
				// Holds a list of missing fields.
				var missing = new Array();
			
				if(Container.lacks_value(content_id+'_name')) {
					if(!focus_field) focus_field = 'name';
					missing[missing.length] = 'name'
				}
				if(Container.lacks_value(content_id+'_email')) {
					if(!focus_field) focus_field = 'email';
					missing[missing.length] = 'email address'
				}
				if(missing.length==0) {
					if($(content_id+'_email') && $(content_id+'_email').value!='' && !Shortcut.is_valid_email($(content_id+'_email').value)) {
						error_message = 'The email address you entered is invalid.';
						focus_field = 'email';
					}
				}
				else error_message = 'You must provide your '+missing.join(' and ')+'.';
			}
		}
		
		// The "Add New Contest" and "Edit Contest" containers.
		else if(popup_id=='contests_admin') {
			if(response=='admin') error_message = 'You must be an admin to do that.';
		}
		
		// The "Edit EPK ???" containers.
		else if(popup_id.substr(0,4)) {
			
			// The heading is always required
			if(Container.lacks_value(content_id+'_heading')) {
				if(popup_id=='epk_awards') error_message = 'You must provide the name of the award.';
				else if(popup_id=='epk_links') error_message = 'You must provide a website title.';
				else error_message = 'You must provide a heading.';
				focus_field = 'heading';	
			}
			else if(popup_id=='epk_information' && $(content_id+'_email').value!='' && !Shortcut.is_valid_email($(content_id+'_email').value)) {
				error_message = 'The email address you entered is invalid.';
				focus_field = 'email';
			}
		}
		
		// The "Event Editor" container.
		else if(popup_id=='event_editor') {
		
			// The "Attendees" tab and "Message" textarea.
			if(tab_id=='attendees' && Container.lacks_value(content_id+'_message')) response = 'blank';
			
			// If the textarea is blank, an error should show.
			if(response=='blank') {
				error_message = 'You must provide a message to send.';
				focus_field = 'message';
			}
		}
		
		// The "Edit Feedback" and "Leave Feedback" containers.
		else if(popup_id=='feedback_edit' || popup_id=='feedback_leave') {
			
			// Post-submit
			if(response=='blank' || response=='noname' || response=='noemail' || response=='nonameemail') {}

			// Pre-submit
			else if(response=='') {
				if(Container.lacks_value(content_id+'_text')) response = 'blank';
				else if($(content_id+'_nouser_name') && $(content_id+'_nouser_email')) {
					
					var combination = 0;
					
					if(Container.lacks_value(content_id+'_nouser_name')) combination += 1;
					if(!Shortcut.is_valid_email($(content_id+'_nouser_email').value)) combination += 2;
					
					if(combination==1) response = 'noname';
					else if(combination==2) response = 'noemail';
					else if(combination==3) response = 'nonameemail';
				}
			}
			
			// Post-submit and Pre-submit
			if(response=='blank') {
				error_message = 'You did not provide any feedback.';
				focus_field = ('text');
			}
			else if(response=='noname') {
				error_message = 'You must provide your name.';
				focus_field = 'nouser_name';
			}
			else if(response=='noemail') {
				error_message = 'You must provide a valid email address.';
				focus_field = 'nouser_email';
			}
			else if(response=='nonameemail') {
				error_message = 'You must provide your name and a valid email address.';
				focus_field = 'nouser_name';
			}
			else if(response=='frozen') error_message = 'Feedback is disabled at this time.';
		}
		
		// The "Add to Friends" and "Delete Friend" containers.
		else if(popup_id=='friend_add' || popup_id=='friend_remove') {
			
			// Post-submit
			if(response=='baduser') {
				error_message = 'This user does not exist.';
			}
		}
		
		// The "Invite Your Friends" container.
		else if(popup_id=='invite') {
			
			// Waiting message.
			Container.show_info('If you have a lot of contacts, this may take a moment. Please wait...',container_id,tab_id);
			
			// Post-submit
			if(response=='provider') {
				error_message = 'Sorry, but we don\'t yet support your email provider.';
				focus_field = 'email';
			}
			else if(response=='bademail') {
				error_message = 'The email address you entered is not valid.';
				focus_field = 'email';
			}
			else if(response=='internal') error_message = 'There was an internal error. Please try again later.';
			else if(response=='loginfail') {
				error_message = 'Could not login. Please check for typos or try again later.';
				focus_field = 'email';
			}
			else if(response=='contacts') error_message = 'We couldn\'t get your contacts. Please try again.';
			else if(response=='allinvited') {
				error_message = 'All of your contacts have already been invited. Try a different email address.';
				$(content_id+'_email').value = '';
				$(content_id+'_pw').value = '';
				focus_field = 'email';
			}
		 	
			// Pre-submit
			if(response=='') {
				if(Container.lacks_value(content_id+'_email')) {
					error_message = 'You must provide an email address.';
					focus_field = 'email';
				}
				else if(Container.lacks_value(content_id+'_pw')) {
					error_message = 'You must provide a password.';
					focus_field = 'pw';
				}
			}
		}
		
		// The "Login" container.
		else if(popup_id=='login') {
			
			// The "Login" tab.
			if(tab_id=='login') {
				
				// Post-submit
				if(response=='already') error_message = 'You are already signed-in.';
				else if(response=='deleted') error_message = 'Your account was disabled.';
				else if(response=='reset') error_message = 'You must reset your password.';
				else if(response=='nouser') {
					error_message = 'The user does not exist.';
					focus_field = 'username';
				}
				else if(response=='badpw') {
					error_message = 'The password is incorrect.';
					focus_field = 'password';
				}
				
				// Pre-submit
				else if(Container.lacks_value(content_id+'_username')) {
					error_message = 'You must enter a username.';
					focus_field = 'username';
				}
				else if(Container.lacks_value(content_id+'_password')) {
					error_message = 'You must enter a password.';
					focus_field = 'password';
				}
			}
			
			// The "Forgot Password?" tab.
			else if(tab_id=='forgot_password') {
				
				// Post-submit
				if(response=='noreg') error_message = 'This user is not registered.';
				else if(response=='disabled') error_message = 'Your account was disabled.';
				
				// Pre-submit
				else if(Container.lacks_value(content_id+'_email')) {
					error_message = 'You must enter a valid email address.';
					focus_field = 'resetpw';
				}
				else if(!Shortcut.is_valid_email($(content_id+'_email').value)) {
					error_message = 'You must enter a valid email address.';
					focus_field = 'email';
				}
			}
		}
			
		// The "Report a Bug" container.
		else if(popup_id=='report_bug') {
			
			// Pre-submit
			if(Container.lacks_value(content_id+'_message')) {
				error_message = 'Please describe the bug you\'ve been experiencing.';
				focus_field = 'message';
			}
			else if($(content_id+'_email') && $(content_id+'_email').value!='' && !Shortcut.is_valid_email($(content_id+'_email').value)) {
				if($(container_id+'_0').style.display=='none') Container.toggle_toggle(container_id+'_0');
				error_message = 'The email address is invalid.';
				focus_field = 'email';
			}
		}
		
		// The"Send a Message" containers.
		else if(popup_id=='message_reply' || popup_id=='message_send') {
			
			// Post-submit and Pre-submit
			if(response=='blank' || (response=='' && Container.lacks_value(content_id+'_message'))) {
				error_message = 'You did not enter any text in the message body.';
				focus_field = ('message');
			}
		}
		
		// The "Settings" container.
		else if(popup_id=='settings') {
			
			// Holds a list of missing fields.
			var missing = new Array();
			
			// Post-submit
			if(response=='missing') error_message = 'You did not complete the form. Please try again.';
			else if(response=='member_delete') error_message = 'Cannot delete member. All groups must have at least one member.';
			
			// The "Group" and "Personal" tabs.
			if(tab_id=='group' || tab_id=='personal') {
				
				if(tab_id=='group') {
					if(Container.lacks_value(content_id+'_fullname')) {
						missing[missing.length] = 'Group Name';
						if(!focus_field) focus_field = 'fullname';
					}
				}
				else {
					if(Container.lacks_value(content_id+'_firstname')) {
						missing[missing.length] = 'First Name';
						if(!focus_field) focus_field = 'firstname';
					}
					if(Container.lacks_value(content_id+'_lastname')) {
						missing[missing.length] = 'Last Name';
						if(!focus_field) focus_field = 'lastname';
					}
				}
				if($(content_id+'_country').value=='-') {
					missing[missing.length] = 'Country';
					if(!focus_field) focus_field = 'country';
				}
				var birthday_missing_text = (tab_id=='group' ? 'Founded' : 'Birthday');
				if(isNaN($(content_id+'_month').value)) {
					missing[missing.length] = birthday_missing_text;
					if(!focus_field) focus_field = 'month';
				}
				else if(isNaN($(content_id+'_date').value)) {
					missing[missing.length] = birthday_missing_text;
					if(!focus_field) focus_field = 'date';
				}
				else if(isNaN($(content_id+'_year').value)) {
					missing[missing.length] = birthday_missing_text;
					if(!focus_field) focus_field = 'year';
				}
			}
			
			// The "Contact" tab.
			else if(tab_id=='contact') {
				
				// Assumes an error.
				focus_field = 'email';
				
				// Possible error messages.
				var email_none = 'You are required to provide an email address.';
				var email_bad = 'The email address you entered is not valid.';
				
				// Post-submit
				if(response=='email_none') error_message = email_none;
				else if(response=='email_taken') error_message = 'That email address is already in use.';
				else if(response=='email_bad') error_message = email_bad;
				
				// Pre-submit
				else if(Container.lacks_value(content_id+'_email')) error_message = email_none;
				else if(!Shortcut.is_valid_email($(content_id+'_email').value)) error_message = email_bad;
				
				// All is good.
				else focus_field = false;
			}
			
			// The "Themes" tab.
			else if(tab_id=='themes') {
			
				// Post-submit
				if(response=='title_taken') error_message = 'You cannot create a new theme using an existing title. Please rename and try again.';
				else if(response=='no_title' || Container.lacks_value(content_id+'_title')) {
					error_message = 'You must give your theme a title.';
					focus_field = 'title';
				}
			}
			
			// The "Account" tab.
			else if(tab_id=='account') {
				
				// Post-submit
				if(response=='pw_current_none') {
					error_message = 'To update your password, you must provide your current password.';
					focus_field = 'password_current';
				}
				else if(response=='pw_current_wrong') {
					error_message = 'Unable to update password because the current password is incorrect.';
					focus_field = 'password_current';
				}
				else if(response=='pw_new_short') {
					error_message = 'Your new password must be at least 6 characters long.';
					focus_field = 'password_new';
				}
				else if(response=='pw_no_match') {
					error_message = '"Confirm Password" must match "New Password".';
					focus_field = 'password_confirm';
				}
			}
			
			// If fields are missing, show an error message.
			if(missing.length>0) error_message = 'The following field'+(missing.length==1 ? ' is' : 's are')+' required: '+missing.join(', ');
		}
		
		// Focuses on a form element.
		if(focus_field) Container.focus_and_select(content_id+'_'+focus_field);
		
		// Returns the error message (or false if there is none).
		return error_message;
	},

	// Code to be executed when the pop-up loads.
	popup_onload:function(popup_id) {
		
		// The "Alert" container focuses on the button.
		if(popup_id=='alert') Container.focus_and_select('popup_alert_button');

		// The "Create New Blog Entry" container.
		else if(popup_id=='blog_post' && Container.lacks_value('popup_blog_post_edit_text')) Container.focus_and_select('popup_blog_post_edit_text');

		// The "Cancel Account" container focuses on the "Reason" textarea.
		else if(popup_id=='cancel_account') Container.focus_and_select('popup_cancel_account_reason');

		// The "Contact Us" container focuses on the "Message" textarea.
		else if(popup_id=='contact_us') Container.focus_and_select('popup_contact_us_message');
		
		// The "Leave Feedback" container focuses on the "Text" textarea.
		else if(popup_id=='feedback_leave') Container.focus_and_select('popup_'+popup_id+'_text');

		// The "Invite Your Friends" container.
		else if(popup_id=='invite') {
			
			// If the "Email" field is blank, focuses there.
			if(Container.lacks_value('popup_invite_email')) Container.focus_and_select('popup_invite_email');
			
			// If the "Email" field is filled, focuses on the "Password" field.
			else Container.focus_and_select('popup_invite_pw');
		}

		// The "Login" container.
		else if(popup_id=='login') {
			
			// Will be true if there are tabs.
			var tabs_exist = (!$('popup_login_email'));
			
			// For the "Forgot Password?" tab, focuses on the "Email Address" field.
			if(!tabs_exist || $('content_popup_login_login').style.display=='none') {
				Container.focus_and_select('popup_login_'+(tabs_exist ? 'forgot_password_' : '')+'email');
			}
			
			// For the "Login" tab, focuses on the "Username" field.
			else Container.focus_and_select('popup_login_login_username');
		}

		// The "Send a Message" containers focus on the "Message" textarea.
		else if(popup_id=='message_reply' || popup_id=='message_send') Container.focus_and_select('popup_'+popup_id+'_message');

		// The "Flag Blog Entry", "Report a Bug", "Flag Media", and "Report User" containers focus on the textarea.
		else if(popup_id.substr(0,7)=='report_') Container.focus_and_select('popup_'+popup_id+'_message');
		
		// Manager loader
		else if(popup_id=='manager') {
			JS.open('backstage');
			CSS.open('manager');
			Backstage.manager_call();
		}
		
		else if(popup_id=='upload') {
			JS.open('upload');
			CSS.open('upload');
		}
	},
	
	// Code to determine if pressing the cancel button should close the pop-up.
	popup_onclose:function(container_id,tab_id) {
		
		// Variables.
		var popup_id = Container.get_popup_id(container_id);
		var content_id = Container.get_content_id(container_id,tab_id);
		var close_popup = false;
		
		// The "Edit Feedback" container.
		if(popup_id=='feedback_edit') {

			// Will close if there are no changes or if the user confirms close anyway.
			if($(content_id+'_text').value==$(content_id+'_initial_value').value || confirm('Discard changes?')) close_popup = true;
		}
		
		// The "Leave Feedback" and "Send a Message" containers.
		else if(popup_id=='feedback_leave' || popup_id=='message_reply' || popup_id=='message_send') {
			
			// Will close only if there's no message to be lost or if the user confirms that the message is to be discarded.
			if(Container.lacks_value(content_id+(popup_id=='feedback_leave' ? '_text' : '_message')) || confirm('Discard '+(popup_id=='feedback_leave' ? 'comments' : 'message')+'?')) close_popup = true;
		}
		
		// Will close if there is no unsaved forms or if the user confirms close anyway.
		else if(!Container.any_unsaved_settings(popup_id) || confirm('Some of your changes have not been saved.\nAre you sure you want to close?')) close_popup = true;

		// For all other containers, allows the pop-up to close.
		else close_popup = true;
		
		// If closing was confirmed, certain actions need to be performed for certain containers.
		if(close_popup) {
			if(popup_id=='settings') {
				JS.close('themes');
				JS.close('jscolor/jscolor');
			}
			else if(popup_id=='manager') {
				CSS.close('manager');
				Backstage.folder_id=0;
				Sortable.destroy('folder_list');
				Sortable.destroy('media_files');
				$('popups').update('');
			}
			
			else if(popup_id=='upload') {
				JS.close('upload');
				CSS.close('upload');
			}
		}
		
		// Returns true if the pop-up is allowed to close.
		return close_popup;
	},
	
	// What to do after the pop-up form was submitted.
	popup_submit:function(response,container_id,tab_id,preview) {
		
		// Variables.
		var popup_id = Container.get_popup_id(container_id);
		var content_id = Container.get_content_id(container_id,tab_id);
		
		// Was this submission a preview?
		preview = (preview==undefined || !preview ? false : true);
		
		// If there was no submission error.
		if(!Container.get_popup_error(response,container_id,tab_id)) {
			
			// To have gotten to this point, response must be "success". So remove those first 7 letters.
			response = response.substr(7);
			
			if(popup_id=='alert') {
				Container.close_popup(container_id,tab_id,true);
			}
			else if(popup_id=='blog_post') {
				Container.close_popup(container_id,tab_id,true);
				if(window.location=domainROOT+'/backstage') { window.location=window.location; }
				Container.refresh_blog_viewer(); // The Blogs container on a user's MyStage.
				if(Blog && $('blog_entry_'+response)) Blog.refresh_entry(response);
			}
			else if(popup_id=='blog_roll_edit') {
				Blog.update_roll();
				$('popup_blog_roll_edit_0').update(response);
				$('content_popup_blog_roll_edit').reset();
				Container.toggle_hint(content_id+'_link',true);
			}
			else if(popup_id=='bulletin') {
				Container.refresh_container('bulletin');
			}
			else if(popup_id=='cancel_account') {
				window.location=domainROOT+'/logout';
			}
			else if(popup_id=='confirm') {
				Container.close_popup(container_id,tab_id,true);
			}
			else if(popup_id=='contact_us') {
				Container.show_alert('Thank you for your inquiry. We will respond as soon as possible.','Thank You!');
				// Lines below are in case container is not a pop-up.
				if($('content_'+content_id)) {
					$('content_'+content_id).reset();
					Container.toggle_hint(content_id+'_category_of_inquiry',true);
					Container.toggle_hint(content_id+'_message',true);
					if($('contact_us_recaptcha')) Recaptcha.reload();
					if($('info_contact_us')) $('info_contact_us').hide();
				}
			}
			else if(popup_id=='contests_admin') {
				Container.refresh_container('contest_info',Contests.contest_id);
				Container.refresh_container('browse_contests');
				Container.refresh_container('contests_rules',Contests.contest_id);
				Container.close_popup(container_id,tab_id,true);
			}
			else if(popup_id=='contests_submit') {
				if(response=='') {
					Container.close_popup(container_id,tab_id,true);
					Container.refresh_container('contests_submissions_'+Contests.contest_id);
				}
				else Container.show_popup('contests_submit',response,'agree');
			}
			else if(popup_id.substr(0,4)=='epk_') {
				Container.mark_changes(container_id,false);
				EPK.show_saved_message(response);
			}
			else if(popup_id=='event_details') {
				if(response.substr(0,5)=='login') {
					Container.task = "Events.show_details("+response.substr(5)+");";
					Container.show_popup('login');
				}
				else Container.close_popup(container_id,tab_id,true);
			}
			else if(popup_id=='event_editor') {
				
				// The attendees tab just refreshes the form.
				if(tab_id=='attendees') {
					Container.show_info('Your message has been sent!',container_id,tab_id);
					$('content_'+container_id+'_'+tab_id).reset();
					Container.toggle_hint(content_id+'_message',true);
				}
				
				// Other tabs will close the container.
				else {
					Events.refresh_calendar();
					if(tab_id=='cancel_event') Container.show_alert('You have successfully canceled the event.','Event Canceled');
					else Container.close_popup(container_id,tab_id,true);
				}
			}
			else if(popup_id=='feedback_edit' || popup_id=='feedback_leave') {
				Container.close_popup(container_id,tab_id,true);
				Container.refresh_feedback(response);
			}
			else if(popup_id=='friend_add' || popup_id=='friend_remove') {
				Container.show_alert(response);
				
				// Link will only be refreshed for deletion. After adding a friend, the user doesn't immediately become a friend. He/she must first confirm.
				if(popup_id=='friend_remove') {
					var friend_id = 0;
					if(Container.ministage_user!=undefined) friend_id = Container.ministage_user;
					else if(Container.current_page!=undefined) friend_id = Container.current_page;
					$('friend_link_'+friend_id).update('<a href="javascript:void(0);" onclick="Container.add_friend('+friend_id+');">Add to Friends</a>');
				}
			}
			else if(popup_id=='invite') {
				if(response=='') Container.show_alert('Your invites have been sent!','Invites Sent');
				else Container.show_popup('invite',response);
			}
			else if(popup_id=='login') {
				if(tab_id=='login') {
					
					// The home page redirects to backstage on login.
					if(window.location==domainROOT+'/'||window.location.href.match(/\/(register|registered|logout)/)) { this.show_loading_popup(); window.location = '/backstage'; }
					
					// Forums or Collab Lab.
					else if(window.location.href.match(/\/(forums|collab)/)) { this.show_loading_popup(); window.location = window.location; }
					
					// For the login page, this will redirect the user by removing /login/r from the URL.
					else if(container_id.substr(0,6)!='popup_') window.location.href = window.location.href.replace('/login/r','');
					
					Container.close_popup(container_id,tab_id,true);
					Container.quick_update('control_panel'); // The control panel in the upper-right corner of the page.
					if($('login')) $('login').hide(); // This is for the in-page login container (not the pop-up).
					if($('welcome_to_talenttrove')) $('welcome_to_talenttrove').hide(); // The welcome container on the home page.
					if($('mystage_profile_buttons_visitor')) $('mystage_profile_buttons_visitor').hide(); // The controls below the user's photo on his/her MyStage when NOT logged-in.
					if($('mystage_profile_buttons_user')) $('mystage_profile_buttons_user').show(); // The controls below the user's photo on his/her MyStage when logged-in.
					if($('mystage_profile_settings')) Container.quick_update('mystage_profile_settings',false,Container.current_page);
					if($('mystage_profile_contact')) Container.quick_update('mystage_profile_contact',false,Container.current_page);
					Container.refresh_blog_viewer(); // The Blogs container on a user's MyStage.
					Container.refresh_feedback();
					Container.refresh_container('ministage_'+Container.ministage_user+'_'+Container.ministage_type);
				}
				else if(tab_id=='forgot_password') {
					Container.show_info('Please check your email for instructions.',container_id,tab_id);
				}
			}
			else if(popup_id=='message_reply' || popup_id=='message_send') {
				Container.close_popup(container_id,tab_id,true);
				if($('replied_'+response)) {
					$('replied_'+response).style.backgroundPosition = 'left';
				}
				// Lines below are in case container is not a pop-up.
				if($('content_'+content_id)) {
					$('content_'+content_id).reset();
					Container.toggle_hint(content_id+'_subject',true);
					Container.toggle_hint(content_id+'_message',true);
				}
			}
			else if(popup_id=='message_view') {
				Container.show_popup('message_reply',response);
			}
			else if(popup_id=='press_post') {
				
				// The "Sources" tab.
				if(tab_id=='sources') {
					
					// Converts the JSON string into an object.
					var json_object = eval('('+response+')');
				
					// Clears the source fields.
					Press.clear_source_fields();
				
					// Updates the select box on the "Sources" tab.
					if($('popup_press_post_sources_sources')) $('popup_press_post_sources_sources').replace(json_object.sources);
					
					// Updates the select box on the "Article" tab.
					if($('popup_press_post_article_source_id')) {
						
						// Saves the current value, so it isn't lost.
						var current_source_id = $('popup_press_post_article_source_id').value;
						
						// Updates the select box.
						$('popup_press_post_article_source_id').replace(json_object.article);
						
						// Restores the old value.
						$('popup_press_post_article_source_id').value = current_source_id;
					}
				}
				
				// The "Article" tab.
				else if(tab_id=='article') {
					
					// Refreshes the article.
					Press.change_article(response);
					
					// Closes the pop-up.
					Container.close_popup(container_id,tab_id,true);
				}
			}
			else if(popup_id=='report_blog') {
				Container.show_alert('Thank you for taking the time to flag this blog entry. We appreciate your feedback.','Thank You!');
			}
			else if(popup_id=='report_bug') {
				Container.show_alert('Thank you for taking the time to report the bug you\'ve been experiencing. We appreciate your feedback.','Thank You!');
			}
			else if(popup_id=='report_media') {
				Container.show_alert('Thank you for taking the time to flag this media. We appreciate your help.','Thank You!');
			}
			else if(popup_id=='report_user') {
				Container.show_alert('Thank you for taking the time to report this user. We appreciate your help.','Thank You!');
			}
			else if(popup_id=='settings') {
				Container.show_info('Your '+tab_id.substring(0,1).toUpperCase() + tab_id.substring(1).toLowerCase() +' Settings have been saved!',container_id,tab_id);
				Container.mark_changes('tab_'+container_id+'_'+tab_id,false);
				if(tab_id=='personal' || tab_id=='group' || tab_id=='profile') {
					if(tab_id=='group') {
						Container.update_group_members();	
					}
					Container.quick_update('control_panel'); // The control panel in the upper-right corner of the page.
					Container.quick_update('title_mystage_profile',false,Container.current_page);
					Container.quick_update('mystage_profile_status',false,Container.current_page);
					Container.quick_update('mystage_profile_settings',false,Container.current_page);
					Container.quick_update('ministage_'+Container.ministage_user+'_'+Container.ministage_type+'_0',false,Container.ministage_user);
					Container.quick_update('ministage_settings',false,Container.ministage_user,Container.ministage_type);
					Container.refresh_container('about_me_'+Container.current_page);
				}
				else if(tab_id=='contact' && $('mystage_profile_contact')) Container.quick_update('mystage_profile_contact',false,Container.current_page);
				else if(tab_id=='themes') {
					
					// Only the manager interface needs to do this stuff.
					if(Theme.is_manager) {
						Theme.update_saved_list();
						Theme.edit_theme(response);
					}
					
					// For non-managers, the theme will update.
					else Theme.change_theme(response);
					
					//	if(preview) Container.update_css(response,true);
					//	else Themes.update_editor(response,false);
				}
				else if(tab_id=='account') {
					$('popup_settings_account_password_current').value = '';
					$('popup_settings_account_password_new').value = '';
					$('popup_settings_account_password_confirm').value = '';
				}
			}
			else Container.close_popup(container_id,tab_id,true);
			
			// Re-enables the submit button, if one exists.
			Container.enable_submit(container_id,tab_id);
		}
	},
	
	////////////////////////////////////////
	//   MISCELLANEOUS POP-UP FUNCTIONS   //
	////////////////////////////////////////
	
	// Adds a user as a friend.
	add_friend:function(username,remove) {
		if(remove==undefined) remove = false;
		if(username==undefined) Container.show_alert('You must specify a username.','Error');
		else if(remove) Container.show_popup('friend_remove',username);
		else Container.show_popup('friend_add',username);
	},
	
	// Clears a flagged media from the admin page.
	clear_flag:function(flag_id) {
		
		// Makes sure the flag is set.
		if(flag_id==undefined) flag_id = 0;
		
		// The Ajax.
		new Ajax.Request(engineURL, { method:'post',
			parameters:{ control:'container', action:'clear_flag', flag_id:flag_id },
		onComplete:function(transport) {
			
			// If the user is not logged-in.
			if(transport.responseText=='login') {
				
				// Will attempt to re-set theme automatically following successful login.
				Container.task = "Container.hide_popup('popup_login');Container.clear_flag("+flag_id+");";
				
				// Shows the "Login" pop-up container.
				Container.show_popup('login');
			}
			
			// If the user is not an admin.
			else if(transport.responseText=='admin') Container.show_alert('You cannot clear this flag because you are not an admin.','Error');

			// Refreshes the container.
			else Container.refresh_container('flagged_content');
		}});
	},
	
	// Closes a pop-up container (possibly).
	close_popup:function(container_id,tab_id,did_submit) {
		
		// If variable is undefined, use false, because false, along with popup_onclose(), will close the pop-up.
		if(did_submit==undefined) did_submit = false;
		
		// "Manager" popup is here because there seems to be an error in popup_onclose()
		// that is causing the code to break before the function can return true. Once
		// we figure out what's causing this, we can probably remove the line below.
		if(container_id=='popup_manager') Container.hide_popup(container_id,tab_id);
		
		// If the closing of the pop-up container was confirmed.
		else if(did_submit || Container.popup_onclose(container_id,tab_id)) {
			var do_evaluate = (did_submit && Container.task!=undefined && Container.task);
			
			// If there's a delayed task that needs to be done (except for Alert and Confirm containers), do the task.
			if(do_evaluate && container_id!='popup_alert' && container_id!='popup_confirm') eval(Container.task);
			
			// All the pop-up HTML will disappear.
			else if(!do_evaluate) Container.hide_popup(container_id,tab_id);
			
			// If there's a delayed task that needs to be done for Alert and Confirm containers, do the task.
			else {
				Container.hide_popup(container_id,tab_id);
				eval(Container.task);
			}
			
			// Clears the task.
			if(Container.task!=undefined && Container.task) Container.task = false;
		}
	},
	
	// Shows the "Contact Us" pop-up container.
	contact_us:function(category_of_inquiry) {
		Container.show_popup('contact_us',category_of_inquiry);
	},
	
	// Shows the "Settings" pop-up container.
	edit_settings:function(tab_id) {
		Container.show_popup('settings',tab_id==undefined ? false : tab_id);
	},
	
	// Shows the "Flag Blog Entry" pop-up container.
	flag_blog:function(post_id) {
		Container.show_popup('report_blog',post_id);
	},
	
	// Shows the "Flag Media" pop-up container.
	flag_media:function(media_id) {
		Container.show_popup('report_media',media_id);
	},
	
	// Gets the ID of the content by putting the container_id and tab_id together.
	get_content_id:function(container_id,tab_id) {
		if(tab_id==undefined || !tab_id || tab_id=='false') tab_id = false;
		return container_id+(tab_id ? '_'+tab_id : '');
	},
	
	// Returns ",variable:value", for Ajax.
	get_parameter_string:function(variable,value) {
		if(value==undefined || !value) value = '';
		else {
			value = value.replace(/'/g,"\\'");
		}
		return ","+variable+":'"+value+"'";
	},
	
	// Did the submission of the pop-up form result in an error. If so, shows the error message.
	get_popup_error:function(response,container_id,tab_id) {
		
		// Assumes an error, by default.
		var return_value = true;
		
		// If there was no response, there must've been a connection problem.
		if(response==undefined || response=='') Container.show_error('There was a connection problem.',container_id,tab_id);
		
		// If CAPTCHA solution was incorrect.
		else if(response=='captcha') {
			
			// Displays the error message.
			Container.show_error('Your CAPTCHA solution is not correct. Please try again.',container_id,tab_id);
			
			// There's a bug that won't allow a CAPTCHA with a previously incorrect solution to validate. CAPTCHA must be reloaded.
			Recaptcha.reload();
			
			// Focuses on the response field.
			Container.focus_and_select('recaptcha_response_field');
		}
		
		// If there was a response of "success", indicating no error, will return false.
		else if(response.substring(0,7)=='success') {
			return_value = false;
		}
		
		// If there's an error, this handles it.
		else {
			var error_message = Container.popup_errors(response,container_id,tab_id);
			Container.show_error((error_message ? error_message : 'There was an error.'),container_id,tab_id);
		}
		
		// There's an error. Allow resubmission.
		if(return_value) Container.enable_submit(container_id,tab_id);
		
		// Returns the return value.
		return return_value;
	},
	
	// Gets the pop-up ID from a container ID by removing the "popup_" prefix.
	get_popup_id:function(container_id) {
		var return_value = '';
		if(container_id!=undefined) {
			if(container_id.substr(0,6)=='popup_') return_value = container_id.substr(6);
			else return_value = container_id;
		}
		return return_value;
	},
	
	// Closes a pop-up container (definitely).
	hide_popup:function(container_id,tab_id) {
		
		// Clears the popups <div>.
		if($(container_id) && Container.get_popup_id(container_id)!=container_id) $(container_id).hide();
		if($('popup_cover')) $('popup_cover').hide();
		
		// Re-enables the submit button in case the user refreshes the page. (for non-pop-ups)
		Container.enable_submit(container_id,tab_id);
		
		// Fixes an Opera bug. Forces redraw of screen .
		if(window.opera) document.body.style += '';
	},
	
	// Shows the "Leave Feedback" pop-up container.
	leave_feedback:function(id,type) {
		if(id==undefined) {
			if(type==undefined) var message = 'Cannot leave feedback.';
			else if(type=='media') var message = 'To leave feedback, there must be media.';
			else if(type=='mystage') var message = 'To leave feedback, there must be a recipient.';
			else var message = 'Cannot leave feedback.';
			Container.show_alert(message,'Error');
		}
		else {
			if(type==undefined) type = 'mystage';
			Container.show_popup('feedback_leave',id,type);
		}
	},
	
	// Loads the CAPTCHA.
	load_captcha:function(container_id) {
		if(container_id!=undefined && $('recaptcha_widget')) {
			Recaptcha.create('6LeBmgUAAAAAAIy74VyfjfYCWbNi7i62-e_nkKAm',container_id+'_recaptcha',{
				theme: 'custom',
				//callback: Recaptcha.focus_response_field,
				custom_theme_widget: 'recaptcha_widget'
			});
		}
	},
	
	// Removes a user as a friend.
	remove_friend:function(username) {
		Container.add_friend(username,true);
	},
	
	// Renders the pop-up.
	render_popup:function(popup_id,popup_content) {
		
		// Shows the HTML.
		$('popups').update(popup_content);
		
		// The highest point on the screen the pop-up container should appear.
		var high_point = 121;
		
		// Determines the vertical position of the pop-up. Pop-up will be vertically centered, with a minimum of 0px from the top.
		var all_scroll = (document.body.scrollTop==undefined ? 0 : document.body.scrollTop);
		var moz_scroll = (window.pageYOffset==undefined ? 0 : window.pageYOffset);
		var win_scroll = (document.documentElement.scrollTop==undefined ? 0 : document.documentElement.scrollTop);
		var scroll_amount = all_scroll;
		if(moz_scroll>scroll_amount) scroll_amount = moz_scroll;
		if(win_scroll>scroll_amount) scroll_amount = win_scroll;
		if(navigator.appName=='Opera') var new_position = high_point;
		else {
			var viewport_height = document.viewport.getHeight();
			var popup_height = $('popup_'+popup_id).getHeight();
			var new_position = (viewport_height-popup_height)/2;
			if(new_position<20) new_position = 20;
		}
		var style_top = (scroll_amount+new_position);
		if(style_top<high_point) style_top = high_point;
		if($('popup_'+popup_id)) $('popup_'+popup_id).style.top = style_top+'px';
		
		// Runs onload code specific to this pop-up.
		Container.popup_onload(popup_id);
	},
	
	// Shows the "Report a Bug" pop-up container.
	report_bug:function() {
		Container.show_popup('report_bug');
	},
	
	// Shows the "Report User" pop-up container.
	report_user:function(user_id) {
		Container.show_popup('report_user',user_id);
	},
	
	// Shows the "Send a Message" pop-up container.
	send_message:function(username,subject) {
		if(username==undefined) Container.show_alert('To send a message, there must be a recipient.','Error');
		else {
			if(subject==undefined) subject = '';
			Container.show_popup('message_send',username,subject);
		}
	},
	
	// Shows an alert pop-up container.
	show_alert:function(message,title,button) {
		if(message==undefined) message = '';
		if(title==undefined) title = '';
		if(button==undefined) button = '';
		Container.show_popup('alert',message,title,button);
	},

	// Shows a confirm pop-up container.
	show_confirm:function(task,message,title,button) {
		Container.task = (task==undefined ? false : task);
		if(message==undefined) message = '';
		if(title==undefined) title = '';
		if(button==undefined) button = '';
		Container.show_popup('confirm',message,title,button);
	},

	// Shows the "Loading" pop-up.
	show_loading_popup:function() {
		
		// The HTML for the pop-up.
		var popup_html = '';
		popup_html += '<div id="popup_cover"></div>';
		popup_html += '<article class="container important" id="popup_loading" style="width:200px;">';
		popup_html += '<header>';
		popup_html += '<h2 id="title_loading">Loading</h2>';
		popup_html += '<p id="header_feedback_mystage_21163">';
		popup_html += '<a rel="nofollow" onclick="Container.report_bug();" href="javascript:void(0);">Report Bug</a>';
		popup_html += '</p>';
		popup_html += '<a rel="nofollow" onclick="return Container.close_popup(\'popup_loading\',false,false);" href="javascript:void(0);" title="Close"></a>';
		popup_html += '</header>';
		popup_html += '<div id="content_loading" class="content">';
		popup_html += '<p style="border-bottom:none;text-align:center;">';
		popup_html += '<img style="border:0;" alt="Loading..." src="http://cdn.talenttrove.net/images/throbber_bar.gif" /><br />';
		popup_html += 'Please wait...';
		popup_html += '</p>';
		popup_html += '</div>';
		popup_html += '</article>';
		
		// Renders the pop-up.
		Container.render_popup('loading',popup_html);
	},
	
	// Shows a pop-up container with a specific ID.
	show_popup:function(popup_id,var1,var2,var3) {
		
		// If there's no pop-up ID specified, nothing will happen.
		if(popup_id!=undefined) {
			
			// Shows the "Loading" container.
			Container.show_loading_popup();
			
			// Makes sure the variables aren't undefined before going into the Ajax.
			if(var1==undefined) var1 = '';
			if(var2==undefined) var2 = '';
			if(var3==undefined) var3 = '';
			
			// The Ajax.
			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'container', action:'show_popup', popup_id:popup_id, var1:var1, var2:var2, var3:var3 },
			onComplete:function(transport) {
				
				// Gets the response text.
				var response = transport.responseText;
				
				// The user needs to login or solve captcha.
				if(response=='login') {
					
					// Delays the current task until after the user signs in.
					Container.task = "Container.show_popup('"+popup_id+"','"+var1+"','"+var2+"','"+var3+"');";
					
					// Shows the login pop-up container.
					Container.show_popup(response);
				}
				
				// This is for disabled feedback.
				else if(response=='frozen') Container.show_alert('Feedback is disabled at this time.','Error');
				
				// If the user tries to load a pop-up container that is not a predefined pop-up.
				else if(response=='nopopup') Container.show_alert('The "'+popup_id+'" container is not a valid pop-up container.','Error');
				
				// If a user does not exist. (Assumes var1 is a username.)
				else if(response=='nouser') Container.show_alert('The user "'+var1+'" does not exist.','Error');
				
				// If the user is trying to do something to himself/herself that he/she is not allowed to do.
				else if(response=='self') {

					if(popup_id=='blog_subscribe') Container.show_alert('You cannot subscribe to your own blog.','Error');
					else if(popup_id=='feedback_leave') Container.show_alert('You cannot leave feedback for yourself.','Error');
					else if(popup_id=='friend_add') Container.show_alert('You cannot add yourself as a friend.','Error');
					else if(popup_id=='message_send') Container.show_alert('You cannot send a message to yourself.','Error');
					else Container.show_alert('You cannot perform that action on yourself.','Error');
				}
				
				// The "Submit Content" container for the contests.
				else if(popup_id=='contests_submit' && (response=='no_contest' || response=='pre_submit' || response=='post_submit')) {
					if(response=='no_contest') Container.show_alert('This contest does not exist.','Error');
					else if(response=='pre_submit') Container.show_alert('This contest is not accepting content yet.','Error');
					else if(response=='post_submit') Container.show_alert('The submission period for this contest is over.','Error');
				}
				
				// The "Add to Friends" and "Delete Friend" containers.
				else if((popup_id=='friend_add' && response.substring(0,7)=='already') || (popup_id=='friend_remove' && response.substring(0,9)=='notfriend')) {
					
					//if(response.substring(0,7)=='already') Container.show_alert('You are already friends with '+response.substr(7)+'.','Error');
					//else if(response.substring(0,9)=='notfriend') Container.show_alert(response.substr(9)+' is not on your list of friends.','Error');
				}
				
				// Updates the "Subscribe" and "Unsubscribe" links for blogs.
				else if(popup_id=='blog_subscribe') {
					var is_subscribed = (response.substring(7,8)=='1');
					var blogger_username = response.substring(8);
					if($('blog_subscribe_link')) {
						$('blog_subscribe_link').replace('<a href="javascript:void(0);" onclick="Blog.'+(is_subscribed ? 'un' : '')+'subscribe(\''+blogger_username+'\');" id="blog_subscribe_link" rel="nofollow" style="font-weight:bold;">'+(is_subscribed ? 'Unsubscribe' : 'Subscribe')+'</a>');
					}
				}
				
				// If HTML was returned, render the pop-up.
				else Container.render_popup(popup_id,response);
			}});
		}
	},
	
	// Submits the pop-up form.
	submit_popup:function(container_id,tab_id,preview) {
		
		// Gets the pop-up ID.
		var popup_id = Container.get_popup_id(container_id);
		
		// Gets the content ID.
		var content_id = Container.get_content_id(container_id,tab_id);
		
		// Makes sure preview is either true or false.
		preview = (preview==undefined || !preview ? false : true);
		
		// Disables the submit button to prohibit multiple submissions.
		if(!preview) Container.disable_submit(container_id,tab_id);
		
		// Generic parameters.
		var parameters = "control:'container'";
		parameters += Container.get_parameter_string('action','submit_form');
		parameters += Container.get_parameter_string('popup_id',popup_id);
		parameters += Container.get_parameter_string('tab_id',tab_id);
		
		// "preview" was previously being used for themes. It is currently not being used.
		//parameters += Container.get_parameter_string('preview',preview ? '1' : '0');

		// An array of form tags.
		var tags = new Array('input','select','textarea');
		
		// Loops through the tags.
		for(var tag_counter=tags.length-1; tag_counter>=0; --tag_counter) {
			
			// Gets the form elements.
			var elements = $('content_'+content_id).getElementsByTagName(tags[tag_counter]);
			
			// Loops through the form elements, and adds them to the parameters.
			for(var counter=elements.length-1; counter>=0; --counter) {
				if(elements[counter].id) {
					var param_name = false;
					var param_value = false;
					if(elements[counter].type=='radio') {
						if(elements[counter].checked) {
							param_name = elements[counter].name;
							param_value = elements[counter].value;
						}
					}
					else {
						param_name = elements[counter].id;
						if(elements[counter].type=='checkbox') {
							param_value = (elements[counter].checked ? elements[counter].value : 'false');
							if(param_value=='') param_value = 'true';
						}
						else {
							param_value = (Container.lacks_value(elements[counter].id,false) ? '' : elements[counter].value);
							param_value = param_value.replace(/[\n\r]/g,'\\n');
						}
					}
					if(param_name) {
						if(param_name.indexOf(content_id+'_')==0) param_name = param_name.substring(content_id.length+1);
						if(param_name!='submit') parameters += Container.get_parameter_string(param_name,param_value);
					}
				}
			}
		}
		// The submission.
		eval("new Ajax.Request(engineURL,{method:'post',parameters:{"+parameters+"},onComplete:function(transport) {Container.popup_submit(transport.responseText,'"+container_id+"','"+tab_id+"',"+(preview ? 'true' : 'false')+");}});");
	},
	
	// Form validation.
	validate_form:function(container_id,tab_id,preview) {
		
		// Initial validation. Returns an error message or false.
		var error_message = Container.popup_errors(false,container_id,tab_id);
		
		// Based on validation success, either shows the error message or submits the form
		if(error_message) Container.show_error(error_message,container_id,tab_id);
		else if(Container.validate_form_custom(container_id,tab_id)) Container.submit_popup(container_id,tab_id,preview);
		
		// Returns false.
		return false;
	},
	
	// For containers that require confirmation on submit.
	validate_form_custom:function(container_id,tab_id) {
		
		// Gets the pop-up ID.
		var popup_id = Container.get_popup_id(container_id);
		
		// Will submit the form by default.
		var return_value = true;
		
		// For certain containers, not confirming will not submit the form.
		if(popup_id=='cancel_account' && !confirm('Are you sure you want to cancel your TalentTrove account?')) return_value = false;
		else if(popup_id=='event_editor' && tab_id=='cancel_event' && !confirm('Are you sure you want to cancel this event?')) return_value = false;
		
		// Returns true or false.
		return return_value;
	},
	
	/////////////////
	//   BUTTONS   //
	/////////////////
	
	// Disables a button with a specified ID.
	disable_button:function(button_id,disable) {
		if($(button_id)) {
			if(disable==undefined) disable = true;
			$(button_id).disabled = disable;
			if(disable) $(button_id).addClassName('disabled');
			else $(button_id).removeClassName('disabled');
		}
	},
	
	// Enables a button with a specified ID.
	enable_button:function(button_id) {
		Container.disable_button(button_id,false);
	},
	
	// Disables a container's default submit button.
	disable_submit:function(container_id,tab_id,disable) {
		if($(container_id+'_'+tab_id+'_submit')) {
			Container.disable_button(container_id+'_'+tab_id+'_submit',disable);
		}
		else if($(container_id+'_submit')) {
			Container.disable_button(container_id+'_submit',disable);
		}
	},
	
	// Enables a container's default submit button.
	enable_submit:function(container_id,tab_id) {
		Container.disable_submit(container_id,tab_id,false);
	},
	
	////////////////////
	//   PAGINATION   //
	////////////////////
	
	pagination_index:new Array(),
	pagination_class_files:new Array(),
	pagination_class_names:new Array(),
	pagination_page_number:new Array(),
	pagination_total_pages:new Array(),
	pagination_label:new Array(),
	pagination_links:new Array(),
	pagination_scripts:new Array(),
	
	// Gets the index value of a pagination container.
	pagination_get_index:function(container_id) {
		
		// Will return -1 by default.
		var index_value = -1;
		
		// The container ID must be specified.
		if(container_id!=undefined) {
			
			// Loops through the array of pagination indexes.
			for(var counter=Container.pagination_index.length-1; counter>=0; --counter) {
			
				// If there's a match.
				if(Container.pagination_index[counter]==container_id) index_value = counter;
			}
		}
		
		// Returns the index value.
		return index_value;
	},
	
	// Changes the page. The page_change parameter represents the difference as a positive or negative integer.
	pagination:function(container_id,page_change) {

		// Makes sure the container and pagination exists.
		if($(container_id)) {
			
			// Gets some variables.
			var is_bound = Container.pagination_links[Container.pagination_get_index(container_id)]>0;
			var page_number = Container.pagination_page_number[Container.pagination_get_index(container_id)] + page_change;
			var total_pages = Container.pagination_total_pages[Container.pagination_get_index(container_id)];
			
			// If bound, keeps pagination from going from first-to-last or last-to-first.
			if(!(is_bound && (page_number<1 || page_number>total_pages))) {
	
			
				// If page is not bound, will cause pagination to loop.
				if(page_number<1) page_number = total_pages;
				else if(page_number>total_pages) page_number = 1;
	
				// Displays a temporary "Please wait..." message.
				if($('pagination_navigation_'+container_id)) {
					var pagination_navigation = $('pagination_navigation_'+container_id).innerHTML;
					$('pagination_navigation_'+container_id).update('Please wait...');
				}
	
				// The Ajax.
				new Ajax.Request(engineURL, { method:'post',
					parameters:{ control:'container', action:'pagination', container_id:container_id, page_number:page_number, class_file:Container.pagination_class_files[Container.pagination_get_index(container_id)], class_name:Container.pagination_class_names[Container.pagination_get_index(container_id)] },
				onComplete:function(transport) {
				
					// Updates the variable and display.
					Container.pagination_page_number[Container.pagination_get_index(container_id)] = page_number;
					$('pagination_'+container_id).update(transport.responseText);
					if($('pagination_display_'+container_id)) $('pagination_display_'+container_id).update(Container.pagination_label[Container.pagination_get_index(container_id)]+' '+page_number+' of '+total_pages);
					
					// Removes the "Please wait..." message and goes back to the navigation.
					if($('pagination_navigation_'+container_id)) $('pagination_navigation_'+container_id).update(pagination_navigation);
		
					// Update for the press page.
					if(Container.press_id!=undefined) Container.press_highlight(Container.press_id,true);;
		
					// Stuff that only needs to be done if the pagination is bound.
					if(is_bound) {
						Container.pagination_disable(container_id,'prev',page_number,1);
						Container.pagination_disable(container_id,'next',page_number,total_pages);
						Container.pagination_update_links(container_id);
					}
					
					// The responseText should never be empty with pagination.
					if(transport.responseText=='') {
						
						// Shows an error message.
						Container.show_error('Pagination Error',container_id);
						
						// Maybe do some automatic error reporting here...
					}
					else if(Container.pagination_scripts[Container.pagination_get_index(container_id)]) eval(Container.pagination_scripts[Container.pagination_get_index(container_id)]);
				}});
			}
		}
	},
	
	// Disables the Previous/Next arrows if the user is at the beginning/end. Enables otherwise.
	pagination_disable:function(container_id,prev_next,page_number,page_bound) {
		$('pagination_'+prev_next+'_'+container_id).addClassName(prev_next+(page_number==page_bound ? '_disabled' : ''));
		$('pagination_'+prev_next+'_'+container_id).removeClassName(prev_next+(page_number==page_bound ? '' : '_disabled'));
	},
	
	// Used in template to setup the variables.
	pagination_setup:function(container_id,class_file,class_name,page_number,total_pages,label,links,scripts) {
		
		// Gets the index of this container.
		var new_index = Container.pagination_get_index(container_id);
		
		// If no index was found, add a new one.
		if(new_index==-1) new_index = Container.pagination_index.length;
		
		Container.pagination_index[new_index] = container_id;
		Container.pagination_class_files[new_index] = class_file;
		Container.pagination_class_names[new_index] = class_name;
		Container.pagination_total_pages[new_index] = total_pages;
		Container.pagination_label[new_index] = label;
		Container.pagination_links[new_index] = links;
		Container.pagination_scripts[new_index] = scripts;
		
		// Without this "if", the pagination will temporarily stick on the second page.
		// We need to make sure the number that keeps track of the current page doesn't get overwritten.
		if(Container.pagination_page_number[new_index]==undefined) {
			Container.pagination_page_number[new_index] = page_number;
		}
	},
	
	// Updates the links to different pages (ex: "1 | 2 | 3"). Very similar to class function create_pagination_page_links().
	pagination_update_links:function(container_id) {

		// Makes sure there's a place to display the links.
		if($('pagination_links_'+container_id)) {
			
			// Gets a few variables.
			var page_number = Container.pagination_page_number[Container.pagination_get_index(container_id)];
			var total_pages = Container.pagination_total_pages[Container.pagination_get_index(container_id)];
			var link_count = Container.pagination_links[Container.pagination_get_index(container_id)];
		
			// The first (start) and last (end) link numbers.
			var is_odd = (link_count%2==1 ? 1 : 0);
			var start = page_number-((link_count-is_odd)/2)-is_odd+1;
			var end = start + link_count;
			
			// Fixes the link numbers if they are out of bounds.
			var change = 0;
			if(start<1) change = 1-start;
			else if(end>total_pages+1) change = total_pages-end+1;
			start += change;
			end += change;
			
			// Forms an array of links.
			var link_array = new Array();
			for(var counter=start; counter<end; counter++) {
				link_array.push('<a href="javascript:void(0);" onclick="Container.pagination(\''+container_id+'\','+counter+'-Container.pagination_page_number['+Container.pagination_get_index(container_id)+']);"'+(counter==page_number ? ' class="on"' : '')+'>'+counter+'</a>');
			}
			
			// Updates the page links.
			$('pagination_links_'+container_id).update(link_array.join(' | '));
		}
	},
	
	////////////////
	//   THEMES   //
	////////////////
	
	// Changes a theme dynamically.
	change_theme:function(theme_id,hide_cover) {
		if(!theme_id) theme_id = ($('popup_settings_themes_theme_id') ? $('popup_settings_themes_theme_id').value : 1);
		if(hide_cover==undefined) hide_cover = false;
		if(theme_id!=undefined) {
			new Ajax.Request(engineURL, { method:'get',
				parameters:{ control:'theme', action:'change', theme_id:theme_id },
			onComplete:function(transport) {
				Container.update_css(transport.responseText,hide_cover);
			}});
		}
	},
	
	// Sets a theme to a user's MyStage, blog, or media pages.
	set_theme:function(theme_id,set_where) {
		
		// Determines where the theme will be set (MyStage, blogs, media, or all).
		if(set_where==undefined || set_where=='all') set_where = 'all';
		else if(set_where!='mystage' && set_where!='blog' && set_where!='media') set_where = false;
		
		// Forms part of the confirm string.
		if(set_where=='mystage') var where_string = ' on your MyStage';
		else if(set_where=='blog') var where_string = ' on your blog pages';
		else if(set_where=='media') var where_string = ' on your media pages';
		else var where_string = '';
		
		// If the variables are set and the user confirms.
		if(theme_id!=undefined && set_where && confirm('Are you sure you would like to use this theme'+where_string+'?')) {
			
			// The Ajax.
			new Ajax.Request(engineURL, { method:'get',
				parameters:{ control:'container', action:'themes_set', theme_id:theme_id, set_where:set_where },
			onComplete:function(transport) {
				
				// The user is not logged-in.
				if(transport.responseText=='login') {
					
					// Will attempt to re-set theme automatically following successful login.
					Container.task = "Container.hide_popup('popup_login');Container.set_theme("+theme_id+");";
					
					// Shows the "Login" pop-up container.
					Container.show_popup('login');
				}
				
				// The saving was successful.
				else if(transport.responseText=='success') {
				
					// Hides the container, if it exists.
					if($('themebox')) $('themebox').hide();
					
					// This is where the change_theme() function should be called, if applicable.
					// If calling this function from a themebox, change_theme() won't be called,
					// because the theme will already be set. If calling this function from
					// settings, use change_theme() only when on the user's mystage, media, or
					// blog pages, and if his/her settings allow for themes to be displayed on
					// that page.
				}
			}});
		}
	},
	
	update_css:function(new_css,hide_cover) {
		if(new_css!=undefined) {
			var ss = document.createElement('style');
			ss.setAttribute("type", "text/css");
			if(ss.styleSheet) ss.styleSheet.cssText = new_css;
			else ss.appendChild(document.createTextNode(new_css));
			var hh = document.getElementsByTagName('head')[0];
			hh.appendChild(ss);

			// Makes the pop-up cover invisible.
			if($('popup_cover') && hide_cover!=undefined && hide_cover) {
				$('popup_cover').remove();
			}
		}
	},
	
	////////////////////////////
	//   SETTINGS CONTAINER   //
	////////////////////////////
	
	// Returns true if there are any unsaved settings.
	any_unsaved_settings:function(popup_id) {
		
		// Will be set to true if there are unsaved forms in the Settings container.
		var unsaved = false;
			
		// Gets the ID of the container.
		var container_id = ($(popup_id) ? popup_id : 'popup_'+popup_id);
			
		// Makes sure the user is viewing a tabbed container.
		if($('tab_'+container_id)) {
		
			// An array of tabs.
			var tabs = new Array();
		
			// Gets all the descendants of the container.
			var descendants = $(container_id).descendants();
			
			// Loops through the descendants.
			for(var counter=descendants.length-1; counter>=0; --counter) {
				
				// If the descendant is a tab.
				if(descendants[counter].id.substr(0,4)=='tab_')	{
					
					// Adds it to the array of tabs.
					tabs[tabs.length] = descendants[counter];
				}
			}
		
			// Loops through the tabs.
			for(var counter=tabs.length-1; counter>=0; --counter) {
				var tab_text = tabs[counter].firstDescendant().innerHTML;
				if(tab_text.substr(0,2)=='* ') {
					unsaved = true;
					break;
				}
			}
		}
		
		// Uses the title instead.
		else if($('title_'+container_id)) {
		
			// The title text.
			var title_text = $('title_'+container_id).innerHTML;
		
			// Unsaved fields?
			unsaved = (title_text.substr(title_text.length-2)==' *');
		}
		
		// Returns true if there are unsaved forms.
		return unsaved;
	},
	
	// Navigates away to a URL only if all settings are saved or if the user confirms.
	leave_settings:function(destination_url) {
		if(destination_url!=undefined && (!Container.any_unsaved_settings('settings') || confirm('You are about to navigate away from this page. All unsaved settings will be lost.\nContinue anyway?'))) {
			Shortcut.goto(destination_url);
		}
	},
	
	// Adds an (*) next to a tab. Removes it if mark is false.
	mark_changes:function(element_id,mark) {
		if($(element_id) && (element_id.substr(0,4)=='tab_' || element_id.substr(0,6)=='title_')) {
			if(mark==undefined) mark = true;
			if(element_id.substr(0,4)=='tab_') {
				var current_value = $(element_id).firstDescendant().innerHTML;
				var already_marked = (current_value.substr(0,2)=='* ');
				if(mark && !already_marked) $(element_id).firstDescendant().innerHTML = '* '+current_value;
				else if(!mark && already_marked) $(element_id).firstDescendant().innerHTML = current_value.substring(2);
			}
			else {
				var current_value = $(element_id).innerHTML;
				var already_marked = (current_value.substr(current_value.length-2,2)==' *');
				if(mark && !already_marked) $(element_id).innerHTML = current_value+' *';
				else if(!mark && already_marked) $(element_id).innerHTML = current_value.substring(0,current_value.length-2);
			}
		}
		else if($('title_'+element_id.substr(4))) Container.mark_changes('title_'+element_id.substr(4),mark);
		else if($('title_'+element_id)) Container.mark_changes('title_'+element_id,mark);
	},
	
	edit_group_member:function(member_id) {
		
		// Makes sure a member ID was specified.
		if(member_id!=undefined) {
			
			// The Ajax.
			new Ajax.Request(engineURL, { method:'get',
				parameters:{ control:'settings', action:'edit_group_member', member_id:member_id },
			onComplete:function(transport) {
				
				// Converts the JSON string into an object.
				var json_object = eval('('+transport.responseText+')');
				
				// Turns off any hints.
				Container.toggle_hint('popup_settings_group_firstname',false);
				Container.toggle_hint('popup_settings_group_lastname',false);
				
				// Updates the variable that keeps track of the ID.
				$('popup_settings_group_member_id').value = (json_object.member_id==undefined ? 0 : json_object.member_id);
				
				// Updates the textboxes.
				$('popup_settings_group_firstname').value = (json_object.firstname==undefined ? '' : json_object.firstname);
				$('popup_settings_group_lastname').value = (json_object.lastname==undefined ? '' : json_object.lastname);
				
				// Shows or hides the checkbox.
				$('popup_settings_group_member_delete_label').style.display = ($('popup_settings_group_member_id').value==0 || json_object.count<2 ? 'none' : 'block');
				
				// Unchecks the checkbox.
				$('popup_settings_group_member_delete').checked = false;
				
				// Updates the instructions.
				Container.update_group_member_instructions($('popup_settings_group_member_id').value);
			}});
		}
	},
	
	update_group_member_instructions:function(member_id) {
		if($('settings_members_instructions')) {
			if(member_id>0) var instructions = 'To edit the selected member, make the desired changes below, and click the "Save" button.';
			else var instructions = 'To add a new member, just provide his or her name using the textboxes below, then click "Save".';
			$('settings_members_instructions').update(instructions);
		}
	},
	
	update_group_members:function() {
		if($('popup_settings_group_members')) {
			new Ajax.Request(engineURL, { method:'get',
				parameters:{ control:'settings', action:'update_group_members' },
			onComplete:function(transport) {
				$('popup_settings_group_members').replace(transport.responseText);
				$('popup_settings_group_member_id').value = 0;
				$('popup_settings_group_firstname').value = '';
				$('popup_settings_group_lastname').value = '';
				$('popup_settings_group_member_delete_label').style.display = 'none';
				Container.update_group_member_instructions(0);
			}});
		}
	},
		
	//////////////////
	//   FEEDBACK   //
	//////////////////
	
	// Deletes feedback.
	delete_feedback:function(feedback_id) {
		
		// Requests confirmation.
		if(confirm('Are you sure you want to delete this comment?') && feedback_id!=undefined) {

			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'container', action:'feedback_delete', feedback_id:feedback_id },
			onComplete:function(transport) {
				if(transport.responseText.substr(0,7)=='success') {
					Container.refresh_feedback(transport.responseText.substr(7));
				}
				else if(transport.responseText=='login') Container.show_alert('You must be logged-in to delete feedback.','Error');
				else if(transport.responseText=='permission') Container.show_alert('You don\'t have permission to delete this comment.','Error');
				else Container.show_alert('There was a problem deleting feedback.','Error');
			}});
		}
	},
	
	// Shows the "Edit Feedback" pop-up container.
	edit_feedback:function(feedback_id) {
		if(feedback_id==undefined) Container.show_alert('To edit feedback, you must specify which feedback to edit.','Error');
		else Container.show_popup('feedback_edit',feedback_id);
	},
	
	// Refreshes the various feedback containers.
	refresh_feedback:function(recipient_id) {
		
		// An array of all article elements.
		var articles = document.getElementsByTagName('article');
		
		// Loops through the array.
		for(var counter=articles.length-1; counter>=0; --counter) {
			
			// If this is a feedback container.
			if(articles[counter].id.substr(0,9)=='feedback_') {
				
				// If there's no specified recipient ID, or if the specified ID was found in the container's ID.
				if(recipient_id==undefined || articles[counter].id.indexOf('_'+recipient_id)!=-1) {
					
					// Refresh the container.
					Container.refresh_container(articles[counter].id);
				}
			}
		}
	},
	
	////////////////////////
	//   STATUS/TWITTER   //
	////////////////////////
	
	clear_status:function() {
		$('bulletin_new_status').clear();
		Container.update_status();
	},
	
	update_status:function(allow_blank) {
		if(allow_blank==undefined) allow_blank = false;
		if(allow_blank || !Container.lacks_value('bulletin_new_status')) Container.validate_form('bulletin',false);
		else Container.show_confirm("Container.update_status(true);",'Are you sure you want to clear your status?','Clear Status');
		return false;
	},
	
	unlink_twitter:function() {
		
		// Requests confirmation from the user.
		if(confirm('Are you sure you want to unlink your Twitter?')) {
			
			// Temporary status message.
			Container.show_info('Currently unlinking Twitter. Please wait...','bulletin');
			
			// Closes the popup.
			Container.close_popup('popup_twitter',false,false);
			
			// The Ajax.
			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'container', action:'unlink_twitter' },
			onComplete:function(transport) {
				
				Container.refresh_container('bulletin');
			}});
		}
	},
	
	//////////////////////
	//   LOADING APPS   //
	//////////////////////
	
	// Loads an app.
	load_app:function(app_id) {
		
		// Makes sure an app ID was provided.
		if(app_id!=undefined) {
			
			// The Ajax.
			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'container', action:'load_app', app_id:app_id },
			onComplete:function(transport) {
				
				if(transport.responseText && $('app_'+app_id)) {
					$('app_'+app_id).replace(transport.responseText);
				}
			}});
		}
	},
	
	///////////////////////
	//   MISCELLANEOUS   //
	///////////////////////
	
	// Keeps track of the current page.
	current_page:'',

	// Cancels a user's account.
	cancel_account:function() {
		if(!Container.any_unsaved_settings('settings') || confirm('Are you sure you want to cancel your account?')) {
			Container.show_popup('cancel_account');
		}
	},

	// Changes the selection of a given element and updates a counter.
	change_selection:function(element_id,is_selected,container_id,button_text) {
		
		// Changes the selection.
		if($(element_id)) {
			if(is_selected==undefined) is_selected = false;
			if(is_selected) $(element_id).addClassName('on');
			else $(element_id).removeClassName('on');
		}
		
		// Updates the counter and submit button text.
		if(container_id!=undefined && $(container_id)) {
			var counter_value = 0;
			var inputs = $(container_id).getElementsByTagName('input');
			for(var counter=0; counter<inputs.length; counter++) {
				if(inputs[counter].type=='checkbox' && !inputs[counter].disabled && inputs[counter].value!='' && inputs[counter].checked) {
					counter_value++;
				}
			}
			if($(container_id+'_counter')) $(container_id+'_counter').update(counter_value);
			if($(container_id+'_submit') && button_text!=undefined && button_text) {
				
				$(container_id+'_submit').value = (counter_value==0 ? 'Skip this Step' : button_text)+' \u00BB';
			}
		}
	},
	
	// Changes to a different tab.
	change_tab:function(container_id,tab_id) {
		
		// Makes sure this is a tabbed container.
		if($('content_'+container_id+'_'+tab_id)) {
			
			// Gets the siblings of the new tab.
			var elements = $('content_'+container_id+'_'+tab_id).siblings();
			
			// Loops through the siblings.
			for(var counter=elements.length-1; counter>=0; --counter) {
	
				// Gets the ID of this tab.
				var position_of_id = ('content_'+container_id+'_').length;
				var element_id = elements[counter].id.substring(position_of_id);
	
				// Hides the old tab and its content.
				$('tab_'+container_id+'_'+element_id).removeClassName('on');
				$(elements[counter].id).hide();
				$('info_'+elements[counter].id.substr(8)).hide();
			}
		
			// Shows the new tab and its content.
			$('tab_'+container_id+'_'+tab_id).className = 'on';
			$('content_'+container_id+'_'+tab_id).show();
			
			// For blog entry posting/editing, this is to update the preview.
			var popup_id = Container.get_popup_id(container_id);
			if(popup_id=='blog_post') {
				if(tab_id=='preview') {
					var fields = new Array('title','text','tags','cat_id','no_comments');
					for(var counter=fields.length-1; counter>=0; --counter) {
						if($(container_id+'_preview_'+fields[counter])) {
							var new_value = '';
							if($(container_id+'_edit_'+fields[counter]) && !Container.lacks_value(container_id+'_edit_'+fields[counter])) {
								new_value = $(container_id+'_edit_'+fields[counter]).value;
							}
							$(container_id+'_preview_'+fields[counter]).value = new_value;
						}
					}
					new Ajax.Request(engineURL, { method:'post',
						parameters:{ control:'container', action:'blog_render', title:$(container_id+'_preview_title').value, text:$(container_id+'_preview_text').value },
					onComplete:function(transport) {
						if(transport.responseText=='') $('blog_preview').update('There was an error rendering the preview. This is likely a connection error.<br />Please check your connection and try again.');
						else $('blog_preview').update(transport.responseText);
					}});
				}
				else $('blog_preview').update('Loading preview...');
			}
		}
	},
	
	// Adds or removes media from a user's favorites list.
	favorite_media:function(media_id,add_to_favorites) {
		
		// Makes sure a media ID was specified.
		if(media_id!=undefined) {
			
			// Validates the variable.
			add_to_favorites = (add_to_favorites==undefined || add_to_favorites ? 1 : 0);
			
			// The Ajax.
			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'container', action:'favorite_media', id:media_id, add:add_to_favorites },
			onComplete:function(transport) {
				
				// If the user is not logged-in.
				if(transport.responseText=='login') {
					
					// Will attempt to re-favorite automatically following successful login.
					Container.task = "Container.hide_popup('popup_login');Container.favorite_media("+media_id+");";
					
					// Shows the "Login" pop-up container.
					Container.show_popup('login');
				}
				
				// If successful.
				else if(transport.responseText.substr(0,7)=='success' && $('media_details_'+media_id)) {
					$('media_details_'+media_id).replace(transport.responseText.substr(7));
				}
			}});
		}
	},
	
	// Focuses on and selects a particular element.
	focus_and_select:function(element_id) {
		if($(element_id) && $(element_id).type!='hidden' && !$(element_id).disabled && $(element_id).offsetHeight>0) {
			$(element_id).focus();
			$(element_id).select();
		}	
	},

	// Gets the suffix for the ID of something based on the container and tab IDs.
	get_suffix:function(container_id,tab_id) {
		return container_id+(tab_id==undefined || !tab_id || tab_id=='false' ? '' : '_'+tab_id);
	},
	
	// Returns true if element lacks a value. If true, will focus on element.
	lacks_value:function(element_id,focus_and_select) {
		if(focus_and_select==undefined) focus_and_select = true;
		var return_value = false;
		if($(element_id) && ($(element_id).value=='' || $(element_id).hasClassName('hint'))) {
			if(focus_and_select) Container.focus_and_select(element_id);
			return_value = true;
		}
		return return_value;
	},

	// Used to quickly update the innerHTML of a specified element.
	quick_update:function(element_id,replace_element,var1,var2,var3) {
		if(element_id!=undefined && $(element_id)) {
			if(var1==undefined) var1 = '';
			if(var2==undefined) var2 = '';
			if(var3==undefined) var3 = '';
			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'container', action:'quick_update', element_id:element_id, var1:var1, var2:var2, var3:var3 },
			onComplete:function(transport) {
				if(transport.responseText!='') {
					if(transport.responseText==' ') $(element_id).hide();
					else $(element_id).show();
					if(replace_element!=undefined && replace_element) $(element_id).replace(transport.responseText);
					else $(element_id).update(transport.responseText);
				}
			}});
		}
	},
	
	rate_media:function(media_id,thumbs_up) {
		if(media_id!=undefined && thumbs_up!=undefined) {
			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'container', action:'rate_media', media_id:media_id, thumbs:(thumbs_up ? 1 : 0) },
			onComplete:function(transport) {
				if(transport.responseText=='login') {
					
					// Will attempt to re-rate automatically following successful login.
					Container.task = "Container.hide_popup('popup_login');Container.rate_media("+media_id+","+(thumbs_up ? 'true' : 'false')+");";
					
					// Shows the "Login" pop-up container.
					Container.show_popup('login');
				}
				else if(transport.responseText!='' && $('thumbs_'+media_id)) {
					$('thumbs_'+media_id).replace(transport.responseText);
				}
				
				// If successful.
				else if(transport.responseText.substr(0,7)=='success' && $('media_details_'+media_id)) {
					$('media_details_'+media_id).replace(transport.responseText.substr(7));
				}
			}});
		}
	},
	
	// Refreshes a container with a given ID.
	refresh_container:function(element_id,variable) {
		if(element_id!=undefined && $(element_id)) {
			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'container', action:'refresh_container', element_id:element_id, variable:variable },
			onComplete:function(transport) {
				if(transport.responseText!='') {
					$(element_id).replace(transport.responseText);
					
					// For the contest feedback container, since it has a built-in form.
					if(element_id.substr(0,18)=='feedback_contests_') {
						Container.focus_and_select('contests_feedback_message');
					}
				}
			}});
		}
	},
	
	// Refreshes the blog viewer container for a user.
	refresh_blog_viewer:function() {
		
		// The small container in the right column.
		Container.refresh_container('blog_list_'+Container.current_page);
		
		// The wide container in the middle column (removed).
		//Container.refresh_container('blog_view_'+Container.current_page);
	},
	
	// Selects all the enabled checkboxes within a container.
	select_all:function(content_id,do_check,button_text) {
		
		// Button text when there are items selected.
		if(button_text==undefined) button_text = false;
		
		// Will select the checkbox by default.
		if(do_check==undefined) do_check = true;
					
		// Makes sure the element exists.
		if(content_id!=undefined && $(content_id)) {
				
			// Gets the inputs.
			var inputs = $(content_id).getElementsByTagName('input');
			
			// Loops through all the inputs.
			for(var counter=0; counter<inputs.length; counter++) {
			
				// If the input is an enabled checkbox with a value.
				if(inputs[counter].type=='checkbox' && !inputs[counter].disabled && inputs[counter].value!='') {
					
					// Checks or unchecks the checkbox.
					inputs[counter].checked = (do_check ? 'checked' : '');
					
					// Updates the selection and counter.
					Container.change_selection(inputs[counter].id+'_holder',do_check,content_id,button_text);
				}
			}
		}
	},
	
	// Handles the submission of the email form in the Sharing container.
	share_by_email:function(type,id) {
		
		// Gets the content ID.
		var content_id = 'sharebox_'+type+'_'+id;
		
		// If the "To" field was left blank.
		if(Container.lacks_value(content_id+'_to')) Container.show_alert('You must supply at least one email address.');
		
		// If the "To" field was filled-in.
		else {
		
			// The Ajax.
			new Ajax.Request(engineURL, { method:'post',
				parameters:{ control:'share', action:'send', type:type, id:id, to:$(content_id+'_to').value, message:$(content_id+'_message').value },
			onComplete:function(transport) {
				
				// Success
				if(transport.responseText==1) {
					
					// Resets the form.
					$('content_'+content_id+'_email').reset();
					
					// Resets the "To" field.
					Container.toggle_hint(content_id+'_to',true);
					
					// Shows a message of success.
					Container.show_alert('Form submission was successful. Thank you!');
				}
				
				// Failed
				else Container.show_alert('There was a problem. Please try again.','Error');
			}});
		}
		
		// Returns false.
		return false;
	},
	
	// Turns a textbox hint on or off.
	toggle_hint:function(element_id,show_hint,hint_text) {
		if($(element_id) && show_hint && ($(element_id).value=='' || hint_text==undefined)) {
			$(element_id).addClassName('hint');
			$(element_id).removeClassName('hint_off');
			if(hint_text!=undefined) $(element_id).value = hint_text;
		}
		else if($(element_id) && !show_hint && ($(element_id).value==hint_text || hint_text==undefined)) {
			$(element_id).addClassName('hint_off');
			$(element_id).removeClassName('hint');
			if(hint_text!=undefined) $(element_id).value = '';
		}
		return false;
	},
	
	// Toggles the selection of an element.
	toggle_item:function(element_id,selected) {
		if(element_id!=undefined && $(element_id)) {
			if(selected==undefined) {
				if($(element_id).hasClassName('on')) $(element_id).removeClassName('on');
				else $(element_id).addClassName('on');
			}
			else if(selected) $(element_id).addClassName('on');
			else $(element_id).removeClassName('on');
		}
	},
	
	// Toggles expandable/collapsable content.
	toggle_toggle:function(toggle_id) {
		if($(toggle_id)) {
			$(toggle_id).toggle();
			if($(toggle_id+'_arrow')) {
				var arrow = $(toggle_id+'_arrow').innerHTML;
				$(toggle_id+'_arrow').update(arrow=='\u25BC' ? '&#9658;' : '&#9660;');
			}
		}
	},

	// Shows an error message within a container.
	show_error:function(message,container_id,tab_id) {
		if(message!='0') Container.show_info(message,container_id,tab_id,true);
	},

	// Shows an info message within a container.
	show_info:function(message,container_id,tab_id,is_error) {
		
		// Checks to make sure the container exists.
		if(message!=undefined) {
			
			// Gets the ID of the info block.
			var info_id = 'info_'+Container.get_suffix(container_id,tab_id);
			
			// The message is an info message by default.
			if(is_error==undefined) is_error = false;
			
			// If the container/tab exists.
			if($(info_id)) {
				
				// The link to hide the message.
				var close_message = ' <a href="javascript:void(0);" onclick="$(\''+info_id+'\').hide();">&times;</a>';
			
				// Updates the message.
				if(is_error) {
					$(info_id).addClassName('error');
					$(info_id).removeClassName('info');
					$(info_id).update('<b>ERROR:</b> '+message+close_message);
				}
				else {
					$(info_id).addClassName('info');
					$(info_id).removeClassName('error');
					$(info_id).update(message+close_message);
				}
				
				// Displays the message.
				$(info_id).show();
			}
			// If the container/tab does NOT exist.
			else Container.show_alert(message,(is_error ? 'Error' : 'Alert'));
		}
	}
}