
/*
1.Global Functions
*/
var adState = 0;
var speed = 4;
var timeout = 5;

var psdSwapState = 0;
var pfSwapState = 0;
var pfSwapC1 = '';
var pfSwapC2 = '';
var pfAdv = 0;
var pfAdvTmp = '';
var firsttime = [1,1,1,1,1];
var pics = ['tyre','tyre','batt','oil','disc'];

//total: 8
var checkclasses = ['blank','wrong','right']
var userData = [];
var loginState = 0;
var regmatrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var regNames = ['login', 'firstName', 'lastName', 'password', 'email'];

var currentDialog = 1;

var forumStr = 'Forums';

var action = "";
var aid = "";

var regError = 1;
var errorFlag = 0;

//Added stupidvars
//var gid = parseInt("0");
var gid = parseInt("0");
var fid = parseInt("0");
var tid = parseInt("0");
var pid = parseInt("0");
var cd = parseInt("0");
var cp = parseInt("0");

//DB ForumVars
var regUsers;

//request vars
var req;
var response;
var funcs = ['pfReset', 'loginDo', 'dummy', 'dummy', 'fInputCheck', 'popResult', 'popResult', 'dummy', 'showForumStatus', 'loadForumVars', 'xmlPut', 'postListener', 'postListener', 'threadListener'];
var maxProcs = 1;
var currentProcs = 0;

//IE check regexp
var t = new RegExp('internet explorer','gi');
var ie = (t.test(navigator.appName) ? 1 : 0)

//XML listener
var xmlData;
var xmlLevel;
var xmlDone;
var xmlNext;
var xmlDepth = 0;
var xmlRowsBefore;
var xmlPages = [];
var postForm = 0;
var lastPost = 0;

//posts
var editing = 0;
var editID = 0;

//path constructor
var currentPath = [];
var pathMatrix = [forumStr];

//ppp
var postsPerPage = 10;
var currentPage = 0;
var totalPages = 0;

//insert your onload functions here
window.onload = function() {

	setAd();
	showAd();



	if(action)
		doAction(action, aid);

	if(obj = document.getElementById("pType"))
		switchProd(obj);


	if(typeof(pfStart) != 'undefined')
		if(pfStart == 1)
			pfSwap();

	if( typeof( forumModes ) != "undefined" ){
		//alert('res: ' + document.cookie);
		d = jsGetCookie('', 1);
		//alert('res: ' + document.cookie);
		if(parseInt(d['id']) > 0){
			userData = d;
		}


		if(gid != 0){
			currentPath[0] = gid;
			if(fid != 0){
				currentPath[1] = fid;
				if(tid != 0){
					currentPath[2] = tid;
				}
			}
		}

		if(cd != 0){
			currentDialog = cd;
		}

		if(cp != 0){
			currentPage = cp;
		}

		//if(typeof(d.path) != 'undefined' && d.path != 'undefined')
		//	currentPath = d.path.split(',');
		initForum();
	}
}

window.onunload = function() {
	if(typeof(forumModes) != "undefined"){
		//jsSetCookie('path', currentPath);
		//if(userData.id)
			//logoutDo(0);
		if(clockID)
			killClock();
	}
}

//---------------------------------------A test function, please delete before publishing project!!!
function alertSID(response){
	alert(response.data);
}

//insert your onresize functions here <!------------------------------------------REWRITE!!!
//window.onresize = function() {
	//refreshDivs();
//}

function refreshDivs(){
	if(el = document.getElementById("headerDivs"))
		el.refresh();
}

function dummy(response){
	//do nothing;
	return;
}

function jsSetCookie( sName, sValue ){
	//document.cookie = document.cookie + sName + "=" + escape(sValue) + "; ";
	document.cookie = sName + "=" + sValue + "; ";
	//alert('res: ' + document.cookie);
}

function jsGetCookie(sName, mode){
	var aCookie = document.cookie.split("; ");
	if(mode == 0)
		for (var i = 0, maxi = aCookie.length; i < maxi; i++){
			var aCrumb = aCookie[i].split("=");
			if (sName == aCrumb[0]){
				return unescape(aCrumb[1]);
			}
		}
	else {
		var d = [];
		c = 0;
		for (var i = 0, maxi = aCookie.length; i < maxi; i++){
			var aCrumb = aCookie[i].split("=");
			d[aCrumb[0]] = unescape(aCrumb[1]);
			//alert('getting: ' + aCrumb[0] + ' -> ' + aCrumb[1]);
			c++;
		}
		//alert('get id: ' + d['id']);
		return d
	}
	return false;
}

function serialize(x){
	function sN(x)
	{
		return((parseInt(x)==x)&&(x<2147483648)?'i':'d')+':'+x+';'
	}
	function sS(x)
	{
		//x=escape(x);
		return 's:'+x.length+':"'+x+'";'
	}
	function sO(x)
	{
		var a=[];
			for(var i in x)
				if('function'!=typeof(x[i]))
					a[a.length]=sX(isNaN(d=parseInt(i))?i:d)+sX(x[i]);
		return 'a:'+a.length+':{'+a.join('')+'}';
	}
	function sX(x)
	{
		if(x==null)return 'N;';
		switch(typeof(x))
		{
			case 'string':
				return sS(x);
			case 'number':
				return sN(x);
			case 'object':
				return sO(x)
		}
	}
	return sX(x)
}

/*
2.Block Functions
Menu
*/

function calcOffsetX(el) {
	offset = el.offsetLeft;
	if (el.offsetParent)
		offset += calcOffsetX(el.offsetParent)
	return offset;
}

function showDiv(id, open){
	div = "div" + id;
	cell = "cell" + id;
	el1 = document.getElementById(div);
	el2 = document.getElementById(cell);

	if (open == 1){
		el1.style.visibility = "visible";
		el2.style.visibility = "visible";
		alignDiv(el1, el2);

	} else {
		el1.style.visibility = "hidden";
		el2.style.visibility = "hidden";
	}
}

function alignDiv(el1, el2){
	divWidth = parseInt(el1.offsetWidth);
	cellWidth = parseInt(el2.clientWidth);
	divX = calcOffsetX(el1);
	divPos = divX + divWidth;
	cellPos = calcOffsetX(el2) + cellWidth;
	if (cellPos > divPos)
		el1.style.left = ((cellPos-divWidth))+'px';
}

/*
Advertisment
*/
function setAd(){
	if (adState != 0)
		return;
	if(div = document.getElementById("adv"))
		div.style.top = "0px";
}

function showAd(){
	if (adState != 0)
		return;

	if(div = document.getElementById("adv")){

		div.style.visibility = "visible";

		divHeight = parseInt(div.offsetHeight);

		if(div.style.top == "0px"){
			div.style.top = "-" + divHeight + "px";
			count = 1;
		}
		divTop = parseInt(div.style.top);

		realPos = Math.abs(divTop);

		if(realPos < 6){
			adState = 1;
			return;
		}

		div.style.top = divTop + realPos/speed + "px";
		setTimeout("showAd()",timeout);
	}
}

function hideAd(){
	if (adState == 0)
		return;

	div = document.getElementById("adv");

	divHeight = parseInt(div.offsetHeight);
	divTop = parseInt(div.style.top);

	realPos = divTop + divHeight;

	if(realPos < 6){
		div.style.visibility = "hidden";
		return;
	}

	div.style.top = divTop - realPos/speed + "px";
	setTimeout("hideAd()",timeout);
}

/*
Product Search Display
*/
function switchList(pid){
	if(pid == cPage)return;

	if(cont = document.getElementById("psdContainer"))
		if(el = document.getElementById("page"+pid)){

			listItems[cPage] = cont.innerHTML;

			cont.innerHTML = listItems[pid];

			cPage = pid;

			for(i = 0, imax = listItems.length; i < imax; i++)
				if(c = document.getElementById("page"+i))
					c.className = "psdUnsel";

			el.className = "psdSel";

			for (x in orderMas) {
				if (orderMas[x]) {
					if (el = document.getElementById("chkb" + orderMatrix[x])) {
						el.checked = true;
					}
				}
			}

		}
}

function psdSwap(){
	if(psdSwapState == 0){
		if(sel = document.getElementById("psdSelects"))
			sel.innerHTML = '';

		if(txt = document.getElementById("psdSearch"))
			txt.innerHTML = nusrc;

		if(butt = document.getElementById("psdButton"))
			butt.innerHTML = imgDown;
		psdSwapState = 1;
	} else {
		if(sel = document.getElementById("psdSelects"))
			sel.innerHTML = selHTML;

		if(txt = document.getElementById("psdSearch"))
			txt.innerHTML = '';

		if(butt = document.getElementById("psdButton"))
			butt.innerHTML = imgUp;
		psdSwapState = 0;
	}
}

function popProd(target){
	window.open(target,"_blank","height=1,width=600,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=yes,left=200,top=200");
}

/*
Product Finder
*/
function pfSwap(){

	c1 = document.getElementById("pf");
	c2 = document.getElementById("ban");
	c3 = document.getElementById("cbutt");

	var tmp;

	if(pfSwapState == 1){
		c1.innerHTML = pfSwapC1;
		pfSwapC1 = '';
		c1.style.padding = '0px 20px 20px 0px';

		c2.innerHTML = pfSwapC2;
		pfSwapC2 = '';
		c2.style.padding = '0px 0px 20px 0px';

		tmp = c3.innerHTML;
		c3.innerHTML = pfSwapC3;
		pfSwapC3 = tmp;

		pfSwapState = 0;

		pfSelect(mode);
	} else {
		pfSwapC1 = c1.innerHTML;
		c1.innerHTML = '';
		c1.style.padding = '0px 20px 0px 0px';

		pfSwapC2 = c2.innerHTML;
		c2.innerHTML = '';
		c2.style.padding = '0px 0px 0px 0px';

		tmp = c3.innerHTML;
		c3.innerHTML = pfSwapC3;
		pfSwapC3 = tmp;

		pfSwapState = 1;
	}
}

