// JavaScript Document
/*
load album hot
*/
if($("#nfHome_AlbumHotOther1").length > 0) {		
	if($("#nfHome_AlbumHotOther1").html().length < 1 && $("#nfHome_AlbumHotOther2").html().length < 1) {		
		$("div.footer-main").hide();
		//$.get("/xml/newface_block_albumhot.xml?"+(new Date()).getTime(),{},function(xml){
		$.get("/xml/newface_block_albumhot.xml",{},function(xml){
			var temp = '';
			var	k = 1;
			myHTMLOutput = '';
			$('item',xml).each(function(i) {								
				if(k < 5){						
					myHTMLOutput = myHTMLOutput +  decodeURI($(this).find("description").text());					
				}else{
					temp = temp +  decodeURI($(this).find("description").text());
				}
				k++;
			});			
			$("#nfHome_AlbumHotOther1").append(myHTMLOutput+'<br class="clr" />');			
			$("#nfHome_AlbumHotOther2").append(temp+'<br class="clr" />');			
			$("div.footer-main").show();
		});
	}
}
/*
load ca khuc moi
*/
if($("#nfHome_SongNew1").length > 0) {		
	if($("#nfHome_SongNew1").html().length < 1) {		
		$("div.footer-main").hide();				
		//$.get("/xml/newface_block_songsnew1.xml?"+(new Date()).getTime(),{},function(xml){      					 					
		 $.get("/xml/newface_block_songsnew1.xml",{},function(xml){      					 					
			myHTMLOutput = '';
			$('item',xml).each(function(i) {								
				myHTMLOutput = myHTMLOutput +  $(this).find("description").text();
			});			
			$("#nfHome_SongNew1").append(myHTMLOutput);	
			$("div.footer-main").show();
			clickAAddToCart();
		});		
	}
}

/*
load ca si hot
*/
if($("#nfHome_SingerHot1").length > 0 && $("#nfHome_SingerList1").length > 0) {		
	if($("#nfHome_SingerHot1").html().length < 1 && $("#nfHome_SingerList1").html().length < 1) {	
		//$.get("/xml/newface_block_hotsinger1.xml?"+(new Date()).getTime(),{},function(xml){ 
		$.get("/xml/newface_block_hotsinger1.xml",{},function(xml){ 
			myHTMLOutput = '';
			var k = 1;
			var temp1 = '';
			var temp2 = '';
			var temp3 = '';
			$('item',xml).each(function(i) {	
				if(k == 1)
					myHTMLOutput = myHTMLOutput +  $(this).find("description").text();
				else if(k < 5)
					temp3  = temp3 + $(this).find("description").text();
				else if(k < 10)
					temp1  = temp1 + $(this).find("description").text();
				else
					temp2  = temp2 + $(this).find("description").text();
				k++;
			});					
			$("#nfHome_SingerHot1").append(myHTMLOutput);
			$("#nfHome_SingerList1").append(temp3+'<br class="clr" />');
			$("#nfHome_SingerHotS11").append(temp1);
			$("#nfHome_SingerHotS21").append(temp2);		
			clickChangeHotSinger();
		});
	}
}
/*
load qua tang am nhac
*/
if($("#nfHome_RequestMusic").length > 0) {		
	if($("#nfHome_RequestMusic").html().length < 1) {	
		//$.get("/xml/newface_block_request.xml?"+(new Date()).getTime(),{},function(xml){ 
		$.get("/xml/newface_block_request.xml",{},function(xml){ 
			myHTMLOutput = '';			
			$('item',xml).each(function(i) {
				//myHTMLOutput = myHTMLOutput +  decodeURI($(this).find("description").text());
				myHTMLOutput = myHTMLOutput + $(this).find("description").text();
			});					
			$("#nfHome_RequestMusic").append(myHTMLOutput);
			$("#nfHome_QTAN").click(function () {	
				if(checkLogin()){
					tb_show('Qua Tang Am Nhac', '/includes/NewFace_QuaTangAmNhac.php?TB_iframe=true&height=300&width=500&modal=true');
				}else{
					loadLogin('');						
				}
			});
		});
	}
}
/*
load channel z
*/
function mycarousel_itemLoadCallback(carousel, state){		
	if (carousel.has(carousel.first, carousel.last)) {
		return;
	}
	if(carousel.first == 1 || carousel.first == 4 || carousel.first == 7){
		//var filename = '/xml/newface_block_channelz'+carousel.first+".xml?"+(new Date()).getTime();
		var filename = '/xml/newface_block_channelz'+carousel.first+".xml";
		$.get(filename, {}, function(xml) {
			mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);							
		},
		'xml'
		);
	}
};
function mycarousel_itemAddCallback(carousel, first, last, xml){		
	carousel.size(parseInt($('total', xml).text()));	
	$('item', xml).each(function(i) {
		carousel.add(first + i, mycarousel_getItemHTML($(this).find("image").text(), $(this).find("title").text(), $(this).find("artist").text(), $(this).find("link").text(), $(this).find("linkartist").text()));			
	});
};
function mycarousel_getItemHTML(url, title, artist, href, linkartist)
{
	return '<a href="' + decodeURI(href) + '" target="_blank"><img src="' + decodeURI(url) + '" width="120" height="84" alt="" border = "0" class="boderpic" /></a><br /><h1><a href="' + decodeURI(href) + '" target="_blank">' +  decodeURI(title) + '</a></h1><p><a href="' + decodeURI(linkartist) + '" target="_blank">' + decodeURI(artist) +'</a></p>';
};

