/*
jiangfan于2015年2月4日更新
jiangfan于2015年3月7日更新
Version：1.7
*/
; (function ($) {
    $.fn.extend({
        "imgAppend": function () {
            //居中、右文本添加的个数，为了判断文本图片是否一起显示出来
            var count = 0;
            //居中居右文本的处理
            function imgHandler(t) {
                var alignVal = t.getAttribute("calign"), x = t.getAttribute("x"), cid = t.getAttribute("cid");
                if (alignVal == "0") {
                    t.style.left = x + "px";
                    if ($(t).parent()[0].id == "wrapC") {
                        $PlusContainer.find("#wrapC").css({ "left": x - 4 });
                    }
                }
                else if (alignVal == "1") {
                    t.style.left = x - t.width + "px";
                    if ($(t).parent()[0].id == "wrapC") {
                        $PlusContainer.find("#wrapC").css({ "left": x - t.width - 4 });
                    }
                }
                else if (alignVal == "2") {
                    t.style.left = x - t.width / 2 + "px";
                    if ($(t).parent()[0].id == "wrapC") {
                        $PlusContainer.find("#wrapC").css({ "left": x - t.width / 2 - 4 });
                    }
                }
                else {
                    t.style.left = x + "px";
                    if ($(t).parent()[0].id == "wrapC") {
                        $PlusContainer.find("#wrapC").css({ "left": x - 4 });
                    }
                }
                //$("#"+t.id).remove();
                t.removeAttribute("width");
                t.removeAttribute("height");
                if (t.getAttribute("jg")=="1")
                    judgeOverBorder(t);
                else if(t.getAttribute("jg")=="2")
                {
                    judgeOverBorder(t,2);
                    t.setAttribute("jg","1");
                }
                else{
                     judgeOverBorder(t);
                }
                count++;
            }
            //图片添加不进去计数器也加1
            function errorHandler() {
                count++;
            }
            //文本的追加
            function appendText(cId, ox) {
                //用来装Img元素
                var tempArray = new Array();
                for (var i = 0; i < TextJson.length; i++) {
                    if (!(TextJson[i].TemplateTransactionID == cId)) {
                        continue;
                    }
                    tempArray.push('<img class="textC text' + cId + '" ox="' + ox + '" id="text' + TextJson[i].TextPropertyId + '" srcs="' + TextJson[i].TextImage + "&random=" + (new Date()).valueOf() + '" style="top:' + TextJson[i].TextY + 'px; z-index:1" x="' + TextJson[i].TextX + '" calign="' + TextJson[i].TextAlign + '" cid="' + cId + '" jsonIndex="' + i + '"  />');
                    TextJson[i].TextImage = null;
                }
                //$(".cContainer").on("load","img",fun....然后在append图片，图片是没有绑定这个load事件的。猜测img是不会往上冒泡的。
                //换种方法。先添加img
                $(".cContainer[transid=" + cId + "]").append(tempArray.join(""));
                //然后给图片绑定load事件
                $(".text" + cId).load(function () { imgHandler(this); });
                var $img = $(".cContainer[transid=" + cId + "]").find(".text" + cId);
                for (var j = 0; j < $img.length; j++) {
                    $img[j].src = $img[j].getAttribute("srcs");
                    $img[j].removeAttribute("srcs");
                }
            }
            //logo的追加
            function appendLogo(cId, ox) {
                //用来装Img元素
                var tempArray = new Array();
                for (var i = 0; i < logoJson.length; i++) {
                    if (!(logoJson[i].TemplateTransactionID == cId)) {
                        continue;
                    }
                    tempArray.push('<img class="textC logox" ox="' + ox + '" id="logo' + logoJson[i].LogoId + '" data-x="' + logoJson[i].LogoX + '" data-y="' + logoJson[i].LogoY + '" data-width="' + logoJson[i].LogoWidth + '" data-height="' + logoJson[i].LogoHeight + '" src="' + logoJson[i].OriginalThumbnailsName + '" style="top:' + logoJson[i].LogoY + 'px;left:' + logoJson[i].LogoX + 'px;width:' + logoJson[i].LogoWidth + 'px;height:' + logoJson[i].LogoHeight + 'px;" logoIndex="' + i + '"  />');
                }
                $(".cContainer[transid=" + cId + "]").append(tempArray.join(""));
            }
            var $o = this.find(".cContainer"), ol = $o.length;
            for (var i = 0; i < ol; i++) {
                //追加文字
                appendText($o.eq(i).attr("transid"), i);
                //追加logo
                appendLogo($o.eq(i).attr("transid"), i);
            }
        },
        "inputChange": function () {
            var param = {
                dftContainer: "#PlusContainer",
                dftSingleSlider: ".stext"
            }
            $(param.dftContainer).on("keyup", param.dftSingleSlider, function (s) {
                //textid,更改的值,文本json的索引，更改图片的url
                var $O = $("#text" + $(this).attr("id").slice(5)), index = $O.attr("jsonindex");
                if (s.which != 37 && s.which != 39) {
                    //$(this).val($.trim(this.value));

                    nowValue = $.trim(this.value);
                    if (TextJson[index].Text == nowValue) {
                        return false;
                    }
                    TextJson[index].Text = nowValue;
                    TextJson[index].TextImage = null;
                    var requestUrl = drawTextImageUrl + "?operation=1&random=" + Math.random() + "&text=" + encodeURIComponent(JSON.stringify(TextJson[index]));
                    $O.attr("jg", "2");
                    $O.attr("src", requestUrl);
                    if (nowValue == "") {
                        $(this).createNewDrag($("#wrapC"));
                    }
                    else {
                        if (!$("#wrapC").length)
                            $O.createNewDrag($("#wrapC"));
                    }
                }
                return false;
            });
        },
        "printf": function () {
            var doing = this.attr("doing"), objTmp = new Object(), arrayHtml = new Array();
            $this = this;
            if (parseInt(doing)) {
                return false;
            }
            if (this[0].id == "printfc") {
                this.addClass("backWaiting");
                this.attr("doing", "1");
            }
            else {
                if (this[0].id == "save") {
                    //if($.checkEmpty("保存名片上没有填写任何内容不能保存。",1)==1)
                    //   return false;
                    if (overBorderArray.length > 0) {
                        warnShow('文字超出了名片出血线，为避免您的印刷品出错，请修正后再保存！');
                        return;
                    }
                }
                else {
                    //if($.checkEmpty("下载名片上没有填写任何内容不能下载。",1)==1)
                    //    return false;
                }
                if (!$.cookie("uid")||$.cookie("uid")=="") {
                    popup_login('callbarkord');
                    return;
                }
                objTmp.containerCss = { width: '466px', height: '173px', 'background-color': '#fff', color: '#666', "font-weight": "bold", "font-size": "15px" };
                objTmp.closeHTML = '<a id="qyptClose" title="关闭"></a>';
                objTmp.focus = false;
                arrayHtml[0] ='<div class="newPrint"><div class="LeftInfo">一幅图印刷<span style="color:#f60; font-weight:bold;">2</span>盒名片低至<span style="color:#f60; font-weight:bold;">8~10</span>元起</div><a class="RightInfo" onclick="$.modal.close();showPrint();return false;">直接印刷</a></div>';
                arrayHtml[1] = '<div class="loadingForDialog1">' + (this[0].id == "save" ? '正在保存中，请稍候......' : '生成文件中，请稍候......') + '</div>';
                gaituCommonDialog(arrayHtml.join(""), objTmp);
            }
            var newTextJson = [], newLogoJson = [];
            //操作logo
            for (var i = 0; i < logoJson.length; i++) {
                if (!logoJson[i].hidden) {
                    newLogoJson.push(logoJson[i]);
                }
            }
            for (var i = 0; i < TextJson.length; i++) {
                if (!TextJson[i].isDel) {
                    newTextJson.push(TextJson[i]);
                }
            }
            //操作文本

            obj.url = printAjaxUrl;
            obj.data = {};
            obj.data.rate = ratio;
            obj.data.Templateid = templateid;
            obj.data.TextList = JSON.stringify(newTextJson);
            obj.data.TemplateTransactionJson = JSON.stringify(TemplateTransactionJson);
            obj.data.LogoList = JSON.stringify(newLogoJson);
            obj.dataType = "html";
            if (this[0].id == "printfc") {
                obj.data.Operation = 1;
                commonAjaxRequest(obj, function (data) {
                    if (data != "error") {
                        var drawid = parseInt(data);
                        if (drawid > 0)
                            window.location.href = printUrl + "?drawid=" + data;
                        else {
                            var objTmp = new Object(), arrayHtml = new Array();
                            objTmp.containerCss = { width: '466px', height: '144px', 'background-color': '#fff', color: '#666' };
                            objTmp.closeHTML = '<a id="qyptClose" title="关闭"></a>';
                            objTmp.focus = false;
                            objTmp.onShow = function () {
                                $(".dialogOrangeBtn").click(function () {
                                    $.modal.close();
                                    return false;
                                })
                            }
                            arrayHtml[0] = '<div style=" text-align:center; padding-top:46px;color: #ff0000;font-size: 18px;">印刷名片失败，请您稍后重试！</div>';
                            arrayHtml[1] = '<div class="dialogOrangeBtn" style=" width:138px; height:30px; line-height:30px; margin:0 auto; margin-top:23px;">确定</div>';
                            gaituCommonDialog(arrayHtml.join(""), objTmp);
                        }
                    }
                    else {
                        $("#canclePrint").click();
                    }
                });
            }
            else if (this[0].id == "save") {
                obj.data.Operation = 2;
                commonAjaxRequest(obj, function (data) {
                    if (data != "error") {
                        var drawid = parseInt(data);
                        $.modal.close();
                        if (drawid > 0) {
                            var wenzi = "我的模板";
                            if ($.cookie("AreaSiteID")&&parseInt($.cookie("AreaSiteID"))!=0) {
                                fileMann = "http://i.yifutu.com/Space/Page/FileManager/MyLocFilesSaved.aspx";
                                wenzi = "已保存的文件";
                            }
                            var objTmp = new Object(), arrayHtml = new Array();
                            objTmp.containerCss = { width: '466px', height: '173px', 'background-color': '#fff', color: '#666' };
                            objTmp.closeHTML = '<a id="qyptClose" title="关闭"></a>';
                            objTmp.focus = false;
                            arrayHtml[0] ='<div class="newPrint"><div class="LeftInfo">一幅图印刷<span style="color:#f60; font-weight:bold;">2</span>盒名片低至<span style="color:#f60; font-weight:bold;">8~10</span>元起</div><a class="RightInfo" onclick="$.modal.close();showPrint();return false;">直接印刷</a></div>';
                            arrayHtml[1] = '<div class="loadingForDialog2">保存成功！请到<a href="' + fileMann + '"  style="color:#29b0ea;font-size:15px;">' + wenzi + '</a>中查看。</div>';
                            arrayHtml[2] = '<p class="loadingForDialog3"><a onclick="$.modal.close();">继续设计</a></p>';
                            gaituCommonDialog(arrayHtml.join(""), objTmp);
                            GoSave(drawid);
                        }
                        else {
                            var objTmp = new Object(), arrayHtml = new Array();
                            objTmp.containerCss = { width: '466px', height: '144px', 'background-color': '#fff', color: '#666' };
                            objTmp.closeHTML = '<a id="qyptClose" title="关闭"></a>';
                            objTmp.focus = false;
                            objTmp.onShow = function () {
                                $(".dialogOrangeBtn").click(function () {
                                    $.modal.close();
                                    return false;
                                })
                            }
                            arrayHtml[0] = '<div style=" text-align:center; padding-top:46px;color: #ff0000;font-size: 18px;">保存名片失败，请您稍后重试！</div>';
                            arrayHtml[1] = '<div class="dialogOrangeBtn" style=" width:138px; height:30px; line-height:30px; margin:0 auto; margin-top:23px;">确定</div>';
                            gaituCommonDialog(arrayHtml.join(""), objTmp);
                        }
                    }
                    else {
                        $.modal.close();
                        var objTmp = new Object(), arrayHtml = new Array();
                        objTmp.containerCss = { width: '466px', height: '144px', 'background-color': '#fff', color: '#666', padding: "0px 20 0 20px" };
                        objTmp.closeHTML = '<a id="qyptClose" title="关闭"></a>';
                        objTmp.focus = false;
                        objTmp.onShow = function () {
                            $(".dialogOrangeBtn").click(function () {
                                $.modal.close();
                                return false;
                            })
                        }
                        arrayHtml[0] = '<div style=" text-align:center; padding-top:28px;color: #ff6600;font-size: 18px;">访问咱名片制作的小伙伴太多了。服务器有点繁忙，请您联系客服，或之后再试^_^！</div>';
                        arrayHtml[1] = '<div class="dialogOrangeBtn" style=" width:138px; height:30px; line-height:30px; margin:0 auto; margin-top:23px;">确定</div>';
                        gaituCommonDialog(arrayHtml.join(""), objTmp);
                    }
                });
            }
            else if (this[0].id = "download") {
                obj.data.cateID = 1;
                obj.data.format = Format;
                obj.data.Operation = 10;
                commonAjaxRequest(obj, function (data) {
                    if (data != "error") {
                        var elemIF = document.createElement("iframe");
                        elemIF.src = data;
                        elemIF.style.display = "none";
                        document.body.appendChild(elemIF);
                        $(".loadingForDialog1").addClass("ploadingForDialog").removeClass("loadingForDialog1").html('<span>下载已自动开始，请稍候.......</span><br/>如果还没开始，单击此处：<a href="' + data + '" target="_blank">' + data + '</a>');
                    }
                });
            }
        },
        "imgSlide": function (events) {
            var param = {
                //倍数
                paramMultiple: 2,
                //基数
                dftjs: 0,
                dftContainer: "#PlusContainer",
                dftSingleSlider: ".sliderc",
                dftAddJian: ".jian,.add",
                imgId: 0
            }, $current = this, $val, distict = 0, multiple = 0, x = 0;
            events && $.extend(param, events);
            function moveImg(multiple) {
                var $img = $(param.imgId), imgWidth = parseInt($img[0].width), imgHeight = parseInt($img[0].height), centerX = 0, centerY = 0;
                //caculate center x,y
                centerX = parseInt($img.attr("data-x")) + $img.attr("data-width") / 2, centerY = parseInt($img.attr("data-y")) + $img.attr("data-height") / 2, imgWidth = $img.attr("data-width") * multiple, imgHeight = $img.attr("data-height") * multiple;
                $img.css({ width: imgWidth, height: imgHeight, left: function () { return centerX - imgWidth / 2 }, top: function () { return centerY - imgHeight / 2 } });
                logoJson[$img.attr("logoIndex")].LogoWidth = parseInt(imgWidth);
                logoJson[$img.attr("logoIndex")].LogoHeight = parseInt(imgHeight);
                logoJson[$img.attr("logoIndex")].LogoX = parseInt(centerX - imgWidth / 2);
                logoJson[$img.attr("logoIndex")].LogoY = parseInt(centerY - imgHeight / 2);
                if ($img.parent()[0].id == "wrapC") {
                    $PlusContainer.find("#wrapC").css({ "left": centerX - imgWidth / 2 - 4 });
                    $PlusContainer.find("#wrapC").css({ "top": centerY - imgHeight / 2 - 4 });
                }
                judgeOverBorder($img[0]);
            }
            function slide(e, $asp) {
                if (typeof (e) == "object")
                    x = parseInt(e.pageX - progresLeft) - 4;
                else
                    x = parseInt($this.css("left")) + e;
                if (x >= -1 && x <= 99) {
                    $asp.css({ left: x });
                    $val.html(param.dftjs + (x + 1) * param.paramMultiple + "%");
                    moveImg((param.dftjs + (x + 1) * param.paramMultiple) / 100);
                }
                else if (x < -1) {
                    x = -1;
                    $asp.css({ left: x });
                    $val.html(param.dftjs + (x + 1) + "%");
                }
                else if (x > 99) {
                    x = 99;
                    $asp.css({ left: 99 });
                    $val.html((param.dftjs + (x + 1) * param.paramMultiple) + "%");
                }
                return false;
            }
            //绑定滑块滑动
            $(param.dftContainer).on("mousedown", param.dftSingleSlider, function (s) {
                $this = $(this);
                param.imgId = $this.attr("data-value");
                x = 0, progresLeft = $this.parent().offset().left;
                $val = $this.find(".percentc");
                $(document.body).mousemove(function (e) {
                    slide(e, $this);
                })
                return false;
            }).on("click", param.dftSingleSlider, function () {
                return false;
            });
            var cls = this.attr("class");
            $(param.dftContainer).on("click", param.dftAddJian, function (s) {
                $this = $(this).siblings(".progress").find(param.dftSingleSlider);
                param.imgId = $this.attr("data-value");
                $val = $this.find(".percentc");
                if ($(this).hasClass("jian")) {
                    slide(-1, $this);
                }
                else {
                    slide(1, $this);
                }
                return false;
            });
            $(document.body).mouseup(function () {
                $(this).unbind("mousemove").css("cursor", "default");
                return false;
            })
        },
        "editAppend": function (faceid, backid) {
            var omTemp1 = new Array(), omTemp2 = new Array(), imgTemp1 = new Array(), imgTemp2 = new Array(), sflag = "";
            for (var i = 0; i < TextJson.length; i++) {
                if (TextJson[i].TemplateTransactionID == faceid) {
                    omTemp1.push('<div class="stextCon faceText" data-value="face"><input id="input'+TextJson[i].TextPropertyId+'" class="stext" jsonindex="'+i+'" value="'+TextJson[i].Text+'" /></div>');
                }
                else if (TextJson[i].TemplateTransactionID == backid) {
                    omTemp2.push('<div class="stextCon backText gt_hidden" data-value="back"><input id="input'+TextJson[i].TextPropertyId+'" class="stext" jsonindex="'+i+'" value="'+TextJson[i].Text+'" /></div>');
                }
            }
            for (var i = 0; i < logoJson.length; i++) {
                if (logoJson[i].TemplateTransactionID == faceid) {
                    sflag = logoJson[i].Type == 1 ? "faceLogo" : "faceCode";
                    imgTemp1.push('<div class="slogo ' + sflag + '" data-op="' + logoJson[i].Type + '"><div class="sl" id="s1' + logoJson[i].LogoId + '" logoindex="' + i + '"><img id="dlogo-' + logoJson[i].LogoId + '" src="' + logoJson[i].OriginalThumbnailsName + '" alt="" /></div><div class="sr"><div class="sr1"><div class="changeLogo" style="z-index:' + parameterMp.faceZindex + '" data-value="' + logoJson[i].LogoId + '" data-op="' + logoJson[i].Type + '">更换' + (logoJson[i].Type == 1 ? 'LOGO' : '二维码') + '</div>' + (logoJson[i].Type == 1 && parameterMp.faceZindex == 15 ? '<a class="designLogo" target="_blank" href="' + shejiLogo + '">设计LOGO</a>' : '') + '</div><div class="sr2"><div class="sr2-1">调整大小：</div><div class="jian"></div><div class="progress"><div class="' + (logoJson[i].Type == 1 ? 'sliderc' : 'Esliderc') + '" data-value="#logo' + logoJson[i].LogoId + '"><div class="percentc"></div></div></div><div class="add"></div><div class="opLogo" data-value="#logo' + logoJson[i].LogoId + '">隐藏LOGO</div></div></div></div>');
                    parameterMp.faceZindex--;
                }
                else if (logoJson[i].TemplateTransactionID == backid) {
                    sflag = logoJson[i].Type == 1 ? "backLogo" : "backCode";
                    imgTemp2.push('<div class="slogo ' + sflag + ' gt_hidden"  data-op="' + logoJson[i].Type + '""><div class="sl" id="s1' + logoJson[i].LogoId + '" logoindex="' + i + '"><img id="dlogo-' + logoJson[i].LogoId + '" src="' + logoJson[i].OriginalThumbnailsName + '" alt="" /></div><div class="sr"><div class="sr1"><div class="changeLogo" style="z-index:' + parameterMp.backZindex + '" data-value="' + logoJson[i].LogoId + '" data-op="' + logoJson[i].Type + '">更换' + (logoJson[i].Type == 1 ? 'LOGO' : '二维码') + '</div>' + (logoJson[i].Type == 1 && parameterMp.backZindex == 15 ? '<a class="designLogo" target="_blank" href="' + shejiLogo + '">设计LOGO</a>' : '') + '</div><div class="sr2"><div class="sr2-1">调整大小：</div><div class="jian"></div><div class="progress"><div class="' + (logoJson[i].Type == 1 ? 'sliderc' : 'Esliderc') + '" data-value="#logo' + logoJson[i].LogoId + '"><div class="percentc"></div></div></div><div class="add"></div><div class="opLogo" data-value="#logo' + logoJson[i].LogoId + '">隐藏LOGO</div></div></div></div>');
                    parameterMp.backZindex--;
                }
            }
            $PlusContainer.find("#stextContainer").append(omTemp1.join("")).append(omTemp2.join(""));
            if (imgTemp1.length || imgTemp2.length)
                $PlusContainer.find("#slogoContainer").append(imgTemp1.join("")).append(imgTemp2.join("")).css("padding-bottom", "10px");
        },
        //拖动，我的最爱
        "dragme": function (pm) {
            var parameter = {
                conTainerMarking: ".cContainer",
                pcontainerC: "#PlusContainer",
                drageClass: ".textC"
            };
            pm && $.extend(parameter, pm);
            //this的说明，fn上的this就是jQuery对象
            //这里的$current代表了传入的jQuery对象。如果传入的是类选择器，则$current代表了类集合           
            var $current = this, cleft = 0, ctop = 0, cwidth = 0, cheight = 0, tempArray = new Array(), containerLeft = 0,
                containerTop = 0, temWidth = 0, temHeight = 0;
            //构造拖动外框
            function a($c) {
                cleft = parseFloat($c.css("left")), ctop = parseFloat($c.css("top")), cwidth = $c.width(), cheight = $c.height();
                tempArray[0] = '<div id="wrapC" style="left:' + (cleft - 4) + 'px;top:' + (ctop - 4) + 'px;">';
                tempArray[1] = '</div>';
                $c.addClass("acmove");
                $c.wrap(tempArray.join(""));
                $("#wrapC").append('<div class="lftTop"></div><div class="lftBtm"></div><div class="rgtTop"></div><div class="rgtBtm"></div>');
                return $("#wrapC");
            }
            //移除拖动外框
            function b($temp) {
                var $tempImg = $temp.find("img");
                cleft = parseFloat($temp.css("left")) + 4, ctop = parseFloat($temp.css("top")) + 4;
                $temp.find("div").remove();
                $tempImg.unwrap().removeClass("acmove").css({ left: cleft + "px", top: ctop + "px" });

            }
            function toSetJson($drag) {
                var index = 0, currWidth = $drag.width() - 2;
                if (!$drag.find("img").hasClass("logox")) {
                    index = $drag.find("img").attr("jsonindex");
                    TextJson[index].TextX = parseFloat($drag.css("left")) + 4;
                    TextJson[index].TextY = parseFloat($drag.css("top")) + 4;
                    //居右
                    if (TextJson[index].TextAlign == 1) {
                        TextJson[index].TextX += currWidth;
                    }
                    else if (TextJson[index].TextAlign == 2) {
                        TextJson[index].TextX += currWidth / 2;
                    }
                    $drag.find("img").attr("x", TextJson[index].TextX).css({ left: parseFloat($drag.css("left")) + 4, top: parseFloat($drag.css("top")) + 4 });
                    if (parameterMp.moveJude)
                        judgeOverBorder($drag.find("img")[0]);
                }
                else {
                    index = $drag.find("img").attr("logoindex");
                    logoJson[index].LogoX = parseInt($drag.css("left")) + 4;
                    logoJson[index].LogoY = parseInt($drag.css("top")) + 4;
                    $drag.find("img").attr("data-x", logoJson[index].LogoX).attr("data-y", logoJson[index].LogoY).css({ left: logoJson[index].LogoX, top: logoJson[index].LogoY });
                    judgeOverBorder($drag.find("img")[0]);                   
                }
            }
            function keybordPress($drag, step, e) {
                var dleft = 0, dtop = 0, dwidth = $drag.outerWidth(), dheight = $drag.outerHeight();
                if (e == "x") {
                    dleft = parseFloat($drag.css("left")) + step;
                    if (dleft <= parameterMp.x - 4) {
                        $drag.css({ "left": parameterMp.x - 4 });
                    }
                    else if (parameterMp.width - dwidth - dleft <= parameterMp.x - 4) {
                        $drag.css({ "left": parameterMp.width - dwidth - parameterMp.x + 4 });
                    }
                    else {
                        $drag.css({ "left": dleft });
                    }
                }
                else if (e == "y") {
                    dtop = parseFloat($drag.css("top")) + step;
                    if (dtop <= parameterMp.y - 4) {
                        $drag.css({ "top": parameterMp.y - 4 });
                    }
                    else if (parameterMp.height - dheight - dtop <= parameterMp.y - 4) {
                        $drag.css({ "top": parameterMp.height - dheight - parameterMp.y + 4 });
                    }
                    else {
                        $drag.css({ "top": dtop });
                    }
                }
                d($drag);
                toSetJson($drag);
            }
            //移动
            function c($drag, e) {
                var epageX = e.pageX - containerLeft, epageY = e.pageY - containerTop, xpos, ypos, OCwidth = cwidth + 8, OCheight = cheight + 8, index = 0;
                cleft = epageX, ctop = epageY;
                //让鼠标居中，并控制移动范围
                //xpos = epageX - OCwidth / 2, ypos = epageY - OCheight / 2, (xpos = containerLeft > e.pageX - OCwidth / 2-parameterMp.x+4 ? parameterMp.x-4 : e.pageX + OCwidth / 2 >parameterMp.width+containerLeft-parameterMp.x+4 ? parameterMp.width - OCwidth-parameterMp.x+4 : xpos,
                //                                                           ypos =containerTop>  e.pageY - OCheight/ 2-parameterMp.y+4 ? parameterMp.y-4: e.pageY+ OCheight/ 2 >parameterMp.height + containerTop-parameterMp.y+4? parameterMp.height -OCheight-parameterMp.y+4 : ypos), $drag.css({
                //    top: ypos,
                //    left: xpos
                //});
                xpos = epageX - temWidth, ypos = epageY - temHeight, (xpos = containerLeft > e.pageX - temWidth - parameterMp.x + 4 ? parameterMp.x - 4 : e.pageX + OCwidth - temWidth > parameterMp.width + containerLeft - parameterMp.x + 4 ? parameterMp.width - OCwidth - parameterMp.x + 4 : xpos,
                                                                               ypos = containerTop > e.pageY - temHeight - parameterMp.y + 4 ? parameterMp.y - 4 : e.pageY + OCheight - temHeight > parameterMp.height + containerTop - parameterMp.y + 4 ? parameterMp.height - OCheight - parameterMp.y + 4 : ypos), $drag.css({
                                                                                   top: ypos,
                                                                                   left: xpos
                                                                               });
                //设置textjson
                if (!$drag.find("img").hasClass("logox")) {
                    index = $drag.find("img").attr("jsonindex");
                    TextJson[index].TextX = xpos + 4;
                    TextJson[index].TextY = ypos + 4;
                    //居右
                    if (TextJson[index].TextAlign == 1) {
                        TextJson[index].TextX += cwidth;
                    }
                    else if (TextJson[index].TextAlign == 2) {
                        TextJson[index].TextX += cwidth / 2;
                    }
                    $drag.find("img").attr("x", TextJson[index].TextX).css({ left: xpos + 4, top: TextJson[index].TextY });
                    if (parameterMp.moveJude)
                        judgeOverBorder($drag.find("img")[0]);                  
                }
                else {
                    index = $drag.find("img").attr("logoindex");
                    logoJson[index].LogoX = parseInt(xpos) + 4;
                    logoJson[index].LogoY = parseInt(ypos) + 4;
                    $drag.find("img").attr("data-x", logoJson[index].LogoX).attr("data-y", logoJson[index].LogoY).css({ left: logoJson[index].LogoX, top: logoJson[index].LogoY });
                    judgeOverBorder($drag.find("img")[0]);                 
                }
                d($drag);
            }
            //得到参考线
            function d($d) {
                if ($("." + parameterMp.shu).length)
                    $("." + parameterMp.shu).remove();
                if ($("." + parameterMp.heng).length)
                    $("." + parameterMp.heng).remove();
                var x1 = Math.round(parseFloat($d.css("left"))) + 3, x2 = x1 + Math.round(parseFloat($d.outerWidth())) - 7, y1 = Math.round(parseFloat($d.css("top"))) + 3, y2 = y1 + Math.round(parseFloat($d.outerHeight())) - 7,
                    $allImg = $d.siblings("img"), x1to = 0, x2to = 0, y1to = 0, y2to = 0, $temp, cuLeft = 0, cuTop = 0;
                for (var i = 0, max = $allImg.length; i < max; i++) {
                    $temp = $($allImg[i]), x1to = Math.round(parseFloat($temp.css("left"))) - 1,
                        x2to = x1to + Math.round(parseFloat($temp.width())) + 2,
                        y1to = Math.round(parseFloat($temp.css("top"))) - 1,
                        y2to = y1to + Math.round(parseFloat($temp.height())) + 2;
                    if (x1 == x1to || x1 == x2to || x2 == x1to || x2 == x2to || y1 == y1to || y1 == y2to || y2 == y1to || y2 == y2to) {
                        if (x1 == x1to || x1 == x2to) {
                            cuLeft = x1;
                        }
                        else if (x2 == x1to || x2 == x2to) {
                            cuLeft = x2;
                        }
                        if (y1 == y1to || y1 == y2to) {
                            cuTop = y1;
                        }
                        else if (y2 == y1to || y2 == y2to) {
                            cuTop = y2;
                        }
                        if (cuLeft) {
                            $d.parents(".cContainer").append('<div class="' + parameterMp.shu + '" style="left:' + cuLeft + 'px"></div>');
                        }
                        if (cuTop) {
                            $d.parents(".cContainer").append('<div class="' + parameterMp.heng + '" style="top:' + cuTop + 'px"></div>');
                        }
                        break;
                    }
                }
            }
            //鼠标的按下事件
            $(parameter.pcontainerC).on("mousedown", parameter.drageClass, function (s) {
                //移除keyup事件
                $(document.body).unbind("keydown");
                //相应事件里的this代表js对象。所以要构造下，它代表了被点击的对象。
                $this = $(this);
                containerLeft = $this.parents(parameter.conTainerMarking).offset().left;
                containerTop = $this.parents(parameter.conTainerMarking).offset().top;
                var $wrapC = $("#wrapC"), xx = s.pageX, yy = s.pageY, index = $this.attr("jsonindex");
                //移除drag
                if ($wrapC.length)
                    b($wrapC);
                var $drag = a($this);
                temWidth = xx - parseFloat($drag.css("left")) - containerLeft, temHeight = yy - parseFloat($drag.css("top")) - containerTop;
                $(document.body).mousemove(function (e) {

                    var xxx = e.pageX, yyy = e.pageY;
                    if (xx != xxx || yy != yyy) {
                        c($drag, e);
                    }
                    //阻止冒泡
                    return false;
                });
                $(document.body).keydown(function (e) {
                    var $dragT = $PlusContainer.find("#wrapC");
                    if (e.which == 37) {
                        keybordPress($dragT, -1, "x");
                    }
                    else if (e.which == 38) {
                        keybordPress($dragT, -1, "y");
                    }
                    else if (e.which == 39) {
                        keybordPress($dragT, 1, "x");
                    }
                    else if (e.which == 40) {
                        keybordPress($dragT, 1, "y");
                    }
                    return false;
                });
                //如果是正面，触发正面click
                if ($this.attr("ox") == "0") {
                    $PlusContainer.find("#faceTab").click();
                }
                else
                    $PlusContainer.find("#backTab").click();
                $this = $(this);
                if (!$this.hasClass("logox")) {
                    $PlusContainer.find(".stext[jsonindex=" + index + "]").trigger("click", 1);
                }
                else {
                    index = $this.attr("logoindex");
                    $PlusContainer.find(".sl[logoindex=" + index + "]").click();
                }
                return false;
            });
            $(document.body).mouseup(function () {
                $(this).unbind("mousemove");
                if ($("." + parameterMp.shu).length)
                    $("." + parameterMp.shu).remove();
                if ($("." + parameterMp.heng).length)
                    $("." + parameterMp.heng).remove();
            })
        },
        "createNewDrag": function ($temp) {
            if (this.parent().attr("id") == "wrapC")
                return false;
            if ($temp.length) {
                //移除选框
                var $tempImg = $temp.find("img");
                cleft = parseFloat($temp.css("left")) + 4, ctop = parseFloat($temp.css("top")) + 4;
                $temp.find("div").remove();
                $tempImg.unwrap().removeClass("acmove").css({ left: cleft + "px", top: ctop + "px" });
            }
            if (this.hasClass("textC")) {
                var cleft = parseFloat(this.css("left")), ctop = parseFloat(this.css("top")), cwidth = this.width(), cheight = this.height(), tempArray = new Array();
                tempArray[0] = '<div id="wrapC" style="left:' + (cleft - 4) + 'px;top:' + (ctop - 4) + 'px;">';
                tempArray[1] = '</div>';
                this.addClass("acmove");
                this.wrap(tempArray.join(""));
                $("#wrapC").append('<div class="lftTop"></div><div class="lftBtm"></div><div class="rgtTop"></div><div class="rgtBtm"></div>');
            }
        }
    });
    //二维码以及logo上传后的图片加载
    $.loadPicture = function (t) {
        var parameter = {
            dftBig: 100
        }
        var width = t.width, height = t.height, x = parseInt((parameterMp.width - width) / 2), y = parseInt((parameterMp.height - height) / 2), sflag,
             zoom = 1, thanBig = (width >= height ? width : height), thanSmall = (width >= height ? height : width), cZindex, ox = 0, tempZindex = 15;
        function picCutting() {
            if (thanBig >= parameter.dftBig) {
                zoom = thanBig / parameter.dftBig;
                thanSmall = Math.round(thanSmall / zoom);
                if (width >= height) {
                    width = parameter.dftBig, height = thanSmall;
                }
                else
                    width = thanSmall, height = parameter.dftBig;
            }
            //else
            //{
            //    zoom=parameter.dftBig/thanBig;
            //    thanSmall=parseInt(thanSmall*zoom);
            //}

            x = parseInt((parameterMp.width - width) / 2), y = parseInt((parameterMp.height - height) / 2);

        }
        var transactioncid = $PlusContainer.find(".c .cContainer").attr("transid");
        if (t.getAttribute("Type") == 1)
            picCutting();
        else {
            parameter.dftBig = 82;
            picCutting();
        }
        //插入到logoJson
        logoJson.push({ LogoId: logoJson.length, 'FileUrlInfo_ID': t.getAttribute("FileUrlInfo_ID"), TemplateTransactionID: transactioncid, IsChange: true, LogoPath: t.getAttribute("LogoPath"), LogoUrl: t.getAttribute("LogoUrl"), LogoWidth: width, LogoHeight: height, LogoX: x, LogoY: y, Type: t.getAttribute("Type"), ZIndex: (t.getAttribute("ZIndex") == null ? 0 : t.getAttribute("ZIndex")) });
        if ($PlusContainer.find(".c .one").length) {
            sflag = t.getAttribute("Type") == 1 ? "faceLogo" : "faceCode";
            cZindex = parameterMp.faceZindex;
            ox = 0;
            tempZindex = parameterMp.faceZindex;
            parameterMp.faceZindex--;

        }
        else {
            sflag = t.getAttribute("Type") == 1 ? "backLogo" : "backCode";
            cZindex = parameterMp.backZindex;
            ox = 1;
            tempZindex = parameterMp.backZindex;
            parameterMp.backZindex--;
        }
        //data-width,data-height是定义成一百表示当更换logo时，要遵循100px的规则
        $PlusContainer.find(".c .cContainer").append('<img class="textC logox" ox="' + ox + '" logoindex="' + (logoJson.length - 1) + '" id="logonew' + (logoJson.length - 1) + '" data-x="' + x + '" data-y="' + y + '" data-width="' + width + '" data-height="' + height + '" src="' + t.src + '" alt=""  style=" left:' + x + 'px;top:' + y + 'px; width:' + (width) + 'px;height:' + height + 'px;' + (t.getAttribute("Type") == 7 ? 'z-index:3' : '') + '"/>');
        $PlusContainer.find(".slogoContainer").append('<div class="slogo ' + sflag + '" data-op="' + t.getAttribute("Type") + '"><div class="sl" id="s1new' + (logoJson.length - 1) + '" logoindex="' + (logoJson.length - 1) + '"><img id="dlogo-new' + (logoJson.length - 1) + '" src="' + t.src + '" alt="" /></div><div class="sr"><div class="sr1"><div class="changeLogo" style="z-index:' + cZindex + '" data-op="' + t.getAttribute("Type") + '" data-value="new' + (logoJson.length - 1) + '">更换' + (t.getAttribute("Type") == 1 ? 'LOGO' : '二维码') + '</div>' + (t.getAttribute("Type") == 1 && tempZindex == 15 ? '<a class="designLogo" target="_blank"  href="' + shejiLogo + '">设计LOGO</a>' : '') + '</div><div class="sr2"><div class="sr2-1">调整大小：</div><div class="jian"></div><div class="progress"><div class="' + (t.getAttribute("Type") == "1" ? 'sliderc' : 'Esliderc') + '" data-value="#logonew' + (logoJson.length - 1) + '"><div class="percentc"></div></div></div><div class="add"></div><div class="opLogo" data-op="' + t.getAttribute("Type") + '" data-value="#logonew' + (logoJson.length - 1) + '">隐藏' + (t.getAttribute("Type") == 1 ? 'LOGO' : '二维码') + '</div></div></div></div>');
    };
    $.loadText = function (t) {
        var alignVal = t.getAttribute("calign"), x = t.getAttribute("x"), y = (parameterMp.height - 15) / 2, ox = 0, $temps, sflag = "", dv = "";
        //判断是否是首次
        if (t.getAttribute("jg") == undefined) {
            x = parameterMp.width / 2, y = (parameterMp.height - 15) / 2;
            if ($PlusContainer.find(".c .one").length) {
                sflag = "faceText", dv = "face";
                ox = 0;
                $temps = $PlusContainer.find(".one");
            }
            else {
                sflag = "backText", dv = "back";
                ox = 1;
                $temps = $PlusContainer.find(".two");
            }
            t.setAttribute("x", x);
            t.setAttribute("calign", 2);
            t.setAttribute("ox", ox);
            t.setAttribute("id", "textnew" + (TextJson.length));
            t.setAttribute("jsonindex", TextJson.length);
            //t.setAttribute("style","z-index:1;top:"+y+"px;left:"+x+"px");
            t.style.ZIndex = 1;
            t.style.top = y + "px";
            t.className = "textC";
            $temps.append(t);
            alignVal = 2;
        }
        if (alignVal == "0") {
            t.style.left = x + "px";
            if ($(t).parent()[0].id == "wrapC") {
                $PlusContainer.find("#wrapC").css({ "left": x - 4 });
            }
        }
        else if (alignVal == "1") {
            t.style.left = x - t.width + "px";
            if ($(t).parent()[0].id == "wrapC") {
                $PlusContainer.find("#wrapC").css({ "left": x - t.width - 4 });
            }
        }
        else if (alignVal == "2") {
            t.style.left = x - t.width / 2 + "px";
            if ($(t).parent()[0].id == "wrapC") {
                $PlusContainer.find("#wrapC").css({ "left": x - t.width / 2 - 4 });
            }
        }
        else {
            t.style.left = x + "px";
            if ($(t).parent()[0].id == "wrapC") {
                $PlusContainer.find("#wrapC").css({ "left": x - 4 });
            }
        }
        t.removeAttribute("width");
        t.removeAttribute("height");
        if (t.getAttribute("jg"))
            judgeOverBorder(t);
        if (t.getAttribute("jg") == undefined) {
            var transactioncid = $PlusContainer.find(".c .cContainer").attr("transid");
            TextJson.push({ "TextAlign": 2, "CMYK": "0,0,0,100", "Text": "新增文字项", "TextFontSize": 13, "TemplateTransactionID": transactioncid, "TextFontColor": "#251E1C", "TextX": x, "TextY": y, "Type": 1, "TextFontType": "微软雅黑" });
            $PlusContainer.find("#stextContainer").append('<div class="stextCon ' + sflag + '" data-value="' + dv + '"><input id="inputnew' + (TextJson.length - 1) + '" class="stext" jsonindex="' + (TextJson.length - 1) + '" value="新增文字项" /></div>');
            var $owx = $PlusContainer.find(".PlusContainer-contexR-nav2");
            $owx.scrollTop($owx[0].scrollHeight - $owx[0].clientHeight);
            $("#textnew" + (TextJson.length - 1)).createNewDrag($("#wrapC"));
            $(".stext[jsonindex=" + (TextJson.length - 1) + "]").click();
            t.setAttribute("jg", 1);
        }
    };
    $.dataScroll = function () {
        var gundongTimer = 0;
        var halfHeight = parseInt($('.PlusContainer-headerR-Ul').height()) / 2;
        $PlusContainer.find(".PlusContainer-headerR-Ul").hover(function () {
            clearInterval(gundongTimer);
        }, function () {
            gundongTimer = setInterval(function () {
                if (parseInt($('.PlusContainer-headerR-Ul').css('top')) <= -parseInt(halfHeight)) {
                    $('.PlusContainer-headerR-Ul').css('top', '0px');
                }
                $('.PlusContainer-headerR-Ul').animate({ 'top': '-=' + 38 + 'px' }, 600);
            }, 2000)
        }).trigger("mouseleave");
    };
    $.dialogTip = function (val, Cax) {
        var objTmp = new Object(), arrayHtml = new Array();
        objTmp.containerCss = { width: '410px', height: '73px', 'background-color': '#fff', color: '#666', "font-size": "14px", "line-height": "24px", "padding": "25px 30px", "text-indent": "38px" };
        objTmp.closeHTML = '<a id="qyptClose" title="关闭"></a>';
        objTmp.focus = false;
        if (Cax) {
            objTmp.containerCss = { width: '466px', height: '144px', 'background-color': '#fff', color: '#666', "font-size": "16px", "text-align": "center" };
            arrayHtml[0] = '<p style="margin-top:40px;">' + val + '</p>';
            arrayHtml[1] = '<div class=" dialogOrangeBtn" style="width:108px;height:28px; margin:0 auto;line-height:28px; color:#fff; margin-top:22px;">确定</div>';
            objTmp.onShow = function () {
                $(".dialogOrangeBtn").click(function () {
                    $.modal.close();
                })
            }
        }
        else
            arrayHtml[0] = val;
        gaituCommonDialog(arrayHtml.join(""), objTmp);
    };
    $.checkEmpty = function (val) {
        var faceLength = $PlusContainer.find(".faceText").length, backLength = $PlusContainer.find(".backText").length;
        if (faceLength == 0 || backLength == 0) {
            $.dialogTip(val, 1);
            return 1;
        }
        else {
            var $temp = $PlusContainer.find(".faceText"), jc = 0;
            for (var jx = 0; jx < faceLength; jx++) {
                if ($.trim($($temp[jx]).find("input").val()) == "") {
                    jc++;
                }
            }
            if (jc == faceLength) {
                $.dialogTip(val, 1);
                return 1;
            }
            $temp = $PlusContainer.find(".backText"), jc = 0;
            for (var jx = 0; jx < backLength; jx++) {
                if ($.trim($($temp[jx]).find("input").val()) == "") {
                    jc++;
                }
            }
            if (jc == backLength) {
                $.dialogTip(val, 1);
                return 1;
            }
        }
        return 0;
    };
})(jQuery);
//定义全局$变量。
var $PlusContainer = $("#PlusContainer"), $this;
$("#PlusContainer").find(".o3").hover(function () {
    $this = $(this);
    $this.find("div").removeClass("gt_hidden");
}, function () {
    $this = $(this);
    $this.find("div").addClass("gt_hidden");
});
$("#PlusContainer").find(".PlusContainer-search-3").hover(function () {
    $this = $(this);
    $this.find(".s1").css({ "background-position": "0px -305px" });
    $this.find(".s2").css({ "color": "#f60" });
    $this.find(".s3").css({ "background-position": "-246px -152px" });
    $this.find(".recently").removeClass("gt_hidden");
},
function () {
    $this = $(this);
    $this.find(".s1").css({ "background-position": "0px -327px" });
    $this.find(".s2").css({ "color": "#666666" });
    $this.find(".s3").css({ "background-position": "-256px -152px" });
    $this.find(".recently").addClass("gt_hidden");
});
$("#PlusContainer").find(".in2").hover(function () {
    $this = $(this);
    if ($this.attr("active") == "1")
        $(this).css({ "background-position": "-54px 0" });
},
function () {
    $this = $(this);
    if ($this.attr("active") == "1")
        $(this).css({ "background-position": "-27px 0" });
}
);
$("#ckfwcity").hover(function () {
    $(this).css("color", "#f60");
    $("#fwctspan").css("background-position", "-246px -152px");
    $(".city_menu2").show();
}, function () {
    $(this).css("color", "#666");
    $("#fwctspan").css("background-position", "-256px -152px");
    $(".city_menu2").hide();
});
//最近使用，最近保存，最近收藏
$("#PlusContainer .recently").find(".core").hover(function () {
    $('.rencImgC').hide();
    $('.rencImgC .ccclist').hide();
    $this = $(this);
    $this.siblings(".core").css({ color: '#666', 'background-color': '#e4dddd', 'border-color': '#d9cebd' });
    $this.css({ color: '#fff', 'background-color': '#f60', 'border-color': '#cd6702' });
    var index = $this.index();
    obj.url = commonUrl;
    if (index == 0) {
        $("#tipsLogin").remove();
        if ($('.rencImgC .clist1').attr("load") == "1") {
            $('.rencImgC').show();
            $('.rencImgC .clist1').show();
        }
        else {
            obj.data = "Operation=6";
            obj.dataType = "json";
            commonAjaxRequest(obj, function (json) {
                if (json != "error") {
                    var result_html = '';
                    if (json.length > 0) {
                        $.each(json, function (key, val) {
                            result_html += '<a class="imgCCC" ' + (key % 2 == 0 ? 'style="margin-right:16px;"' : '') + ' href="' + val.Href + '" title="' + val.Title + '"><img src="' + val.Src + '" class="' + val.Format + '"  alt="' + val.Title + '"></a>';
                        });
                        $('.rencImgC').show();
                        $('.rencImgC .clist1').html(result_html).attr("load", 1).show();
                    }
                }
            });
        }
    }
    else if (index == 1) {
        if (!$.cookie("uid")||$.cookie("uid")=="") {
            var result_html = '<p id="tipsLogin" style="padding-top:14px;clear:both;">您还没有登录，现在去<a class="lohover" onclick="popup_login(\'callbarkord\');return false;" style="color:#2ca9e0;" href="javascript:void(0)">登录</a>，您还可以去<a href="' + reg + '" class="lohover" style="color:#2ca9e0;" target="_blank">注册</a></p>';
            if (!$("#tipsLogin").length)
                $('.recently').append(result_html);
            return;
        }
        if ($('.rencImgC .clist2').attr("load") == "1") {
            $('.rencImgC').show();
            $('.rencImgC .clist2').show();
        }
        else {
            obj.data = "Operation=2";
            obj.dataType = "json";
            commonAjaxRequest(obj, function (json) {
                if (json != "error") {
                    var result_html = '';
                    if (json.length > 0) {
                        $.each(json, function (key, val) {
                            result_html += '<a class="imgCCC" ' + (key % 2 == 0 ? 'style="margin-right:16px;"' : '') + ' href="' + val.Href + '" title="' + val.Title + '"><img src="' + val.Src + '" class="' + val.Format + '"  alt="' + val.Title + '"></a>';
                        });
                        $('.rencImgC .clist2').html(result_html).attr("load", 1).show();
                        $('.rencImgC').show();
                    }
                }
            });
        }
    }
    else if (index == 2) {
        if (!$.cookie("uid")||$.cookie("uid")=="") {
            var result_html = '<p id="tipsLogin" style="padding-top:14px;clear:both;">您还没有登录，现在去<a class="lohover" onclick="popup_login(\'callbarkord\');return false;" style="color:#2ca9e0;" href="javascript:void(0)">登录</a>，您还可以去<a href="' + reg + '" class="lohover" style="color:#2ca9e0;" target="_blank">注册</a></p>';
            if (!$("#tipsLogin").length)
                $('.recently').append(result_html);
            return;
        }
        if ($('.rencImgC .clist3').attr("load") == "1") {
            $('.rencImgC').show();
            $('.rencImgC .clist3').show();
        }
        else {
            obj.data = "Operation=3";
            obj.dataType = "json";
            commonAjaxRequest(obj, function (json) {
                if (json != "error") {
                    var result_html = '';
                    if (json.length > 0) {
                        $.each(json, function (key, val) {
                            result_html += '<a class="imgCCC" ' + (key % 2 == 0 ? 'style="margin-right:16px;"' : '') + ' href="' + val.Href + '" title="' + val.Title + '"><img src="' + val.Src + '" class="' + val.Format + '"  alt="' + val.Title + '"></a>';
                        });
                        $('.rencImgC .clist3').html(result_html).attr("load", 1).show();
                        $('.rencImgC').show();
                    }
                }
            });
        }
    }
},
function () {
}
);
//圆角预览
$("#PlusContainer").on("click", ".o1", function () {
    $this = $(this);
    $this.attr("checkeds") || $this.attr("checkeds", 0);
    if (!parseInt($this.attr("checkeds"))) {
        $this.css("background-position", "-198px -120px");
        $this.attr("checkeds", "1");
        $PlusContainer.find(".circles").show();
    }
    else {
        $this.css("background-position", "-213px -120px");
        $this.attr("checkeds", "0");
        $PlusContainer.find(".circles").hide();
    }
})
.on("click", ".t2", function () {
    var transactioncid = $PlusContainer.find(".c .cContainer").attr("transid");
    var ojson = { "TextAlign": 2, "CMYK": "0,0,0,100", "Text": "新增文字项", "TextFontSize": 13, "TemplateTransactionID": transactioncid, "TextFontColor": "#251E1C", "TextX": 15, "TextY": 15, "Type": 1, "TextFontType": "微软雅黑" };
    var img = new Image(), imgWid = 69;
    if (document.addEventListener) {
        img.addEventListener("load", function () { $.loadText(this) }, false);
    }
    else if (document.attachEvent) {
        img.attachEvent("onload", function () { $.loadText(img); });
    }
    img.src = drawTextImageUrl + "?operation=1&random=" + Math.random() + "&text=" + encodeURIComponent(JSON.stringify(ojson));
    return false;
})
.on("click", ".t3", function (e, erid) {
    //二维码个数判断
    if (!erid)
        if ($PlusContainer.find(".slogo[data-op=7]:visible").length >= 1) {
            $.dialogTip("您好，名片正面二维码和反面二维码仅支持各制作一个。如果您还有其它二维码，请直接<a style='color:#29b0ea;cursor:pointer;' id='scewm'>上传图片</a>即可。如果您想更换刚制作的二维码内容，请在下方编辑框内点击“更换二维码”即可。");
            return false;
        }
var objTmp = new Object(), arrayHtml = new Array();
objTmp.containerCss = { width: '372px', height: '375px', padding: '0 0 0 28px', 'background-color': '#fff', color: '#666' };
objTmp.closeHTML = '<a id="qyptClose" title="关闭"></a>';
objTmp.focus = false;
objTmp.onShow = function () {
    var tom = {};
    var objs = {};
    objs.url = drawTextImageUrl;
    objs.type = "get";
    objs.dataType = "jsonp";
    objs.jsonp = "jsonp_callback";
    $("#makeEwm").click(function () {

        var leng = $(".ewmInput").length, si = 0;
        $(".ewmInput").each(function () {
            $this = $(this);
            var temps = $this.attr("tempAttr");
            tom[temps] = $this.val();
            if ($.trim(tom[temps]) == "") {
                si++;
            }
        });
        $("#donotEmpty").remove();
        if (si == leng) {
            $(".dialogOrangeBtn").append('<div id="donotEmpty" style="position:absolute;right:-89px;top:0px;color:red;font-size:13px;font-weight:normal;">内容不能为空</div>');
            return false;
        }
        $("#makeEwm").html("生成二维码中").css({ "background": "url(http://gtcdn1.gaitu.com/images/enterprise/waiting.gif) no-repeat #ff944d 116px 18px" });
        objs.data = "operation=3&vCardJson=" + encodeURIComponent(JSON.stringify(tom));
        commonAjaxRequest(objs, function (data) {
            if (erid) {
                $.modal.close();
                $("#logo" + erid)[0].src = data;
                $("#dlogo-" + erid)[0].src = data;
                if (erid.indexOf("new") > -1) {
                    logoJson[erid.slice(3)].LogoPath = data;
                    logoJson[erid.slice(3)].LogoUrl = data;
                }
                else {
                    for (var jf = 0; jf < logoJson.length; jf++) {
                        if (logoJson[jf].LogoId == erid) {
                            logoJson[jf].LogoPath = data;
                            logoJson[jf].LogoUrl = data;
                            logoJson[jf].OriginalThumbnailsName = data;
                            break;
                        }
                    }
                }
                return false;
            }
            if (data != "error") {
                $.modal.close();
                var img = new Image();
                img.setAttribute("FileUrlInfo_ID", 1014);
                img.setAttribute("LogoPath", data);
                img.setAttribute("LogoUrl", data);
                img.setAttribute("Type", 7);
                if (document.addEventListener) {
                    img.addEventListener("load", function () { $.loadPicture(this) }, false);
                }
                else if (document.attachEvent) {
                    img.attachEvent("onload", function () { $.loadPicture(img); });
                }
                //img
                img.src = data;

            }
            else {
                $.modal.close();
            }
        });
    });
};
arrayHtml[0] = '<p style="font-size:16px; line-height:20px;padding:24px 0 12px 0px;width:341px;border-bottom:1px solid #dddddd;margin-bottom:14px;">编辑二维码内容</p>';
arrayHtml[1] = '<div style="width:341px;border-bottom:1px solid #dddddd;height:180px; overflow:auto;margin-bottom:20px;"><table>';
var str1 = '', txt = '', temp = { shouji: 0, dianhua: 0, name: 0, zw: 0, dz: 0, yx: 0, wz: 0 };
for (var i = 0, jindex = 0; i < TextJson.length; i++) {
    jindex = TextJson[i].Text.indexOf("：") == -1 ? (TextJson[i].Text.indexOf(":") == -1 ? 0 : TextJson[i].Text.indexOf(":") + 1) : TextJson[i].Text.indexOf("：") + 1;
    if (TextJson[i].isDel)
        txt = '';
    else
        txt = TextJson[i].Text.substr(jindex);
    if (/手机/.test(TextJson[i].PropertyText) && !temp.shouji) {
        temp.shouji = 1;
        str1 += '<tr><td style="padding:10px 10px 0 0;">手机：</td><td><input type="text" class="ewmInput" tempAttr="CELLTel" value="' + txt + '" /></td></tr>';
    }
    else if (/姓名/.test(TextJson[i].PropertyText) && !temp.name) {
        temp.name = 1;
        str1 += '<tr><td style="padding:10px 10px 0 0;">姓名：</td><td><input type="text" class="ewmInput" tempAttr="FN" value="' + txt + '" /></td></tr>';
    }
    else if (/职位/.test(TextJson[i].PropertyText) && !temp.zw) {
        temp.zw = 1;
        str1 += '<tr><td style="padding:10px 10px 0 0;">职位：</td><td><input type="text" class="ewmInput" tempAttr="TITLE" value="' + txt + '" /></td></tr>';
    }
    else if (/公司/.test(TextJson[i].PropertyText) && !temp.wz) {
        temp.wz = 1;
        str1 += '<tr><td style="padding:10px 10px 0 0;">公司：</td><td><input type="text" class="ewmInput" tempAttr="ORG" value="' + txt + '" /></td></tr>';
    }
}
if (!temp.shouji) {
    str1 += '<tr><td style="padding:10px 10px 0 0;">手机：</td><td><input type="text" class="ewmInput" tempAttr="CELLTel" value="" /></td></tr>';
}
arrayHtml[2] = str1;
arrayHtml[3] = '</table></div>';
arrayHtml[4] = '<div class="dialogOrangeBtn" id="makeEwm" style="width:146px;height:34px;line-height:34px;font-weight:bold;position:relative;">确定生成二维码</div>';
arrayHtml[5] = '<p style="color:#999;font-size:13px; line-height:22px;padding-top:8px;">注：如果您已有二维码图片，请直接<span id="scewm" style="color:#29b0ea;cursor:pointer;">上传图片</span>即可</p>';
gaituCommonDialog(arrayHtml.join(""), objTmp);
})
    .on("focus", ".in1", function () {
        //输入框活动焦点
        $this = $(this);
        $this.css({ color: '#666' });
        if ($this.val() == '请输入模板编号') {
            $this.val('');
        }
    })
    .on("paste", ".in1", function (e) {
        $this.css({ 'color': '#666', 'border-color': '#ff6600' });
        $this.siblings("input").css({ "background-position": "-27px 0" }).attr("active", 1);
    })
    .on("blur", ".in1", function () {
        $this = $(this);
        $this.css({ color: '#999' });
        if ($.trim($this.val()) == "")
            $this.val("请输入模板编号")
    })
    .on("keyup", ".in1", function (e) {
        if ($(".tempidEmpty").length) {
            $(".tempidEmpty").remove();
        }
        $this = $(this);
        this.value = this.value.replace(/\D/g, '');
        var value = this.value
        if (value != "") {
            $this.css({ 'color': '#666', 'border-color': '#ff6600' });
            $this.siblings("input").css({ "background-position": "-27px 0" }).attr("active", 1);
        }
        else {
            $this.css({ 'color': '#999', 'border-color': '#dcdcdc' });
            $this.siblings("input").css({ "background-position": "0 0" }).attr("active", 0);

        }
        obj.url = commonUrl;
        obj.data = 'Operation=8&templateid=' + value;
        if (e.which == 13) {
            commonAjaxRequest(obj, function (data) {
                if (parseInt(data) == "0") {
                    $PlusContainer.find(".PlusContainer-search-2").find(".tempidEmpty").remove();
                    var array = new Array();
                    array[0] = '<div class="tempidEmpty">该模板不存在！';
                    array[1] = '<div class="si"></div>';
                    array[2] = '</div>';
                    $PlusContainer.find(".PlusContainer-search-2").append(array.join("")).find(".tempidEmpty").show().animate({ top: "-63px" }, 500);
                    return false;
                }
                window.location.href = tempUrl.replace(/\d+/, value);
            });
        }
        return false;
    })
