YAHOO.namespace("roidialog.container");

YAHOO.util.Event.onDOMReady(function () {
	
	// Calculate ROI
	var handleCalculate = function() {
		var time_in_day = 8,
			cost_data_entry = .25,
			man_hours_ayear = 0,
			time_in_paperwork =0,
			hours_saved=0;
			
		man_hours_ayear = ((time_in_day)*(this.form.staff.value))*(this.form.workdays.value);
		time_in_paperwork = ((this.form.staff.value) * (this.form.papertime.value))*(this.form.workdays.value);
		hours_saved = time_in_paperwork - ((cost_data_entry)*(this.form.staff.value))*(this.form.workdays.value);

		this.form.totalcosts.value =(time_in_paperwork)*(this.form.staffcost.value);
		this.form.hourssaved.value=hours_saved;
		this.form.totalsavings.value=hours_saved*this.form.staffcost.value;		
		//this.render();
	};
	
	// Reset the ROI form
	var handleReset = function() {
		this.form.staff.value="";
		this.form.staffcost.value="";
		this.form.papertime.value="";
		
		this.form.workdays.value="";
		this.form.totalcosts.value="0";
		this.form.hourssaved.value="0";
		this.form.totalsavings.value="0";
	}
	
	//User closes the dialog
	var handleClose = function() {
		this.cancel();
	};

	
    //Create Dialog
    YAHOO.util.Dom.removeClass("roiDialog", "yui-pe-content");
	YAHOO.roidialog.container.roiDialog = new YAHOO.widget.Dialog("roiDialog", 
							{ width : "50em",
							  fixedcenter : true,
							  visible : false,
							  iframe : true,
							  constraintoviewport : true,
							  buttons : [ { text:"Calculate", handler:handleCalculate, isDefault:true },
								      { text:"Reset", handler:handleReset },
									  { text:"Close", handler:handleClose}
									    ]
							});

	
	// Render the Dialog
	YAHOO.roidialog.container.roiDialog.render();

	YAHOO.util.Event.addListener("show", "click", YAHOO.roidialog.container.roiDialog.show, YAHOO.roidialog.container.roiDialog, true);
	YAHOO.util.Event.addListener("hide", "click", YAHOO.roidialog.container.roiDialog.hide, YAHOO.roidialog.container.roiDialog, true);
});
