//Doan code Save va Get Cookie
var expDays = 1;

var exp = new Date(); 

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {  

	var endstr = document.cookie.indexOf (";", offset);  

	if (endstr == -1) { endstr = document.cookie.length; }

	return unescape(document.cookie.substring(offset, endstr));

}

function GetCookie (name) {  

	var arg = name + "=";  

	var alen = arg.length;  

	var clen = document.cookie.length;  

	var i = 0;  

	while (i < clen) {    

		var j = i + alen;    

		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    

		i = document.cookie.indexOf(" ", i) + 1;    

		if (i == 0) break;   

	}  

	return null;

}

function SetCookie (name, value) {  

	var argv = SetCookie.arguments;  

	var argc = SetCookie.arguments.length;  

	var expires = (argc > 2) ? argv[2] : null;  

	var path = (argc > 3) ? argv[3] : null;  

	var domain = (argc > 4) ? argv[4] : null;  

	var secure = (argc > 5) ? argv[5] : false;  

	document.cookie = name + "=" + escape (value) + 

	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 

	((path == null) ? "" : ("; path=" + path)) +  

	((domain == null) ? "" : ("; domain=" + domain)) +    

	((secure == true) ? "; secure" : "");
}

//Ket thuc Doan code Save va Get Cookie

function CatExpandMenu(spanId, target, align, boxId) {
	var catId = spanId;
	
	var cat_ex_cookie = GetCookie('catExpanding');
	var selectedCatCookie = GetCookie('selectedCat');
	var selectedAlignCookie = GetCookie('boxAlign');
	var box_ex_cookie = GetCookie('boxExpanding');
	
	if(cat_ex_cookie != null) {
		if(document.getElementById(cat_ex_cookie) != null) {
			var expandingMenu = document.getElementById(cat_ex_cookie);
			if(spanId == cat_ex_cookie) {							
				if (expandingMenu.style.display == 'none') {
					expandingMenu.style.display = 'block';
				}
				else {
					expandingMenu.style.display = 'none';
				}
			}
			else {
				expandingMenu.style.display = 'none';
			}
		}
	}
	
	if(selectedCatCookie != null) {
		if(document.getElementById(selectedCatCookie) != null) {
			var selectedCat = document.getElementById(selectedCatCookie);
			if(selectedAlignCookie==1)
				selectedCat.className='catalogue_top';
			if(selectedAlignCookie==2)
				selectedCat.className='catalogue_left';
			if(selectedAlignCookie==3)
				selectedCat.className='catalogue_right';
			if(selectedAlignCookie==4)
				selectedCat.className='catalogue_bottom';
		}
	}
	
	if(box_ex_cookie != null) {
		if(box_ex_cookie != boxId){
			if(document.getElementById(box_ex_cookie) != null) {
				var expandingMenu = document.getElementById(box_ex_cookie);
				expandingMenu.style.display='none';
			}
			if(document.getElementById(boxId) != null) {
				var expandingMenu = document.getElementById(boxId);
				expandingMenu.style.display='block';
			}
		}				
	}	
	
	SetCookie('catExpanding',spanId);
	SetCookie('selectedCat',"cat" + catId);
	SetCookie('boxAlign', align);
	SetCookie('boxExpanding',boxId);	
	
	if (target != "") {
		window.location = target;
	}
	else {
		if(spanId != cat_ex_cookie) {
			if(document.getElementById(spanId) != null) {
				var expandingMenu = document.getElementById(spanId);
				expandingMenu.style.display='block';
			}
		}
		if(document.getElementById("cat" + catId) != null) {
			var selectedCat = document.getElementById("cat" + catId);
			//selectedCat.className='menu_selected';
			if(align==1)
				selectedCat.className='menu_selected_top';
			if(align==2)
				selectedCat.className='menu_selected_left';
			if(align==3)
				selectedCat.className='menu_selected_right';
			if(align==4)
				selectedCat.className='menu_selected_bottom';
		}
	}	
}

function BoxExpandMenu(spanId) {
	var box_ex_cookie = GetCookie('boxExpanding');
	
	if(box_ex_cookie != null) {
		if(document.getElementById(box_ex_cookie) != null) {
			var expandingMenu = document.getElementById(box_ex_cookie);
			if(spanId == box_ex_cookie) {							
				if (expandingMenu.style.display == 'none') {
					expandingMenu.style.display = 'block';
				}
				else {
					expandingMenu.style.display = 'none';
				}
			}
			else {
				expandingMenu.style.display = 'none';
				if(document.getElementById(spanId) != null){
					document.getElementById(spanId).style.display = 'block';
				}
			}
		}
		else {
			if(document.getElementById(spanId) != null){
				document.getElementById(spanId).style.display = 'block';
			}
		}
	}
	else {
		if(document.getElementById(spanId) != null){
			document.getElementById(spanId).style.display = 'block';
		}
	}	
	
	SetCookie('boxExpanding',spanId);	
}

function CatLink(catId, target, align) {
	SetCookie('selectedCat',"cat" + catId);
	SetCookie('boxAlign', align);
	window.location = target;
}

function loadPage() {
	var cat_ex_cookie = GetCookie('catExpanding');
	var box_ex_cookie = GetCookie('boxExpanding');
	var cat_selected_cookie = GetCookie('selectedCat');
	var selectedAlignCookie = GetCookie('boxAlign');
	
	if(cat_ex_cookie != null) {
		if(document.getElementById(cat_ex_cookie) != null) {
			var expandingMenu = document.getElementById(cat_ex_cookie);
			expandingMenu.style.display='block';
		}		
	}
		
	if(box_ex_cookie != null) {
		if(document.getElementById(box_ex_cookie) != null) {
			var expandingMenu = document.getElementById(box_ex_cookie);
			expandingMenu.style.display='block';
		}		
	}
	
	if(cat_selected_cookie != null) {
		if(document.getElementById(cat_selected_cookie) != null) {
			var selectedCat = document.getElementById(cat_selected_cookie);
			//selectedCat.className='menu_selected';
			if(selectedAlignCookie==1)
				selectedCat.className='menu_selected_top';
			if(selectedAlignCookie==2)
				selectedCat.className='menu_selected_left';
			if(selectedAlignCookie==3)
				selectedCat.className='menu_selected_right';
			if(selectedAlignCookie==4)
				selectedCat.className='menu_selected_bottom';
		}
	}	
}
