
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 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;
}

/**_____________________________
|							|
| 	The Mighty Popup				|
|							|
|							|
|_____________________________**/

var loaded = new Array();
function cobacoba(url, string, TheDiv, asd)
{
var x;
var loadedstatus;
	for (x in loaded) //is the div already loaded ? Look inside the array
		{
		if (loaded[x]==string)
		loadedstatus=1;
		}
	loaded[x] = string;
/*	loaded[x] = string;
	alert(loaded[x]);
	for (x in loaded)
	{
		if (loaded[x]==string)
		loadedstatus=1;
	}*/

	if (loadedstatus != 1) //If not, load it and add it to the array (love the splice thingy)
		{
		changeRequest(url, string, TheDiv);
		buttontoppicks(asd);
		loaded.splice(0,0,TheDiv);
		}
	else if (loadedstatus==1)
		{
		loadedstatus = 0;
		buttontoppicks(asd);
		}
}


function Popup(url, str, titl, conf)
{
if (titl=="")
{
titl="Default"; //Default popup title
}

	//----Wilson---- get size cross-browser
	if (self.innerHeight) { // Everyone but IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		myScroll = document.documentElement.scrollTop;
	} else if (document.body) { // Other IE, such as IE7
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		myScroll = document.body.scrollTop;
	}
	// get page height - cross browser
	if (window.innerHeight && window.scrollMaxY) {	
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		myScrollWidth = document.body.offsetWidth;
		myScrollHeight = document.body.offsetHeight;
	}
	//-----------------------

this.Id = "popme"; // Will be used as general ID, the boder will be named [Id]border, and the container for the ajax called div container_[id]
this.Top = (myHeight-1100/2)+myScroll; // Distance from the top in pixels
this.Left = screen.height/3; // Distance from the left in pixels
this.Height = 450; // Height WITHOUT the border
this.Width = 600; // Width WITHOUT the border
this.BgColor = "#eef3f7"; //Container BG
this.BgImg = ""; // Container BG image
this.A_Mask = ['#000000', 0, 40, 2000]; //Fading mask behind the popup, color, opacity start, opacity stop, speed
this.A_Border = [1, '#CDCDCD']; //Border, width in pixel and color
this.A_Title = [23, titl, '#F0F4F7', 'img-wip/bgCart.gif', 'img-wip/cart-no.gif']; // Title bar, height, title, background color, background image, close button
Border = Id+"border";
Container = "container_"+Id;

// Config for LOGIN POPUP
if (conf=="login") {
	this.Height = 600;
	this.Width = 390;
	this.Left = screen.height/2.25;
//	this.Top = (myHeight-1200/2)+myScroll;
	this.Top = 10;
	this.BgColor = "#fff";
	//this.left= (screen.width - this.Width)/2;
	this.A_Title = [25, titl, '#F0F4F7', 'img-wip/bgCart.gif', 'img-wip/cart-no.gif'];
}
if (conf=="wizard") {
	this.Height = 246;
	this.Width = 420;
	this.Left = screen.height/2.5;
	this.Top = (myHeight-900/2)+myScroll;
	this.BgColor = "#f0f0f7";
	this.A_Title = [25, titl, '#f0f0f7', 'img-wip/bgCart.gif', 'img-wip/cart-no.gif'];
}
if (conf=="player") {
	this.Height = 275;
	this.Top = (myHeight-900/2)+myScroll;
	this.A_Title = [25, titl, '#f0f0f7', 'img-wip/bgCart.gif', 'img-wip/cart-no.gif'];
}
if (conf=="passchange") {
	this.Height = 200;
	this.Width = 390;
	this.Left = screen.height/2.25;
//	this.Top = (myHeight-1000/2)+myScroll;
	this.Top = screen.width/5;
	this.BgColor = "#f0f0f7";
	this.A_Title = [25, titl, '#f0f0f7', 'img-wip/bgCart.gif', 'img-wip/cart-no.gif'];
}
//Creates the fading mask

	this.Mask = function (BgColor, opacStart, opacEnd, Millisec)
	{
	var div = document.createElement("div")	
	var Style = div.style;
	div.id = "mask";
	Style.zIndex="2"
	Style.top = "0px";
	Style.left = "0px";
	Style.height = myScrollHeight; //If you find a better way let me know :D
	Style.width = "100%";
	Style.position = "absolute";
	Style.backgroundColor = BgColor;
	Style.display = "none";
	
	document.body.appendChild(div);
	
		//Cross browser way to set the opacity
		Fade = function Opac(opacity) 
		{
		Style.opacity = (opacity / 100);
		Style.MozOpacity = (opacity / 100);
		Style.KhtmlOpacity = (opacity / 100);
		Style.filter = "alpha(opacity=" + opacity + ")";
		} 
		//Sets the base opacity
		Fade(0);
		//Makes the layer visible
		Style.display = "block";
		
		if (Millisec != 0)
		{
			//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("Fade("+i+")",(timer * speed));
					timer++;
				}
			} 
			else if(opacStart < opacEnd) 
			{
				for(i = opacStart; i <= opacEnd; i++)
					{
					setTimeout("Fade("+i+")",(timer * speed));
					timer++;
					}
			}
		}
		else
		{
			Fade(opacEnd);
			Style.display = "block";
		}
	}

