var xhr = new_xhr();
var url = 'http://spanish.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 = "Se ocurri&oacute; un error. Favor de volver a intentar m&aacute;s tarde.";
              return false;
            }
            var json = eval('(' + xhr.responseText + ')');
            if (json.error) {
                resp_div.innerHTML = "El dominio "+json.domain+" no est&aacute; disponible.";
            }   
            if (json.available) {
                resp_div.innerHTML = "&iexcl;&iexcl;El dominio "+json.domain+" s&iacute; EST&Aacute; DISPONIBLE!!<br /><a href='http://www.hostmonster.com/track/omniunlimited/signup?page=cgi-bin/signup/"+json.domain+"'>&iexcl;Haga clic aqu&iacute; para Obtenerlo Ya!</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;
    }   
}

