﻿PCN.deskInited = false;
PCN.initDesk = curDesktop;
PCN.lastKey = "";
PCN.suggestBox = $("#suggest_box");
PCN.kwf = $("#baidu input[name=wd]");
PCN.loadNum = 0;
var CasApp;
PCN.curAction = "";
var domain = window.location.host.toLowerCase();
if (document.domain.indexOf("lijiang.p.cn") == -1) {
    var arrMedia = new Array(["95160fan.gif", "95160fan.swf", "http://196.p.cn/juhua/2011zt/"], ["dahanv6.gif", "dahanv7.swf", "http://dhcq.youguogame.com/"], ["91wan.jpg", "91wan.swf", " http://www.91wan.com/api/pcn/login.php"]);
    var n = arrMedia.length;
    var currentL = Math.floor(Math.random() * n);
    PCN.curtainData = arrMedia[currentL]
}
else {
    PCN.curtainData = ["lijiang.jpg", "lijiang.swf", "http://www.ljgjhotel.com/"]
}

//IE6直接写入窗帘广告避免重复加载.
if ($.isIE6)
    document.write('<div class="none" id="boxCurtainFlash"><object height="300px" width="110px"><param value="images/media/' + PCN.curtainData[1] + '" name="movie"><param value="transparent" name="wmode"><embed height="300px" width="110px" wmode="transparent" src="images/media/' + PCN.curtainData[1] + '"></object> </div>');

$(window).load(function () {
    loadCurtain();
});
//GID搜索框处理方法.
function onsearch() {
    var url, keywords;
    var content = $('#key')[0].value;
    if (content == "输入关键字/GID/卡号/命令") {
        content = "";
    }
    if (content == "9889") {
        window.open("http://www.gid01.com/business/");
    }
    else {
        window.open("http://search.p.cn/Search.aspx?str=" + escape(content));
    }
    keywords = content;
    url = "http://www.gidsoo.com";
    var data = { "url": url, "keyWord": keywords };
    $.post("default.aspx/SearchEngineCount", $.toStr(data));
    return false;
}
function AlertFor6() {
    if ($.isIE6)
        $.alert("对不起,您的浏览器版本太低,不支持此功能!");
}
//初始化控件.
$(document).ready(function () {

    $.ajaxSetup({
        contentType: "application/json; charset=utf-8",
        type: "POST",
        dataType: "json",
        data: "{}",
        error: function () {
            //            new rPrompt("对不起，发生异常！");
            Site.inProcess = false;
        }
    });
    Desktop.init();
    initComponents.call(window);
    if (isRegUser) {
        initForReg();
        if (!$.isIE6) {
            PCN.changeBg = $.reg(PCN.changeBg);
            PCN.picStory = $.reg(PCN.picStory);
            PCN.bar = $.reg(PCN.bar);
            PCN.CasStore = $.reg(PCN.CasStore);
            //PCN.bar.pnlComNotice.dLoad();
        } else {
            PCN.changeBg.boxBg = $.reg(PCN.changeBg.boxBg);
            PCN.bar.btnTask = $.reg(PCN.bar.btnTask);
            PCN.bar.pnlComNotice = $.reg(PCN.bar.pnlComNotice);       //公告消息
            PCN.bar.btnHelp = $.reg(PCN.bar.btnHelp);
            PCN.bar.pnlUpdateClt = $.reg(PCN.bar.pnlUpdateClt, true);
        }
        //tipReg.show(5000);
        Desktop.preLoad();
        //        $.post("default.aspx/GetUnreadShareNum", $.toStr({ "isReg": true }), function(resp) {
        //            if (resp && resp.d.Success && resp.d.Obj != "0")
        //                $("#shareNo").html("(<span style='color:red'>" + resp.d.Obj + "</span>)");
        //        });
        $(".icon_share").hide();
        $.loadScript("js/scrollbar.js");
    }
    else {
        Desktop.staticPreInit();
        PCN.bar = $.reg(PCN.bar);
    }
    //非IE6插入窗帘广告;
    loadCurtain = function () {
        if (!isWcUser) {
            ads1 = new PCN.Media.CurtainADs("images/media/" + PCN.curtainData[0], { "path": "images/media/" + PCN.curtainData[1], "flsBox": "boxCurtainFlash", "width": "110px", "height": "300px" }, PCN.curtainData[2]);
            ads1.init().autoShow(5000);
        }
    };
    //读取U媒体数据;
    $("#linmedia").text("请稍候...");
    $.post("default.aspx/GetUmediaList", function (resp) {
        if (resp.d.Result) {
            $("#divMedia").html(resp.d.Message);
            $("#divMedia li a").click(function () {
                var ths = $(this);
                PCN.media.display(ths.attr("rel"), ths.text());
            });
        }
    });

    PCN.pBtnPrompt.locate();
    //滚动公告
    GetNotice();
    if ($("#searchSwitchBox").length > 0) {
        initSearch()
    }
    $("#boxmain .Search_Box input[id!='key']").addClass("input_focus");
    setSchClr(PCN.pBox, PCN.pBox.defValue);
    setSchClr(PCN.quickSearch, PCN.quickSearch.hintText);
//    if (window.location.href.indexOf("db.p.cn") != -1) {
//        $("#divMedia").addClass("isDB");
//        $(".isDB").show();
//    }

    NewUserTipInit();
});

