
//Constructor
var JRouteDB=function()
{
	//Field
	this.routes=new Array();
	//Method
	this.reset=JRouteDB_reset;
	this.getRoute=JRouteDB_getRoute;
	this.loadRoute=JRouteDB_loadRoute;
}

function JRouteDB_reset()
{
	this.routes=new Array();
}

function JRouteDB_getRoute(id,map)
{
	// loop to find the route
	for(var i=0;i<this.routes.length;i++)
	{
		var route=this.routes[i];
		if(g_isNull(route))
			continue;
		if(route.id==id)
		{
			return route;
		}
	}
	
	// if not find , load the route
	return this.loadRoute(id,map);
}

function JRouteDB_loadRoute(id,map)
{
	var xmlreader=new ActiveXObject("Microsoft.XMLDOM");
	var xmlreader2=new ActiveXObject("Microsoft.XMLDOM");
	var url="RouteDataQuery.aspx?action=getroute&param="+id.toString();

	xmlreader.async=false;
	xmlreader.load(url);
	
	var routeXml;
	// get the xml data 
	var infoNode=xmlreader.selectSingleNode('result/info');
	
	var contentNode=xmlreader.selectSingleNode('result/content/route');
	routeXml=contentNode.xml;
	// creaet the route
	var route=new JRoute();
	route.fromXml(xmlreader2,routeXml,map);
	route.id=infoNode.getAttribute("id");
	this.routes[this.routes.length]=route;
	return route;
}
