
var tinyMCE=null;
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-*-*-*-*-*-*-*SORRENDEZÉS*-*-*-*-*-*-*-*-*-*-*-*-*-*-
document.onmousedown=dragHandler;
var toPozval = -1;
var saveTop = 0;

function moveHandler(e){
  if (e == null) { e = window.event } 
  if (e.button<=1&&dragOK){
     savedTarget.style.top=e.clientY-dragYoffset+'px';
     //alert(e.clientY-dragYoffset);
     vane = in_coordArray(e.clientY-dragYoffset);  
     if (vane != -1) {
         clearLines();
         document.getElementById("tol_"+vane).className = "to_line_hl";
         toPozval = vane;
     } else {
         clearLines();
         toPozval = -1;
     } 
     return false;
  }
}

function clearLines() {
   var items = getElementsByClass("to_line_hl");
   for (i=0;i<items.length;i++) {
        items[i].className = "to_line";
    } 
}

function cleanup(e) {
  document.onmousemove=null;
  document.onmouseup=null;
  savedTarget.style.cursor=orgCursor;
  savedTarget.style.zIndex = 10;
  lightup(savedTarget,100);
  if (toPozval != -1) toPoz(toPozval,savedTarget);
    else savedTarget.style.top=saveTop;
  dragOK=false;
}

function dragHandler(e){
  var htype='-moz-grabbing';
  if (e == null) { e = window.event; htype='move';} 
  var target = e.target != null ? e.target : e.srcElement;
  orgCursor=target.style.cursor;
  if (target.className=="admin_row") {
     savedTarget=target;
     saveTop = savedTarget.style.top;       
     target.style.cursor=htype;
     lightup(target,60);
     target.style.zIndex = 100;
     dragOK=true;
     dragYoffset=e.clientY-parseInt(vidPaneID.style.top);
     document.onmousemove=moveHandler;
     document.onmouseup=cleanup;
     return false;
  }
}

function in_coordArray(num) {
    for (c=0;c<poz.length;c++) {
        var coord = poz[c];
        for (i=coord-6;i<=coord+9;i++) if ((num+12)==i) return c;
    }
    return -1;
}

function toPoz(topo,obj) {
    //alert(topo)    
    //alert(obj.id.split("_")[1])
    frompo = parseInt(obj.id.split("_")[1]);
    //var toTop = document.getElementById().style.top;
    if (frompo > topo) {
        for (i=topo+1;i<frompo;i++) {
            p = parseInt(document.getElementById("arow_"+i).style.top.split('p')[0])+27;
            document.getElementById("arow_"+i).style.top = p+"px"; 
        }
        obj.style.top = (poz[topo]+3)+"px";
    }
    
    if (frompo < topo) {
        for (i=topo;i>frompo;i--) {
            p = parseInt(document.getElementById("arow_"+i).style.top.split('p')[0])-27;
            document.getElementById("arow_"+i).style.top = p+"px"; 
             
        }
        obj.style.top = (poz[topo]-24)+"px"; 
    }
    var p=new Array();
    p['sPri'] = frompo;
    p['tPri'] = topo;
    p['groupID'] = group_id; 
    p['command'] = "set_priority"; 
    p['mpoint'] = mpoint;
    p['bwi'] = document.getElementById("admin_fields").style.width;
    p['top_pos'] = top_pos;
    setFuggony('admin_fields');
    switch (adminsubject) {
        case "newscateg": file = "categ_list.php"; break;     
        case "news": file = "news_list.php"; break;     
        case "content": file = "content_data.php"; break;     
    }
    getAjax(file,p,function(){if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){document.getElementById('admin_fields').innerHTML=xmlHttp.responseText}}); 
    clearLines();    
}
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* Categ *-**-**-**-**-**-**-*

function addCateg(sel) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "new_form";
    p['selected'] = sel;
    getAjax("categ_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("a.modalCloseImg").click();
                            $('#cms_popup').html(xmlHttp.responseText); 
                        }
                        });
}

var timer = 0; 
function saveNewCateg() {
    document.getElementById('box_reflect').innerHTML="<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...";
    var p=serializeForm(document.newcateg);
    p['command'] = "add_new";
    if (navigator.userAgent.indexOf("MSIE")>=0) p['is_IE'] = true;
        else p['is_IE'] = false;
    getAjax("categ_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('box_reflect').innerHTML=xmlHttp.responseText;
                            timer = setTimeout('refreshCategList()', 1200); 
                        }
                        });
}

function refreshCategList() {
    $('#cms_popup').html("");
    $("a.modalCloseImg").click();
    var p=new Array();
    p['bwi'] = document.getElementById("admin_fields").style.width;
    p['top_pos'] = top_pos;
    getAjax("categ_list.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('admin_fields').innerHTML=xmlHttp.responseText; 
                        }
                        });
}

function editCateg (id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("categ_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("a.modalCloseImg").click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal(); 
                        }
                        });
}

function saveEditedCateg() {
    document.getElementById('box_reflect').innerHTML="<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...";
    var p=serializeForm(document.editcateg);
    p['command'] = "edited";
    if (navigator.userAgent.indexOf("MSIE")>=0) p['is_IE'] = true;
        else p['is_IE'] = false;
    getAjax("categ_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('box_reflect').innerHTML=xmlHttp.responseText;
                            //timer = setTimeout('refreshCategList()', 1200); 
                        }
                        });
}

function delCateg(id) {
     if (confirm("Valóban törli a kategóriát?")) {
        var p=new Array();
        p['command'] = "delete";
        p['delid'] = id;
        getAjax("categ_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');refreshCategList();", 1200); 
                        }
                        });
     }
}
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* Tiny *-**-**-**-**-**-**-*

function editorInit(type,e_mode,ta_name) {
    switch (type) {
        case "full":
            pins = "style,layer,table,advhr,advimage,advlink,noneditable,visualchars,nonbreaking,xhtmlxtras,template,paste,directionality,fullscreen,preview,filemanager",
            tab1 = "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,ltr,rtl,separator,anchor,link,unlink,image";
            tab2 = "undo,redo,,separator,formatselect,fontselect,fontsizeselect,styleselect,forecolor,separator,table,col_after,col_before,row_after,row_before,delete_col,delete_row,row_props,cell_props";
            tab3 = "hr,removeformat,separator,sub,sup,separator,charmap,pasteword";
        break;
        case "base":
            pins = "style,layer,advlink,visualchars,nonbreaking,paste,directionality,fullscreen,preview,filemanager",
            tab1 = "bold,italic,underline,undo,redo,link,unlink,separator,image,separator,fontselect";
            tab2 = "";
            tab3 = "";
        break;
        case "simple":
            pins = "style,layer,advlink,visualchars,nonbreaking,paste,directionality,fullscreen,preview",
            tab1 = "bold,italic,underline,undo,redo,link,unlink";
            tab2 = "";
            tab3 = "";
        break;   
    }
    
    tinyMCE.init({
            mode : ""+e_mode+"",
            elements : ""+ta_name+"",
            theme : "advanced",
            content_css : "/css/base.css",
            //plugins : "zoom,flash",
            plugins : "style,layer,table,advhr,advimage,advlink,noneditable,visualchars,nonbreaking,xhtmlxtras,template,paste,directionality,fullscreen,preview,filemanager",
            theme_advanced_buttons1 : ""+tab1+"",
            theme_advanced_buttons2 : ""+tab2+"",
            theme_advanced_buttons3 : tab3,
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_path_location : "bottom",
            convert_urls : false,
            font_size_style_values : "xx-small,x-small,small,11px,medium,large,x-large",
            //font_size_style_values : "xx-small,x-small,small,11px,medium,large,x-large,xx-large",
            //font_size_style_values : "10px,11px,12px",
            extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],object[align|width|height],param[name|value],embed[src|type|wmode|width|height]",
            language : "hu",
            relative_urls:false
    });     
}

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* News *-**-**-**-**-**-**-*

