var btn1 = new Image();
btn1.src="/images/ui/button1.gif";
var btn2 = new Image();
btn2.src="/images/ui/button2.gif";


var isNS = navigator.appName.toLowerCase().indexOf("netscape") != -1;

function btn(img, state)
{
	window.status = "";
	var i = getImg(img);
	if(state == 'on')
		i.src = btn2.src;
	else
		i.src = btn1.src;
}

function getImg(id)
{
	return document.getElementById(id);		
}

function message(txt)
{
}


function ROImage(imgId, roImgSrc)
{
	var img = document.getElementById(imgId);
	if(!img) return;

	img.setAttribute("origSrc", img.src);
	img.setAttribute("altSrc", roImgSrc);

	img.attachEvent("onmouseover", ROImageIn);
	img.attachEvent("onmouseout", ROImageOut);	
}

function ROImageIn()
{
	var target = event.target || event.srcElement;
	if(target.nodeName != "IMG") return;

	target.src = target.getAttribute("altSrc");
}

function ROImageOut()
{
	var target = event.target || event.srcElement;
	if(target.nodeName != "IMG") return;

	target.src = target.getAttribute("origSrc");	
}


var isKHTML = (navigator.vendor == "Apple Computer, Inc." || navigator.vendor == "KDE");
var isIE = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);

/*
HTMLElement Prototyping in KHTML and WebCore
Copyright (C) 2005  Jason Davis, http://www.jasonkarldavis.com
Additional thanks to Brothercake, http://www.brothercake.com

This code is licensed under the LGPL:
	http://www.gnu.org/licenses/lgpl.html
*/

if (navigator.vendor == "Apple Computer, Inc." || navigator.vendor == "KDE") { // WebCore/KHTML
	(function(c) {
		for (var i in c)
			window["HTML" + i + "Element"] = document.createElement(c[ i ]).constructor;
	})({
		Html: "html", Head: "head", Link: "link", Title: "title", Meta: "meta",
		Base: "base", IsIndex: "isindex", Style: "style", Body: "body", Form: "form",
		Select: "select", OptGroup: "optgroup", Option: "option", Input: "input",
		TextArea: "textarea", Button: "button", Label: "label", FieldSet: "fieldset",
		Legend: "legend", UList: "ul", OList: "ol", DList: "dl", Directory: "dir",
		Menu: "menu", LI: "li", Div: "div", Paragraph: "p", Heading: "h1", Quote: "q",
		Pre: "pre", BR: "br", BaseFont: "basefont", Font: "font", HR: "hr", Mod: "ins",
		Anchor: "a", Image: "img", Object: "object", Param: "param", Applet: "applet",
		Map: "map", Area: "area", Script: "script", Table: "table", TableCaption: "caption",
		TableCol: "col", TableSection: "tbody", TableRow: "tr", TableCell: "td",
		FrameSet: "frameset", Frame: "frame", IFrame: "iframe"
	});

	function HTMLElement() {}
	HTMLElement.prototype     = HTMLHtmlElement.__proto__.__proto__;	
	var HTMLDocument          = document.constructor;
	var HTMLCollection        = document.links.constructor;
	var HTMLOptionsCollection = document.createElement("select").options.constructor;
	var Text                  = document.createTextNode("").constructor;
	var Node                  = Text;
}

if(!("attachEvent" in HTMLElement))
{

HTMLElement.prototype.attachEvent = function (sType, fHandler) {
   var shortTypeName = sType.replace(/on/, "");
   fHandler["handler"] = function (e) {
      window.event = e;
      return fHandler();
   };
   this.addEventListener(shortTypeName, fHandler["handler"], false);
};

HTMLElement.prototype.detachEvent = function (sType, fHandler) {
   var shortTypeName = sType.replace(/on/, "");
   if (typeof fHandler["handler"] == "function")
      this.removeEventListener(shortTypeName, fHandler["handler"], false);
   else   // we can always try :-)
      this.removeEventListener(shortTypeName, fHandler, true);
};

}


