var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
   
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      }
    }
  }
  /*
if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
}
*/



try{
  var betoltes_queue=new Array();
  var moopage4history=new Array();
}catch(e){

}
var queue_kezd=0;
var queue_veg=0;
var current_url="";


function betolt_getes_link(url){
  history_push(url);  
  betolt_queue(url,'','AJAX=1',true);
  return false;  
}

function history_push(url){
  moopage4history.push(url);
}

function history_pop(){
  if (moopage4history.length>0){
    moopage4history.pop();
  } else {
    return "";
  }
}

function get_histrory_top(){
  if (moopage4history.length>0){
    return moopage4history[moopage4history.length-1];
  } else {
    return "";
  }
}

function history_back(){
  history_pop();
  betolt_queue(get_histrory_top(),'','AJAX=1',true);
}


function queue_pop(){

  queue_kezd++;

}

function queue_first(){
  index=queue_kezd % 10;  
  tmp=betoltes_queue[index];
  return tmp;
}

function queue_push(mit,hova,params,js_kent){
  index=queue_veg % 10;  
  betoltes_queue[index]=new Array(mit,hova,params,js_kent);
  queue_veg++;
  
}

function queue_count(){
  return (queue_veg-queue_kezd);
}

function betolt_queue(mit,hova,params,js_kent){
  current_url=mit;
  queue_push(mit,hova,params,js_kent);
  if (queue_count()==1) queue_processor();
}

function queue_processor(){
  if (queue_count()>0){
    try{
    tmp=queue_first();
    }catch(e){}
    betolt(tmp[0],tmp[1],tmp[2],tmp[3]);
  }
}
var target_betolt="";


function betolt(mit,hova,params,js_kent){
  //alert('betolthiv:'+hova);
  //alert("js_kent"+js_kent);
  target_betolt=hova;

  if (mit=="") mit="/";
    
  xmlHttp.open("POST", mit, true);
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("Connection", "close");
  
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState == 4) {
      try{
        var result = xmlHttp.responseText;
        tmp=queue_first();
        if (tmp[3]==true){
          eval(result);
        }else{
          document.getElementById(tmp[1]).innerHTML=(result);
        }
      }catch(e){
      }
      queue_pop();
      queue_processor();
    }
  }  
  

  xmlHttp.send(params);
}

var timeout;

function form_postolo(the_form,hova,cel_id,js_kent,var_e,submitgomb){
  //clearTimeout(timeout);
  var x=document.getElementById(the_form);
  var params="";
  
  for (var i=0;i<x.length;i++)
  { 
    element=x.elements[i];
    if (element.name=="") continue;
    
    if (i!=0) params+="&";
    
    if (element.type=="hidden" || element.type=="text" || element.type=="select-one" || element.type=="password" || element.type=="textarea"){
      params+=(element.name+"="+encodeURIComponentNew(element.value));
      //alert("params"+params);
    }
    if (element.name==submitgomb){
      params+=(element.name+"=1");
    }
        
    if (element.type=="checkbox" && element.checked){
        params+=(element.name+"="+encodeURIComponentNew(element.value));
    }
  }
  
  params+="&AJAX=1";
  
  betolt_queue(hova,cel_id,params,js_kent);
  //}
}

function moo_post(form_id,submitgomb){
  var target=location.search;
  if (current_url!="") target=current_url;
  form_postolo(form_id,target,'',true,false,submitgomb);
}

function moo_submitlink3(form_id,mitmire){
  for (key in mitmire){
    try{
      document.getElementById(key).name=mitmire[key];
    } catch(e){
    }
  }
  try{
    moo_post(form_id,"");
  } catch(e){
  }
}  

/*
A karakter kódolásokkal való játék
*/

function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}


var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}


