/*========== geo.js ==========*/
var Geo={};

// AJAX: Obtener ciudades
Geo.getCities=function(){
	
	geoAjax.getCities($('state_id').value, function(response){
		
		$('city_id').innerHTML="";
			
			if(response.total==0){
				var op=new Element('option', {
					'value':"0"
				}).appendText("No identificado");
				
				$('city_id').adopt(op);
				
				return;
			}
			var op=new Element('option', {
					'value':"0"
				}).appendText("Seleccione");
				
				$('city_id').adopt(op);
				
			for(var x=0; x<response.total; x++){
				
				var op=new Element('option', {
					'value':response.data[x].cityID
				}).appendText(response.data[x].cityName);
				
				$('city_id').adopt(op);
			}
			
		});
}


// AJAX: Obtener estados
Geo.getStates=function(){

	geoAjax.getStates($('countries_id').value, function(response){
		
		
		$('state_id').innerHTML="";
		$('city_id').innerHTML="";
			
			
				$('city_id').adopt(op);

		if(response.total==0){
			var op=new Element('option', {
				'value':"0"
			}).appendText("No identificado");
			
			$('state_id').adopt(op);
			var op1=new Element('option', {
				'value':"0"
			}).appendText("No identificado");
			
			$('state_id').adopt(op);
			$('city_id').adopt(op1);
			return;
		}
		var op=new Element('option', {
				'value':"0"
			}).appendText("Seleccione");
		var op1=new Element('option', {
				'value':"0"
			}).appendText("Seleccione");	
			$('state_id').adopt(op);
			$('city_id').adopt(op1);
		for(var x=0; x<response.total; x++){
			
			var op=new Element('option', {
				'value':response.data[x].stateID
			}).appendText(response.data[x].stateName);
			
			$('state_id').adopt(op);
		}
		
	});
}