function switchProd(obj, m){

	pfDisable();

	if(cont = document.getElementById("content")){
		mode = obj.selectedIndex;
		m = document.getElementById("modeInp");

		m.value = mode;

		cont.innerHTML = modes[0][mode];

		if(form = document.getElementById("pfForm"))
			form.action = actions[mode];

		if(b = document.getElementById("pfBody"))
			b.style.background = '#FFF1E3';
			//b.style.background = 'url(/pic/pf/' + pics[mode] + '.gif) bottom right #FFF1E3 no-repeat';

		if(butt = document.getElementById("button"))
			if(mode != 0)
				butt.innerHTML = button;
			else
				butt.innerHTML = '';

		if(clr = document.getElementById("clear"))
			if(mode != 0)
				clr.innerHTML = clear;
			else
				clr.innerHTML = '';

		//if(firsttime[mode]){
		//	if(mode != 1)
		//		firsttime[mode] = 0;
		//	pfSelect(mode);
		//}
	}
}

function pfSelect(mode, ctrl){
	return;
	var struct = new Array();

	pfDisable();

	if(ctrl){
		for(i = 0; i < 11; i++){
			if(mode == 1 && i == 1){
				if(inp1 = document.getElementById("cell" + i)){
					inp1.checked = false;
					struct[i] = 0;
				}

				if(inp2 = document.getElementById("cell" + i + "a")){
					inp2.checked = false;
					struct[i] = 0;
				}
			} else {
				if(sel = document.getElementById("sel" + i)){
					sel.selectedIndex = 0;
					struct[i] = 0;
				}
			}
		}
	} else {
		if(mode == 1 && firsttime[mode]){
			var imax = 7;
			if(pfAdv)
				imax = 11

			for(i = 0; i < imax; i++){
				switch(i){
					case 0:
						struct[i] = 1;
						break;
					case 1:
						struct[i] = parseInt(defSeason);
						break;
					case 2:
						struct[i] = parseInt(defWidth);
						break;
					case 3:
						struct[i] = parseInt(defProfile);
						break;
					case 4:
						struct[i] = parseInt(defRadius) + '0';
						break;
					default:
						struct[i] = 0;
						break;
				}
			}
			if(defSeason == 1)
				if(inp = document.getElementById("cell1"))
					inp.checked = true;

			if(defSeason == 2)
				if(inp = document.getElementById("cell1a"))
					inp.checked = true;


			firsttime[mode] = 0;

		} else {
			for(i = 0; i < 11; i++){
				if(mode == 1 && i == 1){
					if(inp1 = document.getElementById("cell" + i))
						if(inp1.checked == true)
							struct[i] = inp1.value;

					if(inp2 = document.getElementById("cell" + i + "a"))
						if(inp2.checked == true)
							struct[i] = inp2.value;
				} else {
					if(sel = document.getElementById("sel" + i))
						if(sel.options.item(sel.selectedIndex))
							struct[i] = sel.options.item(sel.selectedIndex).value;
						else
							struct[i] = sel.options(sel.selectedIndex).value;
				}
			}
		}
	}
	//alert(struct.join(",") + ' : ' + struct.length);
	request(struct, mode, 0);
}

function pfDisable(){
	for(i = 0; i < 11; i++)
		if(sel = document.getElementById("sel" + i))
			sel.disabled = true;
}

function pfEnable(){
	for(i = 0; i < 11; i++)
		if(sel = document.getElementById("sel" + i))
			sel.disabled = false;
}

function pfReset(response){

	for(var a in response.data)
		if(cell = document.getElementById("cell" + a))
			if(sel = document.getElementById("sel" + a)){
				//alert(sel.parentElement.innerHTML);
				//continue;

				if(sel.options.item(sel.selectedIndex)){
					oldi = sel.options.item(sel.selectedIndex).value;
					oldv = sel.options.item(0).value;
					oldtxt = sel.options.item(0).innerHTML;
				} else {
					oldi = sel.options.item(sel.selectedIndex).value;
					oldv = sel.options.item(0).value;
					oldtxt = sel.options.item(0).innerHTML;
				}
				//alert(sel.name);

				n = sel.getAttribute('name');

				html = '<select onchange="pfSelect(' + response.mode + ');" name="' + n + '" id="sel' + a + '">\n';
				html += '<option value="' + oldv + '"' + (oldi == b ? ' selected="selected"' : '') + '>' + oldtxt + '</option>\n';
				html +=  response.data[a];
				/*
				//alert('index: ' + a + '\n' + html);
				if(mode == 1 && a == 4)
					for(var b in response.data[a])
						html += '<option value="' + b + '"' + (oldi == b ? ' selected="selected"' : '') + '>R' + response.data[a][b] + '</option>\n';
				else
					for(var b in response.data[a])
						html += '<option value="' + b + '"' + (oldi == b ? ' selected="selected"' : '') + '>' + response.data[a][b] + '</option>\n';
				*/

				html += '</select>\n';

				cell.innerHTML = html;

				sel = document.getElementById("sel" + a);

				sel.disabled = false;
			}

	if(cont = document.getElementById("content"))
		modes[0][mode] = cont.innerHTML;
}

function pfAdvSearch(which){
	if(el = document.getElementById("addParams")){
		if(pfAdv){
			if(l2 = document.getElementById("pfAdvL2"))
				l2.innerHTML = pfAdvTmp;

			if(l1 = document.getElementById("pfAdvL1"))
				l1.innerHTML = '<img src="/pic/arrows/down.gif" alt="" />';

			el.innerHTML = '';
			pfAdv = 0;
			pfSelect(mode, 0);
			return;
		} else {
			if(l2 = document.getElementById("pfAdvL2")){
				pfAdvTmp = l2.innerHTML;
				l2.innerHTML = closeBtnStr;
			}

			if(l1 = document.getElementById("pfAdvL1"))
				l1.innerHTML = '<img src="/pic/arrows/up.gif" alt="" />';

			if(which)
				el.innerHTML = modes[0][6];
			else
				el.innerHTML = modes[0][5];

			pfAdv = 1;
			pfSelect(mode, 1);
			return;
		}
	}
}

/*
XMLHTTPRequest Module
*/

//if (typeof XMLHttpRequest != "object")
//function XMLHttpRequest(){
//	return new ActiveXObject("Microsoft.XMLHTTP");
//}


function CRObj()
{
	var obj = null;
	try{
		obj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc){
			obj = null;
		}
	}

	if (!obj && typeof XMLHttpRequest!="undefined"){
		obj = new XMLHttpRequest();
	}
	return obj;
}

function request(matrix, mode, func){		
	if(currentProcs < maxProcs){
		currentProcs++;
		req = CRObj();
		requrl = "/supra/request";
		if (req){
			req.onreadystatechange = processReqChange;			
			if ( func == 2 ){
				jsSetCookie('id', 0);
				jsSetCookie('login', '');
			}
			q = 'mode=' + mode + '&matrix=' + matrix + '&func=' + func + '&rand=' + Math.random();

			req.open("POST", requrl);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.send(q);			
		} else {
			var url = requrl + '?mode=' + mode + '&matrix=' + matrix + '&func=' + func + '&non=1&rand=' + Math.random();

			var span = null;
			span = document.body.appendChild(document.createElement("SPAN"));

			span.style.display = 'none';
			span.innerHTML = 'script span<script></' + 'script>';

			var s = span.getElementsByTagName("script")[0];
			s.type = "text/javascript";

			if (s.setAttribute)
				s.setAttribute('src', url);
			else
				s.src = url;
		}

	} else {
		setTimeout('request("' + matrix + '", ' + mode + ', ' + func + ')', 500);
	}
}

function processReqChange() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			currentProcs--;
			eval('response = ' + unescape(req.responseText));
			//if(parseInt(response.func) == 1)
			//	alert(req.responseText);
			//if(parseInt(response.func) == 0)
			//	alert(req.responseText);

			if(parseInt(response.func) == 10)
				xmlPut(response);
			else
				eval(funcs[response.func] + '(response)');
		}
	}
}


/*
Folder View
*/
function swapMenu(id){

	var handler = 3;

	if(el = document.getElementById("r"+id))
		handler = (el.style.display == 'none' ? 1 : 0);

	// hide/show level
	for(i = 0, imax = mmIds.length; i < imax; i++)
		if(lp = document.getElementById("r" + mmIds[i])){
			lp.style.display = 'none';
			document.images['smn'+mmIds[i]].src = '/pic/fv/o.gif';
		}


	if(handler == 1)
		el.style.display = '';
	if(handler == 0)
		el.style.display = 'none';

	// change icons
	picPath = document.images['smn' + id].src;
	ln = picPath.length - 5;
	picName = picPath.substring(ln);

	if(handler == 1)
		document.images['smn' + id].src = '/pic/fv/c.gif';
	else
		document.images['smn' + id].src = '/pic/fv/o.gif';
}

/*
Product Search Display
*/
function setStyleSel(s) {
	tr = document.getElementById(s);
	tr.style.backgroundColor='#fffbf7';

	for(i = 0, imax = tr.cells.length; i < imax; i++){
		tr.cells.item(i).style.color = "#333";
	}
}

function setStyleUnsel(s,c) {
	document.getElementById(s).style.backgroundColor=c;
	for(i = 0, imax = tr.cells.length; i < imax; i++){
		tr.cells.item(i).style.color = "#000";
	}
}

/*
Dynamic Map
*/

