﻿/*** 车型查询器 ***/
var CarModels = function()
{
	var base = this;
	
	base.xml = null;
	
	//加载车型数据
	//path: 数据地址
	base.load = function(path)
	{
		if(!AjaxRequest)
		{
			alert("javascript not found: Ajax!");
			return;
		}
		var ajax = new AjaxRequest();
		ajax.url = path;
		ajax.method = "get";
		ajax.onComplete = function(obj)
		{
			base.xml = obj.xml;
			base.onloadComplete();
		}
		ajax.open();
	}
	
	//车型数据完成加载
	base.onloadComplete = function()
	{
	}
	
	/*** 获取指定品牌 ***/
	// id: 品牌编号
	base.getBrand = function(id)
	{
		return base.xml.selectSingleNode("/xmldata/allitems/brand[id='" + id + "']");
	}
	
	/*** 获取指定系列 ***/
	// id: 系列编号
	base.getSerial = function(id)
	{
		return base.xml.selectSingleNode("/xmldata/allitems/brand/serial[id='" + id + "']");
	}
	
	// 获取指定车型
	// id: 车型编号
	base.getModel = function(id)
	{
		return base.xml.selectSingleNode("/xmldata/allitems/brand/serial/model[id='" + id + "']");
	}
	
	// 获取指定车型
	// id: 车型编号
	base.getModelById = function(brand,serial,model)
	{
		return base.xml.selectSingleNode("/xmldata/allitems/brand[id='" + brand + "']/serial[id='" + serial + "']/model[id='" + model + "']");
	}
	
	/*** 获取所有品牌 ***/
	base.getBrands = function()
	{
		return base.xml.selectNodes("/xmldata/allitems/brand");
	}
	
	/*** 获取指定品牌的所有系列 ***/
	base.getSerialsById = function(id)
	{
		return base.xml.selectNodes("/xmldata/allitems/brand[id='" + id + "']/serial");
	}
	
	// 获取指定品牌的所有系列
	
	base.getSerialsByName = function(name)
	{
		return base.xml.selectNodes("/xmldata/allitems/brand[name='" + name + "']/serial");
	}
	
	//获取指定系列的所有车型
	//id: 系列编号
	base.getModels = function(id)
	{
		return base.xml.selectNodes("/xmldata/allitems/brand/serial[id='" + id + "']/model");
	}
	
	//获取指定系列的所有车型
	//brand: 品牌名称
	//serial: 系列名称
	base.getModelsById = function(brand, serial)
	{
		return base.xml.selectNodes("/xmldata/allitems/brand[id='" + brand + "']/serial[id='" + serial + "']/model");
	}
	
}
