﻿
/*Cookie 增、删、查操作*/
var my = ["mystock", "dde_mystock", "table_style"];
function pd(v) { return v == "undefined" || v == null || v == "" || v == "null"; }
function op(v){if(arguments[1]) window.location.href=v; else window.open(v);}
function setC(n, v) {
    var exp = new Date(), t = arguments[2] || 30;
    exp.setTime(exp.getTime() + t * 24 * 60 * 60 * 1000);
    document.cookie = n + "=" + escape(v) + ";expires=" + exp.toGMTString();
}
function getC(n) {
    var arr = document.cookie.match(new RegExp("(^| )" + n + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}

function delC(n) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getC(n);
    if (cval != null) document.cookie = n + "=" + cval + ";expires=" + exp.toGMTString();
}
function getNewSubmitForm(method) {
    var submitForm = document.createElement("FORM");
    document.body.appendChild(submitForm);
    submitForm.method = method;
    return submitForm;
}
function createFormElement(inputForm, elementName, elementValue) {
    var newElement = document.createElement("<input name='" + elementName + "' type='hidden'>");
    inputForm.appendChild(newElement);
    newElement.value = elementValue;
    return newElement;
}

function Msg(){
    var oW = window;
    if(this.status) oW=this;
    if(this.obj && this.obj.status)
      oW = this.obj;
    oW.status = Array.apply(null,arguments).join(this.separator || "");
    !g_bDebugFlag || alert(oW.status);
  }
  function $id(o) { return (typeof o == "object") ? o : document.getElementById(o); }
  function I() { var a = arguments; if (a.length == 4) $id(a[0]).getElementsByTagName(a[3])[a[1]].className = a[2]; else if (a.length == 5) $id(a[0]).getElementsByTagName(a[3])[a[1]].getElementsByTagName(a[4])[0].className = a[2]; }
  function setTmpNav(i) { I("temp_nav", i, "b1", "a"); }
  var ML = new Array(10, 20, 50, 200, 10, 300, 0, 0, 400, 450, 500, 225);
  var news = new Array(3, 23, 22, 21, 20, 17);
  

//================= by shuaishuai 2010-03-13 start==============
$(function(){
	$('#menu > a').each(function(i){
	    
	    $(this).mouseover(function(){
	         //全部设置为隐藏
		 $('#nav').show();
	         $('#nav > div').each(function(i){
	            $(this).hide();
	         });
		 
	         $('#chdmenu_'+i).show();
		 var have = false;
		 $('#chdmenu_'+i +' > a').each(function(j){
			have = true; 
			
		 });
		 if(!have){
			$('#nav').hide();
		 }
		 
	    });
	});
});

function setMenu(index,chdindex){
    if(index==0){
	index = 1;
    }else if(index==1){
	 index = 12;
    }
    $('#menu > a').each(function(i){
	    if(index-1==i){
            	$(this).attr('class','v12');
            	//全部设置为隐藏
            	$('#nav > div').each(function(i){
                	$(this).hide();
            	});
		$('#chdmenu_'+i).show();
		var have = false;
		$('#chdmenu_'+i +' > a').each(function(j){
			have = true; 
			
		});
		if(!have){
			$('#nav').hide();
		}
		
            	
		$('#chdmenu_'+i +' > a').each(function(k){
			if(chdindex){
				if(chdindex==k){
					$(this).attr('class','m1');
				}
			}else{
				if(k==0){
					$(this).attr('class','m1');
					;return;
				}
			}
		});
	    }else{
	        $(this).attr('class','');
            //全部设置为隐藏
	    }
	});
}
//================= by shuaishuai 2010-03-13 end==============









function setMenu1(i) {
      i=i-1;
	if(i==-1){ i=0;}
      if (i >= 11 || typeof i == "undefined") return;      
      
      I("menu", i, "v12", "a");
      var d = "men_" + i, s = arguments[1] || 0;
      if ($id(d)) {
          $id(d).className = "nav-w2";
          $id(d).style.marginLeft = ML[i] + "px";
          I(d, s, "m1", "a");
      } else {
          $id("nav").style.display = "none";
      }
  }
  var bi=[];
  function movMenu() {
      var i = arguments[0] || 0, ma = $id("menu").getElementsByTagName("a"); 
      bi[0]=0;
      for (var j = 0; j < ma.length; j++) {
          if (ma[j].className == "v12" &&j!=i) {
              bi[1] = j;
              ma[j].className = "";//
              if ($id("men_" + j)) {
                  bi[0] = 1;
                  $id("men_" + j).className = "nav-w1";
                  var sma = $id("men_" + j).getElementsByTagName("a");
                  for (var k = 0; k < sma.length; k++)
                      if (sma[k].className == "m1")
                        { bi[2] = k; break; }
              }
              break;
          }
      }
      setMenu(j==ma.length?j:i);
  }
  
  function motMenu() {      
      var i = arguments[0] || 0;
      var ma = $id("menu").getElementsByTagName("a");
      for (var j = 0; j < ma.length; j++) {
          if (ma[j].className == "v12" && bi[1] < 12) {
            ma[j].className="";
            if($id("men_"+j)){
                $id("men_" + j).className = "nav-w1";
                $id("nav").style.display = bi[0]==1?"":"none";
            }
            break;
        }
      }
      setMenu(bi[1],bi[2]);
  }
  function evtMenu(i) {
        
      setTimeout("motMenu(i)",1000);
  }

/*
  function testBind(i) {
          this.over=function(){
            alert("您点击了第 "+(i+1)+"个A");
          }
  }
  window.onload = function() {
      var list = $id("menu").getElementsByTagName("a");
      for (var i = 0; i <= list.length; i++) {
//          if (document.all) list_obj[i].attachEvent("onmouseover", testBind);
//          else list_obj[i].addEventListener("mouseover", testBind, false);
          var c = new testBind(i);
            if(document.all)   list[i].attachEvent("onmouseover",c.over);
      }
  }
  */
var channelUrl=["/dde/@.htm","/dde/analy-@.htm","/superview/@.htm","/ccfx/@.htm","/cccb/@.htm"];
  function cgeTopHotStock() {
      try {      
            var ai = arguments[0]||0;                        
          var hst = hot[ai][0].split(";", 8);
          var str = "";
          for (var i = 0; i < hst.length; i++) {
              var shst = hst[i].split(",", 2);
              if (!pd(shst)) {
                  str += ("<a href=\"" +channelUrl[ai].replace("@", shst[0]) + "\" target=\"_blank\">" + shst[1] + "</a> ");
              }
          }
          $id("top_hot").innerHTML = "<b>热门搜索：<\/b>" + str;
      } catch (e) { }
  }
  function cgeSearch(ix){
      var a = arguments[1] || 0;
      var el = $id("top_search_" + a).getElementsByTagName("li");
      for (var i = 0; i < el.length; i++) {
        if(ix==i)       el[i].getElementsByTagName("a")[0].className="v-top";  else el[i].getElementsByTagName("a")[0].className="";
    }
    cgeTopHotStock(ix);
  }
  function A(){
    var a=arguments;
    for(var i=0;i<a[2];i++){
      if(i==a[1]){
        $id("a_"+a[0]+i).className=a[3];
        $id("ul_"+a[0]+i).style.display="";
        if(a.length==6) $id("m_"+a[0]).href=a[5];
      }else{
        $id("a_"+a[0]+i).className=a[4];
        $id("ul_"+a[0]+i).style.display="none";
      }
    }
  }


function _A(){
var a=arguments;
  if(a.length==4)
    A(a[0],a[1],a[2],"v1","",a[3]);
  else
    A(a[0],a[1],a[2],"v1","");
}
function _A2(){
var a=arguments;
  if(a.length==4)
    A(a[0],a[1],a[2],"v3","",a[3]);
  else
    A(a[0],a[1],a[2],"v3","");
}

function _A5(tableid,x){
    var t=$id("ul_"+tableid);
    
    for(var i=1;i<t.rows.length;i++){
        if(i<=((x+1)*10) && i>=(x*10+1))
            t.rows[i].style.display="";
        else    t.rows[i].style.display="none";
    }
    var c=t.getElementsByTagName("table")[0].getElementsByTagName("td");
    for(var j=0;j<c.length;j++)
        c[j].className=(j==x?"dq":"");    
}

function drop_mouseover(pos){
	try{window.clearTimeout(timer);}catch(e){}
}
function drop_mouseout(pos){
	var posSel=document.getElementById(pos+"Sel").style.display;
	if(posSel=="block"){
		timer = setTimeout("drop_hide('"+pos+"')", 1000);
	}
}
function drop_hide(pos){
	document.getElementById(pos+"Sel").style.display="none";
}
function search_show(type,href){
    //    document.getElementById(pos+"SearchType").value=searchType;
    
    $id("headSel").style.display = "none";
    $id("headSlected").innerHTML = href.innerHTML;
    for (var i = 0; i < 3; i++) {
        if (type == i) { $id("top_search_" + i).style.display = "";cgeSearch(0,type); }
        else $id("top_search_" + i).style.display = "none";
    }
//    document.getElementById(pos+'q').focus();
//    var sE = document.getElementById("searchExtend");
//    if(sE != undefined && searchType == "bar"){
//    	sE.style.display="block";
//    }else if(sE != undefined){
//    	sE.style.display="none";
//    }
//	try{window.clearTimeout(timer);}catch(e){}
//	return false;
}


function change() {
    
    if (document.all) {
        var oObj = event.srcElement;
        if (oObj.tagName.toLowerCase() == "td") {
            var oTr = oObj.parentNode;
            oTr.className = (oTr.className.toLowerCase() == "heng") ? "" : "heng";
            oTr.tag = (oTr.tag == true) ? false : true;
        }
    } else {
    alert(oObj.tagName);
    }
}

function out() {
   
    if (document.all) {
        var oObj = event.srcElement;
        if (oObj.tagName.toLowerCase() == "td") {
            var oTr = oObj.parentNode;
            if (!oTr.tag)
                oTr.className = "";
        }
    } else {

    }

}

function over() {
    
    if (document.all) {
        var oObj = event.srcElement;      
        if (oObj.tagName.toLowerCase() == "td") {
            var oTr = oObj.parentNode;
            if (!oTr.tag)
                oTr.className = "outheng";
        }
    } else {
        
    }
}


function dosearch(){
    var ki = 0,uid=0,url="";
    for (var i = 0; i < 3; i++) {
        if ($id("top_search_" + i).style.display != "none") {uid = i;break;}
    }
    var el = $id("top_search_" + uid).getElementsByTagName("li");
    for (var i = 0; i < el.length; i++) {
        if (el[i].getElementsByTagName("a")[0].className == "v-top") {          ki = i; break;        }
    }
    var code = $id("c_stockcode").value;
    if (uid == 0) {
        try{        
            op(channelUrl[ki].replace("@", code));
           }catch(e){
           alert(e);
           op("/dde/"+code+".htm")
        }
    } else if (uid == 1) {url="http://www.538538.com/";
        switch (ki) {
            case 0:op(url+"Stock---"+code+".html"); break;
            case 1:op(url+"Stock_4---"+code+"---149.html");break;
            case 2:op(url+"Stock_4---.html"+code+"---351.html"); break;
            case 3:op(url+"Stock_Code_Total---"+code+"---474.html"); break;
            case 4:op(url+"Stock_4---"+code+"---354.html");break;
        }
    } else if (uid == 2) {url="http://www.guge.cc/";
    switch (ki) {
        case 0:op(url+"history-"+code+".html"); break;
        case 1:op(url+"now-"+code+".html"); break;
        case 2:op(url+"zjfx-"+code+".html"); break;
        case 3:op(url+"zldx-"+code+".html"); break;
        case 4:op(url+"zjfx-"+code+"2.html"); break;
    }
    }
    
}

function defaultStocklist(tid){
    var des=arguments[1]||"股票代码/拼音/名称";
    window.suggestStock_top = new Suggest(tid, des, ["/themes/2009/js/stocklist_A.js"], ["stocka_suggest"], StockSuggestConfiguration, null, [200, 800, 0.95, "solid", "#EEE", "#FFF", 3, 3, 0.2, "#000", "#444", "#F1F5FC", false]);
}



function addFav(stock) {
    if (MK == 4) {
        delFav(stock);
        return;
    }
    var tc = getC(my[1]);    
    if (!pd(stock) || tc.indexOf(stock) == -1) {
        setC(my[1], tc + "," + stock);
        alert(stock + " 关注股添加成功！");
        return;

    } else {
        alert(stock + " 已存在的自选股"); return false;
    }

}

function delFav(stock) {
    var tc = getC(my[1]);
    if (tc.indexOf(stock) == -1) {
        alert("删除失败！自选股中不存在该只股票！");
        return false;
    } else {
        var arr = tc.split(",");
        var tmp = "";
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] != stock) tmp += arr[i] + ",";
        }
        setC(my[1], tmp);
        //alert($.cookie(my_cook));
        alert("删除自选股成功！");
        //window.location.reload();
        return;
    }
}

