function ShowHideSubMenu(id)
{
	displayed = document.getElementById('sub' + id).style.display;
	
	if(displayed == 'block')
	{
		document.getElementById('sub' + id).style.display = 'none';
		
		//RemoveMenuItem('sub' + id);
	}
	else
	{
		document.getElementById('sub' + id).style.display = 'block';
		
		//AddMenuItem('sub' + id);
	}
	
	ChangeCssClass(id);
	GenerateCategoryTree(id);
}

function ChangeCssClass(id)
{
	currentClass = document.getElementById('item' + id).className;
	
	if(currentClass == 'open')
	{
		document.getElementById('item' + id).className = '';
	}
	else
	{
		document.getElementById('item' + id).className = 'open';
	}
}

function GenerateCategoryTree(id)
{
    iTreeCategoryCount = document.getElementById("hdnCategoryCount").value;
    sCategoryTree = "";
    for (i = 0; i < iTreeCategoryCount; i++)
        sCategoryTree += document.getElementById('sub' + i).style.display + ";";
    
    MakeRequest("AjaxRequest.aspx?Module=9&CategoryTree=" + sCategoryTree, "");
}

function AddMenuItem(id)
{	
	if(sTemp = ReadCookie('menu'))
	{
		sTemp = sTemp + ',' + id;
	}
	else
	{
		sTemp = id;
	}
	
	SetCookie('menu', sTemp, 30);
}

function RemoveMenuItem(id)
{
	if(sTemp = ReadCookie('menu'))
	{
		aTemp = sTemp.split(',');
		
		sMenu = '';
		
		for(i = 0; i < aTemp.length; i++)
		{
			if(aTemp[i] !== id)
			{
				if(sMenu != '')
				{
					sMenu += ',';				
				}
				
				sMenu += aTemp[i];
			}
		}
	}

	SetCookie('menu', sMenu, 30);
}

function SetCookie(cookieName, cookieValue, nDays)
{
    
	var today = new Date();
	var expire = new Date();

	expire.setTime(today.getTime() + 3600000*24*nDays);
	
	document.cookie = cookieName + "=" + cookieValue + ";expires=" + expire.toGMTString();

    test = ReadCookie(cookieName);
    
}