//点击正面
    .on("click", ".onec,#faceTab", function () {
        $this = $(this);
        //名片正面被点击
        var faceJudge = /onec/.test($this.attr("class")) || /tabs/.test($this.attr("class"))
        //正面被点击
        if (!($this.hasClass("c") || $this.hasClass("ccc"))) {
            //反面图片去掉c
            $PlusContainer.find(".twoc").removeClass("c");
            $PlusContainer.find(".onec").addClass("c");
            //正面的编辑器出现
            $PlusContainer.find("#backTab").removeClass("ccc");
            $PlusContainer.find("#faceTab").addClass("ccc");
            $PlusContainer.find(".faceLogo").removeClass("gt_hidden");
            $PlusContainer.find(".backLogo").addClass("gt_hidden");
            $PlusContainer.find(".faceText").removeClass("gt_hidden");
            $PlusContainer.find(".backText").addClass("gt_hidden");
            $PlusContainer.find(".backCode").addClass("gt_hidden");
            $PlusContainer.find(".faceCode").removeClass("gt_hidden");
            //$this.createNewDrag($("#wrapC"),$this);
        }
        return false;
    })//点击反面
    .on("click", ".twoc,#backTab", function () {
        $this = $(this);
        //名片反面被点击
        if (!($this.hasClass("c") || $this.hasClass("ccc"))) {
            //反面图片去掉c
            $PlusContainer.find(".onec").removeClass("c");
            $PlusContainer.find(".twoc").addClass("c");
            //正面的编辑器出现
            $PlusContainer.find("#faceTab").removeClass("ccc");
            $PlusContainer.find("#backTab").addClass("ccc");
            $PlusContainer.find(".backLogo").removeClass("gt_hidden");
            $PlusContainer.find(".faceLogo").addClass("gt_hidden");
            $PlusContainer.find(".backText").removeClass("gt_hidden");
            $PlusContainer.find(".faceText").addClass("gt_hidden");
            $PlusContainer.find(".faceCode").addClass("gt_hidden");
            $PlusContainer.find(".backCode").removeClass("gt_hidden");
            //$this.createNewDrag($("#wrapC"),$this);
        }
        return false;
    })
    .on("click", ".ff1", function () {
        $this = $(this);
        var shouqi = $this.attr("shouqi") || 0;
        if (!parseInt(shouqi)) {
            $PlusContainer.find(".PlusContainer-contexR-1").stop().animate({ height: "26px" }, 500, function () {
                $PlusContainer.find(".PlusContainer-contexR-2").height("202");
                $this.attr("shouqi", "1").addClass("ff2").attr("title", "展开");
            });
        }
        else {
            $PlusContainer.find(".PlusContainer-contexR-2").height("142");
            $PlusContainer.find(".PlusContainer-contexR-1").stop().animate({ height: "86px" }, 500, function () {
                $this.attr("shouqi", "0").removeClass("ff2").attr("title", "收起");
            });
        }

    })
    .on("click", ".opLogo", function () {
        $this = $(this);
        var $currentLogo = $($this.attr("data-value"));
        if ($currentLogo.is(":visible")) {
            $currentLogo.hide();
            this.innerHTML = "显示" + ($this.attr("data-op") == 7 ? "二维码" : "LOGO");
            logoJson[$currentLogo.attr("logoindex")].hidden = 1;
            var idt = $this.attr("data-value").slice(1);
            removeValueOfArray(idt, overBorderArray);
            if (overBorderArray.length == 0) {
                $(".PlusContainer-contexL-2").addClass("gt_hidden");
            }
            $this.parents(".slogo").removeClass("xfError").find(".imgTips").remove();
        }
        else {
            $currentLogo.show();
            judgeOverBorder($currentLogo[0]);
            this.innerHTML = "隐藏" + ($this.attr("data-op") == 7 ? "二维码" : "LOGO");
            logoJson[$currentLogo.attr("logoindex")].hidden = 0;
        }
    })
    .on("click", ".changeLogo", function (e) {
        $this = $(this);
        var tef = $this.attr("fi") || 0;
        if (!parseInt(tef)) {
            logo_lmid = $this.attr("data-value");
            if ($this.attr("data-op") != 7) {
                logoType = "oldLogo";
                $PlusContainer.find(".logoLayer").addClass("gt_hidden");
                $PlusContainer.find(".t1").attr("cflag", 0);
                $("#logoBox").parent().attr("fi", "0");
                $("#logoBox").remove();
                var temp = new Array();
                temp[0] = '<div id="logoBox" style="position:absolute;left:0px;top:34px;z-index:4; padding:15px 0px 0px 21px; width:258px; height:46px; background-color:#fff;border:2px solid #f60; color:#666; font-size:13px;">';
                temp[1] = '<div class="uploadLogo" style="cursor:pointer;border:1px solid #d9cebd; background-color:#e4dddd; width:75px; height:29px; text-align:center;margin-right:2px;float:left;line-height:29px;">上传LOGO</div>';
                temp[2] = '<div class="getLogo" style="cursor:pointer;border:1px solid #d9cebd; background-color:#e4dddd; width:75px; height:29px; text-align:center;margin-right:2px;float:left;line-height:29px;">挑选LOGO</div>';
                temp[3] = '<div class="myLogo" style="cursor:pointer;border:1px solid #d9cebd; background-color:#e4dddd; width:75px; height:29px; text-align:center;margin-right:2px;float:left;line-height:29px;">我的LOGO</div>';
                temp[4] = '</div>';
                $this.append(temp.join(""));
                $this.attr("fi", "1");
            }
            else {
                $PlusContainer.find(".t3").trigger("click", [$this.attr("data-value")]);
            }
        }
        else {
            $("#logoBox").remove();
            $this.attr("fi", "0");
        }
        return false;
    })
    .on("click", ".r3 .t1", function () {
        $this = $(this);
        //限制上传图片个数
        if ($PlusContainer.find(".slogo[data-op=1]:visible").length >= 4) {
            $.dialogTip("您好，名片正面图片（logo）和反面图片（logo）仅支持各上传四张。如果您还有其它图片，建议您将多个图片合成一个图片后在进行上传。");
            return false;
        }
        var cflag = $this.attr("cflag") || 0;
        $PlusContainer.find(".changeLogo").attr("fi", 0);
        $("#logoBox").remove();
        if (!parseFloat(cflag)) {
            $PlusContainer.find(".logoLayer").removeClass("gt_hidden");
            $this.attr("cflag", 1);
            logoType = "newLogo";
        }
        else {
            $PlusContainer.find(".logoLayer").addClass("gt_hidden");
            $this.attr("cflag", 0);
        }
        return false;
    })
    .on("click", ".uploadLogo", function () {

        var arrayHtml = new Array();
        arrayHtml[0] = '<div id="ifr-dialog" >';
        arrayHtml[1] = '<iframe frameborder="0" scrolling="no" id="ifr-dialog-container" frameborder="0" src="' + upload_frm_url + '" class="box-iframe"></iframe>';
        arrayHtml[2] = '</div>';
        $.modal(arrayHtml.join(""), { opacity: 30, close: true, closeHTML: '<a id="qyptClose" title="关闭" style="right:-36px;"></a>', overlayClose: false, "containerId": "ifr-dialog-content", containerCss: { width: "480px", height: "150px", "background-color": "#ffffff", padding: "0px"} });

    })
    .on("click", ".getLogo,.myLogo", function () {
        var objTmp = new Object(), arrayHtml = new Array(), frameUrl = '', fow = 0;
        if (/getLogo/.test($(this).attr("class"))) {
            frameUrl = $("#hid_LogoUrl").val() + "logo/logobox.aspx";
            fow = 1;
        }
        else
            frameUrl = $("#hid_LogoUrl").val() + "logo/mylogo.aspx";
        objTmp.containerCss = { width: '450px', height: (fow == 1 ? '465px' : '260px'), padding: '28px', 'background-color': '#fff', color: '#666' };
        objTmp.closeHTML = '<a id="qyptClose" title="关闭"></a>';
        objTmp.focus = false;
        arrayHtml[0] = '<p style=" font-size:16px; line-height:18px; padding-bottom:13px; border-bottom:1px solid #dddddd;">挑选LOGO</p>';
        arrayHtml[1] = '<iframe src="' + frameUrl + '" scrolling="no" frameborder="no" style="border: none; width: 100%; height: 100%; overflow: hidden;"></iframe>';
        gaituCommonDialog(arrayHtml.join(""), objTmp);
    })
    .on("click", "#canclePrint", function () {
        $PlusContainer.find("#overAll").hide();
        $PlusContainer.find(".o3").css("z-index", 305);
        $PlusContainer.find(".PlusContainer-contexL-pic").removeClass("PlusContainer-f60");
        $PlusContainer.find(".bigclient_print").hide();
        $PlusContainer.find("#printfc").removeClass("backWaiting").attr("doing", "0");
    });
