﻿//meerdere plaatjes tonen, leuk: http://aquitaine.kijiji.fr/c-Immobilier-Fermes-Granges-Maison-W0QQAdIdZ180677923

var resultHttpobject=GetHttpObject();
var getInfoHttpobject=GetHttpObject();
var fillValueSelectBoxHttpobject=GetHttpObject();
var singlehttpobject=GetHttpObject();
var saveBasketHttpObject=GetHttpObject();
var selrow=1;
var selsf="";
var curtext="";
var cursf="";
var prevurl="";
var keyhandled=false;
var startrecordA=1;
var startrecordB=1;
var tmr;
var curHash="";
var globalSingleViewResultNum=0;
 
function insertInTextArea(el,ins) { 
    if (el.setSelectionRange){ 
        el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length); 
    } 
    else if (document.selection && document.selection.createRange) { 
        el.focus(); 
        var range = document.selection.createRange(); 
        range.text = ins + range.text; 
    } 
} 

function xmlencode(string) {
    return string.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;')
        .replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function centerElement(element) 
{
//   element.style.left=(f_clientWidth()/2-parseInt(element.style.width)/2)+"px";
//   element.style.top=(f_clientHeight()/2-parseInt(element.style.height)/2)+"px";
//element.style.margin="200 auto";
}

function setShim(mydiv,mydivshim)
{
  if(document.getElementById(mydiv)&&document.getElementById(mydivshim))
  { 
//alert(parseInt(document.getElementById(mydiv).style.width));
    //alert(document.getElementById(mydiv).style.innerwidth);
    document.getElementById(mydivshim).style.display=document.getElementById(mydiv).style.display;
    document.getElementById(mydivshim).style.left=document.getElementById(mydiv).style.left;
    document.getElementById(mydivshim).style.top=document.getElementById(mydiv).style.top;
    document.getElementById(mydivshim).style.width=document.getElementById(mydiv).style.width;
    document.getElementById(mydivshim).style.height=document.getElementById(mydiv).style.height;    
	//alert(mydivshim);
	//alert(document.getElementById(mydivshim).style.display);
	//alert(document.getElementById(mydivshim).style.left);
	//alert(document.getElementById(mydivshim).style.top);
	//alert(document.getElementById(mydivshim).style.width);
	//alert(document.getElementById(mydivshim).style.height);
  }
}

function plusInfo()
{
if(document.getElementById("collapse_plus_info").innerHTML.toLowerCase()=="<b>+ plus d\'info</b>")
{
  document.getElementById("collapse_plus_info").innerHTML="<B>- Plus d\'info</B>";
  document.getElementById("plus_info").style.display="block";
}
else
{
  document.getElementById("collapse_plus_info").innerHTML="<B>+ Plus d\'info</B>";
  document.getElementById("plus_info").style.display="none";
}
}

function showRecord(tag,value)
{
   getInfoHttpobject.abort();
   fillValueSelectBoxHttpobject.abort();
   singlehttpobject.abort();
   if (singlehttpobject !=null)
   {
      //addHistory("action=singleView&resultnum="+resultnum+"&"+getQuery(""))
      //var url="/mediawiki-1.15.1/ccscripts/showsinglepage.php";
      //url=url+"?str=abcd";
      //url=url+"&objectid="+objectId;            
      singlehttpobject.onreadystatechange=showSingleResultsStateChanged;
      //singlehttpobject.open("GET","/mediawiki-1.15.1/ccscripts/showsinglepage.php?resultnum="+resultnum+"&"+getQuery(""),true);
      //singlehttpobject.send(null);
	  var params = "reqspec="+unescape(encodeURIComponent('<ccQuery><fields><ccAdvancedSelect><freetext>yes</freetext><field queryfield="'+xmlencode(tag)+'">'+xmlencode(tag)+'</field><owner>searchfield1</owner><freetextvalue>'+xmlencode(value)+'</freetextvalue></ccAdvancedSelect></fields><first>1</first><sort>ccRelevance</sort><resultnum>1</resultnum></ccQuery>'));
	  singlehttpobject.open("POST","/ccscripts/showsinglepage.php",true);
	  singlehttpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  singlehttpobject.setRequestHeader("Content-length", params.length);
	  singlehttpobject.setRequestHeader("Connection", "close");
	  singlehttpobject.send(params);
   }   
   new Animation(document.getElementById('singleviewdivInner'),800,600);
   ///alert(objectId);
}

function showArticeInMain(tag,value)
{
   getInfoHttpobject.abort();
   fillValueSelectBoxHttpobject.abort();
   singlehttpobject.abort();
   if (singlehttpobject !=null)
   {
      //addHistory("action=singleView&resultnum="+resultnum+"&"+getQuery(""))
      //var url="/mediawiki-1.15.1/ccscripts/showarticle.php";
      //url=url+"?str=abcd";
      //url=url+"&objectid="+objectId;            
      singlehttpobject.onreadystatechange=showSingleResultsStateChangedInMain;
      //singlehttpobject.open("GET","/ccscripts/showsinglepage.php?resultnum="+resultnum+"&"+getQuery(""),true);
      //singlehttpobject.send(null);
	  var params = "reqspec="+unescape(encodeURIComponent('<ccQuery><fields><ccAdvancedSelect><freetext>yes</freetext><field queryfield="'+xmlencode(tag)+'">'+xmlencode(tag)+'</field><owner>searchfield1</owner><freetextvalue>'+xmlencode(value)+'</freetextvalue></ccAdvancedSelect></fields><first>1</first><sort>ccRelevance</sort><resultnum>1</resultnum></ccQuery>'));
	  singlehttpobject.open("POST","/ccscripts/showarticle.php",true);
	  singlehttpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  singlehttpobject.setRequestHeader("Content-length", params.length);
	  singlehttpobject.setRequestHeader("Connection", "close");
	  singlehttpobject.send(params);
   }   
}

function singleview(resultnum)
{
   //singlehttpobject=GetHttpObject();
   //resultHttpobject.abort();
   getInfoHttpobject.abort();
   fillValueSelectBoxHttpobject.abort();
   singlehttpobject.abort();
   if (singlehttpobject !=null)
   {
      //addHistory("action=singleView&resultnum="+resultnum+"&"+getQuery(""))
      //var url="/mediawiki-1.15.1/ccscripts/showsinglepage.php";
      //url=url+"?str=abcd";
      //url=url+"&objectid="+objectId;            
      singlehttpobject.onreadystatechange=showSingleResultsStateChanged;
      //singlehttpobject.open("GET","/mediawiki-1.15.1/ccscripts/showsinglepage.php?resultnum="+resultnum+"&"+getQuery(""),true);
      //singlehttpobject.send(null);
	  var params = "reqspec="+unescape(getQuery2("",resultnum,"","","","","","",""));
	  singlehttpobject.open("POST","/ccscripts/showsinglepage.php",true);
	  singlehttpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  singlehttpobject.setRequestHeader("Content-length", params.length);
	  singlehttpobject.setRequestHeader("Connection", "close");
	  singlehttpobject.send(params);
   }   
   new Animation(document.getElementById('singleviewdivInner'),800,600);
   ///alert(objectId);
}

function singleviewimage(_filename)
{
   //addHistory("action=singleViewimage&fn="+_filename)

   DisplayWidth = f_clientWidth() - 60;
   DisplayHeight = f_clientHeight() - 80;
   changeFileName(_filename);
   
   document.getElementById('CcZoomImage1').style.width=DisplayWidth+"px";
   document.getElementById('CcZoomImage1').style.height=DisplayHeight+"px";   
   
   new Animation(document.getElementById('singleviewdivInnerImage'),5000,5000);
   BodyLoad();

   //document.getElementById("singleviewdivInnerImage").innerHTML="<img alt='' src='/ccscripts/ajaxbusy.gif' />";
   //singleimagehttpobject=GetHttpObject();
   //if (singleimagehttpobject !=null)
   //{
   //   var url="/mediawiki-1.15.1/ccscripts/showsingleimage.php";
   //   url=url+"?str=abcd";
   //   url=url+"&objectid="+objectId;
   //   singleimagehttpobject.onreadystatechange=showSingleResultsImageStateChanged;
   //   singleimagehttpobject.open("GET",url,true);
   //   singleimagehttpobject.send(null);
   //}   
   //new Animation(document.getElementById('singleviewdivInnerImage'),5000,5000);
   /////alert(objectId);
}

function showSingleResultsStateChanged()
{
  if (singlehttpobject.readyState==4)
  {
    document.getElementById("singleviewdivInner").innerHTML=singlehttpobject.responseText;
  }
}

function showSingleResultsStateChangedInMain()
{
  if (singlehttpobject.readyState==4)
  {
    document.getElementById("ccresults").innerHTML=singlehttpobject.responseText;
  }
}

function showSingleResultsImageStateChanged()
{
  if (singleimagehttpobject.readyState==4)
  {
    document.getElementById("singleviewdivInnerImage").innerHTML=singleimagehttpobject.responseText;
    //BodyLoad();	
  }
}

Animation = function(element,width,height) 
{
   this.steps=18;
   this.viewportwidth = f_clientWidth();
   this.viewportheight = f_clientHeight();

   element.style.display="block";
   this.actualWidth=parseInt(element.style.width,10);
   this.actualHeight=parseInt(element.style.height,10);
   if (width>this.viewportwidth-20) {width=this.viewportwidth-20;}
   if (height>this.viewportheight-20) {height=this.viewportheight-20;}
   this.destinationWidth=width;
   this.destinationHeight=height;
   this.increaseWidth=(this.destinationWidth-this.actualWidth)/this.steps;
   this.increaseHeight=(this.destinationHeight-this.actualHeight)/this.steps;
   this.element=element;
   this.animate();
}
 
Animation.prototype.animate = function()
{
   this.steps--;
   this.actualWidth+=this.increaseWidth;
   this.actualHeight+=this.increaseHeight;
   this.element.style.width=this.actualWidth+"px";
   this.element.style.height=this.actualHeight+"px";
   this.element.style.left=(this.viewportwidth/2-this.actualWidth/2+f_scrollLeft())+"px";
   this.element.style.top=(this.viewportheight/2-this.actualHeight/2+f_scrollTop())+"px";
   
   if(document.getElementById(this.element.id+'Shim')) { setShim(this.element.id,this.element.id+'Shim'); }     	 
 
   if(this.steps==0&&this.destinationWidth==0) {this.element.style.display="none";}
   //if(this.steps==0)
   //{
   //}
   var self=this;
   if (this.steps>0) setTimeout(function () {self.animate.call(self)},6);
}
  
 function showpdflist()
 {
   document.getElementById("pdf").value=document.getElementById("ccresults").innerHTML;
   document.forms['generatePdfForm'].submit(); 
   //alert("saved");
 }
 
 function showpdfsingle()
 {
   document.getElementById("pdf").value=document.getElementById("singleviewdivInner").innerHTML;
   document.forms['generatePdfForm'].submit(); 
   //alert("saved");
 }

 function showpdfzoom()
 {
   document.getElementById("pdf").value="<img src='"+HiddenPic.src+"'/>";
   //oldDisplay=document.getElementById("CcZoomImageToolbox1").style.display;
   //document.getElementById("CcZoomImageToolbox1").style.display='none';
   //document.getElementById("pdf").value=document.getElementById("singleviewdivInnerImage").innerHTML;
   //document.getElementById("CcZoomImageToolbox1").style.display=oldDisplay;
   document.forms['generatePdfForm'].submit(); 
 }
 
 function showprintlist()
 {
   document.getElementById("print").value=document.getElementById("ccresults").innerHTML;
   document.forms['generatePrintForm'].submit(); 
   //alert("saved");
 }
 
 function showprintsingle()
 {
   document.getElementById("print").value=document.getElementById("singleviewdivInner").innerHTML;
   document.forms['generatePrintForm'].submit(); 
   //alert("saved");
 }

 function showprintzoom()
 {
   document.getElementById("print").value="<img src='"+HiddenPic.src+"'/>";
   document.forms['generatePrintForm'].submit(); 
   //alert("saved");
 }

 function showBasketSummary()
 {
   if(document.getElementById('basketsummarytxt'))
   {
	   var bask=document.getElementById("basket").innerHTML;
		if(bask=="")
		{
		  bask="<basket></basket>";
		}
		else
		{
		  bask=decode64(bask);
		}
		var xmlDoc;
		if (window.DOMParser)
		{
		  parser=new DOMParser();
		  if (bask.substr(0, 5)=='<?xml')
		  {
			 xmlDoc=parser.parseFromString(bask,"text/xml");
		  }
		  else
		  {
			 xmlDoc=parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?>'+bask,"text/xml");
		  }
		}
		else // Internet Explorer
		{
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML('<?xml version="1.0" encoding="UTF-8"?>'+bask); 
		}
		document.getElementById('basketsummarytxt').innerHTML=xmlDoc.getElementsByTagName("id").length+' objects';
		if(xmlDoc.getElementsByTagName("id").length>0)
		{
		  document.getElementById("filterbasket").style.display="inline";
		}
		else
		{
		  document.getElementById("filterbasket").style.display="none";
		}	
	}
}

   function setBasket(active,id)
  { 
    var bask=document.getElementById("basket").innerHTML;
	if(bask=="")
	{
	  bask="<basket></basket>";
	}
	else
	{
	  bask=decode64(bask);
	}
    var xmlDoc;
    if (window.DOMParser)
    {
      parser=new DOMParser();
	  if (bask.substr(0, 5)=='<?xml')
	  {
	    xmlDoc=parser.parseFromString(bask,"text/xml");
	  }
	  else
	  {
	    xmlDoc=parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?>'+bask,"text/xml");
	  }
    }
    else // Internet Explorer
    {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async="false";
      xmlDoc.loadXML('<?xml version="1.0" encoding="UTF-8"?>'+bask); 
    }    
    if(active==true)
	{	
	  var newnode=xmlDoc.createElement("id");
	  var newtext=xmlDoc.createTextNode(id);
	  newnode.appendChild(newtext);
	  xmlDoc.documentElement.appendChild(newnode);	   
	}
	else
	{ 
	  var values=xmlDoc.getElementsByTagName("id");
	  for(var i = 0; i < values.length; i++)
	  {
		if (values[i].childNodes[0].nodeValue==id)
		{ 
		  values[i].parentNode.removeChild(values[i]);
		}
	  }      
	}
	var str="";
	if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
    document.getElementById("basket").innerHTML=encode64(str);
	showBasketSummary();
  }
  
function startUpload()
 {  
   //document.getElementById('f1_upload_process').style.visibility = 'visible';
   return true;
 }
 
 function stripslashes(str)
 {
   str=str.replace(/\\'/g,'\'');
   str=str.replace(/\\"/g,'"');
   str=str.replace(/\\0/g,'\0');
   str=str.replace(/\\\\/g,'\\');
   return str;
  }

 function loadBasketFromFile(data)
 {
     if (saveBasketHttpObject !=null)
     {
        saveBasketHttpObject.abort();
		//if(document.getElementById("ccresultsajaxbusy")) {document.getElementById("ccresultsajaxbusy").style.display="block"};
        //resultHttpobject.onreadystatechange=showResultsStateChanged;
		//var params = "reqspec="+unescape(getQuery2("",0,"","","","","","",""));
		//addHistory(params);
		saveBasketHttpObject.open("GET","/ccscripts/"+data,false);
		saveBasketHttpObject.setRequestHeader("Connection", "close");
		saveBasketHttpObject.send(null);
        loadBasketFromString(stripslashes(saveBasketHttpObject.responseText));
     }    
  }
 
 function loadBasketFromString(data)
 {
    document.getElementById('filterbasket').innerHTML='masquer &gt;&gt;'; 
    document.getElementById('basketmanager').style.display='none';
    var xmlDoc;
	if (window.DOMParser)
    {
      parser=new DOMParser();
      xmlDoc=parser.parseFromString('<?xml version="1.0" encoding="utf-8" ?>'+data,'text/xml');
    }
    else // Internet Explorer
    {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async="false";
      xmlDoc.loadXML('<?xml version="1.0" encoding="utf-8" ?>'+data);
    }
    //document.getElementById("basket").innerHTML="<basket></basket>";
	document.getElementById("basket").innerHTML="";
    var ids = xmlDoc.getElementsByTagName("id");
    for(var i=0; i < ids.length; i++) 
	{ 
	  if(ids[i].childNodes[0] && ids[i].childNodes[0].nodeValue)
	  {
  	    //alert(ids[i].childNodes[0].nodeValue);
        try
        {	
          setBasket(true,ids[i].childNodes[0].nodeValue);
        }
        catch(ex)
	    {        
		//Why do we get an error here?
        } 	  
	  }
		
	}
	resetQuery();
	showBasketSummary();
 }
  
 function addOptionToSearchfield(sel,txt,val)
  {
   var elOptNew=document.createElement('option');
   elOptNew.text=txt;
   elOptNew.value=val;
   try
   {
      sel.add(elOptNew, null); // standards compliant; doesn't work in IE
    }
    catch(ex)
	{
      sel.add(elOptNew); // IE only
    } 
  }
  
  function setupSearchbox(curs)
  {    
    if(curs)
	{
		while (curs.length > 0)
		{
		  curs.remove(0);
		}
		addOptionToSearchfield(curs,'Alle velden','<ccAdvancedSelect><freetext>yes</freetext><select>no</select><field queryfield="*">Tous</field><values></values></ccAdvancedSelect>');
		addOptionToSearchfield(curs,'Titel','<ccAdvancedSelect><freetext>yes</freetext><select type="abcd">yes</select><field queryfield="title">Titel</field><values></values></ccAdvancedSelect>');
		addOptionToSearchfield(curs,'Categorie','<ccAdvancedSelect><freetext>yes</freetext><select type="abcd">yes</select><field queryfield="categorie">Numero</field><values></values></ccAdvancedSelect>');
	}
  }
 
  function getCheckedValue(crit) 
  {
     if(document.getElementById(crit+'a').checked) { return ('and'); }
     if(document.getElementById(crit+'b').checked) { return ('or'); }
     if(document.getElementById(crit+'c').checked) { return ('not'); }
  }

  var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";

   function encode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      do {
         chr1 = input.charCodeAt(i++);
         chr2 = input.charCodeAt(i++);
         chr3 = input.charCodeAt(i++);

         enc1 = chr1 >> 2;
         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
         enc4 = chr3 & 63;

         if (isNaN(chr2)) {
            enc3 = enc4 = 64;
         } else if (isNaN(chr3)) {
            enc4 = 64;
         }

         output = output +
            keyStr.charAt(enc1) +
            keyStr.charAt(enc2) +
            keyStr.charAt(enc3) +
            keyStr.charAt(enc4);
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
      } while (i < input.length);

      return output;
   }

   function decode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
      var base64test = /[^A-Za-z0-9\+\/\=]/g;
      if (base64test.exec(input)) {
      }
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

      do {
         enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
         enc4 = keyStr.indexOf(input.charAt(i++));

         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
         chr3 = ((enc3 & 3) << 6) | enc4;

         output = output + String.fromCharCode(chr1);

         if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
         }
         if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
         }

         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";

      } while (i < input.length);

      return output;
   }

	/* UTF8 encoding/decoding functions
	 * Copyright (c) 2006 by Ali Farhadi.
	 * released under the terms of the Gnu Public License.
	 * see the GPL for details.
	 *
	 * Email: ali[at]farhadi[dot]ir
	 * Website: http://farhadi.ir/
	 */

	//an alias of String.fromCharCode
	function chr(code)
	{
		return String.fromCharCode(code);
	}

	//returns utf8 encoded charachter of a unicode value.
	//code must be a number indicating the Unicode value.
	//returned value is a string between 1 and 4 charachters.
	function code2utf(code)
	{
		if (code < 128) return chr(code);
		if (code < 2048) return chr(192+(code>>6)) + chr(128+(code&63));
		if (code < 65536) return chr(224+(code>>12)) + chr(128+((code>>6)&63)) + chr(128+(code&63));
		if (code < 2097152) return chr(240+(code>>18)) + chr(128+((code>>12)&63)) + chr(128+((code>>6)&63)) + chr(128+(code&63));
	}

	//it is a private function for internal use in utf8Encode function 
	function _utf8Encode(str)
	{	
		var utf8str = new Array();
		for (var i=0; i<str.length; i++) {
			utf8str[i] = code2utf(str.charCodeAt(i));
		}
		return utf8str.join('');
	}

	//Encodes a unicode string to UTF8 format.
	function utf8Encode(str)
	{	
		var utf8str = new Array();
		var pos,j = 0;
		var tmpStr = '';
		
		while ((pos = str.search(/[^\x00-\x7F]/)) != -1) {
			tmpStr = str.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0];
			utf8str[j++] = str.substr(0, pos);
			utf8str[j++] = _utf8Encode(tmpStr);
			str = str.substr(pos + tmpStr.length);
		}
		
		utf8str[j++] = str;
		return utf8str.join('');
	}

	//it is a private function for internal use in utf8Decode function 
	function _utf8Decode(utf8str)
	{	
		var str = new Array();
		var code,code2,code3,code4,j = 0;
		for (var i=0; i<utf8str.length; ) {
			code = utf8str.charCodeAt(i++);
			if (code > 127) code2 = utf8str.charCodeAt(i++);
			if (code > 223) code3 = utf8str.charCodeAt(i++);
			if (code > 239) code4 = utf8str.charCodeAt(i++);
			
			if (code < 128) str[j++]= chr(code);
			else if (code < 224) str[j++] = chr(((code-192)<<6) + (code2-128));
			else if (code < 240) str[j++] = chr(((code-224)<<12) + ((code2-128)<<6) + (code3-128));
			else str[j++] = chr(((code-240)<<18) + ((code2-128)<<12) + ((code3-128)<<6) + (code4-128));
		}
		return str.join('');
	}

	//Decodes a UTF8 formated string
	function utf8Decode(utf8str)
	{
		var str = new Array();
		var pos = 0;
		var tmpStr = '';
		var j=0;
		while ((pos = utf8str.search(/[^\x00-\x7F]/)) != -1) {
			tmpStr = utf8str.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0];
			str[j++]= utf8str.substr(0, pos) + _utf8Decode(tmpStr);
			utf8str = utf8str.substr(pos + tmpStr.length);
		}
		
		str[j++] = utf8str;
		return str.join('');
	}

   //**** support back button of browser
    /*! 
    * Copyright (c) 2009 Andreas Blixt <andreas@blixt.org> 
    * Contributors: Aaron Ogle <aogle@avencia.com>, 
    * Matti Virkkunen <mvirkkunen@gmail.com> 
    * This and more JavaScript libraries: http://blixt.org/js 
    * MIT License: http://www.opensource.org/licenses/mit-license.php 
    * 
    * Hash handler 
    * Keeps track of the history of changes to the hash part in the address bar. 
    */ 
    /* WARNING for Internet Explorer 7 and below: 
    * If an element on the page has the same ID as the hash used, the history will 
    * get messed up. 
    * 
    * Does not support history in Safari 2 and below. 
    * 
    * Example: 
    * function handler(newHash, initial) { 
    * if (initial) 
    * alert('Hash is "' + newHash + '"'); 
    * else 
    * alert('Hash changed to "' + newHash + '"'); 
    * } 
    * Hash.init(handler, document.getElementById('hidden-iframe')); 
    * Hash.go('abc123'); 
    * 
    * Updated by Matti Virkkunen (mvirkkunen@gmail.com) on 2009-11-16: 
    * - Added second argument to callback that indicated whether the callback is due 
    * to initial state (true) or due to an actual change to the hash (false). 
    * 
    * Updated by Aaron Ogle (aogle@avencia.com) on 2009-08-11: 
    * - Fixed bug where Firefox automatically unescapes location.hash but no other 
    * browsers do. Always get the hash by parsing location.href and never use 
    * location.hash. 
    */ 

    var Hash = (function () { 
    var 
    // Import globals 
    window = this, 
    documentMode = document.documentMode, 
    history = window.history, 
    location = window.location, 
    // Plugin variables 
    callback, hash, 
    // IE-specific 
    iframe, 

    getHash = function () { 
    // Internet Explorer 6 (and possibly other browsers) extracts the query 
    // string out of the location.hash property into the location.search 
    // property, so we can't rely on it. The location.search property can't be 
    // relied on either, since if the URL contains a real query string, that's 
    // what it will be set to. The only way to get the whole hash is to parse 
    // it from the location.href property. 
    // 
    // Another thing to note is that in Internet Explorer 6 and 7 (and possibly 
    // other browsers), subsequent hashes are removed from the location.href 
    // (and location.hash) property if the location.search property is set. 
    // 
    // Via Aaron: Firefox 3.5 (and below?) always unescape location.hash which 
    // causes poll to fire the hashchange event twice on escaped hashes. This is 
    // because the hash variable (escaped) will not match location.hash 
    // (unescaped.) The only consistent option is to rely completely on 
    // location.href. 
    var index = location.href.indexOf('#'); 
    return (index == -1 ? '' : location.href.substr(index + 1)); 
    }, 

    // Used by all browsers except Internet Explorer 7 and below. 
    poll = function () { 
    var curHash = getHash(); 
    if (curHash != hash) { 
    hash = curHash; 
    callback(curHash, false); 
    } 
    }, 

    // Used to create a history entry with a value in the iframe. 
    setIframe = function (newHash) { 
    try { 
    var doc = iframe.contentWindow.document; 
    doc.open(); 
    doc.write('<html><body>' + newHash + '</body></html>'); 
    doc.close(); 
    hash = newHash; 
    } catch (e) { 
    setTimeout(function () { setIframe(newHash); }, 10); 
    } 
    }, 

    // Used by Internet Explorer 7 and below to set up an iframe that keeps track 
    // of history changes. 
    setUpIframe = function () { 
    // Don't run until access to the iframe is allowed. 
    try { 
    iframe.contentWindow.document; 
    } catch (e) { 
    setTimeout(setUpIframe, 10); 
    return; 
    } 

    // Create a history entry for the initial state. 
    setIframe(hash); 
    var data = hash; 

    setInterval(function () { 
    var curData, curHash; 

    try {
    curData = iframe.contentWindow.document.body.innerText||iframe.contentWindow.document.body.textContent; 
    if (curData != data) { 
    data = curData; 
    location.hash = hash = curData; 
    callback(curData, true); 
    } else { 
    curHash = getHash(); 
    if (curHash != hash) setIframe(curHash); 
    } 
    } catch (e) { 
    } 
    }, 50); 
    }; 

    return { 
    init: function (cb, ifr) { 
    // init can only be called once. 
    if (callback) return; 

    callback = cb; 

    // Keep track of the hash value. 
    hash = getHash(); 
    cb(hash, true); 

    // Run specific code for Internet Explorer. 
    if (window.ActiveXObject) { 
    if (!documentMode || documentMode < 8) { 
    // Internet Explorer 5.5/6/7 need an iframe for history 
    // support. 
    iframe = ifr; 
    setUpIframe(); 
    } else { 
    // Internet Explorer 8 has onhashchange event. 
    window.attachEvent('onhashchange', poll); 
    } 
    } else { 
    // Change Opera navigation mode to improve history support. 
    if (history.navigationMode) history.navigationMode = 'compatible'; 

    setInterval(poll, 50); 
    } 
    }, 

    go: function (newHash) { 
    // Cancel if the new hash is the same as the current one, since there 
    // is no cross-browser way to keep track of navigation to the exact 
    // same hash multiple times in a row. A wrapper can handle this by 
    // adding an incrementing counter to the end of the hash. 
    if (newHash == hash) return; 
    if (iframe) { 
    setIframe(newHash); 
    } else { 
    location.hash = hash = newHash; 
    callback(newHash, false);
    } 
    } 
    }; 
    })();


  function addHistory(req)
  {
    //alert(req);
    //curHash=req;
    //Hash.go(req)
  }

  function getUriValue(key, query)
  {
    var re = new RegExp("[?|&]" + key + "=(.*?)&");
    var matches = re.exec("?" +query + "&");
    if (!matches || matches.length < 2)
        return "";
    return decodeURIComponent(matches[1].replace("+", " "));
  }

  function handler(newHash, initial)
  {
    if(curHash!=newHash)
    {
      //if (initial) 
      //  alert('Hash is "' + newHash + '"'); 
      //else 
      //  alert('Hash changed to "' + newHash + '"'); 

      //action=executeQuery&str=doui&fields=*&first=1&sort=ccRelevance
      //action=singleView&resultnum=1&str=doui&fields=*&first=1&sort=ccRelevance
      //action=singleViewimage&fn=images/41183.cci

      //alert("new hash: "+newHash);
      
      //document.getElementById("tb1").value=getUriValue("tb1",newHash);

      //sf = document.getElementById("searchfield");
	  //if(sf)
	  //{
      //  fld = getUriValue("fields",newHash);
      //  for(index = 0; index < sf.length; index++) if(sf[index].value == fld) sf.selectedIndex = index;
      //}
      
      sf = document.getElementById("selectsort");
      fld = getUriValue("sort",newHash);
      for(index = 0; index < sf.length; index++) if(sf[index].value == fld) sf.selectedIndex = index;
           
      startrecordA=parseInt(getUriValue("firsta",newHash));
      startrecordB=parseInt(getUriValue("firstb",newHash));

      if (getUriValue("action",newHash)=="executeQuery")
      {
        if(document.getElementById('singleviewdivInnerImage') && document.getElementById('singleviewdivInnerImage').style.display!="none") {new Animation(document.getElementById('singleviewdivInnerImage'),0,0);}
        if(document.getElementById('singleviewdivInner') && document.getElementById('singleviewdivInner').style.display!="none") {new Animation(document.getElementById('singleviewdivInner'),0,0);}
        executeQuery();
      }
      if (getUriValue("action",newHash)=="singleView")
      {
        if(document.getElementById('singleviewdivInnerImage') && document.getElementById('singleviewdivInnerImage').style.display!="none") {new Animation(document.getElementById('singleviewdivInnerImage'),0,0);}
        executeQuery();
        setTimeout("singleview(getUriValue('resultnum','"+newHash+"'));",1000);
      }
      if (getUriValue("action",newHash)=="singleViewimage")
      {
        singleviewimage(getUriValue("fn",newHash));
      }

    }
  } 

   ///** support back button of browser

  function processTypedText(cursf)
  {
     selsf=cursf;
     getInfo(document.getElementById(selsf+"tb").value,cursf,300,1,6,0);
  }
  
  function setQuery2(str)
  {
    if(str!=null&&str!="")
	{
  	  var xmlDoc;
      if (window.DOMParser)
      {
        parser=new DOMParser();
	    if (str.substr(0, 5)=='<?xml')
	    {
	      xmlDoc=parser.parseFromString(str,"text/xml");
	    }
	    else
	    {
	      xmlDoc=parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?>'+str,"text/xml");
	    }      
      }
	  else
	  {
	    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	    xmlDoc.async="false";
	    if (str.substr(0, 5)=='<?xml')
	    {
	      xmlDoc.loadXML(str); 
	    }
	    else
	    {
	      xmlDoc.loadXML('<?xml version="1.0" encoding="UTF-8"?>'+str); 
	    }
	  }
	
	  var firstrec=xmlDoc.getElementsByTagName("firsta");
	  if(firstrec&&firstrec[0]&&firstrec[0].firstChild&&firstrec[0].firstChild.nodeValue)
	  {
	    startrecordA=parseInt(firstrec[0].firstChild.nodeValue);
	  }
	  else
	  {
	    startrecordA=1;
	  }
	  var firstrec=xmlDoc.getElementsByTagName("firstb");
	  if(firstrec&&firstrec[0]&&firstrec[0].firstChild&&firstrec[0].firstChild.nodeValue)
	  {
	    startrecordB=parseInt(firstrec[0].firstChild.nodeValue);
	  }
	  else
	  {
	    startrecordB=1;
	  }
	  var values=xmlDoc.getElementsByTagName("ccAdvancedSelect");
	  for(var i = 0; i < values.length; i++)
	  {     curvalue=values[i];
          var curtag;

		  curChosenField=""
		  curtag=curvalue.getElementsByTagName("field")[0];
		  //if(curtag) {curChosenField=curtag.getAttribute('queryfield');}
		  if(curtag&&curtag.firstChild) {curChosenField=curtag.firstChild.nodeValue;}

		  curOwner="";
		  curtag=curvalue.getElementsByTagName("owner")[0];
		  if(curtag&&curtag.firstChild) {curOwner=curtag.firstChild.nodeValue;}

		  curValues="";
		  curtag=curvalue.getElementsByTagName("values")[0];
		  if(curtag&&curtag.firstChild) {curValues=curtag.firstChild.nodeValue;}

		  curFreetextValue="";
		  curtag=curvalue.getElementsByTagName("freetextvalue")[0];
		  if(curtag&&curtag.firstChild) {curFreetextValue=curtag.firstChild.nodeValue;}

		  var cursf=document.getElementById(curOwner);

		  setupSearchbox(cursf);
		
          for(index = 0; index < cursf.length; index++)  if(cursf[index].text == curChosenField)
		  {
		    cursf.selectedIndex = index;
		    cursf.options[index].value=curvalue.xml; //werkt dit ook in Chrome, Safari, etc?
		  }		

		  var curtb=document.getElementById(curOwner+"tb");
		  curtb.value=curFreetextValue;
		
	  }
    }
  }
  
  function getQuery2(neglectsf,resultnum,str,length,firstterm,num,selrowafter,fields,owner)
  { 
    //if(document.getElementById("searchfield"))
	{
//alert("Get: "+document.getElementById("searchfield").options[document.getElementById("searchfield").selectedIndex].value);
		var xmlDoc;
		if (window.DOMParser)
		{
		  parser=new DOMParser();
		  xmlDoc=parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?><ccQuery></ccQuery>',"text/xml");
		}
		else // Internet Explorer
		{
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML('<?xml version="1.0" encoding="UTF-8"?><ccQuery></ccQuery>');
		}  
		var rootnode=xmlDoc.getElementsByTagName("ccQuery")[0];
		var newnode=xmlDoc.createElement("fields");
		rootnode.appendChild(newnode);	 

		//if(document.getElementById("searchfield"))
		if(selsf=="searchfield")
		{
		   var sfnode=getXmlDocSelectBox("searchfield").getElementsByTagName("ccAdvancedSelect")[0];       
		   
		   var newtextnode=xmlDoc.createElement("owner");
		   var newtext=xmlDoc.createTextNode("searchfield");
		   newtextnode.appendChild(newtext);
		   sfnode.appendChild(newtextnode);

		   var newtextnode=xmlDoc.createElement("freetextvalue");
		   if(document.getElementById("searchfieldtb"))
		   {
			 var newtext=xmlDoc.createTextNode(document.getElementById("searchfieldtb").value);
			 newtextnode.appendChild(newtext);
		   }
		   sfnode.appendChild(newtextnode);
		   if(xmlDoc.importNode) //safari & chrome
		   {
			 isfnode=xmlDoc.importNode(sfnode,true);	   
			 newnode.appendChild(isfnode);
		   }
		   else
		   {
			 newnode.appendChild(sfnode);
		   }
		}
		
		if(document.getElementById("searchfield1") && neglectsf!="searchfield" && neglectsf!="searchfield1")
		{
		   var sfnode=getXmlDocSelectBox("searchfield1").getElementsByTagName("ccAdvancedSelect")[0];       

		   var newtextnode=xmlDoc.createElement("owner");
		   var newtext=xmlDoc.createTextNode("searchfield1");
		   newtextnode.appendChild(newtext);
		   sfnode.appendChild(newtextnode);

		   var newtextnode=xmlDoc.createElement("freetextvalue");
		   if(document.getElementById("searchfield1tb"))
		   {
			 var newtext=xmlDoc.createTextNode(document.getElementById("searchfield1tb").value);
			 newtextnode.appendChild(newtext);
		   }
		   sfnode.appendChild(newtextnode);
		   if(xmlDoc.importNode) //safari & chrome
		   {
			 isfnode=xmlDoc.importNode(sfnode,true);	   
			 newnode.appendChild(isfnode);
		   }
		   else
		   {
			 newnode.appendChild(sfnode);
		   }
		}
		if(document.getElementById("searchfield2") && neglectsf!="searchfield" && neglectsf!="searchfield2")
		{
		   var sfnode=getXmlDocSelectBox("searchfield2").getElementsByTagName("ccAdvancedSelect")[0];       

		   var newtextnode=xmlDoc.createElement("owner");
		   var newtext=xmlDoc.createTextNode("searchfield2");
		   newtextnode.appendChild(newtext);
		   sfnode.appendChild(newtextnode);

		   var newtextnode=xmlDoc.createElement("freetextvalue");
		   if(document.getElementById("searchfield2tb"))
		   {
			 var newtext=xmlDoc.createTextNode(document.getElementById("searchfield2tb").value);
			 newtextnode.appendChild(newtext);
		   }
		   sfnode.appendChild(newtextnode);
		   if(xmlDoc.importNode) //safari & chrome
		   {  	     
			 isfnode=xmlDoc.importNode(sfnode,true);	   
			 newnode.appendChild(isfnode);
		   }
		   else
		   {
			 newnode.appendChild(sfnode);
		   }
		}
		if(document.getElementById("searchfield3") && neglectsf!="searchfield" && neglectsf!="searchfield3")
		{
		   var sfnode=getXmlDocSelectBox("searchfield3").getElementsByTagName("ccAdvancedSelect")[0];       

		   var newtextnode=xmlDoc.createElement("owner");
		   var newtext=xmlDoc.createTextNode("searchfield3");
		   newtextnode.appendChild(newtext);
		   sfnode.appendChild(newtextnode);

		   var newtextnode=xmlDoc.createElement("freetextvalue");
		   if(document.getElementById("searchfield3tb"))
		   {
			 var newtext=xmlDoc.createTextNode(document.getElementById("searchfield3tb").value);
			 newtextnode.appendChild(newtext);
		   }
		   sfnode.appendChild(newtextnode);
		   if(xmlDoc.importNode) //safari & chrome
		   {  	     
			 isfnode=xmlDoc.importNode(sfnode,true);	   
			 newnode.appendChild(isfnode);
		   }
		   else
		   {
			 newnode.appendChild(sfnode);
		   }
		}
		if(document.getElementById("searchfield4") && neglectsf!="searchfield" && neglectsf!="searchfield4")
		{
		   var sfnode=getXmlDocSelectBox("searchfield4").getElementsByTagName("ccAdvancedSelect")[0];       

		   var newtextnode=xmlDoc.createElement("owner");
		   var newtext=xmlDoc.createTextNode("searchfield4");
		   newtextnode.appendChild(newtext);
		   sfnode.appendChild(newtextnode);

		   var newtextnode=xmlDoc.createElement("freetextvalue");
		   if(document.getElementById("searchfield4tb"))
		   {
			 var newtext=xmlDoc.createTextNode(document.getElementById("searchfield4tb").value);
			 newtextnode.appendChild(newtext);
		   }
		   sfnode.appendChild(newtextnode);
		   if(xmlDoc.importNode) //safari & chrome
		   {  	     
			 isfnode=xmlDoc.importNode(sfnode,true);	   
			 newnode.appendChild(isfnode);
		   }
		   else
		   {
			 newnode.appendChild(sfnode);
		   }
		}
		//if(document.getElementById("searchfield5") && neglectsf!="searchfield" && neglectsf!="searchfield5")
		if(selsf=="searchfield5")
		{

		  var sfnode=getXmlDocSelectBox("searchfield5").getElementsByTagName("ccAdvancedSelect")[0];       

		   var newtextnode=xmlDoc.createElement("owner");
		   var newtext=xmlDoc.createTextNode("searchfield5");
		   newtextnode.appendChild(newtext);
		   sfnode.appendChild(newtextnode);

		   var newtextnode=xmlDoc.createElement("freetextvalue");
		   if(document.getElementById("searchfield5tb"))
		   {
			 var newtext=xmlDoc.createTextNode(document.getElementById("searchfield5tb").value);
			 newtextnode.appendChild(newtext);
		   }
		   sfnode.appendChild(newtextnode);
		   if(xmlDoc.importNode) //safari & chrome
		   {  	     
			 isfnode=xmlDoc.importNode(sfnode,true);	   
			 newnode.appendChild(isfnode);
		   }
		   else
		   {
			 newnode.appendChild(sfnode);
		   }

		}

		//var c2=xmlDoc.createElement("crit2"); c2.appendChild(xmlDoc.createTextNode(getCheckedValue("crit2"))); newnode.appendChild(c2);
		//var c3=xmlDoc.createElement("crit3"); c3.appendChild(xmlDoc.createTextNode(getCheckedValue("crit3"))); newnode.appendChild(c3);
		//var c4=xmlDoc.createElement("crit4"); c4.appendChild(xmlDoc.createTextNode(getCheckedValue("crit4"))); newnode.appendChild(c4);
		//var c5=xmlDoc.createElement("crit5"); c5.appendChild(xmlDoc.createTextNode(getCheckedValue("crit5"))); newnode.appendChild(c5);
		var firstNode=xmlDoc.createElement("firsta"); firstNode.appendChild(xmlDoc.createTextNode(startrecordA)); rootnode.appendChild(firstNode);
		var firstNode=xmlDoc.createElement("firstb"); firstNode.appendChild(xmlDoc.createTextNode(startrecordB)); rootnode.appendChild(firstNode);
		var sortNode=xmlDoc.createElement("sort"); 
		if (document.getElementById("selectsort"))
		{
		  sortNode.appendChild(xmlDoc.createTextNode(document.getElementById("selectsort").value));
		}
		else
		{
		  sortNode.appendChild(xmlDoc.createTextNode("ccRelevance"));
		}
		rootnode.appendChild(sortNode);

		//extra parameter showSingleObject
		var resultnumNode=xmlDoc.createElement("resultnum"); resultnumNode.appendChild(xmlDoc.createTextNode(resultnum)); rootnode.appendChild(resultnumNode);

		//extra parameters getInfo
		var strNode=xmlDoc.createElement("str"); strNode.appendChild(xmlDoc.createTextNode(str)); rootnode.appendChild(strNode);
		var lengthNode=xmlDoc.createElement("length"); lengthNode.appendChild(xmlDoc.createTextNode(length)); rootnode.appendChild(lengthNode);
		var firsttermNode=xmlDoc.createElement("firstterm"); firsttermNode.appendChild(xmlDoc.createTextNode(firstterm)); rootnode.appendChild(firsttermNode);
		var numNode=xmlDoc.createElement("num"); numNode.appendChild(xmlDoc.createTextNode(num)); rootnode.appendChild(numNode);
		var fieldsNode=xmlDoc.createElement("scanfields"); fieldsNode.appendChild(xmlDoc.createTextNode(fields)); rootnode.appendChild(fieldsNode);
		var selrowafterNode=xmlDoc.createElement("selrowafter"); selrowafterNode.appendChild(xmlDoc.createTextNode(selrowafter)); rootnode.appendChild(selrowafterNode);
		var ownerNode=xmlDoc.createElement("owner"); ownerNode.appendChild(xmlDoc.createTextNode(owner)); rootnode.appendChild(ownerNode);
		var filterOnBasketNode=xmlDoc.createElement("basketfilter"); if(document.getElementById("filterbasket")) {if(document.getElementById("filterbasket").innerHTML.substring(0,4)=="voir") {filterOnBasketNode.appendChild(xmlDoc.createTextNode("no"));} else {filterOnBasketNode.appendChild(xmlDoc.createTextNode("yes"));}}else {filterOnBasketNode.appendChild(xmlDoc.createTextNode("no"));} rootnode.appendChild(filterOnBasketNode);
		var bask="";
		if(document.getElementById("basket"))
		{
		  document.getElementById("basket").innerHTML;
		}
		if(bask=="")
		{
		  bask="<basket></basket>";
		}
		else
		{
		  bask=decode64(bask);
		}
		var xmlDocBasket;
		if (window.DOMParser)
		{
		  parser=new DOMParser();
		  if (bask.substr(0, 5)=='<?xml')
		  {
			xmlDocBasket=parser.parseFromString(bask,"text/xml");
		  }
		  else
		  {
			xmlDocBasket=parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?>'+bask,"text/xml");
		  }      
		}
		else // Internet Explorer
		{
		  xmlDocBasket=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDocBasket.async="false";
		  xmlDocBasket.loadXML('<?xml version="1.0" encoding="UTF-8"?>'+bask); 
		}
		if(xmlDoc.importNode)
		{
		  ibask=xmlDoc.importNode(xmlDocBasket.documentElement,true);
		  xmlDoc.documentElement.appendChild(ibask);	
		}
		else
		{
		  xmlDoc.documentElement.appendChild(xmlDocBasket.documentElement);	
		}

		var str="";
		if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
		return str;
	}
  }
  
  function getQuery(neglectsf)
  {
      //hier moet een xml structuur uitkomen voor het geheel!
        var url="";
//	    if(neglectsf!="searchfield" && neglectsf!="searchfield1") url=url+"&tb1="+encodeURIComponent(document.getElementById("searchfield1tb").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield2") url=url+"&tb2="+encodeURIComponent(document.getElementById("searchfield2tb").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield3") url=url+"&tb3="+encodeURIComponent(document.getElementById("searchfield3tb").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield4") url=url+"&tb4="+encodeURIComponent(document.getElementById("searchfield4tb").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield5") url=url+"&tb5="+encodeURIComponent(document.getElementById("searchfield5tb").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield1") url=url+"&sf1="+encodeURIComponent(document.getElementById("searchfield1").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield2") url=url+"&sf2="+encodeURIComponent(document.getElementById("searchfield2").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield3") url=url+"&sf3="+encodeURIComponent(document.getElementById("searchfield3").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield4") url=url+"&sf4="+encodeURIComponent(document.getElementById("searchfield4").value);
//		if(neglectsf!="searchfield" && neglectsf!="searchfield5") url=url+"&sf5="+encodeURIComponent(document.getElementById("searchfield5").value);
//		url=url+"&crit2="+encodeURIComponent(getCheckedValue("crit2"));
//		url=url+"&crit3="+encodeURIComponent(getCheckedValue("crit3"));
//		url=url+"&crit4="+encodeURIComponent(getCheckedValue("crit4"));
//		url=url+"&crit5="+encodeURIComponent(getCheckedValue("crit5"));
//      url=url+"&first="+encodeURIComponent(startrecord);
//      url=url+"&sort="+encodeURIComponent(document.getElementById("selectsort").value);
        return url;
  }

	function Set_Cookie( name, value, expires, path, domain, secure )
	{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
	}

	function Get_Cookie( check_name ) {
		// first we'll split this cookie up into name/value pairs
		// note: document.cookie only returns name=value, not the other components
		var a_all_cookies = document.cookie.split( ';' );
		var a_temp_cookie = '';
		var cookie_name = '';
		var cookie_value = '';
		var b_cookie_found = false; // set boolean t/f default f

		for ( i = 0; i < a_all_cookies.length; i++ )
		{
			// now we'll split apart each name=value pair
			a_temp_cookie = a_all_cookies[i].split( '=' );


			// and trim left/right whitespace while we're at it
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

			// if the extracted name matches passed check_name
			if ( cookie_name == check_name )
			{
				b_cookie_found = true;
				// we need to handle case where cookie has no value but exists (no = sign, that is):
				if ( a_temp_cookie.length > 1 )
				{
					cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				}
				// note that in cases where cookie is initialized but no value, null is returned
				return cookie_value;
				break;
			}
			a_temp_cookie = null;
			cookie_name = '';
		}
		if ( !b_cookie_found )
		{
			return null;
		}
	}
	
	// this deletes the cookie when called
	function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
	//use:Delete_Cookie('test', '/', '');


