function Field(name, value){
	this.value = value;
	this.name = name;
}

Field.prototype.setField = function(formName){
	
	var input = document.forms[formName].elements[this.name];
	var inputtype = input.type
	if(input.length && !input.type && input[0].type){
		 inputtype = input[0].type;
	}

	switch(inputtype) {
		case "radio":
			for(var i=0;i < input.length; i++){
				if(input[i].value == this.value){
					input[i].checked = true;
				}
			}
			return;
		case "checkbox":
			if(input.length) {
				var tmpValues = this.value.split(/,/);
				for(var j=0;j < tmpValues.length; j++) {
					for(var i=0;i < input.length;i++){
						if(input[i].value == tmpValues[j]){
							input[i].checked = true;
						}
					}
				}
			} else {
				if(input.value == this.value && input.checked != null) { 
					input.checked = true;
				}			
			}
			return;
		case "select-one":
			for(var i=0;i < input.length;i++){
				if(input[i].value == this.value){
					input[i].selected = true;
				}
			}
			return;
		case "select-multiple":
			var tmpValues = this.value.split(/,/);
			for(var j=0;j < tmpValues.length; j++) {
				for(var i=0;i < input.length;i++){
					if(input[i].value == tmpValues[j]){
						input[i].selected = true;
					}
				}
			}
			return;
		default:
			input.value = this.value;
			return;
	}
};

function Form(formName){
	this.formName = formName;
	this.fields = new Array();
}

Form.prototype.addField = function(name, value){
	this.fields.push(new Field(name, value));
};

Form.prototype.fill = function(){
	for(var i=0; i < this.fields.length; i++){
		this.fields[i].setField(this.formName);
	}
};

Form.prototype.displayErrors = function(errorHTML,ClassName){
	var errors = document.getElementById("errors");
	errors.innerHTML = errorHTML;
	errors.className = ClassName;
};
