
// 滑动效果
function GetObj(objName){
			if(document.getElementById){
				return eval('document.getElementById("' + objName + '")');
			}else if(document.layers){
				return eval("document.layers['" + objName +"']");
			}else{
				return eval('document.all.' + objName);
			}
		}
		
function ADMenuNEW(index,flag,styledisp,stylehide)
{
	for(var i=0;i<10;i++)
	{
		if(GetObj("jkcon"+flag+i)&&GetObj("ADm"+flag+i))
		{
			if (i==index)
			{
			GetObj("jkcon"+flag+index).style.display = 'block';
			GetObj("ADm"+flag+index).className = styledisp;
			}
			else
			{
			GetObj("jkcon"+flag+i).style.display = 'none';
			GetObj("ADm"+flag+i).className = stylehide;
			}
		}
	}
}
	
function addBookmark(title,url) {
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
return true;
}
}
var tiptimeout;
function mhover(evt,tips)
{
clearTimeout(tiptimeout);
if (!document.all)
{x=evt.pageX;y=evt.pageY;}
else
{x=window.event.x;y=window.event.y+document.documentElement.scrollTop;}
y=y+15;
document.getElementById('hovertips').innerHTML=tips;
if (x>document.body.clientWidth-250)
{document.getElementById('hovertips').style.left='';document.getElementById('hovertips').style.right='0px';}
else
{document.getElementById('hovertips').style.right='';document.getElementById('hovertips').style.left=x+'px';}
document.getElementById('hovertips').style.top=y+'px';
document.getElementById('hovertips').style.display='block';
}
function mhoverout()
{tiptimeout=setTimeout("document.getElementById('hovertips').style.display='none'",500);}

//查询
// for query
var currLine = -1;
var currTRs = [];
var oninput = false;
function queryInit()
{
    document.getElementById('realstock-query-query').value = '代码/名称/拼音';
    document.getElementById('realstock-query-query').onfocus = function()
    {
        oninput = true;
        if(document.getElementById('realstock-query-query').value == '代码/名称/拼音')
            document.getElementById('realstock-query-query').value = '';
    }
    document.getElementById('realstock-query-query').onblur = function ()
    {
      oninput = false;
    }
    document.getElementById('realstock-query-query').onkeyup = function (ev)
    {
        ev = ev||window.event;
        if(ev.keyCode == 38 || ev.keyCode == 40 )    // key is up or down
        {
            if (currTRs)
            {
                var newLine = currLine;
                if(ev.keyCode == 38)
                {
                    if(currLine > 0)
                        newLine = currLine -1;
                }
                else
                {
                    if(currLine < currTRs.length -1)
                        newLine = currLine +1;
                }
                selectChange(newLine);
            }
        }
        else
        {
            var query =  document.getElementById('realstock-query-query').value;
            query = query.replace(' ', '');
            if( query == '') 
            {
                document.getElementById('realstock-query-select').innerHTML = '';
                return;
            }
            var args = {
                method : 'get', onComplete : onSugRecved
            };
            query = encodeURIComponent(query); 
            query = 'http://quote.jinku.com/sfquery.php?query=' + query
            var myAjaj = new Ajaj(query, args); 
        }
    }
}
function onSugRecved(rep, query)
{
    var ret = decodeURIComponent(rep);
    var lines = ret.split('|');
    var query = document.getElementById('realstock-query-query').value;
    var content = '<table id=\'realstock-query-select-table\'>'
    for(var i=0; i< lines.length&&i < 10; i++)
    {
        stocks = lines[i].split(';');
        if(stocks.length != 5 )
            continue;
        content += '<tr class=\'realstock-query-select-unselected\'>';        
        content += '<td width=50px>' + stocks[0] + '</td>' + '<td class=\'hide\'>' + stocks[1] + '</td>' + '<td width=60px>' + stocks[2] + '</td>' + '<td width=55px>' + stocks[3] + '</td>' + '<td class=\'hide\'>' + stocks[4]+ '</td>';
        content += '</tr>';
    }
    
    content += '</table>';
    document.getElementById('realstock-query-select').innerHTML = content;
    window.setTimeout(selectInit, 100);
        
}
function selectInit()
{
    var table = document.getElementById('realstock-query-select-table');
    if (table)
    {
        if (table.childNodes[0])
        {
            currTRs = table.childNodes[0].childNodes;
            selectChange(0)
            for (var i=0; i< currTRs.length; i++)
            {
                currTRs[i].onmouseover = function()
                {
                    var j = 0;
                    for(j =0; j< currTRs.length; j++)
                    {
                        if(currTRs[j] == this)
                            break;
                    }
                    selectChange(j);
                }
                
                currTRs[i].onclick = function()
                {
                    var j = 0;
                    for(j =0; j< currTRs.length; j++)
                    {
                        if(currTRs[j] == this)
                            break;
                    }
                    document.getElementById('realstock-query-form').submit();
                }
            }
        }
    }    
}

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;
    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 = "";
    }
    document.getElementById('realstock-query-code').value = tds[0].innerHTML;
    document.getElementById('realstock-query-market').value = tds[1].innerHTML;
    document.getElementById('realstock-query-type').value = tds[4].innerHTML;

}