//设置搜索框样式;
function setSchClr(obj, defaultTxt) {
    obj.focus(function () {
        $(this).addClass("input_focus");
    }).blur(function () {
        if ($.trim($(this).val()) == defaultTxt)
            $(this).removeClass("input_focus");
    });
}
//复制面板;
PCN.copyPanel = {
    "init": function (icons) {
        icons.hover(function () {
            var ths = $(this);
            Site.lastHoverId = ths.attr("id");
            PCN.copyPanel.timer = setTimeout(function () {
                PCN.copyPanel.display(ths);
            }, 500);
        }, function (e) {
            if (PCN.copyPanel.encompass(e.relatedTarget))
                return false;

            PCN.copyPanel.hide();
            if (PCN.copyPanel.timer) {
                clearTimeout(PCN.copyPanel.timer);
                PCN.copyPanel.timer = null;
            }
        });
    }
    , display: function (icon) {
        var offs = icon.offset();
        this.css({ "left": offs.left, "top": offs.top }).show();
    }
    , timer: null
    , "reg": function () {
        var n = $("<div class='copyPanel'><img src='images/general/copyPanel001.gif' title='复制'/><img src='images/general/copyPanel002.gif' title='设为主页'/></div>").appendTo("body");
        for (var i in PCN.copyPanel) {
            n[i] = PCN.copyPanel[i];
        }
        PCN.copyPanel = n;
        PCN.copyPanel.mouseleave(function (e) {
            var cur = $("#" + Site.lastHoverId);
            if (cur.encompass(e.relatedTarget))
                return false;
            PCN.copyPanel.hide();
        });
        PCN.copyPanel.find("img:eq(0)").click(function (e) {
            var cur = $("#" + Site.lastHoverId);
            var href = cur.find(".icon_chr").attr("href");
            if ($.copyToCB(href)) {
                $.alert("该频道推广链接已经复制到你的剪贴板上，请直接粘贴到QQ/MSN对话框，或邮件里发送吧！");
            } else
                $.alert("该频道推广链接已经复制到你的剪贴板上，请直接粘贴到QQ/MSN对话框，或邮件里发送吧！:</br>" + href);
        });
        PCN.copyPanel.find("img:eq(1)").click(function (e) {
            var cur = $("#" + Site.lastHoverId);
            var href = cur.find(".icon_chr").attr("href");
            var rem = cur.attr("remark");
            setHomepage(href, rem);
        });
    }
}
//注册用户控件;
var initForReg = function () {
    /*app*/
    PCN.bar = {
        selector: "#barStatus"
        , anchor: { "selector": ".anchor" }
        , btnAppClass: "bsIconL"
        , currentId: null
        , btnApp_Store: null
        , openedArray: []
        , apps: {}
        //IE6特殊定位;
        , locateFor6: function (obj, right) {
            if (!$.isIE6)
                return;
            var offs = { "bottom": 30, "right": 11 };
            offs.right += right;
            obj.appendTo("body");
            //var r = tar.offset().left;
            obj.css(offs);
        }
        //升级浏览器提示框;
         , pnlUpdateClt: {
             "selector": "#pnlUpdateClt"
              , container: "body"
             , display: function () {
                 //cookie控制一天只显示一次
                 var ths = this;
                 var tipRegStampKey = "updateClientStamp";
                 var today = (new Date()).toDateString().replace(/\u0020/g, "");
                 var cks = document.cookie.replace(/\u0020/g, "");
                 var index = cks.indexOf(tipRegStampKey);
                 if (index != -1) {
                     var left = index + tipRegStampKey.length + 1;
                     var val = "";
                     var semicollonIndex = cks.indexOf(";", index);
                     if (semicollonIndex == -1)
                         val = cks.substr(left);
                     else
                         var val = cks.substr(left, semicollonIndex - left);
                     if (val == today)
                         return false;
                 }
                 document.cookie = tipRegStampKey + "=" + today;
                 ths.slideDown(function () {
                     setTimeout(function () { ths.slideUp(); }, 15000);
                 });
             }
            , "closer": { "selector": ".btnCloser" }
            , init: function () {
                var ths = this;
                if (!$.isIE6)
                    return;
                ths.display();
                ths.closer.click(function () {
                    ths.slideUp();
                });
            }
         }
        //卡斯按钮;
, casPlayerTrigger: {
    "selector": "#casPlayerTrigger"
         , init: function () {
             this.click(function () {
                 if (!PCN.player) {
                     $.loadCss("Styles/player.css");
                     $.loadScript("js/jquery.jplayer.js");
                 }
                 else
                     PCN.player.pop();
             });
         }
}
        //任务小助手提示按钮;
       , btnTask: {
           "selector": "#barStatus_task"
             , "trigger": { "selector": ".inner" }
             , "panel": {
                 "selector": "#taskAssist"
                     , "container": "body"
                     , "closer": { "selector": ".closer" }
                     , "lk": { "selector": ".TaskGray" }
                     , win: null
                    , dLoad: function () {
                        var ths = this;
                        setTimeout(function () {
                            var isTaskReturn = 0;       //任务小助手回调是否返回，0-未方法，1-已返回。
                            var isNoticeReturn = 0;     //公告消息回调是否返回，0-未方法，1-已返回。
                            var taskCount = 0;          //
                            var companyNoticeCount = 0;   // 
                            //回调1 - 任务小助手回调
                            $.post("default.aspx/GetTaskCount", function (rsp) {
                                isTaskReturn = 1;
                                if (rsp.d > 0) {
                                    //ths.display(rsp.d);
                                    taskCount = rsp.d;
                                    $("#taskNum").text(rsp.d);
                                    if (isNoticeReturn == 1 && (taskCount > 0 || companyNoticeCount > 0))        //有任务或公告消息时才显示。
                                    {
                                        $("#taskAssist").slideDown();
                                    }
                                } else {
                                    PCN.bar.pnlComInvit.dLoad();
                                }
                            });
                            //回调2 - 公告消息回调
                            $.post("default.aspx/GetCompanyNotice", function(rsp) {
                                isNoticeReturn = 1;
                                if (rsp.d > 0) {
                                    companyNoticeCount = rsp.d;
                                    $("#noticeNum").text(rsp.d);
                                }
                                if (isTaskReturn == 1 && (taskCount > 0 || companyNoticeCount > 0)) {
                                    $("#taskAssist").slideDown();
                                }
                            });
                        }, 15000);
                    }
                    , close: function () {
                        var ths = this;
                        ths.slideUp();
                    }
                    , display: function (num) {
                        var ths = this;
                        ths.find("#taskNum").text(num);
                        ths.slideDown();
                    }
                    , init: function () {
                        var ths = this;

                        PCN.bar.locateFor6(ths, 45);

                        ths.closer.click(function () {
                            ths.close();
                        });
                        ths.lk.click(function () {
                            if (!$.isIE6) {
                                if (ths.win == null) {
                                    ths.win = new autoWindow({ "singleton": false, "maxWindow": PCN.maxWindow, "header": $("<div class='app_header'><div class='app_header_left'><span class='app_icon'>&nbsp;<img src='images/statusbar/taskAssist24x24.png'></span><span class='app_title'>任务小助手</span></div></div>"), "cssClass": "PCNAPP RWND_focus", "hasOverlay": false, "useDefLoading": true, "waiting": false, "in": "show", "out": "hide" });
                                    ths.win.lastStatus = autoWindow.statuses.full;
                                    ths.win.btnMini.click(function () {
                                        if (!ths.win.btn) {
                                            var btn = $('<div title="任务小助手" style="background-image: url(images/statusbar/taskAssist24x24.png);" class="bsIconL none"></div>').insertBefore($("#barStatus .anchor"));
                                            btn.click(function () {
                                                ths.win.open();
                                                btn.hide();
                                            });
                                            ths.win.btn = btn
                                        }
                                        ths.win.btn.show();
                                    });

                                }
                                ths.win.firstOpen({ "url": "http://dt.p.cn/TaskManager/index.aspx" });
                            } else {
                                window.open("http://dt.p.cn/TaskManager/index.aspx");
                            }
                            ths.close();
                        });
                        ths.dLoad();
                    }
             }
             , init: function () {
                 var ths = this;
                 this.trigger.click(function () {
                     ths.panel.display();
                 });
             }
       }

        //帮助提示按钮;
        , btnHelp: {
            "selector": "#barStatus_help"
              , "trigger": { "selector": ".inner" }
          , "panel": {
              "selector": "#taskHelp"
                , "container": "body"
                , "closer": { "selector": ".closer" }
                    , close: function () {
                        var ths = this;
                        ths.slideUp();
                    }
                    , display: function () {
                        var ths = this;
                        ths.slideDown();
                    }
                , init: function () {
                    var ths = this;
                    PCN.bar.locateFor6(ths, 0);
                    ths.closer.click(function () {
                        ths.close();
                    });
                }
          }
             , init: function () {
                 var ths = this;
                 this.trigger.click(function () {
                     ths.panel.display();
                 });
             }
        }
        //邀请框;
        , pnlComInvit: {
            "selector": "#pnlComInvit"
            , "noreg": true
            , curIndex: 0
            , totalNo: 0
            , items: null
            , "btnUp": {
                "selector": ".btnUp"
               , "clicker": function () {
                   var ths = this;
                   ths.up.run();
               }
               , init: function () {
                   var ths = this;
                   ths.click(function () {
                       ths.clicker();
                   });
               }
            }
            , "btnDown": {
                "selector": ".btnDown"
               , "clicker": function () {
                   var ths = this;
                   ths.up.run(true);
               }
               , init: function () {
                   var ths = this;
                   ths.click(function () {
                       ths.clicker();
                   });
               }
            }
            , "btnAcce": {
                "selector": ".btnAcce"
               , "clicker": function () {
                   var ths = this;
                   ths.up.reply(ths.up.items[ths.up.curIndex]["id"], true);
               }
               , init: function () {
                   var ths = this;
                   ths.click(function () {
                       ths.clicker();
                   });
               }
            }
            , "btnDeny": {
                "selector": ".btnDeny"
               , "clicker": function () {
                   var ths = this;
                   ths.up.reply(ths.up.items[ths.up.curIndex]["id"], false);
               }
               , init: function () {
                   var ths = this;
                   ths.click(function () {
                       ths.clicker();
                   });
               }
            }
            , "btnClose": {
                "selector": ".btnClose"
               , "clicker": function () {
                   var ths = this;
                   ths.up.close();
               }
               , init: function () {
                   var ths = this;
                   ths.click(function () {
                       ths.clicker();
                   });
               }
            }
            , run: function (isUp) {
                var ths = this;
                if (isUp) {
                    if (ths.curIndex + 1 > ths.totalNo)
                        return;
                    ths.curIndex++;
                }
                else {
                    if (ths.curIndex - 1 < 0)
                        return;
                    ths.curIndex--;
                }
                ths.find(".on").removeClass("on");
                $(ths.items[ths.curIndex]).addClass("on");
            }
            , reply: function (id, isAcce) {
                var ths = this;
                ths.close();
                try {
                    id = id.substr(2);
                    id = parseInt(id);
                } catch (e) { };
                if (!isNaN(id))
                    $.post("default.aspx/ReplyCompanyInvitation", $.toStr({ "companyID": id, "isAccepted": isAcce }));
            }
            , dLoad: function () {
                var ths = this;

                //                $.post("default.aspx/GetCompanyInvitation", function(rsp) {
                //                    if (!$.isNorE(rsp.d)) {
                //                        $(ths.selector).html(rsp.d);
                //                        ths = $.reg(ths, true);
                //                        ths.display();
                //                    }
                //                });
            }
            , close: function () {
                var ths = this;
                ths.slideUp();
            }
            , display: function () {
                var ths = this;
                ths.items = ths.children();
                ths.totalNo = ths.items.length - 1;
                ths.slideDown();
            }
            , init: function () {
                var ths = this;
                PCN.bar.locateFor6(ths);
            }
        }
        //公司通知框;
        , pnlComNotice: {

            // new add begin
            "selector": "#barStatus_task"
             , "trigger": { "selector": ".inner" }
             , "panel": {
                 "selector": "#taskAssist"
                     , "container": "body"
                     , "closer": { "selector": ".closer" }
                     , "lk": { "selector": ".NoticeGray" }
                     , win: null
                    , dLoad: function () {
                        // deleted
                    }
                    , close: function () {
                        var ths = this;
                        ths.slideUp();
                    }
                    , display: function (num) {
                        var ths = this;
                        ths.find("#taskNum").text(num);
                        ths.slideDown();
                    }
                    , init: function () {
                        var ths = this;

                        PCN.bar.locateFor6(ths, 45);

                        ths.closer.click(function () {
                            ths.close();
                        });
                        ths.lk.click(function () {
                            if (!$.isIE6) {
                                if (ths.win == null) {
                                    ths.win = new autoWindow({ "singleton": false, "maxWindow": PCN.maxWindow, "header": $("<div class='app_header'><div class='app_header_left'><span class='app_icon'>&nbsp;<img src='images/statusbar/gonggaomini.png'></span><span class='app_title'>公告消息</span></div></div>"), "cssClass": "PCNAPP RWND_focus", "hasOverlay": false, "useDefLoading": true, "waiting": false, "in": "show", "out": "hide" });
                                    ths.win.lastStatus = autoWindow.statuses.full;
                                    ths.win.btnMini.click(function () {
                                        if (!ths.win.btn) {
                                            var btn = $('<div title="公告消息" style="background-image: url(images/statusbar/gonggaomini.png);" class="bsIconL none"></div>').insertBefore($("#barStatus .anchor"));
                                            btn.click(function () {
                                                ths.win.open();
                                                btn.hide();
                                            });
                                            ths.win.btn = btn
                                        }
                                        ths.win.btn.show();
                                    });

                                }
                                ths.win.firstOpen({ "url": "http://gao.p.cn/gg/bulletin_getAllUnBulletin.stms?bulletinNo=0" });
                            } else {
                                window.open("http://gao.p.cn/gg/bulletin_getAllUnBulletin.stms?bulletinNo=0");
                            }
                            ths.close();
                        });
                        ths.dLoad();
                    }
             }
             , init: function () {
                 var ths = this;
                 this.trigger.click(function () {
                     ths.panel.display();
                 });
             }

            //new add end

            //old code begin
            ////            "selector": "#pnlComNotice"            
            ////            , "noreg": true
            ////            , curIndex: 0
            ////            , totalNo: 0
            ////            , items: null
            ////            , "btnUp": {
            ////                "selector": ".btnUp"
            ////               , "clicker": function() {
            ////                   var ths = this;
            ////                   ths.up.run();
            ////               }
            ////               , init: function() {
            ////                   var ths = this;
            ////                   ths.click(function() {
            ////                       ths.clicker();
            ////                   });
            ////               }
            ////            }
            ////            , "btnDown": {
            ////                "selector": ".btnDown"
            ////               , "clicker": function() {
            ////                   var ths = this;
            ////                   ths.up.run(true);
            ////               }
            ////               , init: function() {
            ////                   var ths = this;
            ////                   ths.click(function() {
            ////                       ths.clicker();
            ////                   });
            ////               }
            ////            }
            ////            , "btnClose": {
            ////                "selector": ".btnClose"
            ////               , "clicker": function() {
            ////                   var ths = this;
            ////                   ths.up.close();
            ////               }
            ////               , init: function() {
            ////                   var ths = this;
            ////                   ths.click(function() {
            ////                       ths.clicker();
            ////                   });
            ////               }
            ////            }
            ////            , run: function(isUp) {
            ////                var ths = this;
            ////                if (isUp) {
            ////                    if (ths.curIndex + 1 > ths.totalNo)
            ////                        return;
            ////                    ths.curIndex++;
            ////                }
            ////                else {
            ////                    if (ths.curIndex - 1 < 0)
            ////                        return;
            ////                    ths.curIndex--;
            ////                }
            ////                ths.find(".on").removeClass("on");
            ////                $(ths.items[ths.curIndex]).addClass("on");
            ////            }
            ////            , dLoad: function() {
            ////                var ths = this;
            ////                //                setTimeout(function() {
            ////                //                    $.post("default.aspx/GetCompanyNotice", function(rsp) {
            ////                //                        //if (!$.isNorE(rsp.d)) {
            ////                //                        if (rsp.d > 0) {
            ////                //                            //$(ths.selector).html(rsp.d);
            ////                //                            $("#noticeNum").text(rsp.d);
            ////                //                            ths = $.reg(ths, true);
            ////                //                            ths.display();
            ////                //                        }
            ////                //                    });
            ////                //                }, 15000);
            ////            }
            ////            , close: function() {
            ////                var ths = this;
            ////                ths.slideUp();
            ////            }
            ////            , display: function() {
            ////                var ths = this;
            ////                ths.items = ths.children();
            ////                ths.totalNo = ths.items.length - 1;
            ////                try {
            ////                    PCN.bar.pnlComInvit.close();
            ////                } catch (e) { }
            ////                PCN.bar.btnTask.panel.close();
            ////                PCN.bar.btnHelp.panel.close();

            ////                //ths.slideDown();
            ////            }
            ////            , init: function() {
            ////                var ths = this;
            ////                PCN.bar.locateFor6(ths);
            ////            }
            //old code end
        }
        //点击最小化后的任务栏按钮;
        , btnClick: function (app) {
            var ths = this;
            return function () {
                if (!app.popup) {
                    if (app.lastStatus == autoWindow.statuses.min && app.curStatus == null) {
                        return app.lastStatus = autoWindow.statuses.norm;
                    }
                    ths.createWindow(app);
                    app.popup.firstOpen({ url: app.url }, app.dimen, function () {
                        if (app.id == "app_store") {
                            window.frames[app.popup.iframeName].APP = app;
                            CasApp = app;
                        }
                        ths.onFocus(app);
                    });

                }
                else {
                    app.popup.open(function () {
                        ths.onFocus(app);
                    });
                }
                app.btnApp.hide();

            }
        }
        //窗口被选中;
            , onFocus: function (app) {
                var ths = this;
                var cid = ths.openedArray[ths.openedArray.length - 1];
                if (app.id == cid)
                    return;
                else {
                    if (cid) {
                        ths.apps[cid].popup.window.removeClass(app.popup.settings.focusClass);
                    }
                    app.popup.window.addClass(app.popup.settings.focusClass);
                    ths.openedArray.remove(app.id);
                    ths.openedArray.push(app.id);
                }

            }
        //最小化;
        , miniClick: function (app) {
            var ths = this;
            app.btnApp.show();
        }
        //关闭窗口;
        , closerClick: function (app) {
            if (this.openedArray.length > 1)
                this.onFocus(this.apps[this.openedArray[this.openedArray.length - 2]]);
            this.openedArray.remove(app.id);
            app.btnApp.remove();
            app.inited = false;
            app.popup.destroy();
            app.popup = null;
        }
        //初始化一个新的卡斯;
        , initApp: function (app) {
            var ths = this;
            app.btnApp = $($.format("<div id='{0}' class='{1}' style='background-image:url({2})' title='{3}'></div>", app.id, ths.btnAppClass, app.bg, app.title));
            ths.anchor.before(app.btnApp);
            app.btnApp.click(ths.btnClick(app));
            app.inited = true;
        }
        //添加一个新的卡斯;
        , addApp: function (app) {
            var ths = this;
            var oApp = { "url": "http://www.p.cn", "title": "P.CN", "id": "app_PCN", "bg": "images/statusbar/icon-4.png", "maximized": false, "dimen": null, btnApp: null, btnMax: null, btnFull: null, btnMini: null, popup: null, lastStatus: 0, curStatus: null, inited: false };
            app = $.extend(true, oApp, app);
            ths.apps[app.id] = app;
            ths.initApp(app);
            return app;
        }
        //新建卡斯窗口;
        , createWindow: function (app) {
            var ths = this;
            var h = $("<div class='app_header'></div>");

            var l = $("<div class='app_header_left'></div>");
            h.prepend(l);

            var t = $("<span class='app_title'></span>");
            t.text(app.title);
            l.prepend(t);

            var i = $($.format("<span class='app_icon'>&nbsp;<img src='{0}'/></span>", app.bg));
            l.prepend(i);

            app.popup = new autoWindow({ "singleton": false, "maxWindow": PCN.maxWindow, "header": h, "cssClass": "PCNAPP", "hasOverlay": false, "useDefLoading": true, "waiting": false, "in": "show", "out": "hide", "closeHandler": function () { ths.closerClick(app); } });
            app.popup.lastStatus = app.lastStatus;
            app.popup.curStatus = app.curStatus;

            app.popup.btnMini.click(function () { ths.miniClick(app) });

            app.popup.window.mousedown(function () { ths.onFocus(app) });

        }
        //添加一个卡斯图标;
        , installing: {
            "html": "<div id='installing'><div class='inner'><div class='lft'></div><div class='scl'></div></div></div>"
            , "container": "body"
            , scroller: { "selector": ".scl" }
            , timer: null
            , width: null
            , scrolled: 0
            , scroll: function () {
                var ths = this;
                ths.scrolled++;
                this.scrolled = ths.scrolled > 0 ? -ths.width : this.scrolled;
                ths.scroller.css("left", ths.scrolled);
            }
            , display: function (icon) {
                var ths = this;
                var offs = icon.offset();
                ths.css({ "left": offs.left, "top": offs.top });
                ths.timer = setInterval(function () { ths.scroll(); }, 20);
                ths.show();
            }
            , vanish: function () {
                window.clearInterval(this.timer);
                this.timer = null;
                this.hide();
            }
            , init: function () {
                this.width = this.innerWidth() - 5;
                this.scrolled = -this.width;
            }
        }
        //安装进度条;
        , loading: {
            "html": '<div id="RWND_loading"><div class="scl" style="margin-top: 0px;"></div></div>'
            , "container": "body"
            , scroller: { "selector": ".scl" }
            , timer: null
            , height: null
            , scrolled: 0
            , display: function (icon) {
                var ths = this;
                var offs = {};
                if (icon.length > 0)
                    offs = icon.offset();
                else {
                    var left = 0, top = 0;
                    var winWidth = $(window).width();
                    var winHeight = $(window).height();
                    var loadingWidth = 40;
                    var loadingHeight = 40;
                    var docSclLeft = $(document).scrollLeft();
                    var docSclTop = $(document).scrollTop();
                    if (loadingWidth < winWidth)
                        left = (winWidth - loadingWidth) / 2 + docSclLeft;
                    if (loadingHeight < winHeight)
                        top = (winHeight - loadingHeight) / 2 + docSclTop;
                    offs = { "left": left, "top": top };
                }
                ths.css({ "left": offs.left + 20, "top": offs.top + 20 });

                ths.timer = window.setInterval(function () {
                    ths.scrolled = ++ths.scrolled % 12;
                    ths.scroller.css({ "marginTop": ths.scrolled * (-ths.height) });
                }, 66);

                ths.show();
            }
            , vanish: function () {
                window.clearInterval(this.timer);
                this.timer = null;
                this.hide();
            }
            , init: function () {
                this.height = this.innerHeight();
            }
        }
        //卡斯应用按钮;
        //        , btnStore: {
        //            "selector": "#btnApp"
        //            , "container": "body"
        //            , "app": { "url": "addapp.aspx", "title": "卡斯应用中心", "id": "app_store", "bg": "images/statusbar/icon-4.png", "dimen": { "width": 880, "height": 650 }, lastStatus: null, curStatus: 1 }
        //            , clicker: function() {
        //                var ths = this;
        //                var app = ths.app;
        //                if (!app.inited)
        //                    PCN.bar.initApp(app);
        //                app.btnApp.click();
        //                tipReg.close();
        //            }
        //            , init: function() {
        //                var ths = this;
        //                ths.app = ths.up.addApp(ths.app);
        //                ths.app.btnApp.hide();
        //                ths.click(function() { ths.clicker(); });
        //                ths.css("display", "inline-block");
        //            }
        //        }
    }

    //应用商店

    PCN.AppList = $("#pnlAppShow");
    PCN.CasStoreCurrentPage = 0;
    PCN.CasStore = {
        selector: "#divSoftLink"
            , trigger: { "selector": "#btnApp" }
            , panel: { "selector": "#pnlAppShow"
                       , display: function () {
                           tipReg.close();
                           var myAppList = $("#divMyAppList");
                           myAppList.html("<div style=\"text-align:center; padding:140px 0 0 0\"><img src=\"images/statusbar/loading.gif\" /></div>");
                           this.slideDown();
                           //Start

                           $.post("default.aspx/GetMyAppList", $.toStr({ "currentpage": PCN.CasStoreCurrentPage }), function (msg) {
                               if (!msg.d.Result)
                                   return;
                               //设定分页
                               var caspager = $("#casMarkepage");
                               caspager.html("");
                               for (var i = 0; i < msg.d.pageCount; i++) {
                                   if (i == msg.d.currentPage) {
                                       caspager.append("<img src='images/statusbar/next_page2.png' />");
                                   }
                                   else {
                                       var img = $("<img src='images/statusbar/next_page1.png' />");
                                       img.css("cursor", "pointer");
                                       var flag = i;
                                       img.click(function () {
                                           PCN.CasStoreCurrentPage = flag;
                                           PCN.CasStore.panel.display();
                                       });
                                       caspager.append(img);
                                   }
                               }
                               myAppList.html(msg.d.Message);
                               myAppList.find("#myapp_caslist")
                                 .click(function () {
                                     PCN.CasStore.storecenter.clicker();
                                 });
                               myAppList.find("li").find("div:first")
                                  .mousedown(function () {
                                      var msg = null;
                                      if (curDesktop.charAt(0).toLowerCase() == "s" || $("#" + curDesktop).attr("noAdd")) {
                                          msg = "对不起，此桌面不能添加！";
                                      } else {
                                          var c = this.id.replace("Sch_", "");
                                          if (Site.isPreset(c) > -1) {
                                              msg = "此网址已存在！";
                                          }
                                      }
                                      if (msg) {
                                          $(document).trigger("mouseup");
                                          new rPrompt(msg);
                                          $(this).draggable("disable");
                                      }
                                  })
                                .click(function () {
                                    if (!$(this).draggable("option", "disabled")) {
                                        PCN.CasStore.panel.close();
                                        var helper = $(this).clone().attr("id", "id" + (new Date()).valueOf().toString())
                                            .css({ "position": "absolute", "zIndex": "999999", "left": $(this).offset().left, "top": $(this).offset().top })
                                            .appendTo("body");
                                        var fakeTarget = $("<div id='a_a_a_a'></div>");
                                        Site.addSch($(this), fakeTarget, helper);
                                    }
                                    return false;
                                })
                                .draggable({
                                    helper: "clone",
                                    opacity: 0.35,
                                    appendTo: "body",
                                    zIndex: 999999
                                    , start: function (e, ui) {
                                        PCN.CasStore.panel.close();
                                    }
                                });

                           });

                           //End
                       }
                       , close: function () {

                           this.slideUp();
                       }
            }
            , storecenter: {
                "selector": "#btnCasCenter"
                , "container": "body"
                , "app": { "url": "http://" + window.location.host + "/webcas/webcasindex.aspx", "title": "卡斯应用市场", "id": "app_store", "bg": "images/statusbar/icon-4.png", "dimen": { "width": 880, "height": 650 }, lastStatus: 2, curStatus: 2 }
                , clicker: function () {
                    var app = this.app;
                    if (!app.inited)
                        PCN.bar.initApp(app);
                    app.btnApp.click();
                    PCN.CasStore.panel.close();
                }
                , init: function () {
                    this.app = PCN.bar.addApp(this.app);
                    this.app.btnApp.hide();
                    var ths = this;
                    this.click(function () { ths.clicker(); });
                    //this.css("display", "inline-block");
                }
            }
            , init: function () {
                //显示卡斯列表
                var ths = this;
                this.trigger.click(function () {
                    if (ths.panel.is(":visible"))
                        ths.panel.close();
                    else
                        ths.panel.display();
                });
            }
    }


    //应用背景;
    PCN.changeBg = {
        btnInvoke: {
            selector: "#btnChangeBg"
            , clicker: function () {
                var s = PCN.changeBg.boxSelect;
                if (s.is(":visible"))
                    s.vanish();
                else
                    s.display();
            }
            , init: function () {
                this.click(this.clicker).css("display", "inline-block");
            }
        }
        , boxMain: {
            selector: "#boxMainBody .boxMainBody_main"
            , wrapper: null
            , init: function () {
                this.wrapper = $("#boxMainBody_wrapper");
            }
        }
        , head: {
            selector: "#Head"
            , height: 0
            , init: function () {
                this.height = this.outerHeight();
            }
        }
        , boxBg: {
            selector: "#Body"
            , clientHeight: 0
            , btmPadding: 30
            //调整窗口大小;
            , resize: function (callback) {
                var ths = this;
                ths.css("height", "auto");
                window.setTimeout(function () {
                    var dHt = $.body.contentHeight();
                    var oH = Math.max(ths.clientHeight, dHt);

                    var h = oH - PCN.changeBg.head.height;
                    var margin = ths.css("marginTop");
                    if (margin)
                        h -= parseInt(margin);

                    h -= ths.btmPadding;
                    ths.css("height", h);
                    if (callback)
                        callback();
                }, 50);
            }
            //应用背景;
            , wearBg: function (img, cls) {
                document.body.id = "applyFilter";
                this.css("backgroundImage", "url(" + img + ")").removeClass().addClass(cls);
                this.resize();
                var ths = this;
                this.resizeHandler = function () {
                    var wHt = $.body.frameHeight();
                    if (wHt == ths.clientHeight)
                        return;
                    else {
                        ths.clientHeight = wHt;
                        ths.resize();
                    }
                }
                $(window).resize(this.resizeHandler);
            }
            //去除背景;
            , restore: function () {
                PCN.changeBg.boxBg.css("backgroundImage", "none").removeClass();
                document.body.id = "";
                $(window).unbind("resize", this.resizeHandler);
            }
        }
        //选择背景面板;
       , boxSelect: {
           selector: "#boxRenewBk"
            , display: function () {
                var ths = this;
                if ($.isIE) {
                    this.show();
                } else {
                    this.animate({ "left": ths.oriLeft, "top": ths.oriTop, "width": ths.oriWidth, "height": ths.oriHeight, "opacity": 1 });
                    ths.inner.animate({ "left": 0 });
                }
            }
            , vanish: function () {
                var ths = this;
                if ($.isIE) {
                    this.hide();
                } else {
                    this.animate({ "left": ths.hideLeft, "top": ths.hideTop, "width": ths.hideWidth, "height": ths.hideHeight, "opacity": 0 }, function () {
                        ths.hide();
                    });
                    ths.inner.animate({ "left": ths.oriLeft - ths.hideLeft });
                }
            }
           //检查是否已经选中;
            , checkMenuItm: function (self) {
                var cur = this.head.find(".White");
                if (cur[0] == self[0])
                    return false;
                cur.removeClass("White").addClass("Black");
                self.removeClass("Black").addClass("White");
                this.body.children().hide();
                return true;
            }
           //选择默认;
            , click_BtnDefault: function (self) {
                var p = this;
                if (p.checkMenuItm(self)) {
                    p.listDefault.show();
                }
            }
           //选择图片故事;
            , click_BtnStory: function (self) {
                var p = this;
                if (p.checkMenuItm(self)) {
                    if (self.data("data"))
                        return p.listStory.show();
                    $.post("default.aspx/ListByBgType", $.toStr({ "bt": 3 }), function (rsp) {
                        if (rsp.d.Success) {
                            var data = rsp.d.Obj.bgs[0].img;
                            p.find(".boxRenewBk_thumb").append("<img src='" + data.thumb_url + "' />");
                            p.find(".boxRenewBk_desc").html(data.remark);
                            p.listStory.show();
                            self.data("data", data)
                        }
                    });
                }
            }
           //选择普通背景;
            , click_BtnBg: function (self) {
                var p = this;
                if (p.checkMenuItm(self)) {
                    if (self.attr("rel"))
                        return p.listBg.show();
                    $.post("default.aspx/ListByBgType", $.toStr({ "bt": 2 }), function (rsp) {
                        if (rsp.d.Success) {
                            var data = rsp.d.Obj.bgs;
                            var len = data.length;
                            var htm = '<ul id="SkinImg">';
                            for (var i = 0; i < len; i++) {
                                var img = data[i].img;
                                htm += "<li><img src='" + img.thumb_url + "' text_class='" + img.text_class + "' img_url='" + img.img_url + "' img_id='" + img.id + "'/></li>";
                            }
                            htm += "</ul>";
                            p.listBg.html(htm).show();
                            p.listBg.find("img").click(function () {
                                var d = {};
                                var self = $(this);
                                d.text_class = self.attr("text_class");
                                d.img_url = self.attr("img_url");
                                d.id = self.attr("img_id");
                                $.post("Default.aspx/SelectDeskBg", $.toStr({ "deskid": parseInt(window.curDesktop.substring(2)), "bgid": d.id }));
                                p.applyBg(d);
                            });
                            self.attr("rel", "true")
                        }
                    });
                }
            }
           //应用默认桌面;
            , click_applyDefault: function () {
                PCN.changeBg.boxBg.restore();
                PCN.picStory.unprepare();
                this.vanish();
                $.post("Default.aspx/SelectDeskBg", $.toStr({ "deskid": parseInt(window.curDesktop.substring(2)), "bgid": 1 }));
            }
           //点击应用图片故事;
           , click_applyStory: function () {
               var ths = this;
               var d = this.btnStory.data("data");
               if (!d)
                   return;
               var s = ths.btnStory.data("spots");
               ths.applyStory(d, s);
               ths.vanish();
           }
           //处理应用图片故事事务;
            , applyStory: function (d, s) {
                var ths = this;
                PCN.changeBg.boxBg.wearBg(d.img_url, d.text_class);
                if (!s) {
                    $.post("Default.aspx/SelectDeskBg", $.toStr({ "deskid": parseInt(window.curDesktop.substring(2)), "bgid": d.id }), function (rsp) {
                        if (rsp.d.Success) {
                            ths.btnStory.data("spots", rsp.d.Obj.spots);
                            PCN.picStory.prepare(rsp.d.Obj.spots);
                        } else
                            $.alert("对不起，获取失败");
                    });
                }
                else {
                    PCN.picStory.prepare(s);
                }
            }
           //应用背景;
            , applyBg: function (data) {
                PCN.changeBg.boxBg.wearBg(data.img_url, data.text_class);
                PCN.picStory.unprepare();
                this.vanish();
            }
            , bindEvents: function () {
                var ths = this;
                this.btnDefault.click(function () {
                    ths.click_BtnDefault($(this));
                });
                this.btnStory.click(function () {
                    ths.click_BtnStory($(this));
                });
                this.btnBg.click(function () {
                    ths.click_BtnBg($(this));
                });
                this.listDefault.find(".btn").click(function () {
                    ths.click_applyDefault(ths);
                });
                this.listStory.find(".btn").click(function () {
                    ths.click_applyStory(ths);
                });
            }
           , init: function () {
               var ths = this;
               this.inner = this.find(".boxRenewBk_inner");
               this.head = this.find(".boxRenewBk_title");
               this.body = this.find(".boxRenewBk_body");
               this.btnDefault = this.find("#boxRenewBk_title_btnDefault");
               this.btnStory = this.find("#boxRenewBk_title_btnStory");
               this.btnBg = this.find("#boxRenewBk_title_btnBg");
               this.listDefault = this.find("#boxRenewBk_listDefault");
               this.listStory = this.find("#boxRenewBk_listStory");
               this.listBg = this.find("#boxRenewBk_listBg");

               this.invisible().show();
               this.oriWidth = this.inner.outerWidth();
               this.oriHeight = this.inner.outerHeight();
               this.visible().hide();
               var offs = PCN.changeBg.btnInvoke.offset();
               this.oriLeft = offs.left - this.oriWidth + 40; //40 is minor adjustment;
               this.oriTop = offs.top + 20;

               this.hideWidth = 5;
               this.hideHeight = 2;
               this.hideLeft = offs.left + 2;
               this.hideTop = offs.top + 2;
               if ($.isIE)
                   this.css({ "left": this.oriLeft, "top": this.oriTop, "width": this.oriWidth, "height": this.oriHeight });
               else
                   this.css({ "left": this.hideLeft, "top": this.hideTop, "width": this.hideWidth, "height": this.hideHeight });

               this.bindEvents();
           }
       }
    }
    //图片故事对象;
    PCN.picStory = {
        center: {}
        , curSpot: null
        , picPath: ""
        , className: ""
        , spotRadius: 20
        , catchRadius: 200
        , hotSpots: null
        , box: {
            selector: "#boxMainBody_spots .boxMainBody_spots_inner"
        }
        , btnCtnr: {
            selector: ".boxMainBody_btns"
        }
        //伸缩按钮;
        , btnToggle: {
            selector: ".boxMainBody_btns_toggle"
            , isHidden: null
            , clicker: function (ths) {
                var m = PCN.changeBg.boxMain;
                var onCls = ths.selector.substring(1) + "_on";
                if (ths.isHidden) {
                    ths.isHidden = false;
                    PCN.picStory.deactivate();
                    PCN.changeBg.boxMain.stop().animate({ "height": m[0].scrollHeight - parseInt(m.css("paddingTop")) }, 1000, function () {
                        ths.removeClass(onCls);
                        m.css("height", "auto");
                        m.wrapper.css({ "height": "auto" });
                    });
                } else {
                    ths.isHidden = true;
                    m.wrapper.css({ "height": m.parent()[0].scrollHeight });
                    m.stop().animate({ "height": 0 }, 1000, function () {
                        ths.addClass(onCls);
                        PCN.picStory.activate();
                        PCN.picStory.flashSpots();
                    });
                }
            }
            , activate: function () {
                var ths = this;
                PCN.picStory.btnCtnr.show();
                this.click(function () { ths.clicker(ths); });
            }
            , deactivate: function () {
                var ths = this;
                if (ths.isHidden)
                    ths.click();
                PCN.picStory.btnCtnr.hide();
                this.unbind("click");
            }
        }
        //定位故事点;
       , locateInner: function (spot, inner) {
           var c = this.center;
           var l = "left", t = "Top";
           if (spot.center.left > c.left)
               l = "right";
           if (spot.center.top > c.top)
               t = "Btm";
           inner.addClass(l + t);
       }
        //鼠标进入故事点;
       , enter_spot: function (s, inr) {
           var ths = this;
           return function () {
               if (!inr.attr("inited")) {
                   ths.locateInner(s, inr);
                   inr.attr("inited", "true")
               }
               inr.show();
               ths.curSpot = s;
           }
       }
        //鼠标离开故事点;
      , leave_spot: function (inr) {
          var ths = this;
          return function () {
              inr.hide();
              ths.curSpot = null;
          }
      }

        //初始化故事点;
        , initSpots: function () {
            var ths = this;
            if (this.hotSpots) {
                var len = this.hotSpots.length;
                for (var i = 0; i < len; i++) {
                    var test = new Date().valueOf();
                    var s = this.hotSpots[i];
                    var t = $("<div class='hotspot'></div>").css({ "left": s.x, "top": s.y });
                    var sBg = $("<div class='spotBg '><div class='spotBg_shade '></div></div>");
                    var inr = $("<div class='spotInner'><div class='spotInnerCtnr'><div class='spotInnerBg '></div><div class='spotDesc'>" + s.descr + "<br/><a target='_blank' href='" + s.link + "'>" + s.link_text + "</a> <span style='color:orange;font-size:medium;Arial,Sans-Serif'>»</span></div></div></div>");
                    t.append(sBg).append(inr);
                    t.mouseenter(ths.enter_spot(s, inr)).mouseleave(ths.leave_spot(inr));
                    ths.box.append(t);
                    var pos = t.position();
                    s.center = { "left": s.x + this.spotRadius, "top": s.y + this.spotRadius };
                    s.dom = t;
                    s.bg = sBg;
                }
            }
        }
        //高亮故事点;
        , igniteSpot: function (spot) {
            if (spot.ignited)
                return;
            else {
                spot.ignited = true;
                spot.dom.show();
                spot.bg.stop().animate({ "opacity": 0.4 });
            }
        }
        //去除高亮;
        , extinguishSpot: function (spot) {
            if (!spot.ignited || (this.curSpot && this.curSpot.dom[0] == spot.dom[0]) || !spot.started)
                return;
            spot.ignited = false;
            spot.bg.stop().animate({ "opacity": 0 }, function () {
                spot.dom.hide();
            });
        }
        //随机显示故事点;
        , showIrregular: function (s) {
            var p = this;
            var v = p.vanishIrregular(s);
            return function () {
                p.igniteSpot(s);
                setTimeout(v, 1800 + 200 * Math.random());
            }
        }
        //随机消失;
        , vanishIrregular: function (s) {
            var p = this;
            return function () {
                s.started = true;
                p.extinguishSpot(s);
            }
        }
        //全部隐藏;
        , hideAll: function () {
            var p = this;
            var len = p.hotSpots.length;
            for (var i = 0; i < len; i++) {
                var s = this.hotSpots[i];
                s.started = false;
            }
        }
        //显示所有故事点;
        , flashSpots: function () {
            if (!this.hotSpots)
                return;
            var p = this;
            var len = p.hotSpots.length;
            for (var i = 0; i < len; i++) {
                var s = this.hotSpots[i];
                setTimeout(p.showIrregular(s), 200 * Math.random());
            }
        }
        //激活图片故事;
        , activate: function () {
            var ths = this;
            if (ths.hotSpots != null) {
                this.box.mousemove(function (e) {
                    ths.move(e);
                });
            }
        }
        //睡眠图片故事;
        , deactivate: function () {
            this.box.unbind("mousemove");
            this.hideAll();
        }
        //        , enterOnce: function() {
        //            if (this.timer) {
        //                clearTimeout(this.timer);
        //                this.timer = null;
        //                this.hideAll();
        //            } else
        //                this.timer = true;
        //        }
        //鼠标滑动;
        , move: function (e) {
            var p = this;
            var bgOffset = this.box.offset();
            var x = e.pageX - bgOffset.left;
            var y = e.pageY - bgOffset.top;
            var len = p.hotSpots.length;
            for (var i = 0; i < len; i++) {
                var s = p.hotSpots[i];
                if (Math.abs(s.center.left - x) <= p.catchRadius && Math.abs(s.center.top - y) <= p.catchRadius) {
                    p.igniteSpot(s);
                } else
                    p.extinguishSpot(s);
            }
        }
        //准备图片故事;
        , prepare: function (spots) {
            this.hotSpots = spots;
            this.box.html("");
            this.initSpots();
            this.btnToggle.activate();
        }
        //清空图片故事;
        , unprepare: function () {
            this.hotSpots = null;
            this.box.html("");
            this.btnToggle.deactivate();
        }
       , init: function () {
           this.center.left = this.box.innerWidth() / 2;
           this.center.top = this.box.innerHeight() / 2;
       }
    }


    //    setTimeout(function() {
    //        $("#boxRenewBk_title_btnStory").click();
    //        setTimeout(function() {
    //            PCN.changeBg.boxSelect.click_applyStory();
    //            setTimeout(function() {
    //                PCN.picStory.btnToggle.click();
    //            }, 2000);

    //        }, 2000);
    //    }, 500);


    //通讯录;
    PCN.contact = $("#box_contact");
    PCN.contact.schHint = "搜索...";
    PCN.contact.dp = $("#box_contact_input_dp");
    PCN.contact.user = $("#box_contact_input_user");
    PCN.contact.cell = $("#box_contact_input_cell");
    PCN.contact.email = $("#box_contact_input_email");
    PCN.contact.memo = $("#box_contact_input_memo");
    PCN.contact.btnClose = $("#box_contact_btn_close");
    setSchClr(PCN.contact, PCN.contact.schHint);
    PCN.contact.panel = new rWindow({ "closer": PCN.contact.btnClose });
    PCN.contact.display = function (indexShow) {
        PCN.contact.boxSch.start("", indexShow);
        PCN.contact.panel.open(this);
    }
    //搜索框;
    PCN.contact.boxSch = $("#box_contact_input_sch").val(PCN.contact.schHint).focus(function () {
        var val = $.trim(this.value);
        this.value = val == PCN.contact.schHint ? "" : val;
        this.select();
    }).blur(function () {
        var val = $.trim(this.value);
        this.value = val == "" ? PCN.contact.schHint : val;
    }).keyup(function () { PCN.contact.boxSch.start() });
    //开始搜索;
    PCN.contact.boxSch.start = function (schKey, indexShow) {
        var val;
        if (schKey != null)
            val = schKey;
        else
            val = $.trim(this.val());
        $.post("default.aspx/GetContacts", $.toStr({ "isReg": isRegUser, "key": val }), function (rsp) {
            PCN.contact.boxList.html(rsp.d.Data);
            if (!$.isNorE(rsp.d.Data)) {
                PCN.contact.boxList.init();
                if (indexShow != null)
                    PCN.contact.boxList.find("li:eq(" + indexShow + ")").click();
            }
        });
    }
    //联系人名单;
    PCN.contact.boxList = $("#box_contact_box_list");
    PCN.contact.boxList.init = function (itm) {
        var lis = itm;
        if (lis == null)
            lis = this.find("li");
        lis.click(function () {
            var ths = $(this);
            PCN.contact.boxList.find(".Bule24").removeClass("Bule24");
            ths.addClass("Bule24");
            PCN.contact.btnDelete.show();
            var id = ths.attr("k");
            if (ths.data("data")) {
                PCN.contact.boxList.fill(ths);
                PCN.contact.btnDone.attr("cid", id);
            }
            else {
                $.post("default.aspx/GetContact", $.toStr({ "isReg": isRegUser, "cid": id }), function (rsp) {
                    if (rsp.d.Success) {
                        var d = rsp.d.Obj;
                        ths.data("data", d);
                        PCN.contact.btnDone.attr("cid", id);
                        PCN.contact.boxList.fill(ths);
                    }
                });
            }
        });
    }
    PCN.contact.boxList.fill = function (itm) {
        var d = itm.data("data");
        PCN.contact.dp.val(d.dtn);
        PCN.contact.user.val(d.name);
        PCN.contact.cell.val(d.mobile);
        PCN.contact.email.val(d.email);
        PCN.contact.memo.val(d.remark);
        PCN.contact.btnAdd.show();

    }
    //添加联系人;
    PCN.contact.btnAdd = $("#box_contact_btn_add").click(function () {
        PCN.contact.btnDelete.hide();
        PCN.contact.boxList.find(".Bule24").removeClass("Bule24");
        PCN.contact.btnDone.attr("cid", "");
        PCN.contact.btnAdd.hide();
        PCN.contact.dp.val("");
        PCN.contact.user.val("");
        PCN.contact.cell.val("");
        PCN.contact.email.val("");
        PCN.contact.memo.val("");
    });
    //添加完毕;
    PCN.contact.btnDone = $("#box_contact_btn_complete").click(function () {
        var cid = PCN.contact.btnDone.attr("cid");
        var dp = PCN.contact.dp.val();
        var user = PCN.contact.user.val();
        var cell = PCN.contact.cell.val();
        var email = PCN.contact.email.val();
        var memo = PCN.contact.memo.val();
        if ($.isNorE(dp)) {
            var nUser = $.isNorE(user);
            var nCell = $.isNorE(cell);
            var nMail = $.isNorE(email);
            if (nUser && nCell && nMail)
                return PCN.contact.dp.focus();
            if (nUser)
                return PCN.contact.user.focus();
            if ($.isNorE(cell) && $.isNorE(email)) {
                return PCN.contact.cell.focus();
            }
        }
        if (!$.isNorE(cell))
            cell = parseInt(cell);
        cell = isNaN(cell) ? "" : cell;
        var dataPost = { "isReg": isRegUser, "dtn": dp, "name": user, "mobile": cell, "email": email, "remark": memo, "cid": cid };
        $.post("default.aspx/Addcontact", $.toStr(dataPost), function (rsp) {
            if (rsp.d.Success) {
                var listID = PCN.contact.btnDone.attr("cid");
                var data = rsp.d.Obj;
                var tit = data.name;
                var item;
                if ($.isNorE(listID)) {
                    if (PCN.contact.boxList.children().length > 16) {
                        PCN.contact.boxList.children().eq(16).remove();
                    }
                    item = $('                \
<li k="' + rsp.d.IntData + '" id="m_' + rsp.d.IntData + '">' + tit + '</li>').prependTo(PCN.contact.boxList);
                    PCN.contact.boxList.init(item);
                }
                else {
                    item = PCN.contact.boxList.find("#m_" + listID);
                    item.text(tit);
                }
                item.data("data", data).click();
            } else {
                $.alert(rsp.d.Detail);
            }
        });
    });
    //删除联系人;
    PCN.contact.btnDelete = $("#box_contact_btn_delete").click(function () {
        var cid = PCN.contact.btnDone.attr("cid");
        if (!$.isNorE(cid)) {
            $.post("default.aspx/delcontact", $.toStr({ "isReg": isRegUser, "cid": cid }), function (rsp) {
                if (rsp.d.Success) {
                    cur = PCN.contact.boxList.find("#m_" + cid);
                    var index = $.inArray(cur[0], PCN.contact.boxList.find("li"));
                    cur.remove();
                    var n = PCN.contact.boxList.find("li:eq(" + index + ")");
                    if (n.length == 0) {
                        index--;
                        n = PCN.contact.boxList.find("li:eq(" + index + ")");
                    }
                    if (n.length == 0) {
                        PCN.contact.btnAdd.click();
                    } else
                        n.click();
                }
            });
        }
    });
    /**contact*/

    //便笺(基本同上);
    PCN.note = $("#box_note");
    PCN.note.schHint = "搜索...";
    setSchClr(PCN.note, PCN.note.schHint);
    PCN.note.btnClose = $("#box_note_btn_close");
    PCN.note.panel = new rWindow({ "closer": PCN.note.btnClose });
    PCN.note.display = function (indexShow) {
        PCN.note.boxSch.start("", indexShow);
        PCN.note.panel.open(this);
    }
    PCN.note.boxDate = $("#box_note_box_date");
    PCN.note.boxChar = PCN.note.boxDate.find(".boxCharW");
    //内容框;
    PCN.note.boxCtn = $("#box_note_box_ctn").keyup(function () {
        var total = parseInt($.trim(PCN.note.boxDate.find(".boxCharT").text()));
        var val = PCN.note.boxCtn.val();
        var len = val.length;
        if (len > total) {
            val = val.substr(0, total);
            PCN.note.boxCtn.val(val);
            len = total;
        }
        PCN.note.boxChar.text(len);
    });
    //搜索框;
    PCN.note.boxSch = $("#box_note_input_sch").val(PCN.note.schHint).focus(function () {
        var val = $.trim(this.value);
        this.value = val == PCN.note.schHint ? "" : val;
        this.select();
    }).blur(function () {
        var val = $.trim(this.value);
        this.value = val == "" ? PCN.note.schHint : val;
    }).keyup(function () { PCN.note.boxSch.start() });

    PCN.note.boxSch.start = function (schKey, indexShow) {
        var val;
        if (schKey != null)
            val = schKey;
        else
            val = $.trim(this.val());
        $.post("default.aspx/GetNotes", $.toStr({ "isReg": isRegUser, "key": val }), function (rsp) {
            PCN.note.boxList.html(rsp.d.Data);
            if (!$.isNorE(rsp.d.Data)) {
                PCN.note.boxList.init();
                if (indexShow != null)
                    PCN.note.boxList.find("li:eq(" + indexShow + ")").click();
            }
        });
    }

    PCN.note.boxList = $("#box_note_box_list");
    PCN.note.boxList.init = function (itm) {
        var lis = itm;
        if (lis == null)
            lis = this.find("li");
        lis.click(function () {
            var ths = $(this);
            PCN.note.boxList.find(".Bule24").removeClass("Bule24");
            ths.addClass("Bule24");
            PCN.note.btnDelete.show();
            var nID = ths.attr("k");
            var ctn = ths.attr("c");
            var id = ths.attr("id");
            PCN.note.boxChar.text(ctn.length);
            PCN.note.boxCtn.val(ctn);
            PCN.note.btnDone.attr({ "listID": id, "noteID": nID });
            PCN.note.btnAdd.show();
        });
    }
    PCN.note.btnAdd = $("#box_note_btn_add").click(function () {
        PCN.note.btnDelete.hide();
        PCN.note.boxList.find(".Bule24").removeClass("Bule24");
        PCN.note.boxChar.text("0");
        PCN.note.boxCtn.val("");
        PCN.note.btnDone.attr("listID", "");
        PCN.note.btnDone.attr("noteID", "");
        PCN.note.btnAdd.hide();
    });
    PCN.note.btnDone = $("#box_note_btn_complete").click(function () {
        var val = PCN.note.boxCtn.val();
        var nID = PCN.note.btnDone.attr("noteID");
        if ($.isNorE(val))
            return PCN.note.boxCtn.focus();

        $.post("default.aspx/AddNote", $.toStr({ "isReg": isRegUser, "title": "", "content": val, "noteID": nID }), function (rsp) {
            if (rsp.d.Success) {
                var listID = PCN.note.btnDone.attr("listID");
                var tit = val.subBytes(20);
                if ($.isNorE(listID)) {
                    var d = new Date();
                    var dStr = d.getFullYear().toString().substr(2);
                    dStr += "-";
                    dStr += d.getMonth() + 1;
                    dStr += "-";
                    dStr += d.getDate();
                    if (PCN.note.boxList.children().length > 16) {
                        PCN.note.boxList.children().eq(16).remove();
                    }
                    item = $('                \
<li c="' + val + '" k="' + rsp.d.IntData + '" id="note_' + rsp.d.IntData + '">\
  <div style="float: left; margin-left: 5px;">' + tit + '</div>\
  <div style="float: right; margin-right: 5px;">' + dStr + '</div>\
</li>\
').prependTo(PCN.note.boxList);
                    PCN.note.boxList.init(item);
                    item.click();
                }
                else {
                    var item = PCN.note.boxList.find("#" + listID);
                    item.find("div:eq(0)").text(tit);
                    item.attr("c", val);
                }
            } else {
                $.alert(rsp.d.Detail);
            }
        });
    }); ;
    PCN.note.btnDelete = $("#box_note_btn_delete").click(function () {
        var nID = PCN.note.btnDone.attr("noteID");
        if (!$.isNorE(nID)) {
            $.post("default.aspx/delNote", $.toStr({ "isReg": isRegUser, "noteID": nID }), function (rsp) {
                if (rsp.d.Success) {
                    var listID = PCN.note.btnDone.attr("listID");
                    var cur = PCN.note.boxList.find("#" + listID);
                    var index = $.inArray(cur[0], PCN.note.boxList.find("li"));
                    cur.remove();
                    var n = PCN.note.boxList.find("li:eq(" + index + ")");
                    if (n.length == 0) {
                        index--;
                        n = PCN.note.boxList.find("li:eq(" + index + ")");
                    }
                    if (n.length == 0) {
                        PCN.note.btnAdd.click();
                    } else
                        n.click();
                }
            });
        }
    });
    /**note*/

};

