﻿if (window.location.href.indexOf('Album.aspx') < 0) {
    $().ready(function() {
        if ($('#txt_Id_').val() == '') {
            $($('#txt_DisabledCIds_').val()).attr('disabled', 'disabled');
        }
        if ($('.date').length > 0) {
            $('div', document).click(function() {
                if ($(this).attr('class') == 'btn_date') {
                    return false;
                } else {
                    $('.datepicker').hide();
                }
            });
            $('input', '.date').keypress(function() { return false; });
        }
        $('#cate_manage,#w_Log').css('display', $('#display_logo').css('display'));
        $('<div id="bg_top"></div>').appendTo($('body'));
        $('iframe').attr('allowTransparency', true);
        SetImageSize(100, 100);
        if ($.browser.mozilla) {
            $('a:contains(\'添加收藏\')', '#blog_search_list').remove();
        }
    });
}

/*　根据输入的长宽尺寸，大图改缩略图　*/
function SetImageSize(w,h) {
    $('img', '.special_log_img_p').each(function() {
        var width = this.width;
        var height = this.height;
        if (width > w || height > h) {
            if (width > height) {
                height = height * (w / width);
                width = w;
            } else {
                width = width * (h / height);
                height = h;
            }
        }
        this.width = width;
        this.height = height;
        $(this).attr('class','border_img');
    });
}

function CheckTopFrame() {
    if (window.top.indexOf('/Admin/Default.aspx') < 0) {
        window.location.href = "/Admin/Default.aspx";
    }
}

function clearData(cIds,pIds){
    $(cIds,pIds).val('');
    if(cIds.indexOf('select')>=0){
        $('select', pIds).attr('selectedIndex', 0);
    }
    $($('#txt_DisabledCIds_').val()).attr('disabled', 'disabled');
}

function CheckData(cIds, pIds, btn) {
    var b = true;
    $(cIds, pIds).each(function() {
        if ($(this).val() == '') {
            SAlert($(this).attr('title') + "不能为空！");
            b = false;
            return false;
        }
    });
    if (b) {
        var login = true;
        if (window.location.href.indexOf('/Portal/Settings/') >= 0 || window.location.href.indexOf('/Admin/') >= 0) {
            $.post('/Portal/ImageAjax.ashx', { 'method': 'IsLogin' }, function(data) {
                login = data == '1' ? true : false;
            });
        }
        if (b && login) { $(btn).click(); } else if (!login) { ShowReLogin() }
    }
}

function setId(sId, cId) {
    $('#txt_Id_').val(sId);
    $(cId).click();
}

function showQuery(){
    $('#query_edit').toggle('slow');
}

/* 日志类型 专用 */
function pop(obj) {
    var srcobj = $(obj).parent().parent().parent().parent().parent();
    if ($(obj).attr('src') == '/Images/pop+.gif') {
        $(obj).attr('src', '/Images/pop-.gif').attr('alt', '收起子类别');
        $('a:eq(0)', $(obj).parent().next()).removeAttr('disabled');
        srcobj.next().show();
    } else {
        $(obj).attr('src', '/Images/pop+.gif').attr('alt','展开子类别');
        srcobj.next().hide();
        $('a:eq(0)', $(obj).parent().next()).attr('disabled', 'disabled');
    }
}

function popDiv(obj) {
    if ($(obj).attr('src') == '/Images/pop+.gif') {
        $(obj).attr('src', '/Images/pop-.gif').attr('alt', '收起子类别').parent().next().show();
    } else {
        $(obj).attr('src', '/Images/pop+.gif').attr('alt', '展开子类别').parent().next().hide();
    }
}

