function resetSelectBox(reset){
	
	if ($('state_id')&&reset<1){
		$('state_id').innerHTML='<option value=\"0\">select</option>';
	}
	if ($('city_id')&&reset<2){
		$('city_id').innerHTML='<option value=\"0\">select</option>';
	}
	
	if ($('venue_id')&&reset<3){
		$('venue_id').innerHTML='<option value=\"0\">select</option>';
	}
}

window.addEvent( 'domready', function() {
	if ($('country_id')){
		$('country_id').addEvent('change', function(){
			var e = document.getElementById('country_id');
			var country_id = e.options[e.selectedIndex].value;
			
			if (country_id==0){
				resetSelectBox(0)		
				return;
			}else{
			
			var url = 'index.php?option=com_jlticketcenter&controller=events&task=getCountryBoxes&id='+country_id+'&format=raw';
			var jsonRequest = new Request.JSON({url: url, onSuccess: function(response){
				if ($('state_id')){$('state_id').innerHTML = response.states};
				if ($('city_id')){$('city_id').innerHTML = response.cities;}
				if ($('venue_id')){$('venue_id').innerHTML = response.venues;}
			}}).send();
			
			}
		});
	}// END Country
	
	if ($('state_id')){
		$('state_id').addEvent('change', function(){
			var e = document.getElementById('state_id');
			var state_id = e.options[e.selectedIndex].value;

			if (state_id==0){
				resetSelectBox(1)		
				return;
			}else{
				var url = 'index.php?option=com_jlticketcenter&controller=events&task=getStatesBoxes&id='+state_id+'&format=raw';
			
				var jsonRequest = new Request.JSON({url: url, onSuccess: function(response){
					if ($('city_id')){$('city_id').innerHTML = response.cities;}
					if ($('venue_id')){$('venue_id').innerHTML = response.venues;}
				}}).send();
			}
		});
	}//End State
	
	
	if ($('city_id')){
		$('city_id').addEvent('change', function(){
			var e = document.getElementById('city_id');
			var city_id = e.options[e.selectedIndex].value;
			
			if (city_id==0){
				resetSelectBox(3)		
				return;
			}else{
				var url = 'index.php?option=com_jlticketcenter&controller=events&task=getCitiesBoxes&id='+city_id+'&format=raw';
			
				var jsonRequest = new Request.JSON({url: url, onSuccess: function(response){
					if ($('venue_id')){$('venue_id').innerHTML = response.venues;}
				}}).send();
			}
		});
	}//End City
	
	if ($('venue_id')){
		$('venue_id').addEvent('change', function(){
			var e = document.getElementById('venue_id');
			var venue_id = e.options[e.selectedIndex].value;
			
			if (venue_id==0){
				return;
			}else{
				var url = 'index.php?option=com_jlticketcenter&controller=events&task=getVenueBoxes&id='+venue_id+'&format=raw';
			
				var jsonRequest = new Request.JSON({url: url, onSuccess: function(response){
					if ($('tickets')){$('tickets').value = response.seats;}
				}}).send();
			}
		});
	}//End City
	
	
});