function clearFav() {
    try {
        setC(my[1], "");
        alert("自选股清除成功！");
        return;
    } catch (e) { alert(e); }
}


function K(mk) {            
    var tf = getNewSubmitForm("POST");
    switch (mk) {
        case -1: createFormElement(tf, "mk", mk); createFormElement(tf, "c", arguments[1]);
            createFormElement(tf, "s", SORT == 1 ? 0 : 1);
            break;
        case -2: createFormElement(tf, "mk", mk);
            createFormElement(tf, "p", arguments[1]);
            createFormElement(tf, "c", COL);
            createFormElement(tf, "s", SORT); 
            break;
        case -3:
            var tsk = $id("stocks").value;
            if (pd(tsk) || tsk == "股票代码/拼音") { alert("请输入正确的股票代码！"); return; }
            var mc = getC(my[1]);
            //if (pd(mc)) { 
		//setC(my[1], tsk);  
	   //}else { 
		//setC(my[1], mc + "," + tsk);
	   //}
            createFormElement(tf, "my", tsk);
            createFormElement(tf, "mk", 4);
            break;
        case 4: var mc = getC(my[1]);            
            if (pd(mc)) {
                confirm("您的关注股为空，是否现在添加关注股？\n操作帮助：\n1、通过点击股票名称前的序号添加关注股\n2、在关注股中点击序号删除这支股票\n3、点击标题头\"序号\"清空关注股");
                return;
            }
            createFormElement(tf, "my", mc);
            flag = true;
            break;
    }
    document.body.appendChild(tf);
    tf.action = "";
    tf.submit();
}


