﻿
$('.btn100').mouseover(function() { $(this).addClass('over'); }).mouseout(function() { $(this).removeClass('over'); });

function toggle_md(divID) {
    if ($("#tw_" + divID).css("display") != "none")
        $("#tw_" + divID).css("display", "none");
    else
        $("#tw_" + divID).css("display", "block");
}
//获取网页内容尺寸
function getPageSize() {
    //检测浏览器的渲染模式
    var body = (document.compatMode && document.compatMode.toLowerCase() == "css1compat") ? document.documentElement : document.body;

    var bodyOffsetWidth = 0;
    var bodyOffsetHeight = 0;
    var bodyScrollWidth = 0;
    var bodyScrollHeight = 0;
    var pageDimensions = [0, 0];

    pageDimensions[0] = body.clientHeight;
    pageDimensions[1] = body.clientWidth;

    bodyOffsetWidth = body.offsetWidth;
    bodyOffsetHeight = body.offsetHeight;
    bodyScrollWidth = body.scrollWidth;
    bodyScrollHeight = body.scrollHeight;

    if (bodyOffsetHeight > pageDimensions[0]) {
        pageDimensions[0] = bodyOffsetHeight;
    }

    if (bodyOffsetWidth > pageDimensions[1]) {
        pageDimensions[1] = bodyOffsetWidth;
    }

    if (bodyScrollHeight > pageDimensions[0]) {
        pageDimensions[0] = bodyScrollHeight;
    }

    if (bodyScrollWidth > pageDimensions[1]) {
        pageDimensions[1] = bodyScrollWidth;
    }

    return pageDimensions;
}

function bhget(s) {
    return document.getElementById(s);
}

//自定
function switch_div(t) {
    var sdiv = document.getElementById(t);
    var s = sdiv.style.display;
    if (s != "none") {
        sdiv.style.display = "none";
        return false;
    }
    else {
        sdiv.style.display = "block";
        return true;
    }
}

function show_CMT(s) {
    $('#message_CMT').show();
    $('body').append('<div id="message_BG" class="d_BG"></div>');
    $('#message_BG').show();
    resizeMask();
    if ($('#cmt_Input').html().indexOf('fckContents___Config') == -1) {
        $.getScript('/Editor/fckeditor/fckeditor.js');
        $('#cmt_Input').load('/Editor/fckeditor/Editor.htm', '', function() {
            $('#fckContents').text(s);
        });
    }
    else {
        FCKeditorAPI.GetInstance('fckContents').SetHTML(s);
    }
}

function show_CMT2(s) {
    $('#msg_CMT').show();
    $('body').append('<div id="message_BG" class="d_BG"></div>');
    $('#message_BG').show();
    resizeMask();
}

function show_weightupdate(url) {
    var jstxt = '<div id="weightUpdateDiv" class="weightUpdate"><div style="width:320px;margin:48px 0 0 36px;line-height:20px;">亲爱的用户：<br />　　您已经超过7天没有更新体重了，为了更好的瘦身，请立即更新您的体重。</div><div style="margin:12px 0 0 36px;">今日体重：<input type="text" value="" class="form-text" style="width:80px" id="inputWeight"  onkeypress=""/> KG</div>';
    jstxt = jstxt + '<div style="margin:20px 0 0 200px" class="riji_banner"><ul><li><a href="javascript:void(0)" onclick="update_weightupdate(\'' + url + '\');">确定</a></li><li><a href="javascript:void(0);" onclick="hidden_weightupdate();">以后再说</a></li></ul></div>';
    jstxt = jstxt + "</div><script>$('#inputWeight').keypress(function(e){if (e.which == 13) {update_weightupdate('" + url + "');}});</script>";
    $('body').append('<div id="message_BG" class="d_BG"></div>');
    $('body').append(jstxt);
    $('#message_BG').show();
    $('#weightUpdateDiv').show();
    resizeMask();
}


function update_weightupdate(url) {
    var weighttxt = $('#inputWeight').val();

    $.post('/HttpHandle/editWeight.ashx', { weight: weighttxt }, function(txt) { alert(txt); if (txt.indexOf("成功") > 0) { window.location = url; } });
}

function hidden_weightupdate() {
    $("#weightUpdateDiv").remove();
    $("#message_BG").remove();
}

function show_diaryupdate(url) {
    var jstxt = '<div id="weightUpdateDiv" class="weightUpdate"><div style="width:320px;margin:48px 0 0 36px;line-height:20px;">亲爱的用户：<br />　　您今天还没有写过日记，是否马上去写日记？</div><div style="margin:12px 0 0 36px;"></div>';
    jstxt = jstxt + '<div style="margin:20px 0 0 200px" class="riji_banner"><ul><li><a href="' + url + '">确定</a></li><li><a href="javascript:void(0);" onclick="hidden_weightupdate();">暂时不写</a></li></ul></div>';
    jstxt = jstxt + "</div>";
    $('body').append('<div id="message_BG" class="d_BG"></div>');
    $('body').append(jstxt);
    $('#message_BG').show();
    $('#weightUpdateDiv').show();
    resizeMask();
}

function hidden_CMT() {
    var cmt = document.getElementById("message_CMT");
    cmt.style.display = "none";
    $("#message_BG").remove();
}

function hidden_CMT2() {
    var cmt = document.getElementById("msg_CMT");
    cmt.style.display = "none";
    $("#message_BG").remove();
}

function reply_CMT(s) {
    show_CMT(s);
}


function resizeMask() {
    var s = getPageSize();
    var bg = document.getElementById("message_BG");
    bg.style.width = s[1] + "px";
    bg.style.height = s[0] + "px";
}

function inserthtml(htmlstr, FCKID) {//往FCKeditor中插入内容
    if (htmlstr.length > 2) {
        FCKeditorAPI.GetInstance(FCKID).InsertHtml(htmlstr);
    }
}

function insert_img_CMT(img, FCKID) {
    var str = img.src;
    var reg = /http:\/\/[^\/]+/;
    str = str.replace(reg, "");
    var imgsrc = "<img src='" + str + "'>";
    inserthtml(imgsrc, FCKID);
}

function overTAB(s) {
    var o1 = document.getElementById("o0");
    var o2 = document.getElementById("o1");
    var s0 = document.getElementById("set0");
    var s1 = document.getElementById("set1");
    if (s == "0") {
        o1.className = "current";
        o2.className = "";
        s0.style.display = "block";
        s1.style.display = "none";
    }
    else {
        o1.className = "";
        o2.className = "current";
        s0.style.display = "none";
        s1.style.display = "block";
    }
}

function click_tag(s, k) {
    var o1 = document.getElementById(s);
    o1.value += k + " ";
}
//单行滚动
function startmarquee(lh, speed, delay, index) {
    var t;
    var p = false;
    var o = document.getElementById(index);
    o.innerHTML += o.innerHTML;
    o.onmouseover = function() { p = true }
    o.onmouseout = function() { p = false }
    o.scrollTop = 0;
    function start() {
        t = setInterval(scrolling, speed);
        if (!p) o.scrollTop += 2;
    }
    function scrolling() {
        if (o.scrollTop % lh != 0) {
            o.scrollTop += 2;
            if (o.scrollTop >= o.scrollHeight / 2) o.scrollTop = 0;
        } else {
            clearInterval(t);
            setTimeout(start, delay);
        }
    }
    setTimeout(start, delay);
}

function changeDiaryTab(s) {
    $('#uurili1').hide();
    $('#zhouji').hide();
    $('#quanjilu').hide();
    if (s == 1) {
        $('#uurili1').fadeIn("fast");
    }

    if (s == 2) {
        $('#zhouji').fadeIn("fast");
    }

    if (s == 3) {
        $('#quanjilu').fadeIn("fast");
    }
    for (i = 1; i <= 3; i++) {
        $('#DiaryTab' + i).removeClass();
    }
    $('#DiaryTab' + s).addClass('current');
}

function selectItem(s, path, vID) {
    //document.getElementById("topImage").src = path;
    var x = document.getElementsByTagName("INPUT");
    for (var i = 0; i < x.length; i++) {
        if (x[i].value == s && x[i].type == 'radio' && x[i].id == vID) {
            x[i].checked = true;
            break;
        }
    }
}