if($("#mycarousel").length > 0) {
	$('#mycarousel').jcarousel({        
		itemLoadCallback: mycarousel_itemLoadCallback
	});
}
/*
action of box ca khuc moi
*/
$("#nfHome_SongNewA1").click(function () {	
	$('#nfHome_SongNew2').hide();		
	$('#nfHome_SongNew3').hide();		
	$('#nfHome_SongNew4').hide();		
	$("#nfHome_SongNewA2").removeClass("CurTab");
	$("#nfHome_SongNewA3").removeClass("CurTab");
	$("#nfHome_SongNewA4").removeClass("CurTab");
	$("div.footer-main").hide();
	
	$('#nfHome_SongNew1').show();	
	$("#nfHome_SongNewA1").addClass("CurTab");	
	$("div.footer-main").show();
	
	return false;
});
$("#nfHome_SongNewA2").click(function () {	
	$('#nfHome_SongNew1').hide();		
	$('#nfHome_SongNew3').hide();		
	$('#nfHome_SongNew4').hide();		
	$("#nfHome_SongNewA1").removeClass("CurTab");
	$("#nfHome_SongNewA3").removeClass("CurTab");
	$("#nfHome_SongNewA4").removeClass("CurTab");
	$("div.footer-main").hide();	
	if($("#nfHome_SongNew2").html().length < 1) {		
		//$.get("/xml/newface_block_songsnew2.xml?"+(new Date()).getTime(),{},function(xml){
		 $.get("/xml/newface_block_songsnew2.xml",{},function(xml){
			myHTMLOutput = '';
			$('item',xml).each(function(i) {
				//myHTMLOutput = myHTMLOutput +  decodeURI($(this).find("description").text());					
				myHTMLOutput = myHTMLOutput +  $(this).find("description").text();					
			});			
			$("#nfHome_SongNew2").html(myHTMLOutput);		
			clickAAddToCart();
		});
	}
	$('#nfHome_SongNew2').show();					
	$("#nfHome_SongNewA2").addClass("CurTab");
	$("div.footer-main").show();
	setTimeout('ZME_widget_mix()', 500);

	return false;
});

$("#nfHome_SongNewA3").click(function () {	
	$('#nfHome_SongNew1').hide();		
	$('#nfHome_SongNew2').hide();		
	$('#nfHome_SongNew4').hide();		
	$("#nfHome_SongNewA1").removeClass("CurTab");
	$("#nfHome_SongNewA2").removeClass("CurTab");
	$("#nfHome_SongNewA4").removeClass("CurTab");
	$("div.footer-main").hide();
	if($("#nfHome_SongNew3").html().length < 1) {		
		//$.get("/xml/newface_block_songsnew3.xml?"+(new Date()).getTime(),{},function(xml){
		$.get("/xml/newface_block_songsnew3.xml",{},function(xml){
			myHTMLOutput = '';
			$('item',xml).each(function(i) {
				//myHTMLOutput = myHTMLOutput +  decodeURI($(this).find("description").text());					
				myHTMLOutput = myHTMLOutput + $(this).find("description").text();					
			});			
			$("#nfHome_SongNew3").html(myHTMLOutput);	
			clickAAddToCart();
		});
	}
	$('#nfHome_SongNew3').show();					
	$("#nfHome_SongNewA3").addClass("CurTab");	
	$("div.footer-main").show();
	setTimeout('ZME_widget_mix()', 500);

	return false;
});

$("#nfHome_SongNewA4").click(function () {	
	$('#nfHome_SongNew1').hide();		
	$('#nfHome_SongNew2').hide();		
	$('#nfHome_SongNew3').hide();		
	$("#nfHome_SongNewA1").removeClass("CurTab");
	$("#nfHome_SongNewA2").removeClass("CurTab");
	$("#nfHome_SongNewA3").removeClass("CurTab");
	$("div.footer-main").hide();
	if($("#nfHome_SongNew4").html().length < 1) {		
		//$.get("/xml/newface_block_songsnew4.xml?"+(new Date()).getTime(),{},function(xml){ 
		$.get("/xml/newface_block_songsnew4.xml",{},function(xml){ 
			myHTMLOutput = '';
			$('item',xml).each(function(i) {
				myHTMLOutput = myHTMLOutput + $(this).find("description").text();
			});			
			$("#nfHome_SongNew4").html(myHTMLOutput);		
			clickAAddToCart();
		});
	}
	$('#nfHome_SongNew4').show();					
	$("#nfHome_SongNewA4").addClass("CurTab");
	$("div.footer-main").show();
	setTimeout('ZME_widget_mix()', 500);

	return false;
});
/*
action of box album hot
*/
$("#nfHome_AlbumHot").click(function () {		
	$('#nfHome_AlHotNew').hide();		
	$("#nfHome_AlbumNew").removeClass("curColl");
	
	$('#nfHome_AlHotContent1').show();
	$('#nfHome_AlHotContent2').show();		
	$("#nfHome_AlbumHot").addClass("curColl");
	
	return false;
});

$("#nfHome_AlbumNew").click(function () {
	$("div.footer-main").hide();
	$('#nfHome_AlHotContent1').hide();
	$('#nfHome_AlHotContent2').hide();
	$("#nfHome_AlbumHot").removeClass("curColl");
	
	$("#nfHome_AlbumNew").addClass("curColl");
	if($("#nfHome_AlHotNew").html().length < 1) {
		//$.get("/xml/newface_block_albumnew.xml?"+(new Date()).getTime(),{},function(xml){
		$.get("/xml/newface_block_albumnew.xml",{},function(xml){
			var temp1 = '';
			var temp2 = '';
			var	k 	  = 1;
			myHTMLOutput = '';
			$('item',xml).each(function(i) {
				if(k < 3){
					myHTMLOutput = myHTMLOutput + $(this).find("description").text();
				}else if(k < 7){
					temp1 = temp1 + $(this).find("description").text();
				}else{
					temp2 = temp2 + $(this).find("description").text();
				}
				k++;
			});
			$("#nfHome_AlHotNew").append(myHTMLOutput);
			$("#nfHome_AlbumNewOther1").append(temp1+'<br class="clr" />');
			$("#nfHome_AlbumNewOther2").append(temp2+'<br class="clr" />');
		});
	}
	$('#nfHome_AlHotNew').show();
	$("div.footer-main").show();
	
	return false;
});
/*
action of box news
*/
$("#nfHome_MP3News").click(function () {
	newsTabActive($(this).attr('id'));
	
	if($("#nfHome_MP3NewsContent").html().length < 1) {
		//$.get("/xml/newface_block_newska.xml?"+(new Date()).getTime(),{},function(xml){
		$.get("/xml/newface_block_mp3news.xml",{},function(xml){
			myHTMLOutput = '<div class="col-karaoke" id="nfHome_NewsAlready">';
			var	k = 1;
			$('item',xml).each(function(i) {
				nImage	 		= $(this).find("Image").text();
				nLink 			= $(this).find("Link").text();
				nTitle 			= $(this).find("Title").text();
				nDescription 	= $(this).find("Description").text();
				mydata	= '';
				if (i == 0) {
					myHTMLOutput += '<div class="img"><a href="'+ nLink + '" target="_blank"><img src="' + nImage + '" alt="" width="152" height="119" border="0"/></a></div>';
					myHTMLOutput += '<h1><a href="' + nLink + '" target="_blank">' + nTitle + '</a></h1>' + nDescription;
				} else {
					mydata += '<p><a href="' + nLink + '" target="_blank">&raquo; ' + nTitle + ' </a></p>';
				}
				myHTMLOutput = myHTMLOutput + '<div>' + mydata + '</div><br class="clr"/>';
			});
			myHTMLOutput += '</div><br class="clr" />';		
			
			$("#nfHome_MP3NewsContent").html(myHTMLOutput);			
		});
	}		

	$('#nfHome_MP3NewsContent').show();	
	$("div.footer-main").show();
	
	return false;
});

