var acti = null;
var isExists = false;
function checkPCClient()
{	
	if(memberCosType == 'NONE')
	{
		openDialog('dialog', 400, 259, webPath + "/popup/pop_listener_guide.jsp")
		return false;
	}
	else if(memberCosType == 'NOT_MEMBER')
	{
		openDialog('dialog', 400, 500, webPath + "/popup/pop_play_guide.jsp")
		return false;
	}
	
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		try
		{
			acti = new ActiveXObject("MIMETYPE.MimetypeCtrl.1");
		}
		catch(err)
		{
			//alert(err);
		}
	
		if (acti == null )
		{
			location.href = webPath + '/common/pcclient_down.jsp';
			return false;
		}
	}
	else
	{ 
		for (var i = 0; i < navigator.mimeTypes.length ; i++) 
		{
			if (navigator.mimeTypes[i].type == 'application/x-itst-activex')
			{
				isExists = true;
				break;
			}
		}
		
		if(!isExists)
		{
			location.href = webPath + '/common/pcclient_down.jsp';
			return false;
		}
	}
	return true;
}

function checkPCClientFree()
{	
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		try
		{
			acti = new ActiveXObject("MIMETYPE.MimetypeCtrl.1");
		}
		catch(err)
		{
			//alert(err);
		}
	
		if (acti == null )
		{
			location.href = webPath + '/common/pcclient_down.jsp';
			return false;
		}
	}
	else
	{ 
		for (var i = 0; i < navigator.mimeTypes.length ; i++) 
		{
			if (navigator.mimeTypes[i].type == 'application/x-itst-activex')
			{
				isExists = true;
				break;
			}
		}
		
		if(!isExists)
		{
			location.href = webPath + '/common/pcclient_down.jsp';
			return false;
		}
	}
	return true;
}

function fnPlay(vlu1, vlu2) 
{	
	checkFreeStreamingArray(vlu1, vlu2);
	/**original
	if(vlu1 == 0)
		jAlert('Streaming play', noExistContentsMsg);
		
	else
	{
		if(checkPCClient())
		{
			location.href = 'pcclt:/m:' + vlu2 +',/t:' +vlu1;
		}
	}
	**/
	
	/*
	else
		PlayerWindow = window.open(webPath + '/player/aod/update.jsp?musicId='+vlu+":id:","Hub_Player", "width=288, height=303, left="+((screen.width - 288)/2)+",top="+((screen.height - 303)/2) + ",status=0,resizable=0, scrollbars=0");
	*/
	
}

function fnFPlay(vlu1, vlu2) 
{	
	if(vlu1 == 0)
		jAlert('Streaming play', noExistContentsMsg);
		
	else
	{
		if(checkPCClientFree())
		{
			location.href = 'pcclt:/m:' + vlu2 +',/t:' +vlu1;
		}
	}
}

function fnScrapMv(vlu1, vlu2)
{
	$.get(webPath + "/action/get_songcode.jsp?mvFileId=" + vlu1, function(data){
		if(data =="")
			jAlert("Warning", noStremingMsg);
		else 
			checkFreeStreamingArray(data, vlu2)
	});
}

function fnMv(vlu1, vlu2) {
	checkFreeStreamingArray(vlu1, vlu2);
	/**original
	if(vlu1 == 0)
	{
		jAlert('Streaming play', noExistContentsMsg);
	}
	else
	{
		if(checkPCClient())
			location.href = 'pcclt:/m:' + vlu2 +',/t:' +vlu1;
	}
	**/
	/*
	else
	{
		opUrl = webPath + "/player/vod/update.jsp?count=0&musicId="+vlu+":id:";
		window.open(opUrl, "Hub_PlayerMV","toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no,scrollbars=no,resizable=no,width=345,height=458");
	}
	*/
}

