function list_query (sourceobj,targetobj) {
  removeAllItem(targetobj)
  val = sourceobj.options[sourceobj.options.selectedIndex].value;
  query = filename="query.php?where=" + val + "&op=listQuery&stupidie=" + new Date().getTime();
  if (sourceobj.name=="forras_lista") {
    filename = "query.php?where=" + val + "&op=fflistQuery&stupidie=" + new Date().getTime();
  }
  ajaxRequest(filename,false);
  textlist=ajaxreq.responseXML.getElementsByTagName("resultnev");
  vallist=ajaxreq.responseXML.getElementsByTagName("resultid");
  leirlist=ajaxreq.responseXML.getElementsByTagName("resultle");
  for (j=0;j < vallist.length;j++) {
    ter_text=textlist[j].firstChild.nodeValue;
    ter_val=vallist[j].firstChild.nodeValue;
    targetobj.options[j]=new Option(ter_text,ter_val,false,false);
  }
  if (targetobj.name=="lista_lista[]") {
    document.listaform.listanev.value=ajaxreq.responseXML.getElementsByTagName("listanev")[0].firstChild.nodeValue;
    document.listaform.rendesnev.value=ajaxreq.responseXML.getElementsByTagName("rendesnev")[0].firstChild.nodeValue;
    try {
    document.listaform.leiras.value=ajaxreq.responseXML.getElementsByTagName("leiras")[0].firstChild.nodeValue;
    } catch (e) {document.listaform.leiras.value=""};
    document.listaform.szolgadmin.checked=ajaxreq.responseXML.getElementsByTagName("szolgadmin")[0].firstChild.nodeValue==0?0:1;
    document.listaform.ugyfeladmin.checked=ajaxreq.responseXML.getElementsByTagName("ugyfeladmin")[0].firstChild.nodeValue==0?0:1;
    document.listaform.szervezet_k.checked=ajaxreq.responseXML.getElementsByTagName("szervezet_k")[0].firstChild.nodeValue==0?0:1;
    document.listaform.multisearch.checked=ajaxreq.responseXML.getElementsByTagName("multisearch")[0].firstChild.nodeValue==0?0:1;
    document.listaform.box.value=ajaxreq.responseXML.getElementsByTagName("box")[0].firstChild.nodeValue;
  }
}

function teszt_query (sourceobj,targetobj) {
  removeAllItem(targetobj)
  if (sourceobj.name=='plista_tesztek') {
    removeAllItem (document.tesztform['teszt_blista[]']);
  }
  val = sourceobj.options[sourceobj.options.selectedIndex].value;
  if (targetobj.name=='teszt_valaszok[]') {
    filename="query.php?where=" + val + "&op=tesztQuery&stupidie=" + new Date().getTime();
  } else {
    filename="query.php?where=" + val + "&op=tesztQuery&teszt=v&oldal="+sourceobj.name.substr(0,1);
  }
  ajaxRequest(filename,false);
  textvalasz=ajaxreq.responseXML.getElementsByTagName("resultvalasz");
  valvalasz=ajaxreq.responseXML.getElementsByTagName("resultid");
  if (targetobj.name=='teszt_valaszok[]') {
    helyese=ajaxreq.responseXML.getElementsByTagName("resulthelyese");
    for (j=0;j < valvalasz.length;j++) {
      if (helyese[j].firstChild.nodeValue==1) {
        he_szoveg="I__";
      } else {
        he_szoveg="N__";
      }
      ter_text=he_szoveg + textvalasz[j].firstChild.nodeValue;
      ter_val=valvalasz[j].firstChild.nodeValue;
      targetobj.options[j]=new Option(ter_text,ter_text,false,false);
    }
   } else {
      for (j=0;j < valvalasz.length;j++) {
      ter_text=he_szoveg + textvalasz[j].firstChild.nodeValue;
      ter_val=valvalasz[j].firstChild.nodeValue;
      targetobj.options[j]=new Option(ter_text,ter_text,false,false);
     }
   }
   document.tesztform.kerdes.value=ajaxreq.responseXML.getElementsByTagName("kerdes")[0].firstChild.nodeValue;
   document.tesztform.temakor.value=ajaxreq.responseXML.getElementsByTagName("tema")[0].firstChild.nodeValue;
   switchField(document.tesztform.temakor,document.tesztform.ujtemakor);
}



function listAddElement (sourceobj,targetobj) {
  if (checkElement (sourceobj,targetobj)) {

    var tex = sourceobj.value;
    var hossz = targetobj.length;
    targetobj.options[hossz]=new Option(tex,tex,false,false);
    targetobj.options[hossz-1].selected=false;
    targetobj.options[hossz].selected = true;
  }
}

function tesztAddElement (sourceobj,targetobj) {
  if (checkElement (sourceobj,targetobj)) {
    //alert (sourceobj.name.substr(1));
    if (sourceobj.name.substr(1)!='oszlop_bevitel') {
      if (document.tesztform.helyes_e.checked) {
        var tex = "I__"+sourceobj.value;
      } else {
        var tex = "N__"+sourceobj.value;
      }
    } else {
      var tex = sourceobj.value;
    }
    var hossz = targetobj.length;
    targetobj.options[hossz]=new Option(tex,tex,false,false);
    targetobj.options[hossz-1].selected=false;
    targetobj.options[hossz].selected = true;
    sourceobj.value="";
    if (sourceobj.name.substr(1)!='oszlop_bevitel') {
      document.tesztform.helyes_e.checked=false;
    }
  }
}