/***显示提示开始***/
var VarChkInputProdInterval;
var time = 5;
//主调函数
function promptShow(type, text) {
    time = 5;
    var typeText = '';
    var randomNum = Math.round(Math.random() * 10000000);
    if (text == '' || text == undefined) {
        text = '保存成功';
    }
    switch (type) {
        case 's':
            typeText = 'jq-notice';
            break;
        case 'e':
            typeText = 'jq-error';
            break;
        default:
            typeText = 'jq-remind';
    }
    $(document).ready(function() {
        $('body').append('<div id="message_BG" style="top: 0; left: 0; position: absolute; z-index: 1000;" class="d_BG">');
        $('#message_BG').show();
        resizeMask();
        $('body').append('<div class="jqmWindow jqmWindowInfo ' + typeText + '" id="promptBox' + randomNum + '" style="z-index: 9999; display:none;"><div class="jq-title"><span class="jq-title-name">提示信息</span><a href="javascript:void(0);" class="jqmClose jq-title-close"></a></div><div class="text-wrap"><div class="text-title">' + text + '</div><div class="timer">[该提示信息将在&nbsp;<b><span id="promptInfo' + randomNum + '" class="timer">5</span></b>&nbsp;秒后自动关闭]</div></div></div>');
        $('#promptBox' + randomNum).show();
        showSelProdDiv(randomNum);
        $('.jqmClose').click(function() {
            setStoptime(randomNum);
        });
    });
}

//判断记时器状态函数
function showSelProdDiv(randomNum) {
    if (!VarChkInputProdInterval) // 避免执行多次
        VarChkInputProdInterval = setInterval("setBegintime(" + randomNum + ")", 1000);
}

//执行函数
function setBegintime(randomNum) {
    time = time - 1;
    $('#promptInfo' + randomNum).text(time);
    if (time <= 0) {
        setStoptime(randomNum);
    }
}

//停止函数
function setStoptime(randomNum) {
    clearInterval(VarChkInputProdInterval)
    VarChkInputProdInterval = 0; // 置零
    $('#message_BG').remove();
    $('#promptBox' + randomNum).remove();
}
/***显示提示结束***/

function CopyToClipboard(meintext, showtext) {
    if (window.clipboardData) {
        // the IE-manier
        window.clipboardData.setData("Text", meintext);
    }
    else if (window.netscape) {
        // dit is belangrijk maar staat nergens duidelijk vermeld:
        // you have to sign the code to enable this, or see notes below 
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

        // maak een interface naar het clipboard
        var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                        .createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
        //alert(clip);
        // maak een transferable
        var trans = Components.classes['@mozilla.org/widget/transferable;1']
                        .createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;

        // specificeer wat voor soort data we op willen halen; text in dit geval
        trans.addDataFlavor('text/unicode');

        // om de data uit de transferable te halen hebben we 2 nieuwe objecten 
        // nodig om het in op te slaan
        var str = new Object();
        var len = new Object();
        str = Components.classes["@mozilla.org/supports-string;1"]
                        .createInstance(Components.interfaces.nsISupportsString);
        var copytext = meintext;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip) return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);
    }
    else {
        return false;
    }

    if (showtext == undefined) {
        alert("复制成功");
    }
    else {
        alert(showtext);
    }
    return false;
}

function showFoodBox(day) {
    $(document).ready(function() {
        $('body').append('<div id="message_BG" style="top: 0; left: 0; position: absolute; z-index: 0;" class="d_BG">');
        $('#message_BG').show();
        resizeMask();
        $('#ajax-progress').show();
        $('body').append('<div class="jqmWindow jqmWindowCan jqmID1" id="foodBox" style="z-index: 9999; display:none;"><div class="jq-title"><span class="jq-title-name">步点™计算器 ' + day + " " + getDayOfWeek(day) + '</span><a class="jqmClose jq-title-close" href="javascript:void(0)"/></div><div id="foodContain"></div></div>');
        $('#foodContain').load('/httphandle/FoodDiary.aspx', { day: day, anticache: Math.floor(Math.random() * 1000) }, function() { $('#ajax-progress').hide(); $('#foodBox').show(); })
        $('.jqmClose').click(function() {
            $('#message_BG').remove();
            $('#foodBox').remove();
        });
    });
}

