﻿var imgServer = 'http://static.mp3.zing.vn/';
var domain_name = 'http://mp3.zing.vn/';

String.prototype.trim = function() { //Trim ambas direcciones
   return this.replace(/^[ ]+|[ ]+$/g,"");
}

String.prototype.tripSpace = function() { //Trim ambas direcciones
   return this.replace(/(\s\s+)/g, " ");
	 //replace(/^[ ]+|[ ]+$/g,"");
}

String.prototype.stripViet = function()
{
	var replaceChr = String.prototype.stripViet.arguments[0];
	var stripped_str = this;
	var viet = [];
	i = 0;
	viet[i++] = new Array('a', "/á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ/g");
	viet[i++] = new Array('o', "/ó|ò|ỏ|õ|ọ|ơ|ớ|ờ|ở|ỡ|ợ|ô|ố|ồ|ổ|ỗ|ộ/g");
	viet[i++] = new Array('e', "/é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ/g");
	viet[i++] = new Array('u', "/ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự/g");
	viet[i++] = new Array('i', "/í|ì|ỉ|ĩ|ị/g");
	viet[i++] = new Array('y', "/ý|ỳ|ỷ|ỹ|ỵ/g");
	viet[i++] = new Array('d', "/đ/g");
	for(var i = 0; i < viet.length; i++) {
		stripped_str = stripped_str.replace(eval(viet[i][1]), viet[i][0]);
		stripped_str = stripped_str.replace(eval(viet[i][1].toUpperCase().replace('G', 'g')), viet[i][0].toUpperCase());
	}
	if (replaceChr) {
		return stripped_str.replace(/[\W]|_/g, replaceChr).replace(/\s/g, replaceChr).replace(/^\-+|\-+$/g, replaceChr);
	} else {
		return stripped_str;
	}
};

//Kiem tra ki tu dac biet
function existsSpecialChars(str)
{
		//var re = /^[0-9a-zA-Z ]*$/;
		/*
		var re = /([!@#$%^&*]$/;
		str = str.trim();
		var pos = str.search(re);
		if(pos == -1)
			return false;
		else
			return true;
		*/
}	

//Kiem tra URL
function isURL(str) {
	var pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.0123456789/~:";
	if (str.length > 0) {
		if (str.length < 5 ) {
			return false;
		} else {
			if (str.lastIndexOf(".") == -1) { 											// khong tim thay dau cham
				return false;
			} else {
				if (str.lastIndexOf(".") == (str.length - 1)) return false;				// dau cham nam o cuoi cung
//				if (!isAlpha(str.charCodeAt(str.lastIndexOf(".") + 1))) return false;	// sau dau cham khong phai ki tu Alphabet
			}
			for (var c=0; c<pattern.length; c++) {
				if (pattern.indexOf(str.charAt(c),0) == -1) return false;				// ki tu khong hop le
			}
		}
	}
	return true;	
}
//Kiem tra email
function isEmailAddr(email) {
	var pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.0123456789@~";
	var theStr = new String(email)
	var index = theStr.indexOf("@");

	for (var a=0; a<pattern.length; a++) {
		if (pattern.indexOf(email.charAt(a),0) == -1) return false;
	}
	if (theStr.indexOf(" ",0) != -1) return false;
	if (index > 0) {
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1)) return true;
	}
	return false;
}


//Open popup
function openWindow(filename, winname, width, height, feature) {	
	var features, top, left;
	var reOpera = /opera/i ;
	var winnameRequired = ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) || reOpera.test(navigator.userAgent));
	
	left = (window.screen.width - width) / 2;
	top = (window.screen.height - height) / 2;	
	if(feature == '')
		features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",status=0,location=0";
	else
		features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "," + feature;
