﻿var popup = null;
var tempTxt;
var opened=false;
var tableListTrack


	function addToplay(folder,trackId) {
	    popup = window.open('','Top1MusicMediaPlayer', 'toolbar=no,width=700,height=520');	   		   	

		if ((popup.location == 'about:blank') || (wL.toLowerCase() == pL.toLowerCase())) { 
            popup.location = 'http://music.top1.vn/play/' + folder + '/' + trackId + '.htm';
            popup.focus();
        } else {
            
        }
	    
	function addToplayForMember(folder,trackId) {
	    popup = window.open('','Top1MusicMediaPlayer', 'toolbar=no,width=700,height=520');
	   	
		if ((popup.location == 'about:blank') || (wL.toLowerCase() == pL.toLowerCase())) {        
            popup.location = 'http://music.top1.vn/playmember/' + folder + '/' + trackId + '.htm';
            popup.focus();
        } else {                      
        }	   	   	    
	}
	
	function addToplayForMember1(folder,trackId) {	  
	    popup = open('http://music.top1.vn/playmember/' + folder + '/' + trackId + '.htm','Top1MusicMediaPlayer', 'toolbar=no,width=700,height=520');	   
	}   
	    
	}
	function addToplay1(folder,trackId) {	  
	    popup = open('http://music.top1.vn/play/' + folder + '/' + trackId + '.htm','Top1MusicMediaPlayer', 'toolbar=no,width=700,height=520');	   		    	    	    
	}
	
	var thinhTrackName;
	var thinhGenerName;	
	
	function addTrackNameAndAlbumName(trackName,generName)
	{
	    thinhTrackName=null;
	    thinhGenerName=null;
	    thinhTrackName=trackName;
	    thinhGenerName=generName;	   
	}
	
	function play(folder,trackId) {	  	    	    
	        if (!popup) {	
	            addToplay(folder,trackId);    	           	           	           	  
   	        } else {
	            if (popup.closed) {
	            
	             addToplay1(folder,trackId);   	                 	  	               	               	                             
	            }  else {
	                 tableListTrack = popup.document.getElementById('table-1');
	                 tbody_track = popup.document.getElementById('table-1').tBodies[0];   	     
            	     
	                var newRow = tbody_track.insertRow(tbody_track.rows.length);
            	    
    	            popup.document.getElementById('maxTrack').innerHTML = '<input type=hidden value='+tbody_track.rows.length+' name=max_track >';
            	    
	                newRow.style.cursor='move';
	                newRow.id = tbody_track.rows.length;	
        	              
	                var newCell0 = newRow.insertCell(0);
	                newCell0.style.width = '1%';
	                var newCell1 = newRow.insertCell(1);
	               var newCell2 = newRow.insertCell(2);
	                newCell2.className = "ta-c";
	                newCell2.style.width="1%";
	                newCell2.noWrap="nowrap";   	    
	                newCell0.innerHTML = cell_0(trackId,thinhTrackName,thinhGenerName);	   
	                newCell1.innerHTML = cell_1(folder,tbody_track.rows.length,thinhTrackName,thinhGenerName);	     

	                popup.focus();              
                    playlistData=popup.document.getElementById('playlist_data'); 
                    playlistData.innerHTML +='<input type=hidden name=track_item id=track_item_'+(tbody_track.rows.length-1)+  ' value='+trackId+' />';           
   	            }   	       	    
   	    }
}	
//  Play for member
function playForMember(folder,trackId) {	  	    	    
        if (!popup) {	
            addToplayForMember(folder,trackId);    	           	           	           	  
        } else {
            if (popup.closed) {
            
             addToplayForMember1(folder,trackId);   	                 	  	               	               	                             
            }  else {
                 tableListTrack = popup.document.getElementById('table-1');
                 tbody_track = popup.document.getElementById('table-1').tBodies[0];   	     
        	     
                var newRow = tbody_track.insertRow(tbody_track.rows.length);
        	    
	            popup.document.getElementById('maxTrack').innerHTML = '<input type=hidden value='+tbody_track.rows.length+' name=max_track >';
        	    
                newRow.style.cursor='move';
                newRow.id = tbody_track.rows.length;	
    	              
                var newCell0 = newRow.insertCell(0);
                newCell0.style.width = '1%';
                var newCell1 = newRow.insertCell(1);
               var newCell2 = newRow.insertCell(2);
                newCell2.className = "ta-c";
                newCell2.style.width="1%";
                newCell2.noWrap="nowrap";   	    
                newCell0.innerHTML = cell_0(trackId,thinhTrackName,thinhGenerName);	   
                newCell1.innerHTML = cell_1(folder,tbody_track.rows.length,thinhTrackName,thinhGenerName);	     

                popup.focus();              
                playlistData=popup.document.getElementById('playlist_data'); 
                playlistData.innerHTML +='<input type=hidden name=track_item id=track_item_'+(tbody_track.rows.length-1)+  ' value='+trackId+' />';           
            }
   	    }
    }
