﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
var LoadArea = false; //是否需要加载area.xml文档，默认不需要的，针对编辑页面，需要，可以使用#Province,#City,#Region三个下拉框用于填充和选择#RegionID隐藏表单，用于存储最终的区ID
var xmlData = null;
function getQueryString(key) { var value = ""; var sURL = window.document.URL; if (sURL.indexOf("?") > 0) { var arrayParams = sURL.split("?"); var arrayURLParams = arrayParams[1].split("&"); for (var i = 0; i < arrayURLParams.length; i++) { var sParam = arrayURLParams[i].split("="); if ((sParam[0] == key) && (sParam[1] != "")) { value = sParam[1]; break; } } } return value; }
var DeliveryList = null;
var cityID = 0; //发货城市
var totolFel = 0; //总费用
var CanDistribution = 0;
var oldFullAddressValue="";

function killErrors() {
    return true;
}
window.onerror = killErrors;
jQuery(document).ready(function() {
    if (LoadArea) {
        var PKID = parseInt(jQuery("#PKID option:selected").val());
        LoadSelect(PKID);
        $("#PKID").change(function() {
            LoadSelect(parseInt($("#PKID option:selected").val()));
        });
        $("#RegionID").ProCityRegion({ callback: function() {
            // GetUserAreaList($("#CityID").val());
        }
        });
    }
    if (window.document.URL.split("?")[0].indexOf("ticket_") >= 0) {
        $("#tellf").addthis();
        $(document).bind("contextmenu", function() { return false; });
        $(document).bind("selectstart", function() { return false; });
        $(document).bind("mousedown", function() { return false; });
    }
    $("#FullAddress").focus(function() { oldFullAddressValue = $(this).val(); }).blur(IsNeedGetCanDistribution);
});

function IsNeedGetCanDistribution() {
    if ($(this).val() != oldFullAddressValue) {
        GetCanDistribution();
    }
}