function showCity(id, x, y){
	if (el = document.getElementById(id)){
		el.style.visibility = "visible";
		el.style.left = x + "px";
		el.style.top = y + "px";
		window.statu
	}
}

function hideCity(id){
	if (el = document.getElementById(id)){
		el.style.visibility = "hidden";
	}
}

/*
Login
*/
function loginSwap(){
	c1 = document.getElementById("loginLinks");
	c2 = document.getElementById("loginField");

	if(loginState == 0){
		c1.innerHTML = loginLinks1;
		c2.innerHTML = loginCases[1];
		loginState = 1;
	} else {
		c1.innerHTML = loginLinks0;
		c2.innerHTML = loginCases[0];
		loginState = 0;
	}
}

function loginCheck(inp, state){
	if(state == 0){
		saveForm('forumLog');
		if(inp.value != "")
			request(inp.value, 0, 1);
	} else {
		if(inp = document.getElementById("login"))
			if(inp2 = document.getElementById("password"))
				if(inp.value != "" && inp2.value != "")
					request(inp.value + ',' + inp2.value, 1, 1);
	}
}

function loginDo(response, ctrl){
	if(ctrl){
		if(inp = document.getElementById("login"))
			inp.value = "";
		if(inp2 = document.getElementById("password"))
			inp2.value = "";

		loginSwap();

		if(us = document.getElementById("user"))
			us.innerHTML = userData.login;

		request(userData.id, 0, 3);

		//reloading
		regUsers = null;
		loadForumVars(0, 1);
		reloadForum();

	}
	else
		if(response.mode == 0){			
			if(inp = document.getElementById("login"))
				if(response.data > 0)
					inp.className = checkclasses[2];
				else
					inp.className = checkclasses[1];
		}
		else{			
			if(response.data == false){
				//popError('login');
				if(inp2 = document.getElementById("password")){
					inp2.className = checkclasses[1];
				}
			} else {
				userData = response.data;

				//reloading
				regUsers = null;
				loadForumVars(0, 1);
				reloadForum();

				if(inp = document.getElementById("login"))
					inp.value = "";
				if(inp2 = document.getElementById("password"))
					inp2.value = "";

				loginSwap();

				if(us = document.getElementById("user"))
					us.innerHTML = userData.login;

				jsSetCookie('id', userData['id']);
				jsSetCookie('login', userData['login']);
				jsSetCookie('email', userData['email']);
				jsSetCookie('firstName', userData['firstName']);
				jsSetCookie('lastName', userData['lastName']);
				jsSetCookie('country', userData['country']);
				jsSetCookie('city', userData['city']);
				jsSetCookie('address', userData['address']);
				jsSetCookie('postCode', userData['postCode']);

				jsSetCookie('phone', userData['phone']);
				jsSetCookie('fax', userData['fax']);
				jsSetCookie('birthday', userData['birthday']);
				jsSetCookie('signature', userData['signature']);
				/*
				alert('SET : ' + document.cookie);
				for (var i in userData)
					jsSetCookie(i, userData[i]);
				alert('SET : ' + document.cookie);
				*/
			}
		}
}

function logoutDo(mode){
	if(mode) {
		loginSwap();

		request(userData.id, 0, 2);
		userData = [];

		regUsers = null;
		loadForumVars(0, 1);
		reloadForum();
	}
	else{
		if(userData){
			for (var i in userData)
				jsSetCookie(i, userData[i]);
			request(userData.id, 0, 2);
		}
	}
}

/*
Forum
*/

//use this one for loading everything in
function initForum(){

	if(typeof(userData.id) == "undefined")
		loadForumVars(0, 1);
	runForum();
}

function reloadForum(){
	if(regUsers != null){
		buildDialog(currentDialog, currentPath, true);
	} else
		setTimeout(reloadForum, 300);
}

function runForum(){
	if(userData.id)
		loginDo(userData, 1);
	else
		if(regUsers != null){
			buildDialog(currentDialog, currentPath, true);
		} else
			setTimeout(runForum, 300);
}

function loadForumVars(d, ctrl){
	if(ctrl){
		if(userData.id){
			request(0, 1, 9);
		}
		else{
			request(0, 0, 9);
		}
	} else {
		switch(parseInt(d.mode)){
			case 0:
				regUsers = d.data;
				break;
			case 1:
				regUsers = d.data;
				break;
		}
	}

}


function buildDialog(mode, data, norel){	
	if(norel){
		if(errorFlag)return;
		if(typeof(forumModes) == "object"){
			if(d = document.getElementById("forum")){
				switch(mode){
					case 1:						
						//main forum
						if( data ){
							if( data.length > 2 ){
								d.innerHTML = forumModes[3];
								startClock();
								postForm = 1;
							}
							else if( data.length ==  2 ){
								d.innerHTML = forumModes[2];
								startClock();
								postForm = 1;
							}
							else
								d.innerHTML = forumModes[2];

							if ( data.length > 0 ){
								xmlLoad(data);
								currentPath = data;
							}
							else{
								xmlLoad(0);
								currentPath = [];
							}
						}
						else{
							d.innerHTML = forumModes[2];
							xmlLoad(0);
							currentPath = [];
							if(p = document.getElementById("path"))
								p.innerHTML = '<span class="fPath" onclick="javascript: buildDialog(1, [], false);">' + forumStr + '<\/span>';
						}
						//forumStatus
						loadForumStatus();
						break;
					case 2:
						//lost password
						d.innerHTML = forumModes[5];

						tmp = '';
						if(t = document.getElementById("fTitle"))
							tmp = t.innerHTML;

						if(p = document.getElementById("path"))
							p.innerHTML = '<span class="fPath" onclick="javascript: buildDialog(1, [], false);">' + forumStr + '<\/span>&nbsp;<span class="fPath">\/<\/span>&nbsp;<span class="fPath" onclick="javascript: buildDialog(' + mode + ');">' + tmp + '<\/span>';

						break;
					case 3:
						//view profile
						d.innerHTML = forumModes[0];
						//d.innerHTML = forumModes[1];

						tmp = '';
						if(t = document.getElementById("fTitle"))
							tmp = t.innerHTML;

						if(p = document.getElementById("path"))
							p.innerHTML = '<span class="fPath" onclick="javascript: buildDialog(1, [], false);">' + forumStr + '<\/span>&nbsp;<span class="fPath">\/<\/span>&nbsp;<span class="fPath" onclick="javascript: buildDialog(' + mode + ');">' + tmp + '<\/span>';

						buildProfile();

						break;
					case 4:
						//register
						d.innerHTML = forumModes[1];

						tmp = '';
						if(t = document.getElementById("fTitle"))
							tmp = t.innerHTML;

						if(p = document.getElementById("path"))
							p.innerHTML = '<span class="fPath" onclick="javascript: buildDialog(1, [], false);">' + forumStr + '<\/span>&nbsp;<span class="fPath">\/<\/span>&nbsp;<span class="fPath" onclick="javascript: buildDialog(' + mode + ');">' + tmp + '<\/span>';

						break;
				}

				currentDialog = mode;

				if(userData.id)
					request(userData.id, 0, 3);
			}
		}
	}
	else{
		if( data )
			document.location = addy + '?gid=' + (typeof(data[0]) != 'undefined' ? data[0] : 0) + '&fid=' + (typeof(data[1]) != 'undefined' ? data[1] : 0) + '&tid=' + (typeof(data[2]) != 'undefined' ? data[2] : 0) + '&cd=' + mode + 'cp=' + currentPage;
		else
			document.location = addy + '?gid=' + (typeof(currentPath[0]) != 'undefined' ? currentPath[0] : 0) + '&fid=' + (typeof(currentPath[1]) != 'undefined' ? currentPath[1] : 0) + '&tid=' + (typeof(currentPath[2]) != 'undefined' ? currentPath[2] : 0) + '&cd=' + mode + 'cp=' + currentPage;
	}
}

function buildProfile(){

	if(userData.id){

		if(el = document.getElementById("inp0"))
			el.value = userData.login;

		if(el = document.getElementById("inp1"))
			el.value = userData['firstName'];

		if(el = document.getElementById("inp2"))
			el.value = userData.lastName;

		if(el = document.getElementById("inp5"))
			el.value = userData.email;

		if(el = document.getElementById("inp6"))
			el.value = userData.email;
	}
}

function loadForumStatus(){
	if(el = document.getElementById("statusInfo")){
		if(userData.id){
			request(0, 1, 8);
		} else {
			request(0, 0, 8);
		}
	}
}

function constructPath(){
	var str = new String();
	var path = [];
	str += '<span class="fPath" onclick="javascript: buildDialog(' + currentDialog + ', [], false);">' + pathMatrix[0] + '<\/span>';

	if(p = document.getElementById("path")){
		for(i = 0, imax = currentPath.length; i < imax; i++){
			if(typeof(currentPath[i]) == "number" || parseInt(currentPath[i]) > 0){
				path[path.length] = currentPath[i];
				if(typeof(xmlData[i][0]['title']) != "undefined"){
					str += '&nbsp;<span class="fPath">\/<\/span>&nbsp;';
					str += '<span class="fPath" onclick="javascript: buildDialog(' + currentDialog + ', [' + path + ']);">' + xmlData[i][0]['title'] + '<\/span>';
				} else if(typeof(xmlData[i][0][0]['title']) != "undefined"){
					str += '&nbsp;<span class="fPath">\/<\/span>&nbsp;';
					str += '<span class="fPath" onclick="javascript: buildDialog(' + currentDialog + ', [' + path + ']);">' + xmlData[i][0][0]['title'] + '<\/span>';
				} else
					break;
			} else
				break;
		}
		p.innerHTML = str;
	} else
		return;
}

