$(document).ready(function(){
	$("#btn_ok").click(function(){					   				   
		$("#label").replaceWith('<label id="label" for="email">Processing...</label>');
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailVal = $("#email").val();
		if(emailVal == '') {
			$("#label").replaceWith('<label class="error" id="label" for="email">Please enter your e-mail address below</label>');
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$("#label").replaceWith('<label class="error" id="label" for="email">Please enter a valid email address</label>');
			hasError = true;
		}

		if(hasError == false) {
			$("#btn_ok").replaceWith('<img id="btn_loading" type="image" class="button" src="gfx/btn_loading.gif" alt="Sending..." width="16" height="16">');
			
			$.post("inc/sendEmail.php",
   				{ email: emailVal, fromJS: "yup" },
   					function(data){
 						$("#email").replaceWith('<input id="email" type="text" class="text done" name="email" maxlength="40" value="">');
						$("#btn_loading").replaceWith('<img id="btn_done" type="image" class="button" src="gfx/btn_done.gif" alt="Complete" width="16" height="16">');
						$("#label").replaceWith('<label id="label" for="email">Thank you for signing up!</label>');
   					}
				 );
		}
		return false;
	});						   
});