
function lalika(){
    alert('dsa')
}
function doajax2(dir,fname,params,returnfunc){
 eval(fname+" = GetXmlHttpObject();");
 var url=dir+fname+".php"
 eval(fname).onreadystatechange = eval(returnfunc);
 eval(fname).open("POST",url,true);
 eval(fname).setRequestHeader("Content-type", "application/x-www-form-urlencoded");

 sendparams = new Array();
 for ( var xkey in params ){
  sendparams[sendparams.length] = xkey+'='+params[xkey].toString().replace('&','%26');
 }

 eval(fname).send(sendparams.join("&"));

}

//AJAX KEZELO OBJECT
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function geid(id){
	return document.getElementById(id);
}

function storeCaret (textEl) {
if (textEl.createTextRange) {
      textEl.caretPos = document.selection.createRange().duplicate();

	}

}
function insertAtCaret (textEl, text) {
   if (textEl.createTextRange && textEl.caretPos) {
	var caretPos = textEl.caretPos;
      caretPos.text =
      caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
          text + ' ' : text;
   }else if (textEl.selectionStart || textEl.selectionStart == '0') {
	var startPos = textEl.selectionStart;
	var endPos = textEl.selectionEnd;
	textEl.value = textEl.value.substring(0, startPos)+ text+ textEl.value.substring(endPos, textEl.value.length);
   } else
	textEl.value += text;
}


function commentedit(id) {
	var params = {
		"id" : id
		  }
	doajax2("ajax/","ajax_commentedit" , params, "commentedit_response");
	document.getElementById('hozzaszolas').style.display = "block";
	setTimeout(function(){document.getElementById('texta').focus();},500);
	document.getElementById('mod').value = id;
}

function commentedit_response(){
  if (ajax_commentedit.readyState==4) {
	document.getElementById('texta').value = ajax_commentedit.responseText;
  }
}

function moderated(id,forumid) {
  var params = {
	"commentid" : id,
	"forumid" : forumid
	    }
  doajax2("ajax/","ajax_moderation" , params , "moderated_response");
}


function moderated_response(){
	if (ajax_moderation.readyState==4) {
    var resp = new Array();
    resp = ajax_moderation.responseText.split("###");
    getforum(resp[0],resp[1]);
    }
}

function getforum(page,forumID)
  {

	if( document.getElementById('lapozomax') != null )
    	var lapozomax = document.getElementById('lapozomax').value;
    else
	var lapozomax = 10;
    if(page != "")
      post_page = page
    else
      post_page = "none";
	//alert("forumId=" + forumID + post_page + lapozomax);
    var params = {
			"forumId" : forumID,
			"page" : page,
			"lapozomax" : lapozomax
			};
    doajax2("ajax/","ajax_forum" , params, "forum_response");
  }

function forum_response(){
	if (ajax_forum.readyState==4) {
    		resp = ajax_forum.responseText.split('|#|#');
		document.getElementById('forum').innerHTML = resp[0];
	}
}


function smileys(mit)
  {
  var box = document.getElementById(mit);
if(box.style.display == "block" || box.style.display == "")
    {
    box.style.display = "none";
    }
  else
    {
    box.style.display = "block";
    }
  }
function forum_box(mit) {

  var box = document.getElementById(mit);
  var kep = document.getElementById(mit+"_kep");
  if(box.style.display == "block" || box.style.display == "")
    {
    kep.src = "img/forum_open"+mit.substr(5,1)+".jpg";
    box.style.display = "none";
    }
  else
    {
    kep.src = "img/forum_close"+mit.substr(5,1)+".jpg";
    box.style.display = "block";
    }

}
function history(comment_id,id) {
  var history_div = document.getElementById('history_'+id);
  if(history_div.style.display == "block")
    {
    history_div.style.display = "none";
    }
  else
    {
    history_div.style.display = "block";
    var params = {
	"comment_id" : comment_id,
	"id" : id
    }
    doajax2("ajax/","ajax_history" , params, "history_response");
    }

}

function history_response(){
	if (ajax_history.readyState==4) {
	     var resp = new Array();
       resp = ajax_history.responseText.split("###");
   		 document.getElementById('history_'+resp[1]).innerHTML = resp[0];
   		}
}

function reply(id) {
	document.getElementById('replyid').value = id;
	document.getElementById('hozzaszolas').style.display = "block";
	setTimeout(function(){document.getElementById('texta').focus();},500);
}

function deldiv(id) {
	geid('answer'+id).value='';
	geid('hiddenanswer'+id).value='';
	geid('divid'+id).style.display = "none";
}

function csekkAnswer() {
	for(i=2; i<=last_id_global; i++) {
		geid('hiddenanswer'+i).value = geid('answer'+i).value;
	}
}
var last_id_global = 0;
var csekk = 0;
function addNewAnswer(last_id) {
	if(csekk == 0 ) {
		last_id_global = last_id;
	}
	csekk++;
	last_id_global++;
	var div = document.createElement("div");
	div.id = 'divid'+last_id_global;

	var frm = geid('ujszavazas_form');


	var span = document.createElement("span");
	span.id='span'+last_id_global;

	var input = document.createElement("input");
	input.setAttribute( "type", "text" );
	input.setAttribute("id", "answer"+last_id_global);
	input.setAttribute("name", "answer"+last_id_global);
	input.setAttribute( "value", "" );

	var inputh = document.createElement("input");
	inputh.setAttribute( "type", "hidden" );
	inputh.setAttribute("id", "hiddenanswer"+last_id_global);
	inputh.setAttribute("name", "hiddenanswer"+last_id_global);
	inputh.setAttribute( "value", "" );


	geid('szavazas_valasz').appendChild(div);
	geid('divid'+last_id_global).appendChild(input);
	geid('divid'+last_id_global).appendChild(span);
	geid('span'+last_id_global).innerHTML = "<a href='' onClick='deldiv(\""+last_id_global+"\"); return false;'>Törlés</a>";
	frm.appendChild(inputh);
	geid('answer'+last_id_global).style.width = "150px";

}

function csekkinputs(ez,az) {
	var arr = document.getElementById(ez).getElementsByTagName("Input");
	if(document.getElementById(az).checked == true)
			document.getElementById(az).checked = false;
		else
			document.getElementById(az).checked = true;

	for(var i=0; i<arr.length; i++) {
		if(document.getElementById(arr[i].id).checked == true)
			document.getElementById(arr[i].id).checked = false;
		else
			document.getElementById(arr[i].id).checked = true;

	}
}
