	var ext_arr=new Array("com","net","org");
	var domain_object_arr=new Array();

	function index_checkdomain_init()
	{
		document.checkdomain_form.domain.focus();

		image_arr=new Array("checking.gif","checking_dot.gif","available.gif","unavailable.gif");
		//preloadImages(document.checkdomain_form.this_path.value,image_arr);
	}

	function domain_object(domain,ext,index)
	{
		this.domain=domain;
		this.ext=ext;
		this.state="checking";

		this.index=index;

		this.change_state=change_state;

		this.httpRequest=false;
		this.makeHttpRequest=add_domain_object;

		this.makeHttpRequest();

		setTimeout("domain_object_arr["+index+"].change_state('checking_dot')",600);
	}

	function change_state(state)
	{
		if(this.state!="delete")
		{
			this.state=state;
			show_domain_object();
		}
	}

	function add_domain_object()
	{
		var index=this.index;
		var now=new Date();

		if(window.XMLHttpRequest)
			this.httpRequest=new XMLHttpRequest();
		else if(window.ActiveXObject)
			this.httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
		this.httpRequest.onreadystatechange=function ()
		{
			if(index<domain_object_arr.length)
				if(domain_object_arr[index].httpRequest.readyState==4)
					if(domain_object_arr[index].httpRequest.status==200)
					{
						/*if(domain_object_arr[index].httpRequest.responseText=="1")
						{
							domain_object_arr[index].change_state("available");
						}
						else
						{
							domain_object_arr[index].change_state("unavailable");
						}*/
						if(domain_object_arr[index].httpRequest.responseText!="0")
						{
							domain_object_arr[index].change_state("available");
						}
						else
						{
							domain_object_arr[index].change_state("unavailable");
						}
					}
		}

		this.httpRequest.open('GET',"checkdomain.php?time="+now.getTime()+"&domain="+this.domain+"&ext="+this.ext,true);
		this.httpRequest.send(null);
	}

	function show_domain_object()
	{
		var i;
		for(i=0;i<domain_object_arr.length;i++)
			if(domain_object_arr[i].state!="delete")
				break;
		if(i==domain_object_arr.length)
		{
			document.getElementById("index_checkdomain_result_table").innerHTML="";
			return;
		}

		var html="";

		html+="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

		for(i=0;i<domain_object_arr.length;i++)
		{
			if(domain_object_arr[i].state!="delete")
			{
				html+="<tr>";
				html+="	<td>";
				html+="		<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"font_header_column\">";
				html+="		<tr>";
				html+="			<td height=\"25\" valign=\"bottom\">";
				if(domain_object_arr[i].state=="unavailable")
					html+="<a href=\"http://"+domain_object_arr[i].domain+"."+domain_object_arr[i].ext+"/\" target=\"_blank\" class=\"menu\" onmouseover=\"window.status='http://"+domain_object_arr[i].domain+"."+domain_object_arr[i].ext+"/';return true;\" onmouseout=\"window.status=' ';return true;\">"+domain_object_arr[i].domain+"."+domain_object_arr[i].ext+"</a>";
				else if(domain_object_arr[i].state=="available")
					html+="<a href=\"choose-plan.php?domain="+domain_object_arr[i].domain+"&ext="+domain_object_arr[i].ext+"\" class=\"green\" onmouseover=\"window.status='จดโดเมน "+domain_object_arr[i].domain+"."+domain_object_arr[i].ext+"';return true;\" onmouseout=\"window.status=' ';return true;\" class=\"index_checkdomain_output_order_style\">"+domain_object_arr[i].domain+"."+domain_object_arr[i].ext+"</a>";
				else html+=domain_object_arr[i].domain+"."+domain_object_arr[i].ext;
				html+="			</td>";
				html+="		</tr>";
				html+="		</table>";
				html+="	</td>";

				html+="	<td valign=\"bottom\"><img src=\""+document.checkdomain_form.this_path.value+"images/"+domain_object_arr[i].state+".gif\" border=\"0\"></td>";

				html+="	<td valign=\"bottom\">";
				html+="		<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
				html+="		<tr>";
				html+="			<td valign=\"bottom\">";
				if(domain_object_arr[i].state=="available")
					html+="<a href=\"choose-plan.php?domain="+domain_object_arr[i].domain+"&ext="+domain_object_arr[i].ext+"\" class=\"green\" onmouseover=\"window.status='จดโดเมน "+domain_object_arr[i].domain+"."+domain_object_arr[i].ext+"';return true;\" onmouseout=\"window.status=' ';return true;\" class=\"index_checkdomain_output_order_style\">เลือกโดเมนนี้</a>";
				else if(domain_object_arr[i].state=="unavailable")
					html+="<font class=\"font_header\">โดเมนนี้ถูกจดไปแล้ว</font>";
				html+="			</td>";
				html+="			<td valign=\"bottom\"></td>";
				html+="		</tr>";
				html+="		</table>";
				html+="	</td>";
				html+="</tr>";
			}
		}

		html+="</table>";

		document.getElementById("index_checkdomain_result_table").innerHTML=html;
	}

	function index_checkdomain_checkdomain_click()
	{
		if(document.checkdomain_form.domain.value.length==0)
		{
			alert("กรุณากรอก domain name")
			return
		}

		if(document.checkdomain_form.domain.value.length<2)
		{
			alert("domain name ต้องมีความยาวอย่างน้อย 2 อักษร")
			return
		}

		if(document.checkdomain_form.domain.value.length>63)
		{
			alert("domain name ต้องมีความยาวอย่างมาก 63 อักษร")
			return
		}

		var i=0
		for(i=0;i<document.checkdomain_form.domain.value.length;i++)
		{
			if(document.checkdomain_form.domain.value.substring(i,i+1)<'A'||document.checkdomain_form.domain.value.substring(i,i+1)>'Z')
				if(document.checkdomain_form.domain.value.substring(i,i+1)<'a'||document.checkdomain_form.domain.value.substring(i,i+1)>'z')
					if(document.checkdomain_form.domain.value.substring(i,i+1)<'0'||document.checkdomain_form.domain.value.substring(i,i+1)>'9')
						if(document.checkdomain_form.domain.value.substring(i,i+1)!='-')
						{
							alert("domain name ต้องเป็นตัวเลข ตัวอักษรภาษาอังกฤษ หรือ เครื่องหมาย - เท่านั้น")
							return
						}
		}

		if(document.checkdomain_form.domain.value.substring(0,1)=='-')
		{
			alert("domain name ห้ามขึ้นต้นด้วยเครื่องหมาย -")
			return
		}

		if(document.checkdomain_form.domain.value.substring(document.checkdomain_form.domain.value.length-1,document.checkdomain_form.domain.value.length)=='-')
		{
			alert("domain name ห้ามลงท้ายด้วยเครื่องหมาย -")
			return
		}

		var i;
		for(i=0;i<domain_object_arr.length;i++)
			if(domain_object_arr[i].state!="delete")
				domain_object_arr[i].change_state("delete");

		for(i=0;i<ext_arr.length;i++)
		{
			domain_object_arr.push(new domain_object(document.checkdomain_form.domain.value,ext_arr[i],domain_object_arr.length));
			show_domain_object();
		}
	}
