var xhr = new_xhr();
var url = 'http://www.lowcostwebdesignchulavista.com/wp-content/themes/lcwdcv/affiliate_code.php';

function chk_dom() {
    if (url.match(/yourdomain/)){
      alert('Please configure the url variable to the proper location where you created affiliate_code.php');
      return false;
    }
    var domainname = document.domain_search.domainname.value;
    var tld = document.domain_search.tld.value;
    var domain = domainname + '.' + tld;
    if (!xhr) {
        return false;
    }   
    xhr.onreadystatechange = statusCheck;
    xhr.open('GET', url + '?domain=' + domain, true);
    xhr.send(null);
}

function statusCheck() {
    if (xhr.readyState == 4) {
        if (xhr.status == 200) {
            var resp_div = document.getElementById('response');
            if (xhr.responseText.match(/^Fatal/)){
              resp_div.innerHTML = "An error occurred. Please try again later.";
              return false;
            }
            var json = eval('(' + xhr.responseText + ')');
            if (json.error) {
                resp_div.innerHTML = "The domain "+json.domain+" is unavailable";
            }   
            if (json.available) {
                resp_div.innerHTML = "The domain "+json.domain+" is AVAILABLE!!<br /><a href='http://www.hostmonster.com/track/omniunlimited/signup?page=cgi-bin/signup/"+json.domain+"'>Click here to Claim it Now!</a>";
            }   
            else {
                return false;
            }   
        }   
    }   
}

function new_xhr() {
    var req;
    try {
        req = new XMLHttpRequest();
    }   
    catch(e) {
        try {
            req = new ActiveXObject("Microsoft.XMLHttp");
        }   
        catch(e) {}
    }   
    if (!req) {
        return false;
    }   
    else {
        return req;
    }   
}