function ReadCookie(cookiename)
{
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return ""; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function OpenMenu()
{

	if(sTemp = ReadCookie('menu'))
	{			
	
		aTemp = sTemp.split(',');
	
		for(i = 0; i < aTemp.length; i++)
		{
			if(document.getElementById(aTemp[i]))
			{
				menuID = aTemp[i].substring(3,aTemp[i].length);
																
				document.getElementById(aTemp[i]).style.display = 'block';
				
				ChangeCssClass(menuID);
			}
		}
	}
	
}

function HideContent(d)
{
    if(d.length < 1)
    {
        return;
    }
    
    var dd = document.getElementById(d);
    
    dd.style.display = "none";
}

function ShowContent(d)
{
    if(d.length < 1)
    {
        return;
    }
    
    var dd = document.getElementById(d);
    
    dd.style.display = "";
    
}


function openPopup (imageURL, caption) 
{
  // Constants - change these to suit your requirements Note that the defaultWidth
  // and defaultHeight variables should be set to more than your largest image to
  // overcome a bug in Mozilla (at least up to Firefox 0.9).

  var windowTop = 100;                // Top position of popup
  var windowLeft = 100                // Left position of popup
  var defaultWidth = 550;             // Default width (for browsers that cannot resize)
  var defaultHeight = 400;            // Default height (for browsers that cannot resize)
  var onLoseFocusExit = true;         // Set if window to exit when it loses focus
  var undefined;

  // Set up the window open options
  var Options = "width=" + defaultWidth + ",height=" + defaultHeight + ",top=" + windowTop + ",left=" + windowLeft 
  
  // Now write the HTML markup to the new window, ensuring that we insert the 
  // parameter URL of the image and the parameter description of the image in 
  // the right place.
  var myScript = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" +
    "<html>\n" + 
    "<head>\n" + 
    "<title>" + caption + "\</title>\n" +
    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n" +
    "<meta http-equiv=\"Content-Language\" content=\"en-gb\">\n" +
    "<script language=\"JavaScript\" type=\"text/javascript\">\n" +
    "function resizewindow () {\n" +
    "  var width = document.myimage.width;\n" + 
    "  var height = document.myimage.height;\n";
  
  // Netscape  
  if (navigator.appName.indexOf("Netscape") != -1) { 
    myScript = myScript +  "  window.innerHeight = height;\n  window.innerWidth = width;\n"
  }
   
  // Opera 
  else if (navigator.appName.indexOf("Opera") != -1) {
    myScript = myScript +  "  window.resizeTo (width+12, height+31);\n"
  }
  
  // Microsoft 
  else if (navigator.appName.indexOf("Microsoft") != -1) { 
    myScript = myScript + "  window.resizeTo (width+12, height+31);\n" 
  }
  
  // Assume a frig factor for any other browsers
  else {
    myScript = myScript + "  window.resizeTo (width+14, height+34);\n"
  }
      
  myScript = myScript + "}\n" + "window.onload = resizewindow;\n" +
    "</script>\n</head>\n" + "<body ";
    
  if (onLoseFocusExit) {myScript = myScript + "onblur=\"self.close()\" ";}
    
  myScript = myScript + "style=\"margin: 0px; padding: 0px;\">\n" +
    "<img src=\"" + imageURL + "\" alt=\"" + caption + "\" title=\"" + caption + "\" name=\"myimage\">\n" + 
    "</body>\n" +  "</html>\n";
        
  //alert (myScript);
  
  // Create the popup window
  var imageWindow = window.open ("","imageWin",Options);
  imageWindow.document.write (myScript);
  imageWindow.document.close ();
  if (window.focus) imageWindow.focus();
}



function ShowPopupImage(imageURL, imageTitle)
{
    myWindow = window.open('', 'newWindow', 'width=300,height=255,top=100,left=100');
    
    myWindow.document.write('<html><head>');
    
    myWindow.document.write('');
    
    myWindow.document.write('<title>' + imageTitle + '</title><style>body{margin:0}a img{border:0}</style></head><body>');
    myWindow.document.write('<a href="javascript:window.close()"><img src="' + imageURL + '" alt="' + imageTitle + '" /></a>');
    myWindow.document.write('</body></html>');
    myWindow.document.close();
    
    newWidth = myWindow.document.images[0].width;
    newHeight = myWindow.document.images[0].height;
    
    myWindow.window.resizeTo(newWidth,newHeight);
    
    myWindow.onload = function() {
    
        if (self.innerWidth)
        {
            newViewportWidth = myWindow.innerWidth;
            newViewportHeight = myWindow.innerHeight;
        }
        else if (document.body)
        {
            newViewportWidth = myWindow.document.body.clientWidth;
            newViewportHeight = myWindow.document.body.clientHeight;
        }
        
        newWidth = newWidth + newWidth - newViewportWidth;
        newHeight = newHeight + newHeight - newViewportHeight;
            
        myWindow.window.resizeTo (newWidth,newHeight);
        
        myWindow.focus();
        
    }
}

var clearedUsername = 0;

function ClearUsername()
{
    if(clearedUsername == 0)
    {
        clearedUsername = 1;
        document.getElementById("ctl00_m_oHeaderAnonymousControl_txtLoginEmail").value = '';
        //  document.login_form.login_email.value = '';
    }
}

var clearedUsernameCheckMenu = 0;

function ClearUsernameCheckMenu()
{
    if(clearedUsernameCheckMenu == 0)
    {
        clearedUsernameCheckMenu = 1;
        document.getElementById("ctl00_Content_txtLoginEmail").value = '';
    }
}

var clearedPassword = 0;

function ClearPassword()
{
    if(clearedPassword == 0)
    {
        clearedPassword = 1;
    
        document.getElementById("ctl00_m_oHeaderAnonymousControl_login_password_text").style.display = 'none';
        document.getElementById("ctl00_m_oHeaderAnonymousControl_txtLoginPassword").style.display = 'inline';
        
        document.getElementById("ctl00_m_oHeaderAnonymousControl_txtLoginPassword").focus();
        
    /*
        document.login_form.login_password_text.style.display = 'none';
        document.login_form.login_password.style.display = 'inline';
        
        document.login_form.login_password.focus();
      */
    }
}

var clearedPasswordCheckMenu = 0;

function ClearPasswordCheckMenu()
{
    if(clearedPasswordCheckMenu == 0)
    {
        clearedPasswordCheckMenu = 1;
    
        document.getElementById("ctl00_Content_login_password_text").style.display = 'none';
        document.getElementById("ctl00_Content_txtLoginPassword").style.display = 'inline';
        
        document.getElementById("ctl00_Content_txtLoginPassword").focus();       
    }
}

function FocusButton(oEvent, oButton) 
{   
    if ((oEvent.keyCode == 13) || (oEvent.which == 13))
        document.getElementById(oButton).focus();
}