﻿

var SearchPopupW = 320;
var SearchPopupH1 = 200;
var SearchPopupH2 = 25;

var urlLocation = "/Common/WebService.asmx/";

var LogID;
var divUserShowID;

var SitePageType = 0;
var SiteLogTypeID = 0;
var SiteLogCateID = 0;
var SiteLogID = 0;
var SiteUrl = "/";
var CateOrder = '';
var CateListModel = 0;

var SiteUserID = 0;
var SiteUserName = "";
var SiteUserRole = 0;

$(document).ready(function () {

    SiteUserID = $.cookie("CurrentMemberID");
    SiteUserName = $.cookie("CurrentMemberEmail");
    SiteUserRole = $.cookie("CurrentMemberFlag");

    if (SiteUserID == null) SiteUserID = 0;
    if (SiteUserName == null) SiteUserName = "";
    if (SiteUserRole == null) SiteUserRole = 0;

    CheckMemberState();
    setActiveStyleSheet();
})

function bookmark(title, url) {
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "")
}

function getWebPageTitle() {
    kdocTitle = document.title; //标题 
    if (kdocTitle == null) {
        var t_titles = document.getElementByTagName("title")
        if (t_titles && t_titles.length > 0) {
            kdocTitle = t_titles[0];
        } else {
            kdocTitle = "";
        }
    }

    return kdocTitle;
}

function getIEVersonNumber() {
    var ua = navigator.userAgent;
    var IEVerson = '';
    if (ua.indexOf('MSIE 7.0') > -1) {
        IEVerson = 'IE7';
    }
    else if (ua.indexOf('Firefox') > -1) {
        IEVerson = 'MOZ';
    }

    return IEVerson;
}

function setActiveStyleSheet() {
    var title = getIEVersonNumber();

    if (title != '') {
        try {
            var obj = document.getElementsByTagName('link')[0];
            if (obj != null) {
                var str = obj.href.replace('.css', '');
                obj.href = str + '_' + title + '.css';
            }
        } catch (e) { }
    }
}
function CheckMemberState() {
    if (document.getElementById("divLoginUserName") == null) return;

    if (SiteUserID == "" || SiteUserID == "0") {
        document.getElementById("divLoginUserName").innerText = "";
        if (document.getElementById("divLogin") != null) document.getElementById("divLogin").style.display = "";
        if (document.getElementById("divLogout") != null) document.getElementById("divLogout").style.display = "none";
        $(".divLogin").show(); $(".divLogout").hide();
    }
    else {
        document.getElementById("divLoginUserName").innerText = SiteUserName;
        if (document.getElementById("divLogin") != null) document.getElementById("divLogin").style.display = "none";
        if (document.getElementById("divLogout") != null) document.getElementById("divLogout").style.display = "";
        $(".divLogin").hide(); $(".divLogout").show();
    }

    var Mail_From = Request("From");
    if (Mail_From != "") $.cookie("CurrentMemberMailFrom", Mail_From);
}

function Print() {
    bdhtml = window.document.body.innerHTML;
    sprnstr = "<!--startprint-->";
    eprnstr = "<!--endprint-->";
    prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
    prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
    var w = window.open("/Common/popPrint.aspx", "print")
    w.document.body.innerHTML = prnhtml;
    w.print();
    w.close();
}

function ShowFlag(Flag, Cnt) {
    return (Flag.indexOf("{" + Cnt + "}") > -1);
}

function SendEmail(MailTo, MailCc, MailSubject, MailContent) {

    var filePath = "/Common/WebService.asmx/SendEmail";
    var data = "MailTo=" + MailTo + "&MailCc=" + MailCc + "&MailSubject=" + MailSubject + "&MailContent=" + MailContent;

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) { }
    });
}

