//-------------------------------------------AJAX
//--------XMLHttpRequest objektum ltrehozsa
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;
}


//---------------Form POST
function form_post_ajax(form_id, uzenet_id, feld_php, send_hiba, char_set, add, fv)
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	  alert ("elavult!");
	  return;
	}
	if (char_set=="")
	{
		char_set='iso-8859-2';
	}
	var url=feld_php;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", 'application/x-www-form-urlencoded; charset='+char_set);
	xmlHttp.onreadystatechange=function(){
		adatok_kuldese_post_ajax_eval(uzenet_id, xmlHttp, fv)
	}
	var send_data='';
	if(form_id)
	{
		var ananasz = document.getElementById(form_id).elements;
		for(var i = 0;i < ananasz.length; i++)
		{
			if (ananasz[i].type == "checkbox") 
			{
				if(ananasz[i].checked)
				{
					send_data+=ananasz[i].name + '=' + escape(ananasz[i].value);
				}
				else
				{
					send_data+=ananasz[i].name + '=';
				}
	    }
			else if(ananasz[i].type=="radio")
			{
				if(ananasz[i].checked)
				{
					send_data+=ananasz[i].name + '=' + escape(ananasz[i].value);
				}
			}
			else
			{
				send_data+=ananasz[i].name + '=' + escape(ananasz[i].value);
			}
			if (i<ananasz.length-1)
			{
				send_data+='&';
			}
		}
	}
	send_data+='&'+add;
	if(uzenet_id!="")
	{
		document.getElementById(uzenet_id).innerHTML="...";
	}
	
	try
	{
		xmlHttp.send(send_data);
	}
	catch (e)
	{
		if(uzenet_id!="")
		{
			uzenet_id=document.getElementById(uzenet_id);
			uzenet_id.innerHTML=send_hiba;
		}
	}
}
	
function adatok_kuldese_post_ajax_eval(uzenet_id, xmlHttp, fv)
{
	if (xmlHttp.readyState==4)
	{
		if(uzenet_id!="")
		{
			document.getElementById(uzenet_id).innerHTML=xmlHttp.responseText;
		}
		eval(fv);
	}
}

//--------------GET-es adatklds
function ajax_data(ut, adat, uz_id, fv)
{
	if(uz_id != "")
	{
		document.getElementById(uz_id).innerHTML="...";
	}
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	  alert ("Az n bngszje tl elavult!");
	  return;
	}
	ut+="?"+adat+"&sid="+Math.random();
	xmlHttp.open("GET",ut,true);
	xmlHttp.onreadystatechange=function()
	{
		adatok_kuldese_ajax_data_eval(uz_id, xmlHttp, fv);
	}
	xmlHttp.send(null);
}
	
function adatok_kuldese_ajax_data_eval(uz_id, xmlHttp, fv) 
{ 
	if (xmlHttp.readyState==4)
	{
		if(uz_id != "")
		{
			document.getElementById(uz_id).innerHTML=xmlHttp.responseText;
		}
		eval(fv);
	}
}

//-------------------------------Enterre ajax
function enterajax(e, mi)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
			
     if(key == 13)
     {
			eval(mi);
     }
}

//-------------------------------Formvalidls tmja

function jelmeg(passwd, passwd1, msg)
{
	if(passwd.value==passwd1.value)
	{
		return true;
	}
	else
	{
		alert(msg);
		passwd.focus();
		return false;
	}
}

