function vote(models,shopid){

	var type = models;
	var type_id = $("input[name='vote']:checked").val();
	var item_id = shopid;
	if(type_id > 0){
		$.post(_ROOT_+"/common/vote",{typeId:type_id,itemId:item_id,category:type,ajax:1},function(msg){
		               if(msg.status==1){
		               	    alert(msg.info);
		               }else if(msg.status==0){
					    	alert(msg.info);
					    }
		},"json");
	}else{
		alert("请选择选项！");
	}
	
}


function addFavorite(url,title,id){
    var fav_url = url;
    var fav_title = title;
    var fav_id  = id;
    if (document.all && window.external){
      window.external.AddFavorite(fav_url,fav_title);
    }else if (window.sidebar){
      window.sidebar.addPanel(fav_title,fav_url,"");
    }else{
      alert("浏览器不支持，请手动加入收藏夹");
    }
    if(fav_id > 0){
    	
	    if(document.all && window.external || window.sidebar){
	    			$.post(_ROOT_+"/common/favorite",{item_id:fav_id,ajax:1},function(msg){
	                             window.location.reload();
			},"json");
	    }
    }
  }
  
  
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;  
  
var mask;
function addMask(a){
		var offsetwidth=$("#"+a).width();
 		var offsetheight=$("#"+a).height();
		var top1;
		var left1;
		if(Sys.chrome){
			top1=(document.body.scrollTop+(document.documentElement.clientHeight-offsetheight)/2)+"px";
			left1=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-offsetwidth)/2)+"px";
			}
			else{
				top1=(document.documentElement.scrollTop+(document.documentElement.clientHeight-offsetheight)/2)+"px";
				left1=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-offsetwidth)/2)+"px";
			}
			$("#"+a).css({position: "absolute",'top':top1,'left':left1,'z-index':200});
			$("#"+a).css("display","block");
			mask=document.createElement("div");
			var W=document.body.scrollWidth;
			var H=document.body.scrollHeight;
			mask.id="mask";
			mask.style.cssText="position:absolute;z-index:5;width:"+W+"px;height:"+H+"px;background:#000;filter:alpha(opacity=30);opacity:0.3;top:0;left:0;";
			document.body.appendChild(mask);
	
}

function delMask(b){
	$('#'+b).css("display","none");
	document.body.removeChild(mask);
}

////////////////////////////////////////////////////////
//
//添加日志
//
/////////////////////////////////////////////////////////
function addLogMask(){
	addMask("addLogTypeForm");
}

function cancelLogMask(){
	delMask("addLogTypeForm");
}

function addLogType(){
	var ifms= document.getElementById("shopframe");   
	var subWebs = document.frames ? document.frames["shopframe"].document : ifms.contentDocument; 
	var varItem ;   
	//var varItem = new Option(objItemText, objItemValue);      
	//objSelect.options.add(varItem);   
	var typename = $("#textLogType").val();
	$.post(_ROOT_+"/userlog/addloggroup",{name:typename,ajax:1},function(msg){
		            if(msg.status == 1){
  						varItem = new Option(msg.data['name'],msg.data['id']);
		            	subWebs.getElementById('logTypeSel').options.add(varItem);
		            	varItem.selected = true;
					    }else if(msg.status == 0){
					    	alert(msg.info);
					    }  
		                delMask("addLogTypeForm");
	},"json");
}
////////////////////////////////////////////////////////
//
//添加关注（好友）
//
/////////////////////////////////////////////////////////
//添加阴影
function masks(uid,uname,type){
	
	var value = $("#adjust").val();

	if(value == 0){
		alert("请您先登陆再加关注！");
		doLogin('iframe_login');
		return false;
	}
	addMask("addFriendDiv");
	if(type == 1){
		 parent.document.getElementById('group-title').innerHTML="为<b>"+uname+"</b>选择分组";
	}else{
		$("#group-title").html("为<b>"+uname+"</b>选择分组");
	}
	$("#alias").attr("value",uname);
	$("#friendId").attr("value",uid);
	$("#iframeValue").attr("value",type);
}
//删除阴影
function closeMasks(){
	delMask("addFriendDiv");
}
//创建好友分组文本框
function createGroupSpan(){
	$("#createGroupSpan").css("display","none");
	$("#createGroupText").css("display","block");
}
function closeGroupSpan(){
	$("#createGroupText").css("display","none");
	$("#createGroupSpan").css("display","block");
}
function addGroup(){
	var groupName = $("#groupName").val();
		$.post(_ROOT_+"/user/addfriendgroup",{name:groupName},function(msg){
		            if(msg.status == 1){
					    $("#checkBoxSpan").append('<li><input id="checkName[]" type="checkbox" name="checkName[]" checked value="'+msg.data['id']+'" /><label for="classmate">'+msg.data['name']+'</label></li>');
					   closeGroupSpan();
					    }else if(msg.status == 0){
					    	alert(msg.info);
					    }
	},"json");
}


//给关注的好友分组
function addFriend(){
	var groupId = "";
		$("input[name='checkName[]']:checked").each(function(i,n){
			groupId = groupId + "," + n.value;
		});
		if(groupId == ""){
			groupId = ",1,";
		}else{
			groupId = groupId + ",";
		}
		

		
		var friendAlias = $("#alias").val();
		var friendId    = $("#friendId").val();
		var iframeValue = $("#iframeValue").val();
        if(iframeValue == 1){
		var ifms= document.getElementById("shopframe");   
	    var subWebs = document.frames ? document.frames["shopframe"].document : ifms.contentDocument;
        }
	$.post(_ROOT_+"/user/addfriend",{group_id:groupId,alias:friendAlias,friend_id:friendId},function(msg){
					if(msg.status == 1){
						$("#ufId").attr("value",msg.data);
						if(iframeValue == 2){
					$('<span id=\"delFriend'+friendId+'\" style=\"cursor:pointer\"  onclick=\'delFriend('+friendId+',\"'+friendAlias+'\",2'+')\'>取消关注<\/span>').replaceAll('#addFriend'+friendId);
						}else if(iframeValue==1){
							var strs = '<span id=\"delFriend'+friendId+'\" style=\"cursor:pointer\" onclick=\'parent.delFriend('+friendId+',\"'+friendAlias+'\",1'+')\'>取消关注<\/span>'
						subWebs.getElementById('city'+friendId).innerHTML = strs;
						}
					    delMask("addFriendDiv");
					    alert(msg.info);
					}else if(msg.status == 0){
					    	alert(msg.info);
					 } 
	},"json");
}

//删除关注的好友
function delFriend(friendId,friendName,type){
	if(confirm("确定取消关注吗？")){
		if(type == 1){
		var ifms= document.getElementById("shopframe");   
	    var subWebs = document.frames ? document.frames["shopframe"].document : ifms.contentDocument; 
		}
		    $.post(_ROOT_+"/user/delfriend",{friend_id:friendId},function(msg){
		               if(msg.status == 1){
                      if(type == 1){
                     var str = '<span id=\"addFriend'+msg.data['uid']+'\" style=\"cursor:pointer;\" onclick=\"parent.masks('+msg.data['uid']+','+'\''+msg.data['username']+'\''+',1)\"><img src=\"'+_PUBLIC_+'\/images\/gz1.jpg\"\/><\/span>';
	             subWebs.getElementById('city'+friendId).innerHTML = str;
                      }else{
                      		$('<span id=\"addFriend'+msg.data['uid']+'\" style=\"cursor:pointer;\" onclick=\"masks('+msg.data['uid']+','+'\''+msg.data['username']+'\''+',2)\"><img src=\"'+_PUBLIC_+'\/images\/gz1.jpg\"\/><\/span>').replaceAll('#delFriend'+friendId);
                      }
					    }else if(msg.status == 0){
					    	alert(msg.info);
					    }
		},"json");
	}
	
	}
	
// 店主申请星探店铺弹出框
function applyShoperMask(tempname,tempid,tempuid){
	var value = $("#adjust").val();
	if(value == 0){
		alert("请您先登陆再申请认证店主！");
		doLogin('iframe_login');
		return false;
	}
	addMask("applytempshoper");
	$("#dialog-title").html("认领<b>"+tempname+"</b>店铺");
	$("#tempshopid").attr("value",tempid);
	$("#tempuid").attr("value",tempuid);
}

//删除店主申请星探店铺弹出框
function closeShoperMask(){
	delMask("applytempshoper");
	$("input[name='img_list']").attr("value",''); 
	$(".img_list").html('');
}

//申请店主认证：
function applyShoper(){
	var shopername = $("#shopername").val();
	var shopertel = $("#shopertel").val();
	
	var certifymobilephone = /^1[3|5|8][0-9]\d{4,8}$/;
	if(!shopername){
		alert("请填入您的姓名！");
		shoername.focus();
		return false;
	}
	if(!shopertel){
		alert("请填入您的联系方式！");
		shopertel.focus();
		return false;
	}
	if(!certifymobilephone.test(shopertel)){
		alert("手机号码不正确！");
		shopertel.focus();
		return false;
	}
	var temp_id  = $("#tempshopid").val();
	var temp_uid = $("#tempuid").val();
	var licence  = $("input[name='img_list']").val();
	if(!licence){
		alert("请上传营业执照！");
		return false;
	}
	$.post(_ROOT_+"/common/applyshoper",{tempid:temp_id,tempuid:temp_uid,licence:licence,shopername:shopername,shopertel:shopertel,ajax:1},function(msg){
						if(msg.status == 0){
							alert(msg.info);
							parent.doLogin('iframe_login');
						}else if(msg.status == 1){
							alert(msg.info);
							parent.location.href = _ROOT_+"/user/userattest";	
					    }else if(msg.status == 2){
							 closeShoperMask();
			                 alert(msg.info);
					    }else if(msg.status == 3){
					    	alert(msg.info);
					    }else if(msg.status == 4){
					    	alert(msg.info);
					    }
					    
	},"json");
}




