if(typeof $=="undefined"){$=function(A){return document.getElementById(A)}}if(typeof $C=="undefined"){$C=function(A){return document.createElement(A)}}Function.prototype.Bind=function(){var D=this,B=arguments[0],A=new Array();for(var C=1;C<arguments.length;C++){A.push(arguments[C])}return function(){return D.apply(B,A)}};Function.prototype.BindForEvent=function(){var D=this,B=arguments[0],A=new Array();for(var C=1;C<arguments.length;C++){A.push(arguments[C])}return function(E){return D.apply(B,[(E||window.event)].concat(A))}};function setCookie(B,D,C){if(C){var A=new Date();A.setTime(A.getTime()+C*24*3600*1000);document.cookie=B+"="+encodeURI(D)+"; expires="+A.toGMTString()}else{document.cookie=B+"="+encodeURI(D)+";"}}var isIE=false;var userAgent=navigator.userAgent.toLowerCase();if((userAgent.indexOf("msie")!=-1)&&(userAgent.indexOf("opera")==-1)){isIE=true}function getCookie(B){var A=document.cookie.match(new RegExp(B+"=([^;]*)"));return A!=null?decodeURI(A[1]):null}var TotalCtrl={opts:{},_oCode:{},_hqItv:{},_aImg:[],_aStatus:[],_sinaJs:"http://hq.sinajs.cn/?list=",_textMdl:'<ul@CL@><li>@T@</li><li>@R@</li><li>@CG@</li><li>@P@</li><li class="name" title="@NAME@">@NAME@</li></ul>',_sThreadId:"_s_@J@_@TIME@",_thdNum:0,_html1:'<dl>			<dt><div><span>@COUNTRY@</span></div></dt>			<dd class="title"><div><ul><li>行情时间</li><li>涨跌幅</li><li>涨跌额</li><li>最新价</li><li class="name">指数名称</li></ul></div><label>关注</label></dd>			@DDS@		</dl>',_html2:'<dd><div id="hq_@CODE@"><span class="loading">读取中...请稍候</span></div><label><input type="checkbox" id="ck_@CODE@" /></label></dd>',Init:function(){var B=0;var K=this._sThreadId.replace("@J@",B);for(var E in this.opts){var H="";for(var D in this.opts[E]){var J="";for(var C in this.opts[E][D]){J+=this._html2.replace(/@CODE@/g,C);var L=C;var I=this.opts[E][D][C];var A=!I.interval?300000:I.interval;var F=K.replace("@TIME@",A);if(this._oCode[F]){this._oCode[F].push(L)}else{this._oCode[F]=[L]}B++;if(B%40==0){K=this._sThreadId.replace("@J@",B)}}var G=this._html1.replace("@COUNTRY@",D).replace("@DDS@",J);H+=G}$(E+"_col").innerHTML=H}this._hqCtrl()},_drawInit:function(){alert("")},_hqCtrl:function(){for(var B in this._oCode){var A=parseInt(B.replace(/_s_\d*_/,""));this._loadHq(this._oCode[B]);this._hqItv[B]=window.setInterval(this._loadHq.Bind(this,this._oCode[B]),A)}},_loadHq:function(B){var A=new IO.Script();A.load(this._sinaJs+B.join(","),this._filltext.Bind(this,B))},_checkThread:function(){if(this._thdNum!=this._oCode.length){return }else{this._thdNum=0;alert("ok");return }},_filltext:function(D){for(var B=0;B<D.length;B++){var C=window["hq_str_"+D[B]].split(",");var A=this._textMdl.replace("@P@",C[1]).replace(/@NAME@/g,C[0]).replace("@CG@",this._plus(C[2])).replace("@R@",this._plus(C[3])+"%").replace("@T@",this._parseTime(C[4]));$("hq_"+D[B]).innerHTML=this._colorize(A,C[2])}},_plus:function(A){return A>0?"+"+A:A},_colorize:function(B,A){if(A>0){return B.replace("@CL@",' class="up"')}else{if(A<0){return B.replace("@CL@",' class="down"')}}return B.replace("@CL@","")},_parseTime:function(A){if(/:/.test(A)){var B=A.split(":");var __TIME_USTOCN_ABS=Math.abs(getGlobalTimezone("US"));B[0]=B[0]*1+__TIME_USTOCN_ABS>=23?B[0]*1+__TIME_USTOCN_ABS-24:B[0]*1+__TIME_USTOCN_ABS;return B.join(":")}else{return A}}};var ColorCtrl={_globalIndexColor_CookieName:"gic",Init:function(){this._us_radio=$("us_pattern");this._cn_radio=$("cn_pattern");this._wrap=$("wrap");this._us_radio.onclick=this._setClass.Bind(this,"wrap","u");this._cn_radio.onclick=this._setClass.Bind(this,"wrap cnIndex","c");this._setDefault()},_setDefault:function(){var A=getCookie(this._globalIndexColor_CookieName);if(A=="c"){this._cn_radio.checked="checked";this._setClass("wrap cnIndex")}else{this._us_radio.checked="checked";this._setClass("wrap")}},_setClass:function(B,A){this._wrap.className=B;if(A){setCookie(this._globalIndexColor_CookieName,A,30)}}};function initCheckbox(){var A="GI_MY";var D=getCookie(A);D=D==null?"":[",",D,","].join("");var E=document.getElementsByTagName("input");for(var C=0;C<E.length;C++){if(E[C].type.toLowerCase()=="checkbox"&&/^ck_.*/.test(E[C].id)){var B=E[C];B.checked=(D.indexOf([",",B.id.replace(/^ck_/,""),","].join(""))!=-1);B.onclick=function(){var F="GI_MY";var H=getCookie(F);H=H==null?"":[",",H,","].join("");var G=this.id.replace(/^ck_/,"");if(this.checked){if(H.split(",").length>=100+2){alert("添加失败，自选指数数量不能超过100。")}else{if(H.indexOf([",",G,","].join(""))==-1){setCookie(F,[H,G].join("").replace(/^,/,""),30);alert("添加成功，请于自选股指中查看。")}else{alert("添加失败，该项已存在。")}}}else{if(H.indexOf([",",G,","].join(""))==-1){alert("删除失败，该项不存在。")}else{setCookie(F,H.replace([",",G,","].join(""),",").replace(/^,/,"").replace(/,$/,""),30);alert("删除成功。")}}}}}}function main(){ColorCtrl.Init();TotalCtrl.Init();initCheckbox()};