﻿/* JScript File */

//* Email Field Effects Script *//
function Clear(theText) { if (theText.value == theText.defaultValue) {theText.value = ""} }
function Fill(theText) { if (theText.value == "") {theText.value = "Notify me on website launch date"} }

//* Email Form Validation (AJAX) Script *//
$(document).ready(function(){
    $('#signup').submit(function() {
			 
/* Set variables */			
	var emailField = $('#email').val();
	var emailValid = /.+@.+\.[a-zA-Z]{2,4}$/;

/* Empty all error/success messages if any*/
	$('.fail,.success').empty();	

/* Email field validation */	
	if(!emailValid.test(emailField)) {

/* Empty all error/success messages if any*/			
		$('.fail,.success').empty()

/* Error - Invalid email message */	
		$('#signup').after('<span class="fail">*Please enter a valid email adress.</span>')
		$('span').fadeIn('slow')
		$('#email').focus()
		return false;
			
	} else {

/* Empty all error/success messages if any*/
		$('.fail,.success').empty();

/* Success - Insert subscribers data */			
		$.ajax({
			url: 'email.php',
			data: {'email': emailField},
			type: 'POST',

/* Success - Valid email message */	
			success: function() {
				$('#signup').after('<span class="success">Thank you for signing up!</span>')
				$('span').fadeIn('slow')
				}
			})
		return false;
		}
	});
});