var playerWidth;
var playerHeight;
var screenWidth;
var screenHeight;
var sourceID;
var sourceURL;
var allowFullScreen;
var autoStart;
var currentPosition;
var currentRemaining;
var playerStatus;
var showNavigation;

var currentPlayerWidth;
var currentPlayerHeight;
var currentScreenWidth;
var currentScreenHeight;

var stream_type;
var scope;
var content_group;
var current_guid;
var central_id;
var current_bitrate = "";
var trueworld_token;
var referer = "truemusic";
var ext;
var clientip;
var theme_path;
var guidtype;
var channel;
var jwplayer;
var playerSize;

var playCount=0;

var siamza_url = "http://truemusic.truelife.com/home/player/theme_tv/siamza/";
var showVoteComment = true;
var t_mp3download = "tagMP3Download1";
var t_mbdownload = "tagMBDownload1";
var t_mvdownload = "tagMVDownload1";

// ---------------------------------------------
// Playlist Variable
// ---------------------------------------------

var content_meta 




function initFPlayer(){
switch (playerSize)
	{
	case "tl":
			currentPlayerWidth=fpSize_w_tl.m;
			currentPlayerHeight=fpSize_h_tl.m;
			currentScreenWidth=fpSize_w_tl.m;
			currentScreenHeight=fpSize_h_tl.m;
			allowFullScreen=true;
			break;
	case "mini":
			currentPlayerWidth=fpSize_w_mini.m;
			currentPlayerHeight=fpSize_h_mini.m;
			currentScreenWidth=fpSize_w_mini.m;
			currentScreenHeight=0;
			allowFullScreen=false;
			break;
	default:
			currentPlayerWidth=fpSize_w.m;
			currentPlayerHeight=fpSize_h.m;
			currentScreenWidth=fpSize_w.m;
			currentScreenHeight=fpSize_h.m;
			allowFullScreen=true;
			break;
	}
	
	showNavigation=true;
	autoStart=true;
	prepareFPlayer();
	writeFPlayer();
	showBitrate(defaultTxtBitrate);
}

function createFlashMVPlayer(){
	defindPlayerSize(playerSize);
	allowFullScreen=true;
	showNavigation=true;
	autoStart=true;
	prepareFPlayer_SongGUID();
	writeFPlayer();
}


function initMVFPlayer(){
	
	createcartform();
	gid("adsframe1").src = "http://truemusic.truelife.com/home/inc/ad_banner.php?siteid=24&zoneid=90&width=468&height=60&keyword=-";
	gid("statframe").src = domain_name+"home/player/inc/stat.php?pagename=MV_PLAYER&bgcolor=dadada&cgn=Music&cgs=MV_PLAYER";
	//initVoteComment(current_guid);
}


function prepareFPlayer(){
	//get_trueworld_token()
	if (current_bitrate == ""){current_bitrate = vdo_quality.hi;}
	//sourceURL = stream_url.replace("~streamtype~", stream_type).replace("~scope~", scope).replace("~contentgroup~", content_group).replace("~guid~", current_guid).replace("~bitrate~", current_bitrate).replace("~trueworldtoken~", trueworld_token).replace("~referer~", referer).replace("~channel~", channel).replace("~ext~", ext).replace("~clientip~", clientip).replace("~jwplayer~", jwplayer);
	sourceURL = stream_url.replace("~streamtype~", stream_type).replace("~scope~", scope).replace("~contentgroup~", content_group).replace("~guid~", current_guid).replace("~bitrate~", current_bitrate).replace("~trueworldtoken~", trueworld_token).replace("~referer~", referer).replace("~channel~", channel).replace("~ext~", ext).replace("~clientip~", clientip).replace("~jwplayer~", jwplayer).replace("~file~", file).replace("~needinfo~", needinfo);
	sourceURL = removeTrailingSpaces(sourceURL);
	//sourceURL = encodeURIComponent(stream_url);
}

