//*** Allgemeine Scripte

var dhtmlObj, dhtmlIn, dhtmlOut, dhtmlStyle;
var phpsid, objBug, objHelp, objAges, objIsland, objMyrinahn, objChat, objNjal;

function getObj(){
	if (document.layers){
		dhtmlObj = "document.layers";
		dhtmlIn = "[";
		dhtmlOut = "]";
		dhtmlStyle = "";
	}
	if (document.all){
		dhtmlObj = "document.all";
		dhtmlIn = "[";
		dhtmlOut = "]";
		dhtmlStyle = ".style";
	}
	if (document.getElementById){
		dhtmlObj = "document.getElementById";
		dhtmlIn = "(";
		dhtmlOut = ")";
		dhtmlStyle = ".style";
	}

}

function init(sid, setfocus) {
	phpsid = sid;
	getObj();
	if (setfocus == '1') {
		focus();
	}
}

function rollOver() {
	if (document.images) {
		obj = document.images[arguments[0]];
		type = obj.src.substring(obj.src.lastIndexOf('.'));
		obj.src = obj.src.substring(0, obj.src.length-type.length) + "_hi" + type;
	}
}

function rollOut() {
	if (document.images) {
		obj = document.images[arguments[0]];
		type = obj.src.substring(obj.src.lastIndexOf('.'));
		obj.src = obj.src.substring(0, obj.src.length-type.length-3) + type;
	}
}

function thisStyleObj(name) {
	return eval(dhtmlObj + dhtmlIn + '"' + name + '"' + dhtmlOut + dhtmlStyle);
}


//*** Allgemeine Fensterscripte

function closeBug() {
	//schliesst das Bugreportfenster
	objBug = (objBug)?objBug:eval('window.bug' + phpsid);
	closeObject(parent.objBug);
}

function closeHelp() {
	//schliesst das Hilfefenster
	objHelp = (objHelp)?objHelp:eval('window.help' + phpsid);
	closeObject(parent.objHelp);
}

function closeObject(obj) {
	if (document.layers && obj) {
		if (!obj.closed) {
			obj.close();
		}
	} else {
		if (obj) {
			obj.close();
		}
	}
}

function focusObject(obj) {
	if (document.layers && obj) {
		if (!obj.closed) {
			obj.focus();
		}
	} else {
		if (obj) {
			obj.focus();
		}
	}
}

function openBug() {
	//oeffnet das Bugreportfenster
	objBug = eval('window.bug' + phpsid);
	parent.objBug = parent.window.open('/bug.php', 'bug' + phpsid, 'scrollbars=no,width=700,height=550');
}

function openHelp(theHelp) {
	//oeffnet das Hilfefenster
	objHelp = eval('window.help' + phpsid);
	parent.objHelp = parent.window.open('/fs_help.php?help=' + theHelp, 'help' + phpsid, 'scrollbars=no,width=210,height=300');
}

function openAgeAdvent() {
	//oeffnet den Adventskalender im Hauptfenster
	closeHelp();
	parent.window.opener.location.href = '/special/advent/';
}

function openAgeDuesseldorf() {
	//oeffnet das Zeitalter Duesseldorf im Hauptfenster
	closeHelp();
	parent.window.opener.location.href = '/duesseldorf/';
}

function openAgeLooriva() {
	//oeffnet das Zeitalter Looriva im Hauptfenster
	closeHelp();
	parent.window.opener.location.href = '/map.php';
}

function openAgeMyrinahn() {
	//oeffnet das Zeitalter Myrinahn im Hauptfenster
	closeHelp();
	parent.window.opener.location.href = '/myrinahn/';
}

function openNewYear() {
	//oeffnet die Neujahrskarte im Hauptfenster
	closeHelp();
	parent.window.opener.location.href = '/special/newyear/';
}

function openAgeNjal() {
	//oeffnet das Zeitalter N'jal im Hauptfenster
	closeHelp();
	parent.window.opener.location.href = '/njal/';
}

function reloadMenu(sid, act) {
	//laedt das Menu neu
	if (act == '1' && parent.window.opener.frames['menu']) {
		parent.window.opener.frames['menu'].location.reload();
	}
	init(sid, '1');
}


//*** Fensterscripte Hauptseite

function onloadLooriva(sid, theURL, features) {
	init(sid);
	openAges(theURL, features)
}

function openAges(theURL, features) {
	//oeffnet das Infofenster ueber die Zeitalter
	objAges = eval('window.ages' + phpsid);
	parent.objAges = parent.window.open(theURL, 'ages' + phpsid, features);
}

