
// display limits
var maxartwork = 7;
var maxinstruments = 10;


// FADE.JS WORKS OFF OF RGB VALUES FOR IT'S BASE COLOR. 
// SET THE THREE VARIABLES BELOW TO THE RED, GREEN AND BLUE VALUES FOR YOUR 
// DESIRED BASE COLOR.

// the beginning color
var FADE_RED = 153; //51;
var FADE_GREEN = 0; //255;
var FADE_BLUE = 0;  //51;


// the target color
var goal_red = 255;
var goal_green = 255;
var goal_blue = 204;

//360147


// THE THREE VARIABLES BELOW DEFINE THE MOVEMENT OF THE FADE:
//
// 		FADE_HOLD 	= Time (in milliseconds) that your base color lasts
//					  before the fade begins.
//		FADE_SPEED 	= Time (in milliseconds) that each color of the fade lasts
//		FADE_STEP	= Increase in the RGB value per color change

var FADE_HOLD = 100;
var FADE_SPEED = 30;
var FADE_STEP = 25;

// FOR BASIC FUNCTIONALITY, LEAVE EVERYTHING BELOW THIS POINT AS IS.
var fade_r = FADE_RED
var fade_g = FADE_GREEN
var fade_b = FADE_BLUE

function fade(container)
{
	if (fade_r == 0) fade_r == FADE_RED;
	if (fade_g == 0) fade_g == FADE_GREEN;
	if (fade_b == 0) fade_b == FADE_BLUE;
	
	if (fade_r + fade_g + fade_b != (goal_red + goal_green + goal_blue))
	{	
		document.getElementById(container).style.background = "rgb(" + fade_r + "," + fade_g + "," + fade_b + ")";
		
		if ((fade_r == FADE_RED) && (fade_g == FADE_GREEN) && (fade_b == FADE_BLUE))
		{
			setTimeout('fade("' + container + '")', FADE_HOLD)
		}
		else
		{	
			setTimeout('fade("' + container + '")', FADE_SPEED)
		}
		
		if ((fade_r >= goal_red) || (fade_r + FADE_STEP > goal_red)) fade_r = goal_red; else fade_r = fade_r + FADE_STEP;
		if ((fade_g >= goal_green) || (fade_g + FADE_STEP > goal_green)) fade_g = goal_green; else fade_g = fade_g + FADE_STEP;
		if ((fade_b >= goal_blue) || (fade_b + FADE_STEP > goal_blue)) fade_b = goal_blue; else fade_b = fade_b + FADE_STEP;
	}
	else
	{	
		document.getElementById(container).style.background = "rgb(" + fade_r + "," + fade_g + "," + fade_b + ")";
		fade_r = FADE_RED;
		fade_g = FADE_GREEN;
		fade_b = FADE_BLUE;
	}
}




