// Define ajax var 
var ajax;
var $WebRoot = '/';
var $CMSSub = 'cms.clevver.com';

// Function to auto build user URL
function BuildURL(){
	var lname = document.getElementById("LoginName");
	var user_url = document.getElementById("user_url");
	user_url.firstChild.nodeValue = lname.value;
}

// Function to auto build user LoginName
function BuildLoginName(){
	var lname = document.getElementById("Title");
	var LoginName_text = document.getElementById("LoginName");
	document.form1.LoginName.value=CleanText(lname.value);
	var user_url = document.getElementById("user_url");
	user_url.firstChild.nodeValue=CleanText(lname.value);
}

// Function to auto build user LoginName
function BuildArtistLoginName(){
	var lname = document.getElementById("Name");
	var LoginName_text = document.getElementById("LoginName");
	document.form1.LoginName.value=CleanText(lname.value);
	var user_url = document.getElementById("user_url");
	user_url.firstChild.nodeValue=CleanText(lname.value);
}

// Function to remove all special characters and spaces from a text string
function CleanText(str) {
re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\ |\./g;
	// remove special characters like "$" and "," etc...
	var CleanText=str.replace(re, "");
	var CleanText = CleanText.replace(/[^\w]+/g,"");
	var ToLower=CleanText.toLowerCase();
	return ToLower;
}

// Function to verify a LoginName is available
function CheckLoginName() {
var str=document.form1.LoginName.value;
 ajax =  new Ajax.Updater(
         'login_check',
         $WebRoot + 'admin_ajax.php?A=CL&N=' + str,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){ } 
         });

}

function CheckNewLogin(newpass){
	if(document.form1.EnableLogin.checked == true){
		document.form1.Email.disabled = false;
		document.form1.Password.disabled = false;
		document.form1.Password.value = newpass;
	} else {
		document.form1.Email.disabled = true;
		document.form1.Password.disabled = true;
		document.form1.Email.value = '';
		document.form1.Password.value = '';
	}	
}

function CheckReleaseDate(){
	if(document.form1.ReleaseDate.checked == true){
		document.form1.Date_Month.disabled = true;
		document.form1.Date_Day.disabled = true;
		document.form1.Date_Year.disabled = true;
	} else {
		document.form1.Date_Month.disabled = false;
		document.form1.Date_Day.disabled = false;
		document.form1.Date_Year.disabled = false;
	}	
}

// this function will return the value of a checked Sub type radio button
function GetSubType()
{
	var SubType_val="";
for (var i=0; i < document.form1.SubType.length; i++)
   {
   if (document.form1.SubType[i].checked)
      {
      SubType_val = document.form1.SubType[i].value;   
       return SubType_val;
      }
   }
   
}

// this function will either enable or disable the file upload option
function CheckFrameUpload(type){
	if(type=='video'){
		document.form1.upfile_0.disabled = true;
	} else {
		document.form1.upfile_0.disabled = false;
	}	
}

// this function will enable required form fields for different hosting options
function ChangeHosted(type){
	if(type=='local'){
		document.form1.Ex56.disabled = true;
		document.form1.Ex300.disabled = true;
		document.form1.Filename.disabled = false;
		document.form1.ScreenType[0].disabled = false;
	} else {
		document.form1.Ex56.disabled = false;
		document.form1.Ex300.disabled = false;
		document.form1.Filename.disabled = true;
		document.form1.ScreenType[0].disabled = true;
		document.form1.ScreenType[1].checked = true;
	}	
}

// This function runs the get_frames functions again if the filename changes
function UpdateFrames(file_name, type, sub_type){
	if(document.form1.ScreenType[1].checked==true){
		get_frames(file_name, type, sub_type);
	}
}

// Function to get framecap images from encoding server
function get_frames(file_name, type, sub_type, selected, fcmulti) {
	show_wait('framediv');
 ajax =  new Ajax.Updater(
         'framediv',
         $WebRoot + 'admin_get_remote_frames.php?T=' + type + '&F=' + file_name + '&ST=' + sub_type + '&S=' + selected + '&FCM=' + fcmulti,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){ } 
         });

}