//	if(! winnameRequired)	winname = "";
	newwindow = window.open(filename, winname, features);
	newwindow.focus();
}
//
//Cookie
function GetCookie(sName)
{
  // cookies are separated by semicolons
 var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function Search(keyword, type)
{    
	window.opener.location = "/mp3/search/do.html?t=" + type + "&q=" + encodeURIComponent(keyword);
	window.opener.focus();
}

function PopUpSong(songInfo, obj)
{
	if (!songInfo) {
		return true;
	}
	var arrSong = songInfo.split('||');
	if (arrSong.length == 2) {
		if (window.ActiveXObject) {
			openWindow('helplive.htm', 'popupsong', 475, 400, '');
		} else {
			openWindow('helplive.htm', 'popupsong', 475, 400, '');
		}
		if (obj) {
			obj.name = 'zing';
			obj.href = location.href.replace('#' + obj.name, '') + '#' + obj.name;
		} else {
			return false;
		}
	}
	return false;
}

function cut(text) {
	if(text.length > 28) {
		txt = text.substr(0,14) + '...' + text.substr(text.length-12,12);
		document.write(txt);
	} else {
		document.write(text);
	}
}

function cut_1(text) {
	if(text.length > 36) {
		txt = text.substr(0,17) + '...' + text.substr(text.length-16,16);
		document.write(txt);
	} else {
		document.write(text);
	}
}

function cut_2(text) {
	if(text.length > 33) {
		txt = text.substr(0,16) + '...' + text.substr(text.length-14,14);
		document.write(txt);
	} else {
		document.write(text);
	}
}

function sndReq_4() {
	alert("Đăng nhập để add bài hát vào album của mình!");
	$('frmLogin').AccountName.focus();
}

//Add song to playlist
function AddPlaylist(id)
{
	openWindow('/add/?sid=' + id, 'Add', 575, 240, 'scrollbars=0');
}

//Add song to playlist
function AddPlaylist_1(id)
{
	openWindow('/add/?sid=cooki', 'Add', 575, 240, 'scrollbars=0');
}

//Add song to cookie
function AddCookiePlaylist(id)
{
	AddCookiePlaylist_1(id);
	/*var cooki, arr_cookie = new Array();
//	if(confirm("Đăng nhập để add bài hát vào playlist của mình!\nChọn OK để đăng nhập vào hệ thống?\nNếu chọn Cancel thì bài hát sẽ được add vào Cookie Playlist."))
//	{
//		document.frmReferer.action = '/mp3/login/index.html';
//		document.frmReferer.submit();
//			window.opener.location = '/mp3/login/index.html';
//			window.opener.focus();
//	}
//	else
//	{
		cooki = GetCookie('PlaylistCookies');
		if(cooki != null)
		{
			arr_cookie = cooki.split(",");
			if(arr_cookie.length > 0)
				for(var i = 0; i < arr_cookie.length; i++)
				{
					if(arr_cookie[i] == id)
					{
						alert('Bài hát này đã tồn tại trong cookie playlist!');
						return;
					}
				}
			document.cookie = 'PlaylistCookies=' + cooki + ',' + id + ';expires=Fri, 30-Jun-2017 08:00:00 ;path=/';
		}
		else
			document.cookie = 'PlaylistCookies=' + id + ';expires=Fri, 30-Jun-2017 08:00:00 ;path=/';
		alert("Bài hát này đã được lưu vào album tạm.");
//	}*/
}

//Add song to cookie
function AddCookiePlaylist_1(info)
{
	var cooki, arr_cookie = new Array();	
	var splitInfo =  info.split("|");
	
	id = splitInfo[0];
	cooki = GetCookie('PlaylistCookies');
	if(cooki != null)
	{
		arr_cookie = cooki.split(",");
		if(arr_cookie.length > 0)
			for(var i = 0; i < arr_cookie.length; i++)
			{
				arr_cookieInfo = arr_cookie[i].split("|");
				if(arr_cookieInfo[0] == id)
				{
					alert('Bài hát này đã tồn tại trong album tạm!');
					return;
				}
			}
		document.cookie = 'PlaylistCookies=' + cooki + ',' + info + ';expires=Fri, 30-Jun-2017 08:00:00 ;path=/';				
	}
	else{
		document.cookie = 'PlaylistCookies=' + info + ';expires=Fri, 30-Jun-2017 08:00:00 ;path=/';
	}
	
	alert("Bài hát này đã được lưu vào album tạm.");
	
	//// khuc nay refesh lai cai block ne ^^.
	var url  = '/mp3/cookie/add.html';
	var myAjax 	= new Ajax.Request
	(
		url, 
		{
			method		: "get",
			parameters	: '',
			onComplete	: responsePlaylistCookies
		}
	)
}

function responsePlaylistCookies(originalRequest)
{
	var responseText = originalRequest.responseText;
	
	if(responseText){
		if(window.opener)
			window.opener.$('block_cooki_album').innerHTML = responseText;
		else
			$('block_cooki_album').innerHTML = responseText;
	}
}

//Remove song from cookie playlist
function RemoveCookieSong(id)
{
	var cooki, arr_cookie = new Array();
	if(confirm("Bạn muốn xóa bài hát này khỏi album tạm?"))
	{
		cooki = GetCookie('PlaylistCookies');
		if(cooki != null)
		{
			arr_cookie = cooki.split(",");
			if(arr_cookie.length > 0)
				for(var i = 0; i < arr_cookie.length; i++)
				{
					arr_cookieInfo = arr_cookie[i].split("|");
					if(arr_cookieInfo[0] == id)
						delete arr_cookie[i];
				}
			arr_cookie.sort();
			cooki = arr_cookie.join(",");
			cooki = cooki.substr(0, cooki.length - 1);
			document.cookie = 'PlaylistCookies=' + cooki + ';expires=Fri, 30-Jun-2017 08:00:00 ;path=/';
		}	
		
		cooki = GetCookie('PlaylistCookies');
		if(cooki == 'undefined' || !cooki){
			top.$('block_cooki_album').innerHTML = '';
			return false;
		}
		return true;
	}
	else return false;
}
//Remove song from cookie playlist
function RemoveCookiePlaylist()
{
	var cooki, arr_cookie = new Array();
	if(confirm("Bạn muốn xóa album tạm?"))
	{
		cooki = GetCookie('PlaylistCookies');
		if(cooki != null)
		{
			document.cookie = 'PlaylistCookies=;expires=Fri, 30-Jun-2007 08:00:00 ;path=/';
			location.href = '/';
		}
		return true;
	}
	else return false;
}
//Remove song from cookie playlist
function RemoveCookiePlaylist_1()
{
	var cooki, arr_cookie = new Array();
	cooki = GetCookie('PlaylistCookies');
	if(cooki != null)
	{
		document.cookie = 'PlaylistCookies=;expires=Fri, 30-Jun-2007 08:00:00 ;path=/';
		location.href = '/';
	}
	return true;
}
//Remove song from cookie playlist
function RemoveSong()
{
	if(confirm("Bạn muốn xóa bài hát này khỏi album trong khi nghe?"))
	{
		return true;
	}
	else return false;
}
//Show 
function showFullList(object)
{
	object.style.overflow = 'auto';
	object.style.borderColor = '#EEEEEE';
	object.style.backgroundColor = '#EEEEEE';
}

function hideFullList(object)
{
	object.style.overflow = 'hidden';
	object.style.borderColor = '#FFFFFF';
	object.style.backgroundColor = '#FFFFFF';
	object.scrollTop = '0px';
}

//play media
function play()
{
	document.getElementById('wPlayer').controls.play();
}

//playlist media
function playlist(id, txt_search, txt_replace, player)
{
	document.getElementById(id).innerHTML = player.replace(txt_search, txt_replace);
	if(document.getElementById('wPlayer').controls) {
		window.setTimeout('play()', 1);
	}
}

function remove(href)
{
	if(confirm('Bạn thực sự muốn xóa?'))
	{
		window.location = href;
	}
	else return;
}

function checkDeletePlaylist(action){
	if(confirm('Bạn có thực sự muốn xóa?')) {
		document.frmReferer.action = action;
		document.frmReferer.submit();
	} 
	else return;
}


/*********************************************
* Search result page
**********************************************/
//clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6
//clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95
var searchPlayer = '<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http:/activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" width="320" height="62">';
searchPlayer += '<param name="URL" value="songid"><param name="playCount" value="1"><param name="autoStart" value="true"><param name="volume" value="75"><param name="enabled" value="1"><param name="enableContextMenu" value="0"><param name="showstatusbar" value="true"><param name="enableErrorDialogs" value="0"><param name="autorewind" value="1"><param name="ShowTracker" value="false"><param name="ShowPositionControls" value="false"><param name="ShowControls" value="true">';
// searchPlayer += '<embed width="320" height="65" showtracker="1" showstatusbar="1" showpositioncontrols="1" showgotobar="0" showdisplay="0" showaudiocontrols="1" showcontrols="1" playcount="1" mute="0" enabletracker="1" enablefullscreencontrols="1" enablecontextmenu="0" displaysize="1" autostart="1" autosize="1" name="Player" src="songid" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" type="application/x-mplayer2" />';
searchPlayer += '<embed type="application/x-mplayer2" showtracker=1 showpositioncontrols=1 enableErrorDialogs="0" autostart="1" pluginspage="http:/activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" showstatusbar="1" showcontrols="1" enablecontextmenu="0" autorewind="1" volume="75" src="songid" name="Player" width="320" height="65" />';
searchPlayer += '</object>';

var searchPlayerVideo = '<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http:/activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" width="320" height="260">';
searchPlayerVideo += '<param name="URL" value="songid"><param name="playCount" value="1"><param name="autoStart" value="true"><param name="volume" value="75"><param name="enabled" value="1"><param name="enableContextMenu" value="0"><param name="showstatusbar" value="true"><param name="enableErrorDialogs" value="0"><param name="autorewind" value="1"><param name="ShowTracker" value="false"><param name="ShowPositionControls" value="false"><param name="ShowControls" value="true">';
searchPlayerVideo += '<embed type="application/x-mplayer2" showtracker=1 showpositioncontrols=1 enableErrorDialogs="0" autostart="1" pluginspage="http:/activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" showstatusbar="1" showcontrols="1" enablecontextmenu="0" autorewind="1" volume="75" src="songid" filename="songid" name="Player" width="320" height="260" />';
searchPlayerVideo += '</object>';

var oldBlockID;
var oldPlayerID;

function showSongDetail(id, status)
{
	obj = document.getElementById(id);
	obj.style.display = status;
}

function replacePlayer(blockID, playerID, txt_search, txt_replace, searchPlayer)
{
	// open new
	if (blockID == oldBlockID) {		
		obj = document.getElementById(blockID);
		if (obj.style.display == 'none') {
			showSongDetail(blockID, 'block');
			playlist(playerID, txt_search, txt_replace, searchPlayer);
		} else {
			document.getElementById(playerID).innerHTML = '';
			showSongDetail(blockID, 'none');
		}
	} else {
		if (oldBlockID) {
			document.getElementById(oldPlayerID).innerHTML = '';
			showSongDetail(oldBlockID, 'none');
		}
		showSongDetail(blockID, 'block');
		playlist(playerID, txt_search, txt_replace, searchPlayer);
		oldBlockID = blockID;
		oldPlayerID = playerID;
	}
}

function download(msg, file)
{
	if (msg != '' && file == '') {
		alert(msg);
		return;
	}
	
	window.open('/download/?' + file);
}

// count song
/*function countSong()
{
	xmlhttp.open('get', '/mp3/vote/do.'+id_num+'.'+vote+'.html');
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
}*/
function getEmbed(domain_flash, domain_site, url, extension, number)
{
	var embed = '';
	var id = "embed" + number;
	if(extension == "mp3")
		embed = '<object width="315" height="270"><param name="movie" value="' + domain_flash + 'skins/black/flash/player/mp3Player.swf?xmlurl=' + domain_site + '/blog/?' + url + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed width="315" height="270" src="' + domain_flash + 'skins/black/flash/player/mp3Player.swf?xmlurl=' + domain_site + '/blog/?' + url + '" quality="high" wmode="transparent" type="application/x-shockwave-flash"></embed></object>';	
	//	embed = '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="20" width="385" src="' + domain + '/skins/zing/flash/player.swf?data=/blog/?' + url + '&shuffle=false&autostart=true&repeat=true&showdownload=true" />';
	else if(extension == "flv")
		embed = '<object width="385" height="300"><param name="movie" value="' + domain_flash + 'skins/zing/flash/flvplayer.swf?file=http://mp3.zing.vn/blog/?' + url + '&shuffle=false&autostart=true&repeat=true&showdownload=true" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed width="385" height="300" src="' + domain_flash + 'skins/zing/flash/flvplayer.swf?file=' + domain_site + '/blog/?' + url + '&shuffle=false&autostart=true&repeat=true&showdownload=true" quality="high" wmode="transparent" type="application/x-shockwave-flash"></embed></object>';
	//	embed = '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="300" width="385" src="' + domain + '/skins/zing/flash/flvplayer.swf?file=/blog/?' + url + '&shuffle=false&repeat=true&showdownload=true&autostart=true" />';
	//else if(extension == "wma")
	//	embed = '<object width="320" height="65"><param name="movie" value="' + domain_site + '/playsong/?' + url + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="' + domain_site + '/playsong/?' + url + '" quality="high" wmode="transparent" type="application/x-shockwave-flash" width="320" height="65" enablecontextmenu="0"></embed></object>';
	//	embed = '<embed type="application/x-shockwave-flash" width="320" height="65" allowfullscreen="true" flashvars="autostart=true" enablecontextmenu="0" src="' + domain + '/playsong/?' + url + '" />';		
	//else if(extension == "wmv")
	//	embed = '<object width="320" height="240"><param name="movie" value="' + domain_site + '/playsong/?' + url + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="' + domain_site + '/playsong/?' + url + '" quality="high" wmode="transparent" type="application/x-shockwave-flash" width="320" height="240" enablecontextmenu="0"></embed></object>';
	document.getElementById(id).value = embed;
	document.getElementById(id).style.display = 'block';
}

function getEmbed1(domain_flash, domain_site, url, extension, number, skin,background_flag)
{
	var embed = '';
	var width='0';
	var heigth='0';
	var id = "embed" + number;
	if (skin==0)
	{
		if (background_flag!=1)
		{
			width='257';
			heigth='200';
		}
		else
		{
			width='0';
			heigth='0';				
		}		
	}
	else
	{
		if (background_flag!=1)
		{
			width='300';
			heigth='61';
		}
		else
		{
			width='0';
			heigth='0';				
		}
	}	

	if(extension == "mp3")
	{
		embed = '<object width="'+width+'" height="'+heigth+'"><param name="movie" value="' + domain_flash + 'skins/black/flash/player/mp3Player_skin'+skin+'.swf?xmlurl=' + domain_site + '/blog/?' + url + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed width="'+width+'" height="'+heigth+'" src="' + domain_flash + 'skins/black/flash/player/mp3Player_skin'+skin+'.swf?xmlurl=' + domain_site + '/blog/?' + url + '" quality="high" wmode="transparent" type="application/x-shockwave-flash"></embed></object>';	
	}
	document.getElementById(id).value = embed;
	document.getElementById(id).style.display = 'block';
}


function getEmbed_forum(domain_flash, domain_site, url, extension, number, skin)
{
	var embed = '';
	var id = "embed_forum" + number;
	if(extension == "mp3")
		embed = '[FLASH]'+ domain_flash + 'skins/black/flash/player/mp3Player_skin'+skin+'.swf?xmlurl=' + domain_site + '/blog/?' + url+ '[/FLASH]';
	document.getElementById(id).value = embed;
	document.getElementById(id).style.display = 'block';
}

function radio_getEmbed_blog(domain_flash, domain_site, url, extension)
{
	var embed = '';
	var id = "embed_blog";
	if(extension == "mp3"){
	embed = '<object width="257" height="200"><param name="movie" value="' + domain_flash + 'skins/black/flash/player/mp3Player.swf?xmlurl=' + domain_site + '/blog/?' + url + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed width="257" height="200" src="' + domain_flash + 'skins/black/flash/player/mp3Player.swf?xmlurl=' + domain_site + '/blog/?' + url + '" quality="high" wmode="transparent" type="application/x-shockwave-flash"></embed></object>';	

	}
	document.getElementById(id).value = embed;
	document.getElementById(id).style.display = 'block';
}


function radio_getEmbed_forum(domain_flash, domain_site, url, extension)
{
	var embed = '';
	var id = "embed_forum";
	if(extension == "mp3")
		embed = '[FLASH]'+ domain_flash + 'skins/black/flash/player/mp3Player.swf?xmlurl=' + domain_site + '/blog/?' + url+ '[/FLASH]';
	document.getElementById(id).value = embed;
	document.getElementById(id).style.display = 'block';
}

function zingMenu(name, css)
{
	var arrZingMenu = document.getElementsByName(name);
	for (var i = 0; i < arrZingMenu.length; i++) {
		if (location.pathname != '/' && location.pathname != '/mp3' && arrZingMenu[i].href.search(location.pathname) != -1) {
			arrZingMenu[i].className = css;
			break;
		}
	}
}

//---------------------
//thong bao
//---------------------
function annoucement(){
	alert("Vui lòng đăng nhập để sử dụng chức năng này!!!!");
	$('frmLogin').AccountName.focus();
	return false;
}

function StringAvailable(str)
{
	var array_str = str.split(" ");
	var lengthAvaillable = 20;
	var flag = true;
	for (i in array_str)
	{
		if (array_str[i].length > lengthAvaillable)
		{
			flag = false;
		}
	}
	
	if (flag == false)		
		return false;	
	else return true;
}

var ca = new Array ('a','à.á.ạ.ả.ã.â.ầ.ấ.ậ.ẩ.ẫ.ă.ằ.ắ.ặ.ẳ.ẵ');
var caB = new Array ('A','À.Á.Ạ.Ả.Ã.Â.Ầ.Ấ.Ậ.Ẩ.Ẫ.Ă.Ằ.Ắ.Ặ.Ẳ.Ẵ');
var ce = new Array ('e','è.é.ẹ.ẻ.ẽ.ê.ề.ế.ệ.ể.ễ');
var ceB = new Array ('E','È.É.Ẹ.Ẻ.Ẽ.Ê.Ề.Ế.Ệ.Ể.Ễ');
var ci = new Array ('i','ì.í.ị.ỉ.ĩ');
var ciB = new Array ('I','Ì.Í.Ị.Ỉ.Ĩ');
var co = new Array ('o','ò.ó.ọ.ỏ.õ.ô.ồ.ố.ộ.ổ.ỗ.ơ.ờ.ớ.ợ.ở.ỡ');
var coB = new Array ('O','Ò.Ó.Ọ.Ỏ.Õ.Ô.Ồ.Ố.Ộ.Ổ.Ỗ.Ơ.Ờ.Ớ.Ợ.Ở.Ỡ');
var cu = new Array ('u','ù.ú.ụ.ủ.ũ.ư.ừ.ứ.ự.ử.ữ');
var cuB = new Array ('U','Ù.Ú.Ụ.Ủ.Ũ.Ư.Ừ.Ứ.Ự.Ử.Ữ');
var cy = new Array ('y','ỳ.ý.ỵ.ỷ.ỹ');
var cyB = new Array ('Y','Ỳ.Ý.Ỵ.Ỷ.Ỹ');
var cd = new Array ('d','đ');
var cdB = new Array ('D','Đ');
var cs = new Array ('','\'.~.@.#.%.^.&.,.&');
var bangkitucoso = new Array(ca,ce,ci,co,cu,cy,cd,caB,ceB,ciB,coB,cuB,cyB,cdB,cs);
//var bangkitucoso = new Array(caB,ceB,ciB,coB,cuB,cyB,cdB,cs);
function stripViet(bv)
{
   var markhongdau = new Array();
   markhongdau[0]=bv;
   for (j=0; j < bangkitucoso.length; j++) // max j = 8
   {
      marthaythe = bangkitucoso[j][1].split('.'); // tach cac chuoi co dau thanh tung phan tu rieng biet
      for (i=0; i < marthaythe.length; i++)
      {
	       markhongdau[i+1] = mThayThe(markhongdau[i],marthaythe[i],bangkitucoso[j][0]);
           markhongdau[0]=markhongdau[i+1];
      }
   }//end of for
   // kiem tra loi injection
   // document.getElementById(\'uoon\').innerHTML =markhongdau[0]; 
   return markhongdau[0];
}

function mThayThe(ccha,cbithay,cthaythe)
{
   var ccon =  cbithay ;
   var cmoi=ccha.replace(ccon,cthaythe);
   return cmoi;
}
//Add Album to Favourite
function Favourite_Add_Album(PlaylistID)
{
	var url  = '/includes/FavouriteAddPlaylist.php';		
	var myAjax 	= new Ajax.Request
	(
		url, 
		{
			method		: "get",
			parameters	: 'PlaylistID='+PlaylistID,
			onComplete	: response_Favourite_Add_Album
		}
	)
}

function response_Favourite_Add_Album(originalRequest)
{
	var responseText = originalRequest.responseText;

	//Add Success
	if (responseText == '1')
	{
		alert('Đã thêm album này vào danh sách album yêu thích của bạn');
	}
	else
	//Duplicate
	if (responseText == '0')
	{
		alert('Album này đã tồn tại trong danh sách yêu thích của bạn');	
	}
	else
	//No Login
	if (responseText == '-1')
	{
		alert('Bạn chưa đăng nhập. Vui lòng đăng nhập để thực hiện chức năng này');	
	}	
}

function Album_Add_Song(param)
{
	if ($('isLogged').value=='1')
	{
		AddPlaylist(param.split('||##||')[0]);	
	}
	else
	{
		AddCookiePlaylist_1(param.split('||##||')[1]);
	}
}