﻿/// <reference path="jquery-1.3.1.js"/>

function Signup(timeout, input, submit) {
    var uri = '/SignUp.ashx';
    var that = this;
    submit
    .click(function() {
        that.Register(input.val());
        return false;
    });

    input
    .blur(function() {
        if (this.value == '') {
            this.value = 'Enter your email here';
            this.style.color = '#ADADAD';
        }
    })
    .focus(function() {
        if (this.value == 'Enter your email here') {
            this.value = '';
            this.style.color = '#000000';
        }
    });

    this.Register = function(email) {
        if (email === '' || email === 'Enter your email here')
            return;
            
        $.ajax({
            type: "POST",
            url: uri,
            data: "email=" + email,
            processData: true,
            timeout: this.timeout,
            dataType: "html",
            success: function(data) {
                switch (data) {
                    case 'OK':
                        alert('Thanks for that! We will let you know when form.ly launches.');
                        break;
                    case 'EMAIL_REQUIRED':
                        alert('Please enter your e-mail address.');
                        break;
                    case 'EMAIL_NOT_VALID':
                        alert('Please enter a valid e-mail address.');
                        break;
                    default:
                        alert('An unexpected error has occurred. Please try again later.');
                        break;
                }
            }
        });
    }
}

$().ready(function() {
    var signup = new Signup(10000, $('#input-email'), $('#Submit'));
});