// 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);
}
//cuongnt - dat phong
function book_hotel(frm)
{
	txt_name 			= frm.txt_name.value
	txt_address 		= frm.txt_address.value
	txt_tel 			= frm.txt_tel.value
	txt_date_in 		= frm.txt_date_in.value
	txt_date_out 		= frm.txt_date_out.value
	txt_loai_phong 		= frm.txt_loai_phong.value
	txt_loai_giuong 	= frm.txt_loai_giuong.value
	txt_so_nguoi 		= frm.txt_so_nguoi.value
	txt_so_phong 		= frm.txt_so_phong.value
	txt_email 			= frm.txt_email.value
	if (!txt_name){
		 alert('Vui lòng nhập họ tên.');
		 frm.txt_name.focus();
		 return false;
		}
	if (!txt_address){
		alert('Vui lòng nhập địa chỉ.');
		frm.txt_address.focus();
		return false;
	}
	if (!txt_tel){
		alert('Vui lòng nhập số điện thoại.');
		frm.txt_tel.focus();
		return false;
	}
	if (!txt_date_in){
		 alert('Vui lòng nhập ngày đến.');
		 frm.txt_date_in.focus();
		 return false;
		}
	if (!txt_date_out){
		alert('Vui lòng nhập ngày đi.');
		frm.txt_date_out.focus();
		return false;
	}
	var date = new Date();
	var month = date.getMonth() + 1;
	month = (month < 10)? "0" + month : ""+ month;
	
	var day = date.getDate();
	day = (day < 10)? "0" + day : ""+ day;
	
	var year = date.getFullYear();
	var today = year + "-" + month + "-" + day;

	if (txt_date_in > txt_date_out || txt_date_in < today)
	{
		alert('Vui lòng kiểm tra ngày đến và ngày đi !');
		return false;
	}
	 if (!txt_loai_phong){
		alert('Vui lòng chọn loại phòng.');
		frm.txt_loai_phong.focus();
		return false;
	 }
	 if(txt_loai_phong == "Stardard Room")
	 {
		 if(txt_so_phong > 25)
		 {
			 alert('Vui lòng chọn lại số phòng.Stardard Room tối đa là 25 phòng.');
			frm.txt_so_phong.focus();
			return false;
		 }
	 }
	 if(txt_loai_phong == "Superior Room")
	 {
		 if(txt_so_phong > 5)
		 {
			 alert('Vui lòng chọn lại số phòng.Superior Room tối đa là 5 phòng.');
			frm.txt_so_phong.focus();
			return false;
		 }
	 }
	 /*if(txt_loai_phong == "Louis Suite Room")
	 {
		 if(txt_so_phong > 5)
		 {
			 alert('Vui lòng chọn lại số phòng.Louis Suite Room tối đa là 5 phòng.');
			frm.txt_so_phong.focus();
			return false;
		 }
	 }*/
	 if (!txt_loai_giuong){
		alert('Vui lòng chọn loại giường.');
		frm.txt_loai_giuong.focus();
		return false;
	 }
	 if (!txt_so_phong){
		alert('Vui lòng chọn số phòng.');
		frm.txt_so_phong.focus();
		return false;
	 }
	 if (!txt_so_nguoi){
		alert('Vui lòng chọn số người.');
		frm.txt_so_nguoi.focus();
		return false;
	 }
	 email=txt_email
	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;
	}
	
	 else
	 {
		var	query	=	"act=book_hotel&txt_name="		+	txt_name	+
						"&txt_address="					+	txt_address	+
						"&txt_tel="						+	txt_tel	+
						"&txt_date_in="					+	txt_date_in	+
						"&txt_date_out="				+	txt_date_out	+
						"&txt_loai_phong="				+	txt_loai_phong	+
						"&txt_loai_giuong="				+	txt_loai_giuong	+
						"&txt_so_nguoi="				+	txt_so_nguoi+
						"&txt_so_phong="				+	txt_so_phong+
						"&txt_email="					+	txt_email;
		var http 	=	khoitao_ajax();
		try
		{
			//$$$('loading').innerHTML = '<img src="/images/ajax-loader.gif" alt="Loading..." align="middle" />';
			http.open("POST", "/action.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)
					{
						alert("Đã thực hiện đặt phò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;
	}
}
/*So sanh height cua 2 the div tgp_body_content & tgp_right*/
function EqualHeight(elements) { 
    //Xác định chiều cao của cột cao nhất 
    tallest = 0; 
    elements.each(function() { 
        elementHeight = jQuery(this).height(); 
        if(elementHeight > tallest) { 
            tallest = elementHeight; 
        } 
    }); 
    //Chỉnh chiều cao cho tất cả các cột 
    //theo chiều cao của cột cao nhất 
    elements.height(tallest); 
} 
//Áp đặt chiều cao cho các cột khi trang 
//đã được load hoàn tất. 
$(document).ready(function()
{
	$(function(){
		Cufon.replace('.tgp_container .tgp_right .r_menu ul li a', {hover: {color: '#F90'},outline :'none'});
		Cufon.replace('.tgp_container .tgp_body .b_content .intro .left .title,.tgp_container .tgp_body .b_top .box_left,.gioi_thieu .title', {fontFamily:'HP-Garam',color: '-linear-gradient(#F90, #F90)'});  
		Cufon.replace('.tgp_container .tgp_right .r_menu ul li a  ', {fontFamily:'HP-Garam',color: '-linear-gradient(#FFFFFF, #FFFFFF)'});  
	});
	
	$('#photo_1').show().galleryView({
		filmstrip_size: 4,
		panel_width: 564,
		panel_height: 140,
		frame_width: 136,
		frame_height: 96,
		background_color: '',
		wrapper_width: 600,
		nav_theme: 'dark',
		border: 'none',
		show_captions:false,
		caption_text_color: 'black'
	});

});
jQuery(window).load(function(){ 
	
	

   // EqualHeight(jQuery(".tgp_container .tgp_body .b_footer,.tgp_container .tgp_right .space")); 
 
    //Tự động điều chỉnh lại chiều cao sau khi 
    //resize browser. Nếu không quan tâm đến việc 
    //resize browser, bạn có thể gỡ bỏ hàm này 
    jQuery(window).resize(function(){ 
       // EqualHeight(jQuery(".tgp_container .tgp_body .b_footer,.tgp_container .tgp_right .space")); 
    }); 
}); 