$("#nfHome_News").click(function () {		
	newsTabActive($(this).attr('id'));

	if($("#nfHome_NewsContent").html().length < 1) {		
		//$.get("/xml/newface_block_newska.xml?"+(new Date()).getTime(),{},function(xml){
		$.get("/xml/newface_block_news.xml",{},function(xml){
			myHTMLOutput = '<div class="col-karaoke" id="nfHome_NewsAlready">';	 				
			var	k = 1;
			mydata = '';
			$('item',xml).each(function(i) {
				nImage	 		= $(this).find("image155x122").text();
				nLink 			= $(this).find("link").text();
				nTitle 			= $(this).find("title").text();							
				nDescription 	= $(this).find("description").text();
				if (i == 0) {
					myHTMLOutput += '<div class="img"><a href="'+ nLink + '" target="_blank"><img src="' + nImage + '" alt="" width="152" height="119" border="0"/></a></div>';
					myHTMLOutput += '<h1><a href="' + nLink + '" target="_blank">' + nTitle + '</a></h1>' + nDescription;
				} else {
					mydata += '<p><a href="' + nLink + '" target="_blank">&raquo; ' + nTitle + ' </a></p>';
				}
			});
			myHTMLOutput += '<div>' + mydata + '</div><br class="clr"/></div>';
			
			$("#nfHome_NewsContent").html(myHTMLOutput);			
		});
	}		

	$('#nfHome_NewsContent').show();	
	$("div.footer-main").show();
	
	return false;
});

$("#nfHome_Karaoke").click(function () {	
	newsTabActive($(this).attr('id'));

	if($("#nfHome_KaContent").html().length < 1) {		
		//$.get("/xml/newface_block_newska.xml?"+(new Date()).getTime(),{},function(xml){
		$.get("/xml/newface_block_newska.xml",{},function(xml){
			myHTMLOutput = '<div class="col-karaoke" id="nfHome_KaAlready">';	 				
			var	k = 1;
			$('item',xml).each(function(i) {
				kaTitle 	= $(this).find("title").text();
				kaLink 		= $(this).find("link").text();
				kaCreator 	= $(this).find("creator").text();							
				mydata = '<h2><a href="'+kaLink+'" target="_blank">'+kaTitle+'</a></h2><p><a href="'+kaLink+'" target="_blank">'+kaCreator+'</a></p>';				
				myHTMLOutput = myHTMLOutput + mydata;
				if(k == 5){
					myHTMLOutput = myHTMLOutput + '</div><div class="col-karaoke">';
				}
				k++;
			});
			myHTMLOutput += '</div><br class="clr" />';		
			
			$("#nfHome_KaContent").html(myHTMLOutput);			
		});
	}		
	$("#nfHome_KaContent").show();
	$("div.footer-main").show();
	
	return false;
});

$("#nfHome_Photo").click(function () {
	newsTabActive($(this).attr('id'));

	if($("#nfHome_PhotoContent").html().length < 1) {		
		//$.get("/xml/newface_block_newsphoto.xml?"+(new Date()).getTime(),{},function(xml){ 
		$.get("/xml/newface_block_newsphoto.xml",{},function(xml){ 
			myHTMLOutput = '<div class="rwPhoto" id="nfHome_PhoAlready">';	 				
			var	k = 1;
			$('item',xml).each(function(i) {
				if(k < 5){
					phoTitle 	= $(this).find("title").text();
					phoLink 	= $(this).find("link").text();
					thumb 		= $(this).find("thumbnail").text();							
					mydata = '<div class="colPhoto"><div class="imgPhoto"><a href="'+phoLink+'"><img width="99" height="99" src="'+thumb+'" border="0"/></a></div><h1><a href="'+phoLink+'">'+phoTitle+'</a></h1></div>';				
					myHTMLOutput = myHTMLOutput + mydata;					
					k++;
				}
			});
			myHTMLOutput += '<br class="clr"/></div>';		
			
			$("#nfHome_PhotoContent").html(myHTMLOutput);			
		});
	}	
	$("#nfHome_PhotoContent").show();
	$("div.footer-main").show();
	
	return false;
});

