﻿document.write("<script src='js/partsConfig.js'></script>");

var minNum=1;
	function setBrand()//添加 品牌
	{
		for(var i=0 ;i<p_Brand.length;i++)
		{
			if(p_Brand[i][4]>=minNum){
		        var op= new Option(p_Brand[i][0],p_Brand[i][1]);
				op.title=p_Brand[i][0];
				document.getElementById("BBrand").options.add(op);
			}
		}
	}
  
	function setType()//添加机型
	{
		var Brand=document.getElementById("BBrand").value;
		var Type=document.getElementById("TType");
		Type.length=0;
		var other=new Option("All models","null");
		other.title="OTHER";
		Type.options.add(other);
		for(var i=0 ;i<p_Brand.length;i++)
		{
		 	if(p_Brand[i][1]==Brand)
			{
				var Types= p_Brand[i][2];
				for(var j=0;j<Types.length;j++)
				{
					if(Types[j][3]>=minNum){
						var op=new Option(Types[j][0],Types[j][1]);
						op.title=Types[j][0];
						Type.options.add(op);
					}
				}
				break;
			}
		}
		
		setParts();
	}
	
	function setParts()//添加位置
	{
		var Brand=document.getElementById("BBrand").value;
		var Type=document.getElementById("TType").value;
		var Part=document.getElementById("PParts");
		Part.length=0;
		var parts=new Option("All locations","null");
		parts.title="PARTS";
		Part.options.add(parts);
		for(var i=0 ;i<p_Brand.length;i++)
		{
		    if(p_Brand[i][1]==Brand)
		    {
				var Types= p_Brand[i][2];
				for(var j=0;j<Types.length;j++)
				{
					if(Types[j][1]==Type)
					{
						var Parts=Types[j][2];
						
						for(var z=0;z<Parts.length;z++)
						{
							if(Parts[z][2]>=minNum){
								var op=new Option(Parts[z][0],Parts[z][1]);
								op.title=Parts[z][0];
								Part.options.add(op);
							}
						}
						break;
					}
				}
		     }
		}
		
	}
 
	function validate()
	{  
		var select4=document.getElementById("BBrand");
		var select=document.getElementById("TType");
		var select2=document.getElementById("PParts");
		var FNo=document.getElementById("FNo");
		if(select4.value=="null")
		{
			alert("Select brand！");
			return false;
		}
		else if(select.value=="null")
		{
			alert("Select Model！");
			return false;
		}
		else if(select2.value=="null")
		{
			alert("Select location！");
			return false;
		}
		else if(FNo.value=="enter the numbers or number plate accessories")
		{
			alert("Search keywords can not be empty, please enter keyword Accessories (accessories name, parts number or parts number plate) fuzzy search!");
			return false;
		}
		else
		{
		return true;
		}	
	}
	
	function addPart()
	{
		$.each(p_Brand,function(n,value) {
			if($(this)[4]<=0){
				return;
			}
			var app="";
			var Brand=$(this)[1];
        	app+="<li><span><img src='"+$(this)[3]+"' title='"+$(this)[0]+"' Brand='"+Brand+"'/></span><ul>";
			$.each($(this)[2],function(n,value) {
				var Type=$(this)[1];
				if($(this)[3]>=minNum){
					//app+="<li><a href='javascript:void(0);' Brand='"+Brand+"' Type='"+Type+"'>" + $(this)[0] + "</a></li>";  //old,But't IE 6 no run.
					app+="<li><a style='cursor:pointer;' Brand='"+Brand+"' Type='"+Type+"'>" + $(this)[0] + "</a></li>";					
				}
			});
			app+="</ul></li>";
			$(".content #PList").append(app);
        });
        $(".content #PList").find(">li").addClass("pp_z");
        $(".content #PList").find(">li>span").addClass("logo_pp");
        $(".content #PList").find(">li>ul").addClass("pp_list");
	}
	
	
	