function prepareFPlayer_SongGUID(){
	//get_trueworld_token()
	if (current_bitrate == ""){current_bitrate = vdo_quality.hi;}
	//sourceURL = stream_url.replace("~streamtype~", stream_type).replace("~scope~", scope).replace("~contentgroup~", content_group).replace("~guid~", current_guid).replace("~bitrate~", current_bitrate).replace("~trueworldtoken~", trueworld_token).replace("~referer~", referer).replace("~channel~", channel).replace("~ext~", ext).replace("~clientip~", clientip).replace("~jwplayer~", jwplayer);
	sourceURL = streamSongGUID_url.replace("~streamtype~", stream_type).replace("~scope~", scope).replace("~contentgroup~", content_group).replace("~guid~", current_guid).replace("~bitrate~", current_bitrate).replace("~trueworldtoken~", trueworld_token).replace("~referer~", referer).replace("~channel~", channel).replace("~ext~", ext).replace("~clientip~", clientip).replace("~jwplayer~", jwplayer).replace("~file~", file).replace("~needinfo~", needinfo);
	sourceURL = removeTrailingSpaces(sourceURL);
	//sourceURL = encodeURIComponent(stream_url);
}

function removeTrailingSpaces(arg) {
	while(''+arg.charAt(arg.length-1)==' ') { arg=arg.substring(0,arg.length-1); }
	return(arg);
}

function writeFPlayer()
{
  var so = new SWFObject('/home/player/flash/mediaplayer3_16.swf',swf,currentPlayerWidth,currentPlayerHeight,'9');
  so.addParam('allowscriptaccess','always');
  so.addParam('allowfullscreen',allowFullScreen);
  so.addParam('shownavigation',showNavigation);  
  so.addVariable('javascriptid','fpObj');
  so.addVariable('enablejs','true');
  so.addVariable('usefullscreen','true');
  so.addVariable('width',currentPlayerWidth);
  so.addVariable('height',currentPlayerHeight); 
  so.addVariable('displaywidth',currentScreenWidth);
  so.addVariable('displayheight',currentScreenHeight);
  //so.addVariable("overstretch", "fit");
  so.addVariable('autostart',autoStart);
  //so.addVariable('controlbar',"bottom");
  //so.addVariable('file','http://truemusic.truelife.com/home/player/streammanager.xml');
  so.addVariable('file',sourceURL);
  so.addParam("wmode","transparent");
  so.addParam("allowScriptAccess", "always");
  so.write('showFlashPlayer');
}


function defindPlayerSize(playerSize){
	switch (playerSize)
	{
	case "tl":
			currentPlayerWidth=fpSize_w_tl.m;
			currentPlayerHeight=fpSize_h_tl.m;
			currentScreenWidth=currentPlayerWidth;
			currentScreenHeight=currentPlayerHeight+19;
			break;
	case "mini":
			currentPlayerWidth=fpSize_w_mini.m;
			currentPlayerHeight=fpSize_h_mini.m;
			currentScreenWidth=fpSize_w_mini.m;
			currentScreenHeight=0;
			break;
	default:
			currentPlayerWidth=fpSize_w.m;
			currentPlayerHeight=fpSize_h.m;
			currentScreenWidth=fpSize_w.m;
			currentScreenHeight=fpSize_h.m;
			break;
	}
}

function set_hi_quality()
{
	current_guid = stream_guid.hi;
	current_bitrate = vdo_quality.hi;
	prepareFPlayer();
	writeFPlayer();
	showBitrate("hi");
}

function set_low_quality()
{
	current_guid = stream_guid.low;
	current_bitrate = vdo_quality.low;
	prepareFPlayer();
	writeFPlayer();
	showBitrate("low");
}


