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

function slider(title, type) {
    if (type==undefined) type='id';
    
    pre = undefined;
    if (type=='id') pre = "#";
    if (type=='class') pre = ".";
    
    if (pre != undefined) {
        if ($(pre+title).css("display") == "none") $(pre+title).slideDown("fast");
            else $(pre+title).slideUp("fast");
    }
    
}

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

var dragOK=false;

function moveHandler2(e){
  if (e == null) { e = window.event } 
  //$("#respp").html(savedTarget.id+" "+Math.random());
  if (e.button<=1&&dragOK){
     savedTarget.style.top=e.clientY-dragYoffset+'px';
     savedTarget.style.left=e.clientX-dragXoffset+'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 dropItem(e) {
  objz = $(".field_over");
  $(".field_over_tilt").removeClass("field_over_tilt");
  if (objz.length == 1) {
      //alert($(objz[0]).attr("id"));
      str = $(objz[0]).attr("id");
      targ_id = "#"+str.replace("equip","cont");
      hid_id = "#"+str.replace("equip","itemid");

      $(targ_id).removeClass("dragTilt");
      $(targ_id).css("background",savedTarget.style.background);
      $(targ_id).css("z-index","10");
      
      hid_id = "#"+savedTarget.id.replace("cont","itemid");
      
      //alert(targ_id.replace("inv","itemid")+ " "+ targ_id);
      if ("#"+savedTarget.id != targ_id && targ_id.replace("inv","itemid") != hid_id) {
          savedTarget.style.background="";
          savedTarget.style.zIndex="1000";
          savedTarget.className="equip_field_drag dragTilt";

          //alert("toslot="+targ_id+"&fromslot="+hid_id);
          $("#map_resp").html("toslot="+targ_id+"&fromslot="+hid_id);
          //alert($(hid_id).val());
          $("#tp_fuggony").html("Mentés folyamatban ...");
          $('#tp_fuggony').animate({ opacity:0.7 }, 0);
          $('#tp_fuggony').show();
          $("#bp_fuggony").html("Mentés folyamatban ...");
          $('#bp_fuggony').animate({ opacity:0.7 }, 0);
          $('#bp_fuggony').show();
          $("#ol2_fuggony").html("Mentés folyamatban ...");
          $('#ol2_fuggony').animate({ opacity:0.7 }, 0);
          $('#ol2_fuggony').show();
          var oival = $("#overItems").val();
          if (!$("#overItems").length ) var oival = "char_page";
          var binn = (binedItemsAr) ? 1 : 0;
          $.ajax({
            type: "POST",
            url: BASEURL+"ajax/character.php",
            data: "command=itemMove&itemid="+$(hid_id).val()+"&toslot="+targ_id+"&fromslot="+hid_id+"&overItems="+oival+"&binn="+binn,
            cache: false,
            success:
                function(result){
                    //if (DEVEL) alert(result);
                    rsplit = result.split(";_;_");
                    if (rsplit[0] == "nok") alert("Sikertelen!");
                    //$("#tools_panel").html("gsdfg");
                    if (oival == "char_page") $("#tools_panel").html(rsplit[1]);
                        else {
                            //if (DEVEL) alert(rsplit[1]);
                            rsplit_split=rsplit[1].split("#;#;");
                            $("#overload2_items").html(rsplit_split[0]);
                            $("#overItems").val(rsplit_split[1]);
                        }
                    if (rsplit[2]) $("#taska_panel").html(rsplit[2]);
                        else {
                           $("#bp_fuggony").html("");
                           $('#bp_fuggony').hide();
                        }
                     if (oival == "char_page") refreshCharPoints();
                } 
          });
      } else if (/^\#inv_\d+$/.test(targ_id)) $(targ_id).css("background","");
  } 
  document.onmousemove=null;
  document.onmouseup=null;
  savedTarget.style.cursor = orgCursor;
  savedTarget.style.zIndex = 10;
  
  savedTarget.style.top='0px';
  savedTarget.style.left='0px';
  
  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;
  }
  //$("#respp").html($(target).attr("class"));
  if (target.className=="invent_field_drag" || target.className=="equip_field_drag") {
      hidePositionedDiv();
      savedTarget=target;
     //saveTop = savedTarget.style.top;       
     target.style.cursor=htype;
     target.style.zIndex = 100;
     dragOK=true;
     dragYoffset=e.clientY-parseInt(vidPaneID.style.top);
     dragXoffset=e.clientX-parseInt(vidPaneID.style.left);
     document.onmousemove=moveHandler2;
     document.onmouseup=dropItem;
     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();    
}
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* 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";
            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,separator,code";
        break;
        case "mail":
            pins = "style,expers_mess,head_insert,foot_insert,layer,table,advhr,advimage,advlink,noneditable,visualchars,nonbreaking,xhtmlxtras,template,paste,directionality,fullscreen,preview,filemanager",
            tab1 = "bold,italic,underline,strikethrough,separator,sub,sup,separator,bullist,numlist,separator,outdent,indent ,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,separator,image,table,hr";
            tab2 = "undo,redo,separator,fontselect,fontsizeselect,forecolor,backcolor,separator,expers_mess,head_insert,foot_insert"; //,col_after,col_before,row_after,row_before,delete_col,delete_row,row_props,cell_props";
            tab3 = "";
        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",
            //plugins : "zoom,flash",
            plugins : ""+pins+"",
            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],embed[src|type|wmode|width|height]",
            language : "hu",
            relative_urls:false
    });     
}

  //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* 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({minWidth:420});
                            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({minWidth:420});
                            editorInit('simple','textareas',''); 
                        }
                        });
}

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.split("_")[0]);
                            txt = $('#cont_nav').html();
                            if (txt.indexOf(ret.split("_")[1]) == -1) $('#cont_nav').html(txt+ret.split("_")[1]+"&nbsp;&#187;&nbsp;"); 
                            //$('#add_new_content').attr('href', 'javascript:addContent('+group+')');
                            timer = setTimeout('refreshContentList('+group+')', 1200); // 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({minWidth:750});
                            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);
                        });
}

