$(document).ready(function(){
	$('select#storestate').val('');
	lftgcityoptions = [];
	var cityfield = $('select#storecity').get(0);
	for(i=0;i<cityfield.length;i++)lftgcityoptions.push(cityfield.options[i]);
	lftgstoreoptions = [];
	var storefield = $('select#stores').get(0);
	for(i=0;i<storefield.length;i++)lftgstoreoptions.push(storefield.options[i]);
	$('select#storecity').attr('length',1);
	$('select#stores').attr('length',1);
	$('select#storestate').change(function(){
		$('select#storecity').attr('length',1).get(0).selectedIndex=0;
		$('select#stores').attr('length',1).val('');
		var thisState = $(this).val();
		var thisCityField = $('select#storecity').get(0);
		for(i=0;i<lftgcityoptions.length;i++){
			var thisOption = lftgcityoptions[i];
			if ($(thisOption).attr('state') == thisState) {   
			    try {
					thisCityField.add(thisOption, null);
				} 
				catch (e) {
					thisCityField.add(thisOption, thisCityField.length);
				}
			}
		}
		return false;
	});
	$('select#storecity').change(function(){
		$('select#stores').attr('length',1).val('');
		var thisCity = $(this).val();
		var thisState = $('select#storestate').val();
		var thisStoreField = $('select#stores').get(0);
		for(i=0;i<lftgstoreoptions.length;i++){
			var thisOption = lftgstoreoptions[i];
			if (($(thisOption).attr('state') == thisState) && ($(thisOption).attr('city') == thisCity)) {
			    try {
					thisStoreField.add(thisOption, null);
				} 
				catch (e) {
					thisStoreField.add(thisOption, thisStoreField.length);
				}
			}
		}
		//If there is only 1 store, automatically select it in the list and display the information
		if(thisStoreField.length == 2)
		{
			thisStoreField.selectedIndex = 1;
			$('select#stores').change();
		}
		
		return false;
	});
	$('select#stores').change(function(){
		var thisStoreNumber = $(this).val();
		if($('.storeDiv:visible').length>0){
			$('.storeDiv:visible').fadeOut('slow');
			setTimeout("$('#store'+"+thisStoreNumber+").fadeIn('slow');",600);
		}
		else{
			$('#store'+thisStoreNumber).fadeIn('slow');
		}
		return false;
	});
	return false;
});