﻿var emailMsg = "Enter e-mail address here";
function removeDefaultText(textBox) {
    if (textBox.value == emailMsg) {
        textBox.value = "";
    }
}
function replaceDefaultText(textBox) {
    if (textBox.value.trim() == "") {
        textBox.value = emailMsg;
    }
}
function saveEmailAddress(textBox) {

    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(textBox.value))) {
        alert("Please enter a valid e-mail address.");
        return false;
    }

    var xmlhttp;
    if (window.XMLHttpRequest) //Code for IE7+, Firefox, Chrome, Opera, Safari
    {
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) //Code for IE6, IE5
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            alert(xmlhttp.responseText);
            textBox.value = emailMsg;
        }
    }

    xmlhttp.open("GET", "SaveEmail.aspx?email=" + textBox.value, true);
    xmlhttp.send(null);
}
String.prototype.trim = function() { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }