/*
 * plz include jquery
 * 
 */

$(document).ready(function(){
	
});//ready



//
function chartAct(tid, price, date, target)
{
	//alert(tid+' ) '+price+' ) '+date +' ) '+target);
	//alert(target+$("#tr_bp_l"+target).css());

	//if()
	//window.open($("#tr_bp"+target).html());
	
	$("tr[id^=tr_bp_l]").each(function(){
		$(this).hide();
	});
	$("tr[id^=tr_bp_s]").each(function(){
		$(this).show();
	});
	
	
	$("#tr_bp_l"+target).show();	
	$("#tr_bp_s"+target).hide();
	//alert($("#tr_bp"+target).html());
	
	//http://61.64.54.59:8080/test/pricetrend.jsp?t_id=T1271185535768_888&buyprice=1318&buydate=20100422
	//alert("http://61.64.54.59:8080/test/pricetrend.jsp?t_id="+tid+"&buyprice="+price+"&buydate="+date);
	
	//var url = "bprice_chart.php?t_id="+tid+"&buyprice="+price+"&buydate="+date;
	var url = "t_id="+tid+"&buyprice="+price+"&buydate="+date;
	//alert(url);
	
	//swfobject.embedSWF("open-flash-chart.swf", "chart", "514", "228", "9.0.0", "expressInstall.swf", {"data-file":url} );
	//
	//alert("http://61.64.54.59:8080/test/pricetrend.jsp?"+url);
	
	
	//alert($("#ifchart").attr("src"));
	if($("#_PATH").html()!='')
		$("#ifchart").attr("src", $("#_PATH").html()+"/flot.php?"+url);
	else
		$("#ifchart").attr("src", "flot.php?"+url);
	return;
	
	$.ajax({
		//url:"http://61.64.54.59:8080/test/pricetrend.jsp?t_id=T1271185335955_294&buyprice=2010&buydate=20100430",
		//url:"http://61.64.54.59:8080/test/pricetrend.jsp?"+url,
		url:"flot.php?t_id=T1271185543940_919&buyprice=2390&buydate=20100423",
		//url:"bprice_chart.php?t_id="+t_id+'&buyprice='+price+'&buydate='+date,
		type:"get",
		dataType:"html",
		cache:false,
		beforeSend:function(){
			$("#chart").html("<img src='images/loading_2.gif' /> Loading....");
		},		
		success: function(Jdata){
			$("#chart").html(Jdata);
			//
			
		},//success
		complete:function(){
			//type2Cname('c_type');
		},
		Error:function(){
			//alert('error');
		}
		
	});//.ajax
	

}


//
//get <span>5</span>
//repert <img star>*5
function repetStar(path)
{

	var cnt=0;	
	$("span[id^=star]").each(function(){
		cnt = parseInt($(this).html());
		
		if(cnt>0)$(this).html('');
		while(cnt > 0)
		{
			$(this).append('<img src="'+path+'images/star.gif" width="12" height="12" border="0" />');
			cnt--;
		}
		
		
	});

}//fun repetStar()


//
function getTag(mod)
{
	//
	//get>json default tag item
	if($("#sp_tagCom").html()!='')
	{
		eval('tagCom='+$("#sp_tagCom").html());
		
		
		//add default tag to input select
		$("select[name^=tag]").each(function(){
			for(var key in tagCom)
			{
				if($(this).text().search(tagCom[key]) < 0)
					$(this).append("<option value='"+key+"'>"+tagCom[key]+"</option>");
			}
		});
	}
	
	
	//
	//get>json (h_id)aggign tag item
	if($("#sp_tagHid").html()!='')
	{
		eval('tagHid='+$("#sp_tagHid").html());
		fillTag(mod);
	}


}//getTag



//
//if mod has value, don't reset it
function fillTag(mod)
{
	for(var hid in tagHid)
	{
		if(!mod)$('select[name=tag'+hid+'] option:selected').remove();
		for(var tag_id in tagHid[hid])
		{
			if($("select[name=tag"+hid+"]").text().search(tagHid[hid][tag_id]) < 0){
				$("select[name=tag"+hid+"]").prepend("<option value='"+tag_id+"'>"+tagHid[hid][tag_id]+"</option>");
			}
		}
		
		if(!mod)
		{
			$("select[name=tag"+hid+"]").prepend('<option value="null">請選擇</option>');
			$("select[name=tag"+hid+"] option[value='null']").attr("selected", true);
		}

	}
}//fillTag
//fillTag

