window.CheckAverpice = false;
window.LoginOut = 'http://nj.zsb.house365.com/sell/jump/login/';
//单击发布小区
function addlishi(id)
{
  if(id>0)
  {
    $.ajax({
         type: 'get',
         url : '/ajax/find_block_detail/',
         data: {'id' : id},
         dataType:'json',
         success: function(data){
			if(data.errorCode == '401')
			{
				jump_win(LoginOut , '请重新登录');
				return false;
			}
            $("#district").val(data.district);
            $("#street").val(data.streetname);
            $("#blockaddress").val(data.address);
            $("#block_id").val(data.id);
            $("#blockshowname").val(data.blockname);
            getBlockImg(1);
            if ($('#tbl').val() == 'sell') {
                showblockinfo (data.averprice , data.address ,data.esta_block, data.url_block);
            }
         }
     });
   }else{
	
   }
}

//添加临时模板
function tempblock_add () {	
	var query = $("#block_add").serialize();
	$.ajax({
		type: 'get',
		url : '/ajax/add_temp_block/',
		data: query,
		dataType:'json',
		success: function(data){
			if(data.errorCode == '401')
			{
				jump_win(LoginOut , '请重新登录');
				return false;
			}
			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 returnStrLen(sStr) {
	aMatch = sStr.match(/[\u4E00-\u9FA5|，]+/g);
	return (!aMatch ? 1 : 2);
}
	
//发布出租 租赁方式选择
$(".jsInput_rRadio").click(function(){							
    if($(this).val() == '合租')
    {
        $("#jsLeaseWaySelect").show()
    }
    else
    {
        $("#jsLeaseWaySelect").hide()
    }
});	

//autocomplete后单击小区填充信息
function getblock( district,street,address,id,streetid) {
	$("#district").val(district);
	$("#street").val(street);
	$("#streetid").val(streetid);
	$("#blockaddress").val(address);
	$("#block_id").val(id);
}

//添加小区
function block_add(){
	$('#jsNameInputOp').val($('#blockshowname').val());
	openWin('newblockadd');
}

//区属找板块
function getstreet(obj) {	
	text1=encodeURI(encodeURI($(obj).text()));
	$.ajax({ 
		async:false,  
		type: 'get',  
		url : '/ajax/find_street_list/', 
		data: 'district='+text1,
		dataType:'html',
		success: function(msg){		
			if(msg == 'errorCode401')
			{
				jump_win(LoginOut , '请重新登录');
				return false;
			}
			$("#street_add").html(msg);
			$("#qs").html("请选择版块");
			$("#bankuai").html("请选择版块");
		}  
	}); 
}
//设置编译器的值
function setEditorRemark(html) {
	$('#remark').val(html);
	$("#remark_iframe").contents().find(".ke-edit-iframe").contents().find('.ke-content').html(html);
}
function reload_remark() {
	/***
	var randnum = Math.random();
	var iframeurl = "/editor/house/?" + randnum;
	$("#remark_iframe").attr("src",iframeurl);***/

	/*var oIframe = document.getElementById("remark_iframe");
	oIframe.contentWindow.document.getElementsByTagName('iframe')[0].innerHTML = ''; 
	alert(0)*/
	setEditorRemark('');
}	

function savetemplate()
{
	$("#t_blockname").val($("input[name='blockshowname']").val());
	
	$("#t_remark").val($("#remark").attr("value"));
	$("#t_district").val($("#district").attr("value"));
	$("#t_street").val($("#street").attr("value"));
	$("#t_blockaddress").val($("#blockaddress").attr("value"));
	$("#t_block_id").val($("#block_id").attr("value"));
	$("#t_streetid").val($("#streetid").attr("value"));
	document.t_add.submit();
}
 
 function showblockinfo (averprice , address ,blockesta, urlblock){
    var str = '';
	$("#blockPrice").html(''); 
	if (averprice > 0) {
		str = str + '<span class="tB">均价：<strong class="p" id="averprice">' + averprice + '</strong>元/㎡</span>';
	} else {
		str = str + '<span class="tB">均价：<strong class="p" id="averprice">暂无均价</strong></span>';
	}
	str = str + '<span class="tB">状态：<strong class="zN">' + blockesta + '</strong></span>';
	if (blockesta == '正式小区') {
		str += '<a class="tB" href="' + urlblock + '" target="_blank">查看详情&gt;&gt;</a>';
	}
	$(".blockPBox").css('display', 'block'); 
	$("#blockPrice").html(str); 
	window.CheckAverpice = false;
}

function clearblockinfo()
{
	$(".blockPBox").css('display', 'none'); 
	$("#blockPrice").html(''); 
	$("#district").val('');
	$("#street").val('');
	$("#streetid").val('');
	$("#blockaddress").val('');
	$("#block_id").val('');
	$("#remark").val('');
	$("#tuku1").hide();
	$("#t1").html('');
	$("#tuku0").hide();
	$("#t0").html('');
	reload_remark();
	window.CheckAverpice = false;
}
//设置价格的label和priceunit
function setPriceLabelAndUnit(label, unit) {
	$('#priceunitname').val('');
	$('#priceunitname').val(label);
	$('#priceunit').val(unit);
}
//用于租赁方式切换价格
function changePriceUnit(rentType, infotype) {
	if (infotype == 1 || infotype == 2) {
		$('#priceunitshow').css('display', 'none');
		$('#priceshow3').css('display', 'none');
		$('#priceshow4').css('display', 'none');
		if (rentType == '日租') {
			$('#priceshow1').css('display', 'none');
			$('#priceshow2').css('display', 'block');
			setPriceLabelAndUnit('元/天', 4);
		} else {
			$('#priceshow1').css('display', 'block');
			$('#priceshow2').css('display', 'none');
			setPriceLabelAndUnit('元/月', 1);
		}
	} else {	
		$('#priceshow1').css('display', 'none');
		$('#priceshow2').css('display', 'none');
		$('#priceunitshow').css('display', 'block');
		if (rentType == '日租') {
			$('#priceshow3').css('display', 'none');
			$('#priceshow4').css('display', 'block');
			setPriceLabelAndUnit('元/天*平方米', 2);
		} else {
			$('#priceshow3').css('display', 'block');
			$('#priceshow4').css('display', 'none');
			setPriceLabelAndUnit('元/月', 1);
		}
	}
}

//去除左右空格
function ltrimSpace(str) {
	return str.replace(/\s+/g,"");
}

function getfeature(infotype) {	
   if (infotype == 1 || infotype == 2 || infotype == 3 || infotype == 4) {
		$('#feature_id').css('display', 'block');
		$('#jsAddTagBox').html('');
   } else {
		$('#feature_id').css('display', 'none');
   }
   $.ajax({ 
	async:false,  
	type: 'get',  
	url : '/ajax/find_housefeature/', 
	data: 'infotype='+infotype+'&tbl=sell',
	dataType:'html',
	success: function(msg){	
			if(msg == 'errorCode401')
			{
				jump_win(LoginOut , '请重新登录');
				return false;
			}	
			$("#jsAddTagInnerBox").html(msg);
			html = '';
			for(i=0; i<3; i++) {
				html += '<p class="addTag radius4">+</p>';
			}
			$('#jsAddTagBoxN').html(html);
		}  
	}); 

}

//检测房源发布价格范围规则
var checkPriceRangeRule = function(result)
{
	if(typeof result != 'undefined' && result.status == 200  && parseFloat(result.data.averprice) > 0)
	{
		var averprice = parseFloat(result.data.averprice);
		//priceRatio = ((currentPrice - averprice)/averprice).toFixed(1);
		priceRatio = (currentPrice - averprice)/averprice;

		//判断是否疑似虚假房源
		if(suspectedShamRange.length > 0)
		{
			if((parseFloat(suspectedShamRange[0].min)/100) <= priceRatio && (parseFloat(suspectedShamRange[0].max)/100) > priceRatio)
			{
				showPop('.popfalse');
				return false;
			}

			if((parseFloat(suspectedShamRange[1].min)/100) < priceRatio && (parseFloat(suspectedShamRange[1].max)/100) >= priceRatio)
			{
				showPop('.popfalse');
				return false;
			}
		}

		//判断系统拦截房源
		if(systemInterceptRange.length > 0)
		{
			if((parseFloat(systemInterceptRange[0].min)/100) <= priceRatio && (parseFloat(systemInterceptRange[0].max)/100) > priceRatio)
			{
				showPop('.popintercept');
				return false;
			}

			if((parseFloat(systemInterceptRange[1].min)/100) < priceRatio && (parseFloat(systemInterceptRange[1].max)/100) >= priceRatio)
			{
				showPop('.popintercept');
				return false;
			}
		}

		//判断禁止发布房源
		if(banPublishRange.length > 0)
		{
			if((parseFloat(banPublishRange[0].max)/100) > priceRatio || (parseFloat(banPublishRange[1].min)/100) < priceRatio)
			{
				showPop('.popban');
				return false;
			}
		}
	}
	else
	{
		//判断是否禁止发布
		if(currentPrice < 500 || currentPrice > 350000)
		{	
			showPop('.popban');
			return false;
		}
		else if(mright == '产权房')
		{
			showPop('.popfalse');
			return false;
		}
	}

	return true;
}


//记录每次操作的当前小区ID,防止重复操作查房价
var prevBlockId;

//记录每次操作的当前面积,防止重复操作查房价
var prevBuildarea;

//记录每次操作的当前第几层,防止重复操作查房价
var prevFloor;

//记录每次操作的当前总共多少层,防止重复操作查房价
var prevTotalFloor;

//记录每次操作的当前朝向,防止重复操作查房价
var prevForward;

//记录每次操作的当前几室,防止重复操作查房价
var prevRoom;

//记录每次操作的当前几厅,防止重复操作查房价
var prevHall;

//记录小区查房价
var blockHousePriceData;

//当前小区价格
var currentPrice;

//房源权属
var mright;

//防止重复提交
var repetSubmitStatus = true;
	
$(function() {
	//日租切换
	$("input[name='renttype']").click(function() {
		changePriceUnit($(this).val(), $("input[name='infotype']").val());
	});
    //房源类型切换
    $(".titleTabBox .item").click(function() {
        infotype = $(this).attr('id');
        var tbl = $("input[name='tbl']").val();
        $("input[name='infotype']").val(infotype);
        $(".titleTabBox .itemOn").attr('class', 'item');
        $(this).attr('class', 'item itemOn');
        $.ajax({
            type: 'get',
            url: '/ajax/find_house_add_ext/',
            data: 'tbl='+tbl+'&infotype=' + infotype,
            dataType: 'html',
            success: function(msg) {
				if(msg == 'errorCode401')
				{
					jump_win(LoginOut , '请重新登录');
					return false;
				}
                //写字楼、商铺隐藏房型文本框
                if (infotype != 1)
                {
                    if (infotype == 3 || infotype == 4 || infotype == 5 || infotype == 6) {
                        $("#roomshow").hide();
                    } else {
                        $("#roomshow").show();
                    }
                } else {
                    $("#roomshow").show();
                }
				
                if (infotype == 6)
                {
                    $('#buildyearShow').hide();
                    $('#buildyearShow1').show();
                    $("#fitmentshow").hide();
                    $("#floorshow").hide();	
                    $("#housekindShow").css('display', 'block');	
                } else {
                    $('#buildyearShow').show();
                    $('#buildyearShow1').hide();
                    $("#fitmentshow").show();
                    $("#floorshow").show();	
                    $("#housekindShow").css('display', 'none');	
                }
                $("#infotypeblock").html(msg);
                if ($("input[name='renttype']:checked").val() != '') {
                    changePriceUnit($("input[name='renttype']:checked").val(), $("input[name='infotype']").val());
                }
				//多图数值的控制 住宅为5 非住宅为3
				if (infotype == 1) {
					$('#star_room').html('5');
				} else {
					$('#star_room').html('3');
				}
				getfeature(infotype);
            }
        });
        return true;
    });
	

    //单层 跃层 切换
    $(".jsInputRadio").each(function(index, element) {
        if ($(this).attr("checked") == true || $(this).attr("checked") == "checked")
        {
            $(this).parents(".fgInput")
                    .next(".jsInputBox").show().siblings(".jsInputBox").hide()
        }
    });
    $("#jsInputRadio1").click(function() {
        $("#jsInputBox1").show();
        $("#jsInputBox2").hide();
    })
    $("#jsInputRadio2").click(function() {
        $("#jsInputBox2").show();
        $("#jsInputBox1").hide()
    })

    
	//详细信息 添加房源特色
	$("#jsAddTagInnerBox .addTagInner").hover(function(){
		$(this).addClass("addTagInnerHover");
	},function(){
		$(this).removeClass("addTagInnerHover");
	}).live('click', function(){
		if($(this).hasClass("addTagInnerSelect"))
		{
			$(this).removeClass("addTagInnerSelect");
			$("#jsAddTagBoxN").prepend('<p class="addTag radius4">+</p>')
			
			var oNum =$(this).attr("num")
			
			$("#jsAddTagBox").find(".addTagInner").each(function(index, element) {
				if($(this).attr("num") == oNum )	
				{ 
					$(this).remove()
				}
			});	
		}
		else
		{
			if($("#jsAddTagBox").find(".addTagInner").length >= 3)
			{
				openWin("jsDialog");
				$("#jsDialog .text").empty().html("对不起！您最多只可添加三个标签");
				return false
			}
			$(this).addClass("addTagInnerSelect");
			$('<p class="addTagInner radius4" num='+$(this).attr("num")+'>'+$(this).html()+'<span class="delBtn" title="删除"></span><input type="hidden" name="feature[]" value="'+$(this).attr("num")+'" /></p>').appendTo("#jsAddTagBox")
			$("#jsAddTagBoxN").find(".addTag:first").remove();
		}
	})
	$("#jsAddTagBox").find(".addTagInner").live("mouseover",function(){
		$(this).find(".delBtn").show();
	}).live("mouseout",function(){
		$(this).find(".delBtn").hide();
	})
	$("#jsAddTagBox").find(".delBtn").live("click",function(){

		$(this).parents(".addTagInner").remove();
		$("#jsAddTagBoxN").prepend('<p class="addTag radius4" >+</p>');
		var oNum =$(this).parents(".addTagInner").attr("num")
			
		$("#jsAddTagInnerBox").find(".addTagInner").each(function(index, element) {
			if($(this).attr("num") == oNum )	
			{ 
				$(this).removeClass("addTagInnerSelect")
			}
		});	
	})
    
	$.validator.addMethod("textInteger",function(value,element,params){
		var reg1 = "^-?//d+$";
		if(value.match(reg1)!=0)
		{
			return true
		}
		else
		{
			return false
		}
	},"请正确输入楼层");
	
	$.validator.addMethod("price",function(value,element,params){
		return value > 0
	},"请输入大于0的数");

	$("#jsInputRadio1,#jsInputRadio2").click(function(){
		$(this).parents(".fgInput").siblings(".textFgErroy").find("label.error").hide();
	})

	//出售提交
	$("#jsBtnSubmit_sell").click(function(){
		
		if(!repetSubmitStatus)
		{
			alert('数据已提交中，请勿重复提交！');
			return false;
		}

		repetSubmitStatus = false;

	    //add by gehaifeng start
	    /*if ($('#price').val() != '' && $('#buildarea').val() != '' && $("input[name='infotype']").val() == 1 && $("input[name='mright']").val() == '产权房') {
            if( $('#totalfloor').val() != '' && $('#floor').val() != '' ){
                var rate = 0.9;
                if( $('#floor').val()==1 || $('#totalfloor').val()==$('#floor').val() ){
                    rate = 0.85;
                }
                var area_extend = '0';
                if($('#buildarea').val()<60){
                    area_extend = '10';
                }else if( $('#buildarea').val()>=60 && $('#buildarea').val()<90 ){
                    area_extend = '20';
                }else if( $('#buildarea').val()>=90 && $('#buildarea').val()<144 ){
                    area_extend = '30';
                }else if( $('#buildarea').val()>=144 ){
                    area_extend = '40';
                }
                if(area_prices && area_prices[area_extend]){
                    var a_p = area_prices[area_extend]['average_price'];
                    var h_a_p = ($('#price').val() * 10000 / $('#buildarea').val()).toFixed() ;
                    if( h_a_p < (a_p*rate) ){
                        if( !confirm("您的房源价格疑似虚假，您是否继续发布该房源？\n一旦被核实为虚假房源，会冻结房源，并且直接降1星！") ){
                            return false;
                        }
                    }
                }
            }
		}*/
		//add by gehaifeng end
		
		$("#jsForm_sell").validate({
                    errorPlacement:function(error,element) { 
                        error.appendTo(element.parents(".jsFgInput").siblings(".textFgErroy"))
                    },
//					submitHandler:function(form)
//					{
//						//均价不能小于小区价格的70%
//						if ($('#price').val() != '' && $('#buildarea').val() != ''
//							&& $("input[name='infotype']").val() == 1
//								&& $("input[name='mright']").val() == '产权房') {
//							var rate = 0;
//							rate = $("input[name='lctype']:checked").val() == 1 ? 0.70 : 0.5;
//							var blockaverprice = parseInt($('#averprice').html()) * rate;
//							var buildarea = $('#buildarea').val() ? $('#buildarea').val() : 1;
//							var houseaverprice = ($('#price').val() * 10000 / buildarea).toFixed() ;
//							if (houseaverprice <= blockaverprice && isNaN(blockaverprice) == false) {
//								openWin('JS_noteHouse3');
//								return false;
//							}
//						}
//						//均价不能超过小区价格的30%，只提示一次
//						if (window.CheckAverpice == false && $('#price').val() != ''
//							&& $('#buildarea').val() != '' && $("input[name='infotype']").val() == 1
//								&& $("input[name='mright']").val() == '产权房') {
//							var blockaverprice = parseInt($('#averprice').html()) * 1.30;
//							var buildarea = $('#buildarea').val() ? $('#buildarea').val() : 1;
//							var houseaverprice = ($('#price').val() * 10000 / buildarea).toFixed() ;
//							if (houseaverprice >= blockaverprice && isNaN(blockaverprice) == false) {
//								//南京不让提示过高，暂时屏蔽
//								//openWin('JS_noteHouse2');
//								//window.CheckAverpice = true;
//								//return false;
//								$('#new_login_btn_none').show();
//								form.submit();
//							} else {
//								$('#new_login_btn_none').show();
//								form.submit();
//							}
//						}
//						else
//						{
//							$('#new_login_btn_none').show();
//							form.submit();
//						}
//
//						return false;
//					},
                    rules: 
                    {
                        blockshowname:
                        {
                            required: true
                        },
                        price:
                        {
                            required: true,
                            number:true,
                            price : true
                        },
                        priceterm_name:
                        {
                            required: true
                        },
                        pricetypename:
                        {
                            required: true
                        },
						taxonlytypename:
                        {
                            required: true
                        },
                        buildarea:
                        {
                            required: true,
                            number:true
                        },
                        room:
                        {	
                            required: true,
                            digits:true,
                            min : 1
                        },
                        hall:
                        {
                            required: true,
                            digits:true	
                        },
                        toilet:
                        {
                            required: true,
                            digits:true	
                        },
                        mright:
                        {//权属
                            required: true	
                        },
                        forward:
                        {//朝向
                            required: true
                        },
                        fitment:
                        {//装修
                            required: true
                        },
                        /*housekind:
                        {//别墅类型属性
                            required: true
                        },*/
                        address:
                        {//房源标题
                            required: true,
							remote:{
								url:'/ajax/check_sensitive_word/',
								type: "post",               //数据发送方式
								dataType: "json",           //接受数据格式   
								data: {                     //要传递的数据
									keyword: function() {
										return encodeURI($("#address").val())
									},
									randmod:Math.random()
								}
							}
                        },
                        buildyear:
                        {//建筑年代
                            required: true,
                            digits:true,
                            maxlength:4,
                            minlength:4
                        },
                        ownid:
                        {//建筑年代
                            maxlength:15
                        },
						floor:
						{//单层 1
                            required: function(){
                                if($("#jsInputRadio1").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            number:true,
                            textInteger:true	
                        },
                        totalfloor:
                        {//单层 2
                            required: function(){
                                if($("#jsInputRadio1").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            digits:true,
                            min:function(){
                                return parseInt($("#floor").val())
                            }	
                        },
                        subfloor:
                        {//跃层1
                            required:function(){
                                if($("#jsInputRadio2").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            number:true,
                            textInteger:true	
                        },
                        floor2:
                        {//跃层1
                            required:function(){
                                if($("#jsInputRadio2").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            number:true,
                            min:function(){
                                    return parseInt($("#subfloor").val())
                            },
                            textInteger:true	
                        },
                        totalfloor2:
                        {//跃层1
                            required:function(){
                                if($("#jsInputRadio2").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            digits:true,
                            min:function(){
                                return parseInt($("#floor2").val())
                            }		
                        },
						fee:
                        {
                            number:true	
                        }
			},
			messages: 
			{
				blockshowname:
				{
					required: "请选择小区"
				},
				price:
				{
					required: "请填写售价",
					number:"请正确填写售价"
				},
				priceterm_name:
				{
					required: "请选择价格条件"
				},
				pricetypename:
				{
					required: "请选择税费情况"
				},
				taxonlytypename:
				{
					required: "请选择个费情况"
				},
				buildarea:
				{
					required: "请填写产证面积",
					number:"请正确填写产证面积"
				},
				room:
				{	
					required: "请填写户型",
					digits:"请正确填写户型"	,
					min : "室必须大于0"
				},
				hall:
				{
					required: "请填写户型",
					digits:"请正确填写户型"	
				},
				toilet:
				{
					required: "请填写户型",
					digits:"请正确填写户型"	
				} ,
				houseType5:
				{
					required: "请填写户型",
					digits:"请正确填写户型"	
				},
				mright:
				{//权属
					required: "请选择权属"	
				} ,
				payment:
				{//支付方式
					required: "请选择支付方式"	
				} ,
				forward:
				{//朝向
					required: "请选择朝向"
				},
				fitment:
				{//装修
					required: "请选择装修情况"
				},
				/*housekind:
				{   //别墅类型
					required: "请选择别墅类型"
				},*/
				housekindname:
				{//车位属性
					required: "请选择车位属性"
				},
				address:
				{//房源标题
					required: "请填写房源标题"
				},
				buildyear:
				{//建筑年代
					digits:"请正确填写 - 格式:2010",
					maxlength:"请正确填写 - 格式:2010",
					minlength:"请正确填写 - 格式:2010",
					required: "请填写建筑年代"
				},
				ownid:
				{//建筑年代
					maxlength:"内部编号在15个字之内"
				},
				floor:
				{//单层 1
					required: "请填写楼层",
					number:"请正确填写楼层"		
				},
				totalfloor:
				{//单层 2
					required: "请填写楼层",
					digits:"请正确填写楼层"	,
					min:"楼层必须小于总楼层"	
				},
				subfloor:
				{//跃层 1
					required: "请填写楼层",
					number:"请正确填写楼层"		
				},
				floor2:
				{//跃层 2
					required: "请填写楼层",
					number:"请正确填写楼层"	,
					min:"楼层必须大于底楼"
				},
				totalfloor2:
				{//跃层 2
					required: "请填写楼层",
					digits:"请正确填写楼层"	,
					min:"楼层必须小于总楼层"
				},
				fee:
				{
					number:"请正确填写物业费"	
				}
			}
			//debug:true
		});
		
		var mItemObj = $('#showImage').find('.mItem');

		//var result = true;
		var result = $("#jsForm_sell").valid();
		
		if(result)
		{
			//判断全景图片类型是否选中
			if(mItemObj.length > 0)
			{
				mItemObj.each(function(){
					var imageNum = $(this).attr('imageNum');
					var imageTypeVal = $('#imageType_'+imageNum).val();

					if(!imageTypeVal)
					{
						result = false;
						alert('请选择全景图的类型！');

						//防止重复提交
						repetSubmitStatus = true;

						return false;
					}
				});
			}
			
			//小区名称
			var blockshowName = $('input[name=blockshowname]').val();
			
			//当前第几层
			var floor = parseInt($('#floor').val());

			//总共多少层
			var totalFloor = parseInt($('#totalfloor').val());
			
			//朝向
			var forward = $('input[name=forward]').val();
			
			//几室
			var room = parseInt($('input[name=room]').val());

			//几厅
			var hall = parseInt($('input[name=hall]').val());
			
			//当前房源总价
			var currentTotalPrice = parseFloat($('#price').val());
			
			//房源面积
			var buildarea = parseFloat($('#buildarea').val());
			
			//当前房源单价，保留一位小数
			//currentPrice = ((currentTotalPrice/buildarea).toFixed(1))*10000;
			currentPrice = (currentTotalPrice/buildarea)*10000;
			
			//小区ID
			var currentBlockId = parseInt($('#block_id').val());

			var infotype = parseInt($('input[name=infotype]').val());

			mright = $('input[name=mright]').val();

			if(infotype > 1  || mright == '使用权房')
			{
				//检测房源发布价格范围规则
				var checkResult = checkPriceRangeRule();

				if(checkResult)
				{	
					$("#jsForm_sell").submit();
				}

				//防止重复提交
				repetSubmitStatus = true;

				return true;
			}
			
			//防止重复操作查房价
			if(typeof prevBlockId != 'undefined' && prevBlockId == currentBlockId && prevBuildarea == buildarea && prevFloor == floor && prevTotalFloor == totalFloor && prevForward == forward && prevRoom == room && prevHall == hall)
			{
				//检测房源发布价格范围规则
				var checkResult = checkPriceRangeRule(blockHousePriceData);

				if(checkResult)
				{		
					$("#jsForm_sell").submit();
				}

				//防止重复提交
				repetSubmitStatus = true;
			}
			else if(currentBlockId > 0)
			{
				//获取查房价
				$.ajax({
					type: 'get',
					url: '/sell/getHousePrice',
					data: {
						blockId : currentBlockId,
						blockName : blockshowName,
						buildArea : buildarea,
						floor : floor,
						totalFloor : totalFloor,
						forward : forward,
						livingRoom : room,
						room : hall
					},
					dataType: 'json',
					success: function(result) 
					{
						if(result.status == '200')
						{
							//*******记录参数，防止重复操作查房价START******//
							prevBlockId = currentBlockId;

							prevBuildarea = buildarea;

							prevFloor = floor;

							prevTotalFloor = totalFloor;

							prevForward = forward;

							prevRoom = room;

							prevHall = hall;
							//*******记录参数，防止重复操作查房价END******//

							blockHousePriceData = result;
							
							//检测房源发布价格范围规则
							var checkResult = checkPriceRangeRule(blockHousePriceData);
							
							if(checkResult)
							{	
								$("#jsForm_sell").submit();
							}
						}
						else
						{
							//检测房源发布价格范围规则
							var checkResult = checkPriceRangeRule(result);
							
							if(checkResult)
							{	
								$("#jsForm_sell").submit();
							}
						}

						//防止重复提交
						repetSubmitStatus = true;
					}
				});
			}
			else
			{
				//检测房源发布价格范围规则
				var checkResult = checkPriceRangeRule();

				if(checkResult)
				{		
					$("#jsForm_sell").submit();
				}

				//防止重复提交
				repetSubmitStatus = true;
			}
		}
		else
		{
			//防止重复提交
			repetSubmitStatus = true;
		}
	})
	
	//失效房源提交
	$("#jsBtnSubmit_disablesell").click(function(){
	
		var id =$("#id").val();
		if(id)
		{
			$('#jsForm_sell').attr('action', '/sell/updatedisable/');
			
		}
		else
		{
			$('#jsForm_sell').attr('action', '/sell/insertdisable/');
		}
		
		$("#jsForm_sell").validate({
                    errorPlacement:function(error,element) { 
                        error.appendTo(element.parents(".jsFgInput").siblings(".textFgErroy"))
                    },
					submitHandler:function(form)
					{
						//验证关键字
						$.ajax({
							type: 'post',
							url : '/ajax/banwords/',
							data: {address:encodeURI(encodeURI($('#address').val())),
								remark:encodeURI(encodeURI($('#remark').val()))},
							dataType:'json',
							success: function(data){
								if(data.errorCode == '401')
								{
									jump_win(LoginOut , '请重新登录');
									return false;
								}
								if (data.status == 2) {
									$('#banwords').html('您输入的房源标题中含有敏感词，请重新输入！');
									$('#address').focus();
									openWin('JS_noteHouse4');
									return false;
								} else if (data.status == 3) {
									$('#banwords').html('您输入的房源描述中含有敏感词，请重新输入！');
									$('#remark').focus();
									openWin('JS_noteHouse4');
									return false;
								} else {
									//均价不能小于小区价格的65%
									if ($('#price').val() != '' && $('#buildarea').val() != ''
										&& $("input[name='infotype']").val() == 1
											&& $("input[name='mright']").val() == '产权房') {
										var rate = 0;
										rate = $("input[name='lctype']:checked").val() == 1 ? 0.65 : 0.5;
										var blockaverprice = parseInt($('#averprice').html()) * rate;
										var buildarea = $('#buildarea').val() ? $('#buildarea').val() : 1;
										var houseaverprice = ($('#price').val() * 10000 / buildarea).toFixed() ;
										if (houseaverprice <= blockaverprice && isNaN(blockaverprice) == false) {
											openWin('JS_noteHouse3');
											return false;
										}
									}
									//均价不能超过小区价格的30%，只提示一次
									if (window.CheckAverpice == false && $('#price').val() != ''
										&& $('#buildarea').val() != '' && $("input[name='infotype']").val() == 1
											&& $("input[name='mright']").val() == '产权房') {
										var blockaverprice = parseInt($('#averprice').html()) * 1.35;
										var buildarea = $('#buildarea').val() ? $('#buildarea').val() : 1;
										var houseaverprice = ($('#price').val() * 10000 / buildarea).toFixed() ;
										if (houseaverprice >= blockaverprice && isNaN(blockaverprice) == false) {
											openWin('JS_noteHouse2');
											window.CheckAverpice = true;
											return false;
										} else {
											$('#new_login_btn_none').show();
											form.submit();
										}
									}
									else
									{
										$('#new_login_btn_none').show();
										form.submit();
									}
								}
							}
						});
						return false;
					},
                    rules: 
                    {
                        blockshowname:
                        {
                            required: true
                        },
                        price:
                        {
                            required: true,
                            number:true,
                            price : true
                        },
                        priceterm_name:
                        {
                            required: true
                        },
                        pricetypename:
                        {
                            required: true
                        },
						taxonlytypename:
                        {
                            required: true
                        },
                        buildarea:
                        {
                            required: true,
                            number:true
                        },
                        room:
                        {	
                            required: true,
                            digits:true,
                            min : 1
                        },
                        hall:
                        {
                            required: true,
                            digits:true	
                        },
                        toilet:
                        {
                            required: true,
                            digits:true	
                        },
                        mright:
                        {//权属
                            required: true	
                        },
                        forward:
                        {//朝向
                            required: true
                        },
                        fitment:
                        {//装修
                            required: true
                        },
                        /*housekind:
                        {//别墅类型属性
                            required: true
                        },*/
                        address:
                        {//房源标题
                            required: true
                        },
                        buildyear:
                        {//建筑年代
                            required: true,
                            digits:true,
                            maxlength:4,
                            minlength:4
                        },
                        ownid:
                        {//建筑年代
                            maxlength:15
                        },
						floor:
						{//单层 1
                            required: function(){
                                if($("#jsInputRadio1").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            number:true,
                            textInteger:true	
                        },
                        totalfloor:
                        {//单层 2
                            required: function(){
                                if($("#jsInputRadio1").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            digits:true,
                            min:function(){
                                return parseInt($("#floor").val())
                            }	
                        },
                        subfloor:
                        {//跃层1
                            required:function(){
                                if($("#jsInputRadio2").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            number:true,
                            textInteger:true	
                        },
                        floor2:
                        {//跃层1
                            required:function(){
                                if($("#jsInputRadio2").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            number:true,
                            min:function(){
                                    return parseInt($("#subfloor").val())
                            },
                            textInteger:true	
                        },
                        totalfloor2:
                        {//跃层1
                            required:function(){
                                if($("#jsInputRadio2").attr("checked"))
                                {
                                    return true
                                }
                                else
                                {
                                    return false
                                }	
                            },
                            digits:true,
                            min:function(){
                                return parseInt($("#floor2").val())
                            }		
                        },
						fee:
                        {
                            number:true	
                        }
			},
			messages: 
			{
                            blockshowname:
                            {
                                required: "请选择小区"
                            },
                            price:
                            {
                                required: "请填写售价",
                                number:"请正确填写售价"
                            },
                            priceterm_name:
                            {
                                required: "请选择价格条件"
                            },
                            pricetypename:
                            {
                                required: "请选择税费情况"
                            },
							taxonlytypename:
                            {
                                required: "请选择个税情况"
                            },
                            buildarea:
                            {
                                required: "请填写产证面积",
                                number:"请正确填写产证面积"
                            },
                            room:
                            {	
                                required: "请填写户型",
                                digits:"请正确填写户型"	,
                                min : "室必须大于0"
                            },
                            hall:
                            {
                                required: "请填写户型",
                                digits:"请正确填写户型"	
                            },
                            toilet:
                            {
                                required: "请填写户型",
                                digits:"请正确填写户型"	
                            } ,
                            houseType5:
                            {
                                required: "请填写户型",
                                digits:"请正确填写户型"	
                            },
                            mright:
                            {//权属
                                required: "请选择权属"	
                            } ,
                            payment:
                            {//支付方式
                                required: "请选择支付方式"	
                            } ,
                            forward:
                            {//朝向
                                required: "请选择朝向"
                            },
                            fitment:
                            {//装修
                                required: "请选择装修情况"
                            },
                            /*housekind:
                            {   //别墅类型
                                required: "请选择别墅类型"
                            },*/
                            housekindname:
                            {//车位属性
                                required: "请选择车位属性"
                            },
                            address:
                            {//房源标题
                                required: "请填写房源标题"
                            },
                            buildyear:
                            {//建筑年代
                                digits:"请正确填写 - 格式:2010",
                                maxlength:"请正确填写 - 格式:2010",
                                minlength:"请正确填写 - 格式:2010",
                                required: "请填写建筑年代"
                            },
                            ownid:
                            {//建筑年代
                                maxlength:"内部编号在15个字之内"
                            },
                            floor:
                            {//单层 1
                                required: "请填写楼层",
                                number:"请正确填写楼层"		
                            },
                            totalfloor:
                            {//单层 2
                                required: "请填写楼层",
                                digits:"请正确填写楼层"	,
                                min:"楼层必须小于总楼层"	
                            },
                            subfloor:
                            {//跃层 1
                                required: "请填写楼层",
                                number:"请正确填写楼层"		
                            },
                            floor2:
                            {//跃层 2
                                required: "请填写楼层",
                                number:"请正确填写楼层"	,
                                min:"楼层必须大于底楼"
                            },
                            totalfloor2:
                            {//跃层 2
                                required: "请填写楼层",
                                digits:"请正确填写楼层"	,
                                min:"楼层必须小于总楼层"
                            },
							fee:
							{
								number:"请正确填写物业费"	
							}
			}
			//debug:true
		})
		var mItemObj = $('#showImage').find('.mItem');
		var result = true;

		if(mItemObj.length > 0 && $("#jsForm_sell").valid())
		{
			mItemObj.each(function(){
				var imageNum = $(this).attr('imageNum');
				var imageTypeVal = $('#imageType_'+imageNum).val();

				if(!imageTypeVal)
				{
					result = false;
					alert('请选择全景图的类型！');
					
					return false;
				}
			});
		}
		
		if(result)
		{
			$("#jsForm_sell").submit();
		}
		
	})
        
        //模板验证
        $("#template_add").validate({
            errorPlacement:function(error,element) 
            { 
                error.appendTo(element.parents(".jsFgInput").siblings(".textFgErroy"))
            },
            submitHandler:function(form){
                var remark = $('#remark').val().replace(/\s+/g,"").replace("&nbsp;","");
                var obj_value_arr = remark.split("");
                var num = 0;
                for (var i = 0; i < obj_value_arr.length; i++) {
                    num += returnStrLen(obj_value_arr[i]);
                }
                if (remark == '' || num < 20) {
                     $("#jsErrorBox").html("请填写20个字符以上的房源描述！");
                     $("#jsErrorBox").show();
                     return false;
                } else {
                    form.submit();
                }
            },
            rules: 
            {
                template_name:
                {
                    required:true,
                    rangelength:[1,6]
                },
                blockshowname:
                {
                    required:true
                },
                remark:
                {
                    required:true
                }
            },
            messages: 
            {
                template_name:
                {
                    required:"请填写模版名称",
                    rangelength:"模板名称在1-6个字之间"
                },
                blockshowname:
                {
                    required:"请选择小区"
                },
                remark:
                {
                    required:"请填写房源描述"
                }
            }
        })
		
	$.validator.addMethod("buildarea_rent",function(value,element,params){
		//整租和合租状态下面积必须小于租金
		var infotype = $("input[name='infotype']").val();
		var renttype = $("input[name='renttype']:checked").val();
		if ((renttype == '整租' || renttype == '合租') && parseInt(value) >= parseInt($('#price').val())
			&& (infotype == 1 || infotype == 2)) {
			return false;
		} else {
			return true;
		}
	}, "请确认您填写的租金和面积是否有误");
	
	$.validator.addMethod("buildarea_rent_1",function(value,element,params){
		var infotype = $("input[name='infotype']").val();
		//住宅面积大于等于300平米以上就有提示
		if (infotype == 1 && parseInt(value) >= 300) {
			return false;
		} else {
			return true;
		}
	}, "请确认您填写的面积是否准确");
	$.validator.addMethod("buildarea_rent_2",function(value,element,params){
		var renttype = $("input[name='renttype']:checked").val();
		if (renttype == '整租' && parseInt(value) < 20 && $("input[name='infotype']").val() != 4) {
			return false;
		} else {
			return true;
		}
	}, "整租的面积太小了吧？请查实后填写");

	$.validator.addMethod("price_rent",function(value,element,params){
		var renttype = $("input[name='renttype']:checked").val();
		var infotype = $("input[name='infotype']").val();
		if (infotype == 3 || infotype == 4 || infotype ==5) {
			if (renttype == '整租') {
				if (parseInt(value) <= 1500000) {
					return true;
				} else {
					return false;
				}
			} else {
				return true;
			}
		} else {
			return true;
		}
	}, "您输入的租金过高请核实");

	//出租提交
	$("#jsBtnSubmit_rent").click(function(){
		$("#jsForm_rent").validate({
		
			errorPlacement:function(error,element) 
			{ 
				error.appendTo(element.parents(".jsFgInput").siblings(".textFgErroy"))
			},
			submitHandler:function(form)
			{
				$('#new_login_btn_none').show();
				form.submit();
			},
			rules: 
			{
				blockshowname:
				{
					required: true
				},
				price:
				{
					required: true,
					number:true,
					price : true,
					price_rent : true
				},
				priceunit:
				{
					required: true,
					number:true
				},
				buildarea:
				{
					required: true,
					number:true,
					buildarea_rent:true,
					buildarea_rent_1:true,
					buildarea_rent_2:true
				},
				room:
				{	
					required: true,
					digits:true,
					min : 1
				},
				hall:
				{
					required: true,
					digits:true	
				},
				toilet:
				{
					required: true,
					digits:true	
				},
				forward:
				{//朝向
					required: true
				},
				payment:
				{//支付
					required: true
				},
				fitment:
				{//装修
					required: true
				},
				address:
				{//房源标题
					required: true,
					remote:{
						url:'/ajax/check_sensitive_word/',
						type: "post",               //数据发送方式
						dataType: "json",           //接受数据格式   
						data: {                     //要传递的数据
							keyword: function() {
								return encodeURI($("#address").val())
							},
							randmod:Math.random()
						}
					}
				},
				housekindname:
				{//车位属性
					required: true
				},
				ownid:
				{//建筑年代
					
					maxlength:15
				},
						floor:
				{//单层 1
				     required: function(){
						if($("#jsInputRadio1").attr("checked"))
						{
							return true
						}
						else
						{
							return false
						}	
					},
					number:true,
					textInteger:true	
				},
				totalfloor:
				{//单层 2
					required: function(){
						if($("#jsInputRadio1").attr("checked"))
						{
							return true
						}
						else
						{
							return false
						}	
					},
					digits:true,
					min:function(){
						return parseInt($("#floor").val())
					}	
				},
				subfloor:
				{//跃层1
					required:function(){
						if($("#jsInputRadio2").attr("checked"))
						{
							return true
						}
						else
						{
							return false
						}	
					},
					number:true,
					textInteger:true	
				},
				floor2:
				{//跃层1
					required:function(){
						if($("#jsInputRadio2").attr("checked"))
						{
							return true
						}
						else
						{
							return false
						}	
					},
					number:true,
					min:function(){
						return parseInt($("#subfloor").val())
					},
					textInteger:true	
				},
				totalfloor2:
				{//跃层1
					required:function(){
						if($("#jsInputRadio2").attr("checked"))
						{
							return true
						}
						else
						{
							return false
						}	
					},
					digits:true,
					min:function(){
						return parseInt($("#floor2").val())
					}		
				},
				fee:
				{
					number:true	
				}
			},
			 messages: 
			 {
				blockshowname:
				{
					 required: "请选择小区"
				},
				price:
				{
					 required: "请填写租金",
					 number:"请正确填写租金"
				},
				priceunit:
				{
					 required: "请填写租金单位"
					 
				},
				buildarea:
				{
					required: "请填写产证面积",
					number:"请正确填写产证面积"
				},
				room:
				{	
					required: "请填写户型",
					digits:"请正确填写户型"	,
					min : "室必须大于0"
				},
				hall:
				{
					required: "请填写户型",
					digits:"请正确填写户型"	
				},
				toilet:
				{
					required: "请填写户型",
					digits:"请正确填写户型"	
				} ,
				houseType5:
				{
					required: "请填写户型",
					digits:"请正确填写户型"	
				},
				payment:
				{//支付方式
					required: "请选择支付方式"	
				} ,
				forward:
				{//朝向
					required: "请选择朝向"
				},
				fitment:
				{//装修
					required: "请选择装修情况"
				},
				/*housekind:
				{//别墅类型属性
					required: "请选择别墅类型"
				},*/
				address:
				{//房源标题
					required: "请填写房源标题"
				},
				ownid:
				{//建筑年代
					
					maxlength:"内部编号在15个字之内"
				},
				floor:
				{//单层 1
					required: "请填写楼层",
					number:"请正确填写楼层"		
				},
				totalfloor:
				{//单层 2
					required: "请填写楼层",
					digits:"请正确填写楼层"	,
					min:"楼层必须小于总楼层"	
				},
				subfloor:
				{//跃层 1
					required: "请填写楼层",
					number:"请正确填写楼层"		
				},
				floor2:
				{//跃层 2
					required: "请填写楼层",
					number:"请正确填写楼层"	,
					min:"楼层必须大于底楼"
				},
				totalfloor2:
				{//跃层 2
					required: "请填写楼层",
					digits:"请正确填写楼层"	,
					min:"楼层必须小于总楼层"
				},
				fee:
				{
					number:"请正确填写物业费"	
				}
			 }
		})
		$("#jsForm_rent").submit();
	})
	//联想框 历史小区下拉条
	if($("#blockshowname").length >0)
	{
		var positionLeft = $("#blockshowname").offset().left;
		var positionTop = $("#blockshowname").offset().top;
		$("#historyHouse").css({left:positionLeft,top:positionTop+29});
		$(window).resize(function(e) {
			positionLeft = $("#blockshowname").offset().left;
			positionTop = $("#blockshowname").offset().top;
			$("#historyHouse").css({left:positionLeft,top:positionTop+29});
		});
		$("#blockshowname").bind("click",function(){
			if($(".ui-autocomplete").is(":hidden"))
			{
				$("#historyHouse").show();
			}
			else
			{
				$("#historyHouse").hide();		
			}
		});
		$("#blockshowname").bind("keyup",function(){
			if($(this).val() != "")
			{
				$("#historyHouse").hide();
			}
			else
			{
				$("#historyHouse").show()
			}
		})
		$("#historyHouse").bind("click",function(){
			$("#blockshowname").focus();
			$(this).hide();
			
		})

		$("#historyHouse,#blockshowname").bind("click",function(event){
			event.stopPropagation();
		})
	}
	
	//房源模板
	$(".jsTemplateBox .item").click(function() {
		id = $(this).attr('ids');
		$(this).siblings(".item").removeClass("itemAdd");
		if($(this).hasClass("itemAdd"))
		{

			$(this).removeClass("itemAdd");
			$('#jsLabelBlockshowname').show();
			$("#district").val("");
			$("#street").val("");
			$("#streetid").val("");
			$("#blockaddress").val("");
			$("#block_id").val("");
			$("#blockshowname").val("");
			reload_remark();
		}
		else
		{
			$(this).addClass("itemAdd");
			$('#jsLabelBlockshowname').hide();
			$.ajax({
				type: 'get',
				url : '/ajax/find_module_detail/',
				data: 'id='+id,
				dataType:'json',
				success: function(data){
					if(data.errorCode == '401')
					{
						jump_win(LoginOut , '请重新登录');
						return false;
					}
					$("#district").val(data.district);
					$("#street").val(data.street);
					$("#streetid").val(data.streetid);
					$("#blockaddress").val(data.address);
					$("#block_id").val(data.block_id);
					$("#blockshowname").val(data.block_name);
					//$("#remark").val(data.remark);
					$("#historyHouse").hide();
					getBlockImg(1);
					if ($('#tbl').val() == 'sell') {
				        showblockinfo (data.averprice , data.address ,data.esta_block, data.url_block);
			        }
					setEditorRemark(data.remark);
				}
			});
		}
		return true;
	});
	
	//键盘码,多个键盘码组合暂不考虑
	var keyCodeArr = {13:13,16:16,17:17,18:18,20:20,27:27,33:33,34:34,35:35,36:36,37:37,38:38,39:39,40:40,45:45,46:46,91:91,93:93,144:144};

	$("#blockshowname").keyup(function(e){
		var e = e ? e : window.event;
		
		//小区查找，防止误按键盘码
		if(typeof keyCodeArr[e.keyCode] != 'undefined')
		{
			return;
		}

		clearblockinfo();
	});

	$(document).click(function(a){
		$("#historyHouse").hide();
	})
});