var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;

var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = getMouseXY;

var tempX = 100;
var tempY = 1000;

function go_to_searchresults( searchphrase ) {
	window.location.href='/q/'+escape(val('q'))+'.html';
}

function getObj(name) {
  if (document.getElementById) {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all) {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers) {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

var largepreview = document.getElementById('large_preview');

largepreview.xpos = tempX;
largepreview.ypos = tempY;
try {
	largepreview.style.left = largepreview.xpos;
	largepreview.style.top = largepreview.ypos;
}
catch (ex) {}

function showInfo(name,description){
	var content = '<table style="width:350px;border:2px black solid;background-color:#ffffff"><tr><td style="font-size:10pt;"><b>'+name+'</b></td></tr><tr><td style="font-size:10pt;">'+description+'</td></tr></table>';
	showFloatingBlockNice( content );
}

function showImage(image){
	image = image.replace(' ','%20');
	var content = '<img src="'+image+'" style="border:2px black solid"/>';
	showFloatingBlock( content );
}	

function showFloatingBlockNice(content){
	if (ns4) { largepreview.document.write(content); largepreview.document.close(); }
	if (ns6) { largepreview.innerHTML = content; }
	if (ie4) { document.all("large_preview").innerHTML = content; }
	largepreview.xpos = parseInt(tempX - 175);
	largepreview.ypos = parseInt(tempY + 30);
	try {
		largepreview.style.left = largepreview.xpos + 'px';
		largepreview.style.top = largepreview.ypos + 'px';
	}
	catch (ex) {}
	largepreview.style.display = 'block';
}

function showFloatingBlock(content){
	if (ns4) { largepreview.document.write(content); largepreview.document.close(); }
	if (ns6) { largepreview.innerHTML = content; }
	if (ie4) { document.all("large_preview").innerHTML = content; }
	largepreview.xpos = parseInt(tempX + 10);
	largepreview.ypos = parseInt(tempY - 25);
	try {
		largepreview.style.left = largepreview.xpos + 'px';
		largepreview.style.top = largepreview.ypos + 'px';
	}
	catch (ex) {}
	largepreview.style.display = 'block';
}

function hideFloatingBlock(){
	if (ns4)
		largepreview.style.visibility = 'hidden';
	else if (ns6||ie4)
		largepreview.style.display = 'none';
}

function getMouseXY(e) {
	try {
		tempX = event.clientX;
		tempY = event.clientY;
	} 
	catch(ex) {
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0) tempX = 0;
	if (tempY < 0) tempY = 0;  
	
	if (!ns6) {
		if( typeof( window.pageYOffset ) == 'number' ) {
		    //Netscape compliant
		    tempY += window.pageYOffset;
		    tempX += window.pageXOffset;
		} 
		else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		    //DOM compliant
		    tempY += document.body.scrollTop;
		    tempX += document.body.scrollLeft;
		} 
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		    //IE6 standards compliant mode
		    tempY += document.documentElement.scrollTop;
		    tempX += document.documentElement.scrollLeft;
		}
		if (tempX < 0) tempX = 0;
		if (tempY < 0) tempY = 0;  
	}
}

function findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function validateForm() { //v4.0
	  var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
	  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=findObj(args[i]);
	    if (val) { nm=val.name; if ((val=val.value)!="") {
	      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
	        if (p<1 || p==(val.length-1)) errors+='- '+nm+' moet een geldig e-mail address bevatten.\n';
	      } else if (test!='R') { num = parseFloat(val);
	        if (isNaN(val)) errors+='- '+nm+' moet een nummer bevatten.\n';
	        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
	          min=test.substring(8,p); max=test.substring(p+1);
	          if (num<min || max<num) errors+='- '+nm+' moet een nummer tussen '+min+' en '+max+' bevatten.\n';
	    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
	  } if (errors) alert('De volgende fouten zijn opgetreden:\n'+errors);
	  document.returnValue = (errors == '');
	}
	
function ShowHide(elem) {
	var x = document.getElementById(elem).style;
	x.display = (x.display == 'block') ? 'none' : 'block';
}

function bookmarksite(title, url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if(window.opera && window.print) {
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) {
		window.external.AddFavorite(url, title);
	}
}



function base64_encode( input ) {

	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
	var i = 0;

	input = Base64._utf8_encode(input);

	while (i < input.length) {

		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);

	}

	return output;
}


function base64_decode( input ) {

	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	while (i < input.length) {
		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);
		}
	}
	return utf8_decode(output);
}

function utf8_encode( string ) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return utftext;
}

function utf8_decode( utftext ) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;

	while ( i < utftext.length ) {
		c = utftext.charCodeAt(i);
		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		}
		else if((c > 191) && (c < 224)) {
			c2 = utftext.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		}
		else {
			c2 = utftext.charCodeAt(i+1);
			c3 = utftext.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}
	return string;
}
 


function val(i) {
	return document.getElementById(i).value;
}


function newWindow(mypage,myname,w,h,features) {
	  if(screen.width){
	  var winl = (screen.width-w)/2;
	  var wint = (screen.height-h)/2;
	  }else{winl = 0;wint =0;}
	  if (winl < 0) winl = 0;
	  if (wint < 0) wint = 0;
	  var settings = 'height=' + h + ',';
	  settings += 'width=' + w + ',';
	  settings += 'top=' + wint + ',';
	  settings += 'left=' + winl + ',';
	  settings += features;
	  win = window.open(mypage,myname,settings);
	  win.window.focus();
} 


/* EMAIL VALIDATION SCRIPT */
		
function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
	     even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    //alert("The username doesn't seem to be valid.")
	    return false
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        //alert("Destination IP address is invalid!")
			return false
		    }
	    }
	    return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
	    return false
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   //alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   //alert(errStr)
	   return false
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}