// Function to display wait screen for given div
function show_wait(divname) {
 ajax = new Ajax.Updater(divname, $WebRoot + 'ajax.php?A=WAIT', {method:'get'});
}

function show_wait_small(divname) {
 ajax = new Ajax.Updater(divname, $WebRoot + 'ajax.php?A=WAITSM', {method:'get'});
}


// Function to filter admin search results by Status type - MOVIE SECTION
function filter_results(filter_type, search_string, search_type) {
 show_wait('search_results');
 ajax =  new Ajax.Updater(
         'search_results',
         $WebRoot + 'admin_ajax.php?A=FS&ST=' + search_type + '&Q=' + search_string + '&T=' + filter_type,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('search_results');} 
         });

}

// Function to filter admin search results by Status type - MUSIC SECTION
function filter_music_results(filter_type, search_string, search_type) {
 show_wait('search_results');
 ajax =  new Ajax.Updater(
         'search_results',
         $WebRoot + 'admin_ajax.php?A=AS&ST=' + search_type + '&Q=' + search_string + '&T=' + filter_type,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('search_results');} 
         });

}

// Function to filter admin search results by Status type - VIDEO GAME SECTION
function filter_game_results(filter_type, search_string, search_type) {
 show_wait('search_results');
 ajax =  new Ajax.Updater(
         'search_results',
         $WebRoot + 'admin_ajax.php?A=GS&ST=' + search_type + '&Q=' + search_string + '&T=' + filter_type,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('search_results');} 
         });

}

// Function to filter admin search results by Status type - TV SECTION
function filter_tv_results(filter_type, search_string, search_type) {
 show_wait('search_results');
 ajax =  new Ajax.Updater(
         'search_results',
         $WebRoot + 'admin_ajax.php?A=TS&ST=' + search_type + '&Q=' + search_string + '&T=' + filter_type,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('search_results');} 
         });

}

// Function to filter admin search results by Status type - CLEVVER TV SECTION
function filter_show_results(filter_type, search_string, search_type) {
 show_wait('search_results');
 ajax =  new Ajax.Updater(
         'search_results',
         $WebRoot + 'admin_ajax.php?A=CS&ST=' + search_type + '&Q=' + search_string + '&T=' + filter_type,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('search_results');} 
         });

}

// Function to get clips type for the home features sections
function get_type_menu(Type) {
 show_wait_small('clip_type_menu');
 ajax =  new Ajax.Updater(
         'clip_type_menu',
         $WebRoot + 'admin_ajax.php?A=GCT&T=' + Type,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('clip_type_menu');} 
         });

}

// Function to get clips for the features sections
function get_clips(ID, Type) {
 show_wait_small('clips_menu');
 ajax =  new Ajax.Updater(
         'clips_menu',
         $WebRoot + 'admin_ajax.php?A=GC&ID=' + ID + '&T=' + Type,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('clips_menu');} 
         });

}

// Function to lookup artist albums
function get_artist_albums(aid) {
	show_wait('album_info');
	 ajax =  new Ajax.Updater(
			 'album_info',
			 $WebRoot + 'admin_ajax.php?A=LA&AID=' + aid,
			 {
			 method:'get',
			 asynchronous:true,
			 onComplete:function(){new Effect.Highlight('album_info');} 
			 });	 
}

// Function to change "pages" in video comments
function move_comments(vid,offset) {
 ajax =  new Ajax.Updater(
         'comments_list',
         'http://' + $CMSSub + $WebRoot + 'ajax.php?A=CP&v=' + vid + '&o=' + offset,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('comments_list');} 
         });

}

// Function to delete comments
function delete_comments(cid,vid) {
	if(confirm('Are you sure you want to delete this comment?')){
	 ajax =  new Ajax.Updater(
			 'comments_list',
			 'http://' + $CMSSub + $WebRoot + 'ajax.php?A=CD&c=' + cid + '&v=' + vid + '&o=0',
			 {
			 method:'get',
			 asynchronous:true,
			 onComplete:function(){new Effect.Highlight('comments_list');} 
			 });
	}	 
}

