function showLoader(type) {
$("#"+type+"_result").html("<center><div style='color:#FB6400; font-weight:bold; font-size:13px;' id='load'><img src='theme/images/loading.gif'> Đang tải dữ liệu ...</div></center>").hide().fadeIn('slow');
block = true;
}
function showResult(type,data) {
	$("#"+type+"_result").html(data).hide().fadeIn('fast');
	exitContent("load");
	block = false;
}
function exitContent(type) {
	$("#"+type+"_result").html('').hide().fadeOut("slow");
	block = false;
}
function checkLogin(){
showLoader('load');
    $.ajax({
        url: 'check_login.php',
        type: 'POST',
        data: '',
        dataType: "html",
        success: function(data){
            showResult("login",data);
			showAlbum('salbum','1');
        }
    });
}
function loadAjax(keyword,page,by,type){
showLoader('load');
    $.ajax({
        url: 'index.php',
        type: 'POST',
        data: "keyword="+keyword+"&page="+page+"&by="+by+"&type="+type,
        dataType: "html",
        success: function(data){
            showResult("list",data);
        }
    });
}
function channelZ(keyword,page,row){
showLoader('load');
    $.ajax({
        url: 'channelZ.php',
        type: 'POST',
        data: "keyword="+keyword+"&page="+page+"&row="+row,
        dataType: "html",
        success: function(data){
            showResult("list",data);
        }
    });
}
function listZ(tid,page){
showLoader('load');
    $.ajax({
        url: 'channelZ.php',
        type: 'POST',
        data: "tid="+tid+"&page="+page,
        dataType: "html",
        success: function(data){
            showResult("list",data);
        }
    });
}


function topZ(keyword,page,row){
showLoader('load');
    $.ajax({
        url: 'topZ.php',
        type: 'POST',
        data: "keyword="+keyword+"&page="+page+"&row="+row,
        dataType: "html",
        success: function(data){
            showResult("list",data);
        }
    });
}
function listtopZ(topid,page){
showLoader('load');
    $.ajax({
        url: 'topZ.php',
        type: 'POST',
        data: "topid="+topid+"&page="+page,
        dataType: "html",
        success: function(data){
            showResult("list",data);
        }
    });
}

function listR(rid,page){
showLoader('load');
    $.ajax({
        url: 'ring.php',
        type: 'POST',
        data: "rid="+rid+"&page="+page,
        dataType: "html",
        success: function(data){
            showResult("list",data);
        }
    });
}
function ringR(keyword,page,row){
showLoader('load');
    $.ajax({
        url: 'ring.php',
        type: 'POST',
        data: "keyword="+keyword+"&page="+page+"&row="+row,
        dataType: "html",
        success: function(data){
            showResult("list",data);
        }
    });
}
function playR(id,name,singer){
showLoader('load');
    $.ajax({
        url: 'ring.php',
        type: 'POST',
        data: "id="+id+"&name="+name+"&singer="+singer,
        dataType: "html",
        success: function(data){
            showResult("play",data);
        }
    });
}

function playZ(id,name,singer){
showLoader('load');
    $.ajax({
        url: 'channelZ.php',
        type: 'POST',
        data: "id="+id+"&name="+name+"&singer="+singer,
        dataType: "html",
        success: function(data){
            showResult("play",data);
        }
    });
}



function playtopZ(id,name,singer){
showLoader('load');
    $.ajax({
        url: 'topZ.php',
        type: 'POST',
        data: "id="+id+"&name="+name+"&singer="+singer,
        dataType: "html",
        success: function(data){
            showResult("play",data);
        }
    });
}