function showBitrate(quality)
{
	
	if(isBitrate){
		$("showBitrate").style.display = "";
		if (quality=="" || quality == null)	{
			quality = defaultTxtBitrate;
		}
		switch (quality)
		{
		case "hi":
			document.getElementById("div_low_quality").innerHTML = '<A HREF="#" onclick="set_low_quality();" class="lnk_bitrate">256</a>';
			document.getElementById("div_hi_quality").innerHTML = '<font class="b_white">512</font>';
			break;
		case "low":
			document.getElementById("div_low_quality").innerHTML = '<font class="b_white">256</font>';
			document.getElementById("div_hi_quality").innerHTML = '<A HREF="#" onclick="set_hi_quality();" class="lnk_bitrate">512</a>';
			break;
		}
	}
	else {
		$("showBitrate").style.display = "none";
	}
}

function set_zoom_in()
{
	currentPlayerWidth=fpSize_w.s;
	currentPlayerHeight=fpSize_h.s;
	currentScreenWidth=fpSize_w.s;
	currentScreenHeight=fpSize_h.s;
	allowFullScreen=true;
	showNavigation=true;
	autoStart=true;
	prepareFPlayer();
	writeFPlayer();
	$("zoom_title_size").innerHTML = ''+fpSize.s+'%';
}

function set_zoom_out()
{
	currentPlayerWidth=fpSize_w.m;
	currentPlayerHeight=fpSize_h.m;
	currentScreenWidth=fpSize_w.m;
	currentScreenHeight=fpSize_h.m;
	allowFullScreen=true;
	showNavigation=true;
	autoStart=true;
	prepareFPlayer();
	writeFPlayer();
	$("zoom_title_size").innerHTML = ''+fpSize.m+'%';
}

function set_zoom_in_tl()
{
	currentPlayerWidth=fpSize_w_tl.s;
	currentPlayerHeight=fpSize_h_tl.s;
	currentScreenWidth=fpSize_w_tl.s;
	currentScreenHeight=fpSize_h_tl.s;
	allowFullScreen=true;
	showNavigation=true;
	autoStart=true;
	prepareFPlayer_SongGUID()
	writeFPlayer();
	$("zoom_title_size").innerHTML = ''+fpSize.s+'%';
}

function set_zoom_out_tl()
{
	currentPlayerWidth=fpSize_w_tl.m;
	currentPlayerHeight=fpSize_h_tl.m;
	currentScreenWidth=fpSize_w_tl.m;
	currentScreenHeight=fpSize_h_tl.m;
	allowFullScreen=true;
	showNavigation=true;
	autoStart=true;
	prepareFPlayer_SongGUID()
	writeFPlayer();
	$("zoom_title_size").innerHTML = ''+fpSize.m+'%';
}



function addToFavorite()
{
	var strTitle = document.title;
	strTitle = strTitle.substring(0,100);
	//window.external.AddFavorite(location.href, strTitle); 
	if (window.sidebar) { // Mozilla Firefox Bookmark		
		window.sidebar.addPanel(strTitle, location.href,"");	
	} else if( window.external ) { // IE Favorite		
		window.external.AddFavorite( location.href, strTitle); 
	}	else if(window.opera && window.print) { // Opera Hotlist		
		return true; 
	}
}


function sendToFriends()
{
	var path = window.location;
	var windowprops = "directories=no,scrollbars=no,width=480,height=350,left=200,top=50,resizable=1";
	window.open(domain_trueworld+"newsletter/send2fr/index.jsp?requestpath=" + escape(path),"",windowprops)
}

function get_trueworld_token()
{
	var URL = "http://truemusic.truelife.com/home/player/inc/inc_genTrueworldToken2.php";
		param = "r=" + Math.floor(Math.random()*100);
		URL = URL+"?"+param;
	var xmlr = new clsAjaxMini(); 
	var xChild = xmlr.LoadSync("GET", URL,"",true);
		trueworld_token = xChild;

}

function get_livechat_meta(conId)
{
	var URL = "http://truemusic.truelife.com/home/player/inc/inc_call_meta_livechat.php";
		param = "conId="+conId+"&r=" + Math.floor(Math.random()*100);
		URL = URL+"?"+param;
		
	var xmlr = new clsAjaxMini(); 
	var xChild = xmlr.LoadSync("GET", URL,"",true);
	//	trueworld_token = escape(xChild);
		$("livechat_meta").innerHTML = xChild;
}