// End play for member
	function addToplayForMember(folder,trackId) {
	    popup = window.open('','Top1MusicMediaPlayer', 'toolbar=no,width=700,height=520');
	   	
		if ((popup.location == 'about:blank') || (wL.toLowerCase() == pL.toLowerCase())) {        
            popup.location = 'http://music.top1.vn/playmember/' + folder + '/' + trackId + '.htm';
            popup.focus();
        } else {                      
        }	   	   	    
	}
	
	function addToplayForMember1(folder,trackId) {	  
	    popup = open('http://music.top1.vn/playmember/' + folder + '/' + trackId + '.htm','Top1MusicMediaPlayer', 'toolbar=no,width=700,height=520');	   
	}



//  Play for member
function playForMember(folder,trackId) {	  	    	    
        if (!popup) {	
            addToplayForMember(folder,trackId);    	           	           	           	  
        } else {
            if (popup.closed) {
            
             addToplayForMember1(folder,trackId);   	                 	  	               	               	                             
            }  else {
                 tableListTrack = popup.document.getElementById('table-1');
                 tbody_track = popup.document.getElementById('table-1').tBodies[0];   	     
        	     
                var newRow = tbody_track.insertRow(tbody_track.rows.length);
        	    
	            popup.document.getElementById('maxTrack').innerHTML = '<input type=hidden value='+tbody_track.rows.length+' name=max_track >';
        	    
                newRow.style.cursor='move';
                newRow.id = tbody_track.rows.length;	
    	              
                var newCell0 = newRow.insertCell(0);
                newCell0.style.width = '1%';
                var newCell1 = newRow.insertCell(1);
               var newCell2 = newRow.insertCell(2);
                newCell2.className = "ta-c";
                newCell2.style.width="1%";
                newCell2.noWrap="nowrap";   	    
                newCell0.innerHTML = cell_0(trackId,thinhTrackName,thinhGenerName);	   
                newCell1.innerHTML = cell_1(folder,tbody_track.rows.length,thinhTrackName,thinhGenerName);	     

                popup.focus();              
                playlistData=popup.document.getElementById('playlist_data'); 
                playlistData.innerHTML +='<input type=hidden name=track_item id=track_item_'+(tbody_track.rows.length-1)+  ' value='+trackId+' />';           
            }
   	    }
    }   	   
//Play album*****************************************************

	function addToplayAlbum(auth,albumId) {
	    popup = window.open('http://music.top1.vn/WebSite/pages/mediaPlayer.aspx?albumId=' + albumId +'&auth='+auth,     'Top1MusicMediaPlayer', 'toolbar=no,width=700,height=520');	
	}
	
	function playAlbum(auth, albumId) {	
	    addToplayAlbum(auth, albumId);     	    	    	   		   
	}   

	//Play list*****************************************************
	function addToplayList(auth, listId) {
	    popup = window.open('http://music.top1.vn/WebSite/pages/mediaPlayer.aspx?listId=' + listId + '&auth='+auth,     'Top1MusicMediaPlayer', 'toolbar=no,width=700,height=520');	
	}
	
	function playPlayList(auth, listId) {	 
	    addToplayList(auth, listId);  	
    }
    //********************************
    function openPlayList(trackid) {
	    popup = window.open('http://music.top1.vn/myplaylist/' + trackid + '.htm', "displayWindow", 'toolbar=no,width=400,height=270,top=300, left=400,scrollbars=yes,resizable=no');	    
	}
	function sendEmail(trackid,url) {
	    popup = window.open('http://music.top1.vn/sendemail/' + trackid + '.htm?url='+url, "displayWindow", 'toolbar=no,width=450,height=410,top=100, left=400,scrollbars=no,resizable=no');	    
	}
	
	//********************************
    	function errorMessage(trackid) {
	    popup = window.open('http://music.top1.vn/error/' + trackid + '.htm', "displayWindow", 'toolbar=no,width=250,height=50,top=300, left=250,scrollbars=0,resizable=0');	    
	}
	
function IsBlocked(popupwin){
    if(!popupwin) return true;
    try{
        return popupwin.closed;
    }
    catch(e){
        return true;
    }
}

var buildMediaOK = false;
	function playBackGround(folder,trackId) {
	    	  	    	    	    
	    if (bWin32IE) {

            if (!buildMediaOK) {
                if (IsBlocked(popup)) { 
                    document.getElementById('mediaPlayerInsite').innerHTML = buildMediaToPlayInsite(folder,trackId);
                    updateTrackInfoPlayerInsite(thinhGenerName,thinhTrackName)
                    document.getElementById('main-player').style.display='';
                    opened = false;
                  
                } else {
                 opened = true;
                }
                buildMediaOK = true;	 
                updatePlayStatusIcon(trackId, 3)
                preTrack=trackId;                          	                        
		     } else {					     					          
                    document.getElementById('Top1MusicMedia').URL="http://music.top1.vn/stream/" + folder + "/" + trackId+".htm";
                    document.getElementById('Top1MusicMedia').src="http://music.top1.vn/stream/" + folder + "/" + trackId+".htm";                                
                    updateTrackInfoPlayerInsite(thinhGenerName,thinhTrackName);	
                    updatePlayStatusIcon(preTrack, 44)  
                    updatePlayStatusIcon(trackId, 3)
		            preTrack=trackId; 							 					     
		     }
				mediaPlay();
				document.getElementById('album_link').focus(); 			        
	    } 
}


