// AJAX INIT
function $$$(id) {
	return document.getElementById(id);
}
function khoitao_ajax()
{
	var x;
	try 
	{
		x	=	new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
    	try 
		{
			x	=	new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(f) { x	=	null; }
  	}
	if	((!x)&&(typeof XMLHttpRequest!="undefined"))
	{
		x=new XMLHttpRequest();
  	}
	return  x;
}
function	Forward(url)
{
	window.location.href = url;
}
function	_postback()
{
	return void(1);
}

function dat_phong(frm)
{
	if (frm.txt_ten.value == '')
	{
		 alert('Bạn chưa nhập họ & tên.');
		 frm.txt_ten.focus();
		 return false;
	}
	if (frm.txt_don_vi.value == '')
	{
		 alert('Bạn chưa nhập đơn vị.');
		 frm.txt_don_vi.focus();
		 return false;
	}
	if (frm.txt_tel.value == '')
	{
		 alert('Bạn chưa nhập điện thoại.');
		 frm.txt_tel.focus();
		 return false;
	}
	email=frm.txt_email.value;
	if (!email.match(/^([-\d\w][-.\d\w]*)?[-\d\w]@([-\w\d]+\.)+[a-zA-Z]{2,6}$/))
	{
		alert('Địa chỉ email không hợp lệ.');
		frm.txt_email.focus();
		return false;
	}

	if (frm.txt_noi_dung.value == '')
	{
		alert('Bạn chưa nhập Nội dung.');
		frm.txt_noi_dung.focus();
		return false;
	}
	
	txt_ten			=	encodeURIComponent(frm.txt_ten.value);
	txt_don_vi		=	encodeURIComponent(frm.txt_don_vi.value);
	txt_quoc_gia	=	encodeURIComponent(frm.txt_quoc_gia.value);
	txt_tel			=	encodeURIComponent(frm.txt_tel.value);
	txt_email		=	encodeURIComponent(frm.txt_email.value);
	
	txt_ngay_den	=	encodeURIComponent(frm.txt_ngay_den.value);
	txt_ngay_di		=	encodeURIComponent(frm.txt_ngay_di.value);
	
	txt_so_phong	=	encodeURIComponent(frm.txt_so_phong.value);
	txt_so_khach	=	encodeURIComponent(frm.txt_so_khach.value);
	
	txt_noi_dung	=	encodeURIComponent(frm.txt_noi_dung.value);
	
	var	query	=	"txt_ten="+txt_ten+"&txt_don_vi="+txt_don_vi+"&txt_quoc_gia="+txt_quoc_gia+"&txt_tel="+txt_tel+"&txt_email="+txt_email+"&txt_ngay_den="+txt_ngay_den+"&txt_ngay_di="+txt_ngay_di+"&txt_noi_dung="+txt_noi_dung+"&txt_so_phong="+txt_so_phong+"&txt_so_khach="+txt_so_khach;
	var http 	=	khoitao_ajax();
	try
	{
		http.open("POST", "/dat_phong.php");
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Cache-control", "no-cache");		
    	http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
				if (http.status == 200)
				{
					x = http.responseText;
					if (x != "OK")
					{
						alert(x);
					}
					else
					{
						alert("Đã thực hiện đặt phòng Thành công.");
						$$$('frm_booking').innerHTML = $$$('frm_booking').innerHTML;
					}
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}