/*================= Myview2 ============================
This view is the actual order form.
*/

var Myview2 = function(aModel, aController)
{

// inheritance from the Abstractclass

	this.inheritFrom = Abstractclass;
  	this.inheritFrom(aModel, aController);
  	
  	var md = aModel;
  	var cd = aController;
  	
// The form id and methods 

	var viewform = document.getElementById("view2Form");
	viewform.method = "post";
	viewform.action = "src/form_alt.php";
	
// The kind to be ordered: input field

	var ordInput = document.getElementById("order");
	
// The button to submit the order

	var submitBut = document.getElementById("formsubmit");
	submitBut.setAttribute("type", "submit"); 
	submitBut.onclick = function (event)
	{
  		EventBus.dispatch (event.type, cd, event);
	}
	
// The button to cancel the order

	var cancelBut = document.getElementById("cancel");
	cancelBut.setAttribute("type", "reset"); 
	cancelBut.setAttribute("value", "Cancel"); 
	cancelBut.onclick = function (event)
	{
  		EventBus.dispatch (event.type, cd);
	}
	
// update function overrides the function from the Abstractclass

	this.update = function (event)
	{
		evType = event.type;
		
// The order kind will be retrieved from the Model class.

		if(evType == "selView")
		{
			ordInput.value = md.mmes.getMes();
		}

/*
When order was submitted the tasks of the viewform will be
executed, in this case the php form will be processed.
*/

		if(evType == "submitOrder")
		{
			viewform.submit();
		}
	}
}