/*日期控件专用*/
function CreateDatePicker(IsShowTime, ValId, TargetId, DateFormat, TimeFormat) {
    document.write('<div class="btn_date" onclick="DatePick(\'' + TargetId + '\')"></div><div class="datepicker"' + (IsShowTime == 1 ? '' : ' style="height:170px;"') + ' id="' + TargetId + '"><embed src="/JSControls/DatePicker/DatePicker.swf?IsShowTime=' + IsShowTime + '&DateFormat=' + DateFormat + (TimeFormat == null ? '' : '&TimeFormat=' + TimeFormat) + '&ValId=' + ValId + '&TargetId=' + TargetId + '" quality="high" bgcolor="#869ca7" width="180" height="198" name="DateField" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></div>');
}
function DatePick(targetId) {
    $('.datepicker[id!="+targetId+"]').css('display', 'none');
    $('#' + targetId).css('display', 'block');
}

function ReturnValue(val, valId, targetId) {
    $('#'+valId).val(val);
    $('#' + targetId).css('display', 'none');
    if (ChangeConstellation) {
        ChangeConstellation();
    }
}

/*弹出控件*/
function ShowFrame(src, width, height, title, target, xleft, ytop, btns, after) {
    var dialog = new Boxy("<iframe src=\"" + src + "\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" width=\"" + width + "\" height=\"" + height + "\"></iframe>", { title: title, unloadOnHide: true, afterHide: after == null ? function() { } : after, modal: true });
    dialog.moveTo(xleft, ytop);
    $('#btn_Cancel_').click(function() { dialog.hide(); });
    if (btns != null) {
        $(btns).click(function() { dialog.hide(); });
    }
}

function SAlert(message) {
    Boxy.alert(message, null, { title: "提示信息" });
    return false;
}

function SConfirm(message, btn) {
    Boxy.confirm(message, function() { $(btn).click(); }, { title: "请确认", modal: true });
}

function ShowLogin() {
    var dialog = new Boxy($('#div_login'), { title: "用户登录" });
    $('#btn_ShowLogin_').unbind().click(function() { dialog.show(); });
    $('#btn_Cancel_').click(function() { dialog.hide(); });
    $('#txt_UName_').focus();
}

function CheckLogin() {
    if ($('#txt_UName_').val() == '' || $('#txt_UPwd_').val() == '') {
        PortalAlert('用户名密码不能为空！');
    } else {
        $('#txt_Name_,#ctl00_txt_Name_').val($('#txt_UName_').val());
        $('#txt_Pwd_,#ctl00_txt_Pwd_').val($('#txt_UPwd_').val());
        $('#btn_Login_').click();
    }
}
function LogOut() {
    var src = $('#frm_upimg').attr('src');
    $('#frm_upimg').attr('src', '');
    Boxy.confirm_logout("确定要退出吗？", function() { $('#btn_LogOut_,#ctl00_btn_LogOut').click(); }, function() { $('#frm_upimg').attr('src', src); }, { title: "提示信息", modal: true });
}

function PortalAlert(message) {
    var dialog = new Boxy('<div id="div_alert" style="text-align:center;display:none;"><div>' + message + '</div><button id="btn_Yes_" class="boxy-btn1" style="margin-top:15px;">确定</button></div>', { unloadOnHide: true, modal: true });
    $('#btn_Yes_').click(function() { dialog.hide(); });
}

/*无缝滚动*/
function video_scroll(scroll_panel, scroll1, scrool2) {
    var speed = 18;
    var tab = document.getElementById(scroll_panel);
    var tab1 = document.getElementById(scroll1);
    var tab2 = document.getElementById(scrool2);
    tab2.innerHTML = tab1.innerHTML;
    function Marquee() {
        if (tab2.offsetWidth - tab.scrollLeft <= 0)
            tab.scrollLeft -= tab1.offsetWidth
        else {
            tab.scrollLeft++;
        }
    }
    var MyMar = setInterval(Marquee, speed);
    tab.onmouseover = function() { clearInterval(MyMar) };
    tab.onmouseout = function() { MyMar = setInterval(Marquee, speed) };
}

