<!-- This sets the onclick functionality for the song list in product display. -->
var tabberOptions = {

    'onClick': function(argsObj) {

    var t = argsObj.tabber; /* Tabber object */
    var id = t.id; /* ID of the main tabber DIV */
    var i = argsObj.index; /* Which tab was clicked (0 is the first tab) */
    var e = argsObj.event; /* Event object */

	if (t.tabs[i].headingText == "Song List") {
      loadToc(id.substring(3));
    }
  }

};

function loadToc(prime) {
	try	{    // Firefox, Opera 8.0+, Safari    
		xmlHttp=new XMLHttpRequest();    
	} catch (e) {    // Internet Explorer    
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			} catch (e) {
				alert("Your browser does not support AJAX!");
		        return null;        
		    }      
		}    
	}  
    xmlHttp.onreadystatechange=function() {
    	if(xmlHttp.readyState==4) {
 			var xmldoc = xmlHttp.responseXML;
 			//--alert(xmlHttp.responseText);
 			var toc = xmldoc.getElementsByTagName('toc');
 			var products = xmldoc.getElementsByTagName('product');
 			var titles = xmldoc.getElementsByTagName('product');
 			var artists = xmldoc.getElementsByTagName('artists');
 			var eprint = xmldoc.getElementsByTagName('product');
			var text = "<table>";
			text += "<tr><td><b>Product #<td><b>Title</b></td><td><b>Artist</b></td><td><b>Song #</b></td></tr>\n";
			var savprodnum = ""
 			for (var i=0; i < products.length; i = (i + 1)) {
 				var prodnum = xmldoc.getElementsByTagName('product')[i].getAttribute("prodnum");
				try	{
					try	{
						text += "<tr>";
						if (prodnum != savprodnum) {
							text += "<td>" + prodnum + "</td>";
							savprodnum = prodnum;
						} else {
							text += "<td>&nbsp;</td>";
						}
						text += "<td>";
						if (xmldoc.getElementsByTagName('title')[i].firstChild != null) {
							text += xmldoc.getElementsByTagName('title')[i].firstChild.nodeValue;
						}
						text += "</td><td>";
						if (xmldoc.getElementsByTagName('artist')[i].firstChild != null) {
							text += xmldoc.getElementsByTagName('artist')[i].firstChild.nodeValue;
						}
						text += "</td><td>";
						if (xmldoc.getElementsByTagName('eprintid')[i].firstChild != null) {
							eprintid = xmldoc.getElementsByTagName('eprintid')[i].firstChild.nodeValue;
							text += "<a href=\"/" + eprintid + ".item\">" + eprintid + "</a>";
						}
						text += "</td></tr>";
				 	} catch (inner) {
				 	}
				    var tocdiv = document.getElementById("tocdiv" + prime);
			        tocdiv.innerHTML = text;
	 			} catch (e) {
	 				alert(e);
	 			}
		 	}
    	}
    }
	
    var url="/catalog/aj?option=toclist&prime=" + prime;
    if (document.getElementById("tocdiv" + prime).innerHTML != "Please wait while we gather this information...") {
    	//--alert("div already loaded");
    } else {
		//--alert("Calling " + url);
	    xmlHttp.open("POST",url,true);
	    xmlHttp.send(null);	
	}
    return true;
}