function delContent(id, num, group) {
    if (num > 0) alert("Előbb az almenüpontokat kell törölni!");
    else 
    if (confirm("Valóban törli a tartalmat?")) {
        var p=new Array();
        p['command'] = "delete";
        p['delid'] = id;
        getAjax("content_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('');refreshContentList('"+group+"');", 1000); 
                        }
                        });
     }    
}

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* 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;
    if(params["x"] == '1') {
        xmlHttp1=GetXmlHttpObject(ret_func);
        xmlHttp1.open("GET", url , true);
        xmlHttp1.send(null);
    } else {
        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();
    
    if (file.split("/")[0] != "ajax") var url = BASEURL+"cms/"+file;
        else 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 OpenNewWindowNoScroll(url, x, y) {
    var options = "toolbar=no,menubar=no,scrollbars=no,resizable=yes,width=" + x + ",height=" + y;
        msgWindow=window.open(url,"", options);
}

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 in_array (needle, haystack, argStrict) {
    var key = '', strict = !!argStrict; 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {                
                return true;
            }
        }
    }
    return false;
}
   
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=0; i<inputs.length; i++){ 
        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=0; i<inputs.length; i++){ 
        if(!inputs[i].value) params[inputs[i].name]= '';
            else  params[inputs[i].name]= inputs[i].value;
    }
                    
    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###');
                } 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++){ 
                        if(inputs[i].name=='vid'){}
                        else if(!inputs[i].value){
                            params+=inputs[i].name+'=&';
                        } else {
                            params+=inputs[i].name+'='+inputs[i].value+'&';
                        }
                    }
                    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(inputs[i].id);
                                } 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###');

                    return params;
                    
                }

function serializeTA(ta_txt) {
    
    var c=ta_txt.replace(/&/g, '###ANDJEL###');
    c=c.replace(/\+/g, '###PLUSZ###');

    return c;
    
}

//

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

function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}

function serialize (mixed_value) {
    
    var _getType = function (inp) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {
            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            match = cons.match(/(\w+)\(/);
            if (match) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {
        case "function": 
            val = ""; 
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
            //mixed_value = this.utf8_encode(mixed_value);
            val = "s:" + encodeURIComponent(mixed_value).replace(/%../g, 'x').length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") { 
                    continue; 
                }
                
                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
                vals += this.serialize(okey) +
                        this.serialize(mixed_value[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
        case "undefined": // Fall-through
        default: // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP
            val = "N";
            break;
    }
    if (type != "object" && type != "array") {
        val += ";";
    }
    return val;
}

function is_object (mixed_var){
    if (mixed_var instanceof Array) {
        return false;
    } else {
        return (mixed_var !== null) && (typeof( mixed_var ) == 'object');
    }
}

// NOT CMS

/*------------------------------------------------------
/*------------------------------------------------------*/
function refreshTList(type,group) {
    $('#admin_fields').html("Betöltés folyamatban ...");
    if (group == undefined) group='all';
    $('#cms_popup').html('');
    $('a.modalCloseImg').click(); 
    if (type=='items') var p=serializeForm(document.filter_form);
        else var p=new Array();
    p['command'] = "refresh";
    p['group_id'] = group;
    p['listed_type'] = type;
    if (type=='fights') p['page'] = $('#page').val();
    //p['s_txt'] = document.getElementById("search_text").value;
    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) {
   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;
        
        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 == "missions") {
                                    editorInit('base','exact','start_txt_'+id);
                                    editorInit('base','exact','end_txt_'+id);
                                    editorInit('base','exact','qlog_txt_'+id);    
                                    editorInit('base','exact','park_txt_'+id);    
                                } else if (type == "jobs") {
                                    editorInit('base','exact','description,advert');
                                    //editorInit('base','exact','advert');
                                } else editorInit('base','exact','megj');
                                $(".datepickers").datepicker(); 

                                if (type=="missionpersons" || type=="npcs") {
                                    $("#updPic_"+row).uploadify({ 
                                        'uploader': '/js/uploadify/uploadify.swf',
                                        'script': '/js/uploadify/uploadify.php',
                                        'folder': BASE+'images/missions/'+type+'/tmp',
                                        'cancelImg': '/images/cancel.png',
                                        'fileDesc': 'kép fájlok (JPG,GIF,PNG)',
                                        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
                                        'buttonText': 'Kep csere...',
                                        'auto': true,
                                        'multi': false,
                                        'onComplete': function (event,queueID,fileObj,response,data) {
                                                            var q=new Array();
                                                            q['command'] = "upd_pic";
                                                            q['name'] = fileObj.name;
                                                            q['size'] = fileObj.size;
                                                            q['type'] = fileObj.type;
                                                            q['eid'] = id;
                                                            getAjax(thefile,q, function(){
                                                                if (xmlHttp.responseText == "nok")
                                                                    alert("Sikertelen feltöltés!");
                                                                else {
                                                                   //alert(xmlHttp.responseText);
                                                                    $("#pers_pic_"+row).attr("src",BASEURL+"images/missions/"+type+"/"+xmlHttp.responseText);
                                                                    $("#ed_pers_pic_"+row).attr("src",BASEURL+"images/missions/"+type+"/"+xmlHttp.responseText);
                                                                }
                                                            });
                                                        }
                                        });
                                }
                            }
                            });
   } else {
       if (type=='hallg_tant' || type=='hallg_onlab' ) {
            $('#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","");
       } else
       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) {
    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";
    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 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 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 == "hallg_tant") p['selfelev'] = $("#selfelev").val();

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

    getAjax(thefile,p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            //alert(xmlHttp.responseText);
                            $('a.modalCloseImg').click();                   
                            $('#cms_popup').html(xmlHttp.responseText);
                            $('#cms_popup').modal(); 
                            if (type == "missions") {
                                editorInit('base','exact','start_txt_new');
                                editorInit('base','exact','end_txt_new');
                                editorInit('base','exact','qlog_txt_new');    
                                editorInit('base','exact','park_txt_new');    
                            } else if (type == "jobs") {
                                editorInit('base','exact','description,advert');
                            } else editorInit('base','exact','megj'); 
                            $(".datepickers").datepicker();
                            $("#addmissionform").css("height", $("#simplemodal-container").css("height"));
                        }
                        });
}

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("$('a.modalCloseImg').click();", 1500);
                            timer1 = setTimeout('refreshTList("'+type+'")', 1500);
                        });   
}