function fnPlaySelect(vlu) 
{
	var f = document.frm;
	var tmpMusicId = "";
	var chk = false;
	var svc_chk = false;
	
	if(f.musicId == null)
		return false;
	
	if(f.musicId.value != null)
	{
		tmpMusicId = f.musicId.value;
		if(f.musicId.checked == true) 
			chk = true;
		if(tmpMusicId != "0")
			svc_chk = true;
	}
	else
	{
		for (var i=0;i<f.musicId.length;i++) 
		{
			var idValue = f.musicId[i];
			if(idValue.checked == true) {
	 			chk = true;
	 			 
	 			if (idValue.value != "0") {
					svc_chk = true;
					tmpMusicId = tmpMusicId + ":" + idValue.value;
				}
	        }
		}
		tmpMusicId = tmpMusicId.substring(1);
	}
	
	if (chk && !svc_chk) {
		jAlert('Alert', noStremingMsg);
		return;
	}

	if(chk == true )
		fnPlay(tmpMusicId, vlu)  
		//window.open(webPath + '/player/aod/update.jsp?musicId='+tmpMusicId,"Hub_Player","left=0, top=0, location=0, toolbar=no, directories=no,status=no,menubar=no,scrollbars=no,resizable=no, width=288,height=303");
	else 
		jAlert('Alert', checkContentMsg);
		
	return;
}

function fnFPlaySelect(vlu) 
{
	var f = document.frm;
	var tmpMusicId = "";
	var chk = false;
	var svc_chk = false;
	
	if(f.musicId == null)
		return false;
	
	if(f.musicId.value != null)
	{
		tmpMusicId = f.musicId.value;
		if(f.musicId.checked == true) 
			chk = true;
		if(tmpMusicId != "0")
			svc_chk = true;
	}
	else
	{
		for (var i=0;i<f.musicId.length;i++) 
		{
			var idValue = f.musicId[i];
			if(idValue.checked == true) {
	 			chk = true;
	 			 
	 			if (idValue.value != "0") {
					svc_chk = true;
					tmpMusicId = tmpMusicId + ":" + idValue.value;
				}
	        }
		}
		tmpMusicId = tmpMusicId.substring(1);
	}
	
	if (chk && !svc_chk) {
		jAlert('Alert', noStremingMsg);
		return;
	}

	if(chk == true )
		fnFPlay(tmpMusicId, vlu)  
		//window.open(webPath + '/player/aod/update.jsp?musicId='+tmpMusicId,"Hub_Player","left=0, top=0, location=0, toolbar=no, directories=no,status=no,menubar=no,scrollbars=no,resizable=no, width=288,height=303");
	else 
		jAlert('Alert', checkContentMsg);
		
	return;
}

function fnAllChk() {
	var f = document.frm;

	if(f.musicId == null)
		return false;
	
	
	var chklen = f.musicId.length ;
	//alert(chklen);
	if (chklen==undefined) {
		if (f.allCheck.checked==true) {
			f.musicId.checked = true;
			f.fileId.checked = true;
			f.UMId.checked = true;
		} else {
			f.musicId.checked = false;
			f.fileId.checked = false;
			f.UMId.checked = false;
		}
	}

	if (f.allCheck.checked==true) {
		for (var ii=0;ii<chklen;ii++) {
			f.musicId[ii].checked = true;
			f.fileId[ii].checked = true;
			f.UMId[ii].checked = true;
		}
	 } else {
		for (var ii=0;ii<chklen;ii++) {
			f.musicId[ii].checked = false;
			f.fileId[ii].checked = false;
			f.UMId[ii].checked = false;
		}
	 }
}

function CheckChk() {
	var f = document.frm;
	var sum = 0;
	
	if(f.musicId == null)
		return false;
	
	var checklen = f.musicId.length;
	
	if (checklen==undefined) {
		if (f.musicId.checked==true) {
			sum = 1;
		}
	}

	for (var ii=0;ii<f.musicId.length;ii++) {
		if (f.musicId[ii].checked==false) {
			sum += sum;
			} else {
			sum += 1;
		}
	}

	if (sum==0) {
		jAlert("Warning", selectContentMsg); 
		//winOPC('/web/popup/check_pop.jsp?checkgubun=selectcheck1','checkPop','270','130');
		return false;
	} else {
		return true;
	}
}

// hidden fileId check
function fnSameChk() {
	var f = document.frm;
	if(f.musicId == null)
		return false;
	
	var chklen = f.musicId.length ;
	
	if (chklen==undefined) {
		if (f.musicId.checked==true) {
			f.musicId.checked = true;
			f.fileId.checked = true;
			f.UMId.checked = true;
		} else {
			f.musicId.checked = false;
			f.fileId.checked = false;
			f.UMId.checked = false;
		}
	}

	for (var ii=0;ii<f.musicId.length;ii++) {
		if (f.musicId[ii].checked==false) {
			f.fileId[ii].checked = false;
			f.UMId[ii].checked = false;
			} else {
			f.fileId[ii].checked = true;
			f.UMId[ii].checked = true;
		}
	}
}

