
	var gR = [];
	function getRandom(max){
		var rand = Math.ceil(max*Math.random());
		if (gR.indexOf(rand) > -1) return getRandom(max);
		gR.push(rand);
		return rand; 
	}
	
	checkContactForm = function(){
		var ok = true;
		$('contactFormErrors').update('');
		if ($('contactName').getValue() == ''){
			$('contactFormErrors').insert("Naam is verplicht<br/>");
			ok = false;
		}
		if ($('contactAdres').getValue() == ''){
			$('contactFormErrors').insert("Email is verplicht<br/>");
			ok = false;
		}else{
			if (!is_email($('contactAdres').getValue())){
				$('contactFormErrors').insert("Ongeldig e-mail-adres.<br/>");
				ok = false;
			}
		}
		if (ok) $('contactForm').submit();
	}
	
	is_email = function(emailStr) {
		var checkTLD=1;
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray=emailStr.match(emailPat);

		if (matchArray==null) {
			return false;
		}

		var user=matchArray[1];
		var domain=matchArray[2];

		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				return false;
			}
		}

		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				return false;
			}
		}
		
		if (user.match(userPat)==null) {
			return false;
		}

		var IPArray=domain.match(ipDomainPat);
		
		if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					return false;
		   		}
			}
			return true;
		}
		
		 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;

		for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
				return false;
		   }
		}

		if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
			return false;
		}

		if (len<2) {
			return false;
		}
		
		return true;
	}	
	
	assignTooltip = function(elem){
		var img = elem.getAttribute('imgID');
		if (!img || !$(img)) return;
		$(img).setAttribute('title', elem.getAttribute('title'));
		$j('#'+img).mbTooltip({ 
	      wait:100,
	      cssClass:"default", 
	      timePerWord:0,  
	      hasArrow:false,
	      hasShadow:true,
	      imgPath:"/images/",
	      ancor:"mouse",
	      shadowColor:"black", 
	      mb_fade:100
	    });		
	}
	
	
   function maxWindow() {
        window.moveTo(0, 0);


        if (document.all) {
            top.window.resizeTo(screen.availWidth, screen.availHeight);
        }

        else if (document.layers || document.getElementById) {
            if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
                top.window.outerHeight = screen.availHeight;
                top.window.outerWidth = screen.availWidth;
            }
        }
    }
	
	function reportConfession(id){
		var ok = true;
		var email = $(id+'_reportImage_email').getValue().toString().replace(' ' , '');
		var reason = $(id + '_reportImage_reason').getValue();
		
		if (email == '' || (!is_email(email)) ){
			ok = false;
			$(id+ '_emailError').show();
		}else{
			$(id+ '_emailError').hide();
		}

		if (reason == ''  ){
			ok = false;
			$(id+ '_reasonError').show();
		}else{
			$(id+ '_reasonError').hide();
		}
		if (ok){
			var wpsRPC = new wps.rpc;
			wpsRPC.createCall('confessions', function(){alert('Je melding is doorgegeven aan de redactie')});
			wpsRPC.call('reportPost', "id="+id, "email="+email, "reason="+escape(reason));
		}
	}
	
	function reportImage(id){
		var ok = true;
		var email = $(id+'_reportImage_email').getValue().toString().replace(' ' , '');
		var reason = $(id + '_reportImage_reason').getValue();
		
		if (email == '' || (!is_email(email)) ){
			ok = false;
			$(id+ '_emailError').show();
		}else{
			$(id+ '_emailError').hide();
		}

		if (reason == ''  ){
			ok = false;
			$(id+ '_reasonError').show();
		}else{
			$(id+ '_reasonError').hide();
		}
		if (ok){
			var wpsRPC = new wps.rpc;
			wpsRPC.createCall('gallery_upload', function(){alert('Je melding is doorgegeven aan de redactie')});
			wpsRPC.call('reportPost', "id="+id, "email="+email, "reason="+escape(reason));
		}
	}
	
	requestConfession = function(){
		if ($('confession').getValue().replace(' ', '') != ''){
			var wpsRPC = new wps.rpc;
			wpsRPC.createCall('confessions', setSerial);
			wpsRPC.call('requestSerial');
		}else{
			alert("Je hebt geen confession ingevuld");
		}
	}
	
	setSerial = function(req){
		var serial = req.responseJSON.serial;
		var name = $('confession_name').getValue();
		var confession = encodeURIComponent($('confession').getValue());
		var wpsRPC = new wps.rpc;
		wpsRPC.createCall('confessions', function(){
			window.location.reload();
		});
		wpsRPC.call('store', "serial="+serial, "name="+name, "confession="+confession);
	}
	
	resizeColumn = function(){
		
		
	}
