
var tinyMCE=null;
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* Categ *-**-**-**-**-**-**-*

function addCateg(sel) {
    document.getElementById('cms_popup').innerHTML="<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';
    var p=new Array();
    p['command'] = "new_form";
    p['selected'] = sel;
    getAjax("categ_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('cms_popup').innerHTML=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() {
    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;
    getAjax("categ_list.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('admin_fields').innerHTML=xmlHttp.responseText; 
                        }
                        });
}

function editCateg (id) {
    document.getElementById('cms_popup').innerHTML="<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';
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("categ_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText; 
                        }
                        });
}

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") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            document.getElementById('cms_popup').style.display="block";
                            timer = setTimeout("document.getElementById('cms_popup').style.display='none';document.getElementById('cms_popup').innerHTML='';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,link,unlink,image,media";
            tab2 = "undo,redo,,separator,fontselect,fontsizeselect,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, code";
        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,code,media";
            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;
        case "just_text":
            pins = "style,layer,visualchars,nonbreaking,paste,directionality,fullscreen,preview",
            tab1 = "bold,italic,underline,separator,undo,redo,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist";
            tab2 = "";
            tab3 = "";
        break;    
    }
    
    tinyMCE.init({
            mode : ""+e_mode+"",
            elements : ""+ta_name+"",
            theme : "advanced",
            //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",                                                                                                                                                                                                                                                      
            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|_value],embed[quality|type|pluginspage|width|height|src|align|allowscriptaccess|allowfullscreen],iframe[src|scrolling|frameborder|style|allowTransparency]",
            language : "hu",
            relative_urls:false
    });     
}

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

function addNews() {
    document.getElementById('cms_popup').innerHTML="<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';
    var p=new Array();
    p['command'] = "new_form";
    getAjax("news_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            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) {
    document.getElementById('cms_popup').innerHTML="<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';
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("news_data.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            editorInit('base','exact','lead');
                            editorInit('full','exact','content'); 
                        }
                        });
}

function saveEditedNews() {
    document.getElementById('box_reflect').innerHTML="<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){
                            document.getElementById('box_reflect').innerHTML=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") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            document.getElementById('cms_popup').style.display="block";
                            timer = setTimeout("document.getElementById('cms_popup').style.display='none';document.getElementById('cms_popup').innerHTML='';refreshNewsList('"+newscateg+"');", 1200); 
                        }
                        });
     }
}

function inactNews(id) {
    document.getElementById('cms_popup').innerHTML="<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...";
    document.getElementById('cms_popup').style.display="block";
    var p=new Array();
    p['command'] = "status_change";
    p['aid'] = id;
    getAjax("news_data.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                        timer = setTimeout("document.getElementById('cms_popup').style.display='none';document.getElementById('cms_popup').innerHTML='';refreshNewsList('"+newscateg+"');", 600); 
                    }
                    });
}

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

function postComment(id,replyto) {
    if (replyto== undefined) replyto = "";
    document.getElementById('cms_popup').innerHTML="<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';
    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") {
                        document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                        editorInit('simple','exact','the_comment');  
                    }
                    });
}

function sendNewComment() {
    document.getElementById('box_reflect').innerHTML="<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);
                            document.getElementById('box_reflect').innerHTML=ret;
                            timer = setTimeout('document.getElementById("cms_popup").innerHTML="";document.getElementById("cms_popup").style.display="none";', 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+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+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=0; i<inputs.length; i++){ 
        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=0; i<inputs.length; i++){ 
        opts = inputs[i].options;
        params+=inputs[i].name+'=';
        if (opts){
            for (o=0; o<opts.length;o++){ 
                if (opts[o]) {
                    if (opts[o].selected && o!='lastChild') {
                        params+=opts[o].value+';';
                    }
                }
            }
        }
        params=params.substr(0,params.length-1);
        params+='&';
    }
    inputs= f.getElementsByTagName('textarea');
    for (i=0; i<inputs.length; i++){ 
        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+'&';
            }
        } else params+=inputs[i].name+'='+inputs[i].value+'&';
        
    }
    params=params.replace(/\+/g, '###PLUSZ###');
    //alert(params);
    return params;
    
}

//

function timeDown() {
    thetime = parseInt(document.getElementById("timer_show").innerHTML)-1;
    document.getElementById("timer_show").innerHTML = thetime;
    document.getElementById("hatravan").value = 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';
    document.getElementById('cms_popup').innerHTML="";
    document.getElementById('cms_popup').style.display="none";
    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") {
                            document.getElementById('admin_fields').innerHTML=xmlHttp.responseText; 
                        }
                        });
}

function editTheUser (id) {
    document.getElementById('cms_popup').innerHTML="<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';
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("felhasznalok.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            //editorInit('simple','textareas','');
                        }
                        });
}

function saveEditedUser() {
    document.getElementById('box_reflect').innerHTML="<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){
                            document.getElementById('box_reflect').innerHTML=ret;
                            timer = setTimeout('refreshUserList()', 1200);
                        });
}

