﻿function menushow(div, user, n) {
    for (i = 1; i <= n; i++) {

        var menu = document.getElementById(div + i);
        var con = document.getElementById(div + "_ul" + i);
        /* menu.className = i == cursel ? "check" : "";*/
        if (con.style.display = "block") {
            con.style.display = i == user ? "block" : "none";
        }
    }
}

function menuFix(ulname, divname) {
    var sfEls = document.getElementById(ulname);
    var sfdiv = document.getElementById(divname);
    if (sfEls.style.display == "none" || sfEls.style.display == "") {
        sfEls.style.display = "block";

    }
    else {
        sfEls.style.display = "none";
    }
}
function menuFix1() {
    var id = document.getElementById("dataid").value;
    var sfEls = document.getElementById("area_div_ul" + id);
    var sfdiv = document.getElementById("area_div" + id);
    if (sfEls.style.display == "none" || sfEls.style.display == "") {
        sfEls.style.display = "block";
    }
    else {
        sfEls.style.display = "none";
    }
}

function clicksection() {
    var id = document.getElementById("seclidataid").value
    if (id != "") {
        var secli = document.getElementById("secli_" + id);
        secli.style.background = "#fff6d1";
        if (document.getElementById("pridateid").value != "") {
            document.getElementById(document.getElementById("pridateid").value).style.background = "";
        }
        else {
            document.getElementById("pridateid").value = id;
        }
    }
}

function chage(type) {
    if (type == 1) {
        document.getElementById('collect1').style.display = "block";
        document.getElementById('collect2').style.display = "none";
        document.getElementById('co1').className = "check";
        document.getElementById('co2').className = "";
    }
    else {
        document.getElementById('collect1').style.display = "none";
        document.getElementById('collect2').style.display = "block";
        document.getElementById('co1').className = "";
        document.getElementById('co2').className = "check";
    }
}

function undisplay() {
    document.getElementById("toppic").style.display = "none";
}
function changdisplay(dataid) {

    if (document.getElementById("operate_div" + dataid).style.display == "none") {
        document.getElementById("operate_div" + dataid).style.display = "block";
    }
    else {
        document.getElementById("operate_div" + dataid).style.display = "none";
    }
}

function redirectnewpage(url) {
    window.open(url, "商家地图", "width=700,height=500,location=no, toolbar =no, menubar=no, scrollbars=no, resizeable=no, status=no,dependent=true");
}

function nodata() {
    document.getElementById("nodata").style.display = "block";
}

function AddStore(type, id) {
    jQuery.ajax(
                {
                    type: "post",
                    url: "Ajax/AddFavourite.aspx",
                    data: "id=" + id + "&type=" + type,
                    success: function(msg) {
                        jtip(msg);
                    }
                })
}

function mouserover(id) {
    document.getElementById(id).className = "rank_check1 j_left";
}
function mouseout(id) {
    document.getElementById(id).className = "rank_span1 j_left";
}

function checksection() {
    var fs = $("#drSection").val() + "";
    var ss = $("#drSubSection").val() + "";
    if (fs == "-1" || ss == "-1") {
        jtip("请选择您所在的区域");
        return false;
    }
    return true;
}

function autohide() {
    $("#toppic").slideUp("slow");
}

function showsection() {
    $("#divsection").show();
}

function hidesection() {
    $("#divsection").hide();
}

function showtogo(index) {

    var v = $("#hotli" + index);
    var _v = $("#_hotli" + index);

    $(".linone").removeClass("show");
    $(".linone").addClass("hide");
    $(".head").removeClass("hide");
    $(".head").removeClass("show");


    $("#_hotli" + index).removeClass("hide");
    $("#_hotli" + index).addClass("show");
    v.addClass("hide");
}

function showfood(cursel) {
    handlecookie("tab", cursel, { expires: 1, path: "/", secure: false });
    for (i = 0; i <= 1; i++) {
        document.getElementById("fli" + i).className = i == cursel ? "tab_check" : "";
        document.getElementById("fdiv" + i).style.display = i == cursel ? "" : "none";
    }

}

/************
  没登录时  p1=-1 , p2 = -1，点击检查是否登录。
  登录后没收藏的： p1=foodid , p2= userid;
  登录后收藏的：  p1=foodfarateid ,p2=0;
  

 ******************/
function handlecol(p1, p2 , target) {
    var ppp = $("#top_spanpoint").html().replace(/(^[\s]*)|([\s]*$)/g, "");
    if (p1 == -1 && ppp == "") {
        jtip("登录后才能进行此操作。");
        return false;
    }
    if (p1 == -1 && ppp != "") {
        //刷新获取数据
         window.location =  window.location.href;
    }
    if (p2 == 0) { //已经收藏,些操作是删除收藏
        delmyStore(p1 , target);
    }
    else { //收藏
        AddmyStore("food", p1,target);
    }
}

//移除收藏
function delmyStore(id, target) {
    jQuery.ajax(
    {
        type: "post",
        url: "../Ajax/deletefavourite.aspx",
        data: "id=" + id,
        success: function(msg) {
            if (msg == 0) {
                jerror();
            }
            else {
                target.innerHTML = "我要收藏";
                jtip("操作成功。");
            }
        }
    })
}
//收藏
function AddmyStore(type, id , target) {
    jQuery.ajax(
                {
                    type: "post",
                    url: "../Ajax/AddFavourite.aspx",
                    data: "id=" + id + "&type=" + type,
                    success: function(msg) {
                        jtip(msg);
                        target.innerHTML = "移除收藏";;
                    }
                })
 }

///根据cookie显示数据
function intitable() {
    var v = handlecookie("tab");
    if (v != null) {
        showfood(v);
    }
}


function setmy() {
    var key = $("#tbkey").val() + "";
    if (key == "请输入菜名") {
        $("#tbkey").val("");
    }
}

function checkprice() {

    debugger;
    var p1 = $("#tbstar").val();
    var p2 = $("#tbend").val();
    var patrn = /^[0-9]{1,4}$/;
    if (p1 != "") {
        if (!patrn.test(p1)) {
            alert("请输入整数。");
            $("#tbstar").focus();
            return false;
        }
        else {
            $("#tbstar").css("border", "#D9D9D9"); //
        }
    }
    if (p2 != "") {
        if (!patrn.test(p2)) {
            alert("请输入整数。");
            $("#tbend").focus();
            return false;
        }
        else {
            $("#tbend").css("border", "#D9D9D9"); //
        }
    }
    return true;
} 

/*****************************************************************/
//操作cookie
//value:不为空时,表示设置cookie
//value:为空时,表示得到这个名字的cookie
// add by jijunjian 2010-03-26;
function handlecookie(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie 
        options = options || {};
        if (value === null || value == "") {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            }
            else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    }
    else { // only name given, get cookie 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want? 
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

