var serverURL = 'http://vpfactory.com';
var create = 0;
var premade = 0;
var modified = 0;
var perform = 0;
window.perf = 0;
var vnp = new Object();
var playerDetails = new Object();
var nid = 0;
var rnid = 0;
playerDetails.id = 0;
window.arrClicked = 0;
window.flashPlaying = false;
window.gotoProperties = 0;

window.data = '';
window.currentplaylist = new Object();
window.player = new Object();
window.currentskin = new Object();
window.swfuploadinited = false;
window.duplicatedSkin = false;
window.duplicatedPlayer = false;
window.currTheme = false;
window.customThemeColor = false;

window.videoCollection = new Array;
window.playlistCollection = new Array;

function $(id)
{
	return document.getElementById(id);
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}



function windowkeypressevent(event)
{
	
	try {
		if ( $('previewmodal').style.display == "block")
		{

			if (event.keyCode == 13 || event.keyCode == 27)
			{
				closePreview2();
				event.preventDefault();
				event.returnValue = false;
				return;
			}
		}
	} catch(e){}
	
	try {
		
		if ( $('browseskins').style.display == "block")
		{

			if (event.keyCode == 13)
			{
				skinsfinish();
				event.preventDefault();
				event.returnValue = false;
			}

			if (event.keyCode == 27)
			{
				showSkins();
				event.preventDefault();
				event.returnValue = false;
			}
		}
	} catch(e){}
	
	try {
		
		if ( $('welcome').style.display == "block")
		{

			if (event.keyCode == 13)
			{
				welcome();
				if (window.uac == 1) {
					showToolTip(1,'f');
				}else {
					showToolTip(1,'p');
				}
				event.preventDefault();
				event.returnValue = false;
			}

			if (event.keyCode == 27)
			{
				welcome();
				event.preventDefault();
				event.returnValue = false;
			}
		}
	} catch(e){}

	try {
		if ( $('terms').style.display == "block")
		{

			if (event.keyCode == 13)
			{
				clickerfinish();
				event.preventDefault();
				event.returnValue = false;
			}

			if (event.keyCode == 27)
			{
				clicker();
				event.preventDefault();
				event.returnValue = false;
			}
		}
	} catch(e){}

	try
	{
		if ($('warning').style.display == "block")
		{
			if (event.keyCode == 13)
			{
				eval(document.perform);
				event.preventDefault();
				event.returnValue = false;
			}

			if (event.keyCode == 27)
			{
				createModal();
				event.preventDefault();
				event.returnValue = false;
			}
		}
	}catch(e){}
}

function  printInfo(e)
{
	cancelEvent(e);
}

function cancelEvent(e)
{
	e = e ? e : window.event;
	if(e.stopPropagation)
	e.stopPropagation();
	if(e.preventDefault)
	e.preventDefault();
	e.cancelBubble = true;
	e.cancel = true;
	e.returnValue = false;
	return false;
}

function hookEvent(element, eventName, callback)
{
	if(typeof(element) == "string")
	element = document.getElementById(element);
	if(element == null)
	return;

	try {
		if(typeof element.addEventListener == "function")
		{
			if(eventName == 'mousewheel')
			element.addEventListener('DOMMouseScroll', callback, false);
			element.addEventListener(eventName, callback, true);
		}
		else if(element.attachEvent)
		element.attachEvent("on" + eventName, callback);
	}catch(e){};
}

function unhookEvent(element, eventName, callback)
{
	if(typeof(element) == "string")
	element = document.getElementById(element);
	if(element == null)
	return;
	if(element.removeEventListener)
	{
		if(eventName == 'mousewheel')
		element.removeEventListener('DOMMouseScroll', callback, false);
		element.removeEventListener(eventName, callback, false);
	}
	else if(element.detachEvent)
	element.detachEvent("on" + eventName, callback);
}

function cancelEvent(e)
{
	e = e ? e : window.event;
	if(e.stopPropagation)
	e.stopPropagation();
	if(e.preventDefault)
	e.preventDefault();
	e.cancelBubble = true;
	e.cancel = true;
	e.returnValue = false;
	return false;
}

function cancelMouseEvent(e)
{
	e = e ? e : window.event;
	
	if (typeof e.srcElement == "object") obj = e.srcElement; else obj = e.currentTarget;

	if (obj.id == 'scrollholder1')
	{
		if ($('track1') != null)
		{
			cancelEvent(e);
		}
	}
	if (obj.id == 'videosholder')
	{
		if ($('track0') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'scrollholder2')
	{
		if ($('track2') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'scrollholder3')
	{
		if ($('track3') != null)
		{
			cancelEvent(e);
		}
	}


	if (obj.id == 'scrollholder5' || obj.id == 'videostable' || obj.id == 'videosdiv')
	{
		if ($('track5') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'scrollholder6')
	{
		if ($('track6') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'scrollholder7')
	{
		if ($('track7') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'scrollholder8')
	{
		if ($('track8') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'scrollholder9')
	{
		if ($('track9') != null)
		{
			cancelEvent(e);
		}
	}
	//for ads and commercials

	if (obj.id == 'vnpholder')
	{

		if ($('track216') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'commholder')
	{
		if ($('track144') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'scrollholder216')
	{

		if ($('track216') != null)
		{
			cancelEvent(e);
		}
	}

	if (obj.id == 'scrollholder0')
	{
		if ($('track0') != null)
		{
			cancelEvent(e);
		}
	}
	
	if (obj.id == 'scrollholder144')
	{
		if ($('track144') != null)
		{
			cancelEvent(e);
		}
	}	
}

function MouseWheel(e)
{
	e = e ? e : window.event;
	var wheelData = e.detail ? e.detail : e.wheelDelta;
	//do something

	return cancelEvent(e);
}


function str_replace(search, replace, subject)
{
	var s = subject;
	var ra = r instanceof Array, sa = s instanceof Array;
	var f = [].concat(search);
	var r = [].concat(replace);
	var i = (s = [].concat(s)).length;
	var j = 0;

	while (j = 0, i--) {
		if (s[i]) {
			while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
		}
	}

	return sa ? s : s[0];
}

function checkradio(el, input, inputs, others, classname)
{

	if (classname)
	el.className = "radio checked "+classname;
	else
	el.className = "radio checked";

	if (typeof others === "string")
	{
		if (classname)
		document.getElementById(others).className = "radio "+classname;
		else
		document.getElementById(others).className = "radio";
	} else {
		for (i in others)
		{
			if (typeof others[i] != "function")
			{
				if (classname)
				document.getElementById(others[i]).className = "radio "+classname;
				else
				document.getElementById(others[i]).className = "radio";
			}
		}
	}

	eval("window."+input+" = 1");
	if (typeof inputs === "string")
	{
		eval("window."+inputs+" = 0");
	} else {
		for (i in inputs)
		{
			if (typeof inputs[i] != "function")
			eval("window."+inputs[i]+" = 0");
		}
	}
	document.modified = 1;
}


function checkradioplacement(el, input, inputs, others, classname)
{

	if (classname)
	el.className = "radio checked "+classname;
	else
	el.className = "radio checked";

	if (typeof others === "string")
	{
		if (classname)
		document.getElementById(others).className = "radio "+classname;
		else
		document.getElementById(others).className = "radio";
	} else {
		for (i in others)
		{
			if (typeof others[i] != "function")
			{
				if (classname)
				document.getElementById(others[i]).className = "radio "+classname;
				else
				document.getElementById(others[i]).className = "radio";
			}
		}
	}

	eval("window."+input+" = 1");
	if (typeof inputs === "string")
	{
		eval("window."+inputs+" = 0");
	} else {
		for (i in inputs)
		{
			if (typeof inputs[i] != "function")
			eval("window."+inputs[i]+" = 0");
		}
	}
	document.modified = 1;
	//
	var pl = currentskin.verticalplacement + currentskin.horizontalplacement;
	$('vp_holder').setParameter('watermarkPos', pl);
}

function checkradiogroup(el, group, action)
{
	var divs = document.getElementsByTagName('div');

	for (i in divs)
	{
		try {
			if (divs[i].getAttribute('group') == "skins")
			{
				divs[i].className = "radio";
			}

		}catch(e){}
	}
	el.className = "radio checked";
	if (action)
	eval(action);
	/*		if (classname)
	el.className = "radio checked "+classname;
	else
	el.className = "radio checked";

	if (typeof others === "string")
	{
	if (classname)
	document.getElementById(others).className = "radio "+classname;
	else
	document.getElementById(others).className = "radio";
	} else {
	for (i in others)
	{
	if (typeof others[i] != "function")
	{
	if (classname)
	document.getElementById(others[i]).className = "radio "+classname;
	else
	document.getElementById(others[i]).className = "radio";
	}
	}
	}

	eval("window."+input+" = 1");
	if (typeof inputs === "string")
	{
	eval("window."+inputs+" = 0");
	} else {
	for (i in inputs)
	{
	if (typeof inputs[i] != "function")
	eval("window."+inputs[i]+" = 0");
	}
	}*/


	document.modified = 1;
}

function checkskinradio(el, input, inputs, others, classname)
{

	if (classname)
	el.className = "radio checked "+classname;
	else
	el.className = "radio checked";

	if (typeof others === "string")
	{
		if (classname)
		document.getElementById(others).className = "radio "+classname;
		else
		document.getElementById(others).className = "radio";
	} else {
		for (i in others)
		{
			if (typeof others[i] != "function")
			{
				if (classname)
				document.getElementById(others[i]).className = "radio "+classname;
				else
				document.getElementById(others[i]).className = "radio";
			}
		}
	}

	eval("window."+input+" = 1");

	input = input.replace('currentskin.', '');
	
	//processing current Theme
	currTheme = getCTheme(input);
	if (typeof currTheme != 'undefined') {
		if (!customThemeColor)
			loadTheme(currTheme);
	}
	else {
		//showRedNotification('Failed to load the default colors for the current theme.', 1);
		currTheme = false;
	}	
	//end theme process
	
	if (input == "buttonStyle1")
	try {$('vp_holder').setParameter('buttonStyle', "1")}catch(e){}
	if (input == "buttonStyle2")
	try {$('vp_holder').setParameter('buttonStyle', "2")}catch(e){}
	if (input == "buttonStyle3")
	try {$('vp_holder').setParameter('buttonStyle', "3")}catch(e){}
	if (input == "buttonStyle4")
	try {$('vp_holder').setParameter('buttonStyle', "4")}catch(e){}
	if (input == "buttonStyle5")
	try {$('vp_holder').setParameter('buttonStyle', "5")}catch(e){}
	if (input == "buttonStyle6")
	try {$('vp_holder').setParameter('buttonStyle', "6")}catch(e){}
	if (input == "buttonStyle7")
	try {$('vp_holder').setParameter('buttonStyle', "7")}catch(e){}
	if (input == "buttonStyle8")
	try {$('vp_holder').setParameter('buttonStyle', "8")}catch(e){}			
	
	if (typeof inputs === "string")
	{
		eval("window."+inputs+" = 0");
	} else {
		for (i in inputs)
		{
			if (typeof inputs[i] != "function")
			eval("window."+inputs[i]+" = 0");
		}
	}
	document.modified = 1;	
}

function checkbox(el, input, div, inverse)
{
	if (el.className == "checkbox on")
	{
		el.className = "checkbox";
		eval("window."+input+" = 0");
		//Players module
		if (el.readAttribute('rel') && el.readAttribute('itemid')) {
			var itemid = el.readAttribute('itemid');
			if (el.readAttribute('rel') == 'browsevideo') {
				markVideo(itemid, false);
			}
			if (el.readAttribute('rel') == 'browseplaylist') {
				markPlaylist(itemid, false);
			}
		}
		
		if (div)
		{
			if (inverse)
			document.getElementById(div).style.visibility = "visible";
			else
			document.getElementById(div).style.visibility = "hidden";
		}
	} else {
		el.className = "checkbox on";
		eval("window."+input+" = 1");
		//Players module
		if (el.readAttribute('rel') && el.readAttribute('itemid')) {
			var itemid = el.readAttribute('itemid');
			if (el.readAttribute('rel') == 'browsevideo') {
				markVideo(itemid, true);
			}
			if (el.readAttribute('rel') == 'browseplaylist') {
				markPlaylist(itemid, true);
			}
		}
		
		if (div)
		{
			if (inverse)
			document.getElementById(div).style.visibility = "hidden";
			else
			document.getElementById(div).style.visibility = "visible";
		}
	}
	document.modified = 1;
}

function skinscheckbox(el, input, div, inverse, callFlash)
{
	if (el.className == "checkbox on")
	{
		el.className = "checkbox";
		eval("window."+input+" = 0");

		var aa = input.replace('currentskin.details.', '');
		if (callFlash) {
			$('vp_holder').setParameter(aa, 'false');
		}

		if (div)
		{
			if (inverse)
			document.getElementById(div).style.visibility = "visible";
			else
			document.getElementById(div).style.visibility = "hidden";
		}
	} else {

		el.className = "checkbox on";
		eval("window."+input+" = 1");
		var aa = input.replace('currentskin.details.', '');
		if (callFlash) {
			$('vp_holder').setParameter(aa, 'true');
		}

		if (div)
		{
			if (inverse)
			document.getElementById(div).style.visibility = "hidden";
			else
			document.getElementById(div).style.visibility = "visible";
		}
	}
	document.modified = 1;
}

function checkTargetDisabled(source, target) {
	if (source.className == "checkbox") {
		$(target).disabled = true;
	}else {
		$(target).disabled = false;
	}
}

function poppicker(event, target)
{
	var w = getSize()[0];

	if ((event.clientX + 165) > w)
	{
		dif =  w - (event.clientX + 165);

		if (dif < 0)
		document.getElementById('mini').style.left = (event.clientX + dif - 185)+'px';
		else
		document.getElementById('mini').style.left = (event.clientX - dif)+'px';
	}
	else
	document.getElementById('mini').style.left = (event.clientX - 165)+'px';

	document.getElementById('mini').style.top = (event.screenY) - 125+'px';


	if (browser.isIE)
	{
		document.getElementById('mini').style.top = (event.clientY + 10)+'px';
	}

	pickertarget = target;
	if ($(target+'i').style.backgroundColor.indexOf('rgb')>=0)
	{
		var c = str_replace('rgb', '', $(target+'i').style.backgroundColor)

		c = str_replace('(', '', c);
		c = str_replace(')', '', c);
		c = c.split(', ');
		currentColor = Colors.ColorFromRGB(c[0], c[1], c[2]	);
	} else {
		currentColor = Colors.ColorFromHex($(target+'i').style.backgroundColor);
	}
	window.lastcolor = currentColor.HexString();
	colorChanged('box');

	$S('mini').display='block';
	window.colortarget = target;

	/*flashTogglePlay(false);
	var thediv=document.getElementById('displayboxwarning');
	thediv.style.height = getDocHeight()+"px";
	thediv.style.position = "absolute";
	thediv.style.marginLeft = "0px";
	thediv.style.marginTop = "0px";
	thediv.style.zIndex = "101";
	thediv.style.left = "0px";
	thediv.style.top = "0px";
	thediv.style.display = "block";


	thediv.innerHTML = "<table width='100%'><tr><td align='center' valign='middle' width='100%' height='100%'></td></tr></table>";*/

}

function showplaylists()
{
	if (document.getElementById('addplaylists').style.display == 'none')
	{
		var scr = getscreen();
		//448px
		if (scr[0] > 448)
		{
			document.getElementById('addplaylists').style.marginLeft = (scr[0] - 448) / 2 +'px';
		} else {
			document.getElementById('addplaylists').style.marginLeft = '0px';
		}
		document.getElementById('addplaylists').style.display = 'block';
	}
	else
	document.getElementById('addplaylists').style.display = 'none';
}

function getscreen()
{
	return [screen.width,screen.height];
}

function getcheckedplaylists()
{
	var divs = document.getElementsByTagName('div');
	var result = new Array();
	var j =0;
	for (i in divs)
	{
		try {
			if (divs[i].getAttribute('rel') == "playlist")
			{
				if (divs[i].className == "checkbox on")
				{
					result[j] = divs[i];
					j ++;
				}
			}
		} catch(e){}
	}

	return result;
}

function addplaylists()
{
	var ch = getcheckedplaylists();
	if (ch.length > 0)
	{
		//disable
		document.getElementById('playlist').className = "dropdown disabled";
		if (document.getElementById('playlistddt').className == "dropdowncontentpressed")
		dropdown('playlist');
	} else {
		document.getElementById('playlist').className = "dropdown";
	}

	showplaylists();
}

function watchhide(el)
{
	if (el.className == "checkbox")
	{
		document.getElementById('playlisthide').className = "dropdown disabled";
		//disable the dropdown
	} else {
		document.getElementById('playlisthide').className = "dropdown";
	}
}


function watchwah(el)
{
	if (el.className == "checkbox on")
	{
		document.getElementById('widthandheight').className = "disabled";
		//disable the dropdown
	} else {
		document.getElementById('widthandheight').className = "";
	}
}

function selectAllVideos()
{
	var divs = document.getElementsByTagName('div');

	for (i in divs)
	{
		try {
			if (divs[i].className.indexOf('checkbox') != -1)
			{
				divs[i].className = 'checkbox on';
			}
		} catch(e) {}
	}
}

function deselectAllVideos()
{
	var divs = document.getElementsByTagName('div');

	for (var i in divs)
	{
		try {
			if (divs[i].className.indexOf('checkbox') != -1)
			{
				divs[i].className = 'checkbox';
			}
		} catch(e) {}
	}
}

function showGallery(id, playlist)
{
	if (document.getElementById(id).style.display == "block")
	{
		//close all
		document.getElementById('playlisttype').value = 'new';
		document.getElementById('playlistid').value = -1;
		document.getElementById('playlisttitle').innerHTML = "Create New Playlist";
		var divs = document.getElementsByTagName('div');

		for (var i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "gallery")
				{
					divs[i].style.display = 'none';
				}

			} catch(e) {}
		}

		for (var i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "video")
				{
					divs[i].className = "checkbox";
				}
			}catch(e){}
		}
	}
	else{
		var divs = document.getElementsByTagName('div');

		for (var i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "gallery")
				{
					divs[i].style.display = 'none';
				}

			} catch(e) {}
		}
		document.getElementById('playlisttype').value = 'update';
		document.getElementById('playlistid').value = id;
		document.getElementById(id).style.display = 'block';
		document.getElementById('playlisttitle').innerHTML = "Edit playlist "+playlist;

		//auto select videos
		var divs = document.getElementsByTagName('div');
		var numericid = id.substring(3);
		//deselect all
		for (var i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "video")
				{
					divs[i].className = "checkbox";
				}
			}catch(e){}
		}

		//select those needed to
		for (var i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "video")
				{
					for (j in videos[numericid])
					{
						if (divs[i].getAttribute('value') == videos[numericid][j])
						{

							divs[i].className = "checkbox on";
						} else {
						}
					}
				}

			} catch(e) {}
		}
	}
}