/*分页脚本*/
function InitPager() {
    if ($('#a_prev').attr('href')) {
        if ($('#a_prev').attr('href').indexOf('=MinPage') > 0) { $('#a_prev').removeAttr('href'); }
        if ($('#a_next').attr('href').indexOf('=MaxPage') > 0) { $('#a_next').removeAttr('href'); }
    }
    var curpage = parseInt($('#txt_CurPage_').val());
    var pagecount = parseInt($('#txt_TotalPage_').val());
    
    if (curpage - 2 <= 1) {
        for (var i = 1; i <= (5 <= pagecount ? 5 : pagecount); i++) {
            $('<a title="第' + i + '页" onclick="ChangePage(\'' + i + '\')" class="p_num' + (i == curpage ? ' cur_p" style="color:#FFFFFF;"' : '"') + '>' + i + '</a>').insertBefore('#a_next');
        }
    } else if (curpage + 2 >= pagecount) {
        for (var i = pagecount - 4 >= 1 ? pagecount - 4 : 1; i <= pagecount; i++) {
            $('<a title="第' + i + '页" onclick="ChangePage(\'' + i + '\')" class="p_num' + (i == curpage ? ' cur_p" style="color:#FFFFFF;"' : '"') + '>' + i + '</a>').insertBefore('#a_next');
        }
    } else {
        for (var i = curpage - 2; i <= curpage + 2; i++) {
            $('<a title="第' + i + '页" onclick="ChangePage(\'' + i + '\')" class="p_num' + (i == curpage ? ' cur_p" style="color:#FFFFFF;"' : '"') + '>' + i + '</a>').insertBefore('#a_next');
        }
    }
    
//    for (var i = 1; i <= parseInt($('#txt_TotalPage_').val()); i++) {
//        $('<a onclick="ChangePage(\'' + i + '\')" class="p_num' + (i == parseInt($('#txt_CurPage_').val()) ? ' cur_p" style="color:#FFFFFF;"' : '"') + '>' + i + '</a>').insertBefore('#a_next');
    //    }
    if ($('#main_panel').length > 0) {
        $('#page_bar_bottom').html($('#page_bar_top').html());
        var rowCount = Math.ceil(parseInt($('#txt_PageSize_').val()) / 2);
        if (rowCount > 1) {
            $('#main_panel,#bg_bottom').css('height', (60 + 320 * rowCount) + 'px');
        }
    }
}

/*分页脚本2*/
function CPageInitPager() {
//    if ($('#a_prev').attr('href').indexOf('=MinPage') > 0) { $('#a_prev').removeAttr('href'); }
//    if ($('#a_next').attr('href').indexOf('=MaxPage') > 0) { $('#a_next').removeAttr('href'); }
    var curpage = parseInt($('#ctl00_c1_txt_CurPage_').val());
    var pagecount = parseInt($('#ctl00_c1_txt_TotalPage_').val());
    if (curpage - 2 <= 1) {
        for (var i = 1; i <= (5 <= pagecount ? 5 : pagecount); i++) {
            $('<a title="第' + i + '页" onclick="ChangePage(\'' + i + '\')" class="p_num' + (i == curpage ? ' cur_p" style="color:#FFFFFF;"' : '"') + '>' + i + '</a>').insertBefore('#a_next');
        }
    } else if (curpage + 2 >= pagecount) {
        for (var i = pagecount - 4 >= 1 ? pagecount - 4 : 1; i <= pagecount; i++) {
            $('<a title="第' + i + '页" onclick="ChangePage(\'' + i + '\')" class="p_num' + (i == curpage ? ' cur_p" style="color:#FFFFFF;"' : '"') + '>' + i + '</a>').insertBefore('#a_next');
        }
    } else {
        for (var i = curpage - 2; i <= curpage + 2; i++) {
            $('<a title="第' + i + '页" onclick="ChangePage(\'' + i + '\')" class="p_num' + (i == curpage ? ' cur_p" style="color:#FFFFFF;"' : '"') + '>' + i + '</a>').insertBefore('#a_next');
        }
    }
    $('#page_bar_bottom').html($('#page_bar_top').html());
}

