
//window.status += 'a ';

function sequel(prelude) {
	document.writing.prelude.value = prelude;
	location.hash = 'writing';
	document.writing.beiras.focus();
}

function insertNewTag(){
/*
	for (var i=0;i<=fileNum;i++) {
		if (document.getElementsByName("file"+ i).length > 0) {
			if (document.getElementsByName("file"+ i).item(0).value=='') {
				removeTag(i);
			}
		}
	}
*/
	if(maxFileNum > numOfTags) {
		fileNum++;
		numOfTags++;
		containerTag = document.getElementById("container");
		newTag = document.createElement("SPAN");
		containerTag.appendChild(newTag);
		newTag.setAttribute("id", "span"+ fileNum);
		newTag.innerHTML += "<br /><input type='file' name='file"+ fileNum +"' size='72'>";
		newTag.innerHTML += "<input type='button' name='"+ fileNum +"' value='Melléklet törlése' class='forumbutton' onclick=\"removeTag("+ fileNum +")\">";
	}
}

//window.status += 'abc ';

function removeTag(num) {
	oldTag = document.getElementById("span"+ num);
	oldTag.innerHTML = "";
	numOfTags--;
	}

function addTag(tag) {
	document.writing.beiras.focus();
	if (window.getSelection) {
		var beiras = document.writing.beiras;
		var selStart = beiras.selectionStart;
		var selEnd = beiras.selectionEnd;
		beiras.value = beiras.value.substring(0, selStart)
			+"["+ tag +"]"
			+ beiras.value.substring(selStart, selEnd)
			+"[/"+ tag +"]"
			+ beiras.value.substring(selEnd);
		beiras.setSelectionRange(selStart + tag.length + 2, selEnd + tag.length + 2);
	} else if (document.selection) {
		active = document.selection.createRange();
		var ranLen = active.text.length;
		active.text = "["+ tag +"]"+ active.text +"[/"+ tag +"]";
		active.moveStart("character",-(ranLen+tag.length+3));
		active.moveEnd("character",-(tag.length+3));
		active.select();
	}
}

function checkIrcForm() {

	formErrors = '';
	if (document.forms['irc'].irc_nick.value.length < 2) {
		formErrors = "Nem adtál meg nicknevet!";
	}
	if (document.forms['irc'].fullname.value.length < 2 || !document.forms['irc'].fullname.value.match(/[\wáÁéÉíÍóÓöÖõÕúÚüÜûÛ]{2,} [\wáÁéÉíÍóÓöÖõÕúÚüÜûÛ]{2,}/)) {
		formErrors += "\nNem, vagy nem jól adtad meg a teljes nevedet!";
	}

	if (formErrors) {
		alert(formErrors);
	} else {
		window.open("../irc/irc.php?nick="+document.forms['irc'].nick.value+"&fullname="+document.forms['irc'].fullname.value+"&password="+document.forms['irc'].password.value, "makettinfo_irc", "left=0,top=0,toolbar=0,status=0,scrollbars=1,resizable=1");
	}

	return false;
}

function checkForm() {

	document.writing.elkuld_nobot.onclick = function() {return false;};

	if (document.writing.beiras.value.match(/(http:\/\/)|(www\.)/) && !document.writing.beiras.value.match(/\[URL\]/)) {
		if (!confirm('Ugye ismered a linkek létrehozásának módját? Ha még nem, kérlek, nézz be "A LINK GOMB HASZNÁLATA!" c. topikba, illetve próbálkozz a LINK gombbal.\n\nHa elküldés elõtt szeretnéd helyesen megadni a link(ek)et, kattints a Mégse gombra.\nKöszönjük, további jó fórumozást!')) {
			document.writing.elkuld_nobot.onclick = function() {};
			return false;
		} else {
			window.open('forszoveg.php?forumID=242', '_blank');
		}
	}
	var formErrors = '';
	var email_pattern1 = /^(\s*)(([0-9a-zA-Z_\-]*[a-zA-Z][0-9a-zA-Z_\-]*)\.?)+@(([0-9a-zA-Z_\-]*[a-zA-Z][0-9a-zA-Z_\-]*)\.?){2,}\.[a-zA-Z]+(\s*)$/
	var email_pattern2 = /^(\s*)(([0-9a-zA-Z_\-]*[a-zA-Z][0-9a-zA-Z_\-]*)\.?)+@[0-9]{1,3}(\.[0-9]{1,3}){3}(\s*)$/
	var email_pattern3 = /^(\s*)\S{2,}@\S{2,}\.\S{2,}(\s*)$/
	var nick_pattern1 = /^(\s*)[\w\d\-\_\.]*[\w\d][\w\d\-\_\.]*(\s*)$/
	var nick_pattern2 = /^(\s*)\S{3,}(\s*)$/
	var nick_pattern3 = /^(\s*)([\w\d\-\_\.áÁéÉíÍóÓöÖõÕúÚüÜûÛ]*[\w\dáÁéÉíÍóÓöÖõÕúÚüÜûÛ][\w\d\-\_\.áÁéÉíÍóÓöÖõÕúÚüÜûÛ]*(\s*))+$/

	var nick = document.writing.nick.value;
	if (!(nick.match(nick_pattern3) && nick.match(nick_pattern2))) {
		formErrors = "Nem, vagy nem jól adtad meg a nick-nevedet! (A névben nem szerepelhetnek különleges karakterek!)";
		document.writing.nick.focus();
	}
	var email = document.writing.email.value;
	if (!((email.match(email_pattern1) || email.match(email_pattern2)) && email.match(email_pattern3))) {
		formErrors += "\nNem, vagy nem jól adtad meg az email-címedet!";
		document.writing.email.focus();
	}
	if (document.writing.beiras.value.length < 2) {
		formErrors += "\nNem küldhetsz üres hozzászólást!";
		document.writing.beiras.focus();
	}

	if (formErrors != '') {
		alert(formErrors);
		document.writing.elkuld_nobot.onclick = function() {};
		return false;
	} else {
		var now = new Date();
		document.writing.sended.value = now.getTime();
		return true;
	}
}