/*function savePlaylist()
{
var type = document.getElementById('playlisttype').value;
var id = document.getElementById('playlistid').value;

var divs = document.getElementsByTagName('div');
var sels = new Array();
var j = 0;

for (var i in divs)
{
try {
if (divs[i].getAttribute('rel') == "video")
{
if (divs[i].className == "checkbox on")
{
sels[j] = divs[i].getAttribute('value');
j++;
}
}
}catch(e){}
}
document.getElementById('playlistsels').value = sels.join(',');

if (type == "new")
{
//popup the name
var a = prompt("Please enter a name for the new playlist:");
document.getElementById('playlistname').value = a;
} else {

}
document.getElementById('playlistform').submit();
}*/

function GET(url, callback, evil)
{
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType('text/html');
			// See note below about this line
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert(e);
			}
		}
	}

	if (!req)
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			if (req.status == 200)
			{
				window.data = req.responseText;
				if (evil)
				{
					eval(callback);
				}
				else {
					eval(callback+'(window.data)');
				}
			}
		}
	};


	req.open('GET', url, true);
	req.send(null);
}

function POST(url, callback, params, evil)
{
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType('text/html');
			// See note below about this line
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert(e);
			}
		}
	}

	if (!req)
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			if (req.status == 200)
			{
				if (evil)
				eval(callback);
				else
				eval(callback+'(req.responseText)');
			}
		}
	};

	/*req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");*/
	req.open('POST', url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params .length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
}


function editPlayer(id)
{
	if (checkForChanges())
	{
		GET('/players/getplayer/?tpid='+id, 'showPlayerDetails');
		showNotification('Loading...', 0);
	} else {
		document.perform = "document.modified = 0;GET('/players/getplayer/?tpid="+id+"', 'showPlayerDetails');";
		var name = $('playername').value.trim();
		$('playername').value = name;
		createModal('You have made changes to the "'+name+'" player. <br />If you continue you will lose these changes. <br />Are you sure you want to continue?', 'document.modified = 0; eval(document.perform); createModal();', 'createModal()', 'Abort changes');
	}
}

function removeVNP(show)
{
	var ol = $('vnpl');
	while (ol.hasChildNodes())
	{
		ol.removeChild(ol.firstChild)
	}
	vnp.videos = new Array();
	vnp.playlists = new Array();

	if ($('track0') != null)
	$('track0').parentNode.removeChild($('track0'));

	if (show)
	showNotification('Removed all content.', 1);

	ScrollLoad ("scrollholder0", "scroll0", true);

	var object = new Object();
	object.videos = new Array();
	object.playlists = new Array();
	
	for (i=0; i< window.vnp.videos.length; i++)
	{
		var xxx = {};
		xxx.id = window.vnp.videos[i].id;
		object.videos.push(xxx);
	}

	for (i=0; i< window.vnp.playlists.length; i++)
	{
		var xxx = {};
		xxx.id = window.vnp.playlists[i].id;
		object.playlists.push(xxx);
	}
	object.skinid = $('skinid').value;


	var aaa = object.toJSONString();
	aaa = str_replace('"', '`', aaa);
	$('vpparent').innerHTML = '<div id="vp_holder" class="vp_holder"> </div>';
	var flashvars = {
		htmlPage: document.location,
		settingsFile: "/players/feedxml?string="+aaa
	};
	var params = {
		allowFullScreen: "true",
		wmode: "opaque"
	};

	swfobject.embedSWF("/player.swf", "vp_holder", "473", "340", "9.0.115", "swfobject/expressInstall.swf", flashvars, params);
}

function setVideoCollection() {
	if (allvideos.length > 0) {
		for (var i = 0; i < allvideos.length; i++) {
			videoCollection[i] = Object.clone(allvideos[i]);
			videoCollection[i].checked = false;
		}
	}
}

function setPlaylistCollection() {
	if (allplaylists.length > 0) {
		for (var i = 0; i < allplaylists.length; i++) {
			playlistCollection[i] = Object.clone(allplaylists[i]);
			playlistCollection[i].checked = false;
		}
	}
}

function showPlayerDetails(text)
{
	var link1 = "#";
	var link2 = "#";
	var link3 = "#";
	var link4 = embedFacebook();
	//resetam quicklink-ul
	$('qlink').style.display = 'block';
	$('qupload').style.display = 'none';
	$('videopath').value = 'Paste video URL';

	eval(text);
	document.title = 'Video Player Factory';
	window.location.href = '#properties';
	//mark the tr
	selectPlayer(playerDetails.id);

	showNotification('Loaded player "'+playerDetails.name+'"', 1);
	//playerDetails.name = str_replace('&ghi;', '"', playerDetails.name);
	//playerDetails.name = str_replace('&apo;', "'", playerDetails.name);

	$('playername').value=playerDetails.name;

	try {
		playerDetails.skin.properties.title = str_replace('&apo;', "'", playerDetails.skin.properties.title);
		playerDetails.skin.properties.title = str_replace('&apo;', "'", playerDetails.skin.properties.title);
		$('skinname').value=playerDetails.skin.properties.title;
		$('skinid').value=playerDetails.skin.properties.id;

	} catch(e) {$('skinname').value = "Classic";$('skinid').value = 1;}

	var ol = $('vnpl');
	while (ol.hasChildNodes())
	{
		ol.removeChild(ol.firstChild)
	}

	var div = $('videosholder');
	while (div.hasChildNodes())
	{
		div.removeChild(div.firstChild)
	}

	div.innerHTML = '<div id="scrollholder0" class="scrollholder"><div class="scroll" id="scroll0"><ol class="form_list" id="vnpl"></ol></div></div>';

	var ol = $('vnpl');
	var j = 1;

	vnp.videos = playerDetails.videos;
	vnp.playlists = playerDetails.playlists;
	
	assignVideoCollection(vnp.videos);
	assignPlaylistCollection(vnp.playlists);
	
	for (i in playerDetails.videos)
	{
		if (typeof playerDetails.videos[i].title === "string")
		{
			if (playerDetails.videos[i].title.length > 35)
			title = playerDetails.videos[i].title.substring(0, 35)+'[...]';
			else
			title = playerDetails.videos[i].title;

			if (j == playerDetails.videos.length && playerDetails.playlists.length == 0)
			{
				ol.innerHTML += "<li itemtype='video' itemid='"+playerDetails.videos[i].id+"' class='w95 last avideo' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+playerDetails.id+"', '"+playerDetails.videos[i].id+"', 'video');\"/></a></li>";
			}
			else {
				ol.innerHTML += "<li itemtype='video' itemid='"+playerDetails.videos[i].id+"' class='w95 avideo' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+playerDetails.id+"', '"+playerDetails.videos[i].id+"', 'video');\"/></a></li>";
			}
			j++;
		}
	}

	var j = 1;
	for (i in playerDetails.playlists)
	{
		if (typeof playerDetails.playlists[i].playlist === "string")
		{

			if (playerDetails.playlists[i].playlist.length > 35)
			title = playerDetails.playlists[i].playlist.substring(0, 35)+'[...]';
			else
			title = playerDetails.playlists[i].playlist;

			if (j == playerDetails.playlists.length)
			{
				ol.innerHTML += "<li itemtype='playlist' itemid='"+playerDetails.playlists[i].id+"' class='w95 last aplaylist' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+playerDetails.id+"', '"+playerDetails.playlists[i].id+"', 'playlist');\"/></a></li>";
			} else {
				ol.innerHTML += "<li itemtype='playlist' itemid='"+playerDetails.playlists[i].id+"' class='w95 aplaylist' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+playerDetails.id+"', '"+playerDetails.playlists[i].id+"', 'playlist');\"/></a></li>";
			}
			j++;
		}
	}

	document.No = 0;
	ScrollLoad ("scrollholder0", "scroll0", true);


	$('playerdescription').value=playerDetails.description;
	$('located').value=playerDetails.located;

	$('date').value=playerDetails.date;

	if (playerDetails.status == "published")
	{
		$('statusimg').src="/images/bulet_green.png";
		$('statustex').value="Published";
		$('embed_options').style.display = 'block';
	}

	if (playerDetails.status == "saved")
	{
		$('statusimg').src="/images/bulet_yellow.png";
		$('statustex').value="Saved";
		$('embed_options').style.display = 'none';
	}

	if (playerDetails.status == "notpublished")
	{
		$('statusimg').src="/images/bulet_red.png";
		$('statustex').value = "Not Published";
		$('embed_options').style.display = 'none';
	}

	try {
		if (playerDetails.status == "published")
		{
			if (playerDetails.skin.properties.autoResize == "1") {
				insertEmbed(playerDetails.txtid, "100%","100%");
				link1 = 'javascript:reloadEmbed("default", "' + playerDetails.txtid + '", "100%", "100%")';
				link2 = 'javascript:reloadEmbed("wordpress", "' + playerDetails.txtid + '", "100%", "100%")';
				link3 = 'javascript:reloadEmbed("myspace", "' + playerDetails.txtid + '", "100%", "100%")';
			}
			else {
				insertEmbed(playerDetails.txtid, playerDetails.skin.properties.playerWidth,playerDetails.skin.properties.playerHeight);
				link1 = 'javascript:reloadEmbed("default", "' + playerDetails.txtid + '", "' + playerDetails.skin.properties.playerWidth + '", "' + playerDetails.skin.properties.playerHeight + '")';
				link2 = 'javascript:reloadEmbed("wordpress", "' + playerDetails.txtid + '", "' + playerDetails.skin.properties.playerWidth + '", "' + playerDetails.skin.properties.playerHeight + '")';
				link3 = 'javascript:reloadEmbed("myspace", "' + playerDetails.txtid + '", "' + playerDetails.skin.properties.playerWidth + '", "' + playerDetails.skin.properties.playerHeight + '")';
			}
		} else {
			$('embedcode').value = "To generate the embed code click on Publish";
		}

		//popup
		if (window.publish > 0)
		{
			var txt = '';
			txt += "<table align='center' cellpadding='' style='margin-top:15px'><tr>";
			txt += "<td><a style='color:transparent' href='" + link1 + "'><img id='img_default' src='/images/default_over.png' border=''/></a></td>";
			//txt += "<td><a style='color:transparent' href='" + link2 + "'><img id='img_wordpress' src='images/wordpress.png' border=''/></a></td>";
			txt += "<td><a style='color:transparent' href='" + link3 + "'><img id='img_myspace' src='/images/myspace.png' border=''/></a></td>";
			txt += "<td><a style='color:transparent' href='" + link4 + "' target='_blank'><img id='img_facebook' src='/images/facebook.png' border=''/></a></td>";
			txt += "</tr></table>";

			if (uac == 2) {
				txt += "<div style='line-height:1px; width:340px; background:#373737; margin: 5px 34px 0 34px'>&nbsp;</div>";			
				txt += "<p style='font-size: 11px; line-height:18px; margin-bottom: -25px'>IMPORTANT: The player will not work on websites for which you did not set a license. <br/>To configure your licenses please go to the My Account page (link pe My Account) ";
				txt += "To configure your licenses please go to the <a href='/settings'>My Account</a> page.</p>";
			}

			
			createModal('<textarea id="embedtextarea" rows="4" cols="40"></textarea>'+txt, 'createModal();', 'createModal();', 'Embed Code');
			$('embedtextarea').value = $('embedcode').value;
			$('embedtextarea').select();
			window.publish = 0;
		}

	} catch(e) {
		if (playerDetails.status == "published") {
			insertEmbed(playerDetails.txtid, "100%","100%");
			link1 = 'javascript:reloadEmbed("default", "' + playerDetails.txtid + '", "100%", "100%")';
			link2 = 'javascript:reloadEmbed("wordpress", "' + playerDetails.txtid + '", "100%", "100%")';
			link3 = 'javascript:reloadEmbed("myspace", "' + playerDetails.txtid + '", "100%", "100%")';
		}
		else
		$('embedcode').value = "To generate the embed code click on Publish";

		if (window.publish > 0)
		{
			//showNotification("You haven\'t define any licenses. You can do this action in your <a href='/settings'>settings</a> page.");
			var txt = '';
			txt += "<table align='center' cellpadding='' style='margin-top:15px'><tr>";
			txt += "<td><a style='color:transparent' href='" + link1 + "'><img id='img_default' src='/images/default_over.png' border=''/></a></td>";
			//txt += "<td><a style='color:transparent' href='" + link2 + "'><img id='img_wordpress' src='images/wordpress.png' border=''/></a></td>";
			txt += "<td><a style='color:transparent' href='" + link3 + "'><img id='img_myspace' src='/images/myspace.png' border=''/></a></td>";
			txt += "<td><a style='color:transparent' href='" + link4 + "' target='_blank'><img id='img_facebook' src='/images/facebook.png' border=''/></a></td>";
			txt += "</tr></table>";

			if (uac == 2) {
				txt += "<div style='line-height:1px; width:340px; background:#373737; margin: 5px 34px 0 34px'>&nbsp;</div>";
				txt += "<p style='font-size: 11px; line-height:18px; margin-bottom: -25px'>IMPORTANT: The player will not work on websites for which you did not set a license. <br/>To configure your licenses please go to the My Account page (link pe My Account) ";
				txt += "To configure your licenses please go to the <a href='/settings'>My Account</a> page.</p>";
			}

			createModal('<textarea id="embedtextarea" rows="4" cols="40" ></textarea>'+txt, 'createModal();', 'createModal();', 'Embed Code');
			$('embedtextarea').value = $('embedcode').value;
			$('embedtextarea').select();
			window.publish = 0;
		}
	}
	var object = new Object();
	object.videos = new Array();
	object.playlists = new Array();
	
	for (i=0; i< window.vnp.videos.length; i++)
	{
		var xxx = {};
		xxx.id = window.vnp.videos[i].id;
		object.videos.push(xxx);
	}

	for (i=0; i< window.vnp.playlists.length; i++)
	{
		var xxx = {};
		xxx.id = window.vnp.playlists[i].id;
		object.playlists.push(xxx);
	}
		
	object.skinid = $('skinid').value;
	object.playerid = playerDetails.txtid;


	var aaa = object.toJSONString();
	$('vpparent').innerHTML = '<div id="vp_holder" class="vp_holder"> </div>';

	aaa = str_replace('"', '\\`', aaa);
	aaa = str_replace('&', '_|_', aaa);
	
	//aaa = encodeURIComponent(aaa);

	var flashvars = {
		htmlPage: document.location,
		settingsFile: "/players/feedxml?string="+aaa+"|||"+playerDetails.status
	};
	flashvars.parseJSON = false;
	flashvars.toJSONString = false;

	var params = {
		allowFullScreen: "true",
		wmode: "opaque"
	};

	swfobject.embedSWF("/player.swf", "vp_holder", "473", "340", "9.0.115", "swfobject/expressInstall.swf", flashvars, params);

}

