﻿var L_LAUNCHSAP_TEXT = "Launch stand-alone Windows Media Player";
var g_bNetscape = ( -1 != navigator.appName.indexOf( "Netscape" ) );
//---------------------
//Hien thi window media
//---------------------
function showPLayer(link)
{
	var height = 60;
	var e = link.split('.'); e = e[e.length-1];

	if( e == 'wmv' ) height =300;

	var WMP7;
	try
	{
		if ( navigator.appName != "Netscape" )
		{
			WMP7 = new ActiveXObject('WMPlayer.OCX');
		}
	}
	catch (error)
	{
		;
	}
	var HTML = '';

	// Windows Media Player 7 Code
	if ( WMP7 )
	{
	HTML +=  ('<OBJECT height="'+height+'" width="100%" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" VIEWASTEXT>');
	HTML +=  ('<PARAM NAME="URL" VALUE="'+link+'">');
	HTML +=  ('<PARAM NAME="rate" VALUE="1">');
	HTML +=  ('<PARAM NAME="balance" VALUE="0">');
	HTML +=  ('<PARAM NAME="currentPosition" VALUE="0">');
	HTML +=  ('<PARAM NAME="defaultFrame" VALUE="">');
	HTML +=  ('<PARAM NAME="playCount" VALUE="999">');
	HTML +=  ('<PARAM NAME="autoStart" VALUE="1">');
	HTML +=  ('<PARAM NAME="currentMarker" VALUE="0">');
	HTML +=  ('<PARAM NAME="invokeURLs" VALUE="-1">');
	HTML +=  ('<PARAM NAME="baseURL" VALUE="">');
	HTML +=  ('<PARAM NAME="mute" VALUE="0">');
	HTML +=  ('<PARAM NAME="uiMode" VALUE="full">');
	HTML +=  ('<PARAM NAME="stretchToFit" VALUE="0">');
	HTML +=  ('<PARAM NAME="windowlessVideo" VALUE="0">');
	HTML +=  ('<PARAM NAME="enabled" VALUE="-1">');
	HTML +=  ('<PARAM NAME="enableContextMenu" VALUE="0">');
	HTML +=  ('<PARAM NAME="fullScreen" VALUE="0">');
	HTML +=  ('<PARAM NAME="SAMIStyle" VALUE="">');
	HTML +=  ('<PARAM NAME="SAMILang" VALUE="">');
	HTML +=  ('<PARAM NAME="SAMIFilename" VALUE="">');
	HTML +=  ('<PARAM NAME="captioningID" VALUE="">');
	HTML +=  ('<PARAM NAME="Volume" VALUE="100">');
	HTML +=  ('</OBJECT>');
	}

	// Windows Media Player 6.4 Code
	else
	{
	HTML +=  ('<OBJECT  classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" ');
	HTML +=  ('codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" ');
	HTML +=  ('width="100%" height="'+height+'"');
	HTML +=  ('standby="Loading Microsoft Windows Media Player components..." ');
	HTML +=  ('type="application/x-oleobject" VIEWASTEXT> ');
	HTML +=  ('<PARAM NAME="FileName"           VALUE="'+link+'">');
	HTML +=  ('<PARAM NAME="TransparentAtStart" Value="false">');
	HTML +=  ('<PARAM NAME="AutoStart"          Value="true">');
	HTML +=  ('<PARAM NAME="AnimationatStart"   Value="false">');
	HTML +=  ('<PARAM NAME="ShowControls"       Value="false">');
	HTML +=  ('<PARAM NAME="ShowDisplay"	 value ="false">');
	HTML +=  ('<PARAM NAME="playCount" VALUE="999">');
	HTML +=  ('<PARAM NAME="displaySize" 	 Value="0">');
	HTML +=  ('<PARAM NAME="Volume" VALUE="100">');
	HTML +=  ('<Embed type="application/x-mplayer2" ');
	HTML +=  ('pluginspage= ');
	HTML +=  ('"http://www.microsoft.com/Windows/MediaPlayer/" ');
	HTML +=  ('src="'+link+'" ');
	HTML +=  ('Name=MediaPlayer ');
	HTML +=  ('transparentAtStart=0 ');
	HTML +=  ('autostart=1 ');
	HTML +=  ('playcount=999 ');
	HTML +=  ('volume=100');
	HTML +=  ('animationAtStart=0 ');
	HTML +=  ('width="100%" height="'+height+'"');	
	HTML +=  ('displaySize=0></embed> ');
	HTML +=  ('</OBJECT> ');
	}
	
	return HTML;
}
function showPLayerz(link)
{
	link = decodeTxt(link); //Giai ma duong link 
		
	var height = 60;
	var e = link.split('.'); e = e[e.length-1];

	if( e == 'wmv' ) height =300;

	var WMP7;
	try
	{
		if ( navigator.appName != "Netscape" )
		{
			WMP7 = new ActiveXObject('WMPlayer.OCX');
		}
	}
	catch (error)
	{
		;
	}
	var HTML = '';

	// Windows Media Player 7 Code
	if ( WMP7 )
	{
	HTML +=  ('<OBJECT id="Player" height="'+height+'" width="100%" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" VIEWASTEXT>');
	HTML +=  ('<PARAM NAME="URL" VALUE="'+link+'">');
	HTML +=  ('<PARAM NAME="rate" VALUE="1">');
	HTML +=  ('<PARAM NAME="balance" VALUE="0">');
	HTML +=  ('<PARAM NAME="currentPosition" VALUE="0">');
	HTML +=  ('<PARAM NAME="defaultFrame" VALUE="">');
	HTML +=  ('<PARAM NAME="playCount" VALUE="999">');
	HTML +=  ('<PARAM NAME="autoStart" VALUE="1">');
	HTML +=  ('<PARAM NAME="currentMarker" VALUE="0">');
	HTML +=  ('<PARAM NAME="invokeURLs" VALUE="-1">');
	HTML +=  ('<PARAM NAME="baseURL" VALUE="">');
	HTML +=  ('<PARAM NAME="mute" VALUE="0">');
	HTML +=  ('<PARAM NAME="uiMode" VALUE="full">');
	HTML +=  ('<PARAM NAME="stretchToFit" VALUE="0">');
	HTML +=  ('<PARAM NAME="windowlessVideo" VALUE="0">');
	HTML +=  ('<PARAM NAME="enabled" VALUE="-1">');
	HTML +=  ('<PARAM NAME="enableContextMenu" VALUE="0">');
	HTML +=  ('<PARAM NAME="fullScreen" VALUE="0">');
	HTML +=  ('<PARAM NAME="SAMIStyle" VALUE="">');
	HTML +=  ('<PARAM NAME="SAMILang" VALUE="">');
	HTML +=  ('<PARAM NAME="SAMIFilename" VALUE="">');
	HTML +=  ('<PARAM NAME="captioningID" VALUE="">');
	HTML +=  ('<PARAM NAME="Volume" VALUE="100">');
	HTML +=  ('</OBJECT>');
	}

	// Windows Media Player 6.4 Code
	else
	{
	HTML +=  ('<OBJECT ID="Player"  classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" ');
	HTML +=  ('codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" ');
	HTML +=  ('width="100%" height="'+height+'"');
	HTML +=  ('standby="Loading Microsoft Windows Media Player components..." ');
	HTML +=  ('type="application/x-oleobject" VIEWASTEXT> ');
	HTML +=  ('<PARAM NAME="FileName"           VALUE="'+link+'">');
	HTML +=  ('<PARAM NAME="TransparentAtStart" Value="false">');
	HTML +=  ('<PARAM NAME="AutoStart"          Value="true">');
	HTML +=  ('<PARAM NAME="AnimationatStart"   Value="false">');
	HTML +=  ('<PARAM NAME="ShowControls"       Value="false">');
	HTML +=  ('<PARAM NAME="ShowDisplay"	 value ="false">');
	HTML +=  ('<PARAM NAME="playCount" VALUE="999">');
	HTML +=  ('<PARAM NAME="displaySize" 	 Value="0">');
	HTML +=  ('<PARAM NAME="Volume" VALUE="100">');
	HTML +=  ('<Embed type="application/x-mplayer2" ');
	HTML +=  ('pluginspage= ');
	HTML +=  ('"http://www.microsoft.com/Windows/MediaPlayer/" ');
	HTML +=  ('src="'+link+'" ');
	HTML +=  ('Name=MediaPlayer ');
	HTML +=  ('transparentAtStart=0 ');
	HTML +=  ('autostart=1 ');
	HTML +=  ('playcount=999 ');
	HTML +=  ('volume=100');
	HTML +=  ('animationAtStart=0 ');
	HTML +=  ('width="100%" height="'+height+'"');	
	HTML +=  ('displaySize=0></embed> ');
	HTML +=  ('</OBJECT> ');
	}
	
	return HTML;
}


