// Globals
var stockCode = '000001';
var stockType = 'SH';
var dataObj = {};
var currItems = [];
var currDate = '00000000'
var sNumber = -1;
var avgVol = 0;
var totalVol = 0;
var changeRate = 0;

var znzF10Instance = null;

function selectChange(newLine)
{
    if (currLine < 0 || currLine > currTRs.length -1)
        currLine = 0;
        
    currTRs[currLine].className = "realstock-query-select-unselected";
    currTRs[newLine].className = "realstock-query-select-selected";
    currLine = newLine;
    
    // set input values
    var tds = currTRs[currLine].childNodes;      
    var stype = tds[1].innerHTML;
    document.getElementById('realstock-query-code').name = 'code';
    var nowaction = document.getElementById('realstock-query-form').action.toString();
    if (nowaction.lastIndexOf("/") > 0){
        nowaction = nowaction.substring(0, nowaction.lastIndexOf("/")+1);
    }else{
        nowaction = "";
    }
    if(stype == 'SH'){
        document.getElementById('realstock-query-form').action = nowaction+"F10.php";
        document.getElementById('realstock-query-code').value = 'sh' + tds[0].innerHTML;
    }else{
        if(stype == 'SZ'){
            document.getElementById('realstock-query-form').action = nowaction+"F10.php";
            document.getElementById('realstock-query-code').value = 'sz' + tds[0].innerHTML;                    
        }else{
            document.getElementById('realstock-query-form').action = nowaction+"newsort.php";
            document.getElementById('realstock-query-code').name = 'boardNo';
            document.getElementById('realstock-query-code').value = '' + tds[0].innerHTML;
            if(stype == 'IH'){
                document.getElementById('realstock-query-code').value = 'SHHQ' + tds[0].innerHTML;
            }
            if(stype == 'IZ'){
                document.getElementById('realstock-query-code').value = 'SZHQ' + tds[0].innerHTML;
            }
            if(stype.indexOf('68') == 0){
                document.getElementById('realstock-query-code').name = 'market';
                document.getElementById('realstock-query-code').value = tds[1].innerHTML.toString().substring(2);
            }
        }
    }

}

function   SetCwinHeight()  
{  

}

function start()
{
    stockCode = getQueryString('code');
    if (stockCode == '')
        stockCode = 'sh000001';
      
    if (stockCode.substr(0, 2) == 'sh')
    {
        stockCode = stockCode.substr(2, stockCode.length);
        stockType = 'SH';
    }
    else
    {
        stockCode = stockCode.substr(2, stockCode.length);
        stockType = 'SZ';
    } 
    
    $("rightcode").innerHTML = "&nbsp;&nbsp;&nbsp;<a href='realstock.php?code="+ stockType.toLowerCase() + stockCode+"'>"+stockName + " [" + stockCode + "]</a>&nbsp;";

    znzF10Instance = new znzBigF10("stock-f10", stockCode, stockType, f10_data);
    
    if (f10_type){
        znzF10Instance.clickone(f10_type);
    }
    $('stock-index-all').innerHTML = "<a href='index.php' style='float:left'>返回首页</a>"
    queryInit();
}

window.onload = start;

// for F10
function znzBigF10(divID, stockCode, stockType, data)
{
    this.divID = divID;
    this.stockCode = stockCode || '000001';
    this.stockType = stockType || 'SH';
    if(data)
        this.data = data;   
    this._init(); 
}

znzBigF10.prototype._init = function(divobj, infoarr)
{
    if(!this.data)
        return;

    this.infoarr = KISSY.JSON.parse(this.data);
    
    if(this.infoarr.length == 1 && this.infoarr[0] == -1)
        return;
        
    var inne = "";
    for(var i = 0; i < this.infoarr.length; i++)
    {
        f10url = "F10.php?code="+ stockType.toLowerCase() + stockCode + "&type=" + this.infoarr[i][1];
        inne += "<div class='left-list' id='left-list"+i+"'><a onfocus='this.blur()' href='" + f10url +"'>" + decodeURIComponent(this.infoarr[i][0])+"</a></div>";
    }
  
    $(this.divID + "-list").innerHTML = inne;
}

znzBigF10.prototype.clickone = function(f10id)
{
    if(!this.infoarr)
        return;
        
    for (var i = 0 ; i < this.infoarr.length; i++){
        if (this.infoarr[i][1] == f10id){
            $("righttype").innerHTML = decodeURIComponent(this.infoarr[i][0]);
            $("left-list"+i).className = 'left-listcur';
        }else{
            $("left-list"+i).className = 'left-list';
        }
    }
    var infoURL = "/mirror/F10/" + this.stockType + 'HQ' + this.stockCode+"_d_"+f10id+".html?r="+ Math.random().toString(); 
    $(this.divID + "-iframe").src = infoURL;
}