function closeDialog(){
	if(mydiv = document.getElementById("matrix")){
		mydiv.style.visibility = "hidden";
		mydiv.style.left = "-1000px";
		mydiv.style.top = "-1000px";

		errorFlag = 0;
	}
}

function fInputCheck(response, inp, mode){
	//regError
	if(response){
		if(el = document.getElementById("inp0")){
			if(response.data > 0){
				el.className = checkclasses[1];
				regmatrix[0] = 1;
			} else {
				el.className = checkclasses[2];
				regmatrix[0] = 2;
			}
		}
		return;
	}
	
	
	if(!mode && inp.name == "login" && inp.value != "" && inp.value.match(/^[_a-zA-Zā-žĀ-Ž0-9-]{5,16}$/)){
		put = new Array();
		put[inp.name] = inp.value;
		request(serialize(put), 0, 4);
	
	}
	//alert(  mode);
	
	if (inp){
		if(inp.name == "login" || inp.name == "password" || inp.name == "fpassword2x"){
			if(inp.value == '' || !inp.value.match(/^[_a-zA-Zā-žĀ-Ž0-9-]{4,16}$/)){
				inp.className = checkclasses[1];
				return false;
			} else {
				inp.className = checkclasses[2];
				if(inp.name != "login"){
					if(checkEquals(0) == true)
						return true;
					else
						return false;
				} else
					return true;
			}
		}

		if(inp.name == "firstName" || inp.name == "lastName"){
			if(inp.value == '' || !inp.value.match(/^[_a-zA-Zā-žĀ-Ž]{1,}$/)){
				inp.className = checkclasses[1];
				return false;
			} else {
				inp.className = checkclasses[2];
				return true;
			}
		}

		if(inp.name == "email" || inp.name == "mail2x"){
			if(inp.value == '' || !inp.value.match(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]{2,})+$/)){
				inp.className = checkclasses[1];
				return false;
			}
			else{
				inp.className = checkclasses[2];
				if(checkEquals(1) == true)
					return true;
				else
					return false;
			}
		}

		if(inp.name == "phone" || inp.name == "fax"){
			if(inp.value != ''){
				if(!inp.value.match(/^[0-9]{7,}$/)){
					inp.className = checkclasses[1];
					return false;
				} else {
					inp.className = checkclasses[2];
					return true;
				}
			}
		}
	}
}

function checkEquals(mode){
	switch (mode){
		case 0:
			// password compare
			if(regmatrix[3] == 1 && regmatrix[4] == 1){
				if(pass1 = document.getElementById("inp3")){
					if(pass2 = document.getElementById("inp4")){
						if(pass1.value == '' || pass2.value == '' || pass1.value != pass2.value || pass1.value.length < 5 || pass2.value.length < 5){
							//pass1.className = checkclasses[1];
							pass2.className = checkclasses[1];
							return false;
						} else {
							pass1.className = checkclasses[2];
							pass2.className = checkclasses[2];
							return true;
						}
					}
				}
			}
			break;

		case 1:
			// mail compare
			if(regmatrix[5] == 1 && regmatrix[6] == 1){
				if(pass1 = document.getElementById("inp5")){
					if(pass2 = document.getElementById("inp6")){
						if(pass1.value == '' || pass2.value == '' || pass1.value != pass2.value){
							//pass1.className = checkclasses[1];
							pass2.className = checkclasses[1];
							return false;
						} else {
							pass1.className = checkclasses[2];
							pass2.className = checkclasses[2];
							return true;
						}
					}
				}
			}
			break;
	}
	return false;
}

function fRegButton(){
	if(el = document.getElementById('fmRegButton'))
		if(el.style.visibility == 'hidden')
			el.style.visibility = 'visible';
		else
			el.style.visibility = 'hidden';
}

function submitProfile(mode){
	if(mode){

		//if(!in_array(1, regmatrix)){
		//	popError('all');
		//	return;
		//}

		//if(regmatrix[0] == 2){
		var regVars = [];
		error = 0;
		for(i = 0, imax = 7; i < imax; i++){
			if(el = document.getElementById("inp" + i)){
				if(fInputCheck(false, el, true) == false){
					error = el.name;
					//break;
				} else if(in_array(el.name, regNames)){
					regVars[el.name] = el.value;
				}
			}
		}
		if(error == "mail2x")
			error = 0;
		//alert(checkEquals(0));
		//alert(checkEquals(1));

		if(regmatrix[3] == 1 && regmatrix[4] == 1)
			if(checkEquals(0) == false){
				error = 'password';
			}

		if(regmatrix[5] == 1 && regmatrix[6] == 1)
			if(checkEquals(1) == false){
				error = 'email';
			}

		regVars['id'] = userData.id;

		if(error)
			popError(error);
		else {
			saveForm('forumReg');
			request(serialize(regVars), mode, 5);
		}

	} else {
		if(!in_array(1, regmatrix)){
			popError('all');
			return;
		}

		//if(regmatrix[0] == 2){
		var regVars = [];
		error = 0;
		for(i = 0, imax = 7; i < imax; i++)
			if(el = document.getElementById("inp" + i))
				if(fInputCheck(false, el, true) == false){
					error = el.name;
					break;
				} else if(in_array(el.name, regNames))
					regVars[el.name] = el.value;

		for(i = 0, imax = 2; i < imax; i++)
			if(checkEquals(i) == false){
				error = (i == 0 ? 'password' : 'email');
				break;
			}
		if(error){
			//popError(error);
			popError('all');
		}
		else{
			saveForm('forumReg');
			request(serialize(regVars), mode, 5);
		}
		//} else {
		//	popError('login');
		//}
	}
}

function popError(what){
	if(typeof(forumErrors) == "object"){
		if(mydiv = document.getElementById("matrix")){
			if(t = document.getElementById("fTitle"))
				if(dt = document.getElementById("fDTitle"))
					dt.innerHTML = t.innerHTML;

			if(c = document.getElementById("dContent"))
				c.innerHTML = forumErrors[what];			
			//mydiv.style.width = "500px";
			mydiv.style.width = "auto";
			mydiv.style.left = "450px";
			mydiv.style.top = "300px";
			mydiv.style.visibility = "visible";

			errorFlag = 1;
		}
	}
}

function popResult(response){
	if(errorFlag)return;

	if(response.data['e']){
		if(response.data['e'] == 0){
			popError(response.data['e']);
			if(response.data['e'] == 'login')
				if(el = document.getElementById('inp0'))
					fInputCheck(false, el);
		}
		return;
	}

	//alert(response.data);

	if(typeof(forumResults) == "object"){
		//if(typeof(forumResults[response.data['d']]) != 'undefined' && typeof(forumResults[response.data['d']][response.data['r']]) != 'undefined')
			if(mydiv = document.getElementById("matrix")){
				if(t = document.getElementById("fTitle"))
					if(dt = document.getElementById("fDTitle"))
						dt.innerHTML = t.innerHTML;

				if(c = document.getElementById("dContent"))
					c.innerHTML = forumResults[response.data['d']][response.data['r']];

				mydiv.style.width = "500px";
				mydiv.style.left = "400px";
				mydiv.style.top = "300px";
				mydiv.style.visibility = "visible";
			}
	}

	//buildDialog(1, [], false);
}

function doAction(action, aid){
	request(aid, action, 6);
}

function getPass(){
	if(el = document.getElementById("inp0"))
		if(el.value != ""){
			request(el.value, 0, 7);
		}
}

function saveForm(form){
	if(typeof(window.external) == "oject")
	 	window.external.AutoCompleteSaveForm(document.forms[form]);
}

function showForumStatus(response){
	if(el = document.getElementById("statusInfo")){
		if(forumBlurbs[0]){
			if(parseInt(response.mode) == 1){

				var userNames = [];

				if(response.data != userNames){

					var cnt = 0;

					for(var a in regUsers){
						cnt++;
						for(i = 0, imax = response.data.length; i < imax; i++)
							if(regUsers[a]['id'] == response.data[i]){
								userNames[i] = regUsers[a]['login'];
								continue;
							}
					}

					var needles = ['{online}', '{pop}', '{members}'];
					var replaces = [imax, cnt, userNames.join(', ')]
				} else {
					var cnt = 0;
					for(var a in regUsers){
						cnt++;
					}

					var needles = ['{online}', '{pop}', '{members}'];
					var replaces = [0, cnt, '']
				}

				var str = forumBlurbs[0][response.mode]

				for(i = 0, imax = needles.length; i < imax; i++){
					if(replaces[i])
						str = str.replace(needles[i], replaces[i]);
				}
			} else {
				var needles = ['{online}', '{pop}'];
				var replaces = [response.data, regUsers];
				var str = forumBlurbs[0][response.mode];

				for(i = 0, imax = needles.length; i < imax; i++){
					if(replaces[i])
						str = str.replace(needles[i], replaces[i]);
				}
			}

			el.innerHTML = str;
		}
	}
}

/*
PHP associated
*/

function in_array(n, a){
	if(typeof(a) == "array"){
		for(i = 0, im = a.length; i < im; i++){
			if(a[i] == n)
				return true;
		}

	} else if (typeof(a) == "object"){
		for (var i in a){
			if(a[i] == n)
				return true;
		}
	}
	return false;
}

function array_keys(a){
	var keys = [];
	if(typeof(a) == "array"){
		for(i = 0, im = a.length; i < im; i++){
			if(typeof(a[i]) != 'undefined')
				keys[keys.length] = i;
		}
	} else if (typeof(a) == "object"){
		for (var i in a){
			if(typeof(a[i]) != 'undefined')
				keys[keys.length] = i;
		}
	}
	return keys;
}

