//Initialize dojo.
dojo.require("dojo.lfx.*");
dojo.require("dojo.io.*");
dojo.require("dojo.widget.*");
dojo.require("dojo.widget.Dialog");
dojo.require("dojo.widget.Tooltip");

//The variables that define the state of the divs on the page.  The functions in this script use these variables to determine if the div should be displayed or hidden.
var state_playlist_names=0;
var state_new_playlist=0;
var state_new_playlist_missing_title_error=0;
var state_new_playlist_invalid_title_error=0;
var state_new_playlist_double_quote_error=0;
var state_new_playlist_single_quote_error=0;
var state_new_playlist_hash_error=0;
var state_edit_playlist=0;
var state_list_playlist_items=0;
var state_missing_playlist_title_error_from_dialog=0;
var state_invalid_playlist_title_error_from_dialog1=0;
var state_invalid_playlist_title_error_from_dialog2=0;
var state_dvd_names=0;
var state_new_dvd=0;
var state_new_dvd_missing_title_error=0;
var state_new_dvd_invalid_title_error=0;
var state_edit_dvd=0;
var state_list_dvd_items=0;
var state_missing_dvd_title_error_from_dialog=0;
var state_invalid_dvd_title_error_from_dialog1=0;
var state_invalid_dvd_title_error_from_dialog2=0;
var state_shopping_cart_items=0;

//The variables used to define the common dialogs used throughout the application.
//var delete_playlist_dialog;
var login_dialog;
var added_to_playlist_dialog;
var select_playlist_dialog;
var new_playlist_dialog;
var video_already_exists_dialog;
var remove_video_dialog;
var delete_dvd_dialog;
var select_dvd_dialog;
var new_dvd_dialog;
var added_to_dvd_dialog;
var video_already_exists_in_dvd_dialog;
var video_no_running_time_dialog;
var dvd_too_long_dialog;
var video_not_for_sale_dialog;
var remove_video_from_dvd_dialog;
var dvd_already_exists_in_shopping_cart_dialog;
var added_dvd_to_shopping_cart_dialog;
var remove_dvd_from_shopping_cart_dialog;
var empty_dvd_dialog;

//Initialize function to be called once dojo is initialized.
function init(e) {
	//Initialize the common dialogs.
	delete_playlist_dialog = dojo.widget.byId("dialog_delete_playlist");
	login_dialog = dojo.widget.byId("dialog_login");
	added_to_playlist_dialog = dojo.widget.byId("dialog_added_to_playlist");
	select_playlist_dialog = dojo.widget.byId("dialog_select_playlist");
	new_playlist_dialog = dojo.widget.byId("dialog_new_playlist");
	video_already_exists_dialog = dojo.widget.byId("dialog_video_already_exists");
	remove_video_dialog = dojo.widget.byId("dialog_remove_video");
	delete_dvd_dialog = dojo.widget.byId("dialog_delete_dvd");
	select_dvd_dialog = dojo.widget.byId("dialog_select_dvd");
	new_dvd_dialog = dojo.widget.byId("dialog_new_dvd");
	added_to_dvd_dialog = dojo.widget.byId("dialog_added_to_dvd");
	video_already_exists_in_dvd_dialog = dojo.widget.byId("dialog_video_already_exists_in_dvd");
	video_no_running_time_dialog = dojo.widget.byId("dialog_video_no_running_time");
	dvd_too_long_dialog = dojo.widget.byId("dialog_dvd_too_long");
	remove_video_from_dvd_dialog = dojo.widget.byId("dialog_remove_video_from_dvd");
	dvd_already_exists_in_shopping_cart_dialog = dojo.widget.byId("dialog_dvd_already_exists_in_shopping_cart");
	added_dvd_to_shopping_cart_dialog = dojo.widget.byId("dialog_added_dvd_to_shopping_cart");
	remove_dvd_from_shopping_cart_dialog = dojo.widget.byId("dialog_remove_dvd_from_shopping_cart");
	empty_dvd_dialog = dojo.widget.byId("dialog_empty_dvd");
	video_not_for_sale_dialog = dojo.widget.byId("dialog_video_not_for_sale");
	
}
dojo.addOnLoad(init);

//Function is called when the server responds with javascript code.  The javascript code is then executed.
function process_response(js_code){
	eval(js_code);
}

//Function to connect to the server and send a request.  The first parameter is the name of the function to call on the server.  The second parameter is an array of function parameters.
function send_request(function_name, function_params){
	dojo.io.XMLHTTPTransport.clearCache();
	//The url the request is sent to.
	var base_url="/typo3conf/ext/mediaburn_playlist/playlist_webservice.php";
	//Check to see which function should be called on the server.  Once the function is known, the rest of the url can be constructed using the parameters array.
	if(function_name=='submit_new_playlist'){
		base_url=base_url+'?function=submit_new_playlist'+'&title='+function_params[0]+'&description='+function_params[1]+'&userid='+function_params[2];
	}
	if(function_name=='get_playlist_description'){
		base_url=base_url+'?function=get_playlist_description'+'&edit='+function_params[0]+'&title='+function_params[1]+'&userid='+function_params[2];
	}
	if(function_name=='get_playlist_current'){
		base_url=base_url+'?function=get_playlist_current'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='update_playlist'){
		base_url=base_url+'?function=update_playlist'+'&title='+function_params[0]+'&description='+function_params[1]+'&current='+function_params[2]+'&userid='+function_params[3];
	}
	if(function_name=='delete_playlist'){
		base_url=base_url+'?function=delete_playlist'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='add_video_to_playlist'){
		base_url=base_url+'?function=add_video_to_playlist'+'&videoid='+function_params[0]+'&playlist_title='+function_params[1]+'&userid='+function_params[2];
	}
	if(function_name=='set_new_active_playlist'){
		base_url=base_url+'?function=set_new_active_playlist'+'&userid='+function_params[0];
	}
	if(function_name=='playlist_exists_from_dialog'){
		base_url=base_url+'?function=playlist_exists_from_dialog'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='create_new_playlist_from_dialog'){
		base_url=base_url+'?function=create_new_playlist_from_dialog'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='set_existing_active_playlist_from_dialog'){
		base_url=base_url+'?function=set_existing_active_playlist_from_dialog'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='remove_video_from_playlist'){
		base_url=base_url+'?function=remove_video_from_playlist'+'&videoid='+function_params[0]+'&title='+function_params[1]+'&userid='+function_params[2];
	}
	if(function_name=='submit_new_dvd'){
		base_url=base_url+'?function=submit_new_dvd'+'&title='+function_params[0]+'&description='+function_params[1]+'&userid='+function_params[2];
	}
	if(function_name=='get_dvd_description'){
		base_url=base_url+'?function=get_dvd_description'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='get_dvd_current'){
		base_url=base_url+'?function=get_dvd_current'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='update_dvd'){
		base_url=base_url+'?function=update_dvd'+'&title='+function_params[0]+'&description='+function_params[1]+'&current='+function_params[2]+'&userid='+function_params[3];
	}
	if(function_name=='delete_dvd'){
		base_url=base_url+'?function=delete_dvd'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='set_new_active_dvd'){
		base_url=base_url+'?function=set_new_active_dvd'+'&userid='+function_params[0];
	}
	if(function_name=='set_existing_active_dvd_from_dialog'){
		base_url=base_url+'?function=set_existing_active_dvd_from_dialog'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='add_video_to_dvd'){
		base_url=base_url+'?function=add_video_to_dvd'+'&videoid='+function_params[0]+'&dvd_title='+function_params[1]+'&userid='+function_params[2];
	}
	if(function_name=='dvd_exists_from_dialog'){
		base_url=base_url+'?function=dvd_exists_from_dialog'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='create_new_dvd_from_dialog'){
		base_url=base_url+'?function=create_new_dvd_from_dialog'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='video_has_runtime'){
		base_url=base_url+'?function=video_has_runtime'+'&videoid='+function_params[0];
	}
	if(function_name=='reload_playlist_items'){
		base_url=base_url+'?function=reload_playlist_items'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='reload_dvd_items'){
		base_url=base_url+'?function=reload_dvd_items'+'&title='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='remove_video_from_dvd'){
		base_url=base_url+'?function=remove_video_from_dvd'+'&videoid='+function_params[0]+'&title='+function_params[1]+'&userid='+function_params[2];
	}
	if(function_name=='shopping_cart_has_dvd'){
		base_url=base_url+'?function=shopping_cart_has_dvd'+'&dvdid='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='add_dvd_to_shopping_cart'){
		base_url=base_url+'?function=add_dvd_to_shopping_cart'+'&dvdid='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='remove_dvd_from_shopping_cart'){
		base_url=base_url+'?function=remove_dvd_from_shopping_cart'+'&dvdid='+function_params[0]+'&userid='+function_params[1];
	}
	if(function_name=='dvd_has_videos'){
		base_url=base_url+'?function=dvd_has_videos'+'&dvdid='+function_params[0]+'&userid='+function_params[1];
	}
	dojo.io.bind({
	url: base_url,
   	handle: function(type, data, evt){
        if(type == "load"){
        	//Get the response and process the xml.
        	process_response(data);
       }
        else if(type == "error"){
		//Error occured.
		alert('You\'r request could not be processed.');
        }
        else{
            	//Unknown event occured.
            	alert('Somthing strange happened.  Request not processed.');
        }},
    	mimetype: "text/plain"
	});
}

//Function to display or hide the playlist names div depending on the state of the div.
function display_playlist_names(){
	//Initialize the DOM HTML elements.
	var playlist_names=document.getElementById('playlist_names');
	var new_playlist=document.getElementById('new_playlist');
	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');
	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');
	var edit_playlist_div=document.getElementById('edit_playlist');
	var list_playlist_items_div=document.getElementById('playlist_items');
	var dvd_names=document.getElementById('dvd_names');
	var new_dvd=document.getElementById('new_dvd');
	var edit_dvd_div=document.getElementById('edit_dvd');
	var list_dvd_items_div=document.getElementById('dvd_items');
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');
	if(state_playlist_names){
		dojo.lfx.wipeOut(playlist_names).play();
		state_playlist_names=0;
	}
	else{
		dojo.lfx.wipeIn(playlist_names).play();
		state_playlist_names=1;
	}
	//Check if other DIV elements should be hidden.
	if(state_new_playlist){
		dojo.lfx.wipeOut(new_playlist).play();
		state_new_playist=0;
	}
	if(state_new_playlist_missing_title_error){
		dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
		state_new_paylist_missing_title_error=0;
	}
	if(state_new_playlist_invalid_title_error){
		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
		state_new_playlist_invalid_title_error=0;
	}
	if(state_edit_playlist){
		dojo.lfx.wipeOut(edit_playlist_div).play();
		state_edit_playlist=0;
	}
	if(state_list_playlist_items){
		dojo.lfx.wipeOut(list_playlist_items_div).play();
		state_list_playlist_items=0;
	}
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}	
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd_div).play();
		state_edit_dvd=0;
	}
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_dvd_items=0;
	}
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}

}

