function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getUserProfile(userId) {
	document.getElementById('profileUserId').value = userId;
	var wLeft = (screen.width - 330) / 2;
	var wTop = (screen.height - 115) / 2;
	_pWin = window.open('','profileWin','menubar=0,resizable=0,width=330,height=115,status=0,toolbar=0,location=0,left=' + wLeft + ',top=' + wTop);
	if(typeof(focus)=="function")
		_pWin.focus();
	document.userProfileForm.submit();
}

function copyToClipboard(sCopyText)
{
	if (window.clipboardData)
	{
		window.clipboardData.setData("Text", sCopyText);
	}
	else if (window.netscape)
	{
		try
		{
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		}
		catch (e)
		{
			alert("Your current Internet Security settings do not allow data copying to clipboard");
			return ;
		}
		

		var clip = Components.classes['@mozilla.org/widget/clipboard;1']
		.createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		var trans = Components.classes['@mozilla.org/widget/transferable;1']
		.createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		trans.addDataFlavor('text/unicode');

		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"]
		.createInstance(Components.interfaces.nsISupportsString);
		var copytext=sCopyText;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return ;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	alert("Copied to clipboard");
	//return false;
}
function copyToEmbedTag(mediaId, mediaTitle, embedTagPath)
{
	//alert("mediaId:::"+mediaId);
	//alert(" mediaTitle:::"+mediaTitle);
	//alert("EmbedTadPath:::"+embedTagPath)
	var embedTagPath="http://"+embedTagPath;
	var one="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\"EmbedVideoPlayer\" width=\"380\" height=\"311\" codebase=\"http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab\">\n";
	var two= "<param name=\"movie\" value=\""+embedTagPath+"EmbedVideoPlayer.swf?mediaId="+mediaId+"&mediaTitle="+mediaTitle+"\" />\n	<param name=\"quality\" value=\"high\" />\n	<param name=\"bgcolor\" value=\"#869ca7\" />\n<param name=\"allowfullscreen\" value=\"true\"/>\n<param name=\"allowscriptaccess\" value=\"always\" />\n <param name=\"FlashVars\" value=\"mediaId="+mediaId+"&mediaTitle="+mediaTitle+"\">";
	var three= "<embed src=\""+embedTagPath+"EmbedVideoPlayer.swf?mediaId="+mediaId+"&mediaTitle="+mediaTitle+"\" quality=\"high\" bgcolor=\"#869ca7\" width=\"380\" height=\"311\" name=\"EmbedVideoPlayer\" align=\"middle\" play=\"true\" loop=\"false\" quality=\"high\" ";
	var four= "allowscriptaccess=\"always\" allowfullscreen =\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\">\n</embed>\n</object>";
	var copyEmbed=one+two+three+four;
	if (window.clipboardData)
	{
		window.clipboardData.setData("Text", copyEmbed);
	}
	else if (window.netscape)
	{
		try
		{
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		}
		catch (e)
		{
			alert("Your current Internet Security settings do not allow data copying to clipboard");
			return ;
		}
		

		var clip = Components.classes['@mozilla.org/widget/clipboard;1']
		.createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		var trans = Components.classes['@mozilla.org/widget/transferable;1']
		.createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		trans.addDataFlavor('text/unicode');

		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"]
		.createInstance(Components.interfaces.nsISupportsString);
		var copytext=copyEmbed;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return ;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	alert("Copied to clipboard");
	//return false;
}


function exploreByCategory(catId) {
	//$("#mediaCategory").val(catId);
	document.getElementById('mediaCategory').value=catId;
	
	if(document.getElementById('exploreForm') == null) {
		document.exploreFilterForm.submit();
	}
	else {
		$("#browseBy").val('all');
		$("#mediaLanguage").val('');
		document.getElementById('mediaTags').value = '';
		document.exploreForm.submit();
	}
}

function previewMedia(mPath, mTitle) {
	document.getElementById('previewMediaPath').value = mPath;
	document.getElementById('previewMediaTitle').value = mTitle;
	var wLeft = (screen.width - 340) / 2;
	var wTop = (screen.height - 310) / 2;	
	_win = window.open('','previewWin','menubar=0,resizable=0,width=340,height=310,status=0,toolbar=0,location=0,left=' + wLeft + ',top=' + wTop);
	if(typeof(focus)=="function")
		_win.focus();
	document.previewMediaForm.submit();
}

String.prototype.trim = function () {
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function signIn() {
	var loc = document.location.href;
	var index = loc.lastIndexOf('/');
	$('#returnURL').val(loc.substring(index));
	document.signInForm.submit();
}

function addToFavorites(mediaId) {
	UserAJAXController.addToFavorites(userVO, mediaId, function (data) {
		if (data.success) {
			alert("Added successfully to Favorites.");
		}
		else {
			alert("Add to Favorites failed.");
		}
	});
}
function openMedia(mediaId, showMS, showTR) {
	$("#openMediaId").val(mediaId);
	$("#openShowTranscript").val(showTR);
	$("#openShowMultiSync").val(showMS);
	document.openMediaForm.submit();
}