function rename(a)
{
	if (a.innerHTML == "Rename")
	{
		$('playername').disabled = false;
		$('playername').focus();
		a.innerHTML = "Save";
	} else {
		$('playername').disabled = true;
		$('playername').blur();
		a.innerHTML = "Rename";
		document.modified = 1;
	}
}

function reloadEmbed(type, id, w, h) {
	var srcs = new Array('default', 'wordpress', 'myspace', 'facebook');
	for (var i in srcs) {
		if (typeof srcs[i] == "string" && $('img_' + srcs[i]))
		//if ($('img_' + srcs[i]).src == 'images/' + srcs[i] + '_over.png')
		$('img_' + srcs[i]).src = '/images/' + srcs[i] + '.png';
	}

	if ($("img_" + type)) {
		$("img_" + type).src = "/images/" + type + "_over.png";
	}

	if (playerDetails) {
		if (!id || !w || !h) {
			id = playerDetails.txtid;
			if (playerDetails.skin.properties) {
				if (playerDetails.skin.properties.autoResize == "1") {
					w = "100%";
					h = "100%";
				}
				else {
					w = playerDetails.skin.properties.playerWidth;
					h = playerDetails.skin.properties.playerHeight;
				}
			}
			else if (playerDetails.skinDetails){
				if (playerDetails.skinDetails.autoResize == "1") {
					w = "100%";
					h = "100%";
				}
				else {
					w = playerDetails.skinDetails.playerWidth;
					h = playerDetails.skinDetails.playerHeight;
				}
			}
			else {
				return;
			}
		}
		switch(type) {
			case 'default':
			insertEmbed(id, w, h);
			break;
			case 'wordpress':
			insertEmbedWordPress(id, w, h);
			break;
			case 'myspace':
			insertEmbedMySpace(id, w, h);
			break;
			default:
			break;
		}
		if ($('embedtextarea')) {
			$('embedtextarea').value = $('embedcode').value;
			$('embedtextarea').select();
		}
	}
	else return;
}

function showEmbed()
{
	var link1 = "#";
	var link2 = "#";
	var link3 = "#";
	var link4 = embedFacebook();

	try {
		if (playerDetails.status == "published") {
			if (playerDetails.skinDetails) {
				if (playerDetails.skinDetails.autoResize == "1") {
					insertEmbed(playerDetails.txtid, "100%","100%");
					link1 = 'javascript:reloadEmbed("default", "' + playerDetails.txtid + '", "100%", "100%")';
					link2 = 'javascript:reloadEmbed("wordpress", "' + playerDetails.txtid + '", "100%", "100%")';
					link3 = 'javascript:reloadEmbed("myspace", "' + playerDetails.txtid + '", "100%", "100%")';
				}
				else {
					insertEmbed(playerDetails.txtid, playerDetails.skinDetails.playerWidth,playerDetails.skinDetails.playerHeight);
					link1 = 'javascript:reloadEmbed("default", "' + playerDetails.txtid + '", "' + playerDetails.skinDetails.playerWidth + '", "' + playerDetails.skinDetails.playerHeight + '")';
					link2 = 'javascript:reloadEmbed("wordpress", "' + playerDetails.txtid + '", "' + playerDetails.skinDetails.playerWidth + '", "' + playerDetails.skinDetails.playerHeight + '")';
					link3 = 'javascript:reloadEmbed("myspace", "' + playerDetails.txtid + '", "' + playerDetails.skinDetails.playerWidth + '", "' + playerDetails.skinDetails.playerHeight + '")';
				}
			}
			else if (playerDetails.skin.properties) {
				if (playerDetails.skin.properties.autoResize == "1") {
					insertEmbed(playerDetails.txtid, "100%","100%");
					link1 = 'javascript:reloadEmbed("default", "' + playerDetails.txtid + '", "100%", "100%")';
					link2 = 'javascript:reloadEmbed("wordpress", "' + playerDetails.txtid + '", "100%", "100%")';
					link3 = 'javascript:reloadEmbed("myspace", "' + playerDetails.txtid + '", "100%", "100%")';
				}
				else {
					insertEmbed(playerDetails.txtid, playerDetails.skin.properties.playerWidth,playerDetails.skin.properties.playerHeight);
					link1 = 'javascript:reloadEmbed("default", "' + playerDetails.txtid + '", "' + playerDetails.skin.properties.playerWidth + '", "' + playerDetails.skin.properties.playerHeight + '")';
					link2 = 'javascript:reloadEmbed("wordpress", "' + playerDetails.txtid + '", "' + playerDetails.skin.properties.playerWidth + '", "' + playerDetails.skin.properties.playerHeight + '")';
					link3 = 'javascript:reloadEmbed("myspace", "' + playerDetails.txtid + '", "' + playerDetails.skin.properties.playerWidth + '", "' + playerDetails.skin.properties.playerHeight + '")';
				}
			}

			//popup
			if (window.publish > 0)
			{
				var txt = '';
				/*txt += "<table align='center' cellpadding='' style='margin-top:15px'><tr>";
				txt += "<td><a style='color:transparent' href='" + link1 + "'><img id='img_default' src='images/default_over.png' border=''/></a></td>";
				//txt += "<td><a style='color:transparent' href='" + link2 + "'><img id='img_wordpress' src='images/wordpress.png' border=''/></a></td>";
				txt += "<td><a style='color:transparent' href='" + link3 + "'><img id='img_myspace' src='images/myspace.png' border=''/></a></td>";
				txt += "<td><a style='color:transparent' href='" + link4 + "' target='_blank'><img id='img_facebook' src='images/facebook.png' border=''/></a></td>";
				txt += "</tr></table>";

				if (uac == 2) {
					txt += "<div style='line-height:1px; width:340px; background:#373737; margin: 5px 34px 0 34px'>&nbsp;</div>";
					txt += "<p style='font-size: 11px; line-height:18px; margin-bottom: -25px'>IMPORTANT: The player will not work on websites<br/> for which you did not set a license.<br/>";
					txt += "To configure your licenses please go to the <a href='/settings'>My Account</a> page.</p>";
				}*/
				
/* 				txt += '<div style="color:#697581; font-size:12px; text-align:left; margin-left:70px; padding:10px 0">';
				txt += '<input type="checkbox" style="valign:middle; width: auto; border: none; height: auto; padding: 0;" onclick="personalPublish('+playerDetails.id+')"/> ';
				txt += 'Publish on my personal VPF page';
				txt += '</div>'; */
				
				
				createModalEmbed('<textarea id="embedtextarea" rows="4" cols="39" ></textarea>'+txt, 'createModalEmbed();', 'createModalEmbed();', 'Embed Code');
				$('embedtextarea').value = $('embedcode').value;
				$('embedtextarea').select();

				l1 = link1.substr(11,link1.length);
				l3 = link3.substr(11,link3.length);
				$('ddv_default').onclick = function() { embedDDSelect(this, 'default', l1); };
				$('ddv_myspace').onclick = function() { embedDDSelect(this, 'myspace', l3); };
				window.publish = 0;
				
				//resetam dropdown-ul
				embedDDSelect($('ddv_default'), 'default', 'void(0)');
				$('ulEmbeddd').style.display = 'none';
			}
		} else {
			$('embedcode').value = "To generate the embed code click on Publish";
		}

	} catch(e) {
		if (playerDetails.status == "published") {
			insertEmbed(playerDetails.txtid, "100%","100%");
			link1 = 'javascript:reloadEmbed("default", "' + playerDetails.txtid + '", "100%", "100%")';
			link2 = 'javascript:reloadEmbed("wordpress", "' + playerDetails.txtid + '", "100%", "100%")';
			link3 = 'javascript:reloadEmbed("myspace", "' + playerDetails.txtid + '", "100%", "100%")';
		}
		else
		$('embedcode').value = "To generate the embed code click on Publish";

		if (window.publish > 0)
		{
			//showNotification("You haven\'t define any licenses. You can do this action in your <a href='/settings'>settings</a> page.");
			var txt = '';
			txt += "<table align='center' cellpadding='' style='margin-top:15px'><tr>";
			txt += "<td><a style='color:transparent' href='" + link1 + "'><img id='img_default' src='/images/default_over.png' border=''/></a></td>";
			//txt += "<td><a style='color:transparent' href='" + link2 + "'><img id='img_wordpress' src='images/wordpress.png' border=''/></a></td>";
			txt += "<td><a style='color:transparent' href='" + link3 + "'><img id='img_myspace' src='/images/myspace.png' border=''/></a></td>";
			txt += "<td><a style='color:transparent' href='" + link4 + "' target='_blank'><img id='img_facebook' src='/images/facebook.png' border=''/></a></td>";
			txt += "</tr></table>";

			if (uac == 2) {
				txt += "<div style='line-height:1px; width:340px; background:#373737; margin: 5px 34px 0 34px'>&nbsp;</div>";			
				txt += "<p style='font-size: 11px; line-height:18px; margin-bottom: -25px'>IMPORTANT: The player will not work on websites<br/> for which you did not set a license.<br/>";
				txt += "To configure your licenses please go to the <a href='/settings'>My Account</a> page.</p>";
			}


			createModal('<textarea id="embedtextarea" rows="4" cols="40"></textarea>'+txt, 'createModal();', 'createModal();', 'Embed Code');
			$('embedtextarea').value = $('embedcode').value;
			$('embedtextarea').select();
			window.publish = 0;
		}
	}
}

function personalPublish(id) {
	//todo
	if (id) {
		POST('/players/vpfpublish/', '', 'id='+id+'&flag=1');	
	}
}

function renameskin(e)
{

	document.modified = 1;
	if (typeof e.currentTarget != "undefined")
	{
		var target = e.currentTarget;
	}
	else if (e.srcElement)
	{
		var target = e.srcElement;
	}

	window.currentskin.title = $(target.id).value;
	$('skinname').value = $(target.id).value;
/* 	$('skinname2').value = $(target.id).value;
	$('skinname3').value = $(target.id).value;
	$('skinname4').value = $(target.id).value; */

	/*if (a.innerHTML == "Rename")
	{
	$('skinname'+which).disabled = false;
	$('skinname'+which).focus();
	a.innerHTML = "Save";
	} else {
	$('skinname'+which).disabled = true;
	$('skinname'+which).blur();
	a.innerHTML = "Rename";
	window.currentskin.title = $('skinname'+which).value;

	$('skinname').value = $('skinname'+which).value;
	$('skinname2').value = $('skinname'+which).value;
	$('skinname3').value = $('skinname'+which).value;
	$('skinname4').value = $('skinname'+which).value;
	document.modified = 1;
	}*/
}



function askToSave()
{
	if (document.perform != '')
	{
		eval(document.perform);
		document.perform = '';
	}
}


function resetPlayerForm()
{
	$('playername').value='';
	$('skinname').value='Classic';
	$('skinid').value='1';
	playerDetails = false;

	$('embedcode').value = 'To generate the embed code click on Publish';
	var ol = $('vnpl');
	while (ol.hasChildNodes())
	{
		ol.removeChild(ol.firstChild)
	}

	$('playerdescription').value='';
	$('located').value='http://';
	$('embedcode').value = 'To generate the embed code click on Publish';

	var d = new Date();
	var day = parseInt(d.getDate());
	if (day < 10)
	day = "0"+day;
	var month = parseInt(d.getMonth()) + 1;
	if (month < 10)
	month  = "0"+month;
	$('date').value=d.getFullYear() + "-"+month+"-"+day;

	$('statusimg').src="/images/bulet_red.png";
	$('statustex').value = "Not Published";
	//resetam quick link-ul
	$('qlink').style.display = 'block';
	$('qupload').style.display = 'none';
	$('videopath').value = 'Paste video URL';

	removeVNP(0);
}

function checkForChanges()
{
	try {
		if (document.modified)
		{
			return false;
		}
		else
		return true;
	} catch(e) {}
	return true;
}

function savePlayer(publish, confirm)
{
	var p = new Object;

	if (parseInt(publish) > 0 ) p.publish = true;
	else p.publish = false;


	if ($('playername').value.trim().length == 0 && !confirm)
	{
		document.perform = "savePlayer('"+publish+"', 1)";
		if ($('warning').style.display == "block")
		createModal();

		createModal('Please enter a name for your new player:<br /><input type="text" id="newplayername" />', 'eval(document.perform);', 'createModal()', 'Player name');
		$('newplayername').focus();
		return 0;
	} else {
		if ($('playername').value.trim().length > 0)
		{
			p.name = $('playername').value.trim();
			$('playername').value = p.name;
			if ($('warning').style.display == "block")
			{
				createModal();
			}
		}
		else
		if ($('newplayername').value.trim().length > 0)
		{
			p.name = $('newplayername').value.trim();
			$('newplayername').value = p.name;
			if ($('warning').style.display == "block")
			{
				createModal();
			}
		}
		else
		{
			document.perform = "savePlayer('"+publish+"', 1)";
			if ($('warning').style.display == "block")
			{
				createModal();
			}
			createModal('Please enter a name for your new player:<br /><input type="text" id="newplayername" />', 'eval(document.perform); ', 'createModal()', 'Player name');
			$('newplayername').focus();
			return 0;
		}

	}

	if ($('skinname').value.length == 0)
	{
		showRedNotification('Please choose a skin', 1);
		return 0;
	} else p.skiname = $('skinname').value;

	p.skinid = $('skinid').value;
	p.description = $('playerdescription').value;

	p.located = $('located').value;

	var ol = $('vnpl');
	p.videos = new Array();
	p.playlists = new Array();
	p.videos = vnp.videos;
	p.playlists = vnp.playlists;

	
	for (i in p.videos)
	{
		var tmp_title = vnp.videos[i].title;
		var tmp_description = vnp.videos[i].description;
		
		delete p.videos[i].title;
		delete p.videos[i].description;
		//obiectul "p" este o referinta la "vnp", motiv pentru care refacem atributele sterse
		vnp.videos[i].title = tmp_title;		
		vnp.videos[i].description = tmp_description;		
	}
	
	for (i in p.playlists)
	{
		var tmp_playlistname = vnp.playlists[i].playlist;
		
		delete p.playlists[i].playlist;
		//obiectul "p" este o referinta la "vnp", motiv pentru care refacem atributele sterse
		vnp.playlists[i].playlist = tmp_playlistname;
	}
	
	try {
		if (playerDetails.id != '' && playerDetails.id != '0' && typeof playerDetails.id != "undefined")
		{
			p.id = playerDetails.id;
			var ptype = "old";
		} else {
			var ptype = "new";
		}
	}catch(e){ptype = "new";}

	document.modified = 0;
	showNotification('Saving player "'+p.name+'"', 0);

	
	$('playername').value = p.name;
	
	window.publish = publish;


	var string  = p.toJSONString();
	string = str_replace('&', 'and', string);
	//inlocuit functia "escape" cu "encodeURIComponent", astfel incat sa nu mai avem erori la caractere straine, accente etc.
	params = "string="+encodeURIComponent(string);
	
	if (ptype == "old")
	{
		POST('/players/saveplayer/', 'document.selectedplayer="'+playerDetails.id+'"; showNotification("Player saved.", 1);GET("/players/list", "showPlayers")', params,1);
	}
	else {
		POST('/players/saveplayer/', 'showNotification("Player saved.", 1);insertPlayer', params);
	}
	
}

