var RequestQuote = Class.create(); 

				
				
				
RequestQuote.prototype = 
{
	initialize: function()
	{
		Event.observe(window, 'load', this.windowOnLoad.bindAsEventListener(this));		
	},
	
	windowOnLoad: function()
	{
		//set up a form validator	
		
		var displayErrors;
		
		if (!this.isSafari())
			displayErrors = this.displayErrors;
		
		this.validator = new RedSquare.FormValidator
							 (
							  	$('form-request-quote'), 
								displayErrors
							 );
		
		Event.observe($('material'), 'change', this.materialOnChange.bindAsEventListener(this));
					
		this.updateStyles($('material').value);
					
		$('form-request-quote').elements[0].focus();
	},
	
	materialOnChange: function(event)
	{
		var element = Event.element(event);
		
		this.updateStyles(element.value);					
	},
	
	updateStyles: function(material)
	{
		var style = $('style');
		
		style.options.length = 0;
		
		if (material == '')
		{
			style.options[style.options.length] = new Option('choose a fence material first', '');
		}
		else
		{
			style.options[style.options.length] = new Option('choose a style');
			
			for (var i=0; i<FenceStyles[material].length; i++)
			{
				style.options[style.options.length] = new Option(FenceStyles[material][i], FenceStyles[material][i]);
			} 
		}
	},
				
	displayErrors: function(culprits, errors)
	{	
		$('note-errors').innerHTML = 'ERROR:<br />' + errors.join("<br />");
		
		document.location.hash = 'note-errors';
	},
	
	isSafari: function()
	{
		return navigator.userAgent.match(/Safari/i);
		
	}
}

// initialize an anonymous instance

new RequestQuote();