/*
//obsolete
function delay(cycle, time, func){
	if(cycle){
		eval(func);
	} else
		setTimeout("delay(1, 0, " + func + ")", time);
}
*/

/*
XML DSO dor non-IE
*/
var sources = document.getElementsByTagName("xml");;
//tags to check
var checkPoints;
//tables in the document
var tables = document.getElementsByTagName("table");

function xmlLoad(matrix){

	var query = new String();

	if(typeof(matrix) == "array")
		query = matrix.join(",");
	else
		query = matrix;

	if(userData.id)
		request(query, userData.id, 10);
	else
		request(query, 0, 10);
}


function xmlPut(response){
	if(ie) {
		if(xmls = document.getElementsByTagName("xml")){
			var d = response.data.length - 2;
			xmlDepth = Math.max(0, d);
			var cnt = 0;
			for (var a in response.data){
				if(parseInt(a) == xmlDepth){
					if(response.data[a].length > 0){
						if(xmls[cnt])
							xmls[cnt].parentElement.innerHTML = '<xml id="srcL' + cnt + '">' + generateXML(response.data[a]) + '</xml>';
					} else {
						if(c = document.getElementById("content")){
							c.innerHTML = forumResults[2][0];
							c.style.visibility = "visible";
						}
					}
					if(cnt < xmls.length)
						cnt++;
				} else if(parseInt(a) > xmlDepth) {
					if(xmls[cnt]){
						xmlData = response.data;
						xmlLevel = parseInt(a);
						xmlDone = 1;
						//xmlNext = 1;

						if(xmlData.length == 4)
							preparePages();
						else
							xmlListener();
					}
					break;
				}

			}
		} else {
			setTimeout('xmlPut(' + response + ')', 100);
		}
	} else {
		document.getElementById("content").style.visibility = "visible";
		xmlData = response.data;
		xmlLevel = xmlData.length - 2;
		xmlDone = 0;

		if(xmlData.length == 4)
			preparePages();
		else
			fillTables();
	}
}

var log = [];
var cnt = [];

function fillTables(){
	if(typeof(xmlData[xmlLevel]) != 'undefined'){
		var tables = document.getElementsByTagName("table");

		var srcstr = '#srcL' + xmlDone;

		cnt[xmlLevel] = 0;

		for(i = 0, imax = tables.length; i < imax; i++){
			if(tables[i].getAttribute('datasrc') != null && tables[i].getAttribute('datasrc') == srcstr){
				if(xmlLevel){
					for(j = 0, jmax = xmlData[xmlLevel][cnt[xmlLevel]].length; j < jmax; j++){
						if(j){
							var clone = tables[i].childNodes[1].cloneNode(true);
							tables[i].appendChild(clone);
//							var spans = clone.getElementsByTagName("SPAN");
//							fillNode(spans, xmlData[xmlLevel][cnt][j]);
						}
					}
				} else {
					for(j = 0, jmax = xmlData[xmlLevel].length; j < jmax; j++){
						if(j){
							var clone = tables[i].childNodes[1].cloneNode(true);
							tables[i].appendChild(clone);
//							var spans = clone.getElementsByTagName("SPAN");
//							fillNode(spans, xmlData[xmlLevel][j]);
						}
					}
				}
				//tables[i].setAttribute('datasrc', (srcstr + cnt[xmlLevel]));
				cnt[xmlLevel]++;
			}
			if(typeof(xmlData[xmlLevel][cnt[xmlLevel]]) == 'undefined')break;
		}
		xmlDone++;
		xmlLevel++;
		fillTables();
	} else {
		constructPath();
		xmlDone--;
		xmlLevel--;
		fillCells();
	}
}
function DUMP(obj,inc)
{
	var res = [];
	if (!inc) inc = 0;
	var app = '';
	for(i=0;i < inc; i++) app += ' ';
	res.push(typeof(obj)+':');
	if (inc && typeof(obj) == 'object') return res.join('');
	switch(typeof(obj))
	{
		case 'object':
			res.push(' {');
			for(a in obj)
			{
				res.push("\n"+app+a+':'+DUMP(obj[a],inc+1));
			}
			break;
		case 'string':
			res.push('"'+obj+'"');
			break;
		default:
			res.push(obj);
			break;
	}
	return res.join('');
}
function fillCells(){
	if(typeof(xmlData[xmlLevel]) != 'undefined'){
		var tables = document.getElementsByTagName("table");
		var srcstr = '#srcL' + xmlDone;
		for(i = tables.length - 1; i > 0; i--){
			if(tables[i].getAttribute('datasrc') != null && tables[i].getAttribute('datasrc') == srcstr){
				var c = 0;
				for(j = 0, jmax = tables[i].childNodes.length; j < jmax; j++){
					if(tables[i].childNodes[j].nodeType != 3 && tables[i].childNodes[j].tagName == "TBODY"){

						var spans = tables[i].childNodes[j].getElementsByTagName("SPAN");

						if(xmlLevel){
							if(typeof(xmlData[xmlLevel][cnt[xmlLevel] - 1][c]) != 'undefined')
								fillNode(spans, xmlData[xmlLevel][cnt[xmlLevel] - 1][c]);
						} else {
							if(typeof(xmlData[xmlLevel][c]) != 'undefined')
								fillNode(spans, xmlData[xmlLevel][c]);
						}


						c++;
					}
				}
				cnt[xmlLevel]--;
			}
			if(typeof(xmlData[xmlLevel][cnt[xmlLevel] - 1]) == 'undefined'){
				break;
			}
		}
		xmlDone--;
		xmlLevel--;
		fillCells();
	} else {

		if(xmlData.length > 2){
			if(t = document.getElementsByName("threadHide")){
				for(i = 0, imax = t.length; i < imax; i++){
					t[i].style.display = "none";
				}
			}

			/*
			if(t1 = document.getElementById("thread1"))
				t1.style.display = "none";

			if(t2 = document.getElementById("thread2"))
				t2.style.display = "none";

			if(t3 = document.getElementById("thread3"))
				t3.style.display = "none";
			*/
		}
		if(userData.id){
			var invisibles = ['editPost'];
			if(invisibles.length > 0)
				for(i = 0, imax = invisibles.length; i < imax; i++)
					if(el = document.getElementById(invisibles[i]))
						el.style.visibility = "visible";

			var nodisplays = [];
			if(nodisplays.length > 0)
				for(i = 0, imax = nodisplays.length; i < imax; i++)
					if(el = document.getElementById(nodisplays[i]))
						el.style.display = "none";

			if(xmlData.length > 2){
				if(nts = document.getElementById("newThread")){
					nts.innerHTML = addThreadTXT;
					nts.style.visibility = "visible";
				}
			}

			postForm = 1;
			buildPostForm();
		}
	}
}


function drawLog(){
	alert(log.join('\n'));
}

//function getChildsByTag(p, tag){
//	var
//
//	return false;
//}

function fillNode(t, inp){
	//alert('t: ' + t + ', inp: ' + inp);

	for(x = 0, imax = t.length; x < imax; x++){
		for(var k in inp){
			//alert('k: ' + k + ', inp[k]: ' + inp[k]);
			if(t[x].getAttribute('datafld') != null && t[x].getAttribute('datafld') == k && t[x].innerHTML == ''){
				t[x].innerHTML = inp[k];
				//break;
			}
		}
	}
	//return false;
}



//var xmlData;
//var xmlLevel;
//var xmlDone;
//var xmlNext;

function preparePages(){
	var l = xmlData[3][0].length;

	if(l > postsPerPage){
		if(el = document.getElementById("pageNav")){

			totalPages = Math.ceil(l / postsPerPage);

			var item = [];
			var sum = 0;
			var str = new String;
			str += '<table cellpadding="0" cellspacing="0" style="padding: 0px 5px 0px 5px !important;"><tr><td style="cusor: hand; cursor: pointer;"><a href="javascript: switchPage(0);"><img src="/pic/arrows/reverse.gif" alt="" /></a></td>';

			if(lastPost){
				currentPage = totalPages - 1;
				lastPost = 0;
			}

			var amp1 = 3;
			var amp2 = 3;
			var total = amp1 + amp2;
			var da = totalPages - currentPage;

			if(da < amp2){
				amp1 = amp2 + amp1 - da;
				amp2 = da;
			}

			var db = currentPage - amp1;

			if(db < 0){
				amp1 = currentPage;
				amp2 = Math.min((totalPages - currentPage), (total - amp1));
			}

			var c = 0;
			for(i = 0; i < totalPages; i++){
				item = [];
				for(j = 0; j < postsPerPage; j++){

					item[item.length] = xmlData[3][0][sum];
					if(sum < (l - 1))
						sum++;
					else
						break;
				}
				xmlPages[i] = item;

				if(i < (currentPage - amp1) && c == 0)
				str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">...</a></td>';

				if(i >= (currentPage - amp1) && i < (currentPage + amp2))
					str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">' + (i + 1) + '</a></td>';

				if(i >= (currentPage + amp2) && c >= i){
					str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">...</a></td>';
					c = 0;
				}

				c++;
			}
			//alert(currentPage);
			if(xmlPages.length != totalPages)
				totalPages = xmlPages.length;

			xmlData[3][0] = xmlPages[currentPage];

			str += '<td style="cusor: hand; cursor: pointer;"><a href="javascript: switchPage(' + totalPages + ');"><img src="/pic/arrows/forward.gif" alt="" /></a></td><td style="width: 95%;">&nbsp;</td></tr></table>';

			el.innerHTML = str;
		} else
			totalPages = 0;
	} else
		totalPages = 0;

	if(ie)
		xmlListener();
	else
		fillTables();
}