//初始化控件;
var initComponents = function () {
    var emtpyBox = $("<div style='font-size:0;height:0;width:0;position:absolute;'></div>").appendTo("body");
    $(window).scroll(function () { emtpyBox.html(""); });

    PCN.copyPanel.reg();

    PCN.desktop = $("#desktop");

    PCN.boxmain = $("#boxmain");

    PCN.locaTip = $("#locaTip");
    $("#curLocation").click(function () {
        var ths = $(this);
        ths.toggleClass("CityYellow_On");
        if (ths.hasClass("CityYellow_On"))
            PCN.locaTip.slideDown();
        else
            PCN.locaTip.slideUp();
    });
    var lks = PCN.locaTip.find("td");
    var len = lks.length;
    var txt = $.trim($("#curLocation").find("span:first").text());
    for (var i = 0; i < len; i++) {
        if ($.trim($(lks[i]).text()) == txt) {
            $(lks[i]).addClass("CityYellow");
            break;
        }
    }
    //U媒体;
    PCN.media = $("#box_uMedia");
    PCN.media.closeBtn = PCN.media.find(".btn_uMedia_Close");
    PCN.media.cue = PCN.media.find(".box_uMedia_cue");
    PCN.media.cDown = PCN.media.find(".box_uMedia_countDown");
    PCN.media.secondBox = PCN.media.find(".box_uMedia_countDown .box_second");
    PCN.media.closeBtn.click(function () {
        PCN.media.fadeOut();
    });
    //倒计时;
    PCN.media.countDown = function (batchID) {
        PCN.media.cue.hide();
        PCN.media.cDown.show();
        var count = 5;
        var timer = setInterval(function () {
            if (count == 0) {
                PCN.media.cDown.hide();
                PCN.media.cue.show().text("正在获取奖励中......");
                PCN.media.getPrize(batchID);
                clearInterval(timer);
            }
            PCN.media.secondBox.text(--count);
        }, 1000);
    }
    //
    PCN.media.display = function (batchID, title) {
        PCN.media.closeBtn.hide();
        PCN.media.secondBox.text("5");
        this.find("#box_uMedia_title").text(title);
        this.fadeIn("fast");
        $.post("default.aspx/ShowAdText", $.toStr({ "batchId": batchID }), function (rsp) {
            if (rsp.d.Success) {
                PCN.media.find("#box_uMedia_ctn").html(rsp.d.Content);
                PCN.media.countDown(batchID);
            }
            else {
                PCN.media.cue.text(rsp.d.Content);
                PCN.media.closeBtn.show();
            }
        });
    }
    //获取奖励;
    PCN.media.getPrize = function (batchID) {
        PCN.media.closeBtn.show();
        $.post("default.aspx/GetPrize", $.toStr({ "batchID": batchID, "ip": ipAddr }), function (rsp) {
            PCN.media.cue.text(rsp.d);
        });
    }
    if (!$.isIE6) {
        $("#introduceTourBtn").click(function () {
            PCN.tour.start();
            return false;
        });
    }
    PCN.iconPanel = $("#icon_panel");
    PCN.iconPanel.mouseleave(function (e) {
        if ($("#" + Site.lastHoverId).encompass(e.relatedTarget))
            return false;
        $("#" + Site.lastHoverId).mouseleave();
    });
    //返利按钮;
    PCN.rebateIcon = $("#icon_rebate");
    if (PCN.rebateIcon.length === 0)
        PCN.rebateIcon = $("<div id='icon_rebate'></div>").appendTo("body").click(function () {
            new rebatePrompt();
        }).mouseleave(function (e) {
            if (!$(e.relatedTarget).is(".icon"))
                $(this).hide();
        });
    //快速搜索结果框;
    PCN.qSchResult = $("#qckSchResult");
    PCN.qSchResult.container = $("#qckSchResult").find(".container");
    PCN.qSchResult.emptyModel = $("#qckSchResult").find(".result");
    PCN.qSchResult.locate = function () {
        var box = $("#Search");
        var pos = box.offset();
        var l = pos.left - (this.width() - box.width());
        var t = pos.top + box.height() + 1;
        this.css({ left: l, top: t });
        return this;
    }
    //快速搜索框;
    PCN.quickSearch = $("#qckSchBox");
    PCN.quickSearch.hintText = "快速添加网址";
    PCN.quickSearch.Btn = $("#qckSchBtn");
    PCN.quickSearch.cateList = $("#qckSchCateList");
    PCN.quickSearch.btnCateList = $("#btnQckSchCateList");
    //响应搜索;
    PCN.quickSearch.Btn.click(function () { PCN.quickSearch.start(); });
    $(document).click(function () {
        PCN.quickSearch.cateList.hide();
    });
    //显示分类;
    PCN.quickSearch.btnCateList.click(function (e) {
        PCN.quickSearch.cateList.show();
        e.stopPropagation();
    });
    //选中结果;
    PCN.quickSearch.cateList.find("li").click(function () {
        var ths = $(this);
        var gt = ths.find("div").attr("gt");
        PCN.quickSearch.cateList.find(".selected").removeClass("selected");
        ths.addClass("selected");
        PCN.quickSearch.btnCateList.attr("gt", gt);
    }).mouseenter(function () {
        $(this).addClass("on");
    }).mouseleave(function () {
        $(this).removeClass("on");
    });
    //处理选 中;
    PCN.quickSearch.cateList.select = function (itm) {
        var gt = itm.attr("gt");
        if ($.isNorE(gt)) {
            this.find("li:first").click();
            return false;
        }
        var cur = this.find("li>div[gt=" + gt + "]");
        if (cur.length == 0)
            this.find("li:first").click();
        else
            cur.parent().click();
    }
    //处理搜索;
    PCN.quickSearch.start = function () {
        var val = $.trim(this.val());
        var res = PCN.qSchResult;
        if (val == "" || val == PCN.quickSearch.hintText) {
            if (res.is(":visible"))
                PCN.quickSearch.vanish();
            this.val("").focus();
            return false;
        }
        res.locate().container.html(PCN.qSchResult.emptyModel).end().show();
        var gt = PCN.quickSearch.btnCateList.attr("gt");
        $.post("default.aspx/GetSearchResult", $.toStr({ "key": val, "attr": Desktop.getAttr(), "gtid": gt }), function (data) {
            res.container.html(data.d);
            res.slideDown(function () {
                $(document).click(PCN.quickSearch.vanish);
                res.click(function (e) { e.stopPropagation(); });
            });
            res.find("li").find("div:first")
            .mousedown(function () {
                var msg = null;
                if (curDesktop.charAt(0).toLowerCase() == "s" || $("#" + curDesktop).attr("noAdd")) {
                    msg = "对不起，此桌面不能添加！";
                } else {
                    var c = this.id.replace("Sch_", "");
                    if (Site.isPreset(c) > -1) {
                        msg = "此网址已存在！";
                    }
                }
                if (msg) {
                    $(document).trigger("mouseup");
                    new rPrompt(msg);
                    $(this).draggable("disable");
                }
            })
            .click(function () {
                if (!$(this).draggable("option", "disabled")) {
                    PCN.quickSearch.vanish();
                    var helper = $(this).clone().attr("id", "id" + (new Date()).valueOf().toString())
                        .css({ "position": "absolute", "zIndex": "999999", "left": $(this).offset().left, "top": $(this).offset().top })
                        .appendTo("body");
                    var fakeTarget = $("<div id='a_a_a_a'></div>");
                    Site.addSch($(this), fakeTarget, helper);
                }
                return false;
            })
            .draggable({
                helper: "clone",
                opacity: 0.35,
                appendTo: "body",
                zIndex: 999999
                , start: function (e, ui) {
                    PCN.quickSearch.vanish();
                }
            });
        });
    };
    PCN.quickSearch.vanish = function () {
        PCN.qSchResult.slideUp(function () {
            $(document).unbind("click", PCN.quickSearch.vanish);
            $(this).unbind("click");
        });
    };
    PCN.quickSearch.bindEvents = function () {
        this.focus(function () {
            var val = $.trim(this.value);
            this.value = val == PCN.quickSearch.hintText ? "" : val;
            this.select();
        }).blur(function () {
            var val = $.trim(this.value);
            this.value = val == "" ? PCN.quickSearch.hintText : val;
        }).keyup(function () { PCN.quickSearch.start() });

    };
    PCN.quickSearch.bindEvents();
    //天气详单框;
    PCN.weatherDetail = $("#weatDetaContainer");
    PCN.weatherDetail.inited = false;
    PCN.weatherDetail.display = function () {
        if (!this.inited) {
            var ths = this;
            ths.invisible().show();
            var divw = PCN.divWeather;
            var offs = divw.offset();
            ths.css({ "left": offs.left + 80, "top": offs.top, "zIndex": 99999 }).hide().visible();
            ths.find(".Add_Web_closeBtn").click(function () { ths.fadeOut(); });
            ths.inited = true;
        }
        this.fadeIn();
    }
    $(".icon_del").click(function () {
        if (Site.lastHoverId != null) {
            Site.remove($("#" + Site.lastHoverId));
            Site.clearHoverTimeout();
        } else { }
        return false
    }).hover(function () {
        $(this).addClass("icon_del_hover")
    },
        function () {
            $(this).removeClass("icon_del_hover")
        });
    //分享格子;
    $(".icon_share").click(function () {
        var data = { "isReg": isRegUser, "siteID": Site.lastHoverId };
        var site = Site.getSiteData($("#" + Site.lastHoverId));
        window.shareSiteData = site;
        var j = $("body").jmodal({
            content: { iframe: "shareSite.aspx?" + $.param(data) },
            initWidth: 520,
            full: true
        });
        Site.clearHoverTimeout();
        PCN.iconPanel.hide()
        return false
    }).hover(function () {
        $(this).addClass("icon_share_hover")
    },
    function () {
        $(this).removeClass("icon_share_hover")
    });

    //删除格子
    $("#liBoxDel").droppable({
        over: function (a, g) {
            var h = g.draggable;
            $(this).css("backgroundPosition", "right top");
        },
        out: function (a, g) {
            $(this).css("backgroundPosition", "left top");
        },
        drop: function (a, g) {
            var h = g.draggable;
            Site.remove(h);
        }
    });
    //修改格子;
    $("#liBoxEdit").droppable({
        over: function (a, g) {
            var h = g.draggable;
            $(this).css("backgroundPosition", "right top")
        },
        out: function (a, g) {
            $(this).css("backgroundPosition", "left top")
        },
        drop: function (a, g) {
            var h = g.draggable;
            if (h.attr("gc") == "12") {
                $.alert("对不起，应用不能修改。");
                return;
            }
            $(".icon_edit").click();
        }
    });
    ///复制格子;
    $("#liBoxCopy").droppable({
        over: function (a, g) {
            var h = g.draggable;
            $(this).css("backgroundPosition", "right top");
        },
        out: function (a, g) {
            $(this).css("backgroundPosition", "left top")
        },
        drop: function (a, g) {
            if (g.draggable.attr("rel") == "sso") {
                return;
            }
            var pureID = g.draggable.attr("id").split("_")[3];
            var data = { "isReg": isRegUser, "siteID": pureID, "deskID": curDesktop };
            var j = $("body").jmodal({
                content: { iframe: "copySite.aspx?" + $.param(data) },
                initWidth: 300,
                initHeight: 170,
                full: true,
                load: function () {
                    window.frames[j.iframe.attr("name")].Doc(data.isReg, pureID);
                }
            });
        }
    });
    $("a.setHomePage").click(function () {
        setHomepage(PCN.url);
        return false
    });
    $("a.setFav").click(function () {
        addFav(PCN.url, "P.CN，我的上网主页!");
        return false
    });
    if (document.all) {
        document.body.style.behavior = "url(#default#homepage)";
        var c = document.body.isHomePage("http://www.p.cn");
        if (c) {
            $("a.setHomePage").remove()
        }
    }
    $("#themeSelector a").click(function () {
        $(this).parents("ul").children("li").removeClass("selected");
        $(this).parent().addClass("selected");
        var a = 0;
        if (this.hash.length > 1) {
            a = this.hash.substr(1)
        }
        $.cookie("theme", a, {
            expires: 300,
            path: "/"
        });
        $("#csslink").attr("href", "/themes/" + a + "/s.css");
        return false
    });
    $(".t" + ($.cookie("theme") ? $.cookie("theme") : "0"), "#themeSelector").parent().addClass("selected");
    var b = 38;
    var f = 40;
    var d = 37;
    var e = 39;
    PCN.kwf.keyup(function (i) {
        switch (i.keyCode) {
            case d:
            case e:
                return false;
                break;
            case f:
                if (!PCN.suggestBox.is(":hidden")) {
                    var a = $("tr", PCN.suggestBox);
                    var h = null;
                    if (a.filter(".hover").length > 0) {
                        h = a.filter(".hover").next();
                        a.removeClass("hover");
                        h.addClass("hover")
                    } else {
                        h = a.eq(0).addClass("hover")
                    }
                    PCN.kwf.val($(".suggest_keyword", h).text())
                }
                return false;
                break;
            case b:
                if (!PCN.suggestBox.is(":hidden")) {
                    var a = $("tr", PCN.suggestBox);
                    var h = null;
                    if (a.filter(".hover").length > 0) {
                        h = a.filter(".hover").prev();
                        a.removeClass("hover");
                        h.addClass("hover")
                    } else {
                        h = a.eq(a.length - 1).addClass("hover")
                    }
                    PCN.kwf.val($(".suggest_keyword", h).text())
                }
                return false;
                break
        }
        var g = $.trim(this.value);
        if (g != "" && g.length > 0) {
            if (g == PCN.lastKey) {
                return false
            }
            PCN.lastKey = g;
            $.getScript("http://www.google.cn/complete/search?hl=zh-CN&client=suggest&js=true&q=" + encodeURIComponent(g))
        } else {
            PCN.suggestBox.hide()
        }
    });
    //隐藏操作格子面板;
    $(document).click(function (g) {
        var a = $(g.target);
        if (a.parents("#suggest_box").length == 0) {
            PCN.suggestBox.hide()
        } else {
            if (a.parents("#icon_panel").length == 0) {
                PCN.iconPanel.hide();
                Site.clearHoverTimeout()
            }
        }
    });

    //P按钮;
    PCN.pBox = $("#key");
    PCN.pBox.defValue = "输入关键字/GID/卡号/命令";
    PCN.pBox.hintBox = $('<div class="pBox_hintBox"><div style="height: 14px;overflow:hidden; " class="pBox_hintBox_top"><div class="pBox_hintBox_topLft"></div><div class="pBox_hintBox_topMid"></div><div class="pBox_hintBox_topRgt"></div></div><div  id="pHintBox"><div class="pBox_hintBox_mainBorder"><div class="pBox_hintBox_topBtns"><div class="pBox_hintBox_addContact"></div><div class="pBox_hintBox_addNote"></div></div><div class="pBox_hintBox_container"></div></div></div></div>').appendTo($('#gid'));
    //添加联络人;
    PCN.pBox.hintBox.btnAddCont = PCN.pBox.hintBox.find(".pBox_hintBox_addContact").click(function () {
        PCN.contact.display();
        PCN.pBox.hintBox.lastKey = "";
    });
    //添加便笺;
    PCN.pBox.hintBox.btnAddNote = PCN.pBox.hintBox.find(".pBox_hintBox_addNote").click(function () {
        PCN.note.display();
        PCN.pBox.hintBox.lastKey = "";
    }); ;
    //提示框;
    PCN.pBox.hintBox.lastKey = "";
    PCN.pBox.hintBox.reg = /^(([eEtTnN] +)|([eE] +\d{4,})|([tTnN] +.+))$/;
    PCN.pBox.hintBox.initList = function (k) {
        var obj;
        if (k == "n") {
            PCN.pBox.hintBox.btnAddNote.show();
            obj = PCN.note;
        }
        else if (k == "t") {
            PCN.pBox.hintBox.btnAddCont.show();
            obj = PCN.contact;
        }
        if (!obj)
            return;
        PCN.pBox.hintBox.inner.find(".listItem div:first").click(function () {
            var index = $.inArray(this, PCN.pBox.hintBox.inner.find(".listItem"));
            obj.display(index);
        });
    }
    //处理提示框要显示的内容;
    PCN.pBox.hintBox.process = function (html, val) {
        PCN.pBox.hintBox.inner.html(html);
        PCN.pBox.hintBox.lastKey = val;
        val = val.charAt(0).toLowerCase();
        if (!$.isNorE(html) || val == "n" || val == "t"/*show note and contact always*/) {
            PCN.pBtnPrompt.hide();
            PCN.pBox.hintBox.display();
            var k = val.charAt(0);

            PCN.pBox.hintBox.btnAddNote.hide();
            PCN.pBox.hintBox.btnAddCont.hide();

            PCN.pBox.hintBox.initList(k);

            PCN.pBox.hintBox.inner.find("span").click(function () {
                var lnk = $(this).attr("link");
                $.fn.jmodal({
                    content: { iframe: lnk },
                    full: true
                });
            });
        } else
            PCN.pBox.hintBox.vanish();
    }
    ; ;
    PCN.pBox.hintBox.inner = PCN.pBox.hintBox.find("#pHintBox .pBox_hintBox_container");

    PCN.pBox.hintBox.vanish = function () {
        PCN.pBox.hintBox.hide();
        $(document).unbind("click", PCN.pBox.hintBox.vanish);
    }
    PCN.pBox.hintBox.display = function () {
        PCN.pBox.hintBox.show();
        $(document).click(PCN.pBox.hintBox.vanish);
    }
    PCN.pBox.hintBox.click(function (e) { e.stopPropagation(); });

    PCN.pBox.blur(function () {
        if (this.value == '') {
            this.value = PCN.pBox.defValue;
        }
    })
        .focus(function () {
            if (this.value == PCN.pBox.defValue) {
                this.value = ''
            }
        })
        .click(function (e) {
            e.stopPropagation();
        });
    PCN.pBox.mouseenter(function () {
        if (PCN.pBox.hintBox.is(":visible") || !($.isNorE(PCN.pBox.val()) || PCN.pBox.defValue == PCN.pBox.val()))
            return false;
        PCN.pBox.isOn = true;
        window.setTimeout(function () {
            if (PCN.pBox.isOn === true) {
                PCN.pBtnPrompt.isVisible = true;
                PCN.pBtnPrompt.fadeIn();
            }
        }, 1000);
    }).mouseleave(function () {
        PCN.pBox.isOn = false;
        if (PCN.pBtnPrompt.isVisible === true) {
            PCN.pBtnPrompt.fadeOut();
            PCN.pBtnPrompt.isVisible = false;
        }
    }).keydown(function (e) {
        if (e.key == 13) {
            onsearch();
            return false;
        };
    }).keyup(function (e) {
        var val = $(this).val();
        if (!($.isNorE(val) || val == PCN.pBox.defValue)) {
            PCN.pBtnPrompt.hide();
        }
        if (PCN.pBox.hintBox.reg.test(val)) {
            PCN.pBtn.click();
        }
    });

    //gid提示框;
    PCN.pBtnPrompt = $(".P_prompt");
    PCN.pBtnPrompt.locate = function () {
        $("#gid").append(this);
    }
    //p按钮点击;
    PCN.pBtn = $("#btnGidSearch");
    PCN.pBtn.click(function (e) {
        e.stopPropagation();
        var val = PCN.pBox.val();
        //        var p = new rPrompt("正在处理中，请稍等......", 3, null, 1000);
        if (val == PCN.pBox.hintBox.lastKey) {
            val = val.charAt(0).toLowerCase();
            var html = PCN.pBox.hintBox.inner.html();
            if (!$.isNorE(html) || val == "n" || val == "t"/*show note and contact always*/) {
                PCN.pBox.hintBox.display();
            } else
                PCN.pBox.hintBox.vanish();
            return false;
        };
        $.post("default.aspx/AddIconByUrl", $.toStr({ 'isReg': isRegUser, 'url': val, 'defaultDeskID': curDesktop, "attr": $("#" + curDesktop).attr("attr") }), function (rsp) {
            var data = rsp.d
            if (!data.Success) {
                $.alert(data.Detail);
            }
            else {
                var type = data.OperationType;
                switch (type) {
                    case 0:
                        new rPrompt("未定义操作。");
                        break;
                    case 1:
                        addSiteP(data.Obj);
                        break;
                    case 2:
                        window.open(data.Obj, '_self');
                        break;
                    case 3:
                        window.open(data.Obj);
                        break;
                    case 8:
                        $.fn.jmodal({ content: { iframe: data.Obj }, initWidth: 500, initHeight: 390, full: true });
                        break;
                    case 4:
                    case 7:
                        $.alert(data.Detail);
                        break;
                    case 11:
                    case 12:
                    case 13:
                    case 14:
                    case 15:
                    case 16:
                        PCN.pBox.hintBox.process(data.Data, val);
                        break;
                }
            }
        });
    }
);
    if (!$.isIE6) {
        //新手上路;
        PCN.tour = $("#tourBox");
        PCN.tour.inst = $("#instructionBox");
        PCN.tour.instMain = PCN.tour.inst.find(".instructionBox_main");
        PCN.tour.stPanel = $("#tourStartPanel");
        PCN.tour.arrWidth = 20;
        PCN.tour.instPadding = 20;
        PCN.tour.curIndex = -1;

        PCN.tour.start = function () {
            PCN.menu.find("li:first").click();
            PCN.tour.stPanel.fadeInEx();
            PCN.boxmain.hide();
        }

        PCN.tour.instMain.find(".instructionBox_main_top_btn").click(function () {
            PCN.tour.stop();
        });
        $(".instructionBox_main_btm_next").click(function () {
            PCN.tour.run(PCN.tour.curIndex + 1);
        });
        $(".instructionBox_main_btm_btns span").click(function () {
            var index = $(this).text();
            index = parseInt(index);
            PCN.tour.run(index - 1);
        });

        PCN.tour.stPanel.find(".instructionBox_main_top_btn").click(function () {
            PCN.tour.stPanel.fadeOutEx("fast", function () {
                PCN.boxmain.show();
            });
        });
        //设置当前步骤;
        var setCurIndex = function (index) {
            PCN.tour.curIndex = index;
            if (PCN.tour.doneHandler) {
                PCN.tour.doneHandler();
                PCN.tour.doneHandler = null;
            }
        }
        //显示指定的步骤;
        PCN.tour.run = function (index) {
            if (!index)
                index = 0;
            setCurIndex(index);

            PCN.tour.stPanel.hide();
            PCN.boxmain.show();

            var sets = PCN.tour.steps[index];
            if (!sets) {
                if (isRegUser)
                    window.open("http://dt.p.cn/MyPanel2.aspx?cuo");
                else
                    window.open("http://p.cn/Reg.aspx");
                return PCN.tour.stop();
            }
            if (sets.init)
                sets.init();
            if (sets.restore)
                PCN.tour.doneHandler = sets.restore;
            var tar = $(eval(sets.target));
            var docHgh = $(document).height();
            var tarHgh = tar.outerHeight();
            var tarWdh = tar.outerWidth() + 6;

            PCN.tour.css("height", docHgh);

            PCN.tour.find(".tourBox_target_container").css({ "width": tarWdh, "height": tarHgh });
            PCN.tour.find(".tourBox_target_mid").css("height", tarHgh - 9 * 2 + 6);

            PCN.tour.inst.removeClass().addClass("step" + (index + 1));
            PCN.tour.inst.find(".bgWrapper").removeClass().addClass("bgWrapper " + sets.bgCoor);
            PCN.tour.inst.find(".pad").css({ "width": 0, "height": 0 });
            var instWdh = 0; instHgh = 0;
            switch (sets.pos) {
                case "left":
                    PCN.tour.inst.find(".instructionBox_right").css("width", PCN.tour.arrWidth);
                    instWdh = sets.dimension.width - PCN.tour.arrWidth;
                    instHgh = sets.dimension.height;
                    break;
                case "below":
                    PCN.tour.inst.find(".instructionBox_top").css("height", PCN.tour.arrWidth);
                    instWdh = sets.dimension.width;
                    instHgh = sets.dimension.height - PCN.tour.arrWidth;
                    break;
            }
            PCN.tour.instMain.css({ "width": instWdh, "height": instHgh });
            if ($.isIE6)
                PCN.tour.inst.find(".bgWrapper").css({ "width": sets.dimension.width + 20, "height": sets.dimension.height + 20 });

            //调整高亮显示框大小;
            PCN.tour.resize = function () {
                var coor = tar.offset();
                var tLft = coor.left - 3;
                if (tarWdh + tLft > $(window).width()) {
                    PCN.tour.css("width", tarWdh + tLft);
                } else
                    PCN.tour.css("width", "100%");
                var topHgh = coor.top - 3;
                var btmHgh = docHgh - coor.top - tarHgh;
                PCN.tour.find(".tourBox_top").css("height", topHgh < 0 ? 0 : topHgh);
                PCN.tour.find(".tourBox_btm").css("height", btmHgh < 0 ? 0 : btmHgh);
                PCN.tour.find(".tourBox_left").css({ "width": tLft });

                var instLft = 0, instTop = 0;
                switch (sets.pos) {
                    case "left":
                        instLft = coor.left - sets.dimension.width - PCN.tour.instPadding + sets.offset.left;
                        instTop = coor.top + sets.offset.top;
                        break;
                    case "below":
                        instLft = coor.left + sets.offset.left;
                        instTop = coor.top + tarHgh + sets.offset.top;
                        break;

                }
                PCN.tour.inst.css({ "left": instLft, "top": instTop });
            }
            PCN.tour.resize();
            $(window).resize(PCN.tour.resize);
            if ($.isIE6)
                this.show();
            else
                this.css("opacity", 0.7).fadeIn();

            var html = "";
            var len = sets.items.length;
            for (var i = 0; i < len; i++) {
                html += '<li><div class="liStyle bgCtnr"><div class="bg"></div></div><div class="instructionBox_main_mid_ctn_chars">' + sets.items[i] + "</div></li>";
            }
            PCN.tour.inst.find("ul").html(html);

            PCN.tour.inst.find(".instructionBox_main_btm_btns .on").removeClass("on");
            PCN.tour.inst.find(".instructionBox_main_btm_btns span").eq(index).addClass("on");
            if ($.isIE6)
                PCN.tour.inst.show();
            else
                PCN.tour.inst.fadeIn("fast");
        }
        PCN.tour.stop = function () {
            setCurIndex(-1);
            if ($.isIE6) {
                this.hide();
                PCN.tour.inst.hide();
            }
            else {
                this.fadeOut("fast");
                PCN.tour.inst.fadeOut("fast");
            }
            $(window).unbind("resize", PCN.tour.resize);
        }
        //步骤数据;
        PCN.tour.steps = [
        { "target": '"#desktop_area_" + curDesktop + " .icon:eq(21)"', "pos": "left", "bgCoor": "instr_bg1", "dimension": { "width": 346, "height": 152 }, "offset": { "left": -5, "top": -90 },
            "items":
            [
                "通过点击格子图标，你可以马上开始使用该网站"
                , "注册成为P.CN用户后你还可以拖动格子，添加和删除格子"
            ]
        }
        , { "target": '"#boxmain"', "pos": "below", "bgCoor": "instr_bg2", "dimension": { "width": 329, "height": 169 }, "offset": { "left": 0, "top": 8 }
            , "items":
                [
                    "在这里您可以直接使用GIDSOO等搜索引擎"
                    , "通过P按钮可快速完成10余种功能的快捷操作"
                    , "还可观看U媒体文字广告，获取PV收益"
                ]
        }
        , { "target": '"#menu_rb"', "pos": "below", "bgCoor": "instr_bg2", "dimension": { "width": 329, "height": 169 }, "offset": { "left": 0, "top": 8 },
            "items":
            [
                "点击返利商家格子图标，进入购物网站，在上面购物后，你将获得返还的PV奖励"
            ]
        }
        , { "target": '"#menu_goods"', "pos": "below", "bgCoor": "instr_bg2", "dimension": { "width": 329, "height": 169 }, "offset": { "left": 0, "top": 8 },
            "items":
            [
                "点击常购商品格子图标，上面有我们为您精心挑选的商品，提供订购"
            ]
        }
        , { "target": '"#Search"', "pos": "below", "bgCoor": "instr_bg3", "dimension": { "width": 329, "height": 169 }, "offset": { "left": -250, "top": 8 },
            "items":
            [
                "您想快速添加你熟悉的网站？你只要在这里输入网站地址或者中文名称，你就可以在搜索出结果中拖动图标 到您的桌面上。"
            ]
        }
        , { "target": '"#desk-bar"', "pos": "below", "bgCoor": "instr_bg2", "dimension": { "width": 329, "height": 169 }, "offset": { "left": 0, "top": 8 },
            "items":
            [
                "点击每个桌面栏，你可以方便的来回切换桌面，同时你也可以通过 添加桌面按钮快速的添加1个空桌面或者 我们为你精心挑选的桌面"
            ]
        }
        , { "target": '"#ulLogin"', "pos": "below", "bgCoor": "instr_bg3", "dimension": { "width": 329, "height": 169 }, "offset": { "left": -300, "top": 8 }
            , "init": function () {
                var clsName = "instructionBox_register";
                if (isRegUser)
                    clsName = "instructionBox_admin";
                PCN.tour.inst.find(".instructionBox_main_btm_next").addClass(clsName);
            }
            , "restore": function () {
                PCN.tour.inst.find(".instructionBox_main_btm_next").removeClass().addClass("instructionBox_main_btm_next bgCtnr");
            }
            , "items":
            [
                "注册账号后，你可以永久保存你个人的网站格子与桌面"
            ]
        }

    ];
    }

}