//Makes new divs, used for the border and the container, absolute position to allow transparency effects on the border
	
	this.MakeDiv = function (Id, Zindex, Overflow, Top, Left, Height, Width, BgColor, BgImg)
	{
	div = document.createElement("div")
	Style = div.style;
	div.id = Id;
	Style.overflow = Overflow;
	Style.zIndex= "100";
	Style.top = Top +"px";
	Style.left = Left +"px";
	Style.height = Height +"px";
	Style.width = Width +"px";
	Style.position = "absolute";
	Style.backgroundColor = BgColor;
	Style.color ="#ffffff";
		
	//Checks the background image, we don't want to write unnecessary code
	if (BgImg != "")
		{
		Style.backgroundImage = "url('"+BgImg+"')";
		}
	
	document.body.appendChild(div);
	}

//Makes a title bar and appends it, with the close button	
	Title = function(Border, Parent, Height, Content, BgColor, BgImg, CloseImg)
	{
	InDiv = document.createElement("div");
	InStyle = InDiv.style;
	InDiv.id = "title_"+Parent;
	InStyle.ClassName = "popuptitle";
	InStyle.height = Height+"px";
	InStyle.width = "100%";
	InStyle.border = "0px";
//	InStyle.padding = "5 0 0 0";
	InStyle.margin = "0px;";
	InStyle.backgroundColor = BgColor;
	
	Inside = "<h3 style='border:0px;margin: 1 0 0 15px;color:#000; font-size:12; text-align:left; padding-top:3;'><div style='float:left;margin-right:5;'><img src='../img-wip/logo_small.gif'></div><label style='margin-top:3;'>"+Content+"</label></h3><a style='position:absolute; right:3; top:4' href='javascript:void(0);' onclick='CloseMe()'><img src='" + CloseImg + "' /></a>"
	
	if (BgImg != "")
		{
		InStyle.background = "url('"+BgImg+"') repeat-x";
		}
	
	InDiv.innerHTML = Inside;
	document.getElementById(Parent).appendChild(InDiv);
	}
	
//Ajax call
	Change = function(url, string, Id)
	{
		
	InDiv = document.createElement("div");
	InDiv.innerHTML = "Loading...";
	InStyle = InDiv.style;
	InDiv.id = "content_"+Id;
	InStyle.ClassName = "popupclass";
	InStyle.height = "100%";
	InStyle.width = "100%";
	InStyle.border = "0px";
	InStyle.margin = "0px;";
	document.getElementById(Container).appendChild(InDiv);
	
	changeRequest(url, string, InDiv.id);
	}
	
		CloseMe = function()
	{
		CloseMask = document.getElementById('mask');
		document.body.removeChild(CloseMask);
		CloseBorder = document.getElementById(Border);
		document.body.removeChild(CloseBorder);
		CloseContainer = document.getElementById(Container);
		document.body.removeChild(CloseContainer);
	}
	

	Mask(A_Mask[0], A_Mask[1], A_Mask[2], A_Mask[3]);
	MakeDiv(Id+"border",2, "",Top-(A_Border[0]/2), Left-(A_Border[0]/2), Height+A_Border[0], Width+A_Border[0], A_Border[1], A_Border[1]);
	MakeDiv(Container,4, "hidden", Top, Left, Height, Width, BgColor, BgImg,"","");
	Title(Id+"border", Container, A_Title[0],  A_Title[1], A_Title[2], A_Title[3], A_Title[4]);
	Change(url, str, Container);			
}


/**_____________________________
|							|
| 	Cart Functions 				|
|							|
|							|
|_____________________________**/

if (document.images)
{
cartNo= new Image(); 
cartNo.src="img-wip/cart-no.gif"; 
 
cartGo= new Image(); 
cartGo.src="img-wip/cart-go.gif"; 
}

var there = 0;
var IdArray = [];
function cartIn(TheButton)
{
var i;
var there = 0;
TheID = document.getElementById(TheButton).id;
ImgNo = "<img id='"+TheID+"' onclick='cartOut("+TheID+")' class='left' src='../img-wip/cart-no.gif'> <img onclick='validate(\"module/ajax/precart.asp\")' class='left' src='../img-wip/cart-go.gif'>"
ImgYes = "<img id='"+TheID+"' onclick='cartIn("+TheID+")' class='left' src='../img-wip/cart.gif'>"

	if (IdArray=="")
	{
	document.getElementById("wrapper"+TheID).innerHTML = ImgNo;
	IdArray.push(TheID);
	str = "Shopping Cart ("+IdArray.length+")";
	there = 0;
	}
	else
	{
		for (i=0;i<IdArray.length;i++)
		{
			if(IdArray[i]==TheID)
			{
			there = 1;
			alert(' Lagu ini sudah dimasukin shopping cart ;) ');
			}
		}
		if (there == 0)
		{
		document.getElementById("wrapper"+TheID).innerHTML = ImgNo;
		IdArray.push(TheID);
		str = "Shopping Cart ("+IdArray.length+")";
		}
	}
}

