﻿$(function(){
	var f = function(el, txt){
		if ($.trim(el.value).length == 0)
			el.value = txt;
	};
	$("#username").each(function(){
		f(this, "Username");
	}).focus(function(){
		if (this.value == "Username")
			this.value = "";
	}).blur(function(){
		f(this, "Username");
	});
	$("#flogin a").click(function(){
		var ins = $('<div><span class="ltitle">Remember me on this computer</span><p>Checking this box will keep you logged in on the computer you are using even if you close your browser.</p></div>').appendTo("#flogin").fadeIn();
		setTimeout(function(){
			ins.fadeOut(function(){
				$(this).remove();
			});
		}, 6000);
		return false;
	});
	$("#subscribe").validate({success: "valid", rules: {
		name: "required",
		email: {
			required: true,
			email: true
		}
	}, errorPlacement: function(error, element){
		element.after(error);
	}, submitHandler: function(form){
		$(document.createElement("img")).attr("src", "images/load.gif").appendTo("#result");
		$(form).ajaxSubmit({dataType: 'json', clearForm: true, success: function(data){
			$("#result").html(data.success ? "Subscription successful!<br />You will receive an email shortly." : data.error);
			setTimeout(function(){
				$("#result").empty();
			}, 10000);
		}});
	}});
});