/* Start: DEBUG =====*/
function log(txt)
{
	document.getElementById("log").innerText += "\n" + txt;
}



// Start: Tong Function ---- //

//---------------------------------------------
// Song Information Function
//---------------------------------------------
function $(name) {
	return document.getElementById(name);
}

function w_play_tv_item(url, newwin)
{
	if (url == domain_name+"home/player/player_livetv.php?guid=1")
	{
		url = livetv_ch3_url;
		newwin = "playerwin";
	}
	if (url == domain_name+"home/player/player_livetv.php?guid=3")
	{
		url = livetv_ch3_url;
		newwin = "playerwin";
	}
	if (newwin != null && newwin != "undefined")
			window.open(url);
	else
	{
		window.location.href = url;
	}
}

/*function w_play_tv_partner_player(url, newwin)
{
	if (url == domain_name+"home/player/theme_tv/siamza/index.php?guid=1")
	{
		url = livetv_ch3_url;
		newwin = "playerwin";
	}
	if (url == domain_name+"home/player/theme_tv/siamza/index.php?guid=3")
	{
		url = livetv_ch3_url;
		newwin = "playerwin";
	}
	if (newwin != null && newwin != "undefined")
			window.open(url);
	else
	{
		window.location.href = url;
	}
}*/


function w_play_tv_partner_player(ch, newwin)
{
	if (ch == "" || ch == null || ch == "undefined")
	{
		alert("กรุณากำหนดช่องรายการ");
		return false;
	}
	else
	{
		var url = siamza_url+"?guid="+ch;
		}	
		if (newwin != null && newwin != "undefined")
			window.open(url);
		else
			window.location.href = url;
	
}

function getUpdate(typ,pr1,pr2,swf) {//t
	
	if(typ == "state" && swf == "fpObj") 
	{	
		stateChange(pr1);
    }else if(typ == "item" && swf == "fpObj") 
    { 
       chargeItem(swf,pr1);
    }
    else if(typ == "time" && swf == "fpObj") 
    { 
        chargeRemain(swf,pr1,pr2);

    }
}




function loadMetaData(JONMessage){
	//alert("JONMessage"+JONMessage);
	   content_meta =eval('(' + JONMessage + ')');

	   //alert("content_meta"+content_meta);
}