function CountHtmlPage(url1, url2, type, id) {

    url1 = url1.replace(/&/g, "%26");
    url1 = url1.replace(/%/g, "@@@");
    url2 = url2.replace(/&/g, "%26");
    url2 = url2.replace(/%/g, "@@@");

    var filePath = "/Common/WebService.asmx/CountHtmlPage";
    var data = "RawUrl=" + url1 + "&Url=" + url2 + "&Type=" + type + "&ID=" + id;

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) { }
    });
}
function GetAscxData(obj, KeyWord, ParamStr) {
    var objParent = $(obj).parent();
    objParent.empty(); objParent.append("<img src='/App_Images/loading.gif' /> loading...");

    var filePath = "/Common/WebService.asmx/GetAscxData";
    var data = "KeyWord=" + KeyWord + "&ParamStr=" + ParamStr + "&LogID=" + SiteLogID + "&CateID=" + SiteLogCateID;

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) { objParent.empty(); objParent.append($(xml).find("string").text()); }
    });
}
function GetAscxData_ByCateField(obj, CateID, CateSearch) {
    var objParent = $(obj).parent();
    objParent.empty(); objParent.append("<img src='/App_Images/loading.gif' /> loading...");
    var filePath = "/Common/WebService.asmx/GetAscxData_ByCateField";
    var data = "CateID=" + CateID + "&CateSearch=" + CateSearch;

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) { objParent.empty(); objParent.append($(xml).find("string").text()); }
    });
}

function GetListData_BySearch(obj, ListModel, Params, Title, LogTypeID, LogCateID, CateFlag, CateOrder, CateSearch, PageIndex, PageSize) {
    $(obj).empty(); $(obj).append("<img src='/App_Images/loading.gif' /> loading...");

    var filePath = "/Common/WebService.asmx/GetListData_BySearch";
    var data = "ListModel=" + ListModel + "&Params=" + Params + "&Title=" + Title + "&LogTypeID=" + LogTypeID + "&LogCateID=" + LogCateID + "&CateFlag=" + CateFlag + "&CateOrder=" + CateOrder + "&CateSearch=" + CateSearch + "&PageIndex=" + PageIndex + "&PageSize=" + PageSize;

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) { $(obj).empty(); $(obj).append($(xml).find("string").text()); }
    });
}
function GetListData_BySearchAndPrice(obj, ListModel, Params, Title, LogTypeID, LogCateID, CateFlag, CateOrder, CateSearch, CatePriceFrom, CatePriceTo, PageIndex, PageSize) {
    $(obj).empty(); $(obj).append("<img src='/App_Images/loading.gif' /> loading...");

    var filePath = "/Common/WebService.asmx/GetListData_BySearchAndPrice";
    var data = "ListModel=" + ListModel + "&Params=" + Params + "&Title=" + Title + "&LogTypeID=" + LogTypeID + "&LogCateID=" + LogCateID + "&CateFlag=" + CateFlag + "&CateOrder=" + CateOrder + "&CateSearch=" + CateSearch + "&CatePriceFrom=" + CatePriceFrom + "&CatePriceTo=" + CatePriceTo + "&PageIndex=" + PageIndex + "&PageSize=" + PageSize;

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) { $(obj).empty(); $(obj).append($(xml).find("string").text()); }
    });
}

function GetLink_ByUserMail(UserMail) {
    var filePath = "/Common/WebService.asmx/GetWord_ByUserMail";

    var str = "";
    $.ajax({ async: false, type: "post", url: filePath, data: "UserMail=" + UserMail, dataType: "xml", timeout: 50000,
        success: function (xml) { str = $(xml).find("string").text(); }
    });

    return str;
}
function GetCash_ByUserMail(UserMail) {
    var filePath = "/Common/WebServiceUser.asmx/Member_GetCashTop";

    var str = "";
    $.ajax({ async: false, type: "post", url: filePath, data: "UserEmail=" + UserMail, dataType: "xml", timeout: 50000,
        success: function (xml) { str = $(xml).find("string").text(); }
    });

    return str;
}

