// 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;
}
$.extend({
  ajaxIt : function(query, lnk, callbackFnk){    
	var http 	=	khoitao_ajax();
	try
	{
	  http.open("POST", lnk);
	  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)
			  {
				  $(".jGrowl-notification .jGrowl-message").each(function(i,e){
						if ($(this).text() == "Processing...")
						{
							$(this).parent().hide();
						}
					});
				  // Callback
				  if(typeof callbackFnk == 'function'){
					  x = http.responseText;
					  callbackFnk.call(this, x);
				  }
				  //---------
			   }
				else
				{
					alert('Có lỗi hệ thống. Xin vui lòng thử lại sau');
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
  }
});
function	Forward(url)
{
	window.location.href = url;
}
function	_postback()
{
	return void(1);
}

jQuery(window).load(function(){ 
	Cufon.replace('.cufon', {fontFamily:'utm',hover:true});
});

function send_contact(contactfrm)
{
	
	$$$("notify").innerHTML = '<img src="/images/ajax-loader.gif" align="absmiddle" border="0" /> Thông tin của bạn đang được gởi đi.';
	
	var ten = contactfrm.txt_ten.value;
	
	var email = contactfrm.txt_email.value;
	
	var tieu_de = contactfrm.txt_tieu_de.value;
	
	var noi_dung = contactfrm.txt_noi_dung.value;
	
	if (!ten || ten.length < 8)
	{
		document.contactfrm.txt_ten.focus();
		$$$("notify").innerHTML = '<span style="color:#C00">Tên từ 8 ký tự trở lên</span> !';
		return false;
	}
	
	else if (!email.match(/^([-\d\w][-.\d\w]*)?[-\d\w]@([-\w\d]+\.)+[a-zA-Z]{2,6}$/))
	{
		document.contactfrm.txt_email.focus();
		$$$("notify").innerHTML = '<span style="color:#C00">Email không đúng</span> !';
		return false;
	}	
	else if (!tieu_de || tieu_de.length < 8)
	{
		document.contactfrm.txt_tieu_de.focus();
		$$$("notify").innerHTML = '<span style="color:#C00">Tiêu đề quá ngắn</span> !';
		return false;
	}	
	else if (!noi_dung || noi_dung.length < 16)
	{
		document.contactfrm.txt_noi_dung.focus();
		$$$("notify").innerHTML = '<span style="color:#C00">Nội dung quá ngắn</span> !';
		return false;
	}		
	else
	{
	}

	var	query	=	"act=contact&txt_ten="+ten+"&txt_tieu_de="+tieu_de+"&txt_noi_dung="+noi_dung+"&txt_email="+email;
	var http 	=	khoitao_ajax();
	try
	{
		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)
				{
					x = http.responseText;
					if (x != "OK")
					{
						$$$("notify").innerHTML = '<span style="color:#C00">'+x+'</span> !';
					}
					else
					{
						$$$("notify").innerHTML = '<span style="color:#C00">Thông tin của bạn đã được gửi đi</span> !';
					}
				}
				else
				{
					$$$("notify").innerHTML = '<span style="color:#C00">Có lỗi hệ thống. Xin vui lòng thử lại sau</span> !';
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
		$$$("notify").innerHTML = '<span style="color:#C00">Đang có lỗi hệ thống!</span><br>Vui lòng thử lại sau !';
	}
	return false;
	
}

function calculHeight()
{
	var leftHeight = $(".body_left").height();
	var rightHeight = $(".body_right").outerHeight();
	var doitacHeight = $(".doi_tac").height();
	var maxHeight = leftHeight;
	if (maxHeight < rightHeight)
		maxHeight = rightHeight;
	
	$(".body_left").css('height',maxHeight);
	$(".body_right").css('height',maxHeight);
	
	$(".body_content").css('height',maxHeight-doitacHeight);
	$(".menu_right").css('height',maxHeight-doitacHeight);
	
}

$(window).load(function()
{
	calculHeight();
});


$(document).ready(function()
{
	$(".slide_doi_tac").jcarousel({
		auto: 3,
        scroll: 3,
		wrap: 'circular',
		animation: 500,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	
	$("#sbo_san_bay_from").live('change',function()
	{
		var query = 'act=load_sbo&type=from&ma='+$(this).val();
		$.ajaxIt(query,'/action.php',function(x)
		{
			$("#sbo_san_bay_to").html(x);
		});
	});
	
	$(".menu_item").hover(function()
	{
		
	},function()
	{
		Cufon.replace('.cufon', {fontFamily:'utm',hover:true});
	});
	
	$("a#inline").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
});



var $container;
		
$(document).ready(	
	function() {
		$container = $("#container");
		$container.wtRotator({
			width:720,
			height:251,
			border:"none",
			button_width:73,
			button_height:68,
			button_margin:0,
			auto_start:true,
			delay:5000,
			transition:"random",
			transition_speed:800,
			block_size:100,
			vert_size:50,
			horz_size:50,
			display_thumbs:false,
			display_dbuttons:false,
			display_playbutton:false,
			display_tooltip:false,
			display_numbers:false,
			cpanel_mouseover:false,
			text_mouseover:false
		});
	}
);

var dem = 0;
function lich_bay_close()
{
	dem ++;
	$(".lich_bay_table").toggle();
	if (dem % 2 == 1)
		$(".btn_lich_bay_close").val("Mở");
	else
		$(".btn_lich_bay_close").val("Đóng");
}