function delTListItem(type,id) {
     if (confirm("Valóban törli, az összes kapcsolódó dologgal együtt?")) {
        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 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('base','exact','megj'); 
                                $(".datepickers").datepicker();
                            }
                            });
   } 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","")
       //} 
   }
}

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
//-**-**-**-**-**-**-**-**-* LISTS *-**-**-**-**-**-**-*

function editListData(list) {
    $('#mylist_data').slideUp("fast");

    var p=new Array();
    p['command'] = "edit_form";
    p['eid'] = list;
    getAjax("list_edit.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            $('#mylist_data_edit').html(xmlHttp.responseText);
                            timer = setTimeout("$('#mylist_data_edit').slideDown('fast');", 1000);
                            //timer2 = setTimeout("", 3000);
                            editorInit('simple','textareas','');
                        }
                        });   
}

var listdata = "";
function saveEditedList() {
    $("#reflect").html('Save in progress ...');
    //alert();
    var p=postSerializeForm(document.editList);
    p += "&command=edited";
    postAjax("list_edit.php",p, function(ret){
                            $('#reflect').html(ret.split("_._;_._;")[0]);
                            listdata = ret.split("_._;_._;")[1];
                            timer = setTimeout('refreshListData()', 1200);
                        });
}

function saveNewList() {
    $("#reflect_new").html('Save in progress ...');
    //alert();
    var p=postSerializeForm(document.addList);
    p += "&command=savenewlist";
    postAjax("list_edit.php",p, function(ret){
                            $('#reflect_new').html(ret);
                            timer = setTimeout('window.location.reload()', 1200);
                        });
}

function refreshListData() {
    $('#mylist_data_edit').slideUp('fast');
    $("#mylist_data").html(listdata);
    $('#mylist_data').slideDown('slow');
}

var order = "regdate";
var sc = "DESC";
function  setPanel(type,list){
    var xtra = type.split("_")[1];
    if (xtra==undefined) xtra = "";
    type = type.split("_")[0]; 
    
    $('#mylist_panel').fadeOut("fast");
    if (xtra == "") {
        $('#readers_mark').removeClass("fm_hl");
        $('#mails_mark').removeClass("fm_hl");
        $('#settings_mark').removeClass("fm_hl");
        $('#signupset_mark').removeClass("fm_hl");
        $('#fields_mark').removeClass("fm_hl");
        $('#stats_mark').removeClass("fm_hl");
        $('#headfoot_mark').removeClass("fm_hl");
        $('#templates_mark').removeClass("fm_hl");
    } else {
        if (xtra.split("-")[0] == "order") {
            if (order == xtra.split("-")[1]) {if (sc == "ASC") sc = "DESC"; else sc = "ASC";} else sc = "ASC";
            order = xtra.split("-")[1]; 
        }
    }
    if (type=='signupset') {
        $('#'+type+'_mark').addClass("fm_hl");
        $('#signup_panel').fadeIn('slow');
    } else {
        var p=new Array();
        p['command'] = "setPanel";
        p['eid'] = list;
        p['order'] = order;
        p['sc'] = sc;
        p['type'] = type;
        if (xtra != "") {
            p['s_txt'] = $("#s_txt").val();
            p['s_stat'] = $("#s_stat").val();
        }
        getAjax("list_edit.php",p, function(){
                            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                                $('#signup_panel').fadeOut('fast');
                                $('#'+type+'_mark').addClass("fm_hl");
                                listdata=xmlHttp.responseText;
                                timer = setTimeout("setContPanel('"+list+"','"+type+"');afterAjax();", 200);
                                timer2 = setTimeout("$('#mylist_panel').fadeIn('slow');", 250);
                            }
                            });
    }
}

function setContPanel(list,type) {
    $('#mylist_panel').html(listdata);
    editorInit('simple','exact','unsubsrcibe_text');
    if (type=='headfoot') {
        getHeads(list);
        getFoots(list);
    } 
}

function delListMember(email, list) {
    if (confirm("Are you sure you want to delete this reader?")) {
        
        var p=new Array();
        p['command'] = "delete_member";
        p['email'] = email;
        p['eid'] = list;
        getAjax("list_edit.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                            setPanel('readers_search',list);
                        }
                        });    
    }
}

function editListMember(row,list) {
    name = $("#row_"+row+"_td_1").html();
    email = $("#row_"+row+"_td_2").html();
    //regdate = $("#row_"+row+"_td_3").html();
    options = "<img src='"+BASEURL+"images/cms_images/edit.gif' alt='edit' title='edit' class='pointer' onclick='editListMember("+row+","+list+")' />";//$("#row_"+row+"_td_4").html();
    
    $("#row_"+row+"_td_1").html("<input type='text' id='name_inp_"+row+"' value='"+name+"' />");   
    $("#row_"+row+"_td_2").html("<input type='text' id='email_inp_"+row+"' value='"+email+"' />");   
    //$("#row_"+row+"_td_3").html("<input type='text' id='regdate_inp_"+row+"' value='"+regdate+"' />");
    $("#edit_butts_"+row).hide();   
    $("#row_"+row+"_td_4").show();
    $("#row_"+row+"_td_4").html("<input type='button' class='butt1' value='Save' onclick='saveMemberRow("+row+","+list+")'/>&nbsp;<input type='button' class='butt1' value='Cancel' onclick='$(" +'"#row_'+row+'_td_1"'+").html("+'"'+name+'"'+");$(" +'"#row_'+row+'_td_2"'+").html("+'"'+email+'"'+");$(" +'"#row_'+row+'_td_4"'+").hide();$(" +'"#edit_butts_'+row+'"'+").show();'/>");   
}

function readerStat(row,list,rid) {
    $("#row_edit_"+row).html("<div id='bet_"+row+"'>Betöltés folyamatban ...</div><div id='row_edit_form_"+row+"' style='display:none'></div>");
    $("#row_edit_"+row).slideDown("slow");
    var p=new Array();
    p['command'] = "reader_stat";
    p['row'] = row;
    p['list'] = list;
    p['rid'] = rid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        //alert(xmlHttp.responseText);
                        $("#row_edit_"+row).html(xmlHttp.responseText);
                    }
                    });
}