function addCart(obj)
{
	// we are calling this from the finder
	if ((obj == undefined) || (obj.id == null))
	{
		// load the catalogID
		var catalogid = this.getAttribute("catalogid")
		var price = this.getAttribute("price")
		var merchnotes = this.getAttribute("merchnotes")
		var merchtitle = this.getAttribute("merchtitle")
		var toolTipText = 'header=[] fade=[on] delay=[5000] body=[Click to remove ' + this.firstChild.nodeValue + ']'
		var digitalcount = this.getAttribute("digitalcount")
		var iHTML = this.firstChild.nodeValue;
		
		var artistname = this.getAttribute("artistname")
	 	var merchdelivery = this.getAttribute("merchdelivery")
	 	var merchformat = this.getAttribute("merchformat")
	 	var merchsource = this.getAttribute("merchsource")
	 	var merchyear = this.getAttribute("merchyear")
                var notesheader=this.getAttribute('notesheader');
                var sourceheader=this.getAttribute('sourceheader');
                var personnelheader=this.getAttribute('personnelheader');
                var songlength=this.getAttribute('songlength');
                var releasedate=this.getAttribute('releasedate');
	 	
	 	var musicians = new Array();
	 	var instruments = new Array();
	 	var images = new Array();
	 	var tempimg = null;
	 	var tempmus = null;
	 	var tempinst = null;

                // load the instruments and musicians	 	
	 	var i=1
	 	while(i>0)
	 	{
	 	    tempmus = this.getAttribute("musician" + i)
	 	    tempinst = this.getAttribute("instrument" + i)
	 	    if (tempmus == null || tempinst == null) {i = 0;} // we found our last musician
	 	    else { musicians[i] = tempmus; instruments[i] = tempinst; i=i+1; } // load this musician
	 	}
	 	
	 	// load the images
	 	i=1
	 	while(i>0)
	 	{
	 	    tempimg = this.getAttribute("image" + i);
	 	    if (tempimg == null) {i = 0;} // we found our last image
	 	    else { images[i] = tempimg; i=i+1; } // load this image
	 	}
	}
	// we are calling this from outside of the finder
	else {
		// load the catalogID
		var catalogid = obj.getAttribute("catalogid")
		var price = obj.getAttribute("price")
		var merchnotes = obj.getAttribute("merchnotes")
		var merchtitle = obj.getAttribute("merchtitle")
		var toolTipText = 'header=[] fade=[on] delay=[5000] body=[Click to remove ' + obj.firstChild.nodeValue + ']'
		var digitalcount = obj.getAttribute("digitalcount")    
                //document.getElementById('spotlightSource').innerHTML = merchsource;
		var iHTML = obj.firstChild.nodeValue;
		var artistname = obj.getAttribute("artistname")
	 	var merchdelivery = obj.getAttribute("merchdelivery")
	 	var merchformat = obj.getAttribute("merchformat")
	 	var merchsource = obj.getAttribute("merchsource")
	 	var merchyear = obj.getAttribute("merchyear")
                var notesheader=obj.getAttribute('notesheader');
                var sourceheader=obj.getAttribute('sourceheader');
                var personnelheader=obj.getAttribute('personnelheader');
                var songlength=obj.getAttribute('songlength');
                var releasedate=obj.getAttribute('releasedate');
	 	
	 	var musicians = new Array();
	 	var instruments = new Array();
	 	var images = new Array();
	 	var tempimg = null;
	 	var tempmus = null;
	 	var tempinst = null;

                // load the instruments and musicians	 	
	 	var i=1
	 	while(i>0)
	 	{
	 	    tempmus = obj.getAttribute("musician" + i)
	 	    tempinst = obj.getAttribute("instrument" + i)
	 	    if (tempmus == null || tempinst == null) {i = 0;} // we found our last musician
	 	    else { musicians[i] = tempmus; instruments[i] = tempinst; i=i+1; } // load this musician
	 	}
	 	
	 	// load the images
	 	i=1
	 	while(i>0)
	 	{
	 	    tempimg = obj.getAttribute("image" + i);
	 	    if (tempimg == null) {i = 0;} // we found our last image
	 	    else { images[i] = tempimg; i=i+1; } // load this image
	 	}
	}

	// test for the order list element and the order form field
	var o=document.getElementById('orders');
	var h=document.getElementById('selectedHighlights')
	if(!o || !h){return;}

        // check to see if we have already added this element and prevent (except for physical merchandise)
	lis=document.getElementById('orders').getElementsByTagName('a');
	for(i=0;i<lis.length;i++)
	{
		// if we already have this catalogID in the cart, and it is digital, then skip
		if ((lis[i].getAttribute("catalogid") == catalogid) && (digitalcount != "0")) {
		    
		// fade down the existing item in cart for feedback
		fade(lis[i].parentNode.id)

		// don't follow the link (causes refresh)
		return false;
		}
        }


	// create a new paragraph inside the orders list and add the item
	var newp=document.createElement('p');
	//newp.className = "cartlink"

	// create a random unique id so the fade algorithm can locate it in the presence of duplicates
	newp.id=Math.random();

	var link = document.createElement('a');
	//link.style.float = "left"

	link.setAttribute("catalogid", catalogid)
	link.setAttribute("merchtitle", merchtitle)
	link.setAttribute("digitalcount", digitalcount)
	link.setAttribute("price", price)
	link.setAttribute("merchnotes", merchnotes)
	link.setAttribute("artistname", artistname)
	link.setAttribute("merchdelivery", merchdelivery)
	link.setAttribute("merchformat", merchformat)
	link.setAttribute("merchsource", merchsource)
	link.setAttribute("merchyear", merchyear)
	link.setAttribute("notesheader", notesheader);
	link.setAttribute("sourceheader", sourceheader);
	link.setAttribute("personnelheader", personnelheader);
	link.setAttribute("songlength", songlength);
        link.setAttribute("releasedate", releasedate);

        for (var i in musicians) { link.setAttribute("musician" + i, musicians[i]); }
        for (var j in instruments) { link.setAttribute("instrument" + j, instruments[j]); }
        for (var k in images) { link.setAttribute("image" + k, images[k]); }

	var span1= document.createElement('span')
	var span2= document.createElement('span')
	span1.className = "cartItemDescriptionSpan"
	span2.className = "littlePriceSpan"

        // add extra informative text to the cart
        var temptype = catalogid.split("_").reverse()
        if (temptype[0] == "CD" || temptype[0] == "ALL") {
            merchtitle = merchtitle + " (" + temptype[0] + ")"  // this is the CD or ALL indicator
        }
        else if (temptype[0] == "TS") {
            merchtitle = merchtitle + " (" + temptype[1] + ")"  // this is the t-shirt size
        } 

	var textnode1 = document.createTextNode(merchtitle)
	var textnode2 = document.createTextNode(price)

	span1.appendChild(textnode1); 
	span2.appendChild(textnode2); 

	link.appendChild(span1);
	link.appendChild(span2);

	link.onclick=function()
	{
	    o.removeChild(newp);
	    RefreshCheckout();
	}
	
	link.onmouseover=updateSpotlight;

	newp.appendChild(link);

	// make each new item the topmost item in the cart
	o.insertBefore(newp, o.firstChild);

	// fade down the new addition to the cart
	fade(newp.id);

	RefreshCheckout();

	// don't follow the link (causes refresh)
	return false;
}