function GetLinkStr(value) {

    var strs = value.split(',');
    if (strs.length == 1) return value;

    var link = "";
    for (var i = 0; i < strs.length; i++) {
        link += "<a href='javascript:void(0)'>" + strs[i] + "</a>";
    }

    return link;
}
function GetLogContent(id) {
    var filePath = "/Common/WebService.asmx/GetLogContent";

    $.ajax({ type: "post", url: filePath, data: "LogID=" + id, dataType: "xml", timeout: 50000,
        success: function (xml) { $("#divLogContent" + id).html($(xml).find("string").text()); }
    });
}
function GetLogPoint(LogID, Obj, Model) {

    var filePath = "/Common/WebService.asmx/GetLogPoint";
    var data = "LogID=" + LogID;
    $(Obj).empty(); $(Obj).append("<li><img src='/App_Images/loading.gif' /> loading ...</li>");

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) {

            var strData = "";

            $(xml).find("Table").each(function () {
                var Point_Qty = $(this).children("Point_Qty").text();
                var Point_Count = $(this).children("Point_Count").text();
                strData += Model.replace("{0}", Point_Qty).replace("{1}", Point_Count);
            })

            $(Obj).empty(); $(Obj).append(strData);
        }
    });
}
function GetLogPhoto(LogID, Obj, Model, Css1, Css2) {

    var filePath = "/Common/WebService.asmx/GetLogPhoto";
    var data = "LogID=" + LogID;
    $(Obj).empty(); $(Obj).append("<li><img src='/App_Images/loading.gif' /> loading ...</li>");

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) {

            var strData = "";
            var logPhotos = $(xml).find("string").text().split(',');

            if (logPhotos.length > 0) strData += Model.replace("{0}", logPhotos[0]).replace("{0}", logPhotos[0]).replace("{1}", Css1).replace("{2}", 1).replace("{2}", 1);
            for (i = 1; i < logPhotos.length; i++) {
                strData += Model.replace("{0}", logPhotos[i]).replace("{0}", logPhotos[i]).replace("{1}", Css2).replace("{2}", i + 1).replace("{2}", i + 1);
            }

            if (strData == "") strData = "<ul><li></li></ul>"; else strData = "<ul>" + strData + "</ul>";
            $(Obj).empty(); $(Obj).append(strData);

        }
    });
}
function GetLogField(LogID, Obj, Model) {
    GetLogField(LogID, Obj, Model, 0);
}
function GetLogField(LogID, Obj, Model, Type) {
    var filePath = "/Common/WebService.asmx/GetLogField";
    var data = "LogID=" + LogID + "&FieldType=" + Type;
    $(Obj).empty(); $(Obj).append("<li><img src='/App_Images/loading.gif' /> loading ...</li>");

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) {

            var strData = "";
            $(xml).find("Table").each(function () {
                var FieldName = $(this).children("ArticleTypeField_Name").text();
                var FieldToop = $(this).children("ArticleTypeField_Toop").text();
                var FieldValue = $(this).children("ArticleField_FieldValue").text();
                if (FieldValue == "") FieldValue = $(this).children("ArticleField_FieldNoteValue").text();
                if (FieldName != "") strData += Model.replace("{0}", FieldName).replace("{1}", GetLinkStr(FieldValue));
            })

            $(Obj).empty(); $(Obj).append(strData);
        }
    });
}
function GetLogPrice(LogID, LogPrice, Obj, Model) {
    var filePath = "/Common/WebService.asmx/GetLogPrice";
    var data = "LogID=" + LogID;
    $(Obj).empty(); $(Obj).append("<li><img src='/App_Images/loading.gif' /> loading ...</li>");

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) {
            var strData = "";

            $(xml).find("BLOG_ARTICLETYPEPRICE").each(function () {
                var PriceId = $(this).children("PriceId").text();
                var PriceSubject = $(this).children("PriceSubject").text();
                var PriceSqty = $(this).children("PriceSqty").text();
                var PriceEqty = $(this).children("PriceEqty").text();
                var PriceRate = (LogPrice * $(this).children("PriceRate").text() / 100).toFixed(2);
                var PriceProcess = $(this).children("PriceProcess").text();
                var PriceNote = $(this).children("PriceNote").text();

                var PriceSave = ((LogPrice - PriceRate) * 100 / LogPrice).toFixed(2);
                strData += Model.replace("{0}", PriceSubject).replace("{1}", PriceRate).replace("{2}", PriceProcess).replace("{3}", PriceSqty).replace("{4}", PriceEqty).replace("{5}", PriceSave);
            })

            $(Obj).empty(); $(Obj).append(strData);
        }
    });
}
function GetLogPrice2(LogID, LogPrice1, LogPrice2, Obj, Model) {
    var filePath = "/Common/WebService.asmx/GetLogPrice";
    var data = "LogID=" + LogID;
    $(Obj).empty(); $(Obj).append("<li><img src='/App_Images/loading.gif' /> loading ...</li>");

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) {
            var strData = "";

            $(xml).find("BLOG_ARTICLETYPEPRICE").each(function () {
                var PriceId = $(this).children("PriceId").text();
                var PriceSubject = $(this).children("PriceSubject").text();
                var PriceSqty = $(this).children("PriceSqty").text();
                var PriceEqty = $(this).children("PriceEqty").text();
                var PriceRate = (LogPrice2 * $(this).children("PriceRate").text() / 100).toFixed(2);
                var PriceProcess = $(this).children("PriceProcess").text();
                var PriceNote = $(this).children("PriceNote").text();

                var PriceSave = ((LogPrice1 - PriceRate) * 100 / LogPrice1).toFixed(2);
                strData += Model.replace("{0}", PriceSubject).replace("{1}", PriceRate).replace("{2}", PriceProcess).replace("{3}", PriceSqty).replace("{4}", PriceEqty).replace("{5}", PriceSave);
            })

            $(Obj).empty(); $(Obj).append(strData);
        }
    });
}
function GetLogMsg(LogID, RowCount, Obj, Model) {
    var filePath = "/Common/WebService.asmx/GetLogMessage";
    var data = "LogID=" + LogID + "&RowCount=" + RowCount;
    $(Obj).empty(); $(Obj).append("<li><img src='/App_Images/loading.gif' /> loading ...</li>");

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) {
            var strData = "";

            $(xml).find("BLOG_MESSAGE").each(function () {
                strData += "";
            })

            $(Obj).empty(); $(Obj).append(strData);
        }
    });
}
function GetLogComment(LogID, RowCount, Obj, Model) {

    var filePath = "/Common/WebService.asmx/GetLogComment";
    var data = "LogID=" + LogID + "&RowCount=" + RowCount;
    $(Obj).empty(); $(Obj).append("<li><img src='/App_Images/loading.gif' /> loading ...</li>");

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) {
            var strData = "";

            $(xml).find("BLOG_COMMENT").each(function () {
                var CommContent = $(this).children("CommContent").text();
                var CommFeedback = $(this).children("CommFeedback").text();
                var CommPosttime = $(this).children("CommPosttime").text();
                var CommAuthor = $(this).children("CommAuthor").text(); if (CommAuthor == "") CommAuthor = "匿名";
                var CommIparea = $(this).children("CommIparea").text();

                if (CommFeedback != '') {
                    var str = Model.replace(/CommContent/g, CommContent);
                    str = str.replace(/CommFeedback/g, CommFeedback)
                    str = str.replace(/CommPosttime/g, CommPosttime)
                    str = str.replace(/CommAuthor/g, CommAuthor)
                    str = str.replace(/CommIparea/g, CommIparea);
                    strData += str;
                }
            })

            $(Obj).empty(); $(Obj).append(strData);
        }
    });
}

