﻿Lucee.UserLogin = function(userlogin) {
    if ($("#username").val() == "") {
        alert("请输入用户名");
        return;
    }
    if ($("#password").val() == "") {
        alert("请输入密码");
        return;
    }
    var read = "0";
    if (document.getElementById("isread").checked) {
        read = 1;
    }
    $.post("/globe/", { action: 3, username: $("#username").val(), password: $("#password").val(), isread: read, rd: Math.random() }, function(res) {
        if (res == "0") {
            alert("登陆失败,用户名和密码错误");
        }
        else {

            
        
            $("#t_login_div").html("<span>您好:<a href=\"http://i.23544.com/user/\">" + res.split("|")[0] + ",欢迎回来!</a><a href='http://i.23544.com/user/'>[进入会员中心]</a><a href='http://www.23544.com/LogOut.aspx'>[退出登陆]</a></span>")
            html = "";
            if (document.getElementById("comentlist_submit") != undefined) {
                html += "<div class=\"hrow_l\">";
                html += "用户：";
                html += "</div>";
                html += "<div class=\"hrow_r\">";
                html += res.split("|")[0];
                html += "</div>";
                $("#comentlist_submit").html(html);
            }
            if (userlogin == "login") {
                if (document.getElementById("login_box") != undefined && document.getElementById("login_box") != null) {
                    var url = "http://www.23544.com/globe/";
                    var data = { action: 24, rd: 0.5547417962602669 };
                    $.post(url, data, function(redata) {
                        if (redata != "0") {
                            var p = redata.split("|");
                            var fid = p[0];
                            var floginname = p[1];
                            var fnickname = p[2];
                            var fheadimg = p[3];
                            var fmoney = p[4];
                            var fintegral_A = p[5];
                            var orderstatus = p[6];
                            var onComment = p[7];
                            var html = "";
                            html += "<div class=\"line\"></div>";
                            html += "<div class=\"Success\">";
                            html += "  <dl>";
                            html += "    <dt><a><img src=\"" + fheadimg + "\" /></a></dt>";
                            html += "    <dd><a><b>" + fnickname + "</b></a>&nbsp;&nbsp;<a href=\"http://i.23544.com/account/Recharge.aspx\">充值</a></dd>";
                            html += "    <dd><span>积分:</span><strong>" + fintegral_A + "</strong></dd>";
                            html += "    <dd><span>余额:</span><strong>￥" + Math.round(fmoney * 100) / 100 + "</strong></dd>";
                            html += "  </dl>";
                            html += "  <div class=\"Zone\">";
                            if (orderstatus > 0)
                                html += "    <a href=\"http://i.23544.com\"><b>" + orderstatus + "</b>未付款</a>";
                            if (onComment > 0)
                                html += "    <a href=\"http://i.23544.com\"><b>" + onComment + "</b>待评价</a>";
                            html += "  </div>";
                            html += "</div>";
                            $("#login_box").html(html);

                        }
                    });

                }
                Lucee.PopWindowClose();
            }
            else {
                Lucee.PopWindowClose();
                Lucee.PopWindow("collect");
            }

        }
    })
}
//购物车
function AddShopCart(fid, count, fremarks) {
    if (fremarks != undefined) {
        if (fremarks == "") {
            fremarks = "鲜花或蛋糕";
        }
    }
    else {
        fremarks = "零食";
    }
    if (count == undefined) {
        $.get("/globe/", { action: 11, rd: Math.random(), fid: fid, fremarks: fremarks }, function() { })
    }
    else {
        $.get("/globe/", { action: 11, rd: Math.random(), fid: fid, count: count, fremarks: fremarks }, function() { })
    }
}
//购物车
function AddShopCart_GroupBuy(fid, count, fremarks) {
    if (fremarks != undefined) {
        if (fremarks == "") {
            fremarks = "鲜花或蛋糕";
        }
    }
    else {
        fremarks = "零食";
    }
    if (count == undefined) {
        $.get("/globe/", { action: 30, rd: Math.random(), fid: fid, fremarks: fremarks }, function() { })
    }
    else {
        $.get("/globe/", { action: 30, rd: Math.random(), fid: fid, count: count, fremarks: fremarks }, function() { })
    }
    document.location.href = "/product/GroupCar.aspx";
}
//注册,登陆切换
Lucee.UserLoginOrRegister = function(flag) {
    if (flag == "userlogin") {
        Lucee.PopWindowClose();
        Lucee.PopWindow("userlogin");
    }
    else if (flag == "userreg") {
        Lucee.PopWindowClose();
        Lucee.PopWindow("userreg");
    }
    else if (flag == "reg") {
        Lucee.PopWindowClose();
        Lucee.PopWindow("reg");
    }
    else if (flag = "collect") {
        Lucee.PopWindowClose();
        Lucee.PopWindow("collect");
    }
    else {
        Lucee.PopWindowClose();
        Lucee.PopWindow("userreg");
    }
}