function updateSpotlight()
{
    var musicians = new Array();
    var instruments = new Array();
    var tempmus = null;
    var tempinst = null;
    var i=1

    var price = this.getAttribute('price');
    var artistname = this.getAttribute('artistname');
    var merchdelivery = this.getAttribute('merchdelivery');
    var merchtitle = this.getAttribute('merchtitle');	
    var merchformat = this.getAttribute('merchformat');
    var merchnotes = this.getAttribute('merchnotes');
    var merchsource = this.getAttribute('merchsource');
    var songlength = this.getAttribute('songlength');
    var catalogid = this.getAttribute('catalogid');
    var toolTipText = 'header=[] fade=[on] delay=[5000] body=[Click to remove ' + merchtitle + ']'
    var digitalcount = this.getAttribute("digitalcount")
    var merchyear = this.getAttribute('merchyear'); // '(' + this.getAttribute('merchyear') + ')';
    var notesheader=this.getAttribute('notesheader');
    var sourceheader=this.getAttribute('sourceheader');
    var personnelheader=this.getAttribute('personnelheader');
    var releasedate=this.getAttribute('releasedate');
    var releasedateFormatted=releasedate

    while(i<maxinstruments)
    {
        tempmus = this.getAttribute("musician" + i)
        tempinst = this.getAttribute("instrument" + i)

        if (tempmus == null || tempinst == null || tempmus == "" || tempinst == "") {

            document.getElementById("musician" + i).innerHTML = ''; 
            document.getElementById("instrument" + i).innerHTML = ''; 
            document.getElementById('spotlightSonglink').setAttribute('musician'+i, null);
            document.getElementById('spotlightSonglink').setAttribute('instrument'+i, null);
            document.getElementById('musician' + i).style.display = "none";            
            document.getElementById('instrument' + i).style.display = "none";            
            
        } // we found our last musician
        else { // load this musician and instrument (trust that we have an instrument entered for this musician)
            document.getElementById("musician" + i).innerHTML = tempmus+'&nbsp;'; 
            document.getElementById("instrument" + i).innerHTML = '('+tempinst+')'+'&nbsp;' 
            document.getElementById('spotlightSonglink').setAttribute('musician'+i, tempmus);
            document.getElementById('spotlightSonglink').setAttribute('instrument'+i, tempinst);
            document.getElementById('musician' + i).style.display = "inline";            
            document.getElementById('instrument' + i).style.display = "inline";            
        } 
        i=i+1;
    }

    var flashhtml=''

    // determine the flash content
    var temptype = catalogid.split("_").reverse()
    var coreid = catalogid.split("_")[0]
    var year=releasedate.split('-')[0]
    var month= "" + (parseInt(releasedate.split('-')[1]))
    var day=releasedate.split('-')[2]
    releasedateFormatted = month + '.' + day + '.' + year


    if (temptype[0] == "ALL" || temptype[0] == "CD") {
         flashhtml = '<object type=\"application/x-shockwave-flash\" data=\"http://www.royaltyetc.com/flash/musicplayer_f6.swf?playlist_url=http://www.royaltyetc.com/mp3/' + coreid + '.xspf" width=\"17\" height=\"17\" style=\"bgcolor=#FFFFFF;\"><param name=\"movie\" value=\"http://www.royaltyetc.com/flash/musicplayer_f6.swf?playlist_url=http://www.royaltyetc.com/mp3/' + coreid + '.xspf\" /><param name=\"bgcolor\" value=\"#FFFFFF\"/><img src=\"noflash.gif\" width=\"17\" height=\"17\" alt=\"\" /></object>'

         // turn off the album title in the release date area
         document.getElementById('spotlightSource').style.display = "none";            
    }
    else if (temptype[0] == "TS") { // turn off some stuff for tshirts
        flashhtml=''
        sourceheader=''
        personnelheader=''
        releasedateFormatted=''
        document.getElementById('spotlightSource').style.display = "inline";            
    } 
    else {
        flashhtml = '<object type=\"application/x-shockwave-flash\" data=\"http://www.royaltyetc.com/flash/musicplayer_f6.swf?song_url=http://www.royaltyetc.com/mp3/' + catalogid + '.mp3" width=\"17\" height=\"17\" style=\"bgcolor=#FFFFFF;\"><param name=\"movie\" value=\"http://www.royaltyetc.com/flash/musicplayer_f6.swf?song_url=http://www.royaltyetc.com/mp3/' + catalogid + '.mp3\" /><param name=\"bgcolor\" value=\"#FFFFFF\"/><img src=\"noflash.gif\" width=\"17\" height=\"17\" alt=\"\" /></object>'
        document.getElementById('spotlightSource').style.display = "inline";            
        // maybe in the future more intense date formatting? it would start here
        //var myDate=new Date();
        //var year=parseInt(releasedate.split('-')[0])
        //var month=parseInt(releasedate.split('-')[1]) + 1
        //var day=parseInt(releasedate.split('-')[2])
        //myDate.setFullYear(year,month,day);
    }

    // only create a sample player for audio
    //if (digitalcount != "0"){
    //    flashhtml = '<object type=\"application/x-shockwave-flash\" data=\"http://www.royaltyetc.com/flash/musicplayer_f6.swf?song_url=http://www.royaltyetc.com/mp3/' + catalogid + '.mp3" width=\"17\" height=\"17\" style=\"bgcolor=#FFFFFF;\"><param name=\"movie\" value=\"http://www.royaltyetc.com/flash/musicplayer_f6.swf?song_url=http://www.royaltyetc.com/mp3/' + catalogid + '.mp3\" /><param name=\"bgcolor\" value=\"#FFFFFF\"/><img src=\"noflash.gif\" width=\"17\" height=\"17\" alt=\"\" /></object>'
    //}

    document.getElementById('flashplayer').innerHTML = flashhtml
    document.getElementById('spotlightTitlePrice').innerHTML = price;
    document.getElementById('spotlightArtistName').innerHTML = artistname;
    document.getElementById('merchDelivery').innerHTML = merchdelivery;
    
    document.getElementById('spotlightNotesHeader').innerHTML = notesheader;
    document.getElementById('spotlightSourceHeader').innerHTML = sourceheader;
    document.getElementById('spotlightPersonnel').innerHTML = personnelheader;
    document.getElementById('spotlightSongLength').innerHTML = '(' + songlength + ')';
    
    document.getElementById('spotlightFormat').innerHTML = merchformat;
    document.getElementById('spotlightNotes').innerHTML = merchnotes;
    document.getElementById('spotlightSource').innerHTML = merchsource;
    document.getElementById('spotlightYear').innerHTML = releasedateFormatted;
    document.getElementById('spotlightSonglink').innerHTML = merchtitle;
    document.getElementById('spotlightSonglink').setAttribute('merchtitle', merchtitle);
    document.getElementById('spotlightSonglink').setAttribute('catalogid', catalogid);
    document.getElementById('spotlightSonglink').setAttribute('digitalcount', digitalcount);
    document.getElementById('spotlightSonglink').setAttribute('price', price);
    document.getElementById('spotlightSonglink').setAttribute('merchnotes', merchnotes);
    document.getElementById('spotlightSonglink').setAttribute('artistname', artistname);
    document.getElementById('spotlightSonglink').setAttribute('merchdelivery', merchdelivery);
    document.getElementById('spotlightSonglink').setAttribute('merchformat', merchformat);
    document.getElementById('spotlightSonglink').setAttribute('merchsource', merchsource);
    document.getElementById('spotlightSonglink').setAttribute('merchyear', merchyear);
    document.getElementById('spotlightSonglink').setAttribute("songlength", songlength);
    document.getElementById('spotlightSonglink').setAttribute('notesheader',notesheader);
    document.getElementById('spotlightSonglink').setAttribute('sourceheader',sourceheader);
    document.getElementById('spotlightSonglink').setAttribute('personnelheader',personnelheader);
    document.getElementById('spotlightSonglink').setAttribute('releasedate',releasedate);

    var ext = ''
    var val = ''
    // determine graphics extention type
    if (BrowserDetect.browser == "Explorer" && BrowserDetect.version < 7) {ext='.gif';}
    else {ext='.png';}

    var untouched = true;
    var numpics = 0;
    var i=1;
    while(i<maxartwork)
    {
        val = this.getAttribute('image'+i);
        if (val != null) 
        {
            // save image for spotlight update        
            document.getElementById('littleimage' + i).style.display = "block";
            document.getElementById('littleimage' + i).style.visibility = "visible";
            document.getElementById('littleimage' + i).src = val+'s'+ext;
            document.getElementById('littleimage' + i).onmouseover = makeShowMeCallback(val+ext); // must use a function generator to scope the val value outside of this loop
            document.getElementById('spotlightSonglink').setAttribute('image'+i, val);

            // load the main album cover
            if (i == 1) {
               document.bigimage.src = val+ext;
               document.getElementById('littleimage' + i).src = val+'s'+ext;
            }
        }
        else 
        {
            // hide the divs when no artwork present
            if (document.getElementById('littleimage' + i)) {
               document.getElementById('littleimage' + i).style.visibility = "hidden";
               document.getElementById('littleimage' + i).style.display = "none";
               document.getElementById('spotlightSonglink').setAttribute('image'+i, null);
            }
            
            if (untouched) {
               numpics = i-1; untouched=false;
               
               // hide/unhide the second table at 3 items
               if (numpics >= 2){document.getElementById('imagerow2container').style.display = "inline"; } // inline display gives us neat staggered display
               else { document.getElementById('imagerow2container').style.display = "none"; }
               
            }
        }
        i=i+1;
    }
    
    // copy all these features to other links (IE only method)
    if (BrowserDetect.browser == "Explorer") 
    {
        document.getElementById('spotlightTitlePrice').mergeAttributes(document.getElementById('spotlightSonglink'));
        document.getElementById('merchDelivery').mergeAttributes(document.getElementById('spotlightSonglink'));
    }
}





