// Standard DOCStudio AJAX script
function DOCStudioSharedAjaxFunction(geturl,posturl,poststr,on_success,on_fail) {
	var xmlHttp;
	try {	xmlHttp=new XMLHttpRequest(); }// Firefox, Opera 8.0+, Safari
	catch (e) {
		try	{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } // Internet Explorer
		catch (e) {
			try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) {
				on_fail("Your browser does not support AJAX.");
				}
			}
		}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if (xmlHttp.responseText) { on_success(xmlHttp.responseText); }
			}
		}

if (posturl != '' && poststr != '') {
	xmlHttp.open('POST', posturl, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", poststr.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
	} else {
	xmlHttp.open("GET",geturl,true);
	xmlHttp.send(null);
	}

}






function whois_ajax(theform,thediv) {
	// set up the ajax submit
	var geturl = '';
	var posturl = '/wp-content/themes/tglo/whois_lookup.php';
	var poststr = "feedback_mode=ajax";
	for (var i=0;i<theform.elements.length;i++) {
		if (theform.elements[i].type == 'checkbox' || theform.elements[i].type == 'radio') {
			if (theform.elements[i].checked) {
				poststr = poststr + "&" + theform.elements[i].name + "=" + encodeURIComponent( theform.elements[i].value );
				}
			} else {
			poststr = poststr + "&" + theform.elements[i].name + "=" + encodeURIComponent( theform.elements[i].value );
			}
		}

	// clear any results
	var selectDiv = document.getElementById(thediv);
	selectDiv.innerHTML = "Checking availability...";

	// send to ajax:
	// get url, post url, post string, function upon success, function upon fail
	DOCStudioSharedAjaxFunction(
		geturl,
		posturl,
		poststr,
		function(aresponse) {
			var whois_response=aresponse.split("|");
			if (whois_response[0] == 'AVAILABLE') {
				selectDiv.innerHTML= "<span style=\"color:green;font-size:14px;line-height:18px;\">Congratulations! <b>" + whois_response[1] + "<\/b> is available!<\/span> <br \/><a href=\"http://www.authentication.travel/register.jsp?type=U&ap=trap\" style=\"color:green;font-weight:bold;font-size:14px;line-height:18px;\">Click here to authenticate and register your <b>.travel<\/b> name!<\/a>";
				} else if (whois_response[0] == 'ERROR') {
				selectDiv.innerHTML= "You did not enter a valid domain name. Please try again.";
				} else {
				selectDiv.innerHTML= "<span style=\"color:red;\">Sorry, the domain name <b>" + whois_response[1] + "<\/b> is already in use. Please try another.<\/span>";
				}
			},
		function(msg) {
			alert('Please try again.');
		})

}