/**
 * Creates a hidden text element with the given name, id and initial value.
 **/
function createHiddenInput(name, id, value, form){
	var element = createInputElement(name, id, "hidden", value);
	if(form){
	   form[name] = element;
	}
	return element;
}

/**
 * Creates an input element.
 **/
function createInputElement(name, id, type, value){
	var element = createElement("Input", name, id);
	//element.setAttribute('type', fieldType);
    //element.setAttribute('name', fieldName);
	element.type = type;
	element.value = value;
	return element;
}

/**
 * Creates a form element.
 * Note: Mozilla is very picky in that the page must be loaded before
 * dynamically adding the form.  I have not tried moving the script tags out of the head tag to
 * see if it works as long as the script is below the parent.  This may work since the parent does in 
 * fact exist at that point.
 **/
function createFormElement(name, id, action, method){
	var element = createElement("Form", name, id);
	element.action = action;
	element.method = method;
	return element;
}

/**
 * Creates an element of the specified type with the given name and id.  The type
 * correlates to a tag such as form, input or div.  The surrounding brackets are not
 * necessary.
 **/
function createElement(type, name, id){
    logDebug("creating element");
	var element = document.createElement(type);
	element.name = name;
	element.id = id;
	logDebug("element: " + element.name);
	return element;
}

/**
 * Creates a select element to add to a form.  Options are the options for the select list.  If
 * this is null then no options are set.  The options parameter should be an array of Option objects.
 **/
 function createSelectElement(name, id, options){
    var element = createElement("select", name, id);
    if(options){
        for(var i = 0; i < options.length; i++){
            element.options[i] = options[i];
        }
    }
    return element;
 }