window.addEvent( 'domready', function(e) {

	// add the show function to each section of content
	$$( 'ul.content' ).addEvents({
		'show': function() {
			$$( 'ul.content' ).setStyle( 'display', 'none' );
			this.setStyle( 'display', 'block' );
		}
	});
	// find all the buttons and add actions
	$$( '.tab-button' ).addEvent( 'click', function(e) {
		e.stop(); // stop the default click action link or button
		// for tab links/buttons go there
		if( this.lang.contains( "tab-" ) ) {
			// if we are on the review one then fire the submit
			if( this.lang == 'tab-go' ) {
				$('equote-form').submit();
			} else {
				$( this.lang ).fireEvent( 'click' );
			}
		}
	});
	 // add event to the uncheck all link
	if( $('remove-all' ) ) $( 'remove-all' ).addEvent( 'click', quote.uncheckAll );
	// add event to check all link
	if( $('add-all' ) ) $( 'add-all' ).addEvent( 'click', quote.checkAll );
	// blur for the zip code to auto fill the city and state
	$( 'zip' ).addEvent( 'blur', function() {
		quote.locationFill( $('city'), $('state'), $('zip') ); 
	});
	
	if( $( 'brought_selection' ) ){
		$( 'brought_selection' ).addEvent( 'change', function() {
			var selectVal = this.getSelected().get("value");
			$('what_brought_you_here').set('value',selectVal);
			
			if( selectVal == 'Other' ){
				$('specify_advertisement_span').setStyle('display','none');
				$('brought_other_span').setStyle('display','block');
				$('what_brought_you_here').set('value',selectVal+': '+ $('brought_other').get('value') );
			}else if( selectVal == 'An Advertisement' ){
				$('brought_other_span').setStyle('display','none');
				$('specify_advertisement_span').setStyle('display','block');
				$('what_brought_you_here').set('value',selectVal + $('specify_advertisement').getSelected().get("value") );
			}else{
				$('brought_other_span').setStyle('display','none');
				$('specify_advertisement_span').setStyle('display','none');
			}
		});
		$( 'brought_other' ).addEvent('keyup',function(){
			$('what_brought_you_here').set('value','Other : '+ this.get('value') );
		});
		
		$('specify_advertisement').addEvent('change',function(){
			var selectVal = this.getSelected().get("value");
			var broughtSelectionVal = $('brought_selection').getSelected().get("value");
			var thisVal = broughtSelectionVal  + selectVal;
			$('what_brought_you_here').set('value',thisVal);
		});
	}
	if( $( 'hear_selection' ) ){
		$( 'hear_selection' ).addEvent( 'change', function() {
			var selectVal = this.getSelected().get("value");
			$('how_you_heard_about_equote').set('value',selectVal);
			if( selectVal == 'Other' ){
				$('hear_other_span').setStyle('display','block');
				$('how_you_heard_about_equote').set('value',selectVal+': '+ $('hear_other').get('value'));
			}else{
				$('hear_other_span').setStyle('display','none');
			}
		});
		$( 'hear_other' ).addEvent('keyup',function(){
			$('how_you_heard_about_equote').set('value','Other : '+ this.get('value') );
		});
	}
	
	
	// add the clicks to the tab
	$$( 'div.tabs div' ).addEvents({
		'click': function() {
			switch( this.id ) {
				case "tab-businesses": if( $('tobicon') ) $('tobicon').setStyle( 'display', '' ); break;
				case "tab-details":
				case "tab-review": if( $('tobicon') ) $('tobicon').setStyle( 'display', 'none' ); break;
			}
			// only if this isn't the currently active one
			if( !this.hasClass('active' ) ) {
				if( quote.tabEvent( this.id ) ) {
					// set the tab styles
					$$( 'div.tabs div' ).removeClass( 'active' );
					this.addClass( 'active' );
					// show/hide content
					$( this.id.replace("tab","content") ).fireEvent( 'show' );
				}
			}
		}
	}).setStyle( 'cursor', 'pointer' );
	
	
	// submit the form

});
