function fn_check_domain_header() {
	var frm_checkdomain=document.getElementById('frm_checkdomain');
	var txt_domainname=document.getElementById('txt_domainname');
	var lis_topdomain=document.getElementById('lis_topdomain');
	var div_alert_progress=document.getElementById('div_alert_progress_check_domain');
	
	if (txt_domainname.value=="")
	{
		alert("กรุณากรอกชื่อโดเมน !");
		txt_domainname.focus();
	}
	else
	{
		frm_checkdomain.style.display="none";
		div_alert_progress.innerHTML="<img src=\"images/progressbar.gif\" />";
		div_alert_progress.style.display="";
		
		m_ajax.create();
		m_ajax.url = "fn.check_domain.php";
		m_ajax.method = "post";
		m_ajax.addParam("str_domain", txt_domainname.value);
		m_ajax.addParam("str_dot_domain", lis_topdomain.options[lis_topdomain.selectedIndex].value);
		m_ajax.function_name = "fn_result_check_domain_header()";
		m_ajax.send();
	}
}

function fn_result_check_domain_header()
{
	var frm_checkdomain=document.getElementById('frm_checkdomain');
	var txt_domainname=document.getElementById('txt_domainname');
	var lis_topdomain=document.getElementById('lis_topdomain');
	var div_alert_progress=document.getElementById('div_alert_progress_check_domain');
	
	var int_result_check_domain=1*m_ajax.responseText;
	
	switch (int_result_check_domain)
	{
		case 0:
			alert("ข้อมูลกรอกไม่ครบ");
			frm_checkdomain.style.display="";
			div_alert_progress.innerHTML="";
			div_alert_progress.style.display="none";
			break;
		case 1:
			alert("โดเมน "+txt_domainname.value+lis_topdomain.options[lis_topdomain.selectedIndex].value+" นี้สามารถจดได้");
			div_alert_progress.innerHTML="<input type=\"button\" value=\"จดโดเมน "+txt_domainname.value+lis_topdomain.options[lis_topdomain.selectedIndex].value+" \" onclick=\"javascript:fn_check_agree();\" />&nbsp;<input type=\"button\" value=\"ลองอีกครั้ง\" onclick=\"javascript:fn_check_again();\" />";
			break;
		case 2:
			alert("โดเมน "+txt_domainname.value+lis_topdomain.options[lis_topdomain.selectedIndex].value+" นี้ไม่สามารถจดได้ เนื่องจากมีเจ้าของแล้ว");
			frm_checkdomain.style.display="";
			div_alert_progress.innerHTML="";
			div_alert_progress.style.display="none";
			break;
		case 3:
			alert("ไม่สามารถค้นหาข้อมูลได้ กรุณาลองใหม่อีกครั้ง");
			frm_checkdomain.style.display="";
			div_alert_progress.innerHTML="";
			div_alert_progress.style.display="none";
			break;
		case 4:
			alert("โดเมนที่ใช้ตรวจสอบไม่ถูกต้อง");
			frm_checkdomain.style.display="";
			div_alert_progress.innerHTML="";
			div_alert_progress.style.display="none";
			break;
	}
}

function fn_check_again()
{
	var frm_checkdomain=document.getElementById('frm_checkdomain');
	var txt_domainname=document.getElementById('txt_domainname');
	var lis_topdomain=document.getElementById('lis_topdomain');
	var div_alert_progress=document.getElementById('div_alert_progress_check_domain');
	
	div_alert_progress.innerHTML="";
	div_alert_progress.style.display="none";
	
	frm_checkdomain.style.display="";
	txt_domainname.focus();
}

function fn_check_agree()
{
	var txt_domainname=document.getElementById('txt_domainname');
	var lis_topdomain=document.getElementById('lis_topdomain');
	
	window.location="domain_buy.php?d="+txt_domainname.value+"&l="+lis_topdomain.selectedIndex;
}