// 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 ajax_newsletter(frm)
{
	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;
	}
	
	var	query	=	"txt_email="+email;
	var http 	=	khoitao_ajax();
	try
	{
		http.open("POST", "/email_reg.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êm email của bạn vào Hệ thống thành công.");
						// $$$('frm_booking').innerHTML = $$$('frm_booking').innerHTML;
					}
				}
				else
				{
					alert('Có lỗi hệ thống. Xin vui lòng thử lại sau');
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}


