// 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);
}
//khanhtq - Gui yeu cau
function yeu_cau(frm)
{
	txt_id = frm.txt_id.value
	txt_yeu_cau = frm.txt_yeu_cau.value
	if(!txt_yeu_cau)
	{
		alert("Vui lòng nhập tên hoặc mả khách hàng!");
		frm.txt_yeu_cau.focus();
		return false;
	}
	var val = 0;
	for( i = 0; i < frm.group1.length; i++ )
	{
	if( frm.group1[i].checked == true )
	val = frm.group1[i].value;
	}
	if(val==0)
	{
		alert("Vui lòng chọn loại yêu cầu");
		return false;
	}
	else

	{
		var	query	=	"act=yeu_cau&txt_yeu_cau="+txt_yeu_cau+"&val="+val+"&txt_id="+txt_id;
		var http 	=	khoitao_ajax();
		try
		{
			$$$('yeu_cau').innerHTML = "<center><img src='/images/ajax-loader_3.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)
					{
						$$$('yeu_cau').innerHTML = http.responseText;
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}
//khanhtq - xem don dat hang
function ao_lop(frm)
{
	txt_khach_hang = frm.txt_khach_hang.value
	//txt_password = frm.txt_password.value
	if(!txt_khach_hang/* ||!txt_password*/)
	{
		alert("Vui lòng nhập tên hoặc mả khách hàng!");
		frm.txt_khach_hang.focus();
		return false;
	}
	else
	{
		var	query	=	"act=ao_lop&txt_khach_hang="+txt_khach_hang;
		var http 	=	khoitao_ajax();
		try
		{
			$$$('ao_lop').innerHTML = "<center><img src='/images/ajax-loader_2.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)
						{
							$$$('ao_lop').innerHTML = http.responseText;
							window.open('/support/index.html');
						}
						else
						{
							
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}
//khanhtq - sign out ao lop
function ao_lop_signout()
{
		var	query	=	"act=ao_lop_signout";
		var http 	=	khoitao_ajax();
		try
		{
			$$$('ao_lop').innerHTML = "<center><img src='/images/ajax-loader_2.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)
					{
						$$$('ao_lop').innerHTML = http.responseText;
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
}
//khanhtq - sign out ao lop
function duyet_mau(val)
{
		var	query	=	"act=duyet_mau&id="+val;
		var http 	=	khoitao_ajax();
		try
		{
			$$$('duyet_mau').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)
					{
						$$$('duyet_mau').innerHTML = http.responseText;
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
}
//khanhtq - tin tuc
function news(val)
{
	var	query	=	"act=news&i="+val;
	var http 	=	khoitao_ajax();
	try
	{
		$$$('news').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)
				{
					$$$('news').innerHTML = http.responseText;
				}
				else
				{
						return false;
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}
//khanhtq - tin tuc
function news_cty(val)
{
	var	query	=	"act=news_cty&i="+val;
	var http 	=	khoitao_ajax();
	try
	{
		$$$('news_cty').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)
				{
					$$$('news_cty').innerHTML = http.responseText;
				}
				else
				{
						return false;
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}

//khanhtq - san pham moi
function pro_new(val)
{
	var	query	=	"act=pro_new&i="+val;
	
	var http 	=	khoitao_ajax();
	try
	{
		$$$('pro_new').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)
				{
					$$$('pro_new').innerHTML = http.responseText;
				}
				else
				{
						return false;
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}
jQuery(window).load(function(){ 
							  
	$(document).ready(function(){
						 
	    Cufon.replace('.box_support .content .title, .box_mau_thiet_ke .title_thiet_ke, .box_yeu_cau_moi_nhat .title_thiet_ke, .box_gui_yeu_cau .title_thiet_ke, .title_size_mau', {fontFamily: 'HP-Helve-Condense', color: '-linear-gradient(#f6ec1c,#f6ec1c)'});							   
	    Cufon.replace('.tgp_menu li a', {fontFamily: 'HP-Helve-Condense', color: '-linear-gradient(#373737,#000000)'});
		Cufon.replace('.tgp_menu li a.active', {fontFamily: 'HP-Helve-Condense', color: '-linear-gradient(#ece7e7,#ffffff)'});
		$(".tgp_menu li").hover(function(){	
		Cufon.replace($(this).find("a"),{fontFamily: 'HP-Helve-Condense', color: '-linear-gradient(#ece7e7,#ffffff)'});											  
		},
		function (){
		Cufon.replace($(this).find("a"),{fontFamily: 'HP-Helve-Condense',color: '-linear-gradient(#373737,#000000)'});
		});
		$(".tgp_menu li").hover(function(){	
		Cufon.replace($(this).find("a.active"),{fontFamily: 'HP-Helve-Condense', color: '-linear-gradient(#ece7e7,#ffffff)'});											  
		},
		function (){
		Cufon.replace($(this).find("a.active"),{fontFamily: 'HP-Helve-Condense',color: '-linear-gradient(#ece7e7,#ffffff)'});
		});
		Cufon.replace('h1.title', {fontFamily: 'HP-Helve-Condense', color: '-linear-gradient(#565555,#000000)'});
		Cufon.replace('h2.title_main, .tgp_body .right .top_news .top_news_title_cat, .tgp_body .right .khach_hang .cat', {fontFamily: 'Tahoma', color: '-linear-gradient(#ece7e7,#ffffff)'});
		//Cufon.replace('h2.title_main_cus ', {fontFamily: 'Tahoma', color: '-linear-gradient(#FF3,#FF3)'});
		$("p.menu_left").click(function()
		{
			$(this).next("ul.sub_menu_left").slideToggle(300).siblings("ul.sub_menu_left").slideUp("slow");
	
		});
	});
	$("#j tr:nth-child(odd)").addClass("odd");
	$("#select-wrapper").jqTransform();
	
	$.fn.stickyfloat = function(options, lockBottom) {
	var $obj 				= this;
	var parentPaddingTop 	= parseInt($obj.parent().css('padding-top'));
	var startOffset 		= $obj.parent().offset().top;
	var opts 				= $.extend({ startOffset: startOffset, offsetY: parentPaddingTop, duration: 200, lockBottom:true,right:0,left:0 }, options);
	
	$obj.css({ position: 'absolute' });
	
	if(opts.lockBottom){
		var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop; //get the maximum scrollTop value
		if( bottomPos < 0 )
			bottomPos = 0;
	}
	
	$(window).scroll(function () { 
		$obj.stop(); // stop all calculations on scroll event

		var pastStartOffset			= $(document).scrollTop() > opts.startOffset;	// check if the window was scrolled down more than the start offset declared.
		var objFartherThanTopPos	= $obj.offset().top > startOffset;	// check if the object is at it's top position (starting point)
		var objBiggerThanWindow 	= $obj.outerHeight() < $(window).height();	// if the window size is smaller than the Obj size, then do not animate.
		
		// if window scrolled down more than startOffset OR obj position is greater than
		// the top position possible (+ offsetY) AND window size must be bigger than Obj size
		if( (pastStartOffset || objFartherThanTopPos) && objBiggerThanWindow ){ 
			var newpos = ($(document).scrollTop() -startOffset + opts.offsetY );
			if ( newpos > bottomPos )
				newpos = bottomPos;
			if ( $(document).scrollTop() < opts.startOffset ) // if window scrolled < starting offset, then reset Obj position (opts.offsetY);
				newpos = parentPaddingTop;

			$obj.animate({ top: newpos }, opts.duration );
		}
	});
};

$('#dow').stickyfloat({ duration: 400 });
$('#dow1').stickyfloat({ duration: 400 ,right:1});


}); 