function addNews() {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "new_form";
    getAjax("news_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("a.modalCloseImg").click(); 
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            editorInit('base','exact','lead');
                            editorInit('full','exact','content');
                        }
                        });
}

var timer = 0; 
function saveNewNews() {
    document.getElementById('box_reflect').innerHTML="<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...";
    var p=postSerializeForm(document.newNews);
    p += "&command=add_new";
    postAjax("news_data.php",p, function(ret){
                            //alert(ret);
                            document.getElementById('box_reflect').innerHTML=ret;
                            timer = setTimeout('refreshNewsList("'+newscateg+'")', 1200); 
                        }); 
}

function refreshNewsList(group) {
    if (group == undefined) group='all';
    document.getElementById('cms_popup').innerHTML="";
    document.getElementById('cms_popup').style.display="none";
    var p=new Array();
    p['bwi'] = document.getElementById("admin_fields").style.width;
    p['top_pos'] = top_pos;
    p['command'] = "refresh";
    p['group_id'] = group;
    p['s_txt'] = document.getElementById("search_text").value;
    newscateg = group;
    getAjax("news_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('admin_fields').innerHTML=xmlHttp.responseText; 
                        }
                        });
}

function editTheNews (id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("news_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("a.modalCloseImg").click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            editorInit('base','exact','lead');
                            editorInit('full','exact','content'); 
                        }
                        });
}

function saveEditedNews() {
    $('box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    
    var p=postSerializeForm(document.editNews);
    p += "&command=edited";
    postAjax("news_data.php",p, function(ret){
                            $('box_reflect').html(ret);
                            timer = setTimeout('refreshNewsList("'+newscateg+'")', 1200);
                        });
}

function delNews(id) {
     if (confirm("Valóban törli a cikket?")) {
        var p=new Array();
        p['command'] = "delete";
        p['delid'] = id;
        getAjax("news_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');refreshNewsList('"+newscateg+"');", 1200); 
                        }
                        });
     }
}

function inactNews(id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "status_change";
    p['aid'] = id;
    getAjax("news_data.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $("a.modalCloseImg").click();
                        $('#cms_popup').html(xmlHttp.responseText);
                        $('#cms_popup').modal();
                        timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');refreshNewsList('"+newscateg+"');", 600); 
                    }
                    });
}

function actNews(id) {
    inactNews(id);
}
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* COMMENTS *-**-**-**-**-**-**-*

function postComment(id,replyto) {
    if (replyto== undefined) replyto = "";
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "commentadd_form";
    p['bid'] = id;
    p['replyto'] = replyto;
    getAjax("comments.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $("a.modalCloseImg").click();
                        $('#cms_popup').html(xmlHttp.responseText);
                        $('#cms_popup').modal();
                        editorInit('simple','exact','the_comment');  
                    }
                    });
}

function sendNewComment() {
    $('#box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    var p=postSerializeForm(document.postComment);
    p += "&command=add_new";
    postAjax("comments.php",p, function(ret){
                            //alert(ret);
                            $('#box_reflect').html(ret);
                            timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');", 1200); 
                        });     
}

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* CONTENTS *-**-**-**-**-**-**-*

function addContent(parent) {
    if (parent == 0 && groupId != 0) parent=groupId;
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "new_form";
    p['parent_id'] = parent;
    getAjax("content_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("a.modalCloseImg").click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            editorInit('simple','textareas','');
                        }
                        });
}

function editTheContent (id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("content_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("a.modalCloseImg").click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            editorInit('simple','textareas','');

                            $("#headUp").uploadify({ 
                            'uploader': '/js/uploadify/uploadify.swf',
                            'script': '/js/uploadify/uploadify.php',
                            'folder': '/images/flaba',
                            'cancelImg': '/images/cancel.png',
                            'fileDesc': 'kép fájlok (JPG,GIF,PNG)',
                            'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
                            'buttonText': 'Feltoltes / csere...',
                            'auto': true,
                            'multi': false,
                            'onComplete': function (event,queueID,fileObj,response,data) {
                                                var q=new Array();
                                                q['command'] = "upd_head";
                                                q['name'] = fileObj.name;
                                                q['size'] = fileObj.size;
                                                q['type'] = fileObj.type;
                                                q['cid'] = id;
                                                getAjax("content_data.php",q, function(){
                                                    if (xmlHttp.responseText.split("#;")[1] == "nok")
                                                        alert(xmlHttp.responseText.split("#;")[0]);
                                                    else {
                                                        $("#editHeadPic").attr("src", xmlHttp.responseText.split("#;")[0]);
                                                        $("#delpicButt").fadeIn("fast");
                                                    }
                                                });
                                            }
                            });
                        } 
    });
}

function delHeadPic(cont_id) {
    var p=new Array();
    p['command'] = "delheadpic";
    p['cont_id'] = cont_id;
    getAjax("content_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            if (xmlHttp.responseText == "ok") {
                                $("#editHeadPic").attr("src", BASEURL+"images/spacer.gif");    
                                $("#delpicButt").fadeOut("fast");
                            } else alert(xmlHttp.responseText);    
                        }
                        });
}

function saveNewContent(group) {
    if (group == undefined) group='0'; 
    $('#box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    var p=postSerializeForm(document.newContent);
    p += "&command=add_new";
    postAjax("content_data.php",p, function(ret){
                            //alert(ret);
                            $('#box_reflect').html(ret);
                            timer = setTimeout('refreshContentList('+group+')', 1200); // group 
                        }); 
}
function delContent(eid, group) {
    if (confirm('Biztosan törli a tartalmat? A művelet nem vonható vissza!')) {
        //$('#box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
        //alert();
        p = "eid="+eid+"&command=delete";
        postAjax("content_data.php",p, function(ret){
                            alert(ret);
                            refreshContentList('+group+');
                        });
    }
}
function saveEditedContent() {
    $('#box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    //alert();
    var p=postSerializeForm(document.editContent);
    p += "&command=edited";
    postAjax("content_data.php",p, function(ret){
                            $('#box_reflect').html(ret);
                            timer = setTimeout('refreshContentList()', 1200);
                        });
}

function refreshContentList(group) {
    if (group == undefined) group='0';
    $('#cms_popup').html("");
    $("a.modalCloseImg").click();
    var p=new Array();
    p['top_pos'] = top_pos;
    p['command'] = "refresh";
    p['groupID'] = group;
    p['mpoint'] = mpoint;
    //p['s_txt'] = document.getElementById("search_text").value;
    contentcateg = group;
    getAjax("content_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('admin_fields').innerHTML=xmlHttp.responseText; 
                        }
                        });
}