function redrawPages(){
	if(el = document.getElementById("pageNav")){
		var str = new String;
		str += '<table cellpadding="0" cellspacing="0" style="padding: 0px 5px 0px 5px !important;"><tr><td style="cusor: hand; cursor: pointer;"><a href="javascript: switchPage(0);"><img src="/pic/arrows/reverse.gif" alt="" /></a></td>';

		var amp1 = 3;
		var amp2 = 3;
		var total = amp1 + amp2;
		var da = totalPages - currentPage;

		if(da < amp2){
			amp1 = amp2 + amp1 - da;
			amp2 = da;
		}

		var db = currentPage - amp1;

		if(db < 0){
			amp1 = currentPage;
			amp2 = Math.min((totalPages - currentPage), (total - amp1));
		}

		var c = 0;
		for(i = 0; i < totalPages; i++){
			if(i < (currentPage - amp1) && c == 0)
				str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">...</a></td>';

			if(i >= (currentPage - amp1) && i < (currentPage + amp2))
				str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">' + (i + 1) + '</a></td>';

			if(i >= (currentPage + amp2) && c >= i){
				str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">...</a></td>';
				c = 0;
			}

			c++;
		}

		str += '<td style="cusor: hand; cursor: pointer;"><a href="javascript: switchPage(' + totalPages + ');"><img src="/pic/arrows/forward.gif" alt="" /></a></td><td style="width: 95%;">&nbsp;</td></tr></table>';

		el.innerHTML = str;
	}
}

function switchPage(val){

	if(ie){
		var xmls = document.getElementsByTagName("xml");

		if(val < 0)
			val = 0;
		if(val > (xmlPages.length - 1))
			val = xmlPages.length - 1;

		var xmlId = xmls[xmls.length - 1].id;

		//xmls[xmls.length - 1].parentElement.innerHTML = '<xml id="' + xmlId + '">' + generateXML(xmlPages[val]) + '</xml>';

		currentPage = val;
		document.location = addy + '?gid=' + (typeof(currentPath[0]) != 'undefined' ? currentPath[0] : 0) + '&fid=' + (typeof(currentPath[1]) != 'undefined' ? currentPath[1] : 0) + '&tid=' + (typeof(currentPath[2]) != 'undefined' ? currentPath[2] : 0) + '&cd=' + currentDialog + '&cp=' + currentPage;

		/*
		if(el = document.getElementById("pageNav")){
			for(i = 1, imax = el.firstChild.firstChild.firstChild.childNodes.length - 2; i < imax; i++){
				if((i - 1) == val)
					el.firstChild.firstChild.firstChild.childNodes[i].firstChild.className = 'psdSel';
				else
					el.firstChild.firstChild.firstChild.childNodes[i].firstChild.className = 'psdUnsel';
			}
		}
		*/

		redrawPages();

	} else {
		currentPage = val;
		document.location = addy + '?gid=' + (typeof(currentPath[0]) != 'undefined' ? currentPath[0] : 0) + '&fid=' + (typeof(currentPath[1]) != 'undefined' ? currentPath[1] : 0) + '&tid=' + (typeof(currentPath[2]) != 'undefined' ? currentPath[2] : 0) + '&cd=' + currentDialog + '&cp=' + currentPage;

		if(el = document.getElementById("pageNav")){

			var sum = 0;
			var str = new String;
			str += '<table cellpadding="0" cellspacing="0" style="padding: 0px 5px 0px 5px !important;"><tr><td style="cusor: hand; cursor: pointer;"><a href="javascript: switchPage(0);"><img src="/pic/arrows/reverse.gif" alt="" /></a></td>';

			var amp1 = 3;
			var amp2 = 3;
			var total = amp1 + amp2;
			var da = totalPages - currentPage;

			if(da < amp2){
				amp1 = amp2 + amp1 - da;
				amp2 = da;
			}

			var db = currentPage - amp1;

			if(db < 0){
				amp1 = currentPage;
				amp2 = Math.min((totalPages - currentPage), (total - amp1));
			}

			var c = 0;
			for(i = 0; i < totalPages; i++){

				if(i < (currentPage - amp1) && c == 0)
				str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">...</a></td>';

				if(i >= (currentPage - amp1) && i < (currentPage + amp2))
					str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">' + (i + 1) + '</a></td>';

				if(i >= (currentPage + amp2) && c >= i){
					str += '<td><a class="' + (currentPage == i ? 'psdSel' : 'psdUnsel') + '" href="javascript: switchPage(' + i + ');">...</a></td>';
					c = 0;
				}

				c++;
			}
			//alert(xmlPages);
			//alert(currentPage);
			//alert(generateXML(xmlData[3][0]));
			//alert(generateXML(xmlPages[currentPage]));

			xmlData[3][0] = xmlPages[currentPage];

			//alert(generateXML(xmlData[3][0]));

			str += '<td style="cusor: hand; cursor: pointer;"><a href="javascript: switchPage(' + totalPages + ');"><img src="/pic/arrows/forward.gif" alt="" /></a></td><td style="width: 95%;">&nbsp;</td></tr></table>';

			xmlLevel = xmlData.length - 2;
			xmlDone = 0;

			d = document.getElementById("forum");
			d.innerHTML = forumModes[3];
			document.getElementById("content").style.visibility = "visible";
			fillTables();
			el = document.getElementById("pageNav")
			el.innerHTML = str;
			loadForumStatus();
		}
	}
	oddColors();
}

function putSrc(xmls, needles, replaces, data){
	for(i = xmlDone, imax = xmls.length; i < imax; i++){
		curPos = i - xmlDone;
		needles[needles.length] = "#srcL" + (xmlLevel - xmlDepth);

		if(data[curPos]){
			xmls[i].parentElement.innerHTML = '<xml id="srcL' + xmlLevel + curPos + '">' + generateXML(data[curPos]) + '</xml>';
			replaces[replaces.length] = "#" + xmls[i].id;
		} else {
			xmls[i].parentElement.innerHTML = '<xml id="srcL' + xmlLevel + curPos + '"></xml>';
			replaces[replaces.length] = 0;
		}
	}
	xmlDone = imax;
}

function xmlListener(){
	//alert(xmlLevel + ' : ' + xmlData[xmlLevel])

	if(typeof(xmlData[xmlLevel]) == "undefined"){
		if(el = document.getElementsByName("fbuttons")){
			if(el.length > 1)
				for(i = 1, imax = el.length; i < imax; i++){
					el[i].style.display = "none";
				}
		}
		constructPath();

		var xmls = document.getElementsByTagName("xml");

		if(xmls.length < 2) {
			setTimeout('xmlListener()', 100);
			return;
		}

		var tables = document.getElementsByTagName("table");

		for(i = (tables.length - 1); i > 0; i--){
			if(typeof(tables[i].dataSrc) != "undefined" && tables[i].dataSrc != ""){
				for(j = (xmls.length - 1); j > 0; j--){
					if(("#" + xmls[j].id) == tables[i].dataSrc){
						if((xmls[j].childNodes[1].childNodes.length * xmlRowsBefore) <= tables[i].rows.length){
							if(buildPostForm()){
								clearTimeout("xmlListener");
								xmlExit();
							}
						} else
							setTimeout('xmlListener()', 200);
						break;
					}
				}
				break;
			}
		}

	} else {

		if(userData.id){
			var invisibles = ['editPost'];
			if(invisibles.length > 0)
				for(i = 0, imax = invisibles.length; i < imax; i++)
					if(el = document.getElementById(invisibles[i]))
						el.style.visibility = "visible";

			var nodisplays = [];
			if(nodisplays.length > 0)
				for(i = 0, imax = nodisplays.length; i < imax; i++)
					if(el = document.getElementById(nodisplays[i]))
						el.style.display = "none";

			if(xmlData.length > 2){
				if(nts = document.getElementById("newThread")){
					nts.innerHTML = addThreadTXT;
					nts.style.visibility = "visible";
				}
			}
		}
		if(xmlData.length > 2){

			if(t1 = document.getElementById("thread1"))
				t1.style.display = "none";

			if(t2 = document.getElementById("thread2"))
				t2.style.display = "none";

			if(t3 = document.getElementById("thread3"))
				t3.style.display = "none";
		}

		var xmls = document.getElementsByTagName("xml");

		if(xmlData[xmlLevel - 1])
			xmlNext = xmlDone + xmlData[xmlLevel - 1].length;
		else
			xmlNext = xmlDone;

		if((xmls.length + xmlDepth) >= xmlNext){
			var tables = document.getElementsByTagName("table");

			var needles = [];
			var replaces = [];

			putSrc(xmls, needles, replaces, xmlData[xmlLevel]);

			cnt = 0;
			for(j = 0, jmax = tables.length; j < jmax; j++){
				if(typeof(tables[j].dataSrc) != "undefined" && tables[j].dataSrc != ""){
					if(tables[j].dataSrc == needles[cnt]){
						if(replaces[cnt]){
							xmlRowsBefore = tables[j].rows.length;
							tables[j].dataSrc = replaces[cnt];
						} else
							tables[j].parentElement.style.display = "none";
						cnt++;
					}
				}
			}
			xmlLevel++;

			setTimeout('xmlListener()', 200);
		} else
			setTimeout('xmlListener()', 200);
	}
}

function xmlExit(){
	if(postForm){
		setTimeout("xmlExit", 200);
	} else {
		window.clearTimeout("xmlListener");
		window.clearTimeout("xmlExit");
		document.getElementById("content").style.visibility = "visible";
		return;
	}
}

