<div class="layout" id="centre">
    <div class="broadCentre radius5">
        <div class="hd">
            <h3 class="h3">
                <?=$method_name ?><?=$module_name ?>房源模板</h3>
            <p class="more"><a href="<?=$documentation['house_template']?>" class="link" target="_blank">使用说明&gt;&gt;</a></p>
        </div>
        <div class="mod">
            <div class="editTemplate">
                <form method="post" action="<?= $action ?>" id="template_add" name="template_add" novalidate="novalidate">
                    <div class="forms">
                        <dl class="list">
                            <!---->
                            <dd class="list_item clearfix">
                                <label class="label">模版名称：</label>
                                <div class="fields">
                                    <div class="fields nameInput">
                                        <div class="fgInput jsNameInput jsFgInput">
                                            <label class="labelPrev labelPrevN jslabelPrev" for="template_name">模板名称最多6个字</label>
                                            <?php
                                            if (!isset($template_name)) {
                                                $template_name = '';
                                            }
                                            ?>
                                            <input type="text" class="jsNameInputT2 input_text w170" id="template_name" name="template_name" value="<?=$template_name ?>">
                                            <input type="hidden" id="template_name_temp" name="template_name_temp" value="<?=$template_name ?>">
                                        </div>
                                        <div class="fgInput textFgErroy" id="showerror"></div>
                                    </div>
                                </div>
                            </dd>
                            <dd class="list_item clearfix">
                                <label class="label">小区：</label>
                                <div class="fields nameInput jsNameInput">
                                    <div class="fgInput jsFgInput">
                                        <?php
                                        if (!isset($block_name)) {
                                            $block_name = '';
                                        }
                                        ?>
                                        <label for="blockshowname" class="labelPrev jslabelPrev" id="jsLabelBlockshowname">输入小区名称 从下拉列表中选择</label>
                                        <input type="text" name="blockshowname" id="blockshowname" class="input_text w205 " value="<?=$block_name ?>">
                                        <?php
                                        if (!isset($block_id)) {
                                            $block_id = '';
                                        }
                                        ?>
                                        <input type="hidden" name="block_id" id="block_id" value="<?=$block_id ?>">
                                    </div>
                                    <div class="fgInput textFgErroy"></div>
                                </div>
                            </dd>
                            <dd class="list_item clearfix">
                                <label class="label">地址：</label>
                                <div class="fields">
                                    <div class="fgInput">
                                    <?php
                                    if (!isset($district)) {
                                        $district = '';
                                    }
                                    ?>
                                        <input type="text" readonly="" class="input_text w70 readonly_input_text" name="district" id="district" value="<?=$district ?>">
                                    </div>
                                    <span class="fg">一</span>
                                    <?php
                                    if (!isset($street)) {
                                        $street = '';
                                    }
                                    ?>
                                    <div class="fgInput">
                                        <input type="text" readonly="" class="input_text w70 readonly_input_text" name="street" id="street" value="<?=$street ?>">
                                    </div>
                                    <span class="fg">一</span>
                                    <?php
                                    if (!isset($address)) {
                                        $address = '';
                                    }
                                    ?>                             
                                    <div class="fgInput">
                                        <input type="text" readonly="" class="input_text w170 readonly_input_text" name="blockaddress" id="blockaddress" value="<?=$address ?>">
                                    </div>
                                </div>
                            </dd>
                            <!---->
                            <dd class="list_item clearfix">
                                <label class="label">房源描述：</label>
                                <div class="fields jsFgInput">
                                    <?php
                                    if (!isset($remark)) {
                                        $remark = '';
                                    }
                                    ?>
                                   <textarea name="remark" id="remark" cols="0" rows="0" style="margin-top:5px; width:835px; height:155px; display:none;"><?=$remark ?></textarea>
                                   
                                   <!--<input type="text" name="remark" class="importantBlock" id="remark" value="">-->
                                    <div class="editorBox"> <iframe id="remark_iframe" frameborder="0" scrolling="no" src="/editor/house_template/" style="width:792px; height:390px;"></iframe></div>
                                    
                                 <!--   <input type="text" name="remark2" class="importantBlock" id="remark2" value="">
                                     -->     
                                           
                                    
                               </div>
                                <div  class="textFgErroy" style="margin-left:88px;">
                                    <label class="error" id="jsErrorBox" style="display:none;width:229px;"></label>
                                </div>
                                

                            </dd>

                            <dd class="list_item clearfix">
                                <label class="label">&nbsp;</label>
                                <div class="fields">
                                    <input type="hidden" name="actiontype" value="submitadd">
                                    <?php
                                    if (!isset($id)) {
                                        $id = '';
                                    }
                                    ?>
                                    <input type="hidden" name="id" value="<?=$id ?>">
                                    <input type="hidden" name="module" value="<?=$module ?>">
                                    <input class="btn btnConColor radius5" style="cursor:pointer;" type="button" value="保存" onclick="checktemplate('<?=$module ?>')">
                                    <a class="btn btnCon radius5" type="button" style="cursor:pointer;" href="<?php echo $url_manage . $module . '/'; ?>">取消</a>
                                </div>
                            </dd>
                        </dl>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div id="newblockadd" class="dialog dialog2 radius5" style="position: absolute; z-index: 9999902; left: 50%; margin-left: -202.5px; top: 310px; display: none;">
    <div class="hd">
        <h3 class="h3">添加新小区</h3>
        <span title="关闭" class="close close-win">Χ</span> </div>
    <div class="mod">
        <form method="post" action="" id="block_add" name="block_add">
            <div class="forms">
                <dl class="list">
                    <dd class="list_item clearfix">
                        <label class="label">小区名称：</label>
                        <div class="fields nameInput ">
                            <div class="fgInput jsNameInput jsFgInput">
                                <label for="jsNameInputOp" class="labelPrev labelPrevN jslabelPrev"><!--请输入小区名称2-8个汉字--></label>
                                <input type="text" class="jsNameInputOp input_text w170" id="jsNameInputOp" name="tcblockname">
                            </div>
                        </div>
                    </dd>
                    <dd class="list_item clearfix ">
                        <label class="label">小区区属：</label>
                        <div class="fields nameInput imitateSelect2">
                            <div class="fgInput jsFgInput">
                                <div class="imitateSelect">
                                    <label class="labelImitate" style="display: inline;">请选择区属</label>
                                    <input type="text" class=" imitate imitateIe" readonly="" name="tcdistrict" id="tcdistrict" value="">
                                    <!--<label  class="error">请选择区属</label>-->
                                    <div class="listImitate">
                                        <dl class="inner innerScroll">
                                        <?php foreach ($house['district'] as $value){  ?>
                                            <dd><a class="link" onclick="getstreet(this);" href="#" ><?=$value ?></a></dd>
                                        <?php } ?>
                                        </dl>
                                    </div>
                                </div>
                            </div>
                            <p class="textFg textFgLabel">版块：</p>
                            <div class="fgInput jsFgInput">
                                <div class="imitateSelect ">
                                    <label class="labelImitate" id="qs" style="display: inline;">请选择版块</label>
                                    <input type="text" class=" imitate imitateIe" readonly="" name="tcstreetname" value="" id="bankuai">
                                    <input type="hidden" class="jsImitateHidden" id="tcstreetid" name="tcstreetid" value="">
                                    <!--<label  class="error">请选择版块</label>-->
                                    <div class="listImitate">
                                        <dl class="inner innerScroll" id="street_add">
                                        </dl>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </dd>
                    <dd class="list_item clearfix">
                        <label class="label">小区地址：</label>
                        <div class="fields nameInput ">
                            <div class="fgInput jsNameInput jsFgInput">
                                <label for="jsNameInputDz" class="labelPrev labelPrevN jslabelPrev">请输入小区地址2-30个汉字</label>
                                <input type="text" class="jsNameInputDz input_text w276" id="jsNameInputDz" name="tcaddress">
                                <label class="error" id="xqerror" style="display:none"></label>
                            </div>
                        </div>
                    </dd>
                    <dd class="list_item clearfix"> <a id="jsBtnSubmitP" onclick="tempblock_add()" href="####" class="btnPopo btnCon radius5">提交</a> </dd>
                </dl>
            </div>
        </form>
    </div>