function addFoodBox(day, type, id) {
    $(document).ready(function() {
        $('body').append('<div id="message_BG" style="top: 0; left: 0; position: absolute; z-index: 0;" class="d_BG">');
        $('#message_BG').show();
        resizeMask();
        $('#ajax-progress').show();
        $('body').append('<div class="jqmWindow jqmWindowCan jqmID1" id="foodBox" style="z-index: 9999; display:none;"><div class="jq-title"><span class="jq-title-name">步点™计算器 ' + day + " " + getDayOfWeek(day) + '</span><a class="jqmClose jq-title-close" href="javascript:void(0)"/></div><div id="foodContain"></div></div>');
        $('#foodContain').load('/httphandle/FoodDiary.aspx', { day: day, foodtype: type, foodid: id, anticache: Math.floor(Math.random() * 1000) }, function() { $('#ajax-progress').hide(); $('#foodBox').show(); })
        $('.jqmClose').click(function() {
            $('#message_BG').remove();
            $('#foodBox').remove();
        });
    });
}

function showFoodList(day,username) {
    $(document).ready(function() {
        $('body').append('<div id="message_BG" style="top: 0; left: 0; position: absolute; z-index: 0;" class="d_BG">');
        $('#message_BG').show();
        resizeMask();

        $('#ajax-progress').show();
        $('body').append('<div class="jqmWindow jqmWindowCan jqmID1" id="foodBox" style="z-index: 9999; display:none;width:770px;height:500px;overflow:auto;margin-left:-385px; "><div class="jq-title"><span class="jq-title-name">饮食安排 ' + day + " " + getDayOfWeek(day) + '</span><a class="jqmClose jq-title-close" href="javascript:void(0)"/></div><div id="foodContain"></div></div>');
        $('#foodContain').load('/httphandle/FoodList.aspx', { day: day, anticache: Math.floor(Math.random() * 1000), un: username }, function() { $('#ajax-progress').hide(); $('#foodBox').show(); })

        $('.jqmClose').click(function() {
            $('#message_BG').remove();
            $('#foodBox').remove();
        });
    });
}