function showInfo(artist, album)
{
	GetAlbumInfo(artist, album);
}

function GetAlbumInfo(artist, album)
{
	var reqXml = "<GetAlbumInformation>";
	reqXml += "<artist>"+ artist + "</artist>";
	reqXml += "<album>" + album + "</album>";
    	reqXml += "</GetAlbumInformation>";

	var wshandler = new WebServiceHandler();
	wshandler.handler = handleAlbumInfo;
	wshandler.sendRequest("GetAlbumInformation", "http://hef.bifirecords.com/webservices/bifiservice.php", 
reqXml);
}

function handleAlbumInfo(xml)
{
	var ai = new AlbumInfo();
	ai.parse(xml);

	var infoDiv = document.getElementById("infoDiv");
	if(!infoDiv) return;

	infoDiv.style.display = "block";
	infoDiv.style.height = "auto";
	//infoDiv.style.border = "1px dashed #F0F0F0";

	var infoDiv2 = document.getElementById("infoDiv2");
	var img = document.getElementById("infoimg");
	img.src = ai.img;
	img.width = 100;
	
	var info = "<b>" + ai.bandname + "</b><br>";
	info += "<i>" + ai.title + "</i><br><br>";
	info += ai.description;
	info += "<br>";

	infoDiv2.innerHTML = info;

	//infoDiv2.style.backgroundColor = "#E0E0E0";
	//infoDiv2.style.opacity = 0.75;
}


var AlbumInfo = function() {};
AlbumInfo.prototype =
{
	artist: "",
	title: "",
	description: "",
	price: "",
	catalogNumber: "",
	img: "",
	bandname: "",
	trackNames: new Array(),
	mp3s: new Array(),

	parse: function(xml)
	{
		var node = xml.getElementsByTagName("return")[0];
		for(var i=0; i<node.childNodes.length; i++)
		{
			var child = node.childNodes[i];
			if(child.firstChild != null)
			{
				//alert(child.nodeName + ": " + child.firstChild.data);
				this[child.nodeName] = child.firstChild.data;
			}
		}
	}
}



var WebServiceHandler = function() {};

WebServiceHandler.prototype = 
{

	inited: false,
	async: true,
	xmlhttp: null,
	handler: null,

	init: function()
	{
		if(typeof ActiveXObject != 'undefined')
		{
			try
			{
				this.xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			}
			catch(e)
			{
				this.xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
			}
		}
		else if(typeof XMLHttpRequest != 'undefined')
		{
			this.xmlhttp = new XMLHttpRequest();
		}
		else
		{
			alert("your browser is not supported");
			return false;
		}

		var thisObj = this;
		this.handleResponse = function() { thisObj.handleXMLResponse(); };
		this.inited = true;
		
	},
	
	sendRequest: function (soapaction, url, body)
	{
		if(!this.inited)
			this.init();

		this.xmlhttp.open("POST", url, this.async);
		this.xmlhttp.onreadystatechange = this.handleResponse;
		var requestXml = this.soapRequestXML(body);
		this.xmlhttp.setRequestHeader("SOAPAction", soapaction);
		this.xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
		this.xmlhttp.send(requestXml);
	},

	handleXMLResponse: function()
	{
		if(this.xmlhttp.readyState == 4)
		{
			this.handler(this.xmlhttp.responseXML);

			/*
			if(this.xmlhttp.responseXML.xml)
				alert(this.xmlhttp.responseXML.xml);
			else if(typeof(XMLSerializer) != 'undefined')
			{
				var serializer = new XMLSerializer();
				alert(serializer.serializeToString(this.xmlhttp.responseXML));
			}
			else
				alert(this.xmlhttp.responseXML);
			*/
		}
	},

	soapRequestXML: function(body)
	{
		var env = "<?xml version=\"1.0\"?>";
		//env += "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\"";
		env += "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"";
		env += " soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">";
		env += "<soap:Body>";
		env += body;
		env += "</soap:Body>";
		env += "</soap:Envelope>";

		return env;
	}
}


