(function($)
{
    $.fn.extend({
        /*
        **  选择地区（级联）
        **  $(".HoverShowContainerBtn").HoverShowContainer({ ShowContainer: "div" });
        */

        "SelectRegion": function(options)
        {
            options = $.extend({
                ShowBox: "ShowBox", //输出盒子
                UrlID: "UrlID", //参数名
                GetUrl: "GetUrl", //发送url
                HiddenVal: "#HiddenVal"  //返回值
            }, options);
            return this.live("change", function()
            {
                var Val = $(this).val();
                var html = "";
                var Empty = "";
                var $this = $(this);
                var AllBox = $(this).nextAll(options.ShowBox);
                AllBox.remove();
                $("<select class=\"SelectRegion UIDropDown\"><option value=\"NULL\" selected=\"selected\">请选择</option></select>").insertAfter(this);
                var Box = $(this).next(options.ShowBox);

                $.ajax({
                    type: "GET",
                    url: options.GetUrl,
                    data: options.UrlID + "=" + Val,
                    dataType: "xml",
                    async: false, //同步执行，执行完毕，才会执行其他函数
                    cache: false,
                    beforeSend: function(XMLHttpRequest)
                    {
                        Box.html("<option value=\"请选择\">请选择</option>");
                    },
                    success: function(data)
                    {
                        //alert("11");
                        $(data).find("IsEmpty").each(function()
                        {//找到根节点
                            Empty = $(this).children("Empty").text();
                            //节点名称
                        });
                        if (Empty == "Empty" && Val != "请选择")
                        {
                            $this.next().remove();
                            $(options.HiddenVal).val(Val);
                            //alert(Val);
                        } else
                        {

                            $(data).find("Category").each(function()
                            {//找到根节点
                                Box.append("<option value=\"" + $(this).children("GUID").text() + "\">" + $(this).children("Name").text() + "</option>");
                            });
                        }
                        //alert($(options.HiddenVal).val());
                    },
                    complete: function(XMLHttpRequest, textStatus)
                    {
                        //HideLoading();
                    },
                    error: function()
                    {
                        //请求出错处理
                    }
                });
            });
        },
        /*
        **  悬停出现（指定ID）
        **  $(".HoverShowIDBtn").HoverShowID({ ShowID: ".HoverShowID" });
        */

        "HoverShowID": function(options)
        {
            options = $.extend({
                ShowID: ".ShowID"   //指定id名称
            }, options);
            return this.hover(function()
            {
                $(options.ShowID).show();
            }, function()
            {
                $(options.ShowID).hide();
            });
        },
        /*
        **  选择分类
        **  $(".HoverShowContainerBtn").HoverShowContainer({ ShowContainer: "div" });
        */
        "SelectCategory": function(options)
        {
            options = $.extend({
                HoverCss: "HoverCss", //当前选中的classname
                ShowBox: "ShowBox", //输出盒子
                UrlID: "UrlID", //参数名
                GetUrl: "GetUrl", //发送url
                HiddenVal: "#HiddenVal", //返回值
                Btn: "#Btn"  //发布按钮
            }, options);
            $(options.Btn).hide();
            return this.live("click", function()
            {
                var Val = $(this).attr("GUID");
                var html = "";
                var Empty = "";
                var Publish = "";
                $(this).addClass(options.HoverCss);
                $(this).siblings().removeClass(options.HoverCss);
                var Box = $(this).parent().next(options.ShowBox);
                //alert("11");
                $.ajax({
                    type: "GET",
                    url: options.GetUrl,
                    data: options.UrlID + "=" + Val,
                    dataType: "xml",
                    async: false, //同步执行，执行完毕，才会执行其他函数
                    cache: false,
                    beforeSend: function(XMLHttpRequest)
                    {
                        Box.html("");
                    },
                    success: function(data)
                    {
                        //alert("11");
                        $(data).find("Properties").each(function()
                        {//找到根节点
                            Empty = $(this).children("IsEmpty").text();
                            Publish = $(this).children("Publish").text();
                            //节点名称
                        });
                        if (Empty == "True" && Publish == "True")
                        {
                            $(options.HiddenVal).val(Val);
                            //alert($(options.HiddenVal).val());
                            $(options.Btn).show();
                            //alert(Val);
                        } else if (Empty == "False" && Publish == "True")
                        {
                            $(options.HiddenVal).val(Val);
                            //alert($(options.HiddenVal).val());
                            $(options.Btn).show();
                        } else
                        {
                            $(data).find("Category").each(function()
                            {//找到根节点
                                html += "<li GUID=\"" + $(this).children("GUID").text() + "\">" + $(this).children("Name").text() + "</li>";
                                //节点名称
                            });
                            Box.html(html);
                            $(options.Btn).hide();
                        }
                        //alert($(options.HiddenVal).val());
                    },
                    complete: function(XMLHttpRequest, textStatus)
                    {
                        //HideLoading();
                    },
                    error: function()
                    {
                        //请求出错处理
                    }
                });
            });
        },
        /*
        **  放大镜
        **  $(".ProdTopPicBig").Zoom({ ZoomFingerBox: ".ZoomFingerBox", ZoomShowBox: ".ZoomBox", ZoomBigImg: ".ZoomBox img" });
        */

        "Zoom": function(options)
        {
            options = $.extend({
                ZoomFingerBox: ".ZoomFingerBox", //放大镜
                ZoomShowBox: ".ZoomBox", //放大的容器
                ZoomBigImg: ".ZoomBox img"          //放大后的图片
            }, options);

            var $pre = $(options.ZoomShowBox);
            var $preimg = $(options.ZoomBigImg);
            var p_w = parseInt($preimg.css("width"), 10);
            //这里不能使用 $preimg.width(). width()方法对隐藏元素无效
            var p_h = parseInt($preimg.css("height"), 10);
            return this.bind("mouseenter", function(e)
            {
                var $this = $(this);
                var $zoom = $this.find(options.ZoomFingerBox);
                $zoom.show();
                $pre.show();
                PositionPopupZoom($this, $zoom, e.pageX, e.pageY, p_w, p_h, $preimg);
                $this.bind("mousemove", function(e)
                {
                    setTimeout(function()
                    {
                        PositionPopupZoom($this, $zoom, e.pageX, e.pageY, p_w, p_h, $preimg);
                    }, 10);
                });
            }).bind("mouseleave", function()
            {
                var $this = $(this);
                var $zoom = $this.find(options.ZoomFingerBox);
                $zoom.hide();
                $pre.hide();
                $this.unbind("mousemove");
            });
        },
        /*
        **  图片展廊
        **  $(".ProdTopPicSmall").PicGallery({ TurnLeft: ".PicTurnLeft", TurnRight: ".PicTurnRight", PicSmallBox: ".PicSmallBox", BigPic: ".ProdTopPicBig img" });
        */

        "PicGallery": function(options)
        {
            options = $.extend({
                TurnLeft: ".PicTurnLeft", //向右移动按钮
                TurnRight: ".PicTurnRight", //向左移动按钮
                PicSmallBox: ".PicSmallBox", //小图列表容器
                BigPic: ".ProdTopPicBig img"              //大图
            }, options);
            return this.bind("mouseenter", function()
            {
                var ListLength = $(options.PicSmallBox).children().length;
                var $TurnLeft = $(options.TurnLeft);
                var $TurnRight = $(options.TurnRight);
                var $ImageList = $(options.PicSmallBox);
                var $BigPic = $(options.BigPic);
                if (ListLength > 3)
                {//判断子类个数，如果大于3（一行中最多的显示个数）则绑定两个控制按钮
                    $TurnLeft.bind("click", function()
                    {
                        $ImageList.children().last().insertBefore($ImageList.children().first());
                        if ($ImageList.children().eq(3).hasClass("AddBorder"))
                        {
                            $ImageList.children().eq(2).addClass("AddBorder").siblings().removeClass("AddBorder");
                            $BigPic.attr("src", $ImageList.children().eq(2).children().attr("src"));
                        }
                    });
                    $TurnRight.bind("click", function()
                    {
                        $ImageList.children().first().insertAfter($ImageList.children().last());
                        if ($ImageList.children().last().hasClass("AddBorder"))
                        {
                            $ImageList.children().first().addClass("AddBorder").siblings().removeClass("AddBorder");
                            $BigPic.attr("src", $ImageList.children().first().children().attr("src"));
                        }
                    });
                }
                $ImageList.children().bind("click", function()
                {
                    var SmallImg = $(this).children().attr("src");
                    $(this).addClass("AddBorder").siblings().removeClass("AddBorder");
                    $BigPic.attr("src", SmallImg);
                });
            }).bind("mouseleave", function()
            {
                var ListLength = $(options.PicSmallBox).children().length;
                if (ListLength > 3)
                {
                    var $TurnLeft = $(options.TurnLeft);
                    var $TurnRight = $(options.TurnRight);
                    $TurnLeft.unbind("click");
                    $TurnRight.unbind("click");
                }
            });
        }
    });

    /*
    wrap : 当前绑定的元素
    zoom : 当前绑定的元素里的popupzoom元素
    x, y : 当前鼠标在页面上的位置
    w, h : 放大的图片的高度和宽度,用来计算比例
    */
    var zoompos = {
        x: 0,
        y: 0
    };
    //定义一个对象，缓存x,y变量.
    function PositionPopupZoom(wrap, zoom, x, y, w, h, id)
    {
        var wrapLeft = wrap.offset().left;
        var wrapTop = wrap.offset().top;
        var zoomWidth = zoom.width();
        var zoomHeight = zoom.height();
        var wrapWidth = wrap.width();
        var wrapHeight = wrap.height();
        //计算半透明层的x,y.确定它不超出图片
        zoompos.x = x - wrapLeft - (zoomWidth / 2);
        zoompos.y = y - wrapTop - (zoomHeight / 2);
        if (zoompos.x <= 0)
        {
            zoompos.x = 0;
        }
        if (zoompos.y <= 0)
        {
            zoompos.y = 0;
        }
        if (zoompos.x + zoomWidth >= wrapWidth)
        {
            zoompos.x = wrapWidth - zoomWidth;
        }
        if (zoompos.y + zoomHeight >= wrapHeight)
        {
            zoompos.y = wrapHeight - zoomHeight;
        }
        //放大比例
        var xRatio = w / wrapWidth;
        var yRatio = h / wrapHeight;
        //设置位置
        zoom.css({
            left: zoompos.x,
            top: zoompos.y
        });
        id.css({
            left: -(zoompos.x * parseInt(xRatio, 10)),
            top: -(zoompos.y * parseInt(yRatio, 10))
        });
    }

    /*
    **  显示分类
    **  $(".HaveList").ShowCategory({ ShowBoxId: ".ShowBoxId" });
    */
    $.fn.ShowCategory = function(options)
    {
        var defaults = {
            ShowBoxId: "ShowBoxId"          //显示的盒子
        }
        var options = $.extend(defaults, options);

        return this.hover(function()
        {
            $(this).css("z-index", "9");
            $(this).children(options.ShowBoxId).stop(true, true).show("fast");
        }, function()
        {
            $(this).css("z-index", "1");
            $(this).children(options.ShowBoxId).stop(true, true).hide("fast");
        });
    };
    /*
    **  显示地区
    **  $(".HaveList").ShowRegion({ ShowBox: ".ShowBox", GetUrl: ".ShowBox", LocationUrl: "LocationUrl", UrlID: "UrlID" });
    */
    $.fn.ShowRegion = function(options)
    {
        var defaults = {
            ShowBox: "ShowBox", //显示的盒子
            GetUrl: "GetUrl", //发送请求的链接
            LocationUrl: "LocationUrl", //专向地址
            UrlID: "UrlID" //参数名
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oThis = $(this);
            var oShowBox = $(options.ShowBox);
            var RegionValue = oThis.attr("GUID");
            oThis.bind("click", function()
            {

                $.ajax({
                    type: "GET",
                    url: options.GetUrl,
                    data: options.UrlID + "=" + RegionValue,
                    dataType: "xml",
                    async: false, //同步执行，执行完毕，才会执行其他函数
                    cache: false,
                    beforeSend: function(XMLHttpRequest)
                    {
                        oShowBox.html("");
                    },
                    success: function(data)
                    {
                        //alert("11");
                        $(data).find("Properties").each(function()
                        {//找到根节点
                            Empty = $(this).children("IsEmpty").text();
                            //节点名称
                        });
                        if (Empty == "True")
                        {
                            top.location.href = options.LocationUrl + RegionValue;
                            //alert(Val);
                        } else
                        {
                            $(data).find("Region").each(function()
                            {//找到根节点
                                oShowBox.append("<li GUID=\"" + $(this).children("GUID").text() + "\">" + $(this).children("Name").text() + "</li>");
                            });
                        }
                        //alert($(options.HiddenVal).val());
                    },
                    complete: function(XMLHttpRequest, textStatus)
                    {
                        //HideLoading();
                    },
                    error: function()
                    {
                        //请求出错处理
                    }
                });
            });
            $(document).click(function()
            {
                oShowBox.hide();
            });
        });
    };
    /*
    **  相册展示
    **   $("#UIPhotoBox").UIPhoto({ PhotoUrl: "http://www.cssghost.com/Images/Pic01.jpg" });
    */
    $.fn.UIPhoto = function(options)
    {
        var defaults = {
            TurnLeft: "#PhotoTurnLeft",
            TurnRight: "#PhotoTurnRight",
            PhotoGroup: "#PhotoGroup",
            PhotoGroupWidth: 920,
            Speed: 100,
            PhotoShow: "#PhotoShow",
            PhotoInfo: "#PhotoInfo",
            PhotoUrl: ""

        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oBtnL = $(options.TurnLeft);
            var oBtnR = $(options.TurnRight);
            var oPhotoGroup = $(options.PhotoGroup);
            var oPhotoShow = $(options.PhotoShow);
            var oPhotoInfo = $(options.PhotoInfo);
            var nWidth = options.PhotoGroupWidth;
            var nSpeed = options.Speed;
            var sPhotoUrl = options.PhotoUrl;
            var nTimes = $("li", oPhotoGroup).length - 1;
            var nTime = 0;
            var ListImg = $("img", oPhotoGroup);
            $("ul", oPhotoGroup).css("width", $("li", oPhotoGroup).length * nWidth);
            //alert(nTime);
            //alert($("li",oPhotoGroup).length);
            oBtnL.bind("click", function()
            {
                animate("Prev");
            });
            oBtnR.bind("click", function()
            {
                animate("Next");
            });
            ListImg.bind("click", function()
            {
                var oThis = $(this);
                var nRel = oThis.attr("rel");
                var nTitle = oThis.attr("title");
                //alert(nRel);
                ListImg.css("border", "1px solid #ccc");
                oThis.css("border", "1px solid #000");
                $("img", oPhotoShow).attr("src", nRel);
                $("li", oPhotoInfo).first().text("图片信息：" + nTitle);
            });
            function animate(Action)
            {
                var oTime = nTime;
                switch (Action)
                {
                    case "Next":
                        nTime = (oTime >= nTimes) ? nTimes : nTime + 1;
                        break;
                    case "Prev":
                        nTime = (nTime <= 0) ? 0 : nTime - 1;
                        break;
                    default:
                        break;
                }
                var nDiff = Math.abs(oTime - nTime);
                var speed = nDiff * nSpeed;

                p = (nTime * nWidth * -1);
                $("ul", oPhotoGroup).animate(
						{ marginLeft: p },
						speed
					);

                if (nTime == nTimes)
                {
                    oBtnR.hide();
                } else
                {
                    oBtnR.show();
                };
                if (nTime == 0)
                {
                    oBtnL.hide();
                } else
                {
                    oBtnL.show();
                };
            }
            if (sPhotoUrl)
            {
                $("img", oPhotoShow).attr("src", sPhotoUrl);
            }
            else
            {
                //alert("123");
                ListImg.first().click();
            }
        });
    };
    /*
    **  生成select地区
    **  $(".HaveList").ShowRegion1({ ShowBox: ".ShowBox", GetUrl: ".ShowBox", UrlID: ".ShowBox", HiddenVal: ".ShowBox" });
    */
    $.fn.ShowRegion1 = function(options)
    {
        var defaults = {
            ShowBox: "ShowBox", //显示的盒子
            GetUrl: "GetUrl", //发送请求的链接
            UrlID: "UrlID", //参数名
            HiddenVal: "HiddenVal"          //程序获取的隐藏域
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oThis = $(this);
            var oShowBox = $(options.ShowBox);
            var RegionValue = oThis.attr("GUID");
            oThis.bind("click", function()
            {

                $.ajax({
                    type: "GET",
                    url: options.GetUrl,
                    data: options.UrlID + "=" + RegionValue,
                    dataType: "xml",
                    async: false, //同步执行，执行完毕，才会执行其他函数
                    cache: false,
                    beforeSend: function(XMLHttpRequest)
                    {
                        oShowBox.html("");
                    },
                    success: function(data)
                    {
                        //alert("11");
                        $(data).find("IsEmpty").each(function()
                        {//找到根节点
                            Empty = $(this).children("Empty").text();
                            //节点名称
                        });
                        if (Empty == "True")
                        {
                            $(options.HiddenVal).val(RegionValue);
                            oShowBox.hide();
                            //alert(Val);
                        } else
                        {
                            $(data).find("Region").each(function()
                            {//找到根节点
                                Box.append("<li GUID=\"" + $(this).children("GUID").text() + "\">" + $(this).children("Name").text() + "</li>");
                            });
                        }
                        //alert($(options.HiddenVal).val());
                    },
                    complete: function(XMLHttpRequest, textStatus)
                    {
                        //HideLoading();
                    },
                    error: function()
                    {
                        //请求出错处理
                    }
                });
            });
            $(document).click(function()
            {
                oShowBox.hide();
            });
        });
    };
    /*
    **  价格计算
    **  $("#CheckShoppingBox").Total({ Num: ".CheckShoppingNum", Price: ".CheckShoppingPrice", Subtotal: ".CheckShoppingSubtotal" , Total: "#Total"});
    */
    $.fn.Total = function(options)
    {
        var defaults = {
            Num: ".CheckShoppingNum", //输入个数
            Price: ".CheckShoppingPrice", //商品单价
            Subtotal: ".CheckShoppingSubtotal", //商品小计
            Total: "#Total"          //商品总价
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oNum = $(options.Num);
            var oPrice = $(options.Price);
            var oSubtotal = $(options.Subtotal);
            var oTotal = $(options.Total);
            var nIndex = oNum.length;
            var nNum = nPrice = nSubtotal = nTotal = 0;
            var i = 0;
            for (i = 0; i < nIndex; i++)
            {
                nPrice = parseFloat(oPrice.eq(i).text()).toFixed(2);
                nNum = parseFloat(oNum.eq(i).val()).toFixed(2);
                nSubtotal = parseFloat(nPrice * nNum);
                oSubtotal.eq(i).text(nSubtotal.toFixed(2));
                nTotal = parseFloat(nTotal) + parseFloat(oSubtotal.eq(i).text());
                oTotal.text(nTotal.toFixed(2));
            };
            //alert(nIndex);
        });
    };
    /*
    **  修改价格
    **  $("#Verification").EditPrice({ InputPrice: "#Text_Price", InputFare: "#Text_Fare", ShowBox: "#EditPriceShow"});
    */
    $.fn.EditPrice = function(options)
    {
        var defaults = {
            InputPrice: "#Text_Price", //价格input
            InputFare: "#Text_Fare", //运费input
            ShowBox: "#EditPriceShow" //输出盒子
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oPrice = $(options.InputPrice);
            var oFare = $(options.InputFare);
            var oShowBox = $(options.ShowBox);
            oPrice.bind("blur", function()
            {
                EditTotal(oShowBox);
            });
            oFare.bind("blur", function()
            {
                EditTotal(oShowBox);
            });
            function EditTotal(obj)
            {
                var nTotal = 0;
                var Price = oPrice.val();
                var Fare = oFare.val();
                Price = Price == "" ? 0 : Price;
                Fare = Fare == "" ? 0 : Fare;
                nTotal = (parseFloat(Price) + parseFloat(Fare)).toFixed(2);

                obj.html("商品价格：<span>" + Price + "</span>元 + 运费：<span>" + Fare + "</span>元 = 总价格：<span>" + nTotal + "</span>元");

            }

            //alert(nIndex);
        });
    };
    /*
    **  输入验证
    **  $(".CheckShoppingNum").InputVerification({ Module: "Num" });
    */
    $.fn.InputVerification = function(options)
    {
        var defaults = {
            Module: "Num" //个数
        }
        var options = $.extend(defaults, options);

        return this.blur(function()
        {
            var oThis = $(this);
            var sVal = oThis.val();
            var sModule = options.Module;
            var sRegular;
            sRegular = /^[1-9]\d*$/;
            sVal = sRegular.test(sVal) ? sVal : "1";
            oThis.val(sVal);
            switch (sModule)
            {
                case "Num":
                    $("#CheckShoppingBox").Total({
                        Num: ".CheckShoppingNum",
                        Price: ".CheckShoppingPrice",
                        Subtotal: ".CheckShoppingSubtotal",
                        Total: "#Total"
                    });
                    break;
                default:
                    break;
            }
        });
    };
    /*
    **  关闭层
    **  $("#CloseTipsBtn").CloseBox({ CloseBoxID: ".CommonTips" });
    */
    $.fn.CloseBox = function(options)
    {
        var defaults = {
            CloseBoxID: "#CloseBoxId"          //关闭的盒子
        }
        var options = $.extend(defaults, options);

        return this.bind("click", function()
        {
            $(options.CloseBoxID).hide();
        });
    };
    /*
    **  切换样式
    **  $(".HaveList").TurnList({ TurnImg: "HaveImg", TurnList: "HaveList" });
    */
    $.fn.TurnList = function(options)
    {
        var defaults = {
            TurnImg: "TurnImg", //带图片的列表样式
            TurnList: "TurnList"          //纯文字的列表样式
        }
        var options = $.extend(defaults, options);

        return this.live("hover", function()
        {
            $(this).attr("class", options.TurnImg);
            $(this).siblings().attr("class", options.TurnList);

        });
    };
    /*
    **  选项卡悬停版
    **  $(".TagsBoxMenu > li").TagsHover({ TagsHover: "TagsHoverCss", TagsContent: ".TagsBoxContent" });
    */
    $.fn.TagsHover = function(options)
    {
        var defaults = {
            TagsHover: "TagsHoverClassName", //激活状态下的className
            TagsContent: ".TagsContentObject"                     //显示的box
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oTags = $(this);
            oTags.hover(function()
            {
                var TagsLength = oTags.parent().children().length;
                var ContentLength = $(options.TagsContent).children().length;
                //                alert(TagsLength);
                //                alert(ContentLength);
                if (TagsLength != ContentLength)
                {
                    alert("菜单层数量和内容层数量不一样!");
                } else
                {
                    oTags.addClass(options.TagsHover).siblings().removeClass(options.TagsHover);
                    var index = oTags.index();
                    $(options.TagsContent).children().eq(index).show().siblings().hide();
                }

            });
        });
    };
    /*
    **  选择参数（指定ID）
    **  $(".ClickShowIDBtn").ChooseParameter({ HoverCss: "ParameterHover", HiddenID: "#ParameterHidden1" });
    */
    $.fn.ChooseParameter = function(options)
    {
        var defaults = {
            HoverCss: "ParameterHover", //选中的样式
            HiddenID: "#HiddenID"          //取值的hidden
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oThis = $(this);
            var sHoverCss = options.HoverCss;
            var oHidden = $(options.HiddenID);
            var oParameter = $("li", oThis);
            oParameter.bind("click", function()
            {
                var oChoose = $(this);
                var sValue = oChoose.attr("alt");
                oChoose.addClass(sHoverCss).siblings().removeClass(sHoverCss);
                oHidden.val(sValue);
                //alert(oHidden.val());
            });
        });
    };
    /*
    **  点击出现（指定ID）
    **  $(".ClickShowIDBtn").ClickShowID({ ShowID: ".ClickShowID" });
    */
    $.fn.ClickShowID = function(options)
    {
        var defaults = {
            ShowID: "ShowID"          //显示的盒子
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oThis = $(this);
            var oShowBox = $(options.ShowID, oThis);
            oThis.click(function()
            {
                oThis.css("z-index", "9");
                oShowBox.show();
                return false;
            });
            $(document).click(function()
            {
                oShowBox.hide();
            });
        });
    };
    /*
    **  模拟File
    **  $(".UIFile").UIFile({FileBtn:".FileBtn"});
    */
    $.fn.UIFile = function(options)
    {
        options = $.extend({
            FileBtn: ".FileBtn",
            ShowPicBox: ".ProdUploadPicNull"
        }, options);

        return this.each(function()
        {
            var oFile = $(this);
            var oShowPicBox = oFile.parents().siblings(options.ShowPicBox);
            var oFileBtn = oShowPicBox.children(options.FileBtn);
            var FileWrapper = $("<div>", {
                className: "UIfileBg"
            });
            oFile.css("opacity", 0.0);
            oFile.wrap(FileWrapper);
            if ($.browser.msie)
            {
                oFile.bind("propertychange", function()
                {
                    if (oFile.val())
                    {
                        oFile.trigger("ChangeOver");
                    } else
                    {
                        oFile.trigger("ChangeNull");
                    }
                });
            } else
            {
                oFile.bind("change", function()
                {
                    if (oFile.val())
                    {
                        oFile.trigger("ChangeOver");
                    } else
                    {
                        oFile.trigger("ChangeNull");
                    }
                });
            }
            oFile.bind("ChangeOver", function()
            {
                oShowPicBox.addClass("ProdUploadPicChange");
                oFileBtn.show();
            }).bind("ChangeNull", function()
            {
                //alert("1");
                oShowPicBox.removeClass("ProdUploadPicChange");
                oFileBtn.hide();
                if ($.browser.msie)
                {
                    oFile.replaceWith(afile.clone());
                } else
                {
                    oFile.val("");
                }
            });
            oFileBtn.bind("click", function()
            {
                //alert("1");
                oFile.trigger("ChangeNull");
            });
        });
    };
    /*
    **  UpLoadFile
    **  $(".UIFile").UpLoadFile({FileWait:".FileBtn"});
    */
    $.fn.UpLoadFile = function(options)
    {
        options = $.extend({
            FileWait: "#UpLoadWait",
            FileFrom: "#formFile"
        }, options);

        return this.each(function()
        {
            var oFile = $(this);
            var oLoad = $(options.FileWait);
            var FileWrapper = $("<div>", {
                className: "UIfileBg"
            });
            oFile.css("opacity", 0.0);
            oFile.wrap(FileWrapper);
            if ($.browser.msie)
            {
                oFile.bind("propertychange", function()
                {
                    if (oFile.val())
                    {
                        oFile.trigger("ChangeOver");
                    } else
                    {
                        oFile.trigger("ChangeNull");
                    }
                });
            } else
            {
                oFile.bind("change", function()
                {
                    if (oFile.val())
                    {
                        oFile.trigger("ChangeOver");
                    } else
                    {
                        oFile.trigger("ChangeNull");
                    }
                });
            }
            oFile.bind("ChangeOver", function()
            {
                $('#formFile').submit();
                oFile.hide();
                oLoad.show();
            }).bind("ChangeNull", function()
            {
                oLoad.hide();
                if ($.browser.msie)
                {
                    oFile.replaceWith(afile.clone());
                } else
                {
                    oFile.val("");
                }
            });
        });
    };
    /*
    **  模拟select
    **  $("select.UISelect").UISelect({IsShow:true,ShowBox:"#RefundReasonTips"});
    */
    $.fn.UISelect = function(options)
    {
        options = $.extend({
            render: function(option)
            {
                return $("<li>", {
                    html: option.text()
                });
            },
            className: "",
            IsShow: false,
            Addition: "",
            Hidden: "#HiddenRegion",
            AjaxUrl: "/ReturnRegion.aspx",
            AjaxID: "RegionGUID",
            ShowBox: ""
        }, options);

        return this.each(function()
        {
            var oSelect = $(this);
            var bShow = options.IsShow;
            var oShowBox = $(options.ShowBox);
            var sAddition = options.Addition;
            var oHidden = $(options.Hidden);
            var nWidth = oSelect.outerWidth();
            var hSelectContainer = $("<div>", {
                width: nWidth + 32,
                className: 'UISelectBox',
                html: "<div class=\"SelectShow\"></div>"
            });

            var hOptionList = $("<ul>", {
                className: "OptionList"
            });
            var oSelectShow = hSelectContainer.find(".SelectShow");
            if (bShow)
            {
                $("li", oShowBox).hide();
            }

            if (options.className)
            {
                hOptionList.addClass(options.className);
            }
            if (oSelect.find("option").length > 8)
            {
                hOptionList.css("height", "210px");
            }
            oSelect.find("option").each(function(i)
            {
                var oOption = $(this);
                if (i == oSelect.attr("selectedIndex"))
                {
                    oSelectShow.html(oOption.text());
                }
                var oLi = options.render(oOption);
                oLi.css("width", nWidth);
                oLi.click(function()
                {
                    oSelectShow.html(oOption.text());
                    hOptionList.trigger("hide");
                    oSelect.val(oOption.val());
                    if (bShow)
                    {
                        var nIndex = $(this).index();
                        //alert(oSelect.val());
                        $("li", oShowBox).eq(nIndex).show().siblings().hide();
                    }
                    switch (sAddition)
                    {
                        case "Region":
                            //alert("1");
                            LoadSelectRegion(oSelect, oOption.val(), options.AjaxUrl, options.AjaxID, oHidden);
                            break;
                        case "OtherInput":
                            if (oOption.val() == "Other")
                            {
                                oShowBox.show();
                            } else
                            {
                                oShowBox.hide();
                            }
                            break;
                        default:
                            //alert("11");
                            break;
                    }
                    return false;
                });
                hOptionList.append(oLi);
            });

            hSelectContainer.append(hOptionList.hide());
            oSelect.hide().after(hSelectContainer);

            hOptionList.bind("show", function()
            {
                if (hOptionList.is(":animated"))
                {
                    return false;
                }
                oSelect.next().css("z-index", "9");
                oSelectShow.addClass("SelectHover");
                hOptionList.slideDown();

            }).bind("hide", function()
            {
                if (hOptionList.is(":animated"))
                {
                    return false;
                }
                oSelect.next().css("z-index", "0");
                oSelectShow.removeClass("SelectHover");
                hOptionList.slideUp();

            }).bind("toggle", function()
            {
                if (oSelectShow.hasClass("SelectHover"))
                {
                    hOptionList.trigger("hide");
                } else
                    hOptionList.trigger("show");
            });

            oSelectShow.click(function()
            {
                hOptionList.trigger("toggle");
                return false;
            });

            $(document).click(function()
            {
                hOptionList.trigger("hide");
            });
        });
    };
    /*
    **  五连图
    **  $("#UIFlashBox").UIFlash();
    */
    $.fn.UIFlash = function(options)
    {
        var defaults = {
            TurnBtn: ".UIFlashBtn", //操作小按钮
            ImgList: ".UIFlashList", //图片List
            ImgHeight: 400  //位移距离
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oTurnBtn = $("li", options.TurnBtn);
            var oImgList = $(options.ImgList);
            var TurnHeight = options.ImgHeight;
            var Adjust = true;
            var nTimes = 0;
            var playTimer = null;
            BtnAuto();
            $(this).mouseover(function()
            {
                clearInterval(playTimer);
            });
            $(this).mouseout(function()
            {
                BtnAuto();
            });
            oTurnBtn.bind("click", function()
            {
                nIndex = $(this).index();
                if (nIndex > nTimes)
                {
                    Adjust = true;
                } else
                {
                    Adjust = false;
                }
                var nDiff = Math.abs(nIndex - nTimes);
                //alert(nDiff);
                nTimes = nIndex;
                PicShow(nIndex);
                Animate(nDiff);
                //alert(nIndex);
                //BtnAuto();
            });
            function PicShow(index)
            {
                oTurnBtn.eq(index).addClass("UIBtnHover").siblings().removeClass("UIBtnHover");
            }

            function BtnAuto()
            {
                playTimer = setInterval(function()
                {

                    //oTurnBtn.eq(nTimes).click();
                    //if(nTimes == (oTurnBtn.length - 1)) {
                    //	nTimes = -1;
                    //}
                    if (nTimes == (oTurnBtn.length - 1))
                    {
                        Adjust = false;
                        Animate(oTurnBtn.length - 1);
                        PicShow(0);
                        nTimes = 0;
                    } else
                    {
                        nTimes++;
                        Animate(1);
                        PicShow(nTimes);
                    }
                }, 2000);
            }

            function Animate(index)
            {
                p = index * TurnHeight * -1;
                if (Adjust)
                {
                    oImgList.stop().animate({
                        top: "+=" + p
                    }, 600);
                } else
                {
                    //alert("1");
                    if (nTimes == oTurnBtn.length - 1)
                    {
                        oImgList.stop().animate({
                            top: "0"
                        }, 600);
                    } else
                    {
                        oImgList.stop().animate({
                            top: "-=" + p
                        }, 600);
                    }
                    Adjust = true;
                }
            }

        });
    };
    /*
    **  折叠菜单
    **  $(".CenterMenuName").FoldMenu({ OpenCss: "MenuOpen", CloseCss: "MenuClose", FoldBox: ".CenterMenuList" });
    */
    $.fn.FoldMenu = function(options)
    {
        var defaults = {
            OpenCss: "OpenCss", //打开状态下的样式
            CloseCss: "CloseCss", //关闭状态下的样式
            FoldBox: "FoldBox"     //需要折叠的盒子
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oMenu = $(this);
            oMenu.bind("click", function()
            {
                var MenuCss = $("h3", oMenu).attr("class");
                if (MenuCss == options.OpenCss)
                {
                    $("h3", oMenu).attr("class", options.CloseCss);
                    oMenu.next(options.FoldBox).slideUp("normal");
                } else
                {
                    $("h3", oMenu).attr("class", options.OpenCss);
                    oMenu.next(options.FoldBox).slideDown("normal");
                }
            })
        });
    };
    /*
    **  倒计时
    **  $("input[name='ChooseAddress']").ClickShowInput({ ShowID: ".ClickShowInput", RadioName: "#ClickShowInputBtn" });
    */
    $.fn.Countdown = function(options)
    {
        var defaults = {
            LastTime: 0, //剩余的总时间
            ShowBox: "ShowBox", //显示倒计时的Box
            updateTime: 1000,
            minus: false
        };
        var opts = $.extend({}, defaults, options), cancel = false;
        var LastTime = opts.LastTime;
        return this.each(function()
        {
            var intval = window.setInterval(function()
            {

                var days = Math.floor(LastTime / (60 * 60 * 24)), hours = Math.floor(LastTime / 60 / 60) % 24, minutes = Math.floor(LastTime / 60) % 60, seconds = LastTime % 60, time = "";

                if (LastTime > 0)
                {
                    time = days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒";
                    LastTime--;
                } else
                {
                    time = "已经过期";
                    cancel = true;
                }

                $(opts.ShowBox).html(time);

                if (cancel)
                {
                    cancel = false;
                    clearInterval(intval);
                }

            }, opts.updateTime);

        });
    }
    /*
    **  点击出现(指定ID,input)
    **  $("input[name='ChooseAddress']").ClickShowInput({ ShowID: ".ClickShowInput", RadioName: "#ClickShowInputBtn" });
    */
    $.fn.ClickShowInput = function(options)
    {
        var defaults = {
            ShowID: ".ShowID",
            RadioName: "#RadioName"
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oCheck = $(this);
            oCheck.bind("click", function()
            {
                //alert("1");
                if ($(options.RadioName).attr("checked") == true)
                {
                    $(options.ShowID).stop(true, true).show();
                } else
                {
                    $(options.ShowID).stop(true, true).hide();
                }
            })
        });
    };
    /*
    **  点击出现(指定ID,input)
    **  $("").ClickShow({ ShowID: ".ShowID" });
    */
    $.fn.ClickShow = function(options)
    {
        var defaults = {
            ShowID: ".ShowID"
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oThis = $(this);
            oThis.bind("click", function()
            {
                $(options.ShowID).stop(true, true).show();
            })
        });
    };
    /*
    **  选择图片加入fck
    **  $("").ChoosePhoto({ ShowID: ".ShowID" });
    */
    $.fn.ChoosePhoto = function(options)
    {
        var defaults = {
            PicList: ".JoinPic",
            PicHidden: ".PicHidden",
            SendBtn: ".SendBtn"
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oThis = $(this);
            var oPicList = $(options.PicList);
            var oPicHidden = $(options.PicHidden);
            var aPic = new Array();
            var sPic;

            oPicList.bind("toggle", function()
            {
                //alert("1");
                var oPic = $(this).children();
                $(this).css("border", "1px solid #000");
                aPic.push(oPic.attr("src"));
                oPicHidden.val(aPic);
            }, function()
            {
                $(this).css("border", "1px solid #000");
                aPic.push(oPic.attr("src"));
                oPicHidden.val(aPic);
            });
        });
    };
    /*
    **  全选
    **  $("").AllCheck({ CheckName: "CheckName", AllCheckBtn: "#AllCheck" });
    */
    $.fn.AllCheck = function(options)
    {
        var defaults = {
            CheckName: "CheckName",
            AllCheckBtn: ".AllCheckBtn"
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oThis = $(this);
            var oCheckList = oThis.find("input[name=" + options.CheckName + "]");
            var oBtn = $(options.AllCheckBtn);

            oBtn.bind("click", function()
            {
                if (oBtn.attr("checked"))
                {
                    oCheckList.attr("checked", "checked");
                }
                else
                {
                    oCheckList.attr("checked", "");
                }
            });
        });
    };
    /*
    **  弹出层
    **  $("body").UILayer({ Module: "alert", TipsTitle: "提示信息标题", TipsText: "提示信息", Url: "iFrame.html" });
    **  $("body").UILayer({Width:"200",Height:"50",Module:"iFrame",FrameUrl:"iFrame.html"});
    */
    $.fn.UILayer = function(options)
    {
        var defaults = {
            LayerBox: "#UILayerBox", //弹出框
            LayerHead: "#UILayerHead", //Tags
            LayerFrame: "#UILayerFrame", //框架
            LayerText: "#UILayerText", //提示文本
            LayerBtn: "#UILayerBtn", //提示文本
            Module: "alert", //使用的模块名称
            Width: 400, //弹出框宽度
            Height: 400, //弹出框高度
            TipsTitle: "提示信息", //提示信息标题
            TipsText: "提示信息提示信息提示信息提示信息提示信息提示信息提示信息提示信息提示信息提示信息提示信息提示信息", //提示信息
            FrameUrl: "FrameUrl", //iframe地址
            BtnHide: false, //是否隐藏确认按钮
            Url: ""  //跳转页面
        }
        var options = $.extend(defaults, options);

        return this.each(function()
        {
            var oLayer = $("body");
            var sModule = options.Module;
            var oLayerBox = $(options.LayerBox);
            var oLayerHead = $(options.LayerHead);
            var oLayerFrame = $(options.LayerFrame);
            var oLayerText = $(options.LayerText);
            var oLayerTag = $("h6", oLayerHead);
            var oLayerTagClose = $("p", oLayerHead);
            var oLayerTagBtn = $(options.LayerBtn);
            var sUrl = options.Url;
            var nWidth, nHeight, nLayerWidth;
            oLayerBox.show();
            oLayerTagBtn.show();
            //关键操作，初始Layer
            //alert(nWidth);
            switch (sModule)
            {
                case "alert":
                    oLayerText.text(options.TipsText);
                    nWidth = oLayerText.width();
                    //alert(nWidth);
                    nWidth = nWidth < 200 ? 200 : (nWidth > 600 ? 600 : nWidth);
                    oLayerText.css("width", nWidth + "px");
                    oLayerBox.css("width", nWidth + 20 + "px");
                    nHeight = oLayerText.outerHeight();
                    break;
                case "iFrame":
                    oLayerFrame.html("");
                    nWidth = options.Width;
                    nHeight = options.Height;
                    oLayerBox.css("width", nWidth + "px");
                    var hIframe = $("<iframe>", {
                        id: "UIIframe",
                        src: options.FrameUrl,
                        width: nWidth + "px",
                        height: nHeight + "px",
                        frameborder: 0,
                        scrolling: "no"
                    });
                    oLayerFrame.append(hIframe);
                    //LayerSize('', '', 'UIIframe');
                    if (options.BtnHide)
                    {
                        //alert("1");
                        oLayerTagBtn.hide();
                    }
                    break;
                default:
                    break;
            }

            var sWidth = ($(window).width() - nWidth) / 2;
            var sHeight = $(window).scrollTop() + ($(window).height() - nHeight) / 3;

            oLayer.addClass("Relative");
            oLayerBox.css({
                left: sWidth + "px",
                top: sHeight + "px"
            });
            oLayerTag.text(options.TipsTitle);

            oLayerBox.css("visibility", "visible");

            //CloseLayer
            oLayerTagClose.bind("click", function()
            {
                oLayer.removeClass("Relative");
                oLayerBox.css("visibility", "hidden");
            });
            oLayerTagBtn.bind("click", function()
            {
                if (sUrl)
                {
                    window.location.href = sUrl //
                } else
                {
                    oLayer.removeClass("Relative");
                    oLayerBox.css("visibility", "hidden");
                }
            });
        });
    };
    function LoadSelectRegion(SelectObj, RegionGuid, AjaxUrl, AjaxID, HiddenObj)
    {
        //alert("1");
        var html = "";
        var Empty = "";
        var AllBox = SelectObj.next().nextAll();

        AllBox.remove();


        $.ajax({
            type: "GET",
            url: AjaxUrl,
            data: AjaxID + "=" + RegionGuid,
            dataType: "xml",
            async: true, //同步执行，执行完毕，才会执行其他函数
            cache: false,
            beforeSend: function(XMLHttpRequest)
            {
            },
            success: function(data)
            {
                //alert("11");
                $(data).find("Properties").each(function()
                {//找到根节点
                    Empty = $(this).children("IsEmpty").text();
                    //alert(Empty);
                    //节点名称
                    sNull = $(this).children("IsNull").text();
                });
                if (Empty == "True" || sNull == "NULL")
                {
                    if (sNull == "NULL")
                    {
                        HiddenObj.val("");
                    }
                    //alert("1");
                    HiddenObj.val(RegionGuid);
                    //alert(RegionGuid);
                } else
                {
                    //alert("1");
                    HiddenObj.val("");
                    $("<select><option value=\"请选择\" selected=\"selected\">请选择</option></select>").insertAfter(SelectObj.next());

                    var NextSelect = SelectObj.nextAll("select:first");
                    //alert("1");
                    $(data).find("Category").each(function()
                    {//找到根节点
                        NextSelect.append("<option value=\"" + $(this).children("GUID").text() + "\">" + $(this).children("Name").text() + "</option>");
                    });

                    NextSelect.UISelect({ Addition: "Region" });
                }
                //alert($(options.HiddenVal).val());
            },
            complete: function(XMLHttpRequest, textStatus)
            {
                //HideLoading();
            },
            error: function()
            {
                HiddenObj.val("");
                //请求出错处理
            }
        });
    }

})(jQuery);
/*
**  传输数据，可传输给iframe父级目标
**  SendData('iframe', Kind, SendTarget, SendHidden, SendText)
*/
function SendData(Addition, Kind, SendTarget, SendHidden, SendText)
{
    var sAddition = Addition; //附加功能
    var sKind = Kind; //目标种类 img div input
    var oSendTarget; //传输目标
    var oSendHidden; //传输目标隐藏域
    var sSendHidden = SendText; //传输内容
    switch (sAddition)
    {
        case "iframe":
            //alert("1");
            oSendTarget = $(window.parent.document).find(SendTarget);
            oSendHidden = $(window.parent.document).find(SendHidden);
            break;
        default:
            //alert("2");
            oSendTarget = $(SendTarget);
            oSendHidden = $(SendHidden);
            break;
    }
    switch (sKind)
    {
        case "img":
            oSendTarget.attr("src", SendText);
            break;
        case "div":
            //alert("2");
            oSendTarget.text(SendText);
            break;
        case "input":
            //alert("3");
            oSendTarget.val(SendText);
            break;
        default:
            break;
    }

    oSendHidden.val(SendText);
    //alert(oSendHidden.val());
    $(window.parent.document).find("body").removeClass("Relative");
    $(window.parent.document).find("#UILayerBox").css("visibility", "hidden");
}
/*
**  弹出层辅助function 自动转变弹出层大小
**  SendData(Addition, Kind, SendTarget, SendHidden, SendText)
*/
function LayerSize(Addition, Kind, obj)
{
    var sWidth = $(window.frames["" + obj + ""].document).find(window).width();
    var sHeight = $(window.frames["" + obj + ""].document).find(window).height();
    var sAddition = Addition; //附加功能
    var sKind = Kind; //目标种类 img div input
    switch (sAddition)
    {
        case "iframe":
        default:
            break;
    }
    switch (sKind)
    {
        default:
            break;
    }
    alert(sWidth);
    alert(sHeight);
    //$(window.parent.document).find("body").removeClass("Relative");
    //$(window.parent.document).find("#UILayerBox").css("visibility", "hidden");     	
}
/*
**  转为Loading画面
**  只适用于弹出层
*/
function UIFrameLoading()
{
    //alert("1");
    var oLayer = $("body");
    oLayer.addClass("Relative");
    //$(window.parent.document).find("#UILayerBox").css({"width":"260px", "height": "100px"});
    //$(window.parent.document).find("#UIIframe").css({"width":"240px", "height": "70px"});
    $(window.parent.document).find("#UILayerHead h6").text("正在上传请稍后");
    $(window.parent.document).find("#UILayerHead p").hide();
    var sWidth = $(window).width();
    var sHeight = $(window).height();
    //alert(sWidth);
    var Mask = $("<div>", {
        width: sWidth,
        height: sHeight,
        className: 'UIMask',
        html: ""
    });
    oLayer.append(Mask);
    return true;
}