function groupPath(ref){
	if(ie){
		invoker = window.event.srcElement

		var path = [];

		switch(invoker.tagName){
			case 'TD':

				//if(currentPath.length > 0)
				//	path[1] = invoker.parentElement.parentElement.firstChild.firstChild.firstChild.innerHTML;
				//else
					var dataHolder = invoker.parentElement.parentElement.firstChild.firstChild;

				break;
			case 'SPAN':

				//if(currentPath.length > 0)
				//	path[1] = invoker.parentElement.parentElement.parentElement.firstChild.firstChild.firstChild.innerHTML;
				//else
					var dataHolder = invoker.parentElement.parentElement.parentElement.firstChild.firstChild;

				break;
		}
		if(dataHolder){
			for(i = dataHolder.childNodes.length - 1; i >= 0; i--)
				if(dataHolder.childNodes[i].innerHTML != "")
					path[path.length] = dataHolder.childNodes[i].innerHTML;

			buildDialog(currentDialog, path);
		}
	} else {
		var dataHolder = ref.childNodes[1].childNodes[1].childNodes[0].childNodes[1];
		var path=[];

		if(dataHolder){
			for(i = dataHolder.childNodes.length - 1; i >= 0; i--)
				if(dataHolder.childNodes[i].nodeType != 3 && dataHolder.childNodes[i].innerHTML != "")
					path[path.length] = dataHolder.childNodes[i].innerHTML;

			buildDialog(currentDialog, path);
		}
	}
}

function forumPath(ref){
	if(ie){
		invoker = window.event.srcElement

		var path = [];
		//path = currentPath;

		switch(invoker.tagName){
			case 'TD':
				if(typeof(invoker.id) == "undefined" || invoker.id == "")
					var dataHolder = invoker.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.firstChild.firstChild;
				else
					var dataHolder = invoker.parentElement.parentElement.parentElement.firstChild.firstChild.firstChild;
				break;
			case 'SPAN':
				var dataHolder = invoker.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.firstChild.firstChild;

				//if(invoker.dataFld == "title"){
				//	alert(invoker.parentElement.innerHTML);
				//} else if(invoker.dataFld == "short") {
				//
				//}

				break;
			case 'IMG':
				var dataHolder = invoker.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.firstChild.firstChild.firstChild;

				break;
		}
		if(dataHolder){
			for(i = dataHolder.childNodes.length - 1; i >= 0; i--)
				if(dataHolder.childNodes[i].innerHTML != "")
					path[path.length] = dataHolder.childNodes[i].innerHTML;
			//alert(path);

			buildDialog(currentDialog, path, false);
		}
	} else {
		var dataHolder = ref.parentNode.parentNode.childNodes[0].childNodes[1];
		var path=[];

		if(dataHolder){
			for(i = dataHolder.childNodes.length - 1; i >= 0; i--)
				if(dataHolder.childNodes[i].nodeType != 3 && dataHolder.childNodes[i].innerHTML != "")
					path[path.length] = dataHolder.childNodes[i].innerHTML;

			buildDialog(currentDialog, path, false);
		}

		/*
		var path = [];
		//path = currentPath;

		switch(invoker.tagName){
			case 'TD':
				if(typeof(invoker.id) == "undefined" || invoker.id == "")
					var dataHolder = invoker.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.firstChild.firstChild;
				else
					var dataHolder = invoker.parentElement.parentElement.parentElement.firstChild.firstChild.firstChild;
				break;
			case 'SPAN':
				var dataHolder = invoker.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.firstChild.firstChild;

				//if(invoker.dataFld == "title"){
				//	alert(invoker.parentElement.innerHTML);
				//} else if(invoker.dataFld == "short") {
				//
				//}

				break;
			case 'IMG':
				var dataHolder = invoker.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.firstChild.firstChild.firstChild;

				break;
		}
		if(dataHolder){
			for(i = dataHolder.childNodes.length - 1; i >= 0; i--)
				if(dataHolder.childNodes[i].innerHTML != "")
					path[path.length] = dataHolder.childNodes[i].innerHTML;
			//alert(path);

			buildDialog(currentDialog, path);
		}
		*/
	}
}

function xmlTest(){
	var tbls = document.getElementsByTagName("table");
	var xmls = document.getElementsByTagName("xml");
	var dtbls = 0;
	var dsrcs = [];

	alert("total tables: " + tbls.length + ", total xml data islands: " + xmls.length);

	for(i = 0, imax = tbls.length; i < imax; i++){
		if(tbls[i].datasrc != "undefined" && tbls[i].datasrc != ""){
			dtbls++;
			dsrcs[dsrcs.length] = tbls[i].datasrc;
		}
	}

	alert("total data bind tables: " + dtbls + ", datasrc string: " + dsrcs.join("\n"));
}

//function xmlSet() {
//	if(ie.test(navigator.appName)) {
//		var loaded = 0;
//
//		for(i = 0, imax = sources.length; i < imax; i++)
//			if(sources[0].parsed == true)
//				loaded++;
//
//		if(loaded == sources.length){
//			//nothing
//		} else {
//			setTimeout("xmlSet()", 200);
//		}
//	}
//}

function oddColors(){
	if(tables = document.getElementsByTagName("table")){
		var cnt = 0;
		for(i = 0, imax = tables.length; i < imax; i++)
			if(typeof(tables[i].dataSrc) != "undefined" && tables[i].dataSrc != "")
				if(!cnt)
					cnt++;
				else {
					var n = 0;
					for(j = 0, jmax = tables[i].rows.length; j < jmax; j++){
						if(n > 3)
							for(x = 0, xmax = tables[i].rows[j].cells.length; x < xmax; x++)
								tables[i].rows[j].cells[x].style.background = "#eee";
						if(n > 4)
							n = 0;
						else
							n++;
					}
				}
	}
}

function buildPostForm(){	
	if(postForm > 0){
		if( userData.id ){			
			if( el = document.getElementById( "p1" ) ){				
				el.style.display = "";
			}

			if(subj = document.getElementById("title"))
				subj.value = "RE: " + xmlData[3][0][0]['title'];
			if(!ie){
				if(div = document.getElementById("short"))
					div.parentNode.innerHTML = '<textarea class="frInput" id="short" name="short" value="" style="height: 150px; width: 100%;"></textarea>';
			}

		}
		oddColors();

		postForm = 0;
	}

	return true;
}

function submitNewThread(){
	if( userData.id ){		
		var matrix = [];

		for(i = 0, imax = currentPath.length; i < imax; i++)
			matrix[matrix.length] = currentPath[i];

		if( subj = document.getElementById("newtitle") )
			if(subj.value != ''){
				if(subj.value.length > 64){
					alert("Please do not enter more than 64 symbols in the subject field of your post.");
					return false;
				}
				else{					
					var str = [];
					str = subj.value.split(',');
					matrix[matrix.length] = str.join(':comma:');					
				}
			}
			else{
				alert("Please type in a title for your post.");
				return false;
			}
		if(ie){
			if(el = document.getElementById("short"))
				if(el.innerHTML != '')
					if(el.innerHTML.length > 1024){
						alert("Please do not enter more than 1024 symbols in your post.");
						return false;
					}
					else{						
						var str = [];
						str = el.innerHTML.split(',');
						matrix[matrix.length] = str.join(':comma:');						
					}
				else {
					alert("The post is empty. Please write the post and then submit it.");
					return false;
				}				
		}
		else{
			if(el = document.getElementById("short"))
				if(el.value != '')
					if(el.value.length > 1024){
						alert("Please do not enter more than 1024 symbols in your post.");
						return false;
					} else {
						var str = [];
						str = el.value.split(',');
//						matrix[matrix.length] = escape(str.join(':comma:'));
						matrix[matrix.length] = str.join(':comma:');
					}
				else {
					alert("The post is empty. Please write the post and then submit it.");
					return false;
				}
		}		
		if( editing ){
			if( editID ){
				matrix[matrix.length] = editID;
				request(matrix, userData.id, 12);
			}
			else
				request(matrix, userData.id, 11);
		}
		else{			
			request(matrix, userData.id, 13);
		}
	}
	else
		alert('Only registered and logged in users may post replies! Please log in or register if you have not done it.');
}

function submitPost(){
	if( userData.id ){		
		var matrix = [];

		for(i = 0, imax = currentPath.length; i < imax; i++)
			matrix[matrix.length] = currentPath[i];

		if(subj = document.getElementById("title"))
			if(subj.value != ''){
				if(subj.value.length > 64){
					alert("Please do not enter more than 64 symbols in the subject field of your post.");
					return false;
				} else {
					var str = [];
					str = subj.value.split(',');
//					matrix[matrix.length] = escape(str.join(':comma:'));
					matrix[matrix.length] = str.join(':comma:');
				}
			} else {
				alert("Please type in a title for your post.");
				return false;
			}
		if(ie){
			if(el = document.getElementById("short"))
				if(el.innerHTML != '')
					if(el.innerHTML.length > 1024){
						alert("Please do not enter more than 1024 symbols in your post.");
						return false;
					} else {
						var str = [];
						str = el.innerHTML.split(',');
//						matrix[matrix.length] = escape(str.join(':comma:'));
						matrix[matrix.length] = str.join(':comma:');
					}
				else {
					alert("The post is empty. Please write the post and then submit it.");
					return false;
				}
		} else {
			if(el = document.getElementById("short"))
				if(el.value != '')
					if(el.value.length > 1024){
						alert("Please do not enter more than 1024 symbols in your post.");
						return false;
					} else {
						var str = [];
						str = el.value.split(',');
//						matrix[matrix.length] = escape(str.join(':comma:'));
						matrix[matrix.length] = str.join(':comma:');
					}
				else {
					alert("The post is empty. Please write the post and then submit it.");
					return false;
				}
		}

		if(editing){
			if(editID){
				matrix[matrix.length] = editID;
				request(matrix, userData.id, 12);
			} else
				request(matrix, userData.id, 11);
		} else
			request(matrix, userData.id, 11);
	} else
		alert('Only registered and logged in users may post replies! Please log in or register if you have not done it.');
}