$("#nfHome_Forum").click(function () {
	newsTabActive($(this).attr('id'));

	if($("#nfHome_4rContent").html().length < 1) {		
		//$.get("/xml/newface_block_newsforum.xml?"+(new Date()).getTime(),{},function(xml){   
		$.get("/xml/newface_block_newsforum.xml",{},function(xml){   
			myHTMLOutput = '<div class="col-karaoke" id="nfHome_FrAlready">';	 				
			var	k = 1;
			$('item',xml).each(function(i) {
				if(k < 11){
					frTitle 	= $(this).find("title").text();
					frLink 		= $(this).find("link").text();
					frCreator 	= $(this).find("author").text();							
					mydata = '<h2><img src="'+GLOBAL_IMAGE_PATH+'skins/gentle/images/ico_forum.gif"> <a href="'+frLink+'" target="_blank">'+frTitle+'</a></h2><p>bởi '+frCreator+'</p>';				
					myHTMLOutput = myHTMLOutput + mydata;
					if(k == 5){
						myHTMLOutput = myHTMLOutput + '</div><div class="col-karaoke">';
					}								
					k++;
				}
			});
			myHTMLOutput += '</div><br class="clr" />';					
			$("#nfHome_4rContent").html(myHTMLOutput);			
		});
	}	
	$("#nfHome_4rContent").show();
	$("div.footer-main").show();
	
	return false;
});
/*
action of ca si hot
*/
function clickChangeHotSinger(){
	$("a.nfHome_SingerHotA").click(function () {	
		var id = $(this).attr("id").split("h");			
		$('#nfHome_SingerHot1').hide();
		$('#nfHome_SingerHot2').hide();
		$('#nfHome_SingerHot3').hide();
		$('#nfHome_SingerList1').hide();
		$('#nfHome_SingerList2').hide();
		$('#nfHome_SingerList3').hide();
		if($("#nfHome_SingerHot"+id[1]).html().length < 1 && $("#nfHome_SingerList"+id[1]).html().length < 1) {			
			//$.get("/xml/newface_block_hotsinger"+id[1]+".xml?"+(new Date()).getTime(),{},function(xml){
			$.get("/xml/newface_block_hotsinger"+id[1]+".xml",{},function(xml){
				myHTMLOutput = '';
				var k = 1;
				var temp1 = '';
				var temp2 = '';
				var temp3 = '';
				$('item',xml).each(function(i) {	
					if(k == 1)
						myHTMLOutput = myHTMLOutput +  $(this).find("description").text();
					else if(k < 5)
						temp3  = temp3 +  $(this).find("description").text();
					else if(k < 10)
						temp1  = temp1 +  $(this).find("description").text();
					else
						temp2  = temp2 +  $(this).find("description").text();
					k++;
				});					
				$("#nfHome_SingerHot"+id[1]).html(myHTMLOutput);
				$("#nfHome_SingerList"+id[1]).html(temp3+'<br class="clr" />');
				$("#nfHome_SingerHotS1"+id[1]).html(temp1);
				$("#nfHome_SingerHotS2"+id[1]).html(temp2);						
				clickChangeHotSinger();
			});		
		}
		$('#nfHome_SingerHot'+id[1]).show();
		$('#nfHome_SingerList'+id[1]).show();
		return false;
	});
}
/*
action of album reccommend
*/
$("a.nfHome_AlRec").mouseover(function () {
	var id = $(this).attr("id");
	var name = $("#"+id).html().split(".");
	$("#nfHome_AlRecPic").attr("src",$("#nfHome_AlRec"+id).val());
	$("#nfHome_AlRecName").html(name[1]);		
});
/*
click add song to cart
*/
function clickAAddToCart(){
	$("a.nfSong_AddCookies").click(function () {
		var id = $(this).attr("id");
		if (addSongToCart(id)) {	
			$(this).html('<img src="' + GLOBAL_IMAGE_PATH + 'skins/gentle/images/icon-check.png" width="13" height="12" border=0>');
			$(this).removeAttr('href');
		}
		return false;
	});
}

$("a.nfSong_AddCookies").click(function () {
	var id = $(this).attr("id");
	if (addSongToCart(id)) {	
		if ($(this).attr('name') == 'nghecakhuc') {
			$(this).attr('class', 'disableButton');
		} else {
			$(this).html('<img src="' + GLOBAL_IMAGE_PATH + 'skins/gentle/images/icon-check.png" width="13" height="12" border=0>');
		}
		$(this).removeAttr('href');
	}
	return false;
});

$("a.nfSong_AddCookies_Share").click(function () {
	var id = $(this).attr("id");
	if (addSongToCart(id)) {	
		if ($(this).attr('name') == 'nghecakhuc') {
			$(this).attr('class', 'disableButton');
		} else {
			$(this).html('<img src="' + GLOBAL_IMAGE_PATH + 'skins/gentle/images/icon-check.png" width="14" height="14" border=0 class="img" align="absmiddle"><span class="dathem">Đã thêm</span>');
		}
		$(this).removeAttr('href');
	}
	return false;
});

/*
click add favourite album
*/
$("a.generalFavourite").click(function () {
	if(!checkLogin()){
		loadLogin('no_refresh=1');
		return false;
	}else {			
		var albumID = $(this).attr("id");
		$.post("/includes/NewFace_NgheAlbum_YeuThich.php", { 	
			'id': albumID
		  },  		  
		  function(data){  		  	
			//// set up thong bao + show			
			if(data == -1 ){ //// chua login												
				jAlert('warning', 'Bạn vui lòng Đăng Nhập trước khi lưu album vào danh sách yêu thích.', 'Lưu ý');
			}else if(data == 1 ){//// thanh cong				
				$("#pic"+albumID).html('<img src="'+GLOBAL_IMAGE_PATH+'skins/gentle/images/icon-check.png" width="13px" height="12px">');
			}else if(data == -2 ){//// da click yeu thich
				$("#pic"+albumID).html('<img src="'+GLOBAL_IMAGE_PATH+'skins/gentle/images/icon-check.png" width="13px" height="12px">');
			}else if(data == -3 ){//// da click yeu thich
				$("#pic"+albumID).html('<img src="'+GLOBAL_IMAGE_PATH+'skins/gentle/images/icon-check.png" width="13px" height="12px">');				
				jAlert('error', 'Album này không tồn tại hoặc đã được xét trạng thái ẩn.', 'Thông báo lỗi');
			}else{ //// khong gui duoc
				jAlert('error', 'Hệ thống đang bận hoặc đang quá tải, vui lòng gửi lại sau.', 'Thông báo lỗi');
			}									
		  }  
		);
		return false;
	}
});
/*
click to anything ^^!
*/
$("#login_my_upload, #login_my_music, #login_docking_bar").click(function () {	
	if(checkLogin())
		return true;
	else{
		var href = $(this).attr("href");
		loadLoginURL(href);	
		return false;
	}
});
$("#nctUpload").click(function () {	
	if(checkLogin())
		location.href = '/mp3/upload/index.html';
	else{		
		loadLoginURL('/mp3/upload/index.html');	
		return false;
	}
});
$("#nctTaoAlbum").click(function () {	
	if(checkLogin())
		location.href = '/mp3/nhac-cua-toi/tao-album-nhanh/index.html';
	else{		
		loadLoginURL('/mp3/nhac-cua-toi/tao-album-nhanh/index.html');	
		return false;
	}
});
$("#nfHome_LienHe").click(function () {	
	tb_show('LienHe', '/includes/NewFace_LienHe.php?TB_iframe=true&height=380&width=500&modal=true');	
	return false;
});
/*
click to send recommend zing top song ^^!
*/
$("#recSubmit").click(function () {	
	if(!checkLogin()){
		loadLogin('');
		return false;
	}else {		
		if($('#recTitle').val().trim().length < 2){
			$('#recErr').html('Hãy nhập tên bài hát bạn muốn đề cử!');
			$('#recTitle').focus();
			return false;
		}else if($('#recArtist').val().trim().length < 2){
			$('#recErr').html('Hãy nhập tên ca sĩ trình bày!');
			$('#recArtist').focus();
			return false;
		}else if($('#recComposer').val().trim().length < 2){
			$('#recErr').html('Hãy nhập tên nhạc sĩ');
			$('#recComposer').focus();
			return false;
		}else{
			$("#recForm").submit();
		}	
	}												   
});