//        <div class='bubble hidden Bule24'>
//        <a href='#close' class='bubble-close' title='关闭'>
//            <img src='images/bubble_closebox.gif' width='10' height='10' />
//        </a>
//        <div>
//            2010-8-21日凌晨1点到4点进行服务器升级，届时P.CN及各项服务将中止，带来不便敬请谅解！
//        </div>
//    </div>
//提示框;
var tipReg = {
    timeout: 5000,
    show: function (a) {

        /*********************************show only once a day*************************************/
        /*
        var tipRegStampKey = "tipRegStamp";
        var today = (new Date()).toDateString().replace(/\u0020/g, "");
        var cks = document.cookie.replace(/\u0020/g, "");
        var index = cks.indexOf(tipRegStampKey);
        if (index != -1) {
        var left = index + tipRegStampKey.length + 1;
        var val = "";
        var semicollonIndex = cks.indexOf(";", index);
        if (semicollonIndex == -1)
        val = cks.substr(left);
        else
        var val = cks.substr(left, semicollonIndex - left);
        if (val == today)
        return false;
        }
        document.cookie = tipRegStampKey + "=" + today;
        */
        /**********************************************************************/
        a = a || 50000;
        //        var c = $("#btnApp");
        //                  $(".bubble").removeClass("hidden").css({
        //                      left: c.offset().left + c.width()*2 - $(".bubble").width(),
        //                      top: c.offset().top + c.height()
        //                  }).fadeIn("slow");
        //$(".bubble").fadeIn("slow");
        var b = this;
        b.timeout = window.setTimeout(function () {

            b.close();
        },
      a);
        $(".bubble,.bubble-close").click(function (e) {
            tipReg.close("fast");
            return false;
        })
        $(".bubble a").click(function (e) {
            e.stopPropagation();
            tipReg.close("fast");
        });
    },
    close: function (a) {
        if (this.timeout != null) {
            window.clearTimeout(this.timeout);
            this.timeout = null
        }
        a = a || "slow";
        $(".bubble").fadeOut(a)
    }
};
//初始化搜索框;
function initSearch() {
    var b = ["Tool_Img007.png", "Tool_Img008.png", "Tool_Img009.png"];
    $.each(b,
    function (e, d) {
        var c = new Image();
        c.src = "/images/" + d;
    });
    $("#searchSwitchBox li").click(function (e) {
        var id = this.id;
        $("#searchSwitchBox li").each(function (index, ele) {
            var eID = ele.id;
            $(this).removeClass(eID + "on");
        });
        $(this).addClass(id + "on")

        var nid = id.replace("li", "");
        $('.Search_Box>div').addClass("none");
        $("#" + nid).removeClass("none");

        //点击淘宝网时才加载iframe
        if ($(this).is("#litaobao")) {
            if ($("#ifrtaobao").attr("src") != "taobao.htm") {
                $("#ifrtaobao").attr("src", "taobao.htm");
            }
        }

    });
}
//使格子不可点击;
function setSiteInactive(b) {
    var d = b.css("top");
    var c = b.css("left");
    var a = curDesktop + "_" + d.replace("px", "") + "_" + c.replace("px", "");
    b.empty().attr("id", a).removeClass().addClass("icon inactive").css("backgroundImage", "").unbind().draggable("destroy");
    Site.initInactive($("#" + a))
}
//根据格子位置获取索引;
function gridToPos(d, c, a, b) {
    return Site.gridToPos(d, c, a, b)
}
//取得格子位置;
function idToGrid(a) {
    var c = a.css("top").replace("px", "");
    var b = a.css("left").replace("px", "");
    return new Array(c, b)
}
//根据索引取得位置;
function posToGrid(index, width, height) {
    width = width || 90;
    height = height || 90;
    index = index.toString();
    if (index.length < 2)
        index = "0" + index;
    var ten = parseInt(index.charAt(0));
    var one = parseInt(index.charAt(1));
    var top = ten * height;
    var left = one * width;
    return new Array(top, left)
}
//添加新格子;
function addNewSite(b) {
    a = "S_" + b.sid;
    b.bg = b.bg || "";
    if (b.fc == "") {
        if (b.bg == "icon_white") {
            b.color = "#000"
        } else {
            b.color = "#fff"
        }
    }
    var icon2 = "";
    if (get_extname(b.icon) == "png" && $.isIE6) {
        icon2 = "_background-image:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + b.icon + "',sizingMethod='crop');";
    }
    var nid = b.did + "_" + a;

    $("#" + b.did + "_" + b.pos_y + "_" + b.pos_x).attr("id", nid).unbind().removeClass("inactive").html('<div class="icon_bg ' + b.bg + '"></div><div class="icon_ft" style="background-image: url(' + b.icon + ');' + ";" + icon2 + '"></div><div class="icon_chr" title="' + b.title + '" edittitle="' + b.title + '" href="' + b.url + '" target="_blank" style="color:' + b.color + ' ;" >' + b.title.subBytes(0, 10) + '<div class="mask"><div class="maskInner"></div></div></div>');

    if (get_extname(b.bg) == "png" && $.isIE6) {
        $("#" + nid).find(".icon_bg").attr("style",
        "background-image:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + b.bg + "',sizingMethod='crop')")
    }
    Site.initDrag($("#" + nid));
    return nid;
}
//格子对象;
var Site = {
    inProcess: false,
    lastHoverTimeoutId: null,
    lastHoverId: null,
    editSiteId: null,
    //检查是否正在请求后台;
    checkStatus: function () {
        if (this.inProcess)
            new rPrompt("请稍等，上次请求正在处理中...");
        return this.inProcess;
    },
    //处理返回请求;
    checkRsp: function (result) {
        this.inProcess = false;
        var suc = result.d.Success;
        if (!suc) {
            $.fn.hideJmodal();
            if (result.d.NeedRefresh) {
                var ctn = $('<div style=" width:290px; padding:25px 30px;background-color:#fff; overflow:hidden;"> \
   <span style="display:inline-block;vertical-align:middle;width:63px;"><img src="images/Update.png"></span> \
   <span style="width:155px;vertical-align:middle;display:inline-block;margin-left:5px; font-size:12px; line-height:22px; color:#333;">可能您的PCN客户端或者使用其他方式进行了添加网址操作,我们正在为您更新数据，请稍后... </span></div>');
                var r = new RPrompt(ctn);
                setTimeout(r.close, 3000);
                Desktop.load(curDesktop, true);
            }
            else if (result.d.Detail) {
                new rPrompt(result.d.Detail);
            } else {
                new rPrompt("操作失败");
            }
        }
        return suc;
    },
    //添加快速搜索格子;
    addSch: function (d, t, helperCopy) {
        if (this.checkStatus()) {
            helperCopy.remove();
            return false;
        }
        var hasPos = false;
        var id = t.attr("id");
        var idArr = id.split("_");
        if (idArr.length == 4) {
            var pos = -1;
            var grid = [];
            if (!isNaN(parseInt(idArr[2]))) {//移动图标
                hasPos = true;
                PCN.currentGrid = id;
                grid = idToGrid($("#" + id));
                pos = gridToPos(grid[1], grid[0]);
            }
            else if ((pos = Site.findEmptyPos()) > -1) {//点击图标
                hasPos = true;
            }

            if (hasPos) {
                var success = null;
                var curNode = $("#" + PCN.currentGrid)
                var os = curNode.offset();
                var os_p = curNode.position();
                grid = idToGrid(curNode);

                data = Site.getSiteData(d);
                data.did = curDesktop;
                data.pos_x = grid[1];
                data.pos_y = grid[0];

                var navType = d.attr("navtype");
                //start if
                if (navType != '应用程序') {
                    $.post("/default.aspx/AddSysIcon", $.toStr({
                        deskStr: curDesktop,
                        position: pos,
                        webSiteID: data.sid,
                        content: para[curDesktop].desktop.toStr(),
                        isReg: isRegUser,
                        attr: Desktop.getAttr()
                    }), function (result) {
                        if (result.d.Success) {
                            data.sid = result.d.Obj;
                        }
                        success = Site.checkRsp(result);
                    })

                    this.inProcess = true;
                    helperCopy.animate({ "top": os.top, "left": os.left }, 1000, function () {
                        curNode.parent().append(helperCopy.css({ "zIndex": 10, "left": os_p.left, "top": os_p.top }));
                        var update = function () {
                            if (success == null)
                                setTimeout(update, 100);
                            else {
                                if (success == true) {
                                    para[curDesktop].desktop[pos] = data.sid;
                                    Site.update(data);
                                }
                                helperCopy.remove();
                            }
                        }
                        update();
                    });
                }
                else {
                    helperCopy.remove();
                    Site.install(data);
                }
                //end if
            }
        }
        return hasPos;
    },
    //修改登陆信息;
    setLogin: function (id) {
        var j = $.fn.jmodal({
            content: { iframe: "SetLogin.aspx?id=" + id },
            initWidth: 350,
            initHeight: 310,
            full: true,
            load: function () { window.frames[j.iframe.attr("name")].websiteID = id; }
        });
    },
    //保存格子回调;
    update: function (a) {//for save site succeed callback;
        var b = $("#" + PCN.currentGrid);
        grida = idToGrid(b);
        var g = gridToPos(grida[1], grida[0]);
        para[curDesktop].desktop[g] = a.sid.toString();
        PCN.currentGrid = null;
        setSiteInactive(b);
        return addNewSite(a);
    },
    //添加应用格子;
    install: function (site) {
        var appId = site.sid;
        site.sid = "temp";
        var nid = this.update(site);
        var icon = $("#" + nid);
        PCN.bar.installing.display(icon);
        $.post("addApp.aspx/AddToDesk", $.toStr({ "app_id": appId, "desk_id": para[curDesktop].desktopId }), function (rsp) {
            PCN.bar.installing.vanish();
            if (rsp.d) {
                if (!rsp.d.Success) {
                    var index = $.inArray(site.sid, para[curDesktop].desktop);
                    if (index > -1) {
                        para[curDesktop].desktop[index] = 0;
                        setSiteInactive(icon);
                    }
                    $.alert(rsp.d.Detail);
                } else {
                    var id = rsp.d.IntData;
                    nid = nid.replace("temp", id);
                    icon.attr("id", nid);
                    icon.attr("gc", "12");
                    icon.addClass("gc_12");

                    var grida = idToGrid(icon);
                    var g = gridToPos(grida[1], grida[0]);
                    para[curDesktop].desktop[g] = id.toString();

                }
            }
        });
    }
    //响应修改格子事件;
    , edit: function (a) {//as update site click handler
        var b = idToGrid($("#" + a));
        var addr = a;
        a = a.split("_");
        Site.editSiteId = a[2] + "_" + a[3];
        PCN.currentGrid = addr;

        var j = $.fn.jmodal({
            content: { iframe: "AddSite.aspx" },
            initHeight: 598,
            initWidth: 782,
            full: true,
            load: function () {
                var ifm = window.frames[j.iframe.attr("name")];
                ifm.Popup.open("customed");
                ifm.Popup.siteData = Site.getSiteData($("#" + addr));
            }
        });

    },
    //取得格子数据;
    getSiteData: function (div) {
        var fullSid = div.attr("id");
        var pureID = "";
        if (fullSid)
            pureID = fullSid.split("_")[3];
        var bg = div.find(".icon_bg").attr("class").replace("icon_bg", "");
        var bgClass = "";
        var mat = bg.match(/.*(icon_\w+).*/);
        if (mat)
            bgClass = mat[1];
        var mat = div.find(".icon_ft").css("backgroundImage").match(/url\(["']?(.+?)["']?\)/);
        var iconImg = null;
        if (mat)
            iconImg = mat[1];
        if (iconImg == null || iconImg == "")
            iconImg = div.find(".icon_ft")[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src;
        return { sid: pureID, bg: bgClass, url: div.find(".icon_chr").attr("href"), icon: iconImg, color: div.find(".icon_chr").css("color"), title: div.find(".icon_chr").attr("edittitle") };
    },
    //删除格子;
    remove: function (c) {
        if (this.checkStatus())
            return false;
        var pureId = c.attr("id").substr(c.attr("id").lastIndexOf("_") + 1);
        var index = $.inArray(pureId, para[curDesktop].desktop);
        if (index > -1) {
            var data = { isReg: isRegUser, "pos": index, "websiteID": pureId, "deskID": para[curDesktop].desktopId, "data": para[curDesktop].desktop.toStr() };
            $.post("default.aspx/DelIcon", $.toStr(data), function (result, textStatus, xhr) {
                if (Site.checkRsp(result)) {
                    para[curDesktop].desktop[index] = 0;
                    setSiteInactive(c);
                    PCN.iconPanel.hide();
                    Site.clearHoverTimeout();
                }
            });
            this.inProcess = true;
        } else
            new rPrompt("删除失败！");

    },
    //交换格子;
    swap: function (ui, tgt, helperCopy) {
        if (this.checkStatus()) {
            helperCopy.remove();
            return false;
        }
        var drg = ui.draggable;
        var drgPos = {
            top: drg.css("top"),
            left: drg.css("left")
        };
        var tgtPos = {
            top: tgt.css("top"),
            left: tgt.css("left")
        };
        var tgtOs = tgt.offset();
        var postData = { "deskID": para[curDesktop].desktopId, "content": para[curDesktop].desktop.toString(), "isReg": isRegUser };
        var thsDeskId = curDesktop;

        helperCopy.animate({ top: tgtOs.top, left: tgtOs.left }
            , function () {
                drg.show();
                helperCopy.remove();
            }
        );
        drg.hide().css({ top: tgtPos.top, left: tgtPos.left });


        if (tgt.hasClass("inactive")) {
            tgt.attr("id", curDesktop + "_" + drgPos.top.replace("px", "") + "_" + drgPos.left.replace("px", ""));
            tgt.css({
                top: drgPos.top,
                left: drgPos.left
            });
        } else {
            tgt.animate({ top: drgPos.top, left: drgPos.left });
        }

        postData["siteMsg"] = [];
        if (!tgt.hasClass("inactive"))
            postData["siteMsg"].push({ "Site": tgt.attr("id"), "SiteLeft": drgPos.left.replace("px", ""), "SiteTop": drgPos.top.replace("px", "") });
        postData["siteMsg"].push({ "Site": drg.attr("id"), "SiteLeft": tgtPos.left.replace("px", ""), "SiteTop": tgtPos.top.replace("px", "") });

        $.post("default.aspx/TransIcon", $.toStr(postData), function (rsp) {
            if (Site.checkRsp(rsp)) {
                var content = rsp.d.DataArray;
                para[thsDeskId].desktop = content;
            } else {
                drg.css({
                    top: drgPos.top,
                    left: drgPos.left
                });
                tgt.css({
                    top: tgtPos.top,
                    left: tgtPos.left
                });
            }
        });
        this.inProcess = true;
    },
    //初始化空格子;
    initInactive: function (a) {
        if (!a) {
            a = $(".inactive")
        }
        a.hover(function () {
            $(this).addClass("hover");
            PCN.iconPanel.hide()
        },
        function () {
            $(this).removeClass("hover")
        }).click(function (f) {
            var j = $.fn.jmodal({
                content: { iframe: "AddSite.aspx" },
                initHeight: 598,
                initWidth: 782,
                full: true,
                load: function () {
                    var ifm = window.frames[j.iframe.attr("name")];
                    ifm.Popup.open("customed");
                }
            });
            Site.editSiteId = null;
            var b = $(this);
            PCN.currentGrid = this.id;
        })
    }
    //查找第一个空位置;
    , findEmptyPos: function () {
        var desk = para[curDesktop].desktop;
        var len = desk.length;
        var i = 0;
        for (; i < len; i++) {
            if (desk[i] == "0")
                break;
        }
        if (i >= len) {
            i = -1;
            new rPrompt("桌面已满");
        } else {
            var grid = posToGrid(i);
            PCN.currentGrid = curDesktop + "_" + grid[0] + "_" + grid[1];
        }
        return i;
    },
    //是否格子已存在;
    isPreset: function (a) {
        return $.inArray(a, para[curDesktop].desktop)
    },
    //根据位置计算索引;
    gridToPos: function (e, d, a, c) {
        e = parseInt(e);
        d = parseInt(d);
        a = a || 90;
        c = c || 90;
        var b = para[curDesktop].desktopCols || 10;
        return Math.floor(d / c) * b + Math.floor(e / a)
    },
    //阻止格子消失;
    clearHoverTimeout: function () {
        if (this.lastHoverTimeoutId != null) {
            window.clearTimeout(this.lastHoverTimeoutId);
            this.lastHoverTimeoutId = null
        }
    },
    //格子ID转为数组;
    splitSiteId: function (a) {
        if (a != null && a != "") {
            var segments = a.split("_");
            if (segments.length < 4)
                return null;
            else
                return segments[3];
        }
        else {
            return null;
        }
    },
    //修改格子名称;
    updateSiteName: function (id, name) {
        var nodes = $("#" + id).find(".icon_chr")[0].childNodes;
        var len = nodes.length;
        for (var i = 0; i < len; i++) {
            if (nodes[i].nodeType == 3)
                return $(nodes[i]).replaceWith(name);
        }
    },
    //初始化拖动;
    initDrag: function (b) {
        var a = this;
        Site.initClick(b);
        b.draggable({
            helper: "clone",
            opacity: 0.35,
            zIndex: 9999,
            revert: "invalid",
            appendTo: "body",
            start: function (c, d) {
                $("#boxmain").hide();
                if (!$.isIE6) {
                    PCN.tour.stPanel.hide();
                }
                $("#boxmainAc").show();
                PCN.iconPanel.hide()
            },
            stop: function (c, d) {
                $("#boxmain").show();
                $("#boxmainAc").hide()
            }
        }).hover(function () {
            var c = $(this);
            a.lastHoverId = c.attr("id");
            var rel = c.attr("rel");
            if (rel)
                rel = rel.toLowerCase();
            var gc = c.attr("gc")
            if (gc != "12") {
                if (rel == "sso") {
                    $(".icon_share").hide();
                    $(".icon_edit").addClass("icon_edit2").unbind().click(function () {
                        Site.setLogin(Site.lastHoverId);
                        Site.clearHoverTimeout();
                        PCN.iconPanel.hide();
                        return false
                    }).hover(function () {
                        $(this).addClass("icon_edit2_hover")
                    },
                function () {
                    $(this).removeClass("icon_edit2_hover")
                });
                } else {
                    $(".icon_share").show();
                    $(".icon_edit").removeClass("icon_edit2").unbind().click(function () {
                        Site.edit(Site.lastHoverId);
                        Site.clearHoverTimeout();
                        PCN.iconPanel.hide();
                        return false
                    }).hover(function () {
                        $(this).addClass("icon_edit_hover")
                    },
                    function () {
                        $(this).removeClass("icon_edit_hover")
                    });
                };
            }
            PCN.iconPanel.css({
                top: c.offset().top - 10,
                left: c.offset().left + 8
            });
            a.clearHoverTimeout();
            if (gc != "12") {
                a.lastHoverTimeoutId = window.setTimeout(function () {
                    PCN.iconPanel.show();
                },
            1000);
            }
        },
        function (e) {
            if (e.relatedTarget && PCN.iconPanel.encompass(e.relatedTarget))
                return false;
            a.clearHoverTimeout();
            PCN.iconPanel.hide();
        })
    },
    //初始化投放;
    initDroppable: function (a) {
        if (!a) {
            a = $(".icon", ".icon_area")
        }
        a.droppable({
            accept: ".icon,.HomeIcon",
            drop: function (e, ui) {
                var drg = ui.draggable;
                var ths = $(this);
                var helperCopy = ui.helper.clone();
                var os = ui.helper.offset();
                helperCopy.appendTo("body").css({ "left": os.left, "top": os.top, "zIndex": 999999 });
                if (drg.attr("id").indexOf("X_X_") != -1)
                    Site.addSch(drg, ths, helperCopy);
                else
                    Site.swap(ui, ths, helperCopy);
            }
        })
    }
    //初始化点击;
    , initClick: function (icons) {
        icons.mouseenter(function () {
            $(this).find(".mask").show();
        })
        .mouseleave(function () {
            $(this).find(".mask").hide();
        }).click(function () {
            var o = $(this);
            var gc = o.attr("gc");
            if (gc == "12") {
                var appid = o.data("appid");
                if (appid) {
                    var app = PCN.bar.apps[appid];
                    if ($.isIE6) {
                        window.open(app.url);
                    } else {
                        if (!app.inited)
                            PCN.bar.initApp(app);
                        app.btnApp.click();
                    }
                }
                else {
                    var id = o.attr("id");
                    id = id.substr(id.lastIndexOf("_") + 1);
                    if ($.isNorE(id))
                        return false;
                    else
                        id = parseInt(id);
                    $.post("Default.aspx/ClickGrid", $.toStr({ "gid": id, "gc": o.attr("gc") }), function (rsp) {
                        if (rsp.d) {
                            if (rsp.d.Success) {
                                var data = rsp.d.Obj;
                                var aid = "app_" + data.id;
                                var app = PCN.bar.apps[aid];
                                if ($.isIE6) {
                                    if (!app) {
                                        app = {};
                                        app.url = data.address;
                                    }
                                    window.open(app.url);
                                } else {
                                    if (!app) {
                                        app = {};
                                        app.id = aid;
                                        app.url = data.address;
                                        app.title = data.name;
                                        app.bg = $.isNorE(data.bar_icon) ? "images/app/ks.png;" : data.bar_icon;
                                        app.dimen = {};
                                        app.dimen.width = data.window_width;
                                        app.dimen.height = data.window_height;
                                        app.lastStatus = data.window_type;
                                        app = PCN.bar.addApp(app);
                                    }
                                    app.btnApp.click();

                                }
                                o.data("appid", aid);
                            } else
                                $.alert(rsp.d.Detail);
                        } else
                            $.alert("未知错误");
                    });
                }
            } else if (gc == "13") {
                $("").jmodal({
                    content: { iframe: "AddZFOrderNo.aspx" },
                    full: true
                });
                return false

            } else {
                var href = $(this).find(".icon_chr").attr("href");
                Site.clearHoverTimeout();
                PCN.iconPanel.hide();
                window.open(href);
                $.post("default.aspx/ClickIcon", $.toStr({ "url": href }));
                return false;
            }
        });
    }
};
$(".desktopMenu").not(".active").hover(function () {
    $(this).addClass("hover")
},
function () {
    $(this).removeClass("hover")
});
//桌面对象;
var Desktop = {
    isChanging: false
    //添加;
    , add: function () {
        $("").jmodal({
            content: { iframe: "AddDesk.aspx" },
            full: true
        });
        return false
    },
    //修改;
    edit: function (did) {
        if (!did)
            did = curDesktop;
        var p = this;
        var j = $.fn.jmodal({
            content: { iframe: "AddDesktop.aspx?id=2" },
            initWidth: 350,
            initHeight: 170,
            full: true,
            load: function () {
                window.frames[j.iframe.attr("name")].fill({ "name": para[did].title, "title": "修改桌面", "id": did });
            }
        });
        return false
    },
    //修改回调;
    editComplete: function (a) {
        var did = a["Did"];
        var title = a["Title"];
        $("#" + did).find(".navOnInnerMid").text(title);
        window.para[did].title = title;
    },
    //切换桌面;
    change: function (b) {
        var a = b.split("_");
        if (b == curDesktop) {
            return false;
        }
        $("#desktopLoading_loading").show();
        $("#desktopLoading_error").hide();
        if ($("#desktop_area_" + b).length == 0) {
            this.load(b);
        } else {
            var a = b.split("_");
            $("#desktop_area_" + b).show();
            Desktop.close(b)
        }
        $.cookie("ldid", b, {
            expires: 180
        });
        return false
    }
    , init: function () {
        var p = this;
        $("#addNew").click(
          Desktop.add
          );
        $("#btnEditDesk").click(function () {
            Desktop.edit(PCN.editDeskPanel.data("did"));
        });
        $("#btnDeleteDesk").click(function () {
            rConfirmDeed(function () {
                var did = PCN.editDeskPanel.data("did");
                var para = { isReg: isRegUser, 'deskStr': did, "attr": $("#" + did).attr("attr") };
                $.ajax({
                    type: "POST",
                    url: "Default.aspx/DelDesktop",
                    data: $.toStr(para),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        if (msg.d.Result) {
                            Desktop.del(curDesktop);
                        } else {
                            $.alert(msg.d.Message);
                        }
                    }
                });
            }, "确认要删除此桌面吗？");
        });
        //格子提示框;
        PCN.iconHintbox = $("<div id='iconHintbox'><table cellspacing=0 cellpadding=0 border=0  style='width:100%;height:100%;zoom:1;'><tr><td  class='tdLeft'>&nbsp;</td><td style='padding:0.5em;color:#b7c6cc;vertical-align:top;' class='White12'></td><td class='tdRight'>&nbsp;</td></tr></table></div>").appendTo("#desktop");
        PCN.iconHintbox.iWidth = 180;
        PCN.iconHintbox.iHeight = 170;
        PCN.iconHintbox.timer = null;
        PCN.iconHintbox.init = function (did) {
            var actives = $(".icon:not('.inactive')", $("#desktop_area_" + did));
            actives.mouseenter(function () {
                if ($(this).attr("shh") == "false")
                    return;
                var ths = this;
                PCN.iconHintbox.timer = setTimeout(function () {
                    PCN.iconHintbox.timer = null;
                    PCN.iconHintbox.find(".White12").html($(ths).attr("remark") + "<br/>" + $(ths).attr("hh"));
                    var coor = idToGrid($(ths));
                    var tp = parseInt(coor[0]), lft = parseInt(coor[1]);
                    var clsNm = "ih";
                    var nmX = "Left", nmY = "Top";

                    if (lft >= 90 * 8) {
                        nmX = "Right";
                        lft -= PCN.iconHintbox.iWidth - 20;
                    } else {
                        lft += 80 + 12; //13 is the margin of icon_area ;
                    }
                    if (tp >= 90 * 5) {
                        nmY = "Btm";
                        tp -= PCN.iconHintbox.iHeight - 80;
                    }
                    clsNm += nmX + nmY;
                    PCN.iconHintbox.removeClass().addClass(clsNm).css({ "left": lft, "top": tp });
                    if ($.isIE6) {
                        PCN.iconHintbox.show();
                    }
                    else
                        PCN.iconHintbox.fadeIn("fast");
                }, 50);
            });
            actives.mouseleave(function () {
                if (PCN.iconHintbox.timer) {
                    clearTimeout(PCN.iconHintbox.timer);
                    PCN.iconHintbox.timer = null;
                }
                else {
                    PCN.iconHintbox.hide();
                }
            });
        }
        //分页框;
        PCN.pages = $("<div id='submenuPageBox'></div>").appendTo("body");
        //修改桌面栏;
        PCN.editDeskPanel = $("#editDeskPanel").hide();
        PCN.pages.display = function (mItm) {
            var id = mItm.attr("id");
            var pid = "page_" + id;
            PCN.pages.children().hide();
            var pctnr = PCN.pages.find("#" + pid);
            if (pctnr.length > 0) {
                pctnr.show();
            }
            else {
                pctnr = $("<div id='" + pid + "'></div>").appendTo(PCN.pages);
                if (id == "menu_rb") {
                    pctnr.append("<span id='S_2' sm='true' attr='100' mt='1' rel='0_0'>&nbsp;&nbsp;</span><span id='S_10' mt='1'  sm='true' attr='100'  rel='0_1'>&nbsp;&nbsp;</span>");
                } else if (id == "menu_goods") {
                    pctnr.append("<span id='S_4'  sm='true' attr='100'  mt='1' rel='0_0'>&nbsp;&nbsp;</span><span id='S_12'  mt='1' sm='true' attr='100' rel='0_1'>&nbsp;&nbsp;</span>");
                }
                Desktop.initPageMenu(pctnr.find("span"));
            };
            PCN.pages.appendTo(mItm).show();
            pctnr.find('span:first').click();
        };
        //二级菜单;
        PCN.subMenu = $("#desktopList");
        PCN.subMenu.init = function (itm) {
            itm.click(function () {
                var deskID = this.id;
                if (deskID.indexOf("menu_") == 0) {
                    PCN.pages.display($(this));
                }
                else {
                    if (!Desktop.clickMenu(this.id)) {
                        return false;
                    }
                }
                PCN.subMenu.activate($(this));
                return false;
            });
        }
        //显示指定的二级菜单;
        PCN.subMenu.activate = function (itm) {
            var deskID = itm[0].id;
            var subMenuCtnrID = itm.attr("mt");
            var clientType = itm.attr("attr");
            PCN.subMenu.find(".editPanel").hide();

            var prev = PCN.subMenu.find("#menu_" + subMenuCtnrID + " .submenuOn");
            prev.removeClass("submenuOn");
            itm.addClass("submenuOn");
            if (itm.hasClass("DMItem") && clientType == "2") {
                prev.find(".desk_edit").remove();
                $('<a class="desk_edit" href="#" style="color:#0CF;margin-left:1em;">删除</a>').click(function () {
                    $("#btnDeleteDesk").click();
                    return false;
                }).appendTo(itm);
            }

        }
        //添加我的返利; 
        PCN.subMenu.addMyRebate = function (list, needInit) {
            var dom = $('<li class="DMItem" id="menuItmRebate"  mt="myRebate" sm="true" attr="14"><div style="float: left;">我的返利</div></li>');
            needInit ? PCN.subMenu.init(dom) : null;
            dom.prependTo(list);
        }
        //下载二级菜单;
        PCN.subMenu.download = function (attr, mt, deskID) {
            this.show().children().hide();
            var tarList = this.find("#menu_" + mt);
            if (tarList.length > 0) {
                if (!PCN.deskInited)
                    PCN.subMenu.addMyRebate(tarList, true);
                return tarList.show();
            } else {
                if (mt == "myRebate") {
                    var newList = $('<ul id="menu_' + mt + '"class="GrayPart"></ul>');
                    if (!PCN.deskInited)
                        PCN.subMenu.addMyRebate(newList);
                    PCN.subMenu.append(newList);
                    PCN.subMenu.init(newList.find("li"));

                } else {
                    var para = { "isReg": isRegUser, "attr": attr, "deskStr": deskID, "defaultDeskStr": window.defaultDesktop };
                    $.post("default.aspx/ShowMenus", $.toStr(para), function (msg) {
                        var newList = $('<ul id="menu_' + mt + '"class="GrayPart"></ul>');
                        newList.html(msg.d);
                        if (!PCN.deskInited)
                            PCN.subMenu.addMyRebate(newList);
                        PCN.subMenu.append(newList);
                        PCN.subMenu.init(newList.find("li"));
                    });
                }
            }
        }
        //点击二级菜单;
        PCN.subMenu.display = function (mItm) {
            var deskID = mItm.attr("id");
            var isSubmenuShow = mItm.attr("sm");
            var subMenuCtnrID = mItm.attr("mt");

            if (!PCN.deskInited && isSubmenuShow == "false") {
                mItm.attr("sm", "true");
            }
            if (!PCN.deskInited && isSubmenuShow == "false") {
                mItm.attr("mt", "myRebate");
                subMenuCtnrID = "myRebate"
            }

            !PCN.deskInited ? isSubmenuShow = "true" : null;

            var attr = mItm.attr("attr");
            $("#desktopLoading_loading").hide();
            var editable = false;
            for (var i = 0; i < modifiable_desk.length; i++) {
                if (attr == modifiable_desk[i] + "") {
                    editable = true;
                    break;
                };
            }
            var pnl = PCN.editDeskPanel;
            if (editable) {
                pnl.data("did", deskID);
                pnl.show();
            } else {
                pnl.hide();
            }
            if (isSubmenuShow == "true")
                PCN.subMenu.download(attr, subMenuCtnrID, deskID);
        }
        PCN.subMenu.vanish = function () {
            this.hide();
            this.find(".submenuOn").removeClass("submenuOn");
        }

        //一级菜单;
        PCN.menu = $("#desk-bar");
        PCN.menu.init = function (itm) {
            itm.click(function () {
                if (Desktop.clickMenu(this.id)) {
                    PCN.menu.activate($(this));
                    return false;
                }
            });
        }
        PCN.menu.activate = function (itm) {
            var n = PCN.menu.find(".navOnInnerMid");
            if (n.length > 0) {
                var txt = n.html();
                n.parent().html('<div class="navOrdiInner">' + txt + '</div>');
            }
            if (itm.hasClass("Default")) {
                itm.removeClass("Default").addClass("Default_On");
            } else {
                PCN.menu.find(".Default_On").removeClass("Default_On").addClass("Default");
                var txt = itm.find("div").html();
                itm.html('<div class="navOnInnerLeft"></div>\
               <div class="navOnInnerMid">' + txt + '</div>\
               <div class="navOnInnerRght"></div>');
            }
            PCN.quickSearch.cateList.select(itm);
        }
        PCN.menu.init(PCN.menu.find("li"));
        PCN.subMenu.init(PCN.subMenu.find(".DMItem"));
    }
    //显示分页菜单 ;
    , activatePageMenu: function (itm) {
        itm.parent().find(".submenuPageOn").removeClass("submenuPageOn");
        itm.addClass("submenuPageOn");
        itm.parents("li").addClass("submenuOn");
    }
    , initPageMenu: function (itm) {
        itm.click(function () {
            if (Desktop.clickMenu(this.id)) {
                Desktop.activatePageMenu($(this));
                PCN.pages.show();
            }
            return false;
        });
    }
    , clickMenu: function (id) {
        if (id == curDesktop || Desktop.isChanging == true) {
            return false;
        }
        Desktop.isChanging = true;
        PCN.pages.hide();
        PCN.subMenu.vanish();
        PCN.editDeskPanel.hide();
        Desktop.change(id);
        PCN.subMenu.find(".desk_edit").remove();
        return true;
    }
    , create: function (a) {
        did = a.data["desktopId"];
        title = a.data["title"];
        sm = a.data["sm"];
        attr = a.data["attr"];
        gt = a.data.gt;
        var b = $('<li class="NavigationBj" id="' + did + '" href="#' + did + '" gt="' + gt + '" ' + '" rel="' + did + '" attr="' + attr + '" sm="' + sm + '" ' + '><div class="navOrdiInner">' + title + "</div></li>");
        PCN.menu.init(b);
        $("#addNew").parents("li").before(b);

        window.para[did] = a.data;

        $("#" + did).click();
        desktopNum++;
        return false
    },
    del: function (did) {
        $("#" + did).remove();
        var curNode = PCN.menu.find("li:first");
        curNode.click(); //TODO
        desktopNum--;
    },
    sendDel: function (did) {
        did = did ? did : curDesktop;
        var para = { isReg: isRegUser, 'deskStr': did, "attr": Desktop.getAttr() };
        $.ajax({
            type: "POST",
            url: "default.aspx/DelDesktop",
            data: $.toStr(para),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (!msg.d.Result) {
                    return;
                }
                Desktop.del(msg.d.Did);
            },
            error: function () {
            }
        });
    }
    //隐藏被切换掉的桌面;
    , close: function (tarID) {
        if (curDesktop == tarID)
            return;
        var tar = $("#" + tarID);
        var cur = $("#" + curDesktop);
        var curId = curDesktop;
        if (tar.attr("attr") == "6") {
            PCN.boxmain.fadeOut();
            if (!$.isIE6) { PCN.tour.stPanel.fadeOutEx(); }
            PCN.desktop.css("height", "920px");
            PCN.changeBg.boxBg.resize();
        }
        else if (cur.attr("attr") == "6") {
            PCN.boxmain.fadeIn();
            PCN.desktop.css("height", "530px");
            PCN.changeBg.boxBg.resize();
        }
        //计算滚动方向;
        var goLeft = true;
        if (cur.length > 0) {
            if ($.contains(PCN.menu[0], tar[0])) {
                if ($.contains(PCN.menu[0], cur[0])) {//all in menu;
                    var c = PCN.menu.find("li");
                    goLeft = jQuery.inArray(cur[0], c) > jQuery.inArray(tar[0], c);
                } else {
                    goLeft = true; //tar in menu,cur in submenu,go left;
                }
            } else {
                if ($.contains(PCN.menu[0], cur[0])) {//tar in submenu,cur in menu,go right;
                    goLeft = false;
                } else {//all in submenu
                    var allInPage = false;
                    var curInPage = $.contains(PCN.pages[0], cur[0]);
                    var tarInPage = $.contains(PCN.pages[0], tar[0]);
                    if (curInPage && tarInPage) {
                        allInPage = true; //all in page
                    }
                    if (allInPage) {
                        var curParent = cur.parent();
                        var tarParent = tar.parent();
                        if (curParent[0] == tarParent[0]) {
                            var list = curParent.children();
                            goLeft = $.inArray(cur[0], list) > $.inArray(tar[0], list);
                        } else {
                            var list = PCN.pages.children();
                            goLeft = $.inArray(curParent[0], list) > $.inArray(tarParent[0], list);
                        }
                    } else {
                        var c = PCN.subMenu.find("li");
                        var curIndex;
                        while ((curIndex = jQuery.inArray(cur[0], c)) == -1) {
                            cur = cur.parent();
                        }
                        var tarIndex;
                        while ((tarIndex = jQuery.inArray(tar[0], c)) == -1) {
                            tar = tar.parent();
                        }
                        goLeft = curIndex > tarIndex;
                    }
                }
            }
        }
        var b = -895;
        var d = 895;
        if (goLeft) {
            b = 895;
            d = -895
        }
        $("#desktop_area_" + curDesktop).css("left", "0");
        $("#desktop_area_" + curDesktop).animate({
            left: b
        },
        {
            duration: 500,
            complete: function () {
                $("#desktop_area_" + curId).hide();
            }
        });
        Desktop.show(tarID, d);
    },
    //显示切换到的桌面;
    show: function (b, a) {
        $("#desktop_area_" + b).removeClass("none").css("left", a).animate({ left: 0 }, 500, function () {
            var deskID = b;
            var mItm = $("#" + deskID);
            PCN.subMenu.display(mItm);
            curDesktop = b;
            Desktop.isChanging = false;
        });
    }
    //检查桌面是否已满 ;
    , checkFull: function (did) {
        if (!did)
            did = curDesktop;
        var desk = window.para[did].desktop;
        var full = true;
        for (var i in desk) {
            if (desk[i] == "0") {
                full = false;
                break;
            }
        }
        return full;
    }
    , getAttr: function () {
        return $("#" + curDesktop).attr("attr");
    }
    //初次加载初始化;
    , staticPreInit: function () {
        PCN.menu.activate($("#" + curDesktop));
        PCN.subMenu.display($("#" + curDesktop));
        Desktop.initLoad(curDesktop);
        if (curDesktop == defaultDesktop)
            GetWeather(curDesktop);
    }
    //初次加载;
    , preLoad: function () {
        var did = curDesktop; ;
        var dType = curDesktop.charAt(0);
        $.post("default.aspx/GetDefaultGrids", $.toStr({ "deskStr": curDesktop }), function (msg) {
            var data = msg.d;
            if (!data)
                return;
            if (!data.Result) {
                new rPrompt("对不起，桌面加载发生异常！");
            } else {
                if (!$.isNorE(data.bgUrl)) {
                    $("body").css("background", "url(" + data.bgUrl + ")");
                } else if ((!$.isIE6) && data.userDeskBg) {
                    var img = data.userDeskBg.img;
                    var spts = data.userDeskBg.spots;
                    if (img && !$.isNorE(img.img_url)) {
                        if (spts) {
                            PCN.changeBg.boxSelect.applyStory(img, spts);
                        } else {
                            PCN.changeBg.boxSelect.applyBg(img);
                        }
                    }
                }
                if (!$.isIE6) {
                    PCN.changeBg.boxBg.resize(function () {
                        if (!PCN.maxBody) {
                            PCN.maxBody = $("<div class='maxBody'></div>").appendTo($("#Body"));
                            PCN.maxBody.css({ "height": $("#Body").height() });
                        }
                    });
                }
                var newDesk = $("#" + "desktop_area_" + curDesktop)
                newDesk.html(data.Message);
                Desktop.staticPreInit();
                PCN.deskInited = true;
            }
        });

    }
    //初始化加载的桌面;
    , initLoad: function (did) {
        var newDesk = $("#desktop_area_" + did);
        var desktopType = did.charAt(0);
        var menuItem = $("#" + did);
        var attr = menuItem.attr("attr");
        var actives = $(".icon:not('.inactive')", newDesk);
        var inactives = $(".inactive", newDesk);
        var every = $(".icon", newDesk);

        if (attr == "6") { //rss;
            menuItem.attr("noAdd", "true"); //不准添加网址格子；
            var actives = $(".Rss:not('.RssEmpty')", newDesk);
            actives.each(function (ind, ele) {
                RSS.loadUnit($(ele));
            });

            RSS.initActive(actives);
            RSS.initDrop($(".Rss", newDesk));
            RSS.initInactive($(".RssEmpty", newDesk));
        }
        else {
            //PCN.iconHintbox.init(did);

            if (did === "S_2" || did === "S_10") {
                Site.initClick(actives);
                actives.hover(function (e) {
                    if (e.relatedTarget === PCN.Icon[0])
                        return;
                    var pos = $(this).offset();
                    var wid = PCN.rebateIcon.outerWidth();
                    var hei = PCN.rebateIcon.outerHeight();
                    PCN.rebateIcon.css({ "left": pos.left + 80 - wid, "top": pos.top - hei / 2 }).show();
                }, function (e) {
                    if (e.relatedTarget !== PCN.rebateIcon[0])
                        PCN.rebateIcon.hide();
                });
            } else if (did === "S_4" || did === "S_12") {
                Site.initClick(actives);
            } else if (did == "S_9") {
                Site.initClick(actives.filter(":not(#S_9_S_3197741)"));
                newDesk.find("#S_9_S_3197741").click(function () {
                    $.fn.jmodal({
                        content: { iframe: "http://online.jiangmin.com/KvOnline.aspx" },
                        initWidth: 550,
                        initHeight: 445,
                        full: true,
                        hasCloser: true,
                        title: "江民在线杀毒"
                    });
                    return false;
                });
            } else if (desktopType == "D" && attr != "3" && attr != "10" && attr != "12"/*除了历史,常用购物都能修改删除*/) {
                Site.initInactive(inactives);
                Site.initDrag(actives);
                Site.initDroppable(every)
            } else {//其它的只能点击
                menuItem.attr("noAdd", "true");
                Site.initClick(actives);
            }
            if (desktopType == "D" && attr == "5")/*联合登录不准添加； 可以进行修改、删除*/{
                menuItem.attr("noAdd", "true"); //
            }
            if (defaultDesktop == did || attr == "12") {
                PCN.iconHintbox.init(did);
            }
            if (attr == "12") {
                PCN.copyPanel.init($(".icon:not('.inactive'):gt(0)", newDesk));
            }
        }
    }
    //下载;
    , load: function (oDid, notClose) {
        var handleErr = function () {
            $("#desktopLoading_loading").hide();
            $("#desktopLoading_error")
            .show()
            .find("a").click(function () {
                Desktop.change(oDid);
                $("#desktopLoading_error").hide();
                return false
            });
            Desktop.isChanging = false;
            return false;
        }
        var para = { "deskStr": oDid, isReg: isRegUser, "attr": $("#" + oDid).attr("attr") };
        $.ajax({
            type: "POST",
            url: "default.aspx/ChangeDesktop",
            data: $.toStr(para),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                var data = msg.d;
                if (!data.Result) {
                    return handleErr();
                }
                var desktopType = data.DesktopType;
                var did = data.DeskID;
                if (oDid != did)  //menuMyRebate
                    $("#" + oDid).attr("id", did);
                var tit = data.Title;
                var ctn = data.Content;
                window.para[did] = { "title": tit, "desktopId": did.split("_")[1], "desktop": ctn };

                var newId = "desktop_area_" + did;
                var newDesk = $("#" + newId);
                if (newDesk.length == 0)
                    newDesk = $("<div></div>").attr("id", newId).addClass("icon_area none").prependTo($("#desktop"));
                else
                    newDesk.find(".icon").droppable("destroy").draggable("destroy");
                newDesk.html(data.Data);
                Desktop.initLoad(did);
                if (did == defaultDesktop)
                    GetWeather(did);
                if (!notClose)
                    Desktop.close(did);

            },
            error: function (c) {
                handleErr();
            }
        });
    }
};

window.google = {
    ac: {}
};
window.google.ac.h = function (d, f, c) {
    var f = d[0];
    var c = d[1];
    var g = "<table cellspacing='0' cellpadding='0'>";
    var b = c.length;
    if (b > 0) {
        for (var e = 0; e < b; e++) {
            g += "<tr><td class='suggest_keyword'>" + c[e][0] + "</td><td class='suggest_num'>" + c[e][1] + "</td></tr>"
        }
        g += "</table>";
        var h = PCN.kwf.offset();
        PCN.suggestBox.html(g).css({
            left: h.left,
            top: h.top + PCN.kwf.outerHeight()
        });
        if (PCN.suggestBox.width() < PCN.kwf.outerWidth()) {
            $("table", PCN.suggestBox).width(PCN.kwf.outerWidth())
        }
        PCN.suggestBox.show();
        $("tr", PCN.suggestBox).hover(function () {
            $(this).addClass("hover")
        },
        function () {
            $(this).removeClass("hover")
        }).click(function () {
            PCN.kwf.val($(".suggest_keyword", this).text());
            PCN.suggestBox.hide()
        })
    } else {
        PCN.suggestBox.hide()
    }
};


/// 获取分页数据

function Reg() {
    $.fn.jmodal({
        content: { iframe: "Reg.aspx" },
        initWidth: 500,
        initHeight: 450,
        full: true
    });
}

function NoRegDirect() {
    alert("还没注册P.CN,请注册后登录！");
    window.location.href = "http://www.p.cn";
}

function GetWeather(did) {
    PCN.divWeather = $("#" + did + "_180_180");

//    if (typeof (IPData) != "undefined") {
//        cityName = "北京市";
//    }
//    else {
//        if (!IPData)
//            IPData = ["", "北京市"];
//        var proName = IPData[2];
//        var cityName;
//        if (proName == "北京市" || proName == "上海市" || proName == "北京市" || proName == "天津市" || proName == "重庆市") {
//            cityName = proName
//        }
//        else {
//            cityName = IPData[3];
//        }
    //    }
    var cityName = "北京市";
    $.ajax({
        type: "POST",
        url: "default.aspx/GetWeatherMsg",
        data: "{'cityName': '" + cityName + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg.d.wt) {
                var timer;
                PCN.divWeather.append("<div class='weaIcon'>" + msg.d.wt.icon + "</div>");
                PCN.divWeather.append($("<div class='weaLoca'></div>").html(msg.d.wt.loc));
                PCN.divWeather.append($("<div class='weaTemp'></div>").html(msg.d.wt.temp));
                PCN.weatherDetail.find(".container").html(msg.d.list);
                PCN.divWeather.click(function () {
                    PCN.weatherDetail.display();
                });
            }
        }
    });
}

