﻿//======================================google统计使用代码===========================================================
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-10207856-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//========================================google统计使用代码=========================================================


//AJAX辅助函数

//AJAX POST方式调用
function AjaxPostCall(onload,url,params)
{
    new net.ContentLoader(onload,url,"POST",params);
}

function AjaxGetCall(onload,url,params)
{
    new net.ContentLoader(onload,url,"GET",params);
}

//----------------------获取地址栏中的参数的值-----------------------
 function getParamByUrl(queryStringName)
 { 
    var returnValue=""; 
    var URLString=new String(document.location);
    var serachLocation=-1; 
    var queryStringLength=queryStringName.length; 
    do { serachLocation=URLString.indexOf(queryStringName+"\="); 
     if (serachLocation!=-1) 
         { if ((URLString.charAt(serachLocation-1)=='?') || (URLString.charAt(serachLocation-1)=='&')) 
             { URLString=URLString.substr(serachLocation); break; } URLString=URLString.substr(serachLocation+queryStringLength+1); }  } 
             while (serachLocation!=-1) 
     if (serachLocation!=-1)
         { var seperatorLocation=URLString.indexOf("&");
             if (seperatorLocation==-1) { returnValue=URLString.substr(queryStringLength+1); } 
             else { returnValue=URLString.substring(queryStringLength+1,seperatorLocation); }  } 
     return returnValue;
}

function classpage(type)
{
    var url="../Data/Blog/SelectClassGroup.ashx";
    var gourl="Class.aspx";
    var uid = getParamByUrl("uid");
    if(type==0)
    {
        url="Data/Blog/SelectClassGroup.ashx";
        gourl="Blog/Class.aspx";
            AjaxPostCall(function(){
                var result = this.req.responseText;
                uid = result;
                
                AjaxPostCall(function(){
                    var result = this.req.responseText;
                    var schoolid = result.split('|')[0]; 
                    var classid = result.split('|')[1]; 
                    window.location.href=""+gourl+"?classid="+classid+"&schoolid="+schoolid+"&uid="+uid;
                     
                },
                url,
                "operate=getclassid&uid="+uid
                );
                
            },
            'Data/User/SelectUserInfo.ashx',
            "operate=getSession"
            );
    } else {
    
            AjaxPostCall(function(){
                var result = this.req.responseText;
                var schoolid = result.split('|')[0]; 
                var classid = result.split('|')[1]; 
                window.location.href=""+gourl+"?classid="+classid+"&schoolid="+schoolid+"&uid="+uid;
                 
            },
            url,
            "operate=getclassid&uid="+uid
            );
    }
    
    

 
}

//带参数的地址转向
function urlgo(url)
{
    var obj = url.indexOf("?") != "-1"?"&":"?";
    window.location.href=url+obj+"uid="+getParamByUrl("uid");
}
//以SESSION为参数的地址转向
function urlsession(url)
{
    var obj = url.indexOf("?") != "-1"?"&":"?";
    
    AjaxPostCall(function(){
        var result = this.req.responseText;
        window.location.href=url+obj+"uid="+result;
    },
    '../Data/User/SelectUserInfo.ashx',
    "operate=getSession"
    );
}
//不带SESSION的地址转向
function urlnosession()
{
    AjaxPostCall(function(){
        var result = this.req.responseText;
        if(result == "" || result == null)
        {
            window.location.href="../login.aspx";
        }
    },
    '../Data/User/SelectUserInfo.ashx',
    "operate=getSession"
    );
}

//------------------------------控制图片比例--------------------------------------
 function proDownImage(ImgD, proMaxWidth, proMaxHeight)
{ 　　　

    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0)
    { 　　　
        var rate = (proMaxWidth/image.width < proMaxHeight/image.height)?proMaxWidth/image.width:proMaxHeight/image.height;
 　     if(rate <= 1)
        {
            ImgD.width = image.width*rate;
            ImgD.height =image.height*rate;
        }
        else 
        {
            ImgD.width = image.width; 
            ImgD.height =image.height;
        } 　　　
    }
}

//搜索学生
function searchstudent()
{
    var param = $("#txtSearch").val();
    if(param=="" || param==null)
    {
        param = "";
    }
    window.location.href="../Blog/MySpace_FindFirends.aspx?uid="+getParamByUrl("uid")+"&operate=all&search="+param;

}




function getMyClassUrl()
{
    AjaxPostCall(function(){
        var result = this.req.responseText; 
            window.location.href= "Blog/"+result;
        },
    'Data/Blog/SelectClassInfo.ashx',
    ("operate=getMyClassUrl")
    );
}

