// 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 tt_kh(id)
{
	var	query	=	"act=khach_hang&i="+id;
	var http 	=	khoitao_ajax();
	try
	{
		$$$('box_content').innerHTML = "<center style = 'padding-top:10px'><img src='/images/ajax-loader.gif' /></center>";
		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)
				{
					$$$('box_content').innerHTML = http.responseText;
				}
				else
				{
					alert('Co loi he thong. Vui long thu lai sau.');
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}

function send_mail(id)
{
	var so = id;
	var id_cms = document.getElementById("id_cms").value;
	var txt_name = document.getElementById("txtName_"+id).value;
	var txt_tel = document.getElementById("txtTel_"+id).value;
	var txt_email = document.getElementById("txtEmail_"+id).value;
	var txt_khai_giang = document.getElementById("khai_giang_"+id).value;
	var txt_thoi_luong = document.getElementById("thoi_luong_"+id).value;
	var txt_khoa = document.getElementById("khoa_"+id).value;
	var txt_lich_hoc = document.getElementById("lich_hoc_"+id).value;
	var txt_gio_hoc = document.getElementById("gio_hoc_"+id).value;
	var txt_dia_diem = document.getElementById("dia_diem_"+id).value;
	var txt_hoc_phi = document.getElementById("hoc_phi_"+id).value;	
	
	if(!txt_name)
	{
		alert("Vui lòng nhập họ tên !");
		frmContact.txt_name.focus();
		return false;
	}
	if(!txt_tel)
	{
		alert("Vui lòng nhập số điện thoại !");
		frmContact.txt_tel.focus();
		return false;
	}
	if(!txt_email)
	{
		alert("Vui lòng nhập email !");
		frmContact.txt_email.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ệ.');
		frmContact.txt_email.focus();
		return false;
	}
	else
	{
		
		
		var	query	=	"act=send_dk_khoa_hoc&txt_name="+txt_name+
											"&txt_tel="+txt_tel+
											"&txt_email="+txt_email+
											"&txt_khai_giang="+txt_khai_giang+
											"&txt_thoi_luong="+txt_thoi_luong+
											"&txt_khoa="+txt_khoa+
											"&txt_lich_hoc="+txt_lich_hoc+
											"&txt_gio_hoc="+txt_gio_hoc+
											"&txt_dia_diem="+txt_dia_diem+
											"&txt_hoc_phi="+txt_hoc_phi+
											"&id_cms="+id_cms;											
										
		var http 	=	khoitao_ajax();
		try
		{
			
			//$$$('inner').innerHTML = "<center style='margin-top:50px'><img src='/images/loading.gif' /></center>";
			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("Gởi mail thành công ! ");
							window.location.href = "/lich-hoc/the-gioi-phang.html";
							
						}
						else
						{
							alert(x);
							window.location.href = "/lich-hoc/the-gioi-phang.html";
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
		
	}
}

function send_res(frmContact)
{
	txtName = frmContact.txtName.value
	txtTel = frmContact.txtTel.value
	txtEmail = frmContact.txtEmail.value
	txtSubject=frmContact.txtSubject.value
	txtkhaigiang=frmContact.txtkhaigiang.value
	txtthoiluong=frmContact.txtthoiluong.value
	txtkhoa=frmContact.txtkhoa.value
	txtlichhoc=frmContact.txtlichhoc.value
	txtgiohoc=frmContact.txtgiohoc.value
	txtdiadiem=frmContact.txtdiadiem.value
	if(!txtName)
	{
		alert("Vui lòng nhập họ tên !");
		frmContact.txtName.focus();
		return false;
	}
	if(!txtTel)
	{
		alert("Vui lòng nhập số điện thoại !");
		frmContact.txtTel.focus();
		return false;
	}
	if(!txtEmail)
	{
		alert("Vui lòng nhập email !");
		frmContact.txtEmail.focus();
		return false;
	}
	email=txtEmail
	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ệ.');
		frmContact.txtEmail.focus();
		return false;
	}
	else
	{
		var	query	=	"act=send_res&txtName="+txtName+"&txtTel="+txtTel+"&txtEmail="+txtEmail+"&txtSubject="+txtSubject+"&txtkhaigiang="+txtkhaigiang+"&txtthoiluong="+txtthoiluong+"&txtkhoa="+txtkhoa+"&txtlichhoc="+txtlichhoc+"&txtgiohoc="+txtgiohoc+"&txtdiadiem="+txtdiadiem;
		var http 	=	khoitao_ajax();
		try
		{
			//$$$('inner').innerHTML = "<center style='margin-top:50px'><img src='/images/loading.gif' /></center>";
			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("Gởi mail thành công ! ");
							window.location.href = "/lich-hoc/the-gioi-phang.html";
							
						}
						else
						{
							alert(x);
							window.location.href = "/";
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}


function	Forward(url)
{
	window.location.href = url;
}
function	_postback()
{
	return void(1);
}
//Menu xo xuong
var timeout         = 100;
var closetimer		= 0;
var ddmenuitem      = 0;
jQuery(window).load(function(){ 
/*function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('.jsddm > li').bind('mouseover', jsddm_open);
	$('.jsddm > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;*/
	Cufon.replace('h1.right_title', {fontFamily:'TTF',color:'-linear-gradient(#616161, #616161)'});
	Cufon.replace('h1.page_title', {fontFamily:'TTF',color:'-linear-gradient(#616161, #616161)'});
}); 
$(document).ready(function() { 
	$('.tgp_container .tgp_slider .tgp_bottom_menu .jsddm li ul').superfish(); 
	$('.tgp_container .tgp_bottom_menu .jsddm').superfish(); 
});
$(document).ready(function()
{
/*So sanh height cua 2 the div tgp_left_content & tgp_right_content*/
function EqualHeight(elements) { 
    tallest = 0; 
    elements.each(function() { 
        elementHeight = jQuery(this).height(); 
        if(elementHeight > tallest) { 
            tallest = elementHeight; 
        } 
    }); 
    elements.height(tallest); 
} 
jQuery(window).load(function(){ 
    EqualHeight(jQuery(".left_content, .right_content")); 
    jQuery(window).resize(function(){ 
        EqualHeight(jQuery(".left_content, .right_content")); 
    }); 
});
});
jQuery(window).load(function(){ 
$("#waterwheelCarousel").waterwheelCarousel("horizontal",{
startingItem: 9

});
$("#txt_dt_time").datepicker( {"dateFormat":"dd-mm-yy" });
});
