// JavaScript Document
// Handles display of e-mail addresses
function level(a)
{
	document.write("<a href='mailto:"+a+"@ballor.hu'>");
	document.write(a+"@ballor.hu");
	document.write("</a>");
}

function addSmile(code) {
	var ta = document.getElementById("uzenet_id");
	document.uzenetform.uzenet.value += code;
	ta.focus();
} 

function insertAtCursor(myField, myValue, bbCode1, bbCode2, endOfLine) {
var bbb;
if (document.selection) {
//IE support
var str = document.selection.createRange().text;
myField.focus();
sel = document.selection.createRange();
sel.text = bbCode1 + myValue + bbCode2 + endOfLine;
if(myValue=='') { bbb=bbCode2.length; sel.moveStart('character',-bbb); sel.moveEnd('character',-bbb); }
sel.select();
return;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
var bbb2, bbV;
if(myValue=='') myValue = myField.value.substring(startPos, endPos);
myField.value = myField.value.substring(0, startPos) + bbCode1 + myValue + bbCode2 + endOfLine + myField.value.substring(endPos, myField.value.length);
if(myValue=='') { bbb=bbCode1.length; myField.selectionStart=startPos+bbb; myField.selectionEnd=endPos+bbb; }
else { bbb=bbCode1.length; bbb2=bbCode2.length; bbV=myValue.length; myField.selectionStart=startPos+bbV+bbb+bbb2; myField.selectionEnd=startPos+bbV+bbb+bbb2; } 
myField.focus();
return;
} else {
myField.value += myValue;
return;
}
}

function paste_strinL(strinL, isQuote, bbCode1, bbCode2, endOfLine){ 
if((isQuote==1 || isQuote==2) && strinL=='') alert(l_quoteMsgAlert);
else{
if (isQuote==1) {
bbCode1='<em>'; bbCode2='</em>'; endOfLine='\n';
}
if (isQuote==2) {
bbCode1='<strong>'; bbCode2='</strong>'; endOfLine='\n';
}
var isForm=document.forms["uzenetform"];
if (isForm) {
var input=document.forms["uzenetform"].elements["uzenet"];
insertAtCursor(input, strinL, bbCode1, bbCode2, endOfLine);
}
else alert(l_accessDenied);
}
}

function pasteSel() { 
if(document.getSelection) selection=document.getSelection(); 
else if(document.selection) selection=document.selection.createRange().text; 
else if(window.getSelection) selection=window.getSelection(); 
else selection=''; 
}	

function paste_strinLicon(strinL){ 
var input=document.forms["forumform"].elements["forum_icon"];
input.value='';
input.value=strinL;
}

var check;
function alertForumDelete(){
if (!check || check==0) check = 1;
else if (check == 1) check = 0;
if (check == 1) {
alert('FIGYELEM: a fórum, a benne levo témák és a hozzászólások végérvényesen el fognak veszni!');
}
}


function DoP(action) {
	var rvmsg;
	var cmsg = document.uzenetform.uzenet.value;

	if (action == "url") {
	var thisURL = prompt("Add meg az URL-t!   A http://-vel", "");
	if (thisURL.length>7)
	{
	 var thisTitle = prompt("Mi a link neve?", "");
	}
	var urlcode = "[url="+thisURL+"]"+thisTitle+"[/url]";
	rvmsg = cmsg+urlcode;
	if (thisURL.length>8 && thisTitle.length>1)
		{
		document.uzenetform.uzenet.value=rvmsg;
		}
	document.uzenetform.uzenet.focus();
	return;
	}
	
	if (action == "img") {
	var thisImage = prompt("Add meg a beszúrandó kép URL-jét!", "http://");
	var imagecode = "[img]"+thisImage+"[/img]";
	rvmsg = cmsg+imagecode;
	if (thisImage.length>8)
		{
		document.uzenetform.uzenet.value=rvmsg;
		}
	document.uzenetform.uzenet.focus();
	return;
	}
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'none')
          e.style.display = 'block';
       else
          e.style.display = 'none';
    }

function showStuff(id) {
		document.getElementById(id).style.display = 'block';
	}
	
function Ajax()
{
	var
		$http,
		$self = arguments.callee;
		if (window.XMLHttpRequest) {
		$http = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			$http = new ActiveXObject('Msxml2.XMLHTTP');
		} catch(e) {
			$http = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}

	if ($http) {
		$http.onreadystatechange = function()
		{
			if (/4|^complete$/.test($http.readyState)) {
				document.getElementById('ReloadThis').innerHTML = $http.responseText;
				setTimeout(function(){$self();}, 5000);
			}
		};
		$http.open('GET', '/pages/refresh.php' + '?' + new Date().getTime(), true);
		$http.send(null);
	}

}

function AjaxChat()
{
	var
		$http,
		$self = arguments.callee;
		if (window.XMLHttpRequest) {
		$http = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			$http = new ActiveXObject('Msxml2.XMLHTTP');
		} catch(e) {
			$http = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}

	if ($http) {
		$http.onreadystatechange = function()
		{
			if (/4|^complete$/.test($http.readyState)) {
				document.getElementById('ReloadChat').innerHTML = $http.responseText;
				setTimeout(function(){$self();}, 5000);
			}
		};
		$http.open('GET', '/pages/chat.php' + '?' + new Date().getTime(), true);
		$http.send(null);
	}

}