function chargeItem(swf,pr1)
{
       var obj = document.getElementById(swf).itemData(pr1);   
        if (obj["title"] != '')
        {
            loadMetaData(obj["title"]);
			if (content_meta.isAd == "False" || content_meta.isAd == "false" || content_meta.isAd == false){
				playCount++;
				if (playCount==1)
				{
					gid("statframe").src = domain_name+"home/player/inc/stat.php?pagename=MV_STREAMING&bgcolor=dadada&cgn=Music&cgs=MV_STREAMING";
					//gid("rating_mv").src = "http://enabling.truelife.com/rating/ratingservice.jsp?guid="+content_meta.streamMVGUID+"&type=mv&w=75&h=20&color=#FFFFFF";
				}
				else
				{
					gid("statframe").src = domain_name+"home/player/inc/stat.php?pagename=MV_STREAMING&bgcolor=dadada&cgn=Music&cgs=MV_STREAMING";
				}
			}
		
		if (content_meta.title != "")
			{
				gid(song_title_text_name).innerHTML = content_meta.title;
				gid(song_top_title_text_name).innerHTML = content_meta.title;
			}
			else
			{
				gid(song_title_text_name).innerHTML ="";
				gid(song_top_title_text_name).innerHTML = "";
			}
			
			if (content_meta.albumGUID != "" && content_meta.artistGUID != "")
			{
				gid(album_title_text_name).innerHTML = "<a class=\"bLink\" href=\""+domain_music+"home/artist_album.php?guid=" + content_meta.artistGUID +"&amp;album_guid="+ content_meta.albumGUID +"\" target=\"_blank\">" + content_meta.album  + "</a>" ;
			}
			else
			{
				gid(album_title_text_name).innerHTML = "";
			}

			if (content_meta.artistGUID != "" && content_meta.artistGUID != "undefined" && content_meta.artistGUID != null)
			{
				gid(artist_title_text_name).innerHTML = "<a class=\"bLink\" href=\""+domain_name+"home/artist.php?guid=" + content_meta.artistGUID +"\" target=\"_blank\">" + content_meta.artist  + "</a>" ;
			}
			else
			{
				gid(artist_title_text_name).innerHTML = "";
			}

			

			//**** add to shopping cart
		/*	if (content_meta.offlineJukebox == "true" || content_meta.offlineJukebox == "True" || content_meta.downloadMusicGUID == true)
			{
				if (content_meta.downloadMusicGUID != "" && content_meta.downloadMusicGUID != "undefined" && content_meta.downloadMusicGUID != null)
				{
					token = content_meta.downloadMusicGUID;
					cart_title = content_meta.title +" - "+content_meta.album;
					cart_title = cart_title.replace(/\'/g, "\\\'");
					if (content_meta.downloadPrice != "" && content_meta.downloadPrice != "undefined" && content_meta.downloadPrice != null)
						downloadprice = content_meta.downloadPrice;
					else
						downloadprice = "0";

					//var click_buy = "addCart('"+central_id+"','"+content_meta.downloadMusicGUID+"','"+content_meta.downloadSID+"','"+cart_title+"','"+content_meta.downloadPrice+"','"+world+"','"+media_type+"','"+quantity+"','"+ref+"','"+cartid+"')";
					var click_buy = "addtoshoppingcart('"+token+"','"+content_id_type+"','"+content_type+"','"+cart_title+"','"+quantity+"','"+downloadprice+"','"+duplicate+"','"+extendparam+"','"+cartid+"');";
					gid(cart_title_text_name).innerHTML = "<a href=\"#\" onclick=\""+click_buy+"\" class=\"Pinklink\">ซื้อ("+content_meta.downloadPrice+" บ.)</a>";
				}
				else
				{
					gid(cart_title_text_name).innerHTML = "ซื้อ";
				}
			}
			else
			{
				gid(cart_title_text_name).innerHTML = "ซื้อ";
			}
*/
		
			//**** Lyric
			if (content_meta.lyricGUID != "" && content_meta.lyricGUID != "undefined" && content_meta.lyricGUID != null)
			{
				lyric_link = lyric_url + "?guid=" + content_meta.lyricGUID;
				gid(lyric_title_text_name).innerHTML = "<a href=\"#\" class=\"Pinklink\" onclick=\"openWin('"+lyric_link+"','winLyric',572,600);\">เนื้อร้อง</a>&nbsp;&nbsp;";
			}
			else
			{
				gid(lyric_title_text_name).innerHTML = "เนื้อเพลง";
			}

			


			//**** add to jukebox
			
			if ((content_meta.onlineJukebox=="True" || content_meta.onlineJukebox=="true") && (content_meta.streamMusicGUID != ""))
			{
				gid(jukebox_title_text_name).innerHTML = "<a href=\"#\" class=\"Pinklink\" onclick=\"addtojukebox('"+content_meta.streamMusicGUID+"');return false;\" >เก็บลง My Jukebox</a>" ;
			}
			else
			{
				gid(jukebox_title_text_name).innerHTML = "เก็บลง My Jukebox";
			}

			if (content_meta.albumImageURL != "" && content_meta.albumImageURL != "undefined" && content_meta.albumImageURL != null)
			{
				gid("thumb").src = content_meta.albumImageURL;
			}
			else
			{
				gid("thumb").src = '<img src="'+domain_music+'"home/player/images/thumb.gif" id="thumb" class="img_thumb">' ;
			}

			//**** ads banner
			if (content_meta.bannerAdSource == "undefined" || content_meta.bannerAdSource == "" || content_meta.bannerAdSource == null)
			{
				gid("adsframe1").src = "http://truemusic.truelife.com/home/inc/ad_banner.php?siteid=24&zoneid=90&width=468&height=60&keyword=";
			}
			else{
				gid("adsframe1").src = "http://truemusic.truelife.com/home/inc/ad_banner.php?siteid=24&zoneid=90&width=468&height=60&keyword="+content_meta.bannerAdSource;
			}
			//**** download mp3
			
			gid(t_mp3download).innerHTML = getMP3Download();
			gid(t_mbdownload).innerHTML = getMBDownload();
			gid(t_mvdownload).innerHTML = getMVDownload();

			try
			{
				//alert(EMBED_CODE);
				if(content_meta.songGUID != ""){
					//alert(content_meta.songGUID);
					document.frmembed.embed_input.value = EMBED_CODE_MV.replace("~songguid~", content_meta.songGUID).replace("~songguid~", content_meta.songGUID);
					$("zone_embed").className = "show";
				}
				else{
					$("zone_embed").className = "hide";
				}
			}
			catch (e)
			{
				alert(e.description);
			}
			

			/* Mobile */
			if (content_meta.colorRingOn2222 != null && content_meta.colorRingOn2222 != "undefined"
					&& content_meta.ringtoneOn2222 != null && content_meta.ringtoneOn2222 != "undefined"
					&& content_meta.colorRingIVRNumber != null && content_meta.colorRingIVRNumber != "undefined"
					&& content_meta.colorRingPrice != null && content_meta.colorRingPrice != "undefined"
					&& content_meta.ringtoneIVRNumber != null && content_meta.ringtoneIVRNumber != "undefined"
					&& content_meta.ringtonePrice != null && content_meta.ringtonePrice != "undefined")
			{
				if (content_meta.colorRingIVRNumber != "" || content_meta.ringtoneIVRNumber != "")
				{
					gid("ringtone_zone").className = "show";

					
						if (content_meta.ringtoneIVRNumber != "" || content_meta.colorRingIVRNumber != ""){
							gid(ringtone_banner_text_name).src = images_tl_path+"tbl_ringtone_text.gif";
						}
						else{
							gid(ringtone_banner_text_name).src = images_tl_path+"tbl_ringtone_textno2222.gif";
						}
							

					// Ringtone
						if (content_meta.ringtoneIVRNumber != "" && content_meta.ringtoneIVRNumber != "undefined")
						{
							gid("ringtone_download_zone").className = "show";
							
							getRingtoneIVRNumber = ConvRingtoneIVRNumber(content_meta.ringtoneIVRNumber);
							
							gid(ringtone_code_text_name).innerHTML = getRingtoneIVRNumber;

							if (content_meta.ringtonePrice != "" && content_meta.ringtonePrice != "undefined"  && content_meta.ringtonePrice != null)
								gid(ringtone_price_text_name).innerHTML = content_meta.ringtonePrice;
							else
								gid(ringtone_price_text_name).innerHTML = "";
						}
						else
						{
							gid("ringtone_download_zone").className = "hide";
							gid(ringtone_code_text_name).innerHTML = "-";
						}

					// Color Ring
						if (content_meta.colorRingIVRNumber != "" && content_meta.colorRingIVRNumber != "undefined"  && content_meta.colorRingIVRNumber != null)
						{
							gid("colorring_download_zone").className = "show";
							gid(colorring_code_text_name).innerHTML = content_meta.colorRingIVRNumber+"00";
							if (content_meta.colorRingPrice != "" && content_meta.colorRingPrice != "undefined")
								gid(colorring_price_text_name).innerHTML = content_meta.colorRingPrice;
							else
								gid(colorring_price_text_name).innerHTML = "";
						}
						else
						{
							gid("colorring_download_zone").className = "hide";
							gid(colorring_code_text_name).innerHTML = "";
						}
				}
				else
				{
					gid("ringtone_zone").className = "hide";
				}
			}
			else
				gid("ringtone_zone").className = "hide";


            /*gid("Cotnent_Title").innerHTML = content_meta.title;
            gid("contentguid").innerHTML = content_meta.contentguid;    
            gid("contentgroup").innerHTML = content_meta.contentgroup;    
            gid("fileext").innerHTML = content_meta.fileext;    
            gid("ticket_id").innerHTML = content_meta.ticket_id;    
            gid("statusCode").innerHTML = content_meta.statusCode;    
            gid("statusText").innerHTML = content_meta.statusCode;
			*/
			/*if (content_meta.isAd == "False" || content_meta.isAd == "false" || content_meta.isAd == false){
				statMusicChart_tlmv(content_meta.streamMVGUID,content_meta.title,content_meta.artistGUID,content_meta.artist,content_meta.albumGUID,content_meta.album,content_meta.songGroup);
			}*/
			//initVoteComment(current_guid);
		/*	if (gid("tagCommentFrame")){
				try {
					if (gid("tagCommentFrame").src == "")  gid("tagCommentFrame").src = COMMENT_MV_URL + guid;
					alert("create comment");
				}catch(e){ }
			}

			try{
				var docHt = 0, sh, oh;
				sh = window.frames["commentFrame"].document.body.scrollHeight;
				alert(sh);
				gid("tagCommentFrame").height = sh;
				//getElement("tagTotalComment").innerHTML = getTotalComment();
				//window.frames["commentFrame"].document.forms["Comment"].rtp.value = COMMENT_MV_URL + guid;
			}catch(e){ }*/
			

		/*	try{
				alert("adjustIFrameSize");
				var docHt = 0, sh, oh;
				alert(window.frames["commentFrame"].document.body.scrollHeight);
				sh = window.frames["commentFrame"].document.body.scrollHeight;
				alert(sh);
				gid("tagCommentFrame").height = sh;
				//getElement("tagTotalComment").innerHTML = getTotalComment();
				//window.frames["commentFrame"].document.forms["Comment"].rtp.value = COMMENT_MV_URL + guid;
			}catch(e){ alert(e.description);}
*/
		
        }
       
}