$PlusContainer.on("blur", ".stext",function(){
    if($(this).attr("moretext")&&$(this).attr("moretext")=="1")
        $(this).addClass("borderColor-FFAD33x").parent().append('<div class="xfError"><div class="errX">×</div>该文字超出裁切线范围，请重新调整</div>');
    else
        $(this).removeClass("borderColor-FFAD33x").css("color", "#999").parent().find(".xfError").remove();
});
$PlusContainer.on("click", ".stext", function (e, dragClick) {
    $this = $(this);
    var index = $this.attr("jsonindex");
    clearAllStyleToStar(index);
    $PlusContainer.find(".RgbCon").addClass("gt_hidden");
    $PlusContainer.find(".fontT").css("cursor", "pointer");
    $PlusContainer.find(".fontS").css("cursor", "pointer");
    $PlusContainer.find(".str4").attr("cFlag", "0")
    $(".borderColor-FFAD33").removeClass("borderColor-FFAD33");
    $this.css({ "color": "#666" }).addClass("borderColor-FFAD33");
    //if(TextJson[$this.attr("jsonindex")].TextAlign!=3)
    $PlusContainer.find(".fontStd").addClass("fontSt").removeClass("fontStd");
    //else
    //$PlusContainer.find(".fontSt").addClass("fontStd").removeClass("fontSt");
    $PlusContainer.find(".nike").addClass("addi").removeClass("nike");
    $PlusContainer.find(".fontS").css("color", "#666").attr("active", 1).find("span").html(parseInt(TextJson[$this.attr("jsonindex")].TextFontSize) + "号");
    $PlusContainer.find(".fontT").attr("active", 1);
    $PlusContainer.find(".s1Select").attr("cflag", 0).removeClass("s1Select");
    //不是点击左侧图片触发
    if (!dragClick) {
        $PlusContainer.find(".textC[jsonindex=" + $this.attr("jsonindex") + "]").createNewDrag($("#wrapC"));
        $(document.body).unbind("keydown");
    }
    //默认字体处理
    if (!TextJson[$this.attr("jsonindex")].TextFontTypeC) {
        TextJson[$this.attr("jsonindex")].TextFontTypeC = TextJson[$this.attr("jsonindex")].TextFontType;
    }
    var fontTjs = $PlusContainer.find(".fontFamily a[data-value=" + TextJson[$this.attr("jsonindex")].TextFontType + "]");
    if (fontTjs.length) {
        var str = fontTjs.css("background-position"), strsp = str.split(" ");
        $PlusContainer.find(".fontT").css({ "background-position": function () {
            return "-8px" + " " + (parseFloat(strsp[1]) + 4) + "px";
        } 
        })
    }
    else {
        $PlusContainer.find(".fontT").css({ "background-position": "-8px 4px" });
        $PlusContainer.find(".fontFamily a:eq(0)").attr("data-value", TextJson[$this.attr("jsonindex")].TextFontTypeC);
    }
    if (!getsCookie("firstTips")) {
        $PlusContainer.find(".one").append('<div class="tipsMove" style="width:' + (Format == 'H' ? '388' : '481') + 'px">注：使用键盘上下左右键或鼠标拖动红色文本框可移动该元素。</br>推荐使用“键盘上下左右键”来使用蓝色对齐线功能。<span>不再提示</span></div>');
        $PlusContainer.find(".PlusContainer-search-2").append('<div class="tipsMove" style="height: 32px;width: 348px;line-height: 32px;text-align: center;left: -30px;top: 32px;">如您需要增加“文字内容”请点击下方文字项即可<span style="vertical-align:inherit">不再提示</span></div>');
        $PlusContainer.find(".PlusContainer-search-2").append('<div class="TriangleDown"></div>');
        $PlusContainer.find(".tipsMove").slideDown();
        setsCookie("firstTips", "twoOne");
        setTimeout(function () {
            if ($PlusContainer.find(".tipsMove").length) {
                $PlusContainer.find(".tipsMove").slideUp();
                $PlusContainer.find(".TriangleDown").remove();
            }
        }, 15000)
    }
    return false;
})
    .on("click", ".tipsMove span", function () {
        $(this).parent().slideUp();
        if($(this).parents(".PlusContainer-search-2").find(".TriangleDown").length)
        {
            $(this).parents(".PlusContainer-search-2").find(".TriangleDown").remove();
        }
    })