//Function to display or hide the new playlist form div depending on the state of the div.  Also, validate the form and send the request to the server.
function submit_new_playlist(form){
	//Initialize the DOM HTML elements.
	var new_playlist=document.getElementById('new_playlist');
	var new_playlist_title=document.getElementById('new_playlist_title');
	var new_playlist_description=document.getElementById('new_playlist_description');
	var new_playlist_userid=document.getElementById('constants_userid');
	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');
	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');
	var new_playlist_double_quote_error=document.getElementById('new_playlist_double_quote_error');
	var new_playlist_single_quote_error=document.getElementById('new_playlist_single_quote_error');
	var new_playlist_hash_error=document.getElementById('new_playlist_hash_error');
	var playlist_names=document.getElementById('playlist_names');
	var edit_playlist_div=document.getElementById('edit_playlist');
	var list_playlist_items_div=document.getElementById('playlist_items');
	var dvd_names=document.getElementById('dvd_names');
	var new_dvd=document.getElementById('new_dvd');
	var edit_dvd_div=document.getElementById('edit_dvd');
	var list_dvd_items_div=document.getElementById('dvd_items');
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');

	//Check if form data is being submitted.
	if(form){
		//Check if a playlist title was provided.
		if(new_playlist_title.value){
			//Check for double quotes.
			if(new_playlist_title.value.search(/"/)>(-1)){
				//Check if any other error messages are being displayed.
				if(state_new_playlist_missing_title_error){
					dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
					state_new_playlist_missing_title_error=0;
				}
				if(state_new_playlist_single_quote_error){
					dojo.lfx.wipeOut(new_playlist_single_quote_error).play();
					state_new_playlist_single_quote_error=0;
				}
				if(state_new_playlist_invalid_title_error){
					dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
					state_new_playlist_invalid_title_error=0;
				}
				if(state_new_playlist_hash_error){
					dojo.lfx.wipeOut(new_playlist_hash_error).play();
					state_new_playlist_hash_error=0;
				}
				//Display the double quote error message.
				dojo.lfx.wipeIn(new_playlist_double_quote_error).play();
				state_new_playlist_double_quote_error=1;
				return;
			}	
			//Check for single quotes.
			if(new_playlist_title.value.search(/'/)>(-1)){
				//Check for any other error messages that are being displayed.
				if(state_new_playlist_double_quote_error){
					dojo.lfx.wipeOut(new_playlist_double_quote_error).play();
					state_new_playlist_double_quote_error=0;
				}
				if(state_new_playlist_missing_title_error){
					dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
					state_new_playlist_missing_title_error=0;
				}
				if(state_new_playlist_invalid_title_error){
					dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
					state_new_playlist_invalid_title_error=0;
				}
				if(state_new_playlist_hash_error){
					dojo.lfx.wipeOut(new_playlist_hash_error).play();
					state_new_playlist_hash_error=0;
				}
				dojo.lfx.wipeIn(new_playlist_single_quote_error).play();
				state_new_playlist_single_quote_error=1;
				return;
			}
			//Check for a hash symble.
			if(new_playlist_title.value.search(/#/)>(-1)){
				//Check for any other error messages.
				if(state_new_playlist_double_quote_error){
					dojo.lfx.wipeOut(new_playlist_double_quote_error).play();
					state_new_playlist_double_quote_error=0;
				}
				if(state_new_playlist_single_quote_error){
					dojo.lfx.wipeOut(new_playlist_single_quote_error).play();
					state_new_playlist_single_quote_error=0;
				}
				if(state_new_playlist_missing_title_error){
					dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
					state_new_playlist_missing_title_error=0;
				}
				if(state_new_playlist_invalid_title_error){
					dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
					state_new_playlist_invalid_title_error=0;
				}
				dojo.lfx.wipeIn(new_playlist_hash_error).play();
				state_new_playlist_hash_error=1;
				return;
			}	
			//Send a request to the server to create a new playlist.
			var params=new Array(new_playlist_title.value, new_playlist_description.value, new_playlist_userid.value);
			send_request('submit_new_playlist', params);
			return;
		}
		//A playlist title was not provided.
		else{
			//Check for any other error messages that are being displayed.
			if(state_new_playlist_double_quote_error){
				dojo.lfx.wipeOut(new_playlist_double_quote_error).play();
				state_new_playlist_double_quote_error=0;
			}
			if(state_new_playlist_single_quote_error){
				dojo.lfx.wipeOut(new_playlist_single_quote_error).play();
				state_new_playlist_single_quote_error=0;
			}
			if(state_new_playlist_invalid_title_error){
				dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
				state_new_playlist_invalid_title_error=0;
			}
			if(state_new_playlist_hash_error){
				dojo.lfx.wipeOut(new_playlist_hash_error).play();
				state_new_playlist_hash_error=0;
			}
			//Display an error message.
			dojo.lfx.wipeIn(new_playlist_missing_title_error).play();
			state_new_playlist_missing_title_error=1;
			return;
		}
	}
	//Check if the new playlist form should be displayed.
	if(state_new_playlist){
		dojo.lfx.wipeOut(new_playlist, 500).play();
		state_new_playlist=0;
	}
	else{
		dojo.lfx.wipeIn(new_playlist, 500).play();
		state_new_playlist=1;
	}

	//Check if other DIV elements should be hidden.
	if(state_playlist_names){
		dojo.lfx.wipeOut(playlist_names).play();
		state_playlist_names=0;
	}
	if(state_new_playlist_missing_title_error){
		dojo.lfx.wipeOut(new_playlist_title_error).play();
		state_new_playlist_missing_title_error=0;
	}
	if(state_new_playlist_invalid_title_error){
		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
		state_new_playlist_invalid_title_error=0;
	}
	if(state_new_playlist_double_quote_error){
		dojo.lfx.wipeOut(new_playlist_double_quote_error).play();
		state_new_playlist_double_quote_error=0;
	}
	if(state_new_playlist_single_quote_error){
		dojo.lfx.wipeOut(new_playlist_single_quote_error).play();
		state_new_playlist_single_quote_error=0;
	}
	if(state_new_playlist_hash_error){
		dojo.lfx.wipeOut(new_playlist_hash_error).play();
		state_new_playlist_hash_error=0;
	}
	if(state_edit_playlist){
		dojo.lfx.wipeOut(edit_playlist_div).play();
		state_edit_playlist=0;
	}
	if(state_list_playlist_items){
		dojo.lfx.wipeOut(list_playlist_items_div).play();
		state_list_playlist_items=0;
	}
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd_div).play();
		state_edit_dvd=0;
	}
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_playlist_items=0;
	}
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}
}

//Function is called as a response from the server when submit_new_playlist is called.
function response_submit_new_playlist(error, number_of_playlists, playlist_title){
	//Initialize the DOM HTML elements.
	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');
	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');
	var new_playlist=document.getElementById('new_playlist');
	var display_playlists=document.getElementById('display_playlists');
	var new_playlist_title=document.getElementById('new_playlist_title');
	var new_playlist_description=document.getElementById('new_playlist_description');
	var user_playlist_names=document.getElementById('playlist_names_table');
	//Check if there was an error submitting the new playlist.
	if(error){
		//Check for any other error messages that are being displayed.
		if(state_new_playlist_double_quote_error){
			dojo.lfx.wipeOut(new_playlist_double_quote_error).play();
			state_new_playlist_double_quote_error=0;
		}
		if(state_new_playlist_single_quote_error){
			dojo.lfx.wipeOut(new_playlist_single_quote_error).play();
			state_new_playlist_single_quote_error=0;
		}
		if(state_new_playlist_missing_title_error){
			dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
			state_new_playlist_missing_title_error=0;
		}
		if(state_new_playlist_hash_error){
			dojo.lfx.wipeOut(new_playlist_hash_error).play();
			state_new_playlist_hash_error=0;
		}
		dojo.lfx.wipeIn(new_playlist_invalid_title_error).play();
		state_new_playlist_invalid_title_error=1;		
	}
	else{
		//Update the number of playlists displayed.
		display_playlists.innerHTML=number_of_playlists;
		//Update the playlist names displayed.
		var temp_row=user_playlist_names.insertRow(user_playlist_names.rows.length);
		//Replace quotes for the id attribute.
		var temp_title=playlist_title.replace(/&#39;/g, "#DS");
		temp_title=temp_title.replace(/&quot;/g, "#DD");
		temp_row.id='playlist_row_'+temp_title;
		var temp_cell=temp_row.insertCell(0);
		//Replace single quotes.
		temp_title=playlist_title.replace(/&#39;/g, "\\'");
		temp_cell.innerHTML='<a href="javascript: list_playlist_items(\''+temp_title+'\');">'+playlist_title+'</a>';
		//Reset the new playlist form and hide it.
		new_playlist_title.value='';
		new_playlist_description.value='';
		dojo.lfx.wipeOut(new_playlist, 500).play();
		state_new_playlist=0;
		//Check if a previous title error message was displayed.
		if(state_new_playlist_missing_title_error){
			//Reset and hide the new playlist form.
			dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
			state_new_playlist_title_error=0;
		}
		//Check if a previous title error message was displayed.
		if(state_new_playlist_invalid_title_error){
			//Reset and hide the new playlist form.
			dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
			state_new_playlist_invalid_title_error=0;
		}
	}
}

//Function to display or hide the edit playlist form depending on the state of the div.  Also, validate the form and send the request to the server.
function edit_playlist(playlist_title){
	//Initialize the DOM HTML elements.
	var edit_playlist_div=document.getElementById('edit_playlist');
	var edit_playlist_title=document.getElementById('edit_playlist_title');
	var edit_playlist_userid=document.getElementById('constants_userid');
	var playlist_names=document.getElementById('playlist_names');
	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');
	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');
	var list_playlist_items_div=document.getElementById('playlist_items');
	var dvd_names=document.getElementById('dvd_names');
	var new_dvd=document.getElementById('new_dvd');
	var edit_dvd_div=document.getElementById('edit_dvd');
	var new_playlist=document.getElementById('new_playlist');
	var list_dvd_items_div=document.getElementById('dvd_items');
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');
	//Check if the edit playlist form should be submitted.
	if(state_edit_playlist){
		dojo.lfx.wipeOut(edit_playlist_div, 500).play();
		state_edit_playlist=0;
	}
	else{
		//Set the playlist title on the form.
		edit_playlist_title.value=playlist_title;
		//Construct a parameter array and send a request to get the playlist description.
		var params=new Array(1, playlist_title, edit_playlist_userid.value);
		send_request('get_playlist_description', params);
		//Construct a parameter array and send a request to get the playlist current property.
		params=new Array(playlist_title, edit_playlist_userid.value);
		send_request('get_playlist_current', params);
		//Display the edit playlist form.
		dojo.lfx.wipeIn(edit_playlist_div).play();
		state_edit_playlist=1;
	}
	//Check if any DIV elements should be hidden.
	if(state_playlist_names){
		dojo.lfx.wipeOut(playlist_names).play();
		state_playlist_names=0;
	}
	if(state_new_playlist){
		dojo.lfx.wipeOut(new_playlist).play();
		state_new_playlist=0;
	}
	if(state_new_playlist_missing_title_error){
		dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
		state_new_playlist_missing_title_error=0;
	}
	if(state_new_playlist_invalid_title_error){
		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
		state_new_playlist_invalid_title_error=0;
	}	
	if(state_list_playlist_items){
		dojo.lfx.wipeOut(list_playlist_items_div).play();
		state_list_playlist_items=0;
	}
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd).play();
		state_edit_dvd=0;
	}
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_dvd_items=0;
	}
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}
}