function inactUser(id) {
    document.getElementById('cms_popup').innerHTML="<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...";
    document.getElementById('cms_popup').style.display="block";
    var p=new Array();
    p['command'] = "status_change";
    p['aid'] = id;
    getAjax("felhasznalok.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                        timer = setTimeout("document.getElementById('cms_popup').style.display='none';document.getElementById('cms_popup').innerHTML='';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") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            document.getElementById('cms_popup').style.display="block";
                            timer = setTimeout("document.getElementById('cms_popup').style.display='none';document.getElementById('cms_popup').innerHTML='';refreshUserList('"+usercateg+"');", 1200); 
                        }
                        });
     }
}

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


function refreshTantList(group) {
    if (group == undefined) group='all';
    document.getElementById('cms_popup').innerHTML="";
    document.getElementById('cms_popup').style.display="none";
    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") {
                            document.getElementById('admin_fields').innerHTML=xmlHttp.responseText; 
                        }
                        });
}

function actTant(id) {
    document.getElementById('cms_popup').innerHTML="<img src='"+BASEURL+"images/cms_images/loader_mini.gif'>&nbsp;Mentés folyamatban ...";
    document.getElementById('cms_popup').style.display="block";
    var p=new Array();
    p['command'] = "status_change";
    p['aid'] = id;
    getAjax("tantargyak.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                        timer = setTimeout("document.getElementById('cms_popup').style.display='none';document.getElementById('cms_popup').innerHTML='';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") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            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 addTant (id) {
    document.getElementById('cms_popup').innerHTML="<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';
    var p=new Array();
    p['command'] = "add_form";
    getAjax("tantargyak.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            //editorInit('simple','textareas','');
                        }
                        });
}

function addNewTant() {
    document.getElementById('box_reflect').innerHTML="<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){
                            document.getElementById('box_reflect').innerHTML=ret;
                            timer = setTimeout('refreshTantList()', 1200);
                        });
}

function editTheTant (id) {
    document.getElementById('cms_popup').innerHTML="<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';
    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = id;
    getAjax("tantargyak.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            document.getElementById('cms_popup').innerHTML=xmlHttp.responseText;
                            //editorInit('simple','textareas','');
                        }
                        });
}

function saveEditedTant() {
    document.getElementById('box_reflect').innerHTML="<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){
                            document.getElementById('box_reflect').innerHTML=ret;
                            timer = setTimeout('refreshTantList()', 1200);
                        });
}

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

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');
        
        var p=new Array();
        p['command'] = "edit_hlist";
        p['eid'] = id;
        p['row'] = row;
        switch (type) {
           case "onlab": thefile="onlab.php";break;
           case "kurzus": thefile="kurzus.php";break; 
           case "meres": thefile="meres.php";break; 
           case "felev": thefile="felev.php";break; 
           
           default: thefile= "onlab.php"; break;
        }
        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");
           $('#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 chgHStatus(type,itemid,hallgid,nstat) {
        
    var p=new Array();
    p['command'] = "chg_hallg_status";
    p['eid'] = itemid;
    p['hid'] = hallgid;
    p['nstat'] = nstat;
    switch (type) {
       case "onlab": thefile="onlab.php";break;
       case "kurzus": thefile="kurzus.php";break; 
       case "meres": thefile="meres.php";break; 
       case "felev": thefile="felev.php";break; 
           
       default: thefile= "onlab.php"; break;
    }
    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;
    switch (type) {
       case "onlab": thefile="onlab.php";break;
       case "kurzus": thefile="kurzus.php";break; 
       case "meres": thefile="meres.php";break; 
       case "felev": thefile="felev.php";break; 
           
       default: thefile= "onlab.php"; break;
    }
    getAjax(thefile,p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                        }
                        });
}

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);        
                        }
                        });
}

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 forgPass(username) {
    if (username == undefined) username='';  
    var p=new Array();
    p['username'] = username; 
    p['command'] = "forg_pass"; 
    p['module'] = "felhasznalok"; 
    getAjax("ajax.php",p, function(){
                       //alert(xmlHttp.responseText); 
                       $('#forg_pass_pop').html(xmlHttp.responseText);
                       $('#forg_pass_pop').modal();
                  });
}

function getPass() {
    var p=new Array();
    p['username'] = $("#fp_username").val();
    p['code'] = $("#fp_code").val(); 
    p['command'] = "forg_pass";
    p['module'] = "felhasznalok";
    getAjax("ajax.php",p, function(){
                       //alert(xmlHttp.responseText);
                       $('a.modalCloseImg').click();
                       $('#forg_pass_pop').html(xmlHttp.responseText.split("_")[0]);
                       $('#forg_pass_pop').modal();
                       if (xmlHttp.responseText.split("_")[1] == "nok") timer = setTimeout("forgPass('"+p['username']+"');",1500); 
                        else timer = setTimeout("$('a.modalCloseImg').click();",1200);
                  });
}
