simplexhr={
  doxhr:function(container,url,id){
  	if(!document.getElementById || !document.createTextNode){return;}
    simplexhr.outputContainer=document.getElementById(container);
    if(!simplexhr.outputContainer){return;}
    var request;
    try{
      request = new XMLHttpRequest();
    }catch(error){
      try{
        request = new ActiveXObject("Microsoft.XMLHTTP");
      }catch(error){
        return true;
      }
    }
    request.open('get',url,true);
    request.onreadystatechange=function(){
      if(request.readyState == 1){
        simplexhr.outputContainer.innerHTML='loading...';
      }
      if(request.readyState == 4){
        if (request.status && /200|304/.test(request.status))
        {
          simplexhr.retrieved(request, id);
        } else{
          simplexhr.failed(request);
        }
      }
    }
   //request.setRequestHeader('If-Modified-Since', new Date().toGMTString());
    request.send(null);
    return false;
  },
  retrieved:function(requester, id){
  	simplexhr.outputContainer.removeChild(simplexhr.outputContainer.firstChild);
    var i,albumId,artist,albumTitle,comment,td,tr,th;
	var data=requester.responseXML;
	var items=data.getElementsByTagName('item');
 	var table=document.createElement('table');
	/* var tablehead=document.createElement('thead');
	table.appendChild(tablehead);
	tr=document.createElement('tr');
	th=document.createElement('th');
	th.appendChild(document.createTextNode('Starttid'));
	tr.appendChild(th);
  th=document.createElement('th');
	th.appendChild(document.createTextNode('Titel'));
	tr.appendChild(th);
	th=document.createElement('th');
	th.appendChild(document.createTextNode('Beskrivning'));
	tr.appendChild(th);
	th=document.createElement('th');
	th.appendChild(document.createTextNode('Plats'));
	tr.appendChild(th);
	tablehead.appendChild(tr);  */
	var tablebody=document.createElement('tbody');
	table.appendChild(tablebody);
	var all=items.length;
	for(i=0;i<all;i++){
		tr=document.createElement('tr');
		if (getValue(data.getElementsByTagName('startdate')[i].firstChild) == id){
			starttime=getValue(data.getElementsByTagName('starttime')[i].firstChild);
			if (getValue(data.getElementsByTagName('endtime')[i].firstChild) != ""){
				endtime = " - "+getValue(data.getElementsByTagName('endtime')[i].firstChild);
			}else{
				endtime = "";
			}
			title=getValue(data.getElementsByTagName('title')[i+1].firstChild);
			description=getValue(data.getElementsByTagName('description')[i+1].firstChild);
			loca = getValue(data.getElementsByTagName('location')[i].firstChild);
			
			td=document.createElement('td');
			td.appendChild(document.createTextNode(starttime));
			td.appendChild(document.createTextNode(endtime));
			tr.appendChild(td);	
			td=document.createElement('td');
			td.appendChild(document.createTextNode(title));
			tr.appendChild(td);	
			tablebody.appendChild(tr); 
			tr=document.createElement('tr');
			td=document.createElement('td');
			td.colSpan = "2";
			p=document.createElement('p');
			p.appendChild(document.createTextNode(description));
			p.appendChild(document.createTextNode(" "+loca));
			td.appendChild(p);
			tr.appendChild(td);
			tablebody.appendChild(tr);
		}
	}
    simplexhr.outputContainer.appendChild(table);
	return false;
  },
  failed:function(requester){
    alert('The XMLHttpRequest failed. Status: '+requester.status);
  	return false;
  }
}
function getValue(obj){
	if (obj == null){
			return "";
	} else {
			return obj.nodeValue;
	}
}