function unic_utf8(str) {
    nc = "";
    for (i = 0; i < str.length; i++) {
        s = str.substr(i, 6);
        if (arr = s.match(/%u[0-9A-F][0-9A-F][0-9A-F][0-9A-F]/i)) {
            c = arr[0].substr(2, 4);
            c = unic_u(c);
            i += 5;
        } else {
            c = str.charAt(i);
        };
        nc += c;
    };
    return nc;
};

  function showAll(t)
  {    
	//newQuery("Alle velden",t)
	//alert ("Zoek alles: "+t);
	//alert ("Springt naar de zoekresultaten-pagina. Nog niet geimplementeerd.");
	window.location = "/index.php?title=Zoekresultaten&searchfor="+encodeURIComponent(t);
  }
  
  function executeQuery()
  {	 
     Set_Cookie( 'query', unescape(getQuery2("",0,"","","","","","","")), 1, '/', '', '' );
	 if(wgTitle!="Zoekresultaten")
	 {
	   window.location = "/index.php?title=Zoekresultaten";
	 }
	 else
	 {
		 resultHttpobject.abort();
		 getInfoHttpobject.abort();
		 fillValueSelectBoxHttpobject.abort();
		 //singlehttpobject.abort();
		 if (resultHttpobject !=null)
		 {

		 //addHistory("action=executeQuery&"+getQuery(""))
			if(document.getElementById("ccresultsajaxbusy")) {document.getElementById("ccresultsajaxbusy").style.display="block"};
			resultHttpobject.onreadystatechange=showResultsStateChanged;
			var params = "reqspec="+unescape(getQuery2("",0,"","","","","","",""));		
			addHistory(params);
			resultHttpobject.open("POST","/ccscripts/showresults.php",true);
			resultHttpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			resultHttpobject.setRequestHeader("Content-length", params.length);
			resultHttpobject.setRequestHeader("Connection", "close");
			resultHttpobject.send(params);
		 }   
	}
  }
  
  function saveBasket()
  {	 
     if (saveBasketHttpObject !=null)
     {
        saveBasketHttpObject.abort();
		//if(document.getElementById("ccresultsajaxbusy")) {document.getElementById("ccresultsajaxbusy").style.display="block"};
        //resultHttpobject.onreadystatechange=showResultsStateChanged;
		var params = "reqspec="+unescape(getQuery2("",0,"","","","","","",""));
		addHistory(params);
		saveBasketHttpObject.open("POST","/ccscripts/savebasket.php",false);
		saveBasketHttpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		saveBasketHttpObject.setRequestHeader("Content-length", params.length);
		saveBasketHttpObject.setRequestHeader("Connection", "close");
		saveBasketHttpObject.send(params);
        alert("saved");
     }   
  }
  
  function newQuery(searchfield,searchvalue)
  {
     //gebruikt om door te klikken vanuit object-beschrijvingen
     setupSearchbox(document.getElementById("searchfield"));
     setSearchOptions('searchfield');

     //if(document.getElementById('singleviewdivInner').style.display!="none") {new Animation(document.getElementById('singleviewdivInner'),0,0);}
     sf = document.getElementById("searchfield");
	 if(sf) 
	 { 
	   for(index = 0; index < sf.length; index++) 
	   { 
	     if(sf[index].text == searchfield) 
	     { 
		   sf.selectedIndex = index;
	     }
	   }
	 }
     selsf="searchfield";
	 //setValue(searchvalue);
 	 if(document.getElementById(selsf+"tb"))
	 {
//alert("oeps:"+searchvalue);
	    document.getElementById(selsf+"tb").value=searchvalue;
//   	setValue(searchvalue);
		transferSFtoSF1();
	    resetQuery();
	 } 
  }
  
  function newSelectQuery(searchfield,searchvalue)
  {
     //gebruikt om door te klikken vanuit object-beschrijvingen
     setupSearchbox(document.getElementById("searchfield"));
     setSearchOptions('searchfield');

     if(document.getElementById('singleviewdivInner').style.display!="none") {new Animation(document.getElementById('singleviewdivInner'),0,0);}
     sf = document.getElementById("searchfield");
	 if(sf) 
	 { 
	   for(index = 0; index < sf.length; index++) 
	   { 
	     if(sf[index].text == searchfield) 
	     { 
		   sf.selectedIndex = index;
	     }
	   }
	 }
     selsf="searchfield";
	 setValue(searchvalue);
  }

  function setParentNode(child,p)
  {
    if(child.parentNode)
	{
	  if(child.parentNode==p) return child;
	  child.oldParent=child.parentNode;
	  child=child.parentNode.removeChild(child);
	}
	return p.appendChild(child);
  }

  function getInfo(str,sf,length,firstterm,num,selrowafter)
  {
   if(str&&str.length>1)
   {
	  if(firstterm<1) firstterm=1;
      //getInfoHttpobject=GetHttpObject();
      resultHttpobject.abort();
      getInfoHttpobject.abort();
      fillValueSelectBoxHttpobject.abort();
      //singlehttpobject.abort();
      if (getInfoHttpobject !=null)
      {
		var params = "reqspec="+unescape(getQuery2(sf,0,str,length,firstterm,num,selrowafter,getNodeAttribute(getXmlDocSelectBox(sf),"/ccAdvancedSelect/field","queryfield"),""));
        //var url="/mediawiki-1.15.1/ccscripts/fillsearchbox.php";
        //url=url+"?str="+encodeURIComponent(str);
        //url=url+"&length="+encodeURIComponent(length);
        //url=url+"&firstterm="+encodeURIComponent(firstterm);
        //url=url+"&num="+encodeURIComponent(num);        
        //url=url+"&fields="+encodeURIComponent(getNodeAttribute(getXmlDocSelectBox(sf),"/ccAdvancedSelect/field","queryfield"));
        //url=url+"&selrowafter="+encodeURIComponent(selrowafter);
        //url=url+"&"+getQuery(sf);
        if(params!=prevurl)
        {
		  var tbobj=document.getElementById(selsf+"tb");
		  if(tbobj)
		  {
			 var tbobjx=findPosX(tbobj)+2;
			 var tbobjy=findPosY(tbobj)+tbobj.offsetHeight+2;

			 document.getElementById("autoSuggestionsList").style.left=tbobjx+"px";
			 document.getElementById("autoSuggestionsList").style.top=tbobjy+"px";
		  }
		  document.getElementById("autoSuggestionsListInner").innerHTML="<div style='position:absolute; left: 5px; top: 5px; z-index:7000'><img alt='' src='/ccscripts/ajaxbusy.gif' /></div>"+document.getElementById("autoSuggestionsListInner").innerHTML;

		   prevurl=params;
           selrow=selrowafter;        
           curtext=str;
           cursf=sf;
           getInfoHttpobject.onreadystatechange=autoSuggestionListStateChanged;		   
		   getInfoHttpobject.open("POST","/ccscripts/fillsearchbox.php",true);
		   getInfoHttpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   getInfoHttpobject.setRequestHeader("Content-length", params.length);
		   getInfoHttpobject.setRequestHeader("Connection", "close");
		   getInfoHttpobject.send(params);
        }
      }
   }
   else
   {
     document.getElementById("autoSuggestionsListInner").innerHTML="";  
     //document.onkeyup = null;
   }
   
  }

  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1){
		curleft += obj.offsetLeft;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
 
  function findPosY(obj){
    var curtop = 0;
    if(obj.offsetParent)
        while(1){
		curtop += obj.offsetTop;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

  function autoSuggestionListStateChanged()
  {
    if (getInfoHttpobject.readyState==4)
    {
      document.getElementById("autoSuggestionsListInner").innerHTML=getInfoHttpobject.responseText;
      document.onkeyup = KeyCheck;
    }
  }

  function showResultsStateChanged()
  {
    if (resultHttpobject.readyState==4)
    {
      if(document.getElementById("ccresults"))
	  {
		  document.getElementById("ccresults").innerHTML=resultHttpobject.responseText;
		  var scripts = document.getElementById("ccresults").getElementsByTagName("script");
		  if(scripts) for(var i=0; i < scripts.length; i++) eval(scripts[i].innerHTML || scripts[i].text);
	  }
    }
  }

  function GetHttpObject()
  {
  if (window.ActiveXObject) 
    return new ActiveXObject("Microsoft.XMLHTTP");
    else if (window.XMLHttpRequest) 
    return new XMLHttpRequest();
    else 
    {
      return null;
    }
  }

  document.onkeyup = KeyCheck;
  
  function KeyCheck(e)
  { if(document.getElementById('advancedSelect'))
    {
		if(document.getElementById('advancedSelect').style.display!='block')
		{
			var KeyID = (window.event) ? event.keyCode : e.keyCode;

			keyhandled=false;
			if(document.getElementById("autoSuggestionsListInner").innerHTML!="")
			{
			  //alert(KeyID);
			  switch(KeyID)
			  {
				case 27:
				  document.getElementById("autoSuggestionsListInner").innerHTML="";
				  //document.onkeyup = null;
				  prevurl="";
				  keyhandled=true;
				  break
				case 13:
				  if(document.getElementById("rw"+selrow)!=null)
				  {
					prevurl='';
					startrecordA=1;
					startrecordB=1;
					if(tmr) clearTimeout(tmr);
					setValue(document.getElementById("rw"+selrow).innerText||document.getElementById("rw"+selrow).textContent);
					document.getElementById('autoSuggestionsListInner').innerHTML='';
				  }
				  else
				  {		  
					prevurl='';
					startrecordA=1;
					startrecordB=1;
					if(tmr) clearTimeout(tmr);
					document.getElementById('autoSuggestionsListInner').innerHTML='';
					setValue(document.getElementById(selsf+"tb").value);
				  }
				  keyhandled=true;
				  break;
				case 33:
					  if(selrow>1)
					  {
						getInfo(curtext,cursf,300,selrow-6,6,selrow-6);
					  }
					keyhandled=true;
					break;
				case 34:
					//page down
					  getInfo(curtext,cursf,300,selrow+6,6,selrow+6);
					keyhandled=true;
					break;
				case 38:
				  //alert("Arrow Up");
				  if(document.getElementById("rw"+(selrow-1))!=null)
				  {
					  document.getElementById("rw"+selrow).style.backgroundColor="#eeeeee";
					  selrow=selrow-1;
					  document.getElementById("rw"+selrow).style.backgroundColor="#B7C5D2";
				  }
				  else
				  {
					if(selrow>1)
					{
					  getInfo(curtext,cursf,300,selrow-6,6,selrow-1);
					}
				  }
				  keyhandled=true;
				  break;   
				case 40:
				  //alert("Arrow Down");
				  if(document.getElementById("rw"+(selrow+1))!=null)
				  {
					  if(document.getElementById("rw"+selrow)!=null) { document.getElementById("rw"+selrow).style.backgroundColor="#eeeeee"; }
					  selrow=selrow+1;
					  document.getElementById("rw"+selrow).style.backgroundColor="#B7C5D2";
				  }
				  else
				  {
					getInfo(curtext,cursf,300,selrow+1,6,selrow+1);
				  }
				  keyhandled=true;
				  break;   
			   }
			}
			else
			{
			  if(KeyID==13)
			  {
				  if(tmr) {clearTimeout(tmr);}
				  keyhandled=true;
				  prevurl='';
				  startrecordA=1;
				  startrecordB=1;
				  setValue(document.getElementById(selsf+"tb").value);
			  }
			}
		}	
	}
	else
	{
	  keyhandled=false;
	}
  }

  function nextResultPageA()
  {
    startrecordA=startrecordA+10;
    executeQuery();
  }

  function prevResultPageA()
  {
    startrecordA=startrecordA-10;
    executeQuery();
  }

  function nextResultPageB()
  {
    startrecordB=startrecordB+10;
    executeQuery();
  }

  function prevResultPageB()
  {
    startrecordB=startrecordB-10;
    executeQuery();
  }

  function nextSingleResultPage(curpage)
  {
     if (curpage>=startrecord+9)
     {
       nextResultPage();
     }
     singleview(curpage+1);
  }

  function prevSingleResultPage(curpage)
  {
     if (curpage<=startrecord)
     {
       prevResultPage();
     }
     singleview(curpage-1);
  }

  function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
  
  function clearSF(sf)
  {
     if(sf=="searchfield")
	 {
	   setupSearchbox(document.getElementById("searchfield"));
	   setSearchOptions('searchfield');
	   setupSearchbox(document.getElementById("searchfield1"));
	   setSearchOptions('searchfield1');
	   setupSearchbox(document.getElementById("searchfield2"));
	   setSearchOptions('searchfield2');
	   setupSearchbox(document.getElementById("searchfield3"));
	   setSearchOptions('searchfield3');
	   setupSearchbox(document.getElementById("searchfield4"));
	   setSearchOptions('searchfield4');
	   setupSearchbox(document.getElementById("searchfield5"));
	   setSearchOptions('searchfield5');
	 }
     if(sf=="searchfield1")
	 {
	   copySFtoSF('searchfield2','searchfield1');
	   copySFtoSF('searchfield3','searchfield2');
	   copySFtoSF('searchfield4','searchfield3');
	   copySFtoSF('searchfield5','searchfield4');	   
	   setupSearchbox(document.getElementById("searchfield5"));
	   setSearchOptions('searchfield5');
	 }
     if(sf=="searchfield2")
	 {
	   copySFtoSF('searchfield3','searchfield2');
	   copySFtoSF('searchfield4','searchfield3');
	   copySFtoSF('searchfield5','searchfield4');	   
	   setupSearchbox(document.getElementById("searchfield5"));
	   setSearchOptions('searchfield5');
	 }
     if(sf=="searchfield3")
	 {
	   copySFtoSF('searchfield4','searchfield3');
	   copySFtoSF('searchfield5','searchfield4');	   
	   setupSearchbox(document.getElementById("searchfield5"));
	   setSearchOptions('searchfield5');
	 }
     if(sf=="searchfield4")
	 {
	   copySFtoSF('searchfield5','searchfield4');	   
	   setupSearchbox(document.getElementById("searchfield5"));
	   setSearchOptions('searchfield5');
	 }
     if(sf=="searchfield5")
	 {
	   setupSearchbox(document.getElementById("searchfield5"));
	   setSearchOptions('searchfield5');
	 }
	 resetQuery();
  }

  function copySFtoSF(sf,sf2)
  {
	  if(document.getElementById(sf)&&document.getElementById(sf2))
	  {
	    setupSearchbox(document.getElementById(sf2));
	    document.getElementById(sf2).selectedIndex=document.getElementById(sf).selectedIndex;
	    document.getElementById(sf2).options[document.getElementById(sf2).selectedIndex].value=document.getElementById(sf).options[document.getElementById(sf).selectedIndex].value;
	    setSearchOptions(sf2);
	    if(document.getElementById(sf+"tb")) { document.getElementById(sf2+"tb").value=document.getElementById(sf+"tb").value; }
	  }
  }
  
  function transferSFtoSF1()
  {
    copySFtoSF('searchfield','searchfield1');
    setupSearchbox(document.getElementById("searchfield"));
    setSearchOptions('searchfield');
    setupSearchbox(document.getElementById("searchfield2"));
    setSearchOptions('searchfield2');
    setupSearchbox(document.getElementById("searchfield3"));
    setSearchOptions('searchfield3');
    setupSearchbox(document.getElementById("searchfield4"));
    setSearchOptions('searchfield4');
    setupSearchbox(document.getElementById("searchfield5"));
    setSearchOptions('searchfield5');
    //document.getElementById("crit2a").checked=true;
    //document.getElementById("crit3a").checked=true;
    //document.getElementById("crit4a").checked=true;
    //document.getElementById("crit5a").checked=true;	
	
  }

  function transferSF5toSF1()
  {
    copySFtoSF('searchfield5','searchfield1');
    setupSearchbox(document.getElementById("searchfield"));
    setSearchOptions('searchfield');
    setupSearchbox(document.getElementById("searchfield2"));
    setSearchOptions('searchfield2');
    setupSearchbox(document.getElementById("searchfield3"));
    setSearchOptions('searchfield3');
    setupSearchbox(document.getElementById("searchfield4"));
    setSearchOptions('searchfield4');
    setupSearchbox(document.getElementById("searchfield5"));
    setSearchOptions('searchfield5');
    //document.getElementById("crit2a").checked=true;
    //document.getElementById("crit3a").checked=true;
    //document.getElementById("crit4a").checked=true;
    //document.getElementById("crit5a").checked=true;		
  }

  function resetQuery()
  {
 	 document.getElementById("autoSuggestionsListInner").innerHTML="";
	 //document.onkeyup = null;
	 prevurl="";
	 startrecordA=1;
	 startrecordB=1;
	 executeQuery();
  }

  function setValue(str)
  {
	//document.getElementById('advancedsearch').style.display='none'; 
	if(document.getElementById(selsf+"tb"))
	{
		if(str)
		{
		  for(var pos=str.length; pos>0;pos--)
		  {
			if(str.charAt(pos)=="(") { str=str.substring(0,pos-1); break; }
		  }    
		}
	    //document.getElementById(selsf+"tb").value=str;
		setSelectAdvancedValueChecked(true,encode64(str),selsf,true)
		if(selsf=="searchfield") { transferSFtoSF1(); }
		if(selsf=="searchfield5") { transferSF5toSF1(); }		
		resetQuery();
	}
  }

  function getXmlDocSelectBox(activeSearchField)
  {
    if(document.getElementById(activeSearchField))
	{
		if (window.DOMParser)
		{
		  parser=new DOMParser();
		  //xmlDoc=parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?>'+document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value,"text/xml");
		  if (document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value.substr(0, 5)=='<?xml')
		  {
			xmlDoc=parser.parseFromString(document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value,"text/xml");
		  }
		  else
		  {
			xmlDoc=parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?>'+document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value,"text/xml");
		  }
		  
		}
		else // Internet Explorer
		{
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML('<?xml version="1.0" encoding="UTF-8"?>'+document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value); 
		}  
		return xmlDoc;
	}
  }

  function setSelectAdvancedValueChecked(active,fieldvalue,activeSearchField,onlyFreetext)
  {
    xmlDoc = getXmlDocSelectBox(activeSearchField);
    if(!onlyFreetext && getNodeValue(xmlDoc,"/ccAdvancedSelect/select")=="yes")
	{
		if(getNodeAttribute(xmlDoc,"/ccAdvancedSelect/select","multiple")=="yes")
		{
			if(active==true)
			{
			  valuesNode=xmlDoc.getElementsByTagName("values")[0];
			  newnode=xmlDoc.createElement("value");
			  newtext=xmlDoc.createTextNode(fieldvalue);
			  newnode.appendChild(newtext);
			  valuesNode.appendChild(newnode);	 
			}
			else
			{
			  var values=xmlDoc.getElementsByTagName("value");
			  for(var i = 0; i < values.length; i++)
			  {
				if (values[i].childNodes[0].nodeValue==fieldvalue)
				{ 
				  values[i].parentNode.removeChild(values[i]);
				}
			  }      
			}
		}
		else
		{
		  setNodeValue(xmlDoc,"/ccAdvancedSelect/values","value",fieldvalue);
		}	
	}
	else
	{
		//setNodeValue(xmlDoc,"/ccAdvancedSelect/values","","");
		var values=xmlDoc.getElementsByTagName("value");
		for(var i = 0; i < values.length; i++)
		{
		    values[i].parentNode.removeChild(values[i]);
		}      
	}
	if(getNodeValue(xmlDoc,"/ccAdvancedSelect/freetext")=="yes")
	{ 
	  //var html="";
	  //var nl = findNodes(xmlDoc,"/ccAdvancedSelect/values/value");
	  //for(var i=0;i<nl.length;i++)
	  //{
	  //  if (nl[i].childNodes.length>0)
	  //  { 
	  //    if(html!="") { html=html+" or "; }
	  //    //html=html+"["+decode64(nl[i].childNodes[0].nodeValue)+"]";
	  //	  html=html+decode64(nl[i].childNodes[0].nodeValue);
	  //  }
	  //}
	  //html=utf8Decode(html);
	  html=decode64(fieldvalue);
      //waarde niet in de free textbox zetten.... 
	  if(onlyFreetext)
	  {
	  //alert(html);
	    document.getElementById(activeSearchField+"tb").value=html;
	  }
	  else
	  {
	    document.getElementById(activeSearchField+"tb").value="";
	  }
	}
	else
	{
	  if(document.getElementById(activeSearchField+"tb"))
	  {
	    document.getElementById(activeSearchField+"tb").value="";
	  }
	}
	var str="";
	if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
	document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value=str;
  }

  //function setSelectAdvancedFieldChecked(caller,field,activeSearchField)
  //{
  //  xmlDoc = getXmlDocSelectBox(activeSearchField);
  // fields=xmlDoc.getElementsByTagName("field");
  //   for(var i = 0; i < fields.length; i++)
  //   {
  //   if (fields[i].childNodes[0].nodeValue==field)
  //   { 
  //    if(caller.checked) {fields[i].setAttribute("active","true");} else {fields[i].setAttribute("active","false");}
  //  }
  // }
	// var str="";
	// if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
	// document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value=str;
    // ValueSelectResetPage(activeSearchField);
	// fillValueSelectBox(activeSearchField);
  //}
  
  function ValueSelectBoxNextPage(activeSearchField)
  {
	  xmlDoc = getXmlDocSelectBox(activeSearchField);
	  rootNode=xmlDoc.getElementsByTagName("ccAdvancedSelect")[0];
	  firstPageNode=null;
	  if(rootNode.getElementsByTagName("first")[0]) { firstPageNode=rootNode.getElementsByTagName("first")[0].childNodes[0] };
	  if(firstPageNode)
	  {
		  firstPage=firstPageNode.nodeValue;
		  if(firstPage=="")
		  {
			firstPage="2";
		  }
		  else
		  {
			firstPage=parseInt(firstPage)+1;
		  }
		  firstPageNode.nodeValue=firstPage;
	  }
	  else
	  {		  
		  newnode=xmlDoc.createElement("first");
		  newtext=xmlDoc.createTextNode("2");
		  newnode.appendChild(newtext);
		  rootNode.appendChild(newnode);	 
	  }
	
	  var str="";
	  if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
	  document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value=str;
	  
	  fillValueSelectBox(activeSearchField);
  }

  function ValueSelectBoxPrevPage(activeSearchField)
  {
	  xmlDoc = getXmlDocSelectBox(activeSearchField);
	  rootNode=xmlDoc.getElementsByTagName("ccAdvancedSelect")[0];
	  firstPageNode=null;
	  if(rootNode.getElementsByTagName("first")[0]) { firstPageNode=rootNode.getElementsByTagName("first")[0].childNodes[0] };
	  if(firstPageNode)
	  {
		  firstPage=firstPageNode.nodeValue;
		  if(firstPage!="")
		  {
			firstPage=parseInt(firstPage)-1;
			firstPageNode.nodeValue=firstPage;
		    var str="";
			if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
			document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value=str;			  
			fillValueSelectBox(activeSearchField);
		  }
	  }	
  }

  function ValueSelectBoxStartLetters(activeSearchField,startletters)
  {
	  xmlDoc = getXmlDocSelectBox(activeSearchField);
	  rootNode=xmlDoc.getElementsByTagName("ccAdvancedSelect")[0];
	  startLettersNode=null;
	  if(rootNode.getElementsByTagName("startletters")[0]) { startLettersNode=rootNode.getElementsByTagName("startletters")[0] };
	  if(startLettersNode)
	  {
	      if(startLettersNode.childNodes[0])
	      {
		    startLettersNode.childNodes[0].nodeValue=startletters;
		  }
		  else
		  {
  		    newtext=xmlDoc.createTextNode(startletters);
	 	    startLettersNode.appendChild(newtext);
		  }
	  }
	  else
	  {		  
		  newnode=xmlDoc.createElement("startletters");
		  newtext=xmlDoc.createTextNode(startletters);
		  newnode.appendChild(newtext);
		  rootNode.appendChild(newnode);	 
	  }
	
	  var str="";
	  if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
	  document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value=str;
	  fillValueSelectBox(activeSearchField);
  }

  function ValueSelectBoxMask(activeSearchField,mask)
  {

	  xmlDoc = getXmlDocSelectBox(activeSearchField);
	  rootNode=xmlDoc.getElementsByTagName("ccAdvancedSelect")[0];
	  maskNode=null;
	  if(rootNode.getElementsByTagName("mask")[0]) { maskNode=rootNode.getElementsByTagName("mask")[0] };
	  if(maskNode)
	  {
		  //maskNode.nodeValue=mask;
	      if(maskNode.childNodes[0])
	      {
		    maskNode.childNodes[0].nodeValue=mask;
		  }
		  else
		  {
  		    newtext=xmlDoc.createTextNode(mask);
	 	    maskNode.appendChild(newtext);
		  }
	  }
	  else
	  {		  
		  newnode=xmlDoc.createElement("mask");
		  newtext=xmlDoc.createTextNode(mask);
		  newnode.appendChild(newtext);
		  rootNode.appendChild(newnode);	 
	  }
	
	  var str="";
	  if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
	  document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value=str;

	  fillValueSelectBox(activeSearchField);
  }

  function ValueSelectResetPage(activeSearchField)
  {
	  xmlDoc = getXmlDocSelectBox(activeSearchField);
	  rootNode=xmlDoc.getElementsByTagName("ccAdvancedSelect")[0];
	  firstPageNode=null;
	  if(rootNode.getElementsByTagName("first")[0]) { firstPageNode=rootNode.getElementsByTagName("first")[0].childNodes[0] };
	  if(firstPageNode)
	  {
		  firstPageNode.nodeValue="1";
	  }
	  else
	  {		  
		  newnode=xmlDoc.createElement("first");
		  newtext=xmlDoc.createTextNode("1");
		  newnode.appendChild(newtext);
		  rootNode.appendChild(newnode);	 
	  }
	
	  var str="";
	  if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
	  document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value=str;
  }

  function fillValueSelectBox(activeSearchField)
  {
     //fillValueSelectBoxHttpobject=GetHttpObject();
     resultHttpobject.abort();
     getInfoHttpobject.abort();
     fillValueSelectBoxHttpobject.abort();
     //singlehttpobject.abort();
     if (fillValueSelectBoxHttpobject!=null)
     {
		if(document.getElementById("ccadvancedselectajaxbusy")) {document.getElementById("ccadvancedselectajaxbusy").style.display="block"};
		//pagina die getoond wordt, letter, mask, reeds geselecteerde, query, etc.
		//var params = "reqspec="+unescape(document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value);
		//var params = "reqspec="+unescape(document.getElementById(activeSearchField).options[document.getElementById(activeSearchField).selectedIndex].value);
        var params = "reqspec="+unescape(getQuery2("",0,"","","","","","",activeSearchField));
		fillValueSelectBoxHttpobject.onreadystatechange=valueSelectBoxStateChanged;
		fillValueSelectBoxHttpobject.open("POST","/ccscripts/fillselect.php",true);
		fillValueSelectBoxHttpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		fillValueSelectBoxHttpobject.setRequestHeader("Content-length", params.length);
		fillValueSelectBoxHttpobject.setRequestHeader("Connection", "close");
		fillValueSelectBoxHttpobject.send(params);
	}
  }

  function valueSelectBoxStateChanged()
  {
    if (fillValueSelectBoxHttpobject.readyState==4)
    {
      document.getElementById("advancedSelectContentsValues").innerHTML=fillValueSelectBoxHttpobject.responseText;
	  if(document.getElementById("ccadvancedselectajaxbusy")) {document.getElementById("ccadvancedselectajaxbusy").style.display="none"};
    }
  }

  function fillFieldSelectBox(activeSearchField)
  {
    xmlDoc = getXmlDocSelectBox(activeSearchField);
    html="";
	fields=xmlDoc.getElementsByTagName("field");
    for(var i = 0; i < fields.length; i++)
    {
	  html=html+"<span class=\"box_header\">Choisir "+fields[i].childNodes[0].nodeValue+"</span>";
	  html=html+'&nbsp;&nbsp;&nbsp;&nbsp;<span id="resultcount_advancedselectbox"></span>';
	  //html=html+"<input type='checkbox' onclick='setSelectAdvancedFieldChecked(this,\""+fields[i].childNodes[0].nodeValue+"\",\""+activeSearchField+"\");' name='sports' value='soccer'";
	  //if(fields[i].getAttribute("active")=="true") html=html+" checked='yes'";
      //html=html+" />";
	  //html=html+" "+fields[i].childNodes[0].nodeValue;
      //html=html+"&nbsp;&nbsp;&nbsp;";
    }
    document.getElementById("advancedSelectContentsFields").innerHTML=html;
  }
  
  function fillSelectBox(activeSearchField)
  {
    document.getElementById("advancedSelectContentsValues").innerHTML="";
	ValueSelectResetPage(activeSearchField);
    fillFieldSelectBox(activeSearchField);
	fillValueSelectBox(activeSearchField);	
  }

  function findNodesRecursive(root,parentname,findname,nl)
  {
	for(var i=0;i<root.childNodes.length;i++)
	{
	  if(parentname+'/'+root.childNodes[i].nodeName==findname)
	  {
		nl.push(root.childNodes[i]);	 
	  }
	  else
	  {
	    if(root.childNodes[i].nodeType==1) findNodesRecursive(root.childNodes[i],parentname+'/'+root.childNodes[i].nodeName,findname,nl);
	  }	  
	}    
  }
  
  function findNodes(doc,findname)
  {
	var nodelist=new Array();
	findNodesRecursive(doc,"",findname,nodelist);
	return nodelist;
  }
  
  function getNodeValue(doc,findname)
  {
     var nl = findNodes(xmlDoc,findname);
	 if(nl.length>0)
	 {
	   if (nl[0].childNodes.length>0)
	   { 
	     return nl[0].childNodes[0].nodeValue;
	   }
	 }
	 return "";
  }
  
  function setNodeValue(doc,parentName,tagName,nodeval)
  {
     var nl = findNodes(xmlDoc,parentName);
	 if(nl.length>0)
	 {
       for(var i=0;i<nl[0].childNodes.length;i++)
	   {
	     if(nl[0].childNodes[i].nodeName==tagName)
		 {
		   if(nl[0].childNodes[i].childNodes[0])
		   {  //node exists; replace text value
		      nl[0].childNodes[i].childNodes[0].nodeValue=nodeval;
			  return true;
		   }
		   else
		   {  //node exists but without text value
  		      var newtext=xmlDoc.createTextNode(nodeval);
	 	      nl[0].childNodes[i].appendChild(newtext);
			  return true;
		   }
		 }
	   }
	   //node does not exist yet
	   var newnode=xmlDoc.createElement(tagName);
	   var newtext=xmlDoc.createTextNode(nodeval);
	   newnode.appendChild(newtext);
	   nl[0].appendChild(newnode);	 	   
	 }
	 return false; //could not find parentnode!
  }

  function getNodeAttribute(doc,findname,attr)
  {
     var nl = findNodes(xmlDoc,findname);
	 if(nl.length>0)
	 {
       return nl[0].getAttribute(attr);
	 }
	 return "";
  }

  function setSearchOptions(ownerComboId)
  {
    if(document.getElementById(ownerComboId))
	 {
		 var xmlDoc = getXmlDocSelectBox(ownerComboId);
		 setNodeValue(xmlDoc,"/ccAdvancedSelect","owner",ownerComboId);
		 var str="";
		 if(window.DOMParser) {str=(new XMLSerializer()).serializeToString(xmlDoc);} else {str=xmlDoc.documentElement.xml;}
		 document.getElementById(ownerComboId).options[document.getElementById(ownerComboId).selectedIndex].value=str;	 
		 
		 var html="";
		 if(getNodeValue(xmlDoc,"/ccAdvancedSelect/freetext")=="yes")
		 {
		   // http://www.htmlescape.net/stringescape_tool.html
		   if(getNodeValue(xmlDoc,"/ccAdvancedSelect/select")=="yes")
		   { 
			 html=html+'<input class=\"inputtext\" style=\"width: 60px;\" id=\"'+ownerComboId+'tb\" onblur=\"setTimeout(function() {document.getElementById(\'autoSuggestionsListInner\').innerHTML=\'\'; prevurl=\'\';},100);\" onkeyup=\"selsf=\''+ownerComboId+'\'; if(!keyhandled){if(tmr){clearTimeout(tmr); tmr = setTimeout(\'processTypedText(\\\''+ownerComboId+'\\\');\',500);} else {tmr=setTimeout(\'processTypedText(\\\''+ownerComboId+'\\\');\',500);}} keyhandled=false;\" type=\"text\" />';
		   }
		   else
		   {	   	
			 //html=html+'<input class=\"inputtext\" style=\"width: 123px;\" id=\"'+ownerComboId+'tb\" onblur=\"setTimeout(function() {document.getElementById(\'autoSuggestionsListInner\').innerHTML=\'\'; prevurl=\'\';},100);\" onkeyup=\"selsf=\''+ownerComboId+'\'; if(!keyhandled){if(tmr){clearTimeout(tmr); tmr = setTimeout(\'processTypedText(\\\''+ownerComboId+'\\\');\',500);} else {tmr=setTimeout(\'processTypedText(\\\''+ownerComboId+'\\\');\',500);}} keyhandled=false;\" type=\"text\" />';
			 html=html+'<input style=\"width: 60%;	margin: 0; font-size: 95%;" id=\"'+ownerComboId+'tb\" onblur=\"setTimeout(function() {document.getElementById(\'autoSuggestionsListInner\').innerHTML=\'\'; prevurl=\'\';},100);\" onkeyup=\"selsf=\''+ownerComboId+'\'; if(!keyhandled){if(tmr){clearTimeout(tmr); tmr = setTimeout(\'processTypedText(\\\''+ownerComboId+'\\\');\',500);} else {tmr=setTimeout(\'processTypedText(\\\''+ownerComboId+'\\\');\',500);}} keyhandled=false;\" type=\"text\" />';
		   }
		 }
		 if(getNodeValue(xmlDoc,"/ccAdvancedSelect/select")=="yes")
		 {
		   html=html+'&nbsp;<span id=\"advancedSelectButton\" style=\"display: inline;\"><a class=\"prochaine\" href=\"#\" onclick=\"fillSelectBox(\''+ownerComboId+'\'); centerElement(document.getElementById(\'advancedSelect\')); document.getElementById(\'advancedSelect\').style.display=\'block\'; setShim(\'advancedSelect\',\'shimChoicebox\'); return false;\">&nbsp;choisir </a></span>';
		 }

		 if(!document.getElementById(ownerComboId+"criteria"))
		 {
		   //alert(ownerComboId+"criteria");
		 }
		 else
		 {
		   document.getElementById(ownerComboId+"criteria").innerHTML=html;
		   document.getElementById(ownerComboId+"criteria").style.display="inline";
		 }

		 //<input style="width: 200px;" id="tb" onblur="setTimeout(function() {document.getElementById('autoSuggestionsListInner').innerHTML=''; prevurl='';},100);" onkeyup="selsf='searchfeld'; if(!keyhandled){if(tmr){clearTimeout(tmr); tmr = setTimeout('processTypedText(\'tb\',\'searchfield\');',500);} else {tmr=setTimeout('processTypedText(\'tb\',\'searchfield\');',500);}} keyhandled=false;" type="text" />

		 //<ccAdvancedSelect>
		 //  <freetext>yes</freetext>
		 //  <select type='abcd' multiple='yes'>yes</select>
		 //  <field queryfield='titre'>Titres</field>
		 //  <values></values>
		 //</ccAdvancedSelect>
		 
		 //alert("1:"+getNodeValue(xmlDoc,"/ccAdvancedSelect/freetext"));
		 //alert("2:"+getNodeValue(xmlDoc,"/ccAdvancedSelect/select"));
		 //alert("3:"+getNodeAttribute(xmlDoc,"/ccAdvancedSelect/select","type"));
			 
		 //var nl2=findNodes(xmlDoc,"/ccAdvancedSelect/owner");
		 //alert (nl2[0].childNodes[0].nodeValue);
		 //alert (nl2[1].childNodes[0].nodeValue);

		 //alert("F0:"+findNodes(xmlDoc,"/ccAdvancedSelect/owner")[0].childNodes[0].nodeValue);
		 //alert("X:"+getNodeValue(xmlDoc,"/ccAdvancedSelect/owner"));
		 
		 //if(_ownerCombo.options[_ownerCombo.selectedIndex].value.substr(0,18)=='<ccAdvancedSelect>'){_ownerTextbox.style.display='none'; _advancedSelectBt.style.display='inline'; } else { _ownerTextbox.style.display='inline'; _advancedSelectBt.style.display='none';}

	}
  }

  function addComment(id,username,email,realname)
  {
    var commenthttpobject=GetHttpObject();
    if (commenthttpobject !=null)
    {
      //todo: add username
	  var params = 'username='+unescape(encodeURIComponent(username))+'&email='+unescape(encodeURIComponent(email))+'&realname='+unescape(encodeURIComponent(realname))+'&id='+unescape(encodeURIComponent(id))+'&comment='+unescape(encodeURIComponent(document.getElementById('comment').value));
	  commenthttpobject.open('POST','/ccscripts/addCommentToObject.php',false);
	  commenthttpobject.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	  commenthttpobject.setRequestHeader('Content-length', params.length);
	  commenthttpobject.setRequestHeader('Connection', 'close');
	  commenthttpobject.send(params);
	  alert(commenthttpobject.responseText);
      document.getElementById('comment').value="";
	  window.location.reload(true);
    }
	else
	{
	  alert('Could not send comment!');
	}
  }
 