function chargeRemain(swf,pr1,pr2)
{
	if(pr2==0 && (playCount<20 && playCount>0)){
		play();
	}
	adjustIFrameSize();
	
}

function gid(name) {
	return document.getElementById(name);
}

function addtojukebox(content_guid){
	  if(central_id.length<=5){
		 alert("กรุณา login");
		 return false;
	  }else{
		add_to_jukebox(content_guid);
	  }
}

function stateChange(stateValue){
	switch (stateValue)
	{
	case 0: //ready/paused
		playState = 0;
	break;
	case 1: //loading
		playState = 1;
	break;
	case 2: //play
		playState = 2;
	break;
	/*case : //stop
		playState = ;
		break;*/
	}
	//adjustIFrameSize(gid("tagCommentFrame"));
}



function play()
{
    if (playState != 2)
    {
        sendEvent(swf,'playpause','');
    }
	else{
		stop();
		play();
	}
}

function pause()
{
    if (playState == 2)
    {
        sendEvent(swf,'playpause','');
    }
}

function stop()
{
    if (playState == 2)
    {
        sendEvent(swf,'stop','');
    }
}

function sendEvent(swf,typ,prm) { 
	gid(swf).sendEvent(typ,prm); 
};

function statMusicChart_tlmv(songGuid,songTitle,artistGuid,artistTitle,albumGuid,albumTitle,songGroup){
	var param = "l1_guid=" + songGuid + "&l1_title=" + encodeURIComponent(songTitle) + "&l3_guid=" + artistGuid + "&l3_title=" + encodeURIComponent(artistTitle) + "&l2_guid=" + albumGuid + "&l2_title=" + encodeURIComponent(albumTitle) + "&contentType=text&contentGroup=music&contentSubGroup=MV&contentScope=" + encodeURIComponent(songGroup) + "&source=playMV&mode=Streaming";
					document.getElementById("musicchartstat").src = domain_webboard + "MusicChart/musicchart-stat.jsp?" + param;
}