activeMenu('menuTop', 'curmenu', 2);
activeMenu('listalbum', 'CurTab', 3);
if($("div.blog-nhaccuatui").length){
	activeMenu('nhaccuatoi', 'curtabNCT', 3);
}

$('txtLinkPage').val(window.location.href);

$("a[name=createAlbumCookies]").click(function () {	
	if(!checkLogin()){
		loadLoginURL('/mp3/nhac-cua-toi/tao-album/index.html');
		return false;
	}else {
		location.href = '/mp3/nhac-cua-toi/tao-album/index.html';		
		return false;
	}	
});
$("a[name=removeCookies]").click(function () {	
	Os_Cookiess.$Set(COOKIE_MBOX_NAME, '', 0, '/', COOKIE_DOMAIN);
	location.href = '/';			
});

function newsTabActive(activeId)
{
	if ($('#nfHome_MP3News').length) {
		$('#nfHome_MP3NewsContent').hide();
		$("#nfHome_MP3News").removeClass("curNews");
	}
	if ($('#nfHome_News').length) {
		$('#nfHome_NewsContent').hide();
		$("#nfHome_News").removeClass("curNews");
	}
	if ($('#nfHome_Karaoke').length) {
		$('#nfHome_KaContent').hide();
		$("#nfHome_Karaoke").removeClass("curNews");
	}
	if ($('#nfHome_Photo').length) {
		$('#nfHome_PhotoContent').hide();
		$("#nfHome_Photo").removeClass("curNews");
	}
	if ($('#nfHome_Forum').length) {
		$('#nfHome_4rContent').hide();
		$("#nfHome_Forum").removeClass("curNews");
	}

	$('#' + activeId).addClass("curNews");
	$("div.footer-main").hide();
}

