
// 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); 
} 


//cuongnt - kt member
function kt_member(frm)
{
	username = frm.txt_username.value
	password = frm.txt_password.value
	
	if(!username)
	{
		alert("Vui lòng nhập tên đăng nhập!");
		frm.txt_username.focus();
		return false;
	}
	if(!password)
	{
		alert("Vui lòng nhập mật khẩu!");
		frm.txt_password.focus();
		return false;
	}
	else

	{
		var	query	=	"act=kt_member&username="+username+"&password="+password;
		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("Đăng nhập thành công");
							window.location.href = "/thong-bao-noi-bo/the-gioi-phang.html";
						}
						else
						{
							alert("Đăng nhập thất bại");
							window.location.href = "/";
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}

function change_pass(frm)
{
	txt_oldpass = frm.txt_oldpass.value
	txt_newpass = frm.txt_newpass.value
	txt_pass_accept = frm.txt_pass_accept.value
	if(!txt_oldpass)
	{
		alert("Vui lòng nhập mật khẩu!");
		frm.txt_oldpass.focus();
		return false;
	}
	if(!txt_newpass)
	{
		alert("Vui lòng nhập mật khẩu mới!");
		frm.txt_newpass.focus();
		return false;
	}
	if(!txt_pass_accept)
	{
		alert("Vui lòng nhập xác nhận mật khẩu!");
		frm.txt_pass_accept.focus();
		return false;
	}
	if(txt_pass_accept != txt_newpass)
	{
		alert("Xác nhận mật khẩu không chính xác!");
		frm.txt_pass_accept.focus();
		return false;
	}
	else
	{
		var	query	=	"act=change_pass&txt_oldpass="+txt_oldpass+"&txt_newpass="+txt_newpass+"&txt_pass_accept="+txt_pass_accept;
		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("Đổi mật khẩu thành công ! ");
							window.location.href = "/";
						}
						else
						{
							alert(x);
							window.location.href = "/";
						}
					}
					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
	{
		$$$('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)
				{
					$$$('inner').innerHTML = http.responseText;
					window.location.href = "/";
				}
				else
				{
						return false;
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}
//cuongnt - send mail đăng ký
function send_res(frmContact)
{
	txtName = frmContact.txtName.value
	txtAddress = frmContact.txtAddress.value
	txtTel = frmContact.txtTel.value
	txtEmail = frmContact.txtEmail.value
	txtChuyennganh = frmContact.txtChuyennganh.value
	txtVitri = frmContact.txtVitri.value
	txtSubject = frmContact.txtSubject.value
	txtContent = frmContact.txtContent.value
	
	if(!txtName)
	{
		alert("Vui lòng nhập họ tên !");
		frmContact.txtName.focus();
		return false;
	}
	if(!txtAddress)
	{
		alert("Vui lòng nhập địa chỉ !");
		frmContact.txtAddress.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;
	}
	if(!txtChuyennganh)
	{
		alert("Vui lòng nhập chuyên ngành !");
		frmContact.txtChuyennganh.focus();
		return false;
	}
	if(txtVitri== -1)
	{
		alert("Vui lòng nhập vị trí !");
		frmContact.txtVitri.focus();
		return false;
	}
	if(!txtSubject)
	{
		alert("Vui lòng nhập tiêu đề !");
		frmContact.txtSubject.focus();
		return false;
	}
	if(!txtContent)
	{
		alert("Vui lòng nhập nội dung !");
		frmContact.txtContent.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+"&txtAddress="+txtAddress+"&txtTel="+txtTel+"&txtEmail="+txtEmail+"&txtChuyennganh="+txtChuyennganh+"&txtVitri="+txtVitri+"&txtContent="+txtContent+"&txtSubject="+txtSubject;
		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 = "/";
						}
						else
						{
							alert(x);
							window.location.href = "/";
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}



function SkipError()
{
	return true;
}


function checkbox_test(obj){  
  var counter = 0;  // counter for checked checkboxes  
  var i       = 0;  // loop variable  
  var url     = ''; // final url string  
  // get a collection of objects with the specified 'input' TAGNAME  
  var input_obj = obj;
  // loop through all collected objects  
  for (i=0; i < input_obj.length; i++){  
    // if input object is checkbox and checkbox is checked then ...  
    if (input_obj[i].type == 'checkbox' && input_obj[i].checked == true){  
      // ... increase counter and concatenate checkbox value to the url string  
      counter++;  
      url = url + '|' + input_obj[i].value;  
    }  
  }  
  // display url string or message if there is no checked checkboxes  
  if (counter > 0){  
    // remove first '&' from the generated url string  
    url = url.substr(1);  
    // display final url string  
	return url;
    // or you can send checkbox values  
    // window.location.href = 'my_page.php?' + url;  
  }  
  else return "";
}  


function Tab(number)
{
	var count1 = $('#mn_1').val();
	var count2 = $('#mn_2').val();
	var count3 = $('#mn_3').val();
	var count4 = $('#mn_4').val();
	
	
	if (number == count1)
        {
            $$$(count1).style.display='block';
            $$$('menu_1').className = 'active';
            $$$(count2).style.display='none';
            $$$('menu_2').className = '';
			$$$(count3).style.display='none';
            $$$('menu_3').className = '';
			$$$(count4).style.display='none';
            $$$('menu_4').className = '';

        }
        if (number == count2)
        {
            
            $$$(count1).style.display='none';
            $$$('menu_1').className = '';	
			$$$(count2).style.display='block';
            $$$('menu_2').className = 'active';
			$$$(count3).style.display='none';
            $$$('menu_3').className = '';
			$$$(count4).style.display='none';
            $$$('menu_4').className = '';

        }	
		 if (number == count3)
        {
     
            $$$(count1).style.display='none';
            $$$('menu_1').className = '';	
			$$$(count2).style.display='none';
            $$$('menu_2').className = '';
			$$$(count3).style.display='block';
            $$$('menu_3').className = 'active';
			$$$(count4).style.display='none';
            $$$('menu_4').className = '';
		
        }	
		 if (number == count4)
        {

            $$$(count1).style.display='none';
            $$$('menu_1').className = '';	
			$$$(count2).style.display='none';
            $$$('menu_2').className = '';
			$$$(count3).style.display='none';
            $$$('menu_3').className = '';
			$$$(count4).style.display='block';
            $$$('menu_4').className = 'active';

        }	
		
}

//Áp đặt chiều cao cho các cột khi trang 
$(function(){
	Cufon.replace('.tgp_container .tgp_menu ul#nav li a,.banner_title ', { fontFamily: 'HP-Vogue', hover: true });
	
});
//đã được load hoàn tất. 
jQuery(window).load(function(){  
	
    // Đặt tọa độ cho biểu tượng loading
	//$(".loading").fadeIn();
	//$(".loading_status").css("top","50%");
	//$(".loading_status").css("left","45%");
	// Kiểm tra IE
	function isIE()
	{
	  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	}
	
	//Cufon.replace('.tgp_banner .div_1 ul li a,.banner_title', {fontFamily: 'Myriad Pro', color: '#8b806e', hover:true, hoverables:{a:true}});

	$(document).ready(function(){
		$(".loading").fadeOut();
				
		// Fix lỗi css trong IE
		if (isIE())
		{
			$("html").css("overflow","auto");
			$("html body").css("overflow","hidden");
		}
		jQuery("a[class^='fancybox']").fancybox({
			'overlayOpacity'	:	0.7,
			'overlayColor'		:	'#000000',
			'zoomSpeedIn'		:	500,
			'zoomSpeedOut'		:	500
		});	
		

		var $portfolioItem = jQuery('.item');
		$portfolioItem.find('.item-image').css('background-color','#000000');
		jQuery('.zoom-icon, .more-icon').css('opacity','0');
		
		$portfolioItem.hover(function(){
			jQuery(this).find('.item-image').stop(true, true).animate({top: -10}, 500).find('img.portfolio').stop(true, true).animate({opacity: 0.7},500);
			jQuery(this).find('.zoom-icon').stop(true, true).animate({opacity: 1, left: 43},400);
			jQuery(this).find('.more-icon').stop(true, true).animate({opacity: 1, left: 110},400);
		}, function(){
			jQuery(this).find('.zoom-icon').stop(true, true).animate({opacity: 0, left: 31},400);
			jQuery(this).find('.more-icon').stop(true, true).animate({opacity: 0, left: 128},400);
			jQuery(this).find('.item-image').stop(true, true).animate({top: 0}, 500).find('img.portfolio').stop(true, true).animate({opacity: 1},500);
		});
		
		$('.tgp_container .tgp_menu ul.menu_ngang').nmcDropDown({
		submenu_selector: 'div',
		show: {opacity: 'show', top: '-=18px'},
		show_speed: 200,
		hide: {opacity: 'hide', top: '+=18px'},
		hide_speed: 400
		});
		
		//slider home
		$("#slideshow").slideshow({
				pauseSeconds	:	3,
				fadeSpeed		:	2,
				width			:	487,
				height			:	245,
				cssClass		:	'slideshow'
			});
		
			$(".sub_pic").jCarouselLite({
				auto: true,
				speed: 300, // Toc do chay hinh
				auto: 5000,// Thoi gian chay hinh
				visible: 7
			});
		//san pham noi bat
		$('.box_hot_sp').vTicker({
			speed: 500,
			pause: 2000,
			animation: 'fade',
			mousePause: false,
			showItems: 2
		});
		$("#nav li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400); 
			},function(){ 
			$(this).find('ul:first').css({visibility: "hidden"}); 
        }); 
	});
});