/*博客专用*/
//添加收藏
function AddFavorites(url, name) { window.external.addFavorite(url, name + "——长春市第一实验小学"); }
//添加好友
function AddFriend(id) { ShowFrame("/Portal/Settings/AddFriend.aspx?fId=" + id, 250, 100, "添加好友", null, null, null, null); }
//添加分组
function AddGroup(id) { ShowFrame("/Portal/Settings/AddGroup.aspx", 250, 100, "添加分组", null, null, null, null); }
//编辑分组
function EditGroup(id) { ShowFrame("/Portal/Settings/AddGroup.aspx?gId=" + id, 250, 100, "编辑分组", null, null, null, null); }
//复制博客地址
function CopyBlogUrl() { window.clipboardData.setData('text', window.top.location.href); }
//复制日志地址
function CopyLogBlog(root) { window.clipboardData.setData('text', root + '/Portal/LogBlog.aspx?Id=' + $('#ctl00_c1_txt_Id_').val()); }

//回复
function RemoveReply() {
    $('.blog_reply_out').each(function() {
        if ($('.reply_info', $(this).parent()).length > 0) {
            $(this).remove();
        } else {
            $(this).parent().remove();
        }
    });
}
function ShowReply(obj,id) {
    RemoveReply();
    var reply = '';
    if ($('.reply_info', obj.next()).length < 1) {
        reply = '<div class="blog_reply"><div class="blog_reply_top"></div><div class="blog_reply_out"><textarea name="txt_RContent" id="txt_RContent" class="blog_reply_textarea" rows="3"></textarea><button class="boxy-btn1" onclick="Reply(\'' + id + '\');">确定</button>&nbsp;&nbsp;<button class="boxy-btn1" onclick="RemoveReply();">取消</button></div></div>';
        $(reply).insertAfter(obj);
    } else {
        reply = '<div class="blog_reply_out"><textarea name="txt_RContent" id="txt_RContent" class="blog_reply_textarea" rows="3"></textarea><button class="boxy-btn1" onclick="Reply(\'' + id + '\');">确定</button>&nbsp;&nbsp;<button class="boxy-btn1" onclick="RemoveReply();">取消</button></div>';
        $(reply).appendTo(obj.next());
    }  
}
function Reply(id) {
    if ($('#txt_RContent_').val() != '') {
        $('#ctl00_c1_txt_RefId_').val(id);
        $('#ctl00_c1_txt_RContent_').val($('#txt_RContent').val());
        $('#ctl00_c1_btn_Reply_').click();
    }
}
function AddQuote(aname, replyon, content) {
    window.frames["ifrHtmlEditor"].window.frames["HtmlEditor"].document.body.innerHTML = "<div style=\"border:dashed 1px #CCCCCC;margin:10px;padding:10px;\">引自：&nbsp;" + aname + "&nbsp;于&nbsp;" + replyon + "&nbsp;发表的评论<br/>引用内容：<br/>" + unescape(content) + "</div><div>&nbsp;</div>";
    document.documentElement.scrollTop = document.documentElement.scrollHeight;
}
function DelReply(id) { $('#ctl00_c1_txt_rId_').val(id); SConfirm('确定删除此回复吗？', '#ctl00_c1_btn_DelReply_'); }

/* AJAX判断是否有用户登录及用户类型权限如果有，则执行参数中的方法 */
function CheckLoginUser(bId, obj, id) {
    ShowReply(obj, id);
}

/*toggle签名档*/
function HideSign(obj, sId) {
    if ($(obj).text() == '隐藏签名档') {
        $(sId).hide();
        $(obj).text('显示签名档');
    } else {
        $(sId).show();
        $(obj).text('隐藏签名档');
    }
}

/*相册相关*/
function ShowEdit(obj) { if ($('#photo_bar').length == 0 || $('#photo_bar').css('display') == 'none') { $('.edit_album', $(obj)).show(); } }

function HideEdit(obj) { if ($('#photo_bar').length == 0 || $('#photo_bar').css('display') == 'none') { $('.edit_album', $(obj)).hide(); } }

function ShowEditInfo(url, width, height, title) {
    ShowFrame(url, width, height, title, null, null, null, null, null);
}

/*刷新父页面*/
function RefreshParent() {
    window.parent.location.href = window.parent.location.href;
}

