// 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);
}
/*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); 
}
// Kiểm tra IE
	function isIE()
	{
	  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	} 

jQuery(window).load(function(){ 
	
	Cufon.replace('.tgp_container .tgp_body .tgp_right ul li a ,.tgp_container .tgp_body .tgp_body_bottom .hot_line', {fontFamily:'HP-Helve', hover: {color: '#cf0101'}});
	Cufon.replace('.lavaLampWithImage li a', {fontFamily:'HP-Helve', hover: {color: '#cf0101'}});
	Cufon.replace('.title_tin_chi_tiet', {fontFamily:'HP-Helve', hover: {color: '#cf0101'}});
	
	//$('.lavaLampWithImage li.back').corner("cc:#3B80B7 8px");
	
});

$(document).ready(function()
{
	 
	$('#games').coinslider(
	{ 
		hoverPause: false ,
		spw: 4, 
		sph: 3 
	});	
	$('#pane1').jScrollPane();
	
	$("a[rel=contact]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '';
		}
		});	
		
		$("a[rel=example_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '';
		}
		});	
		
		
	
});

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 type = contactfrm.txt_type.value;
	var noi_dung = contactfrm.txt_noi_dung.value;
	
	if (!ten || ten.length < 8)
	{
		document.contactfrm.txt_ten.focus();
		$$$("notify_error").innerHTML = '<span style="color:#C00">Tên từ 8 ký tự trở lên</span> !';
		$$$("notify").innerHTML = '<span style="color:#C00">Đang có lỗi !';
		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_error").innerHTML = '<span style="color:#C00">Email không đúng</span> !';
		$$$("notify").innerHTML = '<span style="color:#C00">Đang có lỗi !';
		return false;
	}
	else if (type == 0)
	{
		$$$("notify_error").innerHTML = '<span style="color:#C00">tiêu đề quá ngắn</span> !';
		$$$("notify").innerHTML = '<span style="color:#C00">Đang có lỗi !';
		return false;
	}		
	else if (!tieu_de || tieu_de.length < 8)
	{
		document.contactfrm.txt_tieu_de.focus();
		$$$("notify_error").innerHTML = '<span style="color:#C00">tiêu đề quá ngắn</span> !';
		$$$("notify").innerHTML = '<span style="color:#C00">Đang có lỗi !';
		return false;
	}	
	else if (!noi_dung || noi_dung.length < 16)
	{
		document.contactfrm.txt_noi_dung.focus();
		$$$("notify_error").innerHTML = '<span style="color:#C00">Nội dung quá ngắn</span> !';
		$$$("notify").innerHTML = '<span style="color:#C00">Đang có lỗi !';
		return false;
	}		
	else
	{
	}

	var	query	=	"act=contact&txt_ten="+ten+"&txt_tieu_de="+tieu_de+"&txt_type="+type+"&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")
					{
						alert(x);
					}
					else
					{
						alert("Thông tin của bạn đã được gửi đi!")
					}
				}
				else
				{
					alert("Có lỗi hệ thống! vui lòng thử lại sau!")
				}
			}
		}
		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;
	
}