/*
 * ul2finder
 * original version written by Christian Heilmann (http://icant.co.uk)
 * turns the nested list with the ID "finder" into a dynamic list
 * uses the CSS classes defined in the variables
 */
function ul2finder()
{
	// Define variables used and classes to be applied/removed
	var i,uls,als,finder;
	var parentClass='parent';
	var showClass='shown';
	var hideClass='hidden';
	var openClass='open';

	// check if our finder list exists, if not, stop all activities
	finder=document.getElementById('finder');
	if(!finder){return;}

	// add the class domenabled to the body
	cssjs('add',document.body,'domenabled')

	// loop through all lists inside finder, position and hide them 
	// by applying the class hidden
	uls=document.getElementById('finder').getElementsByTagName('ul');
	for(i=0;i<uls.length;i++)
	{
		cssjs('add',uls[i],hideClass);
	}	

	// loop through all links of inside finder
	lis=document.getElementById('finder').getElementsByTagName('li');
	for(i=0;i<lis.length;i++)
	{
		// if the li containing the link has no nested list, skip this one
		if(!lis[i].getElementsByTagName('ul')[0])
		{
			// if the list item is one of the final options
			lis[i].getElementsByTagName('a')[0].onclick=addCart;
			lis[i].getElementsByTagName('a')[0].onmouseover=updateSpotlight;
			continue;
		}
		
		
		var newa=document.createElement('a');
		newa.href='#';
		newa.appendChild(document.createTextNode(lis[i].firstChild.nodeValue));
		lis[i].replaceChild(newa,lis[i].firstChild);
		// otherwise apply the parent class
		cssjs('add',newa,parentClass);
		
		// if the user clicks on the link
		lis[i].getElementsByTagName('a')[0].onclick=function()
		{
		// loop through all lists inside finder
			for(var i=0;i<uls.length;i++)
			{
				// avoid the list connected to this link
				var found=false;
				for(j=0;j<uls[i].getElementsByTagName('ul').length;j++)
				{
					if(uls[i].getElementsByTagName('ul')[j] == 		
						this.parentNode.getElementsByTagName('ul')[0])
					{
						// attempt to vertically size "finderparent" to size of collection
						var finderparent = document.getElementById('finderparent');
						var collectionSize = this.parentNode.getElementsByTagName('a').length
						var heightMultiplier = 1.45
						var newheight = collectionSize * heightMultiplier;
						if (newheight < 12)
						{
						    newheight = 12;
						}
						newheight+="em";
						finderparent.style.height = newheight;
						found=true;
						break;
					}
				}
				// and hide all others
				if(!found)
				{
					cssjs('add',uls[i],hideClass)
					cssjs('remove',uls[i],showClass)
					cssjs('remove',uls[i].parentNode.getElementsByTagName('a')[0],openClass)
					cssjs('add',uls[i].parentNode.getElementsByTagName('a')[0],parentClass)
				}
			}	
			// change the current link from parent to open 	
			cssjs('swap',this,parentClass,openClass)
			// show the current nested list 
			cssjs('add',this.parentNode.getElementsByTagName('ul')[0],showClass)

                        //var collectionSize = this.parentNode.getElementsByTagName('a').length
                        //var heightMultiplier = 1.3
			//var newheight = collectionSize * heightMultiplier;
                        //if (newheight < 8)
                        //{
                        //    newheight = 8;
                        //}
                        //newheight+="em";


                        
			// auto-adjust height of selector box container
			var finderparent = document.getElementById('finderparent');
			switch (this.firstChild.nodeValue){
				case "Middlepicker":
				case "Seymore Saves the World":
				case "Space Camp":
				case "ZibraZibra":
				case "Collapsticator":
				case "Ty Morse":
				case "Grickle-grass":
				    newheight = "12em";
 		                    finderparent.style.height = newheight;
 		                    break;
			}

			// don't follow the real HREF of the link
			return false;
		}
	}	
	/*
	 * cssjs
	 * written by Christian Heilmann (http://icant.co.uk)
	 * eases the dynamic application of CSS classes via DOM
	 * parameters: action a, object o and class names c1 and c2 (c2 optional)
	 * actions: swap exchanges c1 and c2 in object oreleasedate
	 *			add adds class c1 to object o
	 *			remove removes class c1 from object o
	 *			check tests if class c1 is applied to object o
	 * example:	cssjs('swap',document.getElementById('foo'),'bar','baz');
	 */
	function cssjs(a,o,c1,c2)
	{
		switch (a){
			case 'swap':
				o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;
		}
	}
	
	// prevent flicker of the menu by setting menu to visible here
	var o=document.getElementById('finderparent');
	o.style.visibility = "visible";

    document.body.style.visibility = "visible";






	
}