function LoadSelect(PKID) {
    if (PKID == 0) {
        $("#UserName").val("");
        $("#GenderM").attr("checked", true);
        $("#UserEmail").val("");
        $("#PostalCode").val("");
        $("#FullAddress").val("");
        $("#tele").val("");
        $("#phone").val("");
        $("#ProvinceID").val("");
        $("#Province").val("");
        $("#CityID").val("");
        $("#City").val("");
        $("#RegionID").val("");
        $("#Region").val("");
        $("#AreaResult").val("");
        $("#showmoney").html(parseFloat(totolFel));
        $("#EmsPrice").css("display", "none");
        $("#get_area option[value!='-1']").remove();
        return; 
    }    
    var item = eval(DeliveryList);
    for (var i = 0; i < item.length - 1; i++) {
        if (item[i].PKID == PKID) {
            $("#UserName").val(item[i].UserName);
            if (item[i].Sex) {
                $("#GenderM").attr("checked", "checked");
            }
            else {
                $("#GenderW").attr("checked", "checked");
            }
            $("#UserEmail").val(item[i].UserEmail);
            $("#PostalCode").val(item[i].PostalCode);
            $("#FullAddress").val(item[i].FullAddress);
            $("#tele").val(item[i].tele);
            $("#phone").val(item[i].phone);
            $("#ProvinceID").val(item[i].ProvinceID);
            $("#Province").val(item[i].Province);
            $("#CityID").val(item[i].CityID);
            $("#City").val(item[i].City);
            $("#RegionID").val(item[i].RegionID);
            $("#Region").val(item[i].Region);
            $("#AreaResult").val(item[i].Province + "-" + item[i].City + "-" + item[i].Region);
            GetDeliveryPrice($("#ProvinceID").val(), $("#CityID").val(), $("#CleanMoney").val(), $("#TotalQ").val());
            //GetUserAreaList($("#CityID").val());
        }
    }
    GetCanDistribution();
}
function GetUserAreaList(userCityID) {
    $("#showmoney").html(parseFloat(totolFel));
    $("#EmsPrice").css("display", "none");
    $("#EmsPrice #tPirce").html("0");
    $("#ShowAreaDescribing").html("请正确选择您所属的区域");
    $("#get_area option[value!='-1']").remove();
    if (userCityID == undefined) {return;}
    //开始计算是同城还是异地
    var areaType = 1;
    if (cityID != userCityID) { areaType = 2; }
    $.ajax({
        type: "get",
        url: "/AjaxUserArea.aspx?t=1&cityID=" + cityID + "&areaType=" + areaType,
        dataType: "json",
        cache: false,
        success: function(json) {
            if (json != undefined) {
                //输出option列表
                $.each(json, function(i, n) {
                    $("<option value=\"" + n.PKID + "\">" + n.AreaName + "</option>").appendTo("#get_area");
                });
            }
        }
    });
}
//省市区处理插件，用弹出层的效果来简化操作
//Writer:杨含斌
//2009-6-22 11:00:40
var xmlDoc = null;
(function($) {
    $.fn.ProCityRegion = function(options) {
        var o = $.extend({
            url: "/View/Scripts/Area.xml", //js 文件位置
            vname: "#AreaResult", //存储结果，样式： 省-市-区
            pro: "#ProvinceID", //存储省ID
            pname: "#Province", //存储省名称
            city: "#CityID", //存储城市ID
            cname: "#City", //存储城市名称
            rname: "#Region", //存储区域名称，用调用的那项来作区域ID
            bold: [851, 892, 871], //需要加粗的省
            callback: function() { }
        }, options);
        var _self = this;
        $.get(o.url, function(result) {
            xmlDoc = result;
        });
        $(o.vname).css("cursor", "pointer").attr("readonly", true).live("click", function() {
            //创建透明遮罩的iframe层
            $("<iframe/>").attr("id", "LyAreaBgLayer").appendTo("body");
            $("<div/>").attr("id", "LyAreaContentLayer").appendTo("body");
            $("#LyAreaBgLayer,#LyAreaContentLayer").css({ width: $(document).width(), height: $(document).height() }).show();
            $("<div/>").attr("id", "LyAreaResult").appendTo("body");
            $("#LyAreaResult").css({ left: ($(document).width() - 500) / 2, top: ($(document).scrollTop() + 100) }).show();
            $("<div class=\"layer\"><h1><img class=\"fR\" src=\"/View/images/closeAreaLayer.gif\" alt=\"关闭\"><p></p><b>请选择地区</b></h1><div class=\"inner\"></div></div>").appendTo("#LyAreaResult");
            $("<dl><dt>请选择省：</dt><dd id=\"ProvinceArea\"></dd><dt>请选择市：</dt><dd id=\"CityArea\"></dd><dt>请选择区域：</dt><dd id=\"RegionArea\"></dd></dl>").appendTo("#LyAreaResult .inner");
            $(xmlDoc).find("Province").each(function() {
                $("<span v=\"" + $(this).attr("id") + "\">" + $(this).attr("name") + "</span>").click(function() {
                    $(this).addClass("on");
                    $(this).siblings().removeClass("on");
                    var v = $(this).attr("v");
                    $(o.pro).val(v);
                    $(o.pname).val($(this).text());
                    $("#LyAreaResult #CityArea,#LyAreaResult #RegionArea").empty();
                    $(xmlDoc).find("Province[id='" + v + "']>City").each(function() {
                        $("<span v=\"" + $(this).attr("id") + "\">" + $(this).attr("name") + "</span>").click(function() {
                            $(this).addClass("on");
                            $(this).siblings().removeClass("on");
                            var v = $(this).attr("v");
                            $(o.city).val(v);
                            $(o.cname).val($(this).text());
                            $("#LyAreaResult #RegionArea").empty();
                            $(xmlDoc).find("Province>City[id='" + v + "']>Region").each(function() {
                                $("<span v=\"" + $(this).attr("id") + "\">" + $(this).attr("name") + "</span>").click(function() {
                                    $(this).addClass("on");
                                    $(this).siblings().removeClass("on");
                                    var v = $(this).attr("v");
                                    $(_self).val(v);
                                    $(o.rname).val($(this).text());
                                    $(o.vname).val($("#LyAreaResult #ProvinceArea .on").text() + "-" + $("#LyAreaResult #CityArea .on").text() + "-" + $("#LyAreaResult #RegionArea .on").text());
                                    $("#LyAreaBgLayer,#LyAreaContentLayer,#LyAreaResult").remove();
                                    GetDeliveryPrice($("#ProvinceID").val(), $("#CityID").val(), $("#CleanMoney").val(), $("#TotalQ").val());
                                    GetCanDistribution();
                                    if (typeof (o.callback) == "function") { o.callback(); }
                                }).appendTo("#LyAreaResult #RegionArea");
                            });
                        }).appendTo("#LyAreaResult #CityArea");
                    });

                }).appendTo("#LyAreaResult #ProvinceArea");
            });
            $.each(o.bold, function(i, n) {
                $("#ProvinceArea span[v='" + n + "']").addClass("b");
            });
            $("#LyAreaResult .layer h1 img").live("click", function() {
                $("#LyAreaBgLayer,#LyAreaContentLayer,#LyAreaResult").remove();
            });
        });
        return _self;
    };
})(jQuery);
function ChangeArea() {
    var RegionID = $("RegionID").val();
    if (RegionID > 0) {
        var s = $(xmlDoc).find("Province>City>Region[id='" + RegionID + "']");
        if (jQuery(s).parent("City").parent("Province").attr("name") != undefined && jQuery(s).parent("City").attr("name") != undefined) {
            $(o.vname).val(jQuery(s).parent("City").parent("Province").attr("name") + "-" + jQuery(s).parent("City").attr("name") + "-" + jQuery(s).attr("name"));
        }
    }
}
//用户选择区域后重新计算费用
//Writer:杨含斌
//2009-7-9 12:05:23
function ModifyArea(qy, totalm) {
    $("#showmoney").html(parseFloat(totalm));
    var getsend = jQuery("input[name='get_send'][type=radio]:checked").val();
    if (qy > 0) {
        if (getsend == "4") {
            $("#EmsPrice").css("display", "none");
            $("#EmsPrice #tPirce").html("0");
            $("#showmoney").html(parseFloat(totalm));
        }
        else {
            //ajax计算费用
            $.ajax({
                type: "get",
                url: "AjaxGetDeliveryPrice.aspx?sendToProvinceid=2313&sendToCityID=2404&price=300&nums=5",
                dataType: "json",
                cache: false,
                success: function(json) {
                    if (json.length > 0) {
                        if (json[0].Gathering > 0) { $("input[name='get_pay']:eq(2)").attr({ disabled: false }); } else { $("input[name='get_pay']:eq(2)").attr({ checked: false, disabled: true }); }
                        if (json[0].fee > 0) {
                            $("#EmsPrice #emsName").html(json[0].name + "配送费用");
                            $("#EmsPrice #sPrice").html(parseInt(json[0].fee));
                            $("#EmsPrice #sNum").html(1);
                            $("#EmsPrice #tPirce").html(parseInt(json[0].fee));
                            $("#EmsPrice").css("display", "");
                            $("#showmoney").html(parseFloat(totalm) + parseInt(json[0].fee));
                        }
                        else {
                            $("#EmsPrice").css("display", "none");
                            $("#EmsPrice #tPirce").html("0");
                            $("#showmoney").html(parseFloat(totalm));
                        }
                        $("#ShowAreaDescribing").html("<b>备注：</b>" + json[0].Describing);
                    }
                }
            });
        }
    }
    else {
        $("#EmsPrice").css("display", "none");
        $("#EmsPrice #tPirce").html("0");
        $("#showmoney").html(parseFloat(totalm));
        $("#ShowAreaDescribing").html("请正确选择您所属的区域");
    }
}