function deletePlayer(id, confirm)
{
	if (!confirm) {
		var t = $('playerstable').lastChild;
		for (var i in t.childNodes)
		{
			try {
				if (t.childNodes[i].getAttribute('rel') == id)
				{
					var name = t.childNodes[i].getAttribute('search');
				}
			} catch(e){}
		}
		createModal('Are you sure you want to delete the player <br />"'+name+'"?', 'deletePlayer('+id+', 1);createModal()', 'createModal()', 'Delete player');
		
	}

	if (confirm)
	{
		var t = $('playerstable').lastChild;

		for (var i in t.childNodes)
		{
			try {
				if (t.childNodes[i].getAttribute('rel') == id)
				{
					t.removeChild(t.childNodes[i]);
					GET('/players/delete/?tpid='+id, "GET('/players/list', 'showPlayers');");
					showNotification('Player deleted.', 1);
				}
			}catch(e){}
		}

		if (document.selectedplayer == id)
		{
			document.selectedplayer = 0;
			resetPlayerForm();
		}

		var k = 0;
		for (var i in t.childNodes)
		{
			try {
				if (t.childNodes[i].getAttribute('rel'))
				{
					k ++;
				}
			}catch(e){}
		}
		if (k == 0)
		{
			/*var tr = document.createElement('TR');
			tr.innerHTML = '<td class="text_blue no_border" width="216" align="center" colspan="5">No players created.</td>';
			tr.setAttribute('class', 'last_tr');
			t.appendChild(tr);*/
			$('scrollholder1').style.height = '40px !important';
			$('scroll1').innerHTML = '<table cellpadding="0" cellspacing="0" border="0" class="players line_h2 resizable" id="playerstable">\
			<tr class="title">\
	                            	<th style="width: 44px">&nbsp;</td>\
	                                <th style="width:206px">Name</td>\
	                                <th style="width:134px">Actions</td>\
	                                <th style="width:510px">Player Info</th>\
	                                <th class="no_border">Preview</th>\
	                            </tr>\
			<tr class="last_tr"><td class="text_blue no_border" width="216" align="center" colspan="5">No players created.</td></tr></table>';
			TableKit.Resizable.init($('playerstable'), '');
		}
		newPlayer();
	}
}

function search(object, obj)
{
	try {
		if ($('colaps_pl').className != 'hide_upload') {
			$('colaps_pl').className='hide_upload';
			expand('playliststable');
			expand('playerstable');
		}
	}catch (e) { }
	if (object.value != "search")
	{
		
		var t = $(obj).lastChild;

		/*if (t.childNodes[0].className == "last_tr")
		{
		//object.value = "search"; return;
		}*/
		object.focus();
		var aux = false;
		var count = 0;
		for (var i in t.childNodes)
		{
			try {
				if (typeof t.childNodes[i] != "function" && typeof t.childNodes[i] != "number")
				{
					if (t.childNodes[i].getAttribute('search').toLowerCase().indexOf(object.value.toLowerCase().trim()) != -1)
					{
						
						if (navigator.userAgent.indexOf("MSIE") != -1)
						t.childNodes[i].style.display = 'block';
						else
						t.childNodes[i].style.display = 'table-row';

						t.childNodes[i].className = "last_tr";
						if (aux) aux.className = "";

						aux = t.childNodes[i];
						count++;
					} else {
						t.childNodes[i].style.display = 'none';
					}
				}
			}catch(e){}
		}
		try {
			$('track1').parentNode.removeChild($('track1'));
		} catch(e){}

		//$('scroll1').style.width = "990px";
		if (obj == 'playliststable' || obj == 'skinstable')
		{
			//moveUp($('scrollholder1', 1));
			/*dw_scrollObj.initScroll('scrollholder1', "up");*/
			$('scrollholder1').style.height = (47*count)+47 +"px";/*;
			*/removeMouseWheeleScrolling('scrollholder1');
		}
		else {
//			if (count > 0)
			$('scrollholder1').style.height = (40*count) + 40+"px";
//			else
//			$('scrollholder1').style.height = "80px";

		}

	}
	
	if (object.value == '')
	{
		if ($('colaps_pl').className == "show_section")
		{
			expand();
		}
	}

}

function newPlayer()
{
	$('embed_options').style.display = 'none';
	if (checkForChanges())
	{
		resetPlayerForm();
		selectPlayer(0);
		
		resetVideoCollection();
		resetPlaylistCollection();
	}
	else {
		//document.peform = 'resetPlayerForm()';
		var name = $('playername').value.trim();
		$('playername').value = name;
		createModal('You have made changes to the "'+name+'" player. <br />If you continue you will lose these changes. <br />Are you sure you want to continue?', 'document.modified = 0; newPlayer(); createModal();', 'createModal()', 'Abort changes');
	}

}

function showDeleteImg(object)
{
	for (i in object.firstChild.childNodes)
	{
		if (object.firstChild.childNodes[i].nodeName == "IMG")
		{
			object.firstChild.childNodes[i].style.display = "block";
		}
	}
}

function hideDeleteImg(object)
{
	for (i in object.firstChild.childNodes)
	{
		if (object.firstChild.childNodes[i].nodeName == "IMG")
		{
			object.firstChild.childNodes[i].style.display = "none";
		}
	}
}

function selectPlayer(id)
{
	var t = $('playerstable').lastChild;
	var j = 1;
	var ok = true;
	for (i in t.childNodes)
	{
		try {
			if (t.childNodes[i].tagName != "TR")
			t.removeChild(t.childNodes[i]);
		} catch(e){}
	}

	for (i in t.childNodes)
	{
		try {
			if (t.childNodes[i].className != 'title')
				t.childNodes[i].className = '';
			if (t.childNodes[i].getAttribute('rel') == id)
			var object = t.childNodes[i];
			if (j == t.childNodes.length)
			{
				if (t.childNodes[i].getAttribute('rel') == id)
				{
					t.childNodes[i].className = 'selected last_tr';
					ok = false;
				} else {
					t.childNodes[i].className = 'last_tr';
				}
			}

			j ++;
		} catch(e) {}
	}
	if (ok && id != 0)
	object.className='selected';
}

function deleteVP(pid, itemid, type, confirm)
{
	if (!confirm)
	{
		document.perform = 'deleteVP("'+pid+'","'+itemid+'","'+type+'",1);createModal()';
		createModal('Are you sure you want to delete this '+type+' from the list?' , 'deleteVP("'+pid+'", "'+itemid+'", "'+type+'", 1);createModal();', 'createModal()', 'Delete content');
	}
	else
	{
		document.modified = true;
		var ol = $('vnpl');
		for (i in ol.childNodes)
		{
			try {

				if (ol.childNodes[i].getAttribute('itemtype') == type && ol.childNodes[i].getAttribute('itemid')==itemid)
				{
					ol.removeChild(ol.childNodes[i]);
					if (type == "video")
					{
						var a = new Array();
						for (i in vnp.videos)
						{
							if (vnp.videos[i].id != itemid)
							{
								a[a.length] = vnp.videos[i];
							}
						}
						vnp.videos = 0;
						vnp.videos = a;
						markVideo(itemid, false);
					}
					else if (type == "playlist")
					{
						var a = new Array();
						for (i in vnp.playlists)
						{
							if (vnp.playlists[i].id != itemid)
							{
								a[a.length] = vnp.playlists[i];
							}
						}
						vnp.playlists = 0;
						vnp.playlists = a;
						markPlaylist(itemid, false);
					}

				}
			} catch(e){}
			if (type == "playlist")
			showNotification('Playlist removed.', 1);

			if (type == "video")
			showNotification('Video removed.', 1);
		}
		//object.parentNode.parentNode.parentNode.removeChild(object.parentNode.parentNode);
		var a = $('vnpl').innerHTML;


		var div = $('videosholder');
		while (div.hasChildNodes())
		{
			div.removeChild(div.firstChild)
		}


		div.innerHTML = '<div id="scrollholder0" class="scrollholder"><div class="scroll" id="scroll0"><ol class="form_list" id="vnpl"></ol></div></div>';

		$('vnpl').innerHTML = a;
		document.No = 0;
		ScrollLoad ("scrollholder0", "scroll0", true);

		var object = new Object();
		object.videos = new Array();
		object.playlists = new Array();
		
		for (i=0; i< window.vnp.videos.length; i++)
		{
			var xxx = {};
			xxx.id = window.vnp.videos[i].id;
			object.videos.push(xxx);
		}

		for (i=0; i< window.vnp.playlists.length; i++)
		{
			var xxx = {};
			xxx.id = window.vnp.playlists[i].id;
			object.playlists.push(xxx);
		}
		object.skinid = $('skinid').value;


		var aaa = object.toJSONString();
		aaa = str_replace('`', '', aaa);
		aaa = str_replace('"', '\\`', aaa);
		aaa = str_replace('&', '_|_', aaa);
		
		$('vpparent').innerHTML = '<div id="vp_holder" class="vp_holder"> </div>';
		var flashvars = {
			htmlPage: document.location,
			settingsFile: "/players/feedxml?string="+aaa
		};
		var params = {
			allowFullScreen: "true",
			wmode: "opaque"
		};

		swfobject.embedSWF("/player.swf", "vp_holder", "473", "340", "9.0.115", "swfobject/expressInstall.swf", flashvars, params);
	}
}

function hidePlayers()
{
	if ( $('scrollholder1').style.display == "none") $('scrollholder1').style.display = "block";
	else $('scrollholder1').style.display = "none";
}

function validatePlayerDuplication(id) {
	var oldname = $('playername').value.trim();
	$('playername').value = oldname;

	if (checkForChanges()) {
		window.setTimeout("duplicatePlayer("+id+")", 1000);
	} else {
		document.perform = 'window.setTimeout("duplicatePlayer('+id+')", 1000)';
		createModal('You have made changes to the current player. <br />If you continue you will lose these changes. <br />Are you sure you want to continue?', 'document.modified = 0; eval(document.perform); createModal();', 'createModal()', 'Abort changes');
	}
}

function duplicatePlayer(id, confirm)
{
	if (!confirm)
	{
		var name = '';
		for (i in allplayers)
		{
			if (typeof allplayers[i] == "object")
			{
				if (allplayers[i]['id'] == id)
				var name = allplayers[i]['name'];
			}
		}
		var search = "Copy of "+name;
		document.perform = 'duplicatePlayer('+id+', 1);createModal();';
		createModal('Please enter a new name for the player<br /><input type="text" onfocus="autoSelect(this)" name="newplayername" id="newplayername" value="'+search+'" />' , 'duplicatePlayer("'+id+'", 1);createModal();', 'createModal()');
		document.getElementById('newplayername').focus();
	} else {
		window.duplicatedPlayer = true;
		var newname = document.getElementById('newplayername').value;
		GET('/players/duplicateplayer/?name='+newname+'&id='+id, 'insertPlayer');
		showNotification('Saving player.', 1);
	}
}

function insertPlayer(text)
{
	if (text.indexOf("ERROR") != -1)
	{
		showRedNotification(str_replace('ERROR:', '', text), 1);
	} else {
		document.selectedplayer = text;
		if (duplicatedPlayer)
		window.setTimeout("GET('/players/getplayer/?tpid="+text+"', 'showPlayerDetails')", 1000);
		GET('/players/list', 'showPlayers');
	}
}

function insertEmbed(id, width, height) {
	var code = '\
<div id="vpf'+id+'"></div>\
<script type="text/javascript" src="' + serverURL + '/swfobject/swfobject.js"></script>\
<script type="text/javascript">\
var flashvars = {\
  htmlPage: document.location,\
  referralVideo: swfobject.getQueryParamValue("referralVideo"),\
  settingsFile: "/publicfeed/?id='+id+'"\
};\
var params = {\
  allowFullScreen: "true",\
  allowScriptAccess: "always"\
};\
swfobject.embedSWF("' + serverURL + '/videoPlayer.swf", "vpf'+id+'", "'+width+'", "'+height+'", "9.0.115", "' + serverURL + '/swfobject/expressInstall.swf", flashvars, params);\
</script>\
	';
	
	$('embedcode').value = code;
}

function insertEmbedWordPress(id, width, height) {
	var code = '[vodpod id=ExternalVideo.867216&w="' + width + '"&h="' + height + '"&fv=?settingsFile=/publicfeed/?id="' + id +'"]';
	$('embedcode').value = code;
}

function insertEmbedMySpace(id, width, height) {
	var code = '<object width="'+width+'" height="'+height+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="vpfplayer'+id+'">\
	<param name="allowfullscreen" value="true" />\
	<param name="allowscriptaccess" value="always" />\
	<param name="movie" value="' + serverURL + '/videoPlayer.swf?settingsFile=/publicfeed/?id='+id+'||myspace.com" />\
	<embed src="' + serverURL + '/videoPlayer.swf?h&settingsFile=/publicfeed/?id='+id+'||myspace.com" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+width+'" height="'+height+'"></embed>\
	</object>';

	$('embedcode').value = code;
}

function getVideo(id)
{
	for (h in window.allvideos)
	{

		if (allvideos[h].id == id)
		{
			return allvideos[h];
		}
	}
}

function getPlaylist(id)
{
	for (i in window.allplaylists)
	{

		if (allplaylists[i].id == id)
		{
			return allplaylists[i];
		}
	}
}

function getplayer(id)
{
	for (i in window.allplayers)
	{
		
		if (allplayers[i].id == id)
		{
			return allplayers[i];
		}
	}
}	

function embedFacebook() {
	var imgDir = "/images/";
	var imgName = "noimage.jpg";

	if (playerDetails) {
		if (playerDetails.videos.length > 0 && playerDetails.videos != "") {
			if (typeof playerDetails.videos[0] == "string")
			var video = getVideo(playerDetails.videos[0]);
			else
			var video = playerDetails.videos[0];

			imgDir = "thumbnails/videos/";
			imgName = video.txtid + ".jpg";
		}
		else if (playerDetails.playlists.length > 0 && playerDetails.playlists != "") {
			if (typeof playerDetails.playlists[0] == "string")
			var playlist = getPlaylist(playerDetails.playlists[0]);
			else
			var playlist = playerDetails.playlists[0];

			if (playlist.videos) {
				if (typeof playlist.videos[0] == "string")
				var video = getVideo(playlist.videos[0]);
				else
				var video = playlist.videos[0];

				imgDir = "thumbnails/videos/";
				imgName = video.txtid + ".jpg";
			}
		}

		var url = serverURL + "/facebook.php?";
		url += "imgPath=" + serverURL + "/" + imgDir + imgName;
		url += "&playerId=" + playerDetails.txtid;
		url += "&currVideo=0";
		url += "&currCateg=0";
		url += "&title=" + playerDetails.name;
		url += "&description=" + playerDetails.description;
		//url += "&htmlPage=" + serverURL + "/players#properties";

		var facebook = "http://www.facebook.com/share.php?u=" + escape(url);
		return facebook;
	}
	return "javascript:void(0)";
}

function redirectFacebook() {
	var fbLink = embedFacebook() ;
	if (fbLink)
	window.open(fbLink);
}