function noSend(row,list,rid) {
    $("#row_edit_"+row).html("<div id='bet_"+row+"'>Betöltés folyamatban ...</div><div id='row_edit_form_"+row+"' style='display:none'></div>");
    $("#row_edit_"+row).slideDown("slow");
    var p=new Array();
    p['command'] = "reader_nosend";
    p['row'] = row;
    p['list'] = list;
    p['rid'] = rid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        //alert(xmlHttp.responseText);
                        $("#row_edit_"+row).html(xmlHttp.responseText);
                    }
                    });
}

function removeBan(rid,row,list,mail) {
    if (confirm("Are you sure you want to remove this mail from ban list?")) {
        var p=new Array();
        p['command'] = "remove_ban";
        p['row'] = row;
        p['list'] = list;
        p['rid'] = rid;
        p['mail'] = mail;
        getAjax("list_edit.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            noSend(row,list,rid);
                        }
                        }); 
    }   
}

function addBanMail(rid,row,list) {
    var p=new Array();
    p['command'] = "add_ban";
    p['row'] = row;
    p['list'] = list;
    p['rid'] = rid;
    p['mail'] = $("#newban_"+row).val();
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        noSend(row,list,rid);
                    }
                    });    
}

function mailStat(row,mailid) {
    $("#row_edit_"+row).html("<div id='bet_"+row+"'>Betöltés folyamatban ...</div><div id='row_edit_form_"+row+"' style='display:none'></div>");
    $("#row_edit_"+row).slideDown("slow");
    var p=new Array();
    p['command'] = "mail_stat";
    p['row'] = row;
    p['mailid'] = mailid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        //alert(xmlHttp.responseText);
                        $("#row_edit_"+row).html(xmlHttp.responseText);
                    }
                    });
}

function editField(row,list,eid) {

    $("#row_edit_"+row).html("<div id='bet_"+row+"'>Betöltés folyamatban ...</div><div id='row_edit_form_"+row+"' style='display:none'></div>");
    $("#row_edit_"+row).slideDown("slow");
    var p=new Array();
    p['command'] = "pfilter_form";
    p['row'] = row;
    p['list'] = list;
    p['eid'] = eid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $("#row_edit_"+row).html(xmlHttp.responseText.split('<!--break-->')[0]);
                        $("#row_edit_"+row).slideDown("fast");
                        if (xmlHttp.responseText.split('<!--break-->')[1] != "") answerRows(eid,row);
                        $('.numans').numeric();
                    }
                    });
} 

function answerRows(eid,row) {
    
    var p=new Array();
    p['command'] = "answer_rows";
    p['num'] = $("#numans_"+row).val();
    p['eid'] = eid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $("#answers_"+row).html(xmlHttp.responseText);
                    }
                    });
}

function chgAnsSel(eid,row,idx) {
    switch (idx) {
        case 0: $("#ans_typed_"+row).html("<input type='checkbox' name='just_num' />"+$("#just_num").val());break;
        case 1: $("#ans_typed_"+row).html($("#label").val()+": <input type='text' name='label' value='' />");break;
        case 2: case 3: 
            $("#ans_typed_"+row).html($("#number_of_answers").val()+":<input type='text' name='numans' class='numans' id='numans_"+row+"' maxlength='2' value='0' size='2' /> <input type='button' class='butt1' value='ok' onclick='answerRows("+eid+","+row+")' />"); 
        break;
    }
    $("#answers_"+row).html(""); 
}

function enaField(chk,id) {
    if (!chk) $("#txtVal_"+id).attr("disabled","disabled");
        else $("#txtVal_"+id).removeAttr("disabled");
}

function saveMemberRow(row,list) {
    var p=new Array();
    p['command'] = "save_member";
    p['oldemail'] = $("#oldemail_"+row).val();
    p['name'] = $("#name_inp_"+row).val();
    p['email'] = $("#email_inp_"+row).val();
    p['eid'] = list;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        //alert(xmlHttp.responseText);
                        $("#row_"+row+"_td_4").html(xmlHttp.responseText.split('_._._._')[0]);
                        datarow = xmlHttp.responseText.split('_._._._')[1];
                        name = $("#row_"+row+"_td_1").html(datarow.split(";")[0]);
                        email = $("#row_"+row+"_td_2").html(datarow.split(";")[1]); 
                        timer = setTimeout("$('#row_"+row+"_td_4').hide();$('#edit_butts_"+row+"').show();", 1200);
                    }
                    }); 
}

function saveField(row,list,eid) {
    var p=postSerializeForm(document.getElementById("pfilterForm_"+eid));
    p += "&command=save_field";
    postAjax("list_edit.php",p, function(ret){
                            //alert(ret);
                            document.getElementById('row_edit_'+row).innerHTML=ret;
                            timer = setTimeout('editField('+row+','+list+','+eid+')', 1000);
                        }); 
}

function editTheMail(row,mailid,list) {
    $("#row_edit_"+row).html("<div id='bet_"+row+"'>Betöltés folyamatban ...</div><div id='row_edit_form_"+row+"' style='display:none'></div>");
    $("#row_edit_"+row).slideDown("slow");
    var p=new Array();
    p['command'] = "mail_form";
    p['row'] = row;
    p['list'] = list;
    p['mailid'] = mailid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        //alert(xmlHttp.responseText);
                        $("#row_edit_form_"+row).html(xmlHttp.responseText);
                        $("#bet_"+row).fadeOut("fast");
                        timer = setTimeout("$('#row_edit_form_"+row+"').slideDown('fast');", 1000);
                        //timer2 = setTimeout("", 3000);
                        editorInit('mail','exact','body_'+row);
                    }
                    });
}

function filterTheMail(row,mailid,list) {
    $("#row_filter_"+row).html("<div id='bet_"+row+"'>Betöltés folyamatban ...</div>");
    $("#row_filter_"+row).slideDown("slow");
    var p=new Array();
    p['command'] = "mail_filter";
    p['row'] = row;
    p['list'] = list;
    p['mailid'] = mailid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        //alert(xmlHttp.responseText);
                        $("#row_filter_"+row).html(xmlHttp.responseText);
                        //$("#bet_"+row).fadeOut("fast");
                        //timer = setTimeout("$('#filter_edit_"+row+"').slideDown('fast');", 1000);
                        //timer2 = setTimeout("", 3000);
                        //editorInit('simple','textareas','');
                    }
                    });
}

