$(document).ready(function(){
		$("input[type=text], input[type=password], select").focus(function(){
			$(this).addClass("focus");
		});
		$("input[type=text], input[type=password], select").blur(function(){
			$(this).removeClass("focus");
		});

	
		var debug = 0;		//display errors
		$("select#auto_manuf").change(function(){
			$.getJSON("/lat/__ajax/sublist/?type=auto_model&item_id="+$(this).val(), function(data){
				if (data.OK){
  					$("select#auto_model").html(data.SUBLIST);
  				} else {
  					if (debug)
  						alert(data.ERROR);
  				}
			});
		});
		$("select#lorry_manuf").change(function(){
			$.getJSON("/lat/__ajax/sublist/?type=lorry_model&item_id="+$(this).val(), function(data){
  				if (data.OK){
  					$("select#lorry_model").html(data.SUBLIST);
  				} else {
  					if (debug)
  						alert(data.ERROR);
  				}
			});
		});
		$("select#wtransp_manuf").change(function(){
			$.getJSON("/lat/__ajax/sublist/?type=wtransp_model&item_id="+$(this).val(), function(data){
  				if (data.OK){
  					$("select#wtransp_model").html(data.SUBLIST);
  				} else {
  					if (debug)
  						alert(data.ERROR);
  				}
			});
		});
		$("select#country").change(function(){
			$.getJSON("/lat/__ajax/sublist/?type=region&item_id="+$(this).val(), function(data){
  				//cleanup
  				$("select#region").html('<option value="">--</option>');
  				$("select#city").html('<option value="">--</option>');
  				$("select#district").html('<option value="">--</option>');
				if (data.OK){
  					$("select#region").html(data.SUBLIST);
  				} else {
  					if (debug)
  						alert(data.ERROR);
  				}
			});
		});		
		
		$("select#region").change(function(){
			$.getJSON("/lat/__ajax/sublist/?type=city&item_id="+$(this).val(), function(data){
  				//cleanup
  				$("select#city").html('<option value="">--</option>');
  				$("select#district").html('<option value="">--</option>');
				if (data.OK){
  					$("select#city").html(data.SUBLIST);
  				} else {
  					if (debug)
  						alert(data.ERROR);
  				}
			});
		});	
		
		$("select#city").change(function(){
			$.getJSON("/lat/__ajax/sublist/?type=district&item_id="+$(this).val(), function(data){
				if (data.OK){
  					$("select#district").html(data.SUBLIST);
  				} else {
  					if (debug)
  						alert(data.ERROR);
  				}
			});
		});	
		
		$("select#country2").change(function(){
			$.getJSON("/lat/__ajax/sublist/?type=region&item_id="+$(this).val(), function(data){
  				//cleanup
  				$("select#region2").html('<option value="">--</option>');
  				$("select#city2").html('<option value="">--</option>');
				if (data.OK){
  					$("select#region2").html(data.SUBLIST);
  				} else {
  					if (debug)
  						alert(data.ERROR);
  				}
			});
		});		
		$("select#region2").change(function(){
			$.getJSON("/lat/__ajax/sublist/?type=city&item_id="+$(this).val(), function(data){
  				//cleanup
  				$("select#city2").html('<option value="">--</option>');
				if (data.OK){
  					$("select#city2").html(data.SUBLIST);
  				} else {
  					if (debug)
  						alert(data.ERROR);
  				}
			});
		});			
});