function cgeTabStyle(v) {
    if (!pd(v)) setC(my[2], v,60);
    var t = getC(my[2]);    
    $id("cont_table").className = (pd(t)||t==1 ? "dde-list1" : "dde-list");
    $id(my[2]).selectedIndex = (pd(t)||t==1?0:1);
}


//更改字体大小
var curfontsize = 12;
var curlineheight = 15;
function fontZoomA() {
    if (curfontsize > 8) {
        $id('news_content').style.fontSize = (--curfontsize) + 'px';
        $id('news_content').style.lineHeight = (--curlineheight) + 'px';
    }
}
function fontZoomB() {
    if (curfontsize < 64) {
        $id('news_content').style.fontSize = (++curfontsize) + 'px';
        $id('news_content').style.lineHeight = (++curlineheight) + 'px';
    }
}

function bigimg(obj) {   
    var p=obj.src;
    if(p!="")
    {
        var divtemp = $id('divtemp'),divimg=$id("divimg");
        divtemp.style.width=document.body.clientWidth;
        divtemp.style.height=document.body.scrollHeight;
        divtemp.style.display ="block";
        divimg.innerHTML ="<img onclick='hidediv()' width='1024px' height='768px' style='cursor:hand' src='"+p+"' />";
        var k = getposi(obj);
        divimg.style.top = k.top;
        divimg.style.left = k.left;
        divimg.style.display = "";
    }
}
function getposi(element) 
{ 
    
    if (arguments.length != 1 ||element == null ) 
    { 
        return null; 
    } 
    var offsetTop = element.offsetTop; 
    var offsetLeft = element.offsetLeft; 
    var offsetWidth = element.offsetWidth; 
    var offsetHeight = element.offsetHeight,divimg=$id("divimg"); 
    while( element = element.offsetParent ) 
    { 
        offsetTop += element.offsetTop; 
        offsetLeft += element.offsetLeft;
    }
    return {top:offsetTop,left:offsetLeft-50};
//    divimg.style.top = offsetTop;
//    divimg.style.left=offsetLeft-50;  
//    divimg.style.display="";  
}
function hidediv()
{
    $id("divtemp").style.display="none";  
    $id("divimg").style.display="none";
}
function cacheStock(code,name,type){
  var ts=getC(my[0]);
  if(pd(ts)) setC(my[0],code+","+name+","+type);
  else {
    if(ts.indexOf(code)==-1)    
         setC(my[0],ts+"`"+code+","+name+","+type);         
   }
  }
function initmystock(){//alert(getC(my[0]));alert(my[0]);
var t="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table-list\">",c = getC(my[0]);
//alert(getC(my[0]));
    if(pd(c)) t +="<tr><td>没有您的最近记录</td></tr>";
    else{
        var s=c.split("`");
        for(var i=c.length-1,j=0;i>=0;i--,j++){
            if(j>19) break;
            if(pd(s[i])) continue;
            var codes=s[i].split(",");
            if(pd(codes[0])) continue;
            t +=(j==0?"<tr>":j%2==0?"</tr><tr>":"");
            t+=("<td align=\"center\" bgcolor=\"\"><a href=\""+channelUrl[codes[2]].replace("@",codes[0])+".html\" target=_blank>["+codes[0]+"]"+codes[1]+"</a><IMG title=\"删除\" onclick=\"\"  class=\"del\" /></td>");
        }               
    }
    t+=("</table>");
     $id("ul_5_1").innerHTML=t; 
}
function Lookmystock(){

$id("ul_5_0").style.display="none";
$id("a_5_0").className="";
    initmystock();
    $id("ul_5_1").style.display="";
    $id("a_5_1").className="v3";
}

