/*
Form Builder 2.0 behavior
============================================================
Last Modified: 2008-12-23
Version: 2.0.0 alpha

Changelog
============================================================
2008-12-23:
	Changed window onload activation to dom:loaded activation
	
2008-10-20:
	Replaced the GST_Utility.get_ancestor with Prototype's .up()
	Removed requirement of GST_Utility
*/

var GST_FB2 = {
	class_on_forms:"GST_form",
	class_name_on_focus:"GST_form_hasfocus",
	
	activate:function()
	{
		// Get all GST_FB2 forms
		var obj_forms = $$('form.' + GST_FB2.class_on_forms);
		
		for (var i = 0; i < obj_forms.length; i++) {
			var form_fields = obj_forms[i].select('input', 'textarea', 'select');
			
			for (var j = 0; j < form_fields.length; j++) {
				form_fields[j].observe('focus', function(e) {
					var li = $(this).up('li');
			
					if (li !== false) {
						li.addClassName(GST_FB2.class_name_on_focus);
					}
				});
				
				form_fields[j].observe('blur', function(e) {
					var li = $(this).up('li');
			
					if (li !== false) {
						li.removeClassName(GST_FB2.class_name_on_focus);
					}
				});
			}
		} // end for(i)
	} // end activate()
}

// Require that Prototype is available
if (typeof Prototype == "undefined") {
	alert("GST Form Builder 2.0 requires the Prototype javascript framework.\n\nPlease check that it is included.");
} else {
	document.observe("dom:loaded", GST_FB2.activate);
}