function getDayOfWeek(dayValue) {
    var day = new Date(Date.parse(dayValue.replace(/-/g, '/'))); //将日期值格式化
    var today = new Array("星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    return today[day.getDay()] //day.getDay();根据Date返一个星期中的某一天，其中0为星期日
}

function formatDate(dayValue) {
    var day = new Date(Date.parse(dayValue.replace(/-/g, '/'))); //将日期值格式化
    var s = day.getFullYear() + "年" + day.getMonth() + "月" + day.getDay() + "日";
    return s;
}


function showDiaryFood(url) {
    var i = 0;
    if ($('#ctl00_ctl00_rootContent_mainContent_DiaryUpdatePanel').length > 0) {
        __doPostBack('ctl00_ctl00_rootContent_mainContent_DiaryUpdatePanel', '');
        i += 1;
    }

    if ($('#ctl00_ctl00_rootContent_mainContent_WeekUpdatePanel').length > 0) {
        __doPostBack('ctl00_ctl00_rootContent_mainContent_WeekUpdatePanel', '');
        i += 1;
    }

    if ($('#ctl00_ctl00_rootContent_mainContent_ListUpdatePanel').length > 0) {
        __doPostBack('ctl00_ctl00_rootContent_mainContent_ListUpdatePanel', '');
        i += 1;
    }

    if (i > 0) {
        $('#message_BG').remove();
        $('#foodBox').remove();
    }
    else {
        alert('保存成功!');
        window.location.href = url;
    }
}

function showWeightFood() {
    var i = 0;
    if ($('#ctl00_ctl00_rootContent_mainContent_DiaryUpdatePanel').length > 0) {
        __doPostBack('ctl00_ctl00_rootContent_mainContent_DiaryUpdatePanel', '');
        i += 1;
    }

    if ($('#ctl00_ctl00_rootContent_mainContent_WeekUpdatePanel').length > 0) {
        __doPostBack('ctl00_ctl00_rootContent_mainContent_WeekUpdatePanel', '');
        i += 1;
    }

    if ($('#ctl00_ctl00_rootContent_mainContent_ListUpdatePanel').length > 0) {
        __doPostBack('ctl00_ctl00_rootContent_mainContent_ListUpdatePanel', '');
        i += 1;
    }

    if (i > 0) {
        $('#message_BG').remove();
        $('#foodBox').remove();
    }
    //    else {
    //        alert('保存成功!');
    //        window.location.replace('/blog/progress/list.aspx');
    //    }
}

function overTAB(s) {
    if ($("#quanjilu_Content" + s).get(0).style.display == 'none') {
        $("#quanjilu_Content" + s).show();
    }
    else {
        $("#quanjilu_Content" + s).hide();
    }
}

function showTAB(s, k, r) {
    for (i = 1; i <= 5; i++) {
        $('#' + s + i).hide();
        $('#' + s + 'TAB' + i).removeClass('current');
    }
    $('#' + s + k).show();
    $('#' + s + 'TAB' + k).addClass('current');
    $('.tzgl').removeClass('hide');
}

function showMessage(s) {
    if ($('#ContentDiv' + s).css('overflow') == 'hidden') {
        $('#ContentDiv' + s).css('overflow', '');
        $('#ContentDiv' + s).css('height', '');
        $('#BoxDiv' + s).height($('#ContentDiv' + s)[0].offsetHeight + 20);
        $('#ClickHref' + s).text("收起短消息");
    }
    else {
        $('#ContentDiv' + s).css('overflow', 'hidden');
        $('#ContentDiv' + s).css('height', '90px');
        $('#BoxDiv' + s).height('');
        $('#ClickHref' + s).text("展开短消息");
    }
}


$(document).ready(function() {
    $(".walkpoints").mousemove(function(e) {
        $("#tipbox").css("visibility", "visible");
        $("#tipbox").css("top", e.pageY + 15);
        $("#tipbox").css("left", e.pageX);
        var rr = this;
        if (rr.title) { rr.rain = rr.title; rr.title = ""; }
        $("#tipbox").html(rr.rain);
    }).mouseout(function() {
        $("#tipbox").css("visibility", "hidden");
    })
})

function addmsn() {
    CopyToClipboard("bangsohelp@hotmail.com", "帐号已复制到剪贴板，请粘贴后添加MSN帐号:bangsohelp@hotmail.com");
}

function addBookmark(title, url) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    } else if (document.all) {
        window.external.AddFavorite(url, title);
    } else if (window.opera && window.print) {
        return true;
    }
}

jQuery.fn.kk_highlight = function(target_value, highlight_style) {
    this.each(function() {
        var target_value2 = target_value;
        var tmp = target_value;
        tmp = tmp.replace(/ /g, "+");
        tmp = tmp.replace(/减肥/g, "+减肥");
        tmp = tmp.replace(/热量/g, "+热量");
        tmp = tmp.replace(/的/g, "+");
        var t = tmp.split('+');

        var j = 0;
        var children = this.childNodes;
        for (var i = 0; i < children.length; i++) {
            var child = children[i];
            if (child.nodeType == 3) {
                for (j = 0; j < t.length; j++) {
                    var temp_value = child.nodeValue
                    target_value = t[j];
                    if (target_value != "") {
                        var key_index = temp_value.indexOf(target_value);
                        if (key_index >= 0) {

                            child.nodeValue = temp_value.substr(0, key_index);
                            $(child).after("<font class='hilite" + j + "'>" + target_value + "</font>" + temp_value.substr(key_index + target_value.length));
                            i += 1;
                        }
                        if (j >= 4) {
                            break;
                        }
                    }
                }
            }
            else {
                $(child).kk_highlight(target_value2, highlight_style);
            }
        }
    });
};

