/**
 * @author Andrew Romashkan
 */

document.observe("dom:loaded", function() {
	Contact.init();
});


Contact = {
	init : function(){
		this.countryAutoComplete = new AutoComplete({
			dom 	: 'contact_country',
			list 	: COUNTRIES_LIST
		});
		
		this.stateAutoComplete = new AutoComplete({
			dom 	: 'contact_state',
			list 	: STATE_LIST
		});
		
		this.stateFieldActivator = {
			init : function(){
				this.dom = $("contact_state");
				this.dom_country = $("contact_country");
				
				var scope = this;
				function prepareValidation(){
					window.setTimeout( function(){
						scope.validate();
					}, 100 );
				}				
				this.dom_country.observe("blur",prepareValidation);				
			
				this.validate();
			},
			enable : function(){
				this.dom.disabled = false;
			},
			disable : function(){
				this.dom.value = "";
				this.dom.disabled = true;
			},
			validate : function(){
				if( this.dom_country.value != "United States" )
					this.disable();
				else
					this.enable();
			}
		}
		this.stateFieldActivator.init();
	}	
}