function fnPutAlbum() {
	var f = document.frm;
	var tmpMusicId = '';
	var cntTag = 0;

	if(f.fileId == null)
		return false;
	
	if (f.fileId.value != null) 
	{
		tmpMusicId = f.fileId.value;
	}
	else
	{
		for (var ii=0;ii<f.fileId.length;ii++) {
			if (f.fileId[ii].checked==true) {
				if (cntTag == 0) {
				tmpMusicId = tmpMusicId + f.fileId[ii].value;
				} else if (cntTag >= 1) {
					tmpMusicId = tmpMusicId +':'+f.fileId[ii].value;
				}
				cntTag += 1;
			}
		}
	}

	if (!CheckChk()) {
		return;
	} else {
		openDialog('dialog', 600, 210, webPath + '/popup/pop_put_album.jsp?fileId=' + tmpMusicId);
	}
}

function fnPut(vlu) {
	openDialog('dialog', 600, 210, webPath + '/popup/pop_put_album.jsp?fileId=' + vlu);
}

function fnWishList() {
	var f = document.frm;
	var tmpFileId = '';
	var cntTag = 0;

	if(f.fileId == null)
		return false;
	
	if (f.fileId.value != null) 
	{
		tempMusicId = f.fileId.value;
	}
	else
	{
		for (var ii=0;ii<f.fileId.length;ii++) {
			if (f.fileId[ii].checked==true) {
				if (cntTag == 0) {
				tmpFileId = tmpFileId + f.fileId[ii].value;
				} else if (cntTag >= 1) {
					tmpFileId = tmpFileId +'|'+f.fileId[ii].value;
				}
				cntTag += 1;
			}
		}
	}
	
	if (!CheckChk()) {
		return;
	} else {
		
		$('#frm').ajaxSubmit(function(responseText){ 
			jAlert("add wishlist", responseText);
		});	
	}
}

function fnWishListInDetail(umid) {
	$.get(webPath + "/action/wishlist_action.jsp?UMId=" + umid, function(data){
			jAlert("WishList", data);
	});
}

function fnMobile(vlu) {
	var f = document.frm;
	winOPC2('','MOBILEPOP','405','413');
	f.target = "MOBILEPOP";
	f.method = "post";
	f.action = "/web/popup/rtset_pop02.jsp?fileId="+vlu;
	f.submit();
}

function fnAlbumDet(val1, val2) {
	//var f = document.frm;
	//	f.fileId.value = val1;
	//	f.artistId.value = val2;
	//	f.method="get";
	//	f.action = "/web/common/album_info.jsp?fileId="+val1+"&artistId="+val2;
		location.href="/web/common/album_info.jsp?fileId="+val1+"&artistId="+val2;
	//	f.submit();
}

function fnArtistDet(val) {
	//var f = document.frm;
	//	f.artistId.value = val;
	//	f.method="get";
	//	f.action = "/web/common/artist_info.jsp";
		location.href="/web/common/artist_info.jsp?artistId="+val;
	//	f.submit();
}

function fnSongDet(val)
{
	//var f = document.frm;
	//f.fileId.value = val;
	//f.action = "/web/common/song_info.jsp";
	//f.submit();
	location.href="/web/common/song_info.jsp?fileId="+val;
}

function fnPlayAll(vlu) {
	$.get(webPath + "/action/get_songcode.jsp?catId=" + vlu, function(data){
		if(data =="")
			jAlert("Warning", noStremingMsg);
		else 
			//PlayerWindow = window.open(webPath + '/player/aod/update.jsp?musicId='+data+":id:","Hub_Player", "width=288, height=303, left="+((screen.width - 288)/2)+",top="+((screen.height - 303)/2) + ",status=0,resizable=0, scrollbars=0");
  			fnPlay(data, vlu);
	});
}

function fnPlayAlbum(vlu1, vlu2) {
	/** original
	$.get(webPath + "/action/get_songcode.jsp?albumId=" + vlu1, function(data){
		if(data =="")
			jAlert("Warning", noStremingMsg);
		else if(checkPCClient())
			location.href = 'pcclt:/m:' + vlu2 + ',/t:' +data; 
	});
	**/
	
	$.get(webPath + "/action/get_songcode.jsp?albumId=" + vlu1, function(data){
		if(data =="")
			jAlert("Warning", noStremingMsg);
		else 
			checkFreeStreamingArray(data, vlu2)
	});
}