var xmlhttp = false;
function createXMLHttpRequest(){
        /*@cc_on
        @if (@_jscript_version>= 5)
                try {
                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try {
                                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (E) {
                                xmlhttp = false;
                        }
                }
        @else
        xmlhttp = false;
        @end @*/
        if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
                try {
                        xmlhttp = new XMLHttpRequest();
                } catch (e) {
                        xmlhttp = false;
                }
        }
        return xmlhttp;
}


function RefreshCheckout()
{
    URL = 'http://www.royaltyetc.com/cgi-bin/cart.py?op=ajax&random=' + Math.random()
    if(xmlhttp){
        xmlhttp.abort();
    }
    
    // Create the object each time a call is about to be made
    if(createXMLHttpRequest()){
	xmlhttp.open("GET", URL, true);
	xmlhttp.onreadystatechange = receiveCheckoutButtons;
	
	// loop through all links of inside finder
	var j=0
	lis=document.getElementById("orders").getElementsByTagName('p');
	for(i=0;i<lis.length;i++)
	{
	    j = i+1
	    j+="" // convert j to a string
            xmlhttp.setRequestHeader(j,lis[i].firstChild.getAttribute("catalogid"))
        }	
	
	xmlhttp.send(null);
    }
}

function receiveCheckoutButtons(){
    if(xmlhttp && xmlhttp.readyState == 4){
        // Do some magic
        document.getElementById("buttons").innerHTML = xmlhttp.responseText;

        // Delete the object after the call is done
        xmlhttp = null;
    }
}


function setAttributeCallback (obj, attribute,value) {
    return value;    
}

function makeShowMeCallback(path) {
  return function() {
    showMe(path);
  };
}

function showMe(path) {
  document.bigimage.src = path; return true;
}

