﻿var Http
var loading=0;

// + ------------------- +
// |        LOGIN        |
// + ------------------- +
function trim(a) {
        return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

function AddPlaylist(id) {
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="playlist.php";
url=url+"?mode=add&id="+id;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=playlist_handleResponse;
Http.send(null);
}

function RemovePlaylist(id) {
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="playlist.php";
url=url+"?mode=del&id="+id;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=playlist_handleResponse;
Http.send(null);
}

function logout(id) {
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="logout.php";
url=url+"?id="+id;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=logout_handleResponse;
Http.send(null);
}

function login(form) {
        Http=GetHttpObject();
        name = eval('encodeURIComponent('+form+'.name.value);');
        pwd = eval('encodeURIComponent('+form+'.pwd.value);');
        if(trim(name) == "" || trim(pwd) == "") {
                alert("B?n ch?a nh?p thông tin ??y ??!");
        } else {

                        document.getElementById("Loading").innerHTML = loadingText;
                        document.getElementById("Loading").style.display = "block";
                        var url="login.php";
                        url=url+"?login=1&name="+name;
                        url=url+"&pwd="+pwd;
                        url=url+"&sid="+Math.random();
                        Http.open("GET",url,true);
                        Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                        Http.onreadystatechange=login_handleResponse;
                        Http.send(null);
                }
                return false;
}

function show_hide(obj,field) {
        var hideshow = document.getElementById(obj);
                if(hideshow.style.display != "none") {
                        hideshow.style.display = "none";
                        document.getElementById(field).innerHTML = '[+]';
                }
                else {
                        hideshow.style.display = "block";
                        document.getElementById(field).innerHTML = '[-]';
                }
        return false;
}

function popupurl(url)
{
 params  = 'width='+screen.width;
 params += ', height='+screen.height;
 params += ', top=0, left=0'
 params += ', scrollbars=1'
 params += ', fullscreen=yes';

 newwin=window.open(url,'windowname4', params);
 if (window.focus) {newwin.focus()}
 return false;
}


function alertBrokenLink(id) {
        if (confirm("Báo link bài hát này ?ã h?ng?")) {
                try{
var url="error.php";
url=url+"?item="+id;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=BrokenResponse;
Http.send(null);

                }
                catch(e){}
                finally{}
        }
}

function BrokenResponse() {
try {

if((Http.readyState == 4)&&(Http.status == 200)){
response=Http.responseText;
alert("Thông báo l?i ?ã ???c g?i ??n chúng tôi.");
}
}
        catch(e){

}
finally{}
}

function TimTuKhoaCS() {
        kw = document.getElementById("tukhoa").value;
        pg = document.getElementById("pg").value;
        if (!kw) alert('Hãy nh?p t? khoá c?n tìm!');
        else {
                kw = encodeURIComponent(kw);

                last_url = '';
                window.location.href = '#TimCaSi,'+pg+','+kw;
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="timdulieu.php";
url=url+"?tukhoa="+kw;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=stateChanged;
Http.send(null);
        }
        return false;

}

function TimTuKhoaCSA(str,pg)
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="timdulieu.php";
url=url+"?tukhoa="+str;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=stateChanged;
Http.send(null);
}

function TimCaSi(str,pg)
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="timdulieu.php";
url=url+"?kitu="+str;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=stateChanged;
Http.send(null);
}

function TimBaiHat(str,pg)
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="dulieubh.php";
url=url+"?kitu="+str;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=stateChangedBH;
Http.send(null);
}


function TimBaiHatCS(str,pg)
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="dulieubh.php";
url=url+"?casi="+str;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=stateChangedBH;
Http.send(null);
}

function TimTuKhoaBH() {
        kw = document.getElementById("tukhoabh").value;
        pg = document.getElementById("pg").value;
        if (!kw) alert('Hãy nh?p t? khoá c?n tìm!');
        else {
                kw = encodeURIComponent(kw);

                last_url = '';
                window.location.href = '#TimBaiHat,'+pg+','+kw;
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="dulieubh.php";
url=url+"?tukhoa="+kw;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=stateChangedBH;
Http.send(null);
        }
        return false;

}

