function clickIE() {
	if (document.all) {
		return false;
	}
}
function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) {
			return false;
		}
	}
}
if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS;
} else {
	document.onmouseup=clickNS;document.oncontextmenu=clickIE;
} 
document.oncontextmenu=new Function("return false");

var new_timer;
var time_value;
var time_total;
var last_question;
var timed;
FormSubmit = function(params) {
	var content_div = 'body';
	var url = unescape(location.href);
	var pars;
	if (typeof $$('FORM')[0] != "undefined") {
	 	pars = Form.serialize($$('FORM')[0]);
	}
	if (typeof pars == "undefined") {
		pars = params;
	} else {
		pars = pars + '&' + params;
	}
	var myAjax = new Ajax.Updater(content_div, url, {method: 'post', encoding: 'windows-1257', evalScripts: true, parameters: pars} );
	return true;
}
checkSession = function(params) {
	var content_div = 'checkSession';
	var url = unescape(location.href);
	var pars = 'action=eks&perform=checkSession';
	var myAjax = new Ajax.Updater(content_div, url, {method: 'post', encoding: 'windows-1257', evalScripts: true, parameters: pars} );
	return true;
}
PerformSubmit = function(pars, content_div) {
	if (typeof pars == "undefined") {
		pars = '';
	}
	if (typeof content_div == "undefined") {
		content_div = 'body';
	}
	var url = unescape(location.href);
	var myAjax = new Ajax.Updater(content_div, url, {method: 'post', encoding: 'windows-1257', evalScripts: true, parameters: pars} );
	return true;
}
getMenu = function() {
	var content_div = 'menu';
	var url = unescape(location.href);
	var pars = 'action=menu';
	var myAjax = new Ajax.Updater(content_div, url, {method: 'post', encoding: 'windows-1257', evalScripts: true, parameters: pars} );
	return true;
}
loadFunction = function (function_name) {
	var content_div = 'body';
	var url = unescape(location.href);
	var pars = 'action=' + function_name;
  	var myAjax = new Ajax.Updater(content_div, url, {method: 'post', encoding: 'windows-1257', evalScripts: true, parameters: pars} );
	return true;
}
loadQuestion = function(question_id) {
	last_question = question_id;
	if ($$('.current')[0] != null) {
		$$('.current')[0].removeClassName('current');
	}
	$('question_' + last_question).addClassName('current');
	var content_div = 'loadQuestion';
	var url = unescape(location.href);
	var pars = 'action=eksamens&perform=loadQuestion&question_id=' + question_id;
	if ($('question_' + last_question).next() != null) {
		pars = pars + '&next=1';
	}
	if ($('question_' + last_question).previous().id != "") {
		pars = pars + '&prev=1';
	}
	var myAjax = new Ajax.Updater(content_div, url, {method: 'post', encoding: 'windows-1257', evalScripts: true, parameters: pars} );
	return true;
}
HideShowTable = function (elem) {
	if (Element.hasClassName(elem,'minimize')) {
		elem.addClassName('maximize');
		elem.removeClassName('minimize');
		elem.up(1).next(0).hide();
	} else {
		elem.addClassName('minimize');
		elem.removeClassName('maximize');
		elem.up(1).next(0).show();
	}
}
changeTime = function() {
    if ($('time_e')) {
	    var width_r = $('time_r').offsetWidth;
	    time_value = time_value + width_r*3/time_total;
	    if (time_value > (width_r-2)) {
	    	time_value = width_r-2;
	    }
	    $('time_e').style.width = time_value + 'px';
		new_timer = setTimeout("changeTime()",3000);
	} else {
		clearTimeout(new_timer);
	}
}
Ajax.Responders.register({
	onCreate: function() {
		showTransparent();
	},
	onComplete: function() {
		if(Ajax.activeRequestCount == 0) {
			$('transparent').hide();
		}
		$j("a#largeImage").fancybox({ 'hideOnContentClick': true });
	}
});
showTransparent = function() {
	var d = document.documentElement;
	var w = window.innerWidth	|| self.innerWidth	|| (d && d.clientWidth)		|| document.body.clientWidth;
	var h = window.innerHeight	|| self.innerHeight	|| (d && d.clientHeight)	|| document.body.clientHeight;
	$('transparent').style.width = (w-50) + 'px';
	$('transparent').style.height = (h-50) + 'px';
	$('transparent').show();
}
raiseError = function(msg, err) {
	showTransparent();
	$('errorBox').show();
	var d = document.documentElement;
	var w = window.innerWidth	|| self.innerWidth	|| (d && d.clientWidth)		|| document.body.clientWidth;
	var h = window.innerHeight	|| self.innerHeight	|| (d && d.clientHeight)	|| document.body.clientHeight;
	//var ew = $('errorBox').offsetWidth;
	//var eh = $('errorBox').offsetHeight;
	var ew = 300;
	var eh = 120;
	var el = (w-ew)/2;
	var et = (h-eh)/2;
	$('errorBox').style.left = el + 'px';
	$('errorBox').style.top = et + 'px';
	$('errorBoxI').innerHTML = '<div class="error2">' + msg + '<br /><br />'+ err + '</div>'; 
}
closeError = function() {
	$('errorBox').hide();
}
checkImageSize = function(imageid) {
	imageobj =  $(imageid);
	ratio = imageobj.naturalWidth/imageobj.naturalHeight*3/4;
	if (ratio < 0) {
		imageobj.style.height = 200 + 'px';
		imageobj.style.width = 150 + 'px';
	}
}