﻿// JScript File for Ajax to check availability of User Name
//Anoop Saha


var obXmlHttp;
//To post msg; clubId is required
function fnCheckAvailability() {
    if (document.getElementById("txtName").value == "Name") {

        document.getElementById("DivErrorDiv").innerHTML = "One of the fields was incomplete or filled out incorrectly—please try again";
        document.getElementById('lightMsg').style.display = 'block';
        document.getElementById('fademsg').style.display = 'block';
        document.getElementById("txtName").focus();
        return false;
    }
    if (document.getElementById("txtCompany").value == "Company") {
        document.getElementById("DivErrorDiv").innerHTML = "One of the fields was incomplete or filled out incorrectly—please try again";
        document.getElementById('lightMsg').style.display = 'block';
        document.getElementById('fademsg').style.display = 'block';
        document.getElementById("txtCompany").focus();
        return false;
    }
    if (document.getElementById("txtEmail").value == "Email") {
        document.getElementById("DivErrorDiv").innerHTML = "One of the fields was incomplete or filled out incorrectly—please try again";
        document.getElementById('lightMsg').style.display = 'block';
        document.getElementById('fademsg').style.display = 'block';
        document.getElementById("txtEmail").focus();
        return false;
    }
    obXmlHttp = GetXmlHttpObject();
    if (obXmlHttp == null) {
        alert("Your browser does not support AJAX!");
        return;
    }
    var dt2 = new Date();
    var url = 'http://www.goldleafdata.com/TestMail.aspx?dt2=' + dt2 + "&name=" + document.getElementById("txtName").value + "&company=" + document.getElementById("txtCompany").value + "&email=" + document.getElementById("txtEmail").value;
    obXmlHttp.onreadystatechange = stateChanged;
    obXmlHttp.open("GET", url, true);
    obXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    obXmlHttp.send(null); //Send the request with a null body.
}

function stateChanged() {
    if (obXmlHttp.readyState == 4) {
        //alert(obXmlHttp.responseText);
        document.getElementById("DivErrorDiv").innerHTML = obXmlHttp.responseText;
        document.getElementById('lightMsg').style.display = 'block';
        document.getElementById('fademsg').style.display = 'block';
        document.getElementById("txtName").value = "Name";
        document.getElementById("txtCompany").value = "Company";
        document.getElementById("txtEmail").value = "Email";
    }
}

function GetXmlHttpObject() {
    var obXmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        obXmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            obXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            obXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return obXmlHttp;
}