function GetLogInquiry(LogID, RowCount, Obj, Model) {
    var filePath = "/Common/WebService.asmx/GetLogInquiry";
    var data = "LogID=" + LogID + "&RowCount=" + RowCount;
    $(Obj).empty(); $(Obj).append("<li><img src='/App_Images/loading.gif' /> loading ...</li>");

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) {
            var strData = "";

            $(xml).find("BLOG_FINISHERS").each(function () {
                var FinishersContent = $(this).children("FinishersContent").text();
                var FinishersFeedback = $(this).children("FinishersFeedback").text();
                var FinishersPosttime = $(this).children("FinishersPosttime").text();
                var FinishersReplytime = $(this).children("FinishersReplytime").text();
                var FinishersAuthor = $(this).children("FinishersAuthor").text(); if (FinishersAuthor == "") FinishersAuthor = "匿名";
                var FinishersIparea = $(this).children("FinishersIparea").text();

                if (FinishersFeedback != '') {
                    var str = Model.replace(/InquiryContent/g, FinishersContent);
                    str = str.replace(/InquiryFeedback/g, FinishersFeedback)
                    str = str.replace(/InquiryPosttime/g, FinishersPosttime)
                    str = str.replace(/InquiryReplytime/g, FinishersReplytime)
                    str = str.replace(/InquiryAuthor/g, FinishersAuthor)
                    str = str.replace(/InquiryIparea/g, FinishersIparea);
                    strData += str;
                }
            })

            $(Obj).empty(); $(Obj).append(strData);
        }
    });
}