//登录框
function loginBox()
{
    var diag = new Dialog();
    diag.Modal = false;
    diag.OkButtonText ="登 录";
    diag.Width = 370;
    diag.Height = 150;
    diag.Title = '用户登陆';
    diag.InnerHtml="<div id='forlogin'>"
      +"<table width='100%' border='0' align='center' cellpadding='4' cellspacing='4' bordercolor='#666666'>"
        +"<tr>"
          +"<td style='height:1px' ></td>"
        +"</tr>"
       +"<tr>"
          +"<td width='60' style='height:10px;' align='right'></td>"
          +"<td></td>"
        +"</tr>"
        +"<tr>"
          +"<td width='60' align='right'>用户名</td>"
          +"<td><input type='text' id='username' style='width:200px;height:20px'  /></td>"
        +"</tr>"
        +"<tr>"
          +"<td width='60' style='height:10px;' align='right'></td>"
          +"<td></td>"
        +"</tr>"
        +"<tr>"
          +"<td width='60' align='right'>密　码</td>"
          +"<td><input type='password' id='userpwd' style='width:200px;height:20px'  /></td>"
        +"</tr>"
        +"<tr>"
          +"<td width='60' style='height:5px;' align='right'></td>"
          +"<td></td>"
        +"</tr>"
        +"<tr>"
          +"<td width='60' align='right'></td>"
          +"<td  align='right' >还没有账号？ <a href='../user/Register.aspx' style='margin-right:45px'>现在立即注册</a></td>"
        +"</tr>"
      +"</table>"
    +"</div>"
    diag.OKEvent = function(){
                if(getDom("username").value =="" ||getDom("userpwd").value ==""){
    	            Dialog.alert("账号密码不能为空");
    	        }
    	        else
    	        {
                    var params = "userid=" + getDom("username").value + "&pwd=" + getDom("userpwd").value +"&operate=loginUser";
                    AjaxPostCall(
                        function(){
                            var result = this.req.responseText;
                         
                            if(result.length > 0)
                            {
                                
                                var params = "session=" + result+"&operate=addSession";     //session赋值
                                AjaxPostCall(function(){
                                    loginGetCzd();
                                    diag.close();
                                    Dialog.alert("登录成功！",function(){location.reload()});
                                },'../Data/User/SelectUserInfo.ashx',params);  
                            } 
                            else
                            {
                                Dialog.alert("用户名密码不符!");
                            }  
                    }
                    
                    ,'../Data/User/SelectUserInfo.ashx',params);
                }
            
    	    };//点击确定后调用的方法
    diag.show();
}

function addLuckyBean()
{
        AjaxPostCall(function(){
            var result = this.req.responseText;
                var msgbean;
                result = parseInt(result);
                if(result == 1)
                {
                    msgbean = "浮云飘过！很艰难的告诉你，你只摇到了 <font color='red'>1</font> 个豆豆";
                }
                else if(result > 1 && result < 10)
                {
                    msgbean = "摇到 <font color='red'>"+result+"</font> 个成长豆。“不积小流，无以成江海”，你懂的。";
                }
                else if(result > 9 && result < 30)
                {
                    msgbean = "没及格啊，才摇到 <font color='red'>"+result+"</font> 个成长豆。";
                }
                else if(result > 29 && result < 50)
                {
                    msgbean = "发挥正常,摇到 <font color='red'>"+result+"</font> 个成长豆,但是我们拒绝平庸！";
                }
                else if(result == 50)
                {
                    msgbean = "幸运总是会不经意的来到你身旁！你摇到了 <font color='red'>50</font> 个豆豆，淡定，淡定。";
                }
                else if(result == 0)
                {
                    msgbean = "亲，不要太贪心哦，今天已经摇过一次了";
                }
                else if(result == -1)
                {
                    msgbean = "很遗憾，你摇豆出错了，你可以重新登录试试";
                }
                Dialog.alert(msgbean);
                getUserinfo(); 

            },
        '../Data/Help/GetBean.ashx',
        "operate=luckbean"
        );
}

function loginGetCzd()
{
     AjaxPostCall(function(){
            var result = this.req.responseText;
            if(result!='False')
            {
               
                //======每日登录+连续登陆==========  
                  AjaxPostCall(function(){
                  var result = this.req.responseText;
                  var dataObj=eval("("+result+")");  
                  var num='0';
                  var otherczd='0';
                    for(var i=0; i<dataObj.root.length; i++)
                    {
                         if(dataObj.root[i].name == 'num')
                         {
                              num=dataObj.root[i].value;
                         }
                         if(dataObj.root[i].name == 'otherczd')
                         {
                             otherczd=dataObj.root[i].value;
                         }
                     }    
                  },
                   '../Data/Dream/AddMiscellaneous.ashx',
                  "operate=selectLoginNum"
                    );
                 //============每日登录+连续登陆结束============== 
            }
        },
        '../Data/Dream/AddMiscellaneous.ashx',
        "operate=addLogin"
    );
}

