
// Get an XMLHttpRequest object in a portable way.
function HTTPRequest()
{
  req = false;
  if (window.XMLHttpRequest) { // Non Internet Explorers
    try {
      req = new XMLHttpRequest();
    } catch (e) { req = false; }
		return req;
  }
	
	if (window.ActiveXObject) { // Microsoft
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } 
		catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) { req = false; }
    }
  }
	return req;
}

function askWhois(div_id, domain, tld, fromdomain, prod_id) {
	var req = HTTPRequest();
	req.open("GET", "http://"+fromdomain+"/whois/whois_lookup.php?domain="+domain+"&tld="+tld+"&ptype="+prod_id, true);
	req.onreadystatechange = function() {
	if (req.readyState != 4) {
		return; // not ready
	}
	if (req.status == 200) {
		if (req.responseText) {
				var res = new Array();
				res = req.responseText.split(';');
				
				if (res[0] == 'Optaget') {

					document.getElementById(div_id).innerHTML = '<font color="#FF0000">' + res[0] + "</font>";
					document.getElementById(div_id+'price').innerHTML = res[1];
					document.getElementById(div_id+'host').innerHTML = res[2];

					document.getElementById(div_id+'dom').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=dom&act=move&xdomain="+domain+"."+tld+'&tld='+tld+'">Flyt</a>';
					document.getElementById(div_id+'shop').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=shop&act=move&xdomain="+domain+"."+tld+'&tld='+tld+'">Flyt</a>';
					document.getElementById(div_id+'web').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=web&act=move&xdomain="+domain+"."+tld+'&tld='+tld+'">Flyt</a>';
					document.getElementById(div_id+'micro').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=micro&act=move&xdomain="+domain+"."+tld+'&tld='+tld+'">Flyt</a>';
					document.getElementById(div_id+'link').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=select&act=move&xdomain="+domain+"."+tld+'&tld='+tld+'">Flyt</a>';
				} else
				if (res[0] == 'Ledigt') {
					document.getElementById(div_id).innerHTML = '<font color="#00AA00">' + res[0] + "</font>";
					document.getElementById(div_id+'price').innerHTML = res[1];
					document.getElementById(div_id+'host').innerHTML = res[2];
					
					document.getElementById(div_id+'dom').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=dom&act=buy&xdomain="+domain+"."+tld+'&tld='+tld+'">Køb</a>';
					document.getElementById(div_id+'shop').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=shop&act=buy&xdomain="+domain+"."+tld+'&tld='+tld+'">Køb</a>';
					document.getElementById(div_id+'web').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=web&act=buy&xdomain="+domain+"."+tld+'&tld='+tld+'">Køb</a>';
					document.getElementById(div_id+'micro').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=micro&act=buy&xdomain="+domain+"."+tld+'&tld='+tld+'">Køb</a>';
					document.getElementById(div_id+'link').innerHTML = '<a href="' + "http://"+fromdomain+"/domain_action.php?type=select&act=buy&xdomain="+domain+"."+tld+'&tld='+tld+'">Køb</a>';				
				} else
				document.getElementById(div_id).innerHTML = '<font color="#CCCCCC">' + req.responseText + "</font>";
		}
	} else {
		// error
	}
	req = null;
}

req.send("");
}


function askWhoisSimple(div_id, domain, tld, fromdomain) {
	var req = HTTPRequest();
	req.open("GET", "http://"+fromdomain+"/whois/whois_lookup.php?domain="+domain+"&tld="+tld, true);

	req.onreadystatechange = function() {
	if (req.readyState != 4) {
		return; // not ready
	}
	if (req.status == 200) {
		if (req.responseText) {
				var res = new Array();
				res = req.responseText.split(';');
				if (res[0] == 'Ikke tilladt') {
					document.getElementById(div_id).innerHTML = '<font color="#FF0000">Domænenavnet er ikke gyldigt</font>';
				}
				if (res[0] == 'Timeout') {
					document.getElementById(div_id).innerHTML = '<font color="#FF0000">Der er opstået en fejl. Gå tilbage og prøv igen.</font>';
				}
				if (res[0] == 'Optaget') {
					document.getElementById(div_id).innerHTML = '<input type="hidden" name="domainmove" value="true"><font color="#4242EE">Domænet: '+domain+"."+tld+' flyttes.</font>';
					document.getElementById(div_id+'submit').style.visibility = 'visible';
				}
				if (res[0] == 'Ledigt') {
					document.getElementById(div_id).innerHTML = '<input type="hidden" name="domainmove" value="false"><font color="#00AA00">Domænet: '+domain+"."+tld+' købes.</font>';
					document.getElementById(div_id+'submit').style.visibility = 'visible';					
				}
		
		}
	} else {
		// error
	}
	req = null;
}

req.send("");
}