function editPost(ref, quote){

	if(!userData.id){
		alert("You need to be registered and logged in to edit or post in forum.");
		return false;
	}
	//alert(ref.tagName);
	var t = ref.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.firstChild.firstChild.innerHTML;
	var s = ref.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.nextSibling.childNodes[1].firstChild.firstChild.firstChild.firstChild.firstChild.innerHTML;
	var pid = ref.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.previousSibling.firstChild.firstChild.innerHTML;

	editing = 1;

	if(subj = document.getElementById("title"))
		subj.value = t;

	if(el = document.getElementById("short"))
		el.innerHTML = s;

	if(quote)
		editID = 0;
	else
		editID = pid;
}

function postListener(response){
	if(parseInt(response.data) == 1){
		lastPost = 1;
		buildDialog(currentDialog, currentPath);
		editing = 0;
		editID = 0;
	} else {
		alert('There was a problem inserting your post. Try posting again and/or reloading the screen. Apologies for inconvenience');
		editing = 0;
		editID = 0;
	}
}

function toLastPost(){
	if(lastPost > 0){
		if(pc = document.getElementByID("postContainer")){
			//alert(pc.offsetHeight);
			//window.scroll(pc.offsetHeight, 0);
		}
		lastPost = 0;
	}

	return true;
}

function addThread(){
	if(userData.id){
		if(el = document.getElementById("p2"))
			el.innerHTML = addThreadHTML;

		if(!ie){
			if(div = document.getElementById("short"))
				div.parentNode.innerHTML = '<textarea class="frInput" id="short" name="short" value="" style="height: 150px; width: 100%;"></textarea>';
			else
				setTimeout("replaceP2()", 200);
		}
	}
}

function replaceP2(){
	if(div = document.getElementById("short"))
		div.parentNode.innerHTML = '<textarea class="frInput" id="short" name="short" value="" style="height: 150px; width: 100%;"></textarea>';
	else
		setTimeout("replaceP2()", 200);
}

function submitThread(){
	if(userData.id){		
		var matrix = [];

		for(i = 0, imax = currentPath.length; i < imax; i++)
			matrix[matrix.length] = currentPath[i];

		if(subj = document.getElementById("title"))
			if(subj.value != ''){
				if(subj.value.length > 64){
					alert("Please do not enter more than 64 symbols in the title field of your thread.");
					return false;
				} else {
					var str = [];
					str = subj.value.split(',');
					matrix[matrix.length] = escape(str.join(':comma:'));
				}
			} else {
				alert("Please type in a title for your thread.");
				return false;
			}

		if(ie){
			if(el = document.getElementById("short"))
				if(el.innerHTML != '')
					if(el.innerHTML.length > 1024){
						alert("Please do not enter more than 1024 symbols in your post.");
						return false;
					} else {
						var str = [];
						str = el.innerHTML.split(',');
						matrix[matrix.length] = escape(str.join(':comma:'));
					}
				else {
					alert("The post is empty. Please write the post and then submit it.");
					return false;
				}
		} else {
			if(el = document.getElementById("short"))
				if(el.value != '')
					if(el.value.length > 1024){
						alert("Please do not enter more than 1024 symbols in your post.");
						return false;
					} else {
						var str = [];
						str = el.value.split(',');
						matrix[matrix.length] = escape(str.join(':comma:'));
					}
				else {
					alert("The post is empty. Please write the post and then submit it.");
					return false;
				}
		}

		//alert('ready!');
		request(matrix, userData.id, 13);
	} else
		alert('Only registered and logged in users may post replies! Please log in or register if you have not done it.');
}

function threadListener(response){
	if(parseInt(response.data) == 1)
		buildDialog(currentDialog, currentPath);
	else
		alert('There was a problem inserting your thread. Try posting again and/or reloading the screen. Apologies for inconvenience');
}

//XML generation
function recurseXML(d, x){
	if((typeof(d) == "array" && d.length)){
		for(k = 0, kmax = d.length; k < kmax; k++){
			if((typeof(d[k]) == "array" && d[k].length) || (typeof(d[k]) == "object" && d[k] != "{}")){
				if(parseInt(k) == k){
					if(x[x.length - 1] && x[x.length - 1] != "<item>")
						x[x.length] = "<item>";
				} else {
					x[x.length] = "<" + k + ">";
				}

				recurseXML(d[k], x);

				if(parseInt(k) == k){
					if(x[x.length - 1] && x[x.length - 1] != "</item>")
						x[x.length] = "</item>";
				} else {
					x[x.length] = "</" + k + ">";
				}
			} else {
				if(parseInt(k) == k){
					x[x.length] = "<item>" + d[k] + "</item>";
				} else {
					x[x.length] = "<" + k + ">" + d[k] + "</" + k + ">";
				}
			}
		}
	} else if (typeof(d) == "object" && d != "{}") {
		for(var k in d){
			if((typeof(d[k]) == "array" && d[k].length) || (typeof(d[k]) == "object" && d[k] != "{}")){
				if(parseInt(k) == k){
					if(x[x.length - 1] && x[x.length - 1] != "<item>")
						x[x.length] = "<item>";
				} else {
					x[x.length] = "<" + k + ">";
				}

				recurseXML(d[k], x);

				if(parseInt(k) == k){
					if(x[x.length - 1] && x[x.length - 1] != "</item>")
						x[x.length] = "</item>";
				} else {
					x[x.length] = "</" + k + ">";
				}
			} else {
				if(parseInt(k) == k){
					x[x.length] = "<item>" + d[k] + "</item>";
				} else {
					x[x.length] = "<" + k + ">" + d[k] + "</" + k + ">";
				}
			}
		}
	}
}

function generateXML(d){

	x = [];

	x[0] = "<\?xml version=\"1.0\"\?><list>";

	recurseXML(d, x);

	x[x.length] = "</list>";

	return x.join("");
}


/*
Post Specific
*/

var flgCode = false;
function codeClick(item){
	if (flgCode){
		var tag = "[/CODE]";
		flgCode = false;
	} else {
		var tag = "[CODE]";
		flgCode = true;
	}

	if (ie){
		var body = document.getElementById( "body" );
		body.innerHTML += tag;
	} else
		document.forms["frmNewPost"].body.value += tag;
}

function boldClick(item){
	if(ie)
		document.execCommand("Bold");
	else
		document.forms["frmNewPost"].body.value += "<b> </b>";

	//checkCommand("Bold");
}

function italicClick(item){
	if(ie)
		document.execCommand("Italic");
	else
		document.forms["frmNewPost"].body.value += "<i> </i>";

	//checkCommand("Italic");
}

function underlineClick(item){
	if(ie)
		document.execCommand("Underline");
	else
		document.forms["frmNewPost"].body.value += "<u> </u>";

	//checkCommand("Underline");
}

function checkCommand(which){
	if(el = document.getElementById("short")){
		alert(el.isContentEditable);
	}

	alert('enabled: ' + document.queryCommandEnabled(which));
	alert('indeterminate: ' + document.queryCommandIndeterm(which));
	alert('state: ' + document.queryCommandState(which));
	alert('supported: ' + document.queryCommandSupported(which));
	alert('value: ' + document.queryCommandValue(which));
}

/*
function fillFields(item){
	if(ie){
		var body = document.getElementById( "body" );
		var hiddenBody = document.forms["frmNewPost"].hiddenBody;
		hiddenBody.value = body.innerHTML;
	}
	else {
		var hiddenBody = document.forms["frmNewPost"].hiddenBody;
		hiddenBody.value = document.forms["frmNewPost"].body.value;
	}
	return true;
}


//function insertSmile(smile){
//	if(ie){
//		var short = document.getElementById("short");
//		short.innerHTML += smile;
//	} else {
//		document.forms["frmNewPost"].body.value += " :" + smile + ": ";
//	}
//}
*/
/*
Clock
*/
var clockID = 0;
var clock = 0;

function updateClock() {
	if(clock = document.getElementById("postClock")){
		if(clockID) {
			clearTimeout(clockID);
			clockID = 0;
		}

		var tDate = new Date();

		str = new String();

		str += tDate.getYear().toString();
		str += "-";
		str += ((tDate.getMonth() + 1).toString().length < 2 ? "0" + (tDate.getMonth() + 1).toString() : (tDate.getMonth() + 1).toString());
		str += "-";
		str += (tDate.getDate().toString().length < 2 ? "0" + tDate.getDate().toString() : tDate.getDate().toString());
		str += "&nbsp;";
		str += (tDate.getHours().toString().length < 2 ? "0" + tDate.getHours().toString() : tDate.getHours().toString());
		str += ":";
		str += (tDate.getMinutes().toString().length < 2 ? "0" + tDate.getMinutes().toString() : tDate.getMinutes().toString());
		str += ":";
		str += (tDate.getSeconds().toString().length < 2 ? "0" + tDate.getSeconds().toString() : tDate.getSeconds().toString());;

		clock.innerHTML = str;

		clockID = setTimeout("updateClock()", 1000);
	} else
		clockID = setTimeout("updateClock()", 1000);
}
function startClock() {
	clockID = setTimeout("updateClock()", 500);
}

function killClock() {
	if(clockID) {
		clearTimeout(clockID);
		clockID = 0;
	}
}

function highlight(obj , on)
{
    if (on)
    {
        document.getElementById(obj).style.color = '#777777';
    }
    else
    {
        document.getElementById(obj).style.color = '#000';
    }
}


function openImagePopup( popupHref, popupName ){
	msgWindow = window.open( popupHref, popupName, "width=650,height=600,menubar=no,scrollbars=yes");
}


function test(){
	alert(1);
}