function delFilter(row,mailid,list,filterid) {
    
    if (confirm("Are you sure you want to delete this filter?")) {
        var p=new Array();
        p['command'] = "del_filter";
        p['filterid'] = filterid;
        getAjax("list_edit.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                            filterTheMail(row,mailid,list);
                        }
                        });
        }
}

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

function saveNewFilter(row,mailid,list) {
    var p=postSerializeForm(document.addFilterForm);
    p += "&command=save_filter";
    postAjax("list_edit.php",p, function(ret){
                            $('a.modalCloseImg').click(); 
                            $('#hidden_popup').html(ret);
                            $('#hidden_popup').modal(); 
                            timer = setTimeout("$('a.modalCloseImg').click();filterTheMail("+row+","+mailid+")", 1000);
                        });     
}

function chgField(idx){
    //alert(idx);
    var p=new Array(); 
    p['command'] = "field_idx"; 
    p['idx'] = idx; 
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        //alert(xmlHttp.responseText);
                        $("#field_exp").html(xmlHttp.responseText);
                        $("#addButt").show();
                        //timer = setTimeout("filterTheMail("+row+","+mailid+","+list+")", 1200);
                    }
                    });
}

function chkTD(idx,mid) {
    switch (idx) {
        case 0: 
            $("#timedata_title_"+mid).html("&nbsp;");
            $("#timedata_box_"+mid).html("&nbsp;");
            $("#timedata_info_"+mid).html("&nbsp;");
        break;
        case 1: 
            $("#timedata_title_"+mid).html("<b>Send date:</b>");
            $("#timedata_box_"+mid).html("<input type='text' name='timedata' value='"+$("#timedata_bu_"+mid).val()+"' style='width:120px'/>");
            $("#timedata_info_"+mid).html("<small>mm.dd.yyyy - hh:mm</small>"); 
        break;
        case 2: 
            $("#timedata_title_"+mid).html("<b>Delay:</b>");
            $("#timedata_box_"+mid).html("<input type='text' name='timedata' value='"+$("#timedata_bu_"+mid).val()+"' style='width:120px'/>");
            $("#timedata_info_"+mid).html("<small>days</small>"); 
        break;
    }    
}

function saveEditedMail(mailid,row,list,as) {
    $("#reflect_"+mailid).html('Save in progress ...');
    //alert();
    var tform = document.getElementById("editMail_"+mailid);
    var p=postSerializeForm(tform);
    p += "&command=editedMail";
    if (as == "act") p += "&status=active";
        else p += "&status=draft";
    postAjax("list_edit.php",p, function(ret){
                            $('#bet_'+row).html(ret.split("_._;_._;")[0]);
                            $('#bet_'+row).fadeIn("fast");
                            $("#row_edit_form_"+row).slideUp("fast");
                            maildata = ret.split("_._;_._;")[1];
                            if (maildata.split('-*-')[0] == "refresh") {
                                timer2 = setTimeout('setPanel("mails",'+list+');', 2200);    
                            } else {
                                $("#row_"+row+"_td_1").html(maildata.split("_;")[0]);
                                //$("#row_"+row+"_td_2").html(maildata.split("_;")[1]);
                                $("#row_"+row+"_td_3").html(maildata.split("_;")[2]); 
                                $("#row_"+row+"_td_5").html(maildata.split("_;")[3]); 
                            }
                            timer = setTimeout('$("#row_edit_'+row+'").slideUp("fast");', 2200);
                        });    
}

function delTheMail(mailid,list) {
    if (confirm("Are you sure you want to delete this mail?")) {
        
        var p=new Array();
        p['command'] = "delete_mail";
        p['mailid'] = mailid;
        getAjax("list_edit.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                            setPanel('mails_search',list);
                        }
                        });    
    }
}

function actMail(mailid,row,toa) {
    if (toa == "active") aszov="Are you sure you want to activate this mail?";
        else aszov = "Are you sure you want to make this mail to draft?";
        
    if (confirm(aszov)) {    
        var p=new Array();
        p['command'] = "act_mail";
        p['mailid'] = mailid;
        p['toa'] = toa;
        p['row'] = row;
        getAjax("list_edit.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            if(xmlHttp.responseText != "") {
                                 $("#row_"+row+"_td_5").html(xmlHttp.responseText);
                            } else alert("Cannot be updated!");
                        }
                        }); 
    }
                           
}

function actReader(rid,butt) {
  
    var p=new Array();
    p['command'] = "act_reader";
    p['rid'] = rid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        if (butt.className=='act_button') butt.className='inact_button';
                                else butt.className='act_button';
                    }
                    }); 
                           
}

function resetParams() {
    $("#sender").val($("#sender_save").val());    
    $("#sender_addr").val($("#sender_addr_save").val());    
    $("#reply_addr").val($("#reply_addr_save").val());    
    $("#unsubsrcibe_text").html($("#unsubsrcibe_text_save").val());    
}

function loadDefaults(mailid) {
    $("#sender_"+mailid).val($("#sender_save_"+mailid).val());    
    $("#sender_addr_"+mailid).val($("#sender_addr_save_"+mailid).val());    
    $("#reply_addr_"+mailid).val($("#reply_addr_save_"+mailid).val());      
}

function resetLinkParams() {
    $("#link_text").val($("#link_text_save").val());    
    $("#body_color").val($("#body_color_save").val());    
    $("#font_color").val($("#font_color_save").val());     
    $("#logo_link").val($("#logo_link_save").val());     
}

function saveLinkParams(list) {
    $("#reflect").html("Save in progress ...");
    $("#reflect").slideDown("fast");
    $("#edbutts").slideUp("fast");
                                                 
    var p=postSerializeForm(document.signupset);
    p += "&command=save_linkparams";
    postAjax("list_edit.php",p, function(ret){
                        $("#reflect").html(ret);
                        $("#link_text_save").val($("#link_text").val);    
                        $("#body_color_save").val($("#body_color").val);    
                        $("#font_color_save").val($("#font_color").val);
                        $("#logo_link_save").val($("#logo_link").val);
                        //timer = setTimeout('$("#reflect").slideUp("fast");$("#edbutts").slideDown("fast");', 1500);
                    }); 
}