//编辑项的点击
    .on("click", ".fontSt .f7", function () {
        $this = $(this);
        var o = parseFloat($this.attr("cFlag") || 0), index = $PlusContainer.find(".borderColor-FFAD33").attr("jsonindex"), $imgDom = $("#text" + $PlusContainer.find(".borderColor-FFAD33").attr("id").slice(5));
        if (!o) {
            if ($this.hasClass("str5") || $this.hasClass("str6") || $this.hasClass("str7")) {
                if (TextJson[index].TextAlign == 3) {
                    return false;
                }
                $PlusContainer.find(".str5").removeClass("strhover");
                $PlusContainer.find(".str6").removeClass("strhover");
                $PlusContainer.find(".str7").removeClass("strhover");
                $this.addClass("strhover");
                textStyleJudge(index, $imgDom, 1);
            }
            else {
                $this.addClass("strhover");
                textStyleJudge(index, $imgDom);
            }

            if (!$this.hasClass("str4")) {
                toGet($imgDom, index);
            }
            else {
                $PlusContainer.find(".RgbCon").removeAttr("style").removeClass("gt_hidden").attr("CbackColor", 2);
                $PlusContainer.find(".ToDefault").remove();
                $PlusContainer.find(".g4").removeClass("ghover").attr("cflag", 0);
            }
            $this.attr("cFlag", "1");
        }
        else {
            if ($this.hasClass("str1") || $this.hasClass("str2") || $this.hasClass("str3") || $this.hasClass("str4"))
                $this.removeClass("strhover");
            else {
                //居中居左居右不让重复点击
                return false;
            }
            textStyleJudge(index);
            if (!$this.hasClass("str4")) {
                toGet($imgDom, index);
            }
            $this.attr("cFlag", "0");
        }
        return false;
    })
    .on("focus", ".stext", function () {
        $this = $(this);
        $this.css("color", "#666");
    })
    .on("blur", ".stext", function () {
        $this = $(this);
        $this.css("color", "#999");
    })
    .on("click", ".stepone .nextStep", function () {
        $PlusContainer.find(".changePositon").removeClass("changePositon");
        $PlusContainer.find(".changePositon1").removeClass("changePositon1");
        $PlusContainer.find("#overAll").css("z-index", "999");
        $PlusContainer.find(".Light").remove();
        $PlusContainer.find(".step").remove();
        guideone[0] = '<div class="step steptwo">';
        guideone[1] = '<div class="nextStep"></div>';
        guideone[2] = '<div class="closeStep"></div>';
        guideone[3] = '</div>';
        guidetwo[0] = '<div class="secondLight Light"></div>';
        $PlusContainer.find(".PlusContainer-contexR-1").addClass("changePositon").removeAttr("style").append(guideone.join("")).append(guidetwo.join(""));
        return false;
    })
    .on("click", ".steptwo .nextStep", function () {
        $PlusContainer.find(".changePositon").removeClass("changePositon");
        $PlusContainer.find(".Light").remove();
        $PlusContainer.find(".step").remove();
        guideone[0] = '<div class="step stepthree">';
        guideone[1] = '<div class="nextStep"></div>';
        guideone[2] = '<div class="closeStep"></div>';
        guideone[3] = '</div>';
        guidetwo[0] = '<div class="threeLight Light"></div>';
        $PlusContainer.find(".PlusContainer-contexR-1").css("overflow", "hidden");
        $PlusContainer.find(".PlusContainer-contexL").addClass("changePositon").append(guideone.join("")).append(guidetwo.join(""));
        return false;
    })
    .on("click", ".stepthree .nextStep", function () {
        $PlusContainer.find(".changePositon").removeClass("changePositon");
        $PlusContainer.find(".Light").remove();
        $PlusContainer.find(".step").remove();
        guideone[0] = '<div class="step stepfour">';
        guideone[1] = '<div class="nextStep"></div>';
        guideone[2] = '<div class="closeStep"></div>';
        guideone[3] = '</div>';
        guidetwo[0] = '<div class="fourLight Light"></div>';
        $PlusContainer.find(".PlusContainer-contexR-2").addClass("changePositon").append(guideone.join("")).append(guidetwo.join(""));
        return false;
    })
    .on("click", ".stepfour .nextStep", function () {
        $PlusContainer.find("#overAll").css("z-index", "2").hide();
        //有position属性的移出
        $PlusContainer.find(".changePositon").removeClass("changePositon");
        $PlusContainer.find(".Light").remove();
        $PlusContainer.find(".step").remove();
        return false;
    })
    .on("click", ".closeStep", function () {
        $PlusContainer.find("#overAll").css("z-index", "2").hide();
        $PlusContainer.find(".PlusContainer-contexR-1").css("overflow", "hidden");
        //有position属性的移出
        $PlusContainer.find(".changePositon").removeClass("changePositon");
        $PlusContainer.find(".changePositon1").removeClass("changePositon1");
        $PlusContainer.find(".Light").remove();
        $PlusContainer.find(".step").remove();
        return false;
    })
    .on("click", ".addi .g1", function () {
        if (!getsCookie("shxwz")) {
            $(this).addClass("g1Dis").removeClass("g1");
            $PlusContainer.find(".errorcx").removeClass("gt_hidden");
            setTimeout(function () {
                $PlusContainer.find(".errorcx").addClass("gt_hidden");
            }, 15000)
        }
    })
    .on("click", ".errorcx b,.errorcx span", function () {
        if (!getsCookie("shxwz")) {
            $(".errorcx").addClass("gt_hidden");
            setsCookie("shxwz", "522");
            $PlusContainer.find(".g1").css({ "color": "#999", "cursor": "default", "background-position": "3px -156px" });

        }

        return false;
    })
    .on("click", ".addi .g3", function () {
        //删除
        $this = $(this);
        var index = 0, $imgDom, propertyVal, theId = 0;
        if ($PlusContainer.find(".borderColor-FFAD33").length) {
            index = $PlusContainer.find(".borderColor-FFAD33").attr("jsonindex"), $imgDom = $("#text" + $PlusContainer.find(".borderColor-FFAD33").attr("id").slice(5)),
                propertyVal = $PlusContainer.find(".borderColor-FFAD33").parent().attr("data-value"), theId = $imgDom.attr("id");
            if ($imgDom.parent()[0].id == "wrapC")
                $("#wrapC").remove();
            else
                $imgDom.remove();
            TextJson[index].isDel = 1;
            $PlusContainer.find(".borderColor-FFAD33").parent().hide(500).remove();
            if ($PlusContainer.find(".stextCon[data-value=" + propertyVal + "]").length) {
                $PlusContainer.find(".stextCon[data-value=" + propertyVal + "]").eq(0).find(".stext").addClass("borderColor-FFAD33").click();
            }
        }
        else {
            index = $PlusContainer.find(".s1Select").attr("logoindex"), $imgDom = $("#logo" + $PlusContainer.find(".s1Select").attr("id").slice(2)), theId = $imgDom.attr("id");
            if ($imgDom.parent()[0].id == "wrapC")
                $("#wrapC").remove();
            else
                $imgDom.remove();
            logoJson[index].hidden = 1;
            $PlusContainer.find(".s1Select").parent().hide(500).remove();
        }
        removeValueOfArray(theId, overBorderArray);
        if (overBorderArray.length == 0) {
            $(".PlusContainer-contexL-2").addClass("gt_hidden");
        }
        return false;
    })
    .on("click", ".Rgbcolor2Square", function () {
        $this = $(this);
        var flag = $this.parents(".RgbCon").attr("cbackcolor");
        if (flag == "1") {
            TemplateTransactionJson[0].BackgroundColor = $this.attr("data-color");
            TemplateTransactionJson[1].BackgroundColor = $this.attr("data-color");
            //改变背景图
            $PlusContainer.find(".cContainer").removeAttr("style").css({ "background-color": $this.attr("data-color") });
            $this.parents(".RgbCon").removeAttr("style").addClass("gt_hidden");
            $PlusContainer.find(".g4").attr("cflag", '0').removeClass("ghover");
            $(".imgTutu").hide();
        }
        else if (flag == "2") {
            var index = $PlusContainer.find(".borderColor-FFAD33").attr("jsonindex"), $imgDom = $("#text" + $PlusContainer.find(".borderColor-FFAD33").attr("id").slice(5));
            TextJson[index].TextFontColor = $this.attr("data-color");
            TextJson[index].CMYK = $this.attr("cmyk");
            toGet($imgDom, index);
            $this.parents(".RgbCon").removeAttr("style").addClass("gt_hidden");
            $PlusContainer.find(".str4").attr("cflag", '0').removeClass("strhover");
        }
        return false;
    })
    .on("hover", ".Rgbcolor2Square", function () {
        $this = $(this);
        var strSplit = $this.attr("cmyk").split(",");
        $PlusContainer.find(".Rgbcolor2-c").val(strSplit[0]);
        $PlusContainer.find(".Rgbcolor2-m").val(strSplit[1]);
        $PlusContainer.find(".Rgbcolor2-y").val(strSplit[2]);
        $PlusContainer.find(".Rgbcolor2-k").val(strSplit[3]);
        $PlusContainer.find(".Rgbcolor2-select").css("background-color", $this.attr("data-color"));
        return false;
    })
    .on("click", ".fixexC .fc1", function () {
        initiateStart();
    })
    .on("click", ".in2", function () {
        $this = $(this);
        var active = $this.attr("active") || 0;
        //没有值或者为灰色
        if (!$(".in1").val() || !parseInt(active))
            return false;
        else {
            var value = $(".in1").val();
            obj.url = commonUrl;
            obj.data = 'Operation=8&templateid=' + value;
            commonAjaxRequest(obj, function (data) {
                if (parseInt(data) == "0") {
                    $PlusContainer.find(".PlusContainer-search-2").find(".tempidEmpty").remove();
                    var array = new Array();
                    array[0] = '<div class="tempidEmpty">该模板不存在！';
                    array[1] = '<div class="si"></div>';
                    array[2] = '</div>';
                    $PlusContainer.find(".PlusContainer-search-2").append(array.join("")).find(".tempidEmpty").show().animate({ top: "-63px" }, 500);
                    return false;
                }
                window.location.href = tempUrl.replace(/\d+/, value);
            });
        }
    });
