﻿function H$(i) {return document.getElementById(i)}
function H$$(c, p) {return p.getElementsByTagName(c)}
var scrollDiv = function () {
 function init (o) {
  this.id = o.id;
  this.at = o.auto ? o.auto : 3;
  this.o = 0;
  this.pos();
 }
 init.prototype = {
  pos : function () {
   clearInterval(this.__b);
   this.o = 0;
   var el = H$(this.id), li = H$$('li', el), l = li.length;
   var _t = li[l-1].offsetHeight;
   var cl = li[l-1].cloneNode(true);
   cl.style.opacity = 0; cl.style.filter = 'alpha(opacity=0)';
   el.insertBefore(cl, el.firstChild);
   el.style.top = -_t + 'px';
   this.anim();
  },
  anim : function () {
   var _this = this;
   this.__a = setInterval(function(){_this.animH()}, 20);
  },
  animH : function () {
   var _t = parseInt(H$(this.id).style.top), _this = this;
   if (_t >= -1) {
    clearInterval(this.__a);
    H$(this.id).style.top = 0;
    var list = H$$('li',H$(this.id));
    H$(this.id).removeChild(list[list.length-1]);
    this.__c = setInterval(function(){_this.animO()}, 20);
    //this.auto();
   }else {
    var __t = Math.abs(_t) - Math.ceil(Math.abs(_t)*.07);
    H$(this.id).style.top = -__t + 'px';
   }
  },
  animO : function () {
   this.o += 2;
   if (this.o == 100) {
    clearInterval(this.__c);
    H$$('li',H$(this.id))[0].style.opacity = 1;
    H$$('li',H$(this.id))[0].style.filter = 'alpha(opacity=100)';
    this.auto();
   }else {
    H$$('li',H$(this.id))[0].style.opacity = this.o/100;
    H$$('li',H$(this.id))[0].style.filter = 'alpha(opacity='+this.o+')';
   }
  },
  auto : function () {
   var _this = this;
   this.__b = setInterval(function(){_this.pos()}, this.at*1000);
  }
 }
 return init;
}();

function f_ChangeNewsList(m,q,count){
    for(var i=1;i<=count;i++){
	    if (i==q){
		    $("#tab_"+m+"_"+i).css("display","block");
		    $("#"+m+"_"+i).attr("class", "on");
		    if(m==2){
		        if(q==1){$("#showMore2")[0].href="http://zixun.wlstock.com/002004.aspx";}
                else{$("#showMore2")[0].href="http://zixun.wlstock.com/002005.aspx";}
		    }
		    else if(m==3){
		        if(q==1){$("#showMore3")[0].href="http://www.wlstock.com/TouZi/index.aspx";}
                else{$("#showMore3")[0].href="http://www.wlstock.com/chaogu";}
		    }
		}
	    else{	
		    $("#tab_"+m+"_"+i).css("display","none");		
		    $("#"+m+"_"+i).removeClass("on");		
		}		
    }
}

//加载行情图
function f_LoadPriceImage(){
    TabsUtil.Init("divPriceImage", 0);
    $("#divPriceImage").tabs("option", "event", "mouseover");
    $("#divPriceImage").bind("tabsselect", function(event, ui) {
        $("#divPriceImage").find("ul li").each(function() {
            $(this).removeClass("on");
        });
        if(ui.index==0){$(ui.tab).parent().attr("class", "on star");}
        else{$(ui.tab).parent().attr("class", "on");}
    });
}

//清空文本框
function f_SetEmpty(obj){
    obj.value="";
}

//验证股票代码或名称
function f_StockSearch(textId,urlType){
    var text=$("#"+textId).val();
    if(text==""||text=="输入股票代码/名称"){
        alert("请输入股票代码或名称！");
        return;
    }
    $.post('/AjaxPage/Public/Stock.aspx', { Stock:text,Oper:"StockExists"},
        function(val){
            var stock = eval("("+val+")");
            var obj=stock.res;
            var stockNo=stock.des;
            if(obj==true){ 
                var url="";
                if(urlType==0){    //个股
                    url="http://hudong.wlstock.com/Stockbar/"+stockNo+".aspx";
                }
                if(urlType==1){    //龙虎榜
                    url="http://hudong.wlstock.com/HuDong/TopStock.aspx?StockNo="+stockNo;
                }
                else if(urlType==2){   //主力资金动向
                    url="http://hudong.wlstock.com/HuDong/StockMoneyFlow.aspx?StockNo="+stockNo;
                }
                window.open(url);
            }
            else{
                alert("您输入的股票代码或名称不正确！");
                return;
            }
        }
    );
}

//博弈周刊订阅
function f_OrderWeekly(){
    var validate = auto_check_form([["txtEmail", "请填入您的邮箱","check"],
                            ["txtEmail", "您输入的邮箱格式不正确","email"]]);
    if(!validate){return;}
    $.get('/AjaxPage/Public/CheckIsLogin.aspx',
        function(val){
            if(val=="0"){
                window.location="http://www.wlstock.com/Register/Login.aspx";
            }
            else{
                alert("订阅成功！");
            }
        }
    );
}

//网友预测
function f_GetStockForecast(){
    $.get('/AjaxPage/Index/GetStockForecastAjax.aspx',{date:new Date()},
        function(val){
            if(val!=""){
                $("#divStockForecast").html(val);
            }
        }
    );
}

//鼠标在向上按钮时的效果
function up(){
    var obj= document.getElementById("divStockForecast");
    var height = obj.style.height.replace("px","");
    var count = obj.scrollTop;
    if(count > 0){
        obj.scrollTop=obj.scrollTop-25;
    }
}
//鼠标在向下按钮时的效果
function down(){
    var obj= document.getElementById("divStockForecast");
    var height = obj.style.height.replace("px","");
    var count = obj.scrollTop;
    if(count<height + 50){
        obj.scrollTop=obj.scrollTop+25;
    }
}

