$(function() {
	loadOrgan();
	
	$('#provinceSelect').change(function(){
		//alert(111)
		var url = ctx + '/organ/changeCities';
		$.ajax({
			url : url,
			type : 'post',
			dataType : 'json',
			data :  [ {
				name : 'province',
				value : $('#provinceSelect').val()
			} ],
			success : function(data) {
				var list = data.cityList;
				$('#citySelect option').remove();
				for(var i=0;i<list.length;i++){
					$('#citySelect').append("<option value="+list[i].aiid+">"+list[i].name+"</option>");
				}
			}
		})
	});
})


function saveEdit(){
	var url = ctx + '/organ/saveEdit';
	var serial = $("form").serialize();
	$.ajax({
		url: url,
		type:'POST',
		data: serial,
		dataType:'json',
		success:function(data){
			if(data.flag){
				window.location.href=ctx + "/organ";
			}
		}
		
	});
}

function loadOrgan(){
	$.ajax({
		url : ctx + '/organ/getOrgan',
		type : 'post',
		dataType : 'json',
		data : [ {
			name : 'id',
			value : $('#idHidden').val()
		} ],
		success : function(data) {
			var organInfo = data.organInfo;
			var cityList = data.cityList;
			var provinceList = data.provinceList;
			
			$('#organCode').val(organInfo.organCode);
			$('#organName').val(organInfo.organName);
			
			var count3=$("#organType option").length;
			for(var i=0;i<count3;i++){
				if($("#organType").get(0).options[i].value == organInfo.organType)  
		        {  
		            $("#organType").get(0).options[i].selected = true;  
		          
		            break;  
		        }  
		    }
			
			for(var i=0;i<provinceList.length;i++){
				$('#provinceSelect').append("<option value="+provinceList[i].aiid+">"+provinceList[i].name+"</option>");
			}
			
			for(var i=0;i<cityList.length;i++){
				$('#citySelect').append("<option value="+cityList[i].aiid+">"+cityList[i].name+"</option>");
			}
		
			var count=$("#provinceSelect option").length;
			for(var i=0;i<count;i++)  
		    {if($("#provinceSelect").get(0).options[i].text == data.province)  
		        {  
		            $("#provinceSelect").get(0).options[i].selected = true;  
		          
		            break;  
		        }  
		    }
			
			var count2=$("#citySelect option").length;
			for(var i=0;i<count2;i++)  
		    {if($("#citySelect").get(0).options[i].text == data.city)  
		        {  
		            $("#citySelect").get(0).options[i].selected = true;  
		          
		            break;  
		        }  
		    }
		}
	});
}