var MarketStatus=function(a){this.status="";
if(a){this.status=a.toUpperCase()
}};
Number.prototype.toChiUnit=function(d,b){if(!d){d=1
}var e=0;
var c="";
if(this<10000){e=this.toFixed(d).toString()
}else{if(this<100000000){e=(this/10000).toFixed(d).toString();
c="萬"
}else{e=(this/100000000).toFixed(d).toString();
c="億"
}}var a=e.split(".");
return new Number(a[0]).toCommasString()+"."+a[1]+((b)?b.replace("$1",c):c)
};
Number.prototype.toSymString=function(a){if(this>0){return"+"+this.toFixed(a).toString()
}return this.toFixed(a).toString()
};
Number.prototype.toPercentString=function(a){if(this>0){return"+"+this.toFixed(a).toString()+"%"
}else{if(isNaN(this)){return new Number(0).toFixed(a)+"%"
}}return this.toFixed(a).toString()+"%"
};
Number.prototype.toCommasString=function(e){var a=this.toFixed(e).toString().split(".");
var d=a[0];
var b=a.length>1?"."+a[1]:"";
var c=/(\d+)(\d{3})/;
while(c.test(d)){d=d.replace(c,"$1,$2")
}return d+b
};
MarketStatus.prototype.toString=function(){var a="";
switch(this.status){case"CT":a="開市中";
break;
case"CL":a="中午收市";
break;
case"DC":a="全日收市";
break
}return a
};
MarketStatus.prototype.isOpen=function(){return(this.status==="CT")
};
var M18={};
M18.marketStatus=new MarketStatus();
M18.path={append:function(d,g){var c=[];
var f=0;
var b=d.split("?");
var a=this.getQs(d);
for(var e in g){a[e]=g[e]
}for(var e in a){if(f!==0){c.push("&")
}c.push(e+"="+a[e]);
f++
}return b[0]+"?"+c.join("")
},get:function(c,a){var b="";
return this.append(c,{t:Math.random()})
},getQs:function(d){var f={};
var c=d.split("?");
if(c.length>1){var b=c[1].split("&");
for(var e=0;
e<b.length;
e++){var a=b[e].split("=");
if(a.length>1){f[a[0]]=decodeURIComponent(a[1])
}}}return f
},market:function(){return this.get("http://home.on.cc/js/index/MAIN_s.js")
},index:function(){return this.get("http://home.on.cc/js/index/HSI_r.js")
},index_HSCEI:function(){return this.get("http://home.on.cc/js/index/HSCEI_r.js")
}};
M18.loadScript=function(c,f,e){var d=document.getElementsByTagName("head")[0];
var b=document.createElement("script");
var a=false;
b.src=c;
b.charset="big5";
b.onload=b.onreadystatechange=function(){if(!a&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){a=true;
f(e);
b.onload=b.onreadystatechange=null;
d.removeChild(b)
}};
d.appendChild(b)
};
M18.indexWidget={index:-1,id:"#indexWidget",indexVal:null,changeVal:null,statusVal:null,content:null,firstLoad:true,init:function(){this.content=$(this.id);
if(this.content.length>0){this.indexVal=this.content.find("tr.index td.val");
this.statusVal=$("#market_status");
this.changeVal=this.content.find("tr.status td.val");
this.load(true);
this.loadStatus(true)
}},load:function(a){if(typeof M18.r_HSI==="undefined"||a===true){M18.loadScript(M18.path.index(),function(){M18.indexWidget.render()
})
}else{M18.indexWidget.render()
}},loadStatus:function(a){if(typeof M18.s_MAIN==="undefined"||a===true){M18.loadScript(M18.path.market(),function(){M18.indexWidget.updateStatus()
})
}else{M18.indexWidget.updateStatus()
}},render:function(){if(M18.r_HSI){if(this.index.toFixed(2)!=new Number(M18.r_HSI.value).toFixed(2)){this.index=new Number(M18.r_HSI.value);
if(this.firstLoad===false){this.indexVal.addClass("highlight");
this.changeVal.addClass("highlight")
}this.firstLoad=false;
this.content.removeClass("up").removeClass("down");
var a=new Number(M18.r_HSI.difference);
if(a>0){this.content.addClass("up")
}else{if(a<0){this.content.addClass("down")
}}this.indexVal.html(this.index.toCommasString(2));
this.changeVal.html(a.toSymString(2)+' <span class="percent">('+((a/(this.index-a))*100).toPercentString(2)+")</span>");
setTimeout(function(){M18.indexWidget.clearHighLight()
},500)
}}if(M18.marketStatus.isOpen()){setTimeout(function(){M18.indexWidget.load(true)
},10000)
}},updateStatus:function(){var a=M18.marketStatus.isOpen();
M18.marketStatus.status=M18.s_MAIN;
if(typeof M18.r_HSI.turnover!="undefined"){this.statusVal.html("&nbsp;"+M18.marketStatus+"&nbsp;&nbsp;&nbsp;大市成交&nbsp;"+new Number(M18.r_HSI.turnover).toChiUnit(2))
}setTimeout(function(){M18.indexWidget.loadStatus(true)
},10000);
if(a==false&&a!=M18.marketStatus.isOpen()){this.render()
}},clearHighLight:function(){this.indexVal.removeClass("highlight");
this.changeVal.removeClass("highlight")
}};
M18.indexWidget_HSCEI={index:-1,id:"#indexWidget_HSCEI",indexVal:null,changeVal:null,statusVal:null,content:null,firstLoad:true,init:function(){this.content=$(this.id);
if(this.content.length>0){this.indexVal=this.content.find("tr.index td.val");
this.statusVal=this.content.find("tr.status td.label");
this.changeVal=this.content.find("tr.status td.val");
this.load(true)
}},load:function(a){if(typeof M18.r_HSCEI==="undefined"||a===true){M18.loadScript(M18.path.index_HSCEI(),function(){M18.indexWidget_HSCEI.render()
})
}else{M18.indexWidget_HSCEI.render()
}},loadStatus:function(a){if(typeof M18.s_MAIN==="undefined"||a===true){M18.loadScript(M18.path.market(),function(){M18.indexWidget_HSCEI.updateStatus()
})
}else{M18.indexWidget_HSCEI.updateStatus()
}},render:function(){if(M18.r_HSCEI){if(this.index.toFixed(2)!=new Number(M18.r_HSCEI.value).toFixed(2)){this.index=new Number(M18.r_HSCEI.value);
if(this.firstLoad===false){this.indexVal.addClass("highlight");
this.changeVal.addClass("highlight")
}this.firstLoad=false;
this.content.removeClass("up").removeClass("down");
var a=new Number(M18.r_HSCEI.difference);
if(a>0){this.content.addClass("up")
}else{if(a<0){this.content.addClass("down")
}}this.indexVal.html(this.index.toCommasString(2));
this.changeVal.html(a.toSymString(2)+' <span class="percent">('+((a/(this.index-a))*100).toPercentString(2)+")</span>");
setTimeout(function(){M18.indexWidget_HSCEI.clearHighLight()
},500)
}}if(M18.marketStatus.isOpen()){setTimeout(function(){M18.indexWidget_HSCEI.load(true)
},10000)
}},updateStatus:function(){var a=M18.marketStatus.isOpen();
M18.marketStatus.status=M18.s_MAIN;
this.statusVal.html("&nbsp;"+M18.marketStatus+"&nbsp;");
setTimeout(function(){M18.indexWidget_HSCEI.loadStatus(true)
},10000);
if(a==false&&a!=M18.marketStatus.isOpen()){this.render()
}},clearHighLight:function(){this.indexVal.removeClass("highlight");
this.changeVal.removeClass("highlight")
}};
