var http_request = false;

function makeRequest(url, parameters) 
{
  http_request = false;
  
  if (window.XMLHttpRequest) 
  {
	 http_request = new XMLHttpRequest();
	 
	 if (http_request.overrideMimeType) 
	 {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
	 
  } 
  else if (window.ActiveXObject) 
  { // IE
	 try 
	 {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } 
	 catch (e) 
	 {
		try 
		{
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (e) 
		{
		}
	 }
  }
  
  if (!http_request) 
  {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('GET', url + parameters, true);
  //alert(url+parameters);
  http_request.send(null);
}

function alertContents() 
{
  if (http_request.readyState == 4) 
  {
	 if (http_request.status == 200) 
	 {
		//alert(http_request.responseText);
		result = http_request.responseText;
		resultArr = result.split("&");
		//alert(resultArr);
		result = resultArr[resultArr.length-2];
		//alert(resultArr.length-2);
		
		for(i = 0; i < resultArr.length; i++)
		{
			//This bit gives our users their results
			var divid = 'myspan'+i;
			if(document.getElementById(divid)) {
				document.getElementById(divid).innerHTML = resultArr[i]; 
			
			
				//This bit adds the details into 
				//our actual order form
				newnode = document.createElement("input");
				var domain = resultArr[i].split("-");
				newnode.value = domain[1].substring(0, 11);
				newnode.name = domain[0];
				newnode.type = "hidden";
				document.getElementById('order_form').appendChild(newnode);
			}
		}
	 } 
	 else 
	 {
		alert('There was a problem with the request.');
	 }
  }
}

function get(obj) 
{

  var getstr = "?";
  
  for (i=0; i<obj.childNodes.length; i++) 
  {
	 if (obj.childNodes[i].tagName == "INPUT") 
	 { 
		if (obj.childNodes[i].type == "text") 
		{
		   getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		}
		
		if (obj.childNodes[i].type == "checkbox") 
		{
		   if (obj.childNodes[i].checked) 
		   {
			  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		   } 
		   else 
		   {
			  getstr += obj.childNodes[i].name + "=&";
		   } 
		}
		
		if (obj.childNodes[i].type == "radio") 
		{
		   if (obj.childNodes[i].checked) 
		   {
			  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		   }
		}
	 }  

	 if (obj.childNodes[i].tagName == "SPAN") 
	 {
		var spancontents = obj.childNodes[i];
		getstr += spancontents.childNodes[0].name + "=" + spancontents.childNodes[0].value + "&";
		getstr += spancontents.childNodes[1].name + "=" + spancontents.childNodes[1].value + "&";
		//alert(spancontents.childNodes[0].name + spancontents.childNodes[0].value);
		//alert(spancontents.childNodes[1].name + spancontents.childNodes[1].value);
	 }
	  
	 if (obj.childNodes[i].tagName == "SELECT") 
	 {
		var sel = obj.childNodes[i];
		getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	 }
  }
  
  makeRequest('whois_result.php', getstr);
  
}