// 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);
}
//BOOK HOTEL - TUAN ANH
function book_hotel(frm)
{
	txt_name 			= frm.txt_name.value
    txt_tel 			= frm.txt_tel.value
	txt_address 		= frm.txt_address.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_tel){
		 alert('Vui lòng nhập số điện thoại.');
		 frm.txt_tel.focus();
		 return false;
		}    
	if (!txt_address){
		alert('Vui lòng nhập địa chỉ.');
		frm.txt_address.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_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_tel=" 					+	txt_tel	+
						"&txt_address="					+	txt_address	+
						"&txt_date_in="					+	txt_date_in	+
						"&txt_date_out="				+	txt_date_out	+
						"&txt_loai_phong="				+	txt_loai_phong	+
						"&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("GET", "/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;
	}
}
/* END */

/*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 
$(function(){
Cufon.replace(' ul.languages li a, ul.menu_ngang li a', {fontFamily:'HP-Avo', hover: {color: '-linear-gradient(#fff, #fff)'},outline :'none'});
Cufon.replace('h1.title, a.more_home2', {fontFamily:'Amazone', hover: {color: '-linear-gradient(#109bbf, #109bbf)'},outline :'none'});

});
//đã được load hoàn tất. 
jQuery(window).load(function(){ 
 
    EqualHeight(jQuery(".container .body .left, .container .body .right")); 
    //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(".container .body .left, .container .body .right"));
    });
	
	//if (document.getElementById("global_act").value == "home")
//	{
//	$(".tgp_wrapper_bottom").css({'background':'url(/images/wrapper_bottom_2.gif) repeat-x left 490px'});
//	$(".tgp_container .tgp_body .tgp_right .tgp_content").css({'background':'none'});
//	}
});


//


$(document).ready(function()
{
    /* begin popup */
    var id = '#dialog';
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo("slow",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
          
	//Set the popup window to center
	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);

	//transition effect
	$(id).fadeIn(2000); 	
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});		
    /* end */
    
    $(".doi_tac").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		auto: true,
		speed: 300, // Toc do chay hinh
		auto: 5000,// Thoi gian chay hinh
		visible: 2
	});
    
    // begin fancy images
	$("a[rel=example_group]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	//end fancy
});