function editInContent(cont_id,lang_id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal(); 
    var p=new Array();
    p['command'] = "editIn_form";
    p['eid'] = cont_id;
    p['langid'] = lang_id;
    getAjax("content_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("a.modalCloseImg").click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            editorInit('full','exact','content'); 
                        }
                        });
}

function saveEditedInContent() {
    $('#box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    //alert();
    var p=postSerializeForm(document.editInContent);
    p += "&command=editedIn";
    postAjax("content_data.php",p, function(ret){
                            document.getElementById('box_reflect').innerHTML=ret;
                            timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');", 1200);
                        });
}


//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* AJAX *-**-**-**-**-**-**-*

function getAjax(file,params,ret_func) {
    var urlparam = "";
    keys = array_keys (params);
    for (k=0;k<keys.length;k++) {
        if (urlparam == "") urlparam = "?"; else urlparam = urlparam+"&";
        urlparam = urlparam+keys[k]+"="+params[keys[k]];
    }
    var url = BASEURL+"cms/"+file+urlparam;
    xmlHttp=GetXmlHttpObject(ret_func);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
}

// IE 6 és régebbiekhez
if (typeof(XMLHttpRequest) == "undefined") {
  XMLHttpRequest = function() {
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
      catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
      catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP"); }
      catch(e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(e) {}
    throw new Error("This browser does not support XMLHttpRequest.");
  };
}

var http = new XMLHttpRequest();

function postAjax(file,params,ret_func) {
    //alert(params);

    var http = new XMLHttpRequest();
    
    var url = BASEURL+"cms/"+file;
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = //ret_func();
    function() {//Call a function when the state changes.
        if(http.readyState == 4 && http.status == 200) {
            //alert(http.responseText) 
            ret_func(http.responseText);
            //document.getElementById('box_reflect').innerHTML=xmlHttp.responseText;  
        }
    }  
    http.send(params); 
}

 var objXmlHttp=null
function GetXmlHttpObject(handler)
{
    var objXmlHttp=null

    if (navigator.userAgent.indexOf("MSIE")>=0)
    { 
        var strName="Msxml2.XMLHTTP"
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
        {
            strName="Microsoft.XMLHTTP"
        } 
        try
        { 
            objXmlHttp=new ActiveXObject(strName)
            objXmlHttp.onreadystatechange=handler
            return objXmlHttp
        } 
        catch(e)
            { 
                alert("Error. Scripting for ActiveX might be disabled") 
                return 
            } 
    } 
    if (navigator.userAgent.indexOf("Mozilla")>=0 || navigator.userAgent.indexOf("Opera")>=0 || navigator.userAgent.indexOf("Safari")>=0)
    {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler 
        return objXmlHttp
    }
}
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//-*-*-*-*-*-*-*-*-*-* EGYÉB HASZNOS FGV-EK -*-*-*-*-*-

function array_keys( input, search_value, argStrict ) {
    
    var tmp_arr = new Array();strict = !!argStrict, include = true, cnt = 0;
    var key = '';
    
    for (key in input) {
        include = true;
        if (search_value != undefined) {
            if( strict && input[key] !== search_value ){
                include = false;
            } else if( input[key] != search_value ){
                include = false;
            }
        }
        if (include) {
            tmp_arr.push(key);
        }
    }
    return tmp_arr;
}

function getElementsByClass( searchClass, domNode, tagName) {
    if (domNode == null) domNode = document;
    if (tagName == null) tagName = '*';
    var el = new Array();
    var tags = domNode.getElementsByTagName(tagName);
    var tcl = " "+searchClass+" ";
    for(i=0,j=0; i<tags.length; i++) {
        var test = " " + tags[i].className + " ";
        if (test.indexOf(tcl) != -1)
            el[j++] = tags[i];
    }
    return el;
}
   
function lightup(tobject, opacity){
    if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
    tobject.style.MozOpacity=opacity/100
    else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4)
    //tobject.filters[0].opacity=opacity
    tobject.style.filter = "alpha(opacity:"+opacity+")"; 
}

function setFuggony(container_id){
    fg = document.getElementById("fugg");
    container = document.getElementById(container_id);
    fg.style.width=container.offsetWidth+"px";
    fg.style.height=container.offsetHeight+"px";
    fg.style.display='block';
}

function serializeForm(the_form) {
    
    f=the_form;
    var params = new Array();
    
    inputs= f.getElementsByTagName('input');
    for (i in inputs){
        if (inputs[i].type == "text" || inputs[i].type == "checkbox" || inputs[i].type == "password" || inputs[i].type == "file" || inputs[i].type == "hidden" || inputs[i].type == "radio") {
            if(inputs[i].type=='radio' && !inputs[i].checked){}
                else if(inputs[i].type=='checkbox' && !inputs[i].checked){}
                     else {
                        if (inputs[i].value) params[inputs[i].name]= inputs[i].value;
                            else {
                                if (inputs[i].type=='checkbox') params[inputs[i].name]= 'on';
                                    else params[inputs[i].name]= '';
                            }
                    }
        }
    }
                    
    inputs= f.getElementsByTagName('select');
    for (i in inputs){
        if(!inputs[i].value) params[inputs[i].name]= '';
            else  params[inputs[i].name]= inputs[i].value;
    }
                    
    inputs= f.getElementsByTagName('textarea');
    for (i in inputs){
        if (tinyMCE) {
            if (tinyMCE.editors){
                if (tinyMCE.editors[inputs[i].id]){
                    c = tinyMCE.editors[inputs[i].id].getContent();
                    if (c) c=c.replace(/&/g, '###ANDJEL###');
                } else {
                    c=inputs[i].value;
                    if (c) c=c.replace(/&/g, '###ANDJEL###');
                }
            } else {
                c=inputs[i].value;
                if (c) c=c.replace(/&/g, '###ANDJEL###');
            }
            if(c) params[inputs[i].name]=c; 
        }
        
    }
    
    return params; 
}

function postSerializeForm(the_form) {
    
    f=the_form;
                    var params = '';
                    inputs= f.getElementsByTagName('input');
                    for (i in inputs){
                        if(inputs[i].type=='file'){}
                        else if(inputs[i].type=='radio' && !inputs[i].checked){}
                        else if(inputs[i].type=='checkbox' && !inputs[i].checked){
                            params+=inputs[i].name+'=0&';
                        } else {
                            if (inputs[i].value){
                                c=inputs[i].value.replace(/&/g, '###ANDJEL###');
                                params+=inputs[i].name+'='+c+'&';
                            }
                        }
                    }
                    inputs= f.getElementsByTagName('select');
                    for (i in inputs){
                        opts = inputs[i].options;
                        //alert(opts);
                        params += inputs[i].name+'=';
                        //alert(inputs[i].name+'=');
                        if (opts){
                            //alert(inputs[i].name+' num ' + opts.length);
                            for (o=0; o<opts.length; o++){
                                if (opts[o]) {
                                    //alert(inputs[i].name+'='+opts[o].value +':'+opts[o].selected );
                                    if (opts[o].selected && o!='lastChild') {
                                        params+=opts[o].value+';';
                                    }
                                }
                            }
                        }
                        params=params.substr(0,params.length-1);
                        params+='&';
                    }
                    inputs= f.getElementsByTagName('textarea');
                    for (i in inputs){
                        if (tinyMCE) {
                            if (tinyMCE.editors){
                                if (tinyMCE.editors[inputs[i].id]){
                                    c = tinyMCE.editors[inputs[i].id].getContent();
                                    if (c) c=c.replace(/&/g, '###ANDJEL###');
                                    //alert(c);
                                } else {
                                    c=inputs[i].value;
                                    if (c) c=c.replace(/&/g, '###ANDJEL###');
                                }
                            } else {
                                c=inputs[i].value;
                                if (c) c=c.replace(/&/g, '###ANDJEL###');
                            } 
                            if(!c){
                                params+=inputs[i].name+'=&';
                            } else {
                                params+=inputs[i].name+'='+inputs[i].value+'&';
                                params+=inputs[i].name+'='+c+'&';
                            }
                        }
                        
                    }
                    params=params.replace(/\+/g, '###PLUSZ###');
                    //alert(params);
                    return params;
                    
                }

//

function timeDown() {
    thetime = parseInt($("#timer_show").html())-1;
    $("#timer_show").html(thetime);
    $("#hatravan").val(thetime);
    if (thetime <= 0) {
        $("#timetilt").slideUp("slow");
        $("#theloginform").slideDown("slow");

    } else timer = setTimeout(timeDown, 1000);
}

function logincheck() {
    if (document.loginform.hatravan.value > 0) { 
        alert('Még nem járt le a biztonsági időkorlát!');
        return false;
    } else {
        if (document.loginform.login.value == '' || document.loginform.pass.value == '') {
            alert('Mindkét mező kitöltése kötelető!');
            return false;    
        } else return true;
    }
}

function sleep(ms)
    {
        var dt = new Date();
        dt.setTime(dt.getTime() + ms);
        while (new Date().getTime() < dt.getTime());
    }


// NOT CMS

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* USERS *-**-**-**-**-**-**-*


function refreshUserList(group) {
    if (group == undefined) group='all';
    $('#cms_popup').html("");
    $("a.modalCloseImg").click();
    var p=new Array();
    p['command'] = "refresh";
    p['group_id'] = group;
    //p['s_txt'] = document.getElementById("search_text").value;
    usercateg = group;
    getAjax("felhasznalok.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('#admin_fields').html(xmlHttp.responseText); 
                        }
                        });
}