//------------- FROM VnExpress ------------------------------
// ap dung search
function UnicodeSet(iStr)
{
	for (i=0, oStr=''; i < iStr.length; i++)
	{
		switch ((j=iStr.charCodeAt(i)))
		{
		case 34:
			oStr=oStr.concat('&quot;');
			break;
		case 38:
			oStr=oStr.concat('&amp;');
			break;
		case 39:
			oStr = oStr.concat('&#39;');
			break;
		case 60:
			oStr = oStr.concat('&lt;');
			break;
		case 62:
			oStr = oStr.concat('&gt;');
			break;
		default:
			if (j < 32 || j > 127 || j==34 || j==39)
			{
				oStr=oStr.concat('&#').concat(j).concat(';');
			}
			else
			{
				oStr=oStr.concat(iStr.charAt(i)); 
			}
			break;
		}
	}
	
	return oStr;
}
function UnicodeGet(iStr)
{
	for (i=0, oStr=''; i < iStr.length; )
	{
		if (iStr.charCodeAt(i)==38)
		{
			if (iStr.charCodeAt(i + 1)==35)
			{
				p=iStr.indexOf(';', i  + 2);
				if (p!=-1)
				{
					if (p - i <= 7)
					{
						if (isFinite(iStr.substr(i + 2, p - i - 2)))
						{
							oStr = oStr.concat(String.fromCharCode(iStr.substr(i + 2, p - i - 2)));
							i = p + 1;
							continue;
						}
					}
				}
			}
			else
			{
				p=iStr.indexOf(';', i  + 1);
				if (p!=-1)
				{
					switch (iStr.substr(i + 1, p - i - 1))
					{
					case 'amp':
						oStr = oStr.concat('&');
						i = p + 1;
						break;
					case 'quot':
						oStr = oStr.concat('"');
						i = p + 1;
						break;
					case 'lt':
						oStr = oStr.concat('<');
						i = p + 1;
						break;
					case 'gt':
						oStr = oStr.concat('>');
						i = p + 1;
						break;
					}
				}
			}
		}
	
	
		oStr=oStr.concat(iStr.charAt(i));
		i++;
	}
	
	return oStr;
}

