
/*


 should Form be responsible for handling the wait image or whatever is used to tell the user that a response is pending.

Basic Form Posting functionality for IMDF

This class will be the sole communicator with imdf.php?  No, another should be - it wuold use this.  

This will also be the documnet source of how all the form elements work and interact - all documentation should be found here.

There will be multiple hidden iframes so the frame name or element needs to be an
argument in any submit

All inputs have ids of "imdfForm_" + name, which means that this form is meant to be used as a singleton - one
form does many jobs - all submits require a target.

//"project","mapsize","minx","miny","maxx","maxy","mapxy","map","scale","mode","layers","slayers","qlayer","qlayers","qmode","qargs","smode","tol","fs","fi","rmode","retlays"

OR

Document the form variables in a readme and make this very simple.

	//  TODO: use a submit pre and post handler registration if needed.

*/


//====================================================
//
//  imdfForm - the main class
//
//====================================================
function imdfForm(){
    
    //  Create the form
    f = document.createElement("form");
    f.method = "POST";
    f.style.display = "none";
    f.action = "imdf.php";
    document.body.appendChild(f);
    this.form = f;
    
    //  Add the inputs?
    this.form.appendChild(createInput("cmd"));

}

//====================================================
//
//  createInput - a helper function for initialization
//
//====================================================
function createInput(name){
    
    newI = document.createElement("input");
    newI.type="hidden";
    newI.name=name;
    newI.id="imdfForm_" + name;
    newI.value = null;
    newI.disabled = true;
    return newI;
}    

//====================================================
//
//  clear - makes all form elements disabled.
//
//====================================================
imdfForm.prototype.clear = imdfForm_Clear;
function imdfForm_Clear(){
    
	for(i=(this.form.childNodes.length-1);i>-1;i--){
		this.form.childNodes[i].disabled = true;
	}
}

//====================================================
//
//  set - set the value of an element and make it enabled
//
//====================================================
imdfForm.prototype.set = imdfForm_Set;
function imdfForm_Set(key,value){
  
  if (this.form.elements.namedItem){
	  theI = this.form.elements.namedItem(key);
	}else{
	  theI = eval("this.form." + key)
	}
	if (theI==null){
	    theI = createInput(key);
	    this.form.appendChild(theI);
	}
	theI.value = value;
	theI.disabled = false;
}

//====================================================
//
//  submit - set the targetId and submit the form
//
//====================================================
imdfForm.prototype.submit = imdfForm_Submit;
function imdfForm_Submit(targetId){

  this.form.target = targetId;
	this.form.submit();
     
}