function editTheUser (id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("felhasznalok.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('#cms_popup').html(xmlHttp.responseText);
                            //editorInit('simple','textareas','');
                        }
                        });
}

function saveEditedUser() {
    $('#box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    //alert();
    var p=postSerializeForm(document.editUser);
    p += "&command=edited";
    postAjax("felhasznalok.php",p, function(ret){
                            $('#box_reflect').html(ret);
                            timer = setTimeout('refreshUserList()', 1200);
                        });
}

function inactUser(id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "status_change";
    p['aid'] = id;
    getAjax("felhasznalok.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $("a.modalCloseImg").click();
                        $('#cms_popup').html(xmlHttp.responseText);
                        $('#cms_popup').modal();
                        timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');refreshUserList('"+usercateg+"');", 600); 
                    }
                    });
}

function actUser(id) {
    inactUser(id);
}

function delUser(id) {
     if (confirm("Valóban törli a felhasználót?")) {
        var p=new Array();
        p['command'] = "delete";
        p['delid'] = id;
        getAjax("felhasznalok.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');refreshUserList('"+usercateg+"');", 1200); 
                        }
                        });
     }
}

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* Tantárgyak *-**-**-**-**-**-**-*


function refreshTantList(group) {
    if (group == undefined) group='all';
    $('#cms_popup').html("");
    $("a.modalCloseImg").click();
    var p=new Array();
    p['command'] = "refresh";
    p['group_id'] = group;
    //p['s_txt'] = document.getElementById("search_text").value;
    usercateg = group;
    getAjax("tantargyak.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('#admin_fields').html(xmlHttp.responseText); 
                        }
                        });
}

function actTant(id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    $('#cms_popup').modal(); 
    var p=new Array();
    p['command'] = "status_change";
    p['aid'] = id;
    getAjax("tantargyak.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $('a.modalCloseImg').click();
                        $('#cms_popup').html(xmlHttp.responseText);
                        $('#cms_popup').modal();
                        timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');refreshTantList('"+usercateg+"');", 600); 
                    }
                    });
}

function delTant(id) {
     if (confirm("Valóban törli a tantárgyat?")) {
        var p=new Array();
        p['command'] = "delete";
        p['delid'] = id;
        getAjax("tantargyak.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');refreshTantList('"+usercateg+"');", 1200); 
                        }
                        });
     }
}

function tantObjs(id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;betöltés folyamatban ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "tant_objs";
    p['tid'] = id;
    getAjax("tantargyak.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $('a.modalCloseImg').click();
                        $('#cms_popup').html(xmlHttp.responseText);
                        $('#cms_popup').modal();
                        //document.getElementById('cms_popup').style.display="block";
                        //timer = setTimeout("document.getElementById('cms_popup').style.display='none';document.getElementById('cms_popup').innerHTML='';refreshTantList('"+usercateg+"');", 1200); 
                    }
                    });
}

function addTantObj(id) {
    var p=new Array();
    p['command'] = "add_tantobj";
    p['tid'] = id;
    p['add'] = $("#add_obj").val();
    getAjax("tantargyak.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $('a.modalCloseImg').click();
                        $('#cms_popup').html(xmlHttp.responseText);
                        $('#cms_popup').modal();
                        //document.getElementById('cms_popup').style.display="block";
                        timer = setTimeout("tantObjs("+id+");", 1000); 
                    }
                    });    
}

function delTantObj(id,oid) {
    if (confirm("Valóban törli az objektumot a listából?")) {
        var p=new Array();
        p['command'] = "del_tantobj";
        p['tid'] = id;
        p['oid'] =oid;
        getAjax("tantargyak.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            //document.getElementById('cms_popup').style.display="block";
                            timer = setTimeout("tantObjs("+id+");", 1000); 
                        }
                        }); 
    }   
}