////基金查询
var currLine2 = -1;
var currTRs2 = [];
function queryInit2()
{
    document.getElementById('realstock-query2-query').value = '代码/名称/拼音';
    document.getElementById('realstock-query2-query').onfocus = function()
    {
        oninput = true;
        if(document.getElementById('realstock-query2-query').value == '代码/名称/拼音')
            document.getElementById('realstock-query2-query').value = '';
    }
    document.getElementById('realstock-query2-query').onblur = function ()
    {
      oninput = false;
    }
    document.getElementById('realstock-query2-query').onkeyup = function (ev)
    {
        ev = ev||window.event;
        if(ev.keyCode == 38 || ev.keyCode == 40 )    // key is up or down
        {
            if (currTRs2)
            {
                var newLine = currLine2;
                if(ev.keyCode == 38)
                {
                    if(currLine2 > 0)
                        newLine = currLine2 -1;
                }
                else
                {
                    if(currLine2 < currTRs2.length -1)
                        newLine = currLine2 +1;
                }
                selectChange2(newLine);
            }
        }
        else
        {
            var query =  document.getElementById('realstock-query2-query').value;
            query = query.replace(' ', '');
            if( query == '') 
            {
                document.getElementById('realstock-query2-select').innerHTML = '';
                return;
            }
            var args = {
                method : 'get', onComplete : onSugRecved2
            };
            query = encodeURIComponent(query); 
            query = 'http://simulate.jinku.com/sfquery.php?query=' + query
            var myAjaj = new Ajaj(query, args); 
        }
    }
}
function onSugRecved2(rep, query)
{
    var ret = decodeURIComponent(rep);
    var lines = ret.split('|');
    var query = document.getElementById('realstock-query2-query').value;
    var content = '<table id=\'realstock-query2-select-table\'>'
    for(var i=0; i< lines.length&&i < 10; i++)
    {
        stocks = lines[i].split(';');
        if(stocks.length != 5 )
            continue;
        content += '<tr class=\'realstock-query2-select-unselected\'>';        
        content += '<td width=50px>' + stocks[0] + '</td>' + '<td class=\'hide\'>' + stocks[1] + '</td>' + '<td width=60px>' + stocks[2] + '</td>' + '<td width=55px>' + stocks[3] + '</td>' + '<td class=\'hide\'>' + stocks[4]+ '</td>';
        content += '</tr>';
    }
    
    content += '</table>';
    document.getElementById('realstock-query2-select').innerHTML = content;
    window.setTimeout(selectInit2, 100);
        
}
function selectInit2()
{
    var table = document.getElementById('realstock-query2-select-table');
    if (table)
    {
        if (table.childNodes[0])
        {
            currTRs2 = table.childNodes[0].childNodes;
            selectChange2(0)
            for (var i=0; i< currTRs2.length; i++)
            {
                currTRs2[i].onmouseover = function()
                {
                    var j = 0;
                    for(j =0; j< currTRs2.length; j++)
                    {
                        if(currTRs2[j] == this)
                            break;
                    }
                    selectChange2(j);
                }
                
                currTRs2[i].onclick = function()
                {
                    var j = 0;
                    for(j =0; j< currTRs2.length; j++)
                    {
                        if(currTRs2[j] == this)
                            break;
                    }
                    document.getElementById('realstock-query2-form').submit();
                }
            }
        }
    }    
}

function selectChange2(newLine)
{
    if (currLine2 < 0 || currLine2 > currTRs2.length -1)
        currLine2 = 0;
        
    currTRs2[currLine2].className = "realstock-query2-select-unselected";
    currTRs2[newLine].className = "realstock-query2-select-selected";
    currLine2 = newLine;
    var tds = currTRs2[currLine2].childNodes;      
    var stype = tds[1].innerHTML;
    document.getElementById('realstock-query2-code').name = 'code';
    var nowaction = document.getElementById('realstock-query2-form').action.toString();
    if (nowaction.lastIndexOf("/") > 0){
        nowaction = nowaction.substring(0, nowaction.lastIndexOf("/")+1);
    }else{
        nowaction = "";
    }
    document.getElementById('realstock-query2-code').value = tds[0].innerHTML;
    document.getElementById('realstock-query2-market').value = tds[1].innerHTML;
    document.getElementById('realstock-query2-type').value = tds[4].innerHTML;

}



