// 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);
	
	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_ngay_den > txt_ngay_di || txt_ngay_den < today)
	{
		alert('Vui lòng kiểm tra ngày đến và ngày đi !');
		return false;
	}
	
	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);
	
	txt_loai_phong	=	encodeURIComponent(frm.txt_loai_phong.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_loai_phong="+txt_loai_phong+"&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;
					}
				}
				else
				{
					alert('Có lỗi hệ thống. Xin vui lòng thử lại sau');
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}
//Xu ly tabs menu
/*$(document).ready(function() {
	$('a.tab').click(function(){
		$('.active').removeClass('active');
		$(this).addClass('active');
		$('.content').slideUp();
		var content_show = $(this).attr('title');
		$('#'+ content_show).slideDown();
		
	});
});*/
$(document).ready(function() {
						   $("#select-wrapper").jqTransform();	
	$('a.tab_news').click(function(){
		$('.active').removeClass('active');
		$(this).addClass('active');
		$('.content_news').slideUp();
		var content_show = $(this).attr('title');
		$('#'+ content_show).slideDown();
		
	});
});
$(function(){
Cufon.replace('h1', {color:'-linear-gradient(#B6D8FE, #083C74)'});
Cufon.replace('h2', {color:'-linear-gradient(#B6D8FE, #083C74)'});
Cufon.replace('h3', {color:'-linear-gradient(#B6D8FE, #083C74)'});
});
$(window).load(function() {
					
	$('#slider').nivoSlider({
		effect:'random',
		slices:15,
		animSpeed:700,
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	$('#slider').data('nivo:vars').stop = true; //Stop the Slider
	$('#slider').data('nivo:vars').stop = false; //Start the Slider
});

