// 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);
}
//cuongnt - kt member
function kt_member(frm)
{
	txt_username = frm.txt_username.value
	txt_password = frm.txt_password.value
	if(!txt_username)
	{
		alert("Vui lòng nhập tên đăng nhập!");
		frm.txt_username.focus();
		return false;
	}
	if(!txt_password)
	{
		alert("Vui lòng nhập mật khẩu!");
		frm.txt_password.focus();
		return false;
	}
	else

	{
		var	query	=	"act=kt_member&txt_username="+txt_username+"&txt_password="+txt_password;
		var http 	=	khoitao_ajax();
		try
		{
			$$$('kt_member').innerHTML = "<center style='margin-top:50px'><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)
					{
						if(http.responseText)
						{
							$$$('kt_member').innerHTML = http.responseText;
						}
						else
						{
							return false;
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}
//cuongnt - sign out kt member
function kt_member_signout()
{
		var	query	=	"act=kt_member_signout";
		var http 	=	khoitao_ajax();
		try
		{
			$$$('kt_member').innerHTML = "<center style='margin-top:50px'><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)
					{
						$$$('kt_member').innerHTML = http.responseText;
						window.location.href = "/";
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
}

//cuongnt - search 
function tim_kiem_tap_chi(frm)
{
	txt_name = frm.txt_name.value
	txt_month = frm.txt_month.value
	txt_year = frm.txt_year.value
	var	query	=	"act=tim_kiem_tc&txt_name="+txt_name +"&txt_month="+txt_month+"&txt_year="+txt_year;
	var http 	=	khoitao_ajax();
	try
	{
		$$$('kqtk').innerHTML = "<center style='margin-top:50px'><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)
				{
					if(http.responseText)
					{
						$$$('kqtk').innerHTML = http.responseText;
					}
					else
					{
						return false;
					}
				}
				else
				{
						return false;
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}

function tim_kiem_lich_tuan(frm)
{
	txt_name = frm.txt_name.value
	txt_month = frm.txt_month.value
	txt_year = frm.txt_year.value
	var	query	=	"act=tim_kiem_lt&txt_name="+txt_name +"&txt_month="+txt_month+"&txt_year="+txt_year;
	var http 	=	khoitao_ajax();
	try
	{
		$$$('kqtk').innerHTML = "<center style='margin-top:50px'><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)
				{
					if(http.responseText)
					{
						$$$('kqtk').innerHTML = http.responseText;
					}
					else
					{
						return false;
					}
				}
				else
				{
						return false;
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}

function tim_kiem_danh_ba(frm)
{
	txt_name = frm.txt_name.value
	txt_cat = frm.txt_cat.value
	var	query	=	"act=tim_kiem_db&txt_name="+txt_name+"&txt_cat="+txt_cat;
	var http 	=	khoitao_ajax();
	try
	{
		$$$('kqtk').innerHTML = "<center style='margin-top:50px'><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)
				{
					if(http.responseText)
					{
						$$$('kqtk').innerHTML = http.responseText;
					}
					else
					{
						return false;
					}
				}
				else
				{
						return false;
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}


$(document).ready(function()
{
/*So sanh height cua 2 the div tgp_body_content & tgp_right*/
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(".tgp_body_content, .tgp_right")); 
    jQuery(window).resize(function(){ 
       // EqualHeight(jQuery(".tgp_body_content, .tgp_right")); 
    }); 
	
});
});
//cuongnt
$(document).ready(function() {

	swfobject.embedSWF("/images/mediaplayer.swf", "video", "310", "300", "9.0.0", "/images/expressInstall.swf", {
		file : '/images/video.flv',
		image : '/images/thumb.jpg',
		width : 310,
		height : 300
	}, {
		wmode : 'opaque',
		allowfullscreen : 'true',
		allowscriptaccess : 'always'
	});
	
	

	
	
	$('ul.sf-menu').superfish(); 

	//xu ly active
	var curr_act = $("#get_act").val();
	
	
	if(curr_act == "home")
	{
		$('ul#topnav li.home').addClass('active');
		$('.book_content #thong_bao').css({'display':'block'});
	
	}
	
	if(curr_act == "lien_he")
	{
		$('ul#topnav li.lien_he').addClass('active');
		$(this).find("span."+curr_act).show();

	}
	if(curr_act == "danh_ba")
	{
		$('ul#topnav li.danh_ba').addClass('active');
		$(this).find("span."+curr_act).show();

	}
	if(curr_act == "lich_tuan")
	{
		$('ul#topnav li.lich_tuan').addClass('active');
		$(this).find("span."+curr_act).show();

	}		
	if(curr_act == "tap_chi")
	{
		$('ul#topnav li.tap_chi').addClass('active');
		$(this).find("span."+curr_act).show();
	}
	if(curr_act == "gop_y")
	{
		$('ul#topnav li.gop_y').addClass('active');
		$(this).find("span."+curr_act).show();

	}
	if(curr_act == "sitemap")
	{
		$('ul#topnav li.sitemap').addClass('active');
		$(this).find("span."+curr_act).show();

	}
	if(curr_act == "hinh_anh")
	{
		$('ul#topnav li.hinh_anh').addClass('active');
		$(this).find("span."+curr_act).show();

	}
	if(curr_act == "hoat_dong")
	{
		$('ul#topnav li.hoat_dong').addClass('active');
		$(this).find("span."+curr_act).show();

	}
	if(curr_act == "gioi_thieu")
	{
		$('ul#topnav li.gioi_thieu').addClass('active');
		 $(this).find("span."+curr_act).show();

		
	}
	$("ul#topnav li").hover(function() { //sự kiện khi đưa chuột vào menu
	//$(this).css({ 'background' : '#FFFFFF'}); //Add background color and image on hovered list item

	$(this).find("span."+curr_act).hide();
		$(this).find("span").show(); //hiễn thị menu cấp 2
	//$(this).addClass('cuong');
	} , function() { //on hover out...
	//$(this).css({ 'background' : 'none'}); 
	$(this).find("span").hide(); //ẩn menu cấp 2
	$(this).find("span."+curr_act).show();
	//$(this).removeClass('cuong');
    });
	
	$('#myselectbox').selectbox();
});
//Thông tin nội bộ
$(document).ready(function(){
	$(".book_title").click(function()
	{
		$(this).next(".book_content").slideToggle(300).siblings(".book_content").slideUp("slow");

	});
	$('div.navigation').css({'width' : '200px', 'float' : 'left'});
	$('div.content').css('display', 'block');
	var onMouseOutOpacity = 1;
	$('#thumbs ul.thumbs li').opacityrollover({
		mouseOutOpacity:   onMouseOutOpacity,
		mouseOverOpacity:  1.0,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
	var gallery = $('#thumbs').galleriffic({
		delay:                     4000,
		numThumbs:                 8,
		preloadAhead:              0,
		enableTopPager:            false,
		enableBottomPager:         false,
		maxPagesToShow:            7,
		imageContainerSel:         '#slideshow',
		controlsContainerSel:      '#controls',
		captionContainerSel:       '#caption',
		loadingContainerSel:       '#loading',
		renderSSControls:          false,
		renderNavControls:         false,
		playLinkText:              'Play Slideshow',
		pauseLinkText:             'Pause Slideshow',
		prevLinkText:              '&lsaquo; Previous Photo',
		nextLinkText:              'Next Photo &rsaquo;',
		nextPageLinkText:          'Next &rsaquo;',
		prevPageLinkText:          '&lsaquo; Prev',
		enableHistory:             false,
		autoStart:                 true,
		syncTransitions:           true,
		defaultTransitionDuration: 900,
		onSlideChange:             function(prevIndex, nextIndex) {
			// 'this' refers to the gallery, which is an extension of $('#thumbs')
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onPageTransitionOut:       function(callback) {
			this.fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn:        function() {
			this.fadeTo('fast', 1.0);
		}
	});
	
});

