﻿var caution = false
//---------------------------------------------------------------------------------------------------------------
function setCookie(name, value, expires, path, domain, secure)
{
	var now = new Date();
	now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "; expires=" + now.toGMTString()) +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "")
	if (!caution || (name + "=" + escape(value)).length <= 4000)
	document.cookie = curCookie
	else
	if (confirm("Cookie exceeds 4KB and will be cut!"))
	document.cookie = curCookie
}
//---------------------------------------------------------------------------------------------------------------
function getCookie(name)
{
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
	return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
	cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
//---------------------------------------------------------------------------------------------------------------
function deleteCookie(name, path, domain)
{
	if (getCookie(name)) {
	document.cookie = name + "=" + 
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	"; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}
//---------------------------------------------------------------------------------------------------------------
var c_name	= "FCMedia";
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							|
\------------------------------------------------------*/
function addToPlaylist(song_id, song_name)
{
	//-- Srote via cookie
	//
	c = getCookie(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;
	
	setCookie(c_name, c);
	
	alert("Bài hát " + song_name + " Đã được thêm vào playlist");
}


/*------------------------------------------------------\
|	remove song from playlist							|
|	Code by mrdotcom@gmail.com							|
\------------------------------------------------------*/
function removeFromPlaylist(song_id)
{
	c = getCookie(c_name); var nc = '';
	
	if(!c) return false;
	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 )
				{
					nc = nc + split_1 + s[0] + split_2 + s[1];
				}
			}
		}
	
		setCookie(c_name, nc);
		
		self.location = self.location;
	}	
}

/*------------------------------------------------------\
|							|
|							|
\------------------------------------------------------*/
function showPlaylist()
{
	var c = ""; var up = ""; var s = "";
	
	c = getCookie(c_name);
	// alert(c); return false;
	if(c)
	{
		playlistWindow = window.open('playlist.asp',"","top=50,left=200,width=,height=,scrollbars"); playlistWindow.resizeTo(270,400); playlistWindow.focus();
	}
	else
	{
		alert('PLaylist đang rỗng, chưa có bài hát nào cả!');
	}
}
/*------------------------------------------------------\
|							|
|							|
\------------------------------------------------------*/
function emptyPlaylist()
{
	if( confirm('Bạn có chắc chắn muốn xoá không?') )
	{
		deleteCookie(c_name);
		alert('Danh sách các bài hát trong playlist đã được xoá toàn bộ!');
	}
}
function setStatusText(strStatus) {
    document.getElementById("statusText").innerHTML = "<b>&nbsp;" + strStatus; + "</b>"
    window.parent.status = ""
    return true
}

	function linkMenuSetup() {
		var links, i;
		
		links = document.all.item("linkMenuItem");
		
		for(i=0; i<links.length; i++) {
			links[i].attachEvent("onclick", linkClick);
			links[i].attachEvent("onmouseenter", linkMouseOver);
			links[i].attachEvent("onmouseleave", linkMouseOut);
			links[i].attachEvent("onmousedown", linkMouseDown);
			links[i].attachEvent("onmouseup", linkMouseUp);
		}
	}

	function linkMouseOver() {
		var td = getEventSource();
		td.className = "linkMenuItem MouseOver";

		var a = td.all.tags("A");
		if (a.length > 0)
			window.status = a[0].href;
	}

	function linkMouseOut() {
		var td = getEventSource();
		td.className = "linkMenuItem";
		
		window.status = "";
	}
	
	function linkMouseDown() {
		var td = getEventSource();
		td.className = "linkMenuItem MouseDown";
	}

	function linkMouseUp() {
		var td = getEventSource();
		td.className = "linkMenuItem MouseOver";
	}

	function linkClick() {
		var td = getEventSource();
		var a = td.all.tags("A");
		if (a.length > 0) a[0].click();
	}

	function getEventSource() {
		var e = event.srcElement;
		while (e.tagName != "TD")
			e = e.parentElement;
		return e;
	}