function GetDeliveryPrice(toproid, tocityid, price, nums) {
    $("#showmoney").html(parseFloat(price));
    var getsend = jQuery("input[name='get_send'][type=radio]:checked").val();

        if (getsend == "4") {
            $("#EmsPrice").css("display", "none");
            $("#EmsPrice #tPirce").html("0");
            $("#showmoney").html(parseFloat(price));
        }
        else {
            //ajax计算费用
            $.ajax({
                type: "get",
                url: "AjaxGetDeliveryPrice.aspx?sendToProvinceid=" + toproid + "&sendToCityID=" + tocityid + "&price=" + price + "&nums=" + nums,
                dataType: "json",
                cache: false,
                success: function(json) {
                if (json.length > 0) {
                    if (json[0].deliverprice > 0) {
                            $("#EmsPrice #emsName").html("配送费用" + (json[0].pricedes==''?'':(':' +json[0].pricedes)));
                            $("#EmsPrice #sPrice").html(parseFloat(json[0].deliverprice));
                            $("#EmsPrice #sNum").html(1);
                            $("#EmsPrice #tPirce").html(parseFloat(json[0].deliverprice));
                            $("#EmsPrice").css("display", "");
                            $("#showmoney").html(parseFloat(price) + parseFloat(json[0].deliverprice));
                        }
                        else {
                            $("#EmsPrice").css("display", "none");
                            $("#EmsPrice #tPirce").html("0");
                            $("#showmoney").html(parseFloat(price));
                        }
                        $("#ShowAreaDescribing").html("<b>备注：</b>" + json[0].pricedes);
                    }
                }
            });
        }
}