function addTant (id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;betöltés folyamatban ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "add_form";
    getAjax("tantargyak.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            editorInit('simple','textareas','');
                        }
                        });
}

function addNewTant() {
    $('#box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    //alert();
    var p=postSerializeForm(document.addTant);
    p += "&command=added";
    postAjax("tantargyak.php",p, function(ret){
                            $('#box_reflect').html(ret);
                            timer = setTimeout('refreshTantList()', 1200);
                        });
}

function editTheTant (id) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;betöltés folyamatban ...");
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("tantargyak.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal();
                            editorInit('simple','textareas','');
                        }
                        });
}

function saveEditedTant() {
    $('#box_reflect').html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...");
    //alert();
    var p=postSerializeForm(document.editTant);
    p += "&command=edited";
    postAjax("tantargyak.php",p, function(ret){
                            $('#box_reflect').html(ret);
                            timer = setTimeout('refreshTantList()', 1200);
                        });
}

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* Tantárgyak - kibontva *-**-**-**-**-**-**-*

function resetMulti(theID) {
    options = document.getElementById(theID).options;
    for(i=0;i<options.length;i++) {
        options[i].selected=false;
    }    
}

function refreshTList(type,group) {
    lang = group;
    if (group == undefined)
    {
      group='all';
      lang = 'en';  
    } 
    $('#cms_popup').html('');
    $('a.modalCloseImg').click(); 
    var p=new Array();
    p['command'] = "refresh";
    p['group_id'] = $("#s_dioc").val();
    p['listed_type'] = type;
    p['s_txt'] = $("#s_name").val();
    p['language'] = lang;
    usercateg = group;
    
        if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    getAjax(thefile,p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('#admin_fields').html(xmlHttp.responseText); 
                        }
                        });
}

function editTListItem (type,row,id,lang) {
   if ($('#ext_row_'+row).css("display") == "none") {
        $('#ext_row_'+row).html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'><small>&nbsp;Betöltés folyamatban ...</small>");
        $('#ext_row_'+row).slideDown("slow");
        $('#ext_pic_'+row).attr("src",BASEURL+'images/cms_images/opened_icon.png');
        
        var p=new Array();
        p['command'] = "edit_row";
        p['eid'] = id;
        p['row'] = row;
        p['language'] = lang;
        
        if (type) thefile = type + ".php";
        else thefile = "onlab.php";

       
        getAjax(thefile,p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                $('#ext_row_'+row).hide();
                                $('#ext_row_'+row).html(xmlHttp.responseText);
                                $('#ext_row_'+row).slideDown('slow');
                                //if (type!='meres') editorInit('base','exact','megj');
                                if(type == 'tours' || type == 'words' || type == 'tours_test')
                                {
                                    //alert("tours");
                                  editorInit('full','textareas','');   
                                } 
                                
                                //alert("ment");
                            }
                            });
   } else {
       //alert($('#ext_row_'+row).css("display"));
       if (confirm("Biztosan bezárja mentés nélkül?")) {
           $('#ext_row_'+row).slideUp("slow");
           $('#ext_pic_'+row).attr("src",BASEURL+'images/cms_images/closed_icon.png');
           timer = setTimeout("$('#ext_row_"+row+"').html('')",1000);
           $('#ext_row_'+row).css("height","")
       } 
   }
}

function saveEditedTListItem(type,the_row, lang) {
    kesz = false;
    $('#ext_row_'+the_row).animate({ height:"20px" }, 1000);
    timer = setTimeout("if (!kesz) {$('#ext_row_"+the_row+"').html('<img src=\""+BASEURL+"images/cms_images/loader_mini.gif\">&nbsp;Mentés folyamatban ...')};",1000);
    
    //alert();
    var p=postSerializeForm(document.getElementById("formListItem_"+the_row));
    p += "&command=edited"; //&language= + lang;
    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    postAjax(thefile,p, function(ret){
                            $('#ext_row_'+the_row).html(ret);
                            kesz = true;
                            timer = setTimeout("$('#ext_row_"+the_row+"').slideUp('slow')", 1500);
                            timer1 = setTimeout('refreshTList("'+type+'", "'+lang+'")', 1950);
                        });
}

function editHListItem (type,row,id,force) {
    if ($('#hallg_list_'+row).css("display") == "none" || force == true) {
        $('#hallg_list_'+row).html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'><small>&nbsp;Betöltés folyamatban ...</small>");
        $('#hallg_list_'+row).slideDown("slow");
        $('#hlist_pic_'+row).attr("src",BASEURL+'images/cms_images/opened_icon.png');
        $('#h2list_pic_'+row).attr("src",BASEURL+'images/cms_images/closed_icon.png');
        
        var p=new Array();
        p['command'] = "edit_hlist";
        p['eid'] = id;
        p['row'] = row;
        
        if (type) thefile = type + ".php";
        else thefile = "onlab.php";

        getAjax(thefile,p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                $('#hallg_list_'+row).hide();
                                $('#hallg_list_'+row).html(xmlHttp.responseText);
                                $('#hallg_list_'+row).slideDown('slow');
                                editorInit('full','textareas',''); 
                                
                            }
                            });
   } else {
       //if (confirm("Biztosan bezárja mentés nélkül?")) {
           $('#hallg_list_'+row).slideUp("slow");
           $('#hlist_pic_'+row).attr("src",BASEURL+'images/cms_images/closed_icon.png');
           timer = setTimeout("$('#hallg_list_"+row+"').html('')",1000);
           $('#hallg_list_'+row).css("height","")
       //} 
   }
}

function editH2ListItem (type,row,id,force) {
    if ($('#hallg_list_'+row).css("display") == "none" || force == true) {
        $('#hallg_list_'+row).html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'><small>&nbsp;Betöltés folyamatban ...</small>");
        $('#hallg_list_'+row).slideDown("slow");
        $('#h2list_pic_'+row).attr("src",BASEURL+'images/cms_images/opened_icon.png');
        $('#hlist_pic_'+row).attr("src",BASEURL+'images/cms_images/closed_icon.png');
        
        var p=new Array();
        p['command'] = "edit_h2list";
        p['eid'] = id;
        p['row'] = row;
        
        if (type) thefile = type + ".php";
        else thefile = "onlab.php";

        getAjax(thefile,p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                $('#hallg_list_'+row).hide();
                                $('#hallg_list_'+row).html(xmlHttp.responseText);
                                $('#hallg_list_'+row).slideDown('slow');
                                //editorInit('base','exact','megj'); 
                                
                            }
                            });
   } else {
       //if (confirm("Biztosan bezárja mentés nélkül?")) {
           $('#hallg_list_'+row).slideUp("slow");
           $('#h2list_pic_'+row).attr("src",BASEURL+'images/cms_images/closed_icon.png');
           timer = setTimeout("$('#hallg_list_"+row+"').html('')",1000);
           $('#hallg_list_'+row).css("height","")
       //} 
   }
}

