// JavaScript Document
var i18n_msg = false;
var timeout_personal;
var personalmenu = true;
var hw_link_data = new Object;
var hw_image_data = new Object;
var hw_category_data = new Object;

function hw_show_personal(show, mode) {
	if (!personalmenu) return;
	if (show)
	{
		document.getElementById('p-personal-menu').style.display = 'block';
		if (mode=='init') timeout_personal = setTimeout('hw_show_personal(false)', 1000);
	}
	else
	{
		document.getElementById('p-personal-menu').style.display = 'none';
		clearTimeout(timeout_personal);
	}
}

var timeout_more;
var moremenu = true;
function ca_more_toggle(show, mode) {
	if (!moremenu) return;
	if (show)
	{
		morebox_style = document.getElementById('ca-more-box').style;
		morebox_style.display = 'block';
//		morebox_style.top=(mouse_y+10)+"px";
//		morebox_style.left=(mouse_x+15)+"px";

		if (mode=='init') timeout_more = setTimeout('ca_more_toggle(false)', 1000);
		else if (timeout_more) clearTimeout(timeout_more);
	}
	else
	{
		document.getElementById('ca-more-box').style.display = 'none';
		if (timeout_more) clearTimeout(timeout_more);
	}
}

function check_pagename(pagename)
{
	forbidden = new Array('[', ']', '{', '}', '&', '?', '<', '>', '\\', ',');
	valid = true;
	if (pagename=="") return false;
	for (i=0; i<forbidden.length; i++)
		if (pagename.indexOf(forbidden[i])!=-1)
		{
			valid=false;
			// TODO: i18n
			hw_alert(["ERR","Sie haben ein nicht erlaubtes Zeichen verwendet"]);
//			hw_alert(i18n_msg[0]["hw_charnotallowed_pre"]+forbidden[i]+i18n_msg[0]["hw_charnotallowed_post"], 'ok');
			return false;
		}
	return true;
}

var mouse_x=0;
var mouse_y=0;

if (navigator.appName == "Netscape")
{
	document.captureEvents(Event.MOUSEMOVE);
}

document.onmousemove = mousexy;

function mousexy(e) {
	if (navigator.appName == "Netscape")
	{
		mouse_x = e.pageX;
		mouse_y = e.pageY;
	}
	else
	{
		var obj = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?
         				window.document.documentElement : window.document.body || null;

		mouse_x = window.event.clientX + obj.scrollLeft;
		mouse_y = window.event.clientY + obj.scrollTop;
	}
}

var page_height = false;
var page_width = false;

function get_page_size()
{
	if (window.innerHeight && window.scrollMaxY)
	{
		page_width = document.body.scrollWidth;
		page_height = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)  // all but Explorer Mac
	{
		page_width = document.body.scrollWidth;
		page_height = document.body.scrollHeight;
	} else if (	document.documentElement &&
				document.documentElement.scrollHeight > document.documentElement.offsetHeight) // Explorer 6 strict mode
	{
		page_width = document.documentElement.scrollWidth;
		page_height = document.documentElement.scrollHeight;
	}
	else // Explorer Mac...would also work in Mozilla and Safari
	{
		page_width = document.body.offsetWidth;
		page_height = document.body.offsetHeight;
	}
}

var LoadOnDemand = function() {}
LoadOnDemand.prototype = {
	callback : false,
	errcount : 0,

	load : function(module, callback, i18n) {
		if(this.modules[module] == 'loaded') {
			window[callback]();
			return;
		}
		if(this.callback) {
			alert("Just one module can load at the same time.\nPlease wait a few seconds.");
			return;
		}
		this.callback = callback;
		if(i18n) {
			this.getFile(wgScriptPath+'/hallowelt/'+module+'/i18n/'+module+'.i18n.'+wgContentLanguage+'.js');
		}
		for(i in this.modules[module]) {
			if(typeof(this.modules[module][i]) == 'function')
				continue;
			this.getFileWithCallback(this.modules[module][i]);
		}
		this.modules[module] = 'loaded';
	},

	getFile : function(path) {
		Ext.Ajax.request({
			url: path,
			success: function(r) {
				eval(r.responseText);
			}
		});
	},

	getFileWithCallback : function(path) {
		Ext.Ajax.request({
			url: path,
			success: function(r) {
				eval(r.responseText);
				lod.doCallback();
			}
		});
	},

	doCallback : function() {
		try {
			callback = this.callback;
			window[callback]();
		}
		catch(e) {
			if(this.errcount == 1000) {
				alert("An error occurred by loading "+this.callback+"().\nAction aborted!");
				this.callback = false;
				this.errcount = 0;
			}
			else {
				this.errcount++;
				window.setTimeout("lod.doCallback()", 10);
			}
			return;
		}
		this.callback = false;
	}
}

var lod = new LoadOnDemand();


var i18nMngr = function() {}
i18nMngr.prototype = {
	load: function(module) {
		hw_load_js(wgScriptPath+'/hallowelt/'+module+'/i18n/'+module+'.i18n.'+wgContentLanguage+'.js');
	}
};

var i18n = new i18nMngr();
