function PriceNode()
{
	this.fcode=null;
	this.tcode=null;
	this.from=null;
	this.price=null;
	this.date=null;
	this.fdate=null;
}

/**
  *数组PriceNode元素比较函数
  *
  */
function CompPriceNode(nodeA,nodeB)
{
	
	return( parseInt(nodeA.price) - parseInt(nodeB.price) );

}

var PriceList = new Array();
function WritePrice(frm)//主函数
{
	var xml=new CXml(frm.document.XMLDocument?frm.document.XMLDocument:'');
	var nodes=xml.GetNodes("record");
	var tPriceTop = document.getElementById("price_top");
	var tPriceBotomR = document.getElementById("price_botom_R");
	var tPriceBotomL = document.getElementById("price_botom_L");
	
	for(i=0;i<nodes.length;i++)
	{
		//屏蔽超过3个汉字的城市
		if( xml.GetChildValue(nodes[i], "from").length >3 || xml.GetChildValue(nodes[i], "to").length >3 )
		{
		    continue;
		}
		
		m_priceNode = new PriceNode();
		m_priceNode.fcode = xml.GetChildValue(nodes[i], "fcode");
		m_priceNode.tcode = xml.GetChildValue(nodes[i], "tcode");
		m_priceNode.from = xml.GetChildValue(nodes[i], "from");
		m_priceNode.to = xml.GetChildValue(nodes[i], "to");
		m_priceNode.price = xml.GetChildValue(nodes[i], "price");
		
		var ddate,tmp;
		tmp = xml.GetChildValue(nodes[i], "date");
		if(parseInt(tmp.substr(4,2)) > 9)
			ddate = tmp.substr(4,2)+"月"+tmp.substr(6,2)+"日";
		else
			ddate = "&nbsp;"+tmp.substr(5,1)+"月"+tmp.substr(6,2)+"日";
		
		m_priceNode.date = ddate;
		m_priceNode.fdate = tmp;
		
		PriceList.push(m_priceNode);
	}
	
	//PriceList.sort(CompPriceNode);
	
	var tFirstIndex=0;
	var tEndIndex=4;
	ClearTable(tPriceTop);
	WritePriceTop(tPriceTop,tFirstIndex,tEndIndex);
	
	tFirstIndex += 4;
	tEndIndex += 5;
	ClearTable(tPriceBotomR);
	WritePriceBotom(tPriceBotomR,tFirstIndex,tEndIndex);

	tFirstIndex += 5;
	tEndIndex += 5;
	ClearTable(tPriceBotomL);
	WritePriceBotom(tPriceBotomL,tFirstIndex,tEndIndex);
}

function WritePriceBotom(tb,tFirst,tEnd)
{
	for(i=tFirst;i<tEnd;i++)
	{
		tr=tb.insertRow(-1);
		td=tr.insertCell(-1);
		td.width="106";
		td.innerHTML="·<a href=\"http://qq.csair.com/query_result.shtml?from="+PriceList[i].fcode+"&to="+PriceList[i].tcode+"&back_radio=1&fromcity="+PriceList[i].from+"&tocity="+PriceList[i].to+"&date="+PriceList[i].fdate+"\">"+PriceList[i].from+"-"+PriceList[i].to+"</a>";
		
		td=tr.insertCell(-1);
		td.width="56";
		td.innerHTML=PriceList[i].date;
		
		td=tr.insertCell(-1);
		td.width="47";
		td.innerHTML="<span class=\"red\">"+PriceList[i].price+"元起</span> ";
	}
}

function WritePriceTop(tb,tFirst,tEnd)
{
	tr = tb.insertRow(-1);
	for(i=tFirst;i<tEnd;i++)
	{
		td = tr.insertCell(-1);
		if( i==0 )
		{
			td.width="28%";
		}
		else 
		{
			td.width="24%";
		}
		td.height="97";
		td.vAlign="top";
		td.innerHTML="<table width=\"84\" height=\"34\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"34\" align=\"center\" valign=\"bottom\"><span class=\"whirt\">"+PriceList[i].from+"--"+PriceList[i].to+"</span></td></tr></table><table width=\"67\" height=\"31\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"51\" height=\"31\" valign=\"top\"><span class=\"size37\">"+PriceList[i].price+"</span><span class=\"whirt\">&nbsp;元</span></td></tr></table>"
	}
}


function ClearTable(tb)
{
	var tRows = tb.rows;
	while( tRows.length!=0 )
	{
		tb.deleteRow(0);
	}
}