//返回val的字节长度 
function getByteLen(val) { 

    var len = 0; 
    var len = val.replace(/[^\x00-\xff]/g,"**").length;

    return len; 
} 


//转发框
function rebroadcast(name,content,rebroadcast_workid)
{
    var diag = new Dialog();
    diag.Modal = true;
    diag.OkButtonText ="转 播";
    diag.Width = 450;
    diag.Height = 200;
    diag.Title = '转发广播';
    diag.InnerHtml="<div id='forlogin'>"
      +"<table width='100%' border='0' align='center' cellpadding='4' cellspacing='4' bordercolor='#666666' style='margin-top:15px'>"
        +"<tr>"
          +"<td><div style='margin:0 auto;_height:50px;min-height:50px;width:400px;text-align:left;padding:5px 5px 5px 5px;color:#666666;background-color:#F5F5F5'>"+name+"："+content+"</div></td>"
        +"</tr>"
        +"<tr><td style='height:20px;padding-left:20px;color:#666666;font-size:12px; line-height:15px;text-align:left'>顺便说两句吧:</td></tr>"
        +"<tr>"
          +"<td><textarea rows='2' id='txtcontent' style='width:400px;border:solid 1px #F1F1F1;font-size:13px; line-height:18px;padding:5px;height:50px;overflow: hidden;'></textarea></td>"
        +"</tr>"
      +"</table>"
    +"</div>"
    diag.OKEvent = function(){
            var content= getDom("txtcontent").value.length>0?getDom("txtcontent").value:"转发广播";
            var params = "rebroadcast_workid=" + rebroadcast_workid + "&content=" + content +"&operate=addRebroadcast";
            diag.close();
            AjaxPostCall(
                function(){
                    var result = this.req.responseText;
                    
                    if(result.length > 0)
                    {
                        var diagsu = new Dialog();
	                    diagsu.AutoClose=2;
	                    diagsu.Title="转发广播";
	                    diagsu.Width = 260;
                        diagsu.Height = 100;
                        diagsu.ShowMessageRow=false;
	                    diagsu.ShowCloseButton=false;
	                    diagsu.InnerHtml="<div style='height:98%; line-height:98px;width:98%;text-align:center'>转播成功</div>"
	                    diagsu.show();
                    } 
                    else
                    {
                        var diagfa = new Dialog();
	                    diagfa.AutoClose=2;
	                    diagfa.Title="转发广播";
	                    diagfa.Width = 260;
                        diagfa.Height = 100;
                        diagfa.ShowMessageRow=false;
	                    diagfa.ShowCloseButton=false;
	                    diagfa.InnerHtml="<div style='height:98%; line-height:98px;width:98%;text-align:center'>转播失败</div>"
	                    diagfa.show();
                    }  
            }
            
            ,'../Data/Blog/AddRebroadcast.ashx',params);
        
            
    };//点击确定后调用的方法
    diag.show();
}



/**
 * 回到页面顶部
 * @param acceleration 加速度
 * @param time 时间间隔 (毫秒)
 **/
function goTop(acceleration, time) {
    acceleration = acceleration || 0.1;
    time = time || 16;

    var x1 = 0;
    var y1 = 0;
    var x2 = 0;
    var y2 = 0;
    var x3 = 0;
    var y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }
    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }
    var x3 = window.scrollX || 0;
    var y3 = window.scrollY || 0;

    // 滚动条到页面顶部的水平距离
    var x = Math.max(x1, Math.max(x2, x3));
    // 滚动条到页面顶部的垂直距离
    var y = Math.max(y1, Math.max(y2, y3));

    // 滚动距离 = 目前距离 / 速度, 因为距离原来越小, 速度是大于 1 的数, 所以滚动距离会越来越小
    var speed = 1 + acceleration;
    window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));

    // 如果距离不为零, 继续调用迭代本函数
    if(x > 0 || y > 0) {
    var invokeFunction = "goTop(" + acceleration + ", " + time + ")";
    window.setTimeout(invokeFunction, time);
    }
} 


