﻿$(document).ready(function () {
	$('#SignUpFormToggle').click(function(e) {
        e.preventDefault();
	if ($('#SignUpFormArea').is(":hidden")) {
  		$('#SignUpFormBox').animate({ top: '-=25' }, 200, function() {});
  		$('#SignUpFormArea').slideDown(200, function() {});
	}
	else {
  		$('#SignUpFormArea').slideUp(200, function() {});
	  	$('#SignUpFormBox').animate({ top: '+=25' }, 200, function() {});
	};
	});

    $("#SearchQuery").focus(function () {
        // Select input field contents
        var formValue = $(this).val();
        if (formValue == "Enter Search") {
            $(this).val('');
        }
    });

    $("#AlertEmail").focus(function () {
        // Select input field contents
        var formValue = $(this).val();
        if (formValue == "Enter Email") {
            $(this).val('');
        }
    });


    $("#SignUpForm").submit(function (event) {
        // stop form from submitting normally
        event.preventDefault();
        // get some values from elements on the page:
        var $form = $(this), term = $form.find('input[name="AlertEmail"]').val(), url = $form.attr('action');
        var dataString = "AlertEMail=" + escape(term);
        // Send the data using post and put the results in a div
        // alert(url);
        // alert(dataString);
        $.ajax({
            url: url,
            type: "POST",
            data: dataString,
            dataType: "html",
            success: function (datahtml) {
                // alert("status returned!");
                var responseMessage = $(datahtml).find('#ResponseValue').text();
                if (responseMessage == "Submitted Okay") {
                    $("#SignUpForm").fadeOut(500, function () { $("#SignUpForm").html("<p><strong>Thank you for registering.</strong></p>").fadeIn(500, function () { }); });
                }
                else {
                    $("#SignUpStatus").text(responseMessage);
                    $("#AlertEmail").animate({ backgroundColor: "#ff0000"  }, 250, function() {});
                    $("#AlertEmail").animate({ backgroundColor: "#ffffcc" }, 1000, "easeOutSine", function() {});

                }
            },
            error: function () {
                $("#SignUpStatus").text("There was an error; try again: ");
                $("#AlertEmail").animate({ backgroundColor: "#ff0000"  }, 250, function() {});
                $("#AlertEmail").animate({ backgroundColor: "#ffffcc" }, 1000, "easeOutSine", function() {});
            },
            async: false
        });
        return false;
    });
});