// Function to add a video to "my favorites"
function fav(vid) {
 ajax =  new Ajax.Updater(
         'add_to_favs',
         'http://' + $CMSSub + $WebRoot + 'ajax.php?A=FV&v=' + vid,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('add_to_favs');} 
         });

}

// Function to flag a video as inappropriate
function flag(vid) {
	if(confirm('Are you sure you want to flag this video? A notice will be sent to the site administrator.')){
	 ajax =  new Ajax.Updater(
         'flag_video',
         'http://' + $CMSSub + $WebRoot + 'ajax.php?A=IV&v=' + vid,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('flag_video');} 
         });
	}
}

// Function to flag a comment as inappropriate
function flag_comment(cid,vid) {
	if(confirm('Are you sure you want to flag this comment? A notice will be sent to the site administrator.')){
	 ajax =  new Ajax.Updater(
         'comments_flagd[' + cid + ']',
         'http://' + $CMSSub + $WebRoot + 'ajax.php?A=IC&c=' + cid + '&v=' + vid,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('comments_flagd[' + cid + ']');} 
         });
	}
}

// Function to recommend a video
function recommend(vid) {
	Effect.SlideUp('recommend_video',{delay:0.0, duration: 0.5}); 
	vid_id=vid;
	setTimeout("recommend_do(vid_id);", 500);
	Effect.SlideDown('recommend_video',{delay:1.0, duration:0.5});
}

// Function to recommend a video, called from above function
function recommend_do(vid) {
	ajax =  new Ajax.Updater(
         'recommend_video',
         'http://' + $CMSSub + $WebRoot + 'ajax.php?A=RV&v=' + vid,
         {
         method:'get',
         asynchronous:true
         });
}

// Function to check for required fields in the STAF form
function verify_staf(){
	var error_message = '';
	
	if(document.form2.YourName.value==''){
		error_message += "\r\nYour name is required.";
	}
	
	if(document.form2.YourEmail.value==''){
		error_message += "\r\nYour email is required.";
	}
	
	if(document.form2.FriendName.value==''){
		error_message += "\r\nYour friend's name is required.";
	}
	
	if(document.form2.FriendEmail.value==''){
		error_message += "\r\nYour friend's email is required.";
	}
	
	if(error_message!=''){
		alert("There was an error sending your message: \r\n" + error_message);
		return false;
	} else {
		return true;
	}
}

// Function to perform "approve all" on video approval page
function approve_all(num_vids){
	for (var x = 1; x <= num_vids; x++) {
		document.getElementById("VideoApprove" + x).checked=true;
	}	
}

