
	// CVS: $Id: core.js,v 1.1.1.1 2006/02/20 21:52:21 xiam Exp $

	var GEKKO_DIV_POPUP_ID = new Number(0);
	var GEKKO_POPUP_DRAG = new Number(0);

	var BUFF_COUNTER = new Number(0);
	var BUFF = new Array();

	function getBrowserEngine() {
		if (navigator.userAgent.indexOf('Gecko') > 0)
			return 'gecko';
		else if (navigator.userAgent.indexOf('MSIE') > 0)
			return 'msie';
	}

	function setEventListener(obj, event, callback) {
		switch (getBrowserEngine()) {
			case 'msie':
				obj.attachEvent('on'+event, callback);
			break;
			case 'gecko':
				obj.addEventListener(event, callback, 0);
			break;
		}
	}

	function scrollTop() {
		switch (getBrowserEngine()) {
			case 'msie':
				scrolly = document.documentElement.scrollTop;
			break;
			case 'gecko':
				scrolly = self.pageYOffset;
			break;
			default:
				scrolly = document.body.scrollTop;
			break;
		}
		return scrolly;
	}

	function gekkoInit() {
		for (i = 0; i < document.forms.length; i++)
			eval("setEventListener(document.forms["+i+"], 'submit', function(){gekkoSendForm("+i+") })");
	}

	function gekkoSendForm(form_id) {
		obj = document.forms[form_id];

		try {
			obj.style.opacity = '0.2';
		} catch (e) {};

		/*

		// this is also a cool effect, still in development...

		var w = document.body.clientWidth;
		var h = document.body.clientWidth;

		div = document.createElement('div');

		document.getElementById('container').style.display = 'none';
		document.getElementById('pageNote').style.display = 'none';

		div.innerHTML = '<img src="'+_C_SITE_REL_URL+'/media/loading.gif" />';
		div.setAttribute('class', 'popup');
		div.setAttribute('style', 'position: relative; display:block; text-align:center; vertical-align:middle; padding:5%; width: 10%; margin-left: 40%; height: 100%;');

		document.body.appendChild(div);
		*/
	}
	function buffSet(obj_data) {
		BUFF[BUFF_COUNTER] = obj_data;
		return BUFF_COUNTER++;
	}
	function buffGet(obj_name) {
		return BUFF[obj_name];
	}
	function confirmAction(url, msg) {
		if (confirm(msg)) {
			location.href = url;
		}
	}
	function mouseDown(e) {
		GEKKO_POPUP_DRAG = 0;

		switch (getBrowserEngine()) {
			case 'msie':
				dhead = event.srcElement;
				e = event;
			break;
			default:
				dhead = e.target;
			break;
		}

		if (dhead.id.substr(0, 12) == 'popup_title_') {

			dcontainer = dhead.parentNode;

			offsetX = e.clientX;
			offsetY = e.clientY;

			origX = parseInt(dcontainer.style.left);
			origY = parseInt(dcontainer.style.top);

			GEKKO_POPUP_DRAG = 1;
			document.onmouseup = function () {
				document.onmousemove = function () { GEKKO_POPUP_DRAG = 0; }
			}
			var usingMSIE = (getBrowserEngine() == 'msie');
			document.onmousemove = function(e) {
				if (GEKKO_POPUP_DRAG) {
					if (usingMSIE)
						e = event;
					dcontainer.style.left = (origX + e.clientX - offsetX)+'px';
					dcontainer.style.top = (origY + e.clientY - offsetY)+'px';
				}
				return false;
			}
		}
	}
	function debug(str) {
		obj = document.getElementById('debug');
		if (!obj) {
			var obj = document.createElement('div');
			obj.id = 'debug';
		}
		obj.innerHTML = str;
	}

	function popupCreate(hidden, width, height) {

		var container = document.createElement('div');
		var dhead = document.createElement('div');
		var dbody = document.createElement('div');

		// I was using setAttribute, but it is not supported by the 80% of the people (thanks MSIE)... :)!

		container.id = 'popup_'+GEKKO_DIV_POPUP_ID;
		container.className = 'popup';
		container.style.position = 'absolute';
		container.style.left = '20px';
		container.style.top = (scrollTop()+20)+'px';
		if (hidden)
			container.style.display = 'none';

		dhead.id = 'popup_title_'+GEKKO_DIV_POPUP_ID;
		dhead.style.textAlign = 'right';
		dhead.style.cursor = 'move';
		dhead.style.padding = '3px';
		dhead.className = 'tbox1';
		dhead.innerHTML = '<img src="'+GEKKO_CLOSE_ICON_URL+'" style="cursor: pointer;" onclick="javascript:popupClose(\''+GEKKO_DIV_POPUP_ID+'\')" />';

		dbody.id = 'popup_body_'+GEKKO_DIV_POPUP_ID;
		dbody.className = 'info';
		dbody.style.cursor = 'wait';
		dbody.innerHTML = '<img src="'+_C_SITE_REL_URL+'/media/loading.gif">';

		if (width)
			container.style.width = width;

		if (height)
			container.style.height = height;

		container.appendChild(dhead);
		container.appendChild(dbody);

		document.body.appendChild(container);

		setEventListener(document, 'mousedown', function(e) { mouseDown(e) } );

		return GEKKO_DIV_POPUP_ID++;
	}
	function popupGet(id) {
		return document.getElementById("popup_"+id);
	}
	function triggerDisplay(obj) {
		obj = document.getElementById(obj);
		obj.style.display = (obj.style.display == 'none') ? 'block' : 'none';
	}
	function popupDisplay(id) {
		document.getElementById('popup_'+id).style.display = 'block';
		document.getElementById('popup_body_'+id).style.cursor = 'normal';
	}
	function popupLoadHTML(id, doc, postvars) {
		varLoadHTML("document.getElementById('popup_body_"+id+"').innerHTML", doc, postvars);
	}
	function popupClose(popup) {
		if (!GEKKO_POPUP_DRAG)
			document.body.removeChild(popupGet(popup));
	}
	/*
	*	AJAX snippets:
	*	Some code borrowed from Ajallerix (http://forge.novell.com/modules/xfmod/project/?ajallerix)
	*	Read file THANKS
	*/
	function initXMLHttpRequest() {
		var req = false;
		if (navigator.userAgent.indexOf('MSIE') > 0) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		} else if (navigator.userAgent.indexOf('Gecko') > 0) {
			try {
				var req = new XMLHttpRequest();
			} catch (e) {}
		}
		return req;
	}
	function varLoadHTML(dest, doc, postvars) {

		var req = initXMLHttpRequest();

		if (req) {

			req.onreadystatechange = function() {
				if (req.readyState == 4)
					eval(dest+'=req.responseText;');
			}

			req.open(postvars ? 'POST' : 'GET', doc, true);

			if (postvars)
				req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

			req.send(postvars);

		} else {
			alert("AJAX features are disabled.");
		}

	}

	function addGroups(form, obj, popup) {
		form = document.getElementById(form);

		// adding checked groups to "groups" array
		groups = new Array();
		j = 0;
		for (i = 0; i < form.elements.length; i++) {
			if (form[i].checked) {
				groups[j] = form[i].value;
				j++;
			}
		}
		var groups = groups.join(',');

		if (groups.length > 255) {
			alert("You've selected too many groups!");
			return false;
		}

		// parent form was previusly saved in groupChooser()
		obj = BUFF[obj];
		obj.value = groups;

		popupClose(popup);
		BUFF[obj] = null;

		return true;
	}

	function groupChooser(obj, m) {
		var o = buffSet(obj);
		var p = popupCreate(true);
		popupLoadHTML(p, _C_SITE_REL_URL+'runscript.php?module=groups&action=chooser&groups='+obj.value+'&object='+o+'&popup='+p+(m ? '&authwizard=1': '')+'&relpath='+_C_SITE_REL_URL);
		popupDisplay(p);
	}

	function chooseIcon(img, icon, object, popup) {
		BUFF[icon].src = img.src;
		BUFF[object].value = img.alt;
		popupClose(popup);
	}
	// will show a preview for the selected text box
	function showPreview(id) {
		var w = document.body.clientWidth;
		var p = popupCreate(true);

		obj = popupGet(p);

		setEventListener(obj, 'click', function() {popupClose(p)});
		obj.style.margin = '10px';
		obj.style.overflow = 'auto';
		obj.style.left = (w/8)+'px';
		obj.style.width = (6*w/8)+'px';
		obj.style.height = '90%';

		//obj.setAttribute("onclick", "popupClose('"+p+"')");
		//obj.setAttribute("style", "margin:10px;overflow:auto;left:"+(w/8)+"px;width:"+(6*w/8)+"px;height:90%;");

		popupLoadHTML(p, _C_SITE_REL_URL+'runscript.php', 'action=preview&data='+escape(document.getElementById(id).value));
		popupDisplay(p);
	}
	function iconChooser(icon, obj, size) {
		if (!size)
			size = '16';
		var o = buffSet(obj);
		var i = buffSet(document.getElementById(icon));
		var p = popupCreate();
		popupLoadHTML(p, _C_SITE_REL_URL+'runscript.php?action=iconlist&size='+size+'&selected='+obj.value+'&object='+o+'&icon='+i+'&popup='+p);
		popupDisplay(p);
	}
	// <form onsubmit="return antiBot(this)">
	function antiBot(obj) {
		obj.auth.value = _C_ANTIBOT;
		return true;
	}
	function useStyleSheet(title) {
		var taglink;
		for (i = 0; (taglink = document.getElementsByTagName("link")[i]); i++) {
			if (taglink.getAttribute("rel") == "alternate stylesheet") {
				taglink.disabled = (taglink.getAttribute("title") == title) ? false : true;
			}
		}
	}
	function ddctrl(id, a) {
		//clearTimeout(ddtime);
		if (id) {
			var obj = document.getElementById(id);
			if (a) {
				obj.style.display='block';
			} else {
				ddtime = setTimeout("ddclear('"+id+"')", 200);
			}
		}
	}
	function ddisplay(obj, a) {
		var par = obj.parentNode;
		for (i = 0; i < obj.childNodes.length; i++) {
			var ul = obj.childNodes[i];
			if (ul.nodeName.toLowerCase() == 'ul') {
				ul.style.display = a ? 'block' : 'none';
			}
		}
	}

	//setEventListener(window, 'load', function () { gekkoInit() });