﻿function checkRemark() {
    var strRemark = getId("txtRemark").value;
    var userName = getId("txtName").value;
    if (IsEmpty(strRemark)) {
        alert("请输入评论！");
        getId("txtRemark").value = "";
        getId("txtRemark").focus();
        return false;
    }
    if (IsEmpty(userName)) {
        alert("请输入姓名！");
        getId("txtName").value = "";
        getId("txtName").focus();
        return false;
    }
    return true;
}
function getXmlhttp() {
    var http_request;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType("text/xml");
        }
    }
    else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    if (!http_request) {
        window.alert("can't create XMLHttpRequest object.");
        return null;
    }
    return http_request;
}
function SubmitKeyClick(button) {
    if (event.keyCode == 13) {
        event.keyCode = 9;
        event.returnValue = false;
        getId(button).focus();
        getId(button).click();
    }
}
function ClickSch() {
    var sch = getId("txtSch").value;
    var currselectvalue = getId("selSch").value;
    if (!IsEmpty(sch)) {
        window.location.href = currselectvalue + "?key=" + escape(sch);
        return true;
    }
    else {
        alert("请输入搜索关键字!");
        getId("txtSch").focus();
        return false;
    }
}
function clickSearch(rul) {
    var sch = getId("txtSch").value;
    if (!IsEmpty(sch)) {
        window.location.href = rul + "/service/search.aspx?key=" + escape(sch);
        return true;
    }
    else {
        alert("请输入搜索关键字!");
        getId("txtSch").focus();
        return false;
    }
}
function upGuest(id, url) {
    var name = getId("txtName").value;
    var guest = getId("txtRemark").value;
    if (IsEmpty(name)) {
        alert("请输入姓名！");
        getId("txtName").focus();
        return false;
    }
    else if (IsEmpty(guest)) {
        alert("有何高见，畅所欲言！");
        getId("txtRemark").focus();
        return false;
    }
    else {
        var url = url + "?type=upguest&id=" + id + "&user=" + escape(name) + "&sign=" + escape(guest);

        var xhttp = getXmlhttp();
        xhttp.onreadystatechange = function() {
            if (xhttp.readyState == 4 && (xhttp.status == 200 || window.location.href.indexOf("http") == -1)) {
                var re = xhttp.responseText;
                if (re == "true") {
                    getId("txtRemark").value = "";
                    alert("评论已经成功提交，感谢关注本站！");
                    guestList(0, vid, varpid, varUrl);
                }
                else {
                    alert(re);
                }
            }
        }
        xhttp.open("GET", url, true);
        xhttp.send(null);
        return;
    }
}
function guestList(varpage, vid, varpid, varUrl) {
    var ulguest = getId("ulguest");
    var url = varUrl + "?type=guestlist&page=" + varpage + "&id=" + vid + "&pid=" + varpid;

    var xhttp = getXmlhttp();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && (xhttp.status == 200 || window.location.href.indexOf("http") == -1)) {
            var re = xhttp.responseText;
            ulguest.innerHTML = re;
            getId("labRemark").innerHTML = "评论（" + getId("lists").innerHTML + "）条";
        }
    }
    xhttp.open("GET", url, true);
    xhttp.send(null);
    return;
}
function getRead(id, url) {
    var readtimes = getId("readTimes");
    var gourl = url + "?class=l&id=" + id;

    var xhttp = getXmlhttp();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && (xhttp.status == 200 || window.location.href.indexOf("http") == -1)) {
            var re = xhttp.responseText;
            readtimes.innerHTML = re;
        }
    }
    xhttp.open("GET", gourl, true);
    xhttp.send(null);
    return;
}
function getRemark(id, url) {
    var remarkCount = getId("remarkCount");
    var gourl = url + "?class=k&id=" + id;

    var xhttp = getXmlhttp();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && (xhttp.status == 200 || window.location.href.indexOf("http") == -1)) {
            var re = xhttp.responseText;
            remarkCount.innerHTML = re;
        }
    }
    xhttp.open("GET", gourl, true);
    xhttp.send(null);
    return;
}
function execInnerScript(innerhtml) {
    var temp = innerhtml.replace(/\n|\r/g, "");
    var regex = /<script.+?<\/script>/gi;
    var arr = temp.match(regex);
    if (arr) {
        for (var i = 0; i < arr.length; i++) {
            var temp = arr[i];
            var reg = new RegExp("^<script(.+?)>(.+)<\/script>$", "gi");
            reg.test(temp);
            eval(RegExp.$2);
        }
    }
}
function setInnerHTML(el, htmlCode) {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
        htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
        htmlCode = htmlCode.replace(/<script([^>]*)>/gi, '<script$1 defer>');
        el.innerHTML = htmlCode;
        el.removeChild(el.firstChild);
    }
    else {
        var el_next = el.nextSibling;
        var el_parent = el.parentNode;
        el_parent.removeChild(el);
        el.innerHTML = htmlCode;
        if (el_next) {
            el_parent.insertBefore(el, el_next)
        } else {
            el_parent.appendChild(el);
        }
    }
}