function openIsland(theURL) {
	//oeffnet ein Insel-Popup
	closeHelp();
	objIsland = eval('window.island' + phpsid);
	parent.objIsland = parent.window.open(theURL, 'island' + phpsid, 'scrollbars=no,width=700,height=550');
}

function leaveIntro() {
	//Verlassen der Introseiten
	closeHelp();
	closeBug();
}

function leaveLooriva() {
	//Verlassen der Hauptseite
	objAges = (objAges)?objAges:eval('window.ages' + phpsid);
	objIsland = (objIsland)?objIsland:eval('window.island' + phpsid);
	closeObject(parent.objAges);
	closeObject(parent.objIsland);
	closeHelp();
	closeBug();
}


//*** Fensterscripte Myrinahn

function leaveMyrinahn() {
	//Verlassen von Myrinahn
	objMyrinahn = (objMyrinahn)?objMyrinahn:eval('window.myrinahn' + phpsid);
	closeObject(parent.objMyrinahn);
	closeHelp();
	closeBug();
}

function menuMyrinahn(sid) {
	//fokussiert die Hauptfenster (Applet)
	init(sid, '0');
	objMyrinahn = (objMyrinahn)?objMyrinahn:eval('window.myrinahn' + phpsid);
	focusObject(parent.objMyrinahn);
}

function openForum(board, thread, sid) {
	//oeffnet das Forum (Maillink)
	init(sid, '0');
	openMyrinahn('fs_thread.php?board=' + board + '&thread=' + thread);
}

function openMyrinahn(theURL) {
	//oeffnet ein Myrinahn-Popup
	closeHelp();
	objMyrinahn = eval('window.myrinahn' + phpsid);
	parent.objMyrinahn = parent.window.open(theURL, 'myrinahn' + phpsid, 'scrollbars=no,resizable=yes,width=700,height=550');
}

function openMyrinahnActivation(user, key, sid) {
	//oeffnet die Aktivierung (Maillink)
	init(sid, '0');
	openMyrinahn('activate_user.php?user=' + user + '&key=' + key);
}


//*** Fensterscripte N'Jal

function closeNjal() {
	//schliesst den Chat und das Hilfefenster
	objChat = (objChat)?objChat:eval('parent.window.opener.chat' + phpsid);
	closeObject(parent.window.opener.objChat);
	closeHelp();
}

function leaveNjal() {
	//Verlassen von N'jal
	objChat = (objChat)?objChat:eval('window.chat' + phpsid);
	objNjal = (objNjal)?objNjal:eval('window.njal' + phpsid);
	closeObject(parent.objChat);
	closeObject(parent.objNjal);
	closeHelp();
	closeBug();
}

function menuNjal(sid) {
	//fokussiert die Hauptfenster (Applet)
	init(sid, '0');
	objChat = (objChat)?objChat:eval('window.chat' + phpsid);
	objNjal = (objNjal)?objNjal:eval('window.njal' + phpsid);
	focusObject(parent.objChat);
	focusObject(parent.objNjal);
}

function openNjal(theURL) {
	//oeffnet ein N'jal-Popup
	closeHelp();
	if (theURL.substring(0, theURL.lastIndexOf('.')) == 'fs_chat') {
		objChat = eval('window.chat' + phpsid);
		parent.objChat = parent.window.open(theURL, 'chat' + phpsid, 'scrollbars=no,resizable=yes,width=700,height=550');
	} else {
		objNjal = eval('window.njal' + phpsid);
		parent.objNjal = parent.window.open(theURL, 'njal' + phpsid, 'scrollbars=no,resizable=yes,width=700,height=550');
	}
}

function openNjalActivation(user, key, sid) {
	//oeffnet die Aktivierung (Maillink)
	init(sid, '0');
	openNjal('activate_user.php?user=' + user + '&key=' + key);
}

function openPm(pm, sid) {
	//oeffnet die PM (Maillink)
	init(sid, '0');
	openNjal('fs_pm.php?pm=' + pm);
}

function openReply(pm, sid) {
	//oeffnet das Antwortfenster (Maillink)
	init(sid, '0');
	openNjal('fs_reply_pm.php?pm=' + pm);
}


//*** Smilies

function addCode(form, field, code) {
	//fuegt einen Smilie zum Text zu
	document.forms[form][field].value = document.forms[form][field].value + code;
}

function addSmilie(form, field, code) {
	//fuegt einen Smilie zum Text zu
	addCode(form, field, code);
}

function chooseSmilie(form, field, code, file) {
	//waehlt einen Smilies aus
	if(document.images){
		obj = document.images['smilie'];
		obj.src = '/pics/smilies/' + file;
	}
	document.forms[form][field].value = code;
}

