﻿function FlowPoster(bSinglePostOnly) {
  this.form = "";
  this.getObject = getObject;
  this.setForm = setForm;
  this.post = post;
  this.singlepost = bSinglePostOnly || false;
	this.isinprogress = false;
	this.post_busy = post_busy;

  function setForm( id ) { this.form = id; }

  /** variables-in:  
        - Event (required)
        - Page (optional)
        - Flow (optional)   */
  function post( flowEvent ) {
    if (this.form == "" || this.form == null) { alert ("There is no form available.\nPlease set this with the setForm function"); }
    else if (flowEvent == "" || flowEvent == null)    { alert ("This function requires an event name"); }
    else {		    		
    	if (!this.singlepost || !this.isinprogress) {
	      obj = getObject( this.form );
	      obj.target = "_self";  // yup - restore default
	      obj.__event.value = flowEvent;
	      if (arguments[1] != "" && arguments[1] != null) { obj.__page.value = arguments[1]; }
	      if (arguments[2] != "" && arguments[2] != null) { obj.__flow.value = arguments[2]; }
	      obj.submit();
	      this.isinprogress = true;
	    }  
    }
  }
  
  function post_busy ( flowEvent ) {
  	document.body.style.cursor = 'wait';
  	this.post( flowEvent );
  }

  function getObject( id ) {
    if (document.getElementById) x = document.getElementById(id);
    else if (document.all) x = document.all[id];
    else if (document.layers)	x = document.layers[id];
    
    return x;
  }
}