function Play(id,name,singer,kat,cat,kbs,type){
showLoader('load');
    $.ajax({
        url: 'index.php',
        type: 'POST',
        data: "id="+id+"&name="+name+"&singer="+singer+"&kat="+kat+"&cat="+cat+"&kbs="+kbs+"&type="+type,
        dataType: "html",
        success: function(data){
            showResult("play",data);
        }
    });
}
function topSong(ts,page){
smallLoader('smallqt');
    $.ajax({
        url: 'top_song.php',
        type: 'POST',
        data: "ts="+ts+"&page="+page,
        dataType: "html",
        success: function(data){
            showResult("top",data);
			exitSmall("<a href=\"javascript:void(0);\" onclick=\"topSong('ca-khuc-viet/chi-tiet.vn','1');\">Việt Nam</a> | <a href=\"javascript:void(0);\" onclick=\"topSong('quoc-te/chi-tiet.channelv','1');\">Châu Á</a> | <a href=\"javascript:void(0);\" onclick=\"topSong('quoc-te/chi-tiet.billboard','1');\">Billboard</a> | <a href=\"javascript:void(0);\" onclick=\"topSong('quoc-te/chi-tiet.soompi','1');\">Hàn Quốc</a>","smallqt");
        }
    });
}
function showComment(media_show,page){
showLoader('load');
    $.ajax({
        url: 'comment.php',
        type: 'POST',
        data: "media_show="+media_show+"&page="+page,
        dataType: "html",
        success: function(data){
            showResult("comment",data);
        }
    });
}



function tComment(type){
smallLoader('top_cr');
    $.ajax({
        url: type+'.php',
        type: 'POST',
        data: "",
        dataType: "html",
        success: function(data){
            showResult("tcomment",data);
			exitSmall("<a href=\"javascript:void(0);\" onClick=\"tComment('comment');\">Cảm nhận mới</a> | <a href=\"javascript:void(0);\" onClick=\"tComment('rate');\">Đánh giá nhiều</a>","top_cr");
        }
    });
}
function mOpen(type){
showLoader('list');
    $.ajax({
        url: 'theme/mopen/'+type+'.htm',
        dataType: "html",
        success: function(url){
            showResult("list",url);
        }
    });
}
function form(show){
showLoader('load');
    $.ajax({
        url: show,
        type: 'POST',
        data: "show="+show,
        dataType: "html",
        success: function(data){
			if(data == '10')
			{
				alert('Bạn đã đăng nhập');
				showAlbum('salbum','1')
				return false;
			}
			if(show == 'search.php')
			{
				showResult('list',data);
				return false;
			}
			

			
			if(data.indexOf("form id"))
			{
				showResult('login',data);
				showAlbum('salbum','1')
				return false;
			}
			if(data == '2')
			{
				exitContent('load');
				alert('Bạn chưa đăng nhập');
				return false;
			}
            showResult('list',data);
        }
    });
}
function smallLoader(type) {
$("#"+type+"_result").html(" <img src='theme/images/tabload.gif'>&nbsp;&nbsp; Loading...").hide().fadeIn("slow");
block = true;
}
function exitSmall(html,type) {
	$("#"+type+"_result").html(html).hide().fadeIn("fast");
	block = false;
}
function addAlbum(type,id){
showLoader('load');
    $.ajax({
        url: 'album.php',
        type: 'POST',
        data: "type="+type+"&id="+id,
        dataType: "html",
        success: function(data){
			if(data == '1')
			{
				exitContent('load');
				alert('Bài hát bạn vừa chọn thuộc Album này.Vui lòng chọn Album khác');
				return false;
			}
			if(data == '2')
			{
				exitContent('load');
				alert('Bài hát cần chuyển đã có trong Album này.Vui lòng chọn Album khác');
				return false;
			}
            alert(data);
			showAlbum('show',id);
			return false;
        }
    });
}
function delAlbum(type,id){
	if (confirm("Nếu xóa Album,tất cả các bài hát trong Album này cũng bị xóa ?"))
	{
		showLoader('load');
  	    $.ajax({
      	  	url: 'album.php',
        	type: 'POST',
        	data: "type="+type+"&id="+id,
        	dataType: "html",
        	success: function(data){
            	alert(data);
				showAlbum('salbum','1');
				return false;
        	}
    	});
	}
	else
	{
		return false;
	}
}
function renameAlbum(type,old){
var news = prompt("Nhập tên mới của Album", "")
if(news)
{
showLoader('load');
  	    $.ajax({
      	  	url: 'album.php',
        	type: 'POST',
        	data: "type="+type+"&old="+old+"&news="+news,
        	dataType: "html",
        	success: function(data){
				if(data == 1)
				{
					exitContent('load');
					alert('Trùng tên Album.Chọn tên khác');
					return false;
				}
				showAlbum('salbum','1');
				alert(data);
				return false;
        	}
    	});
}
}
function playAlbum(type,id){
showLoader('load');
    $.ajax({
        url: 'album.php',
        type: 'POST',
        data: "type=play&id=id",
        dataType: "html",
        success: function(data){
			if(data == 'Bạn phải đăng nhập để sử dụng chức năng này')
			{
				exitContent('load');
				alert('Bạn phải đăng nhập để sử dụng chức năng này');
				return false;
			}
			showResult('play',data);
			playsAlbum(type,id);
        }
    });
}
function playsAlbum(type,id){
showLoader('load');
    $.ajax({
        url: 'album.php',
        type: 'POST',
        data: "type="+type+"&id="+id,
        dataType: "html",
        success: function(data){
			showResult('play',data);
        }
    });
}
function showAlbum(type,id){
showLoader('load');
    $.ajax({
        url: 'album.php',
        type: 'POST',
        data: "type="+type+"&id="+id,
        dataType: "html",
        success: function(data){
            showResult('plist',data);
			return false;
        }
    });
}


