var sub = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var cookieName = "tmpMenu"; 
var p = 0;


function GetCookie(name) 
{ 
	var cname = name + "="; 
 	var dc = document.cookie; 
 
	if (dc.length > 0) 
	{ 
 		begin = dc.indexOf(cname); 

 		if (begin != -1) 
		{ 
 			begin += cname.length; 
 			end = dc.indexOf(";", begin);

 			if (end == -1) end = dc.length;

 			return unescape(dc.substring(begin, end));
 		} 
 	}
 return null;
}

function SetCookie(name,value) 
{
	
	document.cookie = name + "=" + escape (value) + ""  + "; path=" + "/" + "; domain=" + ".interceptor-pse.com"; 
	
}


function writeArray()
{
	
	var cookieValue = sub.join(",");

	SetCookie(cookieName,cookieValue);
	var r = document.cookie;
	

}

function showSelected()
{
	if(document.cookie)
	{
		
		var s = GetCookie(cookieName);
		
		sub = s.split(",");
		
	

		for(var y = 0; y < sub.length; y++)
		{	
			if(sub[y] == 1)
			{
			
				toggleV("tabSub" + (y+1));
				p = p + 1;
			}
		}
		check();
	}
	

}

function toggle(tabID) 
{
	toggleV(tabID);

	var ans = tabID.substring(6,tabID.length);
	    ans = parseInt(ans);
	
		

		if(sub[ans - 1] == 0)
		{
			sub[ans - 1] = 1;
			p = p + 1;
				
		}
		else
		{
			sub[ans - 1] = 0;
			p = p - 1;
				
		}
	check();
	writeArray();
	
}

function toggleV(tabID) 
{
 
	if( document.getElementById(tabID).style.display=='none' ){
  	 document.getElementById(tabID).style.display = '';
 	}else{
  	 document.getElementById(tabID).style.display = 'none';
 	}
}

function showall()
{
	
	if(p == 0 || p == sub.length )
	{
		
		for(var i = 1; i < sub.length + 1; i++)
		{	
		
			toggle("tabSub" + i);
		}				
				
	}
	else
	{	
		
		for(var i = 1; i < sub.length + 1; i++)
		{
			if(sub[i - 1] == 0)
			{
				toggle("tabSub" + i);
				
			}
		}
				
	}			
		
	check();
	writeArray();
	
}

function check()
{
	if(p == sub.length){document.getElementById("BROWSE").innerText = 'Hide All';}
	else{document.getElementById("BROWSE").innerText = 'Browse All';}
	
}