function loadEditor(editorID, ieHack) {
    var editorobj = document.getElementById(editorID);
    editorobj.contentWindow.document.designMode = "on";
    editorobj.contentWindow.document.contentEditable = true;
    editorobj.contentWindow.document.open();
    editorobj.contentWindow.document.write('<html><head><style type="text/css">body {background: #ffffff; margin:1px; padding:1px;color:#666; font-size:14px; overflow:auto;word-wrap: break-word; font-family: Verdana, \'宋体\';cursor:text;min-height:40px;*height:40px;width:90%;} p {padding: 0px; margin: 0px; }blockquote{border:1px double #eee;padding:8px;margin:12px;background-color: #fff;color:#999;}</style></head><body></body></html>');
    editorobj.contentWindow.document.close();
    //IE:当回车的时候,换单行,即用<br>代替<p>
    if(document.all){
       editorobj.document.attachEvent('onkeypress',br_when_newline);      
    }
    editorobj.contentWindow.document.close();
    //Firefox focus()
    if (!document.all) {
        document.getElementById(editorID).contentWindow.document.body.innerHTML = '<br />';
        //document.getElementById(editorID).focus();
    }
    else {
        if (ieHack) {
            $(document).ready(function() {
                var editorWin = document.getElementById(editorID).contentWindow.focus();
            });
        }
    }
}

function br_when_newline(editorID) {
    if (!editorID) {
        var frameEditorObj = document.getElementById(editorID).contentWindow;
        e = frameEditorObj.event;
        if (e.keyCode == 13) {
            var txt = frameEditorObj.document.selection.createRange(); //获得光标位置
            txt.pasteHTML('<br />'); //在光标处添加<BR>
            txt.collapse(false); //设置插入点
            txt.select();
            return false; //直接返回,避免产生<p>
        }
    }
}

function insertFace(editorID, facestr,f) {
    var editorWin = document.getElementById('editor_' + editorID).contentWindow;
    var editorDoc = editorWin.document;
        editorWin.focus();

    if (document.all) {
        //IE
        editorDoc.selection.createRange().pasteHTML('<img src="' + facestr + '" />');
    } else {
        //Firefox
        var icon = document.createElement('img');
        icon.src = facestr;
        var range = editorWin.getSelection().getRangeAt(0);
        range.deleteContents();
        range.surroundContents(icon);
        range.collapse(false);
    }
    $('#messageFaceBox' + editorID).hide();
    editorWin.focus();
}

function commentreply(html) {
    var editorWin = document.getElementById('editor_comment').contentWindow;
    var editorDoc = editorWin.document;
    editorWin.focus();

    if (document.all) {
        //IE
        editorDoc.selection.createRange().pasteHTML(html);
    } else {
        //Firefox
    var oSel = editorWin.getSelection();
    var oRange = oSel.getRangeAt(0);
    var oFragment = oRange.createContextualFragment(html);
    var oLastNode = oFragment.lastChild;
    oRange.insertNode(oFragment);
    oRange.setEndAfter(oLastNode);
    oRange.setStartAfter(oLastNode);

    }
    editorWin.focus();
}

var request = {
    QueryString: function(val) {
        var uri = window.location.search;
        var re = new RegExp("" + val + "\=([^\&\?]*)", "ig");
        return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
    },
    QueryStrings: function() {
        var uri = window.location.search;
        var re = /\w*\=([^\&\?]*)/ig;
        var retval = [];
        while ((arr = re.exec(uri)) != null)
            retval.push(arr[0]);
        return retval;
    },
    setQuery: function(val1, val2) {
        var a = this.QueryStrings();
        var retval = "";
        var seted = false;
        var re = new RegExp("^" + val1 + "\=([^\&\?]*)$", "ig");
        for (var i = 0; i < a.length; i++) {
            if (re.test(a[i])) {
                seted = true;
                a[i] = val1 + "=" + val2;
            }
        }
        retval = a.join("&");
        return "?" + retval + (seted ? "" : (retval ? "&" : "") + val1 + "=" + val2);
    }
}
function isKeyTrigger(e, keyCode) {
    var argv = isKeyTrigger.arguments;
    var argc = isKeyTrigger.arguments.length;
    var bCtrl = false;
    if (argc > 2) {
        bCtrl = argv[2];
    }
    var bAlt = false;
    if (argc > 3) {
        bAlt = argv[3];
    }

    var nav4 = window.Event ? true : false;

    if (typeof e == 'undefined') {
        e = event;
    }

    if (bCtrl &&
        !((typeof e.ctrlKey != 'undefined') ?
            e.ctrlKey : e.modifiers & Event.CONTROL_MASK > 0)) {
        return false;
    }
    if (bAlt &&
        !((typeof e.altKey != 'undefined') ?
            e.altKey : e.modifiers & Event.ALT_MASK > 0)) {
        return false;
    }
    var whichCode = 0;
    if (nav4) whichCode = e.which;
    else if (e.type == "keypress" || e.type == "keydown")
        whichCode = e.keyCode;
    else whichCode = e.button;

    return (whichCode == keyCode);
}

