function CheckAll(form) {
    for (var i = 0; i < form.elements.length; i++) {
        var e = form.elements[i];
        if (e.Name != "chkAll" && e.type == "checkbox")
            e.checked = form.chkAll.checked;
    }
}



function copyUrl(url) {
    var content = '';
    window.clipboardData.setData("Text", url);
    alert("复制成功，您可以按 CTRL+V 键粘贴到 QQ/MSN 上推荐给你的好友");
}
function RemoveHTML(str) {
    var regEx = /<[^>]*>/g;
    return str.replace(regEx, "");
}

function quciklogin() {
    //    alert(top.location.href);

    var str = top.location.href;
    if (str.indexOf("Reg") < 0 && str.indexOf("login") < 0) {
        redirect("/login.aspx?Url=" + str);
    }
    else {
        redirect("/login.aspx");
    }
}

function redirect(a) { window.location.href = a }

function PostReply(UserName) {
    $("comment_txt").focus();
    if (UserName) {
        $("comment_txt").value = "@" + UserName + " ";
    }
}

//function UpFileChk() {
//    if ($("TxtUpload").value == "") {
//        alert("请选择要上传的文件！");
//        return false;
//    }
//    else if (!ChkFileType($("TxtUpload").value)) {
//        alert("只允许上传Txt/Jar/Umd格式的电子书！");
//        return false;
//    }
//    return true;
//}

//function UpImgChk() {
//    if ($("FileUpload1").value == "") {
//        alert("请选择要上传的文件！");
//        return false;
//    }
//    else if (!ChkImgType($("FileUpload1").value)) {
//        alert("请选择正确的图片格式！");
//        return false;
//    }
//    return true;
//}

function ChkFileType(str) {
    //var temp = str.substring(str.lastIndexOf(".") + 1, str.length);
    var temp = str.replace(/^.*(\.[^\.\?]*)\??.*$/, '$1');
    temp = temp.toLowerCase();
    if (temp == ".txt") {
        return true;
    }
    return false;
}
function ChkImgType(str) {
    var temp = str.replace(/^.*(\.[^\.\?]*)\??.*$/, '$1');
    temp = temp.toLowerCase();
    if (temp == ".jpg" || temp == ".bmp" || temp == ".gif" || temp == ".jpeg" || temp == ".png") {
        return true;
    }
    return false;
}

function EnterKeyClick(button, event) {
    if (event.keyCode == 13) {
        //  event.keyCode=9;
        //  event.returnValue = false;
        //  document.all[button].click(); 
        $(button).click();
        //  document.getElementById(button).click();

    }
}

function Chk() {
    if (document.Comment.Content.value == "") {
        alert("请填写评论内容。");
        return false;
    }
    else if (document.Comment.Content.value.length > 500) {
        alert("评论内容超过 500 个字符的限制。");
        return false;
    }
    else if (document.Comment.C_UserName.value == "" || document.Comment.C_UserName.value == "请输入昵称！") {
        alert("请填写昵称");
        return false;
    }
    //else if (document.Comment.C_UserID =="") 
    //{
    //if(!CheckUser(document.Comment.C_UserName.value))
    //{
    //alert("此昵称已经被使用");
    //return false;
    //}
    //else
    //{
    //return true;
    //}
    //}
    return true;
}


function DivOpen(id) {
    $(id).style.display = 'block'
}

function DivClose(id) {
    $(id).style.display = 'none'
}

function DateDemo() {
    var myDate = new Date(); //得到时间对象 
    var y = myDate.getYear(); //获取年 
    var m = myDate.getMonth() + 1; //获取月 
    m = m > 9 ? m : "0" + m; //如果月份小于10,则在前面加0补充为两位数字 
    var d = myDate.getDay(); //获取日 
    d = d > 9 ? d : "0" + d; //如果天数小于10,则在前面加0补充为两位数字 
    var h = myDate.getHours(); //获取小时 
    h = h > 9 ? h : "0" + h; //如果小时数字小于10,则在前面加0补充为两位数字 
    var M = myDate.getMinutes(); //获取分 
    M = M > 9 ? M : "0" + M; //如果分钟小于10,则在前面加0补充为两位数字 
    var s = myDate.getSeconds(); //获取秒 
    s = s > 9 ? s : "0" + s; //如果秒数小于10,则在前面加0补充为两位数字
    return (y + "-" + m + "-" + d + " " + h + ":" + m + ":" + s);
}



function SearchCheck() {
    if (document.search_form1.K.value == "" || document.search_form1.K.value == "请输入您要搜索的书籍关键字") {
        alert("\请输入搜索关键字！");
        document.search_form1.K.focus();
    }
    else {
        redirect("/Search/q_" + encodeURIComponent(escape(document.search_form1.K.value)));
        //        return true;
    }
    return false;
}


function ctrlEnter(BookID, event) {
    if ((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) {
        p_comment(BookID);
    }
}


function BookAddChk() {

    if ($("Book_Name").value == "") {
        alert("请填写书籍名称！");
        return false;
    }
    else if ($("Book_Name").value.length < 2 || $("Book_Name").value.length > 20) {
        alert("书籍名称字数必须是3至20个字！");
        return false;
    }
    else if ($("Book_Author").value == "") {
        alert("请填写书籍作者！");
        return false;
    }
    else if ($("TxtUpload").value == "") {
        alert("请选择要上传的书籍！");
        return false;
    }
    else if (ChkFileType($("TxtUpload").value) == false) {
        alert("只允许上传TXT格式的书籍！");
        return false;
    }
    //    else if ($("FileUpload1").value == "") {
    //        alert("请选择要上传的封面！");
    //        return false;
    //    }

    else if ($("FileUpload1").value != "") {
        if (ChkImgType($("FileUpload1").value) == false) {
            alert("请选择正确的图片类型！");
            return false;
        }
    }
    else if ($("Book_Content").value == "") {
        alert("请填写书籍简介！");
        return false;
    }
    else if ($("Book_Content").value.length > 500) {
        alert("书籍简介字数不能超过500个！");
        return false;
    }
    return true;
}


function convertdate2(strdate) {
    strdate = strdate.replace(/-/ig, '/');
    var d = new Date(strdate);
    var now = new Date();
    var result = now - d;
    //	alert(d+'result:'+result);
    if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() - d.getDate() > 0) {
        result = (now.getDate() - d.getDate()) + "天前";
    }
    else if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate() && now.getHours() - d.getHours() > 0) {
        result = (now.getHours() - d.getHours()) + "小时前"
    }
    else if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate() && now.getHours() == d.getHours() && now.getMinutes() - d.getMinutes() > 0) {
        result = (now.getMinutes() - d.getMinutes()) + "分钟前"
    }
    else {
        result = d.getYear() + "-" + d.getMonth() + "-" + d.getDate();
        //		result = d.format("yyyy.MM.dd hh:mm");
    }
    return result;
}

function scrollback(scroll) {
    if (scroll != 0) {
        document.body.scrollTop = scroll;
    }
    //if (GetCookie("scroll")!=null){document.body.scrollTop=GetCookie("scroll")}
}