//在品牌下拉框中初始化系列数据
//参数：brandId是品牌下拉框的id
//selected_model_id是默认选中的选项Id
function update_brand_options(brandId,selected_model_id){
var ob = document.getElementById(brandId);
if(!ob || ob==undefined)
{
return ;
}
ob.disabled=false;
ob.length=0;
ob.options[0] = new Option('请选择品牌',''); // new Option(optionSeriesName,0) 参数1：text, 参数2：value
var i = 1;
for(n in brandGroupData)
{
var row = brandGroupData[n];
var opvalue = row.code + ' ' + row.name;
ob.options[i]=new Option(opvalue,row.id);
if(selected_model_id == row.id){
	ob.options[i].selected = true;
} 
i++;
}
}

//根据传入的slct_series_value（上级类型value），在下级下拉框（id是slct_model_id）中更新该系列中的值
//参数：slct_model_id下级下拉框的id
// slct_series_value是上级类型value
// selected_model_id是将在下拉框显示的modelId
// groupData是数据存储的地方
// name是下拉框的名称
function update_options(slct_model_id,slct_series_value,groupData,name,selected_model_id){
var m;
if('manufacturerGroupData' == groupData){
	m = manufacturerGroupData[slct_series_value];
	clearSeriesId();
}
if('seriesGroupData' == groupData){
	m = seriesGroupData[slct_series_value];
	clearModelId();
}
if('modelGroupData' == groupData){
	m = modelGroupData[slct_series_value];
	clearCarTypeId();
}
if('carTypeGroupData' == groupData){
	m = carTypeGroupData[slct_series_value];
}
var selObj = document.getElementById(slct_model_id);
if(!selObj || selObj==undefined)
{
return false;
}
clearSelect(selObj,name);
var i = 1;
for(n in m)
{
var row = m[n];
var opvalue = row.name;
selObj.options[i]=new Option(opvalue,row.id);
if(selected_model_id == row.id){
	selObj.options[i].selected = true;
} 
i++;
}
}
//清空下拉框
function clearSelect(selObj,name){
	selObj.innerHTML = '';
	selObj.length=0;
	selObj.options[0] = new Option(name,'');
	selObj.disabled=false;
}

//清空品牌
function clearBrandId(){
	var selObj = document.getElementById('brandId');
	if(!selObj || selObj==undefined)
	{
	return false;
	}
	clearSelect(selObj,'请选择品牌');
	clearManufacturerId();
}

//清空厂商
function clearManufacturerId(){
	var selObj = document.getElementById('manufacturerId');
	if(!selObj || selObj==undefined)
	{
	return false;
	}
	clearSelect(selObj,'请选择厂商');
	clearSeriesId();
}

//清空系列
function clearSeriesId(){
	var selObj = document.getElementById('seriesId');
	if(!selObj || selObj==undefined)
	{
	return false;
	}
	clearSelect(selObj,'请选择系列');
	clearModelId();
}

//清空车型
function clearModelId(){
	var selObj = document.getElementById('modelId');
	if(!selObj || selObj==undefined)
	{
	return false;
	}
	clearSelect(selObj,'请选择车型');
	clearCarTypeId();
}

//清空车款
function clearCarTypeId(){
	var selObj = document.getElementById('carTypeId');
	if(!selObj || selObj==undefined)
	{
	return false;
	}
	clearSelect(selObj,'请选择车款');
	if(document.getElementById('name')){
		document.getElementById('name').value='';
	}
}
function getName(){
	var name = $("#brandId").find('option:selected').text().substr(2,$("#brandId").find('option:selected').text().length); 
	if(name.indexOf($("#manufacturerId").find('option:selected').text()) == -1){
		name = name + "-" + $("#manufacturerId").find('option:selected').text();
	}
	if(name.indexOf($("#seriesId").find('option:selected').text()) == -1){
		name = name + "-" + $("#seriesId").find('option:selected').text();
	}
	if(name.indexOf($("#modelId").find('option:selected').text()) == -1){
		name = name + "-" + $("#modelId").find('option:selected').text();
	}
	if(name.indexOf($("#carTypeId").find('option:selected').text()) == -1){
		name = name + "-" + $("#carTypeId").find('option:selected').text();
	}
	document.getElementById('name').value = name;
}
//手动输入车型车款
function inputName(obj,id){
	if(obj.checked){
		$("#"+id).removeAttr('readonly');
	  	$("#"+id).removeAttr('style');
	  	document.getElementById(id).value = '';
	  	clearBrandId();
	  	$("#brandId").attr('disabled',true);
	  	$("#manufacturerId").attr('disabled',true);
	  	$("#seriesId").attr('disabled',true);
	  	$("#modelId").attr('disabled',true);
	  	$("#carTypeId").attr('disabled',true);
	}else{
		$("#"+id).attr('readonly','readonly');
		$("#"+id).attr('style','background-color:#ACA899;');
		document.getElementById(id).value = '';
		$("#brandId").attr('disabled',false);
	  	$("#manufacturerId").attr('disabled',false);
	  	$("#seriesId").attr('disabled',false);
	  	$("#modelId").attr('disabled',false);
	  	$("#carTypeId").attr('disabled',false);
	  	update_brand_options("brandId",null);
	}
  }
//编辑页面初始化
function inputName1(obj,id){
	if(obj.checked){
		$("#"+id).removeAttr('readonly');
	  	$("#"+id).removeAttr('style');
	  	document.getElementById(id).value = '';
	  	clearBrandId();
	  	$("#brandId").attr('disabled',true);
	  	$("#manufacturerId").attr('disabled',true);
	  	$("#seriesId").attr('disabled',true);
	  	$("#modelId").attr('disabled',true);
	  	$("#carTypeId").attr('disabled',true);
	}else{
		$("#"+id).attr('readonly','readonly');
		$("#"+id).attr('style','background-color:#ACA899;');
		document.getElementById(id).value = '';
		$("#brandId").attr('disabled',false);
	  	$("#manufacturerId").attr('disabled',false);
	  	$("#seriesId").attr('disabled',false);
	  	$("#modelId").attr('disabled',false);
	  	$("#carTypeId").attr('disabled',false);
	}
  }
//显示或隐藏其他信息
  function showOther(obj,id){
  	var table = document.getElementById(id);
  	if('none' == table.style.display){
  		table.style.display = 'block';
  		obj.innerHTML="隐藏";
  	}else{
  		table.style.display = 'none';
  		obj.innerHTML="展开";
  	}
  	
  }
  
  //为注册
  function notRegister(obj,id){
	  if(obj.checked){
		  removeStyle($("#"+id));
		  $("#"+id).removeAttr("reg").removeAttr("tip");
		  $("#"+id).attr("value","").attr("disabled","disabled").css("background-color","#ACA899");
	  }else{
		$("#"+id).removeAttr("disabled").css("background-color","");
		$("#"+id).attr("reg","^[\\S]+$").attr("tip","上户日期是必填项");
	  }
  }
  