function bindpage(pagesize, cpage, un, countid, listid, filename) {
    var recordcount = 0;
    $('#comment_pagecount').load(filename + "?bun=" + un + "&showpage=true", function(data) { bindlist(data, pagesize, cpage, un, listid); });
}

function bindshoppage(pagesize, cpage, id, countid, listid, filename) {
    var recordcount = 0;
    $('#comment_pagecount').load(filename + "?id=" + id + "&showpage=true", function(data) { bindlist(data, pagesize, cpage, id, listid); });
}

function bindlist(recordcount, pagesize, cpage, un, listid) {
    var pagecount = parseInt(recordcount / pagesize);
    pagecount = recordcount % pagesize >= 1 ? pagecount + 1 : pagecount;

    var list = "";
    var currentpage = "";
    currentpage = cpage == '' ? 1 : parseInt(cpage);
    currentpage = currentpage <= 0 ? 1 : currentpage;
    currentpage = currentpage > pagecount ? pagecount : currentpage;
    var firstlink = "", prevlink = "", nextlink = "", lastlink = "", pagelist = "";
    firstlink = currentpage > 1 ? "<a href='javascript:void(0)' onclick='bind(" + pagesize + ",1,\"" + un + "\");'>«</a>" : "«";
    prevlink = currentpage > 1 ? "<a href='javascript:void(0)' onclick='bind(" + pagesize + "," + (parseInt(currentpage) - 1).toString() + ",\"" + un + "\");'>上一页</a>" : "上一页";
    nextlink = currentpage < pagecount ? "<a href='javascript:void(0)' onclick='bind(" + pagesize + "," + (parseInt(currentpage) + 1).toString() + ",\"" + un + "\");'>下一页</a>" : "下一页";
    lastlink = currentpage < pagecount ? "<a href='javascript:void(0)' onclick='bind(" + pagesize + "," + pagecount + ",\"" + un + "\");'>»</a>" : "»";

    var displayNums = 10;
    var r = 1;
    var k = parseInt(currentpage / displayNums);
    var j = pagecount;
    if (k == 0) {
        r = 1;
    }
    else {
        r = k * displayNums;
    }
    r = r == pagecount ? r - displayNums : r;
    r = r <= 0 ? 1 : r;

    if (j / displayNums >= 1) {
        j = k * displayNums + displayNums;
        j = k == 0 ? j + 1 : j;
    }
    j = j > pagecount ? pagecount : j;

    for (var i = r; i <= j; i++) {
        if (i == parseInt(cpage))
            pagelist += "<span class='current'>" + i + "</span>&nbsp;";
        else
            pagelist += "<a href='javascript:void(0);' onclick='bind(" + pagesize + "," + i + ",\"" + un + "\")'>" + i + "</a>&nbsp;";
    }
    $("#" + listid).html(firstlink + " " + prevlink + " " + pagelist + " " + nextlink + " " + lastlink);
}
//foodstart
function changefm(date, cantype) {
    var furl = "", menuurl = ""; 
    if (cantype == "yundong") {
        furl = "/HttpHandle/SportsHotList.aspx";
        menuurl = "/HttpHandle/FoodSportsTopMenu.aspx";
    }
    else {
        furl = "/HttpHandle/FoodRecommendation.aspx";
        menuurl = "/HttpHandle/FoodMealTopMenu.aspx";
    }
    savefoodscroll(); $('#foodDiv').html('<div style=\'padding:20px;text-align:center;\'><img src=\'/images/loader.gif\' /></div>'); $('#topDiv').load('/HttpHandle/FoodMealDiary.aspx', { Type: cantype, day: date }); $('#foodDiv').load(furl, { Type: cantype, day: date }); $('#topMenu').load(menuurl, { Type: cantype, day: date }, function() { hideajax() });
}

