function urlDecodeArray(arr) {//{{{
  var ret = [];
  var i=0;
  for(i=0; i<arr.length; i++) {
    if(arr[i] instanceof Array)
      ret.push(urlDecodeArray(arr[i]));
    else
      ret.push(decodeURIComponent(arr[i]));
  }
  return ret;
}//}}}
$(document).ready(function() {
  $('img.button').hover(
    function(e){e.target.src=e.target.src.replace('1.gif','2.gif');},
    function(e){e.target.src=e.target.src.replace('2.gif','1.gif');}
  );
});
$(document).ready(function() {
  $('div.search select').change(
    function(e){
      var v = $(e.target).children().eq(e.target.selectedIndex).val();
      var extra = e.target.className + "=" + encodeURIComponent(v);
      //alert(v);
      var str = new String(window.location);
      str = jshomeurl+'/aanbod/';
      if(str.indexOf('?')==-1) {
	window.location = str + "?" + extra;
      }
      else {
	if(str.indexOf(e.target.className+"=") == -1) {
	  window.location = str + "&" + extra;
	}
	else {
	  var re = new RegExp(e.target.className+'=[^&?]*');
	  str = str.replace(re,extra);
	  window.location = str;
	}
      }
    }
  );
});

// Form functions
$(document).ready(function() {
    // Zoekformuliertje clearen
    $('input.zoeken').focus(function(e){
      e.target.value='';
    });
    // Forumulier versturen
    $('a.formsubmit').click( function(e) {
      e.preventDefault();
      var currroot = $(e.target).parents('table.form');
      var inputs = currroot.find('input');
      var areas = currroot.find('textarea');

      var str = "?";
      inputs.each(function(index,value) {
	str += value.name;
	str += "=";
	str += encodeURIComponent(value.value);
	str += "&";
      });
      areas.each(function(index,value) {
	str += value.name;
	str += "=";
	str += encodeURIComponent(value.value);
	str += "&";
      });
      str = str.substr(0,str.length-1);
      window.location= new String(window.location) + str;
    });
});

