function urlencode (str) {
    // URL-encodes string  
    // 
    // version: 910.813
    // discuss at: http://phpjs.org/functions/urlencode
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // %          note 1: This reflects PHP 5.3/6.0+ behavior
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
    var hexStr = function (dec) {
        return '%' + (dec < 16 ? '0' : '') + dec.toString(16).toUpperCase();
    };

    var ret = '',
            unreserved = /[\w.\-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();

    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters); https://developer.mozilla.org/index.php?title=en/Core_JavaScript_1.5_Reference/Global_Objects/String/charCodeAt
                ret += ((code - 0xD800) * 0x400) + (str.charCodeAt(i+1) - 0xDC00) + 0x10000;
                i++; // skip the next one as we just retrieved it as a low surrogate
            }
            // We never come across a low surrogate because we skip them, unless invalid
            // Reserved assumed to be in UTF-8, as in PHP
            else if (code === 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048) { // 3 bytes (code < 65536)
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}

function loopSelected(id)
{
  var qryStr = "";
  var selectedStr = "";
  var thisid = "location"+id;
  var selObj = document.getElementById(thisid);
  var i;
	if (selObj !== null) {
		for (i=0; i<selObj.options.length; i++) {
			if (selObj.options[i].selected) {
				if (selectedStr==="") {
					selectedStr = selObj.options[i].value;
				} else {
					selectedStr = selectedStr+"-"+selObj.options[i].value;
				}
			}
		}
		qryStr = id+"="+selectedStr;
	}
	return qryStr;
  }

function loopAll() {
  var j;
  var totalStr = "";
  var location = "";
  var arr = [96,97,98,102,104,106,107,109];
  for (j in arr) {
	if (totalStr==="") {
		totalStr = loopSelected(arr[j]);
	} else {
		totalStr = totalStr+"&"+loopSelected(arr[j]);
	}
  }
  
  location = "action=search&submitted=1&order_by=&ord=&2="+urlencode(document.getElementById('functie').value)+"&15="+urlencode(document.getElementById('plaats').value)+"&"+totalStr;
 
  if (document.getElementById('user_id').value !== "") {
	location = location+"&user_id="+document.getElementById('user_id').value;
  } else if (document.getElementById('bedrijf').value !== "") {
	location = location+"&user_id="+document.getElementById('bedrijf').value;
  }

  window.location.href="/index.php?"+location;

}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		loopAll(); //submit the form
		return false;
	} else {
		return true;
	}
}

// MILLIAN
function loopSelectedMillian(str)
{
  var qryStr = "";
  var selectedStr = "";
  var selObj = document.getElementById(str);
  var i;
	if (selObj !== null) {
		for (i=0; i<selObj.options.length; i++) {
			if (selObj.options[i].selected) {
				if (selectedStr==="") {
					selectedStr = selObj.options[i].value;
				} else {
					selectedStr = selectedStr+"-"+selObj.options[i].value;
				}
			}
		}
		qryStr = str+"="+selectedStr;
	}
	return qryStr;
  }
  
function loopMillian() {
  var j;
  var totalStr = "";
  var location = "";
  var arr = ["handboek","vakgebied","provincie","opleidingsniveau"];
  for (j in arr) {
	if (totalStr==="") {
		totalStr = loopSelectedMillian(arr[j]);
	} else {
		totalStr = totalStr+"&"+loopSelectedMillian(arr[j]);
	}
  }
  if (document.getElementById('trefwoord').value !== "") {
	totalStr = totalStr+"&trefwoord="+urlencode(document.getElementById('trefwoord').value);
  }
  location = "/uitgebreidzoeken_millian.php?action=search&"+totalStr;
  window.location.href=location;
}

function checkEnterMillian(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		loopMillian(); //submit the form
		return false;
	} else {
		return true;
	}
}

// MILLIAN