//用户注册
Lucee.UserRegister = function(fid) {
    var email = $("#tb_email").val();
    var nickname = $("#tb_nickname").val();
    var password = $("#tb_password").val();
    var repassword = $("#tb_repassword").val();
    var areaName = $("#tk_areaname").val();
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if (!myreg.test(email)) {
        alert('提示:\n请输入有效的E_mail！');
        return;
    }
    if (nickname.length < 1 || nickname.length > 12) {
        alert('提示:\n昵称长度为1-12个字符！');
        return;
    }
    if (password != repassword) {
        alert('提示:\n两次密码输入不一致,请重新输入！');
        return;
    }
    if (password.length < 6 || password.length > 16) {
        alert('提示:\n密码长度应该为6-16个字符！');
        return;
    }
    $.post("/globe/", { action: 5, rd: Math.random(), email: email, nickname: nickname, password: password, repassword: repassword, areaName: areaName }, function(res) {
        switch (res) {
            case "0":
                alert('提示:\nEmail格式不正确！');
                break;
            case "2":
                alert('提示:\nEmail格式不正确！');
                break;
            case "3":
                alert('提示:\n密码长度不正确！');
                break;
            case "4":
                alert('提示:\n昵称长度不正确！');
                break;
            case "5":
                alert('提示:\nEmail已存在,请换个Email试试！');
                break;
            case "11":
                alert('提示:\n您今天已经注册过账号了，请明天再试！');
                break;
        }
        if (res.length > 2) {
            var json = res.split('|');
            Lucee.PopWindowClose();
            $("#t_login_div").html("<span>您好:<a href=\"#nogo\">" + json[0] + "</a></span>");


            var html = "";
            if (document.getElementById("comentlist_submit") != undefined) {
                html += "<div class=\"hrow_l\">";
                html += "用户：";
                html += "</div>";
                html += "<div class=\"hrow_r\">";
                html += json[0];
                html += "</div>";
                $("#comentlist_submit").html(html);
            }
            
            
            if (parseInt(fid) > 0) {//打开收藏对话框
                Lucee.PopWindow("collect", fid);
            }
        }
    })
}

//增加标签
Lucee.AddTagList = function() {
    $.get("/globe/", { action: 4, rd: Math.random(), tag: encodeURIComponent($("#user_tagList").val()), fid: $("#product_fid").val() }, function(res) {
        res = parseInt(res);
        switch (res) {
            case 1:
                Lucee.PopWindowClose();
                break;
            case 0:
                alert("标签不能为空");
                break;
            case 2:
                alert("每个标签长度不超过8个字符");
                break;
            case 3:
                alert("不能超过三个标签");
                break;
            case 4:
                alert("每个标签都不能为空");
                break;
        }
    })
}
//将长用标签放入文本框
Lucee.AddTagToText = function(obj) {
    var tag = $("#user_tagList").val();
    tag = $(obj).html() + tag.Trim() + " ";
    $("#user_tagList").val(tag);
}


Lucee.Get_Total_Freight = function(areaId, weight, allmoney, fintegral_All) {
    var ErroHtml = "";
    areaId = parseInt(areaId);
    weight = parseFloat(weight);
    allmoney = parseFloat(allmoney);
    var money = 0;
    var fparentid = $("#selectCity_title").attr("value");

    if (areaId == 999) {
        fparentid = 500400;
    }

    if (fparentid == 500400) {
        $("#PAY_DELIVERY").show();
        if (allmoney >= 38) {
            money = 0;
            ErroHtml = "校园满38元免运费!";
        }
        else {
            money = 2;
            ErroHtml = "校园满38元免运费, 未满38元:2元每单!";
        }
    }
    else if (areaId == 500103 || areaId == 500104 || areaId == 500105 || areaId == 500106 || areaId == 500107 || areaId == 500108 || areaId == 500112 || areaId == 500113 || areaId == 500109) {
        $("#PAY_DELIVERY").hide();
        var payTypeListControl_m = $("#fpaytype .skinSelectradio");
        payTypeListControl_m.each(function() {
            $(this).click(function() {
                payTypeListControl_m.each(function() {
                    $(this).attr("class", "skinSelectradio");
                })
                $(this).attr("class", "skinSelectradio ho");

            })
        });
        if (allmoney >= 68) {
            if (weight <= 1) {
                money = 0;
            }
            else {
                if (weight.toString().indexOf(".") == -1) {
                    money = weight - 1;
                }
                else {
                    var tp = parseFloat(weight.toString().substring(0, weight.toString().indexOf(".")));
                    money = tp;
                }
            }
            ErroHtml = "重庆主城8区(九龙坡区,江北区,渝中区,巴南区,大渡口区,沙坪坝区,渝北区,南岸区)满68元/1kg内免运费,续重1元/kg";
        }
        else {

            if (weight <= 1) {
                money = 5;
            }
            else {
                if (weight.toString().indexOf(".") == -1) {
                    money = 5 + weight - 1;
                }
                else {
                    var tp = parseFloat(weight.toString().substring(0, weight.toString().indexOf(".")));
                    money = 5 + tp;
                }
            }
            ErroHtml = "重庆主城8区(九龙坡区,江北区,渝中区,巴南区,大渡口区,沙坪坝区,渝北区,南岸区)未满68元,1kg内,5元每单,续重1元/kg";
        }
    }
    else {
        $("#PAY_DELIVERY").hide();
        if (allmoney >= 88) {
            if (weight <= 1) {
                money = 0;
            }
            else {
                if (weight.toString().indexOf(".") == -1) {
                    money = (weight - 1) * 2;
                }
                else {
                    var tp = parseFloat(weight.toString().substring(0, weight.toString().indexOf(".")));
                    money = tp * 2;
                }
            }
            ErroHtml = "重庆主城8区以外地(不含新疆,西藏,东北,内蒙古,甘肃)满88元/1kg内免运费,续重2元/kg";
        }
        else {
            if (weight <= 1) {
                money = 6;
            }
            else {
                if (weight.toString().indexOf(".") == -1) {
                    money = 6 + (weight - 1) * 2;
                }
                else {
                    var tp = parseFloat(weight.toString().substring(0, weight.toString().indexOf(".")));
                    money = 6 + tp * 2;
                }
            }
        }
        ErroHtml = "重庆主城8区以外地区,外地(不含新疆,西藏,东北,内蒙古,甘肃)未满88元,1kg内6元每单,续重2元/kg";
    }


    var t1 = "2011-10-3 00:00";
    var t2 = "2011-10-4 00:00";
    var t3 = date2str(new Date());
    if (comptime(t1, t3) == 1 && comptime(t2, t3) == -1) {
        if (fparentid == 500400) {
            $("#PAY_DELIVERY").show();
            if (allmoney >= 28) {
                money = 0;
                ErroHtml = "10月3日活动,大学城地区满28免运费!";
            }
            else {
                money = 2;
                ErroHtml = "校园满38元免运费, 未满38元:2元每单!";
            }
        }
    }





    $("#ErroHtml").html(ErroHtml);
    return money;
}