function fnPlaySharingAlbum(vlu1, vlu2) {	
	checkFreeStreamingList(vlu1, vlu2);
	
	/**
	if(checkPCClient())
	{
		location.href = 'pcclt:/m:' + vlu2 + ',/p:' +vlu1;
	}
	
	**/
	/*
	$.get(webPath + "/action/get_songcode.jsp?playListId=" + vlu, function(data){
		if(data =="")
			jAlert("Warning", noStremingMsg);
		else 
  			fnPlay(data);
	});
	*/
}


function fnLyric(vlu, vlu2) {

	if(vlu2 == 0)
		winOPC2('/web/popup/lyrics_pop.jsp?fileId='+vlu+'&flag='+vlu2,'LYRICPOP','376','455');
	else if(vlu2 == 1)
		winOPC2('/web/popup/lyrics_pop.jsp?fileId='+vlu+'&flag='+vlu2,'LYRICPOP','376','510');
}

function fnAlbumList() {
		location.href="album_list.jsp";
}

function fnAlbumScrap(vlu) {
	$.get(webPath + "/action/albumscrap_action.jsp?UMIds=" + vlu, function(data){
		jAlert('scrap album', data);
	});
}

function fnMvScrap(vlu) {
	$.get(webPath + "/action/mvscrap_action.jsp?UMIds=" + vlu, function(data){
		jAlert('scrap music video', data);
	});
}

function fnFavoriteSong(vlu1, vlu2) {
	var f = document.frm;

	if (vlu2=='M') {
		if (!CheckChk()) {
		return;
		} else {
			winOPC('','Hub_Player','374','209');
			f.target = "Hub_Player";
			f.method = "post";
			f.action = "/web/popup/favoritesong_action.jsp";
			f.submit();
		}
	} else {
		winOPC('/web/popup/favoritesong_action.jsp?UMId='+vlu1,'Hub_Player','374','209');
	}
	
}

function fnRing4u(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?fileId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','441');
}

function fnRingtone(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?fileId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','441');
}

function fnFullsong(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?fileId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','441');
}

function fnContentsDown(vlu1) {
	winOPC2(vlu1,'MOBILEPOP','405','441');
}

function fnMvideo(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?fileId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','441');
}

function fnCuttingRbt(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?fileId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','441');
}

function fnCuttingRt(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?fileId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','441');
}

function fnKaraokeCuttingRbt(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?cCtntId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','441');
}

function fnKaraokeCuttingRt(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?cCtntId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','441');
}

function fnGift(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?fileId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','413');
}

function fnBegging(vlu1,vlu2,vlu3) {
	winOPC2('/web/popup/rtset_pop02.jsp?fileId='+vlu1+'&giftType='+vlu2+'&kind='+vlu3,'MOBILEPOP','405','432');
}

function fnAccomp(vlu) 
{
	winOPC2('/web/popup/rtset_pop_karaoke.jsp?fileId='+vlu,'MOBILEPOP','405','441');
}


function checkFreeStreamingList(vlu1, vlu2){
	if(vlu1 == 0)
		jAlert('Streaming play', noExistContentsMsg);
	else
	{
		$.get(webPath + "/action/check_free_streaming.jsp?musicId=" + vlu1 + "&type=list" , function(data){
			if(data == 'free')
			{
				if(checkPCClientFree())
				{
					location.href = 'pcclt:/m:' + vlu2 + ',/p:' +vlu1;
				}
			}
			else
			{
				if(checkPCClient())
				{
					location.href = 'pcclt:/m:' + vlu2 + ',/p:' +vlu1;
				}
			}
		});
	}
}

function checkFreeStreamingArray(vlu1, vlu2){
	if(vlu1 == 0)
		jAlert('Streaming play', noExistContentsMsg);
	else
	{
		$.get(webPath + "/action/check_free_streaming.jsp?musicId=" + vlu1 + "&type=array", function(data){
			if(data == 'free')
			{
				if(checkPCClientFree())
				{
					location.href = 'pcclt:/m:' + vlu2 + ',/t:' +vlu1;
				}
			}
			else
			{
				if(checkPCClient())
				{
					location.href = 'pcclt:/m:' + vlu2 +',/t:' +vlu1;
				}
			}
		});
	}
}