var req=null;
var console=null;

function addNode(el,text,url) {
  var childElul=document.createElement("ul");
  el.appendChild(childElul);
  
  var childElli=document.createElement("li");
  childElul.appendChild(childElli);
  
  var childEla = document.createElement('a'); 
  childEla.setAttribute('href',url); 
  childElli.appendChild(childEla);
  
  var txtNode=document.createTextNode(text);
  childEla.appendChild(txtNode);
  
  return childElul;
}

function addNode3(el,text,url,bold,img) {
  var childElli=document.createElement("li");
  el.appendChild(childElli);
  
  var childEla = document.createElement('a'); 
  childEla.setAttribute('href',url); 
  childElli.appendChild(childEla);
  
  if ( bold == 1 ) {
   var childElbold = document.createElement("b");
   childEla.appendChild(childElbold);   
   var txtNode=document.createTextNode(text);
   childElbold.appendChild(txtNode);  
  } else {
   //var txtNode=document.createTextNode(text);
   //childEla.appendChild(txtNode);  
   if ( img == 1 ) {
      var childElimg = document.createElement("img");
      childElimg.src="/menu/img/vermeer1.gif";
      childElimg.border = "0"; 
      childEla.appendChild(childElimg);
      var txtNode=document.createTextNode(text);
      childEla.appendChild(txtNode);  
   } else {
      var txtNode=document.createTextNode(text);
      childEla.appendChild(txtNode);  
   }
   
  }  
  return childElli;
}

function addNode2(el,text,url,bold,img) {
  var childElli=document.createElement("li");
  el.appendChild(childElli);
  
  var childEla = document.createElement('a'); 
  childEla.setAttribute('href',url); 
  childElli.appendChild(childEla); 
 
  var txtNode=document.createTextNode(text);
  childEla.appendChild(txtNode);  
       
  return childElli;
}


function initXMLHTTPRequest() {
  var xRequest=null;
  if (window.XMLHttpRequest) {
       xRequest = new XMLHttpRequest();
  } else if (window.ActiveXObject){   
    try {
       xRequest = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e){
     try{
       xRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }
     catch (e){}
     }
  }
  return xRequest;  
}
 function sendRequest(url,params,HttpMethod) {
  if ( !HttpMethod) {
      HttpMethod="GET";
  }
   req=initXMLHTTPRequest();
   if(req) {
 
     req.onreadystatechange=onReadyState;
     req.open(HttpMethod,url,true);
     req.setRequestHeader ("Content-Type","application/x-www-form-urlencoded");
     req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
     
     req.send(params);	 	     
   }
 }
 
 function onReadyState() {
    var ready=req.readyState;
    var data=null;
    
    
    
    if( ready==4) {
    
       var painter = document.createElement("img");
       painter.src="/images/painter_oftheweek.png";
       painter.border = "0";        
       console.appendChild(painter);  
       
       var p = document.createElement("p");
       console.appendChild(p);
       
      
      data=req.responseText;
       
      var childEla = document.createElement('a');
      
      /* var my_url="http://www.bergerfoundation.ch/wat4/picture?ref=" + data + "&type=medium"; */
  
      var my_param=data.split("/");     
      var cd=my_param[1].split(".");    
      
      var my_url="/wat4/Apainter12?museum=" + my_param[0] + "&cd=" + cd[0] + "&babel=en";
      
      childEla.setAttribute('href',my_url);
      console.appendChild(childEla); 
      
      var childElimg = document.createElement("img");
      var my_src="/cgi-bin/scale2.pl?ref=" + my_param[1] + "&scale=40x40";
      childElimg.src=my_src;
      childElimg.border = "0";
      childEla.appendChild(childElimg);  
      
      var childEla2 = document.createElement('a');
      var my_url2 ="/cgi-bin/caption?painter=" + my_param[0];
      childEla2.setAttribute('href',my_url2);
      console.appendChild(childEla2); 
      
      var childEltxt = document.createTextNode(" - Painter's Works -");
      childEla2.appendChild(childEltxt);  
     
    } 
 }

  

function init() {   
       var theAlert = new Array();
       var theUrl  = new Array(); 
       theAlert[0] = 'Fondation Beyeler  - Edvard Munch (1863-1944)';
       
       
       theUrl[0] = 'http://www.beyeler.com/fondation/e/html_11sonderaus/01_aktuelle/intro.htm';
       
       
       
       var p = theAlert.length;
       var whichalert  = Math.round(Math.random()*(p-1));
       
       var message = document.getElementById("foo5"); 
       var childElul0 = addNode(message,theAlert[whichalert],theUrl[whichalert]); 
       //var childElli1 = addNode2(childElul0,'' ,'',1);  
       //var childElhr  = document.createElement("hr");
       //message.appendChild(childElhr);  
       //var ie=document.createElement("div");
       //message.appendChild(ie); 
       
        console=document.getElementById('foo5');
       sendRequest("/wat1/my_random.pl",1);
              
   };   

