﻿Shadowbox.init({
    players: ["inline", "html", "iframe"]
});

        $(document).ready(function() {
$('#q').keypress(function (e) {  
         if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
             /*alert("enter");*/
             open_sbox(); 
             return false;  
         } else {  
             return true;  
        }  
     });  
});

function open_sbox()
{
    if(URLEncode(document.getElementById('q').value) == '')
    {
	Shadowbox.open({
	    content: "<div class='searchError'>Gelieve een zoekopdracht in te vullen. Probeer daarna opnieuw.</div>",
	    player: 'html',
		height: 82,
		width: 300,
		title: 'Fout bij zoekopdracht'
	});
	document.getElementById('q').blur();
    }
    else{
	Shadowbox.open({
		player: 'iframe',
		content: 'SearchResults.aspx?cx=000056366657954927933%3Ay7xposh2cuw&cof=FORID%3A11&ie=UTF-8&q=' + 
URLEncode(document.getElementById('q').value) + '&sa=Search',
		height: 700,
		width: 660,
		title: 'Howest Zoekresultaten'
	});
	document.getElementById('q').blur();
	}

}

// Function retrieved from: http://cass- hacks.com/articles/code/js_url_encode_decode/
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}