function isLong(elem, hossz, helperMsg){
	if(elem.value.length < hossz){
		alert(helperMsg);
		elem.focus();
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isNumeric_notob(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		return false;
	}
}

function isNumeric_e(elem, helperMsg){
	var numericExpression = /^[0-9]*$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isFloat(elem, helperMsg){
	var numericExpression = /^[0-9\.]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isFloat_e(elem, helperMsg){
	var numericExpression = /^[0-9\.]*$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z\- ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet_zj(elem, helperMsg){
	var alphaExp = /^[a-zA-Z()\- ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet_e(elem, helperMsg){
	var alphaExp = /^[a-zA-Z\- ]*$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z\- ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max, msg){
	var uInput = htmlspecialchars(elem.value);
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert(msg);
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator_k(elem, helperMsg){
	var emailExp = /^[@a-zA-Z0-9\.\-\+]*$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

//----------------------DOM
function getelem(s)
{
	return document.getElementById(s);
}

function sel_del(sel, del)
{
	var sel=document.getElementById(sel);
	var opt=sel.options;
	del = del;
	for(var i=0; i<opt.length; i++)
	{
		if(opt[i].text == del)
		{
			sel.remove(i);
			break;
		}
	}
}

function add_option(sel, val, text)
{
	sel = document.getElementById(sel);
	var opt=document.createElement('option');
	opt.value=val;
	opt.text=text;
	try
  {
  	sel.add(opt, null); // standards compliant
  }
	catch(ex)
  {
  	sel.add(opt); // IE only
  }
}

function remove_options(sel)
{
	sel = document.getElementById(sel);
	for(var i = sel.length-1; i >= 0; i--)
	{
		sel.remove(i);
	}
}

function select_option(sel, opt, mode)
{
	sel = document.getElementById(sel);
	for(var i = sel.length-1; i >= 0; i--)
	{
		if(mode == "text")
		{
			if(sel.options[i].text == opt)
			{
				sel.options[i].selected = true;
			}
		}
		else
		{
			if(sel.options[i].value == opt)
			{
				sel.options[i].selected = true;
			}
		}
	}
}

function add_row(tableid, tds, trid)
{
	var tbody = document.getElementById(tableid).getElementsByTagName("TBODY")[0];
	var row = document.createElement("TR");
	var i;
	var td;
	for(i in tds)
	{
		td = document.createElement("TD");
		td.innerHTML = tds[i];
		row.appendChild(td);
	}
	
	if(trid)
	{
		row.id = trid;
	}
	
	tbody.appendChild(row);
}

function num_rows(table)
{
	var oRows = document.getElementById(table).getElementsByTagName('tr');
	return oRows.length;
}

function kozepre(id)
{
	var y;
	y = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	y += document.body.clientHeight/2;
	document.getElementById(id).style.top = y+'px';
	document.getElementById(id).style.display = '';
}
//--------------------------Dtum
function napok(d, m, y)
{
	var days = document.getElementById(d);
	var si = days.selectedIndex;
	remove_options(d);
	var honap = document.getElementById(m).value;
	var ev = document.getElementById(y).value;
	var napok = number_of_days(honap, ev);
	var j;
	for(var i = 1; i <= napok; i++)
	{
		if(i < 10)
		{
			j = '0'+i;
		}
		else
		{
			j = i;
		}
		add_option(d, j, j);
	}
	
	if(si == -1)
	{
		days.selectedIndex = 0;
	}
	else if(si >= napok)
	{
		days.selectedIndex = napok-1;
	}
	else
	{
		days.selectedIndex = si;
	}
}

function number_of_days(month, year)
{
	if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
	{
		return 31;
	}
	else if(month == 2)
	{
		if((year%4) == 0)
		{
			return 29;
		}
		else
		{
			return 28;
		}
	}
	return 30;
}

//--------------------------Egyb
function goTo(url)
{
	window.location.href = url;
}
function goto_loc(url)
{
	window.location.href = url;
}

/*
//--------------------------Karakterkdols
function htmlspecialchars(ch) {
ch = ch.replace(/&/g,"&amp;")
ch = ch.replace(/\"/g,"&quot;")
ch = ch.replace(/\'/g,"&#039;")
ch = ch.replace(/</g,"&lt;")
ch = ch.replace(/>/g,"&gt;")
ch = ch.replace(//g,"&#337;")
ch = ch.replace(//g,"&#336;")
ch = ch.replace(//g,"&#369;")
ch = ch.replace(//g,"&#368;")
return ch
}

function htmlspecialchars_decode(ch) {
ch = ch.replace(/&amp;/g,"&")
ch = ch.replace(/&quot;/g,"\"")
ch = ch.replace(/&#039;/g,"\'")
ch = ch.replace(/&lt;/g,"<;")
ch = ch.replace(/&gt;/g,">")
ch = ch.replace(/&#337;/g,"")
ch = ch.replace(/&#336;/g,"")
ch = ch.replace(/&#369;/g,"")
ch = ch.replace(/&#368;/g,"")
return ch
}*/

//-------------------------------Ajax lapozs s rendezs
g_page = new Array();
g_order = new Array();
function lapoz(n, telem, max, eva)
{
	if(n == "e")
	{
		if(g_page[telem] != 1)
		{
			n = g_page[telem]-1;
		}
		else
		{
			n = g_page[telem];
		}
	}
	else if(n == "k")
	{
		if(g_page[telem] < max)
		{
			n = g_page[telem]+1;
		}
		else
		{
			n = g_page[telem];
		}
	}
	
	if(g_page[telem] != n)
	{
		g_page[telem] = n;
		eval(eva);
	}
}

function rendez(o, telem, eva)
{
	if(o != g_order[telem])
	{
		g_order[telem] = o;
		eval(eva);
	}	
}

//-------------------------------------------AJAX
//--------XMLHttpRequest objektum létrehozása
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;
}


//---------------Form POST
function form_post_ajax(form_id, uzenet_id, feld_php, send_hiba, char_set, add, fv)
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	  alert ("Az Ön böngészője túl elavult!");
	  return;
	}
	if (char_set=="")
	{
		char_set='iso-8859-2';
	}
	var url=feld_php;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", 'application/x-www-form-urlencoded; charset='+char_set);
	xmlHttp.onreadystatechange=function(){
		adatok_kuldese_post_ajax_eval(uzenet_id, xmlHttp, fv)
	}
	var send_data='';
	if(form_id)
	{
		var ananasz = document.getElementById(form_id).elements;
		for(var i = 0;i < ananasz.length; i++)
		{
			if (ananasz[i].type == "checkbox") 
			{
				if(ananasz[i].checked)
				{
					send_data+=ananasz[i].name + '=' + escape(ananasz[i].value);
				}
				else
				{
					send_data+=ananasz[i].name + '=';
				}
	    }
			else if(ananasz[i].type=="radio")
			{
				if(ananasz[i].checked)
				{
					send_data+=ananasz[i].name + '=' + escape(ananasz[i].value);
				}
			}
			else
			{
				send_data+=ananasz[i].name + '=' + escape(ananasz[i].value);
			}
			if (i<ananasz.length-1)
			{
				send_data+='&';
			}
		}
	}
	send_data+='&'+add;
	if(uzenet_id!="")
	{
		document.getElementById(uzenet_id).innerHTML="...";
	}
	
	try
	{
		xmlHttp.send(send_data);
	}
	catch (e)
	{
		if(uzenet_id!="")
		{
			uzenet_id=document.getElementById(uzenet_id);
			uzenet_id.innerHTML=send_hiba;
		}
	}
}
	
function adatok_kuldese_post_ajax_eval(uzenet_id, xmlHttp, fv)
{
	if (xmlHttp.readyState==4)
	{
		if(uzenet_id!="")
		{
			document.getElementById(uzenet_id).innerHTML=xmlHttp.responseText;
		}
		eval(fv);
	}
}

//--------------GET-es adatküldés
function ajax_data(ut, adat, uz_id, fv)
{
	if(uz_id != "")
	{
		document.getElementById(uz_id).innerHTML="...";
	}
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	  alert ("Az Ön böngészője túl elavult!");
	  return;
	}
	ut+="?"+adat+"&sid="+Math.random();
	xmlHttp.open("GET",ut,true);
	xmlHttp.onreadystatechange=function()
	{
		adatok_kuldese_ajax_data_eval(uz_id, xmlHttp, fv);
	}
	xmlHttp.send(null);
}
	
function adatok_kuldese_ajax_data_eval(uz_id, xmlHttp, fv) 
{ 
	if (xmlHttp.readyState==4)
	{
		if(uz_id != "")
		{
			document.getElementById(uz_id).innerHTML=xmlHttp.responseText;
		}
		eval(fv);
	}
}

//-------------------------------Enterre ajax
function enterajax(e, mi)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
			
     if(key == 13)
     {
			eval(mi);
     }
}

//----------------------DOM
function getelem(s)
{
	return document.getElementById(s);
}

function sel_del(sel, del)
{
	var sel=document.getElementById(sel);
	var opt=sel.options;
	del = del;
	for(var i=0; i<opt.length; i++)
	{
		if(opt[i].text == del)
		{
			sel.remove(i);
			break;
		}
	}
}

function add_option(sel, val, text)
{
	sel = document.getElementById(sel);
	var opt=document.createElement('option');
	opt.value=val;
	opt.text=text;
	try
  {
  	sel.add(opt, null); // standards compliant
  }
	catch(ex)
  {
  	sel.add(opt); // IE only
  }
}

function remove_options(sel)
{
	sel = document.getElementById(sel);
	for(var i = sel.length-1; i >= 0; i--)
	{
		sel.remove(i);
	}
}

function select_option(sel, opt, mode)
{
	sel = document.getElementById(sel);
	for(var i = sel.length-1; i >= 0; i--)
	{
		if(mode == "text")
		{
			if(sel.options[i].text == opt)
			{
				sel.options[i].selected = true;
			}
		}
		else
		{
			if(sel.options[i].value == opt)
			{
				sel.options[i].selected = true;
			}
		}
	}
}

function select_unique(sel)
{
	sel = document.getElementById(sel);
	var volt = new Array();
	var val;
	for(var i = sel.length-1; i >= 0; i--)
	{
		val =  sel.options[i].value;
		if(in_array(val, volt))
		{
			sel.remove(i);
		}
		else
		{
			volt[volt.length] = val;
		}
	}
}

function add_row(tableid, tds, trid)
{
	var tbody = document.getElementById(tableid).getElementsByTagName("TBODY")[0];
	var row = document.createElement("TR");
	var i;
	var td;
	for(i in tds)
	{
		td = document.createElement("TD");
		td.innerHTML = tds[i];
		row.appendChild(td);
	}
	
	if(trid)
	{
		row.id = trid;
	}
	
	tbody.appendChild(row);
}

function num_rows(table)
{
	var oRows = document.getElementById(table).getElementsByTagName('tr');
	return oRows.length;
}

function kozepre(id)
{
	var y;
	y = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	y += document.body.clientHeight/2;
	document.getElementById(id).style.top = y+'px';
	document.getElementById(id).style.display = '';
}

function sendparentid(object)
{
	ajax_data("modules/keres.php", "ajax=sendparentid&parent_id="+object.value, "box2", "");
}