//从p按钮添加格子;
function addSiteP(data) {
    if (curDesktop.charAt(0).toLowerCase() == "s" || $("#" + curDesktop).attr("noAdd")) {
        $.alert("对不起，此桌面不能添加！");
    }
    var pos = posToGrid(data.Positon);
    var r = {
        did: curDesktop,
        title: data.Title,
        url: data.Url,
        icon: data.IconUrl,
        bg: data.BackColor,
        color: data.FontColor,
        "pos_x": pos[1],
        "pos_y": pos[0],
        sid: data.WebSiteID.toString()
    };

    var helper = $("<div style='position:absolute;z-index:20000;left:0;top:0;display:none;'></div>");
    var icon2 = "";
    if (get_extname(r.icon) == "png" && $.isIE6) {
        icon2 = "_background-image:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + r.icon + "',sizingMethod='crop');";
    }
    helper.addClass(r.bg).html('<a target="_blank"  style="background-image: url(' + r.icon + ');  color:' + r.color + icon2 + '" class="iconcontent White">' + r.title.subBytes(0, 10) + "</a>")
    if (get_extname(r.bg) == "png" && $.isIE6)
        helper.css({ "_background-image": "none", "_filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + r.bg + "',sizingMethod='crop')" });
    var oriOS = $("#gid").offset();
    helper.appendTo("body").css({ "left": oriOS.left, "top": oriOS.top });
    PCN.currentGrid = curDesktop + "_" + r.pos_y + "_" + r.pos_x;
    var os = $("#" + PCN.currentGrid).offset();
    helper.show().animate({ "left": os.left, "top": os.top }, 1000, function () {
        Site.update(r);
        helper.remove();
        return true;
    });
}

//设为主页
function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}

function clickFriend() {
    $.fn.jmodal({
        content: { iframe: "RecommendPrize.aspx" },
        full: true,
        initWidth: 600
    });
    return false;
}

function MsgClick() {
    $.fn.jmodal({
        content: { iframe: "SayIdea.aspx" },
        initWidth: 550,
        initHeight: 300,
        full: true
    });
    return false;
}
//读取滚动新闻;
function GetNotice() {
    var para = { "isReg": isRegUser };
    $.ajax({
        type: "POST",
        url: "default.aspx/BindAnnouncement",
        data: $.toStr(para),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            $("#notices").html(msg.d);
            $("#notices").textSlider({ line: 1, speed: 500, timer: 3000 });
        }
    });
}

