var LANGUAGE='en';

function dummy() {
	return false;
}

function createXHR() {
	var xhr=null;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		xhr=new XMLHttpRequest();
		//if (xhr.overrideMimeType) xhr.overrideMimeType('text/xml');
  	} else if (window.ActiveXObject) { // IE
		try {
			xhr=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xhr=new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				xhr=null;
			}
		}
	}
	if(xhr==null) alert('Your browser doesn\'t support Ajax!');
	
	return xhr;
}

function getDomain(id, domain) {
	var xhr=createXHR();
	if(xhr==null) return;
	
		//state
	xhr.onreadystatechange=function() {
		if(xhr.readyState==4)
			if(xhr.status==200) {
				var docId=document.getElementById(id);
				if(docId) {
					var cn;
					var xml=xhr.responseXML;
					try {
						if(xml.getElementsByTagName('error').length==0) {
							if(xml.getElementsByTagName('registered')[0].firstChild.nodeValue=='true') {
								cn='exist';
								document.getElementById(id+'_status').innerHTML='[<a href="domain.whois.html?name='+domain+'" target=\"_blank\">whois</a>] [<a href="http://'+domain+'" target=\"_blank\">www</a>]';
								//alert(xhr.responseText);
							} else {
								cn='free'
								document.getElementById(id+'_status').innerHTML='<a href="http://domaindiscount24.net?page=products_checkresults&class=all&language='+LANGUAGE+'&affiliateID=00137984&domain='+domain+'" target=\"_blank\" title=\"Domaindiscount24\">dd24</a>';
							}
						} else {
							cn='error';
							document.getElementById(id+'_status').innerHTML='&nbsp;';
						}
					} catch(e) {
						cn='error';
						document.getElementById(id+'_status').innerHTML='&nbsp;';
					}
					docId.className=cn;
				}
			} else {
				alert('Connection-Error\n'+xhr.error);
			}
	}
	
	var query='request='+domain;
	query+='&load='+Math.random();
	
	xhr.open('POST','/domain');
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

	try {
		xhr.send(query);
	} catch(e) {
		alert('Internal error:\n'+e);
	}
}