function CheckSaveUserAddress() {
    var name = $.trim(jQuery("#UserName").val());
    if (name == '') {
        alert("收件人姓名不能为空");
        $("#UserName").focus();
        return false;
    }
    if (!/^[\u4e00-\u9fa5]{2,5}$/i.test(name)) {
        alert("收件人姓名只能为中文，长度必须在2~5之间");
        $('#UserName').focus();
        return false;
    }
    if ($.trim($("#RegionID").val()) == "") {
        alert("请选择省市县\n\n提示：如果点击地区弹出层无选项，请尝试刷新后操作！");
        return false;
    }
    var zipcode = $.trim($("#PostalCode").val());
    if (zipcode == "") {
        alert("邮政编码不能为空");
        $("#PostalCode").focus();
        return false;
    }
    if (!/^\d{6}$/i.test(zipcode)) {
        alert('邮编格式错误');
        $("#PostalCode").focus();
        return false;
    }
    var addr = $.trim(jQuery('#FullAddress').val());
    if (addr == '') {
        alert('街道地址不能为空');
        $('#FullAddress').focus();
        return false;
    }
    if (addr.length < 4 || addr.length > 25) {
        alert('地址长度必须在4~25之间');
        $('#FullAddress').focus();
        return false;
    }
    var mobile = $.trim(jQuery('#phone').val());
    if (mobile == '') {
        alert('手机号不能为空');
        $('#phone').focus();
        return false;
    }
    if (!/^\d{11,16}$/i.test(mobile)) {
        alert("手机号格式错误\n\n如果是中国大陆以外地区，区号+号码 之间不加任何特殊符号\n\n如香港用户：00852-12345678 则输入 0085212345678 即可");
        $("#phone").focus();
        return false;
    }
    var tele = $.trim($("#tele").val());
    if (tele != "") {
        if (!/^\d{8,16}$/i.test(tele)) {
            alert("请填写正确的电话号！非大陆电话号码格式：地区码+手机号码 之间不加任何特殊符号 例如：0085261509307！");
            return false;
        }
    }
    var email = $.trim($("#UserEmail").val());
    if (email != "") {
        if (!/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(email)) {
            alert("电子邮件格式错误！");
            return false;
        }
    }
    return true;
}
function ShowAlert() {
    if (!CheckOrder()) return;
    var msg = "确认要提交订单吗？\n\n（请确保填写的信息没有错误）";
    if (!confirm(msg)) {
        return false;
    }
    if ($("input[name='get_pay']").get(0).checked) {
        //$("#msg").jQueryDialog({ closeObj: "#button2" });
        $("#msg,#overlayer").css({ "display": "block", "left": (document.body.clientWidth - parseInt($("#msg").width())) / 2 });
    }
    else {
        $("#form1").submit();
    }
}
function CheckOrder() {
    if (!CheckSaveUserAddress()) { return false; }
//    if ($("#get_area").val() == "-1") {
//        alert("请您选择您所在的区域");
//        return false;
//    }
    if ($("input[name='get_fp']").get(0).checked) {
        if ($("input[name='get_tt']:checked").size() <= 0) {
            alert("请选择发票所属是个人还是企业，个人不用填写，企业请填写企业名称！");
            return false;
        }
        if ($.trim($("input[name='get_title']").val()) == "") {
            alert("请输入发票的抬头");
            $("input[name='get_title']").focus();
            return false;
        }
    }
    if ($("input[name='get_send']:checked").size()<=0) {
        alert("请选择送票方式");
        return false;
    }
    if ($("input[name='get_pay']:checked").size() <= 0) {
        alert("请选择支付方式！");
        return false;
    }
    return true;
}
//弹出预定项目窗口
var LoginStatus = 0;//默认未登录
function ShowReservations(PID) {
     var s="";
     d = new Date();                          
     s += (d.getMonth() + 1);        
     s += d.getDate();            
     s += d.getYear();
     s += d.getHours();
     s += d.getMinutes();
     s += d.getSeconds(); 
    if (LoginStatus > 0) {
        $("#LoginFromLayer").hide();
        jQuery("#YuDingLayer").attr("src", "yuding.aspx?id=" + PID + "&sid=" + Math.random() + "&bid=" + s).css({ width: "450px", height: "490px", left: (window.parent.document.body.clientWidth - 450) / 2 }); ;
        jQuery("#YuDingLayer").jQueryDialog();
    }
    else {
        $("#LoginFromLayer").hide();
        jQuery("#YuDingLayer").attr("src", "LoginForm.aspx?id=" + PID + "&sid=" + Math.random() + "&bid=" + s).css({ width: "320px", height: "340px", frameborder: "0" });
        jQuery("#YuDingLayer").jQueryDialog();
    }
    return false;
}
function StringBuilder() { this._strings_ = new Array(); }
StringBuilder.prototype.Append = function(str) { this._strings_.push(str); }
StringBuilder.prototype.ToString = function() { return this._strings_.join(""); }
//用户登录弹出层
//Writer:杨含斌
//2009-6-16 16:12:47
//参数：callback 登录成功后的处理函数
function LoginFrom(callback) {


    
            var re = new RegExp("(1)\\d{10}\|\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+");
            var username = jQuery("#LoginFromLayer #txtUserName").val();
            if (!re.test(username)) {
                $("#errmsg").text("发生错误：系统只支持Email和手机号码作为登录账号！");
                return false;
            }
            var passwd = $.trim(jQuery("#txtPassWord").val());
            if (passwd == "") {
                $("#errmsg").text("发生错误：请填写密码！");
                return false;
            }
            var isSave = 0;
            if (jQuery("#LoginFromLayer #IsSave").attr("checked")) { isSave = 1; }
            return true;

        
  
}
(function($) {
    jQuery.fn.CheckNull = function(classname) {
        var _this = this;
        _this.each(function() {
            var v = jQuery.trim(jQuery(this).val());
            if ((v == "" || v == null) && v != undefined) {
                if (!jQuery(this).hasClass(classname)) { jQuery(this).addClass(classname).blur(function() { jQuery(this).CheckNull(classname); }); }
            }
            else {
                jQuery(this).removeClass(classname);
            }
        });
        return _this;
    };
})(jQuery);