//Function is called as a response from the server when get_playlist_description is called on the server.
function response_get_playlist_description(edit, description){
	if(edit){
		//Initialize the DOM HTML elements.
		var edit_playlist_description=document.getElementById('edit_playlist_description');
		//Set the playlist description on the edit playlist form.
		var temp_description=description.replace(/&quot;/g, '"');
		temp_description=temp_description.replace(/&#39;/g, "'");
		edit_playlist_description.value=temp_description;
		return;
	}
	var playlist_description=document.getElementById('playlist_description');
	//Set the playlist description on the playlist items div.
	var temp_description=description.replace(/&quot;/g, '"');
	temp_description=temp_description.replace(/&#39;/g, "'");
	playlist_description.innerHTML=temp_description;
}

//Function is called as a response from the server when get_playlist_current is called on the server.
function response_get_playlist_current(current, title){
	//Initialize the DOM HTML elements.
	var edit_playlist_current=document.getElementById('edit_playlist_current');
	var display_active_playlist=document.getElementById('display_active_playlist');
	var userid=document.getElementById('constants_userid');
	var temp_title=title.replace(/&#39;/g, "'");
	//Send a request to reload the current playlist items.
	var params=new Array(temp_title, userid.value);
	send_request('reload_playlist_items', params);
	//Replace HTML special characters and set the active playlist.
	temp_title=title.replace(/&#39;/g, "\\'");
	display_active_playlist.innerHTML='<a id="active_playlist_name" href="javascript: list_playlist_items(\''+temp_title+'\');">'+title+'</a>';

	//Set the current playlist on the edit playlist form.
	/*if(current){
		edit_playlist_current.checked=true;
	}
	else{
		edit_playlist_current.checked=false;
	}*/
}

//Function to save the changes made to a playlist.
function edit_playlist_save(){
	//Initialize the DOM HTML elements.
	var edit_playlist_title=document.getElementById('edit_playlist_title');
	var edit_playlist_description=document.getElementById('edit_playlist_description');
	//var edit_playlist_current=document.getElementById('edit_playlist_current');
	var edit_playlist_userid=document.getElementById('constants_userid');
	//Initialize the current variable.
	current=0;
	//If the current checkbox on the edit playlist form is selected, set the current variable to true.
	//if(edit_playlist_current.checked){
		//current=1;
	//}
	//Construct a parameter array and send a request to update the edited playlist.
	var params=new Array(edit_playlist_title.value, edit_playlist_description.value, current, edit_playlist_userid.value);
	send_request('update_playlist', params);
}

//Function is called as a response from the server when update_playlist is called on the server.
function response_update_playlist(current_playlist){
	//Initialize the DOM HTML elements.
	var edit_playlist_div=document.getElementById('edit_playlist');
	var display_active_playlist=document.getElementById('display_active_playlist');
	var userid=document.getElementById('constants_userid');
	//Set the current playlist title.
	if(current_playlist=='None'){
		display_active_playlist.innerHTML=current_playlist;
	}
	else{
		var temp_title=current_playlist.replace(/&#39;/g, "'");
		//Send a request to reload the current playlist items.
		var params=new Array(temp_title, userid.value);
		send_request('reload_playlist_items', params);
		//Replace HTML special characters and set the active playlist.
		temp_title=current_playlist.replace(/&#39;/g, "\\'");
		display_active_playlist.innerHTML='<a id="active_playlist_name" href="javascript: list_playlist_items(\''+temp_title+'\');">'+current_playlist+'</a>';
	}
	//Hide the edit playlist form.
	dojo.lfx.wipeOut(edit_playlist_div).play();
	state_edit_playlist=0;	
}

//Function is called as a response from the server when reload_playlist_items is called on the server.
function response_reload_playlist_items(videoids, preview_links, durations, dates, producers){
	//Initialize DOM HTML elements.
	var playlist_items_table=document.getElementById('playlist_items_table');
	//Remove any existing playlist items.
	for (i=playlist_items_table.rows.length-1; i>=1; i--) {
		playlist_items_table.deleteRow(i);
	}
	//Iterate through the video ids.
	for (i=0; i<videoids.length; i++){
		//Insert the video data into the playlist items table.
		var temp_row=playlist_items_table.insertRow(playlist_items_table.rows.length);
		temp_row.id='video_'+videoids[i];
		//Replace the special characters in the video preview link.
		preview_links[i]=preview_links[i].replace(/&quot;/g, '"');
		try{
			temp_row.innerHTML='<td>'+preview_links[i]+'</td><td>'+durations[i]+'</td><td>'+dates[i]+'</td><td>'+producers[i]+'</td><td><a href="javascript: add_video_to_dvd('+videoids[i]+');">Add To DVD</a></td><td><a href="javascript: remove_video_from_playlist('+videoids[i]+');">Remove Video</a></td>';
		}
		catch(err){
			temp_cell=temp_row.insertCell(0);
			temp_cell.innerHTML=preview_links[i];
			temp_cell=temp_row.insertCell(1);
			temp_cell.innerHTML=durations[i];
			temp_cell=temp_row.insertCell(2);
			temp_cell.innerHTML=dates[i];
			temp_cell=temp_row.insertCell(3);
			temp_cell.innerHTML=producers[i];
			temp_cell=temp_row.insertCell(4);
			temp_cell.innerHTML='<a href="javascript: add_video_to_dvd('+videoids[i]+');">Add To DVD</a>';
			temp_cell=temp_row.insertCell(5);
			temp_cell.innerHTML='<a href="javascript: remove_video_from_playlist('+videoids[i]+');">Remove Video</a>';
		}
	}
}

//Function is called when a user clicks the delete playlist button.  Displays a confirmation dialog.
function show_delete_playlist_confirm(){
	try{
		//Display the confirm delete playlist dialog box.
		delete_playlist_dialog.show();
	}
	catch(err){
		if(confirm('Are you sure you want to delete the playlist?')){
			delete_playlist();
		}
	}
}

//Function to hide the delete playlist confirmation dialog.
function hide_delete_playlist_dialog(){
	try{
		//Hide the confirm delete playlist dialog box.
		delete_playlist_dialog.hide();
	}
	catch(err){
		return;
	}
}

//Function to delete a playlist.
function delete_playlist(){
	//Initialize the DOM HTML elements.
	var edit_playlist_title=document.getElementById('edit_playlist_title');
	var edit_playlist_userid=document.getElementById('constants_userid');
	var display_active_playlist=document.getElementById('display_active_playlist');
	var playlist_names_table=document.getElementById('playlist_names_table');
	var temp_title=edit_playlist_title.value.replace(/"/g, '#DD');
	temp_title=temp_title.replace(/'/g, '#DS');
	var deleted_playlist_row=document.getElementById('playlist_row_'+temp_title);
	var edit_playlist_div=document.getElementById('edit_playlist');
	//Construct a parameter array and send a request to delete the playlist being edited.
	var params=new Array(edit_playlist_title.value, edit_playlist_userid.value);
	send_request('delete_playlist', params);
	//Delete the row that contains the playlist to be deleted.
	playlist_names_table.deleteRow(deleted_playlist_row.rowIndex);
	//Hide the confirm delete dialog.
	hide_delete_playlist_dialog();
	//Hide the edit playlist form.
	dojo.lfx.wipeOut(edit_playlist_div).play();
	state_edit_playlist=0;
}

//Function is called as a response from the server when delete_playlist is called on the server.
function response_delete_playlist(current_playlist, number_of_playlists){
	//Initialize the DOM HTML elements.
	var display_active_playlist=document.getElementById('display_active_playlist');
	var display_playlists=document.getElementById('display_playlists');
	//Set the current playlist title.
	if(current_playlist=='None'){
		display_active_playlist.innerHTML=current_playlist;
	}
	else{
		temp_title=current_playlist.replace(/&#39;/g, "\\'");
		display_active_playlist.innerHTML='<a id="active_playlist_name" href="javascript: list_playlist_items(\''+temp_title+'\');">'+current_playlist+'</a>';
	}
	//Set the number of playlists belonging to the current front-end user.
	display_playlists.innerHTML=number_of_playlists;
}

//Function to display the div element that shows the playlist items for the current playlist.
function list_playlist_items(current_playlist){
	//Initialize the DOM HTML elements.
	var list_playlist_items_div=document.getElementById('playlist_items');
	var userid=document.getElementById('constants_userid');
	var playlist_names=document.getElementById('playlist_names');
	var new_playlist=document.getElementById('new_playlist');
	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');
	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');
	var edit_playlist_div=document.getElementById('edit_playlist');
	var dvd_names=document.getElementById('dvd_names');
	var new_dvd=document.getElementById('new_dvd');
	var edit_dvd_div=document.getElementById('edit_dvd');
	var list_dvd_items_div=document.getElementById('dvd_items');
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');
	var edit_playlist_link=document.getElementById('edit_playlist_link');
	//Construct a parameter array and send a request to get the playlist description.
	var params=new Array(0, current_playlist, userid.value);
	send_request('get_playlist_description', params);
	//Construct a parameter array and send a request to get the playlist current property.
	params=new Array(current_playlist, userid.value);
	send_request('get_playlist_current', params);
	edit_playlist_link.innerHTML='<a href="javascript: edit_playlist(\''+current_playlist+'\');">Edit Playlist</a>';
	//Check if the div element should be hidden.
	if(state_list_playlist_items){
		dojo.lfx.wipeOut(list_playlist_items_div).play();
		state_list_playlist_items=0;
	}
	else{
		dojo.lfx.wipeIn(list_playlist_items_div).play();
		state_list_playlist_items=1;
	}
	//Check if other div elements should be hidden.
	if(state_playlist_names){
		dojo.lfx.wipeOut(playlist_names).play();
		state_playlist_names=0;
	}
	if(state_new_playlist){
		dojo.lfx.wipeOut(new_playlist).play();
		state_new_playlist=0;
	}
	if(state_new_playlist_missing_title_error){
		dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
		state_new_playist_missing_title_error=0;
	}
	if(state_new_playlist_invalid_title_error){
		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
		state_new_playlist_invalid_title_error=0;
	}
	if(state_edit_playlist){
		dojo.lfx.wipeOut(edit_playlist_div).play();
		state_edit_playlist=0;
	}
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd_div).play();
		state_edit_dvd=0;
	}
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_dvd_items=0;
	}
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}
}	

/**
*Function to add a video to the playlist. First, check if the user is currently logged in and if not, will
*show a login dialog box.  Then, attempt to validate the user.  If the user is validated, set the new userid
in the constants div.  Then, ask the user which playlist the video should be added to.
**/
function add_video_to_playlist(videoid){
	//Initialize DOM HTML elements.
	var add_video_to_playlist_userid=document.getElementById('constants_userid');
	var add_video_to_playlist_current_playlist=document.getElementById('active_playlist_name');
	var temp_videoid=document.getElementById('constants_videoid');
	//Check if a userid has been set.  If there is not a userid set, catch the exception and display the login box.
	try{
		var temp_userid=add_video_to_playlist_userid.value;
	}
	catch(err){
		try{
			login_dialog.show();
		}
		catch(err){
			alert("You have to login to use the playlist.");
		}
		return;
			
	}
	//Set the temp video id constant.
	temp_videoid.value=videoid;
	//Check if the front-end user has a current playlist set.  If no playlist is set, display the choose playlist dialog.
	try{
		var temp_playlist_name=add_video_to_playlist_current_playlist.innerHTML;
	}
	catch(err){
		//Send a request to the server to display the available playlists dialog.
		var params=new Array(add_video_to_playlist_userid.value);
		send_request('set_new_active_playlist', params);
		return;
	}
	//Send a request to the server to format the added to playlist dialog and display it.  Also, add the video id to the playlist deatabase table for the specified user.
	var params=new Array(videoid, add_video_to_playlist_current_playlist.innerHTML, add_video_to_playlist_userid.value);
	send_request('add_video_to_playlist', params);
}

//Function to format the added to playlist dialog with the video that was added and the playlist the video was added to.  Function is called as a response from the server.
function response_add_video_to_playlist(exists, video_title, playlist_title, videoid, video_duration, video_date, video_producers, video_preview_link){
	//Initialize DOM HTML elements.
	var added_video_title=document.getElementById('added_video_title');
	var added_playlist_title=document.getElementById('added_playlist_title');
	var not_added_video_title=document.getElementById('not_added_video_title');
	var not_added_playlist_title=document.getElementById('not_added_playlist_title');
	var temp_videoid=document.getElementById('constants_videoid');
	var playlist_items=document.getElementById('playlist_items_table');
	//Check if the video has already been added to the playlist.
	if(exists){
		//Set the video and playlist titles that were not added.
		not_added_video_title.innerHTML=video_title;
		not_added_playlist_title.innerHTML=playlist_title;
		try{
			video_already_exists_dialog.show();
		}
		catch(err){
			alert('The video '+video_title+' has already been added to the playlist '+playlist_title+'.');		
		}
		return;
	}
	//Set the added video and playlist titles.
	added_video_title.innerHTML=video_title;
	added_playlist_title.innerHTML=playlist_title;
	try{
		//Display the added to playlist dialog.
		added_to_playlist_dialog.show();
	}
	catch(err){
		alert('The video '+video_title+' has been added to the playlist '+playlist_title+'.');
	}
	//Insert the video data into the playlist items table.
	var temp_row=playlist_items.insertRow(playlist_items.rows.length);
	temp_row.id='video_'+videoid;
	//Replace the special characters in the video preview link.
	video_preview_link=video_preview_link.replace(/&quot;/g, '"');
	try{
		temp_row.innerHTML='<td>'+video_preview_link+'</td><td>'+video_duration+'</td><td>'+video_date+'</td><td>'+video_producers+'</td><td><a href="javascript: add_video_to_dvd('+videoid+');">Add To DVD</a></td><td><a href="javascript: remove_video_from_playlist('+videoid+');">Remove Video</a></td>';
	}
	catch(err){
		temp_cell=temp_row.insertCell(0);
		temp_cell.innerHTML=video_preview_link;
		temp_cell=temp_row.insertCell(1);
		temp_cell.innerHTML=video_duration;
		temp_cell=temp_row.insertCell(2);
		temp_cell.innerHTML=video_date;
		temp_cell=temp_row.insertCell(3);
		temp_cell.innerHTML=video_producers;
		temp_cell=temp_row.insertCell(4);
		temp_cell.innerHTML='<a href="javascript: add_video_to_dvd('+videoid+');">Add To DVD</a>';
		temp_cell=temp_row.insertCell(5);
		temp_cell.innerHTML='<a href="javascript: remove_video_from_playlist('+videoid+');">Remove Video</a>';
	}
}

//Function to format the set new active playlist dialog and display it.  Function is called as a response from the server.
function response_set_new_active_playlist(playlist_titles){
	//Inititalize DOM HTML elements.
	var select_playlist_names=document.getElementById('select_playlist_names');
	//Remove any existing options in the select element.
	for(cnt in select_playlist_names.options){
		select_playlist_names.remove(cnt);
	} 
	//Add the new playlist option to the list of playlists to select from.
	temp_option=document.createElement('option');
	temp_option.text='--New Playlist--';
	//Append the option to the selection element depending on which method works (browser incompatibility issue).
	try{
		select_playlist_names.add(temp_option, null);
	}
	catch(err){
		select_playlist_names.add(temp_option, select_playlist_names.length);	
	}
	//Iterate through the playlist titles.
	for(cnt in playlist_titles){
		//Create the new option element that will be appended to the selection element.
		temp_option=document.createElement('option');
		//Replace the special characters in the current title.
		temp_title=playlist_titles[cnt];
		temp_title=temp_title.replace(/&#39;/g, "'");
		temp_title=temp_title.replace(/&quot;/g, '"');		
		//Set the text for the current option element.
		temp_option.text=temp_title;
		//Append the option to the selection element depending on which method works (browser incompatibility issue).
		try{
			select_playlist_names.add(temp_option, null);
		}
		catch(err){
			select_playlist_names.add(temp_option, select_playlist_names.length);	
		}
	}
	try{
		//Display the dialog.
		select_playlist_dialog.show();
	}
	catch(err){
		alert('Please select an active playlist.');
	}
}
//Function to close the add video to playlist dialog.
function close_added_to_playlist_dialog(){
	added_to_playlist_dialog.hide();
}

//Function to set the new active playlist via dojo dialog windows.
function set_new_active_playlist(){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var select_playlist_names=document.getElementById('select_playlist_names');
	//Hide the select active playlist dialog.
	select_playlist_dialog.hide();
	//Check if a new playlist is being created.
	if(select_playlist_names.value=='--New Playlist--'){
		new_playlist_dialog.show();
		return;
	}
	//Send a request to the server set the selected playlist as the active playlist.
	var params=new Array(select_playlist_names.value, userid.value);
	send_request('set_existing_active_playlist_from_dialog', params);
}

//Function to create a new playlist via dojo dialog windows.
function create_new_playlist_from_dialog(){
	//Initialize DOM HTML elements.
	var temp_videoid=document.getElementById('constants_videoid');
	var userid=document.getElementById('constants_userid');
	var missing_playlist_title_error_from_dialog=document.getElementById('missing_playlist_title_error_from_dialog');
	var invalid_playlist_title_error_from_dialog1=document.getElementById('invalid_playlist_title_error_from_dialog1');
	var invalid_playlist_title_error_from_dialog2=document.getElementById('invalid_playlist_title_error_from_dialog2');
	var new_playlist_from_dialog_name=document.getElementById('new_playlist_from_dialog_name');
	//Check if the title is missing.
	if(new_playlist_from_dialog_name.value===''){
		//Check if previous error messages should be cleared.
		if(state_invalid_playlist_title_error_from_dialog1){
			state_invalid_title_error_from_dialog1=0;
			dojo.lfx.wipeOut(invalid_playlist_title_error_from_dialog1).play();
		}
		if(state_invalid_playlist_title_error_from_dialog2){
			state_invalid_title_error_from_dialog2=0;
			dojo.lfx.wipeOut(invalid_playlist_title_error_from_dialog2).play();
		}
		//Display the error message.
		state_missing_title_error_from_dialog=1;
		dojo.lfx.wipeIn(missing_playlist_title_error_from_dialog).play();
		return;
	}
	//Check for an invalid title.
	if(new_playlist_from_dialog_name.value=='--New Playlist--'){
		//Check if previous error messages should be cleared.
		if(state_missing_playlist_title_error_from_dialog){
			state_missing_title_error_from_dialog=0;
			dojo.lfx.wipeOut(missing_playlist_title_error_from_dialog).play();
		}
		if(state_invalid_playlist_title_error_from_dialog2){
			state_invalid_title_error_from_dialog2=0;
			dojo.lfx.wipeOut(invalid_playlist_title_error_from_dialog2).play();
		}
		//Display the error message.
		state_invalid_playlist_title_error_from_dialog1=1;
		dojo.lfx.wipeIn(invalid_playlist_title_error_from_dialog1).play();
		return;
	}
	//Send a request to the server to check if the playlist title already exists.
	var params=new Array(new_playlist_from_dialog_name.value, userid.value);
	send_request('playlist_exists_from_dialog', params);
}

//Function is called as a resonse from the server when playlist_exists_from_dialog is called on the server.
function response_playlist_exists_from_dialog(exists){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var missing_playlist_title_error_from_dialog=document.getElementById('missing_playlist_title_error_from_dialog');
	var invalid_playlist_title_error_from_dialog1=document.getElementById('invalid_playlist_title_error_from_dialog1');
	var invalid_playlist_title_error_from_dialog2=document.getElementById('invalid_playlist_title_error_from_dialog2');
	var new_playlist_from_dialog_name=document.getElementById('new_playlist_from_dialog_name');
	//Check if the submitted playlist title already exists in the database.
	if(exists){
		//Check for any previous error messages that should be cleared.
		if(state_missing_playlist_title_error_from_dialog){
			state_missing_playlist_title_error_from_dialog=0;
			dojo.lfx.wipeOut(missing_playlist_title_error_from_dialog).play();
		}
		if(state_invalid_playlist_title_error_from_dialog1){
			state_invalid_playlist_title_error_from_dialog1=0;
			dojo.lfx.wipeOut(invalid_playlist_title_error_from_dialog1).play();
		}
		//Display the error message.
		state_invalid_playlist_title_error_from_dialog2=1;
		dojo.lfx.wipeIn(invalid_playlist_title_error_from_dialog2);
		return;
	}
	//Hide all previous error messages
	if(state_missing_playlist_title_error_from_dialog){
		state_missing_playlist_title_error_from_dialog=0;
		dojo.lfx.wipeOut(missing_playlist_title_error_from_dialog).play();
	}
	if(state_invalid_playlist_title_error_from_dialog1){
		state_invalid_playlist_title_error_from_dialog1=0;
		dojo.lfx.wipeOut(invalid_playlist_title_error_from_dialog1).play();
	}
	if(state_invalid_playlist_title_error_from_dialog2){
		state_invalid_playlist_title_error_from_dialog2=0;
		dojo.lfx.wipeOut(invalid_playlist_title_error_from_dialog2).play();
	}
	//Send a request to create the new playlist
	var params=new Array(new_playlist_from_dialog_name.value, userid.value);
	send_request('create_new_playlist_from_dialog', params);
	//Send a request to reload the current playlist items.
	params=new Array(new_playlist_from_dialog_name.value, userid.value);
	send_request('reload_playlist_items', params);	
	//Hide the new playlist dialog box.
	new_playlist_dialog.hide(); 
}

//Function is called as a response from the server when create_new_playlist_from_dialog is called on the server.
function response_create_new_playlist_from_dialog(number_of_playlists, playlist_title){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var display_playlists=document.getElementById('display_playlists');
	var user_playlist_names=document.getElementById('playlist_names_table');
	var display_active_playlist=document.getElementById('display_active_playlist');
	var temp_videoid=document.getElementById('constants_videoid');
	//Update the active playlist.
	var temp_title=playlist_title.replace(/&#39;/g, "\\'");
	display_active_playlist.innerHTML='<a id="active_playlist_name" href="javascript: list_playlist_items(\''+temp_title+'\');">'+playlist_title+'</a>';
	//Update the number of playlists displayed.
	display_playlists.innerHTML=number_of_playlists;
	//Update the playlist names displayed.
	var temp_row=user_playlist_names.insertRow(user_playlist_names.rows.length);
	//Replace quotes for the id attribute.
	temp_title=playlist_title.replace(/&#39;/g, "#DS");
	temp_title=temp_title.replace(/&quot;/g, "#DD");
	temp_row.id='playlist_row_'+temp_title;
	var temp_cell=temp_row.insertCell(0);
	//Replace single quotes.
	temp_title=playlist_title.replace(/&#39;/g, "\\'");
	temp_cell.innerHTML='<a href="javascript: edit_playlist(\''+temp_title+'\');">'+playlist_title+'</a>';
	var params=new Array(temp_videoid.value, playlist_title, userid.value);
	send_request('add_video_to_playlist', params);
}

//Function is called as a response from the server when set_existing_active_playlist is called on the server.
function response_set_existing_active_playlist_from_dialog(number_of_playlists, playlist_title){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var temp_videoid=document.getElementById('constants_videoid');
	var display_playlists=document.getElementById('display_playlists');
	var user_playlist_names=document.getElementById('playlist_names_table');
	var display_active_playlist=document.getElementById('display_active_playlist');
	//Update the active playlist.
	temp_title=playlist_title.replace(/&#39;/g, "\\'");
	display_active_playlist.innerHTML='<a id="active_playlist_name" href="javascript: list_playlist_items(\''+temp_title+'\');">'+playlist_title+'</a>';
	//Update the number of playlists displayed.
	display_playlists.innerHTML=number_of_playlists;
	//Send a request to the server to format the added to playlist dialog and display it.  Also, add the video id to the playlist deatabase table for the specified user.
	var params=new Array(temp_videoid.value, playlist_title, userid.value);
	send_request('add_video_to_playlist', params);
	//Send a request to reload the current playlist items.
	params=new Array(playlist_title, userid.value);
	send_request('reload_playlist_items', params);
}

//Function to hide the login dialog.
function hide_login_dialog(){
	login_dialog.hide();
}

//Function to hide the select new active playlist dialog.
function hide_select_playlist_dialog(){
	select_playlist_dialog.hide();
}

//Function to hide the create new playlist dialog.
function hide_new_playlist_dialog(){
	new_playlist_dialog.hide();
}

//Function to hide the video has already been added to the playlist dialog.
function hide_video_already_exists_dialog(){
	try{
		video_already_exists_dialog.hide();
	}
	catch(err){
		dojo.lfx.wipeOut(document.getElementById('dialog_video_already_exists')).play();
	}
}

//Function to display the confirm remove video from playlist dialog.
function remove_video_from_playlist(videoid){
	//Initialize DOM HTML elements.
	var temp_videoid=document.getElementById('constants_videoid');
	//Set the temporary videoid.
	temp_videoid.value=videoid;
	try{
		remove_video_dialog.show();	
	}
	catch(err){
		if(confirm('Are you you want to remove the video?')){
			remove_video();
		}
	}
}

//Function to hide the confirm remove video dialog.
function close_remove_video_dialog(){
	remove_video_dialog.hide();
}

//Function to remove a video from a playlist.
function remove_video(){
	//Initialize DOM HTML elements.
	var temp_videoid=document.getElementById('constants_videoid');
	var temp_userid=document.getElementById('constants_userid');
	var current_playlist=document.getElementById('active_playlist_name');
	//Send a request to the server to remove the video from the playlist.
	var params=new Array(temp_videoid.value, current_playlist.innerHTML, temp_userid.value);
	send_request('remove_video_from_playlist', params);
}

//Function is called as a response from the server when remove_video_from_playlist is called on the server.
function response_remove_video_from_playlist(videoid){
	//Initialize the DOM HTML elements.
	var playlist_items_table=document.getElementById('playlist_items_table');
	var temp_row=document.getElementById('video_'+videoid);
	//Delete the table row the video is currently in.
	playlist_items_table.deleteRow(temp_row.rowIndex);
	try{
		remove_video_dialog.hide();
	}
	catch(err){
		return;
	}
	
}

//Function to display the DVD names table.
function display_dvd_names(){
	//Initialize the DOM HTML elements.
	var dvd_names=document.getElementById('dvd_names');
	var playlist_names=document.getElementById('playlist_names');
	var new_playlist=document.getElementById('new_playlist');
	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');
	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');
	var edit_playlist_div=document.getElementById('edit_playlist');
	var list_playlist_items_div=document.getElementById('playlist_items');
	var new_dvd=document.getElementById('new_dvd');
	var edit_dvd_div=document.getElementById('edit_dvd');
	var list_dvd_items_div=document.getElementById('dvd_items');
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');
	
	//Check if the div is already being displayed.
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}
	else{
		dojo.lfx.wipeIn(dvd_names).play();
		state_dvd_names=1;
	}
	//Check if any other divs should be hidden.
	if(state_playlist_names){
		dojo.lfx.wipeOut(playlist_names).play();
		state_playlist_names=0;
	}
	if(state_new_playlist){
		dojo.lfx.wipeOut(new_playlist).play();
		state_new_playlist=0;
	}
	if(state_new_playlist_missing_title_error){
		dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
		state_new_playlist_missing_title_error=0;
	}
	if(state_new_playlist_invalid_title_error){
		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
		state_new_playlist_invalid_title_error=0;
	}
	if(state_edit_playlist){
		dojo.lfx.wipeOut(edit_playlist_div).play();
		state_edit_playlist=0;
	}
	if(state_list_playlist_items){
		dojo.lfx.wipeOut(list_playlist_items_div).play();
		state_list_playlist_items=0;
	}
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}			
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd_div).play();
		state_edit_dvd=0;
	}
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_dvd_items=0;
	}
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}
}

//Function to display the new DVD form or submit the form data.
function submit_new_dvd(form){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var new_dvd=document.getElementById('new_dvd');
	var new_dvd_title=document.getElementById('new_dvd_title');
	var new_dvd_description=document.getElementById('new_dvd_description');	
	var new_dvd_missing_title_error=document.getElementById('new_dvd_missing_title_error');
	var playlist_names=document.getElementById('playlist_names');
	var new_playlist=document.getElementById('new_playlist');
	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');
	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');
	var edit_playlist_div=document.getElementById('edit_playlist');
	var list_playlist_items_div=document.getElementById('playlist_items');
	var dvd_names=document.getElementById('dvd_names');
	var edit_dvd_div=document.getElementById('edit_dvd');
	var list_dvd_items_div=document.getElementById('dvd_items');
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');
	
	//Check if form data is being submitted.
	if(form){
		//Check if a DVD title was provided.
		if(new_dvd_title.value){
			//Send a request to the server to create a new playlist.
			var params=new Array(new_dvd_title.value, new_dvd_description.value, userid.value);
			send_request('submit_new_dvd', params);
			return;
		}
		//A DVD title was not provided.
		else{
			//Display an error message.
			dojo.lfx.wipeIn(new_dvd_missing_title_error).play();
			state_new_dvd_missing_title_error=1;
			return;
		}
	}
	//Check if the new DVD form should be displayed.
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}
	else{
		dojo.lfx.wipeIn(new_dvd).play();
		state_new_dvd=1;
	}
	//Check if any other divs should be hidden.
	if(state_playlist_names){
		dojo.lfx.wipeOut(playlist_names).play();
		state_playlist_names=0;
	}
	if(state_new_playlist){
		dojo.lfx.wipeOut(new_playlist).play();
		state_new_playlist=0;
	}
	if(state_new_playlist_missing_title_error){
		dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
		state_new_playlist_missing_title_error=0;
	}
	if(state_new_playlist_invalid_title_error){
		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
		state_new_playlist_invalid_title_error=0;
	}
	if(state_edit_playlist){
		dojo.lfx.wipeOut(edit_playlist_div).play();
		state_edit_playlist=0;
	}
	if(state_list_playlist_items){
		dojo.lfx.wipeOut(list_playlist_items_div).play();
		state_list_playlist_items=0;
	}
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}	
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd_div).play();
		state_edit_dvd=0;
	}
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_dvd_items=0;
	}
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}
}

