$(document).ready(function()
{
	formInteraction();
});
function formInteraction()
{
	$("#leftContent form").find("input").each(function()
	{
	
		$(this).focus(function()
		{
			if($("#leftContent form").find(".errorInput").length == 0 && !$(".errorMessage").is(":hidden"))
			{
				$(".errorMessage").fadeOut("fast");
			}
			
			$(this).next(".tip").show();
		});
		
		$(this).blur(function()
		{
			if($(this).val() != "") 
			{
				$(this).removeClass("errorInput");
			}
			
			$(this).next(".tip").hide();
		});
	});
}
function submitLogin()
{
	var check = true;
	
	$("#leftContent form").find(".req").each(function()
	{
		if($(this).val() == "") {
			$(this).addClass("errorInput");
			check = false;
		}
	});
	
	if(check)
	{
		if($("#rembme").is(":checked")){
			var now = new Date();
			now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365)
			$.cookie("cuname",$("#uname").val(),{expires:now});
			$.cookie("cpword",$("#pword").val(),{expires:now});
		}
		
		$("#userlogin").submit();
	} else {
		$(".errorMessage").fadeIn("fast");
	}
	
	return false;
}
function submitSignup()
{
	var check = true;
	
	if($("#fpassword").val().search(/\d+/) == -1 || $("#fpassword").val().length < 6)
	{
		$("#fpassword").next(".tip").show();
		$("#fpassword").next(".tip").find("span").css("color","#ff0000");
		
		$("#fpassword").addClass("errorInput");
		
		check = false;
	}
	
	$(".signup").find(".req").each(function()
	{
		if($(this).val() == "") {
			$(this).addClass("errorInput");
			check = false;
		}
	});
	
	if(check)
	{
		$("#fusername").val($("#femail").val());
		$("#newuser").submit();	
	} else {
		$(".errorMessage").fadeIn("fast");
	}
	
	return false;
}