function showPlayers(text)
{
	eval(text);

	window.allplayers = players;
	var t = $('playerstable');
	var d = $('scrollholder1');
	while (t.hasChildNodes())
	{
		t.removeChild(t.firstChild)
	}
	/*var tb = document.createElement('tbody');
	t.appendChild(tb);*/

	try {
		$('track1').parentNode.removeChild($('track1'));
	} catch(e) {}

	var a = "";
	var cnt = 0;
	for (i in players)
	{
		var p = players[i];
		if (typeof p == "object")
		{
			if (p.status == "published")
			var status = "bulet_green";

			if (p.status == "saved")
			var status = "bulet_yellow";

			if (p.status == "notpublished")
			var status = "bulet_red";

			classn = "";
			if (document.selectedplayer == p.id)
			{
				window.playerDetails = p;
				classn = "selected";

				$('statusimg').src='/images/' + status + '.png';
				switch(p.status) {
					case 'published':
					$('statustex').value = "Published";
					$('embed_options').style.display = 'block';
					break;
					case 'saved':
					$('statustex').value = "Saved";
					$('embed_options').style.display = 'none';
					$('embedcode').value = '';
					break;
					case 'notpublished':
					$('statustex').value = "Not Published";
					$('embedcode').value = '';
					break;
				}
			}

			if (i == players.length -1 && document.selectedplayer == p.id)
			{
				classn = "last_tr selected";
				window.playerDetails = p;
			}
			else if (i == players.length -1)
			classn = "last_tr";

			if (parseInt(p.videonumber)  == 0)
			var vlength = "No videos";
			else
			{
				var vlength = parseInt(p.videonumber);
				if (vlength == 1) vlength = "One video";
				else vlength = vlength+" videos";
			}

			if (p.playlists == "")
			{
				if (parseInt(p.videonumber) > 0)
				var plength = "one playlist";
				else
				var plength = "no playlists";
			}
			else {
				var plength = parseInt(p.playlists.length);
				if (plength == 0)
				plength = "one playlist";
				else if (p.videos == "")
				plength = plength + " playlists";
				else
				plength = (plength+1)+" playlists";
			}

			if (window.publish)
			{
				playerDetails.status = 'published';
				showEmbed();
				window.publish = false;
			}
			if (p.name.length > 25) var pname = p.name.substring(0,25)+"..."; else var pname = p.name;

			pname = str_replace('&ghi;', '"', pname);
			pname = str_replace('&apo;', "'", pname);

			p.skin = str_replace('&apo;', "'", p.skin);
			p.skin = str_replace('&apo;', "'", p.skin);


			var w = 473;
			var h = 340;
			if (parseInt(p.skinDetails.autoResize) == 0 && parseInt(p.skinDetails.playerWidth) != 0 && parseInt(p.skinDetails.playerHeight) != 0)
			{
				if (p.skinDetails.playerWidth) var w = p.skinDetails.playerWidth;
				if (p.skinDetails.playerHeight) var h = p.skinDetails.playerHeight;
			}
			var skinhref =  '/skins#'+p.skinDetails.id;
			if (p.description != '' || p.located != 'http://')
			{
				if (p.description != '')
				{
					if (p.located == 'http://')
					var info = p.description.substring(0, 70);
					else {
						var info = p.description.substring( 0, 40);

						var l = 20;
						if (p.description.length <= 40)
						var l = 70 - p.description.length;

						info += "<span class=\"white\">|</span>"+p.located.substring(0, l);
					}
					info += " ... ";
				} else {
					info = p.located.substring(0, 50);
					info += " ... ";
				}
			} else {
				info = '<a href="'+skinhref+'">'+p.skin+' skin</a>  <span class="white">|</span>  '+vlength+' in '+plength+'';
			}

			cnt ++;
			a += '<tr rel="'+p.id+'" search="'+p.name+'" class="'+classn+'">\
		            <td width="44" align="center"><img src="/images/'+status+'.png" width="21" height="21" alt="" /></td>\
		            <td width="206" class="text_blue"><div class="pad3">\
		            	<a href="javascript: editPlayer('+p.id+');" id="inputName-'+p.id+'">'+pname+'</a>\
		            	<input type="text" class="inputChangeName" id="inputNameSelect-'+p.id+'" value="'+pname+'" onkeyup="checkEnter(event,\''+p.id+'\',\'player\');"/>\
		            	</div></td>\
		            <td width="">\
		                <table cellpadding="0" cellspacing="0" border="0" width="100%">\
		                    <tr>\
		                        <td width="33%"><a href="javascript: void(0);" onclick="editName(\''+p.id+'\');"><img src="/images/edit.png" width="13" height="16" alt="Edit" title="Edit" /></a></td>\
		                        <td width="33%"><a href="javascript: deletePlayer('+p.id+');"><img src="/images/delete.png" width="16" height="17" alt="Delete" title="Delete" /></a></td>\
		                        <td width="33%"><a href="javascript: validatePlayerDuplication('+p.id+');"><img src="/images/duplicate.png" width="15" height="17" alt="Duplicate" title="Duplicate" /></a></td>\
		                    </tr>\
		                </table>\
		            </td>\
		            <td width="510" class="text3">\
		                <div class="pad3">'+info+'</div>\
		            </td>\
		            <!--<td width="60" align="center"><a href="/stats/?'+p.id+'"><img src="/images/stats.png" width="17" height="16" alt="Stats" title="Stats" /></a></td>-->\
		            <td align="center" class="no_border">\
		                <a href="javascript: previewPlayer('+p.id+','+w+','+h+');"><img src="/images/preview.png" width="24" height="14" alt="Preview" title="Preview" /></a>\
		            </td>\
		        </tr>\
		        ';
		}
	}

	d.innerHTML = '<div id="scroll1" class="scroll">\
		<table cellpadding="0" cellspacing="0" border="0" class="players line_h2 resizable" id="playerstable">\
			 <tr class="title">\
                                        <td width="44" style="border-left:#bdbdbd solid 1px;">&nbsp;</td>\
                                        <td style="width: 216px;">Name</td>\
                                        <td width="134">Actions</td>\
                                        <td style="width:475px;">Player Info</td>\
                                        <td style="border-right:#bdbdbd solid 1px;" class="no_border">Preview</td>\
                                    </tr>\
	'+a+'</table></div>';
	/*if (players.length-2 > 13)
	{
	d.style.height = "517px";
	document.No = 1;
	ScrollLoad("scrollholder1", "scroll1", true);
	}
	else {*/
	if (cnt > 0)
	d.style.height = players.length*40 + 40 + "px";
	else {
		$('scrollholder1').style.height = '40px !important';
		$('scroll1').innerHTML = '<table id="playerstable" class="resizable players line_h2" cellspacing="0" cellpadding="0" border="0">\
		<tr class="title">\
	                            	<th style="width: 44px">&nbsp;</td>\
	                                <th style="width:206px">Name</td>\
	                                <th style="width:134px">Actions</td>\
	                                <th style="width:510px">Player Info</th>\
	                                <th class="no_border">Preview</th>\
	                            </tr>\
		<tr class="last_tr"><td class="text_blue no_border" width="216" align="center" colspan="5">No players created.</td></tr></table>';
		
	}
	/*}

	if (document.godown)
	moveUp($('scrollholder1'), 1);*/
TableKit.Resizable.init($('playerstable'), '');
	document.godown = false;
	/*if (document.selectedplayer)
	editPlayer(document.selectedplayer);*/
	if (window.perf) {
		eval(window.performDemo);
		window.perf = 0;
	}
}

function autoSelect(textbox)
{
	if (textbox.createTextRange)
	{
		var oRange = textbox.createTextRange();
		oRange.moveStart("character", 0);
		oRange.moveEnd("character", textbox.value.length);
		oRange.select();
	} else if (textbox.setSelectionRange) {
		textbox.setSelectionRange(0, textbox.value.length);
	}
}

function checkall(type)
{
	if (type =="videos")
	{
		var divs = document.getElementsByTagName('div');
		var a = 0;
		for (i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "browsevideo")
				{
					a ++;
					divs[i].className = "checkbox on";
				}
			}catch(e){}
		}
		$('checkall-videos').style.display = 'none';
		$('uncheckall-videos').style.display = 'block';
	} else if (type == "bvideos")
	{
		var divs = document.getElementsByTagName('div');
		var a = 0;
		for (i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "bvideo")
				{
					a ++;
					divs[i].className = "checkbox on";
				}
			}catch(e){}
		}
		$('checkall-bvideos').style.display = 'none';
		$('uncheckall-bvideos').style.display = 'block';
	} else {
		var divs = document.getElementsByTagName('div');
		var a = 0;
		for (i in divs)
		{
			
			try {
				if (divs[i].getAttribute('rel') == "browseplaylist")
				{
					a ++;
					divs[i].className = "checkbox on";
				}
			}catch(e){}
		}
		$('checkall-playlists').style.display = 'none';
		$('uncheckall-playlists').style.display = 'block';
	}
	showNotification(a+" items selected", 1);
	
}

function uncheckall(type)
{
	if (type =="videos")
	{
		var divs = document.getElementsByTagName('div');
		for (i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "browsevideo")
				{
					divs[i].className = "checkbox";
				}
			}catch(e){}
		}
		$('uncheckall-videos').style.display = 'none';
		$('checkall-videos').style.display = 'block';
		
		
	}else if (type == "bvideos")
	{
		var divs = document.getElementsByTagName('div');
		for (i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "bvideo")
				{
					divs[i].className = "checkbox";
				}
			}catch(e){}
		}
		$('uncheckall-bvideos').style.display = 'none';
		$('checkall-bvideos').style.display = 'block';
	} else {
		var divs = document.getElementsByTagName('div');
		for (i in divs)
		{
			try {
				if (divs[i].getAttribute('rel') == "browseplaylist")
				{
					divs[i].className = "checkbox";
				}
			}catch(e){}
		}
		$('uncheckall-playlists').style.display = 'none';
		$('checkall-playlists').style.display = 'block';
	}
}


function closePreview()
{
	$('previewmodal').style.display = "none";
	$('displayboxwarning').style.display = "none";
	$('previewmodalcontent').innerHTML = '';
}

function closePreview2()
{
	swfobject.removeSWF("preview");
	$('previewmodal').style.display = "none";
	$('displayboxwarning2').style.display = "none";
	$('previewmodalcontent').innerHTML = '';
}

function closePreview3()
{
	swfobject.removeSWF("preview_c");
	$('previewmodal_c').style.display = "none";
	$('displayboxwarning2').style.display = "none";
	$('previewmodalcontent_c').innerHTML = '';
	if (window.gotoProperties != 0) {
		createProperties(window.gotoProperties); window.gotoProperties = 0;
	}
}

function previewPlayer(id,w, h)
{
	flashTogglePlay(false);

	if (!w) w = 473;
	if (!h) h = 340;

	$('previewmodalcontent').innerHTML = '<div id="preview"></div>';
	var flashvars = {
		htmlPage: document.location,
		settingsFile: "/players/previewxml?id="+id
	};
	var params = {
		allowFullScreen: "true",
		wmode: "window",
		allowScriptAccess:"sameDomain"
	};

	swfobject.embedSWF("/player.swf", "preview", w, h, "9.0.115", "swfobject/expressInstall.swf", flashvars, params);

	$('previewmodalcontent').style.textAlign = "left";
	$('preview').style.textAlign = "left";
	$('previewmodalcontent').style.paddingLeft = "6px";

	var thediv=document.getElementById('displayboxwarning2');
	thediv.style.height = getDocHeight()+"px";
	thediv.style.position = "absolute";
	thediv.style.marginLeft = "0px";
	thediv.style.marginTop = "0px";
	//thediv.style.zIndex = "1";
	thediv.style.left = "0px";
	thediv.style.top = "0px";
	thediv.style.display = "block";

	$('previewmodal').style.display="block";

	$('previewtopmiddle').style.width = w+'px';
	$('previewmodalcontent').style.width = w+10+'px';
	$('previewbottommiddle').style.width = w+'px';

	var sizes = getSize();
	if (sizes[1] > h)
	document.getElementById('previewmodal').style.top = pos() + (sizes[1] - h) / 2 + "px";
	else
	document.getElementById('previewmodal').style.top = pos() + (h - sizes[1]) / 2 + "px";



	if (sizes[0] > w)
	{
		document.getElementById('previewmodal').style.left = (sizes[0] - w) / 2 + "px";
	}
	else {
		document.getElementById('previewmodal').style.left = (w - sizes[0]) / 2 + "px";
	}
}

function showNotification(message, close)
{
	window.clearTimeout(window.nid);
	$('notification').style.display = "block";
	$('notiftext').innerHTML = message;

	if (close)
	window.nid = window.setTimeout('closeNotification()', 2000);
}

function showRedNotification(message, close)
{
	window.clearTimeout(window.rnid);
	$('notification_red').style.display = "block";
	$('notiftext_red').innerHTML = message;

	if (close)
	window.rnid = window.setTimeout('closeRedNotification()', 2000);
}


function closeRedNotification()
{
	$('notification_red').style.display = "none";
}

function closeNotification()
{
	$('notification').style.display = "none";
}

