/* 
 * aptSearch.js
 *
 * Author: Andy Do <andy.do@resiteonline.com>
 *
 * This included JS is accompanying the class PropMan found in Site.php
 * to add events to Property Search Form.
 * PropMan class was defined to ease the generation of City, State, Bedrooms
 * Price Range, Square Footage input fields.
 *
 * Last Modification: 7.29.2010
 */

$(document).ready(function() {	
	// Change event for City Selection
	$('#selectCity').change(function(){
		var chosen = $('#selectCity :selected').text();
		$('#selectState option').each(function (index) {
			if (chosen.indexOf(", " + $(this).val()) > 0) {
				$('#selectState').attr('selectedIndex', index);
			}
		});
			
	});
	
	// Change event for State Selection
	$('#selectState').change(function () {
		chosen = $('#selectState option:selected').val();
		
		// First remove City List
		$('#selectCity option').each(function (index) {
			if (index > 0) { $(this).remove(); }
		});
		
		// Now rebuild City List
		for (index in cities) {
			if ( chosen == "" || cities[index].indexOf(", " + chosen) > 0 ) {
				comma = cities[index].indexOf(",");
				value = cities[index].substr(0, comma);
				$('#selectCity').append("<option value='" + value + "'>" + cities[index] + "</option>\n");
			}
		}
		
	});
	
	// Add event to Search Button
	$('INPUT.btn_submit').hover(
		function () {
			$(this).css ({
				'background-position' : '0px -26px',
				'color' : '#000000'
			});
		},
		function () {
			$(this).css ({
				'background-position' : '0px 0px',
				'color' : '#ffffff'
			});
		}
	);
});

