function fixInstance(){
       if (window.__flash__removeCallback){
               var oldfunc = __flash__removeCallback;
               __flash__removeCallback = function(instance,name){
                       try{
                               oldfunc(instance,name);
                       }catch(e){}
               };
       } else {
               setTimeout(function(){fixInstance();},1000);
       }
}
fixInstance();
// 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 gio_hang(ten, don_gia)
{	
		// Lấy dữ liệu từ form
		var gten = ten;
		var gdon_gia = don_gia;
		
		var	query	=	"ten="+gten+"&don_gia="+gdon_gia;
						
		var http 	=	khoitao_ajax();
		try
		{
			$$$('gio_hang_thong_bao').innerHTML = "<center><img align='absmiddle' src='/images/loading.gif'> Loading...</center>";

			http.open("POST", "/action.php?act=gio_hang");
			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)
					{
						// Giá trị trả về sau khi xử lý
						x = http.responseText;
						if (x == "OK")
						{
							$$$('gio_hang_thong_bao').innerHTML = "<font color=blue><img src='/images/info.png' align='absmiddle'/> Đã thêm sản phẩm vào giỏ hàng!</font>";
						}
						else
						{
							$$$('gio_hang_thong_bao').innerHTML = "<font color=red><img src='/images/error.png' align='absmiddle'/> " + x + "</font>";
						}
					}
					else
					{
						alert('Có lỗi hệ thống. Vui lòng thử lại sau.');
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
			$$$('gio_hang_thong_bao').innerHTML = "<font color=red><img src='/images/error.png' align='absmiddle'/> Lỗi hệ thống! Vui lòng thử lại sau!</font>";
		}
		return false;
}

function cap_nhat(ten, mau,dongia, soluongmoi, thutu)
{
	// Lấy dữ liệu từ form
	var so_luong = soluongmoi;
	var thu_tu = thutu;
	var don_gia = dongia;
	var	query	=	"ten="+ten+"&mau="+mau+"&don_gia="+don_gia+"&so_luong="+so_luong+"&thu_tu="+thu_tu;
					
	var http 	=	khoitao_ajax();
	try
	{
		$$$('tong_tien_'+thu_tu).innerHTML = "<center><img align='absmiddle' src='/images/loading.gif'> Loading...</center>";

		http.open("POST", "/action.php?act=cap_nhat");
		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)
				{
					// Giá trị trả về sau khi xử lý
					x = http.responseText;
					var ts = x.split("&");
					$$$('tong_tien_'+thu_tu).innerHTML = ts[0];
					$$$('tong_cong').innerHTML = ts[1];
				}
				else
				{
					alert('Có lỗi hệ thống. Vui lòng thử lại sau.');
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}

function xoa_hang(ten, mau, thu_tu)
{
	if (confirm("Bạn có chắc muốn xóa sản phẩm này khỏi giỏ hàng không?"))
	{
		// Lấy dữ liệu từ form
		var	query	=	"ten="+ten+"&mau="+mau;
						
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action.php?act=xoa_hang");
			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)
					{
						// Giá trị trả về sau khi xử lý
						x = http.responseText;
						var d = document.getElementById('bang_tien');
						var dt = document.getElementById("dong_"+thu_tu);
						d.deleteRow(dt.rowIndex);
						$$$('tong_cong').innerHTML = x;
					}
					else
					{
						alert('Có lỗi hệ thống. Vui lòng thử lại sau.');
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}

function xoa_gio_hang()
{
	// Lấy dữ liệu từ form
	var	query	=	"";
					
	var http 	=	khoitao_ajax();
	try
	{
		http.open("POST", "/action.php?act=xoa_gio_hang");
		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)
				{
					// Giá trị trả về sau khi xử lý
					x = http.responseText;
				}
				else
				{
					alert('Có lỗi hệ thống. Vui lòng thử lại sau.');
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}

jQuery(window).load(function(){ 
	$('#myselectbox').selectbox();
	$(".thong_tin").jScrollPane();
	
	var ca = document.getElementById("current_action").value;	
	var current_act = ca.replace("_xem","");
	// Xử lý menu
	var timeout    = 10;
	var closetimer = 0;
	var ddmenuitem = 0;
	var closetimer2 = 0;
	var ddmenuitem2 = 0;
	var selmenu = 0;
	var oldHeight = 0;
	function jsddm_open()
	{  jsddm_canceltimer();
	   jsddm_close();
	   ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	   selmenu = $(this).find('ul');
	}
	
	function jsddm_close()
	{  
		if((ddmenuitem)&&(selmenu.attr('id')!=current_act))
		{
			ddmenuitem.css('visibility', 'hidden');
		}
	}
	
	function jsddm_timer()
	{  closetimer = window.setTimeout(jsddm_close, timeout);}
	
	function jsddm_canceltimer()
	{  if(closetimer)
	   {  window.clearTimeout(closetimer);
		  closetimer = null;}}
	document.onclick = jsddm_close;
	
	function jsddm_open2()
	{  jsddm_canceltimer2();
	   jsddm_close2();
	   ddmenuitem2 = $(this).find('ul').css('visibility', 'visible');
	}
	
	function jsddm_close2()
	{  
		if((ddmenuitem2))
		{
			ddmenuitem2.css('visibility', 'hidden');
		}
	}
	
	function jsddm_timer2()
	{  closetimer2 = window.setTimeout(jsddm_close2, timeout);}
	
	function jsddm_canceltimer2()
	{  if(closetimer2)
	   {  window.clearTimeout(closetimer2);
		  closetimer2 = null;}}
	
	$(document).ready(function(){
		$('.menu > li').bind('mouseover', jsddm_open)
	   	$('.menu > li').bind('mouseout',  jsddm_timer)
		
		$('.quickmenu > li').bind('mouseover', jsddm_open2)
	   	$('.quickmenu > li').bind('mouseout',  jsddm_timer2)
	});
	//-------------------------
	
	// Kiểm tra IE6
	function isIE6()
	{
		if (typeof document.body.style.maxHeight != "undefined") {
		  // IE 7, mozilla, safari, opera 9
		  return false;
		} else {
		  // IE6, older browsers
		  return true;
		}
	}
	//Chỉnh lại bóng đổ
	if (!isIE6())
	{
		oldHeight = $(".shadow_left").height();
		$(".shadow_left").height(oldHeight - 60);
		$(".shadow_right").height(oldHeight - 60);
		$(".shadow_bot_left").css("top",oldHeight + "px");
		$(".shadow_bot_right").css("top",oldHeight + "px");
		$(".shadow_bottom").css("top",oldHeight + "px");
	}
	else
	{
		$(".shadow_left").css("visibility","hidden");
		$(".shadow_right").css("visibility","hidden");
		$(".shadow_bot_left").css("visibility","hidden");
		$(".shadow_bot_right").css("visibility","hidden");
		$(".shadow_bottom").css("visibility","hidden");
		$(".shadow_top_left").css("visibility","hidden");
		$(".shadow_top_right").css("visibility","hidden");
	}
	
	hs.graphicsDir = '/highslide/graphics/';
    hs.outlineType = 'rounded-white';

}); 

