var basePath = "/tyreselector/list/";
var SELECT_TXT="选择您需要查找的", select_cus="请选择", brand_txt="品牌", mode_txt="型号", version_txt="版本", year_txt="年份", defValue="summer";
var brand_s = SELECT_TXT + brand_txt;
var mode_s = SELECT_TXT + mode_txt;
var version_s = select_cus + version_txt;
var year_s = select_cus;

$(function (){
	var $brand = $("#brand");
	var $mode = $("#mode");
	var $version = $("#version");
	var $year = $("#year");
	
	$.get(basePath + "getBrand", function(ps) {
		$brand.html(ps);
		$brand[0].selectedIndex = 0;
		if ($brand[0].refresh != undefined)
			$brand[0].refresh();
	});
	var pa1 = {width:300, style:'width:300px;', hasfirst:true};
	var pa2 = {width:300, style:'width:300px;', hasfirst:true};
	var pa3 = {width:150, style:'width:150px;', hasfirst:true};
	var pa4 = {width:102, style:'width:102px;', hasfirst:true};
	$brand.msDropDown(pa1);
	$mode.msDropDown(pa2);
	$version.msDropDown(pa3);
	$year.msDropDown(pa4);
	
	//$mode.attr("disabled", true);
	//$version.attr("disabled", true);
	//$year.attr("disabled", true);
})

function populateMode(pid) {
	$("#mode").empty();
	$("#version").empty();
	$("#year").empty();
	var $mode = $("#mode");
	
	$.get(basePath + 'getMode', {
		pname : encodeURIComponent(pid)
	}, function(cs) {
		$mode.html(cs);
		//$mode.attr("disabled", false);
		$mode[0].selectedIndex = 0;
		if ($mode[0].refresh != undefined)
			$mode[0].refresh();
	});
}

function populateVersion(pid) {
	$("#version").empty();
	$("#year").empty();
	var bName = $("#brand").val();
	var $version = $("#version");
	
	$.get(basePath + 'getVersion', {
		brandName : encodeURIComponent(bName),
		pname : encodeURIComponent(pid)
	}, function(cs) {
		$version.html(cs);
		//$version.attr("disabled", false);
		$version[0].selectedIndex = 0;
		if ($version[0].refresh != undefined)
			$version[0].refresh();
	});
}

function populateYear(pid) {
	$("#year").empty();
	var $year = $("#year");
	var bName = $("#brand").val();
	var mName = $("#mode").val();
	
	$.get(basePath + 'getYear', {
		pname : encodeURIComponent(pid),
		brandName : encodeURIComponent(bName),
		modeName : encodeURIComponent(mName)
	}, function(cs) {
		$year.html(cs);
		//$year.attr("disabled", false);
		$year[0].selectedIndex = 0;
		if ($year[0].refresh != undefined)
			$year[0].refresh();
	});
}

function setValue(value) {
	defValue = value;
}

function findTyre() {
	var tHtml = '';
	var brand = $("#brand").val();
	var mode = $("#mode").val();
	var ver = $("#version").val();
	var ye = $("#year").val();
	
	if (brand == "-1") {
		alert ('请选择品牌');
		return;
	} else if (mode == "-1") {
		alert ('请选择型号');
		return;
	} else if (ver == "-1") {
		alert ('请选择版本');
		return;
	} else {
		$.get(basePath + 'findTyre', {
			brandName : encodeURIComponent(brand),
			modeName : encodeURIComponent(mode),
			version : encodeURIComponent(ver),
			year : encodeURIComponent(ye),
			defV : defValue
		}, function(cs) {
			$("#content").html(cs);
		});
	}
}

function openwindow(url,name,iWidth,iHeight) {
	var url;                            
	var name;                           
	var iWidth;                         
	var iHeight;                        
	var iTop = (window.screen.availHeight-30-iHeight)/2;       
	var iLeft = (window.screen.availWidth-10-iWidth)/2;        
	window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizeable=no,location=no,status=no');
}

function getTyreSize(pid, i, m, j) {
	var sHtml = '';
	$.get(basePath + 'findTyreSize', {
		patternId : pid
	}, function(cs) {
		var cs_v = eval(cs);
		sHtml += '<tr>';
		sHtml += '<th>轮胎尺寸</th>';
		sHtml += '<th>载重指数</th>';
		sHtml += '<th>速度级别</th>';
		sHtml += '<th>轮胎特殊标记</th>';
		sHtml += '</tr>';
		if (cs_v.length) {
			$.each(cs_v, function(k, n) {
				sHtml += '<tr>';
				sHtml += '<td>'+n.sizeShort+'</td>';
				sHtml += '<td>'+n.li+'</td>';
				sHtml += '<td>'+n.si+'</td>';
				if (n.remark == "") {
					sHtml += '<td>-</td>';
				} else {
					sHtml += '<td>'+n.remark+'</td>';
				}
				sHtml += '</tr>';
			});
		}
		sHtml += '<tr>';
		sHtml += '<td colspan="4" class="tc_msgbz">';
		sHtml += '*:宝马汽车定义的轮胎标记<p>';
		sHtml += 'K1:米其林定义的轮胎标记(用于法拉利汽车)<p>';
		sHtml += 'MO:奔驰汽车定义的轮胎标记<p>';
		sHtml += 'N0:保时捷汽车定义的轮胎标记<p>';
		sHtml += 'N1:保时捷汽车定义的轮胎标记<p>';
		sHtml += 'N2:保时捷汽车定义的轮胎标记<p>';
		sHtml += 'N3:保时捷汽车定义的轮胎标记<p>';
		sHtml += 'ZP:零气压续行轮胎';
		sHtml += '</td>';
		sHtml += '</tr>';
		
		$("#sizeList_"+i+"_"+m+"_"+j+"").empty();
		$("#sizeList_"+i+"_"+m+"_"+j+"").append(sHtml);
	});
	$("#sizeDiv_"+i+"_"+m+"_"+j+"").show();
}

function hiddenSizeDiv(i, m, j) {
	$("#sizeDiv_"+i+"_"+m+"_"+j+"").hide();
}