基于JQuery, 利用一个网页完成,功能: 实时行情数据(包括K线,分时图), 自选股票,股票查询提示, 股票预警通知,可设置刷新间隔,基于cookie保存用户数据;30K大小
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache">
<Meta http-equiv=”Expires” Content=”0″>
<title>$</title>
<script src="http://www.google.com/jsapi"></script>
<style>
body  
{color: #333;font:12px Arial, Helvetica, sans-serif;margin:0;padding:0;text-align:left;background-color:transparent;}
.SearchCont_temp
{text-align:center}
    .SearchCont_temp img
{vertical-align:middle;}
    .suggest 
{
        position
: absolute;    
        background-color
: #FFFFFF;
        border
: 1px solid #A5ACB2;
        
/*border-top: none;*/
/*        filter: alpha(opacity=90);  */
        -moz-opacity
: 0.9;
        opacity
: 0.9;
        margin
: 0;
        left
: 7px;
        margin
: 0;
/*        width: 88.4%;   */
    
}
    .suggest .tableSuggest 
{
        color
: #777777;
        line-height
: 16px;
        margin-top
: 2px;
        width
: 100%;
    
}
    .suggest .tableSuggest td 
{
        text-align
: center;
        padding
: 2px 4px;
    
}
    .suggest .trHeader 
{
        background-color
: #F3F3F3;
    
}
    .suggest .overLine 
{
        background-color
: #F1F5FC;
        color
: #333333;
        cursor
: pointer;
    
}
    .suggest .selectedLine 
{
        background-color
: #F6F8FD;
        color
: #444444;
    
}
    .suggest .overSelectedLine 
{
        background-color
: #EFF3FB;
        color
: #000000;
        cursor
: pointer;
    
}
*:active 
{outline:none;} 
*:focus 
{-moz-outline-style:none;}  
{margin: 0; padding: 0;font-family:"Lucida Grande", Lucida, Verdana, sans-serif;}
 
</style>
</head>
<body onload="init()" >
<span id="_cc" onclick="$('#_pg').toggle();" >$</span>
<div id="_pg"  style="display:none">
<p>
<span onclick="$('#_hq').toggle();" >< 行情查询 > </span><input type="button"  id="_rq_btn" value="启动" onclick="hqMgr()"/>
</p>
<div id="_hq"  style="display:none">
      
<input type="hidden" id="countrySelect" value="cn"/>
    
<input type="hidden" id="suggestQ" name="q" value="" />
    
<input type="hidden" id="suggestCountry" name="country" value="cn" />
    
<div id="searchDiv">&nbsp;<input  type="text" id="_stock"  size=18 onkeypress="quickSrh()" autocomplete="off" name="keyword" style="color: #999999;" value="基金股票代码/拼音" /> 
    
<span id=_gp></span></br></div>     
<onclick="$('#_bj').toggle()">1.报价</p>
<div  id="_bj" style="display:none">    
当前: 
<span id=_cp></span> &nbsp; <span id="_alert_stock" style="color:red"></span><br/>
涨跌: 
<span id=_zr></span><br/>
涨幅: 
<span id=_zp></span><br/>
今开: 
<span id=_jk></span><br/>
昨收: 
<span id=_zs></span><br/>
最高: 
<span id=_zg></span><br/>
最低: 
<span id=_zd></span><br/>
</div>
<p>
    
<div onclick="$('#_fs').toggle()">2.分时图</div>
     
<img id="_fs" src=''  style="display:none">
</p>
<p>
     
<div onclick="$('#_dk').toggle()">3.日K线</div>
     
<img id="_dk" src='' style="display:none">
</p>
</div> 
<onclick="favMgr()" >< 我的自选 ></p>
<div id="_fav"  style="display:none">
     
<div id="searchDiv2">&nbsp;<input  type="text" id="_mstock"  size=18 autocomplete="off" name="keyword2" style="color: #999999;" value="基金股票代码/拼音" />      
      
<span id=_mgp></span>      
     
<input type="button"  value="添加" onclick="addFavStock()"/>
     
<input type="button"  value="清空" onclick="clearFavStocks()"/><br/>    
    
</div>      
     
<id="_zxg_list"></p>
</div>
<onclick="configMgr()" >< 功能设置 ></p>
<div id="_sz"  style="display:none">
    
<onclick="$('#_yj').toggle();">1.价格预警</p>
    
<div id="_yj"  style="display:none">
    高于
<input type='text' id='_hp'  size='5' value=''  /> 或<br/>
    低于
<input type='text' id='_lp'  size='5' value=''  />  时报警 <br/>
    
<input type="button"  value="保存" onclick="saveAlertPrice()"/><input type="button"  value="清除" onclick="clearAlertPrice()"/>
    
</div>    
    
<onclick="$('#_tm').toggle();">2.实时行情</p>
    
<div id="_tm"  style="display:none">
        查询间隔 
<input type='text' id='_it'  size='2' value=''  />  秒        
        
<input type="button"  value="保存" onclick="setAutoQuery()"/> 
    
</div>
</div>
</div> 
<script type="text/javascript"  >        
 google.load(
"jquery""1.3.2"); //Load JQuery Library 
 var interval; 
 
var timerID;
 
var cookie_config = {expires: 365, path: '/'};
 
var suggest_url = 'http://fe1.g-fox.cn:8000/WebContent/stock/js/suggest.js' //'suggest_unicode.js';
 var DEFAULT_INTERVAL = 10//unit second
  function init(){      //initial action
      interval = parseFloat(getInterval())*1000
    loadTimerData(); 
    initSuggest();;
  }
 
function getFavStockInfo(){  
     
if($('#_mstock').val()=='') return ;  
     loadPriceInfo('fav');     
 }
  
function getStockInfo(){  
          
if($('#_stock').val()=='') return ;          
          loadPriceInfo('hq');
          loadDKGraph();          
          loadFSGraph();          
 } 
 
function loadPriceInfo(tp){
    
var url = 'http://hq.sinajs.cn/list=';     
    var stock = $('#_stock').val(); //hq
    if(tp != 'hq')  stock = $('#_mstock').val(); //fav & fav_add 
    var stock_str = 'hq_str_' + stock;        
    
/*
    $.get(url+stock, function(data) {  
        //alert(data);
          eval(data);          
        ?????????
    
*/    
     $.ajax({  
         
//contentType:'application/x-www-form-urlencoded; charset=UTF-8',
        dataType:'script',  
        scriptCharset:'GBK', 
        url:url
+stock,  
        cache: 
true,  
        success: 
function(){                      
        
var st = eval(stock_str);          
          
var elements = st.split(",");
          
if(tp == 'hq'){
              setStockPriceInfo(elements);
          }
else if(tp == 'fav'){
              setFavStockInfo(elements);
          }
else if(tp == 'fav_add'){
              setFavAddStockInfo(elements);
          }              
       }  
       });      
 } 
 
function setFavStockInfo(elements){
        $('#_mgp').html(elements[
0]);         
 } 
 
function setFavAddStockInfo(elements){
     
if(elements[0== '')     return
     
else $('#_mgp').html(elements[0]);     
         
     
var fav_stocks = getFavStocks();              
    
if(getFavStockByCd($('#_mstock').val())==null){ //check duplicate
        fav_stocks.push({cd:$('#_mstock').val(), nm:$('#_mgp').html()});
    }
    saveFavStocks(fav_stocks);        
    listFavStocks();          
 } 
  
function getFavStocks(){      
      
var fs_str = $.cookie('fav_stocks');       
      
return (fs_str!=null?$.evalJSON($.cookie('fav_stocks')): new Array());       
  }
  
function queryHQ(i){
      
var fav_stocks = getFavStocks();       
      $('#_stock').val(fav_stocks[i].cd);
      $('#_gp').val(fav_stocks[i].nm);
      $('#_hq').show();
      getStockInfo();    
  }    
  
  
function clearFavStocks(){
      $.cookie('fav_stocks',
null); 
      listFavStocks();          
 }
 
function removeFavStock(i){
     
var fav_stocks = getFavStocks(); 
     fav_stocks.splice(i,
1);
     saveFavStocks(fav_stocks);        
     listFavStocks();  
 }      
 
function saveFavStocks(fav_stocks){
     $.cookie('fav_stocks',$.toJSON(fav_stocks), cookie_config);  
 }
function addFavStock(){   
   
if($('#_mstock').val()=='' || $('#_mstock').val()=='基金股票代码/拼音') return ;  
   loadPriceInfo('fav_add');         
 }
 
function getFavStockByCd(cd){
     
var fav_stocks = getFavStocks();  
     
for(i=0; i<fav_stocks.length;i++){
         
if(fav_stocks[i].cd == cd) {
             
return fav_stocks[i];
         }     
     }
  } 
 
function listFavStocks(){
      
var fav_stocks = getFavStocks();  
      
var list = '';        
      
for(i=0; i<fav_stocks.length;i++){
           list 
+= (i+1)+'. ' + fav_stocks[i].cd+'&nbsp;' +  fav_stocks[i].nm + '&nbsp; <span style="color:gray"  onclick="queryHQ(' + i+ ')" >查询</span>&nbsp; <span style="color:gray" onclick="removeFavStock(' + i+ ')"  >删除</span>    </br>';
      }
      $('#_zxg_list').html(list);
 }
     
 
function setStockPriceInfo(elements){    
        $('#_gp').html(elements[
0]);  
          $('#_jk').html(elements[
1]);  
          $('#_zs').html(elements[
2]);  
          $('#_cp').html(elements[
3]);          
          $('#_zg').html(elements[
4]);      
          $('#_zd').html(elements[
5]);                          
          
var zr = parseFloat(elements[3]) - parseFloat(elements[2]);
          
var zp = zr/parseFloat(elements[2]) * 100;
          $('#_zr').html(format(zr));            
          $('#_zp').html(format(zp) 
+ '%'); 
          triggerAlertIfNecessary(parseFloat(elements[
3]));       
 }
 
  
function loadDKGraph(){        
    
var stock = $('#_stock').val();         
    $('#_dk').attr('src', 'http:
//image.sinajs.cn/newchart/daily/n/' + stock + '.gif?'+Math.random());  
 }
 
  
function loadFSGraph(){     
    
var stock = $('#_stock').val();         
    $('#_fs').attr('src', 'http:
//image.sinajs.cn/newchart/min/n/' + stock + '.gif?'+Math.random());  
 }

function quickSrh(){
    
if((event.which && event.which == 13|| (event.keyCode && event.keyCode == 13)) {
         getStockInfo();                      
        
return false;
        }  
else return true;
}

 
function loadConfigData(){
      
//loadTimerData();  //only need load when page loaded!
      loadAlertData(); 
  }
  
function loadTimerData(){              
      $('#_it').val(getInterval());            
  }
  
function getInterval(){
    
var it = $.cookie('hq_interval');
    
return (it==null || it =='')?DEFAULT_INTERVAL:it;
}
function loadAlertData(){  
    
var data = getAlertData();            
    
if(data) {
        $('#_hp').val(data.hp);
        $('#_lp').val(data.lp);
    }
else{
        $('#_hp').val('');
        $('#_lp').val('');
    }
}
 
function saveAlertPrice(){      
      
/*  //<div id='_db'></div>
    $('#_db').data($('#_stock').val(), {'hp': $('#_hp').val(), 'lp': $('#_lp').val()});     
    
*/
     $.cookie($('#_stock').val(),$.toJSON({'hp': $('#_hp').val(), 'lp': $('#_lp').val()}), cookie_config);            
 }
 
function clearAlertPrice(){
    $.cookie($('#_stock').val(),
null);  
    $('#_alert_stock').html('');
    $('#_hp').val('');
    $('#_lp').val('');
 }
 
function getAlertData(){   
    
return $.evalJSON($.cookie($('#_stock').val()));            
 }
     
  
function getAlertPrice(tp){   
      
/*
      var data = $('#_db').data('stock');       
    return eval('data.' + tp); 
    
*/
     
var data = getAlertData();            
     
return data!=null?data[tp]:'';
 }

function triggerAlertIfNecessary(cp){    
    
var  hp = getAlertPrice('hp');
    
var  lp = getAlertPrice('lp');
    
var msg = '';
    
    
if(hp != '' &&  cp >= parseFloat(hp)){
        msg 
= ' 高于: ' + hp;
    }
else if(lp != ''  && cp > 0 && cp <= parseFloat(lp)){
        msg 
= ' 低于: ' + lp;                
    } 
    
if(msg!='') openWin(msg);        
    $('#_alert_stock').html(msg);
}
function openWin(msg){
var msgWin=window.open('', 'msgWin', 'height=1, width=418 top='+(screen.availHeight-30)+', left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');  
var msgDoc = msgWin.document;
msgDoc.title 
= $('#_gp').html() + "  -  现价: " + $('#_cp').html()  +  msg;
//msgDoc.write("<TITLE>"+ $('#_gp').html() + "  -  现价: " + $('#_cp').html()  +  msg + "</TITLE>");
//
msgDoc.write("<BODY BGCOLOR=#ffffff  height=1px>" );
//
msgDoc.write("</BODY>"); 
//
msgDoc.close();
//
msgWin.resizeTo(418,0);
//
msgWin.focus();
}
 
function format(n)   {
    
if(n=='') return n;
    
var s = "" + Math.round(n * 100/ 100;
    
var i = s.indexOf('.');
    
if (i < 0)   return   s + ".00";
    
var t = s.substring(0, i + 1+ s.substring(i + 1, i + 3);
    
if (i + 2 == s.length)   t += "0"
    
return t;
}
function setAutoQuery(){
    
var it  = $('#_it').val();    
    $.cookie('hq_interval', it, cookie_config);      
    interval 
= parseFloat(getInterval())*1000//reset interval  for timer        
}
function hqMgr(){        
    
if($('#_rq_btn').val() == '启动') {         
        $('#_rq_btn').val('停止'); 
           startInterval();
    } 
else { 
        $('#_rq_btn').val('启动'); 
        clearInterval(timerID);    
    }         
}
function favMgr(){
    $('#_fav').toggle();
    
if( $('#_fav').is(':visible') ) {         
        listFavStocks(); 
    }
}
function configMgr(){
    $('#_sz').toggle();
    
if( $('#_sz').is(':visible') ) {         
        loadConfigData(); 
    }
}
function startInterval(){
    timerID 
= setInterval("getStockInfo()", interval);
}

 
function loadSuggestData(url, key, callback){
    $.ajax({  
         
//contentType:'application/x-www-form-urlencoded; charset=UTF-8',
        dataType:'script',  
        scriptCharset:'gbk',
        url:url,  
        cache: 
true,  
        success: 
function(){     
            
if(callback)  callback(key);              
       }  
       });      
 }       
    
var Suggest = function (stringUrl, key, searchDiv) {
        
this.stringKeySpliter = ":"
        
this.stringRecordSpliter = "|";
        
this.stringSystemKeys = "s,sh,sz,0,1,2,3,4,5,6,7,8,9";
        
this.arraySystemKeys = new Array();
        
this.arrayPrepareKeys = new Array();
        
this.intPrepareKeysMaxLength = 50;
        
this.stringData = new String();
        
this.processData = function (valueKey) {
            
var suggest = arguments.callee.suggest;
            suggest.stringData 
= suggest.stringRecordSpliter + window[valueKey];
            
var arrayStringSystemKeys = suggest.stringSystemKeys.split(",");
            
for (var i =0; i < arrayStringSystemKeys.length; i++) {
                
var stringNearestData = suggest.getNearestData(arrayStringSystemKeys[i]);
                
var arrayResult = stringNearestData == "" ?  suggest.getResult(suggest.stringData, arrayStringSystemKeys[i]) : suggest.getResult(stringNearestData, arrayStringSystemKeys[i]);
                arrayResult 
= arrayResult == null ? new Array() : arrayResult;
                suggest.arraySystemKeys.push(
new Array(arrayStringSystemKeys[i], arrayResult.join("")));
            }
        };
        
this.processData.suggest = this;     
        loadSuggestData(stringUrl, key, 
this.processData);
        
        
this.getOffsetPos = function (element) {
            
var flag = element.tagName.toUpperCase() == "INPUT" ? true : false;
            
var posTop = 0, posLeft = 0;
            
do {
                posTop 
+= element.offsetTop || 0;
                posLeft 
+= element.offsetLeft || 0;
                element 
= element.offsetParent;
            } 
while (element);
            
if (navigator.appVersion.indexOf("MSIE 6.0"!= -1 && flag) {
                posLeft
++;
            }
            
return [posLeft, posTop];
        };
        
this.getResult = function (stringData, stringKey) {
            
var stringRegExpSystem = "$()*+.[?\^{|";
            
var stringKeySpliter = (stringRegExpSystem.indexOf(this.stringKeySpliter) < 0 ? "" : "\\"+ this.stringKeySpliter;
            
var stringRecordSpliter = (stringRegExpSystem.indexOf(this.stringRecordSpliter) < 0 ? "" : "\\"+ this.stringRecordSpliter;
            
var arrayMatchResult = stringData.match(new RegExp("" + stringRecordSpliter + (isNaN(parseInt(stringKey)) ? "" : "(s[hz])?"+ stringKey + "[^\\" + stringRecordSpliter + "|" + stringKeySpliter + "]*" + stringKeySpliter + "[^\\" + stringRecordSpliter + "|" + stringKeySpliter + "|\n]*""igm"));
            
return arrayMatchResult == null ? new Array() : arrayMatchResult;
        };
        
        
this.getNearestData = function (stringKey) {
            
if (this.arrayPrepareKeys.length == 0) {
                
return new String();
            }
            
var arrayContainers = new Array();
            
for (var i =0; i < this.arraySystemKeys.length; i++) {
                
if (this.arraySystemKeys[i][0== stringKey) {
                    
return this.arraySystemKeys[i][1];
                }
                
if (stringKey.match(new RegExp("^" + this.arraySystemKeys[i][0], "igm")) != null) {
                    arrayContainers.push(
this.arraySystemKeys[i]);
                }
            }
            
for (var i = 0; i < this.arrayPrepareKeys.length; i++) {
                
if (this.arrayPrepareKeys[i][0== stringKey) {
                    
return this.arrayPrepareKeys[i][1];
                }
                
if (stringKey.match(new RegExp("^" + this.arrayPrepareKeys[i][0], "igm")) != null) {
                    arrayContainers.push(
this.arrayPrepareKeys[i]);
                }
            }
            
if (arrayContainers.length == 0) {
                
return new String();
            }
            
else {
                arrayContainers.sort(
                    
function (arrayA, arrayB) {
                        
return arrayB[0].length - arrayA[0].length;
                    }
                );
                
return arrayContainers[0][1];
            }
        };
        
        
this.getQuickResult = function (stringKey) {
            stringKey 
= stringKey.split(this.stringKeySpliter).join("").split(this.stringRecordSpliter).join("");
            
if (stringKey == "") {
                
return new Array();
            }
            
var stringNearestData = this.getNearestData(stringKey);
            
var arrayResult = stringNearestData == "" ?  this.getResult(this.stringData, stringKey) : this.getResult(stringNearestData, stringKey);
            arrayResult 
= arrayResult == null ? new Array() : arrayResult;
            
var booleanIsInSystemKeys = false;
            
for (var i = 0; i < this.arraySystemKeys.length; i++) {
                
if (this.arraySystemKeys[i][0== stringKey) {
                    booleanIsInSystemKeys 
= true;
                    
break;
                }
            }
            
var booleanIsInPrepareKeys = false;
            
for (var i = 0; i < this.arrayPrepareKeys.length; i++) {
                
if (this.arrayPrepareKeys[i][0== stringKey) {
                    booleanIsInPrepareKeys 
= true;
                    
break;
                }
            }
            
if (!booleanIsInSystemKeys && !booleanIsInPrepareKeys) {
                
this.arrayPrepareKeys.push(new Array(stringKey, arrayResult.join("")));
                
if (this.arrayPrepareKeys.length > this.intPrepareKeysMaxLength) {
                    
this.arrayPrepareKeys.sort(
                        
function (arrayA, arrayB) {
                            
return arrayA[0].length - arrayB[0].length;
                        }
                    );
                    
this.arrayPrepareKeys.pop();
                }
            }
            
return arrayResult;
        };
        
this.load = function (stringKey) {
            
if (stringKey.indexOf(","!= -1 && stringKey.indexOf(","!= 0 && stringKey.indexOf(","!= stringKey.length - 1) {
                
var arrayStringKey = stringKey.split(",");
                stringKey 
= arrayStringKey[arrayStringKey.length - 1];
            }
            
if (stringKey.indexOf("\\"!= -1) {
                
return new Array();
            }
            
var stringRegExpSystem = "$()*+.[?^{|";
            
for (var i = 0; i < stringRegExpSystem.length; i++) {
                
if (stringKey.indexOf(stringRegExpSystem.substr(i, 1)) != -1) {
                    
return new Array();
                }
            }
            
var stringMarket = new String();
            
var arrayQuickResult = this.getQuickResult(stringKey);
            arrayQuickResult.length 
= arrayQuickResult.length > 10 ? 10 : arrayQuickResult.length;
            
return arrayQuickResult;
        };
        
this.show = function () {
            
var element = arguments.callee.element;
            
if (!element.booleanScan) {
                
return;
            }
            
if (element.stringLastValue != element.value && element.value != "基金股票代码/拼音") {
                element.line 
= null;
                element.stringLastValue 
= element.value;
                
var arrayResult = element.suggest.load(element.value);
                
if (arrayResult.length > 0) {
                    element.divHint.style.display 
= "block";
                    
var arrayPosition = element.suggest.getOffsetPos(element);

                    element.divHint.style.top 
= arrayPosition[1+ 6 + "px";
                    element.divHint.style.marginTop 
= element.clientHeight + 1 + "px";
//                    element.divHint.style.width = element.clientWidth > 230 ? element.clientWidth : 230 + "px";  //liyousheng
                    var tableContainer = document.createElement("table");
                    tableContainer.className 
= "tableSuggest";
                    tableContainer.id 
= "tableSuggest";
                    
var searchDivObj = this.searchDiv;
                    
if(searchDivObj!=null){
                        tableContainer.style.width 
= searchDivObj.clientWidth + "px";
                    }
                    tableContainer.cellPadding 
= 0;
                    tableContainer.cellSpacing 
= 0;
                    
var trHeader = tableContainer.insertRow(0);
                    trHeader.className 
= "trHeader";
                    
var tdKey = trHeader.insertCell(0);
                    tdKey.innerHTML 
= "选项";
                    
var tdCode = trHeader.insertCell(1);
                    tdCode.innerHTML 
= "代码";
                    
var tdName = trHeader.insertCell(2);
                    tdName.innerHTML 
= "名称";
                    
for (var i = 0; i < arrayResult.length; i++) {
                        
if (isNaN(parseInt(i))) {
                            
continue;
                        };
                        
var arrayRecord = arrayResult[i].replace("|""").split(":");
                        
var arrayCodeAndName = arrayRecord[1].split("-");
                        
var trRecord = tableContainer.insertRow(parseInt(i) + 1);
                        
var tdKey = trRecord.insertCell(0);
                        tdKey.innerHTML 
= arrayRecord[0];
                        
var tdCode = trRecord.insertCell(1);
                        tdCode.innerHTML 
= arrayCodeAndName[0+ arrayCodeAndName[1];
                        
var tdName = trRecord.insertCell(2);
                        tdName.innerHTML 
= arrayCodeAndName[2];
                        trRecord.stringFullCode 
= arrayCodeAndName[0+ arrayCodeAndName[1];
                        trRecord.inputTarget 
= element;
                        trRecord.onmouseover 
= function () {
                            
this.inputTarget.overLine = this;
                            
this.className = this.inputTarget.line == this ? "overSelectedLine" : "overLine";
                        };
                        trRecord.onmouseout 
= function () {
                            
this.inputTarget.overLine = null;
                            
this.className = this.inputTarget.line == this ? "selectedLine" : "";
                        };
                        trRecord.onmousedown 
= function () {
                            
this.inputTarget.booleanScan = true;
                            
this.inputTarget.blur(); // chinese input
                            this.inputTarget.setLine(this);
                            
if (checkSuggest(element)) { 
                                
//document.forms[0].submit();
                                checkquery(element);
                            }
                        };
                    }
                    element.divHint.innerHTML 
= "";
                    element.divHint.appendChild(tableContainer);
                    element.tableHint 
= tableContainer;
                }
else {
                    element.divHint.style.display 
= "none";
                    element.divHint.innerHTML 
= "";
                    element.tableHint 
= null;
                }
            }
        };
        
this.bind = function (element) {
            element.suggest 
= this;
            element.show 
= this.show;
            element.show.element 
= element;
            element.intThread 
= -1;
            element.arrayData 
= new Array();
            
if (element.value != "基金股票代码/拼音") {
//                element.value = "基金股票代码/拼音";   // liyousheng 
            }
            element.style.color 
= "#999999";
            element.booleanScan 
= true;
            element.autocomplete 
= "off";
            
var divDataTable = document.createElement("div");
//            divDataTable.id = 'stock_suggest_box';
//
            divDataTable.innerHTML='<div></div>';
                        
            divDataTable.style.display 
= "none";
            element.parentNode.insertBefore(divDataTable, element);
            element.divHint 
= divDataTable;
            element.tableHint 
= null;
            element.line 
= null;
            element.overLine 
= null;
            divDataTable.className 
= "suggest";
            divDataTable.id 
= "stock_suggest_box";
            
            element.onfocus 
= function () {
                
this.select();
                
this.style.color = "";
//                if (this.value == "基金股票代码/拼音" || this.value == "代码输入错误"||this.value.length>0) {
                if (this.value == "基金股票代码/拼音" || this.value == "代码输入错误") {
                    
this.value = "";
                    
this.style.color = "";
                };
                
this.stringLastValue = this.value;
                
if (this.divHint.innerHTML != "") {
                    
this.divHint.style.display = "block";
                    
var arrayPosition = this.suggest.getOffsetPos(this);

                    
this.divHint.style.top = arrayPosition[1+ 10 + "px";
                    
this.divHint.style.marginTop = this.clientHeight + 1 + "px";
//                    this.divHint.style.width = this.clientWidth > 230 ? this.clientWidth : 230 + "px";   // liyousheng 
                }
                
this.intThread = setInterval(this.show, 10);
            };
            element.onblur 
= function () {
                
if (this.value == "") {
                    
this.value = "基金股票代码/拼音";
                    
this.style.color = "#999999";
                };
                
this.divHint.style.display = "none";
                clearInterval(
this.intThread);
                
this.intThread = -1;
            };
            element.setLine 
= function (line) {
                
var stringKeyFore = "";
                
if (this.value.indexOf(","!= -1 && this.value.indexOf(","!= 0 && this.value.indexOf(","!= this.value.length - 1) {
                    
var arrayStringKeyFore = this.value.split(",");
                    arrayStringKeyFore[arrayStringKeyFore.length 
- 1= "";
                    stringKeyFore 
= arrayStringKeyFore.join(",");
                }
                
if (this.line != null) {
                    
this.line.className = this.overLine == this.line ? "overLine" : "";
                }
                
this.line = line;
                line.className 
= this.overLine == line ? "overSelectedLine" : "selectedLine";
                
this.value = stringKeyFore + line.stringFullCode;
            };
            element.onkeydown 
= function () {
                
if (this.value == "基金股票代码/拼音") {
                    
this.value = "";
                }
                
if (!this.tableHint) {
                    
return true;
                }
                
var stringKeyFore = "";
                
if (this.value.indexOf(","!= -1 && this.value.indexOf(","!= 0 && this.value.indexOf(","!= this.value.length - 1) {
                    
var arrayStringKeyFore = this.value.split(",");
                    arrayStringKeyFore[arrayStringKeyFore.length 
- 1= "";
                    stringKeyFore 
= arrayStringKeyFore.join(",");
                }
                
                
var event = arguments[0|| window.event;
                
switch (event.keyCode) {
                    
case 38//up
                        this.booleanScan = false;
                        
if (this.line == null || this.line.rowIndex == 1) {
                            
this.setLine(this.tableHint.rows[this.tableHint.rows.length - 1]);
                        }
                        
else {
                            
this.setLine(this.tableHint.rows[this.line.rowIndex - 1]);
                        }
                        
return false;
                        
break;
                    
case 40//down
                        this.booleanScan = false;
                        
if (this.line == null || this.line.rowIndex == this.tableHint.rows.length - 1) {
                            
this.setLine(this.tableHint.rows[1]);
                        }
                        
else {
                            
this.setLine(this.tableHint.rows[this.line.rowIndex + 1]);
                        }
                        
return false;
                        
break;
                    
case 13//Enter
                        this.booleanScan = true;
                        
this.stringLastValue = stringKeyFore + this.value;
                        
this.divHint.style.display = "none";
                        
break;
                    
default:
                        
this.booleanScan = true;
                        
break;
                }
            };
        };
        
this.getCode = function (value) {
            
var result = this.load(value);
            
if (result.length == 1) {
                
var stock = result[0].split(":")[1].split("-");
                
return stock[0+ stock[1];
            }
            
else {
                
return value;
            }
        };        
    };

    
function checkSuggest(o) {//TODO getStockInfo
        var value = o.value;
        
if (value=="基金股票代码/拼音" || value=="") {
            
return false;
        }
        $('#suggestQ').value 
= value.replace(/^s[hz]/, '');
        $('#suggestCountry').val($('#countrySelect').val());         
        
return true
    }
    
function checkquery(o){
        
if(o.id == '_mstock'){
            getFavStockInfo();
        }
else if(o.id == '_stock'){
            getStockInfo();
        }    
    }
    
function initSuggest() {
        $(
"#countrySelect").val("cn");  
        window.suggestStock 
= new Suggest(suggest_url, "SuggestData", $("#searchDiv")); 
        window.suggestStock.bind(document.getElementById('_stock'));    
        
       window.suggestStock2 
= new Suggest(suggest_url, "SuggestData", $("#searchDiv2")); 
       window.suggestStock2.bind(document.getElementById('_mstock'));             
    }    
</script> 
<script type="text/javascript"  >  
/**  Cookie plugin */ 
jQuery.cookie 
= function(name, value, options) {
    
if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        
if (value === null) {
            value 
= '';
            options.expires 
= -1;
        }
        
var expires = '';
        
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            
var date;
            
if (typeof options.expires == 'number') {
                date 
= new Date();
                date.setTime(date.getTime() 
+ (options.expires * 24 * 60 * 60 * 1000));
            } 
else {
                date 
= options.expires;
            }
            expires 
= '; expires=+ date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        
// CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason
        var path = options.path ? '; path=+ (options.path) : '';
        
var domain = options.domain ? '; domain=+ (options.domain) : '';
        
var secure = options.secure ? '; secure' : '';
        document.cookie 
= [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } 
else { // only name given, get cookie
        var cookieValue = null;
        
if (document.cookie && document.cookie != '') {
            
var cookies = document.cookie.split(';');
            
for (var i = 0; i < cookies.length; i++) {
                
var cookie = jQuery.trim(cookies[i]);
                
// Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1== (name + '=')) {
                    cookieValue 
= decodeURIComponent(cookie.substring(name.length + 1));
                    
break;
                }
            }
        }
        
return cookieValue;
    }
};

/*
var thing = {plugin: 'jquery-json', version: 2.2};
var encoded = $.toJSON(thing);              //'{"plugin":"jquery-json","version":2.2}'
var name = $.evalJSON(encoded).plugin;      //"jquery-json"
var version = $.evalJSON(encoded).version;  // 2.2
*/
(
function($){$.toJSON=function(o)
{
if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{
if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{
var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z
"';}
if(o.constructor===Array)
{
var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])
||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name
='"'+k+'"';else if(type=="string")
name
=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join("")+"}";}};$.evalJSON=function(src)
{
if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{
if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{
if(string.match(_escapeable))
{
return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'
"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);
</script>
</body>
</html>