/******************************
/******************************
* @author  Paulo Delgado <pdelgado@aismedia.com>
*****************************/
var superIndex=2;

function initXMLHTTP() {
var xmlhttp;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false;
 }
}

	
	return xmlhttp;
}


function verifyDomain() {
	document.getElementById('domain_check_button').disabled = true;
	document.getElementById('domain_check_button').value = "Querying";
	var domain = document.getElementById('domain').value;
	myDiv = document.getElementById('domain_results');
	myDiv.style.display = 'block'
	myDiv.innerHTML = "Please wait...";
	xmlhttp = initXMLHTTP();
	xmlhttp.open("GET","/whois/?domain=" + domain , true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4) {
			myXml = xmlhttp.responseXML;
			errors = myXml.getElementsByTagName('error');
			if(errors.length > 0) {
				myDiv.innerHTML = '<div class="error">' + errors[0].firstChild.data + '</div>';
				document.getElementById('domain_check_button').disabled = false;
				document.getElementById('domain_check_button').value = "Check Again";
			} else {
				domains = myXml.getElementsByTagName('domain');
				rehtml = '<table width="100%">';
				allow_form = false;
				for(i = 0 ; i < domains.length ; i++) {
					name = domains[i].getElementsByTagName('name')[0].firstChild.data;
					response_code = domains[i].getElementsByTagName('response_code')[0].firstChild.data;
					if(response_code == '210') {
						// available
						rehtml += '<tr><td><input type="checkbox" name="domains[]" checked value="'+ name + '"></td><td class="domain_name">' + name + '</td><td style="color: green;">Available!</td></tr>';
						allow_form = true;
					} else {
						// taken
						rehtml += '<tr><td><input type="checkbox" name="" value="" disabled></td><td class="domain_name">' + name + '</td><td style="color: red;">Taken</td></tr>';
					}
					
				}
				if(allow_form) {
					rehtml += '<tr><td colspan="3"><input type="submit" value="Purchase Selected Domains"></td></tr>';
					rehtml += "</table>";
				} else {
					rehtml += "</table>";
				}
				
				myDiv.innerHTML = rehtml;
				document.getElementById('domain_check_button').disabled = false;
				document.getElementById('domain_check_button').value = "Check Again";
			}
		}
	}
	xmlhttp.send(null);
	return false;
}
