/*
TODO:
	Remove unneeded functions/divs
	Add search videos functionality
	Populate LOW profiles
	Add Prepare For Broadcast functionality
*/
var fullListOfChannelObjects = [];
var fullListOfCategoryNames = [];
var fullListOfVideoObjects = [];
var fullListOfLowProfileVideoObjects = [];
var listOfVideosOnCurrChannel = [];
var editingVideoID = 0;
var editingChannelID = 0;
var debugOn = false;
var errors = ['SUCCESS','FAILURE','AJAX_FAILURE','NO_SESSION','NOT_OWNER','NOT_FOUND','BAD_ARG','BAD_LOGIN','NEED_CONFIRM'];
var MemInfo = null;
var createdTrialChannel = false;
var listOfParams = [];
var viewLocation = '#';
var shareLocation = '#';
var params = MN.GetPageParams();
var currentChannelObject = null;//New Manage
var currentTab = 0;//New Manage
var newest5Videos = [];//New Manage
var categorySelected = false;//New Manage
var selectedCategoryIndex = 0;//New Mange
var otherCategorySelected = false;//New Manage
var otherCategoryIndex = 0;//New Manage
var currentCustomColor = 'blue';
var allVideosDescending = false;
var otherVideosDescending = false;
if(params.debug) debugOn = true;
if(debugOn)
{
	MN.Log.ShowPane(500);
}
//LOAD PAGE FUNCTIONS
loadingPageFunction();
pageLoaded();
function loadingPageFunction()
{
	$('loading_page').innerHTML = $('loading_page').innerHTML + '.';
	if($('loading_page').innerHTML.length > 20)
	{
		$('loading_page').style.display = 'none';
		$('container').style.display = 'block';
	}
	if($('loading_page').style.display != 'none')
		setTimeout(loadingPageFunction, 1000);
}
function pageLoaded()
{
	$('loading_page').style.display = 'none';
	$('container').style.display = 'block';
}
//END LOAD PAGE FUNCTIONS
function loadingOn()
{
	$('tab_loading').style.display = 'block';
	if(currentChannelObject) $('block_out').style.height = '1100px';
	else $('block_out').style.height = '900px';
	$('block_out').style.display = 'block';
	if(!MN.nonIE)
	{
		var elements = document.documentElement.getElementsByTagName('select');
		for (var i=0; i<elements.length; i++)
		{
			elements[i].style.visibility = 'hidden';//Turn Off all select boxes
		}
	}
}
function loadingOff()
{
	$('tab_loading').style.display = 'none';
	$('block_out').style.display = 'none';
	if(!MN.nonIE)
	{
		var elements = document.documentElement.getElementsByTagName('select');
		for (var i=0; i<elements.length; i++)
		{
			elements[i].style.visibility = 'visible';//Turn Off all select boxes
		}
	}
}
function loggingOut(resp)
{
	loadingOff();
	if(resp && resp.error != MC.Err.SUCCESS)
	{
		logError('Logging Out Error: ', errors[resp.error]);
		logError('Logging Out Message: ', resp.message);
	}
	if(!debugOn)
	{
		window.location = "index.html";
	}
	else
	{
		if(confirm("Would you like to exit?"))
			window.location = "index.html";
	}
}
function loggingIn(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Logging In Error: ', errors[resp.error]);
		logError('Logging In Message: ', resp.message);
		loadingOn();
		MC.Call('HaveSession',sessionCheck);
	}
	else
	{
		welcomeUser();
	}
}
function sessionCheck(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Session Check Error: ', errors[resp.error]);
		logError('Session Check Message: ', resp.message);
	}
	logError("Valid Session: " + resp.valid);
	if(!resp.valid)
	{
		if(!debugOn)
			window.location="index.html";
		else
			if(confirm("Would you like to exit?"))
				window.location = "index.html";
		return;
	}
	welcomeUser();
}
//ADD CATEGORIES
function addCategory2()
{
	if($('add_cat2').value == '')
		return;
	if($('add_cat2').value == 'All')
	{
		alert("The Category \"All\" already exists",'add_categories_box');
		return;
	}
	if($('add_cat2').value == 'Add Category')
	{
		alert("The Category \"Add Category\" is not a valid category",'add_categories_box');
		return;
	}
	if($('add_cat2').value == '<Add Category>')
	{
		alert("The Category \"&lt;Add Category&gt;\" is not a valid category",'add_categories_box');
		return;
	}
	if(!isInArray(fullListOfCategoryNames,$('add_cat2').value))
	{
		loadingOn();
		if(fullListOfCategoryNames.length)
			MC.Call('SetCategories',reloadCategories,'names',(fullListOfCategoryNames.join('|') + '|' + $('add_cat2').value));
		else
			MC.Call('SetCategories',reloadCategories,'names',$('add_cat2').value);
	}
	else
	{
		alert("The Category \"" + $('add_cat2').value + "\" already exists",'add_categories_box');
	}
}
function openAddCategory()
{
	loadingOn();
	MC.Call('HaveSession',reportSession);
	$('add_categories_box').style.display = 'block';
	updateAddCategory();
}
function updateAddCategory()
{
	var addCategoryList = ['<ul id="add_categories_list">'];
	var addCateogryString = '<li style="list-style-type: none; clear: both; width: 300px;"><input type="hidden" id="newlabel" style="float: left;" /><label for="newlabel" style="float: left;">%s</label><a href="javascript:void removeCategory(%s)" class="delete">Delete</a><br /></li>';
	for(var y=0;y<fullListOfCategoryNames.length;y++)
	{
		addCategoryList.push(addCateogryString.format(fullListOfCategoryNames[y],y));
	}
	addCategoryList.push('<li style="list-style-type: none;"><input type="text" value="<Add Category>" name="add_cat2" id="add_cat2" maxlength="30" style="margin-right: 20px; float:left;" /><a class="btn_blue" href="javascript:void addCategory2()" style="float:left;"><span class="btn_left"></span><span class="btn_mid">Add</span><span class="btn_right"></span></a></li></ul>');
	$('add_categories_message').innerHTML = addCategoryList.join('\n');
	if($('add_categories_box').style.display == 'block')
	{
		$('add_cat2').focus();
		$('add_cat2').select();
	}
}
function closeAddCategory()
{
	$('add_categories_box').style.display = 'none';
}
//END ADD CATEGORIES
//CHANNEL EDITOR
function reportSession(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Report Session Error: ', errors[resp.error]);
		logError('Report Session Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
	}
	logError("Valid Session: " + resp.valid);
	if(!resp.valid)
		logOut();
}
function openChannelEditor(channelID)
{
	loadingOn();
	MC.Call('HaveSession',reportSession);
	viewLocation = 'channel_view.html?channelID=' + channelID;
	shareLocation = 'channel_view.html?share&channelID=' + channelID;
	editingChannelID = channelID;
	$('channel_editor').style.display = 'block';
	reloadChannel();
}
function closeChannelEditor()
{
	viewLocation = 'channel_view.html?channelID=' + fullListOfChannelObjects[0].id;
	shareLocation = 'channel_view.html?share&channelID=' + fullListOfChannelObjects[0].id;
	$('channel_editor').style.display = 'none';
}
function saveChannelCB(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Save Channel CB Error: ', errors[resp.error]);
		logError('Save Channel CB Message: ', resp.message);
		if(resp.error == MC.Err.BAD_ARG)
		{
			if(resp.message == 'Invalid characters in web address')
				alert(resp.message+"\nPlease use alphanumeric characters only.",'channel_editor');
			else
				alert(resp.message,'channel_editor');
		}
		if(resp.error == MC.Err.NOT_FOUND)
			alert('The channel requested does not exist.');
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		//alert('An Error occurred while trying to save channel\nError: ' + errors[resp.error] + '\nMessage: ' + resp.message);
		return;
	}
	else
	{
		logError('Successfully Saved Channel');
	}
	updateChannels();
	$('channel_editor').style.display = 'none';
}
function saveChannel()
{
	var channelToWorkWith = null;
	var heartbeatToSave = 15;
	var allowedMinutesOfOverage = 0;
	var statusOfChannel = 0;
	for(var x=0;x<fullListOfChannelObjects.length;x++)
		if(fullListOfChannelObjects[x].id == editingChannelID)
			channelToWorkWith = fullListOfChannelObjects[x];
	if(!channelToWorkWith)
	{
		alert('An Error occurred while trying to save channel\nMessage: Invalid channel id.');
		return;
	}
	/*
	id, title, desc, webAddr, private, privatePassword, listInPublic, status, allowOverageMin, verifyWatchingMin, message, skin, logo, linkNewMember, includeSignUp
	*/
	if($('form1').short_description.value.length > 255)
	{
		alert('Description length must be shorter than 255 characters.','channel_editor');
		return;
	}
	webAddressText = '';
	if($('form1').web_address.value != '') webAddressText = $('form1').web_address.value;
	if(!webAddressText || webAddressText == '')
	{
		alert("The channel address \"\" is not a valid web address.",'channel_editor');
		return;
	}
	if(!$('form1').public_channel.checked && !$('form1').private_channel.checked)
	{
		alert("The channel must be either public or private.",'channel_editor');
		return;
	}
	if($('form1').continue_billing.checked)
	{
		if($('overage_hours_select').options[$('overage_hours_select').selectedIndex].id == 'hours_1')
			allowedMinutesOfOverage = 60;
		else if($('overage_hours_select').options[$('overage_hours_select').selectedIndex].id == 'hours_2')
			allowedMinutesOfOverage = 120;
		else if($('overage_hours_select').options[$('overage_hours_select').selectedIndex].id == 'hours_3')
			allowedMinutesOfOverage = 180;
		else if($('overage_hours_select').options[$('overage_hours_select').selectedIndex].id == 'hours_4')
			allowedMinutesOfOverage = 240;
		else if($('overage_hours_select').options[$('overage_hours_select').selectedIndex].id == 'hours_5')
			allowedMinutesOfOverage = 300;
		else if($('overage_hours_select').options[$('overage_hours_select').selectedIndex].id == 'hours_6')
			allowedMinutesOfOverage = 360;
		else if($('overage_hours_select').options[$('overage_hours_select').selectedIndex].id == 'hours_7')
			allowedMinutesOfOverage = 420;
		else if($('overage_hours_select').options[$('overage_hours_select').selectedIndex].id == 'hours_nl')
			allowedMinutesOfOverage = 999;
	}
	else if($('form1').turn_off.checked)
	{
		allowedMinutesOfOverage = 0;
	}
	else
	{
		alert("A \'Viewing Minutes\' status must be selected.",'channel_editor');
		return;
	}
	if($('verify_minutes').options[$('verify_minutes').selectedIndex].id == 'minutes_15')
	{
		heartbeatToSave = 15;
	}
	else if($('verify_minutes').options[$('verify_minutes').selectedIndex].id == 'minutes_30')
	{
		heartbeatToSave = 30;
	}
	else if($('verify_minutes').options[$('verify_minutes').selectedIndex].id == 'minutes_45')
	{
		heartbeatToSave = 45;
	}
	else if($('verify_minutes').options[$('verify_minutes').selectedIndex].id == 'minutes_60')
	{
		heartbeatToSave = 60;
	}
	else if($('verify_minutes').options[$('verify_minutes').selectedIndex].id == 'minutes_180')
	{
		heartbeatToSave = 180;
	}
	if(!allowedMinutesOfOverage && MemInfo.availMinutes < MemInfo.minutesUsed)
	{
		statusOfChannel = 0;
	}
	else if(MemInfo.availMinutes < MemInfo.minutesUsed)
	{
		var minutesUsedAlready = MemInfo.minutesUsed - MemInfo.availMinutes;
		if(minutesUsedAlready >= 420 && allowedMinutesOfOverage <= 420)
			statusOfChannel = 0;
		else if(minutesUsedAlready >= 360 && allowedMinutesOfOverage <= 360)
			statusOfChannel = 0;
		else if(minutesUsedAlready >= 300 && allowedMinutesOfOverage <= 300)
			statusOfChannel = 0;
		else if(minutesUsedAlready >= 240 && allowedMinutesOfOverage <= 240)
			statusOfChannel = 0;
		else if(minutesUsedAlready >= 180 && allowedMinutesOfOverage <= 180)
			statusOfChannel = 0;
		else if(minutesUsedAlready >= 120 && allowedMinutesOfOverage <= 120)
			statusOfChannel = 0;
		else if(minutesUsedAlready >= 60 && allowedMinutesOfOverage <= 60)
			statusOfChannel = 0;
		else
			statusOfChannel = -1;
	}
	if($('form1').private_channel.checked && $('form1').password_field.value == '')
	{
		//This does not allow a previously public account to not have a password.
		alert("A password is required for private content.",'channel_editor');
		return;
	}
	if($('form1').private_channel.checked && $('form1').password_field.value != '')
	{
		loadingOn();
		/*MC.Call('SetChannelInfo',saveChannelCB,'id',editingChannelID,'title',$('form1').name_field.value,'desc',$('form1').short_description.value,'webAddr',webAddressText,'private',$('form1').private_channel.checked,'verifyWatchingMin',heartbeatToSave,'allowOverageMin',allowedMinutesOfOverage,'status',statusOfChannel,'listInPublic',$('form1').include_channel.checked,'linkNewMember',false,'showShare',$('show_share').checked,'autoRestart',$('auto_restart').checked,'includeSignUp',false,'playerColor',currentCustomColor,'pauseOnLoad',$('pause_on_load').checked,'privatePassword',$('form1').password_field.value);*/
		MC.Call('SetChannelInfo',saveChannelCB,'id',editingChannelID,'title',$('form1').name_field.value,'desc',$('form1').short_description.value,'webAddr',webAddressText,'private',$('form1').private_channel.checked,'verifyWatchingMin',heartbeatToSave,'allowOverageMin',allowedMinutesOfOverage,'status',statusOfChannel,'listInPublic',$('form1').include_channel.checked,'linkNewMember',false,'showShare',false,'autoRestart',$('auto_restart').checked,'includeSignUp',false,'playerColor',currentCustomColor,'pauseOnLoad',$('pause_on_load').checked,'privatePassword',$('form1').password_field.value);
	}
	else
	{
		loadingOn();
		/*MC.Call('SetChannelInfo',saveChannelCB,'id',editingChannelID,'title',$('form1').name_field.value,'desc',$('form1').short_description.value,'webAddr',webAddressText,'private',$('form1').private_channel.checked,'verifyWatchingMin',heartbeatToSave,'allowOverageMin',allowedMinutesOfOverage,'status',statusOfChannel,'listInPublic',$('form1').include_channel.checked,'linkNewMember',false,'showShare',$('show_share').checked,'autoRestart',$('auto_restart').checked,'includeSignUp',false,'playerColor',currentCustomColor,'pauseOnLoad',$('pause_on_load').checked);*/
		MC.Call('SetChannelInfo',saveChannelCB,'id',editingChannelID,'title',$('form1').name_field.value,'desc',$('form1').short_description.value,'webAddr',webAddressText,'private',$('form1').private_channel.checked,'verifyWatchingMin',heartbeatToSave,'allowOverageMin',allowedMinutesOfOverage,'status',statusOfChannel,'listInPublic',$('form1').include_channel.checked,'linkNewMember',false,'showShare',false,'autoRestart',$('auto_restart').checked,'includeSignUp',false,'playerColor',currentCustomColor,'pauseOnLoad',$('pause_on_load').checked);
	}
}
function reloadChannel()
{
	var channelToWorkWith = null;
	for(var currChannel=0;currChannel<fullListOfChannelObjects.length;currChannel++)
	{
		if(fullListOfChannelObjects[currChannel].id == editingChannelID)
		{
			channelToWorkWith = fullListOfChannelObjects[currChannel];
		}
	}
	if(!channelToWorkWith)
		return;
	
	$('form1').name_field.value = channelToWorkWith.title;
	$('form1').short_description.value = channelToWorkWith.desc;
	$('form1').public_channel.checked = !channelToWorkWith.private;
	$('form1').private_channel.checked = channelToWorkWith.private;
	$('form1').include_channel.checked = channelToWorkWith.listInPublic;
	$('form1').web_address.value = (channelToWorkWith.webAddr || '');
	$('form1').password_field.value = (channelToWorkWith.password || '');
	
	if(channelToWorkWith.status) $('continue_billing').checked = true;
	else $('turn_off').checked = true;
	
	if(channelToWorkWith.allowOverageMin)
	{
		$('form1').turn_off.checked = false;
		$('form1').continue_billing.checked = true;
		if(channelToWorkWith.allowOverageMin == 60)
			$('overage_hours_select').selectedIndex = 0;
		else if(channelToWorkWith.allowOverageMin == 120)
			$('overage_hours_select').selectedIndex = 1;
		else if(channelToWorkWith.allowOverageMin == 180)
			$('overage_hours_select').selectedIndex = 2;
		else if(channelToWorkWith.allowOverageMin == 240)
			$('overage_hours_select').selectedIndex = 3;
		else if(channelToWorkWith.allowOverageMin == 300)
			$('overage_hours_select').selectedIndex = 4;
		else if(channelToWorkWith.allowOverageMin == 360)
			$('overage_hours_select').selectedIndex = 5;
		else if(channelToWorkWith.allowOverageMin == 420)
			$('overage_hours_select').selectedIndex = 6;
		else if(channelToWorkWith.allowOverageMin == 999)
			$('overage_hours_select').selectedIndex = 7;
	}
	else
	{
		$('form1').turn_off.checked = true;
		$('form1').continue_billing.checked = false;
	}
	
	if(channelToWorkWith.verifyWatchingMin == 15)
		$('verify_minutes').selectedIndex = 0;
	else if(channelToWorkWith.verifyWatchingMin == 30)
		$('verify_minutes').selectedIndex = 1;
	else if(channelToWorkWith.verifyWatchingMin == 45)
		$('verify_minutes').selectedIndex = 2;
	else if(channelToWorkWith.verifyWatchingMin == 60)
		$('verify_minutes').selectedIndex = 3;
	else if(channelToWorkWith.verifyWatchingMin == 180)
		$('verify_minutes').selectedIndex = 4;

	//if(channelToWorkWith.linkNewMember) $('link_new_member').checked = true;
	//else if((channelToWorkWith.linkNewMember) == 'undefined') $('link_new_member').checked = true;
	//else $('link_new_member').checked = false;
	//if(channelToWorkWith.includeSignUp) $('include_sign_up').checked = true;
	//else if(typeof(channelToWorkWith.includeSignUp) == 'undefined') $('include_sign_up').checked = true;
	//else $('include_sign_up').checked = false;
	//if(channelToWorkWith.showShare) $('show_share').checked = true;
	//else if(typeof(channelToWorkWith.showShare) == 'undefined') $('show_share').checked = true;
	//else $('show_share').checked = false;
	if(channelToWorkWith.autoRestart) $('auto_restart').checked = true;
	else if(typeof(channelToWorkWith.autoRestart) == 'undefined') $('auto_restart').checked = false;
	else $('auto_restart').checked = false;
	/*
	if(typeof(channelToWorkWith.playerColor) == 'undefined')
	{
		currentCustomColor = 'blue';
		$('cust_color_blue').checked = true;
		$('cust_color_gray').checked = false;
		$('cust_color_green').checked = false;
		$('cust_color_orange').checked = false;
		$('cust_color_black').checked = false;
		$('cust_color_purple').checked = false;
		$('cust_color_red').checked = false;
		$('cust_color_slate').checked = false;
		$('cust_color_yellow').checked = false;
		$('cust_color_brown').checked = false;
	}
	else
	{
		currentCustomColor = channelToWorkWith.playerColor;
		$('cust_color_blue').checked = (channelToWorkWith.playerColor == 'blue');
		$('cust_color_gray').checked = (channelToWorkWith.playerColor == 'gray');
		$('cust_color_green').checked = (channelToWorkWith.playerColor == 'green');
		$('cust_color_orange').checked = (channelToWorkWith.playerColor == 'orange');
		$('cust_color_black').checked = (channelToWorkWith.playerColor == 'black');
		$('cust_color_purple').checked = (channelToWorkWith.playerColor == 'purple');
		$('cust_color_red').checked = (channelToWorkWith.playerColor == 'red');
		$('cust_color_slate').checked = (channelToWorkWith.playerColor == 'slate');
		$('cust_color_yellow').checked = (channelToWorkWith.playerColor == 'yellow');
		$('cust_color_brown').checked = (channelToWorkWith.playerColor == 'brown');
	}
	*/
	if(typeof(channelToWorkWith.pauseOnLoad) == 'undefined') $('pause_on_load').checked = false;
	else $('pause_on_load').checked = channelToWorkWith.pauseOnLoad;
}
function changeCustomColor()
{
	if($('cust_color_blue').checked) currentCustomColor = 'blue';
	else if($('cust_color_gray').checked) currentCustomColor = 'gray';
	else if($('cust_color_green').checked) currentCustomColor = 'green';
	else if($('cust_color_orange').checked) currentCustomColor = 'orange';
	else if($('cust_color_black').checked) currentCustomColor = 'black';
	else if($('cust_color_purple').checked) currentCustomColor = 'purple';
	else if($('cust_color_red').checked) currentCustomColor = 'red';
	else if($('cust_color_slate').checked) currentCustomColor = 'slate';
	else if($('cust_color_yellow').checked) currentCustomColor = 'yellow';
	else if($('cust_color_brown').checked) currentCustomColor = 'brown';
}
function openEmbedLinks()
{
	if(currentChannelObject)
		window.location = "/channel_video_links.html?channelID="+currentChannelObject.id;
	else
		window.location = "/channel_video_links.html";
}
function ShowTabs(startChannel)
{
	//New Manage
	currentTab = startChannel;
	var fullChannelTabString = [];
	var channelTabString = "<div id=\"Channel_%s_Tab\" class=\"inactive_tab\" onclick=\"javascript:void ShowChannel(%s)\"><div style=\"margin: 5px 0 0 10px; color:#2faade; font-size:12px;\"><b>%s</b></div><div style=\"padding: 0 0 0 20px; margin: -18px 8px 0; width:70px; height: 32px; overflow:hidden; color:#2faade; font-size:10px;\">%s</div></div>";
	var channelPrivateTabString = "<div id=\"Channel_%s_Tab\" class=\"inactive_tab\" onclick=\"javascript:void ShowChannel(%s)\"><div style=\"margin: 5px 0 0 10px; color:#2faade; font-size:12px;\"><b>%s</b></div><div style=\"margin: 5px 0 0 10px; width:10px; height:12px; background:url(\'/images/lock10x12.gif\') no-repeat; zIndex: 100000;\"></div><div style=\"padding: 0 0 0 20px; margin: -35px 8px 0; width:70px; height: 32px; overflow:hidden; color:#2faade; font-size:10px;\">%s</div></div>";
	var channelActiveTabString = "<div id=\"Channel_%s_Tab\" class=\"active_tab\" onclick=\"javascript:void ShowChannel(%s)\"><div style=\"margin: 5px 0 0 10px; color:#2faade; font-size:12px;\"><b>%s</b></div><div style=\"padding: 0 0 0 20px; margin: -18px 8px 0; width:70px; height: 32px; overflow:hidden; color:#2faade; font-size:10px;\">%s</div></div>";
	var channelActivePrivateTabString = "<div id=\"Channel_%s_Tab\" class=\"active_tab\" onclick=\"javascript:void ShowChannel(%s)\"><div style=\"margin: 5px 0 0 10px; color:#2faade; font-size:12px;\"><b>%s</b></div><div style=\"margin: 5px 0 0 10px; width:10px; height:12px; background:url(\'/images/lock10x12.gif\') no-repeat; zIndex: 100000;\"></div><div style=\"padding: 0 0 0 20px; margin: -35px 8px 0; width:70px; height: 32px; overflow:hidden; color:#2faade; font-size:10px;\">%s</div></div>";
	for(var channelIndex = startChannel; channelIndex < fullListOfChannelObjects.length; channelIndex++)
	{
		if(currentChannelObject)
		{
			if(currentChannelObject.id == fullListOfChannelObjects[channelIndex].id)
			{
				if(fullListOfChannelObjects[channelIndex].private)
					fullChannelTabString.push(channelActivePrivateTabString.format(channelIndex,channelIndex,(channelIndex+1),fullListOfChannelObjects[channelIndex].title));
				else
					fullChannelTabString.push(channelActiveTabString.format(channelIndex,channelIndex,(channelIndex+1),fullListOfChannelObjects[channelIndex].title));
			}
			else
			{
				if(fullListOfChannelObjects[channelIndex].private)
					fullChannelTabString.push(channelPrivateTabString.format(channelIndex,channelIndex,(channelIndex+1),fullListOfChannelObjects[channelIndex].title));
				else
					fullChannelTabString.push(channelTabString.format(channelIndex,channelIndex,(channelIndex+1),fullListOfChannelObjects[channelIndex].title));
			}
		}
		else
		{
			if(fullListOfChannelObjects[channelIndex].private)
				fullChannelTabString.push(channelPrivateTabString.format(channelIndex,channelIndex,(channelIndex+1),fullListOfChannelObjects[channelIndex].title));
			else
				fullChannelTabString.push(channelTabString.format(channelIndex,channelIndex,(channelIndex+1),fullListOfChannelObjects[channelIndex].title));
		}
		if(channelIndex >= startChannel + 4) break;
	}
	$('More_Channels_Tabs').innerHTML = fullChannelTabString.join('\n');
	
	var fullChannelLinkString = [];
	var channelLinkString = "<div style=\"float:left; padding-top:5px;\"><a href=\"javascript:void ShowTabs(%s)\">%s - %s</a></div>";
	var channelNonLinkString = "<div style=\"float:left; padding-top:5px;\">%s - %s</div>";
	if(fullListOfChannelObjects.length > 5)
	{
		for(var channelLinkIndex = 0; channelLinkIndex < fullListOfChannelObjects.length; channelLinkIndex++)
		{
			if(channelLinkIndex == startChannel)
			{
				if((channelLinkIndex + 4) > fullListOfChannelObjects.length)
					fullChannelLinkString.push(channelNonLinkString.format((channelLinkIndex+1),fullListOfChannelObjects.length));
				else
					fullChannelLinkString.push(channelNonLinkString.format((channelLinkIndex+1),(channelLinkIndex+5)));
			}
			else
			{
				if((channelLinkIndex + 4) > fullListOfChannelObjects.length)
					fullChannelLinkString.push(channelLinkString.format(channelLinkIndex,(channelLinkIndex+1),fullListOfChannelObjects.length));
				else
					fullChannelLinkString.push(channelLinkString.format(channelLinkIndex,(channelLinkIndex+1),(channelLinkIndex+5)));
			}
			channelLinkIndex++;
			channelLinkIndex++;
			channelLinkIndex++;
			channelLinkIndex++;
		}
		$('channels_links').style.display = 'block';
		$('channels_links').innerHTML = fullChannelLinkString.join('<div style="float:left; padding-top:5px;">|</div>');
	}
	if(currentChannelObject) createListOfVideosOnChannel();
	if(currentChannelObject) createOtherList(false);//TODO: change the other checkboxes
	addCategoryOptionsToChannel();
	if(currentChannelObject) addCategoryOptionsToOther();
}
function createTabs()
{
	ShowTabs(0);
}
function createListOfVideosOnChannel()
{
	listOfVideosOnCurrChannel = [];
	for(var videoIDIndex = 0; videoIDIndex < currentChannelObject.videos.length; videoIDIndex++)
	{
		for(var videoIndex = 0; videoIndex < fullListOfVideoObjects.length; videoIndex++)
		{
			if(fullListOfVideoObjects[videoIndex].id == currentChannelObject.videos[videoIDIndex])
			{
				listOfVideosOnCurrChannel.push(fullListOfVideoObjects[videoIndex]);
				break;
			}
		}
	}
}
function addCategoryOptionsToChannel()
{
	//New Manage
	while($('selectedVideosCategories').options.length)
	{
		$('selectedVideosCategories').remove(0);
	}
	var newOption = document.createElement('option');
	newOption.text = 'All';
	try
	{
		$('selectedVideosCategories').add(newOption,null); // standards compliant
	}
	catch(ex)
	{
		$('selectedVideosCategories').add(newOption); // IE only
	}
	for(var catIndex = 0; catIndex < fullListOfCategoryNames.length; catIndex++)
	{
		var y = document.createElement('option');
		y.text = fullListOfCategoryNames[catIndex];
		if(y.text.length > 7)
		{
			var temp = '';
			for(var textIndex = 0; textIndex < y.text.length; textIndex++)
			{
				if(temp.length >= 7)
				{
					temp = temp + '..';
					break;
				}
				temp = temp + y.text.substr(textIndex,1);
			}
			y.text = temp;
		}
		if(selectedCategoryIndex && selectedCategoryIndex - 1 == catIndex) y.selected = true;
		y.id = fullListOfCategoryNames[catIndex].replace(' ','');
		y.value = fullListOfCategoryNames[catIndex];
		try
		{
			$('selectedVideosCategories').add(y,null); // standards compliant
		}
		catch(ex)
		{
			$('selectedVideosCategories').add(y); // IE only
		}
		//var x = fullListOfCategoryNames[catIndex];
		//alert(x);
		//MN.Event.Observe($('num' + catIndex + 'name' + x.replace(' ','')),'click',function(){showSelectedVideosCategories(x.replace(' ',''))});
		//$('num' + catIndex + 'name' + x.replace(' ','')).onclick = function(){alert('1');};//showSelectedVideosCategories(x.replace(' ',''))
	}
	$('selectedVideosCategories').onchange = function(){showSelectedVideosCategories($('selectedVideosCategories').options[$('selectedVideosCategories').selectedIndex].value)};
}
function addCategoryOptionsToOther()
{
	//New Manage
	while($('otherVideosCategories').options.length)
	{
		$('otherVideosCategories').remove(0);
	}
	var newOption = document.createElement('option');
	newOption.text = 'All';
	newOption.value = 'ALL';
	try
	{
		$('otherVideosCategories').add(newOption,null); // standards compliant
	}
	catch(ex)
	{
		$('otherVideosCategories').add(newOption); // IE only
	}
	for(var catIndex = 0; catIndex < fullListOfCategoryNames.length; catIndex++)
	{
		var y = document.createElement('option');
		y.text = fullListOfCategoryNames[catIndex];
		if(y.text.length > 7)
		{
			var temp = '';
			for(var textIndex = 0; textIndex < y.text.length; textIndex++)
			{
				if(temp.length >= 7)
				{
					temp = temp + '..';
					break;
				}
				temp = temp + y.text.substr(textIndex,1);
			}
			y.text = temp;
		}
		if(otherCategoryIndex && otherCategoryIndex - 1 == catIndex) y.selected = true;
		y.id = fullListOfCategoryNames[catIndex].replace(' ','');
		y.value = fullListOfCategoryNames[catIndex];
		try
		{
			$('otherVideosCategories').add(y,null); // standards compliant
		}
		catch(ex)
		{
			$('otherVideosCategories').add(y); // IE only
		}
	}
	$('otherVideosCategories').onchange = function(){showOtherVideosCategories($('otherVideosCategories').options[$('otherVideosCategories').selectedIndex].value)};
}
function showSelectedVideosCategories(selectedCategory)
{
	//New Manage
	selectedCategoryIndex = $('selectedVideosCategories').selectedIndex;
	if(selectedCategory && selectedCategory != '' && selectedCategory.toLowerCase() != 'all' && $('selectedVideosCategories').selectedIndex)
	{
		categorySelected = true;
		if(currentChannelObject)
		{
			loadingOn();
			logError("showSelectedVideosCategories Single Channel Single Category");
			MC.Call('GetChannelVideos',reloadVideosList,'channelID',currentChannelObject.id,'categories',selectedCategory);
		}
		else
		{
			loadingOn();
			logError("showSelectedVideosCategories All Channels Single Category");
			MC.Call('GetChannelVideos',reloadAllVideoObjects,'profiles','ALL','categories',selectedCategory);
		}
	}
	else
	{
		categorySelected = false;
		if(currentChannelObject)
		{
			loadingOn();
			logError("showSelectedVideosCategories Single Channel All Categories");
			MC.Call('GetChannelVideos',reloadVideosList,'channelID',currentChannelObject.id);
		}
		else
		{
			loadingOn();
			logError("showSelectedVideosCategories All Channels All Categories");
			MC.Call('GetChannelVideos',reloadAllVideoObjects,'profiles','ALL');
		}
	}
}
function showOtherVideosCategories(selectedCategory)
{
	//New Manage
	if(selectedCategory && selectedCategory != '' && selectedCategory.toLowerCase() != 'all' && $('otherVideosCategories').selectedIndex)
	{
		otherCategorySelected = true;
	}
	else
	{
		otherCategorySelected = false;
	}
	otherCategoryIndex = $('otherVideosCategories').selectedIndex;
	createOtherList(false);
}
function reloadChannelsList(resp)
{
	loadingOff();
	fullListOfChannelObjects = [];
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Reload Channels List Error: ', errors[resp.error]);
		logError('Reload Channels List Message: ', resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
			return;
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		return;
	}
	logError('Reload Channels List Success');
	for(var y=0;y<resp.channels.length;y++)
	{
		if(!isInArray(fullListOfChannelObjects,resp.channels[y]))
			fullListOfChannelObjects.push(resp.channels[y]);
	}
	fullListOfChannelObjects.sort(function(a,b){return Number(a.id)-Number(b.id);});
	createTabs();//New Manage//TODO:CHECK FOR SPEED
	viewLocation = 'channel_view.html?channelID=' + fullListOfChannelObjects[0].id;
	shareLocation = 'channel_view.html?share&channelID=' + fullListOfChannelObjects[0].id;
	loadingOn();
	updateVideos();//TODO:CHECK FOR SPEED
}
function updateChannels()
{
	loadingOn();
	MC.Call('GetChannelInfo',reloadChannelsList);
}
function selectSimpleGeneral()
{
	$('simple_editor_tab_general').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('simple_editor_tab_exchange').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_noexchange').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_categories').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_ppv').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_general_fieldset').style.display = 'block';
	$('public_exchange').style.display = 'none';
	$('simple_editor_noexchange_fieldset').style.display = 'none';
	$('simple_editor_categories_fieldset').style.display = 'none';
	$('simple_editor_ppv_fieldset').style.display = 'none';
}
function selectSimpleExchange()
{
	$('simple_editor_tab_general').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_exchange').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('simple_editor_tab_noexchange').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_categories').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_ppv').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_general_fieldset').style.display = 'none';
	$('public_exchange').style.display = 'block';
	$('simple_editor_noexchange_fieldset').style.display = 'none';
	$('simple_editor_categories_fieldset').style.display = 'none';
	$('simple_editor_ppv_fieldset').style.display = 'none';
}
function selectSimpleNoExchange()
{
	$('simple_editor_tab_general').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_exchange').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_noexchange').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('simple_editor_tab_categories').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_ppv').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_general_fieldset').style.display = 'none';
	$('public_exchange').style.display = 'none';
	$('simple_editor_noexchange_fieldset').style.display = 'block';
	$('simple_editor_categories_fieldset').style.display = 'none';
	$('simple_editor_ppv_fieldset').style.display = 'none';
}
function selectSimpleCategories()
{
	$('simple_editor_tab_general').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_exchange').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_noexchange').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_categories').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('simple_editor_tab_ppv').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_general_fieldset').style.display = 'none';
	$('public_exchange').style.display = 'none';
	$('simple_editor_noexchange_fieldset').style.display = 'none';
	$('simple_editor_categories_fieldset').style.display = 'block';
	$('simple_editor_ppv_fieldset').style.display = 'none';
}
function selectSimplePPV()
{
	$('simple_editor_tab_general').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_exchange').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_noexchange').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_categories').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('simple_editor_tab_ppv').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('simple_editor_general_fieldset').style.display = 'none';
	$('public_exchange').style.display = 'none';
	$('simple_editor_noexchange_fieldset').style.display = 'none';
	$('simple_editor_categories_fieldset').style.display = 'none';
	$('simple_editor_ppv_fieldset').style.display = 'block';
}
function selectChannelGeneral()
{
	$('channel_editor_tab_general').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('channel_editor_tab_private').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_minutes').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_advanced').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	//$('channel_editor_tab_colors').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('general_fieldset').style.display = 'block';
	$('public_private_fieldset').style.display = 'none';
	$('viewing_minutes_fieldset').style.display = 'none';
	$('advanced_settings_fieldset').style.display = 'none';
	//$('custom_colors').style.display = 'none';
}
function selectChannelPrivate()
{
	$('channel_editor_tab_general').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_private').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('channel_editor_tab_minutes').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_advanced').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	//$('channel_editor_tab_colors').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('general_fieldset').style.display = 'none';
	$('public_private_fieldset').style.display = 'block';
	$('viewing_minutes_fieldset').style.display = 'none';
	$('advanced_settings_fieldset').style.display = 'none';
	//$('custom_colors').style.display = 'none';
}
function selectChannelMinutes()
{
	$('channel_editor_tab_general').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_private').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_minutes').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('channel_editor_tab_advanced').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	//$('channel_editor_tab_colors').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('general_fieldset').style.display = 'none';
	$('public_private_fieldset').style.display = 'none';
	$('viewing_minutes_fieldset').style.display = 'block';
	$('advanced_settings_fieldset').style.display = 'none';
	//$('custom_colors').style.display = 'none';
}
function selectChannelAdvanced()
{
	$('channel_editor_tab_general').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_private').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_minutes').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_advanced').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	//$('channel_editor_tab_colors').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('general_fieldset').style.display = 'none';
	$('public_private_fieldset').style.display = 'none';
	$('viewing_minutes_fieldset').style.display = 'none';
	$('advanced_settings_fieldset').style.display = 'block';
	//$('custom_colors').style.display = 'none';
}
/*
function selectChannelColors()
{
	$('channel_editor_tab_general').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_private').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_minutes').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_advanced').style.background="url('/images/channelEditorTabInactive.jpg') no-repeat";
	$('channel_editor_tab_colors').style.background="url('/images/channelEditorTab.jpg') no-repeat";
	$('general_fieldset').style.display = 'none';
	$('public_private_fieldset').style.display = 'none';
	$('viewing_minutes_fieldset').style.display = 'none';
	$('advanced_settings_fieldset').style.display = 'none';
	$('custom_colors').style.display = 'block';
}
*/
//end CHANNEL EDITOR
//SIMPLE VIDEO EDITOR
var currentVideoToWorkWith = null;
function openVideoEditor(videoID,editorTop)
{
	var videoToWorkWith = null;
	for(var currVideo=0;currVideo<fullListOfVideoObjects.length;currVideo++)
	{
		if(fullListOfVideoObjects[currVideo].id == videoID)
		{
			videoToWorkWith = fullListOfVideoObjects[currVideo];
		}
	}
	if(!videoToWorkWith) return;
	currentVideoToWorkWith = videoToWorkWith;
	if(typeof(videoToWorkWith.fromclip) != 'undefined' && videoToWorkWith.fromclip)
	{
		$('simple_editor_tab_exchange').style.display = 'none';
		$('simple_editor_tab_noexchange').style.display = 'block';
		if($('public_exchange').style.display != 'none')
		{
			selectSimpleNoExchange();
		}
	}
	else
	{
		$('simple_editor_tab_exchange').style.display = 'block';
		$('simple_editor_tab_noexchange').style.display = 'none';
	}
	if(typeof(videoToWorkWith.uneditable) != 'undefined' && videoToWorkWith.uneditable) return;
	changeVideoEditorImg(videoToWorkWith);
	if(typeof(editorTop) != 'undefined')
	{
		$('simple_editor').style.top = editorTop + 'px';
	}
	else
	{
		$('simple_editor').style.top = '300px';
	}
	loadingOn();
	MC.Call('HaveSession',reportSession);
	viewLocation = 'channel_view.html?videoID=' + videoID + '&channelID=0';
	shareLocation = 'channel_view.html?share&videoID=' + videoID + '&channelID=0';
	editingVideoID = videoID;
	$('simple_editor').style.display = 'block';
	if(!isNaN(videoToWorkWith.ppvprice) && Number(videoToWorkWith.ppvprice) < 1) videoToWorkWith.ppvprice = '1.00';
	$('ppv_value').value = videoToWorkWith.ppvprice;
	if($('ppv_value').value.indexOf('.') != -1)
	{
		if($('ppv_value').value.substring($('ppv_value').value.indexOf('.')+1,$('ppv_value').value.length).length == 1)
			$('ppv_value').value = $('ppv_value').value.substring(0,$('ppv_value').value.indexOf('.')) + '.' + $('ppv_value').value.substring($('ppv_value').value.indexOf('.')+1,$('ppv_value').value.length) + '0';
		else if($('ppv_value').value.substring($('ppv_value').value.indexOf('.')+1,$('ppv_value').value.length).length == 0)
			$('ppv_value').value = $('ppv_value').value.substring(0,$('ppv_value').value.indexOf('.')) + '.00';
		else
			$('ppv_value').value = $('ppv_value').value.substring(0,$('ppv_value').value.indexOf('.')) + '.' + $('ppv_value').value.substring($('ppv_value').value.indexOf('.')+1,$('ppv_value').value.length);
	}
	else
	{
		$('ppv_value').value = $('ppv_value').value + '.00';
	}
	/*
	if(typeof(videoToWorkWith.ppvprice) != 'undefined' && Number(videoToWorkWith.ppvprice) >= 1)
	{
		$('ppv_value').value = videoToWorkWith.ppvprice;
	}
	else
	{
		$('ppv_value').value = '1.00';
	}
	*/
	if(typeof(videoToWorkWith.ppv) != 'undefined' && videoToWorkWith.ppv && videoToWorkWith.ppv != 'false')
	{
		$('non_ppv_video').checked = false;
		$('ppv_video').checked = 'checked';
	}
	else
	{
		$('non_ppv_video').checked = 'checked';
		$('ppv_video').checked = false;
	}
	if(typeof(videoToWorkWith.ppvpreviewsecs) != 'undefined')
	{
		$('ppv_preview_time').value = videoToWorkWith.ppvpreviewsecs;
	}
	else
	{
		$('ppv_preview_time').value = '10';
	}
	reloadVideo();
	if($('simple_editor_categories_fieldset').style.display != 'none')
	{
		$('add_cat').focus();
		$('add_cat').select();
	}
}
function closeVideoEditor()
{
	viewLocation = 'channel_view.html?channelID=' + fullListOfChannelObjects[0].id;
	shareLocation = 'channel_view.html?share&channelID=' + fullListOfChannelObjects[0].id;
	$('simple_editor').style.display = 'none';
	$('ppv_value').style.backgroundColor = 'white';
	$('ppv_preview_time').style.backgroundColor = 'white';
	//loadingOn();
	//updateVideos();
}
function saveVideo()
{
	var videoToWorkWith = null;
	listOfCategories = [];
	for(var w=0;w<fullListOfCategoryNames.length;w++)
	{
		if($('cat_cb'+w).checked)
			listOfCategories.push(fullListOfCategoryNames[w]);
	}
	listOfCategories = listOfCategories.join('|');
	for(var x=0;x<fullListOfVideoObjects.length;x++)
		if(fullListOfVideoObjects[x].id == editingVideoID)
			videoToWorkWith = fullListOfVideoObjects[x];
	if(!videoToWorkWith)
	{
		alert('An Error occurred while trying to save video\nMessage: Invalid video id.');
		return;
	}
	var exchangetype = 0;//exchangetype
	if($('form3').unexchangable_video.checked) exchangetype = 0;
	else if($('form3').fully_video.checked) exchangetype = 1;
	else if($('form3').limited_video.checked) exchangetype = 2;
	else if($('form3').personal_video.checked) exchangetype = 3;
	if(exchangetype == 0)
	{
		if($('public_video').checked)
		{
			selectSimpleExchange();
			alert("To allow public exchange this video must be exchangable.");
			return;
		}
	}
	var isPPV = false;
	if($('ppv_video').checked == 'true' || $('ppv_video').checked == 'checked' || $('ppv_video').checked == true) isPPV = true;//ppv
	var currPPVPrice = $('ppv_value').value;//ppvprice
	var currPPVSec = $('ppv_preview_time').value;//ppvpreviewsecs
	if(isPPV && Number(currPPVPrice) < 1)
	{
		selectSimplePPV();
		alert("The Pay-Per-View price must be at least $1.00");
		$('ppv_value').style.backgroundColor = 'yellow';
		return;
	}
	if(isPPV && Number(currPPVSec) != 0 && Number(currPPVSec) < 10)
	{
		selectSimplePPV();
		alert("The Pay-Per-View preview seconds must be 0 or at least 10");
		$('ppv_preview_time').style.backgroundColor = 'yellow';
		return;
	}
	$('ppv_value').style.backgroundColor = 'white';
	$('ppv_preview_time').style.backgroundColor = 'white';
	loadingOn();
	if(isPPV)
		MC.Call('GetMerchantAccountInfo',checkMerchantAccount);
	else
		MC.Call('SetVideoInfo',saveVideoCB,'videoID',editingVideoID,'title',$('form3').name_field.value,'desc',leftTruncate($('form3').short_description.value,150),'categories',listOfCategories,'channelIDs',videoToWorkWith.channels.join('|'),'public',$('form3').public_video.checked,'publicprivate',$('form3').private_video.checked,'publicpassword',$('form3').private_video_password.value,'exchangetype',exchangetype,'ppv',isPPV);
}
function checkMerchantAccount(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Check Merchant Account Error: ', errors[resp.error]);
		logError('Check Merchant Account Message: ', resp.message);
		$('merchant_email').value = '';
		if(resp.error == MC.Err.NOT_FOUND)
			return;
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		selectSimplePPV();
		openMAI();
		alert("To allow PPV, you must provide a merchant account.");
		return;
	}
	if(!resp.email)
	{
		selectSimplePPV();
		openMAI();
		logError('Check Merchant Account Error: ', errors[resp.error]);
		logError('Check Merchant Account Message: ', resp.message);
		$('merchant_email').value = '';
		if(resp.error == MC.Err.NOT_FOUND)
			return;
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		alert("To allow PPV, you must provide a merchant account.");
		return;
	}
	var videoToWorkWith = false;
	for(var x=0;x<fullListOfVideoObjects.length;x++)
		if(fullListOfVideoObjects[x].id == editingVideoID)
			videoToWorkWith = fullListOfVideoObjects[x];
	var isPPV = false;
	if($('ppv_video').checked == 'true' || $('ppv_video').checked == 'checked' || $('ppv_video').checked == true) isPPV = true;//ppv
	var currPPVPrice = $('ppv_value').value;//ppvprice
	var currPPVSec = $('ppv_preview_time').value;//ppvpreviewsecs
	var exchangetype = 0;//exchangetype
	if($('form3').unexchangable_video.checked) exchangetype = 0;
	else if($('form3').fully_video.checked) exchangetype = 1;
	else if($('form3').limited_video.checked) exchangetype = 2;
	else if($('form3').personal_video.checked) exchangetype = 3;
	loadingOn();
	MC.Call('SetVideoInfo',saveVideoCB,'videoID',editingVideoID,'title',$('form3').name_field.value,'desc',leftTruncate($('form3').short_description.value,150),'categories',listOfCategories,'channelIDs',videoToWorkWith.channels.join('|'),'public',$('form3').public_video.checked,'publicprivate',$('form3').private_video.checked,'publicpassword',$('form3').private_video_password.value,'exchangetype',exchangetype,'ppv',isPPV,'ppvprice',currPPVPrice,'ppvpreviewsecs',currPPVSec);
}
function saveVideoCB(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Save Video CB Error: ', errors[resp.error]);
		logError('Save Video CB Message: ', resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
			alert('The video requested does not exist.');
		else if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		else
			alert('An Error occurred while trying to save video\nError: ' + errors[resp.error] + '\nMessage: ' + resp.message);
		return;
	}
	//alert('Video file has been saved');
	loadingOn();
	updateVideos();
	$('simple_editor').style.display = 'none';
}
function editVideo()
{
	if(currentChannelObject == undefined) {
		//window.location = "channel_view.html?videoID=" + editingVideoID + "&edit";
		window.location = "channel_view.html?videoID=" + editingVideoID + "&channelID="+fullListOfChannelObjects[0].id+"&edit";
	} else {
		window.location = "channel_view.html?videoID=" + editingVideoID + "&channelID="+currentChannelObject.id+"&edit";
	}
	return;
}
function changeVideoEditorImg(videoToWorkWith)
{
	if(typeof(videoToWorkWith) == 'undefined') return;
	//NEW EXC/PPV/PPX
	if(typeof(videoToWorkWith.ppv) != 'undefined' && videoToWorkWith.ppv && videoToWorkWith.ppv != 'false')
	{
		if(typeof(videoToWorkWith.exchangetype) != 'undefined' && videoToWorkWith.exchangetype && videoToWorkWith.exchangetype != '0')
		{
			$('simple_editor_img').style.background = "url('images/ppx_large.png') no-repeat";
			$('simple_editor_img').title = "Click to preview PPV, Exchange Video";
		}
		else
		{
			$('simple_editor_img').style.background = "url('images/ppv_large.png') no-repeat";
			$('simple_editor_img').title = "Click to preview Pay-Per-View Video";
		}
	}
	else if(typeof(videoToWorkWith.exchangetype) != 'undefined' && videoToWorkWith.exchangetype && videoToWorkWith.exchangetype != '0')
	{
		$('simple_editor_img').style.background = "url('images/exchange_large.png') no-repeat";
		$('simple_editor_img').title = "Click to preview Exchange Video";
	}
	else
	{
		$('simple_editor_img').style.background = "url('images/thumb_clip_lg.gif') no-repeat";
		$('simple_editor_img').title = "Click to preview Private Video";
	}
}
function getMerchantAccountInfoCB(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Get Merchant Account Info Error: ', errors[resp.error]);
		logError('Get Merchant Account Info Message: ', resp.message);
		if($('merchant_email')) $('merchant_email').value = '';
		if(resp.error == MC.Err.NOT_FOUND)
			return;
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		return;
	}
	MemInfo.merchantAccount = resp;
	if(Number(MemInfo.merchantAccount.accounttype) == 1)
	{
		$('propay').checked = true;
		$('paypal').checked = false;
		changeAccountType();
	}
	else
	{
		$('propay').checked = false;
		$('paypal').checked = true;
		changeAccountType();
	}
}
function setProPay()
{
	$('propay').checked = 'checked';
	$('paypal').checked = false;
	changeAccountType();
}
function setPayPal()
{
	$('propay').checked = false;
	$('paypal').checked = 'checked';
	changeAccountType();
}
function changeAccountType()
{
	$('propay_cell').style.background = 'white';
	$('paypal_cell').style.background = 'white';
	if($('propay').checked)
	{
		$('propay_warning').style.display = 'block';
		$('propay_signup').style.display = 'block';
		$('paypal_signup').style.display = 'none';
		$('account_info').innerHTML = '<table><tr><td>ProPay Email:</td><td><input id="merchant_email"></td></tr></table>';
		if(MemInfo.merchantAccount.email) $('merchant_email').value = MemInfo.merchantAccount.email;
		else $('merchant_email').value = '';
	}
	if($('paypal').checked)
	{
		$('propay_warning').style.display = 'none';
		$('propay_signup').style.display = 'none';
		$('paypal_signup').style.display = 'block';
        //UNCOMMENT THIS IF NSE ALLOWS PAYPAL PRO
		$('account_info').innerHTML = '<table><tr><td>PayPal Email:</td><td><input id="merchant_email"></td></tr><!--<tr><td>PayPal Username:</td><td><input id="merchant_username"></td></tr><tr><td>PayPal Password:</td><td><input type="password" id="merchant_password"></td></tr><tr><td>PayPal Signature:</td><td><input id="merchant_signature" maxlength=100></td><td><a href="javascript:void whatIsSignature()">What is this?</a></td></tr>--></table>';
		if(MemInfo.merchantAccount.email) $('merchant_email').value = MemInfo.merchantAccount.email;
		else $('merchant_email').value = '';
        /*//UNCOMMENT THIS IF NSE ALLOWS PAYPAL PRO
		if(MemInfo.merchantAccount.username) $('merchant_username').value = MemInfo.merchantAccount.username;
		else $('merchant_username').value = '';
		if(MemInfo.merchantAccount.password) $('merchant_password').value = MemInfo.merchantAccount.password;
		else $('merchant_password').value = '';
		if(MemInfo.merchantAccount.signature) $('merchant_signature').value = MemInfo.merchantAccount.signature;
		else $('merchant_signature').value = '';
        */
	}
}
function whatIsSignature()
{
	alert("A PayPal signature is required by PayPal so Maxcast can bill the Pay-Per-View purchaser on their behalf. For more information <a href='https://www.paypal.com/helpcenter/main.jsp;jsessionid=LZnCMRh2nWhrxGqhPGL8dV2vdJlDvyZ74P51nQNZVKPPN6LKXT8j!-862048959?t=solutionTab&ft=homeTab&ps=&target=_parent&solutionId=10776&locale=en_US&_dyncharset=UTF-8&countrycode=US&cmd=_help&serverInstance=9005' target='_blank'>click here</a>");
}
function openMAI()
{
	loadingOn();
	MC.Call('GetMerchantAccountInfo',getMerchantAccountInfoCB);
	$('propay_cell').style.background = 'white';
	$('paypal_cell').style.background = 'white';
	if($('merchant_email')) $('merchant_email').style.background = 'white';
	if($('merchant_username')) $('merchant_username').style.background = 'white';
	if($('merchant_password')) $('merchant_password').style.background = 'white';
	if($('merchant_signature')) $('merchant_signature').style.background = 'white';
	$('merchant_box').style.display='block';
}
function saveMAI()
{
	$('propay_cell').style.background = 'white';
	$('paypal_cell').style.background = 'white';
	//TODO: Add save functionality
	var accounttype = 0;
	if($('propay').checked)
	{
		var accountinfoerror = false;
		$('merchant_email').style.background = 'white';
		if(!$('merchant_email').value)
		{
			$('merchant_email').style.background = 'yellow';
			accountinfoerror = true;
		}
		if(!accountinfoerror)
		{
			accounttype = 1;
			loadingOn();
			MC.Call('SetMerchantAccountInfo',setMerchantAccountInfoCB,'accounttype',accounttype,'email',$('merchant_email').value);//,'accountnum',$('merchant_accnum').value,'username',$('merchant_username').value,'password',$('merchant_password').value
		}
		else
		{
			alert("Please fill in all account information before saving.");
		}
	}
	else if($('paypal').checked)
	{
		var accountinfoerror = false;
		if($('merchant_email')) $('merchant_email').style.background = 'white';
		if($('merchant_username')) $('merchant_username').style.background = 'white';
		if($('merchant_password')) $('merchant_password').style.background = 'white';
		if($('merchant_signature')) $('merchant_signature').style.background = 'white';
		if($('merchant_email') && !$('merchant_email').value)
		{
			$('merchant_email').style.background = 'yellow';
			accountinfoerror = true;
		}
		if($('merchant_username') && !$('merchant_username').value)
		{
			$('merchant_username').style.background = 'yellow';
			accountinfoerror = true;
		}
		if($('merchant_password') && !$('merchant_password').value)
		{
			$('merchant_password').style.background = 'yellow';
			accountinfoerror = true;
		}
		if($('merchant_signature') && !$('merchant_signature').value)
		{
			$('merchant_signature').style.background = 'yellow';
			accountinfoerror = true;
		}
		if(!accountinfoerror)
		{
			accounttype = 2;
			loadingOn();
            var merch_email = '';
            var merch_user = '';
            var merch_pass = '';
            var merch_sign = '';
            if($('merchant_email')) merch_email = $('merchant_email').value;
            if($('merchant_username')) merch_user = $('merchant_username').value
            if($('merchant_password')) merch_pass = $('merchant_password').value
            if($('merchant_signature')) merch_sign = $('merchant_signature').value
			MC.Call('SetMerchantAccountInfo',setMerchantAccountInfoCB,'accounttype',accounttype,'email',merch_email,'username',merch_user,'password',merch_pass,'signature',merch_sign);//,'accountnum',$('merchant_accnum').value
		}
		else
		{
			alert("Please fill in all account information before saving.");
		}
	}
	else
	{
		$('propay_cell').style.background = 'yellow';
		$('paypal_cell').style.background = 'yellow';
		alert("Please select a merchant account before saving.");
	}
	//$('merchant_box').style.display='none';
}
function setMerchantAccountInfoCB(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		alert("An error occurred while setting the merchant account information. Please check the information entered and try again.");
		logError('Set Merchant Account Info Error: ', errors[resp.error]);
		logError('Set Merchant Account Info Message: ', resp.message);
		return;
	}
	$('merchant_box').style.display='none';
}
function closeMAI()
{
	$('merchant_box').style.display='none';
}
function ShowChannel(channelToShow)
{
	//New Manage
	//TODO: change the channel_view to this channel
	$('channel_video_title_row_title').innerHTML = 'Title';
	selectedCategoryIndex = 0;
	$('selectedVideosCategories').options[0].selected = true;
	$('selectedVideosCategories').selectedIndex = 0;
	// ///showSelectedVideosCategories($('selectedVideosCategories').options[0].value);
	//otherCategorySelected = false;
	//otherCategoryIndex = 0;
	
	viewLocation = 'channel_view.html?channelID=' + fullListOfChannelObjects[channelToShow].id;
	shareLocation = 'channel_view.html?share&channelID=' + fullListOfChannelObjects[channelToShow].id;
	var channel_title_string = '<div style="float:left">Channel '
								+ (channelToShow+1)
								+ ': <a href="javascript:void viewChannel('
								+ fullListOfChannelObjects[channelToShow].id
								+ ')">'
								+ fullListOfChannelObjects[channelToShow].title
								+ '</a></div><div title="Edit channel settings" class="edit_channel_button" onclick="javascript:void openChannelEditor('
								+ fullListOfChannelObjects[channelToShow].id
								+ ')"></div><div title="Delete channel" class="delete_channel_button" onclick="javascript:void deleteChannel('
								+ fullListOfChannelObjects[channelToShow].id
								+ ', \''
								+ (fullListOfChannelObjects[channelToShow].title).replace(/\'/g,'\\\'').replace(/\"/g,'&quot;')
								+ '\')"></div><div title="View channel" class="view_channel_button" onclick="javascript:void clickedView()"></div>'
								+ '<div title="Links" class="links_channel_button" onclick="javascript:void openEmbedLinks()">&nbsp;</div>';
	//logError(channel_title_string);
	//alert(channel_title_string);
	$('channel_title').innerHTML = channel_title_string;
	$('channel_desc').innerHTML = fullListOfChannelObjects[channelToShow].desc;
	//currentTab = channelToShow;
	$('channel_table').style.height = "350px";
	$('channel_table').innerHTML = "<br /><br /><b>Loading...</b>";//"<br /><br /><center><b>Loading...</b></center>";
	$('Other_Videos').style.display = "block";
	$('other_videos_table').innerHTML = "<br /><br /><b>Loading...</b>";//"<br /><br /><center><b>Loading...</b></center>";
	for(var channelIndex = 0; channelIndex < fullListOfChannelObjects.length; channelIndex++)
	{
		if($('Channel_'+channelIndex+'_Tab')) $('Channel_'+channelIndex+'_Tab').style.background = "url(\"/images/channel_tab.gif\") no-repeat";
	}
	$('All_Channels_Tab').style.background = "url(\"/images/show_all_tab.gif\") no-repeat";
	$('Channel_'+channelToShow+'_Tab').style.background = "url(\"/images/active_tab.gif\") no-repeat";
	currentChannelObject = fullListOfChannelObjects[channelToShow];
	createListOfVideosOnChannel();
	showSelectedVideosCategories($('selectedVideosCategories').options[0].value);
}
function ShowAll()
{
	//New Manage
	$('channel_video_title_row_title').innerHTML = '<a href="javascript:void sortVideosOnChannel()">Title</a>';
	//currentTab = 0;
	selectedCategoryIndex = 0;
	$('selectedVideosCategories').options[0].selected = true;
	$('selectedVideosCategories').selectedIndex = 0;
	// ///showSelectedVideosCategories($('selectedVideosCategories').options[0].value);
	otherCategorySelected = false;
	otherCategoryIndex = 0;
	
	$('channel_title').innerHTML = '';
	$('channel_desc').innerHTML = '';
	$('channel_table').style.height = "450px";
	$('channel_table').innerHTML = "<br /><br /><b>Loading...</b>";//"<br /><br /><center><b>Loading...</b></center>";
	$('Other_Videos').style.display = "none";
	for(var channelIndex = 0; channelIndex < fullListOfChannelObjects.length; channelIndex++)
	{
		if($('Channel_'+channelIndex+'_Tab')) $('Channel_'+channelIndex+'_Tab').style.background = "url(\"/images/channel_tab.gif\") no-repeat";
	}
	$('All_Channels_Tab').style.background = "url(\"/images/show_all_tab_active.gif\") no-repeat";
	currentChannelObject = null;
	
	showSelectedVideosCategories($('selectedVideosCategories').options[0].value);
	//$('Channel_1_Tab').style.background = "url('/images/channel_tab.gif') no-repeat";//"url('/images/active_tab.gif') no-repeat";
}
function addCategory()
{
	if($('add_cat').value == '')
		return;
	if($('add_cat').value == 'All')
	{
		alert("The Category \"All\" already exists",'simple_editor');
		return;
	}
	if($('add_cat').value == 'Add Category')
	{
		alert("The Category \"Add Category\" is not a valid category",'simple_editor');
		return;
	}
	if($('add_cat').value == '<Add Category>')
	{
		alert("The Category \"&lt;Add Category&gt;\" is not a valid category",'simple_editor');
		return;
	}
	if(!isInArray(fullListOfCategoryNames,$('add_cat').value))
	{
		loadingOn();
		if(fullListOfCategoryNames.length)
			MC.Call('SetCategories',reloadCategories,'names',(fullListOfCategoryNames.join('|') + '|' + $('add_cat').value));
		else
			MC.Call('SetCategories',reloadCategories,'names',$('add_cat').value);
	}
	else
	{
		alert("The Category \"" + $('add_cat').value + "\" already exists",'simple_editor');
	}
}
function reloadCategories(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Reload Categories Error: ' + errors[resp.error]);
		logError('Reload Categories Message: ' + resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
	}
	loadingOn();
	MC.Call('GetCategories',updateCategories);
}
function removeCategory(catToRemove)
{
	var listOfCategoriesFromVideos = [];
	for(var videoIndex = 0; videoIndex < fullListOfVideoObjects.length; videoIndex++)
	{
		for(var catIndex = 0; catIndex < fullListOfVideoObjects[videoIndex].categories.length; catIndex++)
		{
			listOfCategoriesFromVideos.push(fullListOfVideoObjects[videoIndex].categories[catIndex]);
		}
	}
	if(!isInArray(listOfCategoriesFromVideos,fullListOfCategoryNames[catToRemove]))
	{
		loadingOn();
		fullListOfCategoryNames.splice(catToRemove,1);
		MC.Call('SetCategories',reloadCategories,'names',fullListOfCategoryNames.join('|'));
	}
	else
	{
		alert("The category \'" + fullListOfCategoryNames[catToRemove]+ "\' must be removed from all videos before being deleted.");
	}
}
function updateCategoriesList()
{
	var videoToWorkWith = null;
	for(var currVideo=0;currVideo<fullListOfVideoObjects.length;currVideo++)
	{
		if(fullListOfVideoObjects[currVideo].id == editingVideoID)
		{
			videoToWorkWith = fullListOfVideoObjects[currVideo];
		}
	}
	if(!videoToWorkWith)
		return;
	editVideoCategoryList = [];
	editVideoCategoryString = '<li><input type="checkbox" id="cat_cb%s" /><label for="cat_cb%s">%s</label><a class="delete" href="javascript:void removeCategory(%s)">Delete</a></li>';// onclick="changedCheckBox()"
	editVideoCategoryCheckedString = '<li><input type="checkbox" id="cat_cb%s" checked="true" /><label for="cat_cb%s">%s</label><a class="delete" href="javascript:void removeCategory(%s)">Delete</a></li>';// onclick="changedCheckBox()"
	for(var y=0;y<fullListOfCategoryNames.length;y++)
	{
		stringToUse = editVideoCategoryString;
		if (typeof(videoToWorkWith.categories) == "undefined") videoToWorkWith.categories = '';
		for(var currCat=0;currCat<videoToWorkWith.categories.length;currCat++)
		{
			if(fullListOfCategoryNames[y] == videoToWorkWith.categories[currCat])
				stringToUse = editVideoCategoryCheckedString;
		}
		editVideoCategoryList.push(stringToUse.format(y,y,fullListOfCategoryNames[y],y));
	}
	editVideoCategoryList.push('<li><input type="text" value="<Add Category>" name="add_cat" id="add_cat" maxlength="30" style="margin-right: 20px;"/><a class="btn_blue left" id="save_btn" href="javascript:void addCategory()"><span class="btn_left"></span><span class="btn_mid">Add</span><span class="btn_right"></span></a></li>');
	$('categories_list').innerHTML = editVideoCategoryList.join('\n');
	
	if($('simple_editor_categories_fieldset').style.display != 'none')
	{
		if($('add_cat').style.display == 'block')
		{
			$('add_cat').focus();
			$('add_cat').select();
		}
	}
}
function reloadVideo()
{
	var videoToWorkWith = null;
	for(var currVideo=0;currVideo<fullListOfVideoObjects.length;currVideo++)
	{
		if(fullListOfVideoObjects[currVideo].id == editingVideoID)
		{
			videoToWorkWith = fullListOfVideoObjects[currVideo];
			break;
		}
	}
	if(!videoToWorkWith)
		return;
	updateCategoriesList();
	if(typeof(videoToWorkWith.public) != 'undefined' && videoToWorkWith.public)
		$('form3').public_video.checked = true;
	else
		$('form3').public_video.checked = false;
	if(typeof(videoToWorkWith.publicprivate) != 'undefined' && videoToWorkWith.publicprivate)
	{
		$('form3').private_video.checked = true;
		if(typeof(videoToWorkWith.publicpassword) != 'undefined' && videoToWorkWith.publicpassword)
			$('form3').private_video_password.value = videoToWorkWith.publicpassword;
		else
			$('form3').private_video_password.value = '';
	}
	else
	{
		$('form3').private_video.checked = false;
		if(typeof(videoToWorkWith.publicpassword) != 'undefined' && videoToWorkWith.publicpassword)
			$('form3').private_video_password.value = videoToWorkWith.publicpassword;
		else
			$('form3').private_video_password.value = '';
	}
	if(typeof(videoToWorkWith.exchangetype) != 'undefined')
	{
		$('form3').unexchangable_video.checked = false;
		$('form3').fully_video.checked = false;
		$('form3').limited_video.checked = false;
		$('form3').personal_video.checked = false;
		if(videoToWorkWith.exchangetype == 0 || videoToWorkWith.exchangetype == '0') $('form3').unexchangable_video.checked = true;
		if(videoToWorkWith.exchangetype == 1 || videoToWorkWith.exchangetype == '1') $('form3').fully_video.checked = true;
		if(videoToWorkWith.exchangetype == 2 || videoToWorkWith.exchangetype == '2') $('form3').limited_video.checked = true;
		if(videoToWorkWith.exchangetype == 3 || videoToWorkWith.exchangetype == '3') $('form3').personal_video.checked = true;
	}
	else
	{
		$('form3').unexchangable_video.checked = true;
		$('form3').fully_video.checked = false;
		$('form3').limited_video.checked = false;
		$('form3').personal_video.checked = false;
	}
	if(typeof(videoToWorkWith.fromclip) != 'undefined' && videoToWorkWith.fromclip)
	{
		$('simple_editor_tab_exchange').style.display = 'none';
		$('simple_editor_tab_noexchange').style.display = 'block';
		if($('public_exchange').style.display != 'none')
		{
			selectSimpleNoExchange();
		}
	}
	else
	{
		if($('simple_editor_noexchange_fieldset').style.display != 'none')
		{
			selectSimpleExchange();
		}
		$('simple_editor_tab_exchange').style.display = 'block';
		$('simple_editor_tab_noexchange').style.display = 'none';
	}
	$('form3').name_field.value = videoToWorkWith.title;
	$('form3').short_description.value = videoToWorkWith.desc;
}
function sortOtherVideos()
{
	createOtherList(true);
}
function createOtherList(sortByTitle)
{
	//New Manage
	/*
	var otherCategorySelected = false;//New Manage
	var otherCategoryIndex = 0;//New Manage
	*/
	if(!currentChannelObject) return;
	var currentlySelectedOtherCategory = false;
	if(otherCategorySelected && otherCategoryIndex) currentlySelectedOtherCategory = $('otherVideosCategories').options[otherCategoryIndex].value;
	var listOfOtherVideos = [];
	var listOfIDsOfVideosInChannel = [];//Object != object but ID == ID
	for(var videoInChannelIndex = 0; videoInChannelIndex < listOfVideosOnCurrChannel.length; videoInChannelIndex++)
	{
		listOfIDsOfVideosInChannel.push(listOfVideosOnCurrChannel[videoInChannelIndex].id);
	}
	for(var videoIndex = 0; videoIndex < fullListOfVideoObjects.length; videoIndex++)
	{
		if(!isInArray(listOfIDsOfVideosInChannel,fullListOfVideoObjects[videoIndex].id))
		{
			if(currentlySelectedOtherCategory)
			{
				var foundCategory = false;
				for(var catIndex = 0; catIndex < fullListOfVideoObjects[videoIndex].categories.length; catIndex++)
				{
					if(fullListOfVideoObjects[videoIndex].categories[catIndex] == currentlySelectedOtherCategory)
					{
						foundCategory = true;
						break;
					}
				}
				if(foundCategory)
				{
					listOfOtherVideos.push(fullListOfVideoObjects[videoIndex]);
				}
			}
			else
			{
				listOfOtherVideos.push(fullListOfVideoObjects[videoIndex]);
			}
		}
	}
	//alert("fullListOfVideoObjects: "+fullListOfVideoObjects.length+"\nlistOfVideosOnCurrChannel:"+listOfVideosOnCurrChannel.length+"\nlistOfOtherVideos:"+listOfOtherVideos.length);
	//TODO: Update checkboxTitle
	//TODO: Update otherChannelsList
	/*WORKING START*/
	var otherVideosVideoRowInner = '<tr id="video%srow" valign="top">\
									<td class="channel_table_row_img_small">\
										<div style="width:26px;">\
											<div id="other_video_logo_%s" title="Click to preview Private Video" class="left" style="background:url(\'/images/mc_cliplogo_small.gif\') no-repeat; width:26px; height:26px; cursor:pointer;" onclick="javascript:void previewVideo(%s)"></div>\
										</div>\
									</td>\
									<td class="channel_table_row_title_small" valign="middle">\
										<div class="left" style="margin-left:5px; font-size:10px; width:175px; height:15px; white-space:nowrap; overflow:hidden;">\
											<a href="channel_view.html?videoID=%s&channelID=0"><b>%s</b></a>\
										</div>\
									</td>\
									<td class="channel_table_row_buttons_small" valign="middle">\
										<div class="left" style="width:95px; height:15px;">\
											<div id="add_button_other_video_%s" title="Add video to channel" class="add_channel_button right" onclick="javascript:void addVideoToChannel(%s,%s)"></div>\
											<div id="edit_button_other_video_%s" title="Edit video settings" class="edit_channel_button right" onclick="javascript:void openVideoEditor(%s,700)"></div>\
											<div id="new_video_%s" class="new_video_button right" style="display:none"></div>\
										</div>\
									</td>\
									<td class="channel_table_row_checkboxes_small" valign="top">\
										<div class="left" style="width:215px; height:15px; vertical-align: top; margin-top:0; padding-top:0;">\
											<div id="other_videos_table_checkboxes_%s">%s</div>\
										</div>\
									</td>\
									<td class="channel_table_row_categories_small" valign="top">\
										<div class="left" style="width:175px; height:15px; overflow:hidden; white-space:nowrap; verticalAlign:top; margin-top:3px;">\
											%s\
										</div>\
									</td>\
									<td class="channel_table_row_sort_small">\
										<div class="left" style="width:40px; height:15px;">\
											&nbsp;\
										</div>\
										<!--<div class="left" style="background:url(\'/images/icon_move_up.gif\') no-repeat; width:13px; height:13px; cursor:pointer; zIndex: 100000;" onclick="javascript:void MoveUp(%s)"></div><div class="left" style="background:url(\'/images/icon_move_down.gif\') no-repeat; width:13px; height:13px; margin-left:5px; cursor:pointer; zIndex: 100000;" onclick="javascript:void MoveDown(%s)"></div>-->\
									</td>\
								</tr>';
	var otherVideosVideoRow = '<tr id="other_videos_video_row_%s">\
							<td colspan="5">\
								<div id="other_videos_table_inner_%s" width="100%" style="height:22px; overflow:hidden; margin-top:-6px;">\
								</div>\
							</td>\
						</tr>';
	var otherVideosVideoOddRow = '<tr id="other_videos_video_row_%s" class="odd_row">\
							<td colspan="5">\
								<div id="other_videos_table_inner_%s" width="100%" style="height:22px; overflow:hidden; margin-top:-6px;">\
								</div>\
							</td>\
						</tr>';
	/*SORT videos on channel*/
	if(sortByTitle)
	{
		listOfOtherVideos.sort(function(a,b){if(a.title<b.title) return -1;if(a.title==b.title) return 0;return 1;});
		if(otherVideosDescending) listOfOtherVideos.reverse();
		otherVideosDescending = !otherVideosDescending;
	}
	else
	{
		listOfOtherVideos.sort(function(a,b){return Number(a.id)-Number(b.id);});
		listOfOtherVideos.reverse();//Newest first
	}
	/* end SORT */
	//Categories
	var otherVideosRowsList = [];
	var otherVideosRowsInnerList = [];
	for(var rownum=0; rownum<listOfOtherVideos.length; rownum++)
	{
		var videoToWorkWith = listOfOtherVideos[rownum];
		var otherVideosListOfCategories = videoToWorkWith.categories;
		var catLength = 0;
		if(otherVideosListOfCategories) catLength = otherVideosListOfCategories.length;
		var newListOfCat = [];
		for(var y=0;y<catLength;y++)
		{
			if(isInArray(fullListOfCategoryNames,otherVideosListOfCategories[y]))
				newListOfCat.push(otherVideosListOfCategories[y]);
		}
		var otherVideosHtmlStringOfCategories = newListOfCat.join(', ');
		var tempVideoID = videoToWorkWith.id;
		var tempVideoTitle = videoToWorkWith.title;
		var tempVideoDesc = videoToWorkWith.desc;
		if(rownum%2) otherVideosRowsList.push(otherVideosVideoRow.format(rownum,rownum));
		else otherVideosRowsList.push(otherVideosVideoOddRow.format(rownum,rownum));
		
		var categoriesToShow = '&nbsp;';
		if (typeof(videoToWorkWith.categories) == "undefined") videoToWorkWith.categories = '';
		if(videoToWorkWith.categories.length) categoriesToShow = videoToWorkWith.categories;
		otherVideosRowsInnerList.push(otherVideosVideoRowInner.format(tempVideoID,
																		rownum,
																		tempVideoID,
																		tempVideoID,
																		tempVideoTitle,
																		rownum,
																		tempVideoID,
																		currentChannelObject.id,
																		rownum,
																		tempVideoID,
																		tempVideoID,
																		rownum,
																		'<table cellspacing=0 cellpadding=0><tr><td><div style="width:215px; overflow:hidden">'+getChannelIndicesForVideo(videoToWorkWith)+'</div></td></tr></table>',
																		categoriesToShow,
																		tempVideoID,
																		tempVideoID));
		//TODO: SPEEDUP no checkboxes
	}
	$('other_videos_table').innerHTML = '<table width="98%" cellspacing=0 cellpadding=0>' + otherVideosRowsList.join('\n') + '</table>';
	for(var rowIndex=0; rowIndex<listOfOtherVideos.length; rowIndex++)
	{
		$('other_videos_table_inner_'+rowIndex).innerHTML = '<table width="100%">' + otherVideosRowsInnerList[rowIndex] + '</table>';
		var videoToWorkWith = listOfOtherVideos[rowIndex];
		if(typeof(videoToWorkWith.uneditable) != 'undefined' && videoToWorkWith.uneditable)
		{
			$('edit_button_other_video_' + rowIndex).title = 'Uneditable due to exchange setting';
			$('edit_button_other_video_' + rowIndex).onclick = function() {};
			$('edit_button_other_video_' + rowIndex).style.background = "url('/images/edit_button_off.gif') no-repeat";
			$('edit_button_other_video_' + rowIndex).style.cursor = 'default';
			$('add_button_other_video_' + rowIndex).title = 'Cannot add due to exchange setting';
			//$('add_button_other_video_' + rowIndex).onclick = "javascript:void function dummy(){}";
			$('add_button_other_video_' + rowIndex).onclick = function() {};
			$('add_button_other_video_' + rowIndex).style.background = "url('/images/add_button_off.gif') no-repeat";
			$('add_button_other_video_' + rowIndex).style.cursor = 'default';
			//alert($('add_button_other_video_' + rowIndex).onclick);
		}
		else
		{
			$('edit_button_other_video_' + rowIndex).title = 'Edit video settings';
			$('add_button_other_video_' + rowIndex).title = 'Add video to channel';
		}
		changeOtherVideoLogo(videoToWorkWith, rowIndex);
	}
	/*WORKING CURRENT START*/
	/*WORKING CURRENT END*/
	/*WORKING END*/
	//alert("Finish createOtherList " + listOfOtherVideos);
	displayNew5Videos();
}
function changeOtherVideoLogo(videoToWorkWith, rownum)
{
	//NEW EXC/PPV/PPX
	if(typeof(videoToWorkWith.ppv) != 'undefined' && videoToWorkWith.ppv && videoToWorkWith.ppv != 'false')
	{
		if(typeof(videoToWorkWith.exchangetype) != 'undefined' && videoToWorkWith.exchangetype && videoToWorkWith.exchangetype != '0')
		{
			$('other_video_logo_' + rownum).style.background = "url(\'/images/ppx_small.png\') no-repeat";// -1px -37px";
			$('other_video_logo_' + rownum).title = "Click to preview PPV, Exchange Video";
		}
		else
		{
			$('other_video_logo_' + rownum).style.background = "url(\'/images/ppv_small.png\') no-repeat";// -1px -37px";
			$('other_video_logo_' + rownum).title = "Click to preview Pay-Per-View Video";
		}
	}
	else if(typeof(videoToWorkWith.exchangetype) != 'undefined' && videoToWorkWith.exchangetype && videoToWorkWith.exchangetype != '0')
	{
		$('other_video_logo_' + rownum).style.background = "url(\'/images/exchange_small.png\') no-repeat";// -1px -37px";
		$('other_video_logo_' + rownum).title = "Click to preview Exchange Video";
	}
	else
	{
	}
}
function getChannelIndicesForVideo(videoToWorkWith)
{
	var tempText = '';
	for(var channelsIndex=0;channelsIndex<fullListOfChannelObjects.length;channelsIndex++)
	{
		//TODO: SPEEDUP Add each channel index to other_videos_table_checkboxes_ that the video is currently on
		if(isInArray(videoToWorkWith.channels,fullListOfChannelObjects[channelsIndex].id))
		{
			if(tempText.length > 0) tempText = tempText + ', ';
			tempText = tempText + (channelsIndex + 1);
			if(channelsIndex+1<fullListOfChannelObjects.length)
			{
				channelsIndex = channelsIndex + 1;
				if(isInArray(videoToWorkWith.channels,fullListOfChannelObjects[channelsIndex].id))
				{
					tempText = tempText + '-';
					while(isInArray(videoToWorkWith.channels,fullListOfChannelObjects[channelsIndex].id))
					{
						channelsIndex = channelsIndex + 1;
						if(channelsIndex>=fullListOfChannelObjects.length)
						{
							break;
						}
					}
					tempText = tempText + (channelsIndex);
				}
			}
		}
	}
	return tempText;
}
function displayNew5Videos()
{
	if(!newest5Videos.length) return;
	for(var newIndex = 0; newIndex < newest5Videos.length; newIndex++)
	{
		if($('new_video_'+newest5Videos[newIndex].id) && $('new_video_'+newest5Videos[newIndex].id).style)
		{
			$('new_video_'+newest5Videos[newIndex].id).style.display = 'block';
		}
	}
}
function createNewest5Videos()
{
	var newListOfVideoObjects = fullListOfVideoObjects;
	newListOfVideoObjects.sort(function(a,b){return Number(a.id)-Number(b.id);});
	newListOfVideoObjects.reverse();
	newest5Videos = [];
	for(var x = 0; x<5; x++)
	{
		if(newListOfVideoObjects.length <= x) return;
		newest5Videos.push(newListOfVideoObjects[x]);
	}
}
function createChannelTable(sortByTitle)
{
	/*
	TODO: Things needed:
			currentChannelObject
			fullListOfChannelObjects
			currentTab
			listOfVideosOnCurrChannel
	*/
	var channelVideoRowsList = [];
	var channelVideoRowInner = '<tr id="video%srow" valign="top" height="15px" width="770px;">\
									<td class="channel_table_row_image" rowspan=2>\
										<div style="width:35px;">\
											<div id="video_logo_%s" title="Click to preview Private Video" class="left" style="background:url(\'/images/mc_cliplogo_large.gif\') no-repeat; width:35px; height:30px; cursor:pointer;" onclick="javascript:void previewVideo(%s)"></div>\
										</div>\
									</td>\
									<td class="channel_table_row_title">\
										<div class="left" style="width:175px; height:15px; white-space:nowrap; overflow:hidden;">\
											<a href="channel_view.html?videoID=%s&channelID=%s" style="height:14px; overflow:hidden;"><b>%s</b></a>\
										</div>\
									</td>\
									<td class="channel_table_row_buttons">\
										<div class="left" style="width:95px; height:15px;">\
											<div id="remove_button_video_%s" title="Remove video from channel" class="remove_channel_button right" onclick="javascript:void removeVideoFromChannel(%s,%s)"></div>\
											<div id="edit_button_video_%s" title="Edit video settings" class="edit_channel_button right" onclick="javascript:void openVideoEditor(%s,300)"></div>\
											<div id="new_video_%s" class="new_video_button right" style="display:none"></div>\
										</div>\
									</td>\
									<td class="channel_table_row_checkboxes">\
										<div class="left" style="width:215px; height:16px;">\
											<div id="channel_table_checkboxes_%s">%s</div>\
										</div>\
									</td>\
									<td class="channel_table_row_categories">\
										<div class="left" style="width:175px; height:15px; overflow:hidden; white-space:nowrap;">\
											%s\
										</div>\
									</td>\
									<td class="channel_table_row_sort">\
										<div class="left" style="width:40px; height:15px;">\
											<div class="left" style="background:url(\'/images/icon_move_up.gif\') no-repeat; width:15px; height:15px; cursor:pointer; zIndex: 100000;" onclick="javascript:void MoveUp(%s)"></div>\
											<div class="left" style="background:url(\'/images/icon_move_down.gif\') no-repeat; width:15px; height:15px; cursor:pointer; zIndex: 100000;" onclick="javascript:void MoveDown(%s)"></div>\
										</div>\
									</td>\
								</tr>\
								<tr id="desc%srow" style="width:800px;">\
									<td class="channel_table_row_description" colspan=5>\
										<div style="white-space:nowrap; overflow:hidden; width:770px; color:#888888;">%s</div>\
									</td>\
								</tr>';
	if(categorySelected) channelVideoRowInner = '<tr id="video%srow" valign="top" height="15px" width="770px;">\
									<td class="channel_table_row_image" rowspan=2>\
										<div style="width:35px;">\
											<div id="video_logo_%s" title="Click to preview Private Video" class="left" style="background:url(\'/images/mc_cliplogo_large.gif\') no-repeat; width:35px; height:30px; cursor:pointer;" onclick="javascript:void previewVideo(%s)"></div>\
										</div>\
									</td>\
									<td class="channel_table_row_title">\
										<div class="left" style="width:175px; height:15px; white-space:nowrap; overflow:hidden;">\
											<a href="channel_view.html?videoID=%s&channelID=%s" style="height:14px; overflow:hidden;"><b>%s</b></a>\
										</div>\
									</td>\
									<td class="channel_table_row_buttons">\
										<div class="left" style="width:95px; height:15px;">\
											<div id="remove_button_video_%s" title="Remove video from channel" class="remove_channel_button right" onclick="javascript:void removeVideoFromChannel(%s,%s)"></div>\
											<div id="edit_button_video_%s" title="Edit video settings" class="edit_channel_button right" onclick="javascript:void openVideoEditor(%s,300)"></div>\
											<div id="new_video_%s" class="new_video_button right" style="display:none"></div>\
										</div>\
									</td>\
									<td class="channel_table_row_checkboxes">\
										<div class="left" style="width:215px; height:16px;">\
											<div id="channel_table_checkboxes_%s">%s</div>\
										</div>\
									</td>\
									<td class="channel_table_row_categories">\
										<div class="left" style="width:175px; height:15px; overflow:hidden; white-space:nowrap;">\
											%s\
										</div>\
									</td>\
									<td class="channel_table_row_sort">\
										<div class="left" style="width:40px; height:15px;">\
											<!--<div class="left" style="background:url(\'/images/icon_move_up.gif\') no-repeat; width:15px; height:15px; cursor:pointer; zIndex: 100000;" onclick="javascript:void MoveUp(%s)"></div>\
											<div class="left" style="background:url(\'/images/icon_move_down.gif\') no-repeat; width:15px; height:15px; cursor:pointer; zIndex: 100000;" onclick="javascript:void MoveDown(%s)"></div>\
										-->&nbsp;</div>\
									</td>\
								</tr>\
								<tr id="desc%srow" style="width:800px;">\
									<td class="channel_table_row_description" colspan=5>\
										<div style="white-space:nowrap; overflow:hidden; width:770px; color:#888888;">%s</div>\
									</td>\
								</tr>';
	if(!currentChannelObject) channelVideoRowInner = '<tr id="video%srow">\
									<td class="channel_table_row_img_small">\
										<div style="width:26px;">\
											<div id="video_logo_%s" title="Click to preview Private Video" class="left" style="background:url(\'/images/mc_cliplogo_small.gif\') no-repeat; width:26px; height:26px; cursor:pointer;" onclick="javascript:void previewVideo(%s)"></div>\
										</div>\
									</td>\
									<td class="channel_table_row_title_small">\
										<div class="left" style="margin-left:5px; font-size: 10px; width:175px; height:15px; white-space:nowrap; overflow:hidden;">\
											<a href="channel_view.html?videoID=%s&channelID=0"><b>%s</b></a>\
										</div>\
									</td>\
									<td class="channel_table_row_buttons_small">\
										<div class="left" style="width:95px; height:15px;">\
											<div id="delete_button_video_%s" title="Delete video" class="delete_channel_button right" onclick="javascript:void deleteVideo(%s,\'%s\')"></div>\
											<div id="edit_button_video_%s" title="Edit video settings" class="edit_channel_button right" onclick="javascript:void openVideoEditor(%s,300)"></div>\
											<div id="new_video_%s" class="new_video_button right" style="display:none"></div>\
										</div>\
									</td>\
									<td class="channel_table_row_checkboxes_small" valign="top">\
										<div class="left" style="width:215px; height:15px; vertical-align: top; margin-top:0; padding-top:0;">\
											<div id="channel_table_checkboxes_%s">%s</div>\
										</div>\
									</td>\
									<td class="channel_table_row_categories_small" valign="top">\
										<div class="left" style="width:175px; height:15px; overflow:hidden; white-space:nowrap; verticalAlign:top; margin-top:3px;">\
											%s\
										</div>\
									</td>\
									<td class="channel_table_row_sort_small">\
										<div class="left" style="width:40px; height:15px;">\
											&nbsp;\
										</div>\
									</td>\
								</tr>';
	var channelVideoRow = '<tr id="channel_video_row_%s">\
							<td colspan="5">\
								<div id="channel_table_inner_%s" width="100%">\
								</div>\
							</td>\
						</tr>';
	var channelVideoOddRow = '<tr id="channel_video_row_%s" class="odd_row">\
							<td colspan="5">\
								<div id="channel_table_inner_%s" width="100%">\
								</div>\
							</td>\
						</tr>';
	/*SORT videos on channel*/
	if(!currentChannelObject)
	{
		if(sortByTitle)
		{
			listOfVideosOnCurrChannel.sort(function(a,b){if(a.title<b.title) return -1;if(a.title==b.title) return 0;return 1;});
			if(allVideosDescending) listOfVideosOnCurrChannel.reverse();
			allVideosDescending = !allVideosDescending;
		}
		else
		{
			listOfVideosOnCurrChannel.sort(function(a,b){return Number(a.id)-Number(b.id);});
			listOfVideosOnCurrChannel.reverse();//Newest first
		}
	}
	/* end SORT */
	//Categories
	var videoRowsInChannelList = [];
	var videoRowsInnerInChannelList = [];
	for(var rownum=0; rownum<listOfVideosOnCurrChannel.length; rownum++)
	{
		var videoToWorkWith = listOfVideosOnCurrChannel[rownum];
		listOfCategoriesInChannel = videoToWorkWith.categories;
		var catLength = 0;
		if(listOfCategoriesInChannel) catLength = listOfCategoriesInChannel.length;
		var newListOfCat = [];
		for(var y=0;y<catLength;y++)
		{
			if(isInArray(fullListOfCategoryNames,listOfCategoriesInChannel[y]))
				newListOfCat.push(listOfCategoriesInChannel[y]);
		}
		var htmlStringOfCategoriesInChannel = newListOfCat.join(', ');
		var tempVideoID = videoToWorkWith.id;
		var tempStreamID = videoToWorkWith.stream_id;
		var tempVideoTitle = videoToWorkWith.title;
		var tempVideoDesc = videoToWorkWith.desc;
		if(rownum%2) videoRowsInChannelList.push(channelVideoRow.format(rownum,rownum));
		else videoRowsInChannelList.push(channelVideoOddRow.format(rownum,rownum));
		var categoriesToShow = '&nbsp;';
		if (typeof(videoToWorkWith.categories) == "undefined") videoToWorkWith.categories = '';
		if(videoToWorkWith.categories.length) categoriesToShow = videoToWorkWith.categories;
		if(currentChannelObject)
			videoRowsInnerInChannelList.push(channelVideoRowInner.format(rownum, 
																			rownum,
																			tempVideoID,
																			tempVideoID,
																			currentChannelObject.id,
																			tempVideoTitle,
																			rownum,
																			tempVideoID,
																			currentChannelObject.id,
																			rownum,
																			tempVideoID,
																			rownum,
																			rownum,
																			'<table cellspacing=0 cellpadding=0><tr><td><div style="width:215px; overflow:hidden">'+getChannelIndicesForVideo(videoToWorkWith)+'</div></td></tr></table>',
																			categoriesToShow,
																			tempVideoID,
																			tempVideoID,
																			rownum,
																			tempVideoDesc));
		else
			videoRowsInnerInChannelList.push(channelVideoRowInner.format(rownum, 
																			rownum,
																			tempVideoID,
																			tempVideoID,
																			tempVideoTitle,
																			rownum,
																			tempVideoID,
																			(tempVideoTitle).replace(/\'/g,'\\\'').replace(/\"/g,'&quot;'),
																			rownum,
																			tempVideoID,
																			tempVideoID,
																			rownum,
																			'<table cellspacing=0 cellpadding=0><tr><td><div style="width:215px; overflow:hidden">'+getChannelIndicesForVideo(videoToWorkWith)+'</div></td></tr></table>',
																			categoriesToShow));
		//TODO: SPEEDUP no checkboxes
	}
	$('channel_table').innerHTML = '<table width="98%" cellspacing=0 cellpadding=0>' + videoRowsInChannelList.join('\n') + '</table>';
	for(var rowIndex=0; rowIndex<listOfVideosOnCurrChannel.length; rowIndex++)
	{
		$('channel_table_inner_'+rowIndex).innerHTML = '<table width="100%">' + videoRowsInnerInChannelList[rowIndex] + '</table>';
		$('channel_table_inner_'+rowIndex).style.overflow = 'hidden';
		if(currentChannelObject)
		{
			$('channel_table_inner_'+rowIndex).style.height = '45px';
		}
		else
		{
			$('channel_table_inner_'+rowIndex).style.height = '22px';
			$('channel_table_inner_'+rowIndex).style.margin = '-6px 0 0 0';
		}
		var videoToWorkWith = listOfVideosOnCurrChannel[rowIndex];
		if(typeof(videoToWorkWith.uneditable) != 'undefined' && videoToWorkWith.uneditable)
		{
			$('edit_button_video_' + rowIndex).title = 'Uneditable due to exchange setting';
			$('edit_button_video_' + rowIndex).onclick = function() {};
			$('edit_button_video_' + rowIndex).style.background = "url('/images/edit_button_off.gif') no-repeat";
			$('edit_button_video_' + rowIndex).style.cursor = "default";
		}
		else
		{
			$('edit_button_video_' + rowIndex).title = 'Edit video settings';
		}
		changeVideoLogo(videoToWorkWith, rowIndex);
	}
	if(currentChannelObject) MN.SetInnerText($('channel_sort'),'Sort');
	else MN.SetInnerText($('channel_sort'),'');
	displayNew5Videos();
}
function changeVideoLogo(videoToWorkWith, rownum)
{
	if(!currentChannelObject)
	{
		if(typeof(videoToWorkWith.ppv) != 'undefined' && videoToWorkWith.ppv && videoToWorkWith.ppv != 'false')
		{
			if(typeof(videoToWorkWith.exchangetype) != 'undefined' && videoToWorkWith.exchangetype && videoToWorkWith.exchangetype != '0')
			{
				$('video_logo_' + rownum).style.background = "url(\'/images/ppx_small.png\') no-repeat";// -1px -37px";
				$('video_logo_' + rownum).title = "Click to preview PPV, Exchange Video";
			}
			else
			{
				$('video_logo_' + rownum).style.background = "url(\'/images/ppv_small.png\') no-repeat";// -1px -37px";
				$('video_logo_' + rownum).title = "Click to preview Pay-Per-View Video";
			}
		}
		else if(typeof(videoToWorkWith.exchangetype) != 'undefined' && videoToWorkWith.exchangetype && videoToWorkWith.exchangetype != '0')
		{
			$('video_logo_' + rownum).style.background = "url(\'/images/exchange_small.png\') no-repeat";// -1px -37px";
			$('video_logo_' + rownum).title = "Click to preview Exchange Video";
		}
		else
		{
		}
	}
	else
	{
		if(typeof(videoToWorkWith.ppv) != 'undefined' && videoToWorkWith.ppv && videoToWorkWith.ppv != 'false')
		{
			if(typeof(videoToWorkWith.exchangetype) != 'undefined' && videoToWorkWith.exchangetype && videoToWorkWith.exchangetype != '0')
			{
				$('video_logo_' + rownum).style.background = "url(\'/images/ppx_normal.png\') no-repeat";// -1px -37px";
				$('video_logo_' + rownum).title = "Click to preview PPV, Exchange Video";
			}
			else
			{
				$('video_logo_' + rownum).style.background = "url(\'/images/ppv_normal.png\') no-repeat";// -1px -37px";
				$('video_logo_' + rownum).title = "Click to preview Pay-Per-View Video";
			}
		}
		else if(typeof(videoToWorkWith.exchangetype) != 'undefined' && videoToWorkWith.exchangetype && videoToWorkWith.exchangetype != '0')
		{
			$('video_logo_' + rownum).style.background = "url(\'/images/exchange_normal.png\') no-repeat";// -1px -37px";
			$('video_logo_' + rownum).title = "Click to preview Exchange Video";
		}
		else
		{
		}
	}
}
function reloadVideosList(resp)
{
	loadingOff();
	//New Manage
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Reload Video List Error: ' + errors[resp.error]);
		logError('Reload Video List Message: ' + resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		if(resp.error == MC.Err.NOT_FOUND)
		{
			alert('The video or channel requested does not exist.');
			return;
		}
	}
	logError('Reload Video List Success');
	createNewest5Videos();
	createChannelTable(false);
	ShowTabs(currentTab);
	createOtherList(false);
}
function sortVideosOnChannel()
{
	logError('Sort Videos On Channel');
	if(!currentChannelObject) listOfVideosOnCurrChannel = fullListOfVideoObjects;
	createChannelTable(true);
}
function reloadAllVideos(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Reload Video List Error: ' + errors[resp.error]);
		logError('Reload Video List Message: ' + resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		if(resp.error == MC.Err.NOT_FOUND)
		{
			alert('The video or channel requested does not exist.');
			return;
		}
	}
	fullListOfVideoObjects = [];
	for(var x=0;x<resp.videos.length;x++)
	{
		if(!isInArray(fullListOfVideoObjects,resp.videos[x]))
			fullListOfVideoObjects.push(resp.videos[x]);
	}
	fullListOfVideoObjects.sort(function(a,b){return Number(a.id)-Number(b.id);});
	//TODO: fullListOfVideoObjects.reverse();//Newest first?
	showSelectedVideosCategories($('selectedVideosCategories').options[$('selectedVideosCategories').selectedIndex].value);
}
function updateVideos(resp)
{
	loadingOff();
	if(resp)
	{
		if(resp.error != MC.Err.SUCCESS)
		{
			logError('Update Videos Error: ' + errors[resp.error]);
			logError('Update Videos Message: ' + resp.message);
			if(resp.error == MC.Err.NO_SESSION)
				loggingOut({});
			else if(resp.error == MC.Err.NOT_FOUND)
				alert('The video or channel requested does not exist.');
		}
	}
	fullListOfVideoObjects = [];
	loadingOn();
	MC.Call('GetChannelVideos',reloadAllVideos, 'profiles', 'ALL');
}
//end SIMPLE VIDEO EDITOR
//ADD MIN POPUP
function openAddMin()
{
	loadingOn();
	MC.Call('HaveSession',reportSession);
	$('add_min').style.display = 'block';
}
function closeAddMin()
{
	$('add_min').style.display = 'none';
}
function addMinToCart()
{
	if($('no_thank_you').checked)
	{
		$('add_min_form').sku.value = '';
		closeAddMin();
	}
	else if($('min_3500').checked)
	{
		$('add_min_form').sku.value = '1006481';
		$('add_min_form').submit();
	}
	else if($('min_9000').checked)
	{
		$('add_min_form').sku.value = '1006480';
		$('add_min_form').submit();
	}
	else if($('min_24000').checked)
	{
		$('add_min_form').sku.value = '1006479';
		$('add_min_form').submit();
	}
}
//end ADD MIN POPUP
//CONFIRM POPUP
function openConfirm(title,message)
{
	$('confirm_box').style.display = 'block';
	$('confirm_title').innerHTML = title + '<a class=\"close\" href=\"javascript:void closeConfirm()"><\/a>';
	$('confirm_message').innerHTML = message;
}
function cancelConfirm()
{
	closeConfirm();
}
function okayConfirm()
{
	closeConfirm();
}
function closeConfirm()
{
	$('confirm_box').style.display = 'none';
	//resetConfirm();
}
function resetConfirm()
{
	closeConfirm = function(){$('confirm_box').style.display = 'none';};
	cancelConfirm = closeConfirm();
	okayConfirm = closeConfirm();
}
//end CONFIRM POPUP
//ALERT POPUP
function alert(message,extraArgs,title)
{
	if(message == 'You are not logged in or your session expired')
	{
		loadingOff();
		closeAlert = function(){$('alert_box').style.display = 'none';if(!debugOn)window.location = 'index.html'; else if(confirm("Would you like to exit?")) window.location = "index.html";};
		$('alert_box').style.top = '500px';
		$('alert_box').style.display = 'block';
		$('alert_message').innerHTML = message;
		return;
	}
	if(extraArgs)
	{
		if(extraArgs == 'channel_editor')
		{
			$('channel_editor').style.display = 'none';
			closeAlert = function(){$('alert_box').style.display = 'none';$('channel_editor').style.display = 'block';};
			$('alert_box').style.top = '350px';
		}
		else if(extraArgs == 'simple_editor')
		{
			$('simple_editor').style.display = 'none';
			closeAlert = function(){$('alert_box').style.display = 'none';$('simple_editor').style.display = 'block';};
			$('alert_box').style.top = '600px';
		}
		else if(extraArgs == 'add_categories_box')
		{
			$('add_categories_box').style.display = 'none';
			closeAlert = function(){$('alert_box').style.display = 'none';$('add_categories_box').style.display = 'block';};
			$('alert_box').style.top = '500px';
		}
		$('alert_title').innerHTML = 'Alert<a class=\"close\" href=\"javascript:void closeAlert()\"><\/a>';
		if(extraArgs == 'title')
		{
			if(title) $('alert_title').innerHTML = title + '<a class=\"close\" href=\"javascript:void closeAlert()"><\/a>';
		}
	}
	else
	{
		$('alert_box').style.top = '500px';
		resetAlert();
	}
	$('alert_box').style.display = 'block';
	$('alert_message').innerHTML = message;
}
function closeAlert()
{
	$('alert_box').style.display = 'none';
}
function okayAlert()
{
	closeAlert();
}
function resetAlert()
{
	okayAlert = function(){closeAlert();};
	closeAlert = function(){$('alert_box').style.display = 'none';};
	$('alert_title').innerHTML = 'Alert<a class=\"close\" href=\"javascript:void closeAlert()\"><\/a>';
}
//end ALERT POPUP
function SetChnlVidRet(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Set Channel Video Return Error: ', errors[resp.error]);
		logError('Set Channel Video Message: ', resp.message);
	}
	else
	{
		logError('Set Channel Video Return Success');
	}
	loadingOn();
	MC.Call('GetChannelVideos',reloadVideosList,'channelID',currentChannelObject.id);
}
function MoveUp(id)
{
	//find the video in the internal video array and update the array
	var currentVids = listOfVideosOnCurrChannel;
	var curVid;
	for(var i = 0; i < currentVids.length; i++)
	{
		curVid = currentVids[i];
		if(curVid.id == id)
		{
			logError('found video to move up');
			if(currentVids[i - 1] != null)
			{
				logError('moving up video');
				var prevVid = currentVids[i - 1];
				currentVids[i - 1] = curVid;
				currentVids[i] = prevVid;
				
				logError('currentVids set');
				//create the pipe-separated list of video ids
				var videoIDs = '';
				for(var j = 0; j < currentVids.length; j++)
				{
					videoIDs += currentVids[j].id;
					if(j < currentVids.length - 1)
						videoIDs += '|';
				}
				//alert('new list of ids: ', videoIDs);
				//call to the webservice to update on that side
				loadingOn();
				currentChannelObject.videos = videoIDs.split('|');
				MC.Call('SetChannelVideos', SetChnlVidRet, 'channelID', currentChannelObject.id, 'videoIDs', videoIDs);
				break;
			}
			logError('cannot move video up');
		}
	}
}
function MoveDown(id)
{
	//find the video in the internal video array and update the array
	var currentVids = listOfVideosOnCurrChannel;
	var curVid;
	for(var i = 0; i < currentVids.length; i++)
	{
		curVid = currentVids[i];
		if(curVid.id == id)
		{
			logError('found video to move down');
			if(currentVids[i + 1] != null)
			{
				logError('moving down video');
				var prevVid = currentVids[i + 1];
				currentVids[i + 1] = curVid;
				currentVids[i] = prevVid;
				
				logError('currentVids set');
				//create the pipe-separated list of video ids
				var videoIDs = '';
				for(var j = 0; j < currentVids.length; j++)
				{
					videoIDs += currentVids[j].id;
					if(j < currentVids.length - 1)
						videoIDs += '|';
				}
				//alert('new list of ids: ', videoIDs);
				//call to the webservice to update on that side
				loadingOn();
				currentChannelObject.videos = videoIDs.split('|');
				MC.Call('SetChannelVideos', SetChnlVidRet, 'channelID', currentChannelObject.id, 'videoIDs', videoIDs);
				break;
			}
			logError('cannot move video down');
		}
	}
}
function leftTruncate(str, n)
{
	//New Manage
	if (n <= 0) return "";
	else if (n > String(str).length) return str;
	else return String(str).substring(0,n);
}
function reloadAllVideoObjects(resp)
{
	loadingOff();
	//New Manage
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Reload All Video Objects Error: ', errors[resp.error]);
		logError('Reload All Video Objects Message: ', resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
			return;
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		return;
	}
	logError('Reload All Video Objects Success');
	fullListOfVideoObjects = [];
	for(var a=0;a<resp.videos.length;a++)
	{
		if(!isInArray(fullListOfVideoObjects,resp.videos[a]))
		{
			fullListOfVideoObjects.push(resp.videos[a]);
		}
	}
	if(!currentChannelObject) listOfVideosOnCurrChannel = resp.videos;
	createNewest5Videos();
	createChannelTable(false);
	ShowTabs(currentTab);
	createOtherList(false);
}
function reloadChannelObject(resp)
{
	loadingOff();
	//New Manage
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Reload All Channel Objects Error: ', errors[resp.error]);
		logError('Reload All Channel Objects Message: ', resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
			return;
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		return;
	}
	logError('Reload Channel Object Success');
	for(var chanIndex = 0; chanIndex < fullListOfChannelObjects.length; chanIndex++)
	{
		if(fullListOfChannelObjects[chanIndex].id == currentChannelObject.id)
		{
			fullListOfChannelObjects[chanIndex] = resp.channels[0];
			currentChannelObject = resp.channels[0];
			break;
		}
	}
	loadingOn();
	MC.Call('GetChannelVideos',reloadVideosList,'channelID',currentChannelObject.id,'profiles','ALL');
}
function addVideoToChannelCB(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Add Video To Channel CB Error: ', errors[resp.error]);
		logError('Add Video To Channel CB Message: ', resp.message);
		//listOfVideosOnCurrChannel.pop();//Remove because was pushed but didn't actually add to channel
		//This function is also used by removeVideoFromChannel but it is unknown where to add the video back into the list
	}
	//New Manage
	loadingOn();
	MC.Call('GetChannelInfo',reloadChannelObject,'id',currentChannelObject.id);
}
function removeVideoFromChannel(video,channel)
{
	//TODO: SPEEDUP part of speedup
	if($('video'+video+'row')) $('video'+video+'row').style.visibility = 'hidden';
	if($('desc'+video+'row')) $('desc'+video+'row').style.visibility = 'hidden';
	for(var listOfVideoIndex = 0; listOfVideoIndex < fullListOfVideoObjects.length; listOfVideoIndex++)
	{
		if(fullListOfVideoObjects[listOfVideoIndex].id == video)
		{
			for(var listOfChannelIndex = 0; listOfChannelIndex < fullListOfVideoObjects[listOfVideoIndex].channels.length; listOfChannelIndex++)
			{
				if(fullListOfVideoObjects[listOfVideoIndex].channels[listOfChannelIndex] == channel)
				{
					fullListOfVideoObjects[listOfVideoIndex].channels.splice(listOfChannelIndex,1);
					break;
				}
			}
			break;
		}
	}
	for(var videoIndex = 0; videoIndex < listOfVideosOnCurrChannel.length; videoIndex++)
	{
		if(listOfVideosOnCurrChannel[videoIndex].id == video)
		{
			listOfVideosOnCurrChannel.splice(videoIndex,1);
			break;
		}
	}
	loadingOn();
	MC.Call('RemoveVideo',addVideoToChannelCB,'channelID',channel,'videoID',video);
}
function addVideoToChannel(video,channel)
{
	//New Manage
	//TODO: SPEEDUP part of speedup
	if($('video'+video+'row')) $('video'+video+'row').style.visibility = 'hidden';
	if($('desc'+video+'row')) $('desc'+video+'row').style.visibility = 'hidden';
	for(var videoIndex = 0; videoIndex < fullListOfVideoObjects.length; videoIndex++)
	{
		if(fullListOfVideoObjects[videoIndex].id == video)
		{
			fullListOfVideoObjects[videoIndex].channels.push(channel);
			listOfVideosOnCurrChannel.push(fullListOfVideoObjects[videoIndex]);
			break;
		}
	}
	loadingOn();
	MC.Call('AddVideo',addVideoToChannelCB,'channelID',channel,'videoID',video);
}
function deleteChannelCB(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Delete Channel CB Error: ', errors[resp.error]);
		logError('Delete Channel CB Message: ', resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
			alert("The channel requested does not exist");
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		return;
	}
	loadingOn();
	MC.Call('GetChannelInfo',reloadChannelsList);
}
function confirmChannelDelete(channelNum,channelName)
{
	cancelConfirm = function(){closeConfirm();};
	okayConfirm = function(){
		loadingOn();
		if(fullListOfChannelObjects.length != 1)
			MC.Call('DeleteChannel',deleteChannelCB,'id',channelNum);
		else
			alert("Unable to delete channel.\nAll users must have at least 1 channel.");
		closeConfirm();
		};
	openConfirm('WARNING: Deleting Channel \'%s\''.format(channelName),"WARNING: The action you have selected can not be undone.\n Are you sure you want to continue?");
}
function deleteChannel(channelNum,channelName)
{
	loadingOn();
	MC.Call('HaveSession',reportSession);
	cancelConfirm = function(){closeConfirm();};
	okayConfirm = function(){confirmChannelDelete(channelNum,channelName);};
	openConfirm('Deleting Channel \'%s\''.format(channelName),"Are you sure you want to delete channel \'%s\'?".format(channelName));
}
function deleteVideoCB(resp)
{
	loadingOff();
	contentIDToDelete = 0;
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Delete Video CB Error: ', errors[resp.error]);
		logError('Delete Video CB Message: ', resp.message);
		if(resp.error == MC.Err.FAILURE)
			alert(resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
			alert("The video requested does not exist");
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		closeConfirm();
		return;
	}
	closeConfirm();
	fullListOfVideoObjects = [];
	loadingOn();
	MC.Call('GetChannelVideos',reloadAllVideos, 'profiles', 'ALL');
}
function confirmVideoDelete(videoNum,videoName)
{
	cancelConfirm = function(){closeConfirm();};
	okayConfirm = function(){loadingOn();MC.Call('DeleteVideo',deleteVideoCB,'videoID',videoNum,'confirm',1);};
	openConfirm('WARNING: Deleting Video \'%s\''.format(videoName),"WARNING: The action you have selected can not be undone.\n Are you sure you want to continue?");
}
function finishSentEmail(resp)
{
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('finishSentEmail Error: ', errors[resp.error]);
		logError('finishSentEmail Delete Message: ', resp.message);
	}
	else
	{
		alert("EMAIL SENT");
		logError("resp:");
		for(eachElement in resp)
		{
			logError(eachElement);
		}
		logError("End resp");
	}
}
function deleteVideo(videoNum,videoName)
{
	loadingOn();
	MC.Call('HaveSession',reportSession);
	cancelConfirm = function(){closeConfirm();};
	okayConfirm = function(){confirmVideoDelete(videoNum,videoName);};
	openConfirm('Deleting Video \'%s\''.format(videoName),"Are you sure you want to delete the video: \'%s\'?".format(videoName));
}
function viewChannel(channelID)
{
	window.location = "channel_view.html?channelID="+channelID;
}
function viewVideo(videoID)
{
	window.location = "channel_view.html?videoID=" + videoID + "&channelID=0";
}
function saveVideoChannels(currChannelID,currVideoID)
{
	currCheckBoxID = 'chan' + currChannelID + 'video' + currVideoID;
	if($(currCheckBoxID).checked)
	{
		loadingOn();
		MC.Call('AddVideo',updateVideos,'channelID',currChannelID,'videoID',currVideoID);
	}
	else
	{
		loadingOn();
		MC.Call('RemoveVideo',updateVideos,'channelID',currChannelID,'videoID',currVideoID);
	}
}
function logOut()
{
	$('channel_editor').style.display = 'none';
	$('simple_editor').style.display = 'none';
	$('add_categories_box').style.display = 'none';
	$('add_min').style.display = 'none';
	$('confirm_box').style.display = 'none';
	loadingOn();
	MC.Call("ChannelLogout",loggingOut);
}
function dummyCB(resp)
{
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Dummy CB Error: ', errors[resp.error]);
		logError('Dummy CB Message: ', resp.message);
	}
}
function updateCategories(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Update Categories Error: ', errors[resp.error]);
		logError('Update Categories Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
	}
	fullListOfCategoryNames = [];
	if(resp.names)
		for(var x=0;x<resp.names.length;x++)
			if(!isInArray(fullListOfCategoryNames,resp.names[x]))
				fullListOfCategoryNames.push(resp.names[x]);
	updateCategoriesList();
	updateAddCategory();
}
function dumpCategories(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Categories Error: ', errors[resp.error]);
		logError('Categories Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		/*return;*/
	}
	else
	{
		logError("Dump Categories Success");
		fullListOfCategoryNames = [];
		for(var x=0;x<resp.names.length;x++)
			if(!isInArray(fullListOfCategoryNames,resp.names[x]))
				fullListOfCategoryNames.push(resp.names[x]);
	}
	loadingOn();
	MC.Call('GetChannelVideos',dumpChannelVideos, 'profiles', 'ALL');
	//MC.Call('GetChannelVideos',dumpChannelVideos, 'channelID', currentChannel);//New Manage
}
function dumpChannelStats(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Channel Stats Error: ', errors[resp.error]);
		logError('Channel Stats Message: ', resp.message);
		MemInfo.minutesUsed = -1;
	}
	else
	{
		logError("Dump Channel Stats Success");
		MemInfo.minutesUsed = resp.minutesUsed;
	}
	loadingOn();
	MC.Call('GetChannelInfo',dumpChannelInfo);
}
function finishWelcome(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Finish Welcome Error: ', errors[resp.error]);
		logError('Finish Welcome Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		loadingOn();
		MC.Call('GetCategories',dumpCategories);
		return;
	}
	loadingOn();
	MC.Call('GetChannelInfo',dumpChannelInfo);
}
function setFirstVideoChannel(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Set First Video Channel Error: ', errors[resp.error]);
		logError('Set First Video Channel Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
	}
	loadingOn();
	MC.Call('SendWelcomeEmail',finishWelcome,'webAddr',fullListOfChannelObjects[0].webAddr);
}
function addedFirstVideo(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Added First Video Error: ', errors[resp.error]);
		logError('Added First Video Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
	}
	logError("Video ID Returned resp.videoID: " + resp.videoID);
	logError("Channel ID fullListOfChannelObjects: " + fullListOfChannelObjects[0].id);
	loadingOn();
	MC.Call('SetVideoInfo',setFirstVideoChannel,'videoID',resp.videoID,'channelIDs',fullListOfChannelObjects[0].id);
}
function dumpFirstChannelInfo(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('First Channel Info Error: ', errors[resp.error]);
		logError('First Channel Info Message: ', resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
		{
			logError("No channels found.");
			loadingOn();
			MC.Call('GetCategories',dumpCategories);
			return;
		}
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		/*return;*/
	}
	else
	{
		logError("Dump First Channel Info Success");
		loadingOn();
		reloadChannelsList(resp);
	}
	loadingOn();
	//MC.Call('CopyVideoFromUser',addedFirstVideo,'videoID',3225,'fromUserID',56457);
	MC.Call('CopyShareVideo',addedFirstVideo);
}
function firstChannelAdded(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('First Channel Added Error: ', errors[resp.error]);
		logError('First Channel Added Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		loadingOn();
		MC.Call('GetChannelInfo',dumpChannelInfo);// If E-mail wasn't sent continue adding channels
		return;
	}
	loadingOn();
	MC.Call('GetChannelInfo',dumpFirstChannelInfo);
}
function createSingleChannel(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Create Single Channel Error: ', errors[resp.error]);
		logError('Create Single Channel Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
	}
	loadingOn();
	MC.Call('GetChannelInfo',reloadChannelsList);
}
function createChannel()
{
	loadingOn();
	MC.Call('CreateChannel',createSingleChannel);
}
function createChannelCB(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Create Channel CB Error: ', errors[resp.error]);
		logError('Create Channel CB Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		loadingOn();
		MC.Call('GetCategories',dumpCategories);
		return;
	}
	loadingOn();
	MC.Call('GetChannelInfo',dumpChannelInfo);
}
function dumpChannelInfo(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Channel Info Error: ', errors[resp.error]);
		logError('Channel Info Message: ', resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
		{
			logError("No channels found.");
			if(MemInfo.channels != -1 && !createdTrialChannel)
			{
                createdTrialChannel = true;
                loadingOn();
                MC.Call('CreateChannel',firstChannelAdded);
                /*//REMOVED FOR STAND ALONE
				if(isInArray(listOfParams,'trial') || (MemInfo.channels != 0))
				{
					createdTrialChannel = true;
					loadingOn();
					MC.Call('CreateChannel',firstChannelAdded);
				}
				else
				{
					if(!debugOn)
						window.location = 'product_page.html';
				}
                */
			}
			return;
		}
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		/*return;*/
	}
	else
	{
		logError("Dump Channel Info Success");
		//reloadChannelsList(resp);//TODO: See if this is needed
		if(resp.channels)
		{
			if(resp.channels.length < MemInfo.channels)
			{
				if(-1 < resp.channels.length && resp.channels.length < 100)
				{
					loadingOn();
					MC.Call('CreateChannel',createChannelCB);
					return;
				}
			}
		}
		loadingOn();
		reloadChannelsList(resp);
		viewLocation = 'channel_view.html?channelID=' + fullListOfChannelObjects[0].id;
		shareLocation = 'channel_view.html?share&channelID=' + fullListOfChannelObjects[0].id;
	}
	loadingOn();
	MC.Call('GetCategories',dumpCategories);
}
function clickedView()
{
	window.location = viewLocation;
}
function clickedShare()
{
	window.location = shareLocation;
}
function isInArray(array,element)
{
	for(var elementInArray=0;elementInArray<array.length;elementInArray++)
	{
		if(array[elementInArray] == element)
			return true;
	}
	return false;
}
function dumpChannelVideos(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Channel Videos Error: ', errors[resp.error]);
		logError('Channel Videos Message: ', resp.message);
		if(resp.error == MC.Err.NOT_FOUND)
			alert('The video or channel requested does not exist.');
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		/*return;*/
	}
	else
	{
		logError("Dump Channel Videos Success");
		loadingOn();
		reloadAllVideos(resp);//TODO:CHECK FOR SPEED
	}
	loadingOn();
	MC.Call('GetCategories',updateCategories);
}
function dumpMemInfo(resp)
{
	loadingOff();
	if(resp.error != MC.Err.SUCCESS)
	{
		logError('Mem Info Error: ', errors[resp.error]);
		logError('Mem Info Message: ', resp.message);
		if(resp.error == MC.Err.NO_SESSION)
			loggingOut({});
		/*return;*/
		MemInfo = {};
		MemInfo.lastname = '';
		MemInfo.firstname = '';
		MemInfo.email = '';
		MemInfo.memType = '';
		MemInfo.subType = '';
		MemInfo.didItWork = '';
		MemInfo.trialStatus = '';
		MemInfo.channels = -1;
		MemInfo.availMinutes = 0;
		MemInfo.minutesUsed = -1;
		MemInfo.startDate = '10/1/2006';
	}
	else
	{
		logError("Dump Mem Info Success");
		MemInfo = resp;
		MemInfo.minutesUsed = -1;
	}
	logError("MemInfo.availMinutes: " + MemInfo.availMinutes);
	if(MemInfo.availMinutes == 0) MemInfo.availMinutes = 60;
	$('login_message').innerHTML = "Welcome: " + MemInfo.firstname + ' ' + MemInfo.lastname;
	logError("MemInfo.availMinutes: " + MemInfo.availMinutes);
	logError("MemInfo.channels: " + MemInfo.channels);
	loadingOn();
	MC.Call('GetChannelStats',dumpChannelStats);
}
function debugAlert(stringToDisplay)
{
	if(debugOn)
		alert(stringToDisplay);
}
function checkUser()
{
	listOfParams = [];
	for(var x in params)
		listOfParams.push(x);
	if(params.debug) debugOn = true;
	if(listOfParams.length)
	{
		if(params.userID && params.pat)
		{
			loadingOn();
			MC.Call('ChannelLogin',loggingIn,'userID',params.userID,'pat',params.pat);
		}
		else
		{
			loadingOn();
			MC.Call('HaveSession',sessionCheck);
		}
	}
	else
	{
		loadingOn();
		MC.Call('HaveSession',sessionCheck);
	}
}
function previewVideo(videoToPreview)
{
	var previewWidth = 351;
	var previewHeight = 273;
	var previewLeft = (screen.width/2)-(previewWidth/2);
	if(previewLeft < 0) previewLeft = 0;
	var previewTop = (screen.height/2)-(previewHeight/2);
	if(previewTop < 0) previewTop = 0;
	if(currentChannelObject && typeof(currentChannelObject.playerColor) != 'undefined')
		window.open('preview.html?videoID=' + videoToPreview + "&color="+currentChannelObject.playerColor,"Preview","height="+previewHeight+",width="+previewWidth+",resizable=0,status=0,scrollbars=0,menubar=0,fullscreen=0,toolbar=0,sizeable=0,left="+previewLeft+",top="+previewTop,"replace=false");
	else
		window.open('preview.html?videoID=' + videoToPreview,"Preview","height="+previewHeight+",width="+previewWidth+",resizable=0,status=0,scrollbars=0,menubar=0,fullscreen=0,toolbar=0,sizeable=0,left="+previewLeft+",top="+previewTop,"replace=false");
}
function welcomeUser()
{
	loadingOn();
	MC.Call('RefreshMemInfo',dumpMemInfo);
}
createCookie ('maxCookie', 'loginCookie', 365);
checkUser();
function numbersonly(currField, e, dec)
{
	if(currField.id == 'ppv_value') $('ppv_video').checked = 'true';
	var key;
	var keychar;
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	else return true;
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) return true;
	else if ((("0123456789").indexOf(keychar) > -1))
	{
		return true;
	}
	else if (dec && (keychar == ".")){
		if(currField.value.indexOf('.') > 0){
			return false;
		}
		return true;
	}else return false;
}
function unitDec(currField,numOfUnits,numOfDecs)
{
	if(currField.value.indexOf('.') >= 0 && currField.value.substr(currField.value.indexOf('.')+1).length > numOfDecs)
	{
		currField.value = currField.value.substr(0,currField.value.indexOf('.')+1) + currField.value.substr(currField.value.indexOf('.')+1,numOfDecs);
	}
	if(currField.value.indexOf('.') >= 0 && currField.value.substr(0,currField.value.indexOf('.')).length > numOfUnits)
	{
		currField.value = currField.value.substr(0,currField.value.indexOf('.')+1) + currField.value.substr(currField.value.indexOf('.')+1,numOfDecs);
	}
	if(currField.value.indexOf('.') < 0 && currField.value.length > 3)
	{
		currField.value = currField.value.substr(0,numOfUnits);
	}
}