function idpAlert(row,ssz) {
    $('#alert_'+row+'_'+ssz).html("<font color='red'> ! </font>");
}

function saveKurzIdp(eid,row,ssz) {
    var p=new Array();
    p['command'] = "save_idp";
    p['eid'] = eid;
    p['het'] = $('#het_'+row+'_'+ssz).val();      
    p['nap'] = $('#nap_'+row+'_'+ssz).val();      
    p['idopont'] = $('#idopont_'+row+'_'+ssz).val();      
    p['helyszin'] = $('#helyszin_'+row+'_'+ssz).val();
    getAjax("kurzus.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('#alert_'+row+'_'+ssz).html(xmlHttp.responseText);
                            timer = setTimeout("$('#alert_"+row+"_"+ssz+"').html('')", 1200);
                        }
                        });          
}

function addNewKurzIdp(eid,row) {
    var p=new Array();
    p['command'] = "addnew_idp";
    p['eid'] = eid;
    p['het'] = $('#het_new').val();      
    p['nap'] = $('#nap_new').val();      
    p['idopont'] = $('#idopont_new').val();      
    p['helyszin'] = $('#helyszin_new').val();
    getAjax("kurzus.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            editH2ListItem('kurzus',row,eid,true);
                        }
                        });          
}

function delKurzIdp(kiid,eid,row) {
    if (confirm("Valóban törli az időpontot?")) {
        var p=new Array();
        p['command'] = "del_idp";
        p['kiid'] = kiid;
        getAjax("kurzus.php",p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                editH2ListItem('kurzus',row,eid,true);
                            }
                            });
    }     
}

function kurz_news(type,row,id,force) {
    if ($('#news_row_'+row).css("display") == "none" || force == true) {
        $('#news_row_'+row).html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'><small>&nbsp;Betöltés folyamatban ...</small>");
        $('#news_row_'+row).slideDown("slow");

        var p=new Array();
        p['command'] = "kurz_news";
        p['eid'] = id;
        p['row'] = row;
        
        if (type) thefile = type + ".php";
        else thefile = "onlab.php";

        getAjax(thefile,p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                $('#news_row_'+row).hide();
                                $('#news_row_'+row).html(xmlHttp.responseText);
                                $('#news_row_'+row).slideDown('slow');
                                editorInit('base','textareas',''); 
                                $(".datepickers").datepicker();
                                //$.extend($.ui, { datepicker: { version: "@VERSION" } });  
                            }
                            });
   } else {
       //if (confirm("Biztosan bezárja mentés nélkül?")) {
           $('#hallg_list_'+row).slideUp("slow");
           $('#h2list_pic_'+row).attr("src",BASEURL+'images/cms_images/closed_icon.png');
           timer = setTimeout("$('#hallg_list_"+row+"').html('')",1000);
           $('#hallg_list_'+row).css("height","")
       //}
   }
}

function saveKh(khid) {
    
    
    var p=postSerializeForm(document.getElementById("kh_onArticle_"+khid));
    p += "&command=savekh";
    p += "&cim="+$("#kh_cim_"+khid).val();
    p += "&eid="+khid;
    p += "&felkerult="+$("#kh_date_"+khid).val()+" "+$("#kh_time_"+khid).val();
    if ($("#kh_active_"+khid).attr('checked')) p += "&status=1";
        else p += "&status=0";

    postAjax("kurzus.php",p, function(ret){
                            $("#kh_refl_"+khid).html(ret);
                            timer = setTimeout("$('#kh_refl_"+khid+"').html('')", 1200); 
                        });    
}

function addKH(kurzid,row) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    //document.getElementById('cms_popup').style.display='block';
    $('#cms_popup').modal();
    var p=new Array();
    p['command'] = "addKH";
    p['kurzid'] = kurzid;
    p['row'] = row;
    getAjax("kurzus.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("a.modalCloseImg").click();
                            $('#cms_popup').html(xmlHttp.responseText);
                            editorInit('base','textareas','');
                            $('#cms_popup').modal();
                            $(".datepickers").datepicker(); 
                        }
                        });    
}

function saveNewKh(kid,row) {
     var p=postSerializeForm(document.kh_onArticle_new);
     p += "&command=savenewkh";
     postAjax("kurzus.php",p, function(ret){
                            $('a.modalCloseImg').click();                   
                            $('#cms_popup').html(ret);
                            $('#cms_popup').modal(); 
                            kurz_news('kurzus',row,kid,true);                   
                            timer = setTimeout("$('a.modalCloseImg').click();", 1200); 
                        });    
}

function delKH(khid,kid,row) {
     if (confirm("Valóban törölni kívánja a hírt?")) {
        var p=new Array();
        p['command'] = "delKH";
        p['kurzid'] = kid;
        p['khid'] = khid;
        getAjax("kurzus.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            //xmlHttp.responseText; 
                            kurz_news('kurzus',row,kid,true);
                        }
                        });   
     }
}

function chgHStatus(type,itemid,hallgid,nstat) {
    var p=new Array();
    p['command'] = "chg_hallg_status";
    p['eid'] = itemid;
    p['hid'] = hallgid;
    p['nstat'] = nstat;
    
    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    getAjax(thefile,p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                            if (p['nstat'] == "1") $("#oszt_"+itemid+"_"+hallgid).show();
                                else $("#oszt_"+itemid+"_"+hallgid).hide();
                        }
                        });
}

function chgHOszt(type,itemid,hallgid,oszt) {
        
    var p=new Array();
    p['command'] = "chg_osztalyzat";
    p['eid'] = itemid;
    p['hid'] = hallgid;
    p['oszt'] = oszt;
    
    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    getAjax(thefile,p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                        }
                        });
}

function chgHVtant(type,itemid,hallgid,tant_id) {
    var p=new Array();
    p['command'] = "chg_vtant";
    p['eid'] = itemid;
    p['hid'] = hallgid;
    p['tant_id'] = tant_id;
    
    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    getAjax(thefile,p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                        }
                        });   
}

function actTListItem(type,id,obj) {

    if (obj.className=='act_button') obj.className = "inact_button"; else obj.className = "act_button";
    
    var p=new Array();
    p['command'] = "status_change";
    p['aid'] = id;
    
    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    getAjax(thefile,p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();                   
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal(); 
                            timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');", 1200);
                            if (type=='felev') timer1 = setTimeout("refreshTList('"+type+"','"+usercateg+"');", 1200);   
                    }
                    });
}

function delTListItem(type,id) {
     if (confirm("Valóban törli a bejegyzést?")) {
        var p=new Array();
        p['command'] = "delete";
        p['delid'] = id;
        
        if (type) thefile = type + ".php";
        else thefile = "onlab.php";

        getAjax(thefile,p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();                   
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal(); 
                            timer = setTimeout("$('a.modalCloseImg').click();$('#cms_popup').html('');refreshTList('"+type+"','"+usercateg+"');", 1200); 
                        }
                        });
     }
}

