﻿
var xmlHttp = false;
try {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
    try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e2) {
        xmlHttp = false;
    }
}

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}

function AjaxPage(page) {
    
    if (page == "")
        return;

    var nowdata = new Date();
    var url = "AjaxComment.aspx?page=" + page + "&cid=" + sync + "&type=" + nowdata.toLocaleString(); ;
    
    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = cardcallBack_Reluse;

    xmlHttp.send(null);

}



var cityId = 0;
//验证学习卡信息正确性返回函数
function cardcallBack_Reluse() {

    if (xmlHttp.readyState == 4) 
    {
        var commentResult = xmlHttp.responseText;
        document.getElementById("divComment").innerHTML = commentResult;
    }
}


function GetRand() {
    return parseInt(Math.random() * (9999 - 1000 + 1) + 1000);
}


//刷新验证码
var codes;
function ChangeCodes() {
    var aCode = document.getElementById("codeimg");
    codes = GetRand();
    aCode.src = "../Inc/Codeimg.aspx?code=" + codes;
    CheckLogon();
}

function CheckLogon()
{
    var tt=GetUserName();
    if(tt=="")
    {
        document.getElementById("logon").style.display="block";
        document.getElementById("regist").style.display="block";
    }
    else
    {
        document.getElementById("logon").style.display="none";
        document.getElementById("regist").style.display="none";
    }
}


/*******获取Cookies用户名**********/
var GetUserName = function() {
    var userName = new String();
    var strCookie = new String();
    strCookie = decodeURIComponent(document.cookie);
    strTT = "FZSyncValidate=";
    //根据cookies来判断用户是否登录
    if (strCookie.indexOf(strTT) >= 0) {
        var strT1 = new String();
        var strS = new String();
        var arrStr = new Array()
        strT1 = strCookie.substring(strCookie.indexOf(strTT) + strTT.length)
        arrStr = strT1.split("&");
        for (var i = 0; i < arrStr.length; i++) {
            strS = arrStr[i];
            switch (strS.substring(0, strS.indexOf("="))) {
                case "UserName":
                    userName = strS.substring(strS.indexOf("=") + 1);
                    break;
            }
        }
    }
    return userName;
}

////发表评论
//function CheckCommentInfo() {
//    var incode = document.getElementById("txtCodes").value;
//    if (incode == "") {
//        alert('验证码不能为空！');
//        document.getElementById("txtCodes").focus();
//        return false;
//    }
//    else if (incode != codes) {
//    document.getElementById("txtCodes").focus();
//       alert('验证码不正确！');
//       return false;
//   }
//   var uNmae = checkUser();
//   var AnonyResult = checkAnonymity();
//   if (uNmae == "") {
//       if (AnonyResult == false) {
//           alert('您还没有登录，请先登录或选择匿名评论！');
//           return false;
//       }
//       else {
//           return CheckFckTxt();
//       }
//   }
//  
//}


//获取用户名
function checkUser() {
    var objUser = document.getElementById("txtUserName");
    return objUser.value;
}

//判断是否选中匿名
function checkAnonymity() {
    var objAnony = document.getElementById("ckAnonymity");
    if (objAnony.type == "checkbox") {     
        if (objAnony.checked == true) {          
            return true;
        }
        else {
            return false;
        }
    }
}


function GetUrlValue() {
    var Url = top.window.location.href;
    var u, g, StrBack = '';
    if (arguments[arguments.length - 1] == "#")
        u = Url.split("#");
    else
        u = Url.split("?");
    if (u.length == 1) g = '';
    else g = u[1];
    if (g != '') {
        gg = g.split("&");
        var MaxI = gg.length;
        str = arguments[0] + "=";
        for (i = 0; i < MaxI; i++) {
            if (gg[i].indexOf(str) == 0) {
                StrBack = gg[i].replace(str, "");
                break;
            }
        }
    }
    return StrBack;
} 



//返回发布评论
function BackComment() {
    scroller('header_1', 800);
}

function StudyComment() {
    scroller('header_2', 800);
}



function intval(v) {
    v = parseInt(v);
    return isNaN(v) ? 0 : v;
}
// 获取元素信息
function getPos(e) {
    var l = 0;
    var t = 0;
    var w = intval(e.style.width);
    var h = intval(e.style.height);
    var wb = e.offsetWidth;
    var hb = e.offsetHeight;
    while (e.offsetParent) {
        l += e.offsetLeft + (e.currentStyle ? intval(e.currentStyle.borderLeftWidth) : 0);
        t += e.offsetTop + (e.currentStyle ? intval(e.currentStyle.borderTopWidth) : 0);
        e = e.offsetParent;
    }
    l += e.offsetLeft + (e.currentStyle ? intval(e.currentStyle.borderLeftWidth) : 0);
    t += e.offsetTop + (e.currentStyle ? intval(e.currentStyle.borderTopWidth) : 0);
    return { x: l, y: t, w: w, h: h, wb: wb, hb: hb };
}
// 获取滚动条信息
function getScroll() {
    var t, l, w, h;
    if (document.documentElement && document.documentElement.scrollTop) {
        t = document.documentElement.scrollTop;
        l = document.documentElement.scrollLeft;
        w = document.documentElement.scrollWidth;
        h = document.documentElement.scrollHeight;
    } else if (document.body) {
        t = document.body.scrollTop;
        l = document.body.scrollLeft;
        w = document.body.scrollWidth;
        h = document.body.scrollHeight;
    }
    return { t: t, l: l, w: w, h: h };
}
// 锚点(Anchor)间平滑跳转
function scroller(el, duration) {
    if (typeof el != 'object') { el = document.getElementById(el); }
    if (!el) return;
    var z = this;
    z.el = el;
    z.p = getPos(el);
    z.s = getScroll();
    z.clear = function() { window.clearInterval(z.timer); z.timer = null };
    z.t = (new Date).getTime();
    z.step = function() {
        var t = (new Date).getTime();
        var p = (t - z.t) / duration;
        if (t >= duration + z.t) {
            z.clear();
            window.setTimeout(function() { z.scroll(z.p.y, z.p.x) }, 13);
        } else {
            st = ((-Math.cos(p * Math.PI) / 2) + 0.5) * (z.p.y - z.s.t) + z.s.t;
            sl = ((-Math.cos(p * Math.PI) / 2) + 0.5) * (z.p.x - z.s.l) + z.s.l;
            z.scroll(st, sl);
        }
    };
    z.scroll = function(t, l) { window.scrollTo(l, t) };
    z.timer = window.setInterval(function() { z.step(); }, 13);
}
