﻿$(document).ready(function() {
    $('#userset').click(function() {
        $.blockUI({
            message: $('#usersetdiv'),
            css: {
                top: ($(window).height() - 500) / 2 + 'px',
                left: ($(window).width() - 654) / 2 + 'px',
                width: '654px'
            }
        });
    });

    $('#closeuserset').click(function() {
        setTimeout($.unblockUI, 50);
    });
    $('#loadpic').click(function() {
        $.blockUI({
            message: $('#loadpicdiv'),
            css: {
                top: ($(window).height() - 200) / 2 + 'px',
                left: ($(window).width() - 654) / 2 + 'px',
                width: '654px'
            }
        });
    });
    $('#closeloadpic').click(function() { setTimeout($.unblockUI, 50); });

    // head
    $('#usersettop').click(function() {
        $.blockUI({
            message: $('#usersetdivtop'),
            css: {
                top: ($(window).height() - 500) / 2 + 'px',
                left: ($(window).width() - 654) / 2 + 'px',
                width: '654px'
            }
        });
    });

    $('#closeusersettop').click(function() {
        setTimeout($.unblockUI, 50);
    });
    $('#loadpictop').click(function() {
        $.blockUI({
            message: $('#loadpicdivtop'),
            css: {
                top: ($(window).height() - 200) / 2 + 'px',
                left: ($(window).width() - 654) / 2 + 'px',
                width: '654px'
            }
        });
    });
    //在线点菜

    $('#alacarte').click(function() {

        $.blockUI({

            message: $('#alacarteDiv'),
            css: {
                top: ($(window).height() - 200) / 2 + 'px',
                left: ($(window).width() - 620) / 2 + 'px',
                width: '700px'

            }
        });
    });
    $('#Previous').click(function() {
        $.blockUI({

            message: $('#alacarteDiv'),
            css: {
                top: ($(window).height() - 200) / 2 + 'px',
                left: ($(window).width() - 620) / 2 + 'px',
                width: '700px'

            }
        });
    });
    $('#alacartes').click(function() {

                $.blockUI({

                message: $('#alacartesDiv'),
                    
                    css: {
                        top: ($(window).height() - 200) / 2 + 'px',
                        left: ($(window).width() - 620) / 2 + 'px',
                        width: '700px'

                    }
        });
    });


    //关闭DIV层
    $('#close').click(function() {
        setTimeout($.unblockUI, 0);
    });
    //关闭DIV层
    $('#onclose').click(function() {
        setTimeout($.unblockUI, 0);
    });

    //关闭DIV层
    $('#Determine').click(function() {
        alert('点餐成功！');
        setTimeout($.unblockUI, 1000);
    });




    $('#closeloadpictop').click(function() { setTimeout($.unblockUI, 50); });

});

function closediv() {
    setTimeout($.unblockUI, 50);
    window.location.reload();
}

function checkusermemname(oldname) {
    var memName = $.trim($('#MemName').val());
    var nameErr = $('#nameerr');
    var nameIsOk = true;
    if (memName != oldname) {
        if (checkEmpty(memName) || memName.toString().length < 4) {
            nameErr.html("<img src='/images/zone/no_icon.gif' />不能少于4个字符！");
            $('#hidCheck').val("false");
            nameIsOk = false;
            return;
        }
        if (!checkChinaEnglishNumber(memName)) {
            nameErr.html("<img src='/images/zone/no_icon.gif' />只能由中文、英文和数字组成！");
            $('#hidCheck').val("false");
            nameIsOk = false;
            return;
        }
        if (nameIsOk) {
            hasNameInDC(memName);
        }
        if (nameErr.html() == "") {
            nameErr.html("<img src='/images/zone/ok_icon.gif' />");
            nameIsOk = true;
        } 
    }
}

function checkusermobile(oldmobile) {
    var mobile = $.trim($('#MobilePhone').val());
    var mobileerr = $('#mobileerr');
    mobileerr.html("");
    mobileIsOk = true;
    if (mobile != oldmobile) {
        if (checkPhone()) {
            mobileerr.html("<img src='/images/zone/no_icon.gif' />手机号码格式不正确！");
            mobileIsOk = false;
        }
        else if (mobile != "") {
            var url = '/Check/HasMobile';
            var data = "val=" + escape(mobile);
            mobileerr.html(getWaitCode());
            $.ajax({
                type: "Get",
                url: url,
                data: data,
                dataType: "json",
                success: function(json) {
                    if (json.R == "s") {
                        //有会员
                        mobileerr.html("<img src='/images/zone/no_icon.gif' />此手机号码已经被注册！");
                        mobileIsOk = false;
                    }
                    else {
                        if (json.M == "") { mobileIsOk = true; mobileerr.html("<img src='/images/zone/ok_icon.gif' />"); }
                        else { mobileerr.html(json.M); }
                    }
                },
                error: function() {
                }
            });
        }
    }
}

