//**********************************************************************************************************************
/**
* COMPANY: Zipline Interactive
* EMAIL: info@gozipline.com
* PHONE: 509-321-2849
* DESCRIPTION: This document contains programming required for the website templates.  Requires the jQuery library.
*/
//***********************************************************************************************************************


//***********************************************************************************************************************
//ON DOCUMENT READY FUNCTIONS USING JQUERY
//***********************************************************************************************************************
$(function() {

	//ON STATE CHANGE
	$('#search_select_state').change(function() {
		state = get_state_value();
		$.post("index.php", { action: "load_municipalities", state: state },
 			function(data) {
   				$('#search_select_city').html(data);
 			}
 		);
	});

	//HANDLE FORM SUBMIT
	$('#map_search').submit(function() {
		state = get_state_value();
		url = $('#search_select_city').val();	
		if(state != "" && url != null) {
			window.location = url;
		} else {
			alert("You must select a state and a municipality");
		}
		return false;
	});
	
	$('#USA area').click(function(e) {
		e.preventDefault();
		var id = $(this).attr('id');
		
		$('#search_select_state').val(id);
		update_search();
	});
	

	//FUNCTION TO GET CURRENT STATE VALUE
	function get_state_value() {
		var state_value = $('#search_select_state').val();
		return state_value;
	}
	
	function update_search() {
		state = get_state_value();
		$.post("index.php", { action: "load_municipalities", state: state },
 			function(data) {
   				$('#search_select_city').html(data);
 			}
 		);
	}
});
