var HttPRequest = false;
function checkdomain(domainname,suffix) {

HttPRequest = false;

//if ((domainname.substring(0,1)=="-") || (domainname.substring(0,3)=="www") || (domainname=="") || (domainname=="."))
if ((domainname.substring(0,1)=="-") || (domainname=="") || (domainname=="."))
{
  alert("ขออภัยค่ะ ! การตั้งชื่อ Domain ไม่ควรใช้เครื่องหมาย -  เริ่มต้นหรือลงท้ายของชื่อ \nและเครื่องหมายเว้นวรรค หรือ . ในชื่อค่ะ     \nกรุณาตรวจสอบใหม่นะคะ");
  return false;
}

if (window.XMLHttpRequest) { // Mozilla, Safari,...

HttPRequest = new XMLHttpRequest();

if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
} 

if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}


var myhostname="http://"+window.location.hostname;

//
if (suffix == "in.th" || suffix == "co.th" || suffix == "ac.th" || suffix == "or.th" || suffix == "net.th" || suffix == "go.th" || suffix == "mi.th")
{
var url = myhostname+"/v3/check-domain-th.php";
}
else
{
var url = myhostname+"/v3/check-domain.php";
}
//

var pmeters = "domainname="+domainname+"&suffix="+suffix;

HttPRequest.open("POST",url,true);

HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);

HttPRequest.onreadystatechange = function()
{


if(HttPRequest.readyState == 1) // Loading Request
{
  document.getElementById("domainstatus").innerHTML = "<img src='images/loading.gif' align='absmiddle'>";
}

if(HttPRequest.readyState == 2) // Loading Request
{
  document.getElementById("domainstatus").innerHTML = "<img src='images/loading.gif' align='absmiddle'>";
}

if(HttPRequest.readyState == 3) // Loading Request
{
  document.getElementById("domainstatus").innerHTML = "<img src='images/loading.gif' align='absmiddle'>";
}

if(HttPRequest.readyState == 4) // Return Request
{
  //document.getElementById("domainstatus").innerHTML =HttPRequest.responseText;
	if(HttPRequest.responseText == 'Yes') 
	{ 
		document.getElementById("domainstatus").innerHTML = "<span style='padding:0 0 0 5px;color:#339900'> ยินดีด้วยค่ะ "+domainname+"."+suffix+" ชื่อนี้ยังว่างค่ะ</span>";
		document.getElementById("notavailable").style.display = 'none'; 
		document.getElementById("available").style.display = 'block'; 
		document.getElementById("notavailable").style.visibility = 'hidden';
		document.getElementById("available").style.visibility = 'visible';
	} 
	else 
	{ 
		document.getElementById("domainstatus").innerHTML = "<span style='padding:0 0 0 5px;color:#FF0000'> ขออภัยค่ะ "+domainname+"."+suffix+" ชื่อนี้ไม่ว่างค่ะ</span>"; 
		document.getElementById("notavailable").style.display = 'block'; 
		document.getElementById("available").style.display = 'none';
		document.getElementById("notavailable").style.visibility = 'visible';
		document.getElementById("available").style.visibility = 'hidden';
	} 
}

}

/*
HttPRequest.onreadystatechange = call function .... // Call other function
*/

}