var likes = 0;
$PlusContainer.on("click", ".sc", function () {
    $this = $(this);
    if (!$.cookie("uid")||$.cookie("uid")=="") {
          popup_login('callbarkord');
          return;
      }
    obj.url = commonUrl;
    obj.data = {};
    obj.data.Operation = 11;
    obj.data.templateid = templateid;
    commonAjaxRequest(obj, function (data) {
        if (data != "error") {
            if (data == 1) {
                $("#scnum").html(parseFloat($("#scnum").html()) + 1);
                $this.css({ "background-position": "-283px -276px" })

            }
            else {
                $("#sctips").remove();
                $this.append('<span id="sctips" style="position: absolute;color:#f60;left: 4px;top:-19px;">您已经收藏了</span>');
                setTimeout(function () {
                    $('#sctips').remove();
                }, 500)
            }
        }
    });
})
    .on("click", ".xh", function () {
        //喜欢
        $this = $(this);
        obj.url = commonUrl;
        obj.data = {};
        obj.data.Operation = 10;
        obj.data.templateid = templateid;
        if (!likes)
            commonAjaxRequest(obj, function (data) {
                if (data != "error") {
                    $("#xhnum").html(parseFloat($("#xhnum").html()) + 1);
                    likes = 1;
                    $this.css({ "background-position": "-283px -192px" })
                }
            })
        else {

            $this.append('<span id="sctips" style="position: absolute;color:#f60;left:12px;top:-19px;">不能再顶了</span>');
            setTimeout(function () {
                $('#sctips').remove();
            }, 500)

            //$('#sctips').remove();
        }
    })
    .on("click", ".fontS", function () {
        $this = $(this);
        if ($this.attr("active") == undefined || $this.attr("active") == "0") {
            return false;
        }
        var cFlag = $this.attr("cflag") || 0;
        if (!parseInt(cFlag)) {
            $this.css({ "border-color": "#f60" });
            $PlusContainer.find(".sss").removeClass("gt_hidden");
            $PlusContainer.find(".fontS .sb").addClass("sbClick");
            $this.attr("cflag", '1');
        }
        else {
            $this.css({ "border-color": "#dcdcdc" });
            $PlusContainer.find(".sss").addClass("gt_hidden");
            $PlusContainer.find(".fontS .sb").removeClass("sbClick");
            $this.attr("cflag", '0');
        }
        return false;
    })
    .on("click", ".fontT", function () {
        $this = $(this);
        if ($this.attr("active") == undefined || $this.attr("active") == "0") {
            return false;
        }
        var cFlag = $this.attr("cflag") || 0;
        if (!parseInt(cFlag)) {
            $this.css({ "border-color": "#f60" });
            $PlusContainer.find(".fontS").css({ "border-left-color": "#f60" });
            $PlusContainer.find(".fontFamily").removeClass("gt_hidden");
            $PlusContainer.find(".fontT .sb").addClass("sbClick");
            $this.attr("cflag", '1');
        }
        else {
            $this.css({ "border-color": "#dcdcdc" });
            $PlusContainer.find(".fontS").css({ "border-left-color": "#dcdcdc" });
            $PlusContainer.find(".fontFamily").addClass("gt_hidden");
            $PlusContainer.find(".fontT .sb").removeClass("sbClick");
            $this.attr("cflag", '0');
        }
        return false;
    })
    .on("click", ".leftArrow,.rightArrow", function () {
        window.location.href = $(this).attr("data-value");
        return false;
    })