function showIrcChannels() {
	document.getElementById('ircchannels').style.display = 'inline';
}

function hideIrcChannels() {
	document.getElementById('ircchannels').style.display = 'none';
}

function ircchannels_moov() {
	return ajax_post_sync("ircbot/irc_info.php", null);
}

function ajax_post_sync(url, content) {
	if (window.XMLHttpRequest) {
		try {
			var xmlHttp = new XMLHttpRequest();
		} catch (ex) {}
	} else if (window.ActiveXObject) {
		try {
			var xmlHttp = new ActiveXObject("MsXml2.XmlHttp");
		} catch (ex) {}
	}
	
	xmlHttp.open('POST', url, false);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=win-1250');
	xmlHttp.setRequestHeader('Accept-Encoding', 'win-1250');
	xmlHttp.send(content);
	return xmlHttp.responseText;
}

function ajax_post_async(url, content, callback) {
	if (window.XMLHttpRequest) {
		try {
			var xmlHttp = new XMLHttpRequest();
		} catch (e) {}
	} else if (window.ActiveXObject) {
		try {
			var xmlHttp = new ActiveXObject("MsXml2.XmlHttp");
		} catch (e) {}
	}
	
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			callback(xmlHttp.responseText);
		}
	};

	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=win-1250');
	xmlHttp.setRequestHeader('Accept-Encoding', 'win-1250');
	xmlHttp.send(content);
	return true;
}

function new_adv(container) {
	try {
		ajax_post_async("/forum/advertise/new_adv.php?rnd="+Math.random(), '', function (resp) {
			if (resp != '') document.getElementById(container).innerHTML = resp;
		});
	} catch (e) {}
}

/*
function new_adv(container) {
	try {
		var adv = ajax_post_sync("/forum/advertise/new_adv.php?rnd="+Math.random(), '');
		if (adv != '') document.getElementById(container).innerHTML = adv;
	} catch (e) {}
}
*/

function toggle(divId) {
	if (document.getElementById(divId)) {
		document.getElementById(divId).style.display = ( (document.getElementById(divId).style.display!='block') ? 'block' : 'none' );
	}
}

function show(id) {
	document.getElementById(id).style.display = 'inline';
}

function hide(id) {
	document.getElementById(id).style.display = 'none';
}

function setdisplay(id, disp) {
	document.getElementById(id).style.display = disp;
}

var closeTimer, openTimer;
function showpager(table) {
	if (closeTimer != null) clearTimeout(closeTimer);
	openTimer = setTimeout(function() {
		table.childNodes.item(1).style.visibility = "visible";
		}, 500);
}
function hidepager(table) {
	if (openTimer != null) clearTimeout(openTimer);
	closeTimer = setTimeout(function() {
		table.childNodes.item(1).style.visibility = "hidden";
		}, 400);
}

/*
function showpager(table) {
	table.childNodes.item(1).style.visibility = "visible";
//	show_timer = null;
}
function hidepager(table) {
	table.childNodes.item(1).style.visibility = "hidden";
//	table = null;
}
*/

function showanswer(table) {
	table.childNodes.item(1).style.visibility = "visible";
}
function hideanswer(table) {
	table.childNodes.item(1).style.visibility = "hidden";
}

function sleep(ms) {
	var now = new Date();
	var exitTime = now.getTime() + ms;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

/*
function showComments(that) {
	that.nextSibling.style.left = findPosX(that);
	that.nextSibling.style.top = findPosY(that);
	that.nextSibling.style.display = 'block';
}
*/

function show_block(table) {
	toggled_block = table;
	if (show_timer == null) show_timer = setTimeout("showpager(toggled_block);", 1000);
}
function hide_block(table) {
	clearTimeout(show_timer);
	hidepager(table);
}

var show_timer = null;
var toggled_block;