function GetCommentByLogID(id) {
    var filePath = "/Common/WebServiceUser.asmx/GetCommentByLogID";

    $.ajax({ type: "post", url: filePath, data: "LogID=" + id, dataType: "xml", timeout: 50000,
        success: function (xml) { $("#divCommentByLogID").html($(xml).find("string").text()); }
    });
}
function GetCommentByCommentID(id) {
    var filePath = "/Common/WebServiceUser.asmx/GetCommentByCommentID";

    $.ajax({ type: "post", url: filePath, data: "CommentID=" + id, dataType: "xml", timeout: 50000,
        success: function (xml) { $("#divCommentByCommentID").html($(xml).find("string").text()); }
    });
}
function GetUserShowHistory(strListID, strListType, strModel, strParams) {
    var filePath = "/Common/WebService.asmx/GetUserShowHistory";
    var data = "ListType=" + strListType + "&strModel=" + strModel + "&strParams=" + strParams;

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) { $("#" + strListID).parent().html($(xml).find("string").text()); }
    });
}
function GetSearchPopupByLogID(id) {
    LogID = id;

    var filePath = "/Common/WebService.asmx/GetSearchPopupByLogID";
    var data = "ID=" + id;

    $.ajax({ type: "post", url: filePath, data: data, dataType: "xml", timeout: 50000,
        success: function (xml) { work_GetSearchPopupByLogID($(xml).find("string").text()); }
    });
}

//----------------------------------------

function GetParam(url, str) {
    var r = "";

    if (url == null) return r;
    if (str == null) return r;

    var i = url.indexOf('?'); if (i < 0) return r; url = url.substring(i);
    i = url.indexOf(str); if (i < 0) return r; url = url.substring(i + str.length);
    i = url.indexOf('&');

    if (i > -1)
        return url.substring(1, i);
    else
        return url.substring(1);
}

function Request(str) {
    var url = location.href;
    var r = "";

    if (url == null) return r;
    if (str == null) return r;

    var i = url.indexOf('?'); if (i < 0) return r; else url = url.substring(i);
    i = url.indexOf(str + "="); if (i < 0) return r; else url = url.substring(i + str.length + 1);

    i = url.indexOf('&');
    if (i > -1)
        return url.substring(0, i);
    else
        return url;
}

//-------------------------------------------