//加载新闻详细页
function f_NewsDetailLoad(newsId){
    f_GetNewsReply(newsId);
    TabsUtil.Init("tabs", 0);
    f_LoadPriceImage();
    $("#tabs").bind("tabsselect", function(event, ui) {
        $("#artTab").find("li").each(function() {
            $(this).find("span").removeClass("TabOn");
        });
        $(ui.tab).find("span").attr("class", "TabOn");
        if(ui.index > 0){
            var stock=$("#hiStock").val();
            $("#divNewsPrice").load("/YanJiu/NewsPrice.aspx",{Stock:stock})
        }
    });
    DialogUtil.Init("divEmail","showDiv",800,500,true,"发送到Email");
    $.get('/AjaxPage/News/GetReplyCountAjax.aspx',{NewsId:newsId},
        function(val){
            if(val!=""){
                $("#lblReplyNum").html(val);
                $("#lblReplyNum1").html(val);
            }
        }
    );
    $.get('/AjaxPage/News/GetClickNumber.aspx',{NewsId:newsId,date:new Date()});
}

//最新的加载新闻详细页
function f_DetailLoad(newsId){
    f_GetNewsReply(newsId);
    var stock=$("#hiStock").val();
    $("#tab_1_2").load("/YanJiu/NewsPrice.aspx",{Stock:stock})
    $.get('/AjaxPage/News/GetReplyCountAjax.aspx',{NewsId:newsId},
        function(val){
            if(val!=""){
                $("#lblReplyNum").html(val);
                $("#lblReplyNum1").html(val);
            }
        }
    );
    $.get('/AjaxPage/News/GetClickNumber.aspx',{NewsId:newsId,date:new Date()});
    
    $.get('/AjaxPage/Public/CheckIsLogin.aspx',{date:new Date()},
        function(val){
            if(val!="" && $("#divIsLogin").length>0){
                $("#divIsLogin")[0].style.display= val=="1"?"none":"";
            }
        }
    );
}

//切换行情
function f_TahChange(m, q, count) {
    for (var i = 1; i <= count; i++) {
        if (i == q) {
            $("#tab_" + m + "_" + i).css("display", "block");
            $("#" + m + "_" + i).attr("class", "on");
        }
        else {
            $("#tab_" + m + "_" + i).css("display", "none");
            $("#" + m + "_" + i).removeClass("on");
        }
    }
}

//切换行情
function f_GetNewsPrice(m,q,count){
    for(var i=1;i<=count;i++){
	    if (i==q){
		    $("#tab_"+m+"_"+i).css("display","block");
		    $("#"+m+"_"+i).attr("class", "TabOn");
		}
	    else{	
		    $("#tab_"+m+"_"+i).css("display","none");		
		    $("#"+m+"_"+i).removeClass("TabOn");		
		}		
    }
}

//切换排行榜
function f_GetRank(m,q,count){
    for(var i=1;i<=count;i++){
	    if (i==q){
		    $("#tab_"+m+"_"+i).css("display","block");
		    if(q==1){$("#"+m+"_"+i).attr("class", "on star");}
            else{$("#"+m+"_"+i).attr("class", "on");}
		}
	    else{	
		    $("#tab_"+m+"_"+i).css("display","none");		
		    $("#"+m+"_"+i).removeClass("on");		
		}		
    }
}

//加载原创新闻
function f_OriNewsLoad(newsId){
    f_NewsDetailLoad(newsId);
    $("#divBehaviorVote").load("/ZiXun/BehaviorVote.aspx");
}

//最新的加载原创新闻
function f_OriDetailLoad(newsId){
    f_DetailLoad(newsId);
    $("#divBehaviorVote").load("/ZiXun/BehaviorVote.aspx");
}

//得到新闻评论
function f_GetNewsReply(newsId){
    $.get("/AjaxPage/News/GetReplyAjax.aspx",{NewsId:newsId,date:new Date()},
        function(val){
            if(val!=""){
                $("#divReply").html(val);
            }
        }
    );
}

//显示或隐藏divEmail
function f_ShowEmailDiv(){
    var obj=$("#divEmail")[0];
    if(obj.style.display=="none"){
        obj.style.display="";
    }
    else{
        f_HideDiv();
    }
}

//发送邮件
function f_SendEmail(){
    var validate=auto_check_form([["txtToEmail", "输入邮箱帐号","check"],
                            ["txtToEmail", "您输入的邮箱账号格式不正确","email"],
                            ["txtTitle", "请输入标题","check"],
                            ["txtTitle", "请输入正文内容","check"]]);
    if(!validate){
        return;
    }
    var email=$("#txtToEmail").val();
    var title=$("#txtTitle").val();
    var content=$("#txtContent").val();
    $.get("/AjaxPage/News/SendEmail.aspx",{ToEmail:email,Title:title,Content:content,date:new Date()},
        function(val){
            if(val=="1"){
                f_HideDiv();
                alert("发送成功，请注意查收！");
            }
            else{
                alert("发送失败！");
            }
        }
    );
}

function f_Hide(){  
    $("#divEmail").dialog("close");
}

function f_HideDiv(){  
    $("#divEmail").css("display","none");
}

//打印
function f_Print() 
{
    window.print();
}

//五星级股票池
function f_LinkMyWlStock(){
    $.get('/AjaxPage/Public/CheckIsLogin.aspx',
        function(val){
            if(val=="0"){
                window.location="http://www.wlstock.com/Register/Login.aspx";
            }
            else{
                window.location="http://fuwu.wlstock.com";
            }
        }
    );
}
