var FormFiller = Class.create();

FormFiller.prototype = 
{

	initialize: function()
	{},
	
	setFields : function(_values)
	{
		this.values = JSON.parse(_values);    
		for (var i in this.values)
		{
			//do not want to set file elements or submit buttons
			//file of course because it is not allowed
			if($(i).type != 'submit' && $(i).type != 'file'){
				if($(i).type == 'checkbox' ) {
					if (this.values[i] == 'on')
					{
						$(i).checked = true; 
					}					
				}
				else {
					$(i).value = this.values[i];
				}
			}
		}     
	},
  
	setErrors : function(_errors)
	{
		this.errors = JSON.parse(_errors);     
		for (var i in this.errors)
		{
			new Insertion.Bottom(i,'<div style="color: red;">' + (this.errors[i]) + '</div>');  
		}     
	}
}    


var FormHints = new Class.create()

FormHints.prototype = {

	/*
	 * The form hints class: Prepares the form hints. Construct of DOMload
	 */
	initialize :
	function() {
		this.onFocusEventHandler = this.onFocus.bindAsEventListener(this);
		this.onBlurEventHandler = this.onBlur.bindAsEventListener(this);
		this.prepareInputsForHints();
	},

	prepareInputsForHints : 
	function() {
		var tags = new Array("input","textarea","select");
		for (var type=0; type<tags.length; type++ ) {
			var inputs = document.getElementsByTagName(tags[type]);
			for (var i=0; i<inputs.length; i++){
				// test to see if the hint span exists first
				if (inputs[i].ancestors()[0].getElementsByClassName("hint")[0]) {
					// the span exists!  Bind the event handlers
					Event.observe(inputs[i],'focus',this.onFocusEventHandler); 
					Event.observe(inputs[i],'blur',this.onBlurEventHandler);				
				}
			}
		}	
	},
	
	onFocus :
	function (e) {
		el = Event.element(e);
		el.ancestors()[0].getElementsByClassName("hint")[0].setStyle({display : "inline"});	
		return false;
	},
	
	onBlur : 
	function (e) {
		el = Event.element(e);
		el.ancestors()[0].getElementsByClassName("hint")[0].setStyle({display : "none"});	
		return false;
	}
}