function saveParams(list) {
    $("#reflect").html("Save in progress ...");
    $("#reflect").slideDown("fast");
    $("#edbutts").slideUp("fast");
    
    var p=postSerializeForm(document.parameters);
    p += "&command=save_params";
    postAjax("list_edit.php",p, function(ret){
                        $("#reflect").html(ret);
                        $("#sender_save").val($("#sender").val);    
                        $("#sender_addr_save").val($("#sender_addr").val);    
                        $("#reply_addr_save").val($("#reply_addr").val);
                        timer = setTimeout('$("#reflect").slideUp("fast");$("#edbutts").slideDown("fast");', 1500);
                    }); 
}

function previewMail(mailid,row) {
    $("#pre_"+row).html("<span><b><center><br /><br /><br />Loading ...</center></b></span>");
            
    var p=new Array();
    p['command'] = "get_preview";
    p['mailid'] = mailid;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $("#pre_"+row).html("<span>"+xmlHttp.responseText+"</span>");
                        $("#TB_ajaxContent").html("<span>"+xmlHttp.responseText+"</span>");
                    }
                    });        
}


function previewDraft(mailid,row) {
    $("#pre_"+row).html("<span><b><center><br /><br /><br />Loading ...</center></b></span>");
            
    /*var p=new Array();
    p['command'] = "get_preview";
    p['mailid'] = mailid;
    p['themail'] = tinyMCE.editors["body_"+row].getContent();
    alert(p['themail']); */
    body = serializeTA(tinyMCE.editors["body_"+row].getContent());
    pdata = "command=get_preview&mailid="+mailid+"&themail="+body;
    
    postAjax("list_edit.php",pdata, function (ret) {
                        $("#hid_"+row).html("<span>"+ret+"</span>");
                        $("#hid_"+row).modal({minWidth:600,minHeight:300});
                    });        
}

function sendPreview(mailid) {
    var filter = /^.+@.+\..{2,6}$/; 
    
    if (parent.$("#te_mail").val() && filter.test(parent.$("#te_mail").val())) {     
        var p=new Array();
        p['command'] = "send_preview";
        p['mailid'] = mailid;
        p['temail'] = parent.$("#te_mail").val();
        getAjax("list_edit.php",p, function(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                            alert(xmlHttp.responseText);
                            tb_remove();
                        }
                        }); 
    } else alert("Type real e-mail address!");  
}

function loadContent (ta_id,cont,lang) {
    if (confirm("Are you sure to load the default content?\nAll unsaved data will be lost!")) {
    var p=new Array();
    p['command'] = "load_default";
    p['cont'] = cont;
    p['lang'] = lang;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        //alert(xmlHttp.responseText);
                        tinyMCE.editors[ta_id].setContent(xmlHttp.responseText);
                        //$("#pre_"+row).html("<span>"+xmlHttp.responseText+"</span>");
                        //$("#TB_ajaxContent").html("<span>"+xmlHttp.responseText+"</span>");
                    }
                    });        
    }
}

function attached(row, mailid) {
    $("#attach_"+row).css("height","");
    $("#attach_"+row).css("width","");
    $("#attach_"+row).html("Loading. Please wait ...");
    $("#attach_"+row).modal();
    
    var p=new Array();
    p['command'] = "mail_attach";
    p['mailid'] = mailid;
    p['row'] = row;
    getAjax("list_edit.php",p, function(){
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                        $(".attach_row").html(""); 
                        $('a.modalCloseImg').click();
                        $("#attach_"+row).html(xmlHttp.responseText);
                        $("#attach_"+row).modal();
                        var upl_files=new Array();
                        
                        $("#fileUploader").uploadify({ 
                            'uploader': '/js/uploadify/uploadify.swf',
                            'script': '/js/uploadify/uploadify.php',
                            'folder': '/attached/'+UPL_FOLDER,
                            'cancelImg': '/images/cancel.png',
                            'auto': false,
                            'multi': true,
                            'onComplete': function (event,queueID,fileObj,response,data) {
                                                var q=new Array();
                                                q['command'] = "upl_file";
                                                q['name'] = fileObj.name;
                                                q['size'] = fileObj.size;
                                                q['type'] = fileObj.type;
                                                getAjax("list_edit.php",q, function(){/*alert(xmlHttp.responseText);*/});
                                            },
                            'onAllComplete': function (event,data) {alert(data.filesUploaded + " file(s) uploaded!");attached(row, mailid)}

                        });
                    }
                    });
    
}

function delAttFile(fileid, mailid, row) {
    if (confirm("Are you sure you want to delete this file?\nThis will removed from all mail where attached!")) {
        var p=new Array();
        p['command'] = "del_attfile";
        p['fileid'] = fileid;
        getAjax("list_edit.php",p, function(){
                        alert(xmlHttp.responseText);
                        attached(row, mailid);
                        });  
    }  
}

function insertAtt(id, name, row) {
    $(".attach_row").html("");
    $("#attach_"+row).css("height","50px");
    $("#attach_"+row).css("width","300px");
    $("#attach_"+row).html("<b>Insert attached file as link</b><br />Link text: <input type='text' id='linktext' value='"+name+"' onKeyUp='$(\"#linktext\").val(this.value)'/> <input type='button' class='butt1' value='insert' onclick='insertTheAtt("+id+",$(\"#linktext\").val())' />");
    $("#attach_"+row).modal();    
}

function insertTheAtt(id,text) {
    $('a.modalCloseImg').click();
    tinyMCE.activeEditor.execCommand("mceInsertRawHTML", false, "[FILE_"+id+" linktext='"+text+"']");
}

