var xmlhttp;
var doc;

function loadXMLDoc(url)
{
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)  {
	  xmlhttp=new XMLHttpRequest();
	}
	// code for IE
	else if (window.ActiveXObject) {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}


	xmlhttp.onreadystatechange=state_Change;
	xmlhttp.open("GET",url,true);

	// set If-Modified-Since request header and figure out which date to use to stop IE from caching when we don't want it too.
	xmlhttp.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 2000 00:00:00 GMT');
	
	xmlhttp.send(null);

}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200) {
  doc = xmlhttp.responseXML;
  doIt();
  }
  else
  {
  alert("Problem retrieving XML data:" + xmlhttp.statusText);
  }
  }
}

function doIt() {
  // alert("Warwick!!  Are you ready?");
  
  var anchors = document.getElementsByTagName('*');

  // IE 5 hack
  if(anchors.length==0) {
	anchors = document.all
  };

  for (i=0; i < anchors.length; i++) {
     var element = anchors[i];

     var idSplit = element.id.split('_');

     var type="";
     var id="";

     if(idSplit.length > 0) {
		type = idSplit[0];
		id = idSplit[1];
     }

     if (type=="text") {
		element.innerHTML=getText(id);
     }
  }
}

function getText(id) {
  var elements = doc.getElementsByTagName(id);
  var item = elements.item(0);
  if(!item) return "ID " + id +" does not exist in the XML file";
  return item.firstChild.data;
}

// cookie code

function setCookie (name,value) {
  document.cookie = name + "=" + escape (value);
}

function getCookie (cookieName) {
  var cookieSplit = document.cookie.split(';');
  for(var i = 0; i<cookieSplit.length; i++) {
	var aCookie = trim(cookieSplit[i]);
	var cSplit = aCookie.split("=");
	var name = cSplit[0];
	var value = cSplit[1];
	if(cookieName==name) return unescape(value);
  }
  alert("Cookie " + cookieName + " not found");
}

function trim(sString){
	while (sString.substring(0,1) == ' ')
	{
	sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
return sString;
}

function projectClicked(projectId) {
 setCookie("projectId", projectId);
 //document.open("test_project_page.html");
 window.location="test_project_page.html"
}

function test() {
  setCookie("wilma","33");
  setCookie("betty","56");
  setCookie("barney","nine");

  alert(getCookie("bob"));
}