function URLEncode( input )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = input;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for	
	return encoded;
};

function filtery(pattern,list){
	pattern = new RegExp('^'+pattern,"i"); 
	i=0;
	sel=0;
	while(i<list.options.length){
		if(pattern.test(list.options[i].text)){sel=i;break}
		i++;
	}
	list.options.selectedIndex=sel;
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

	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;
}

/* returns the size of your framewindow */
function frame_size(){
	var frameWidth, frameHeight,frameArray = Array();
	if (self.innerWidth)
	 {
	  	frameWidth 	= self.innerWidth;
	  	frameHeight = self.innerHeight;		
	 }	 	 
	 else if (document.documentElement && document.documentElement.clientWidth)
	 {
	  frameWidth 	= document.documentElement.clientWidth;
	  frameHeight 	= document.documentElement.clientHeight;
	 }
	 else if (document.body)
	 {
	  frameWidth 	= document.body.clientWidth;
	  frameHeight	= document.body.clientHeight;	  
	 }	 
	 else {
		alert('Kon de schermresolutie niet bepalen!'); 
	 }	
	 frameArray[0] = frameWidth;
	 frameArray[1] = frameHeight;
	 return frameArray;
}

function menu(nr) {
	var links = new Array();
	links[1] = '<ul><li><a href="index.php">Home</a></li><li><a href="nieuws.php">Nieuws</a></li>					<li><a href="offerteaanvragen.php">Offerte aanvragen</a></li> <li><a href="proefritdag.php">Proefritdag</a></li>		<li><a href="proefrit.php">Proefrit aanvragen</a></li>		<li><a href="infoaanvraag.php">Informatie Aanvragen</a></li></ul>';
	links[2] = '';
	links[3] = '<ul><li><a href="motors.php?dtm=5&amp;dg=1&amp;mode=1">BMW Huisselectie</a></li>	<li><a href="motors.php?dtm=5&amp;mode=2">BMW Occasions</a></li>			<li><a href="motors.php?mode=3&etm=5">Andere Merken</a></li>	<li><a href="demo_motoren.php">Demo Motoren</a></li></ul>';
	links[4] = '<ul><li><a href="parts.php?mode=1&amp;dtm=1&amp;new=1&amp;type=2">Accessoires</a></li>	<li><a href="parts.php?mode=2&amp;new=0&amp;type=1&amp;dtm=1">Onderdelen</a></li>		<!-- <li><a href="parts.php?mode=3&amp;new=0&amp;type=2">Gebruikte Accessoires</a></li> -->	<li><a href="kleding.php">Kleding</a></li>			<li><a href="corbin.php">Corbin</a></li>			<li><a href="aanbiedingen.php">Aanbiedingen</a></li></ul>';
	links[5] = '<ul><li><a href="service.php">Onderhoud</a></li><li><a href="verhuur.php">Verhuur</a></li><li><a href="bedrijfsprofiel.php">Bedrijfsprofiel</a></li>	<li><a href="historie.php">Historie</a></li>			<li><a href="medewerkers.php">Medewerkers</a></li>			<li><a href="contact.php">Contact Opnemen</a></li></ul>';

	document.getElementById('topmenu-onder').innerHTML = links[nr];
}
	
	
