function LoadYear(){
	$("#Year").children("option:selected").text("Loading...");
	$.get("inc/North_America_model.php?action=year",{user:user,l:ver,random:Math.random()},function(data){
		$("#Year").html(data);
		var tmp=readCookie('Year');
		if (tmp)
		{
			//为了兼容ie6的写法
			setTimeout(function(){
			$("#Year").val(tmp);
			LoadMake(tmp,'');
			},1);
		}
	});
}

//==================================
$('#Year').each(function(){
	LoadYear();
});
$("#SortTable").tablesorter();
$('#model').each(function(){
	var tmp=readCookie('model');
	loadmode(tmp,'');
});
function LoadMake(Year,sel) {
	writeCookie('Year',Year,24);
	//$("#Make").children("option:selected").text("Loading...");
	$.get("inc/North_America_model.php?action=make&Year="+Year,{user:user,l:ver,random:Math.random()},function(data){
		$("#Make").html(data);
		var tmp=readCookie('Make');
		if (tmp)
		{
			//为了兼容ie6的写法
			setTimeout(function(){
			$("#Make").val(tmp);
			LoadMode(tmp,'');
			},1);
		}
	});
}
function LoadMode(makeid,sel) {	
	writeCookie('Make',makeid,24);
	$("#Mode").children("option:selected").text("Loading...");
	$.get("inc/North_America_model.php?action=mode&makeid="+makeid,{user:user,l:ver,random:Math.random()},function(data){
		$("#Mode").html(data);
		var tmp=readCookie('Mode');
		if (tmp)
		{
			//为了兼容ie6的写法
			setTimeout(function(){
			$("#Mode").val(tmp);
			LoadModel(tmp,'');
			},1);
		}
	});
}
function LoadModel(modeset_id,sel) {
	writeCookie('Mode',modeset_id,24);
	$("#div_contents").children("option:selected").text("Loading...");
	
	$.get("inc/North_America_model.php?action=model&modeset_id="+modeset_id,{user:user,l:ver,random:Math.random()},function(data){
		$("#div_contents").html(data);
		$('tr:even').addClass('gray');
		//==============================
		$("input.checkthis").click(function(){
			id=$(this).attr("value");
			//alert($(this).attr("checked"));
			if ($(this).attr("checked"))
				writeCookie('pro_'+id,'1',24);			
			else
				writeCookie('pro_'+id,'0',0);
		});
	});
}
function loadmodelselect(modeset_id,sel) {
	$("#mode").val('');
	mod=$(this).parents(".control").attr('id');
	makechange(modeset_id,mod);
}
function loadmode(modeset_id,sel) {
	if (modeset_id=='')
	{
		return;
	}
	$("#div_contents").children("option:selected").text("Loading...");
	$.get("inc/North_America_model.php?action=europemodel&modeset_id="+modeset_id,{user:user,l:ver,random:Math.random()},function(data){
		$("#div_contents").html(data);
		$('tr:even').addClass('gray');
		//==============================
		$("input.checkthis").click(function(){
			id=$(this).attr("value");
			//alert($(this).attr("checked"));
			if ($(this).attr("checked"))
				writeCookie('pro_'+id,'1',24);			
			else
				writeCookie('pro_'+id,'0',0);
		});
	});
	$.get("inc/North_America_model.php?action=getsub&modeset_id="+modeset_id,{user:user,l:ver,random:Math.random()},function(data){
		$("#mode").html(data);
	});
}
function loadproduct(modeset_id,sel)
{
	$.get("inc/North_America_model.php?action=enginechassis&modeset_id="+modeset_id,{user:user,l:ver,random:Math.random()},function(data){
		$("#div_contents").html(data);
		$('tr:even').addClass('gray');
		//==============================
		$("input.checkthis").click(function(){
			id=$(this).attr("value");
			//alert($(this).attr("checked"));
			if ($(this).attr("checked"))
				writeCookie('pro_'+id,'1',24);			
			else
				writeCookie('pro_'+id,'0',0);
		});
	});
}
function loadmodel(style,obj)
{
	if ($('#'+obj+' img').attr('src').indexOf('loading.gif'))
	{
	$.get(style,'',function(data){
		$('#'+obj).html(data);
	});
	}
	$(".TreeTable tr.subtitle").click(function(){
		temp=$(this).attr("id");
		//$(".TreeTable tr."+temp).toggle();
		if ($(".TreeTable tr."+temp).css("display")=="none")
			$(".TreeTable tr."+temp).css("display","");
		else
			$(".TreeTable tr."+temp).css("display","none");
	});
	//鼠标移过变色
	$(".TreeTable tr").hover(
	function(){
		$(this).addClass("hover");
	},
	function () {
		$(this).removeClass("hover");
	  }
	);
}
function showdiv(id) {
	$.get("inc/proshow.php?id="+id,{user:user,l:ver,random:Math.random()},function(data){
		$("select").addClass("hidden");
		$('<div id="POPproview"></div>').appendTo("body"); 
		$('<div id="MUSK"></div>').appendTo("body"); 
		$("div#MUSK").css("top",0);
		$("div#MUSK").css("left",0);
		$("div#MUSK").css({width:$(document).width(),height:$(document).height()});
		$("div#POPproview").html(data);
		$("div#POPproview").css("top",$(document).scrollTop()+$(window).height()/2-600/2);
		$("div#POPproview").css("left",$(window).width()/2-800/2);
		$("div#POPproview").css({width:800,height:600});
		$("div#POPproview").fadeIn("slow");
		$("div#POPproview").draggable({ handle: '.title' });
		//点击MUSK关闭层
		$('#MUSK').click(function(){
			divclose('POPproview');
		});
		//车型树的点击动作
		$(".TreeTable tr.subtitle").click(function(){
			temp=$(this).attr("id");
			oheight=$(".TreeTable").height();
			$(".TreeTable tr."+temp).toggle();
		});
		//鼠标移过变色
		$(".TreeTable tr").hover(
		function(){
			$(this).addClass('hover');
		},
		function () {
			$(this).removeClass("hover");
		  }
		);
	});
}