//
// File:	mnucomm.js
// Description:	Common control functions
//
// Copyright (C) 2001 Office of the Director of Public Prosecutions (ODPP)
//
// Copyright in the material which appears at the Office of the Director of Public Prosecutions web-site is, subject to
// the operation of the Copyright Act 1968, vested in the Crown in the right of the State of New South Wales. 
// In keeping with the NSW Government's commitment to encouraging the availability, dissemination and exchange of
// information (and subject to the operation of the Act), you are welcome to reproduce the material which appears at the
// Office of the Director of Public Prosecutions site for personal, in-house or non-commercial use, without formal
// permission or charge. 
// In the event that you wish to reproduce, alter, store or transmit the material which appears at the Office of the
// Director of Public Prosecutions site for a purpose other than personal, in-house or non-commercial use, you can apply
// to the Office of the Director of Public Prosecutions at the following address for formal permission. 
// Director of Public Prosecutions
// 265 Castlereagh Street
// SYDNEY NSW 2000 , AUSTRALIA
// E-mail enquiries can be directed to enquiries@odpp.nsw.gov.au. 
// Please note that the copyright in the materials appearing at Internet sites which are linked to the Office of the
// Director of Public Prosecutions site vests in the author of those materials, or the author's licensee (subject to the
// operation of the Copyright Act 1968). The Office of the Director of Public Prosecutions cannot and does not grant any
// permission or authority in respect of the copyright in the materials appearing at third-party Internet sites, and
// strongly recommends that you refer to the copyright statements at those sites before making use of the materials. 
//

// ---------------------------  Common support functions  --------------------------------

function who()
{
	MSIE	= navigator.userAgent.indexOf("MSIE") >= 0;
	MSIE2	= navigator.userAgent.indexOf("MSIE2") >= 0 || navigator.userAgent.indexOf("MSIE 2") >= 0;
	MSIE3	= navigator.userAgent.indexOf("MSIE 3") >= 0;
	NN	= navigator.userAgent.indexOf("Mozilla/") >= 0 && !MSIE;
	NN2	= navigator.userAgent.indexOf("Mozilla/2.") >= 0 && !MSIE;
	NN3	= navigator.userAgent.indexOf("Mozilla/3.") >= 0 && !MSIE;
	//Mac	= navigator.userAgent.indexOf("Macintosh") >= 0 || navigator.userAgent.indexOf("Mac_") >= 0;
	//MacAndIE3	= Mac && MSIE3;
	//ns = !MSIE;
	ns = 0;
}

function MM_swapImgRestore()
{
	var i,x,a=document.MM_sr;
	for ( i=0; a && i<a.length && (x=a[i]) && x.oSrc; i++ )
	  x.src = x.oSrc;
}

function MM_preloadImages()
{
	var	d=document;
	
	if ( d.images )
	  {
	  if ( !d.MM_p )
	    d.MM_p = new Array();
	  var	i, j=d.MM_p.length, a=MM_preloadImages.arguments;
	  for ( i=0; i<a.length; i++ )
	    if ( a[i].indexOf("#")!=0 )
	      {
	      d.MM_p[j] = new Image;
	      d.MM_p[j++].src = a[i];
	      }
	  }
}

function MM_findObj(n, d)
{
	var	p,i,x;
	
	if ( !d )
	  d = document;
	if ( (p=n.indexOf("?")) > 0 && parent.frames.length )
	  {
	  d = parent.frames[n.substring(p+1)].document;
	  n = n.substring(0,p);
	  }
	if ( !(x=d[n])&&d.all )
	  x = d.all[n];
	for ( i=0; !x && i<d.forms.length; i++ )
	  x = d.forms[i][n];
	for ( i=0; !x && d.layers && i<d.layers.length; i++ )
	  x = MM_findObj(n,d.layers[i].document);
	return x;
}

function MM_swapImage()
{
	var	i, j=0, x, a=MM_swapImage.arguments;

	document.MM_sr = new Array;
	for ( i=0; i<(a.length-2); i+=3 )
	  if ( (x=MM_findObj(a[i]))!=null )
	    {
	    document.MM_sr[j++] = x;
	    if ( !x.oSrc )
	      x.oSrc = x.src;
	    x.src = a[i+2];
	    }
}

function getCookie(name)
{
	var dcookie = document.cookie; 
	var cname = name + "=";
	var clen = dcookie.length;
	var cbegin = 0;
	var cs = null;

	while (cbegin < clen)
	  {
	  var vbegin = cbegin + cname.length;
	  if (dcookie.substring(cbegin, vbegin) == cname)
	    {
	    var vend = dcookie.indexOf (";", vbegin);
	    if (vend == -1)
	      vend = clen;
	    cs = unescape(dcookie.substring(vbegin, vend));
	    //return unescape(dcookie.substring(vbegin, vend));
	    }
	  cbegin = dcookie.indexOf(" ", cbegin) + 1;
	  if (cbegin == 0)
	    break;
	  }
	return cs;
} // getCookie()

function xsetCookie(name, value, expires)
{
	if (!expires)
	  expires = new Date();
	document.cookie = name + "=" + escape (value) +
			  "; expires=" + expires.toGMTString() +  "; path=/";
} // setCookie()

function setCookie(name, value, expires)
{
	if (expires)
	  exps = 'expires=' + expires.toGMTString() + '; ';
	else
	  exps = "";
	document.cookie = name + "=" + escape (value) + "; " + exps + "path=/";
} // setCookie()

function delCookie(name)
{
	var expireNow = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +
			  "; path=/";
} // delCookie()

function FindEntry(listx,idx)
{
	var	entry;

	while ( idx-- > 0 )
	  {
	  pos = listx.indexOf(",");
	  if ( pos != -1 )
	    {
	    entry = listx.substring(0,pos);
	    listx = listx.substring(pos+1);
	    }
	  else if ( listx != "" )
	    {
	    entry = listx;
	    listx = "";
	    }
	  else
	    entry = "";
	  }
	return(entry);
} // FindEntry()

// Count number of submenu items in a menu
function ItemCount(s)
{
	res = 0;
	if ( s != "" )
	  do
	    {
	    pos = s.indexOf(",");
	    if ( pos >= 0 )
	      s = s.substring(pos+1);
	    res++;
	    if ( res >= 10 )
	      break;
	    }
	  while ( pos >= 0 );
	return(res);
} // ItemCount()

function MakeEsc(s,ch)
{
	res = "";
	while ( (pos=s.indexOf(ch)) >= 0 )
	  {
	  res = res + s.substring(0,pos) + '\\' + ch;
	  s = s.substring(pos+1);
	  }
	res = res + s;
	return(res);
} // MakeEsc()