//字体的变化
    .on("click", ".sss a", function () {
        $this = $(this);
        $PlusContainer.find(".fontS").css({ "border-color": "#dcdcdc" }).attr("cflag", 0).find("span").html($this.html());
        var index = $PlusContainer.find(".borderColor-FFAD33").attr("jsonindex"), $imgDom = $("#text" + $PlusContainer.find(".borderColor-FFAD33").attr("id").slice(5));
        TextJson[index].TextFontSize = $this.attr("data-v");
        toGet($imgDom, index);
        $this.parent().addClass("gt_hidden");
        return false;
    })
//字体类型的变化
    .on("click", ".fontFamily a", function () {
        $this = $(this);
        $PlusContainer.find(".fontT").css({ "border-color": "#dcdcdc" }).attr("cflag", 0);
        $PlusContainer.find(".fontS").css({ "border-left-color": "#dcdcdc" });
        var str = $this.css("background-position"), strsp = str.split(" ");
        $PlusContainer.find(".fontT").css({ "background-position": function () {
            return "-8px" + " " + (parseFloat(strsp[1]) + 4) + "px";
        } 
        }).find(".sb").removeClass("sbClick");
        var index = $PlusContainer.find(".borderColor-FFAD33").attr("jsonindex"), $imgDom = $("#text" + $PlusContainer.find(".borderColor-FFAD33").attr("id").slice(5));
        TextJson[index].TextFontType = $this.attr("data-value");
        toGet($imgDom, index);
        $this.parent().addClass("gt_hidden");
        return false;
    })
    .on("click", ".g4", function () {
        $this = $(this);
        $PlusContainer.find(".str4").removeClass("strhover").attr("cflag", 0);
        var cFlag = $this.attr("cflag") || 0;
        if (!parseInt(cFlag)) {
            $PlusContainer.find(".RgbCon").css({"left":"168px","height":"199px"}).removeClass("gt_hidden").attr("CbackColor", 1);
            if(!$(".ToDefault").length)
            $PlusContainer.find(".RgbCon").append('<a href="javascript:void(0);" class="ToDefault">初始化默认背景</a>');
            $this.attr("cflag", '1').addClass("ghover");
        }
        else {
            $PlusContainer.find(".RgbCon").removeAttr("style").addClass("gt_hidden");
            $this.attr("cflag", '0').removeClass("ghover");
        }
        return false;
    })
    .on("click", ".g2", function () {
        $this = $(this);
        var arrayHtml = new Array(), width = "414px", height = "138px";
        arrayHtml[0] = '<p style=" text-align:center;color:#666666; font-size:16px; line-height:36px; padding:25px 0 14px 0" class="fontFamYahei">重做操作会让您已编辑的信息还原，确认执行此操作？</p>';
        arrayHtml[1] = '<div style=" width:242px;margin:0px auto;"><div class="dialogOrangeBtn" style="width:109px; height:28px;line-height:28px; float:left; ">确定</div><div class="dialogGrayBtn" onclick="$.modal.close();return false;" style="width:109px; height:28px;line-height:28px; float:left; margin-left:20px; ">取消</div></div>';
        $.modal(arrayHtml.join(""), { opacity: 15, close: false, containerCss: { "background-color": "#ffffff", "width": width, height: height, padding: "0px" },
            onShow: function () {
                $(".dialogOrangeBtn").click(function () {
                    window.location.href = tempUrl;
                })
            }
        });
    })
    .on("click", ".sl", function () {
        $this = $(this);
        var cflag = $this.attr("cflag") || 0, sid = $this.attr("id").slice(2);
        $PlusContainer.find(".s1Select").attr("cflag", 0).removeClass("s1Select");
        $PlusContainer.find(".stext").removeClass("borderColor-FFAD33");
        $this.attr("cflag", cflag);
        if (!parseFloat(cflag)) {
            $this.addClass("s1Select");
            $PlusContainer.find(".r3").removeClass("nike").addClass("addi");
            $this.attr("cflag", "1");
        }
        else {
            $this.removeClass("s1Select");
            $PlusContainer.find(".r3").removeClass("addi").addClass("nike");
            $this.attr("cflag", "0");
        }
        $("#logo" + sid).createNewDrag($("#wrapC"));
        return false;
    })
    .on("click", ".closeImgTips", function () {
        $(this).parents(".slogo").removeClass("xfError");
        $(this).parent().remove();
        return false;
    })
    .on("click",".errX",function(){
        $(this).parent().remove();
        return false;
    })
    .on("click",".ToDefault",function(){
        $(".imgTutu").show();
        TemplateTransactionJson[0].BackgroundColor=null;
        TemplateTransactionJson[1].BackgroundColor=null;
        return false;
    })
