$(function(){
	
	J_CaseBaojia();
	function J_CaseBaojia(){
		var wrap = $("#J_RDesInd");
	
		/*报名表单 placeholder*/
		var usePlace = wrap;
		if(usePlace.length > 0){
			$.getScript("/main/Tpl/default/Public/js/jquery.placeholder.js",function(){
				usePlace.find("input[type='text'],textarea").each(function() {
					var clue_on = $(this).closest(".table").find(".clue_on");
					$(this).attr('placeholder', clue_on.text());
					if(!$.browser.msie){
						$(this).focus(function(){$(this).attr("placeholder",'');});
						$(this).blur(function(){$(this).attr("placeholder", clue_on.text());});
					}
				}).placeholder();
			});
		}
		
		
		/*提示*/
		var tips_bg = $(".tips_bg",wrap),
			tips = $(".tips",wrap),
			tips_close = $(".close",tips),
			cookieString = new String(document.cookie),
			cookieHeader = 'hideCaseBaojiaTips',
			beginPosition = cookieString.indexOf(cookieHeader);
		
		//关闭按钮
		tips_close.click(function(){
			//var Then = new Date();				
			//Then.setTime(Then.getTime() + 24*60*60*1000);
			//document.cookie = ' ' + cookieHeader + '=yes;expires='+ Then.toGMTString(); //一天后清除cookie
			document.cookie = ' ' + cookieHeader + '=yes'; //不加上过期时间，关闭浏览器自动清除cookie
			tips_bg.hide();
			tips.hide();
		});
		//cookie是否存在，显示or隐藏
		setTimeout(function(){
			tips_bg.fadeIn("slow");
			tips.fadeIn("slow");
		},35000);

		
		/*处理户型*/
		var cls_phone = $(".cls_phone",wrap),cls_dstyle = $(".cls_dstyle",wrap);
		cls_dstyle.after(cls_phone);
		
	};

});

function J_CaseBaojia_submit(f,isvcode){
	var formId = $("#"+f),
		isvcode = isvcode ? isvcode : 0,//0表示需要，1表示不需要，默认为0
		form = $("form",formId),
		contact = $("#bm_name",formId),//称呼
		phone = $("#bm_phone",formId),//手机
		area = $("#bm_mianji",formId),//面积
		
		check = $("#sys_check",formId),//验证码
		imgcode = $("#imgcode",formId),//验证图片
		btn = $("#_phpok_submit",formId),
		
		yusuan = $("#yusuan",formId),//预算结果，提交后台
		resultShow = $("#resultShow",formId),//预算结果，前台显示
		
		areaVal = parseFloat(area.val()),//面积值
		costResult;

	if(btn.hasClass("disabled")){
		layer.msg('您已经提交过了，感谢您的支持！', {icon: 6,shade: .3,time: 2000});
		return false;
	}

	//基本test
	if(isNaN(areaVal)){layer.msg("请输入正确的面积", {icon: 2,shade: .3,time: 1000});area.focus();return false;}
	//if(!contact.val()){layer.msg("请填写您的称呼", {icon: 2,shade: .3,time: 1000});contact.focus();return false;}
	if(!(/^1[2|3|4|5|7|8][0-9]\d{7,8}$/.test(phone.val()))){layer.msg("手机号码未填写或填写错误", {icon: 2,shade: .3,time: 1000});phone.focus();return false;}
	
	
	costResult = 1000 * areaVal;
	//检查计算结果
	var Result = parseFloat(costResult);
	if (isNaN(Result)){
		layer.msg("计算失败，请检查所填写格式", {icon: 2,shade: .3,time: 1000});return false;
	}else{
		Result = Math.round(costResult/100)/100; //变成万元，并保留两位小数
	}
	yusuan.val(Result);
	$.post(form.attr("action"), form.serialize(),function(data2){
		btn.addClass("disabled");
		form[0].reset();
		data2=data2.replace(/\s/g,'');
		if(data2.indexOf("ok")!== -1){
			layer.msg('提交成功，我们将第一时间与您取得联系！', {icon: 6,shade: .3,time: 2000});
			baiduFxgate();
		}else{
			layer.msg("提交失败！",{icon:2,shade:.3,time:2000});
		}

	});
	return false;
}
