   var http_request = false;

   function makePOSTRequest(url, parameters, type, id) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = function() {
	 if (http_request.readyState == 1) { 
//	document.getElementById(id).innerHTML = 'fetching comments';  
	document.getElementById(id).innerHTML = '';  
	 }
	 if (http_request.readyState == 3) { 
			document.getElementById(id).innerHTML = 'receiving data'; 
     	 }
     	 if (http_request.readyState == 4) {
      	   if (http_request.status == 200) {
       	     	result = http_request.responseText;
       	     	document.getElementById(id).innerHTML = result;            
       	   } else {
       	        document.getElementById(id).innerHTML = "network-issues seems to have run away with the contents";
           }
         }

     };
      var method = type ? type : "POST";
      http_request.open(method, url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }



   function get(obj) {
      var poststr = "message=" + escape( document.getElementById("message").value ) +
                    "&id=" + escape( document.getElementById("id").value ) +
                    "&name=" + escape( document.getElementById("name").value ) +
                    "&email=" + escape( document.getElementById("email").value ) +
                    "&security_code=" + escape( document.getElementById("security_code").value );
      makePOSTRequest('/comment/cpost2.php', poststr, 'POST', 'cbox');
   }

// this will keep polling for messages
// not used for picture-comments.. maybe for the front-page and for an admin?
/* function run() {
	    setInterval("makePOSTRequest('/comment/cpost2.php', '','GET', 'cbox')",'10000')
}
*/
// this will load the messages once (to be called at load-time)
// should be called with the ID of the article (image) we're looking at
function runonce2(randid,mode) {
//          window.setTimeout(function() { makePOSTRequest('/comment/cpost2.php?id=' + randid + '&mode=' + mode, '','GET', 'cbox') }, 2000);
          makePOSTRequest('/comment/cpost2.php?id=' + randid + '&mode=' + mode, '','GET', 'cbox');
}
function getlatest(id) {
          makePOSTRequest('/comment/latest.php', '','GET', id);
}

// henter vote for given id
function getvotes(randid,out) {
//	alert(randid);
          makePOSTRequest('/votes.php?id=' + randid, '','GET', out);
}
// registrerer vote for given id
function vote(randid,score, out) {
         makePOSTRequest('votes?id=' + randid + '&score=' + score, '','GET', out);
}

// skifter captcha-billedet ud
function change() {
        var randomnumber=Math.floor(Math.random()*11)+1;
        var newsource = '/comment/CaptchaSecurityImages.php?width=100&height=40&characters=5&rnd=' + randomnumber;
        setTimeout("document.getElementById('random').src='/comment/loading.gif'",2);
        setTimeout("document.getElementById('random').src='" + newsource+"' ",1000);
}