$("body").click(function (e) {
    $(document.body).unbind("keydown");
    $(".borderColor-FFAD33").removeClass("borderColor-FFAD33");
    $PlusContainer.find(".fontSt").addClass("fontStd").removeClass("fontSt").find(".str4").attr("cflag", "0");
    $PlusContainer.find(".addi").addClass("nike").removeClass("addi");
    $PlusContainer.find(".RgbCon").addClass("gt_hidden");
    $PlusContainer.find(".sss").addClass("gt_hidden");
    $PlusContainer.find(".fontFamily").addClass("gt_hidden");
    $PlusContainer.find(".sb").removeClass("sbClick");
    $PlusContainer.find(".fontS").css({ "color": "#999", "border-color": "#dcdcdc" }).attr("active", 0).attr("cflag", "0");
    $PlusContainer.find(".fontT").css({ "color": "#999", "border-color": "#dcdcdc" }).attr("active", 0).attr("cflag", "0");
    $PlusContainer.find(".g4").attr("cflag", "0").removeClass("ghover");
    $PlusContainer.find(".t1").attr("cflag", "0");
    $PlusContainer.find(".logoLayer").addClass("gt_hidden");
    $PlusContainer.find(".s1Select").removeClass("s1Select").attr("cflag", 0);
    $PlusContainer.find(".fontT").css("cursor", "default");
    $PlusContainer.find(".fontS").css("cursor", "default");
    if ($("#logoBox").length) {
        $("#logoBox").parent().attr("fi", "0");
        $("#logoBox").remove();
    }
    if ($("#wrapC").length) {
        var $tempImg = $("#wrapC").find("img");
        var cleft = parseFloat($("#wrapC").css("left")) + 4, ctop = parseFloat($("#wrapC").css("top")) + 4;
        $("#wrapC").find("div").remove();
        $tempImg.unwrap().removeClass("acmove").css({ left: cleft + "px", top: ctop + "px" });
    }
});
$("body").on("click", "#scewm", function () {
    if ($PlusContainer.find(".slogo[data-op=7]:visible").length == 1) {
        logoType = "oldLogo";
        logo_lmid = $PlusContainer.find(".slogo[data-op=7]:visible").eq(0).find(".changeLogo").attr("data-value");
    }
    else {
        logoType = "erweima";
    }
    $.modal.close();
    showUploadTask(upload_frm_url);
    return false;
});
//什么什么体的判断
function textStyleJudge(index, $imgDom, flo) {
    //加粗是1，斜体是2，下划线是4
    var judgeArray = [{ "aindex": 1, xz: 0 }, { "aindex": 2, xz: 0 }, { "aindex": 4, xz: 0}];
    if ($PlusContainer.find(".str1").hasClass("strhover")) {
        judgeArray[0].xz = 1;
    }
    if ($PlusContainer.find(".str2").hasClass("strhover")) {
        judgeArray[1].xz = 1;
    }
    if ($PlusContainer.find(".str3").hasClass("strhover")) {
        judgeArray[2].xz = 1;
    }
    if ($PlusContainer.find(".str4").hasClass("strhover")) {
        $PlusContainer.find(".RgbCon").removeClass("gt_hidden");
    }
    else {
        $PlusContainer.find(".RgbCon").addClass("gt_hidden");
    }
    if (flo) {
        if ($PlusContainer.find(".str5").hasClass("strhover")) {
            $PlusContainer.find(".str6").removeClass("strhover").attr("cflag", "0");
            $PlusContainer.find(".str7").removeClass("strhover").attr("cflag", "0");
            //设置文本段的x坐标。居左
            //文本段居左
            TextJson[index].TextX = parameterMp.x;
            TextJson[index].TextAlign = 0;
        }
        else if ($PlusContainer.find(".str6").hasClass("strhover")) {
            $PlusContainer.find(".str5").removeClass("strhover").attr("cflag", "0");
            $PlusContainer.find(".str7").removeClass("strhover").attr("cflag", "0");
            //设置文本段居中
            TextJson[index].TextAlign = 2;
            TextJson[index].TextX = parameterMp.width / 2;
        }
        else if ($PlusContainer.find(".str7").hasClass("strhover")) {
            $PlusContainer.find(".str5").removeClass("strhover").attr("cflag", "0");
            $PlusContainer.find(".str6").removeClass("strhover").attr("cflag", "0");
            //设置文本段居右
            TextJson[index].TextAlign = 1;
            TextJson[index].TextX = parameterMp.width - parameterMp.x;
        }
    }
    //设置图片的x，calign
    if ($imgDom) {
        $imgDom.attr("x", TextJson[index].TextX).attr("calign", TextJson[index].TextAlign);
    }
    var num = 0;
    for (var i = 0; i < judgeArray.length; i++) {
        if (judgeArray[i].xz == 1)
            num += judgeArray[i].aindex;
    }
    TextJson[index].TextStyle = num;
}
//请求得到图片
function toGet($t, index) {
    if ($t.length) {
        $t.attr("calign", TextJson[index].TextAlign).attr("jg", "1").attr("src", drawTextImageUrl + "?operation=1&random=" + Math.random() + "&text=" + encodeURIComponent(JSON.stringify(TextJson[index])));
    }
}
//清除所有状态以及选中
function clearAllStyleToStar(index) {
    //清除所有选中状态
    $PlusContainer.find(".f7").removeClass("strhover").attr("cflag", 0);
    if (TextJson[index].TextAlign == 0) {
        $PlusContainer.find(".str5").addClass("strhover").attr("cflag", 1);
    }
    else if (TextJson[index].TextAlign == 1) {
        $PlusContainer.find(".str7").addClass("strhover").attr("cflag", 1);
    }
    else if (TextJson[index].TextAlign == 2) {
        $PlusContainer.find(".str6").addClass("strhover").attr("cflag", 1);
    }
    //加粗
    if (TextJson[index].TextStyle == 1) {
        $PlusContainer.find(".str1").addClass("strhover").attr("cflag", 1);
    }
    //斜体
    else if (TextJson[index].TextStyle == 2) {
        $PlusContainer.find(".str2").addClass("strhover").attr("cflag", 1);
    }
    //加粗和斜体
    else if (TextJson[index].TextStyle == 3) {
        $PlusContainer.find(".str1").addClass("strhover").attr("cflag", 1);
        $PlusContainer.find(".str2").addClass("strhover").attr("cflag", 1);
    }
    //下划线
    else if (TextJson[index].TextStyle == 4) {
        $PlusContainer.find(".str3").addClass("strhover").attr("cflag", 1);
    }
    //加粗 下划线
    else if (TextJson[index].TextStyle == 5) {
        $PlusContainer.find(".str1").addClass("strhover").attr("cflag", 1);
        $PlusContainer.find(".str3").addClass("strhover").attr("cflag", 1);
    }
    //斜体 下划线
    else if (TextJson[index].TextStyle == 6) {
        $PlusContainer.find(".str2").addClass("strhover").attr("cflag", 1);
        $PlusContainer.find(".str3").addClass("strhover").attr("cflag", 1);
    }
    //斜体 下划线 粗体
    else if (TextJson[index].TextStyle == 7) {
        $PlusContainer.find(".str1").addClass("strhover").attr("cflag", 1);
        $PlusContainer.find(".str2").addClass("strhover").attr("cflag", 1);
        $PlusContainer.find(".str3").addClass("strhover").attr("cflag", 1);
    }

}
function commonAjaxRequest(obj, callback) {
    $.ajax({
        url: obj.url,
        type: obj.type,
        dataType: obj.dataType,
        timeout: 60000,
        data: obj.data,
        error: function () {
            if (callback)
                callback("error");
        },
        success: function (data) {
            if (callback)
                callback(data);
        }
    });
}
function GoSave(Save_Id) {
    $.ajax({
        url: 'http://soso.yifutu.com/AjaxPage/FileAjaxHandler.ashx',
        type: 'get',
        data: 'ajaxType=5&id=' + Save_Id,
        dataType: "jsonp",
        cache: !0,
        jsonpCallback: "define",
        async: false,
        timeout: 60000,
        error: function () { },
        success: function (data) {
            //返回值为1
        }
    });
}
function saveMp() {
    showLoad("正在保存,请稍后!");
    obj.url = printUrl;
    obj.data = {};
    obj.data.rate = ratio;
    obj.data.Templateid = templateID;
    obj.data.TextList = JSON.stringify(TextJson);
    obj.data.TemplateTransactionJson = JSON.stringify(TemplateTransactionJson);
    obj.data.LogoList = JSON.stringify(logoJson);
    obj.data.Operation = 2;
    commonAjaxRequest(obj, function (data) {
        if (data != "error") {
            showInfo("<p style='margin-top:3px;font-weight:700;text-align:center;'>保存成功！</p><p class='save_area'><a  href='javascript:void(0)' onclick='sysInfoDialog.close_dialog()'>继续设计</a><a href='javascript:void(0)' onclick='dialogDmPcard();'>下载名片</a><a href='/PrintMp.html?sendtype=2&sendid=" + data + "' target='_blank'>印刷名片</a></p>");
            $('.load_save_mp_list .pagination_ctn').attr("pageIndex", "0");
        }
        else
            showInfo("保存，请稍后再试");
    });
    loading_dialog.close_dialog();
}
function showPrint() {
    //if($.checkEmpty("印刷名片上没有填写任何内容不能印刷。",1)==1)
    //    return false;
    //点击印刷
    if (overBorderArray.length > 0) {
        warnShow('文字或图片超出了名片出血线，为避免您的印刷品出错，请修正后再提交印刷！');
        if ($(".xfError").length == 0) {
            var inputid = 0;
            for (var i = 0; i < overBorderArray.length; i++) {
                inputid = overBorderArray[i].slice(4);
                if (overBorderArray[i].slice(0, 4) == "text") {
                    if ($("#input" + inputid).parent().find(".xfError").length == 0)
                        $("#input" + inputid).addClass("borderColor-FFAD33").parent().append('<div class="xfError"></div>');
                }
                else {
                    if (!$("#s1" + inputid).parent().hasClass("xfError"))
                        $("#s1" + inputid).parent().addClass("xfError").append('<div class="imgTips"><a class="closeImgTips" href="javascript:void(0)"></a>该图片超出范围，请重新调整。</div>');
                }
            }
        }
        return;
    }
    $PlusContainer.find("#overAll").css("z-index", 300).height($(document).height()).show();
    $PlusContainer.find(".o3").css("z-index", 1);
    $PlusContainer.find(".PlusContainer-contexL-pic").addClass("PlusContainer-f60");
    if (Format == "V")
        $PlusContainer.find(".bigclient_print").css({ "left": "526px", "top": "150px" }).show();
    else
        $PlusContainer.find(".bigclient_print").show();
}
function operateMpE(e) {
   if ($.cookie('uid') == null) {
        if($(e).text()=="确认无误，购买"){

        }
        else{
            popup_login();
             return;  
        }
    }
    $this = $(e);
    $this.printf();
    return false;
}
//20150807 liuxuejun 下载添加浮层提示语

