// 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 comment(frm)
{
	id = frm.id.value
	txt_ten = frm.txt_ten.value
	txt_email = frm.txt_email.value
	txt_bien = frm.txt_bien.value
	if(!txt_email)
	{
		alert("Vui lòng nhập Email!");
		frm.txt_email.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;
	}
	txt_noi_dung = frm.txt_noi_dung.value
	if(!txt_email)
	{
		alert("Vui lòng nhập nội dung!");
		frm.txt_noi_dung.focus();
		return false;
	}
	else
	{
		var	query	=	"act=comment&txt_ten="+txt_ten+"&txt_email="+txt_email+"&txt_noi_dung="+txt_noi_dung+"&id="+id+"&txt_bien="+txt_bien;
		var http 	=	khoitao_ajax();
		try
		{
			$$$('comment').innerHTML = "<center><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)
					{
						$$$('comment').innerHTML = http.responseText;
					}
					else
					{
						alert('Co loi he thong. Vui long thu lai sau.');
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}

/*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); 
} 
//Áp đặt chiều cao cho các cột khi trang 
$(function(){
Cufon.replace('.tgp_container .tgp_menu ul#nav li a.act,.tgp_container .tgp_body .tgp_left .tgp_introdution h1.title, .tgp_container .tgp_body .tgp_right .tgp_content h1.tieude span', { fontFamily: 'HP-Hai Au', hover: true });
Cufon.replace('.tgp_copyright .div_2 .slogan ul li', { fontFamily: 'HP-Hai Au'});
});
//đã được load hoàn tất. 
jQuery(window).load(function(){ 
 
    EqualHeight(jQuery(".tgp_container .tgp_body .left .noi_dung .van_ban .van_ban_giua , .tgp_container .tgp_body .left .noi_dung .ke_hoach .ke_hoach_giua")); 
    //Tự động điều chỉnh lại chiều cao sau khi 
    //resize browser. Nếu không quan tâm đến việc 
    //resize browser, bạn có thể gỡ bỏ hàm này 
    jQuery(window).resize(function(){ 
    EqualHeight(jQuery(".tgp_container .tgp_body .left .noi_dung .van_ban .van_ban_giua , .tgp_container .tgp_body .left .noi_dung .ke_hoach .ke_hoach_giua"));
    });
	
	
	
});

function vote(count)
{
  if(count!='0')
  {  
        cur_choice='';
        for (i=1;i<=count;i++)
        {
            va='answer'+i;
            if (document.getElementById(''+va+'').checked)
            {
                a = document.getElementById(''+va+'').value;
                cur_choice=a;
            }
            
        }
        if(cur_choice=='')
        {
              alert("Bạn chưa chọn mục yêu cầu.");
              return false;   
        }
        if(document.getElementById('txtnhapma').value=='')
        {
              alert("Bạn chưa nhập mã xác nhận.");
                return false;   
        }
        if(document.getElementById('txtnhapma').value!='')
        {
            ma=  document.getElementById('cid').value;
            manhap=  document.getElementById('txtnhapma').value;
            if(ma!=manhap)
            {
                alert("Bạn nhập sai mã xác nhận.");
                return false;
            }
        }
   }
    var	query	=	"doi="+cur_choice;
	var http 	=	khoitao_ajax();
	try
	{
		http.open("POST", "/vote.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;
					$("#vote_area").html(x);
				}
				else
				{
					alert('Có lỗi hệ thống. Xin vui lòng thử lại sau');
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
}

var act_value = "";
var page = 0;
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var count_str = "";
function countdown(yr,m,d){
	theyear=yr;themonth=m;theday=d
	var today=new Date()
	var todayy=today.getYear()
	if (todayy < 1000)
	todayy+=1900
	var todaym=today.getMonth()
	var todayd=today.getDate()
	var todayh=today.getHours()
	var todaymin=today.getMinutes()
	var todaysec=today.getSeconds()
	var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
	futurestring=montharray[m-1]+" "+d+", "+yr
	dd=Date.parse(futurestring)-Date.parse(todaystring)
	dday=Math.floor(dd/(60*60*1000*24)*1)
	dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
	dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
	dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
	if(dday==0&&dhour==0&&dmin==0&&dsec==1){
	count_str=current
	return 
	}
	else
	count_str=dday+"|"+dhour+"|"+dmin+"|"+dsec;
	document.getElementById("days").innerHTML = dday;
	document.getElementById("hours").innerHTML = (dhour > 9)?dhour:"0"+dhour;
	document.getElementById("minutes").innerHTML = (dmin > 9)?dmin:"0"+dmin;
	document.getElementById("seconds").innerHTML = (dsec > 9)?dsec:"0"+dsec;
	setTimeout("countdown(theyear,themonth,theday)",1000)
}

//
$(document).ready(function()
{		
	swfobject.embedSWF("/images/mediaplayer.swf", "video", "285", "240", "9.0.0", "/images/expressInstall.swf", {
		file : '/uploads/image/video/ban_hung_ca.flv',
		image : '/uploads/image/video/thump.gif',
		width : 285,
		height : 240
	}, {
		wmode : 'opaque',
		allowfullscreen : 'true',
		allowscriptaccess : 'always'
	});
	
	var newsoption1 = {
		firstname: "mynews",
		secondname: "showhere",
		thirdname:"news_display",
		fourthname:"news_button",
		playingtitle:"Now Playing:",
		nexttitle:"Next News:",
		prevtitle:"Prev News:",
		newsspeed:'10000',
		effectis:'4',
		mouseover:true,
		newscountname:"test",
		disablenewscount:false
	}
	$.init_news(newsoption1);
	
	//slices logo main
	$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	
	
	//xu ly menu
	$(".tgp_container .tgp_banner .menu_main .nav1 .menupre li").hover(function(){
		$(this).find("ul").css({"display":"block"});		
	},
	function(){
		$(this).find("ul").css({"display":"none"});
	});	
	
	
	//tham do ý kiến
	if (act_value == "home")
	{
		$(".vote_box .vote_item").hover(function(){
			$(this).stop().animate({"backgroundColor": '#E37100'},"fast");
		},
		function(){
			if (cur_choice != $(".vote_box .vote_item").index($(this)))
				$(this).stop().animate({"backgroundColor": '#0E0E0E'},"fast");
		});
		
		$(".vote_box .vote_item").click(function(){
			$(".vote_box .vote_item").removeClass("active");
			$(".vote_box .vote_item").css({"background":"#0E0E0E"});
			$(this).addClass("active");
			$(this).css({"background":"#E37100"});
			cur_choice = $(".vote_box .vote_item").index($(this));
		});
	}
	//border hoat dong cap truc thuoc
	$(".tab_new").corner("top 12px");
	$(".tab_new .content-cat-title-current").corner("top 12px");
	//border hoat dong cap truc thuoc
	$(".tab1").corner("top 12px");
	$(".tab1 .content-cat-title-current").corner("top 12px");
	//border hoat dong cap truc thuoc
	$(".tab2").corner("top 12px");
	$(".tab2 .content-cat-title-current").corner("top 12px");
	//border hoat dong cap truc thuoc
	$(".tgp_container .tgp_body .left .noi_dung .van_ban_uocmo h1.title").corner("top 12px");
	$(".tgp_container .tgp_body .left .noi_dung .ke_hoach h1.title").corner("top 12px");
	//border hoat dong cap truc thuoc
	$(".tab3").corner("top 12px");
	$(".tab3 .content-cat-title-current").corner("top 12px");
	//border hoat dong cap truc thuoc
	$(".tab4").corner("top 12px");
	$(".tab4 .content-cat-title-current").corner("top 12px");
	//border hoat dong cap truc thuoc
	$(".tgp_container .tgp_body .left .hdc_tp h1.title").corner("top 12px");
	$(".tgp_container .tgp_body .right .right_chuanang .ke_hoach h1.title_hd").corner("top 12px");
});


function isIE()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