//周刊订阅
function subscribe(content)
{
    AjaxPostCall(function(){
             var result = this.req.responseText;
          
             if(result=="0")
             {
             
                AjaxPostCall(function(){
                        var result = this.req.responseText;
                        var dataObj=eval("("+result+")");
                        var name,school,classname,mobile="";
                        for(var i=0; i<dataObj.root.length; i++)
                        {
                            if(dataObj.root[i].name=="sname")
                            {
                                name = dataObj.root[i].value;
                            }
                            else if(dataObj.root[i].name=="school")
                            {
                                 school = dataObj.root[i].value;
                            }
                            else if(dataObj.root[i].name=="class")
                            {
                                 classname = dataObj.root[i].value;
                            }
                            else if(dataObj.root[i].name=="mobile")
                            {
                                 mobile = dataObj.root[i].value;
                            }
                        }
                        
                            var diag = new Dialog();
                            diag.Modal = false;
                            diag.OkButtonText ="我要订阅";
                            diag.Width = 450;
                            diag.Height = 280;
                            diag.Title = '成长周刊订阅';
                            diag.InnerHtml="<div id='forlogin'>"
                              +"<table width='100%' border='0' align='center' cellpadding='4' cellspacing='4' bordercolor='#666666'>"
                                +"<tr>"
                                  +"<td style='height:50px;text-align:left;padding:5px 0px 5px 22px;color:#666666' >请仔细核对您的订阅信息，如果资料不准确，周刊将无法送到您手上。本周刊订阅完全免费。</td>"
                                +"</tr>"
                                +"<tr>"
                                  +"<td style='height:30px;text-align:left;padding:5px 0px 5px 50px;color:#666666' >姓名："+name+"</td>"
                                +"</tr>"
                                 +"<tr>"
                                  +"<td style='height:30px;text-align:left;padding:5px 0px 5px 50px;color:#666666' >学校："+school+"</td>"
                                +"</tr>"
                                +"<tr>"
                                  +"<td style='height:30px;text-align:left;padding:5px 0px 5px 50px;color:#666666' >班级："+classname+"</td>"
                                +"</tr>"
                               +"<tr>"
                                  +"<td style='height:30px;text-align:left;padding:5px 0px 5px 50px;color:#666666' >周期：</td>"
                                +"</tr>"
                                        +"<tr>"
                                  +"<td style='height:30px;text-align:left;padding:5px 0px 5px 22px;color:red' >如果资料核实无误，请点击下面的“我要订阅”</td>"
                                +"</tr>"
                                
                              +"</table>"
                            +"</div>"
                            diag.OKEvent = function(){
                           
                                var params =  "operate=addWeeklyApply&name="+name+"&mobile="+mobile+"&school_name="+school+"&class_name="+classname;
                                
                          
                                AjaxPostCall(
                                    function(){
                                        var result = this.req.responseText;
                                        if(result!='False')
                                        {
                                            diag.close();
                                            Dialog.alert("订阅成功！");
                                        }
                                }
                                
                                ,'../Data/Weekly/AddWeeklyApply.ashx',params);
                           
                        
    	                    };//点击确定后调用的方法
                        diag.show();
                    },
                    '../Data/Blog/SelectPersonal_Page.ashx',
                    "uid=session"
                );
             }
             else
             {
                 var info = result.split('|');
                 name = info[0];
                 schoolname = info[1];
                 classname=info[2];
                 subdate=info[3];
                 
                 var diag = new Dialog();
                    diag.Modal = false;
                    diag.OkButtonText ="确 定";
                    diag.Width = 450;
                    diag.Height = 280;
                    diag.Title = '成长周刊订阅信息';
                    diag.InnerHtml="<div id='forlogin'>"
                      +"<table width='100%' border='0' align='center' cellpadding='4' cellspacing='4' bordercolor='#666666'>"
                        +"<tr>"
                          +"<td style='height:50px;text-align:left;padding:5px 0px 5px 22px;color:#666666' >您本月已经成功订阅成长周刊，订阅信息如下，如尚未收到周刊，请致电咨询。</td>"
                        +"</tr>"
                        +"<tr>"
                          +"<td style='height:30px;text-align:left;padding:5px 0px 5px 50px;color:#666666' >姓名："+name+"</td>"
                        +"</tr>"
                         +"<tr>"
                          +"<td style='height:30px;text-align:left;padding:5px 0px 5px 50px;color:#666666' >学校："+schoolname+"</td>"
                        +"</tr>"
                        +"<tr>"
                          +"<td style='height:30px;text-align:left;padding:5px 0px 5px 50px;color:#666666' >班级："+classname+"</td>"
                        +"</tr>"
                       +"<tr>"
                          +"<td style='height:30px;text-align:left;padding:5px 0px 5px 50px;color:#666666' >周期："+subdate+"</td>"
                        +"</tr>"
                                +"<tr>"
                          +"<td ></td>"
                        +"</tr>"
                        
                      +"</table>"
                    +"</div>"
                    diag.OKEvent = function(){
                        diag.close();
    	            };//点击确定后调用的方法
                diag.show();
            }
             
        },
        '../Data/Weekly/AddWeeklyApply.ashx',
        "operate=applyInfo"
    );
    

}


function showNotice(title,grow_newsid)
{
    title ="成长网通知";
    var diag = new Dialog();
	diag.Width = 962;
	diag.Height = 600;
	diag.Title = "成长网通知";
	diag.URL = "../Help/GrowNotice.aspx?grow_newsid="+grow_newsid;
	diag.show();

}
