function submitbutton(pressbutton){
  submitform(pressbutton);
}

function submitform(pressbutton){
  var form = document.jaForm;
  
	if (pressbutton) {
		document.jaForm.task.value=pressbutton;
		
		// compose form action
		var action = form.action + "?";
		if(form.controller.value != ''){
		  action += 'controller=' + form.controller.value;
		}
		if(form.task.value != ''){
		  action += '&task=' + form.task.value;
		}
		document.jaForm.action = action;
	}
	try {
		document.jaForm.onsubmit();
	}
	catch(e){}

	document.jaForm.submit();
}

function delSelectedFromList(id){
  var srcList = document.getElementById(id);
  
  for(i=0,n=srcList.length;i<n;i++){
    if(srcList.options[i].selected){
      srcList.options[i] = null;
    }
  }
}
function copyOptionsFromList(src_id, tgt_id){
  var srcList = document.getElementById(src_id);
  var tgtList = document.getElementById(tgt_id);
  
  for(i=0,n=srcList.length;i<n;i++){
    opt = new Option(srcList.options[i].text, srcList.options[i].value);
    tgtList.options.add(opt);
  }
}
function addSelectedToList(src_id, tgt_id){
  var srcList = document.getElementById(src_id);
  var tgtList = document.getElementById(tgt_id);
  
  for(i=0,n=srcList.length;i<n;i++){
    if(srcList.options[i].selected){
      opt = new Option(srcList.options[i].text, srcList.options[i].value);
      tgtList.options.add(opt);
    }
  }
}
function executeTask(id, task){
  var form = document.jaForm;
  cb = eval( 'form.' + id );
  if (cb) {
    //disable other select items
    for (i = 0; true; i++) {
      cbx = eval('form.cb'+i);
      if (!cbx) break;
      cbx.checked = false;
    } // for
    cb.checked = true;
    submitbutton(task);
  }
  return false;
}
function tableOrder(field, order){
  var form = document.jaForm;
  form.filter_order.value = field;
  form.filter_order_Dir.value = order;
  
  submitform('index');
}
function isChecked(isitchecked){
	if (isitchecked == true){
		document.jaForm.boxchecked.value++;
	}
	else {
		document.jaForm.boxchecked.value--;
	}
}
function updateAll(option, framework){
  J.get("index2.php?option=" + option + "&controller=updates&task=all&no_html=1", {framework: framework}, function(data){
    if(data.length > 0){
      alert(data);
    } else {
      document.location.href = 'index2.php?option=' + option + '&controller=updates';
    }
  });
}

function update(option, path, hash, framework, text){
  J.get("index2.php?option=" + option + "&controller=updates&task=apply&no_html=1", {path: path, framework: framework}, function(data){
    if(data.length > 0){
      alert(data);
    } else {
      document.getElementById(hash).innerHTML = text;
    }
  });
}
function revert(option, path, hash, framework, text){
  J.get("index2.php?option=" + option + "&controller=updates&task=revert&no_html=1", {path: path, framework: framework}, function(data){
    if(data.length > 0){
      alert(data);
    } else {
      document.getElementById(hash).innerHTML = text;
    }
  });
}
function table(option, table, field, framework, text){
  J.get("index2.php?option=" + option + "&controller=updates&task=table&no_html=1", {table: table, field: field, framework: framework}, function(data){
    if(data.length > 0){
      alert(data);
    } else {
      document.getElementById(table + "_" + field).innerHTML = text;
    }
  });
}