doFadeObjects = new Object();

doFadeTimers = new Object();



function doFade(object, destOp, rate, delta){

if (!document.all)

return

    if (object != "[object]"){  

        setTimeout("doFade("+object+","+destOp+","+rate+","+delta+")",0);

        return;

    }

        

    clearTimeout(doFadeTimers[object.sourceIndex]);

    

    diff = destOp-object.filters.alpha.opacity;

    direction = 1;

    if (object.filters.alpha.opacity > destOp){

        direction = -1;

    }

    delta=Math.min(direction*diff,delta);

    object.filters.alpha.opacity+=direction*delta;



    if (object.filters.alpha.opacity != destOp){

        doFadeObjects[object.sourceIndex]=object;

        doFadeTimers[object.sourceIndex]=setTimeout("doFade(doFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);

    }

}



var req;

	function loadXMLDoc(url) 

	{

		// branch for native XMLHttpRequest object

		if (window.XMLHttpRequest) {

			req = new XMLHttpRequest();

			req.onreadystatechange = processReqChange;

			req.open("GET", url, true);

			req.send(null);

		// branch for IE/Windows ActiveX version

		} else if (window.ActiveXObject) {

			req = new ActiveXObject("Microsoft.XMLHTTP");

			if (req) {

				req.onreadystatechange = processReqChange;

				req.open("GET", url, true);

				req.send();

			}

		}

	}

	

	

	function processReqChange() 

	{

		if (req.readyState == 4) // only if req shows "complete"

		{

			if (req.status == 200) // only if "OK"

			{

				response  = req.responseXML.documentElement;

				A_Method  =	response.getElementsByTagName('method')[0].firstChild.data;

				A_Result    = response.getElementsByTagName('result')[0].firstChild.data;

				if (A_Method!='addNew')

				{

					eval(A_Method + '(\'\', A_Result)');

				}

				else

				{

					eval(A_Method + '(\'\',\'\', A_Result)');

				}

			} 

			else 

			{

				alert("There was a problem retrieving the XML data:\n" + req.statusText);

			}

		}

	}

function loading(show,type) {



 xmlhttp.open("GET", show, true);



 if(type=='main'){



 xmlhttp.onreadystatechange = MAIN;

  }else if(type=='play'){



 xmlhttp.onreadystatechange = PLAY;



 }



  xmlhttp.send(null);



}



function CreateObject()

{

 var http;

 var browser = navigator.appName; 

 if(browser == "Microsoft Internet Explorer"){

	http = new ActiveXObject("Microsoft.XMLHTTP");

 }else{

	http = new XMLHttpRequest();

	}

  return http;

}



var xmlhttp = CreateObject();



if(!xmlhttp) alert('Sorry we can not creat an ActiveX on your browser');



function MAIN() {

   if(xmlhttp.readyState == 1 || xmlhttp.readyState == 2)

   {

	   document.getElementById("NSH").innerHTML = '<center><img src="music/loading.gif" border=0>&nbsp; Xin Ch&#7901; Ch&#250;t X&#237;u !!...<br><img src="music/load.gif" border=0></center><br>';

   }

   else if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {

      document.getElementById("NSH").innerHTML = xmlhttp.responseText;

        

   }   

}

function PLAY() {

   if(xmlhttp.readyState == 1 || xmlhttp.readyState == 2)

   {

	

	   document.getElementById("play").innerHTML = '<center><img src="music/loading.gif" border=0>&nbsp; Xin Ch&#7901; Ch&#250;t X&#237;u !!...<br><img src="music/load.gif" border=0></center><br>';

   }

   else if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {

      document.getElementById("play").innerHTML = xmlhttp.responseText;

        

   }   

}

function showmain()

{
  loading('musicajax.php?do=main','main');
}

function musicsearch(page)

{

	var key = document.getElementById("key").value;

	if(key.length>2){

	loading('musicajax.php?musicquery='+encodeURI(key)+'&do=musicsearch&page='+page+'','main');

	} else { alert('Từ khóa tìm kiếm phải từ 3 ký tự trở lên');

	}

}

function search(key,page)

{
	loading('musicajax.php?do=search&ltr='+key+'&page='+page+'', 'main');
}

function album(page)

{
  loading('musicajax.php?do=album&page='+page+'&#','main');
}


function viewcat(catid,page,subcatname)

{
  loading('musicajax.php?do=viewcat&id='+catid+'&page='+page+'&#','main');
  document.title = subcatname;
}


function play(id,songname)

{  
  loading('musicajax.php?do=play&song='+id+'&#','play');
  document.title = songname;
}

function viewalbum(id,albumname)

{
  loading('musicajax.php?do=viewalbum&id='+id+'&#','main');
  document.title = albumname;
}

function playall(id,albumname)

{  
  loading('musicajax.php?do=playalbum&id='+id+'&#','play');
  document.title = albumname;
}

function viewartist(artistid,page,artistname)

{  
  loading('musicajax.php?do=viewartist&id='+artistid+'&page='+page+'&#','main');
  document.title = artistname;
}

function playartist(artistid,artistname)

{
	loading('musicajax.php?do=playartist&id='+artistid+'&#','play');
	document.title = artistname;
}


function del()

{

	ht = document.getElementsByTagName("html");

	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";

	if (confirm('Chú ý! Có chắc chắn xóa không ?!'))

	{

		return true;

	}

	else

	{

		ht[0].style.filter = "";

		return false;

	}

}