function addTListItem (type) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal(); 
    var p=new Array();
    p['command'] = "add_form";
    
    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    getAjax(thefile,p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();                   
                            $('#cms_popup').html(xmlHttp.responseText);
                            //editorInit('base','exact','megj');
                            $('#cms_popup').modal(); 
                            //if (type == "meres") editorInit('base','exact','r_leir'); 
                                if(type == 'tours' || type == 'words' || type == 'tours_test')
                                {
                                    //alert("tours");
                                  editorInit('base','textareas','');   
                                } 
                        }
                        });
}

function saveNewTListItem (type) {
    kesz = false;
    //<br />$('#cms_popup').animate({ height:"20px" }, 1000);
    timer = setTimeout("if (!kesz) {$('#cms_popup').html('<img src=\""+BASEURL+"images/cms_images/loader_mini.gif\">&nbsp;Mentés folyamatban ...')};",1000);
    
    //alert();
    var p=postSerializeForm(document.addListItem);
    p += "&command=save_new";

    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    postAjax(thefile,p, function(ret){
                            $('#cms_popup').html(ret);
                            kesz = true;
                            timer = setTimeout("$('#cms_popup').slideUp('slow');", 1500);
                            timer1 = setTimeout('refreshTList("'+type+'")', 1750);
                        });   
}


function removeWordEveProg(type, row, eveprog_id,word_id){
    var p = "eveid="+eveprog_id+"&word_id="+word_id;
    p += "&command=removeWordEveprog";
    thefile = type + ".php";
    postAjax(thefile,p, function(ret){
                            //alert(ret);
                            timer1 = setTimeout('editHListItem("'+type+'","'+row+'","'+word_id+'",true)', 1000);
                        });   
    
}
function addWordEveProg(type, row, eveprog_id,word_id){
    var p = "eveid="+eveprog_id+"&word_id="+word_id;
    p += "&command=addWordEveprog";
    thefile = type + ".php";
    postAjax(thefile,p, function(ret){
                            //alert(ret);
                            timer1 = setTimeout('editHListItem("'+type+'","'+row+'","'+word_id+'",true)', 1000);
                        });   
    
}

function saveEditedEveprog (type, the_row, id) {
    kesz = false;
    $('#ext_row_'+the_row).animate({ height:"20px" }, 1000);
    timer = setTimeout("if (!kesz) {$('#ext_row_"+the_row+"').html('<img src=\""+BASEURL+"images/cms_images/loader_mini.gif\">&nbsp;Mentés folyamatban ...')};",1000);
    
    //alert("eveprog_add_"+the_row);
    var p=postSerializeForm(document.getElementById("eveprog_edit_"+id));
    p += "&command=edited_eveprog";
    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    postAjax(thefile,p, function(ret){
                            $('#ext_row_'+the_row).html(ret);
                            kesz = true;
                            timer = setTimeout("$('#ext_row_"+the_row+"').slideUp('slow')", 1500);
                            timer1 = setTimeout('refreshTList("'+type+'")', 1950);
                        });
}
function editEveProg (type,row,id,force,lang) {
    if ($('#editprog_'+id).css("display") == "none" || force == true) {
        $('#editprog_'+id).html("<img src='"+BASEURL+"images/cms_images/loader_mini.gif'><small>&nbsp;Betöltés folyamatban ...</small>");
        $('#editprog_'+id).slideDown("slow");
        $('#editprog_pic_'+id).attr("src",BASEURL+'images/cms_images/opened_icon.png');
        $('#editprog_'+id).attr("src",BASEURL+'images/cms_images/closed_icon.png');
        
        var p=new Array();
        p['command'] = "edit_eve_prog";
        p['id'] = id;
        p['row'] = row;
        p['language'] = lang;
        
        if (type) thefile = type + ".php";
        else thefile = "onlab.php";

        getAjax(thefile,p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                $('#editprog_'+id).hide();
                                $('#editprog_'+id).html(xmlHttp.responseText);
                                $('#editprog_'+id).slideDown('slow');
                                editorInit('full','exact','leiras'+id); 
                            }
                            });
   } else {
       //if (confirm("Biztosan bezárja mentés nélkül?")) {
           $('#editprog_'+id).slideUp("slow");
           $('#editprog_pic_'+id).attr("src",BASEURL+'images/cms_images/closed_icon.png');
           timer = setTimeout("$('#editprog_"+id+"').html('')",1000);
           $('#editprog_'+id).css("height","")
       //} 
   }}

function saveNewEveprog (type,the_row) {
    kesz = false;
    $('#ext_row_'+the_row).animate({ height:"20px" }, 1000);
    timer = setTimeout("if (!kesz) {$('#ext_row_"+the_row+"').html('<img src=\""+BASEURL+"images/cms_images/loader_mini.gif\">&nbsp;Mentés folyamatban ...')};",1000);
    
    //alert("eveprog_add_"+the_row);
    var p=postSerializeForm(document.getElementById("eveprog_add_"+the_row));
    p += "&command=save_new_eveprog";
    if (type) thefile = type + ".php";
        else thefile = "onlab.php";

    postAjax(thefile,p, function(ret){
                            $('#ext_row_'+the_row).html(ret);
                            kesz = true;
                            timer = setTimeout("$('#ext_row_"+the_row+"').slideUp('slow')", 1500);
                            timer1 = setTimeout('refreshTList("'+type+'")', 1950);
                        });
}


function saveTerheles(fid,eid,value) {
    var p=new Array();
    p['command'] = "save_terh";
    p['eid'] = eid;
    p['fid'] = fid;
    p['value'] = value;
    getAjax("kurzus.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            //alert(xmlHttp.responseText);
                            $("#new_terh_"+eid).val(xmlHttp.responseText);        
                        }
                        });
}

function addNewTerh(eid,row) {
    var p=new Array();
    p['command'] = "add_terh";
    p['eid'] = eid;
    p['fid'] = document.getElementById("fe_id_"+eid).options[document.getElementById("fe_id_"+eid).selectedIndex].value;
    p['value'] = document.getElementById("new_terh_"+eid).value;                
    getAjax("kurzus.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            editHListItem('kurzus',row,eid,true);
                            //alert(xmlHttp.responseText);        
                        }
                        }); 
}

function delTerheles(fid,eid,row) {
    if (confirm("Valóban törölni kívánja az oktatót a listából?")) {
        var p=new Array();
        p['command'] = "del_terh";
        p['eid'] = eid;
        p['fid'] = fid;              
        getAjax("kurzus.php",p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                editHListItem('kurzus',row,eid,true);       
                            }
                            });
    } 
}

//-*-*-*-*-*-*-*-**-**-*-*-*-

function delMalk(maid,eid,row) {
    if (confirm("Valóban törölni kívánja az alkalmat?")) {
        var p=new Array();
        p['command'] = "del_malk";
        p['eid'] = eid;
        p['maid'] = maid;              
        getAjax("meres.php",p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                editHListItem('meres',row,eid,true);       
                            }
                            });
    } 
}