$("#download").attr("style","position:relative");
var xaizaiFloat='<p style="display: none;border: #e7e7e7 1px solid;background: #fff;font: 12px/20px 微软雅黑;width: 328px;padding: 10px;text-align: left;position: absolute;left: -1px;bottom: -65px;height: 38px;">为避免下载后文件格式与色彩模式发生改变，降低印刷效果，强烈建议您，<span class="color1">直接点选左侧下单印刷！</span></p>';
$("#download").append(xaizaiFloat);

$(document).on("mouseover","#download",function(){
    $(this).find("p").show();
});
$(document).on("mouseleave","#download",function(){
    $(this).find("p").hide();
});



function call_back(url, id) {
    url = decodeURIComponent(url);
    $.modal.close();
    //新logo
    if (logoType == "newLogo" || logoType == "erweima") {
        var img = new Image();
        img.setAttribute("FileUrlInfo_ID", 1014);
        img.setAttribute("Type", (logoType == "newLogo" ? "1" : "7"));
        img.setAttribute("LogoUrl", url);
        img.setAttribute("LogoPath", url);
        img.setAttribute("ZIndex", id);
        if (document.addEventListener) {
            img.addEventListener("load", function () { $.loadPicture(this) }, false);
        }
        else if (document.attachEvent) {
            img.attachEvent("onload", function () { $.loadPicture(img); });
        }
        img.src = url;
    }
    else if (logoType == "oldLogo") {
        SelectLogo(id, url, 1, url);
    }
}
function SelectLogo(LogoId, Url, Type, Url2) {
    function logoLoading(t) {
        var $logolmid = $("#logo" + logo_lmid), cwid = $logolmid.attr("data-width"), cheight = $logolmid.attr("data-height"), zoom = 1, cx = $logolmid.attr("data-x"), cy = $logolmid.attr("data-y");
        cx = parseFloat(cx) + cwid / 2, cy = parseFloat(cy) + cheight / 2;
        if (t.width >= t.height && t.width > cwid) {
            zoom = t.width / cwid;
        }
        else if (t.width < t.height && t.height > cheight) {
            zoom = t.height / cheight;
        }
        var xx = parseInt(cx - t.width / zoom / 2), yy = parseInt(cy - t.height / zoom / 2), wwidth = parseInt(t.width / zoom), hheight = parseInt(t.height / zoom);
        $logolmid.attr("src", t.src).css({ "width": function () {
            return wwidth + "px";
        },
            "height": function () {
                return hheight + "px";
            },
            "left": function () {
                return xx + "px";
            },
            "top": function () {
                return yy + "px";
            }
        })
        .attr("data-width", wwidth)
        .attr("data-height", hheight)
        .attr("data-x", xx)
        .attr("data-y", yy);
        if (logoJson.length) {
            logoJson[t.getAttribute("logoIndex")].IsChange = true;
            logoJson[t.getAttribute("logoIndex")].FileUrlInfo_ID = 1014;
            logoJson[t.getAttribute("logoIndex")].LogoPath = Url2;
            logoJson[t.getAttribute("logoIndex")].LogoUrl = Url2;
            logoJson[t.getAttribute("logoIndex")].LogoWidth = wwidth;
            logoJson[t.getAttribute("logoIndex")].LogoHeight = hheight;
            logoJson[t.getAttribute("logoIndex")].LogoX = xx;
            logoJson[t.getAttribute("logoIndex")].LogoY = yy;

        }
        //console.log("id:"+t.id);
    }
    if (Type == 1) {
        Url = Url2;
    }
    if ($.modal.length) {
        $.modal.close();
    }
    if (logoType == "newLogo") {
        var img = new Image();
        img.setAttribute("FileUrlInfo_ID", 1014);
        img.setAttribute("Type", 1);
        img.setAttribute("LogoUrl", Url2);
        img.setAttribute("LogoPath", Url2);
        img.setAttribute("ZIndex", LogoId);
        if (document.addEventListener) {
            img.addEventListener("load", function () { $.loadPicture(this) }, false);
        }
        else if (document.attachEvent) {
            img.attachEvent("onload", function () { $.loadPicture(img); });
        }
        img.src = Url2 + "?random=" + Math.random();
        return false;
    }
    var willWidth = 0, willHeight = 0;
    var $dlogo = $("#dlogo-" + logo_lmid);
    $dlogo.attr("src", Url);
    //added by jf
    var img = new Image();
    //img.setAttribute("cwid",logoJson[i].LogoWidth);
    //img.setAttribute("cheight",logoJson[i].LogoHeight);
    //img.setAttribute("cx",logoJson[i].LogoX);
    //img.setAttribute("cy",logoJson[i].LogoY);
    img.setAttribute("logoIndex", $dlogo.parent().attr("logoindex"));
    img.id = logo_lmid;
    logoJson[$dlogo.parents().attr("logoindex")].ZIndex = parseInt(LogoId);
    if (document.addEventListener) {
        img.addEventListener("load", function () { logoLoading(this) }, false);
    }
    else if (document.attachEvent) {
        //ie的attachEvent的this是全局对象。可以这样解决
        img.attachEvent("onload", function () { logoLoading(img) });
    }
    img.src = Url2 + "?random=" + Math.random();
    //ended by jf
}
function warnShow(text) {
    $("#mberror_card_box").show();
    $("#mberror_card_box").find('h5').html(text);
    $("#mberror_card_box p span").html('5');
    setTimeout(function () { $("#mberror_card_box p span").html('4'); }, 1000);
    setTimeout(function () { $("#mberror_card_box p span").html('3'); }, 2000);
    setTimeout(function () { $("#mberror_card_box p span").html('2'); }, 3000);
    setTimeout(function () { $("#mberror_card_box p span").html('1'); }, 4000);
    setTimeout(function () { $("#mberror_card_box p span").html('0'); }, 5000);
    setTimeout(function () { $("#mberror_card_box").hide(); $("#mberror_card_box p span").html('5'); }, 6000);
}
function setsCookie(name, value) {
    var Days = 300;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//读取cookies
function getsCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))

        return (arr[2]);
    else
        return null;
}
//超出判断
function judgeOverBorder(ele,jfF) {
    var overid = "", top = 0, left = 0, width = 0, height = 0, inputid;
    if (ele) {
        top = parseFloat(ele.style.top), left = parseFloat(ele.style.left), width = ele.width, height = ele.height, overid = ele.id, inputid = overid.slice(4);
    }
    if (ele && (left < parameterMp.x || top < parameterMp.y || left + width > (parameterMp.width - parameterMp.x) || top + height > (parameterMp.height - parameterMp.y))) {
        var flagRpeat = 0;
        for (var j = 0; j < overBorderArray.length; j++) {
            if (overBorderArray[j] == overid) {
                flagRpeat = 1;
                break;
            }
        }
        if (flagRpeat == 0) {
            overBorderArray.push(overid);
            if (overid.slice(0, 4) == "text")                
            {
                if(!jfF)
                    $("#input" + inputid).attr("MoreText",1).addClass("borderColor-FFAD33x").parent().append('<div class="xfError"><div class="errX">×</div>该文字超出裁切线范围，请重新调整</div>');
                else
                    $("#input" + inputid).attr("MoreText",1);
            }
            else {
                $("#s1" + inputid).parent().addClass("xfError").append('<div class="imgTips"><a class="closeImgTips" href="javascript:void(0)"></a>该图片超出范围，请重新调整。</div>');
            }
        }
        parameterMp.moveJude = 1;
    }
    else {
        if (overBorderArray.length > 0) {
            removeValueOfArray(overid, overBorderArray);
            if (overid.slice(0, 4) == "text")
            {
                if(!jfF)
                    $("#input" + inputid).attr("MoreText",0).removeClass("borderColor-FFAD33x").css("color", "#999").parent().find(".xfError").remove();
                else
                    $("#input" + inputid).attr("MoreText",0);
            }
            else {
                $("#s1" + inputid).parent().removeClass("xfError").find(".imgTips").remove();
            }
        }
    }
    if (overBorderArray.length == 0) {
        parameterMp.moveJude = 0;
        $(".PlusContainer-contexL-2").addClass("gt_hidden");
    }
    else {
        $(".PlusContainer-contexL-2").removeClass("gt_hidden");
    }
}
//overBorder里元素的删除
function removeValueOfArray(name, array) {
    for (var i = 0, l = array.length; i < l; i++) {
        if (array[i] == name) {
            array.splice(i, 1);
            return;
        }
    }
}
function initiateStart1() {
    guideone = new Array(), guidetwo = new Array();
    //让遮罩层级变大，遮住一切
    //$PlusContainer.find("#overAll").css("z-index", "999").height($(document).height()).show();
    $PlusContainer.find("#overAll").css({"z-index":"999","height":"100%"}).show();

    guideone[0] = '<div class="step stepone">';
    guideone[1] = '<div class="nextStep"></div>';
    guideone[2] = '<div class="closeStep"></div>';
    guideone[3] = '</div>';
    guidetwo[0] = '<div class="firstLight Light"></div>';
    //第一步显示名片编辑区域
    $PlusContainer.find("#backTab,.PlusContainer-contexR-nav2").addClass("changePositon");
    $PlusContainer.find("#faceTab").addClass("changePositon1");
    $PlusContainer.find("#faceTab").append(guideone.join("")).append(guidetwo.join(""));
}

//变量的定义
var obj = {}, obj1 = {}, guideone, guidetwo, logoType = "";
obj.type = "post";
obj.dataType = "html";
obj1.url = commonUrl;
obj1.data = "Operation=9&templateid=" + templateid;
obj1.type = "post";
obj1.dataType = "html";
var logo_lmid = 0;
var callbarkord="";
var overBorderArray = [];
var parameterMp = {
    width: 400,
    height: 243,
    x: 17,
    y: 17,
    faceZindex: 15,
    backZindex: 15,
    moveJude: 0,
    shu: "sxPsH",
    heng: "hxPsH",
    fontFamilyArray: ["默认字体", "方正细等线简体", "方正中等线简体", "方正黑体简体", "方正大黑简体", "方正超粗黑简体", "方正宋一简体", "方正书宋简体", "方正中雅宋_GBK", "方正大标宋简体", "方正粗宋简体", "方正铁筋隶书简体", "迷你简古隶", "方正隶书简体", "方正隶二简体", "方正毡笔黑简体", "方正细圆简体", "方正准圆简体", "方正粗圆简体", "汉真广标", "方正综艺简体", "微软雅黑", "时尚中黑简体", "方正粗黑宋简体", "方正华隶简体", "方正艺黑简体", "方正细倩简体", "方正中倩简体", "方正粗倩简体", "方正粗活意简体", "迷你简胖娃", "方正北魏楷书简体", "方正魏碑简体", "迷你简书魂", "迷你简神工", "迷你简蝶语", "方正卡通简体", "迷你简彩蝶", "迷你简海韵", "迷你简清韵", "方正特粗光辉简体", "方正楷体简体", "方正硬笔楷书简体", "迷你简行书", "全新硬笔行书简", "方正行楷简体", "迷你简雪君", "方正字迹-童体毛笔字体", "叶根友蚕燕隶书(3500)", "叶根友钢笔行书升级版", "叶根友毛笔行书简体", "方正细珊瑚简体", "方正水柱简体", "方正水黑简体", "方正流行体简体", "方正胖头鱼简体", "方正瘦金书简体", "方正启体简体", "書體坊顏體㊣", "方正平和简体", "迷你简萝卜", "迷你简丫丫", "方正稚艺简体", "迷你简漫步", "方正字迹-童体硬笔字体", "迷你简娃娃篆", "方正姚体简体", "迷你简双线体", "迷你简立黑", "迷你简菱心", "迷你简哈哈", "方正康体简体", "迷你简凌波", "迷你简竹节", "文鼎霹雳体", "迷你简方叠体"]
}
if (Format == "V") {
    parameterMp.width = 243;
    parameterMp.height = 400;
    parameterMp.shu = "sxPsV";
    parameterMp.heng = "hxPsV";
}
$("#mana-more").find("li:eq(0)").css("margin-left", "0px");
//浏览数据的插入
commonAjaxRequest(obj1, function () { });
//小文本段图片的添加
$("#PlusContainer").imgAppend();
//文本段输入框的添加
$(".stextContainer").editAppend($(".one").attr("transid"), $(".two").attr("transid"));
//图片改变触发的图片事件
$(".stext").inputChange();
//拖拽
$(".textC").dragme();
$(".sliderc").imgSlide();
$(".Esliderc").imgSlide({
    dftjs: 100,
    dftSingleSlider: ".Esliderc",
    paramMultiple: 1
});

$.dataScroll();
//新手指导的加入		

//字体的添加
var tempA = new Array(), coordY = 0;
for (var i = 0, l = parameterMp.fontFamilyArray.length; i < l; i++) {
    tempA[i] = "<a data-value='" + parameterMp.fontFamilyArray[i] + "' style='background-position:-3px " + coordY + "px'></a>";
    coordY -= 20;
}
$PlusContainer.find(".fontFamily").append(tempA.join(""));
if (!getsCookie("firstTime")) {
    setsCookie("firstTime", "noOne");
    initiateStart();
}
//背景色判断
if (TemplateTransactionJson[0].BackgroundColor) {
    $(".imgTutu").remove();
    $PlusContainer.find(".one").removeAttr("style").css("background-color", TemplateTransactionJson[0].BackgroundColor);
}
if (TemplateTransactionJson[1].BackgroundColor) {
    $(".imgTutu").remove();
    $PlusContainer.find(".two").removeAttr("style").css("background-color", TemplateTransactionJson[1].BackgroundColor);
}
if (getsCookie("shxwz")) {
    $PlusContainer.find("#g1").removeClass("g1").addClass("g1Dis");
}
$(window).resize(function () {
    $(".fixexC").css({ "left": function () {
        return ($(window).width() - 1000) / 2 + 1000 + 16;
    } 
    });
});





	