/**
* overwrite some ajaxanywhere deault behaviour
*/

/**
* Handle wrong content type. 
*/
AjaxAnywhere.prototype.handleWrongContentType = function() 
{
}

/**
*   If an exception is throws on the server-side during AJAX request, it will be processed
* by this function. The default implementation is alert(stackTrace);
* Override it if you need.
*/
AjaxAnywhere.prototype.handleException = function(type, details) {
}

/**
*   If an HTTP Error code returned during AJAX request, it will be processed
* by this function. The default implementation is alert(code);
* Override it if you need.
*/
AjaxAnywhere.prototype.handleHttpErrorCode = function(code) {
}

AjaxAnywhere.prototype.getZonesToReload = function(url, submitButton) {
	if (this.zonesToReload){
    	return this.zonesToReload;
    }
    return "";
}

AjaxAnywhere.prototype.setZonesToReload = function(zones) {
  this.zonesToReload=zones;
}

/* search for id, then for name */
/* we have some pages where form names are not unique */
AjaxAnywhere.prototype.findForm = function () {
    var form;
    if (this.formId)
        form = document.getElementById(this.formId);
    else if (this.formName != null)
        form = document.forms[this.formName];
    else if (document.forms.length > 0)
        form = document.forms[0];

    return form;
}



function submitAjaxForm(formElement, zones, ajaxObject) {

    var id = formElement.attributes["id"].value;

  if (ajaxObject) {
    if (id) {
      ajaxObject.formId = id;
    } else {
      ajaxObject.formName = formElement.name;
    }
  } else {
    if (id) {
      ajaxAnywhere.formId = id;
    } else {
      ajaxAnywhere.formName = formElement.name;
    }
  }
  ajaxAnywhere.setZonesToReload(zones);
  ajaxAnywhere.submitAJAX();
}
