function ready(a){if(/(?!.*?compatible|.*?webkit)^mozilla|opera/i.test(navigator.userAgent)){document.addEventListener("DOMContentLoaded",a,false)}else{window.setTimeout(a,0)}}function importJs(c,f,e){var d=document.getElementsByTagName("head")[0]||document.documentElement;var b=document.createElement("script");b.src=c;b.type="text/javascript";var a=false;b.onload=b.onreadystatechange=function(){if(!a&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){a=true;if(typeof(f)=="function"){f(e)}d.removeChild(this)}};d.insertBefore(b,d.firstChild)}var js={get:function(a){return(typeof(a)=="string")?document.getElementById(a):a},elem:function(a){return this.get(a)?new this._elemClass(this,a):null},getByClass:function(a){return this.find(document.body,"*",a)},isDefined:function(a){return typeof(a)!="undefined"},isArray:function(a){return a.constructor==Array},isFunction:function(a){return typeof(a)=="function"},msie:(function(){var a=navigator.userAgent.toLowerCase();return/msie/.test(a)&&!/opera/.test(a)})(),trim:function(a){return a.replace(/(^\s*)|(\s*$)/g,"")},format:function(b){var b=arguments[0];for(var a=1;a<arguments.length;a++){b=b.replace(new RegExp("\\{"+(a-1)+"\\}","gm"),arguments[a])}return b},find:function(a,k,g,j,e){var b=new Array();var f=this.get(a).getElementsByTagName(k||"*");for(var d=0;d<f.length;d++){var h=this.elem(f[d]);if(g&&(h.object.className!=g&&!h.object.className.match(new RegExp("(^|\\s)"+g+"(\\s|$)")))){continue}if(j&&!e&&!h.attr(j)){continue}if(j&&e&&h.attr(j)!=e){continue}b.push(h.object)}return b},_elemClass:function(b,a){this.object=b.get(a);this.hide=function(){this.object.style.display="none";return this};this.show=function(){this.object.style.display="";return this};this.html=function(c){return b.isDefined(c)?(this.object.innerHTML=c,this):this.object.innerHTML};this.val=function(c){return b.isDefined(c)?(this.object.value=c,this):this.object.value};this.check=function(c){return b.isDefined(c)?(this.object.checked=c,this):this.object.checked};this.sel=function(c){return b.isDefined(c)?(this.object.selectIndex=c,this):(this.object.selectIndex==-1?null:this.object.options[this.object.selectIndex])};this.attr=function(c,d){return b.isDefined(d)?(this.object.setAttribute(c,d),this):this.object.getAttribute(c)};this.css=function(c,d){return b.isDefined(d)?(this.object.style[c]=d,this):this.object.style[c]};this.className=function(c){return b.isDefined(c)?(this.object.className=c,this):this.object.className};this.find=function(c,e,d,f){return b.find(this.object,c,e,d,f)}}};var quote_ex={init:function(a){window.QuoteData={};QuoteData.show_quote=function(){quote_ex._quoteLoadCallback()};if(!a){a={}}this.timeout=a.timeout||6000;this.add(a.codes);this.defaultCode=a.defaultCode;this.fixedNum=a.fixedNum||2;this.quoteMark=a.quoteMark||"_quote_";this.util.cRed=a.red||"cRed";this.util.cGreen=a.green||"cGreen";this.refresh(a.autoAdd);this.init=function(){}},onQuoteLoading:null,onQuoteLoaded:null,onQuoteProcessing:null,onQuoteProcessed:null,onPageRender:null,onElementRender:null,_codes:null,defaultCode:null,timeout:null,timer:null,quoteMark:null,fixedNum:2,hkFixedNum:3,codeMap:{},quoteElementsMap:null,quoteDataMap:{},refresh:function(a){this._fillQuoteElemenetsMap();if(a!=false){this.addAll()}},_fillQuoteElemenetsMap:function(){var f=js.find(document.body,null,null,this.quoteMark,null);this.quoteElementsMap={};if(!f){return}for(var b=0;b<f.length;b++){var e=js.elem(f[b]);var d=e.attr("code")||this.defaultCode;if(!d){continue}var c=e.attr(this.quoteMark);if(!c){continue}var g=this.quoteElementsMap[d]||(this.quoteElementsMap[d]={});if(g[c]){if(!js.isArray(g[c])){var a=g[c];g[c]=[a]}g[c].push(f[b])}else{g[c]=f[b]}}},addAll:function(){this.clear();for(var a in this.quoteElementsMap){this.codeMap[a]=true}},add:function(c){if(!c){return}var a=js.isArray(c)?c:c.split(",");for(var b=0;b<a.length;b++){this.codeMap[a[b]]=true}this._codes=null},remove:function(c){if(!c){return}var a=js.isArray(c)?c:c.split(",");for(var b=0;b<a.length;b++){if(!this.codeMap[a[b]]){continue}this.codeMap[a[b]]=false}this._codes=null},clear:function(){this.codeMap={};this._codes=null},getCodes:function(){if(!this._codes){this._codes=[];for(var a in this.codeMap){if(this.codeMap[a]){this._codes.push(a)}}}return this._codes},_fillQuoteDataMap:function(){this.eachCode(function(code){try{var isHK=code.substring(0,1)=="h";var quoteStr=isHK?eval("quote_hk_"+code.substring(1)):eval("quote_"+code);if(!quoteStr){return}var quoteData=quote_ex.quoteDataMap[code]||(quote_ex.quoteDataMap[code]={});if(isHK){quote_ex._fillHKQuoteData(quoteData,quoteStr)}else{quote_ex._fillQuoteData(quoteData,quoteStr)}}catch(ex){}})},_fillHKQuoteData:function(i,f){var b=i;b.isHK=true;var j=f.split(";");if(j.length<24){return null}if(js.isFunction(this.onQuoteProcessing)){this.onQuoteProcessing(j,i,f)}b.quotestring=f;var c=j[0];var h=3;b.code="h"+c;b.shortcode=j[0];b.name=decodeURI(j[1]);b.variable=(j[3]*1);b.percentnum=(j[4]*1);b.previousclose=(j[5]*1);b.openprice=(j[6]*1);b.todayhigh=(j[7]*1);b.todaylow=(j[8]*1);b.bid=(j[9]*1).toFixed(h);b.ask=(j[10]*1).toFixed(h);b.yearhigh=(j[11]*1).toFixed(h);b.yearlow=(j[12]*1).toFixed(h);b.sharevolume=(j[13]*1);b.shareamount1=(j[14]*1);b.pe=(j[15]*1).toFixed(h);b.yield=(j[16]*1).toFixed(h);b.lotSize=j[17];b.eps=j[18];b.marketCapital=j[19];b.suspension=j[20];b.time=j[21];b.datetimee=j[22];b.flag=j[23];b.percent=b.percentnum.toFixed(h)+"%";var e=parseFloat(j[2]);var g=b.price;if(!g){g=e}b.price=e;var d=e-g;if(e==0){b.updown=0;d=0}b.arrow=d>0?"\u2191":(d<0?"\u2193":"\u3000");b.trend=d;b.updownarrow=b.variable>0?"\u2191":(b.variable<0?"\u2193":"\u3000");if(js.isFunction(this.onQuoteProcessed)){this.onQuoteProcessed(j,i,f)}},_fillQuoteData:function(l,g){var b=l;b.isHK=false;var m=g.split(";");if(m.length<33){return null}if(js.isFunction(this.onQuoteProcessing)){this.onQuoteProcessing(m,l,g)}b.quotestring=g;var c=m[0];var k=this.fixedNum;var f=(m[10]*1);var i=Number(m[2]);if(f==0){f=i}b.code=m[0];b.shortcode=m[0].substring(1);b.name=m[1];b.previousclose=i;b.openprice=(m[3]*1);b.shareamount=(m[4]/10000).toFixed(0);b.shareamount1=(m[4]/100000000).toFixed(0);b.sharevolume=(m[5]/100).toFixed(0);b.sharevolume1=(m[5]/10000).toFixed(0);if(c=="0000001"||c=="0000100"){b.sharevolume=(m[5]/1).toFixed(0);b.sharevolume1=(m[5]/10000).toFixed(0);if((b.shareamount*1)>100000000){b.shareamount=(m[4]/10000/10).toFixed(0);b.shareamount1=(m[4]/100000000/10).toFixed(0)}}else{b.sharevolume=(m[5]/100).toFixed(0);b.sharevolume1=(m[5]/1000000).toFixed(0)}b.sharecount=(m[6]*1).toFixed(0);b.updown=(m[7]*1);b.todayhigh=(m[8]*1);b.todaylow=(m[9]*1);b.pe=(m[11]*1);b.buyprice1=(m[12]*1).toFixed(k);b.buycount1=(m[13]/100).toFixed(0);b.buyprice2=(m[14]*1).toFixed(k);b.buycount2=(m[15]/100).toFixed(0);b.buyprice3=(m[16]*1).toFixed(k);b.buycount3=(m[17]/100).toFixed(0);b.buyprice4=(m[18]*1).toFixed(k);b.buycount4=(m[19]/100).toFixed(0);b.buyprice5=(m[20]*1).toFixed(k);b.buycount5=(m[21]/100).toFixed(0);b.sellprice1=(m[22]*1).toFixed(k);b.sellcount1=(m[23]/100).toFixed(0);b.sellprice2=(m[24]*1).toFixed(k);b.sellcount2=(m[25]/100).toFixed(0);b.sellprice3=(m[26]*1).toFixed(k);b.sellcount3=(m[27]/100).toFixed(0);b.sellprice4=(m[28]*1).toFixed(k);b.sellcount4=(m[29]/100).toFixed(0);b.sellprice5=(m[30]*1).toFixed(k);b.sellcount5=(m[31]/100).toFixed(0);b.time=m[32];var j=b.price;if(!j){j=f}b.price=f;var e=f-j;if(f==0){b.updown=0;e=0}b.arrow=e>0?"\u2191":(e<0?"\u2193":"\u3000");b.trend=e;var d=(f-i);b.variable=d;var h=(d/i);b.percentnum=h;b.percent=(h*100).toFixed(2)+"%";b.updownarrow=d>0?"\u2191":(d<0?"\u2193":"\u3000");if(js.isFunction(this.onQuoteProcessed)){this.onQuoteProcessed(m,l,g)}},getQuoteData:function(a){return this.quoteDataMap[a]},getQuoteElement:function(a){return this.quoteElementsMap[a]},_quoteLoadCallback:function(){this._fillQuoteDataMap();if(js.isFunction(this.onQuoteLoading)){this.onQuoteLoading()}if(js.isFunction(this.onPageRender)){this.onPageRender()}else{this.defPageRender()}if(js.isFunction(this.onQuoteLoaded)){this.onQuoteLoaded()}},defPageRender:function(){this.eachElememt(function(a,c,b){if(js.isFunction(quote_ex.onElementRender)){quote_ex.onElementRender(a,c,b)}else{quote_ex.defElementRender(a,c,b)}})},colorNeedMap:{percent:true,arrow:true,updownarrow:true,price:true,variable:true,previousclose:true,openprice:true,updown:true,pe:true,todayhigh:true,todaylow:true,buyprice1:true,buyprice2:true,buyprice3:true,buyprice4:true,buyprice5:true,sellprice1:true,sellprice2:true,sellprice3:true,sellprice4:true,sellprice5:true,avg:true},toFixedNeedMap:{price:true,variable:true,previousclose:true,openprice:true,updown:true,pe:true,todayhigh:true,todaylow:true,avg:true},defElementRender:function(a,d,c){var b=js.elem(d);if(this.toFixedNeedMap[a]){b.html(c[a].toFixed(c.isHK?this.hkFixedNum:this.fixedNum))}else{b.html(c[a])}if(this.colorNeedMap[a]){b.className(b.className().replace(new RegExp("\\b("+this.util.cRed+")\\b|\\b("+this.util.cGreen+")\\b","g"),"")+" "+this.util.getUpDownColorCss(c.variable))}},eachCode:function(c){if(!js.isFunction(c)){throw new Error("invalid function")}var a=this.getCodes();for(var b=0;b<a.length;b++){c(a[b])}},eachQuoteData:function(a){if(!js.isFunction(a)){throw new Error("invalid function")}for(var b in this.quoteDataMap){a(b,this.getQuoteData(b))}},eachQuoteElement:function(a){this.eachQuoteData(function(b,c){a(b,c,quote_ex.getQuoteElement(b))})},eachElememt:function(a){this.eachQuoteElement(function(e,f,b){if(!b){return}for(var d in b){var g=b[d];if(js.isArray(g)){for(var c=0;c<g.length;c++){a(d,g[c],f)}}else{a(d,g,f)}}})},_loadCount:0,loadOnce:function(d){this.add(d);var b=this.getCodes();if(b.length==0){return}var e=new Date();var a=""+e.getHours()+e.getMinutes()+e.getSeconds();if(b.length<250||!js.msie){importJs("http://data.quotes.money.163.com/"+a+"?"+b.join(";"))}else{for(var c=0;c<b.length;c+=250){importJs("http://data.quotes.money.163.com/"+a+"?"+b.slice(c,c+250).join(";"))}}this._loadCount++},loadData:function(b){if(this.timer){window.clearTimeout(this.timer);this.timer=null}var a=(new Date()).getHours();if((a>=9&&a<=12)||(a>=13&&a<=16)||this._loadCount==0){this.loadOnce(b)}this.timer=window.setTimeout(function(){quote_ex.loadData()},this.timeout)},util:{cRed:null,cGreen:null,getUpDownColorCss:function(a){return a>0?this.cRed:(a<0?this.cGreen:"")},wrapUpDownColor:function(a,b){return'<span class="'+this.getUpDownColorCss(a)+'">'+b+"</span>"},percentToNumber:function(a){return Number(a.replace("%",""))/100},formatPercent:function(a){return parseInt(a*10000)/100+"%"}}};
