function set_type(type)
{
	$("price_type").value=type;	
}
function update_list()
{
	setTimeout("update_list()",5000); 
	if($F("price_type")==1)
	{
		var url='/price/direct_price_json.php';	
	}
	if($F("price_type")==2)
	{
		var url='/price/indirect_price_json.php';	
	}
	if($F("price_type")==3)
	{
		var url='/price/indexs_price_json.php';	
	}
	GetPriceInfo(url);

}
function GetPriceInfo(url)
{
	var newdate=new Date();
	newtime=newdate.getTime();
	var rel='';
	url=url+"?timestamp="+newtime;
	var myAjax = new Ajax.Request(url,{method:'get',parameters:rel,onComplete: CallBack_price});
	myAjax=null;
	CollectGarbage();
}
function CallBack_price(xmlhttp)
{
	var result=xmlhttp.responseText;
	var price_array=result.evalJSON()
	if($F("price_type")==1)
	{
		var direct_curr_list=$F("direct_curr_list");
		var curr_array=direct_curr_list.split(" ");	
	}
	if($F("price_type")==2)
	{
		var indirect_curr_list=$F("indirect_curr_list");
		var curr_array=indirect_curr_list.split(" ");	
	}
	if($F("price_type")==3)
	{
		var indexs_list=$F("indexs_list");
		var curr_array=indexs_list.split(" ");	
	}
	for(i=0;i<curr_array.length;i++)
	{
		var point=$(curr_array[i]+"_close").innerHTML-parseFloat(price_array[curr_array[i]]["close"]);
		if(point>0)
		{
			$('tr_'+curr_array[i]).style.color='red';	
			var imgsrc="<img src='/images/yx.png' border='0'/>";
			$(curr_array[i]+"_img").innerHTML=imgsrc;
			
		}
		else if(point<0)
		{
			$('tr_'+curr_array[i]).style.color='blue';	
			var imgsrc="<img src='/images/ys.png' border='0'/>";
			$(curr_array[i]+"_img").innerHTML=imgsrc;
		}
		else if(point==0)
		{
			$('tr_'+curr_array[i]).style.color='black';	
			var imgsrc="<img src='/images/yz.png' border='0'/>";
			$(curr_array[i]+"_img").innerHTML=imgsrc;
		}
		$(curr_array[i]+"_close").innerHTML=parseFloat(price_array[curr_array[i]]["close"]).toFixed(get_code_bit(curr_array[i]));
		$(curr_array[i]+"_high").innerHTML=parseFloat(price_array[curr_array[i]]["high"]).toFixed(get_code_bit(curr_array[i]));
		$(curr_array[i]+"_low").innerHTML=parseFloat(price_array[curr_array[i]]["low"]).toFixed(get_code_bit(curr_array[i]));
		var rate =((parseFloat(price_array[curr_array[i]]["close"])-parseFloat(price_array[curr_array[i]]["open"]))/parseFloat(price_array[curr_array[i]]["open"]))*100;
		$(curr_array[i]+"_rate").innerHTML=rate.toFixed(2)+"%";
	}
	xmlhttp=null;
	CollectGarbage();
	
}

function get_price()
{
	setTimeout("get_price()",2000); 
	var currency=$F("price_currency");
	var newdate=new Date();
	newtime=newdate.getTime();
	var url="/price_data/"+currency+".PHP?timestamp="+newtime;
	var rel='';
	var myAjax = new Ajax.Request(url,{method:'get',parameters:rel,onComplete: CallBack_price_curr});
	myAjax=null;
	CollectGarbage();
}

function CallBack_price_curr(xmlhttp)
{
	var result=xmlhttp.responseText;
	var price_array=result.evalJSON()
	var str=price_array["code"];
	str+=" &nbsp;当前报价："+parseFloat(price_array["close"]).toFixed(get_code_bit(price_array["code"]));
	str+=" 报价时间："+price_array["lasttime"];
	str+=" 日高点："+parseFloat(price_array["high"]).toFixed(get_code_bit(price_array["code"]));
	str+=" 日低点："+parseFloat(price_array["low"]).toFixed(get_code_bit(price_array["code"]));
	str+=" 日波幅："+price_array["point"]+"%";
	$("price_detail").innerHTML=str;	
}



function reload_price_60()
{
	var currency=$F("price_currency_60");
	var period=$F("period_60");
	var data="/chart/"+currency+"__"+period+".php";
	//alert(currency+period);
	//reload(escape(data),"flashcontent_60");
	creat_chart(currency,period,"flashcontent_60",40);
}

function reload_price_1440()
{
	var currency=$F("price_currency_1440");
	var period=$F("period_1440");
	var data="/chart/"+currency+"__"+period+".php";
	//reload(escape(data),"flashcontent_1440");
	creat_chart(currency,period,"flashcontent_1440",40);
}

