//根据省份查询城市
function getCityByProvince(province,selectId,city){
	if(province == ''){
		var select = $("#"+selectId);
    	select.empty();//首先清除城市下拉框
    	select.append('<option value="">--请选择--</option>');
	}else{
		$.ajax({
		    url: 'geo/getCity.do?province=' + province,
		    type: 'GET',
		    dataType: 'xml',
		    timeout: 1000,
		    error: function(){
		        alert('获取城市失败，请重新操作');
		    },
		    success: function(xml){
		    	var select = $("#"+selectId);
		    	select.empty();//首先清除城市下拉框
		    	select.append('<option value="">--请选择--</option>');
		    	$(xml).find('city').each(function(){//遍历为城市下拉框添加选项
		            var id = $(this).children('id').text();
		            var name = $(this).children('name').text();
		            if(city == id){
		            	select.append("<option value="+id+" selected>"+name+"</option>");
		            }else{
		            	select.append("<option value="+id+">"+name+"</option>");
		            }
		        });
		    }
		});
	}
}

//通过上级编号查询下级车款车型列表
function getCarType(pid,level,selectId){
	if(pid == ''){
		var select = $("#"+selectId);
    	select.empty();//首先清除车型车款下拉框
    	select.append('<option value="">--请选择--</option>');
	}else{
		$.ajax({
		    url: 'carType/getCarType.do?pid=' + pid + '&level=' + level,
		    type: 'GET',
		    dataType: 'xml',
		    timeout: 1000,
		    error: function(){
		        alert('获取车型车款失败，请重新操作');
		    },
		    success: function(xml){
		    	var select = $("#"+selectId);;
		    	select.empty();//首先清除车型车款下拉框
		    	select.append('<option value="">--请选择--</option>');
		    	$(xml).find('carType').each(function(){//遍历为车型车款下拉框添加选项
		            var id = $(this).children('id').text();
		            var name = $(this).children('name').text();
		            select.append("<option value="+id+">"+name+"</option>");
		        });
		    }
		});
	}
}
 
/*验证码上刷新 */   
function chk_image(){   
	var img = document.getElementById("pic");   
	img.src = "image.jsp?" + Math.random();   
}   

//获取字符串字节数 （将汉字转换成字符，一个汉字长度为3） 
function getBytesCount(str)  
{  
    if (str == null)   
    {   
        return 0;   
    }   
    else   
    {   
        return (str.length + str.replace(/[\u0000-\u00ff]/g,"").length*2);   
    }   
}
//计算字数长度，obj是文本对象，length是能输入的字符长度。
function jisuanzishu(obj,length,show){
   var str=$("#"+obj).val();
   var s=getBytesCount(str);
   if(s > length){
	   for(var i = 0;i<str.length;i++){
		   s = getBytesCount(str.substr(0, i+1));
		   if(s > length){
			   if((s-length) >= 1){
				   $("#"+obj).attr("value",str.substr(0, i));
			   }else{
				   $("#"+obj).attr("value",str.substr(0, i+1));
			   }
			   break;
		   }
	   }
	   $("#"+show).html("<font color=\'red\'>"+getBytesCount($("#"+obj).val())+"</font>/"+length); 
   }else{
	   $("#"+show).html("<font color=\'red\'>"+s+"</font>/"+length); 
   }
}