function cartOut(TheButton)
{
var i
TheID = document.getElementById(TheButton).id;
ImgYes = "<img id='"+TheID+"' onclick='cartIn("+TheID+")' class='left' src='../img-wip/cart.gif'>"
	for (i=0;i<IdArray.length;i++)
	{
		if(IdArray[i]==TheID)
		{
		document.getElementById("wrapper"+TheID).innerHTML = ImgYes;
		IdArray.splice(i, 1);
		there = 0;
		}
	}
}

// _box buat tooltip -------------
function cartIn_box(TheButton)
{
var i;
var there = 0;
TheID = document.getElementById(TheButton).id;
ImgNo = "<img id='"+TheID+"' onclick='cartOut_box("+TheID+")' class='left' src='../img-wip/cart-no.gif'> <img onclick='validate(\"module/ajax/precart.asp\")' class='left' src='../img-wip/cart-go.gif'>";
ImgYes = "<img id='"+TheID+"' onclick='cartIn_box("+TheID+")' class='left' src='../img-wip/cart.gif'>";

	if (IdArray=="")
	{
	IdArray.push(TheID);
	str = "Shopping Cart ("+IdArray.length+")";
	there = 0;
	document.getElementById("wrappers"+TheID).innerHTML = ImgNo;
	}
	else
	{
		for (i=0;i<IdArray.length;i++)
		{
			if(IdArray[i]==TheID)
			{
			there = 1;
			alert(' Lagu ini sudah dimasukin shopping cart ;) ');
			}
		}
		if (there == 0)
		{
		IdArray.push(TheID);
		str = "Shopping Cart ("+IdArray.length+")";
		document.getElementById("wrappers"+TheID).innerHTML = ImgNo;
		}
	}
}
function cartOut_box(TheButton)
{
var i;
TheID = document.getElementById(TheButton).id;
ImgYes = "<img id='"+TheID+"' onclick='cartIn_box("+TheID+")' class='left' src='../img-wip/cart.gif'>"
	for (i=0;i<IdArray.length;i++)
	{
		if(IdArray[i]==TheID)
		{
		document.getElementById("wrappers"+TheID).innerHTML = ImgYes;
		IdArray.splice(i, 1);
		there = 0;
		}
	}
}
//---------------- buat single page----------------
function cartIn_single(TheButton)
{
//alert(TheButton);

var i;
var there = 0;
IdArray.pop();
TheID = document.getElementById(TheButton).id;
ImgNo = "<img id='"+TheID+"' onclick='cartOut("+TheID+")' class='left' src='../img-wip/cart-no.gif'> <img onclick='validate(\"module/ajax/precart.asp\")' class='left' src='../img-wip/cart-go.gif'>"
ImgYes = "<img id='"+TheID+"' onclick='cartIn("+TheID+")' class='left' src='../img-wip/cart.gif'>"

	if (IdArray=="")
	{
//	document.getElementById("wrapper"+TheID).innerHTML = ImgNo;
	IdArray.push(TheID);
	//alert(TheID);
	str = "Shopping Cart ("+IdArray.length+")";
	there = 0;
	
	validate("module/ajax/precart.asp");
	}
	else
	{
		for (i=0;i<IdArray.length;i++)
		{
			//alert(TheID);
			if(IdArray[i]==TheID)
			{
			there = 1;
			alert(' Lagu ini sudah dimasukin shopping cart ;) ');
			}
		}
		if (there == 0)
		{
//		document.getElementById("wrapper"+TheID).innerHTML = ImgNo;
		IdArray.push(TheID);
		str = "Shopping Cart ("+IdArray.length+")";
		validate("module/ajax/precart.asp");
		}
	}
}

function validate(TheUrl)
{
params=IdArray[0]+";";
url = TheUrl;
	for (i=1;i<IdArray.length;i++)
	{
		params = params + IdArray[i]+";";
	}

trailer = params.lastIndexOf(";");
params = params.substr(0, trailer);
params = params + "&t=" + IdArray.length;
Popup(url, params,'Shopping Cart');
}

// Count characters left in textarea
function counter(TheText,TheCounter, Limit)
{
	TextString = document.getElementById(TheText).value;
	Text = TextString.length;

	if (Text>Limit)
	{
		document.getElementById(TheCounter).innerHTML = "0 karakter tersisa";
		document.getElementById(TheText).value = TextString.substr(0, Limit);
	}
	else
	{
		document.getElementById(TheCounter).innerHTML = Limit-Text+" karakter tersisa";
	}
}


function keyDown(e)
{
	
	if (!e) var e = window.event
	if (e.keyCode) key = e.keyCode;
	else if (e.which) key = e.which;

	if (key == 27)
	{
		closeMe();
	}
}
document.onkeydown = keyDown;

// Goggle tracking
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'  type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-6735980-1");
pageTracker._trackPageview();
} catch(err) {}