function saveAttachments(mailid,row) {
    csekks = getElementsByClass("file_check_"+mailid);
    
    var p=new Array();
    p['command'] = "save_attachments";
    p['mailid'] = mailid;
    p['idz'] = "";
    for (c in csekks) if (csekks[c].checked) p['idz'] += csekks[c].value+",";
    getAjax("list_edit.php",p, function(){
                       alert(xmlHttp.responseText);
                       $('a.modalCloseImg').click();
                       editTheMail(row,mailid);
                  });
}

function createNewList() {
    $("#hidden_popup").html("Loading. Please wait ...");
    $("#hidden_popup").modal();
    
    var p=new Array();
    p['command'] = "create_list_form";
    getAjax("list_edit.php",p, function(){
                       $('a.modalCloseImg').click();
                       $("#hidden_popup").html(xmlHttp.responseText); 
                       $("#hidden_popup").modal();
                       editorInit('base','textareas',''); 
                  });
}

function chgTaTo(to,eid) {
    id=document.getElementById('editMail_'+eid).body.id;
    //alert(id);
    if (to == "html") {
        if (tinyMCE.getInstanceById(id)) {
            tinyMCE.execCommand('mceFocus', false, id);                    
            
            tinyMCE.execCommand('mceRemoveControl', false, id);
            document.getElementById('editMail_'+eid).body.style.display = "block";
            $("#ht_"+eid).addClass("vbutt_hl");  
            $("#tm_"+eid).removeClass("vbutt_hl");
        }
    } else {
        if (document.getElementById(id))
        tinyMCE.execCommand('mceAddControl', false, id);
        $("#tm_"+eid).addClass("vbutt_hl");
        $("#ht_"+eid).removeClass("vbutt_hl");
    }

}

function otherListStat(reader, list) {
    $("#hidden_popup").html("Loading. Please wait ...");
    $("#hidden_popup").modal();
    
    var p=new Array();
    p['command'] = "reader_stat";
    p['rid'] = reader;
    p['forcelist'] = list;
    getAjax("list_edit.php",p, function(){
                       $('a.modalCloseImg').click();
                       $("#hidden_popup").html(xmlHttp.responseText); 
                       $("#hidden_popup").modal();
                  });
}

function listReaders(listid,mailid) {
    $("#hidden_popup").html("Loading. Please wait ...");
    $("#hidden_popup").modal();
    
    var p=new Array();
    p['command'] = "reader_list";
    p['list'] = listid;
    p['mailid'] = mailid;
    getAjax("list_edit.php",p, function(){
                       $('a.modalCloseImg').click();
                       $("#hidden_popup").html(xmlHttp.responseText.split("#;")[0]); 
                       $("#hidden_popup").modal();
                       if (xmlHttp.responseText.split("#;")[1] == "all") $('#allCheck').attr('checked', true);
                  });
}

function saveReaderList() {
    var p=postSerializeForm(document.readerListForm);
    p += "&command=readlist_save";
    postAjax("list_edit.php",p, function(ret){
                          // alert(ret);
                           $('a.modalCloseImg').click();
                           $("#hidden_popup").html(ret); 
                           $("#hidden_popup").modal();
                           //timer = setTimeout("$('a.modalCloseImg').click()", 1200);
                        }); 
}

function chkAll(chk) {
    var chkz = getElementsByClass("readChk");
    for (i=0;i<chkz.length;i++) {
        chkz[i].checked = chk;
    }
    
}

function saveHead(headid,list) {
    var q=new Array();
    q['command'] = "save_head";
    q['name'] = $("#headname").val();
    q['headid'] = headid;
    getAjax("head_foot.php",q, function(){
        $('.modalCloseImg').show();
        $('a.modalCloseImg').click();
        $("#hidden_popup").html(xmlHttp.responseText); 
        $("#hidden_popup").modal();
        getHeads(list);
        timer = setTimeout("$('a.modalCloseImg').click();", 1200);
    });    
}

function editHead(headid,list) {
    var q=new Array();
    q['command'] = "edit_head";
    q['headid'] = headid;
    q['list'] = list;
    getAjax("head_foot.php",q, function() {
        $("#hidden_popup").html(xmlHttp.responseText); 
        $("#hidden_popup").modal();
        $('.modalCloseImg').hide(); 

        $("#headUpdater").uploadify({ 
                            'uploader': '/js/uploadify/uploadify.swf',
                            'script': '/js/uploadify/uploadify.php',
                            'folder': '/attached/'+UPL_FOLDER+'/heads',
                            'cancelImg': '/images/cancel.png',
                            'fileDesc': 'kép fájlok (JPG,GIF,PNG)',
                            'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
                            'sizeLimit': '150000',
                            'buttonText': 'Change Image...',
                            'auto': true,
                            'multi': true,
                            'onError': function (event,queueID,fileObj) {
                                                alert("A '"+fileObj.name+"' nevű fájl mérete túl nagy, nem feltölthető!");
                                            },
                            '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['headid'] = headid;
                                                getAjax("head_foot.php",q, function(){
                                                    if (xmlHttp.responseText.split("#;")[1] == "nok")
                                                        alert(xmlHttp.responseText.split("#;")[0]);
                                                    else {
                                                        $("#editHeadPic").attr("src", xmlHttp.responseText.split("#;")[0]);
                                                    }
                                                });
                                            },
                            'onAllComplete': function (event,data) {alert(data.filesUploaded + " file(s) uploaded!");attached(row, mailid)}

                        });
    });
}

function getFoots(list){
    var p=new Array();
    p['command'] = "foot_list";
    p['list'] = list;
    getAjax("head_foot.php",p, function(){ 
                       //alert(xmlHttp.responseText);
                       $("#foots").html(xmlHttp.responseText); 
                  });
}

function addNewFoot(list) {
    $("#hidden_popup").html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ..."); 
    $("#hidden_popup").modal();
    var q=new Array();
    q['command'] = "add_foot";
    q['list'] = list;
    getAjax("head_foot.php",q, function(){
        $('a.modalCloseImg').click();
        $("#hidden_popup").html(xmlHttp.responseText); 
        $("#hidden_popup").modal();
        editorInit('base','exact','text');
    });
}

function editFoot(footid,list) {
    $("#hidden_popup").html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ..."); 
    $("#hidden_popup").modal();
    var q=new Array();
    q['command'] = "add_foot";
    q['list'] = list;
    q['footid'] = footid;
    getAjax("head_foot.php",q, function(){
        $('a.modalCloseImg').click();
        $("#hidden_popup").html(xmlHttp.responseText); 
        $("#hidden_popup").modal();
        editorInit('base','exact','text');
    });
}