function showAlbum01(type,id){
showLoader('load');
    $.ajax({
        url: 'album.php',
        type: 'POST',
        data: "type="+type+"&id="+id,
        dataType: "html",
        success: function(data){
			if(data == 'Bạn phải đăng nhập để sử dụng chức năng này')
			{
				exitContent('load');
				alert('Bạn phải đăng nhập để sử dụng chức năng này');
				return false;
			}
            showResult('plist',data);
			showAlbum(type,id);
        }
    });
}
function pList(type,songname,songid){
showLoader('load');
    $.ajax({
        url: 'album.php',
        type: 'POST',
        data: "type="+type+"&songname="+songname+"&songid="+songid,
        dataType: "html",
        success: function(data){
			if(data == '1')
			{
				alert('Chưa có Album nào trong danh sách,Vui lòng khởi tạo Album');
				form('album.php');
				return false;
			}
			 showResult("plist",data);
        }
    });
}
function searchAlbum(keyword,page){
showLoader('load');
    $.ajax({
        url: 'search.php',
        type: 'POST',
        data: "keyword="+keyword+"&page="+page,
        dataType: "html",
        success: function(data){
			 showResult("list",data);
        }
    });
}
function addFav(type,id){
showLoader('load');
	if(type == 'del')
	{
		if(confirm('Bạn có muốn xóa Album này không ?'))
		{
		}
		else
		{
			exitContent('load');
			return false;
		}
	}
    $.ajax({
        url: 'fav.php',
        type: 'POST',
        data: "type="+type+"&id="+id,
        dataType: "html",
        success: function(data){
			if(data == '1')
			{
				alert('Đã xóa Album này ra khỏi danh sách yêu thích của bạn');
				showFav('show_list','','');
				return false;
			}
			exitContent('load');
			 alert(data);
			 return false;
        }
    });
}
function showFav(type,page){
showLoader('load');
    $.ajax({
        url: 'fav.php',
        type: 'POST',
        data: "type="+type+"&page="+page,
        dataType: "html",
        success: function(data){
			 showResult("list",data);
        }
    });
}
function killErrors() {
return true;
}
window.onerror = killErrors;