//Function is called as a response from the server when submit_new_dvd is called on the server.
function response_submit_new_dvd(error, number_of_dvds, dvd_title){
	//Initialize the DOM HTML elements.
	var new_dvd_invalid_title_error=document.getElementById('new_dvd_invalid_title_error');
	var new_dvd_missing_title_error=document.getElementById('new_dvd_missing_title_error');
	var new_dvd=document.getElementById('new_dvd');
	var display_dvds=document.getElementById('display_dvds');
	var new_dvd_title=document.getElementById('new_dvd_title');
	var new_dvd_description=document.getElementById('new_dvd_description');
	var user_dvd_names=document.getElementById('dvd_names_table');
	//Check if there was an error submitting the new DVD.
	if(error){
		dojo.lfx.wipeIn(new_dvd_invalid_title_error).play();
		state_new_dvd_invalid_title_error=1;		
	}
	else{
		//Update the number of dvds displayed.
		display_dvds.innerHTML=number_of_dvds;
		//Update the DVD names displayed.
		var temp_row=user_dvd_names.insertRow(user_dvd_names.rows.length);
		//Replace quotes for the id attribute.
		var temp_title=dvd_title.replace(/&#39;/g, "#DS");
		temp_title=temp_title.replace(/&quot;/g, "#DD");
		temp_row.id='dvd_row_'+temp_title;
		var temp_cell=temp_row.insertCell(0);
		//Replace single quotes.
		temp_title=dvd_title.replace(/&#39;/g, "\\'");
		temp_cell.innerHTML='<a href="javascript: edit_dvd(\''+temp_title+'\');">'+dvd_title+'</a>';
		//Reset the new playlist form and hide it.
		new_dvd_title.value='';
		new_dvd_description.value='';
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
		//Check if a previous title error message was displayed.
		if(state_new_dvd_missing_title_error){
			//Reset and hide the new DVD form.
			dojo.lfx.wipeOut(new_dvd_missing_title_error).play();
			state_new_dvd_title_error=0;
		}
		//Check if a previous title error message was displayed.
		if(state_new_dvd_invalid_title_error){
			//Reset and hide the new DVD form.
			dojo.lfx.wipeOut(new_dvd_invalid_title_error).play();
			state_new_dvd_invalid_title_error=0;
		}
	}	
}

//Function to display the edit dvd form with the dvd data in it.
function edit_dvd(dvd_title){
	//Initialize the DOM HTML elements.
	var edit_dvd_div=document.getElementById('edit_dvd');
	var edit_dvd_title=document.getElementById('edit_dvd_title');
	var userid=document.getElementById('constants_userid');

	var playlist_names=document.getElementById('playlist_names');

	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');

	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');

	var list_playlist_items_div=document.getElementById('playlist_items');
	var edit_playlist_div=document.getElementById('edit_playlist');
	var dvd_names=document.getElementById('dvd_names');
	var new_dvd=document.getElementById('new_dvd');
	var list_dvd_items_div=document.getElementById('dvd_items');
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');
	
	//Check if the edit DVD form should be submitted.
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd_div).play();
		state_edit_dvd=0;
	}
	else{
		//Set the playlist title on the form.
		edit_dvd_title.value=dvd_title;
		//Construct a parameter array and send a request to get the DVD description.
		var params=new Array(dvd_title, userid.value);
		send_request('get_dvd_description', params);
		//Construct a parameter array and send a request to get the DVD current property.
		params=new Array(dvd_title, userid.value);
		send_request('get_dvd_current', params);
		//Display the edit DVD form.
		dojo.lfx.wipeIn(edit_dvd_div).play();
		state_edit_dvd=1;
	}

	//Check if any DIV elements should be hidden.

	if(state_playlist_names){

		dojo.lfx.wipeOut(playlist_names).play();

		state_playlist_names=0;

	}

	if(state_new_playlist){

		dojo.lfx.wipeOut(new_playlist).play();

		state_new_playlist=0;

	}

	if(state_new_playlist_missing_title_error){

		dojo.lfx.wipeOut(new_playlist_missing_title_error).play();

		state_new_playlist_missing_title_error=0;

	}

	if(state_new_playlist_invalid_title_error){

		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();

		state_new_playlist_invalid_title_error=0;

	}	

	if(state_list_playlist_items){

		dojo.lfx.wipeOut(list_playlist_items_div).play();

		state_list_playlist_items=0;

	}
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}
	if(state_edit_playlist){
		dojo.lfx.wipeOut(edit_playlist_div).play();
		state_edit_playlist=0;
	}
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_dvd_items=0;
	}
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}
}

