// JavaScript Document

var xmlhttp;


function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Mozilla, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5, IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=loadXML;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function parseTitle(t) {
	
	var cleanTab = t;
	
	while(cleanTab.match(/\(/)){
  		cleanTab=cleanTab.replace(/\([^\(\)]+\)/g,"");
	}
	
	cleanTab = cleanTab.trim();
	
	return(cleanTab);
}

function loadXML()
{
if(xmlhttp.readyState!=4) return;
if(xmlhttp.status!=200)
  {
  alert("Problem retrieving XML data - Error " + xmlhttp.status);
  return;
  }

var TABS = "";
var PRE="<div id='tcontent";
var MID="' class='tabcontent'><h2 class='title_Orange'>";
var H2="<h2 class='title_orange'>";
	var POST="</h2><ul id='greyList_1'>";
	var ITEMS="";
var CAP="</ul></div>";
var MINIPAGES="";

AUCTIONS=xmlhttp.responseXML.documentElement.getElementsByTagName("AUCTION");

var webroot = "http://www.eastendhouse.org/";


for (i=0;i<AUCTIONS.length;i++)
  {
  // Build List Items for this auction category:	  
  xx=AUCTIONS[i].getElementsByTagName("ITEM");
    {
	 ITEMS = ""; // Reset contents of ITEMS
	 
		for(m = 0; m<xx.length; m++) {
		//	alert(unescape(xx[m].firstChild.nodeValue));
			
		/*	try { ITEMS += "<li>" + unescape(xx[m].firstChild.nodeValue) + "</li>"; }
			
			catch (e if e instanceof TypeError) {
				  // handle TypeError exceptions
				  alert("TypeError!");
				} catch (e if e instanceof RangeError) {
				  // handle RangeError exceptions
				} catch (e if e instanceof EvalError) {
				  // handle EvalError exceptions
				} catch (e) {
				  throw "don't know what to do!";
				} finally {
				  ITEMS += "<li>" + unescape(xx[m].firstChild.nodeValue) + "</li>";
				}
		
		*/
			
			ITEMS += "<li>" + unescape(xx[m].firstChild.nodeValue) + "</li>";
		}
	}
  // Build TABS list and insert current ITEMS into current DIV
  xx=AUCTIONS[i].getElementsByTagName("CATEGORY");
    {
    try
      {
	  var TITLE = xx[0].firstChild.nodeValue;
//	  alert("Current section = " + TITLE);
      TABS += "<li><a href='javascript:;' rel='tcontent"+ i +"'>" + parseTitle(TITLE) + "</a></li>";
	  //need function to parse value up to [brackets]
	  //need function to strip [ and ] out of value
//	  alert("Creating new tab/tabcontent...");
	  MINIPAGES += PRE + i + MID + TITLE.replace(/[\(\)]/g,"") + POST + ITEMS + CAP;
      }
    catch (er)
      {
      MINIPAGES += "ERROR";
      }
    }
  }
  
document.getElementById('auctionTabs').innerHTML=TABS;

document.getElementById('auctionContent').innerHTML=MINIPAGES;

var myflowers=new ddtabcontent("flowertabs");
myflowers.setpersist(true);
myflowers.setselectedClassTarget("link"); //"link" or "linkparent"
myflowers.init();

}
