function changeTab(tabnum,name,url){
  var tn=tabnum+1;
  var fdata=$('f2').serialize(true);
  var ielements=$('f2').getInputs('checkbox');
  ielements.each(function(n){
    if(n.checked) fdata[n.name]=1;else fdata[n.name]=0;
  });

  fdata['activetab']=tn;
  if(document.getElementById('shorttext'))fdata['shorttext']=editors['shorttext'].getEditorContent();
  if(document.getElementById('longtext'))fdata['longtext']=editors['longtext'].getEditorContent();
  
  new Ajax.Updater(name,url,{
    method:'post',
    evalScripts:true,
    onFailure: function(){ alert('Something went wrong (changeTab)...') },
    onComplete: function(response){
      if (response.status / 100 == 2) {
        var config = new Xinha.Config();
        editors = Xinha.makeEditors(['shorttext','longtext'], config);
        Xinha.startEditors(editors);
      }
    },
    parameters: fdata
  });
}


function saveItem(tabnum,tabname,url,id){
  var action='save';
  var name=tabname;
  var value='';

  
  if(document.getElementById(id).type=='checkbox'){
    if(document.getElementById(id).checked) value=1;else value=0;
  } else if (document.getElementById(id).type=='radio'){
    if(document.getElementById(id).checked) value=document.getElementById(id).value;
  } else {
    value=document.getElementById(id).value;
  }
  if(value!=''){
    new Ajax.Request(url,{
      onFailure: function(){ alert('Something went wrong (SaveItem)...') },
      method:'post',
      parameters: {
        tabnum:tabnum,
        tabname:name,
        id:id,
        value:value,
        action:action
      }
    });
  }
}




function delete_session_tab(ajaxurl,tabname){
  /* Ajax Abfrage */ 

    new Ajax.Request(ajaxurl,{
    onFailure: function(){ alert('Something went wrong (DeleteSessionTab)...') },
    method:'post',
    parameters: {action:'deletesession',tabname:tabname}
  });
}


function save_action(div,ajaxurl,tabname){
    var fdata=$('f2').serialize(true);
    var ielements=$('f2').getInputs('checkbox');
    ielements.each(function(n){
      if(n.checked) fdata[n.name]=1;else fdata[n.name]=0;
    });


    fdata['action']='savesession';
    if(document.getElementById('shorttext'))fdata['shorttext']=editors['shorttext'].getEditorContent();
    if(document.getElementById('longtext'))fdata['longtext']=editors['longtext'].getEditorContent();

    new Ajax.Updater(div,ajaxurl,{
    method:'post',
    evalScripts:true,
    onFailure: function(){ alert('Something went wrong (SaveAction)...') },
    parameters: fdata
  }); 
}


function tabwin_cancel(div,url){
  new Ajax.Updater(div,url,{
    onFailure: function(){ alert('Something went wrong (TabwinCancel)...') },
    method:'post'
  });
}



/* from this point on, all functions are immocms specific */

function changeChildrenSelect(url,tabwindowname,tabnum){
  var parent=document.getElementById('parent').options[document.getElementById('parent').selectedIndex].value;
  var fdata=$('f2').serialize(true);
  fdata['action']='order2change';
  fdata['parentkey']=parent;
  fdata['tabwindowname']=tabwindowname;
  fdata['tabnum']=tabnum;
  fdata['url']=url;
  new Ajax.Updater('oselect',url,{
    method:'post',
    onFailure: function(){ alert('Something went wrong (ChangeChildrenSelect)...') },
    onComplete: function(){ toggle_radio_disable() },
    parameters:fdata
  });
  
  setTimeout('toggle_radio_disable()',1000);    
  saveItem(tabnum,tabwindowname,url,'order2');
}

function changeChildrenSelectArticle(url,tabwindowname,tabnum){
  var parent=document.getElementById('parent').options[document.getElementById('parent').selectedIndex].value;
  var fdata=$('f2').serialize(true);
  fdata['action']='order2change_article';
  fdata['parentkey']=parent;
  fdata['tabwindowname']=tabwindowname;
  fdata['tabnum']=tabnum;
  fdata['url']=url;
  new Ajax.Updater('oselect',url,{
    method:'post',
    onFailure: function(){ alert('Something went wrong (ChangeChildrenSelectArticle)...') },
    onComplete: function(){ toggle_radio_disable() },
    parameters:fdata
  });
  
  setTimeout('toggle_radio_disable()',1000);    
  saveItem(tabnum,tabwindowname,url,'order2');
}

function changeChildrenSelectImmo(url,tabwindowname,tabnum){
  var parent='';
  var fdata=$('f2').serialize(true);
  fdata['action']='order2change_immo';
  fdata['parentkey']=parent;
  fdata['tabwindowname']=tabwindowname;
  fdata['tabnum']=tabnum;
  fdata['url']=url;
  new Ajax.Updater('oselect',url,{
    method:'post',
    onFailure: function(){ alert('Something went wrong (changeChildrenSelectImmo)...') },
    onComplete: function(){ toggle_radio_disable() },
    parameters:fdata
  });
  
  setTimeout('toggle_radio_disable()',1000);    
  saveItem(tabnum,tabwindowname,url,'order2');
}

function toggle_radio_disable(){
  if(document.getElementById('order2').options.length >0)
    document.getElementById('r3').disabled=false;
    
  else
    document.getElementById('r3').disabled=true;
  
}


function changeClass(){

}

function changeType(){

}


function toggle_is_list(){
  if($('is_list').checked){
    $('headline').disabled=false;
    $('class').disabled=false;
  } else {
    $('headline').disabled=true;
    $('class').disabled=true;
  }
}