function checkusermail(oldmail) {
    var mail = $.trim($('#Mail').val());
    var mailerr = $('mailerr');
    mailerr.html('');
    if (mail != oldmail) {
        if (checkEmail()) {
            mailerr.html("<img src='/images/zone/no_icon.gif' />电子邮箱格式不正确！");
            emailIsOk = false;
            return;
        }
        else if (mail != "") {
            hasEmailInDC(mail);
        }
    }
    if (mailerr.html() == "") {
        emailIsOk = true;
        mailerr.html("<img src='/images/zone/ok_icon.gif' />");
    }
}

function AddressByIP() {
    var address = $('#Address');
    if ($.trim(address.val()) == "") {
        $.ajax({
            type: "Post",
            url: "/User/GetAddressByIP",
            dataType: "json",
            success: function(json) {
                address.val(json.toString());
            },
            error: function() {
            }
        });
    }
}
emailIsOk = true;
nameIsOk = true;
mobileIsOk = true;
function usersetsubmit() {
    if (emailIsOk && nameIsOk && mobileIsOk) {
        return true;
    }
    return false;
}

//-----------------上传图片-------------
//限制上传图片大小512K 
var MAXSIZE = 512 * 1024; 
//图片大小限制信息
var ERROR_IMGSIZE = "图片大小不能超过512K！"; 
//默认图片
var NOPHOTO = "/images/zone/nopeople.jpg"; 
//图片是否合格 
var isImg = true; 
/** 
* Input file onchange事件 
* @params obj file对象 
* @return void 
**/
function checkFileChange(obj) {
    isImg = true; 
    //初始化设置 
    updateTips("");
    var img = $('#userPic1');
    var file = obj.value;
    var exp = /.\.jpg|.\.gif|.\.png|.\.bmp/i;
    
    if (exp.test(file)) {//验证格式
        getValue('uploadImg', 'userPic1', 'userPic2');
        //sizeCheck(img);
    } else {
        img.src = NOPHOTO;
        updateTips("图片格式不正确！");
        isImg = false;
    }
} 

/** 
* updateTips 注册错误信息显示 
* @params str 显示内容 
* @return void 
**/
function updateTips(str) {
    if (str != "")
        str = str + "<br/>";
    $("#errorTips").html(str);
}
/** 
* commit 注册提交 
* @return void 
**/
function commit() {
    if (isImg) {
        return true;
    }
    return false;
}
/** 
* errorImg 图片错误显示 
* @params img 图片对象 
* @return void 
**/
function errorImg(img) {
    img.src = NOPHOTO;
}

//obj1上传控件的id obj2<img />控件id obj<div>控件id
function getValue(obj1, obj2, ob3) {
    var isIE = (document.all) ? true : false;
    var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);
    var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);
    var isMozilla = (window.navigator.userAgent.indexOf("Firefox") != -1);
    var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
    var t1 = document.getElementById(obj2);
    var t2 = document.getElementById(ob3);
    if (isIE7 || isIE8) {
        t1.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image')";
        t2.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')";
    }

    var t = document.getElementById(obj1);
    var value = t.value;

    if (isIE7 || isIE8) {
        t.select();
        var value = document.selection.createRange().text;
        document.selection.empty();
    } else if (isMozilla) {
        value = t.files[0].getAsDataURL();
    }
    else if (isOpera) {
        t2.innerHTML = "Opera 浏览器得不到本地路径，所以无法提供预览效果，谢谢！";
        t2.style.visibility = "";
        return;
    }

    if (isIE7 || isIE8) {
        t1.style.visibility = "hidden";
        t2.style.visibility = "";
        t2.style.display = "";
        t1.style.display = "none";
        t2.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = value;
    } else {
        t1.src = value;
        $("#pichide").show();
    }
}


////////////////////添加好友
// code 好友编号
function addFriend(code) {
    //alert(code);
    $.ajax({
        type: "Post",
        url: "/MyDomain/AddFriend",
        data: "friendCode=" + code,
        dataType: "json",
        success: function(json) {
            if (json.R) {
                alert("添加成功！");
            }
            else {
                if (json.ErrCode == 0) {
                    alert("可能网络出现异常，请稍后再试！");
                }
                else if (json.ErrCode == 1) {
                    alert("添加失败，未能找到此会员信息！");
                }
                else if (json.ErrCode == 2) {
                    alert("您采用的是非法请求！");
                }
            }
        },
        error: function() {
        }
    });
}