function saveEditedMalk (maid,roww) {
    var p=new Array();
    p['command'] = "edit_malk";
    p['maid'] = maid;
    p['het'] = document.getElementById("het_"+roww).options[document.getElementById("het_"+roww).selectedIndex].value;
    p['nap'] = document.getElementById("nap_"+roww).options[document.getElementById("nap_"+roww).selectedIndex].value;
    p['ora'] = document.getElementById("ora_"+roww).value; 
    p['felelos_id'] = document.getElementById("feid_"+roww).options[document.getElementById("feid_"+roww).selectedIndex].value;           
    p['matip'] = document.getElementById("tip_"+roww).options[document.getElementById("tip_"+roww).selectedIndex].value;           
    p['hlim'] = document.getElementById("hlim_"+roww).value; 
    getAjax("meres.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            //alert(xmlHttp.responseText);
                            $("#resp_"+roww).html(xmlHttp.responseText);
                            timer = setTimeout("$('#resp_"+roww+"').html('');", 1500);       
                        }
                        });
}

function markIt(obj) {
    id=obj.id.split("_")[1];
     $("#resp_"+id).html('<font color="red"><b>!</b></font>');
}

function saveNewMalk (eid,row) {
    var p=new Array();
    p['command'] = "add_malk";
    p['eid'] = eid;
    p['het'] = document.getElementById("het_new").options[document.getElementById("het_new").selectedIndex].value;
    p['nap'] = document.getElementById("nap_new").options[document.getElementById("nap_new").selectedIndex].value;
    p['ora'] = document.getElementById("ora_new").value; 
    p['felelos_id'] = document.getElementById("feid_new").options[document.getElementById("feid_new").selectedIndex].value;           
    p['matip'] = document.getElementById("tip_new").options[document.getElementById("tip_new").selectedIndex].value;           
    p['hlim'] = document.getElementById("hlim_new").value;
    getAjax("meres.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            editHListItem('meres',row,eid,true);      
                        }
                        });
}

// ------- BETESZ - KIVESZ -------

function betesz(eid,row) {
    var p=new Array();
    sel = $("#nem").val();
    if (sel) {
        p['command'] = "betesz";
        p['eid'] = eid;
        p['sel'] = sel;
        getAjax("felev.php",p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                //alert(xmlHttp.responseText);
                                editHListItem('felev',row,eid,true);      
                            }
                            });
    } else alert("Válassza ki a hozzáadni kívánt tárgyat!");
}

function kivesz(eid,row) {
    var p=new Array();
    sel = $("#igen").val();
    if (sel) {
        p['command'] = "kivesz";
        p['eid'] = eid;
        p['sel'] = sel;
        getAjax("felev.php",p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                //alert(xmlHttp.responseText);
                                editHListItem('felev',row,eid,true);      
                            }
                            });
    } else alert("Válassza ki az eltávolítani kívánt tárgyat!");
}

function kurzTips(eid) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal(); 
    var p=new Array();
    p['command'] = "kurz_tips";
    if (eid == undefined) eid='0';
    p['eid'] = eid;
    getAjax("kurzus.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('a.modalCloseImg').click();                   
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal(); 
                        }
                        });    
}

function saveKurzTip(eid) {
    var p=new Array();
    p['command'] = "savekurztip";
    p['eid'] = eid;
    p['megnev'] = $("#ktMegnev").val();
    p['suly'] = $("#ktSuly").val();
    getAjax("kurzus.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("#ktresp").html(xmlHttp.responseText);
                            timer = setTimeout("kurzTips();", 1500);   
                        }
                        });  
}

function saveNewKurzTip() {
    var p=new Array();
    p['command'] = "savenewkurztip";
    p['megnev'] = $("#newkt").val();
    p['suly'] = $("#newsuly").val();
    if (p['megnev'] != "") {
        getAjax("kurzus.php",p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                $("#newktresp").html(xmlHttp.responseText);
                                timer = setTimeout("kurzTips();", 1500);  
                            }
                            });
    }  
}

function delKurzTip(delid) {
    if (confirm("Valóban törli a tipust?")) {
        var p=new Array();
        p['command'] = "delkurztip";
        p['delid'] = delid;
        getAjax("kurzus.php",p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                $("#newktresp").html(xmlHttp.responseText);
                                timer = setTimeout("kurzTips();", 1200);
                                     
                            }
                            });     
    }
}

function chgLabor(obj,row) {
    $("#obj_sel_"+row).html("<select></select> Betöltés ...");
    var p=new Array();
    p['command'] = "chg_labobj";
    p['labor_id'] = obj.options[obj.selectedIndex].value;
    getAjax("meresalk.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $("#obj_sel_"+row).html(xmlHttp.responseText);     
                        }
                        });
    
}

function slideshowEdit(mpoint) {
    $('#cms_popup').html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ...");
    $('#cms_popup').modal(); 
    var p=new Array();
    p['command'] = "edit_ss";
    p['mpoint'] = mpoint;
    getAjax("slideshow.php",p, function(){
                if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                    $('a.modalCloseImg').click();                   
                    $('#cms_popup').html(xmlHttp.responseText);
                    $('#cms_popup').modal({minWidth:600}); 
                    
                    $("#slideUp").uploadify({ 
                            'uploader': '/js/uploadify/uploadify.swf',
                            'script': '/js/uploadify/uploadify.php',
                            'folder': '/images/flaba',
                            'cancelImg': '/images/cancel.png',
                            'fileDesc': 'kép fájlok (JPG,GIF,PNG)',
                            'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
                            'buttonText': 'Uj feltoltes...',
                            'auto': true,
                            'multi': false,
                            'onComplete': function (event,queueID,fileObj,response,data) {
                                                var q=new Array();
                                                q['command'] = "upd_slide";
                                                q['name'] = fileObj.name;
                                                q['size'] = fileObj.size;
                                                q['type'] = fileObj.type;
                                                q['mid'] = mpoint;
                                                getAjax("slideshow.php",q, function(){
                                                    if (xmlHttp.responseText == "nok")
                                                        alert("Sikertelen feltöltés!");
                                                    else {
                                                       slideshowEdit(mpoint);
                                                    }
                                                });
                                            }
                            });
                }
    });
}

function delSPic(picid,mpoint) {
    var p=new Array();
    p['command'] = "del_pic";
    p['picid'] = picid;
    p['mid'] = mpoint;
    getAjax("slideshow.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                            slideshowEdit(mpoint);     
                        }
                        });
}


function moveUp(picid,mpoint) {
    var p=new Array();
    p['command'] = "moveup_pic";
    p['picid'] = picid;
    p['mid'] = mpoint;
    getAjax("slideshow.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                            slideshowEdit(mpoint);     
                        }
                        });
}

function moveDown(picid,mpoint) {
    var p=new Array();
    p['command'] = "movedown_pic";
    p['picid'] = picid;
    p['mid'] = mpoint;
    getAjax("slideshow.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                            slideshowEdit(mpoint);     
                        }
                        });
}