function createfoodclass(types, days, numbers) {
    showajax(); $('#foodDiv').html('<div style=\'padding:20px;text-align:center;\'><img src=\'/images/loader.gif\' /></div>'); $('#foodDiv').load('/HttpHandle/FoodClass.aspx', { Type: types, day: days, c: numbers, b: numbers, anticache: Math.floor(Math.random() * 1000) }, function() { hideajax() })
}

function bindfoodlink(types, days, urls) {
    showajax(); $('#foodDiv').html('<div style=\'padding:20px;text-align:center;\'><img src=\'/images/loader.gif\' /></div>'); $('#foodDiv').load('/HttpHandle/' + urls, { Type: types, day: days, anticache: Math.floor(Math.random() * 1000) }, function() { hideajax() });
}

function foodover(v) {
    v.parent().parent().parent().find('.shiwu_info_wai #shiwu_tip').show();
}
function foodout(v) {
    v.parent().parent().parent().find('.shiwu_info_wai #shiwu_tip').hide();
}
function foodaddlink(days, belongids, unitid) {
    savefoodscroll(); $('#topDiv').load('/HttpHandle/FoodMealDiary.aspx', { Type: $('.budian_ban .current').get(0).id, day: days, id: belongids, updateType: 'add', unitid: unitid }, function() { hideajax() });
    $('#addpanel' + belongids).hide();
}
function foodfavlink(belongids) {
    $.post('/HttpHandle/FoodFav.ashx',{id:belongids},function(txt){alert(txt);})
}

function foodpage(urls,pages,types,days,c,b,t,key) {
    showajax(); $('#foodDiv').load('/HttpHandle/' + urls, { page: pages, Type:types, day: days,c:c,b:b,t:t,key:key }, function() { hideajax() });
}

function foodsclass(types,days,c,numbers) {
    showajax(); $('#foodDiv').html('<div style=\'padding:20px;text-align:center;\'><img src=\'/images/loader.gif\' /></div>'); $('#foodDiv').load('/HttpHandle/FoodClass.aspx', { Type: types, day: days, c: c, t: 'small', b: numbers, anticache: Math.floor(Math.random() * 1000) }, function() { hideajax() })
}
//foodend

function feedpage(urls, pages,un) {
   $('#callmeContent').load('/HttpHandle/' + urls, { page: pages, bun: un });
}

function savefoodscroll() {
    //    var div = document.getElementById("record_board");
    //    setCookie('foodscroll', div.scrollTop, 1);
    showajax();
}

function hideajax() {
    $('#ajax-progress').hide();
}

function showajax() {
    $('#ajax-progress').show();
}
function jiaone(k) {
    var d = $(k).parent().parent().find("#foodnum").val();
    if (isNaN(d)) {
        d = 1;
    }
    else if (d <= 0) {
        d = 1;
    }
    d = parseFloat(d) + 1 <= 0 ? 1 : parseFloat(d) + 1;
    d = Math.round(d * 10) / 10;
    $(k).parent().parent().find("#foodnum").val(d);
}
function jianone(k) {
    var d = $(k).parent().parent().find("#foodnum").val();
    if (isNaN(d)) {
        d = 1;
    }
    else if (d <= 0) {
        d = 1;
    }
    d = parseFloat(d) - 1 <= 0 ? 1 : parseFloat(d) - 1;
    d = Math.round(d * 10) / 10;
    $(k).parent().parent().find("#foodnum").val(d);
}