
ajaxPost = function(form_id, p_url, target_id, func_complete, func_error)
{
  var frm = $(form_id);

  new Ajax.Updater(
            target_id,
            p_url,
            {
              asynchronous:true,
              evalScripts:true,
              onComplete:function(request){
                            if (showErrorMsg($(target_id)) == true) {
                                setTimeout(func_error, 10);
                            } else {
                                setTimeout(func_complete, 10);
                            }
                           },
              parameters:Form.serialize(frm)
            }
          );
   return false;
}

var _thetis_ajax_item_data = null;
var _thetis_ajax_item_func_complete = null;
var _thetis_ajax_item_func_error = null;

ajaxUploadFile = function(form_id, p_url, target_id, func_complete, func_error)
{
  dojo.io.bind ({
      url:      p_url,
      method:   "post",
      formNode: form_id,
      mimetype: "text/html",
      load: function(type, data, evt) {

                if (is_Opera) {
                  _thetis_ajax_item_data = data;
                  _thetis_ajax_item_func_complete = func_complete;
                  _thetis_ajax_item_func_error = func_error;
                  setTimeout("_onUploadForOpera('"+target_id+"')", 100);
                  return;
                }

                // needed due to problem with IframeIO: http://trac.dojotoolkit.org/ticket/674
                if (data != null) {
                  value = data.documentElement.innerHTML;
                } else {
                  value = dojo.io.iframeContentWindow(dojo.io.IframeTransport.iframe).document.body.innerHTML;
                  if (value.match("/<pre>(.*)</pre>/i")) {
                      // Internet Explorer [Jon Aquino 2006-05-06]
                      value = RegExp.$1;
                  }
                }
                $(target_id).innerHTML = value;
                if (showErrorMsg(target_id) == true) {
                  setTimeout(func_error, 10);
                } else {
                  setTimeout(func_complete, 10);
                }
            },
      error: function(type, error) {
                    if (error.reason != null) {
                        var thetisBoxErr = new ThetisBox;
                        thetisBoxErr.show("TOP-RIGHT", "", "MESSAGE", "", error.reason, "");
                    }
                    setTimeout(func_error(), 10);
                  }
  });
}

_onUploadForOpera = function(target_id) {

  var data = _thetis_ajax_item_data;

  if (data == null)
    return;

  if (data.documentElement.innerHTML.length < 100) {

    setTimeout("_onUploadForOpera('"+target_id+"')", 100);

  } else {

    setTimeout("_onUploadCompletedForOpera('"+target_id+"')", 100);
  }
}

_onUploadCompletedForOpera = function(target_id) {

  var data = _thetis_ajax_item_data;
  var func_complete = _thetis_ajax_item_func_complete;
  var func_error = _thetis_ajax_item_func_error;

  if (data == null)
    return;

  $(target_id).innerHTML = data.documentElement.innerHTML;

  if (showErrorMsg(target_id) == true) {
    setTimeout(func_error, 10);
  } else {
    setTimeout(func_complete, 10);
  }
}

showTab = function(name) {

  var nameArray = new Array("workflow", "basic", "description", "image", "attachment");

  var tab = null;
  for (i=0; i<nameArray.length; i++) {
    tab = $("tab_"+nameArray[i]);
    if (tab != null) {
      tab.style.cursor = "pointer";
      tab.style.backgroundColor = "";   // Not bgColor but style.backgroundColor for initial display.
    }
  }
  var target_tab = $("tab_"+name);
  target_tab.style.cursor = "default";
  var bg = target_tab.bgColor;

  for (i=0; i<nameArray.length; i++) {
    tab = $("tab_"+nameArray[i]);
    if (tab != null) {
      tab.bgColor = "silver";
    }
  }

  target_tab.bgColor = bg;

  for (i=0; i<nameArray.length; i++) {
    div = $("div_"+nameArray[i]);
    if (div != null) {
      div.style.display = "none";
    }
  }

  div = $("div_"+name);
  div.style.visibility = "visible";
  div.style.display = "inline";
}