//media.js
(function () {
    if (!PCN.Media)
        PCN.Media = {};
    PCN.Media.CurtainADs = function (smallPath, bigPath, url) {
        var self = this;
        if (url == "#") {
            this.wins = $("<a target='_blank' class='curtainADs curtainADsLeft'><div class='mask'></div><div class='bigImg'></div><div class='smallImg'></div></a>").appendTo("body");
        }
        else {
            this.wins = $("<a href='" + url + "' target='_blank' class='curtainADs curtainADsLeft'><div class='mask'></div><div class='bigImg'></div><div class='smallImg'></div></a>").appendTo("body");
        }

        this.addComps = function () {
            var flsh = '<object width="WIDTH" height="HEIGHT"><param name="movie"  value="FILENAME"><param name="wmode" value="transparent" /><embed  width="WIDTH" height="HEIGHT" src="FILENAME"  wmode="transparent"></embed></object>';
            var img = "<img src='SRC'/>";
            var smlImg, bigImg;
            if (typeof smallPath !== "string") {
                smlImg = flsh.replace(/FILENAME/g, smallPath.path);
                smlImg = smlImg.replace(/WIDTH/g, smallPath.width);
                smlImg = smlImg.replace(/HEIGHT/g, smallPath.height);
                if ($.isIE6)
                    smlImg = $("#" + smallPath.flsBox).children();
            } else {
                smlImg = img.replace("SRC", smallPath);
            }
            if (typeof bigPath !== "string") {
                bigImg = flsh.replace(/FILENAME/g, bigPath.path);
                bigImg = bigImg.replace(/WIDTH/g, bigPath.width);
                bigImg = bigImg.replace(/HEIGHT/g, bigPath.height);
                if ($.isIE6)
                    bigImg = $("#" + bigPath.flsBox).children();
            } else {
                bigImg = img.replace("SRC", bigPath);
            }

            this.wins.find(".bigImg").append(bigImg);
            this.wins.find(".smallImg").append(smlImg);

            var right = this.wins.clone();
            right.removeClass("curtainADsLeft").addClass("curtainADsRight");
            right.appendTo("body");

            this.wins = $(".curtainADs");
            this.bigImg = this.wins.find(".bigImg");
            this.smallImg = this.wins.find(".smallImg");
            this.masks = this.wins.find(".mask");


            this.enter = function () {
                self.smallImg.hide();
                self.bigImg.show();
                if ($.isIE6) {
                    self.masks.css({ "width": self.bigImg.width(), "height": self.bigImg.height() });
                }
            };
            this.leave = function () {
                self.bigImg.hide();
                self.smallImg.show();
                if ($.isIE6)
                    self.masks.css({ "width": self.smallImg.width(), "height": self.smallImg.height() });
            };
            return this;
        }
        this.bindEvents = function () {
            self.wins.mouseenter(function () { self.enter(); });
            self.wins.mouseleave(function () { self.leave(); });
            return this;
        };
        this.autoShow = function (duration) {
            self.wins.mouseenter();
            setTimeout(function () {
                self.wins.mouseleave();
            }, duration);
            return this;
        }
        this.init = function () {
            this.addComps().bindEvents();
            return this;
        }
    }
})();

