function editShop(id){
	var shopId = id;
	if (!shopId)
	{
		alert('请选择编辑项！');
		return false;
	}
	$.post(_ROOT_+"/shopowner/saveshopid",{shop_id:shopId,ajax:1},function(msg){
		if(msg.status == 1){
			parent.location.href = _ROOT_+"/ushop/shopindex";
		}else{
			alert(msg.info);
		}
	},"json");
}
function shopUrl(url){
		document.location.href=_ROOT_+"/shop/"+url;
}
//申请验证为该店铺申请认证
function enterattestshop(id){
	var shopId = id;
	if (!shopId)
	{
		alert('请选择申请的项目！');
		return false;
	}
	$.post(_ROOT_+"/shopowner/saveattest",{id:shopId,ajax:1},function(msg){
		if(msg.status == 1){
			parent.location.href = _ROOT_+"/shop/attest";
		}else{
			alert(msg.info);
		}
	},"json");
}
//经济人停止店铺
function stopShop(id,type){
	if(id>0){
		$.post(_ROOT_+"/broker/stopshop",{shopid:id},function(data){
			if(type == 1){
				if(data.status == 2){
					$('#a_red'+id).text('开始经纪');
				}else if(data.status == 3){
					$('#a_red'+id).text('暂停经纪');
				}else{
					alert(data.info);
				}
			}else{
				if(data.status == 2){
					$('#operate'+id).text('停业状态');
				}else if(data.status == 3){
					$('#operate'+id).text('营业状态');
				}else{
					alert(data.info);
				}
			}
		},"json");
	}
}
function unsetsession(){
	$.post(_ROOT_+"/broker/unsetshopid",function(data){

		parent.location.href = _ROOT_+"/ushop/shopindex";
	})
}
function addJingJiRen(aid,uid,v,type){
	var shopId = v;
	if(type == '' && aid == ''){
		if (!uid){
		alert('请选择经纪人！');
		return false;
		}
		if(confirm("确定委托他为经纪人")){
			$.post(_ROOT_+"/shopowner/addjingjiren",{id:shopId,userid:uid,ajax:1},function(msg){
				if(msg.status == 1){
					alert(msg.info);
					parent.location.href = _ROOT_+"/shopowner/index";
				}else{
					alert(msg.info);
				}
			},"json");
		}
	}else if(type == 8){
		if (!uid){
				alert('请选择经纪人！');
				return false;
		}
			if(confirm("确定委托他为经纪人")){
				$.post(_ROOT_+"/shoptemp/addjingjiren",{aid:aid,shopId:shopId,uid:uid,type:type,ajax:1},function(msg){
					if(msg.status == 1){
						alert(msg.info);
						parent.location.href = _ROOT_+"/shoptemp/templist";
					}else if(msg.status == 0){
						alert(msg.info);
					}
				},"json");
			}
	}
}


//shopid 星探店铺id tempuid 星探id
function applyJingJiRen(shopid,tempuid){
	if(!shopid){
		alert("请选择店铺！");
		return false;
	}
	$.post(_ROOT_+"/common/applyjingjiren",{shopid:shopid,tempuid:tempuid,ajax:1},function(msg){
					alert(msg.info);
					if(msg.status == 0){
						parent.doLogin('iframe_login');
					}
	},"json");
}

//zid 是最钱沿id

function commitComment(zid){
	var content = $("#content").val();
	if(!content){
		alert("内容不能为空！");
		return false;
	}
	var yzm = $("#yzm").val();
	if(!yzm){
		alert("验证码不能为空！");
		return false;
	}
	$.post(_ROOT_+"/zuiqianyan/commitcomment",{item_id:zid,content:content,yzm:yzm,ajax:1},function(msg){
		            if(msg.status == 1){
						$("#cc_0").before(msg.data);
						showVerify('authnum');
						$("#content").val('');
					}else if(msg.status == 0){
						alert(msg.info);
					}else if(msg.status == 2){
						//将信息存到cookie中以再次显示
						var date=new Date();
						document.cookie = 'TempCom='+escape(content);
						doLogin('iframe_login');
					}
	},"json");
}

//验证码功能
function showVerify(id){
	var Imglink = document.getElementById(id);
    Imglink.src=_ROOT_+"/common/verify/rand/"+Math.random();
}

function writeNews(){
	var sid = $("input[name='sid']:checked").val();
	var title = $("#title").val();
	//在编辑器中取值的方法
	var content = KE.util.getData('content');
	var yzm = $("#yzm").val();
	var bq = $("#bq").val();
	var _id = $('input[name="id"]').val();
	
	$("#content").val(content);
	if(!sid){
		alert("请选择文章类别！");
		return false;
	}
	if(!title){
		alert("标题不能为空！");
		return false;
	}
	if(!bq){
		alert("标签不能为空！");
		return false;
	}
	if(!content){
		alert("内容不能为空！");
		return false;
	}
	
	if(!yzm){
		alert("验证码不能为空！");
		return false;
	}
	if(_id == ''){
		//新增
		$.post(_ROOT_+"/zuiqianyan/write",{sid:sid,title:title,content:content,yzm:yzm,keyword:bq,ajax:1},function(msg){
					if(msg.status == 1){
						alert(msg.info);
						showVerify('authnum');
						$('#title').val('');
						$('#bq').val('');
						$('input[name="id"]').val('');
						$("#yzm").val('');
						var ifm= document.getElementsByTagName('iframe')[0];
						var subWeb = ifm.contentDocument;   
						subWeb.body.innerHTML = '';
						window.open(_ROOT_+"/zuiqianyan/view/id/"+msg.data['id']+"/type/"+msg.data['sid'],"_blank");
					}else if(msg.status == 0){
						alert(msg.info);
					}else if(msg.status == 2){
						alert(msg.info);
						doLogin('iframe_login');
					}
		},"json");
	}else{
		//修改
		$.post(_ROOT_+"/zuiqianyan/write",{sid:sid,title:title,content:content,yzm:yzm,id:_id,ajax:1},function(msg){
			if(msg.status == 1){
				alert(msg.info);
			}else{
				alert(msg.info);
			}
		},"json");
	}
	
}

function dingOrShuai(id,type){
	if(type == 2){
		var str = 'bad';
	}else{
		var str = 'good';
	}
	$.post(_ROOT_+'/zuiqianyan/dingorshuai',{id:id,type:type},function(msg){
		if(msg.status==1){
			var sum = Math.abs(parseInt($("#"+str+id).html()))+1;
			if(type == 2){
			$("#"+str+id).html("-"+sum);
			}else{
			$("#"+str+id).html(sum);
			}
		}else if(msg.status==2){
			alert(msg.info);
			doLogin('iframe_login');
		}else{
			alert(msg.info);
		}
	},'json');
}

function changeUser(){
	$.post(_ROOT_+'/user/changeUser',{ajax:1},function(msg){
			if(msg.status == 1){
				document.getElementById('changeUser').innerHTML = msg.data;
			}else if(msg.status == 0){
				alert(msg.info);
			}
	},'json');
}

//**首页项目切换**//
function changeJMBlock(t){
	var tab = '#tab_'+t;
	$('#recommend li').removeClass('on');
	$(tab).addClass('on');
	
	
	$('.tabbody').css('display','none');
	$('#tabbox_'+t).css('display','');
	
}