function SearchMusic() {

	strSearch = document.getElementById('keyword').value;
	strSearch = UnicodeGet(strSearch);		
	
	while (strSearch.length > 0 && strSearch.charAt(0) <= ' ')
	{
		strSearch = strSearch.substr(1);
	}

	while ((i=strSearch.length) > 0 && strSearch.charAt(i - 1) <= ' ')
	{
		strSearch = strSearch.substr(0, i - 1);
	}
	
	strSearch = UnicodeSet(strSearch);	

	if (strSearch != "") {
		var Ltype = 2 ;
		if (Ltype ==2 ) {
			document.location.href="/webmedia/music/listsongs.aspx?Str=" + strSearch;
			return false;
		}
	}
}

function SearchMedia(returnPage) 
{

	strSearch = document.getElementById('keyword').value;
	strSearch = UnicodeGet(strSearch);		
	while (strSearch.length > 0 && strSearch.charAt(0) <= ' ')
	{
		strSearch = strSearch.substr(1);
	}

	while ((i=strSearch.length) > 0 && strSearch.charAt(i - 1) <= ' ')
	{
		strSearch = strSearch.substr(0, i - 1);
	}
	
	strSearch = UnicodeSet(strSearch);	

	if (strSearch != "") {
			document.location.href=returnPage + "?Str=" + strSearch;
			return false;
	}
}

//--- decode ---
var encN=3;

// DECODES AND UNESCAPES ALL TEXT.
function decodeTxt(s){
	var s1=unescape(s.substr(0,s.length-1));
	var t='';
	for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1));
	return unescape(t);
}

// SIMPLY UNESCAPES TEXT (ONLY INCLUDED TO MAKE A COMPLEMENTARY FUNCTION FOR escapeTxt()
function unescapeTxt(s){
return unescape(s);
}

//--------------
function findObj(id)
{
	return document.getElementById(id);
}

function GuiTang(id)
{
	if(findObj(id).style.display != 'block')
	{
		findObj(id).style.display = 'block';
	}
	else 
	{
		findObj(id).style.display = 'none';
	}
}