// Chia se light box
var SkinEmbbed_lightbox = {
	songIDEnCode: $('#songIDEnCode').val(),
	totalIcon: 11,
	firstID:1,
	totalIconDisplay:7,
	currentID:4,
	width:300,	
	height:61,
	autoPlay:'false',
//	xmlUrl:$('#xmlUrlNoAuto').val(),
	txtForumID:'txtLinkPage',
	txtBlogID: 'txtEmbedCode',	
	createIcon_lightbox: function(id,display){
		var template = '<a href="#" class="mgrightS" onclick="SkinEmbbed_lightbox.changeSkin_lightbox('+id+');return false;" id="lnkSkin_lightbox'+id+'" style="display:'+display+'"><img height="30" width="37" border="0" alt=" " src="'+imageServer+'skins/gentle/images/iconskin'+id+'.gif"/></a>';
		return template;
	},
	createEmbbedCodeBlog_lightbox: function(style){
		if(style == 'cakhuc'){
			var xmlUrl = $('#xmlUrlNoAuto').val();
			var tpl = '<object width='+this.width+' height='+this.height+'><param name=movie value='+imageServer+'skins/default/flash/player/mp3Player_skin'+this.currentID+'.swf?xmlurl=http://' + window.location.hostname + '/blog/?'+xmlUrl+' /><param name=quality value=high /><param name=wmode value=transparent /><embed width='+this.width+' height='+this.height+' src='+imageServer+'skins/default/flash/player/mp3Player_skin'+this.currentID+'.swf?xmlurl=http://' + window.location.hostname + '/blog/?'+xmlUrl+' quality=high wmode=transparent type=application/x-shockwave-flash></embed></object><br />';
			this.currentID = 4;
		}
		else if(style == 'album'){
			var encodeAlbum = $('#encodeAlbum').val();
			var tpl = '<object width=430 height=430><param name=quality value=high /><param name=wmode value=transparent /><embed id=mp3Player width=430 height=430 name=mp3Player allowscriptaccess=always type=application/x-shockwave-flash wmode=transparent quality=high src='+imageServer+'skins/gentle/flash/mp3playlist.swf?xmlURL=http://' + window.location.hostname + '/play/?pid='+encodeAlbum+'||1&songID=0&autoplay=false&wmode=transparent&1></embed></object><br />';			
		}
		else if(style == 'clip'){
			var encodeVideo = $('#EncodeVideo').val();
			var tpl = '<object width=600 height=360><param name=quality value=high /><param name=wmode value=transparent /><embed wmode=transparent id=vidPlayer height=250 width=328 allowfullscreen=true quality=high name=vidPlayer src='+imageServer+'skins/gentle/flash/channelzPlayer.swf?xmlURL=http://'+window.location.hostname+'/play/?pid='+encodeVideo+'||6&songID=0&autoplay=false&wmode=transparent&1 type=application/x-shockwave-flash></embed><br /></object><br />';	
		}
		else if(style == 'AlbumVideo'){
			var encodeVideoAlbum = $('#encodeVideoAlbum').val();
			var tpl = '<object width=600 height=360><param name=quality value=high /><param name=wmode value=transparent /><embed wmode=transparent id=vidPlayer height=250 width=328 allowfullscreen=true quality=high name=vidPlayer src='+imageServer+'skins/gentle/flash/channelzPlayer.swf?xmlURL=http://'+window.location.hostname+'/play/?pid='+encodeVideoAlbum+'||8&songID=0&autoplay=false&wmode=transparent&1 type=application/x-shockwave-flash></embed><br /></object><br />';	
		}
		
		return tpl;
	},
	createEmbbedCodeForum_lightbox: function(style){
		if(style == 'cakhuc'){
			// Cakhuc
			var imageServer = 'http://static.mp3.zing.vn/';		
			var tpl = '[FLASH]'+imageServer+'skins/default/flash/player/mp3Player_skin'+this.currentID+'.swf?xmlurl=http://'  + window.location.hostname  + '/blog/?'+this.xmlUrl+'[/FLASH]';
		}
		else if(style == 'album'){
			var imageServer = 'http://static.mp3.zing.vn/';		
			var tpl = '[FLASH]'+imageServer+'skins/default/flash/player/mp3Player_skin'+this.currentID+'.swf?xmlurl=http://'  + window.location.hostname  + '/blog/?'+this.xmlUrl+'[/FLASH]';
		}
		else if(style == 'clip'){
			var tpl = '[FLASH]'+imageServer+'skins/default/flash/player/mp3Player_skin'+this.currentID+'.swf?xmlurl=http://'  + window.location.hostname  + '/blog/?'+this.xmlUrl+'[/FLASH]';
		}
		else if(style == 'AlbumVideo'){
			var tpl = '[FLASH]'+imageServer+'skins/default/flash/player/mp3Player_skin'+this.currentID+'.swf?xmlurl=http://'  + window.location.hostname  + '/blog/?'+this.xmlUrl+'[/FLASH]';
		}
		
		return tpl;
	},	
	createListIcon_lightbox: function(){
		var html = '';
		var display = '';
		for(i=1;i<=this.totalIcon;i++){
			if((i>=this.firstID) && (i<=this.firstID+this.totalIconDisplay-1)){
				display = '';
			}else{
				display = 'none';				
			}
			html=html+this.createIcon_lightbox(i,display);			
		}
		return html;
	},
	changeSkin_lightbox: function(id){
		var src = imageServer+'skins/gentle/images/SkinPlayer/'+id+'.jpg';
		$('#imgSkinPlayer_lightbox').attr('src',src);
		this.currentID = id;
		$('#divSkinPanel_lightbox').show('fast');
		this.setEmbededCode_lightbox();
	},
	setEmbededCode_lightbox: function(style){
		var forumCode = this.createEmbbedCodeForum_lightbox(style);
		var blogCode = this.createEmbbedCodeBlog_lightbox(style);		
		$('#lblShareLocation').html('Blog');
		$('#lblLinkSong').html('Forum');		
		$('#'+this.txtForumID).val(forumCode);
		$('#'+this.txtBlogID).val(blogCode);		
	},	
	setDemoSkin_lightbox: function(style){
		this.width = 260;
		this.height = 51;	
		$('#divPanelLeft_lightbox').html(this.createEmbbedCodeBlog_lightbox(style));
	},	
	changeAutoPlay_lightbox: function(){
		var chkAutoPlay = $('#chkAutoPlay').attr('checked');
		if(chkAutoPlay){
			this.autoPlay = 'true';
			this.xmlUrl = $('#xmlUrlAuto').val();
		}else{
			this.autoPlay = 'false';
			this.xmlUrl = $('#xmlUrlNoAuto').val();			
		}
		this.setEmbededCode_lightbox();
	},
	changeBackGround_lightbox: function(){
		var chkBackGround = $('#chkBackGround').attr('checked');		
		if(chkBackGround){
			$('#chkAutoPlay').attr('checked','checked');
			this.changeAutoPlay_lightbox();
			$('#chkAutoPlay').attr('disabled','disabled');
			this.width = 1;
			this.height = 1;			
		}else{
			$('#chkAutoPlay').attr('disabled','');
			this.width = 360;
			this.height = 61;						
		}
		this.setEmbededCode_lightbox();		
	},	
	show_lightbox: function(id){
		$('#lnkSkin_lightbox'+id).show();
	},
	
	hide_lightbox: function(id){
		$('#lnkSkin_lightbox'+id).hide();
	},	

	moveLeft_lightbox: function(){
		var firstID_new = this.firstID-1;
		if(firstID_new>=1){
			this.hide_lightbox(firstID_new+this.totalIconDisplay);						
			this.show_lightbox(firstID_new);
			this.firstID = firstID_new;
		}
		return false;
	},
	
	moveRight_lightbox: function(){
		var lastID_new = this.firstID+this.totalIconDisplay;
		if(lastID_new<=this.totalIcon){
			this.hide_lightbox(this.firstID);									
			this.show_lightbox(lastID_new);			
			this.firstID +=1;
		}
		return false;
	}
}

