$(document).ready(function(){
	//global vars
	var form = $("#formSignup");
	var fname = $("#fullname");
	var email = $("#email");

	//On Submitting
	form.submit(function(){
		//first check if they filled in name and email
		if(validateName() & validateEmail()){
			//check if email address is valid
			if(!validateEmailAddress()) {
				alert("Please enter a valid Email Address");
				return false;
			} else { 
				showflash();
				dismissbox();	
				return true;
			}
		} else {
			alert("Please make sure all fields are filled in");
			return false;
		} 
	});
	
	function validateEmail(){
		//testing regular expression
		if(email.val().length < 1){
			return false;
		} else {
			return true;
		}
	}
	
	//validation functions
	function validateEmailAddress(){
		//testing regular expression
		var a = $("#email").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		if(filter.test(a)){
			return true;
		}
		else{
			return false;
		}
	}

	function validateName(){
		//if it's NOT valid
		if(fname.val().length < 1){
			return false;
		}
		//if it's valid
		else{
			
			return true;
		}
	}
	
	function hideflash(){
        /* hide all flash in the page */
        flash = document.getElementsByTagName('embed')
        for (var i = 0; i < flash.length; i++) 
        { 
            flash[i].style.visibility = 'hidden';
        }
	}
	function showflash(){
			/* show all flash */
			flash = document.getElementsByTagName('embed')
			for (var i = 0; i < flash.length; i++) 
			{ 
				flash[i].style.visibility = 'visible';
			}
	}
	
	
	
});
