function decoderFunc2(thisstring) {
	var returnstring = unescape(thisstring);
	var returnstring2 = returnstring.replace(/\+/g, " ");
	return returnstring2;
}

// holds an instance of XMLHttpRequest
var xmlHttpGigs = createXmlHttpRequestObject();

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttpGigs;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttpGigs = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array('MSXML2.xmlHttpGigs.6.0',
                                    'MSXML2.xmlHttpGigs.5.0',
                                    'MSXML2.xmlHttpGigs.4.0',
                                    'MSXML2.xmlHttpGigs.3.0',
                                    'MSXML2.XMLHTTP',
                                    'Microsoft.XMLHTTP');
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttpGigs; i++) 
    {
      try 
 
      { 
        // try to create XMLHttpRequest object
        xmlHttpGigs = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttpGigs)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttpGigs;
}

// read a file from the server
function displayGigs() {

	var contentScroller = document.getElementById('contentscroller');
	contentScroller.innerHTML = "<div style=\"width:100%;text-align:center\"><img src=\"images/loader.gif\" alt=\"WAIT! It's loading...\" /></div>";
  // only continue if xmlHttp isn't void
  if (xmlHttpGigs)
  {
 
    // try to connect to the server
    try
    {
	 
	var theUrl = "processing/getgigs.php";
		
    	// initiate reading a file from the server
    	xmlHttpGigs.open("GET", theUrl, true);
    	xmlHttpGigs.onreadystatechange = handleRequestStateChangeMail;
    	xmlHttpGigs.send(null);
		
    }
    // display the error in case of failure
    catch (e)
    {
		contentScroller.innerHTML = "There was a problem loading the Gigs. Please try again later.";
      //alert("Can't connect to server:\n" + e.toString());
    }
  }
}

// function called when the state of the HTTP request changes
function handleRequestStateChangeMail() 
{
	var contentScroller = document.getElementById('contentscroller');
  // when readyState is 4, we are ready to read the server response
  if (xmlHttpGigs.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttpGigs.status == 200) 
    {
      try
      {
        // do something with the response from the server
        handleServerResponseGigs();
      }
      catch(e)
      {
        // display error message
        //alert("Error reading the response: " + e.toString());
		contentScroller.innerHTML = "There was a problem loading the Gigs. Please try again later.";
      }
    } 
    else
    {
      // display status message
      //alert("There was a problem retrieving the data:\n" +  xmlHttpGigs.statusText);
	  contentScroller.innerHTML = "There was a problem loading the Gigs. Please try again later.";
    }
  }
}

 
// handles the response received from the server
function handleServerResponseGigs()
{
	pageTracker._trackPageview("/gigs" );
  	// read the message from the server
  	var xmlResponseMail = xmlHttpGigs.responseXML;
	if (typeof document.all == "undefined") {
		xmlResponseMail.normalize();
	}
  	// obtain the XML's document element
 	 xmlRootMail = xmlResponseMail.documentElement;  
  	// obtain arrays with manufacturer names and ids 
  	buylinksArray = xmlRootMail.getElementsByTagName("buylink");
	datesArray = xmlRootMail.getElementsByTagName("date");
	venuesArray = xmlRootMail.getElementsByTagName("venue");
	descArray = xmlRootMail.getElementsByTagName("description");
  	// generate HTML output
	var html = "";
  	// iterate through the arrays and create an HTML structure
	if(datesArray.length < 1) {
		html += "There are no gigs listed. Come back and check later!";
	} else {
		//alert("returned results!");
		html += "<table width=\"100%\" border=\"0\" cellpadding=\"6\" cellspacing=\"0\">";
		for (var i=0; i < datesArray.length; i++) {
			html += "<tr>";
			html += "<td style=\"width:36px;\">";
			html += "<a href=\"" + buylinksArray.item(i).firstChild.data + "\" target=\"_blank\"><img src=\"../images/buybutton.gif\" width=\"36\" height=\"13\" alt=\"Buy Tickets\"></a>";
			html += "</td>";
			html += "<td style=\"width:70px;\">";
			html += datesArray.item(i).firstChild.data;
			html += "</td>";
			html += "<td style=\"width:210px;\">";
			html += venuesArray.item(i).firstChild.data;
			html += "</td>";
			html += "<td style=\"width:320px;\">";
			if(descArray.item(i).firstChild.data != "-") {
				html += descArray.item(i).firstChild.data;
			} else {
				html += "&nbsp;"
			}
			
			html += "</td>";
			html += "</tr>";
		}
		html += "</table>";
	
	}
	
	//var myDiv = document.getElementById("contentscroller");
	// display the HTML output
	//myDiv.innerHTML = html;
	document.getElementById('contentscroller').innerHTML = html;
	
}