//Funtion is called as a response from the server when get_dvd_description is called on the server.
function response_get_dvd_description(description){
	//Initialize the DOM HTML elements.
	var edit_dvd_description=document.getElementById('edit_dvd_description');
	//Set the DVD description on the edit DVD form.
	var temp_description=description.replace(/&quot;/g, '"');
	temp_description=temp_description.replace(/&#39;/g, "'");
	edit_dvd_description.value=temp_description;
}

//Function is called as a response from the server when get_dvd_current is called on the server.
function response_get_dvd_current(current){
	//Initialize the DOM HTML elements.
	var edit_dvd_current=document.getElementById('edit_dvd_current');
	//Set the current DVD on the edit DVD form.
	if(current){
		edit_dvd_current.checked=true;
	}
	else{
		edit_dvd_current.checked=false;
	}
}

//Function to save changes made to a DVD.
function edit_dvd_save(){
	//Initialize the DOM HTML elements.
	var edit_dvd_title=document.getElementById('edit_dvd_title');
	var edit_dvd_description=document.getElementById('edit_dvd_description');
	var edit_dvd_current=document.getElementById('edit_dvd_current');
	var userid=document.getElementById('constants_userid');
	//Initialize the current variable.
	current=0;
	//If the current checkbox on the edit DVD form is selected, set the current variable to true.
	if(edit_dvd_current.checked){
		current=1;
	}
	//Construct a parameter array and send a request to update the modified DVD.
	params=new Array(edit_dvd_title.value, edit_dvd_description.value, current, userid.value);
	send_request('update_dvd', params);
}

//Function is called as a response from the server when update_dvd is called on the server.
function response_update_dvd(current_dvd){
	//Initialize the DOM HTML elements.
	var edit_dvd_div=document.getElementById('edit_dvd');
	var display_active_dvd=document.getElementById('display_active_dvd');
	var userid=document.getElementById('constants_userid');
	//Set the current DVD title.
	if(current_dvd=='None'){
		display_active_dvd.innerHTML=current_dvd;
	}
	else{
		var temp_title=current_dvd.replace(/&#39;/g, "'");
		//Send a request to reload the current DVD items.
		var params=new Array(temp_title, userid.value);
		send_request('reload_dvd_items', params);
		temp_title=current_dvd.replace(/&#39;/g, "\\'");
		display_active_dvd.innerHTML='<a id="active_dvd_name" href="javascript: list_dvd_items(\''+temp_title+'\');">'+current_dvd+'</a>';
	}
	//Hide the edit DVD form.
	dojo.lfx.wipeOut(edit_dvd_div).play();
	state_edit_dvd=0;	
}

//Function is called as a response from the server when reload_dvd_items is called on the server.
function response_reload_dvd_items(videos, preview_links, durations, dates, producers, new_running_time, dvdid){
	//Initialize DOM HTML elements.
	var dvd_items=document.getElementById('dvd_items_table');
	var dvd_running_time=document.getElementById('dvd_running_time');
	var show_shopping_cart=document.getElementById('constants_show_shopping_cart');
	var add_dvd_to_shopping_cart_link=document.getElementById('add_dvd_to_shopping_cart_link');
	//Reset the add DVD to shopping cart link.
	add_dvd_to_shopping_cart_link.innerHTML='<a href="javascript: add_dvd_to_shopping_cart('+dvdid+');">Add To Shopping Cart</a>';
	//Remove any existing DVD items.
	for (i=dvd_items.rows.length-1; i>=1; i--) {
		dvd_items.deleteRow(i);
	}
	//Iterate through the video ids.
	for (i=0; i<videos.length; i++){
		//Insert the video data into the DVD items table.
		var temp_row=dvd_items.insertRow(dvd_items.rows.length);
		temp_row.id='video_'+videos[i];
		//Replace the special characters in the video preview link.
		preview_links[i]=preview_links[i].replace(/&quot;/g, '"');
		temp_row.innerHTML='<td>'+preview_links[i]+'</td><td>'+durations[i]+'</td><td>'+dates[i]+'</td><td>'+producers[i]+'</td><td><a href="javascript: remove_video_from_dvd('+videos[i]+');">Remove Video</a></td>';
	}
	dvd_running_time.innerHTML=new_running_time+' min.';
}

//Function displays the confirm delete DVD dialog box.
function show_delete_dvd_confirm(){
	delete_dvd_dialog.show();
}

//Function to hide the confirm delete DVD dialog box.
function hide_delete_dvd_dialog(){
	delete_dvd_dialog.hide();
}

//Function to delete a DVD from the database.
function delete_dvd(){
	//Initialize the DOM HTML elements.
	var edit_dvd_title=document.getElementById('edit_dvd_title');
	var userid=document.getElementById('constants_userid');
	var display_active_dvd=document.getElementById('display_active_dvd');
	var dvd_names_table=document.getElementById('dvd_names_table');
	var temp_title=edit_dvd_title.value.replace(/"/g, '#DD');
	temp_title=temp_title.replace(/'/g, '#DS');
	var deleted_dvd_row=document.getElementById('dvd_row_'+temp_title);
	var edit_dvd_div=document.getElementById('edit_dvd');
	//Construct a parameter array and send a request to delete the DVD being edited.
	params=new Array(edit_dvd_title.value, userid.value);
	send_request('delete_dvd', params);
	//Delete the row that contains the DVD to be deleted.
	dvd_names_table.deleteRow(deleted_dvd_row.rowIndex);
	//Hide the confirm delete dialog.
	hide_delete_dvd_dialog();
	//Hide the edit DVD form.
	dojo.lfx.wipeOut(edit_dvd_div).play();
	state_edit_dvd=0;
}

//Function is called as a response from the server when delete_dvd is called on the server.
function response_delete_dvd(current_dvd, number_of_dvds){
	//Initialize the DOM HTML elements.
	var display_active_dvd=document.getElementById('display_active_dvd');
	var display_dvds=document.getElementById('display_dvds');
	//Set the current DVD title.
	if(current_dvd=='None'){
		display_active_dvd.innerHTML=current_dvd;
	}
	else{
		temp_title=current_dvd.replace(/&#39;/g, "\\'");
		display_active_dvd.innerHTML='<a id="active_dvd_name" href="javascript: list_dvd_items(\''+temp_title+'\');">'+current_dvd+'</a>';
	}
	//Set the number of DVDs belonging to the current front-end user.
	display_dvds.innerHTML=number_of_dvds;	
}

//Function to list all videos on the current DVD.
function list_dvd_items(title){
	//Initialize the DOM HTML elements.
	var list_dvd_items_div=document.getElementById('dvd_items');
	var list_playlist_items_div=document.getElementById('playlist_items');
	var userid=document.getElementById('constants_userid');
	var playlist_names=document.getElementById('playlist_names');
	var new_playlist=document.getElementById('new_playlist');

	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');

	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');

	var edit_playlist_div=document.getElementById('edit_playlist');
	var dvd_names=document.getElementById('dvd_names');
	var new_dvd=document.getElementById('new_dvd');
	var edit_dvd_div=document.getElementById('edit_dvd');
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');
	//Check if the div element should be hidden.
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_dvd_items=0;
	}
	else{
		dojo.lfx.wipeIn(list_dvd_items_div).play();
		state_list_dvd_items=1;
	}
	//Check if other div elements should be hidden.
	if(state_playlist_names){
		dojo.lfx.wipeOut(playlist_names).play();
		state_playlist_names=0;
	}
	if(state_new_playlist){
		dojo.lfx.wipeOut(new_playlist).play();
		state_new_playlist=0;
	}

	if(state_new_playlist_missing_title_error){

		dojo.lfx.wipeOut(new_playlist_missing_title_error).play();

		state_new_playist_missing_title_error=0;

	}

	if(state_new_playlist_invalid_title_error){

		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();

		state_new_playlist_invalid_title_error=0;

	}

	if(state_edit_playlist){

		dojo.lfx.wipeOut(edit_playlist_div).play();

		state_edit_playlist=0;

	}
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd_div).play();
		state_edit_dvd=0;
	}
	if(state_list_playlist_items){
		dojo.lfx.wipeOut(list_playlist_items_div).play();
		state_list_playlist_items=0;
	}
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}
}

//Function to add a video to a DVD.
function add_video_to_dvd(videoid){
	//Initialize DOM HTML elements.
	var temp_videoid=document.getElementById('constants_videoid');
	//Set the temp video id constant.
	temp_videoid.value=videoid;
	video_has_runtime(videoid);
}

//Function to check if the specified video has a runtime.
function video_has_runtime(videoid){
	var params=new Array();
	params=[videoid];
	send_request('video_has_runtime', params);
}

//Function is called as a response from the server when video_has_runtime is called on the server.
function response_video_has_runtime(exists){
	if(!exists){
		try{
			video_no_running_time_dialog.show();
		}
		catch(err){
			alert('The video cannot be added to DVD because it has no running time.');
		}
		return;
	}
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var current_dvd=document.getElementById('active_dvd_name');
	var temp_videoid=document.getElementById('constants_videoid');
	//Check if the front-end user has a current DVD set.  If no DVD is set, display the choose DVD dialog.
	try{
		var temp_dvd_name=current_dvd.innerHTML;
	}
	catch(err){
		//Send a request to the server to display the available DVDs dialog.
		var params=new Array(userid.value);
		send_request('set_new_active_dvd', params);
		return;
	}
	//Send a request to the server to format the added to DVD dialog and display it.  Also, add the video id to the DVD deatabase table for the specified user.
	var params=new Array(temp_videoid.value, current_dvd.innerHTML, userid.value);
	send_request('add_video_to_dvd', params);
} 

//Function is called as a response from the server when set_new_active_dvd is called on the server.
function response_set_new_active_dvd(dvd_titles){
	//Inititalize DOM HTML elements.
	var select_dvd_names=document.getElementById('select_dvd_names');
	//Remove any existing options in the select element.
	for(cnt in select_dvd_names.options){
		select_dvd_names.remove(cnt);
	} 
	//Add the new DVD option to the list of DVDs to select from.
	temp_option=document.createElement('option');
	temp_option.text='--New DVD--';
	//Append the option to the selection element depending on which method works (browser incompatibility issue).
	try{
		select_dvd_names.add(temp_option, null);
	}
	catch(err){
		select_dvd_names.add(temp_option, select_dvd_names.length);	
	}
	//Iterate through the DVD titles.
	for(cnt in dvd_titles){
		//Create the new option element that will be appended to the selection element.
		temp_option=document.createElement('option');
		//Replace the special characters in the current title.
		temp_title=dvd_titles[cnt];
		temp_title=temp_title.replace(/&#39;/g, "'");
		temp_title=temp_title.replace(/&quot;/g, '"');		
		//Set the text for the current option element.
		temp_option.text=temp_title;
		//Append the option to the selection element depending on which method works (browser incompatibility issue).
		try{
			select_dvd_names.add(temp_option, null);
		}
		catch(err){
			select_dvd_names.add(temp_option, dvd_playlist_names.length);	
		}
	}
	try{
		//Display the dialog.
		select_dvd_dialog.show();
	}
	catch(err){
		alert('Please select an active DVD.');
	}
}

//Function to set the active DVD via dojo dialogs.
function set_new_active_dvd(){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var select_dvd_names=document.getElementById('select_dvd_names');
	//Hide the select active DVD dialog.
	select_dvd_dialog.hide();
	//Check if a new DVD is being created.
	if(select_dvd_names.value=='--New DVD--'){
		new_dvd_dialog.show();
		return;
	}
	//Send a request to the server set the selected DVD as the active DVD.
	var params=new Array(select_dvd_names.value, userid.value);
	send_request('set_existing_active_dvd_from_dialog', params);
}

//Function is called as a response from the server when set_existing_active_dvd_from_dialog is called on the server.
function response_set_existing_active_dvd_from_dialog(number_of_dvds, dvd_title){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var temp_videoid=document.getElementById('constants_videoid');
	var display_dvds=document.getElementById('display_dvds');
	var user_dvd_names=document.getElementById('dvd_names_table');
	var display_active_dvd=document.getElementById('display_active_dvd');
	//Update the active DVD.
	temp_title=dvd_title.replace(/&#39;/g, "\\'");
	display_active_dvd.innerHTML='<a id="active_dvd_name" href="javascript: list_dvd_items(\''+temp_title+'\');">'+dvd_title+'</a>';
	//Update the number of DVDs displayed.
	display_dvds.innerHTML=number_of_dvds;
	//Send a request to the server to format the added to dvd dialog and display it.  Also, add the video id to the dvd database table for the specified user.
	var params=new Array(temp_videoid.value, dvd_title, userid.value);
	send_request('add_video_to_dvd', params);	
}

//Function is called as a response from the server when add_video_to_dvd is called on the server.
function response_add_video_to_dvd(exists, too_long, not_for_sale, video_title, dvd_title, videoid, video_duration, video_date, video_producers, video_preview_link, new_running_time){
	//Initialize DOM HTML elements.
	var added_video_title=document.getElementById('added_video_to_dvd_title');
	var added_dvd_title=document.getElementById('added_dvd_title');
	var not_added_video_title=document.getElementById('not_added_video_to_dvd_title');
	var not_added_dvd_title=document.getElementById('not_added_dvd_title');
	var temp_videoid=document.getElementById('constants_videoid');
	var dvd_items=document.getElementById('dvd_items_table');
	var dvd_running_time=document.getElementById('dvd_running_time');
	//Check if the video has already been added to the DVD.
	if(exists){
		//Set the video and DVD titles that were not added.
		not_added_video_title.innerHTML=video_title;
		not_added_dvd_title.innerHTML=dvd_title;
		try{
			video_already_exists_in_dvd_dialog.show();
		}
		catch(err){
			alert('The video '+video_title+' has already been added to the DVD '+dvd_title);
		}
		return;
	}
	//Check if the DVD will be too long if the video is added.
	if(too_long){
		try{
			dvd_too_long_dialog.show();
		}
		catch(err){
			alert('The video cannot be added to the DVD because it will exceed the maximum running time of 120 minutes.');
		}
		return;
	}
	//Check if the video is for sale.
	if(not_for_sale){
		try{
			video_not_for_sale_dialog.show();
		}
		catch(err){
			alert('This video is not for sale.');
		}
		return;
	}
	//Set the added video and DVD titles.
	added_video_title.innerHTML=video_title;
	added_dvd_title.innerHTML=dvd_title;
	try{
		//Display the added to dvd dialog.
		added_to_dvd_dialog.show();
	}
	catch(err){
		alert('The video '+video_title+' has been added to the DVD '+dvd_title);
	}
	//Set the DVD running time.
	dvd_running_time.innerHTML=new_running_time+' min.';
	//Insert the video data into the DVD items table.
	var temp_row=dvd_items.insertRow(dvd_items.rows.length);
	temp_row.id='video_'+videoid;
	try{
		temp_row.innerHTML='<td>'+video_preview_link+'</td><td>'+video_duration+'</td><td>'+video_date+'</td><td>'+video_producers+'</td><td><a href="javascript: remove_video_from_dvd('+videoid+');">Remove Video</a></td>';
	}
	catch(err){
		temp_cell=temp_row.insertCell(0);
		temp_cell.innerHTML=video_preview_link;
		temp_cell=temp_row.insertCell(1);
		temp_cell.innerHTML=video_duration;
		temp_cell=temp_row.insertCell(2);
		temp_cell.innerHTML=video_date;
		temp_cell=temp_row.insertCell(3);
		temp_cell.innerHTML=video_producers;
		temp_cell=temp_row.insertCell(4);
		temp_cell.innerHTML='<a href="javascript: remove_video_from_dvd('+videoid+');">Remove Video</a>';
	}
}

//Function to create a new DVD from a dojo dialog.
function create_new_dvd_from_dialog(){
	//Initialize DOM HTML elements.
	var temp_videoid=document.getElementById('constants_videoid');
	var userid=document.getElementById('constants_userid');
	var missing_dvd_title_error_from_dialog=document.getElementById('missing_dvd_title_error_from_dialog');
	var invalid_dvd_title_error_from_dialog1=document.getElementById('invalid_dvd_title_error_from_dialog1');
	var invalid_dvd_title_error_from_dialog2=document.getElementById('invalid_dvd_title_error_from_dialog2');
	var new_dvd_from_dialog_name=document.getElementById('new_dvd_from_dialog_name');
	//Check if the title is missing.
	if(new_dvd_from_dialog_name.value===''){
		//Check if previous error messages should be cleared.
		if(state_invalid_dvd_title_error_from_dialog1){
			state_invalid_dvd_title_error_from_dialog1=0;
			dojo.lfx.wipeOut(invalid_dvd_title_error_from_dialog1).play();
		}
		if(state_invalid_dvd_title_error_from_dialog2){
			state_invalid_dvd_title_error_from_dialog2=0;
			dojo.lfx.wipeOut(invalid_dvd_title_error_from_dialog2).play();
		}
		//Display the error message.
		state_missing_dvd_title_error_from_dialog=1;
		dojo.lfx.wipeIn(missing_dvd_title_error_from_dialog).play();
		return;
	}
	//Check for an invalid title.
	if(new_dvd_from_dialog_name.value=='--New DVD--'){
		//Check if previous error messages should be cleared.
		if(state_missing_dvd_title_error_from_dialog){
			state_missing_dvd_title_error_from_dialog=0;
			dojo.lfx.wipeOut(missing_dvd_title_error_from_dialog).play();
		}
		if(state_invalid_dvd_title_error_from_dialog2){
			state_invalid_dvd_title_error_from_dialog2=0;
			dojo.lfx.wipeOut(invalid_dvd_title_error_from_dialog2).play();
		}
		//Display the error message.
		state_invalid_dvd_title_error_from_dialog1=1;
		dojo.lfx.wipeIn(invalid_dvd_title_error_from_dialog1).play();
		return;
	}
	//Send a request to the server to check if the DVD title already exists.
	var params=new Array(new_dvd_from_dialog_name.value, userid.value);
	send_request('dvd_exists_from_dialog', params);
}

//Function is called as a response from the server when dvd_exists_from_dialog is called on the server.
function response_dvd_exists_from_dialog(exists){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var missing_dvd_title_error_from_dialog=document.getElementById('missing_dvd_title_error_from_dialog');
	var invalid_dvd_title_error_from_dialog1=document.getElementById('invalid_dvd_title_error_from_dialog1');
	var invalid_dvd_title_error_from_dialog2=document.getElementById('invalid_dvd_title_error_from_dialog2');
	var new_dvd_from_dialog_name=document.getElementById('new_dvd_from_dialog_name');
	//Check if the submitted DVD title already exists in the database.
	if(exists){
		//Check for any previous error messages that should be cleared.
		if(state_missing_dvd_title_error_from_dialog){
			state_missing_dvd_title_error_from_dialog=0;
			dojo.lfx.wipeOut(missing_dvd_title_error_from_dialog).play();
		}
		if(state_invalid_dvd_title_error_from_dialog1){
			state_invalid_dvd_title_error_from_dialog1=0;
			dojo.lfx.wipeOut(invalid_dvd_title_error_from_dialog1).play();
		}
		//Display the error message.
		state_invalid_dvd_title_error_from_dialog2=1;
		dojo.lfx.wipeIn(invalid_dvd_title_error_from_dialog2);
		return;
	}
	//Hide all previous error messages
	if(state_missing_dvd_title_error_from_dialog){
		state_missing_dvd_title_error_from_dialog=0;
		dojo.lfx.wipeOut(missing_dvd_title_error_from_dialog).play();
	}
	if(state_invalid_dvd_title_error_from_dialog1){
		state_invalid_dvd_title_error_from_dialog1=0;
		dojo.lfx.wipeOut(invalid_dvd_title_error_from_dialog1).play();
	}
	if(state_invalid_dvd_title_error_from_dialog2){
		state_invalid_dvd_title_error_from_dialog2=0;
		dojo.lfx.wipeOut(invalid_dvd_title_error_from_dialog2).play();
	}
	//Send a request to create the new DVD.
	var params=new Array(new_dvd_from_dialog_name.value, userid.value);
	send_request('create_new_dvd_from_dialog', params);
	//Hide the new DVD dialog box.
	new_dvd_dialog.hide(); 
}

//Function is called as a response from the server when create_new_dvd_from_dialog is called on the server.
function response_create_new_dvd_from_dialog(number_of_dvds, dvd_title){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	var display_dvds=document.getElementById('display_dvds');
	var dvd_names=document.getElementById('dvd_names_table');
	var display_active_dvd=document.getElementById('display_active_dvd');
	var temp_videoid=document.getElementById('constants_videoid');
	//Update the active DVD.
	var temp_title=dvd_title.replace(/&#39;/g, "\\'");
	display_active_dvd.innerHTML='<a id="active_dvd_name" href="javascript: list_dvd_items(\''+temp_title+'\');">'+dvd_title+'</a>';
	//Update the number of DVDs displayed.
	display_dvds.innerHTML=number_of_dvds;
	//Update the DVD names displayed.
	var temp_row=dvd_names.insertRow(dvd_names.rows.length);
	//Replace quotes for the id attribute.
	temp_title=dvd_title.replace(/&#39;/g, "#DS");
	temp_title=temp_title.replace(/&quot;/g, "#DD");
	temp_row.id='dvd_row_'+temp_title;
	var temp_cell=temp_row.insertCell(0);
	//Replace single quotes.
	temp_title=dvd_title.replace(/&#39;/g, "\\'");
	temp_cell.innerHTML='<a href="javascript: edit_dvd(\''+temp_title+'\');">'+dvd_title+'</a>';
	var params=new Array(temp_videoid.value, dvd_title, userid.value);
	send_request('add_video_to_dvd', params);
}

//Function to hide the select DVD dialog.
function hide_select_dvd_dialog(){
	select_dvd_dialog.hide();
}

//Function to hide the new DVD dialog.
function hide_new_dvd_dialog(){
	new_dvd_dialog.hide();
}

//Function to hide the added to DVD dialog.
function close_added_to_dvd_dialog(){
	added_to_dvd_dialog.hide();
}

//Function to hide the video already added to DVD dialog.
function hide_video_already_exists_in_dvd_dialog(){
	video_already_exists_in_dvd_dialog.hide();
}

//Funtion to hide the video no running time dialog.
function hide_video_no_running_time_dialog(){
	video_no_running_time_dialog.hide();
}

//Function to hide the DVD is too long dialog.
function hide_dvd_too_long_dialog(){
	dvd_too_long_dialog.hide();
}

//Function to display the confirm remove video from DVD dialog.
function remove_video_from_dvd(videoid){
	//Initialize DOM HTML elements.
	var temp_videoid=document.getElementById('constants_videoid');
	//Set the temporary videoid.
	temp_videoid.value=videoid;
	try{
		remove_video_from_dvd_dialog.show();	
	}
	catch(err){
		if(confirm('Are you sure you want to remove the video?')){
			exec_remove_video_from_dvd();
		}
	}
}

//Function to remove a video from a DVD.
function exec_remove_video_from_dvd(){
	//Initialize DOM HTML elements.
	var temp_videoid=document.getElementById('constants_videoid');
	var temp_userid=document.getElementById('constants_userid');
	var current_dvd=document.getElementById('active_dvd_name');
	//Send a request to the server to remove the video from the DVD.
	var params=new Array(temp_videoid.value, current_dvd.innerHTML, temp_userid.value);
	send_request('remove_video_from_dvd', params);
}

//Function is called as a response from the server when remove_video_from_dvd is called on the server.
function response_remove_video_from_dvd(videoid, new_running_time){
	//Initialize the DOM HTML elements.
	var dvd_items_table=document.getElementById('dvd_items_table');
	var temp_row=document.getElementById('video_'+videoid);
	var dvd_running_time=document.getElementById('dvd_running_time');
	//Delete the table row the video is currently in.
	//Initiliaze the table row index counter.
	var cnt=0;
	//Iterate through the table rows.
	for(i in dvd_items_table.rows){
		try{
			//Check if the current row is the row to delete.
			if(dvd_items_table.rows[i].id=='video_'+videoid){
				//Check if the browser is IE.
				if(navigator.appName=='Microsoft Internet Explorer'){
					//Remove the table row.
					dvd_items_table.deleteRow(cnt-1);
					break;
				}
				//A normal browser.
				else{
					//Remove the table row.
					dvd_items_table.deleteRow(i);
					break;
				}
			}
			//Increment the counter.
			cnt++;
		}
		catch(err){
			//Intrement the counter.
			cnt++;
			continue;
		}
	}
	//Update the DVD running time.
	dvd_running_time.innerHTML=new_running_time+' min.';
	try{
		remove_video_from_dvd_dialog.hide();
	}
	catch(err){
		return;
	}
}

//Function to hide the remove video from DVD dialog.
function close_remove_video_from_dvd_dialog(){
	remove_video_from_dvd_dialog.hide();
}

//Function to display the shopping cart items HTML DIV.
function display_shopping_cart_items(){
	//Initialize the HTML DOM elements.
	var shopping_cart_items_div=document.getElementById('shopping_cart_items');
	var playlist_names=document.getElementById('playlist_names');
	var new_playlist=document.getElementById('new_playlist');
	var new_playlist_missing_title_error=document.getElementById('new_playlist_missing_title_error');
	var new_playlist_invalid_title_error=document.getElementById('new_playlist_invalid_title_error');
	var edit_playlist_div=document.getElementById('edit_playlist');
	var dvd_names=document.getElementById('dvd_names');
	var new_dvd=document.getElementById('new_dvd');
	var edit_dvd_div=document.getElementById('edit_dvd');
	var list_dvd_items_div=document.getElementById('dvd_items');
	var list_playlist_items_div=document.getElementById('playlist_items');
	
	if(state_shopping_cart_items){
		dojo.lfx.wipeOut(shopping_cart_items_div).play();
		state_shopping_cart_items=0;
	}
	else{
		dojo.lfx.wipeIn(shopping_cart_items_div).play();
		state_shopping_cart_items=1;
	}
	//Check if other DIV elements should be hidden.
	if(state_playlist_names){
		dojo.lfx.wipeOut(playlist_names).play();
		state_playlist_names=0;
	}
	if(state_new_playlist){
		dojo.lfx.wipeOut(new_playlist).play();
		state_new_playlist=0;
	}
	if(state_new_playlist_missing_title_error){
		dojo.lfx.wipeOut(new_playlist_missing_title_error).play();
		state_new_playlist_missing_title_error=0;
	}
	if(state_new_playlist_invalid_title_error){
		dojo.lfx.wipeOut(new_playlist_invalid_title_error).play();
		state_new_playlist_invalid_title_error=0;
	}
	if(state_edit_playlist){
		dojo.lfx.wipeOut(edit_playlist_div).play();
		state_edit_playlist=0;
	}
	if(state_dvd_names){
		dojo.lfx.wipeOut(dvd_names).play();
		state_dvd_names=0;
	}
	if(state_new_dvd){
		dojo.lfx.wipeOut(new_dvd).play();
		state_new_dvd=0;
	}
	if(state_edit_dvd){
		dojo.lfx.wipeOut(edit_dvd_div).play();
		state_edit_dvd=0;
	}
	if(state_list_dvd_items){
		dojo.lfx.wipeOut(list_dvd_items_div).play();
		state_list_dvd_items=0;
	}
	if(state_list_playlist_items){
		dojo.lfx.wipeOut(list_playlist_items_div).play();
		state_list_playlist_items=0;
	}
}

//Function to add a DVD to the shopping cart.
function add_dvd_to_shopping_cart(dvdid){
	//Initialize DOM HTML elements.
	var temp_dvdid=document.getElementById('constants_dvdid');
	var userid=document.getElementById('constants_userid');
	//Set the temp DVD id constant.
	temp_dvdid.value=dvdid
	var params=new Array(dvdid, userid.value);
	send_request('shopping_cart_has_dvd', params);	
}

//Function is called as a response from the server when shopping_cart_has_dvd is called on the server.
function response_shopping_cart_has_dvd(has_dvd, dvd_title){
	//Initialize DOM HTML elements.
	var temp_dvdid=document.getElementById('constants_dvdid');
	var userid=document.getElementById('constants_userid');
	var not_added_title=document.getElementById('not_added_dvd_to_shopping_cart_title');
	//Check if the front-end user's shopping cart already contains the DVD specified.
	if(has_dvd){
		not_added_title.innerHTML=dvd_title;
		try{
			dvd_already_exists_in_shopping_cart_dialog.show();	
		}
		catch(err){
			alert('The DVD has already been added to the shopping cart.');
		}
		return;
	}
	//Send a request to the server to check if the specified DVD contains any videos.
	var params=new Array(temp_dvdid.value, userid.value);
	send_request('dvd_has_videos', params);	
}

//Function is called as a response from the server when dvd_has_videos is called on the server.
function response_dvd_has_videos(has_videos, dvdid){
	//Initialize DOM HTML elements.
	var userid=document.getElementById('constants_userid');
	//Check if the DVD has any videos.
	if(has_videos){
		//Send a request to the server to format the added DVD dialog and display it.
		var params=new Array(dvdid, userid.value);
		send_request('add_dvd_to_shopping_cart', params);
		return;
	}
	try{
		empty_dvd_dialog.show();
	}
	catch(err){
		alert('Please add some videos to your DVD before adding it to the shopping cart.');
	}
}

//Function is called as a response from the server when add_dvd_to_shopping_cart is called on the server.
function response_add_dvd_to_shopping_cart(dvdid, dvd_name, item_cost, cart_total){
	//Initialize DOM HTML elements.
	var shopping_cart_items_table=document.getElementById('shopping_cart_items_table');
	var shopping_cart_total=document.getElementById('shopping_cart_total');
	var added_dvd_title=document.getElementById('added_dvd_to_shopping_cart_title');
	//Display the added DVD to shopping cart dialog.
	added_dvd_title.innerHTML=dvd_name;
	try{
		added_dvd_to_shopping_cart_dialog.show();
	}
	catch(err){
		alert('The DVD '+dvd_name+' has been added to the shopping cart.');
	}
	//Set the new shopping cart total.
	shopping_cart_total.innerHTML='$'+cart_total+' <i>USD</i>';
	//Add the new table row.
	temp_row=shopping_cart_items_table.insertRow(shopping_cart_items_table.rows.length);
	temp_row.id='shopping_cart_item_'+dvdid;
	try{
		temp_row.innerHTML='<td>'+dvd_name+'</td><td>DVD</td><td>$'+item_cost+'</td><td><a href="javascript: remove_dvd_from_shopping_cart('+dvdid+');">Remove DVD</a></td>';
	}
	catch(err){
		temp_cell=temp_row.insertCell(0);
		temp_cell.innerHTML=dvd_name;
		temp_cell=temp_row.insertCell(1);
		temp_cell.innerHTML='DVD';
		temp_cell=temp_row.insertCell(2);
		temp_cell.innerHTML='$'+item_cost;
		temp_cell=temp_row.insertCell(3);
		temp_cell.innerHTML='<a href="javascript: remove_dvd_from_shopping_cart('+dvdid+');">Remove DVD</a>';
	}
}

//Function to hide the DVD has already been added to the shopping cart dialog.
function hide_dvd_already_exists_in_shopping_cart_dialog(){
	dvd_already_exists_in_shopping_cart_dialog.hide();
}

//Function to hide the added DVD to shopping cart dialog.
function hide_dvd_added_to_shopping_cart_dialog(){
	added_dvd_to_shopping_cart_dialog.hide();
}

//Function to remove a DVD from the shopping cart.
function remove_dvd_from_shopping_cart(dvdid){
	//Initialize DOM HTML elements.
	var temp_dvdid=document.getElementById('constants_dvdid');
	temp_dvdid.value=dvdid;
	try{
		remove_dvd_from_shopping_cart_dialog.show();	
	}
	catch(err){
		if(confirm('Your you sure you want to remove the DVD?')){
			remove_dvd_from_shopping_cart_confirm();
		}
	}
}

//Function is called when yes is clicked in the confirm remove DVD from shopping cart dialog.
function remove_dvd_from_shopping_cart_confirm(){
	//Initialize DOM HTML elements.
	var temp_dvdid=document.getElementById('constants_dvdid');
	var userid=document.getElementById('constants_userid');
	//Send a request to remove the specified DVD from the shopping cart.
	var params=new Array(temp_dvdid.value, userid.value);
	send_request('remove_dvd_from_shopping_cart', params);
}

//Function is called as a response from the server when remove_dvd_from_shopping_cart is called on the server.
function response_remove_dvd_from_shopping_cart(dvdid, new_total){
	//Initialize DOM HTML elements.
	var shopping_cart_items_table=document.getElementById('shopping_cart_items_table');
	var temp_row=document.getElementById('shopping_cart_item_'+dvdid);
	var shopping_cart_total=document.getElementById('shopping_cart_total');
	//Delete the row the DVD is currently in.
	shopping_cart_items_table.deleteRow(temp_row.rowIndex);
	//Update the shopping cart total.
	shopping_cart_total.innerHTML='$'+new_total+' <i>USD</i>';
	try{
		remove_dvd_from_shopping_cart_dialog.hide();
	}
	catch(err){
		return;
	}
}

//Function to hide the empty DVD dialog.
function hide_empty_dvd_dialog(){
	empty_dvd_dialog.hide();
}

//Function to hide the remove dvd from shopping cart dialog.
function remove_dvd_from_shopping_cart_decline(){
	remove_dvd_from_shopping_cart_dialog.hide();
}

function hide_video_not_for_sale_dialog(){
	video_not_for_sale_dialog.hide();
}