//textslider
(function ($) {
    $.fn.textSlider = function (settings) {
        settings = jQuery.extend({
            speed: "normal",
            line: 2,
            timer: 1000
        }, settings);
        if (this.length === 0)
            return null;
        var ul = $("ul:eq(0)", this);
        var li = ul.children();
        var total = li.length;
        if (total <= settings.line)
            return null;
        return new $.textSlider(this, settings);
    };
    $.extend({ textSlider: function ($this, settings) {
        if ($this.length === 0)
            return null;
        var ul = $("ul:eq(0)", $this);
        var li = ul.children();
        var total = li.length;
        if (total <= settings.line)
            return null;
        var timerID;
        var _btnUp = $(".up:eq(0)", $this)
        var _btnDown = $(".down:eq(0)", $this)
        var liHight = $(li[0]).outerHeight();
        var upHeight = 0 - settings.line * liHight; //滚动的高度；
        if (total < settings.line * 2) {
            for (var i = 0; i < settings.line * 2 - total; i++) {
                ul.find("li:eq(" + i + ")").clone().appendTo(ul);
            }
        }
        ul.wrap($("<div></div>").css({ "overflow": "hidden", "white-space": "nowrap", "height": -upHeight }));
        var scrollUp = function () {
            _btnUp.unbind("click", scrollUp);
            ul.animate({ marginTop: upHeight }, settings.speed, function () {
                for (i = 0; i < settings.line; i++) {
                    //$(li[i]).appendTo(ul);
                    ul.find("li:first").appendTo(ul);
                    // alert(ul.html());
                }
                ul.css({ marginTop: 0 });
                _btnUp.bind("click", scrollUp); //Shawphy:绑定向上按钮的点击事件
            });
        };
        var scrollDown = function () {
            _btnDown.unbind("click", scrollDown);
            ul.css({ marginTop: upHeight });
            for (i = 0; i < settings.line; i++) {
                ul.find("li:last").prependTo(ul);
            }
            ul.animate({ marginTop: 0 }, settings.speed, function () {
                _btnDown.bind("click", scrollDown); //Shawphy:绑定向上按钮的点击事件
            });
        };
        var autoPlay = function () {
            timerID = window.setInterval(scrollUp, settings.timer);
            //alert(settings.timer);
        };
        var autoStop = function () {
            window.clearInterval(timerID);
        };
        //事件绑定
        ul.hover(autoStop, autoPlay).mouseout();
        _btnUp.css("cursor", "pointer").click(scrollUp);
        _btnUp.hover(autoStop, autoPlay);
        _btnDown.css("cursor", "pointer").click(scrollDown);
        _btnDown.hover(autoStop, autoPlay);

        this.halt = autoStop;
        this.fire = autoPlay;
        this.dispose = function () {
            this.halt();
            ul.unbind();
            _btnDown.unbind();
            _btnUp.unbind();
        };
    }
    });
})(jQuery);
$(function () {

    $("text[maxlength]").keyup(function () {
        var area = $(this);
        var max = parseInt(area.attr("maxlength"), 10);

        if (max > 0) {
            if (area.val().length > max) {
                area.val(area.val().substr(0, max));
            }
        }
    });
    $("text[maxlength]").blur(function () {
        var area = $(this);
        var max = parseInt(area.attr("maxlength"), 10);
        if (max > 0) {
            if (area.val().length > max) {
                area.val(area.val().substr(0, max));
            }
        }
    });
});

/*密码修改提示初始化*/
function NewUserTipInit() {
    $(".PwdTip_Close").click(function () {
        $("#UserTip_Pwd").fadeOut();
    });
    $("#UserTip_Pwd").find(".Redirect").click(function () {
        $(".PwdTip_Close").click();
    });
    setTimeout(GetIsShowUserTip, 1000);
}

function GetIsShowUserTip() {
    $.post("Default.aspx/IsShowUserTip", function (data) {
        var msg = data.d;
        if (msg.IsEmptyPwd || msg.IsDefPwd) {
            $("#UserTip_Pwd").slideDown();
        }
    });
}