// Function to change selector on the home page Movies section
function change_home_movies(type) {
	// set default styling for all features
	document.getElementById("mov_feat").className = "mod_men_it";
	document.getElementById("mov_view").className = "mod_men_it";
	document.getElementById("mov_recommend").className = "mod_men_it";
	document.getElementById("mov_recent").className = "mod_men_it";	
	
	// set selected styling for given feature
	document.getElementById("mov_" + type).className = "mod_men_or";

 ajax =  new Ajax.Updater(
         'home_movies',
         $WebRoot + 'ajax.php?A=CHM&T=' + type,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('home_movies', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change selector on the home page Music section
function change_home_music(type) {
	// set default styling for all features
	document.getElementById("mus_feat").className = "mod_men_it";
	document.getElementById("mus_view").className = "mod_men_it";
	document.getElementById("mus_recommend").className = "mod_men_it";
	document.getElementById("mus_recent").className = "mod_men_it";	
	
	// set selected styling for given feature
	document.getElementById("mus_" + type).className = "mod_men_or";

 ajax =  new Ajax.Updater(
         'home_music',
         $WebRoot + 'ajax.php?A=CHU&T=' + type,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('home_music', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change selector on the home page Video Games section
function change_home_games(type) {
	// set default styling for all features
	document.getElementById("gam_feat").className = "mod_men_it";
	document.getElementById("gam_view").className = "mod_men_it";
	document.getElementById("gam_recommend").className = "mod_men_it";
	document.getElementById("gam_recent").className = "mod_men_it";	
	
	// set selected styling for given feature
	document.getElementById("gam_" + type).className = "mod_men_or";

 ajax =  new Ajax.Updater(
         'home_games',
         $WebRoot + 'ajax.php?A=CHG&T=' + type,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('home_games', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change selector on the home page TV section
function change_home_tv(type) {
	// set default styling for all features
	document.getElementById("tv_feat").className = "mod_men_it";
	document.getElementById("tv_view").className = "mod_men_it";
	document.getElementById("tv_recommend").className = "mod_men_it";
	document.getElementById("tv_recent").className = "mod_men_it";	
	
	// set selected styling for given feature
	document.getElementById("tv_" + type).className = "mod_men_or";

 ajax =  new Ajax.Updater(
         'home_tv',
         $WebRoot + 'ajax.php?A=CHT&T=' + type,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('home_tv', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change selector on the home page User Video section
function change_home_user(type) {
	// set default styling for all features
	document.getElementById("usr_feat").className = "mod_men_it";
	document.getElementById("usr_view").className = "mod_men_it";
	document.getElementById("usr_recommend").className = "mod_men_it";
	document.getElementById("usr_recent").className = "mod_men_it";	
	
	// set selected styling for given feature
	document.getElementById("usr_" + type).className = "mod_men_or";

 ajax =  new Ajax.Updater(
         'home_user',
         $WebRoot + 'ajax.php?A=CHUV&T=' + type,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('home_user', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change selector on the home page TV section
function change_home_ctv(type) {
	// set default styling for all features
	document.getElementById("ctv_feat").className = "mod_men_it";
	document.getElementById("ctv_view").className = "mod_men_it";
	document.getElementById("ctv_espanol").className = "mod_men_it";
	document.getElementById("ctv_gossip").className = "mod_men_it";
	document.getElementById("ctv_music").className = "mod_men_it";
	document.getElementById("ctv_movies").className = "mod_men_it";	
	
	// set selected styling for given feature
	document.getElementById("ctv_" + type).className = "mod_men_or";

 ajax =  new Ajax.Updater(
         'home_ctv',
         $WebRoot + 'ajax.php?A=CHC&T=' + type,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('home_ctv', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change timeframe on most watched section
function change_most_watched(TF) {
 ajax =  new Ajax.Updater(
         'most_watched',
         $WebRoot + 'ajax.php?A=TOP4&TF=' + TF,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('most_watched', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change timeframe on most recommended section
function change_most_recommended(TF) {
 ajax =  new Ajax.Updater(
         'most_recommend',
         $WebRoot + 'ajax.php?A=TOP4R&TF=' + TF,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('most_recommend', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change timeframe on most inappropriate section
function change_most_inappropriate(TF) {
 ajax =  new Ajax.Updater(
         'most_inappropriate',
         $WebRoot + 'ajax.php?A=TOP4I&TF=' + TF,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('most_inappropriate', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change timeframe on most viewed section
function change_most_viewed(TF) {
 ajax =  new Ajax.Updater(
         'most_viewed',
         $WebRoot + 'ajax.php?A=TOP4MV&TF=' + TF,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('most_viewed', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to change timeframe on most talked section
function change_most_talked(TF) {
 ajax =  new Ajax.Updater(
         'most_talked',
         $WebRoot + 'ajax.php?A=TOP4MT&TF=' + TF,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('most_talked', {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

// Function to select connection speed for player
function play_low(vid, username) {
 ajax =  new Ajax.Updater(
         'player_box',
         $WebRoot + 'ajax.php?A=PLAY56&v=' + vid + '&u=' + username,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){} 
         });

}

function play_med(vid, username) {
 ajax =  new Ajax.Updater(
         'player_box',
         $WebRoot + 'ajax.php?A=PLAY100&v=' + vid + '&u=' + username,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){} 
         });

}

function play_high(vid, username) {
 ajax =  new Ajax.Updater(
         'player_box',
         $WebRoot + 'ajax.php?A=PLAY300&v=' + vid + '&u=' + username,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){} 
         });

}

function load_brightcove($player_id, $width, $height, $vid){
	// By use of this code snippet, I agree to the Brightcove Publisher T and C 
	// found at http://www.brightcove.com/publishertermsandconditions.html. 

	var config = new Array();

	/* 
	* feel free to edit these configurations
	* to modify the player experience
	*/

	config["videoId"] = $vid; //the default video loaded into the player
	config["videoRef"] = null; //the default video loaded into the player by ref id specified in console
	config["lineupId"] = null; //the default lineup loaded into the player
	config["playerTag"] = null; //player tag used for identifying this page in brightcove reporting
	config["autoStart"] = true; //tells the player to start playing video on load
	config["preloadBackColor"] = "#FFFFFF"; //background color while loading the player 
	config["externalAds"] = true;

	/* 
	* set the player's size using the parameters below
	* to make this player dynamically resizable, set the width and height as a percentage
	*/

	config["width"] = $width;
	config["height"] = $height; 
	config["playerId"] = $player_id;  
	createExperience(config, 8);
}

function load_wmg_brightcove($player_id, $width, $height, $vid){
	var config = new Array();
	 config["videoId"] = $vid; //the default video loaded into the player
	 config["videoRef"] = null; //the default video loaded into the player by ref id specified in console
	 config["lineupId"] = null; //the default lineup loaded into the player
	 config["playerTag"] = null; //player tag used for identifying this page in brightcove reporting
	 config["autoStart"] = true; //tells the player to start playing video on load
	 config["preloadBackColor"] = "#000000"; //background color while loading the player
	 config["continuousPlay"] = "false";
	 config["wmode"] = "transparent";  //SCANSCOUT: Must be done for overlay


	 config["playerId"] = $player_id;
	 config["width"] = $width;
	 config["height"] = $height;

	 createExperience(config, 8);
}

function resize(img, height, width){
	
	 if(img.height>height || img.width>width){

		var new_height=getimageheightfromwidth(img.width, img.height, width);
		var new_width=getimagewidthfromheight(img.height, img.width, height);
		
		if(new_height > new_width){
			// if height is larger than allowed, resize by height
			var resize_percentage = (height/img.height);	
		} else if(new_width > width){
			// if width is larger than allowed, resize by width
			var resize_percentage = (width/img.width);
		} else {
			// if neither, just go by width
			var resize_percentage = (width/img.width);
		}
		
		var destination_percent_y = (resize_percentage * 100);
		var destination_percent_x = (resize_percentage * 100);

		var destination_size_x = Math.round(img.width * ( destination_percent_x / 100 )); 
		var destination_size_y = Math.round(img.height * ( destination_percent_y / 100 )); 
	 
	 } else {
	
		var destination_size_x = img.width; 
		var destination_size_y = img.height; 
	 
	 }
	
    // resize the image
    img.width = destination_size_x;
    img.height = destination_size_y;
    img.style.display = "inline";
}

function resizeh(img, height){
	
	 if(img.height>height){

		var new_width=getimagewidthfromheight(img.height, img.width, height);
		
		// if height is larger than allowed, resize by height
		var resize_percentage = (height/img.height);	
		
		var destination_percent_y = (resize_percentage * 100);
		var destination_percent_x = (resize_percentage * 100);

		var destination_size_x = Math.round(img.width * ( destination_percent_x / 100 )); 
		var destination_size_y = Math.round(img.height * ( destination_percent_y / 100 )); 
	 
	 } else {
	
		var destination_size_x = img.width; 
		var destination_size_y = img.height; 
	 
	 }
	
    // resize the image
    img.width = destination_size_x;
    img.height = destination_size_y;
    img.style.visibility = "visible";
    // not sure how to discard of the img object
    // the next line does not work in IE thats why its in
    // a try and catch
    try{
        delete this;
    }catch(e){}
}

function getimageheightfromwidth(orig_width, orig_height, new_width){
	var new_width;
	var resize_percentage = (new_width/orig_width);
	var new_height = Math.round(orig_height * resize_percentage); 
	return new_height;
}
	
function getimagewidthfromheight(orig_height, orig_width, new_width){
	var new_height;
	var resize_percentage = (new_height/orig_height);
	var new_width = Math.round(orig_width * resize_percentage); 
	return new_width;
}

function toogleEditorMode(sEditorID) {
	try {
		if(tinyMCEmode) {
			tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
			tinyMCEmode = false;
		} else {
			tinyMCE.addMCEControl(document.getElementById(sEditorID), sEditorID);
			tinyMCEmode = true;
		}
	} catch(e) {
		//error handling
	}
}

function toogleEditorMode1(sEditorID) {
	try {
		if(tinyMCEmode1) {
			tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
			tinyMCEmode1 = false;
		} else {
			tinyMCE.addMCEControl(document.getElementById(sEditorID), sEditorID);
			tinyMCEmode1 = true;
		}
	} catch(e) {
		//error handling
	}
}

function toogleEditorMode2(sEditorID) {
	try {
		if(tinyMCEmode2) {
			tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
			tinyMCEmode2 = false;
		} else {
			tinyMCE.addMCEControl(document.getElementById(sEditorID), sEditorID);
			tinyMCEmode2 = true;
		}
	} catch(e) {
		//error handling
	}
}

function toogleEditorMode3(sEditorID) {
	try {
		if(tinyMCEmode3) {
			tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
			tinyMCEmode3 = false;
		} else {
			tinyMCE.addMCEControl(document.getElementById(sEditorID), sEditorID);
			tinyMCEmode3 = true;
		}
	} catch(e) {
		//error handling
	}
}

function update_tags(caption_id, caption) {
 caption=caption.replace(/'/,"");
 ajax =  new Ajax.Updater(
         'tag_string_' + caption_id,
         $WebRoot + 'admin_ajax.php?A=UT&caption_id=' + caption_id + '&caption=' + caption,
         {
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('tag_string_' + caption_id, {startcolor:'#6084AD', endcolor:'#FFFFFF'});} 
         });

}

function add_tag(tag, id){
	// get tags field original value
	var tags_string = document.getElementById("Tags_" + id).value;
	
	// create new string with old value and new tag
	if(tags_string==''){
		var new_tags_string = tag;
	} else {
		var new_tags_string = tags_string + " " + tag;
	}
	
	// assign new string to form variable
	document.getElementById("Tags_" + id).value = new_tags_string;
}

function use_suggested(caption_id) {
	// get tags field original value
	var tags_string = document.getElementById("tag_string_" + caption_id).innerHTML;

	var stripped = removeHTMLTags(removeNL(tags_string)); 
	// assign new string to form variable
	document.getElementById("Tags_" + caption_id).value = stripped;
}

function clear_tags(caption_id) {
	// get tags field original value
	var tags_string = document.getElementById("tag_string_" + caption_id).innerHTML;
 
	// assign new string to form variable
	document.getElementById("Tags_" + caption_id).value = '';
}

function removeHTMLTags(strInputCode){
	// function taken from - http://javascript.internet.com/snippets/remove-html-tags.html
 	 strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		return (p1 == "lt")? "<" : ">";
 	});
 	var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
 	return strTagStrippedText;	
}

function removeNL(s){ 
  return s.replace(/[\n\r\t]/g,''); 
}

function set_api_url(url){
	document.form1.URL.value=url;
	
	var old_request="" +
	"<request>\n" +
	"	<login>internal</login>\n" +
	"	<api_key>A32FE17A9A42D925E631F2D68B</api_key>\n" +
	"	<iid>191123</iid>\n" +
	"	<vtype>O</vtype>\n" +
	"</request>\n";
	
	var new_request="" +
	"<request>\n" +
	"	<login>internal</login>\n" +
	"	<api_key>A32FE17A9A42D925E631F2D68B</api_key>\n" +
	"	<vid>191123</vid>\n" +
	"</request>\n";
	
	document.form1.APIRequest.value=new_request;
}

// Function to get a users list (movies, artists, shows, etc.) for a given section
function get_user_options(VID, Type) {
 show_wait_small('ct_userlist' + VID);
 ajax =  new Ajax.Updater(
         'ct_userlist' + VID,
         $WebRoot + 'admin_ajax.php?A=GUO&VID=' + VID + '&T=' + Type,
         { 
         method:'get',
         asynchronous:true,
         onComplete:function(){new Effect.Highlight('ct_userlist' + VID);} 
         });

}

// function to show "up next" feature on player page
function show_upnext(delay) {
		setTimeout("Effect.BlindDown('upnext',{delay:0.0, duration: 0.5});", delay);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}