/**********************************************/
function findObj(id)
{
	return document.getElementById(id);
}
function showPLayer(link){
	link=links(link)

	var height = 62;

	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> ');
	}
	
	setTimeout('change_adsl()', 3000);
	return '<div style="background: #000" align="center"><table><tr><td><div id="adsl"><a href="index.asp" target="_blank"><img src="upload/adver/banner04.gif" border="0" width="360" height="36"></a></div></td></tr></table>' + HTML + '</div>';
	
	//var rn=Math.floor(Math.random()*2)
	//if(rn) 	return '<div style="background: #000" align="center"><img vspace="3" border="0" src="upload/adver/banner04.gif" style="cursor: pointer" onclick="if(confirm(\'Bạn muốn trở về trang chủ\')) self.location=\'index.asp\'"><br>' + HTML + '</div>';
	//else 	return '<div style="background: #000" align="center"><img vspace="3" border="0" src="upload/adver/banner03.gif" style="cursor: pointer" onclick="self.location=\'http://www.freecodevn.com\'"><br>' + HTML + '</div>';
}
function showPhim(link){
	link=links(link)

	var height = 250;

	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> ');
	}

	setTimeout('change_adsl()', 3000);
	return '<div style="background: #000" align="center"><table><tr><td><div id="adsl"><a href="index.asp" target="_blank"><img src="upload/adver/banner04.gif" border="0" width="360" height="36"></a></div></td></tr></table>' + HTML + '</div>';
	
	//var rn=Math.floor(Math.random()*2)
	//if(rn) 	return '<div style="background: #000" align="center"><img vspace="3" border="0" src="upload/adver/banner04.gif" style="cursor: pointer" onclick="if(confirm(\'Bạn muốn trở về trang chủ\')) self.location=\'index.asp\'"><br>' + HTML + '</div>';
	//else 	return '<div style="background: #000" align="center"><img vspace="3" border="0" src="upload/adver/banner03.gif" style="cursor: pointer" onclick="self.location=\'http://www.freecodevn.com\'"><br>' + HTML + '</div>';
}
var adsl_no = 0;
function change_adsl()
{
	adsl_no++;
	if(adsl_no>2) adsl_no = 0;
	
	if(adsl_no == 0) findObj('adsl').innerHTML = '<div id="adsl"><a href="http://www.kythuatvien.com" target="_blank"><img src="upload/adver/banner01.gif" border="0" width="360" height="36"></a></div>';
	if(adsl_no == 1) findObj('adsl').innerHTML = '<div id="adsl"><a href="http://www.nhactructuyen.com" target="_blank"><img src="upload/adver/banner02.gif" border="0" width="360" height="36"></a></div>';
	if(adsl_no == 2) findObj('adsl').innerHTML = '<div id="adsl"><a href="http://www.freecodevn.com" target="_blank"><img src="upload/adver/banner03.gif" border="0" width="360" height="36"></a></div>';
	
	setTimeout('change_adsl()', 3000);
}

function ShowListenInNewWindow(id)
{
	ListenInNewWindow = window.open('smallwin.asp',"","top=200,left=200,width=,height="); ListenInNewWindow.resizeTo(370,160); 
	ListenInNewWindow.focus();
}
function ShowListenInNewWindowwmv(id)
{
	ListenInNewWindowwmv = window.open('smallwin.asp',"","top=200,left=200,width=,height="); ListenInNewWindowwmv.resizeTo(370,400); 
	ListenInNewWindowwmv.focus();
}
function Register() {
	window.location = "register.asp";
}
function Help() {
	window.location = "help.asp";

}
function PrivateAlbum() {
	window.location = "private_album.asp";

}
function GetPass() {
	window.location = "help.asp";

}
function Feedback() {
	window.location = "help.asp";

}
function AddSong(id) {
	window.location.frmSend = ('register.asp?id='+id+'');
}