/////基金查询2
Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		__method.apply(object, arguments);
	}
}
Array.prototype.remove = function(dx) {
	if (isNaN(dx) || dx < 0 || dx > this.length) {
		return false;
	}
	for (var i = 0,
	n = 0; i < this.length; i++) {
		if (this[i] != this[dx]) {
			this[n++] = this[i]
		}
	}
	this.length -= 1
}
Array.prototype.indexOf = function(v, nostrict) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] === v) {
			return i;
		}
		if (nostrict && (this[i] == v)) {
			return i;
		}
	}
	return - 1;
}
Array.prototype.clone = function() {
	var newObj = (this instanceof Array) ? [] : {};
	for (i in this) {
		if (i == 'clone') continue;
		if (this[i] && typeof this[i] == "object") {
			newObj[i] = this[i].clone();
		} else newObj[i] = this[i]
	}
	return newObj;
};
function Round(number, w) {
	var num = number;
	var w10 = 1;
	for (var i = 1; i <= w; i++) {
		w10 *= 10;
	}
	num = Math.round(num * w10) / w10;
	var wdot = num.toString().indexOf(".");
	var NUM = num.toString();
	if (wdot == -1) {
		NUM = NUM + ".";
		wdot = NUM.length - 1;
	}
	if (wdot + w + 1 > NUM.length) {
		for (i = NUM.length; i < wdot + w + 1; i++) NUM = NUM + "0";
	}
	return NUM;
}
//////////////////数字用逗号分隔符
function formatNum(a) {
	var b = parseFloat(a);
	var tempConvert = b.toLocaleString();
	if (tempConvert.charAt(0) == ".") {
		tempConvert = 0 + tempConvert;
	}
	return tempConvert;
} 

//////////////////////几个大盘指数，使用方法：jkIdx = new jkIdxSummary('stock-index-all', 10*1000, '');
function jkIdxSummary(divID, interval, data, realDomain, targetType) {
	this.divID = divID;
	this.interval = interval;
	if (realDomain) this.realDomain = realDomain;
	this.targetType = '_self';
	if (targetType) this.targetType = targetType;
	this._update();
}
jkIdxSummary.prototype._update = function() {
	if (this.data) {
		this._set(this.data);
		this.data = null;
	} else {
		this._refresh();
	}
	window.setTimeout(this._update.bind(this), this.interval);
}
jkIdxSummary.prototype._refresh = function() {
	var args = {
		method: 'get',
		onComplete: function(rep) {
			this._set(rep);
		}.bind(this)
	};
	infoURL = 'http://quote.jinku.com/indexdata.php?cmd=sh000001,sz399001,sh000300|' + Math.random().toString();
	var myAjaj = new Ajaj(infoURL, args);
}
jkIdxSummary.prototype._set = function(dataStr) { //	dataStr2='{"sh000001":[0,1894.61,1896.45,3967113.00],"sh000300":[0,1864.20,1878.31,2832540.25],"sz399001":[0,6763.97,6851.03,2119848.25]}';
	var retObj = dataStr.parseJSON(); //  alert(dataStr);             
	var div = '';
	var color = 'nocolor';
	if (retObj['sh000001'][2] > retObj['sh000001'][1]) color = 'incolor';
	if (retObj['sh000001'][2] < retObj['sh000001'][1]) color = 'decolor';
	var urlPrefix = '';
	if (this.realDomain) {
		urlPrefix = 'http://quote.jinku.com/';
	}
	div += '<b>上证综指</b> <font class=\'' + color + '\'>' + retObj['sh000001'][2].toFixed(2) + '</font> <font class=\'' + color + '\'>' + ((retObj['sh000001'][2] - retObj['sh000001'][1]) * 100 / retObj['sh000001'][1]).toFixed(2) + '%' + '</font> ' + Round(retObj['sh000001'][3] / 10000, 2) + '亿元';
	color = 'nocolor';
	if (retObj['sz399001'][2] > retObj['sz399001'][1]) color = 'incolor';
	if (retObj['sz399001'][2] < retObj['sz399001'][1]) color = 'decolor';
	div += ' | <b>深证成指</b> <font class=\'' + color + '\'>' + retObj['sz399001'][2].toFixed(2) + '</font> <font class=\'' + color + '\'>' + ((retObj['sz399001'][2] - retObj['sz399001'][1]) * 100 / retObj['sz399001'][1]).toFixed(2) + '%' + '</font> ' + Round(retObj['sz399001'][3] / 10000, 2) + '亿元';
	color = 'nocolor';
	if (retObj['sh000300'][2] > retObj['sh000300'][1]) color = 'incolor';
	if (retObj['sh000300'][2] < retObj['sh000300'][1]) color = 'decolor';
	div += ' | <b>沪深300</b> <font class=\'' + color + '\'>' + retObj['sh000300'][2].toFixed(2) + '</font> <font class=\'' + color + '\'>' + ((retObj['sh000300'][2] - retObj['sh000300'][1]) * 100 / retObj['sh000300'][1]).toFixed(2) + '%' + '</font> ' + Round(retObj['sh000300'][3] / 10000, 2) + '亿元';
	document.getElementById(this.divID).innerHTML = div;
} 
////////////////////////////////////////////////////////////////////////////////////lib
if (!Object.prototype.toJSONString) {
	Array.prototype.toJSONString = function() {
		var a = ['['],
		b,
		i,
		l = this.length,
		v;
		function p(s) {
			if (b) {
				a.push(',');
			}
			a.push(s);
			b = true;
		}
		for (i = 0; i < l; i += 1) {
			v = this[i];
			switch (typeof v) {
			case 'object':
				if (v) {
					if (typeof v.toJSONString === 'function') {
						p(v.toJSONString());
					}
				} else {
					p("null");
				}
				break;
			case 'string':
			case 'number':
			case 'boolean':
				p(v.toJSONString());
			}
		}
		a.push(']');
		return a.join('');
	};
	Boolean.prototype.toJSONString = function() {
		return String(this);
	};
	Date.prototype.toJSONString = function() {
		function f(n) {
			return n < 10 ? '0' + n: n;
		}
		return '"' + this.getFullYear() + '-' + f(this.getMonth() + 1) + '-' + f(this.getDate()) + 'T' + f(this.getHours()) + ':' + f(this.getMinutes()) + ':' + f(this.getSeconds()) + '"';
	};
	Number.prototype.toJSONString = function() {
		return isFinite(this) ? String(this) : "null";
	};
	Object.prototype.toJSONString = function() {
		var a = ['{'],
		b,
		k,
		v;
		function p(s) {
			if (b) {
				a.push(',');
			}
			a.push(k.toJSONString(), ':', s);
			b = true;
		}
		for (k in this) {
			if (this.hasOwnProperty(k)) {
				v = this[k];
				switch (typeof v) {
				case 'object':
					if (v) {
						if (typeof v.toJSONString === 'function') {
							p(v.toJSONString());
						}
					} else {
						p("null");
					}
					break;
				case 'string':
				case 'number':
				case 'boolean':
					p(v.toJSONString());
				}
			}
		}
		a.push('}');
		return a.join('');
	}; (function(s) {
		var m = {
			'\b': '\\b',
			'\t': '\\t',
			'\n': '\\n',
			'\f': '\\f',
			'\r': '\\r',
			'"': '\\"',
			'\\': '\\\\'
		};
		s.parseJSON = function(filter) {
			try { //alert(filter);
				if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(this)) {
					var j = eval('(' + this + ')');
					if (typeof filter === 'function') {
						function walk(k, v) {
							if (v && typeof v === 'object') {
								for (var i in v) {
									if (v.hasOwnProperty(i)) {
										v[i] = walk(i, v[i]);
									}
								}
							}
							return filter(k, v);
						}
						j = walk('', j);
					}
					return j;
				}
			} catch(e) {}
			throw new SyntaxError("parseJSON");
		};
		s.toJSONString = function() {
			if (/["\\\x00-\x1f]/.test(this)) {
				return '"' + this.replace(/([\x00-\x1f\\"])/g,
				function(a, b) {
					var c = m[b];
					if (c) {
						return c;
					}
					c = b.charCodeAt();
					return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
				}) + '"';
			}
			return '"' + this + '"';
		};
	})(String.prototype);
}

	function ajax(url, cid) {
		var hot = $(cid);
		$.ajax({
			type:"GET",
			url:url,
			cache:false,
			beforeSend:function(){
				hot.html('<img src="/templet/images/loading.gif" />');		
			},
			success:function(msg){
				hot.html(msg);	
			}
		});		
	}