function saveFoot(list) {
    var p=postSerializeForm(document.FootForm);
    p += "&command=save_foot&list="+list;
    
    postAjax("head_foot.php",p, function(ret){
        $('a.modalCloseImg').click();
        $("#hidden_popup").html(ret); 
        $("#hidden_popup").modal();
        getFoots(list);
        timer = setTimeout("$('a.modalCloseImg').click();", 1200);
    });    
}

function delHead(id,list) {
    if (confirm("Valóban törli a fejlécet?")) {
        var q=new Array();
        q['command'] = "del_head";
        q['id'] = id;
        getAjax("head_foot.php",q, function(){
            alert(xmlHttp.responseText); 
            getHeads(list);
        });
    }
}

function delFoot(id,list) {
    if (confirm("Valóban törli a láblécet?")) {
        var q=new Array();
        q['command'] = "del_foot";
        q['id'] = id;
        getAjax("head_foot.php",q, function(){
            alert(xmlHttp.responseText); 
            getFoots(list);
        });
    }
}

function editTempl(tplid,list) {
    $("#hidden_popup").html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ..."); 
    $("#hidden_popup").modal();
    var q=new Array();
    q['command'] = "add_templ";
    q['list'] = list;
    q['tplid'] = tplid;
    getAjax("templates.php",q, function(){
        $('a.modalCloseImg').click();
        $("#hidden_popup").html(xmlHttp.responseText); 
        $("#hidden_popup").modal();
        editorInit('mail','exact','text');
    });
}

function saveTempl(list) {
    var p=postSerializeForm(document.TemplForm);
    p += "&command=save_templ&list="+list;
    
    postAjax("templates.php",p, function(ret){
        $('a.modalCloseImg').click();
        $("#hidden_popup").html(ret); 
        $("#hidden_popup").modal();
        setPanel('templates',list);
        timer = setTimeout("$('a.modalCloseImg').click();", 1200);
    });    
}

function delTempl(id,list) {
    if (confirm("Valóban törli a sablont?")) {
        var q=new Array();
        q['command'] = "del_templ";
        q['id'] = id;
        getAjax("templates.php",q, function(){
            alert(xmlHttp.responseText); 
            setPanel('templates',list);
        });
    }
}

function addNewTempl(list) {
    $("#hidden_popup").html("<img src='"+BASEURL+"images/cms_images/loader_circ.gif' class='float_left'><b>Betöltés folyamatban!</b><br />Kis türelmet ..."); 
    $("#hidden_popup").modal();
    var q=new Array();
    q['command'] = "add_templ";
    alert(list);
    q['list'] = list;
    getAjax("templates.php",q, function(){
        $('a.modalCloseImg').click();
        $("#hidden_popup").html(xmlHttp.responseText); 
        $("#hidden_popup").modal();
        editorInit('mail','exact','text');
    });
}

function loadTempl(mailid) {
    if (confirm("Biztosan betölti a sablont?\nA betöltés során az eddig beírt szöveg elveszik!")) {    
        var q=new Array();
        q['command'] = "load_templ";
        q['tid'] = $("#template_"+mailid).val();
        if (q['tid'] != "") {
            getAjax("templates.php",q, function(){
                //alert(xmlHttp.responseText); 
                tinyMCE.editors["body_"+mailid].setContent(xmlHttp.responseText);
            });
        }
    }
}

/* ------------------- GUESTBOOK ----------------*/

function addToGuestBook() {
    if ($("#vk_dk").val() == "hosom") {
        var p=postSerializeForm(document.vk_form);
        p += "&command=vk_add";
        $('#hidden_popup').html("Küldés folyamatban ...");
        $('#hidden_popup').modal();

        postAjax("ajax/guestbook.php",p, function(ret){
                                $('a.modalCloseImg').click();
                                $('a.modalCloseImg').hide();                    
                                $('#hidden_popup').html(ret);
                                $('#hidden_popup').modal();
                                refreshGuestBook();
                                $("#vk_name").val("");
                                $("#vk_comment").val("");
                                $("#vk_dk").val("");
                                timer = setTimeout("$('a.modalCloseImg').click();$('a.modalCloseImg').show();", 1000);
                            });
    } else {
        $('#hidden_popup').html("<center><br /><font color='red'><b>Hibás szóellenőrzés!</b></font><br />Tényleg be kell írnod a 'hosom' szót az alsó mezőbe a hozzászóláshoz!<br />Ez a funkció szükséges a szemetelő robotok elkerüléséhez.</center>");
        $('#hidden_popup').modal();
    }  
}

function refreshGuestBook() {
    p = "command=refresh";

    postAjax("ajax/guestbook.php",p, function(ret){                    
                            $('#vk_coms').html(ret);
                            //$('#content_panel').jScrollPane();
                            //timer = setTimeout("$('a.modalCloseImg').click();$('a.modalCloseImg').show();", 1000);
                        });
}

function moreGuestBook(page) {
    $('#vk_more_'+page).html("Betöltés folyamatban...");
    p = "command=morepage&page="+page;

    postAjax("ajax/guestbook.php",p, function(ret){                    
                            $('#vk_more_'+page).html(ret);
                            //$('#content_panel').jScrollPane();
                            //timer = setTimeout("$('a.modalCloseImg').click();$('a.modalCloseImg').show();", 1000);
                        });
}

function delGBEntry(did) {
    if (confirm("Valóban törli a bejegyzést?")) {
        p = "command=del&did="+did;

        $('#hidden_popup').html("Törlés folyamatban ...");
        $('#hidden_popup').modal();
        
        postAjax("ajax/guestbook.php",p, function(ret){                    
                                $('a.modalCloseImg').click();
                                $('a.modalCloseImg').hide();                    
                                $('#hidden_popup').html(ret);
                                $('#hidden_popup').modal();
                                refreshGuestBook();
                                timer = setTimeout("$('a.modalCloseImg').click();$('a.modalCloseImg').show();", 1000);
                            });
    }
}

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

