/* 表单验证相关 */
function changeYzm(){
	jQuery('#yanzheng').focus(function(){jQuery(this).next().trigger('click');});
}
//分页
function pageJs(page,id,type,totle){
	jQuery("#pageNav a").removeClass('active');
	jQuery("#p"+page).addClass('active');
	if(page==1){
		jQuery("#prev").replaceWith("<span id='prev' class='prev'>«上一页</span>");
	}else{
		var pagep=parseInt(page)-1;
		jQuery("#prev").replaceWith("<a href='javascript:pageJs("+pagep+","+id+","+type+","+totle+")' id='prev' class='prev'>«上一页</a>");
	}
	if(page==totle){	
		jQuery("#next").replaceWith("<span id='next' class='previous-off'>下一页 »</span>");
	}else{
		var pagep=parseInt(page)+1;
		jQuery("#next").replaceWith("<a href='javascript:pageJs("+pagep+","+id+","+type+","+totle+")' id='next' class='next'>下一页 »</a>");
	}
	var path = '/comment_glb/getPageInfo';
	jQuery.ajax({
   type: "POST",
   url: path,
   data: "id="+id+"&page="+page+"&totle="+totle+"&type="+type,
   success: function(msg){
	jQuery('#comtList').html(msg);
   }
}); 
}

function support(id,n){
	var path = '/comment_glb/setSupport';
	jQuery.ajax({
		type: "POST",
		url: path,
		data: "id="+id,
		global :false,
		success: function(msg){
		var num=parseInt(n)+1;
		jQuery("#s"+id).replaceWith("<span style='cursor:text'>已支持("+num+")</span>");
   }
}); 
}

function comment(id,type){
			var content = jQuery("#replyText").val();
			var grade = jQuery("#starRate").val();
			if(content==''){
				alert('请先输入相关内容');
				return false;
			}
			if(content.length>100){
				alert("请填写少于100字的评论");
				return false;
			}
			if(content.length<5){
				alert("请填写多于5字的评论");
				return false;
			}
			jQuery.post("/comment_glb/def",{id:id,type:type,content:content,grade:grade}, function (msg){
				if(msg!=''){		
					jQuery("#replyText").val('');
					jQuery("#comtList").prepend(msg);
					var num=parseInt(jQuery("#a1").text())+1;
					jQuery("#a1").text(num);
					jQuery("#warn").remove();
				}else{
					alert('服务器忙，请稍后');
				}
			});
			return false;
}

function message(id){
	var content = jQuery("#mesgText").val();
	var path = "/comment_glb/message";
	if(content==''){
		alert('您还没有填呢。');
		return false;
	}
	if(content.length>100){
				alert("请填写少于100字的评论");
				return false;
	}
	if(content.length<5){
		         alert("请填写多于5字的评论");
				return false;
			}
	jQuery.ajax({
	   type: "POST",
	   url: path,
	   data: "id="+id+"&content="+content,
	   global :false,
	   success: function(msg){
		jQuery("#nomsg").hide();
		jQuery('#mesgText').val(''); 
		jQuery("#messagelist").prepend(msg);
   }
}); 
	return false;
}

function delMdd(id){
	var path = "/comment_glb/delgone";
		jQuery.ajax({
	   type: "POST",
	   url: path,
	   data: "id="+id,
	   global :false,
	   success: function(msg){
		jQuery("#userMdd"+id).remove();
		alert('删除成功');
   }
}); 
}
//搜索城市
function show_shi(id){	
 jQuery.get("/chengshi", {id: id},function(data){
	jQuery("#citylist").empty();
    jQuery("#citylist").append(data);
  }); 
}

function singupyz(){
	var name=jQuery("#name").val();
	var mail=jQuery("#mail").val();
	var paswd = jQuery("#password").val();
	var paswdL= paswd.length;
	var repaswd=jQuery("#repaswd").val();			
	var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	
	function getyanValue(){
		var a ;
		var yanzheng=jQuery("#yanzheng").val();
		jQuery.ajax({
			type:'POST',
			async:false,
			url:'/yanzhengma.php',
			data:'yanzheng='+yanzheng,
			success:function(msg){
				if(msg=='true'){
					a='true';
				}else{
					a='false';
				}
			}
		});
		return a;
	}
	if(getyanValue()=='false'){
		jQuery('#yanzhengma').next().remove().end().after('<i>验证码输入错误</i>');
		jQuery('#yanzheng').select();
		return false;
	}else{
		jQuery('#yanzhengma').next().remove();
	}	

	if(name==""){
		jQuery("#name").focus().next().remove().end().after('<i>名字不能为空</i>');
		return false;
	}else{
		jQuery("#name").next().remove();
	}

	if(mail==""){
		jQuery("#mail").focus().next().remove().end().after("<i>邮箱地址不能为空</i>");
		return false;
	}

	if(search_str.test(mail)){
		 jQuery("#mail").next().remove();
	   }else{
		 jQuery("#mail").focus().next().remove().end().after("<i>邮箱地址填写不正确</i>");
		 return false;
	   }
	function getAjaxValue(){
		var a ;
		var mail=jQuery("#mail").val();
		jQuery.ajax({
			type:'POST',
			async:false,
			url:'/denglu_glb/yuser',
			data:'name='+mail,
			success:function(msg){
				if(msg=='true'){
					a='true';
				}else{
					a='false';
				}
			}
		});
		return a;
	}
	if(getAjaxValue()=='false'){
		jQuery("#mail").focus().next().remove().end().after("<i>邮箱地址已经被使用</i>");
		return false;
	}

	if(paswdL<6 || paswdL >20){
		jQuery("#password").focus().next().remove().end().after("<i>对不起，暂时仅支持6~20位密码</i>");
		return false;
	}else{
		jQuery("#password").next().remove();
	}
	if(paswd!=repaswd){
		jQuery("#repaswd").focus().next().remove().end().after("<i>两次密码输入不一致</i>");
		return false;
	}else{
		jQuery("#repaswd").next().remove();
	}
	if(!jQuery('#agree').attr('checked')){
		jQuery('#agree').parent().next().remove().end().after('<i>您需要同意协议才能继续</i>');
		return false;
	}else{
		jQuery('#agree').parent().next().remove();
	}
}
function loginyz(){
	var mail=jQuery("#mail").val();
	var password=jQuery("#password").val();	
	function getyanValue(){
		var a ;
		var yanzheng=jQuery("#yanzheng").val();

		jQuery.ajax({
			type:'POST',
			async:false,
			url:'/yanzhengma.php',
			data:'yanzheng='+yanzheng,
			success:function(msg){
				return msg;
			}
		});
	}
	if(getyanValue()=='false'){
		jQuery('#yanzhengma').next().remove().end().after('<i>验证码输入错误</i>');
		jQuery('#yanzheng').select();
		return false;
	}else{
		jQuery('#yanzhengma').next().remove();
	}			

	if(mail==""){
		jQuery("#mail").focus().next().remove().end().after('<i>邮箱不能为空</i>');
		return false;
	}else{
		jQuery("#mail").next().remove();
		}
		
 if(password==""){
		jQuery("#password").focus().next().remove().end().after('<i>密码不能为空</i>');
		return false;
	}else{
		jQuery("#password").next().remove();
		}
}

//热门搜索
jQuery(function(){
	jQuery('#hotS > a').click(function(){	
		jQuery('#searchKey').val(jQuery(this).text());
		jQuery('#submit').click();
	})
})

//验证码
function newgdcode(obj,url) {
 obj.src = url+ '&nowtime=' + new Date().getTime();
//后面传递一个随机参数，否则在IE7和火狐下，不刷新图片
};


//洲国家目的地搜索联动
function show_guo(id){
jQuery.get("/searchlian/guo", {id: id},
  function(data){
	jQuery("#mddcs").show();
	jQuery("#mdd_list").empty();
    jQuery("#guo_list").empty();
    jQuery("#guo_list").append(data);
	jQuery("#guocs").hide();
  }); 
}
function show_mdd(id){
jQuery.get("/searchlian/mdd", {id: id},
  function(data){
    jQuery("#mdd_list").empty();
    jQuery("#mdd_list").append(data);
	jQuery("#mddcs").hide();
  }); 
}
jQuery(function(){
jQuery.post("/searchlian/zhou",{},function(data){
    jQuery("#zhou_list").append(data);
  }); 
})

	function delreply(id){
			if(confirm('确实要删除？')){
			$.post("/comment/delreplay.html",{id:id}, function (msg){
				$('#replyItem'+id).css('background', 'red').fadeOut(800);	
			})
		}		
	}
//user 注册用户 留言回复等
$(function(){
		var userID=$('#messagelist').attr('rel');
		$('#messagelist > li').hover(function(){
			var listId = $(this).attr('id').replace('item', '');
			$(this).find('.dowhat').show()
			.children('.replyIt').click(function(){
				$('#replyBox').remove();
				$(this).parent().parent().parent()
				.append('<div id="replyBox"><label for="replyText"><img src="/forum/uc_server/avatar.php?uid='+userID+'&size=small" /></label><textarea id="replyText"></textarea><input type="button" value="确&nbsp;定" onclick="replay('+listId+')"/><div class="clear"></div></div>')
				.find('#replyText').focus().autoResize({ animateDuration : 300, extraSpace : 18, limit: 150 });
			},function(){
				$('#replyBox').remove();
			})
			.next().click(function(){
				if(confirm("确实要删除吗?")){
					$.post("/comment/delmessage",{id:listId}, function (msg){  });
					$("#item"+listId).css('background', 'red').fadeOut(800);
				}
			});
		}, function(){
			$(this).find('.dowhat').hide();			
		}).children('.replyItem').hover(function(){
			var $replyWho = $('img', this).attr('alt');
			var $listId = $(this).parent().attr('id').replace('item', '');
			$(this).find('.dowhat').show().children('.replyIt').click(function(){
				$('#replyBox').remove();
				$(this).parent().parent()
				.after('<div id="replyBox"><label for="replyText"><img src="/forum/uc_server/avatar.php?uid='+userID+'&size=small" /></label><textarea id="replyText"></textarea><input type="button" value="确&nbsp;定" onclick="replay('+$listId+')"/><div class="clear"></div></div>')
				.next().children('textarea').focus().val('@'+$replyWho+'：').autoResize({
					animateDuration : 300, extraSpace : 18, limit: 120 });
			});
			$('del', this).show();
		}, function(){
			$(this).find('.dowhat').hide();
			$('del', this).hide();
		});
		
	})
	function replay(id){
		var replay = $("#replyText").val();
			if(replay==''){
				alert('您还没有填呢。');
				return false;
			}
			if(replay.length>300){
					alert("请填写少于300字的评论");
					return false;
			}
			if(replay.length<5){
					 alert("请填写多于5字的评论");
					return false;
					}
					if(replay==''){
						alert('请先输入相关内容');
						$('#replyText').focus();
				return false;
			}
			$.post("/comment/replay.html",{id:id,replay:replay}, function (msg){
				if(msg!=''){
					$('#item'+id).append(msg).find('.replyItem:last').hide().fadeIn(600);
					$('#replyBox').remove();
				}
			});
	}
	
	//酒店图片等比例缩放
	
	function DrawImg(boxWidth,boxHeight)

{

　　　 var imgWidth=$(".info_s").width();

　　 var imgHeight=$(".info_s").height();

　　　 //比较imgBox的长宽比与img的长宽比大小

　　　 if((boxWidth/boxHeight)>=(imgWidth/imgHeight))

　　　 {

　　　　　　　 //重新设置img的width和height

　　　　　　　 $(".info_s").width((boxHeight*imgWidth)/imgHeight);

　　　　　　　 $(".info_s").height(boxHeight);

　　　　　　　 //让图片居中显示

　　　　　　　 var margin=(boxWidth-$(".info_s").width())/2;

　　　　　　　 $(".info_s").css("margin-left",margin);

　　　 }

　　　 else

　　　 {

　　　　　　　 //重新设置img的width和height

　　　　　　　 $(".info_s").width(boxWidth);

　　　　　　　 $(".info_s").height((boxWidth*imgHeight)/imgWidth);

　　　　　　　 //让图片居中显示

　　　　　　　 var margin=(boxHeight-$(".info_s").height())/2;

　　　　　     $(".info_s").css("margin-top",margin);

　　　 }

} 
	