function reload_price_5()
{
	var currency=$F("price_currency_5");
	var period=$F("period_5");
	var data="/chart/"+currency+"__"+period+"__L.php";
	//reload(escape(data),"flashcontent_5");
	creat_chart(currency,period,"flashcontent_5",80);
}
function reload_price_50()
{
	var currency=$F("price_currency_50");
	var period=$F("period_50");
	var data="/chart/"+currency+"__"+period+".php";
	reload(escape(data),"flashcontent_50");
}
function reload_price_1()
{
	var currency=$F("price_currency_1");
	var period=$F("period_1");
	var data="/chart/"+currency+"__"+period+".php";
	reload(escape(data),"flashcontent_1");
}


function reload(data,flashcontent)
{
	var so = new SWFObject("chart/chart.swf", "chart", "100%", "100%", "9", "#FFFFFF");
	var newdate=new Date();
	newtime=newdate.getTime();
	so.addVariable("data","http://61.152.245.51"+data+"?time="+newtime);
	so.addParam("allowScriptAccess", "sameDomain");
	so.addParam("wmode", "transparent");
	so.write(flashcontent);
}
function set_value(obj,str)
{
	for(i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value==str)
			obj.options[i].selected=true;
	}
}
function changecurr(curr)
{
	if(curr=="GOLD")
	{
		location.href='../gold.php';
		return;
	}
	$("price_currency").value=curr;
	get_news(curr,1);
	get_techs(curr);
	set_value($("price_currency_60"),curr);
	set_value($("price_currency_1440"),curr);
	set_value($("price_currency_5"),curr);
	reload_price_60();
	reload_price_1440();
	reload_price_5();
}


function gourl(str)
{
	if(str=='GOLD')
	{
		location.href='gold.php';
		return;
	}
	location.href='price/price.php?curr='+str;
}
function get_news(currency,to_page)
{
	var url='news_list.php';
	var rel='currency='+currency+"&to_page="+to_page;
	var myAjax = new Ajax.Request(url,{parameters:rel,onComplete: CallBack_get_news});
	$("news_list").innerHTML="<center>正在加载数据,请稍后...</center>";
}

function get_price_list()
{
	var rel='';
	var url='price_all_list.php';
	var myAjax = new Ajax.Request(url,{parameters:rel,onComplete: CallBack_get_price_list});
	$("news_list").innerHTML="正在加载数据,请稍后...";
}
function get_techs(currency)
{
	var url='techs_list.php';
	var rel='currency='+currency;
	var myAjax = new Ajax.Request(url,{parameters:rel,onComplete: CallBack_get_techs});
	$("techs_list").innerHTML="正在加载数据,请稍后...";	
}

function CallBack_get_news(xmlhttp)
{
	var result=xmlhttp.responseText;
	$("news_list").innerHTML=result;
}
function CallBack_get_techs(xmlhttp)
{
	var result=xmlhttp.responseText;
	$("techs_list").innerHTML=result;
}
function CallBack_get_price_list(xmlhttp)
{
	var result=xmlhttp.responseText;
	$("news_list").innerHTML=result;
}

function get_code_bit(str)
{
	var decimals;
	switch(str)
	{
		case 'EURUSD':	decimals=4;	break;
		case 'EURGBP':	decimals=4;	break;
		case 'EURJPY':	decimals=2;	break;
		case 'EURCHF':	decimals=4;	break;
		case 'USDJPY':	decimals=2;	break;
		case 'USDCHF':	decimals=4;	break;
		case 'USDCAD':	decimals=4;	break;
		case 'GBPUSD':	decimals=4;	break;
		case 'GBPJPY':	decimals=2;	break;
		case 'GBPCAD':	decimals=4;	break;
		case 'GBPCHF':	decimals=4;	break;
		case 'AUDUSD':	decimals=4;	break;
		case 'AUDJPY':	decimals=2;	break;
		case 'USD_INDEX':	decimals=2;	break;
		case 'GOLD':	decimals=2;	break;
		case 'SPT_SVR':	decimals=2;	break;
		case 'OIL':	decimals=2;	break;
		case 'SPT_SPI':	decimals=2;	break;
		case 'HSI':		decimals=0;	break;
		case 'NZDUSD':	decimals=4;	break;
		case 'NZDJPY':	decimals=2;	break;
		case 'NZDCHF':	decimals=4;	break;
		case 'NZDCAD':	decimals=4;	break;
		case 'EURCAD':	decimals=4;	break;
		case 'EURAUD':	decimals=4;	break;
		case 'GBPNZD':	decimals=4;	break;
		case 'AUDCAD':	decimals=4;	break;
		case 'AUDNZD':	decimals=4;	break;
		case 'CHFJPY':	decimals=2;	break;
		case 'CADJPY':	decimals=2;	break;
		case 'DAX':		decimals=2;	break;
		case 'DJI':		decimals=1;	break;
		case 'NASDAQ':	decimals=2;	break;
	}
	return decimals;
}

