//==================================tools================================================
function toggle(Divid) {
 if( document.getElementById(Divid).style.display=='none' ){
   document.getElementById(Divid).style.display = '';
 }else{
   document.getElementById(Divid).style.display = 'none';
 }
}

function toggleSBSize(big) {
    var sb = document.getElementById('qstring');
    if (big)
        sb.style.width = '250px';
    else
        sb.style.width = '150px';
}

function set_input(query,id) {
	document.getElementById(id).value = query;
	handleSuggestSelect(query,id);
}

function setStyle(obj,style,value){
	if(getRef(obj)){	
	getRef(obj).style[style]= value;
	} else {
		return false;
	}
}
	
	function getRef(obj){
		return (typeof obj == "string") ?
			 document.getElementById(obj) : obj;
	}
	
	
function spring(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function loaderbar_aan(tijd) {
	setStyleBar('loaderbar','visibility','visible');
	window.setTimeout("setStyleBar('loaderbar','visibility','hidden')", tijd);
	return true;
}

	function setStyleBar(obj,style,value){
		
		getRefBar(obj).style[style]= value;
	};
	
	function getRefBar(obj){
		return (typeof obj == "string") ?
			 document.getElementById(obj) : obj;
	};

// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

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);
   } 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 =
   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);
      }
   } while (i < input.length);

   return output;
}

function clearFocus() {//free focus en stop aanroepen postXX_form
	GL.focus='';
}

function elemformFocus(id) {//element wat na reloaden de focus krijgt
	GL.focus = id;

}
function setFocus() {

if(document.getElementById(GL.focus))
{
document.getElementById(GL.focus).focus();
}
}
function pageScroll(hor,vert) {
    	window.scrollBy(hor,vert); // horizontal and vertical scroll increments
    	//scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
}
//crumb=================================================================================
function setCrumb(input)//opbouw links
{
str_crumbTxt='';
var content='<img src="img/home.jpg"/><img src="img/green_arrow.jpg"/>';
var arr_input = new Array();

arr_input = input.split(",");
var lengte = parseInt(arr_input.length);
var t = 0;
while(t<lengte-1)
	{
	if(arr_crumbTxt[arr_input[t]])
	{
	str_crumbTxt=arr_crumbTxt[arr_input[t]];
	}
	else
	{
	str_crumbTxt=arr_input[t]
	}
	content += '<a href="?page='+arr_input[t] +'">'+str_crumbTxt +'</a><img src="img/green_arrow.jpg"/>';
	t++;
	}
content += arr_input[t];
document.getElementById('crumb_set_marge').innerHTML=content;
}

function setResult(id,content) {
var elm=document.getElementById(id);
if(elm)
{
	elm.innerHTML=content;
}

}


function clearCheck(){
	//clear alle checkboxes
	var el=document.getElementById('cnt_soort');
	var checkboxen = el.getElementsByTagName("input");
	var aantal_checkboxen = checkboxen.length;
	for(var index = 0; index < aantal_checkboxen; index++) {
		if (checkboxen[index].type=="checkbox") {
			checkboxen[index].checked = false;
		}
	}
	
	return clearSoort();
	
}
function handleWis(box){
	//acties als er geen checkbox in cnt_soort meer is aangevinkt
	var el=document.getElementById('cnt_soort');
	var isEmpty=true;
	var checkboxen = el.getElementsByTagName("input");
	var aantal_checkboxen = checkboxen.length;
	for(var index = 0; index < aantal_checkboxen; index++) {
		if (checkboxen[index].type=="checkbox") {
			checkboxen[index].checked == true?isEmpty=false:void(0);
		}
	}
	if(isEmpty){
		//acties
	}
	return isEmpty;
	
}

function IntOnly(myfield, e, dec)
{
var key;
var keychar;
 
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
 
// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;
 
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;
 
 
else
   return false;
}


function getAantal(el,zoekwoorden,source){
	
	if(el.value<999){
		postQuery('/elements/ajax/ajax_resultaat.php','&q='+zoekwoorden,"cnt_result","aantal",el.value,source);
	} else {
		el.value='';
		el.focus();
				
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function getLocationHash(){
    alert(window.location.hash);
}
function addElement(myDiv,name,size) {
  var ni = document.getElementById(myDiv);
  var newdiv = document.createElement('input');
  newdiv.setAttribute('name',name);
  newdiv.setAttribute('size',size); 
  ni.appendChild(newdiv); 
  var newbr = document.createElement("<br>")
  ni.appendChild(newbr);
}

function openWindow(url){
	
	window.open ("http://www.boerderijkamers.nl/"+url,"Locatie","scrollbars=1,width=1000,height=800"); 
}