function initVoteComment(guid){
	if (gid("tagCommentFrame")){
			try {
				if ((showVoteComment == true) && (gid("tagCommentFrame").src == ""))  {gid("tagCommentFrame").src = COMMENT_MV_URL + guid;}
				//window.frames["commentFrame"].document.forms["Comment"].rtp.value = COMMENT_MV_URL + guid;
				//adjustIFrameSize(gid("tagCommentFrame"));
			}catch(e){ }
			window.frames["commentFrame"].document.forms["Comment"].rtp.value = COMMENT_MV_URL + current_guid+"&r="+thispage_encode;
	}
}


function setAdjustIFrameSize(){
	var t = setTimeout("adjustIFrameSize()",5000);
}


function adjustIFrameSize(){
try{
			var sh;
			sh = window.frames["commentFrame"].document.body.scrollHeight;
			$("tagCommentFrame").height = sh;
		}catch(e){  }//alert(e.description);
}

function iframeCommentFocus(){
	window.frames["commentFrame"].document.forms["Comment"].msg.focus();
}


function afterPostComment(){
	//alert("call stat");
	gid("statframe").src = domain_name+"home/player/inc/stat.php?pagename=MV_PLAYER&bgcolor=dadada&cgn=Music&cgs=MV_STREAMING";
}