function SearchSetValue() {
    txtSearchValue.value = unescape(Request("SearchValue"));
}
function GotoSearchPage(SearchValue) {
    if (SearchValue == "") { alert("请输入搜索的内容！"); return }
    window.location.href = "/App_Site/SiteSearch.aspx?Tag=" + escape(SearchValue) + "&LogTypeID=" + 0 + "&LogCateID=" + 0;
}
function GotoSearchPage(SearchValue, LogTypeID, LogCateID) {
    if (SearchValue == "") { alert("请输入搜索的内容！"); return }
    window.location.href = "/App_Site/SiteSearch.aspx?Tag=" + escape(SearchValue) + "&LogTypeID=" + LogTypeID + "&LogCateID=" + LogCateID;
}
function GotoSearchProductPage(Title, TypeID, CateID, Price) {
    var strLink = '/App_Site/SiteSearchProduct.aspx?Title=' + Title;

    if (TypeID != "") strLink += '&LogTypeID=' + TypeID;
    if (CateID != "") strLink += '&LogCateID=' + CateID;
    if (Price != "") strLink += '&Price=' + Price;

    window.location.href = strLink;
}

function ShowModelParam(ModelType, ModelParamSetID, ModelParamID, ModelContentID, ModelName, ModelParamValue) {
    var ModelForm = "ModelFixed.aspx";

    switch (ModelType) {
        case 2:
            ModelForm = "ModelCategory.aspx";
            break;
        case 3:
            ModelForm = "ModelLog.aspx";
            break;
        case 4:
            ModelForm = "ModelList.aspx";
            break;
        case 7:
            ModelForm = "ModelListCommon.aspx";
            break;
        case 5:
            ModelForm = "ModelTag.aspx";
            break;
        case 6:
            ModelForm = "ModelMenu.aspx";
            break;
        case 8:
            ModelForm = "ModelMember.aspx";
            break;
    }

    var strFlagModelParamStart = "<!--divModelParamStart-->";
    var strFlagModelParamEnd = "<!--divModelParamEnd-->";
    var strModelParam = window.showModalDialog("../App_DesignModel/" + ModelForm + "?ModelParamValue=" + escape(ModelParamValue.replace(/&/g, "$")), "ShowModelParam", "dialogWidth: 540px; dialogHeight:640px; center: Yes; status: 0; help: No;scroll: No;");

    if (strModelParam != undefined) {
        document.getElementById(ModelParamSetID).setAttribute("title", ModelName + " " + strModelParam);
        document.getElementById(ModelParamID).setAttribute("title", ModelName + " " + strModelParam);
        document.getElementById(ModelContentID).setAttribute("title", ModelName + " " + strModelParam);

        document.getElementById(ModelParamID).setAttribute("innerHTML", "&nbsp;" + strFlagModelParamStart + strModelParam + strFlagModelParamEnd);
    }
}
function ShowModelDesign(ModelType, ModelName) {
    window.open("../App_DesignModel/ModelDesign.aspx?ModelType=" + ModelType + "&ModelName=" + ModelName, "ModelDesign", "Width: 640px; Height:520px; center: Yes; status: 0; help: No;scroll: No;");
}

function MoveSearchPopup() {
    if (document.getElementById("msgTxtPopup").style.display == "") {
        document.getElementById("msgDivPopup").style.top = document.body.scrollTop + document.body.clientHeight - SearchPopupH1;
    }
    else {
        document.getElementById("msgDivPopup").style.top = document.body.scrollTop + document.body.clientHeight - SearchPopupH2;
    }
    setTimeout("MoveSearchPopup();", 80)
}
function SearchChangePage(pageCount, pageIndex) {
    var i = 1;

    for (i = 1; i < pageCount; i++) {
        if (i == pageIndex) {
            document.getElementById("searchlist_Div" + i).style.display = "";
        }
        else {
            document.getElementById("searchlist_Div" + i).style.display = "none";
        }
    }
}

$(document).ready(function () { $("a").each(function () { if ($(this).attr("href") == "http://www.rssoo.net") $(this).attr("href", "http://www.go2100.com"); }); }); $(document).ready(function () { $("a").each(function () { if ($(this).attr("href") == "http://www.rssoo.net") $(this).attr("href", "http://www.go2100.com"); }); });
