//---------------------------------------//
//---------- GLOBAL FUNCTIONS -----------//
//---------------------------------------//
function getElement(div) {
	var n = false;
	if ((document.all && document.all[div]) || (document.getElementById && document.getElementById(div))) {
		n = (document.all) ? document.all[div] : document.getElementById(div);
	}
	return n;
}
function xmlHttp() {
	var objXMLHttp = null
	if (window.XMLHttpRequest) {
		objXMLHttp = new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
function encMail(s, e, ex, show) {
	switch (show) {
		case "url":
			document.write("<a href=\"mailto:" + s + "&#64;" + e + "." + ex + "\" title=\"" + s + "&#64;" + e + "." + ex + "\">" + s + "&#64;" + e + "." + ex + "</a>");
			break;
		case "show":
			document.write(s + "&#64;" + e + "." + ex);
			break;
		case "open":
			location.href = "mailto:" + s + '@' + e + "." + ex
			break;
	}
}
function getInfo(n) {
	try {
		return eval(n);
	} catch (e) {
		return false;
	}
}
function popUp(uri, ident, ww, wh, extra) {
	var attrib = "width=" + parseInt(ww) + ",height=" + parseInt(wh) + "," + extra;
	if (parseInt(navigator.appVersion) > 3) {
		attrib += ",left=" + parseInt((screen.width - ww) / 2) + ",top=" + parseInt((screen.height - wh) / 2);
	}
	return window.open(uri, ident, attrib);
}
function trimSpace(str) {
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function regReplace(expre, repl, str) {
	str = str.replace(/[\r\n]/g, "");
	var re = new RegExp(expre, "gi");
	return str.replace(re, repl);
}
function setReferer() {
	var ref = document.location.href;
	if (document.location.href.indexOf("/sendurl/") == -1) {
		if (document.domain) { ref = regReplace("http://" + document.domain, "", ref) }
		location.href = "/sendurl/?ref=" + escape(ref);
	}
}
function setFocus(name, item) {
	try {
		if (eval("document." + name + "." + item + "")) {
			eval("document." + name + "." + item + "").focus();
		}
	} catch (e) {
		//null
	}
}
function reloadSession() {
	var xml = xmlHttp();
	if (xml) {
		xml.open("GET", "/assets/reload.asp?cache=" + Math.floor(Math.random() * 10000000), true)
		xml.onreadystatechange = function() {
			if (xml.readyState == 4 && xml.status == 200) {
				setTimeout("reloadSession()", 5 * 60 * 1000);
			}
		}
		xml.send(null);
	}
}

//---------------------------------------//
//----------- MENU FUNCTIONS ------------//
//---------------------------------------//
function displayPage(item) {
	var div = getElement(item);
	if (div) { div.style.display = (div.style.display == "none") ? "block" : "none"; }
}
function recalcMenuHeight(n) {
	var add = parseInt(n) || -10;
	var menu = getElement("menu-left");
	var page = getElement("page");
	if (menu && page) {
		if (menu.offsetHeight && page.offsetHeight) {
			var mHeight = parseInt(menu.offsetHeight);
			var pHeight = parseInt(page.offsetHeight);
			if (mHeight < pHeight) {
				menu.style.height = (page.offsetHeight + add) + "px";
			} else if (mHeight > pHeight) {
				page.style.height = (menu.offsetHeight + add) + "px";
			}
		}
	}
	checkForms()
}
function checkForms() {
	for (var i = 0; i < document.forms.length; i++) {
		var frm = document.forms[i];
		if (frm.action == "/cgi-bin/sendform.asp") {
			frm.action += "?pageid=" + pageID + "&lang=" + pageLang;
		}
	}
}

//---------------------------------------//
//----------- FRONT FUNCTIONS -----------//
//---------------------------------------//
function addSplash() {
	if (document.cookie && pageSplash) {
		location.replace("/start.asp?lang=" + pageLang + "&returnPath=" + escape(location.href));
	}
}

//---------------------------------------//
//----------- DEBAT FUNCTIONS -----------//
//---------------------------------------//
function debatAction(job, root, thread) {
	location.href = "?act=list&job=" + job + "&id=" + root + "&tid=" + thread;
}

//---------------------------------------//
//----------- POLL FUNCTIONS -----------//
//---------------------------------------//
function submitpoll(status, id, object) {
	var xml = xmlHttp();
	var div = getElement("pollbox_" + id);
	if (xml && div) {
		xml.open("GET", "/cgi-bin/poll.asp?PollId=" + id + "&AnswerId=" + object.value + "&Admin=" + status, true)
		xml.onreadystatechange = function() {
			if (xml.readyState == 4 && xml.status == 200) {
				div.innerHTML = xml.responseText;
			}
		}
		xml.send(null);
	}
}

//---------------------------------------//
//------------ FORM FUNCTIONS -----------//
//---------------------------------------//
function validateCustomeForm(obj) {
	var x = 0;
	var err = 0;
	for (x = 1; x < obj.elements.length; x++) {
		var item = obj.elements[x];
		if (item.type == "text" || item.type == "textarea") {
			if (item.className.indexOf("menu-top-sub") == -1) {
				item.className = "";
				if (item.getAttribute("required") == "yes") {
					if (trimSpace(item.value) == "") {
						if (err == 0) { item.focus(); }
						item.value = "";
						item.className = "form_field_req";
						err += 1;
					}
				}
			}
		}
	}
	if (err != 0) {
		return false;
	} else {
		if (obj.custsub) {
			obj.custsub.disabled = true;
		}
		return true;
	}
}
function validateForm() {
	var f = document.search;
	if (f) {
		if (f.keyword) {
			var keyword = trimSpace(f.keyword.value);
			f.keyword.value = keyword;
			f.fm_sub.disabled = (keyword.length != 0) ? true : false;
			if (keyword.length == 0) {
				f.keyword.focus();
				return false;
			} else {
				f.submit();
				return true;
			}
		}
	}
}
function resetForm(obj) {
	var x = 0;
	for (x = 1; x < obj.elements.length; x++) {
		var item = obj.elements[x];
		if (item.type == "text" || item.type == "textarea") {
			if (item.className.indexOf("menu-top-sub") == -1) {
				item.className = "";
			}
		}
	}
}
//---------------------------------------//
//--------- THUMBNAIL FUNCTIONS ---------//
//---------------------------------------//
var bgUrl;
function showImage(path, desc) {
	var page = getElement("page");
	var main = getElement("main");
	var content = getElement("content");
	var contopt = getElement("content_opt");
	var foo = getElement("foo");
	if (main && content && foo) {
		foo.style.display = (foo.style.display == "none") ? "block" : "none";
		content.style.display = (foo.style.display == "none") ? "block" : "none";
		if (contopt) {
			contopt.style.display = (foo.style.display == "none") ? "block" : "none";
		}
		if (foo.style.display == "block") {
			bgUrl = main.style.background;
			if (bgUrl.length != 0) {
				main.style.background = "";
			}
			if (path) {
				foo.innerHTML = "<div id=\"thumb\"><a href=\"javascript:showImage();\"><img src=\"" + path + "\" border=\"0\" id=\"img-src\" onload=\"setImgHeight(this);\" class=\"show-img\"/></a></div><div id=\"content_opt2\" style=\"margin: 0px;\"><a href=\"javascript:showImage();\" title=\"" + escape(btnBack) + "\">" + btnBack + "</a> <span class=\"opt_line\">|</span> <a href=\"/print/?id=image\" target=\"_blank\" title=\"" + escape(btnPrint) + "\">" + btnPrint + "</a> <span class=\"opt_line\">|</span> <a href=\"javascript:location.reload();\" title=\"" + escape(btnTop) + "\">" + btnTop + "</a></div>";
			} else {
				showImage("");
				if (bgUrl.length != 0) { main.style.background = bgUrl; }
			}
		} else {
			foo.innerHTML = "";
			if (bgUrl.length != 0) {
				main.style.background = bgUrl;
			}
		}
	}
}
function setImgHeight(obj) {
	var page = getElement("page");
	var menu = getElement("menu-left");
	if (obj.height > 0) {
		if (page.offsetHeight < (obj.height + 50)) {
			page.style.height = (obj.height + 50) + "px";
			recalcMenuHeight();
		} else if (menu.offsetHeight < (obj.height + 50)) {
			menu.style.height = (obj.height + 50) + "px";
			recalcMenuHeight();
		}
	}
	window.scrollTo(0, 0);
}

//---------------------------------------//
//----------- ONLOAD FUNCTIONS ----------//
//---------------------------------------//
window.onload = function() {
	recalcMenuHeight();
	reloadSession()
}
addSplash();