function getMP3Download(){
	var tmpStr = "";
	//alert("downloadMusicMP3GUID"+content_meta.downloadMusicMP3GUID);
	//alert("featureSupport"+chkFeatureSupport(content_meta.featureSupport));
	if (content_meta.downloadMusicMP3GUID != "" && content_meta.downloadMusicMP3GUID != "undefined"  && content_meta.downloadMusicMP3GUID != null){
		tmpStr = "<a href='"+download_mp3_url+content_meta.songGUID+"' target='_blank'>MP3</a>";
		//tagMP3Download.className = "show";
		
		
		if(chkFeatureSupport(content_meta.featureSupport)){
			gid(t_mp3download).className = "show";
		}
		else
			gid(t_mp3download).className = "hide";
			
	}
	else
		gid(t_mp3download).className = "hide";
	
	
	return tmpStr;
}

function getMBDownload(){
	var tmpStr = "";
	
	if (content_meta.downloadMusicMP3GUID != "" && content_meta.downloadMusicMP3GUID != "undefined"  && content_meta.downloadMusicMP3GUID != null){
		tmpStr = "<a href='"+download_mb_url+content_meta.songGUID+"' target='_blank'>มือถือ</a>";
		//tagMP3Download.className = "show";
		gid(t_mbdownload).className = "show";

		if(chkFeatureSupport(content_meta.featureSupport)){
			gid(t_mbdownload).className = "show";
		}
		else
			gid(t_mbdownload).className = "hide";
	}
	else
		gid(t_mbdownload).className = "hide";
	return tmpStr;
}

function getMVDownload(){
	//alert("downloadMVGUID"+content_meta.downloadMVGUID);
	//alert("featureSupport"+chkFeatureSupport(content_meta.featureSupport));
	var tmpStr = "";
	if (content_meta.downloadMVGUID != "" && content_meta.downloadMVGUID != "undefined"  && content_meta.downloadMVGUID != null){
		tmpStr = "<a href='"+download_mv_url+content_meta.songGUID+"' target='_blank'>MV</a>";
		//tagMP3Download.className = "show";
		gid(t_mvdownload).className = "show";

		if(chkFeatureSupport(content_meta.featureSupport)){
			gid(t_mvdownload).className = "show";
		}
		else
			gid(t_mvdownload).className = "hide";
	}
	else
		gid(t_mvdownload).className = "hide";
	return tmpStr;
}
function chkFeatureSupport(featureSupport) {

	var ca = featureSupport.split(',');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		
		//alert(c + ";" + c.indexOf(nameEQ));
		if (c.indexOf("dracula") != -1) return true;
	}
	return null;
}