function TimTuKhoaBHA(str,pg)
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="dulieubh.php";
url=url+"?tukhoa="+str;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=stateChangedBH;
Http.send(null);
}

function NgheNhac(str)
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="nghenhac.php";
url=url+"?playitem="+str;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=PlayNhac;
Http.send(null);
}

function NgheCaSi(str)
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="nghecasi.php";
url=url+"?playsinger="+str;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=PlayNhac;
Http.send(null);
}

function NgheNhieuNhat()
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="playmost.php";
url=url+"?playmost=ok";
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=PlayNhac;
Http.send(null);
}

function NgheMoiNhat()
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="playnew.php";
url=url+"?playnew=ok";
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=PlayNhac;
Http.send(null);
}

function Playlist(str)
{
Http=GetHttpObject();
if (Http==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
document.getElementById("Loading").innerHTML = loadingText;
document.getElementById("Loading").style.display = "block";
var url="p_list.php";
url=url+"?playlist="+str;
url=url+"&sid="+Math.random();
Http.open("GET",url,true);
Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
Http.onreadystatechange=PlayNhac;
Http.send(null);
}

function stateChanged()
{
if (Http.readyState==4)
{
document.getElementById("Loading").style.display = "none";
document.getElementById("txtHint").innerHTML=Http.responseText;
}
}

function open_cat() {
        Http=GetHttpObject();
        if (Http==null)
        {
        alert ("Your browser does not support AJAX!");
        return;
        }
                Http.open('POST',  'img_cat.php');
                Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                Http.onreadystatechange = stateChanged;
                Http.send('act=open&sid='+Math.random());
}

function img_cat_detail(id,pg,order) {
        Http=GetHttpObject();
        if (Http==null)
        {
        alert ("Your browser does not support AJAX!");
        return;
        }
                Http.open('POST',  'img_cat_detail.php');
                Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                Http.onreadystatechange = cat_detail_response;
                Http.send('act=detail&id='+id+'&pg='+pg+'&order='+order+'&sid='+Math.random());
}

function cat_detail_response()
{
if (Http.readyState==4)
{
document.getElementById("Loading").style.display = "none";
document.getElementById("img_detail").innerHTML=Http.responseText;
}
}

function stateChangedBH()
{
if (Http.readyState==4)
{
document.getElementById("Loading").style.display = "none";
document.getElementById("txtHintBH").innerHTML=Http.responseText;
}
}

function PlayNhac()
{
if (Http.readyState==4)
{
document.getElementById("Loading").style.display = "none";
document.getElementById("ThuongThuc").innerHTML=Http.responseText;
}
}

function login_handleResponse() {
                if((Http.readyState == 4)&&(Http.status == 200)){
                        document.getElementById("Loading").style.display = "none";
                        var response = Http.responseText;
                        if (response) {
                                document.getElementById("Loading").innerHTML = response;
                                document.getElementById("Loading").style.display = "block";
                        }
                        else window.location.href = '?refresh=1';
                }

}
function logout_handleResponse() {
                if((Http.readyState == 4)&&(Http.status == 200)){
                        document.getElementById("Loading").style.display = "none";
                        var response = Http.responseText;
                        if (response) {
                                document.getElementById("Loading").innerHTML = response;
                                document.getElementById("Loading").style.display = "block";
                        }
                        else window.location.href = '?refresh=1';
                }

}

function playlist_handleResponse()
{
if (Http.readyState==4)
{
document.getElementById("Loading").style.display = "none";
document.getElementById("PlayList").innerHTML=Http.responseText;
}
}

function GetHttpObject()
{
var xmlHttp=null;try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function popup(url,wdname,width,height)
{
        if (width == null)  { width  = 200; }   // default width
        if (height == null) { height = 400; }   // default height
        newwin=window.open(url,wdname,'fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height);
        if (document.all)
        {
                newwin.moveTo(0,0);
                newwin.focus();
        }
}

function down_wall(id,width,height) {
        popup('down_wallpaper.php?id='+id,'gift',width,height);
}
