// 
// File:	VerticalForm.js
// Author:	Rob Allen
// Created:	June 6, 2002
//
// Purpose:	To provide a simple form in which field labels and the fields themselves
//		are arranged horizontally, and each successive field is placed in the subsequent
// 		row. Fields are defined by the FieldFactory class. Each form class 
//		must support the following interface:
//
//		addField(fieldDescription)
//		fieldDescription ::= same as input to field factory ctor.
//
//		getHTML()
//
//
// Copyright (c) 2002, ThoughtByDesign. All rights reserved.
// 
// This computer program is protected by copyright law and international treaties.
// Unauthorized reproduction or distribution of this program, or any portion of it,
// may result in severe civil and criminal penalties, and will be prosecuted to the
// maximum extent possible under the law.
// 
// Modification History: 
//	RLA, 6/6/2002, Creation and initial definition
// 


function VerticalForm(title) {
	this.formTitle = title;
	
	this.fieldList = new Array();
}


VerticalForm.prototype.addField = function(fieldLabel, fieldDescription, required, help) {
	var tempRequired = (required != null && required == true);
	var helpLine = null;
	if (arguments.length == 4) {
		helpLine = help;
	} // if
	this.fieldList[this.fieldList.length] = {_type: "field", _description: fieldDescription, _label: fieldLabel, _required: tempRequired, _help: helpLine};
} // addField()


VerticalForm.prototype.addDateEditor = function(fieldLabel, fieldDescription, required) {
	var tempRequired = (required != null && required == true);
	this.fieldList[this.fieldList.length] = {_type: "dateEditor", _description: fieldDescription, _label: fieldLabel, _required: tempRequired};
} // addDateEditor()


VerticalForm.prototype.addHelpLine = function(fieldDescription) {
	this.fieldList[this.fieldList.length] = {_type: "staticText", _description: fieldDescription, _label: null, _required: false};
} // addHelpLine()


VerticalForm.prototype.addSeparator = function(title) {
	this.fieldList[this.fieldList.length] = {_type: "separator", _description: null, _label: title, _required: null};
} // addSeparator()


VerticalForm.prototype.addStaticText = function(staticText) {
	this.fieldList[this.fieldList.length] = {_type: "staticText", _description: staticText, _label: "", _required: false};
} // addStaticText()


VerticalForm.prototype.getHTML = function() {

	var stringToWrite = "<table cellspacing='3px' cellpadding='3px' border='0px' width='90%'>";
	if (this.formTitle != null && this.formTitle.length > 0) {
		stringToWrite += "<tr>";
		stringToWrite += "<td class=clsPageSubHeader colspan=2>"+this.formTitle+"</td>";
		stringToWrite += "</tr>";
	} // if
	
	for (var i = 0; i < this.fieldList.length; i++) {
	
		if (this.fieldList[i]._type == "separator") {
			stringToWrite += "<tr><td class='clsThinLine' colspan=2>&nbsp;</td></tr>";
			stringToWrite += "<tr><td class='clsPageSubHeader' colspan=2>";
			stringToWrite += this.fieldList[i]._label;
			stringToWrite += "</td></tr>";
		} // if
		else if (this.fieldList[i]._type == "dateEditor") {
			stringToWrite += "<tr>";
			stringToWrite += "<td class='clsFieldLabel' align='right'>"+required+this.fieldList[i]._label+"</td>";
			stringToWrite += "<td valign='top' class='clsText'>";
			stringToWrite += this.fieldList[i]._description.getHTML();
			stringToWrite += "</td>";
			stringToWrite += "</tr>";
		} // else if
		else if (this.fieldList[i]._type == "staticText") {
			stringToWrite += "<tr>";
			stringToWrite += "<td class='clsHelpLine' valign='top' colspan='2' style='padding-right:40px; margin-right:40px'>";
			stringToWrite += "<br />";
			stringToWrite += this.fieldList[i]._description;
			stringToWrite += "<br />";
			stringToWrite += "</td>";
			stringToWrite += "</tr>";
		} // else if
		else {
			var required = "";
			if (this.fieldList[i]._required == true) {
				required = "<span class='clsRequired'>*</span> ";
			} // if
			stringToWrite += "<tr>";
			stringToWrite += "<td class='clsFieldLabel' align='right'>"+required+this.fieldList[i]._label+"</td>";
			stringToWrite += "<td valign='top' class='clsText'>";
			if (this.fieldList[i]._help != null) {
				stringToWrite += "<nobr>";
			} // if
			var field = new FieldFactory(this.fieldList[i]._description);
			stringToWrite += field.getHTML();
			if (this.fieldList[i]._help != null) {
				stringToWrite += "<span class='clsHelpLine' style='vertical-align: top'>"+this.fieldList[i]._help+"</span></nobr>";
			} // if
			stringToWrite += "</td>";
			stringToWrite += "</tr>";
		} // else
	} // for
	
	stringToWrite += "</table>";
	
	return stringToWrite;
} // getHTML()	
	

