<?php
$arr_sort=array ('2'=>'室内图', '1'=>'外景图', '0'=>'户型图');
$uploadlimit = array('2'=>10,'1'=>5,'0'=>3);
$isfaceimg = true;  //判断封面图是否已标记，这个设定针对重复图片的情况。

foreach($arr_sort as $key=>$sort) { ?>
    <dd class="list_item clearfix">
        <div class="addPicBox radius3">
            <div class="addPicLeft"><?=$sort?></div>
            <div class="addPicRight pre">
                <div style="width: 89px;" id="spanButtonPlaceholder<?=$key?>" class="addBtn radius5">
                    <span>从电脑选择图片</span>
                </div>

                <?php
                //微信传图按钮ID
                $wechatButton = '';

                //微信HTML结构容器ID
                $wechatHtmlId = '';

                //微信二维码图片地址
                $wechatImageSrc = '';

                //每个种上传模式，限制图片上传的数量
                $imageLimitNum = 0;

                //微信二维码过期时间
                $lastTime = 0;

                //微信唯一标识
                $wechatCacheKey = '';

                //图片上传类型
                $imageUploadType = '';

                //图片地址ID
                $wechatImageSrcId = '';

                //
                $imageWeiXinEwmValid = '';

                $imageWeiXinEwmExpirationId = '';

                if($key == '2')
                {
                    $wechatButton = 'doorinImageWeiXinButton';
                    $wechatHtmlId = 'doorinImageWeiXinHtml';

                    //$wechatImageSrc = $wechatDoorinData['wechat_image'];
                    $wechatImageSrc = '';
                    $imageLimitNum = '10';

                    //$lastTime = $wechatDoorinData['last_time'];
                    $lastTime = '';

                    //$wechatCacheKey = $wechatDoorinData['wechat_cache_key'];
                    $wechatCacheKey = '';

                    $wechatImageSrcId = 'doorinWechatImage';
                    $ImageWeiXinEwmValid = 'doorinImageWeiXinEwmValid';
                    $imageWeiXinEwmExpirationId = 'doorinImageWeiXinEwmExpiration';
                    $imageUploadType = 'doorin';
                }
                elseif($key == '1')
                {
                    $wechatButton = 'dooroutImageWeiXinButton';
                    $wechatHtmlId = 'dooroutImageWeiXinHtml';

                    //$wechatImageSrc = $wechatDooroutData['wechat_image'];
                    $wechatImageSrc = '';
                    $imageLimitNum = '5';

                    //$lastTime = $wechatDooroutData['last_time'];
                    $lastTime = '';

                    //$wechatCacheKey = $wechatDooroutData['wechat_cache_key'];
                    $wechatCacheKey = '';

                    $wechatImageSrcId = 'dooroutWechatImage';
                    $ImageWeiXinEwmValid = 'dooroutImageWeiXinEwmValid';
                    $imageWeiXinEwmExpirationId = 'dooroutImageWeiXinEwmExpiration';
                    $imageUploadType = 'doorout';
                }
                elseif($key == '0')
                {
                    $wechatButton = 'layoutImageWeiXinButton';
                    $wechatHtmlId = 'layoutImageWeiXinHtml';
                    //$wechatImageSrc = $wechatLayoutData['wechat_image'];
                    $wechatImageSrc = '';
                    $imageLimitNum = '3';

                    //$lastTime = $wechatLayoutData['last_time'];
                    $lastTime = '';

                    //$wechatCacheKey = $wechatLayoutData['wechat_cache_key'];
                    $wechatCacheKey = '';

                    $wechatImageSrcId = 'layoutWechatImage';
                    $ImageWeiXinEwmValid = 'layoutImageWeiXinEwmValid';
                    $imageWeiXinEwmExpirationId = 'layoutImageWeiXinEwmExpiration';
                    $imageUploadType = 'layout';
                }
                ?>

                <div class="addBtn radius5 ">
                        <span class="yz-ewmp" id="<?php echo $wechatButton;?>" imageUploadType="<?php echo $imageUploadType;?>" imageLimitNum="<?php echo $imageLimitNum;?>" lastTime="<?php echo $lastTime;?>" wechatCacheKey="<?php echo $wechatCacheKey;?>" wechatImageSrc="<?php echo $wechatImageSrc;?>">
                            微信传图
                        </span>
                </div>

                <div id="<?php echo $wechatHtmlId;?>" class="yz-ewm cf" style="display:none;">

                    <!--二维码未过期-->
                    <div class="fl yz-ewmi" id="<?php echo $ImageWeiXinEwmValid;?>">
                        <img id="<?php echo $wechatImageSrcId;?>" src="" />
                    </div>

                    <!--二维码过期-->
                    <div class="fl yz-ewmw" style="display: none;" id="<?php echo $imageWeiXinEwmExpirationId;?>">
                        <p>二维码已过期</p>
                        <p><a id="<?php echo $imageUploadType;?>WeicodeRefresh" class="JsweicodeRefresh">点此刷新</a></p>
                    </div>

                    <div class="fr pre yz-ewmr">
                        <span class="yz-close">X</span>
                        <p class="yz-ewmt">微信扫描二维码</p>
                        <p>关注后直接上传手机中的<strong style="color:red; font-weight: 700;"><?php echo $sort;?></strong></p>
                    </div>
                </div>

                <p class="text">
                    <?php if($key==2){ ?>
                        为防止图片审核未通过，室内图的房源装修情况请与装修描述相符，最多上传<span class="number">10</span>张。
                    <?php }elseif($key==1){ ?>
                        请不要上传失真图片，如开发商的效果图等，最多上传<span class="number">5</span>张。
                    <?php }else{ ?>
                        为防止图片审核未通过，户型图请与房型描述一致，最多上传<span class="number">3</span>张。<a href="http://zsb.house365.com/tools/draw/draw.html" target="_blank" style="color: #3887F2;">在线绘制户型图>></a>
                    <?php } ?>
                </p>
            </div>
        </div>
    </dd>
    <script type="text/javascript">

        var swfu<?=$key?>;
        var ids<?=$key?>;
        $(function() {

            uploads_zsb("spanButtonPlaceholder<?=$key?>","<?=$key?>");


        });
    </script>

    <?php
    if(isset($house_detail['house_pic' . $key]) && !empty($house_detail['house_pic' . $key])) {
        $style = 'style="display:block"';
        $bolHasHouse = true;
    } else {
        $style = 'style="display:none"';
        $bolHasHouse = false;
    }

    ?>
    <div id="jsPicPreviewBoxM<?=$key?>" style="display:none" ></div>
    <dd class="list_item clearfix" id="picshow<?=$key?>" <?=$style?>>
        <div class="picPreviewBox radius3" >
            <p class="title">您选择的图片</p>
            <div class="picPreviewBoxM clearfix ui-sortable" id="thumbnails<?=$key?>">


                <?php
                if($bolHasHouse)
                {

                    $this->load->model('pic_model');
                    $pic1 = empty($house_detail['pic1'])?'':$house_detail['pic1'];
                    if($pic1){
                        $pic1 = $this->pic_model->pic_format($pic1);
                    }

                    foreach($house_detail['house_pic' . $key] as $k => $v){
                        $title = $v['title'] == '' ? '图片描述30字' : $v['title'];
                        if (!isset($house_detail['pic1']))
                        {
                            $house_detail['pic1'] = '';
                        }
                        $pic_format =  $this->pic_model->pic_format($v['filename']);
                        ?>
                        <div style="" class="mItem">
                            <div class="mItemInner" id="yyyyyy">
                                <div class="mPic">
                                    <img width="130" height="100" alt="" src="<?=$v['filename']?>">
                                    <input type="hidden" name="p_filename[]" value="<?=$v['filename']?>">
                                    <input type="hidden" name="p_sort[]" value="<?=$v['sort']?>" class="psort">
                                    <div class="funM"></div>
                                    <div class="funMtext">
                                        <label><input type="radio" onclick="setIndexPic(this);" value="<?=$v['filename']?>" class="input_r" name="jsPicPreviewList" <?php if($pic1 == $pic_format){ ?> checked <?php } ?>>封面</label>
                                        <a class="bigPicLin" style="bottom:84px;" target="_balnk" href="<? echo str_replace('/thumb','',$v['filename']); ?>" title="查看大图">查看大图</a>
                                        <div class="delBtn" id="<?=$v['sort']?>" imageSrc='<?=$v['filename']?>' title="删除" onclick="setPicDel(<?=$v['id']?>);"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="inputBoxM jsNameInput nameInput "><input type="text" name="p_title[]" value="<?=$title?>" class="jsInputCount input_text w126" onclick="if(this.value=='图片描述30字')this.value='',this.className='jsInputCount input_text w126 input_text_on'" onblur="if(this.value=='')this.value='图片描述30字',this.className='jsInputCount input_text w126'">
                            </div>
                        </div>

                        <?php
                    }
                }
                ?>

            </div>
        </div>
    </dd>
    <?php if($key!=2){ ?>
        <dd style="_display:none;"></dd>
        <dd class="list_item clearfix" id="tuku<?=$key?>" style="display:none">
            <div class="picPreviewBox radius3">
                <p class="title" id="t<?=$key?>">365图库推荐选择您要的图片，即可出现在房源图列中</p>
                <div id="jsPicDepotSZMod<?php if($key==0) echo 2; ?>"  class="list clearfix hide showIe6-7">
                    <?php if($key==1){ ?>
                        <div class="jsPicPreviewList" id="jsPicPreviewList1"></div>
                    <?php }else{ ?>
                        <div class="jsPicPreviewList" id="jsPicPreviewList"></div>
                    <?php } ?>
                </div>
            </div>
            <div id="jsPicDepotSZBtn<?php if($key==0) echo 2; ?>" class="picDepotSZ">
                <p class="jsZK innerSZ">展开图库</p>
                <p class="jsSQ innerSZ innerSZ2">收起图库</p>
            </div>
        </dd>
    <?php } ?>


<?php } ?>
<input type='hidden' name='deleteupload' value='1' />
<input type='hidden' id="delpic" name='delpic' value='' />
<input type='hidden' id="pic1" name='pic1' value='<?=$house_detail['pic1']?>' />
<script src="/source/common/js/plupload-2.3.6/js/plupload.full.min.js"></script>

