var NAMESPRO_AFFILIATE_CODE = 'stl06g0rt4j1abdsj8sf';
var NAMESPRO_URL = "http://www.namespro.ca/SearchResult.asp?affiliatecode="+NAMESPRO_AFFILIATE_CODE+"&domainName=";


function checkDomains(list1, list2)
{
  // clear the results area.
  var results = document.getElementById('results');
  results.innerHTML = "";
  
  // loop through each domain extension
  for (var i in document.form1){
    if ((i.indexOf("ext_") == 0) && (document.form1[i].checked)){
      ext = i.substring(4,i.length);

      // loop through words checking each combo...
      for (i = 0; i < list1.length; i++){
	for (j = 0; j < list2.length; j++){
	  var word1 = (list1[i].replace(/\W/g,''));
	  var word2 = (list2[j].replace(/\W/g,''));
	  var compound;
	  if (document.form1.hyphens.checked){
	    compound =  new Array(word1 + word2,
				  word1 + '-' + word2,
				  word2 + word1,
				  word2 + '-' + word1);
	  } else {
	    compound =  new Array(word1 + word2, word2 + word1);
	  } // end: if
	  for (k = 0; k < compound.length; k++){
	    checkDomain(compound[k]+"."+ext);
	    if (document.form1.plurals.checked)
	      checkDomain(compound[k]+"s."+ext);
	  } // end: for
	} // end: for
      } // end: for
    } // end: if
  } // end: for

} // end: checkDomains

// break str into a list of entries where each entry is separated 
// by whitespace or ",".
function getList(str)
{
  str = str.replace(/\s+/g,','); // convert whitespace to commas
  str = str.replace(/\,+/g,','); // reduce multiple commas to single commas
  str = str.replace(/^\,+/,''); // remove preceeding commas
  str = str.replace(/\,+$/,''); // remove trailing commas
  return str.split(',');
} // end: getList
  

function checkDomain(domain)
{

  results.innerHTML = "<br>here comes the list...<br><br>";
  getServerRequest('php/whois.php','domain='+escape(domain), true, checkDomainAction, domain);
} // end: getImageSrc

function checkDomainAction (responseText, domain)
{
  //alert(responseText);
  //document.form1.results.value += domain + " : " + responseText + "\n";
  var results = document.getElementById('results');
 
  if ((document.form1.show.value == "all") ||
      (document.form1.show.value == responseText)){
    var linkHtml = (responseText == 'avail') ? "<a class='availability avail' href='"+NAMESPRO_URL+ domain +"'>" : "";
    var linkText = (responseText == 'avail') ? "available - click here to register" : "taken";
    results.innerHTML +=  domain + " : <span class='availability "+responseText+"'>"+linkHtml + linkText + "</a></span><br>\n";
  } // end: if
} // end: checkDomainAction

