jQuery(function($){
	$("#LifeKeyword").focus(function(){
		if($.trim(this.value) == "请输入您要搜索的信息！")
			this.value = "";
	}).blur(function(){
		if($.trim(this.value) == "")
			this.value = "请输入您要搜索的信息！";	
	});
	$("#phonebookkeyword").focus(function(){
		if($.trim(this.value) == "请输入名称关键词或电话号码！")
			this.value = "";
	}).blur(function(){
		if($.trim(this.value) == "")
			this.value = "请输入名称关键词或电话号码！";	
	});
	$("#ypKeyword").focus(function(){
		if($.trim(this.value) == "请输入名称关键词或黄页名称！")
			this.value = "";
	}).blur(function(){
		if($.trim(this.value) == "")
			this.value = "请输入名称关键词或黄页名称！";	
	});
	$("#phonebookform").submit(function(){
		var Keyword=$.trim($("#phonebookkeyword").val());
		var aa=$("#Lifehiddenvalue").val();
		var bb=aa.split(",");
		if(Keyword=="请输入名称关键词或电话号码！")
		{
			Keyword="";
		}
		if(Keyword.length==0 ){
			var url="phonelist.aspx";
			if(bb[0]=="0")
				var url=encodeURIComponent("phonelist-0"+bb[1]);
			window.open(url,"_self");
			return false;
		}
		var url="phonelist.aspx?SearchKeyword="+escape(Keyword);
		if(bb[0]=="0")
			var url=encodeURIComponent("phonelist-0-A"+(Keyword)+"A-p0"+bb[1]);
		window.open(url,"_self");
		return false;
	});
	$("#listypform").submit(function(){
		var Keyword=$.trim($("#ypKeyword").val());
		var aa=$("#Lifehiddenvalue").val();
		var bb=aa.split(",");
		if(Keyword=="请输入名称关键词或黄页名称！")
		{
			Keyword="";
		}
		if(Keyword.length==0 ){
			var url="lifelist.aspx";
			if(bb[0]=="0")
				var url=encodeURIComponent("lifelist-0"+bb[1]);
			window.open(url,"_self");
			return false;
		}
		var url="lifelist.aspx?SearchKeyword="+escape(Keyword);
		if(bb[0]=="0")
			var url=encodeURIComponent("lifelist-0-0-0-0-0-A"+(Keyword)+"A-p0"+bb[1]);
		window.open(url,"_self");
		return false;
	});
	$("#TelContent").find("div").each(function(){
		$(this).mouseover(function(){
			var obj=$(this);
			$("#TelContent").find("div").each(function(){
				$(this).removeClass("Current");
			});
			obj.addClass("Current");
		});
	});
	$("#TelListContent").find("div").each(function(){
		$(this).mouseover(function(){
			var obj=$(this);
			$("#TelListContent").find("div").each(function(){
				$(this).removeClass("TCurrent");
			});
			obj.addClass("TCurrent");
		});
	});
	$("#listyhlist").find(".rl").each(function(){
		$(this).mouseover(function(){
			var obj=$(this);
			$("#listyhlist").find(".cur").each(function(){
				$(this).removeClass("cur");
			});
			obj.addClass("cur");
		});
	});
	$("#txtlifesearchform").submit(function(){
		var Keyword=$.trim($("#LifeKeyword").val());
		var ClassID=$.trim($("#txtLifeClassID").val());
		var aa=$("#Lifehiddenvalue").val();
		var bb=aa.split(",");
		if(Keyword=="请输入您要搜索的信息！")
		{
			Keyword="";
		}
		if(Keyword.length==0 && ClassID.length==0 ){
			var url="LifeList.aspx";
			if(bb[0]=="0")
				var url=encodeURIComponent("LifeList-0"+bb[1]);
			window.open(url,"_self");
			return false;
		}
		if(ClassID=="")
			ClassID="0";
		var url="LifeList.aspx?SearchKeyword="+escape(Keyword)+"&ID="+ClassID;
		if(bb[0]=="0")
			var url=encodeURIComponent("LifeList-"+ClassID+"-0-0-0-0-A"+(Keyword)+"A-p0"+bb[1]);
		window.open(url,"_self");
		return false;
	});
	$("#ShareTo").focus(function(){
		ShowDailog('分享信息',301,301,'LifeShare.aspx?id='+$(this).attr("rel"),'true','AntClassBg.gif','AntTuanclose.gif','AntUserTips.gif','66a3dd','F6F9FF','3f80c1','3f80c1');
		return false;	
	});
	$("#EditTo").click(function(){
		ShowDailog('免费发送到手机短信',301,301,'LifeSend.aspx?id='+$(this).attr("rel"),'true','AntClassBg.gif','AntTuanclose.gif','AntClassTips.gif','66a3dd','F6F9FF','3f80c1','3f80c1');//发送到手机短信
		return false;
	});
	$("#Lifesendmobileform").submit(function(){
		var chrmobile = $("#infosendmobile").val();
		if(!$.checkMobilePhone(chrmobile))
		{
			alert("请输入正确的11位手机号码！");
			$("#infosendmobile").focus();
			return false;
		}
		$("#infosendmobilesubmit").attr("disabled", true); //设置为不可点
		$.ajax({
		  url: "/public/ajax.aspx?action=sendinfomobile&aa="+$("#typeid").val()+"&tt="+escape($("#sendcontent").html())+"&&chrmobile="+escape($("#infosendmobile").val()),
		  cache: false,
		  success:function(data)
		  {
			 if(data=="0"){
				alert("信息内容已发送到您手机，请注意查收。");
				window.parent.closeopendiv();
				return false;
			 }
			 else{
				$("#infosendmobilesubmit").attr("disabled", false); //设置为不可点
				alert(data);
				return false;
			 }
		  }
	  });
		return false;
	});
	if($_D("MemberLifeAddForm"))
	{
		$.formValidator.initConfig({formid:"MemberLifeAddForm",errorfocus:false,onerror:function(msg){},onsuccess:function(){	
			var x=document.getElementById("MemberLifeAddForm");
			x.action="lifeadd.aspx?action=addsave&IsCheck=1";
			return true;
		}});
		$.formValidator.getInitConfig("1").wideword = false;
		$("#txtLifeAreaID").formValidator({onshow:"&nbsp;",onfocus:"请选择对应的地区",oncorrect:"&nbsp;"}).inputValidator({min:1,onerror: "请选择对应的地区"})
		$("#txtLifeTitle").formValidator({onshow:"&nbsp;",onfocus:"请选择信息标题，100字以内",oncorrect:"&nbsp;"}).inputValidator({min:1,max:100,onerror: "请选择信息标题，100字以内"})
		$("#txtLifeMan").formValidator({ onshow:"&nbsp;",onfocus: "请输入联系人，方便别人与您快速取得联系。",oncorrect:"&nbsp;"}).inputValidator({ min:2,max:20,onerror: "请输入联系人，方便别人与您快速取得联系。" })
		$("#txtLifeQQ").formValidator({ onshow:"&nbsp;",onfocus: "请输入联系QQ，可以直接显示在线状态。",oncorrect:"&nbsp;"}).inputValidator({ min:0,max:11,onerror: "请输入联系QQ，可以直接显示在线状态。" })
		$("#txtLifeTel").formValidator({ onshow:"&nbsp;",onfocus: "请正确填写电话号码，分机可以用“-”分开" ,oncorrect:"&nbsp;"}).inputValidator({ onerror: "请填手机或电话" }).inputValidator({min:7,max:20,onerror: "电话填写错误。只能填写联系电话或者手机。"})
		$("#txtLifeTypeID").formValidator({onshow:"&nbsp;",onfocus:"请选择生活黄页分类。",oncorrect:"&nbsp;"}).inputValidator({min:1,onerror: "请选择生活黄页分类。"})
		$('#txtLifeAddress').formValidator({ onshow:"&nbsp;",onfocus:'请输入详细地址，不输入可以为空。',oncorrect:"&nbsp;"}).inputValidator({min:0,max:250,onerror: "请输入详细地址，不输入可以为空。"})
		$('#txtLifeUrl').formValidator({ onshow:"&nbsp;请输入网址，前面加入http://",onfocus:'请输入网址，前面加入http://。',oncorrect:"&nbsp;"}).inputValidator({min:0,max:150,onerror: "请输入网址，不输入可以为空。"})
		$('#uploadImageUrl').formValidator({ onshow:"&nbsp;宽*高不能大于150*75",onfocus:'请选择上传代表图片，宽*高不能大于150*75。',oncorrect:"&nbsp;"}).inputValidator({min:0,max:150,onerror: "请选择上传代表图片，宽*高不能大于150*75。"})
	}
	if($_D("phoneaddform"))
	{
		$.formValidator.initConfig({formid:"phoneaddform",errorfocus:false,onerror:function(msg){},onsuccess:function(){	
			$.ajax({
			  url: "/public/ajax.aspx?action=addphone&aa="+escape($("#txtPhoneTitle").val())+"&bb="+escape($("#txtPhoneClassID").val())+"&&cc="+escape($("#txtPhoneTel").val())+"&&dd="+escape($("#txtPhoneMobile").val()),
			  cache: false,
			  success:function(data)
			  {
				 if(data=="0"){
					alert("电话簿信息添加成功，等待管理员审核通过。");
					window.location.href="phonebookadd.aspx";
					return false;
				 }
				 else if(data=="1"){
					alert("电话簿信息修改成功。");
					window.location.href="phonebookadd.aspx";
					return false;
				 }
				 else{
					alert(data);
					return false;
				 }
			  }
		  });
		  return false;
		}});
		$.formValidator.getInitConfig("1").wideword = false;
		$("#txtPhoneTitle").formValidator({onshow:"&nbsp;",onfocus:"<p>正确填写名称，20字以内</p><span></span>",oncorrect:"&nbsp;"}).inputValidator({min:1,onerror: "<p>请正确填写名称，20字以内</p><span></span>"})
		$("#txtPhoneClassID").formValidator({onshow:"&nbsp;",onfocus:"<p>请选择电话簿类别</p><span></span>",oncorrect:"&nbsp;"}).inputValidator({min:1,onerror: "<p>请选择电话簿类别</p><span></span>"})
		$("#txtPhoneTel").formValidator({ onshow:"&nbsp;",onfocus: "<p>(常用电话,如:010-88888888)</p><span></span>",oncorrect:"&nbsp;"}).functionValidator({
			fun:function(val,elem){
				var aa = $("#txtPhoneTel").val();
				var bb = $("#txtPhoneMobile").val();
				if(aa.length==0 && bb.length==0)
				{
					return "电话和手机，至少填写一个！";
				}
				else
				{
					return true;	
				}
			}
		});
		$('#txtPhoneMobile').formValidator({ onshow:"&nbsp;",onfocus:'<p>电话和手机，至少填写一个！</p><span></span>',oncorrect:"&nbsp;"}).functionValidator({
			fun:function(val,elem){
				var aa = $("#txtPhoneTel").val();
				var bb = $("#txtPhoneMobile").val();
				if(aa.length==0 && bb.length==0)
				{
					return "电话和手机，至少填写一个！";
				}
				else
				{
					return true;	
				}
			}
		});
	}
});
var AntLifeClass = {
	InfoZhiDing: function(LifeID) {
        var frm = $("#frm" + LifeID);
		if ( $.trim( $("#Ulfrm_" + LifeID).html() )=="") {
			var val="<iframe frameborder='0' width=656 height=1 id='frm"+LifeID+"' name='frm"+LifeID+"' scrolling='no' src='LifeZhiDing.aspx?LifeID="+LifeID+"&temp=1 "+ new Date().getTime()+" style='width:656px; height:height:100px;    margin:0; padding:0; border:0px; margin-top:0px' ></iframe>";
			$("#Ulfrm" + LifeID).html("");
			$("#Ulfrm_" + LifeID).html(val);
			$("#Ulfrm_" + LifeID).fadeIn();
        }
        else {
            frm.css("height", "0px");
			$("#Ulfrm_" + LifeID).html("");
			$("#Ulfrm" + LifeID).html("");
        }
    },
	setframeheight: function(frmID, height) {
        var frm = $("#frm" + frmID);
        if (frm.length > 0) 
		{
            $_D("frm" + frmID).height= height+ "px";
		}
    },
	DeleteInfo: function(LifeID) {
        if (!window.confirm('此操作不可逆，您确定删除吗?')) 
		{
			return;
		}
		else
		{
         	 $.ajax({
			  url: "../public/ajax.aspx?action=deletelife&LifeID="+LifeID,
			  cache: false,
			  success:function(data)
			  {
				  if(data==0)
				  {
					alert("恭喜您，信息删除成功。");
					window.location.href=window.location.href;
				  }
				  else{
					alert(data);
				  }
			  }
			});	
        }
    },
	RepostInfo: function(obj, LifeID) {
		var ScoreName= $("#RepostInfoScoreName").html();
		var score = $("#RepostInfoScore").html();
		if (!window.confirm("每刷新一条信息，将会扣除" + score +ScoreName+ ",您确定要刷新么?"))
		{
			return;
		}
		
		$.ajax({
			  url: "../public/ajax.aspx?action=flushlife&LifeID="+LifeID,
			  cache: false,
			  success:function(data)
			  {
				  if(data.indexOf("Success")!=-1)
				  {
						alert("恭喜您，本条信息刷新成功，发布时间更新为"+data.replace("Success","")+"。");
				  }
				  else{
				  		alert(data);
				  }
			  }
		});	
	},
	DeleteInfoAll: function() {
        var allID = GetSelectID('LifeID');
        if (allID == "") {
            alert("请先选择要删除的信息!");
            return;
        }
		if (!window.confirm('此操作不可逆，您确定删除选中的信息吗?')) 
		{
			return;
		}
		else
		{
			$.ajax({
			  url: "../public/ajax.aspx?action=deletelife&LifeID="+allID,
			  cache: false,
			  success:function(data)
			  {
				  if(data==0)
				  {
					alert("恭喜您，信息批量删除成功。");
					window.location.href=window.location.href;
				  }
				  else{
					alert(data);
				  }
			  }
			});	
		}
    },
	FlashInfoAll: function() {
		var ScoreName= $("#RepostInfoScoreName").html();
		var score = $('#RepostInfoScore').html();
        var itemCount = 0;
        var allID = GetSelectID('LifeID');
        if (allID == "") {
            alert("请先选择要刷新的信息!");
            return;
        }
        itemCount = allID.split(',').length;
        if (!window.confirm('刷新这些信息需要' + (score * itemCount) +ScoreName+'，您确定刷新这些信息吗?')) {
            return false;
        }
        else {
            $.ajax({
			  url: "../public/ajax.aspx?action=flushlifeall&LifeID="+allID,
			  cache: false,
			  success:function(data)
			  {
				  if(data.indexOf("Success")!=-1)
				  {
					alert("恭喜您，信息刷新成功，共扣除"+(score * itemCount) +ScoreName+"。");
					window.location.href=window.location.href;
				  }
				  else{
					alert(data);
				  }
			  }
			});	
        }
	}
}
function GetSmallLifeClass(_id){
    $.post("/public/ajax.aspx?action=showlifeclassid&typeid=0", {id:_id}, function(data) {
		var $small=$("select[name='txtLifeTypeID']");
		$small.html("");
		$.each(data,function(idx,item){
			$small.append("<option value='"+item.id+"'>"+item.name+"</option>");
		});
		//$("#txtLifeTypeID").val(SmallClassid);
	},"json");
}