<script type="text/javascript">

    var pic_from_sell = <?php echo empty($pic_from_sell) ? 0 : 1?>;

    var mycars=new Array();
    mycars[2]=10;
    mycars[1]=5;
    mycars[0]=3;
    function uploads_zsb(id,key) {
        var uploader = new plupload.Uploader({
            browse_button: id, //触发文件选择对话框的按钮，为那个元素id
            //url: '/pic/house?pic_from_sell='+pic_from_sell, //服务器端的上传页面地址
            url:'http://newrent.house365.com/ajax-action/upload-file',
            flash_swf_url: '/source/common/js/plupload-2.3.6/js/Moxie.swf', //swf文件，当需要使用swf方式进行上传时需要配置该参数
            silverlight_xap_url: '/source/common/js/plupload-2.3.6/js/Moxie.xap', //silverlight文件，当需要使用silverlight方式进行上传时需要配置该参数
            multi_selection: true,
            filters: {
                mime_types: [ //只允许上传图片和zip文件
                    {title: "images", extensions: "jpg,jpeg,png"},
                ],
                max_file_size:'5M'
            },
            file_data_name:'file_name',
            resize:{
                quality:70
            }
        });

        //在实例对象上调用init()方法进行初始化
        uploader.init();

        uploader.bind('BeforeUpload',function (uploader,file) {
            var leng = mycars[key];
            var kid = $('#thumbnails'+key).find('img').length;
            if(kid >= leng){
                alert('图片上传最多'+leng+'张');
                uploader.stop();
                uploader.removeFile(file)
                return;
            }

        });

        //绑定各种事件，并在事件监听函数中做你想做的事
        uploader.bind('FilesAdded', function (uploader, files) {
            //每个事件监听函数都会传入一些很有用的参数，
            //我们可以利用这些参数提供的信息来做比如更新UI，提示上传进度等操作
            uploader.start(); //调用实例对象的start()方法开始上传文件，当然你也可以在其他地方调用该方法
        });
        uploader.bind('UploadProgress', function (uploader, file) {
            //每个事件监听函数都会传入一些很有用的参数，
            //我们可以利用这些参数提供的信息来做比如更新UI，提示上传进度等操作
        });

        uploader.bind('FileUploaded', function (uploader, files, result) {
            var response = JSON.parse(result.response);
            var status = response.status;
            if(status != 'success'){
                alert('图片上传失败:'+ response.msg);
                return false;
            }

            var imgurl = response.pic_url;
            if(imgurl == '1'){
                if(pic_from_sell==1){
                    alert('图片的宽不可小于700像素，高不可小于500像素');
                }else{
                    alert('图片的宽不可小于322像素，高不可小于200像素');
                }
                return false;
            }
            addImageNew(imgurl,key,'thumbnails'+key)
        });

        uploader.bind('Error',function (uploader,errObject) {
            if(errObject.code == '-600'){
                alert('图片过大，不能超过5M');
                return false;
            }else if(errObject.code == plupload.FILE_EXTENSION_ERROR){
                alert("文件格式不是图片，上传失败");
                return false;
            }else{
                alert('上传失败');
                return false;
            }
        })

    }


    function addImageNew(src, upload_infotype, upload_nail) {
        // src的值不以http开头 返回
        const httpPosition = src.indexOf('http');
        if (httpPosition !== 0) return;
        var oSwfu = upload_infotype == 0 ? swfu0 : (upload_infotype == 1 ? swfu1 : swfu2);
        if (src != '' && src != '0')
        {
            var pid = src.split('pid=');
            var joinhtml = upload_infotype == 0 || upload_infotype == 1 ? "<table style='line-height:20px;height:20px;background:#EDEDED;'><tr><td style='width:12px;'><input style='width:12px;margin-left:5px;border:0px;' type='checkbox' onclick='checkPblockPic(this);' value='p_block_" + pid[1] + "' checked /><input id='p_block_" + pid[1] + "' type='hidden' name='p_block[]' value='1' /></td><td>愿加入365图库</td></tr></table>" : "</td></tr><tr><td><input type='hidden' name='p_block[]' value='0' />&nbsp;";
            var tableheight = upload_infotype == 2 ? "height:165px;" : "height:167px;";
            var bigimg = src.replace('/thumb', '');
            if(upload_infotype==10)
            {
                var content = '<div class="housepic"><img width="130" height="100"  src="' + src + '" alt=""><input type="hidden" value="' + src + '" name="p_filename_real[]"><div class="funMtext"><div title="删除" id="' + upload_infotype + '" class="delBtn" imageSrc="' + src + '"></div></div></div>';
            }
            else {
                var content = '<div class="mItem" style=""><div class="mItemInner"><div class="mPic"><img width="130" height="100"  src="' + src + '" alt=""><input type="hidden" value="' + src + '" name="p_filename[]"><input class="psort" type="hidden" value="' + upload_infotype + '" name="p_sort[]"><div class="funM"></div><div class="funMtext"><label><input type="radio" value="' + src + '" onclick="setIndexPic(this);" name="jsPicPreviewList" class="input_r">封面</label><a class="bigPicLin" style="bottom:84px;" target="_balnk" href="' + bigimg + '" title="查看大图">查看大图</a><div title="删除" id="' + upload_infotype + '" class="delBtn" imageSrc="' + src + '"></div></div></div></div><div class="inputBoxM jsNameInput nameInput "><input type="text" onblur="if(this.value==\'\')this.value=\'图片描述30字\',this.className=\'jsInputCount input_text w126\'" onclick="if(this.value==\'图片描述30字\')this.value=\'\',this.className=\'jsInputCount input_text w126 input_text_on\'" class="jsInputCount input_text w126" value="图片描述30字" name="p_title[]"></div></div>';
            }
            $("#" + upload_nail).append(content);
            $("#picshow" + upload_infotype).show();
        }
    }


    $(function(){

        /****
         var showBtn = $('.show-btn'),
         showDiv = $('#xg_rule');
         showBtn.click(function(){
        if(showDiv.height()<150){
            showBtn.css({
                    'background':'url({$conf_url}/template/sz/images/show_btn_ico.gif) no-repeat -1px -1px'
                })
            showDiv.animate({
            'height':'150px'
            })
        }else{
            showBtn.css({
                    'background':'url({$conf_url}/template/sz/images/show_btn_ico.gif) no-repeat -1px -1px'
                })
            showDiv.animate({
            'height':'20px'
            })
        }
    });***/

        $(".pictitle").keyup(function(){

            var str=$(this).val();
            var obj_value_arr = str.split("");

            var num = 0;
            for(var i = 0; i < obj_value_arr.length; i++)
            {
                num += returnStrLen(obj_value_arr[i]);
            }
            if(num>60)
            {
                var num=$(this).val().substr(0,30);
                $(this).val(num);
                alert("超过字数(30个汉字)限制，多出的字将被截断！" );
            }
        });


        $("#blockshowname").blur(function(){
            //addlishi(123);
            //$("#historyHouse").hide();
            //getBlockImg(1);
        });
        $("input[name=room]").blur(function(){
            getBlockImg(1);
        });

        $("input[name=hall]").blur(function(){
            getBlockImg(1);
        });
    })

    //图库推荐图片ajax请求地址
    var isort0url = '';
    var isort1url = '';
    getBlockImg(1);

    //获取小区图库图片
    function getBlockImg(page,type)
    {
        type = type || false ;
        var blockname = $("input[name=blockshowname]").val();
        blockname = encodeURIComponent(blockname);
        var room = $("input[name=room]").val();
        var hall = $("input[name=hall]").val();
        $("#jsPicPreviewList1").html('');
        $("#tuku1").hide();
        $("#t1").html('');
        $("#jsPicPreviewList0").html('');
        $("#tuku0").hide();
        $("#t0").html('');
        if(blockname != '')
        {
            var url1 = "/ajax/find_block_img/?blockname="+blockname+"&page="+page;
            /***
             if(isort1url != url1)
             {
                 isort1url = url1;
                 $.get(isort1url, function(data){
                     if(data)
                     {
                     $("#jsPicPreviewList1").html(data);
                     checkImgSelected(1);
                     $("#tuku1").show();
                     $("#t1").html("365图库为您推荐了<span style='color:#F47936;font-weight:bold;'>"+$("#pic_num").attr("value")+"</span> 张小区外景图片供您选择");
                     }
                 });
             }***/
            $.get(url1, function(data){
                if(data) {
                    $("#jsPicPreviewList1").html(data);
                    checkImgSelected(1);
                    if(type)
                    {
                        var is_display = $($("#jsPicPreviewList1").children("div").get(0)).find('.btn').css('display');
                        if(is_display != 'block' && $("#thumbnails1").find("img").length <5)
                        {
                            //$("#jsPicDepotSZMod").show();
                            $("#jsPicDepotSZBtn").find(".jsZK").click();
                            $($("#jsPicPreviewList1").children("div").get(0)).click();
                        }
                    }
                    $("#tuku1").show();
                    $("#t1").html("365图库为您推荐了<span style='color:#F47936;font-weight:bold;'>"+$("#pic_num").attr("value")+"</span> 张小区外景图片供您选择");
                }
            });
        }

        if(blockname != '' && !(room == 0 && hall == 0))
        {
            var url0 = url1+"&room="+room+"&hall="+hall;
            /***
             if(isort0url != url0)
             {
                 isort0url = url0;
                 $.get(isort0url, function(data){
                     if(data)
                     {
                     $("#jsPicPreviewList").html(data);
                     checkImgSelected(0);
                     $("#tuku0").show();
                     $("#t0").html("365图库为您推荐了<span style='color:#F47936;font-weight:bold;'>"+$("#pic_num1").attr("value")+"</span> 张小区户型图片供您选择");
                     }
                 });
             }  ***/
            $.get(url0, function(data){
                if(data)
                {
                    $("#jsPicPreviewList").html(data);
                    checkImgSelected(0);
                    $("#tuku0").show();
                    $("#t0").html("365图库为您推荐了<span style='color:#F47936;font-weight:bold;'>"+$("#pic_num1").attr("value")+"</span> 张小区户型图片供您选择");
                }
            });
        }


    }

    //上传图片点击设为标题图
    function setIndexPic(obj)
    {
        //console.dir($(this).find(".mPic:first"));
        //.children(':first').attr('src')
        var pic1 = $(obj).val();

        if(/^(http.+)_([0-9]+)x([0-9]+)\.([a-z]+)(\?pid=([0-9]+))?$/.test(pic1))
        {
            var imageValArr = /^(http.+)_([0-9]+)x([0-9]+)\.([a-z]+)(\?pid=([0-9]+))?$/.exec(pic1);

            pic1 = imageValArr[1]+'_'+imageValArr[2]+'x'+imageValArr[3]+'.'+imageValArr[4];
        }

        $('#pic1').val(pic1);
    }
    //检查图片标题
    function checkPicTitle(obj)
    {
        var str = obj.value;
        var obj_value_arr = str.split("");

        var num = 0;
        for(var i = 0; i < obj_value_arr.length; i++)
        {
            num += returnStrLen(obj_value_arr[i]);
        }
        if(num>60)
        {
            var num = str.substr(0,30);
            obj.value = num;
            alert("超过字数(30个汉字)限制，多出的字将被截断！" );
        }
    }
    //选择图库图片
    function selectBlockImg(id, src, sort)
    {
        var bigimg = src.replace('/thumb','');
        var bigimg = bigimg.replace(/_(.*?)\./g,'.');
        var ischecked = $("#bimg_checkbox_"+id).attr("checked");

        if(document.getElementById("bimg_"+id) && ischecked == false)
        {
            $("#bimg_"+id).remove();
            if(sort == 10)
            {
                swfu1.setButtonDisabled(false);
            }
            else
            {
                swfu0.setButtonDisabled(false);
            }
        }
        else if(!document.getElementById("bimg_"+id))
        {
            var sort1 = sort == 9 ? 0 : 1;
            var oSwfu = sort1 == 0 ? swfu0 : swfu1;

            if( $("#thumbnails"+sort1+" img").size() < oSwfu.customSettings.upload_limit )
            {
                var content = "<div class='mItem'><div class='mItemInner'><div class='mPic'><img width='130' height='100' num='7' src='"+src+"' alt=''><div class='funM'></div><div class='funMtext'><label><input type='radio' name='jsPicPreviewList' class='input_r'>封面</label><div imageSrc='"+src+"' title='删除' class='delBtn'  ></div></div></div></div><div class='inputBoxM jsNameInput nameInput '><input type='text' onblur='if(this.value=='')this.value='图片描述30字',this.className='jsInputCount input_text w126'' onclick='if(this.value=='图片描述30字')this.value='',this.className='jsInputCount input_text w126 input_text_on'' class='jsInputCount input_text w126' value='图片描述30字'></div></div>";

                $("#thumbnails"+sort1).append(content);

                if( $("#thumbnails"+sort1+" img").size() >= oSwfu.customSettings.upload_limit ) oSwfu.setButtonDisabled(true);
            }
            else
            {
                $("#bimg_checkbox_"+id).attr("checked",false);
                alert("对不起，您选择的文件数量已达上限。");
            }
        }
    }
    //设置图片是否同意入库
    function checkPblockPic(obj)
    {
        var self = $(obj);
        var p_block = self.val();
        if(self.attr('checked') == true)
        {
            $("#"+p_block).val('1');
        }
        else
        {
            $("#"+p_block).val('0');
        }
    }
    //判断图片是否已选择
    function checkImgSelected(sort)
    {
        var img1s = $("#thumbnails"+sort+" img");
        var img2s = $("#jsPicPreviewList"+sort+" img");
        var img2src = '';
        var img2id = '';

        var img1sarr = new Array();
        var temp = 0;
        img1s.each(function(){
            img1sarr[temp] = $(this).attr('src');
            temp++;
        });

        img2s.each(function(){
            var item = $(this);
            img2src = item.attr('src');
            img2id = item.attr('id');
            img1s.each(function(){
                for(var i=0;i<temp;i++)
                {
                    if(img1sarr[i] == img2src)
                    {
                        item.parents(".item").find(".btn").show();
                    }
                }
            });

        });
    }
    function setPicDel(delid)
    {
        var delpic = $("#delpic").val();
        delpic += delpic != '' ? ','+delid : delid;
        $("#delpic").val(delpic);
    }
    //选择图库图片 box==可点击选择图片外部div ID，  number==最多可以选择的张数  toBox==添加到的div的ID   jsNameInputDz
    function picPreview(box,number,toBox,cs){
        $("#"+toBox).find(".mItem").find(".delBtn").live("click",function(){

            //var picVal = $(this).prev().attr('href');
            var picVal = $(this).attr('imageSrc');

            if(/^(http.+)_([0-9]+)x([0-9]+)\.([a-z]+)(\?pid=([0-9]+))?$/.test(picVal))
            {
                var imageValArr = /^(http.+)_([0-9]+)x([0-9]+)\.([a-z]+)(\?pid=([0-9]+))?$/.exec(picVal);

                picVal = imageValArr[1]+'_'+imageValArr[2]+'x'+imageValArr[3]+'.'+imageValArr[4];
            }

            var pic1 = $('#pic1').val();

            if(picVal == pic1)
            {
                $('#pic1').val('');
            }
            /*
                        if($(this).attr("id")==0)
                        {
                            swfu0.setButtonDisabled(false);
                        }
                        if($(this).attr("id")==1)
                        {
                            swfu1.setButtonDisabled(false);
                        }
                        if($(this).attr("id")==2)
                        {
                            swfu2.setButtonDisabled(false);
                        }*/

            $(this).parents(".mItem").remove();
            var oNum = $(this).parents(".mItem").find("img").attr("num");
            $("#"+box).find("img").each(function(index, element) {
                if($(this).attr("num") == oNum )
                {
                    $(this).parents(".item").find(".btn").hide()
                }
            });
        });
        $("#"+box).find(".item").live("click",function(){
            if(box=='jsPicPreviewList1')
            {
                $("#picshow1").show();
            }else if(box=='jsPicPreviewList0')
            {
                $("#picshow0").show();
            }
            if($(this).find(".btn").is(":hidden"))
            {
                if($("#"+toBox).find("img").length == number)
                {
                    openWin("jsDialog");
                    $("#jsDialog .text").empty().html("对不起！您最多只可添加 "+number+" 张图片");
                    return false
                }
                $(this).find(".btn").show();

                var oNewImg = $(this).find(".pic").html();
                var oForId = toBox +'_' + $(this).find(".pic").find("img").attr("num");
                var oPicLink = $(this).find(".bigPicLin").attr("href");
                var oHtml = '<div class="mItem "><div class="mItemInner">'
                    +'<div class="mPic">'
                    +oNewImg
                    +'<input type="hidden" value="'+$(this).find(".pic").find("img").attr("src")+'?pid=' +$(this).find(".pic").find("img").attr("num") + '" name="p_filename[]">'
                    +'<input class="psort" type="hidden" value="'+cs+'" name="p_sort[]">'
                    +'<div class="funM">'
                    +'</div>'
                    +'<div class="funMtext">'
                    +'<label>'
                    +'<input type="radio" onclick="setIndexPic(this);" value="'+$(this).find(".pic").find("img").attr("src")+'?pid=' +$(this).find(".pic").find("img").attr("num") + '" class="input_r" name="jsPicPreviewList" />封面</label><a class="bigPicLin" style="bottom:84px;" target="_balnk" href="'+oPicLink+'" title="查看大图">查看大图</a>'
                    +'<div class="delBtn" title="删除" id="'+cs+'"  imageSrc="'+$(this).find(".pic").find("img").attr("src")+'"></div>'
                    +'</div>'
                    +'</div>'
                    +'</div>'
                    +'<div class="inputBoxM jsNameInput nameInput ">'
                    +'<input value="图片描述30字" type="text" class="jsInputCount input_text w126" onclick="if(this.value==\'图片描述30字\')this.value=\'\',this.className=\'jsInputCount input_text w126 input_text_on\'" onblur="if(this.value==\'\')this.value=\'图片描述30字\',this.className=\'jsInputCount input_text w126\'"/ name="p_title[]">'
                    +'</div>'
                    +'</div>'
                $(oHtml).appendTo("#"+toBox)//jsPicPreviewBoxM
                $("#picshow"+cs).show();
            }
            else
            {
                var oNum = $(this).find("img").attr("num");
                $("#"+toBox).find("img").each(function(index, element) {
                    if($(this).attr("num") == oNum )
                    {
                        $(this).parents(".mItem").remove()
                    }
                });
                $(this).find(".btn").hide();
            }
        })

    }
    picPreview("jsPicPreviewList1",5,"thumbnails1",1)
    picPreview("jsPicPreviewList2",10,"thumbnails2",2)
    picPreview("jsPicPreviewList",3,"thumbnails0",0)




    //图片选择拖动
    function picPreviewLive(obj){
        $("#"+obj).sortable();//拖动
        $("#"+obj).find(".mItemInner").find("img").live("mousemove",function(event){
            if($("#coordinates").length <=0)
            {
                $("<div id='coordinates' class='radius5' >点击拖动</div>").appendTo("body");
            }
            if($("#coordinates").length >=0)
            {
                var oDiv=$("#coordinates");
                oDiv.css({left:event.pageX+4+'px',top:event.pageY+4+'px'})
            }
        }).live("mouseout",function(){
            $("#coordinates").remove()
        })

        $("#"+obj).find(".mItem").live("mousedown",function(){//
            $("#coordinates").hide();
            $(this).addClass("mItemHover");
            $(this).siblings(".mItem").find("img").css({opacity:0.4});
            $(this).siblings(".mItem").find(".funM").css({opacity:0.2});
            $(this).siblings(".mItem").find(".funMtext").css({opacity:0.4});

        }).live("mouseup",function(){
            $("#coordinates").hide();
            $(this).removeClass("mItemHover");
            $(this).siblings(".mItem").find("img").css({opacity:1});
            $(this).siblings(".mItem").find(".funM").css({opacity:.6});
            $(this).siblings(".mItem").find(".funMtext").css({opacity:1});
        })

        $("#"+obj).find("label").live("mousedown",function(event){
            event.stopPropagation()
        })

        $("#"+obj).find(".delBtn").live("mousedown",function(event){
            event.stopPropagation()
        })
        $("#"+obj).find(".jsInputCount ").live("mousedown",function(event){
            event.stopPropagation()
        })

    }
    $(function() {
        picPreviewLive("thumbnails10");
        picPreviewLive("thumbnails2");
        picPreviewLive("thumbnails1");
        picPreviewLive("thumbnails0");


        $(".bigPicLin").live("click mousedown",function(event){
            $(this).parents(".mItem").removeClass("mItemHover");
            event.stopPropagation();
        });
    });


</script>