$(".btn_share").click(function (){
	if(!checkLogin()){
		loadLogin('no_refresh=1');
	}else{
		var id = $(this).attr("id");
		if(!isNaN(id)){
			var style = $("#style").val();
			
			// For album
			if(style == 'album'){
				// share album
				var albumLink  = $("#LinkAlbum").val();
				var albumTitle = $("#TenAlbum").val();
				var alPic;
				if($("#LinkAlbum"+id).val()){
					albumLink  = $("#LinkAlbum"+id).val();
					albumTitle = $("#TenAlbum"+id).val();
					alPic = $("#AlbumPicture"+id).val();
				}else{
					albumLink  = $("#LinkAlbum").val();
					albumTitle = $("#TenAlbum").val();
					alPic = $("#AlbumPicture").val();
				}
				isAlbum = 1;
				var msg = '<div class="iAlbum">'+
						'<div class="avatarmp3">'+
							'<div class="mask_avatarmp3"></div>'+
							'<div class="img_avatarmp3"><img src="'+alPic+'" alt="Friend avatar" width="50" height="50" /></div>'+
						'</div>'+
						'<div class="txtAlbum">'+
							'<h1><a href="http://mp3.zing.vn" target="_blank">Zing Mp3 - Đỉnh Cao Âm Nhạc</a></h1>'+
							'<p>Chia sẻ <a href="'+albumLink+'">'+albumTitle+'</a> với bạn bè ZingMe</p>'+
						'</div>'+
						'<br class="clr" />'+
					'</div>'+
					'<p class="rwText">Viết lời nhắn<span class="key">(<strong id="countmakeFriend"> 300</strong>)</span></p>'+
					'<p class="rwText"><textarea class="txtShare" name="content" id="content" onkeyup="limitChars(\'content\', 300, \'countmakeFriend\');"/></p>';
			}
			else if(style == 'cakhuc'){
				var albumLink  = "";
				var albumTitle = "";
				var alPic;
				if($("#LinkCakhuc"+id).val()){
					albumLink  = $("#LinkCakhuc"+id).val();
					albumTitle = $("#TenCaKhuc"+id).val();
				}else{
					albumLink  = $("#LinkCakhuc").val();
					albumTitle = $("#TenCaKhuc").val();
				}
				isAlbum = 0;
				var list = SkinEmbbed_lightbox.createListIcon_lightbox();
				// share a song
				var msg =

					'<div class="cntBlogMp3">'+
						'<div class="marginblog">'+
						'<div class="iAlbum">'+
							'<p class="txtsh">Chia sẻ "<span class="str">'+albumTitle+'</span>" với bạn bè Zing me</p>'+
							'<p><img id="imgSkinPlayer_lightbox" src="'+imageServer+'skins/appme/images/SkinPlayer/5.jpg" width="289" height="45" /></p>'+
						'</div>'+
						'<div class="boxskin">'+
							'<p class="txtSkin"><strong>Chọn skin</strong></p>'+
							'<div class="skin">'+
								'<div class="leftskin"><img onclick="return SkinEmbbed_lightbox.moveLeft_lightbox();" src="'+imageServer+'skins/appme/images/zme_mleft.png" width="6" height="14" /></div>'+
								'<div class="listskin">'+list+'</div>'+
								'<div class="rightskin"><img onclick="SkinEmbbed_lightbox.moveRight_lightbox();" id="imgRight" src="'+imageServer+'skins/appme/images/zme_mright.png" width="6" height="14" /></div>'+
								'<br class="clr" />'+
							'</div>'+
						'</div>'+
							'<p class="rwText2"><strong>Viết lời nhắn</strong> <span class="key">(<strong id="countmakeFriend">300</strong>)</span></p>'+
							'<p class="rwText"><textarea id="content" name="content" cols="" rows="" class="txtShare" onkeyup="limitChars(\'content\', 300, \'countmakeFriend\');"></textarea></p>'+
					  '</div>'+
					'</div>';
			}
			else if(style == 'clip'){
				var albumLink  = "";
				var albumTitle = "";
				var alPic;
				if($("#VideoLink"+id).val()){
					albumLink  = $("#VideoLink"+id).val();
					albumTitle = $("#hidVideoName"+id).val();
					alPic = $("#PictureVideo"+id).val();
				}else{
					albumLink  = $("#VideoLink").val();
					albumTitle = $("#hidVideoName").val();
					alPic = $("#PictureVideo").val();
				}
				isAlbum = 0;
				var msg = '<div class="iAlbum">'+
							'<div class="avatarmp3">'+
								'<div class="mask_avatarmp3"></div>'+
								'<div class="img_avatarmp3"><img src="'+alPic+'" alt="Friend avatar" width="50" height="50" /></div>'+
							'</div>'+
							'<div class="txtAlbum">'+
								'<h1><a href="http://mp3.zing.vn" target="_blank">Zing Mp3 - Đỉnh Cao Âm Nhạc</a></h1>'+
								'<p>Chia sẻ <a href="'+albumLink+'" target="_blank">'+albumTitle+'</a> với bạn bè ZingMe</p>'+
							'</div>'+
							'<br class="clr" />'+
						'</div>'+
						'<p class="rwText">Viết lời nhắn<span class="key">(<strong id="countmakeFriend"> 300</strong>)</span></p>'+
						'<p class="rwText"><textarea class="txtShare" name="content" id="content" onkeyup="limitChars(\'content\', 300, \'countmakeFriend\');"/></p>';
			}
			else if(style == 'AlbumVideo'){
				var albumLink  = $("#VideoLink").val();
				var albumTitle = $("#hidVideoName").val();
				isAlbum = 1;
				alPic = $("#PictureVideoName").val();
				var msg = '<div class="iAlbum">'+
							'<div class="avatarmp3">'+
								'<div class="mask_avatarmp3"></div>'+
								'<div class="img_avatarmp3"><img src="'+alPic+'" alt="Friend avatar" width="50" height="50" /></div>'+
							'</div>'+
							'<div class="txtAlbum">'+
								'<h1><a href="http://mp3.zing.vn" target="_blank">Zing Mp3 - Đỉnh Cao Âm Nhạc</a></h1>'+
								'<p>Chia sẻ <a href="'+albumLink+'" target="_blank">'+albumTitle+'</a> với bạn bè ZingMe</p>'+
							'</div>'+
							'<br class="clr" />'+
						'</div>'+
						'<p class="rwText">Viết lời nhắn<span class="key">(<strong id="countmakeFriend"> 300</strong>)</span></p>'+
						'<p class="rwText"><textarea class="txtShare" name="content" id="content" onkeyup="limitChars(\'content\', 300, \'countmakeFriend\');"/></p>';
			}
			
			Boxy.confirm(msg, function(){
				var style = document.getElementById("style").value;
	            if(isAlbum == 0) {
	//				xmlurl = document.getElementById("xmlUrlNoAuto").value;
					alPic = SkinEmbbed_lightbox.createEmbbedCodeBlog_lightbox(style);
				}
				if(style == 'album'){
					url ="/includes/App_MyMusic_Share.php";
					if($("#LinkAlbum"+id).val()){
						albumLink = $("#LinkAlbum"+id).val();
						albumTitle = $("#TenAlbum"+id).val();
					}else{
						albumLink = $("#LinkAlbum").val();
						albumTitle = $("#TenAlbum").val();
					}
					$.ajax({
						type : "POST",
						url : url,
						data: ({content: $("#content").val(),albumPic : alPic, albumLink : albumLink, albumTitle : albumTitle, Album: isAlbum}),
						dataType: "html",
						success : function(msg){
							Boxy.alert(msg,function(){},{autoClose:20000, "title":"Chia sẻ âm nhạc", "cancelTitle":"Đóng"});
						}	
					});
				}
				else if(style == 'cakhuc'){
					url ="/includes/App_MyMusic_Share.php";
					if($("#LinkCakhuc"+id).val()){
						albumLink = $("#LinkCakhuc"+id).val();
						albumTitle = $("#TenCaKhuc"+id).val();
					}else{
						albumLink = $("#LinkCakhuc").val();
						albumTitle = $("#TenCaKhuc").val();
					}
					$.ajax({
						type : "POST",
						url : url,
						data: ({content: $("#content").val(),albumPic : alPic, albumLink : albumLink, albumTitle : albumTitle, Album: isAlbum}),
						dataType: "html",
						success : function(msg){
							Boxy.alert(msg,function(){},{autoClose:20000, "title":"Chia sẻ âm nhạc", "cancelTitle":"Đóng"});
						}
					});
				}
				else if(style == 'clip'){
					url ="/includes/App_MyVideo_Share.php";	
					if($("#VideoLink"+id).val()){
						albumLink = $("#VideoLink"+id).val();
						albumTitle = $("#hidVideoName"+id).val();
					}else{
						albumLink = $("#VideoLink").val();
						albumTitle = $("#hidVideoName").val();
					}
					$.ajax({
						type : "POST",
						url : url,
						data: ({content: $("#content").val(),albumPic : alPic, albumLink : albumLink, albumTitle : albumTitle, Album: isAlbum}),	
						dataType: "html",
						success : function(msg){	
							Boxy.alert(msg,function(){},{autoClose:20000, "title":"Chia sẻ âm nhạc", "cancelTitle":"Đóng"});
						}	
					});
				}
				else if(style == 'AlbumVideo'){
					url ="/includes/App_MyVideo_Share.php";	
					$.ajax({
						type : "POST",
						url : url,
						data: ({content: $("#content").val(),albumPic : alPic, albumLink : $("#VideoLink").val(), albumTitle : $("#hidVideoName").val(), Album: isAlbum}),	
						dataType: "html",
						success : function(msg){	
							Boxy.alert(msg,function(){},{autoClose:20000, "title":"Chia sẻ âm nhạc", "cancelTitle":"Đóng"});
						}	
					});
				}
		},{"cancelTitle":"Đóng", "okTitle":"Chia sẻ", "title":"Chia sẻ âm nhạc", "checkBeforeHide":false});
		}
	}
	return false;
});

