function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

$(document).ready(function(){
    $('.default-value').each(function() {
        var default_value = this.value;
        $(this).css('color', '#BA55D3'); // this could be in the style sheet instead
        $(this).focus(function() {
            if(this.value == default_value) {
                this.value = '';
                $(this).css('color', '#000');
            }
        });
        $(this).blur(function() {
            if(this.value == '') {
                $(this).css('color', '#BA55D3');
                this.value = default_value;
            }
        });
    });


    var email = $("#email_from").val();
    $("#email_from").keyup(function(){
        var email = $("#email_from").val();    

        if(email != 0)
        {
            if(isValidEmailAddress(email))
            {
                $("#validEmail").css({
                    "background-image": "url('ymjz/validYes.png')"
                });
            } else {
                $("#validEmail").css({
                    "background-image": "url('ymjz/validNo.png')"
                });
            }
        } else {
            $("#validEmail").css({
                "background-image": "none"
            });			
        }
    });


    $("#signupForm").submit(function(){
        var email = $("#email_from").val();    

        if (
            email == 0
                ||
            !isValidEmailAddress(email)
        ) {
            alert("Please enter a valid email address.");
            $("#email_from").focus();
            return false;
        }

		// if ($("#textfield").val() != '') {
		// return confirm("Are you sure?");
		// }
        // return confirm("Are you sure?");

        if ($('#agreed:checked').val() == null) {
            alert("You must agree to our privacy policy and terms.");
            return false;
        } else {
            return true;
        }
//$('input:checkbox', this).is(':checked')

	});    
});