function buildMediaToPlayInsite(folder, order) {

link = "http://music.top1.vn/stream/" + folder + "/" + order+".htm"
																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																							
        var HTML;
        
        HTML=('<OBJECT id="Top1MusicMedia" codeBase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" type="application/x-oleobject"');
        HTML+=('height="95"');
        HTML+=('width="502"');
        HTML+=('standby="Loading Microsoft Windows Media Player components..."');
        HTML+=('classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"');
        HTML+=('name="winMediaPlayer">');
        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="0">');
        HTML+=('<PARAM NAME="playCount" VALUE="'+ 1 +'">');
        HTML+=('<PARAM NAME="CursorType" VALUE="-1">');
        HTML+=('<PARAM NAME="autoStart" VALUE="TRUE">');
        HTML+=('<PARAM NAME="currentMarker" VALUE="0">');       
        HTML+=('<PARAM NAME="volume" VALUE="100">');
        HTML+=('<PARAM NAME="mute" VALUE="0">');
        HTML+=('<PARAM NAME="stretchToFit" VALUE="-1"> ');
        HTML+=('<PARAM NAME="windowlessVideo" VALUE="0"> ');
        HTML+=('<PARAM NAME="enabled" VALUE="1">');
        HTML+=('<PARAM NAME="fullScreen" VALUE="0">');
        HTML+=('<PARAM NAME="enableContextMenu" VALUE="0">');
        HTML+=('<PARAM NAME="enableErrorDialogs" VALUE="0">');
        HTML+=('<EMBED  type="application/x-mplayer2"');
        HTML+=('id="wmpEmbed"');
        HTML+=('pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"');
        HTML+=('src="'+ link +'"');
        HTML+=('name="MediaPlayerMusicTop1"');
        HTML+=('height="170"');
        HTML+=('width="365"');
        HTML+=('AutoSize="1"');
        HTML+=('loop="TRUE"');
        HTML+=('AutoStart="TRUE"');
        HTML+=('DisplaySize="1"');
        HTML+=('EnableContextMenu="0"');
        HTML+=('EnableFullScreenControls="1"');
        HTML+=('EnableTracker="1"');
        HTML+=('Mute="0"');
        HTML+=('PlayCount="'+ 1 +'"');
        HTML+=('ShowControls="1"');
        HTML+=('ShowAudioControls="1"');
        HTML+=('ShowDisplay="0"');
        HTML+=('ShowGotoBar="0"');
        HTML+=('ShowPositionControls="1"');
        HTML+=('ShowStatusBar="1"');
        HTML+=('ShowTracker="1">');
        HTML+=('</EMBED>'); 
        HTML+=('</OBJECT>');

return  HTML;
} 

function updateTrackInfoPlayerInsite(thinhGenerName,thinhTrackName) {   
    var albumInfo='';
   
    albumInfo+='<img id="album_image" src="'+thinhGenerName+'" class="fl mr-10 di"';
    albumInfo+=   'width="80px" height="80px">';
    albumInfo+= '<div style="height: 70px; width: 300px" class="fr">';
    albumInfo+=  ' <span class="f-gray f-13"><a class="f-orange f-bold">';
    albumInfo+=  ' <span class="f-orange f-bold f-13" id="song_name"><img src="http://music.top1.vn/Website/images/css/icons/pls.gif"/ >'+thinhTrackName+'</span></a><br />';
    albumInfo+=  'Album:<a id="album_link" onclick="mediaPlay();" href="#" target="blank"><span id="album_name">Đang cập nhật</span></a><br>';
    albumInfo+=  ' </span>';
    albumInfo+=  ' <div class="divider">';
    albumInfo+=  ' </div>';
    albumInfo+=   '<div class="f-orange f-13">';
    albumInfo+=       'Thể hiện :<a id="artist_link" ><span id="artist_name">Đang cập nhật</span> </a>';     
    albumInfo+=  '  <div class="divider">';
    albumInfo+=  '</div>';
    albumInfo+= '  <div class="f-orange f-13">';
    albumInfo+=      'Thể loại :<a id="genre_link"><span id="genre_name">Đang cập nhật</span></a>';
    albumInfo+=  ' </div>';
    albumInfo+=  ' </div>';
        
    document.getElementById('artist_123123').innerHTML=albumInfo;   
}


function copy(text2copy) {
  if (window.clipboardData) {
	window.clipboardData.setData("Text",text2copy);
  } else {
  }
  alert("Đã copy. Bạn chỉ việc dán (paste)!");
}