//重写弹出层的插件
//Writer:杨含斌2009-7-22 10:51:56
(function($) {
    $.fn.jQueryDialog = function(options) {
        var o = $.extend({
            closeObj: "", //需要添加隐藏事件的jquery对象
            showMask: true, //是否显示遮罩层
            maskAlphaColor: "#000", //遮罩透明色
            maskAlpha: 40 	//遮罩透明度
        }, options);
        var _self = this;
        _self.hide();
        $.fn.jQueryDialog.ShowLayer(o);
        _self.css({ "position": "absolute", "z-index": "10002", left: ($(document).width() - _self.width()) / 2, top: ($(document).scrollTop() + 100) }).show(5)
        $(o.closeObj).die("click");
        $(o.closeObj).live("click", function() {
            $.fn.jQueryDialog.CloseLayer(_self);
        });
    }
    $.fn.jQueryDialog.ShowLayer = function(o) {
        var wsize = $(document).width();
        var hsize = $(document).height();
        var maskStyle = "";
        //创建遮罩层
        if (o.showMask) {
            maskStyle = "position:absolute;top:0;left:0;background:" + o.maskAlphaColor + ";filter:alpha(opacity=" + o.maskAlpha + ");-moz-opacity:" + o.maskAlpha / 100 + ";opacity:" + o.maskAlpha / 100 + "";
        }
        else {
            maskStyle = "position:absolute;top:0;left:0;";
        }
        //增加一个可以遮罩select下拉框的iframe
        if ($("#maskiframe").size() <= 0) { $("body").append("<iframe id=\"maskiframe\" style=\"position:absolute;top:0;left:0;z-index:9999;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;display:none;\"></iframe>"); }
        if ($("#maskLevel").size() <= 0) { $("body").append("<div id=\"maskLevel\" style=\"" + maskStyle + ";z-index:10000;display:none;\"></div>"); }
        $("#maskiframe,#maskLevel").css({ width: wsize, height: hsize });
        if ($("#maskiframe:hidden").size() > 0 && $("#maskLevel:hidden").size() > 0) { $("#maskiframe,#maskLevel").fadeIn("slow"); }
    }
    $.fn.jQueryDialog.CloseLayer = function(obj) {
        $(obj).hide();
        if ($("#maskiframe:visible").size() > 0 && $("#maskLevel:visible").size() > 0) { $("#maskiframe,#maskLevel").fadeOut("slow"); }
    };
})(jQuery);
function refundment() {
    alert("请你拨打：400-610-3721");
    return false;
}


function GetCanDistribution() {
    CanDistribution = 0;
    var tocityid = $("#CityID").val();
    var cityname = $("#City").val();
    var address = $("#FullAddress").val();
    if (address != '')
        address = $("#Province").val() + $("#City").val() + $("#Region").val() + address;
    //alert(address);
    $.ajax({
        type: "get",
        url: "AjaxGetDeliveryPrice.aspx?sendToCityID=" + tocityid + "&cityname=" + escape(cityname.replace("市", "")) + "&address=" + escape(address) + "&isGetCanDistribution=1",
        cache: false,
        success: function(result) {
            //alert(result);
            if (result == "true") {
                //alert("here");
                CanDistribution = 1;
                if (jQuery("input[name='get_send']:checked").val() == "1") { jQuery("input[name='get_pay']:eq(2)").removeAttr("checked").attr("disabled", false); }
            } else
            { jQuery("input[name='get_pay']:eq(2)").removeAttr("checked").attr("disabled", true); }
        }
    });
}

