/**_____________________________
|							|
| 	AJAX BOILING PLATE		|
|							|
|							|
|_____________________________**/

var xmlHttp
var loc=""
function changeRequest(url, str, ID)
{
loc=ID
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
url=url+"?q="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function changeRequestPage(url, str, page, ID)
{
loc=ID
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
url=url+"?q="+str;
if (page!=null || page!=" ")
  {
  url=url+"&p="+page;
  }
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById(loc).innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
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;
}


/**_____________________________
|							|
|  ANIMATIONS AND TRANSITIONS|
|							|
|							|
\_____________________________**/

//--- Browsing table extention---

//Change the size of a div
function ChangeSize(size, ID)
{
	var object = document.getElementById(ID).style;
	object.height = size +"px";

}

//Create the animation
function Xpend(height, TheDiv, Timing)
{

	var divStatus = document.getElementById(TheDiv);
	var speed = Math.round(Timing / 100);
    var timer = 0;
	//Closes if it's open and set the class to closed
	if (divStatus.className=="open")
	{
	for (i=height;i>=0;i--)
		{
		setTimeout("ChangeSize(" + i + ",'" + TheDiv + "')",(timer * speed));
		timer++
		}
	divStatus.className="closed";
	divStatus.style.display= "none";
	}
	//Else open , and set the class to "open"
	else
	{
	divStatus.style.display= "block";
		for (i=0;i<=height;i++)
		{
		setTimeout("ChangeSize(" + i + ",'" + TheDiv + "')",(timer * speed));
		timer++
		}
	divStatus.className="open";
	}
}

//-- Div Fade in 

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

/**_____________________________
|							|
|           QUERIES FUNCTIONS		|
|							|
|							|
|____________________________**/

var loaded = new Array();
function CallAndAnimate(address, str, height, TheDiv, Timing)
{

var x;
var loadedstatus;
	
	for (x in loaded) //is the div already loaded ? Look inside the array
		{
		if (loaded[x]==TheDiv)
		loadedstatus=1;
		}

	if (loadedstatus != 1) //If not, load it and add it to the array (love the splice thingy)
		{
		Xpend(height, TheDiv, Timing);
		changeRequest(address, str, TheDiv)
		loaded.splice(0,0,TheDiv);
		}
	else if (loadedstatus==1)
		{
		Xpend(height, TheDiv, Timing);
		loadedstatus = 0;
		}
}

function popAJAX(Popup, Target, url, height) {
document.getElementById('mask').style.display ='block';
document.getElementById(Target).src=url;
document.getElementById(Popup).style.display ='block';
document.getElementById(Popup).style.top =height+"px";
opacity('mask', 0, 40, 3000);
return false;
}
function popCart(Popup, Target, url, height) {
document.getElementById(Target).src=url;
document.getElementById(Popup).style.display ='block';
document.getElementById(Popup).style.top =height+"px";
return false;
}

function unPopAJAX(Popup, Target)
{
document.getElementById(Target).src="../../blank.asp";
document.getElementById('mask').style.display ='none';
changeOpac(0, 'mask');
document.getElementById(Popup).style.display ='none';
}
function unPopCart(Popup)
{
//document.getElementById(Target).src="../../blank.asp";
document.getElementById(Popup).style.display ='none';
}

function doBothType(ReQ,Type,Total,Popup, Target) {
document.getElementById('mask').style.display ='block';
document.getElementById(Target).src="../../download/downloadprocess.asp?q="+ReQ+"&type="+Type+"&total="+Total;
document.getElementById(Popup).style.display ='block';
opacity('mask', 0, 40, 3000);
return false;
}

function clearAndCall(url, str, ID, unload) //Clear the loaded queries array in case we sort the list of songs
{
	if (unload == 1)
	{
		loaded = [];
	}
changeRequest(url,str,ID);
return false;
}





/**_____________________________
|							|
|           VARIOUS PLATYPUS NIBBLE	|
|							|
|							|
|____________________________**/

function clearfield(field)
{
document.getElementById(field).value=""
}

	function pushButton(button1)
	{
		if (button1 == "album_button")
		{
			var button2 = "artis_button";
			var button3 = "song_button";
		}
		else if (button1 == "artis_button")
		{
			var button2 = "album_button";
			var button3 = "song_button";
		}
		else if (button1 == "song_button")
		{
			var button2 = "artis_button";
			var button3 = "album_button";
		}
		
		document.getElementById(button1).style.backgroundColor = '#333';
		document.getElementById(button2).style.backgroundColor='#666'; 
		document.getElementById(button3).style.backgroundColor='#666';
	}
	function pushButton2(button1)
	{
		if (button1 == "top10")
		{
			var button2 = "charts";
		}
		else if (button1 == "charts")
		{
			var button2 = "top10";
		}
		document.getElementById(button1).style.backgroundColor = '#333';
		document.getElementById(button2).style.backgroundColor='#666'; 
	}
	
	function sendForm(theForm)
	{
	var Frm = document.getElementById(theForm);
	var i;
	var url = "download/test.asp?";
		for (i=0; i<Frm.length; i++)
		{
			Frm2=Frm.elements[i];
			if (Frm2.type=="checkbox" && Frm2.checked==true)
			{
			url = url+Frm2.name+"="+Frm2.name+"&";
			}
		}
	window.location.href="http://music.playcircle.net/"+url;
	}
	
	
	function doBothForm(Popup, Target) 
	{
// any Checkbox checked?
//	var hasChecked;
//	var field = document.songform.check;
//	for (i = 0; i < field.length; i++)
//		if (field[i].checked) {
//			hasChecked = true;
//		}
//		if (!hasChecked) {
//			alert('Kamu belum memilih lagu');
//		}
//		else {
// yes ->
		var Frm = document.getElementById('song');
		var i;
		var url = "download/test.asp?";
			for (i=0; i<Frm.length; i++)	
			{
				Frm2=Frm.elements[i];
				if (Frm2.type=="checkbox" && Frm2.checked==true)
				{
				url = url+Frm2.value+"="+Frm2.value+"&";
				}
			}
		
		if (url=="download/test.asp?")
		{
		alert("No song selected")
		}
		else
		{
		document.getElementById('mask').style.display ='block';
		document.getElementById(Target).src=url;
		document.getElementById(Popup).style.display ='block';
		opacity('mask', 0, 40, 3000);
		}
		//check this mau bikin habis add otomatis uncheck all checkboxes
		//{
		//for (i = 0; i < field.length; i++)
		//field[i].checked = false ;
		//}
		
	return false;
	}
//		}
	
	
	function checkAll(field)
	{
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
	}
	
	function uncheckAll(field)
	{
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
	}

function AlertPop(Popup)
	{
		//alert (Popup)
		//alert(document.getElementById(Popup));
		parent.document.getElementById(Popup).style.display ='none';
		parent.document.getElementById('mask').style.display ='none';
//changeOpac(0, 'mask');
		//return false;
	}

	
		function doBothFormArtist(Popup, Target, AlbumID) 
	{
// any Checkbox checked?
//	var hasChecked;
//	var field = document.songform.check;
//	for (i = 0; i < field.length; i++)
//		if (field[i].checked) {
//			hasChecked = true;
//		}
//		if (!hasChecked) {
//			alert('Kamu belum memilih lagu');
//		}
//		else {
// yes ->
		var Frm = document.getElementById('song'+AlbumID);
		var i;
		var url = "download/test.asp?";
			for (i=0; i<Frm.length; i++)	
			{
				Frm2=Frm.elements[i];
				if (Frm2.type=="checkbox" && Frm2.checked==true)
				{
				url = url+Frm2.value+"="+Frm2.value+"&";
				}
			}
		
		if (url=="../../download/test.asp?")
		{
		alert("No song selected")
		}
		else
		{
		document.getElementById('mask').style.display ='block';
		document.getElementById(Target).src=url;
		document.getElementById(Popup).style.display ='block';
		opacity('mask', 0, 40, 3000);
		}
		//check this mau bikin habis add otomatis uncheck all checkboxes
		//{
		//for (i = 0; i < field.length; i++)
		//field[i].checked = false ;
		//}
		
	return false;
	}
//		}
	
	
	
	
	
	
	
	
	
//-------------------------------------------------------------------------------------
// Function : Button Change On New Release 
// Purpose : Change On Off Button On New Release
// Parameter : [IN] Button Id
// Author: Ronny Gunawan
// Date: 13 August 2008
//------------------------------------------------------------------------------------
function buttonnewrelease(buttonclick)
	{
		if (buttonclick == "singles_newrelease")
		{
			var button1 = "singles_newrelease";
			var button2 = "albums_newrelease";
			var button3 = "compilations_newrelease";
			document.getElementById(button1).src  = 'img-wip/tab_single_on.gif';
			document.getElementById(button2).src  = 'img-wip/tab_albums_off.gif';
			document.getElementById(button3).src  = 'img-wip/tab_compilations_off.gif';
		}
		else if (buttonclick == "albums_newrelease")
		{
			var button1 = "singles_newrelease";
			var button2 = "albums_newrelease";
			var button3 = "compilations_newrelease";
			document.getElementById(button1).src  = 'img-wip/tab_single_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_albums_on.gif';
			document.getElementById(button3).src  = 'img-wip/tab_compilations_off.gif';			
		}
		else if (buttonclick == "compilations_newrelease")
		{
			var button1 = "singles_newrelease";
			var button2 = "albums_newrelease";
			var button3 = "compilations_newrelease";
			document.getElementById(button1).src  = 'img-wip/tab_single_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_albums_off.gif';
			document.getElementById(button3).src  = 'img-wip/tab_compilations_on.gif';		
		}
	}

//-------------------------------------------------------------------------------------
// Function : Button Change On News
// Purpose : Change On Off Button On News
// Parameter : [IN] Button Id
// Author: Ronny Gunawan
// Date: 13 August 2008
//------------------------------------------------------------------------------------
function buttonnews(buttonclick)
	{
		if (buttonclick == "berita_news")
		{
			var button1 = "berita_news";
			var button2 = "interview_news";
			var button3 = "event_news";
			var button4 = "photo_news";
			document.getElementById(button1).src  = 'img-wip/tab_berita_on.gif';
			document.getElementById(button2).src  = 'img-wip/tab_interview_off.gif';
			document.getElementById(button3).src  = 'img-wip/tab_event_off.gif';
			document.getElementById(button4).src  = 'img-wip/tab_photo_off.gif';
		}
		else if (buttonclick == "interview_news")
		{
			var button1 = "berita_news";
			var button2 = "interview_news";
			var button3 = "event_news";
			var button4 = "photo_news";
			document.getElementById(button1).src  = 'img-wip/tab_berita_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_interview_on.gif';
			document.getElementById(button3).src  = 'img-wip/tab_event_off.gif';
			document.getElementById(button4).src  = 'img-wip/tab_photo_off.gif';	
		}
		else if (buttonclick == "event_news")
		{
			var button1 = "berita_news";
			var button2 = "interview_news";
			var button3 = "event_news";
			var button4 = "photo_news";
			document.getElementById(button1).src  = 'img-wip/tab_berita_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_interview_off.gif';
			document.getElementById(button3).src  = 'img-wip/tab_event_on.gif';
			document.getElementById(button4).src  = 'img-wip/tab_photo_off.gif';
		}
		else if (buttonclick == "photo_news")
		{
			var button1 = "berita_news";
			var button2 = "interview_news";
			var button3 = "event_news";
			var button4 = "photo_news";
			document.getElementById(button1).src  = 'img-wip/tab_berita_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_interview_off.gif';
			document.getElementById(button3).src  = 'img-wip/tab_event_off.gif';
			document.getElementById(button4).src  = 'img-wip/tab_photo_on.gif';
		}		
	}			

//-------------------------------------------------------------------------------------
// Function : Button Change On News
// Purpose : Change On Off Button On News
// Parameter : [IN] Button Id
// Author: Ronny Gunawan
// Date: 13 August 2008
//------------------------------------------------------------------------------------
function buttonhelp(buttonclick)
	{
		var button1 = "help";
		var button2 = "troubleshoot";
		var button3 = "faq";
		var button4 = "hubungi";
		
		if (buttonclick == "help")
		{
			document.getElementById(button1).src  = 'img-wip/help_topic_ON.gif';
			document.getElementById(button2).src  = 'img-wip/troubleshooting.gif';
			document.getElementById(button3).src  = 'img-wip/FAQ.gif';
			document.getElementById(button4).src  = 'img-wip/hubungi_kami.gif';
		}
		else if (buttonclick == "troubleshoot")
		{
			document.getElementById(button1).src  = 'img-wip/help_topic.gif';
			document.getElementById(button2).src  = 'img-wip/troubleshooting_ON.gif';
			document.getElementById(button3).src  = 'img-wip/FAQ.gif';
			document.getElementById(button4).src  = 'img-wip/hubungi_kami.gif';	
		}
		else if (buttonclick == "faq")
		{
			document.getElementById(button1).src  = 'img-wip/help_topic.gif';
			document.getElementById(button2).src  = 'img-wip/troubleshooting.gif';
			document.getElementById(button3).src  = 'img-wip/FAQ_ON.gif';
			document.getElementById(button4).src  = 'img-wip/hubungi_kami.gif';
		}
		else if (buttonclick == "hubungi")
		{
			document.getElementById(button1).src  = 'img-wip/help_topic.gif';
			document.getElementById(button2).src  = 'img-wip/troubleshooting.gif';
			document.getElementById(button3).src  = 'img-wip/FAQ.gif';
			document.getElementById(button4).src  = 'img-wip/hubungi_kami_ON.gif';
		}		
	}	
	
//-------------------------------------------------------------------------------------
// Function : Button Change On Top Picks
// Purpose : Change On Off Button On Top Picks
// Parameter : [IN] Button Id
// Author: Ronny Gunawan
// Date: 13 August 2008
//------------------------------------------------------------------------------------
function buttontoppicks(buttonclick)
	{
		if (buttonclick == "singles_toppicks")
		{
			var button1 = "singles_toppicks";
			var button2 = "albums_toppicks";
			document.getElementById(button1).src  = 'img-wip/tab_single_on.gif';
			document.getElementById(button2).src  = 'img-wip/tab_albums_off.gif';
		}
		else if (buttonclick == "albums_toppicks")
		{
			var button1 = "singles_toppicks";
			var button2 = "albums_toppicks";
			document.getElementById(button1).src  = 'img-wip/tab_single_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_albums_on.gif';
		}
	}
//-------------------------------------------------------------------------------------
// Function : Button Change On Reviews
// Purpose : Change On Off Button On Reviews
// Parameter : [IN] Button Id
// Author: Wilson
// Date: 09 September 2008
//------------------------------------------------------------------------------------
function buttonreviews(buttonclick)
	{
		if (buttonclick == "berita_reviews")
		{
			var button1 = "berita_reviews";
			var button2 = "interview_reviews";
			document.getElementById(button1).src  = 'img-wip/tab_playmusic_on.gif';
			document.getElementById(button2).src  = 'img-wip/tab_users_off.gif';
		}
		else if (buttonclick == "interview_reviews")
		{
			var button1 = "berita_reviews";
			var button2 = "interview_reviews";
			document.getElementById(button1).src  = 'img-wip/tab_playmusic_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_users_on.gif';
		}
	}
function buttonsingle(buttonclick)
	{
		if (buttonclick == "comments_reviews")
		{
			var button1 = "reviews_reviews";
			var button2 = "lyrics_reviews";
			var button3 = "comments_reviews";
			document.getElementById(button1).src  = 'img-wip/tab_reviews_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_lyrics_off.gif';
			document.getElementById(button3).src  = 'img-wip/tab_comments_on.gif';
		}
		else if (buttonclick == "reviews_reviews")
		{
			var button1 = "comments_reviews";
			var button2 = "lyrics_reviews";
			var button3 = "reviews_reviews";
			document.getElementById(button1).src  = 'img-wip/tab_comments_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_lyrics_off.gif';
			document.getElementById(button3).src  = 'img-wip/tab_reviews_on.gif';
		}
		else if (buttonclick == "lyrics_reviews")
		{
			var button1 = "comments_reviews";
			var button2 = "reviews_reviews";
			var button3 = "lyrics_reviews";
			document.getElementById(button1).src  = 'img-wip/tab_comments_off.gif';
			document.getElementById(button2).src  = 'img-wip/tab_reviews_off.gif';
			document.getElementById(button3).src  = 'img-wip/tab_lyrics_on.gif';
		}
	}


//-------------------------------------------------------------------------------------
// Function : Button Change On FAQ
// Purpose : Change On Off Button On FAQ
// Parameter : [IN] Button Id
// Author: Tommy
// Date: 13 November 2008
//------------------------------------------------------------------------------------
function buttonfaq(buttonclick)
	{
		var button1 = "general_faq";
		var button2 = "technical_faq";
		var button3 = "music_faq";
		if (buttonclick == "general_faq")
		{
			document.getElementById(button1).src  = 'img-wip/faq_general_on.gif';
			document.getElementById(button2).src  = 'img-wip/faq_technical.gif';
			document.getElementById(button3).src  = 'img-wip/faq_music.gif';
		}
		else if (buttonclick == "technical_faq")
		{
			
			document.getElementById(button1).src  = 'img-wip/faq_general.gif';
			document.getElementById(button2).src  = 'img-wip/faq_technical_on.gif';
			document.getElementById(button3).src  = 'img-wip/faq_music.gif';
		}
		else if (buttonclick == "music_faq")
		{
			document.getElementById(button1).src  = 'img-wip/faq_general.gif';
			document.getElementById(button2).src  = 'img-wip/faq_technical.gif';
			document.getElementById(button3).src  = 'img-wip/faq_music_on.gif';
		}
		
	}			

//-------------------------------------------------------------------------------------
// Function : Button Change On Review
// Purpose : Change On Off Button On Review
// Parameter : [IN] Button Id
// Author: Tommy
// Date: 13 November 2008
//------------------------------------------------------------------------------------
function buttonreview(buttonclick)
	{
		var button1 = "critic_review";
		var button2 = "user_review";
		if (buttonclick == "critic_review")
		{
			document.getElementById(button1).src  = 'img-wip/review_critic_on.gif';
			document.getElementById(button2).src  = 'img-wip/review_user.gif';
		}
		else if (buttonclick == "user_review")
		{
			document.getElementById(button1).src  = 'img-wip/revie_critic.gif';
			document.getElementById(button2).src  = 'img-wip/review_user_on.gif';
		}
		
		
	}			


	
//-------------------------------------------------------------------------------------
// Function : Pre-value search box
// Author: Wilson
// Date: 27 August 2008
//------------------------------------------------------------------------------------
function focus_text(e,warna,text)
{
	if(e.value==text)
	{
		e.style.color=warna;
		e.value="";
	}
}
function blur_text(e,warna,text)
{
	if(e.value=="")
	{
		e.style.color=warna;
		e.value=text;
	}
}
//-------------------------------------------------------------------------------------
// Function : Open/Close Cart popup using 1 button
// Purpose : Show / Hide cart popup using 1 button
// Parameter : this
// Author: Wilson
// Date: 12 September 2008
//------------------------------------------------------------------------------------
function toggleCart(e)
	{
		cartid = document.getElementById(e);
		if (cartid.href == "javascript:void(0);")
		{
			cartid.href="javascript:void(0)";
			popCart('cartpopup', 'cartframe', '../cart.asp', 0);
		}
		else if (cartid.href == "javascript:void(0)")
		{
			cartid.href="javascript:void(0);";
			unPopCart('cartpopup');
		}
	}	
//-------------------------------------------------------------------------------------
// Function : un/Select All songs
// Purpose : Remove/INSERT all songs into Precart
// Parameter : input type ID
// Author: Wilson
// Date: 23 September 2008
//------------------------------------------------------------------------------------
function selectAll(str)
{
	unselectAll(str);
	if (there == 0)
	{
		var form = document.forms["a"];
		var txtS = form[str];
		
		for (i = 0; i < form.length; i++)
			cartIn(txtS[i].value);
			
		
	}
	there = 1;
}
function unselectAll(str)
{
	var form = document.forms["a"];
	var txtS = form[str];
	for (i = 0; i < form.length; i++)
	cartOut(txtS[i].value);
}
//-------------------------------------------------------------------------------------
// Function : substitute a href with onClick
// Purpose : tooltip <a href> on IE not work
// Parameter : url
// Author: Wilson
// Date: 5 October 2008
//------------------------------------------------------------------------------------
function body_window(url){
eval('document.location.href=url');
}