function isURL(s) {
	var regexp = /(http|https|rtmp):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function getVidOffset(id) {
	var offset = 0;
	var element = $('ma' + id);
	var parent = Element.getOffsetParent(element);
	offset += parent.offsetTop;
	
	parent = Element.getOffsetParent(parent);
	offset += parent.offsetTop;
	
	parent = Element.getOffsetParent(parent);
	offset += parent.offsetTop;
	
	return offset;
}

function show_hide_men(id) {
	if ((parseInt(id) + 1) % 6 == 0 && document.getElementById('di-menu'+id).style.marginLeft == '') {
		document.getElementById('di-menu'+id).style.marginLeft = '-30px';
	}
	
	if (document.getElementById('di-menu'+id).style.display == 'none') {
		document.getElementById('di-menu'+id).style.display = 'block';
		document.getElementById('di-menu'+id).parentNode.parentNode.style.zIndex = "1"; // for IE7
	}
	else {
		document.getElementById('di-menu'+id).style.display = 'none';
		document.getElementById('di-menu'+id).parentNode.parentNode.style.zIndex = "0"; // for IE7
	}
	
	var offset = getVidOffset(id);
	var menuHeight = $('di-menu' + id).offsetHeight;
	if (offset > 340 && menuHeight > 0) {
		moveDownTime($('scrollholder5'), menuHeight * 1.2);
	}	

}


/*function showMenuArrow(id)
{
try {
for (var i=0; i < 1000; i++)
{
if (i != id)
{
$('ma'+i).style.display = 'none';
document.getElementById('di-menu'+i).style.display = 'none'
}
}
} catch(e) {}
$('ma'+id).style.display = "block";
window.clearTimeout(window.menutimer);
}

function hideMenuArrow(id)
{
$('ma'+id).style.display = "none";
window.menutimer = window.setTimeout("$('ma"+id+"').style.display = 'none';document.getElementById('di-menu"+id+"').style.display = 'none'", 10);
}*/


function showMenuArrow(id)
{
	try {
		for (var i=0; i < 1000; i++)
		{
			if (i != id)
			{
				if ($('ma'+i)) {
				$('ma'+i).style.display = 'none';
				document.getElementById('di-menu'+i).style.display = 'none';
				if (document.getElementById('ma'+id).parentNode.nodeName == "LI") {
					document.getElementById('di-menu'+i).parentNode.parentNode.style.zIndex = "0"; // for IE7
				}
				}
			}
		}
	} catch(e) {}
	
/* 	if ($('ma'+id).innerHTML != '') {
		vidMenus[id] = $('ma'+id).innerHTML;
	}
	else if (typeof vidMenus[id] == 'string')
		$('ma'+id).innerHTML = vidMenus[id];		 */
	
	$('ma'+id).cleanWhitespace();
	$('ma'+id).firstChild.style.display = 'block';
	$S('ma'+id).display = "block";

	//window.clearTimeout(window.menutimer);
}


function hideMenuArrow(id)
{
	//$S('ma'+id).display = "none";
	
	$('ma'+id).cleanWhitespace();
	$('ma'+id).firstChild.style.display = 'none';
	$S('di-menu'+id).display = "none";
	
	//vidMenus[id] = $('ma'+id).innerHTML;
	//$('ma' + id).innerHTML = '';
	
	//window.menutimer = window.setTimeout("$('ma"+id+"').style.display = 'none';document.getElementById('di-menu"+id+"').style.display = 'none'", 10);
}


function hideMenu(id)
{
	/*$('di-menu'+id).style.display = "none";*/
}



function show_hide_menPC(id) {

	if (document.getElementById('dipc-menu'+id).style.display == 'none')
	{
		document.getElementById('dipc-menu'+id).parentNode.parentNode.parentNode.style.zIndex = "1";
		document.getElementById('dipc-menu'+id).style.display = 'block';
	}
	else {
		document.getElementById('dipc-menu'+id).parentNode.parentNode.parentNode.style.zIndex = "0";
		document.getElementById('dipc-menu'+id).style.display = 'none';
	}
}

function showMenuArrowPC(id)
{
	try {
		for (var i=0; i < 1000; i++)
		{
			if (i != id)
			{
				$('mapc'+i).style.display = 'none';
				document.getElementById('dipc-menu'+i).style.display = 'none';
				document.getElementById('dipc-menu'+i).parentNode.parentNode.parentNode.style.zIndex = "0";
			}
		}
	} catch(e) {}
	
/* 	if ($('mapc'+id).innerHTML != '') {
		vidMenusPC[id] = $('mapc'+id).innerHTML;
	}
	else if (typeof vidMenusPC[id] == 'string')
		$('mapc'+id).innerHTML = vidMenusPC[id];	 */	
	
	$('mapc'+id).cleanWhitespace();
	$('mapc'+id).firstChild.style.display = 'block';	
	$S('mapc'+id).display = "block";	
	//window.clearTimeout(window.menutimer2);
}

function hideMenuArrowPC(id)
{
	//$S('mapc'+id).display = "none";
	
	$('mapc'+id).cleanWhitespace();
	$('mapc'+id).firstChild.style.display = 'none';	
	$S('dipc-menu'+id).display = "none";

	//window.menutimer2 = window.setTimeout("$('mapc"+id+"').style.display = 'none';document.getElementById('dipc-menu"+id+"').style.display = 'none'", 10);
}

function setScrollTimeout() {
	window.clearTimeout(window.to);
}

function setScrollTime() {
	window.to = window.setTimeout("$S('slide_bar').display='none'",500);
}

function setScrollTime2() {
	window.to = window.setTimeout("$S('slide_bar2').display='none'",500);
}



function hideMenuPC(id)
{
	$('dipc-menu'+id).style.display = "none";
}

function searchvideosbrowse(obj)
{
	$('scroll7').style.top = "0px";
	var value = obj.toLowerCase().trim();
	var divs = document.getElementsByTagName('div');

	var a = '<div id="clickervideos-div"><table  cellspacing="0" cellpadding="0" border="0" width="100%" id="clickervideos"><tbody>';
	var j =0;

	moveUp($('scrollholder7'), 1);

	var k = 0;
	for (i in window.allvideos)
	{
		if (typeof window.allvideos[i] != "function" && window.allvideos[i].title.toLowerCase().indexOf(value) != -1)
		{
			if (j % 6 == 0)
			{
				a += "<tr>";
			}
			k ++;
			var video = window.allvideos[i];

			try {
				if (video.image == "no image")
				var image = '<img src="/images/noimage.jpg" alt="no image"  />';
				else
				var image = '<img src="/thumbnails/videos/'+video['txtid']+'.jpg" width="94" height="70" alt="" />';
			} catch (e) {var image = '<img src="/thumbnails/videos/'+video['txtid']+'.jpg" width="94" height="70" alt=""/>';}

			var thumb = '';
			if (video.path.indexOf('http://') < 0)
			var thumb = '<li class="th" onclick="refreshThumb(\''+video['txtid']+'\')">Thumb</li>';

			var title = video.title;
			var videoid = video.id;
			a += '<td  align="left">\
							<div class="arrow-menu2" id="ma'+j+'">\
								<div class="small-arrow"><a href="javascript:show_hide_men(\''+j+'\');"></a></div>\
							    <div class="menu-tabs" style="display:none" id="di-menu'+j+'" onmouseout="hideMenu(\''+j+'\')">\
							    	<ul>\
							        	<li class="del" onclick="deleteVideo(\''+video['txtid']+'\')">Delete</li>\
							            <li class="ed" onclick="editVideo(\''+video['txtid']+'\')">Edit</li>\
							            '+thumb+'\
							            <!--<li class="prop" onclick="videoProps(\''+video['txtid']+'\')">Properties</li>-->\
							        </ul>\
							    </div>\
							</div>\
							'+image+'\
                            	<div class="thumb_title">\
                                	<div class="check_selected">\
                                        <div class="checkbox" rel="browsevideo" itemid="'+videoid+'" onclick="checkbox(this, \'autoplay\');">\
                                            <div class="p" onmouseover="showCompleteTitleJs(event, this, \''+addslashes(title.replace(/\"/g,'%22'))+'\');" onmouseout="hideCompleteTitle('+videoid+')">\
                                            	<div class="left">'+title+'</div>\
                                            </div>\
                                        </div>\
                                    </div>\
                                </div>  \
                                </td>';
			if (j % 6 == 5)
			{
				a += "</tr>";
				k = 0;
			}
			j++;
		}
	}

	if (k < 6 && k > 0)
	a += "<td colspan='"+(6 - k)+"'>&nbsp;</td>";
	a+='</tbody></table></div>';

	$('scroll7').innerHTML = '<div class="thumbs">'+a+'</div>';
	document.No = 2;
	//$('videosdiv').innerHTML = a;
	
	selectVideosPrototype();
	
	try {
		$('track7').parentNode.removeChild($('track7'));
	}catch(e){}
	ScrollLoad ("scrollholder7", "scroll7", true);
}


function searchskins(obj)
{
	var value = obj.value.toLowerCase().trim();
	var divs = document.getElementsByTagName('div');

	if (value == "search") return;
	var a = '<div id="skinstable-div"><table  cellspacing="0" cellpadding="0" border="0" width="100%" id="skinstable"><tbody>';
	var j =0;

	moveUp($('scrollholder9'), 1);

	var k = 0;
	for (i in window.allskins)
	{

		if (typeof window.allskins[i] != "function" && window.allskins[i].title.toLowerCase().indexOf(value) != -1)
		{
			if (j % 6 == 0)
			{
				a += "<tr>";
			}
			k ++;
			var skin = window.allskins[i];

			var title = skin.title;
			if (title.length > 10) title = title.substring(0, 10);
			var skinid = skin.id;
			//a += '<td  onmouseover="showMenuArrowPC(\''+j+'\');" onmouseout="hideMenuArrowPC(\''+j+'\');" align="left">\
            if (skin.thumb == '/images/noimage.jpg') skin.thumb = '/images/noimage30.jpg';
			a += '<td align="left">\
					<div class="arrow-menu2" id="mapc'+j+'">\
						<div class="small-arrow"><a href="javascript:show_hide_menPC(\''+j+'\');"></a></div>\
					    <div class="menu-tabs" style="display:none" id="dipc-menu'+j+'" onmouseout="hideMenu(\''+j+'\')">\
					    	<ul>\
					        	<li class="del" onclick="editMenuSkin(\''+skin['id']+'\')">Delete</li>\
					            <li class="ed" onclick="deleteMenuSkin(\''+skin['id']+'\')">Edit</li>\
					        </ul>\
					    </div>\
					</div>\
					<img width="94" height="30" alt="'+title+'"  src="'+skin.thumb+'"/>\
					<div class="thumb_title">\
                        <div group="skins" onclick="checkradiogroup(this, \'skins\')" itemid="'+skinid+'" rel="browseskin" class="radio mfive">\
                        	<div class="p" onmouseover="showCompleteTitleJs(event, this, \''+addslashes(title.replace(/\"/g,'%22'))+'\');" onmouseout="hideCompleteTitle('+skinid+')">\
                            	<p>'+title+'</p>\
                            </div>\
                          </div>\
                	</div>\
                </td>';
			if (j % 6 == 5)
			{
				a += "</tr>";
				k = 0;
			}
			j++;
		}
	}

	if (k < 6 && k > 0)
	a += "<td colspan='"+(6 - k)+"'>&nbsp;</td>";
	a+='</tbody></table></div>';

	$('scroll9').innerHTML = '<div class="thumbs">'+a+'</div>';
	document.No = 2;
	//$('videosdiv').innerHTML = a;
	try {
		$('track9').parentNode.removeChild($('track9'));
	}catch(e){}
	ScrollLoad ("scrollholder9", "scroll9", true);
}

function flashTogglePlay(arg)
{
	try {
		$('vp_holder').togglePlay(arg);
	} catch(e) {}
}

function setFlashPlaying(arg)
{
	window.flashPlaying = arg;
}

function searchplaylistsbrowse(value) {
	s = false;
	if (value != "search" && value != '')
	var s = true;

	var divs = document.getElementsByTagName('div');
	for (i in divs)
	{
		try {
			if (divs[i].getAttribute('rel') == "browseplaylistitem")
			{
			if (divs[i].getAttribute('search').toLowerCase().indexOf(value.toLowerCase()) == -1 && s) {
				divs[i].style.display = 'none';
			}else {
				divs[i].style.display = "block";
			}
			}
		} catch(e){}
	}

	//selectPlaylistsPrototype();	
	
	try {
		$('track8').parentNode.removeChild($('track8'));
	} catch(e){}

	ScrollLoad ("scrollholder8", "scroll8", true);

}

function editMenuSkin(id)
{

	if (checkForChanges())
	{
		window.location.href="/skins/#"+id;
	} else {
		document.perform = "window.location.href='/skins/#"+id+"'";
		var name = $('playername').value.trim();
		$('playername').value = name;
		createModal('You have made changes to the current player. <br />If you continue you will lose these changes. <br />Are you sure you want to continue?', 'document.modified = 0; eval(document.perform); createModal();', 'createModal()', 'Abort changes');
	}
}

function deleteMenuSkin(id, confirm)
{
	if (!confirm)
	{
		createModal('Are you sure you want to delete this skin?', 'deleteMenuSkin('+id+', 1);createModal()', 'createModal()', 'Delete Skin');
	}

	if (confirm)
	{
		skin = getskin(id);
		if (skin.defaultskin == 1)
		{
			showRedNotification("You cannot delete a system skin.", 1);
			return;
		} else {
			GET('/skins/delete/?id='+id, "GET('/skins/list', 'displayMenuSkins');");
		}
		//document.selectedskin = 0;
	}
}

function displayMenuSkins(txt)
{
	eval(txt);
	window.allskins = skins;
	var divs = document.getElementsByTagName('div');

	var a = '<table  cellspacing="0" cellpadding="0" border="0" width="100%" id="skinstable"><tbody>';
	var j =0;

	moveUp($('scrollholder4'), 1);

	var k = 0;
	for (i in window.allskins)
	{

		if (typeof window.allskins[i] != "function")
		{
			if (j % 7 == 0)
			{
				a += "<tr>";
			}
			k ++;
			var skin = window.allskins[i];

			var title = skin.title;

			if (title.length > 10) title = title.substring(0, 10);
			var skinid = skin.id;
			a += '<td  onmouseover="showMenuArrowPC(\''+j+'\');" onmouseout="hideMenuArrowPC(\''+j+'\');" align="left">\
					<div class="arrow-menu2" id="mapc'+j+'">\
						<div class="small-arrow"><a href="javascript:show_hide_menPC(\''+j+'\');"></a></div>\
					    <div class="menu-tabs" style="display:none" id="dipc-menu'+j+'" onmouseout="hideMenu(\''+j+'\')">\
					    	<ul>\
					        	<li class="del" onclick="editMenuSkin(\''+skin['id']+'\')">Delete</li>\
					            <li class="ed" onclick="deleteMenuSkin(\''+skin['id']+'\')">Edit</li>\
					        </ul>\
					    </div>\
					</div>\
					<img width="94" height="70" alt="'+title+'"  src="'+skin.thumb+'"/>\
					<div class="thumb_title">\
                        <div group="skins" onclick="checkradiogroup(this, \'skins\')" itemid="'+skin.id+'" rel="browseskin" class="radio mfive">\
                            <p>'+title+'</p>\
                          </div>\
                	</div>\
                </td>';
			if (j % 7 == 6)
			{
				a += "</tr>";
				k = 0;
			}
			j++;
		}
	}
	if (k < 7 && k > 0)
	a += "<td colspan='"+(7 - k)+"'>&nbsp;</td>";
	a+='</tbody></table>';
	$('scroll9').innerHTML = '<div class="thumbs">'+a+'</div>';
	document.No = 2;
	//$('videosdiv').innerHTML = a;

	try {
		$('track9').parentNode.removeChild($('track9'));
	}catch(e){}
	ScrollLoad ("scrollholder9", "scroll9", true);
}

function removeLoader()
{
	document.body.style.overflow = "visible";
	$('coverall').parentNode.removeChild($('coverall'));
}

function showTutorial(id)
{
	//960 x 634

	var div = $('upgrade_box');

	if (div.style.display != "block")
	{
		try{$('vp_holder').togglePlay(false);} catch(e){}

		$('displayboxwarning').style.width="100%";
		$('displayboxwarning').style.height = getDocHeight()+"px";;
		$('displayboxwarning').style.display="block";

		div.style.display = "block";
		var sizes = getSize();


		var dim = getBrowserDim();

		if (dim[0] >= 1200)
		{
			var w = 960;
		} else {
			var w = dim[0] - 300;
			var h = 0.6875 * w;
		}

		if (dim[1] >= 900)
		{
			var h = 660;
		} else {
			var h = dim[1] - 200;
			var w = h * 1.45
		}

		//alert(dim[0]+'-'+w+'-'+dim[1]+'-'+h);
		if (dim[1] > h)
		div.style.top = pos() + (dim[1] - h) / 2 + "px";
		else
		div.style.top = pos() + (h - dim[1]) / 2 + "px";

		if (dim[0] > w)
		div.style.left = ((dim[0] - w) / 2) - 20 + "px";
		else
		div.style.left = (w - dim[0]) / 2 + "px";

		$('upgrade_box').innerHTML = '<div id="playerbox"></div>\
									<a class="cancel"  href="javascript: showTutorial()">\
										<img src="/images/cancel.jpg" alt="Cancel"/>\
									</a>\
									<div class="clear_upgrade_box"></div>';
		$('upgrade_box').style.width = w+"px";
		$('upgrade_box').style.height = h+25+"px";
		var flashvars = {
			htmlPage: document.location,
			settingsFile: "/demos/demo.php?id="+id+"||"+w+"||"+h
		};
		var params = {
			allowFullScreen: "true",
			allowScriptAccess:"sameDomain"
		};
		swfobject.embedSWF("/player.swf", "playerbox", w, h, "9.0.115", "swfobject/expressInstall.swf", flashvars, params);


	} else {
		swfobject.removeSWF("playerbox");
		div.style.display = "none";
		$('displayboxwarning').style.display="none";
		
	}
}

function getvideobytxt(id)
{
	for (i in window.allvideos)
	{

		if (allvideos[i].txtid == id)
		{
			return allvideos[i];
		}
	}
}


function previewSelectVideo(id)
{
	if (dragStarted) return false;

	var video = getvideobytxt(id);

	if (video.encoded == "0")
	{
		showRedNotification("This video is currently being encoded.", 1);
		return;
	}
	$('previewmodalcontent').innerHTML = '<div id="preview"></div>';
	var flashvars = {
		htmlPage: document.location,
		settingsFile: "/videos/previewvideo?id="+id+"|||notpublished"
	};
	var params = {
		allowFullScreen: "true",
		allowScriptAccess:"sameDomain"
	};

	swfobject.embedSWF("/player.swf", "preview", "473", "340", "9.0.115", "swfobject/expressInstall.swf", flashvars, params);

	$('previewmodalcontent').style.textAlign = "left";
	$('previewmodal').style.zIndex = "103";
	$('preview').style.textAlign = "left";
	//$('previewmodalcontent').style.paddingLeft = "6px";

	var thediv=document.getElementById('displayboxwarning2');
	thediv.style.height = getDocHeight()+"px";
	thediv.style.position = "absolute";
	thediv.style.marginLeft = "0px";
	thediv.style.marginTop = "0px";
	thediv.style.zIndex = "102";
	thediv.style.left = "0px";
	thediv.style.top = "0px";
	thediv.style.display = "block";

	$('previewmodal').style.display="block";

	$('previewtopmiddle').style.width = '490px';
	$('previewmodalcontent').style.width = '510px';
	$('previewbottommiddle').style.width = '490px';

	var sizes = getSize();
	if (sizes[1] > 360)
	document.getElementById('previewmodal').style.top = pos() + (sizes[1] - 600) / 2 + "px";
	else
	document.getElementById('previewmodal').style.top = pos() + (600 - sizes[1]) / 2 + "px";


	if (sizes[0] > 490)
	document.getElementById('previewmodal').style.left = (sizes[0] - 490) / 2 + "px";
	else
	document.getElementById('previewmodal').style.left = (490 - sizes[0]) / 2 + "px";
}

function showQuickTooltip(id)
{
	$('httptooltip').style.display = "block";
}

function hideQuickTooltip(id)
{
	$('httptooltip').style.display = "none";
}

function addQuickHttpVideo(url)
{
	upperurl = url.toUpperCase();
	if ( !isURL(url))
	{
		showRedNotification('Please use a valid URL.', 1);
		return;
	} else
	{
		if (url.indexOf("youtube.com") == -1 && upperurl.indexOf(".FLV") == -1 && upperurl.indexOf(".F4V") == -1 && upperurl.indexOf(".MP4") == -1 && upperurl.indexOf(".M4V") == -1 && upperurl.indexOf(".M4A") == -1 && upperurl.indexOf(".3GP") == -1 && upperurl.indexOf(".MOV") == -1 && upperurl.indexOf("RTMP") == -1)
		{
			showRedNotification('Invalid URL. Please refer to the help section for more details.', 1);
			return;
		} else {
			showNotification('Saving video...');
			GET('/videos/addhttpvideo?path='+url, 'updateQuickVideosWithHttp');
		}
	}
}

function updateHeaderResources(videos) {
	var idx = 0;
	var str = '';
	var img = '';
	if (videos.length > 0) {
		for (i in videos) {
			if (typeof videos[i] == 'object') {
				if (idx % 7 == 0)
				str += '<tr>';

				if (videos[i].image && videos[i].image == "no image")
					img = '<img src="/images/noimage.jpg" alt="img' + i + '" onclick="previewSelectVideo(\'' + videos[i].txtid + '\');"  style="cursor:pointer"/>';
				else
					img = '<img src="/thumbnails/videos/' + videos[i].txtid + '.jpg" width="94" height="70" alt="img' + i + '"  style="cursor:pointer" onclick="previewSelectVideo(\'' + videos[i].txtid + '\');"/>';

				str += '<td>' + img + '<div class="thumb_title"><div class="check_selected"><div class="checkbox" rel="browsevideo" itemid="' + videos[i].id + '" onclick="checkbox(this,\'autoplay\');"><div class="p"><div class="left">' + videos[i].title + '</div></div></div></div></div></td>';

				if (idx % 7 == 6)
					str += '</tr>';

				idx++;
			}
		}

		if (idx % 7 != 6) {
			var colspan = 7 - (idx % 7);

			if (idx % 7 == 5)
			str += '<td></td>';
			else
			str += '<td colspan="' + colspan + '"></td>';

			str += "</tr>";
		}

		if ($('clickervideos')) {
			str = '<table cellpadding="0" cellspacing="0" border="0" id="clickervideos">'+str+'</table>';
			$('clickervideos-div').innerHTML = str;
		}
	}
}

function showQuickLink() {
	$('qlink').style.display = 'none';
	$('qupload').style.display = 'block';
}

function hideQuickLink() {
	$('qlink').style.display = 'block';
	$('qupload').style.display = 'none';
}

function getQuickVideos(args){
	eval(args);
	//update pentru div-ul de selectie al video-urilor
	updateHeaderResources(allvideos);

	var divs = document.getElementsByTagName('div');
	for (i in divs)
	{
		try {
			if (divs[i].getAttribute('rel') == "browsevideo")
			{
				if (divs[i].getAttribute('itemid') == video.id)
				{
					divs[i].className = "checkbox on";
				}
			}
		} catch(e){}
	}

	document.No = 0;
	ScrollLoad ("scrollholder0", "scroll0", true);

	document.modified = 1;
	//update flash
	var object = new Object();
	object.videos = new Array();
	object.playlists = new Array();
	
	for (i=0; i< window.vnp.videos.length; i++)
	{
		var xxx = {};
		xxx.id = window.vnp.videos[i].id;
		object.videos.push(xxx);
	}

	for (i=0; i< window.vnp.playlists.length; i++)
	{
		var xxx = {};
		xxx.id = window.vnp.playlists[i].id;
		object.playlists.push(xxx);
	}
	object.skinid = $('skinid').value;

	var aaa = object.toJSONString();
	aaa = str_replace('`', '', aaa);
	aaa = str_replace('"', '\\`', aaa);
	aaa = str_replace('&', '_|_', aaa);
	$('vpparent').innerHTML = '<div id="vp_holder" class="vp_holder"> </div>';
	var flashvars = {
		htmlPage: document.location,
		settingsFile: "/players/feedxml?string="+aaa
	};
	var params = {
		allowFullScreen: "true",
		wmode: "transparent"
	};

	swfobject.embedSWF("/player.swf", "vp_holder", "473", "340", "9.0.115", "swfobject/expressInstall.swf", flashvars, params);
}

function updateQuickVideosWithHttp(text)
{
	if (text.indexOf('ERROR:') != -1)
	{
		text = str_replace('ERROR: ', '', text);
		showNotification('', 1);
		showRedNotification(text, 1);
		$('videopath').value = "Paste video URL";
		return;
	}
	
	eval(text);
	//continuam doar daca video-ul a fost introdus corect in baza de date
	if (video.id && video.id > 0) {
		vnp.videos.push(video);
		document.allvs.push(video);

		showNotification('Saved.', 1);
		$('videopath').value = "Paste video URL";

		var ol = $('vnpl');
		while (ol.hasChildNodes())
		{
			ol.removeChild(ol.firstChild)
		}

		var div = $('videosholder');
		while (div.hasChildNodes())
		{
			div.removeChild(div.firstChild)
		}
		//reconstruim textarea unde sunt afisate video-urile si playlist-urile
		div.innerHTML = '<div id="scrollholder0" class="scrollholder"><div class="scroll" id="scroll0"><ol class="form_list" id="vnpl"></ol></div></div>';

		var ol = $('vnpl');
		var j = 1;

		for (i in vnp.videos)
		{
			if (typeof vnp.videos[i].title === "string")
			{
				if (vnp.videos[i].title.length > 35)
				title = vnp.videos[i].title.substring(0, 35)+'[...]';
				else
				title = vnp.videos[i].title;

				if (j == vnp.videos.length && vnp.playlists.length == 0)
				{
					ol.innerHTML += "<li itemtype='video' itemid='"+vnp.videos[i].id+"' class='w95 last avideo' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+0+"', '"+vnp.videos[i].id+"', 'video');\"/></a></li>";
				}
				else {
					ol.innerHTML += "<li itemtype='video' itemid='"+vnp.videos[i].id+"' class='w95 avideo' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+0+"', '"+vnp.videos[i].id+"', 'video');\"/></a></li>";
				}
				j++;
			}
		}

		var j = 1;
		for (i in vnp.playlists)
		{
			if (typeof vnp.playlists[i].playlist === "string")
			{

				if (vnp.playlists[i].playlist.length > 35)
				title = vnp.playlists[i].playlist.substring(0, 35)+'[...]';
				else
				title = vnp.playlists[i].playlist;

				if (j == vnp.playlists.length)
				{
					ol.innerHTML += "<li itemtype='playlist' itemid='"+vnp.playlists[i].id+"' class='w95 last' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+0+"', '"+vnp.playlists[i].id+"', 'playlist');\"/></a></li>";
				} else {
					ol.innerHTML += "<li itemtype='playlist' itemid='"+vnp.playlists[i].id+"' class='w95' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+0+"', '"+vnp.playlists[i].id+"', 'playlist');\"/></a></li>";
				}
				j++;
			}
		}
		//citim toate video-urile din db
		GET('/videos/getvideos', 'getQuickVideos');
	}
}




function getBrowserDim() {
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
	&& typeof document.documentElement.clientWidth !=
	'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}

	// older versions of IE

	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return [viewportwidth, viewportheight];
}


function editOrder()
{
	var thediv=document.getElementById('displayboxwarning');
	var page_body = document.getElementById('page_body');
	if(thediv.style.display == "none")
	{

		//insert all the videos
		var a = '<ul id="contentvideos" width="100%">';
		var j =0;
		var k = 0;
		for (i in vnp.videos)
		{
			if (typeof vnp.videos[i] != "function")
			{
				/*if (j % 7 == 0)
				{
				a += "<tr>";
				}*/
				k ++;
				var id =vnp.videos[i].id;
				var video = getVideo(id);
				if (video)
				{
					try {
						if (video.image == "no image")
						var image = '<img src="/images/noimage.jpg" alt="no image"   style="cursor: pointer" onclick="previewSelectVideo(\''+video['txtid']+'\')"/>';
						else
						var image = '<img src="/thumbnails/videos/'+video['txtid']+'.jpg" width="94" height="70" alt=""  style="cursor: pointer" onclick="previewSelectVideo(\''+video['txtid']+'\')"/>';

						if (video.encoded == "0")
						var image = '<img src="/images/processing.jpg" alt="This video is currently being encoded."   style="cursor: pointer" onclick="previewSelectVideo(\''+video['txtid']+'\')"/>';

					} catch (e)
					{
						var image = '<img src="/thumbnails/videos/'+video['txtid']+'.jpg" width="94" height="70" alt=""  style="cursor: pointer" onclick="previewSelectVideo(\''+video['txtid']+'\')"/>';
						if (video.encoded == "0")
						var image = '<img src="/images/processing.jpg" alt="This video is currently being encoded."   style="cursor: pointer" onclick="previewSelectVideo(\''+video['txtid']+'\')"/>';
					}

					var thumb = '';
					try {
						if (video.path.indexOf('http://') < 0)
						var thumb = '<li class="th" onclick="refreshThumb(\''+video['txtid']+'\')">Thumb</li>';
					} catch(e){}

					a += '<li align="left" class="box" itemid="'+video['id']+'">\
							<div>\
								'+image+'\
	                            	<div class="thumb_title">\
	                                	<div class="check_selected">\
	                                        <div class="checkbox" style="background:none;" itemid="'+video.id+'">\
	                                            <div class="p" onmouseover="showCompleteTitleJs(event, this, \''+addslashes(video.title.replace(/\"/g,'%22'))+'\');" onmouseout="hideCompleteTitle('+video.id+')">\
	                                            	<div class="left">'+video.title+'</div>\
	                                            </div>\
	                                        </div>\
	                                    </div>\
	                                </div>  \
	                         </div>\
	                                </td>';
					/*if (j % 7 == 6)
					{
					a += "</tr>";
					}*/
					j++;
				}
			}
		}

		a+='</ul>';
		document.No = 5;

		$('arrangevideos').innerHTML = '<div id="scrollholder11" class="scrollholder" style="overflow: hidden;">\
													<div id="scroll11" class="scroll" style="width: 873px; top: 0px; left: 0px; visibility: visible;">\
													</div>\
												</div>';
		$('scroll11').innerHTML = a;
		dragsortv.makeListSortable(document.getElementById("arrangevideos"),saveVideosOrder);


		//insert all the playlists
		var a = '<ul id="contentplaylists" width="100%">';
		var j =0;
		var k = 0;
		for (i in vnp.playlists)
		{
			if (typeof vnp.videos[i] != "function")
			{
				/*if (j % 7 == 0)
				{
				a += "<tr>";
				}*/
				k ++;
				var id =vnp.playlists[i].id;
				var pl = getPlaylist(id);
				if (pl)
				{

					a += '<li align="left" class="box" itemid="'+pl['id']+'">\
							<div>\
								<img src="/images/playlist_icon.png"\
	                            	<div class="thumb_title">\
	                                	<div class="check_selected">\
	                                        <div class="checkbox" style="background:none;" itemid="'+pl.id+'">\
	                                            <div class="p">\
	                                            	<div class="left">'+pl.playlist+'</div>\
	                                            </div>\
	                                        </div>\
	                                    </div>\
	                                </div>  \
	                         </div>\
	                                </td>';
					/*if (j % 7 == 6)
					{
					a += "</tr>";
					}*/
					j++;
				}
			}
		}

		a+='</ul>';
		document.No = 6;

		$('arrangeplaylists').innerHTML = '<div id="scrollholder10" class="scrollholder" style="overflow: hidden;">\
													<div id="scroll10" class="scroll" style="width: 873px; top: 0px; left: 0px; visibility: visible;">\
													</div>\
												</div>';
		$('scroll10').innerHTML = a;
		dragsortp.makeListSortable(document.getElementById("arrangeplaylists"),savePlaylistsOrder);

		/*selectclickervideos();
		selectclickerplaylists();*/
		thediv.style.display = "";
		//thediv.style.top = pos();
		//632 410
		document.getElementById('rearrange').style.display="block";
		//if ()

		var sizes = getSize();
		if (sizes[1] > 727)
		document.getElementById('rearrange').style.top = pos() + (sizes[1] - 727) / 2 + "px";
		else
		document.getElementById('rearrange').style.top = pos() + 15 + "px";

		if (sizes[0] > 913)
		document.getElementById('rearrange').style.left = (sizes[0] - 913) / 2 + "px";
		else
		document.getElementById('rearrange').style.left = (913 - sizes[0]) / 2 + "px";
		//page_body.style.overflow = "hidden";
		var h = pos() + sizes[1] + "px";
		thediv.style.height = getDocHeight()+"px";
		thediv.innerHTML = "<table width='100%'><tr><td align='center' valign='middle' width='100%' height='100%'></td></tr></table>";
		
		if (document.getElementById('track11') == null)
		{
			ScrollLoad ("scrollholder11", "scroll11", true);
		}
		
		if (document.getElementById('track10') == null)
		{
			ScrollLoad ("scrollholder10", "scroll10", true);
		}

	resizeHorbarEdit('v');
		
	}else{
		thediv.style.display = "none";
		thediv.innerHTML = '';
		//page_body.style.overflow = "auto";
		document.getElementById('rearrange').style.display='none';
	}
	return false;
}


// FAQ
function showQuestion(id)
{
	var qid = "question_" + id;
	var questions = document.getElementsByTagName('div');

	for (i in questions)
	{
		try {
			if (questions[i].id.indexOf('question_q')==0)
			{
				if (questions[i].id != qid) {
					questions[i].style.display = "none";
				}
			}

		} catch(e){}
	}



	if ($(qid).style.display == "none")
	{
		$(qid).style.display = "block";
	}
	else {
		$(qid).style.display = "none";
	}
}

function showFaqCat(id)
{
	var cats = document.getElementsByTagName('div');

	for (i in cats)
	{
		try {
			if (cats[i].id.indexOf('question_q')==0)
			{
				cats[i].style.display = "none";
			}

		} catch(e){}
	}

	for (i in cats)
	{
		try {
			if (cats[i].id.indexOf('cat')==0)
			{
				if (cats[i].id != id) {
					cats[i].style.display = "none";
				}
			}

		} catch(e){}
	}
	if ($(id).style.display == "none")
	{
		$(id).style.display = "block";
	}
	else {
		$(id).style.display = "none";
	}
}

function saveVideosOrder(item)
{
	var group = item.toolManDragGroup
	var list = group.element.parentNode
	var id = list.getAttribute("id")
	if (id == null) return
	group.register('dragend', function() {
		var li = $('contentvideos').getElementsByTagName('li');

		var arr = new Array();
		for (i in li)
		{
			if (li[i].className == "box")
			{
				arr[arr.length] = li[i].getAttribute('itemid');
			}
		}

		vnp.videos = new Array();
		for (i in arr)
		{
			if (typeof arr[i] != "function")
			vnp.videos[vnp.videos.length] = getVideo(arr[i]);
		}

	})
}

function updateOrder()
{
	var thediv=document.getElementById('displayboxwarning');
	var page_body = document.getElementById('page_body');

	thediv.style.display = "none";
	thediv.innerHTML = '';
	document.getElementById('rearrange').style.display='none';

	//refac lista cu vnp

	var ol = $('vnpl');
	while (ol.hasChildNodes())
	{
		ol.removeChild(ol.firstChild)
	}

	var ol = $('vnpl');
	for (i in vnp.videos)
	{
		if (typeof vnp.videos[i].title === "string")
		{
			if (vnp.videos[i].title.length > 20)
			title = vnp.videos[i].title.substring(0, 20)+'[...]';
			else
			title = vnp.videos[i].title;

			if (j == vnp.videos.length && vnp.playlists.length == 0)
			{
				ol.innerHTML += "<li itemtype='video' itemid='"+vnp.videos[i].id+"' class='w95 last' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+playerDetails.id+"', '"+vnp.videos[i].id+"', 'video');\"/></a></li>";
			}
			else {
				ol.innerHTML += "<li itemtype='video' itemid='"+vnp.videos[i].id+"' class='w95' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+playerDetails.id+"', '"+vnp.videos[i].id+"', 'video');\"/></a></li>";
			}
			j++;
		}
	}

	var j = 1;
	for (i in vnp.playlists)
	{
		if (typeof vnp.playlists[i].playlist === "string")
		{
			if (vnp.playlists[i].playlist.length > 20)
			title = vnp.playlists[i].playlist.substring(0, 20)+'[...]';
			else
			title = vnp.playlists[i].playlist;

			if (j == vnp.playlists.length)
			{
				ol.innerHTML += "<li itemtype='playlist' itemid='"+vnp.playlists[i].id+"' class='w95 last' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+playerDetails.id+"', '"+vnp.playlists[i].id+"', 'playlist');\"/></a></li>";
			} else {
				ol.innerHTML += "<li itemtype='playlist' itemid='"+vnp.playlists[i].id+"' class='w95' onmouseover='showDeleteImg(this)' onmouseout='hideDeleteImg(this)'><a href='#''><div>"+title+"</div><img src='/images/delete_blue.png'  onclick=\"deleteVP('"+playerDetails.id+"', '"+vnp.playlists[i].id+"', 'playlist');\"/></a></li>";
			}
			j++;
		}
	}

	var a = $('vnpl').innerHTML;
	$('videosholder').innerHTML = '<div id="scrollholder0" class="scrollholder"><div class="scroll" id="scroll0"><ol class="form_list" id="vnpl"></ol></div></div>';

	$('vnpl').innerHTML = a;
	document.No = 0;
	ScrollLoad ("scrollholder0", "scroll0", true);


	//refac player-ul
	var object = new Object();
	object.videos = new Array();
	object.playlists = new Array();
	
	for (i=0; i< window.vnp.videos.length; i++)
	{
		var xxx = {};
		xxx.id = window.vnp.videos[i].id;
		object.videos.push(xxx);
	}

	for (i=0; i< window.vnp.playlists.length; i++)
	{
		var xxx = {};
		xxx.id = window.vnp.playlists[i].id;
		object.playlists.push(xxx);
	}
	object.skinid = $('skinid').value;

	if (playerDetails)
		object.playerid = playerDetails.txtid;
	else
		object.playerid = 0;
		
	var aaa = object.toJSONString();
	aaa = str_replace('`', '', aaa);
	aaa = str_replace('"', '\\`', aaa);
	aaa = str_replace('&', '_|_', aaa);
	$('vpparent').innerHTML = '<div id="vp_holder" class="vp_holder"> </div>';

	
	var flashvars = {
		htmlPage: document.location,
		settingsFile: "/players/feedxml?string="+aaa
	};
	var params = {
		allowFullScreen: "true",
		wmode: "transparent"
	};

	swfobject.embedSWF("/player.swf", "vp_holder", "473", "340", "9.0.115", "swfobject/expressInstall.swf", flashvars, params);

	document.modified = 1;


}

function savePlaylistsOrder(item)
{
	var group = item.toolManDragGroup
	var list = group.element.parentNode
	var id = list.getAttribute("id")
	if (id == null) return
	group.register('dragend', function()
	{
		var li = $('contentplaylists').getElementsByTagName('li');

		var arr = new Array();
		for (i in li)
		{
			if (li[i].className == "box")
			{
				arr[arr.length] = li[i].getAttribute('itemid');
			}
		}

		vnp.playlists = new Array();
		for (i in arr)
		{
			if (typeof arr[i] != "function")
			vnp.playlists[vnp.playlists.length] = getPlaylist(arr[i]);
		}

	})
}

function order_videos_tab() {
	try {
		document.getElementById('videos_order_tab').style.display = 'block';
		document.getElementById('playlists_order_tab').style.display = 'none';
		resizeHorbarEdit('v');
	} catch(e){}
}

function order_playlists_tab()
{
	try {
		document.getElementById('playlists_order_tab').style.display = 'block';
		document.getElementById('videos_order_tab').style.display = 'none';
		resizeHorbarEdit('p');
	} catch(e){}
}

function loadVideo(id_hook, hook_type) {
	return;
	if (id_hook && hook_type) {
		if (hook_type == 'video') {
			for (var i in playerDetails.videos) {
				if (playerDetails.videos[i].id == id_hook) {
					$('vp_holder').playVideo(0, parseInt(i));
					break;
				}
			}
		}
		else if (hook_type == 'playlist') {
			for (var i in playerDetails.playlists) {
				if (playerDetails.playlists[i].id == id_hook) {
					if (playerDetails.videos[0])
						$('vp_holder').playVideo(parseInt(i) + 1, 0);
					else
						$('vp_holder').playVideo(parseInt(i), 0);
					break;
				}
			}
		}
	}
}

function playVideo(id_hook, hook_type) {
	if (id_hook && hook_type) {
		if (hook_type == 'video') {
			for (var i in window.vnp.videos) {
				if (window.vnp.videos[i].id == id_hook) {
					$('vp_holder').playVideo(0, parseInt(i));
					break;
				}
			}
		}
		else if (hook_type == 'playlist') {
			for (var i in window.vnp.playlists) {
				if (window.vnp.playlists[i].id == id_hook) {
					if (window.vnp.videos[0])
						$('vp_holder').playVideo(parseInt(i) + 1, 0);
					else
						$('vp_holder').playVideo(parseInt(i), 0);
					break;
				}
			}
		}
	}
}

function collapse(obj)
{
	var t = $(obj).lastChild;
	var aux = false;
	for (var i in t.childNodes) {
		try {
			if (typeof t.childNodes[i] != "function" && typeof t.childNodes[i] != "number" && (t.childNodes[i].className != "title" && t.childNodes[i].className != "title last_tr")) {
				t.childNodes[i].style.display = 'none';
			}
			if (typeof t.childNodes[i] != "function" && typeof t.childNodes[i] != "number" && t.childNodes[i].className == "title") {
				t.childNodes[i].className = "title";
			}
		}catch(e){}
	}
	
	try {
		$('track1').parentNode.removeChild($('track1'));
	} catch(e){}
	
	if (obj == 'playliststable' || obj == 'skinstable') {
		$('scrollholder1').style.height = "47px";
	}else {
		$('scrollholder1').style.height = "40px";
	}
}

function expand(obj)
{
	if (!obj) return;
	var t = $(obj).lastChild;
	var aux = false;
	var count = 0;
	if (document.getElementById('searchX').value != 'search') {
		search(document.getElementById('searchX'),obj);
	}else{ 
		if ($('searchX1') != null && document.getElementById('searchX1').value != 'search') {
			search(document.getElementById('searchX1'),obj);
	}else {
		for (var i in t.childNodes) {
			try {
				if (typeof t.childNodes[i] != "function" && typeof t.childNodes[i] != "number") {
					
					if (navigator.userAgent.indexOf("MSIE") != -1) {
						t.childNodes[i].style.display = 'block';
					}else {
						t.childNodes[i].style.display = 'table-row';
					}
					count++;
				}
				
				if (typeof t.childNodes[i] != "function" && typeof t.childNodes[i] != "number" && t.childNodes[i].className == "title last_tr") {
					t.childNodes[i].className = "title";				
				}
			}catch(e){}
		}
		count--;
		
		try {
			$('track1').parentNode.removeChild($('track1'));
		} catch(e){}
	
		if (obj == 'playliststable' || obj == 'skinstable') {
			$('scrollholder1').style.height = (47*count)+47 +"px";
		}
		else {
			if (count > 0) {
				$('scrollholder1').style.height = (40*count) + 40+"px";
			}else {
				$('scrollholder1').style.height = "80px";
			}
		}
	}
	}
	
	
}


function editName(id) {
	document.perform = "finishEditName("+id+")";

	obj = window.page;
	if (obj == 'playlist') {
		for (i in window.allplaylists) {
			for (i in allplaylists) {
				if (typeof allplaylists[i] == "object") {
					if (allplaylists[i]['id'] == id)
					var name = allplaylists[i]['playlist'];
				}
			}
		}
	}
	if (obj == 'skins') {
		for (i in window.allskins) {
			for (i in allskins) {
				if (typeof allskins[i] == "object") {
					if (allskins[i]['id'] == id)
					var name = allskins[i]['title'];
				}
			}
		}
	}
	if (obj == 'player') {
		for (i in window.allplayers) {
			for (i in allplayers) {
				if (typeof allplayers[i] == "object") {
					if (allplayers[i]['id'] == id)
					var name = allplayers[i]['name'];
				}
			}
		}
	}
	
	if ($('warning').style.display == "block") {
		createModal();
	}
	createModal('Please enter a new name:<br /><input type="text" value="'+name+'" id="newname" onfocus="autoSelect(this)"/>', 'eval(document.perform);', 'createModal()', 'Edit name');
	$('newname').focus();
	return 0;
	
}

function finishEditName(id) {
	if ($('newname').value == '') return '';
	obj = window.page;
	var	newname = $('newname').value;
	ok = true;
	if (obj == 'playlist') {
		for (i in window.allplaylists) {
			for (i in allplaylists) {
				if (window.allplaylists[i].playlist == newname) {
					showNotification('You already have a playlist named "'+newname+'".', 1);
					ok = false;
				}
				if (typeof allplaylists[i] == "object") {
					if (allplaylists[i]['id'] == id)
					var name = allplaylists[i]['playlist'];
				}
			}
		}
	}
	if (obj == 'skins') {
		for (i in window.allskins) {
			for (i in allskins) {
				if (window.allskins[i].title == newname) {
					showNotification('You already have a skins named "'+newname+'".', 1);
					ok = false;
				}
				if (typeof allskins[i] == "object") {
					if (allskins[i]['id'] == id)
					var name = allskins[i]['title'];
				}
			}
		}
	}
	if (obj == 'player') {
		for (i in window.allplayers) {
			for (i in allplayers) {
				if (window.allplayers[i].name == newname) {
					showNotification('You already have a player named "'+newname+'".', 1);
					ok = false;
				}
				if (typeof allplayers[i] == "object") {
					if (allplayers[i]['id'] == id)
					var name = allplayers[i]['name'];
				}
			}
		}
	}
	if (ok) {
		$('inputNameSelect-'+id).value = $('newname').value;
		$('inputName-'+id).innerHTML = $('newname').value;
		saveNameAjax(window.page, id);
		$('inputName-'+id).parentNode.parentNode.parentNode.setAttribute('search',$('newname').value);
		/*$('inputNameSelect-'+id).style.display = 'none';
		$('inputName-'+id).style.display = 'inline';*/
		if (window.currentplaylist.id == id) {
			$('playlistnamespanselected').innerHTML = $('newname').value;
			$('playlistnamespan').innerHTML = $('newname').value;
			window.currentplaylist.name = $('newname').value;
		}
		
		if ($('warning').style.display == "block") {
			createModal();
		}
	}
}

function checkEnter(event, id, obj) {
	if (event.keyCode == "13") {
		if ($('inputNameSelect-'+id).value == '')	{
			if ($('inputName-'+id).innerHTML != '')
				$('inputNameSelect-'+id).value = $('inputName-'+id).innerHTML;
			else
				$('inputNameSelect-'+id).value = 'Name';
		}
	
		saveNameAjax(obj, id);
		finishEditName(id);
	}

	if (event.keyCode == "27") {
		finishEditName(id);
	}
}

function saveNameAjax(obj, id) {
	var newName = $('inputNameSelect-'+id).value.trim();
	$('inputNameSelect-'+id).value = newName;
	if (obj == 'playlist') {
		GET('/playlists/saveName/?id='+id+'&name='+newName, 'void');
		$('inputName-'+id).innerHTML = newName;
		for (i in allplaylists) {
			if (typeof allplaylists[i] == "object") {
				if (allplaylists[i]['id'] == id)
					allplaylists[i]['playlist'] = newName;
			}
		}
	}
	if (obj == 'skins') {
		GET('/skins/saveName/?id='+id+'&name='+newName, 'void');
		$('inputName-'+id).innerHTML = newName;
		for (i in allskins) {
			if (typeof allskins[i] == "object") {
				if (allskins[i]['id'] == id)
					allskins[i]['title'] = newName;
			}
		}
	}
	if (obj == 'player') {
		GET('/players/saveName/?id='+id+'&name='+newName, 'void');
		$('inputName-'+id).innerHTML = newName;
		for (i in allplayers) {
			if (typeof allplayers[i] == "object") {
				if (allplayers[i]['id'] == id)
					allplayers[i]['name'] = newName;
			}
		}
	}
}

function showCompleteTitleJs(event, obj, title) {
	var pos = getAbsolutePosition(obj);
	var new_x = mousex;
	var new_y = mousey;
	var top = new_x - pos.x;
	var left = new_y - pos.y;
	setTimeout('showCompleteTitle("'+pos.x+'", "'+pos.y+'", "'+top+'", "'+left+'", "'+title+'")',500);
}

function urldecode(str) {
	str = str.replace(/\+/g, ' ');
	str = unescape(str);
	return str;
}

function showCompleteTitle(x, y, top, left, title) {
	
	var new_x = mousex;
	var new_y = mousey;
	var top1 = new_x - x;
	var left1 = new_y - y;
	if (top1 < 75 && left1 < 30 && top1 > -1 && left1 > -1) {
		var newWidth = title.length * 7;
//		alert(newWidth);
		if (title.indexOf(' ') == -1) {
			title = title.substr(0,25) + '<br/>' + title.substr(25, title.length-25);
		}
		if (newWidth > 220) {
			$('completeTitle').style.top = (new_y-70)+"px";
			$('completeTitleUl').style.width = 200 + "px";
			$('completeTitle').style.left = new_x-parseInt(100)+65+ "px";
		}else {
			$('completeTitle').style.top = (new_y-50)+"px";
			$('completeTitleUl').style.width = parseInt(newWidth)+ 30 + "px";
//			$('completeTitle').style.left = new_x- parseInt((newWidth-20)/2) + "px";
			$('completeTitle').style.left = new_x-parseInt(newWidth/5) + "px";
		}
//		alert(urldecode(title).replace(/\"/g,'%22'));
		$('completeTitleText').innerHTML = urldecode(title);
		$('completeTitle').style.display = 'block';
	}
}

function hideCompleteTitle(id) {
	$('completeTitle').style.display = 'none';
}

function show_coords(event, obj) {
	var pos = getAbsolutePosition(obj);
	x = event.pageX  - pos.x;
	y = event.pageY - pos.y;
	var r = { x: x, y: y };
	return r;
}

function getAbsolutePosition(element) {
	var r = { x: element.offsetLeft, y: element.offsetTop };
	if (element.offsetParent) {
	    var tmp = getAbsolutePosition(element.offsetParent);
	    r.x += tmp.x;
	    r.y += tmp.y;
	}
	return r;
};

var mousex = 0;
var mousey = 0;

document.onmousemove = getMouseXY

function getMouseXY(e) {
	try {
		if (!e) e = window.event;
		if (e) { 
		    if (e.pageX || e.pageY) {
				mousex = e.pageX;
				mousey = e.pageY;
				algor = '[e.pageX]';
				if (e.clientX || e.clientY) algor += ' [e.clientX] '
			}else if (e.clientX || e.clientY) {
				mousex = e.clientX+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);// + document.body.scrollLeft;
				mousey = e.clientY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);// + document.body.scrollTop;
				algor = '[e.clientX]';
				if (e.pageX || e.pageY) algor += ' [e.pageX] '
			}
		}
	}catch(ex) { }
}

function resizeHorbarSkins(id)
{
	h = $(id);
	
	if ($('track9'))
	{
		h.style.width = "875px";
	} else {
		h.style.width = "895px";
	}
}

function resizeHorbarEdit(type)
{
	h = $('horbarv');
	
	if (type == "v")
	{
		if ($('track11'))
		{
			h.style.width = "875px";
		} else {
			h.style.width = "895px";
		}
		$('horbartextv').innerHTML = "Reorder the videos by drag and drop";
		
	}
	if (type == "p")
	{
		if ($('track10'))
		{
			h.style.width = "875px";
		} else {
			h.style.width = "895px";
		}
		$('horbartextv').innerHTML = "Reorder the playlists by drag and drop";
	}
}

function showXClose(id) {
	$(id+'Lupa').style.display = 'none';
	$(id+'XClose').style.display = 'block';
}

function showLupa(id) {
	$(id+'XClose').style.display = 'none';
	$(id+'Lupa').style.display = 'block';
}

function dragbarHandler(nr, targetParam) {
	var handler = 'prog_bar_handler'+nr;
	var diff = 'proc_bar_diff'+nr;
	var bg = 'proc_bar_bg'+nr;
	
 	if ($(handler).offsetTop <= 3)
		$S(handler).top = '8px';
	else if ($(handler).offsetTop >= 74)
		$S(handler).top = '79px';
	
	var margin = 3;
	var percentage = ($(handler).offsetTop - margin) * 100 / 71;
	if (percentage < 0) { percentage = 100; $S(handler).top = '79px';}

	$S(diff).height = percentage + '%';
	$S(bg).height = (100 - percentage) + '%';
	
	var intAlpha = Math.round((100 - percentage));
	$(targetParam).value = intAlpha;

	eval('skinDetails.details.' + targetParam + ' = intAlpha');
	$('vp_holder').setParameter(targetParam, intAlpha);
}

function setDragValue(targetParam, value) {
	return;
	var handler = 'prog_bar_handler';
	var diff = 'proc_bar_diff';
	var bg = 'proc_bar_bg';
	
	$S(bg).height = value + '%';
	$S(diff).height = (100 - value) + '%';
	//$S(handler).top = (value * (71 / 100) + 3) + 'px';
}

/*********************************************************************
 * No onMouseOut event if the mouse pointer hovers a child element 
 * *** Please do not remove this header. ***
 * This code is working on my IE7, IE6, FireFox, Opera and Safari
 * 
 * Usage: 
 * <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
 *		So many childs 
 *	</div>
 *
 * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/
function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target) {
		eval(JavaScript_code);
	}
}
/*********************************************************************/


function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}

/*************** ToolTips **************/
function showToolTip(step,account) {
	if (step == 2 || step == 3) {
		if ($('vupload_parent').style.display == 'none') {
			shupload(0);
		}
	}
	try {
		$('tool'+(step+1)+account).style.display = 'none';
	}catch(e) { }
	try {
		$('tool'+(step-1)+account).style.display = 'none';
	}catch(e) { }
	$('tool'+step+account).style.display = 'block';
}

function addLicense() {
	if (!isURL2($('slicenceinp').value)) {
		showRedNotification('Please enter a valid URL', 1);
		return false;
	}
	var params = 'license='+$('slicenceinp').value+'&editid='+$('editid').value+'&aj=1';
	POST('/settings/license/', '', params);
	showNotification('License added',1);
}

function sortMouseOut(id) {
	window.sortTO = window.setTimeout("vidDropdown('"+id+"')","500");
}

function sortMouseIn() {
	window.clearTimeout(window.sortTO);
}

function embedMouseOut() {
	window.sortTO = window.setTimeout("$('ulEmbeddd').style.display='none'","500");
}

function embedMouseIn() {
	window.clearTimeout(window.sortTO);
}

function dummy() {
}

function demoPrompt() {
	window.perf = 1;
	window.performDemo = "createModal('In order to publish your players, you need to register an account.', 'createModal(); showRegister();', 'createModal();', 'Registration required')";
	savePlayer(0);
	//document.perform = "createModal('In order to publish your players, you need to register an account.', 'createModal(); window.location=\"/index/home#register\"', 'createModal();', 'Registration required')";
	
//	alert(document.perform);
//	setTimeout('eval(document.perform)', 1000);
}

function parsePlayersURL() {
	var hash = str_replace('#', '', window.location.hash);
	var id = parseInt(hash);
	
	if (id && getplayer(id)) {
		editPlayer(id);
	}	
}
