/*======================================================================*\
|| #################################################################### ||
|| # NCT CLONE V3.2 - 30-10-2009                                      # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright © 2008-2009 AnhTrang.Org . All Rights Reserved.        # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ----------- NCT CLONE IS FREE SOFTWARE - OPEN SOURCE ----------- # ||
|| # http://www.anhtrang.org | http://www.anhtrang.org/support.html   # ||
|| #################################################################### ||
\*======================================================================*/

var http = createRequestObject();
var lastUrl = '';
var current_url = '';
var field = '';
var interval = '';
var loadingFlash = "<center><img src='"+site+"/images/wait.gif' alt='Đang tải dữ liệu ...'><br>Đang tải dữ liệu...</center>";
var loadingText = '<center><embed id="ld" wmode="transparent" name="ld" src="'+site+'/images/loading.swf" width="480" height="240" allowfullscreen="true" allowscriptaccess="always" /></center>';

function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}
function str_replace(search, replace, str){
	var ra = replace instanceof Array, sa = str instanceof Array, l = (search = [].concat(search)).length, replace = [].concat(replace), i = (str = [].concat(str)).length;
	while(j = 0, i--)
		while(str[i] = str[i].split(search[j]).join(ra ? replace[j] || "" : replace[0]), ++j < l);
	return sa ? str : str[0];
}

function applyType(obj, value)
{
					var arrType = document.getElementsByName('searchType');
					for (var i = 0; i < arrType.length; i++) {
						arrType[i].className = '';
					}
					obj.className = 'curnav';
					document.getElementById('t').value = value;
}
/*------------------------------------------------------*/
function trim(a) {
	return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

function Title(song,sing)
{
  document.title ='AnhTrang.Org | Song: '+Replaces(song)+' - Singer: '+Replaces(sing);
}
function TitleSing(title)
{
  document.title ='AnhTrang.Org | Singer: '+Replaces(title);
}
function TitleAlbum(title)
{
  document.title ='AnhTrang.Org | Album: '+Replaces(title);
}
function TitleSong(title)
{
  document.title ='AnhTrang.Org | Song: '+Replaces(title);
}

function  Replaces(string) {
   string=string.replace(/'/g,"\'");
  return string
}

function killErrors() {
  return true;
}
window.onerror = killErrors;

function bb_bookmarksite(title,url)
{
	if (window.sidebar) {// firefox
		window.sidebar.addPanel(title, url, "");
	} 
	else if (window.opera && window.print) { // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
			} 
	else if (document.all) {// ie
			window.external.AddFavorite(url, title);
	}
}

function bb_setHomepage(obj)
{
    obj.style.behavior='url(#default#homepage)';
    if (document.all)
    {
        obj.setHomePage('http://AnhTrang.Org');
    }
    else
    {
        alert("Kéo Logo AT vào nút Home để đặt AT làm trang chủ");
    }
}

// + ---------------------- +
// |        PLAYLIST        |
// + ---------------------- +

function Playlist(add_id,remove_id) {
	try{
	document.getElementById("playlist_field").innerHTML = loadingFlash;
    document.getElementById("playlist_field").style.display = "block";
		http.open('POST',  site+'/index.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = function() {
													try {
														if((http.readyState == 4)&&(http.status == 200)){
															var response = http.responseText;
															document.getElementById("playlist_field").innerHTML = response;
														}
													}
													catch(e){}
													finally{}
												}
		http.send('Playlist=1&add_id='+add_id+'&remove_id='+remove_id);
	}
	catch(e){}
	finally{}
}

// + ---------------------- +
// |        RELATED SONG    |
// + ---------------------- +

function related(key,type,related_field) {
	try{
	document.getElementById(related_field).innerHTML = loadingFlash;
    document.getElementById(related_field).style.display = "block";
		http.open('POST',  site+'/index.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = function() 
		{
			try {
				if((http.readyState == 4)&&(http.status == 200)){
					var response = http.responseText;
					document.getElementById(related_field).innerHTML = response;
				}
				}
			catch(e){}
			finally{}
		}
		http.send('related=1&type='+type+'&key='+key+'&related_field='+related_field);
	}
	catch(e){}
	finally{}
}

// + ---------------------- +
// |        SAVE PLAYLIST   |
// + ---------------------- +

function save_playlist() {
	try{
	name = document.getElementById("playlist_name").value;
	document.getElementById("save_playlist").innerHTML = loadingFlash;
    document.getElementById("save_playlist").style.display = "block";
		http.open('POST',  site+'/play_playlist.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = function() 
		{
			try {
				if((http.readyState == 4)&&(http.status == 200)){
					var response = http.responseText;
					document.getElementById("save_playlist").innerHTML = response;
				}
				}
			catch(e){}
			finally{}
		}
		http.send('save=1&name='+name);
	}
	catch(e){}
	finally{}
}

function popup(url,wdname,width,height)
{
	if (width == null)  { width  = 350; }   // default width
	if (height == null) { height = 400; }   // default height
	newwin=window.open(url,wdname,'scrollbars=no,width='+width+',height='+height);
	if (document.all)
	{
		newwin.moveTo(0,0);
		newwin.focus();
	}
}

/*------------------------------------------------------*/

//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "sc1"]

var previoustab=""

function expandcontent(cid, aobject){
if (document.getElementById){
highlighttab(aobject)
if (previoustab!="")
document.getElementById(previoustab).style.display="none"
document.getElementById(cid).style.display="block"
previoustab=cid
}
}

function highlighttab(aobject){
if (typeof tabobjlinks=="undefined")
collecttablinks()
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].className=""
aobject.className="current"
}

function collecttablinks(){
var tabobj=document.getElementById("tablist")
tabobjlinks=tabobj.getElementsByTagName("A")
}

function do_onload(){
collecttablinks()
expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload