$(function(){
    var x = 10;  
	var y = 20;
	$("a.tooltip").mouseover(function(e){
       	this.myTitle = this.title;
		this.title = "";	
	    var tooltip = "<div id='tooltip'>"+ this.myTitle +"</div>"; 
		$("body").append(tooltip);
		$("#tooltip")
			.css({
				"top": (e.pageY+y) + "px",
				"left": (e.pageX+x)  + "px"
			}).show("fast");	  
    }).mouseout(function(){		
		this.title = this.myTitle;
		$("#tooltip").remove();   
    }).mousemove(function(e){
		$("#tooltip")
			.css({
				"top": (e.pageY+y) + "px",
				"left": (e.pageX+x)  + "px"
			});
	});
})

$(function(){
   $("li.main_nav").hover(function(){
$(this).children("ul").stop(true,true).fadeIn();
        },function(){
    $(this).children("ul").stop(true,true).fadeOut();
});
})

$(function(){
	   $(".hist").children("span:first").fadeIn("fast");
	   $(".hist").hover(function(){
			$(this).children("span").stop(true,true).fadeIn("fast");
			
        },function(){
		    $(this).children("span").stop(true,true).fadeOut("fast");
			$(".hist").children("span:first").fadeIn("fast");
		});
})

function StopButton(){
	document.getElementById(arguments[0]).disabled=true;
	document.getElementById(arguments[0]).value="提交("+arguments[1]+")";
	if(--arguments[1]>0){
		window.setTimeout("StopButton('"+arguments[0]+"',"+arguments[1]+")",1000);
	}
	if(arguments[1]<=0){
		document.getElementById(arguments[0]).value='提交';
		document.getElementById(arguments[0]).disabled=false;
	}
}

function SendComment(){	
		var $g_name=$('#g_name').val();
		var $g_username=$('#g_username').val();
		var $g_tel=$('#g_tel').val();
		var $g_mobile=$('#g_mobile').val();
		var $g_email=$('#g_email').val();
		var $g_content=$('#g_content').val();
        var $verifycode=$('#verifycode').val();
	if ($.trim($g_name)=='')
		{
			alert('请您填写姓名！');
			$('#g_name').focus();
			return false;
		}			
		if ($.trim($g_content)=='')
		{
			alert('请您填写留言内容！');
			$('#g_content').focus();
			return false;
		}
		if ($g_content.length<5||$g_content.length>200)
		{
			alert('内容必须在5-200字之间！');		
			return false;
		}
		if ($.trim($verifycode)=='')
		{
			alert('请您填写验证码！');
			$('#verifycode').focus();
			return false;
		}	
		StopButton('CommentSubmit',10);
		$('#sus').html("提交中...").fadeIn("slow");
	$.ajax({		  
		 type: "POST",
         url: "ajax.asp",
         data: "action=ajax_sendcomment&g_name="+$g_name+"&g_username="+$g_username+"&g_tel="+$g_tel+"&g_mobile="+$g_mobile+"&g_email="+$g_email+"&g_content="+$g_content+"&verifycode="+$verifycode+"&time="+new Date().getTime()+"",
		success:function(msg){ 
			if (msg=='ERROR')
			{
				$('#verifycode').focus();
				$('#sus').html("<font color=#ff0000>验证码错误！10秒后可继续提交！</font>").hide().stop(true,true).fadeIn("slow");
		    }
			else
			{
				$('#sus').html(msg).hide().stop(true,true).fadeIn("slow");
				$("#g_name").val("");			
                $('#g_username').val("");
                $('#g_tel').val("");
                $('#g_mobile').val("");
                $('#g_email').val("");
                $('#g_content').val("");
				$("#verifycodeimg").attr("src","_include/verifycode.asp?tm="+Math.random());
			}
			$("#verifycode").val("");
		}
	});
}

function SendSelect(){	
		var $name=$('#name').val();
        var $verifycode=$('#verifycode').val();
	if ($.trim($name)=='')
		{
			alert('请您填写姓名！');
			$('#name').focus();
			return false;
		}			
		if ($.trim($verifycode)=='')
		{
			alert('请您填写验证码！');
			$('#verifycode').focus();
			return false;
		}	
		StopButton('CommentSubmit',10);
		$('#sus').html("提交中...").hide().stop(true,true).fadeIn("slow");
	$.ajax({		  
		 type: "POST",
         url: "ajax.asp",
         data: "action=ajax_sendSelect&name="+$name+"&verifycode="+$verifycode+"&time="+new Date().getTime()+"",
		success:function(msg){ 
			if (msg=='ERROR')
			{
				$('#verifycode').focus();
				$('#sus').html("<font color=#ff0000>验证码错误！10秒后可继续提交！</font>").hide().stop(true,true).fadeIn("slow");
		    }
			else
			{
				$('#sus').html(msg).hide().stop(true,true).fadeIn("slow");
				$("#name").val("");
				$("#verifycodeimg").attr("src","_include/verifycode.asp?tm="+Math.random());
			}
			$("#verifycode").val("");
		}
	});
}