// For change giao dien nghe ca khuc
if ($('#chiase_song').length) {
	if($("#chiase_song").html().length > 0){
		clickChangeTab();
	}
}

function clickChangeTab(){
	$("li.lineli1").click(function () {
		var id = $(this).attr("id").split("_");
		if($("#chiase_song").length){
			$("#chiase_song").hide();
		}
		if($("#lyric_song").length){
			$("#lyric_song").hide();
		}
		if($("#badlyric_song").length){
			$("#badlyric_song").hide();			
		}
		if($("#badalbum_song").length){
			$("#badalbum_song").hide();			
		}
		if($("#kieunghe_song").length){
			$("#kieunghe_song").hide();			
		}
		if($("#"+id[0]+"_song").html().length < 1) {
			if(id[0] == "lyric"){
				$.post("/includes/NewFace_NgheCaKhuc_SongLyric.php", {
						'sid': $('#songID').val(),
						'title': $('#txtSongTitle').val(),
						'artist': $('#hidArtist').val()
					},
					function(data){
						if(data){
							data = data.replace(/{_GLOBAL_IMAGE_PATH_}/g, GLOBAL_IMAGE_PATH);
							$("#lyric_song").append(data);
						}
					}  
				);
			}else if(id[0] == "badlyric"){
					$.post("/includes/NewFace_NgheCaKhuc_BadSongLyric.php", {
							'sid': SongID,
							'p': 'index'
						},
						function(data){
							if(data){
								data = data.replace(/{_GLOBAL_IMAGE_PATH_}/g, GLOBAL_IMAGE_PATH);
								$('#badlyric_song').html(data);
							}
						}  
					);	
			}else if(id[0] == "badalbum"){
				$.post("/includes/NewFace_NgheAlbum_ThongBao.php", {
						'id': $('#nghealbum_id').val(),
						'p': 'index'
					},
					function(data){
						if(data){
							$('#badalbum_song').html(data);
						}
					}  
				);	
			}else if(id[0] == "kieunghe"){
				$.post("/includes/NewFace_NgheAlbum_SapTT.php", {
					   	'f': 1,
						'id': $('#nghealbum_id').val(),
						'name': encodeURIComponent($('#nghealbum_name').val())
					},
					function(data){
						if(data){
							$('#kieunghe_song').html(data);
						}
					}  
				);	
			}
		}
		if(id[0] == "lyric"){
			$("#lyric_css_tag").addClass("CurTag");
			$("#chiase_css_tag").removeClass("CurTag");
			$("#chiase_css_tag").addClass("lineli1");
			$("#badlyric_css_tag").removeClass("CurTag");
			$("#badalbum_css_tag").removeClass("CurTag");
			$("#kieunghe_css_tag").removeClass("CurTag");
		}else if(id[0] == "badlyric"){
			$("#badlyric_css_tag").addClass("CurTag");
			$("#badlyric_css_tag").addClass("lineli1");
			$("#chiase_css_tag").removeClass("CurTag");
			$("#lyric_css_tag").removeClass("CurTag");
			// remove mess error
			$('#lblMessage').html('');
			$('#err_mess0').html('');
			$('#err_mess1').html('');
			$('#err_mess2').html('');
		}else if(id[0] == "badalbum"){
			$("#badalbum_css_tag").addClass("CurTag");
			$("#badalbum_css_tag").addClass("lineli1");
			$("#chiase_css_tag").removeClass("CurTag");
			$("#kieunghe_css_tag").removeClass("CurTag");
			$("#lyric_css_tag").removeClass("CurTag");
			$('#nghealbum_sucotips').html('');
		}else if(id[0] == "kieunghe"){
			$("#badalbum_css_tag").removeClass("CurTag");
			$("#chiase_css_tag").removeClass("CurTag");
			$("#chiase_css_tag").removeClass("CurTag");
			$("#kieunghe_css_tag").addClass("CurTag");
			$("#kieunghe_css_tag").addClass("lineli1");
		}
		$("#"+id[0]+"_song").show();
		return false;
	});
}

$("#chiase_song_link").click(function () {
	$("#lyric_css_tag").removeClass("CurTag");
	$("#badlyric_css_tag").removeClass("CurTag");
	$("#badalbum_css_tag").removeClass("CurTag");
	$("#chiase_css_tag").addClass("CurTag");
	$("#kieunghe_css_tag").removeClass("CurTag");
		
	$("#chiase_song").show();
	$("#lyric_song").hide();
	$("#badlyric_song").hide();
	$("#badalbum_song").hide();
	$("#kieunghe_song").hide();
	
	// remove error mess ca khuc
	$('#lblMessage').html('');
	$('#err_mess0').html('');
	$('#err_mess1').html('');
	$('#err_mess2').html('');
	// remove error mess album
	$('#nghealbum_sucotips').html('');
	return false;
});