function date2str(d) {
    var ret = d.getFullYear() + "-"
    ret += ("00" + (d.getMonth() + 1)).slice(-2) + "-"
    ret += ("00" + d.getDate()).slice(-2) + " "
    ret += ("00" + d.getHours()).slice(-2) + ":"
    ret += ("00" + d.getMinutes()).slice(-2) + ":"
    ret += ("00" + d.getSeconds()).slice(-2)
    return ret;
}

function comptime(beginTime, endTime) {

    var beginTimes = beginTime.substring(0, 10).split('-');
    var endTimes = endTime.substring(0, 10).split('-');
    beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0] + ' ' + beginTime.substring(10, 19);
    endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19);
    var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000;

    if (a < 0) {
        return -1;
    } else if (a > 0) {
        return 1;
    } else if (a == 0) {
        return 0;
    } else {
        return 'exception'
    }
}


/*返回url地址*/
Lucee.UrlRepeater = function(ftype) {
    switch (ftype) {
        case "10001,10435":
            return "flowers";
        case "10001,10436":
            return "cake";
    }
    return "product";
}

  
  
/*用户上传*/
Lucee.UploadFile = function(arrlist) {
    var flashvars = {
        uploadPage: "http://images.23544.com/Upload.axd?action=0",
        action: arrlist.ACTION,
        controlId: arrlist.CONTROID,
        uid: arrlist.ISUSER,
        isCutDown: arrlist.ISCUTDOWN,
        imgurl: arrlist.IMGURL,
        isMultiString: arrlist.ISMULTISTRING,
        folder: arrlist.FOLDER,
        isMulti: arrlist.ISMULTI,
        time: Lucee.GetLX_Time_string()
    };
    swfobject.embedSWF(arrlist.SWF, arrlist.DOCUMENTID, "300", "300", "10.0.0.0", null, flashvars); //不动
    $("#" + arrlist.DOCUMENTID+"_box").css("width", arrlist.WIDTH + "px");
    $("#" + arrlist.DOCUMENTID + "_box").css("height", arrlist.HEIGHT + "px");
}

function completeFile(fileName, controlId, folder) {
    var path = Lucee.GetLX_Time();
    var pathUrl = "/uploadfiles"+ folder + parseInt(path[0]) + "/" + parseInt(path[1]) + "/" + parseInt(path[2]) + "/" + fileName;
    CallBackImgurlPath(pathUrl, controlId);
}
Lucee.GetLX_Time = function() {
    var timelist = new Date();
    var time = timelist.toLocaleDateString();
    time = time.replace("年", "-").replace("月", "-").replace("日", "");
    var str = time;
    str = str.replace(str.replace(/[^\u4e00-\u9fa5]/gi, ""), "").replace(" ", "");
    var time = str.split("-");
    return time;
};
Lucee.GetLX_Time_string = function() {
    var timelist = new Date();
    var time = timelist.toLocaleDateString();
    time = time.replace("年", "-").replace("月", "-").replace("日", "");
    var str = time;
    str = str.replace(str.replace(/[^\u4e00-\u9fa5]/gi, ""), "").replace(" ", "");
    return str;
};