</div>
<div id="JS_noteHouse1" class="dialog radius5">
    <div class="hd">
        <h3 class="h3">提示</h3>
        <span title="关闭" class="close close-win">Χ</span> </div>
    <div class="mod">
        <div class="text"> 添加成功</div>
    </div>
</div>
<div id="JS_noteHouse2" class="dialog radius5">
    <div class="hd">
        <h3 class="h3">提示</h3>
        <span title="关闭" class="close close-win">Χ</span> </div>
    <div class="mod">
        <div class="text"> 添加模板成功</div>
    </div>
</div>
<div id="JS_noteHouse3" class="dialog radius5">
    <div class="hd">
        <h3 class="h3">提示</h3>
        <span title="关闭" class="close close-win">Χ</span> </div>
    <div class="mod">
        <div class="text">模版名称重复</div>
    </div>
</div>
<?=$page_js?>
<script type="text/javascript">
    function checktemplate(module) {	
           templatename=encodeURI(encodeURI($("#template_name").val()));
           template_name_temp=encodeURI(encodeURI($("#template_name_temp").val()));
           //判断是否被修改，没被修改不验证直接提交
           if( templatename != template_name_temp)
           {
                $.ajax({ 
                    type: 'get',  
                    url : '/ajax/exist_templatename/', 
                    data: 'templatename='+templatename+'&module='+module,
                    dataType:'html',
                    success: function(msg){		
                          if(msg==1)
                          {
                          //openWin('JS_noteHouse3');
                          $("#showerror").html("<label for='template_name' class='error'>模版名称重复</label>");
                          }else{
                          $("#template_add").submit();
                          }
                    }  
                }); 
         }else{
            $("#template_add").submit();
         }
    }

    //添加临时模板
    function tempblock_add () {	
        var query = $("#block_add").serialize();
        $.ajax({
            type: 'get',
            url : '/ajax/add_temp_block/',
            data: query,
            dataType:'json',
            success: function(data){
                var msg = data.code;
                switch(msg){
                    case '100':
                        $("#xqerror").html("小区名称在2-8个汉字之间");
                        $("#xqerror").show();
                        break;
                    case '300':
                        $("#xqerror").html("已存在同名小区！");
                        $("#xqerror").show();
                        break;
                    case '400':
                        $("#xqerror").html("区属必须选择！");
                        $("#xqerror").show();
                        break;
                    case '500':
                        $("#xqerror").html("版块必须选择！");
                        $("#xqerror").show();
                        break;
                    case '600':
                        $("#xqerror").html("小区地址在2-30汉字之间！");
                        $("#xqerror").show();
                        break;
                    case '700':
                        $("#xqerror").html("小区地址已存在！");
                        $("#xqerror").show();
                        break;
                    case '200':
                        openWin('JS_noteHouse1'); 
                        $("#jsLabelBlockshowname").hide();
                        $("#blockshowname").val($("#jsNameInputOp").attr("value"));
                        $("#block_id").val(data.id);
                        $("#district").val($("#tcdistrict").attr("value"));
                        $("#street").val($("#bankuai").attr("value"));
                        $("#streetid").val($("#tcstreetid").attr("value"));
                        $("#blockaddress").val($("#jsNameInputDz").attr("value"));
                        break;
                    default:
                        alert("提交失败，请致电客服热线");
                        break;
                }
            }
        });
    }

    $(function() {
        $("#blockshowname").autocomplete({
            source: function( request, response ) {
                clearblockinfo();
                $.ajax({
                    url: "/ajax/find_like_block_list/",
                    type: "POST",
                    dataType: "json",
                    data: {
                        blockname: encodeURIComponent($("#blockshowname").val())
                    },
                    success: function(data) {
                        //判断返回数据是否为空，不为空返回数据，为空返回增加小区链接。
                        if( data[0]['id'] != "0"){
                            response(data);
                            //hiddenblockadd();
                            //getBlockImg(1);
                        }else{
                            response(data);
                            //showblockadd();
                        }
                    }
                });
            },
            minLength: 1,
            removeinput: 0,
            select: function( event, ui ) {
                if(ui.item.id > 0){
                    var blockname = ui.item.label;
                    var district = ui.item.district;
                    var street = ui.item.streetname;
                    var streetid = ui.item.streetid;
                    var averprice = ui.item.averprice;
                    var address = ui.item.address;
                    var blockesta = ui.item.esta_block;
                    var url_block = ui.item.url_block;
                    var id = ui.item.id;

                    //获得小区板块
                    getblock(district,street,address,id,streetid);
                    //显示小区(价格、地址、状态)信息
                    //showblockinfo (averprice , address ,blockesta);
                    //显示小区纠错地址
                    //showblockurl(url_block,blockname);
                    //获取小区id
                    //showblockid(id,blockname);
                    removeinput = 0;
                    //getBlockImg(1);
                }else{
                    removeinput = 1;
                    block_add();
                    //remove_blockinfo();
                }
            },
            close: function(event) {
                if(typeof(removeinput)=='undefined' || removeinput == 1)
                    $("#blockshowname").val("");
            }
        });
    });
</script>