function RefreshFrame() {
    window.top.document.getElementById('f_main').src = window.parent.location.href;
}

function AjaxRemove() {
    $.post('/Portal/ImageAjax.ashx', { method: 'Remove' });
}

function LoadPrevNext(obj, seq, count, img) {
    if (count > 1) {
        var div_w = parseInt($('.min_content').css('width'));
        var w = img.width - 5, h = img.height - 5;
        if (w < 200) { w = 200; }
        if (h < 200) { h = 200; }
        if (seq > 1) {
            var prev = '<div title="上一张" style="background:url(/Images/blank.gif);margin:0px auto;width:' + w / 2 + 'px;height:' + h + 'px;position:absolute;top:0px;left:' + (div_w - w) / 2 + 'px;" class="p_prev" onclick="$(\'.out_border[@p_count=' + (seq - 1) + ']\').click();"></div>';
            $(prev).appendTo($(obj));
        }
        if (seq < count) {
            var next = '<div title="下一张" style="background:url(/Images/blank.gif);margin:0px auto;width:' + w / 2 + 'px;height:' + h + 'px;position:absolute;top:0px;right:' + (div_w - w) / 2 + 'px;" class="p_next" onclick="$(\'.out_border[@p_count=' + (seq + 1) + ']\').click();"></div>';
            $(next).appendTo($(obj));
        }
    }
}

function VideoLoadPrevNext(obj, seq, count, img) {
    if (count > 1) {
        var div_w = parseInt($('.min_content').css('width'));
        var w = img.width - 5, h = img.height - 5;
        if (w < 200) { w = 200; }
        if (h < 200) { h = 200; }
        if (seq > 1) {
            var prev = '<div title="上一视频" style="background:url(/Images/blank.gif);margin:0px auto;width:' + (div_w - w) / 2 + 'px;height:' + h + 'px;position:absolute;top:0px;left:0px;" class="p_prev" onclick="$(\'.out_border[@p_count=' + (seq - 1) + ']\').click();"></div>';
            $(prev).appendTo($(obj));
        }
        if (seq < count) {
            var next = '<div title="下一视频" style="background:url(/Images/blank.gif);margin:0px auto;width:' + (div_w - w) / 2 + 'px;height:' + h + 'px;position:absolute;top:0px;right:0px;" class="p_next" onclick="$(\'.out_border[@p_count=' + (seq + 1) + ']\').click();"></div>';
            $(next).appendTo($(obj));
        }
    }
}

function RegistStarLevel() {
    $('#txt_RecommendStarLevel_').attr('readonly', 'readonly');
    $('img:lt(' + $('#txt_RecommendStarLevel_').val() + ')', '#star_td').attr('src', '/Images/star_2.jpg');
    $('img', '#star_td').click(function() {
        var idx = $(this).attr('seq');
        if ($(this).attr('src') == '/Images/star.jpg') {
            $('img:lt(' + idx + ')', '#star_td').attr('src', '/Images/star_2.jpg');
            $('#txt_RecommendStarLevel_').val(idx);
        } else {
            $('img:gt(' + (idx - 2) + ')', '#star_td').attr('src', '/Images/star.jpg');
            $('#txt_RecommendStarLevel_').val(idx - 1);
        }
    });
}

function LimitChars(obj, count) {
    if (obj.value.length > count) {
        obj.value = obj.value.substr(0, count);
    }
}



function ShowGoTo(message, params) {
    var shtml = '<div style="text-align:center;display:none;"><div style="padding:0px 10px 30px 10px;">' + message + '</div>';
    for (var i = 0; i < params.length; i++) {
        var param = params[i];
        shtml += '<a class="boxy-btn1" style="color:#FFFFFF;margin:3px;" href=' + param[1] + '>' + param[0] + '</a>';
    }
    shtml += '</div>;'
    var dialog = new Boxy(shtml, { title: '系统提示', unloadOnHide: true, modal: true, closeable: false });
    $('#btn_Cancel_').click(function() { dialog.hide(); });
}

function SClose() {
    $('#btn_Cancel_').click();
}