function checkElement (sourceobj,targetobj) {
  if (sourceobj.value=="") {return false;}
  for (i = targetobj.length - 1; i >= 0; i--) {
    if (targetobj.options[i].text==sourceobj.value) {
      return false;
    }
  }
  return true;
}

function saveList (listakObj,listaObj) {
  //listában szereplő elemek lekérdezése
  listaId = listakObj.options[listakObj.options.selectedIndex].value;
  filename="query.php?where=" + listaId +"&op=listQuery&stupidie=" + new Date().getTime();
  ajaxRequest (filename,false);
  vallist=ajaxreq.responseXML.getElementsByTagName("resultid");
  //törlés
  for (i=0;i < vallist.length;i++) {
     x=0;
     for (j=0; j < listaObj.length;j++) {
       if (vallist[i].firstChild.nodeValue==listaObj.options[j].value) {x=1;}
     }
     if (x==0) {
       filename="query.php?listaId="+ listaId +"&delElement="+ vallist[i].firstChild.nodeValue +"&op=deleteListElement&stupidie=" + new Date().getTime();
       ajaxRequest (filename,false);
     }
  }
  //új elemek rögzítése
  for (i=0;i < listaObj.length;i++) {
    tex=escape(encodeURIComponent(listaObj.options[i].text));
    val=listaObj.options[i].value;
    if (val.substring(0,2)=="id") {
      filename="query.php?listaId=" + listaId + "&newElement="+ tex +"&op=saveNewListElement&stupidie=" + new Date().getTime();
      ajaxRequest(filename,false);
    }
  }
}

function deleteConfirm (text){
  var yesOrNo=confirm(text);
  if (yesOrNo) {return true;}
  else {return false;}
}

function checkListForm (obj,check) {
  if (obj.rendesnev.value.length<5) {
    alert("Érvénytelen megnevezés! Legalább 5 karakter legyen");
    return(false);
  }
  if (check==1) {
    filename="query.php?listname=" + obj.rendesnev.value + "&op=checkListName&stupidie=" + new Date().getTime();
    ajaxRequest(filename,false);
    results=ajaxreq.responseXML.getElementsByTagName("result");
    if (results.length>0) {
      alert ("Már létezik ilyen néven lista! Válasszon másikat!");
      return(false);
    }
  }
}

function checkMentorForm (obj,check) {
  if (! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.felh_email.value)){
    alert("Érvénytelen e-mail cím!");
    return (false);
  }

  if (obj.mentor_nev.value.length<1) {
    alert("Érvénytelen megnevezés!");
    return(false);
  }
  if (obj.felh_azonosito.value.length<5) {
    alert("Érvénytelen azonosító! Legalább 5 karakter legyen!");
    return(false);
  }
  if (check==1) {
    filename="query.php?loginname=" + obj.felh_azonosito.value + "&formname=" + obj.name + "&op=checkLoginname&stupidie=" + new Date().getTime();
    ajaxRequest(filename,false);
    results=ajaxreq.responseXML.getElementsByTagName("result");
    if (results.length>0) {
      alert ("Már létezik ez az azonosító! Válasszon másikat!");
      return(false);
    }
  }
  if (check==1 || obj.felh_jelszo1.value.length!=0) {
    if (obj.felh_jelszo1.value.length<6) {
      alert("Érvénytelen jelszó! Legalább 6 karakter legyen!");
      return(false);
    }
  }
  if (obj.felh_jelszo1.value!=obj.felh_jelszo2.value) {
    alert("A megadott jelszavak nem egyeznek!");
    return(false);
  }
}


function clearForm (obj) {
  deselectAllOptions(obj.lista_listak);
  removeAllItem(obj['lista_lista[]']);
  obj.listanev.value="";
  obj.rendesnev.value="";
  obj.leiras.value="";
  obj.szolgadmin.checked=false;
  obj.ugyfeladmin.checked=false;
}

function deleteList() {
  for (i = document.listaform.lista_listak.length - 1; i>=0; i--) {
    if (document.listaform.lista_listak.options[i].selected) {
      lid=document.listaform.lista_listak.options[i].value;
      window.location.href="admin.php?op=lista_torles&lid="+lid;
    }
  }
}

function tesztTorol() {
  for (i = document.tesztform.lista_tesztek.length - 1; i>=0; i--) {
    if (document.tesztform.lista_tesztek.options[i].selected) {
      tid=document.tesztform.lista_tesztek.options[i].value;
      window.location.href="admin.php?op=teszt_torol&tid="+tid;
    }
  }
}

function selectAnsw(obj) {
  string = obj.options[obj.options.selectedIndex].value;
  tof = string.substring(0,1);
  answ = string.substring(3);
  document.tesztform.valasz_bevitel.value=answ;
  if (tof=="I") {
    document.tesztform.helyes_e.checked=true;
  } else {
    document.tesztform.helyes_e.checked=false;
  }
}

function changeAnsw(answobj,tofobj,listobj) {
  if (tofobj.checked==true) {
    newString="I__";
  } else {
    newString="N__";
  }
  newString=newString+answobj.value;
  listobj.options[listobj.options.selectedIndex].value=newString;
  listobj.options[listobj.options.selectedIndex].text=newString;
}

function switchField(obj1,obj2) {
 if (obj1.value=="0") {
   obj2.disabled=false;
   obj2.style.visibility="visible";
 } else {
   obj2.disabled=true;
   obj2.style.visibility="hidden";
 }
}