//---------------------------------------------------------------------------------------------------------------
// PLAYLIST
//---------------------------------------------------------------------------------------------------------------
	var split_1	= '|'; //-- Ngăn cách giữa các cặp giá trị tạo nên một bài hát
	var split_2	= '~'; //-- Ngăn cách giữa tên bài hát và ID bài hát
	var playlistWindow = null;

	/*------------------------------------------------------\
	|	Add song to playlist								|
	|	Code by mrdotcom@gmail.com							|
	\------------------------------------------------------*/
	var playlistRowHeight = 20;
	function playlistAdd(song_id, song_name)
	{
		//-- Srote via cookie
		//
		c = __cookie.getSubValue(c_name);

		if(!c) c = "";
		else
		{
			//-- Kiem tra xem bai hat nay da co trong playlist chua
			//
			cc = c.split(split_1);

			for(i = 0; i < cc.length; i++)
			{
				if(cc[i])
				{
					s = cc[i].split(split_2);
					if( s[0] == song_id )
					{
						alert('Bài này đã có trong playlist rồi');
						return false;
					}
				}
			}
		}
		
		c = c + split_1 + song_id + split_2 + song_name;
		__cookie.setSubValue(c_name, c);
		var pl = findObj('playlist');
		
		alert('Bài hát '+song_name+' đã được thêm vào danh sách nhạc phẩm của bạn');
	}

	/*------------------------------------------------------\
	|	Hide playlist window								|
	|	Code by mrdotcom@gmail.com							|
	\------------------------------------------------------*/
	function playlistHide()
	{
		dd.elements.playlistTitle.hide(); 
		__cookie.setSubValue('__playlistOn', null);	
	}

	/*------------------------------------------------------\
	|	Show playlist window								|
	|	Code by mrdotcom@gmail.com							|
	\------------------------------------------------------*/
	
	var win=null;
	function NewWindow(mypage,myname,w,h,scroll,pos)
	{
		if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
		if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
		settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
		
		return window.open(mypage,myname,settings);
	}
	
	function showPlaylist()
	{
		c = __cookie.getSubValue(c_name);
		if(c)
		{
			win = NewWindow('/webmedia/Include/playlist.htm','mywin','238','400','yes','center');
			win.focus();
		}
		else
		{
			alert("Trong danh sách của bạn hiện chưa có nhạc phẩm nào cả.");
		}
	}
			
	/*------------------------------------------------------\
	|	Empty playlist										|
	|	Code by mrdotcom@gmail.com							|
	\------------------------------------------------------*/
	function emptyPlaylist()
	{
		if( confirm('Bạn có chắc chắn muốn xoá không?') )
		{
			__cookie.setSubValue(c_name, null);
			alert('Danh sách các bài hát trong playlist đã được xoá toàn bộ!');
		}
	}
	
	/*------------------------------------------------------\
	|														|
	\------------------------------------------------------*/
	var ok = 1; var dragTrue;
	function playlistDragMe(id)
	{
		var x1=dd.elements.playlist.x, y1=dd.elements.playlist.y, x2=x1+dd.elements.playlist.w, y2=y1+dd.elements.playlist.h;

		var x = event.clientX;
		var y = event.clientY;

		var item = document.getElementById(id);
		var dragBox = document.getElementById('dragBox');
		var playlist = document.getElementById('playlist');
				
		dragBox.innerHTML = item.innerHTML;
		
		dragBox.style.filter = "Alpha(opacity=90)";
		dragBox.style.top = y + 'px';
		dragBox.style.left = x + 'px';
		
		if( (x>=x1) && (x<=x2) && (y>=y1) && (y<=y2) )
		{
			dragTrue = 1;
			if(ok)
			{
				playlist.saveHTML = playlist.innerHTML;
				playlist.innerHTML = '<div style="background-color: yellow; font-weight: normal; font-size: 11px; padding: 2px">' + item.innerHTML + '</div>' + playlist.innerHTML;
				ok = 0;
			}
		}
		else
		{
			dragTrue = 0;
			if(!ok) playlist.innerHTML = playlist.saveHTML;
			ok = 1;
		}
		
		// window.status = "x="+x+"; y="+y+"; x1="+x1+"; y1 = "+y1+"; x2="+x2+"; y2="+y2;
	}
	
	function playlistDropMe(id, title)
	{
		var dragBox = document.getElementById('dragBox');
		var playlist = document.getElementById('playlist');
		
		if(playlist.saveHTML) playlist.innerHTML = playlist.saveHTML;
		dragBox.style.left = '-1000px';		
		if(dragTrue) playlistAdd(id, title);
	}
