
	// CVS: $Id: core.js,v 1.1.1.1 2006/02/20 21:52:21 xiam Exp $
	var B_POP_COUNTER = new Number(0);
	var BUFF_COUNTER = new Number(0);
	var BUFF = new Array();

	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;
		}
	}
	// div popups
	function popupCreate(hidden, w, h) {
		var obj = document.createElement('div');
		if (hidden) obj.style.display = 'none';
		obj.setAttribute("class", "popup");
		obj.setAttribute("id", "popup_"+B_POP_COUNTER);
		obj.innerHTML = _L_LOADING;
		if (w) obj.style.width = w;
		if (h) obj.style.height = h;
		document.body.appendChild(obj);
		return B_POP_COUNTER++;
	}
	function popupGet(id) {
		return document.getElementById("popup_"+id);
	}
	function popupDisplay(id) {
		var obj = popupGet(id);
		obj.style.display = 'block';
	}
	function triggerDisplay(obj) {
		obj = document.getElementById(obj);
		obj.style.display = (obj.style.display == "none") ? "block" : "none";
	}
	function popupLoadHTML(id, doc, postvars) {
		varLoadHTML("document.getElementById('popup_"+id+"').innerHTML", doc, postvars);
	}
	function popupClose(popup) {
		document.body.removeChild(popupGet(popup));
	}
	/*
		AJAX Functions:
		Borrowed from Ajallerix (http://forge.novell.com/modules/xfmod/project/?ajallerix)
		Read file THANKS
	*/
	function initXMLHttpRequest() {
		if (window.XMLHttpRequest) {
			try {
				req = new XMLHttpRequest();
			} catch(e) {
				req = false;
			}
		} else if (window.ActiveXObject) {
			// untested, may not work.
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				req = false;
			}
		}
		return req;
	}
	function varLoadHTML(dest, doc, postvars) {
		var req = initXMLHttpRequest();
		if (req) {
			req.open(postvars ? 'POST' : 'GET', doc, true);
			if (postvars) req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			req.onreadystatechange = function () {
				if (req.readyState == 4) {
					eval(''+dest+'=req.responseText;');
				}
			}
		} else {
			alert("Cannot initialize XMLHttpRequest");
		}
		req.send(postvars);
	}

	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);

		// nice looking popup imitation
		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);

		var obj = popupGet(p);
		obj.style.position = 'absolute';

		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);

		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(true);
		popupLoadHTML(p, _C_SITE_REL_URL+'runscript.php?action=iconlist&size='+size+'&selected='+obj.value+'&object='+o+'&icon='+i+'&popup='+p+'&relpath='+_C_SITE_REL_URL);
		popupDisplay(p);
	}
	// <form onsubmit="return antiBot(this)">
	function antiBot(obj) {
		obj.auth.value = _C_ANTIBOT;
		return true;
	}
	function uploadImage(id) {
		window.open(_C_SITE_REL_URL+'runscript.php?action=uploadimage&object='+id, '', 'width=340,height=350');
	}
	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';
			}
		}
	}