
function activateMenus()
{
	if ( document.getElementById("main_menu") )
	{
		var LI = document.getElementById("main_menu").getElementsByTagName("li");
		for (var i = 0; i < LI.length; i ++)
		{
			LI[i].onmouseover = function()
			{
			    if ( document.all )
			    {
			        this.className += " iehover";
			    }
			    var img = this.getElementsByTagName('img');
			    if ( img.length > 0 )
			    {
			        img[0].src = img[0].src.split('.gif').join('_r.gif');
			    }
			}
			LI[i].onmouseout  = function()
			{
			    if ( document.all )
			    {
			        this.className = this.className.split(' iehover').join('');
			    }
			    var img = this.getElementsByTagName('img');
			    if ( img.length > 0 )
			    {
			        img[0].src = img[0].src.split('_r.gif').join('.gif');
			    }
			}
		}
	}
}

function openMenu(){
	if ( document.getElementById('right_menu') ){
		var UL = document.getElementById('right_menu').getElementsByTagName('ul'); // Get all the ul's
		var openLevel = 0; // The level we should open
		var finalSelection = true; // Flag to catch the last menu item to select
		var underline = false; // Flag to underline the next level one
		for ( var i = 0; i < UL.length; i ++ ){ // Go through ul's
			if ( UL[i].className == 'rightnew' ){ // Get the main menu
				var LI = UL[i].getElementsByTagName('li'); // Get the li's in the toggle menu
				for ( var j = ( LI.length - 1 ); j >= 0; j -- ){ // Go through the li's backwards
					var liLevel = getLevel(LI[j], 1); // Get the level we're at

					// Check for the underline for level 1
					if ( ( liLevel == 1 ) && underline ){
						LI[j].style.backgroundImage = 'none'; // Remove the dots
						LI[j].style.borderBottom = '1px solid Black'; // Underline
						underline = false; // Flag as done
					}

					// Check if this line links to this page
					if ( LI[j].firstChild && LI[j].firstChild.href ){ // If there's a href
						if ( LI[j].firstChild.href == window.location ){ // Matching the page address window.location
							openLevel = liLevel; // Store the level we are at
						}

						// Get the location path
						var path = location.pathname.toString().split('/');
						// If it's a sub press centre page
						if ( path[1] == 'press_centre' && path.length > 3 ){
							// Get the link path (not full)
							var link_path = LI[j].firstChild.href.split( document.domain )[1];
							// If the link path is found in the page location
							if ( location.pathname.indexOf( link_path ) != -1 ){
								// Hightlight it
								LI[j].className = "open";
								underline = true;
							}
						}
					}

					// If the level is one less than the one we're opening
					if ( liLevel == openLevel ){
						// If it's level 1 then change to the open style
						if ( liLevel == 1 ){
							LI[j].className = "open";
							underline = true;
						}	else if ( finalSelection ){ // Change the bullet on the last selected link
							LI[j].className = "subopen";
							finalSelection = false;
						}
						// Show the UL within the LI if it's there
						if ( LI[j].getElementsByTagName('ul').length ){
							LI[j].getElementsByTagName('ul')[0].style.display = "block";
						}
						openLevel --; // Move down a level
					}
				}
			}
		}
	}
}

function getLevel( li, level ){
	if ( li.parentNode.className == 'rightnew' ){
		return level;
	} else {
		if ( li.parentNode.nodeName == 'UL' ){ level ++; }
		return getLevel( li.parentNode, level );
	}
}

function activePopupLinks()
{
    var A = document.getElementsByTagName('a'); // Get all the links
    for ( var i = 0; i < A.length; i ++ ) // Go through links
    {
        if ( A[i].className.indexOf('popup-') != -1 ) // Find the popups
        {
            A[i].href = 'javascript:popup(\'' + A[i].href + '\',656 ,500 );'; // Rebuild the link
        }
    }
}

function initRollovers()
{
    if ( document.images )
    {
        var preLoad = new Array();
        var tempSrc;
        for (var i = 0; i < document.images.length; i ++ )
        {

            // Only add rollover to images with the classname 'rollover'
            if ( document.images[i].className == 'rollover' )
            {
                var src = document.images[i].getAttribute('src'); // get the src
                var ext = src.substring( src.lastIndexOf('.'), src.length ); // get the file extension
                var hsrc = src.replace( ext, '_r' + ext ); // store the rollover src
                document.images[i].setAttribute('hsrc', hsrc); // set the new src attribute
                document.images[i].style.cursor = 'hand'; // Hand cursor where supported

                // Preload the image
                preLoad[i] = new Image();
                preLoad[i].src = hsrc;

                // Add the rollover functions
                document.images[i].onmouseover = function()
                {
                    tempSrc = this.getAttribute('src');
                    this.setAttribute('src', this.getAttribute('hsrc'));
                }
                document.images[i].onmouseout = function()
                {
                    if (!tempSrc) tempSrc = this.getAttribute('src').replace('_r'+ftype, ftype);
                    this.setAttribute('src', tempSrc);
                }
            }
        }
    }
}

function attachEvents()
{
	document.getElementById('search_term').onmousedown = function()
	{
	    this.value = '';
	    this.focus();
	}
	document.getElementById('search_term').onblur = function()
	{
	    if ( this.value == '' )
	    {
	        this.value = 'Keyword Site Search';
	    }
	}
	document.getElementById('search_button').onmouseover = function()
	{
	    this.src = '/schema/gifs/search_go_r.gif';
	}
	document.getElementById('search_button').onmouseout = function()
	{
	    this.src = '/schema/gifs/search_go.gif';
	}
}

function popup( win, w, h )
{
    if ( window.pop ){ window.pop.close(); } // close an open one
    if ( popup.arguments.length < 2 ){ w = 320; };
    if ( popup.arguments.length < 3 ){ h = 480; };
    pop = window.open( win,'return','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,copyhistory=no,locationbar=no,width=' + w + ',height=' + h + ',screenX=0,screenY=0,top=0,left=0');
}

//////// breadcrumb routines ////////////
function tail( s ) { // trims the first character from string s and returns the remaining string
  return s.substring(1, s.length);
}

function replaceChar(str, c1, c2) { // replaces character c1 with character c2 in string str could use regex instead
    str = str.split(c1);
    str = str.join(c2);
    return str;
}

String.prototype.toProperCase = function()
{
  return this.toLowerCase().replace(/^(.)|\s(.)/g,
      function($1) { return $1.toUpperCase(); });
}

function breadcrumbs( c, links, div ) {
  // displays breadcrumb trail in span.crumbs based on folder names with '_' replaced with ' '
  // c is the character (or string) separating the crumb items, "" for none
  // if links = false then no hyperlinks on the crumbs,
  // if links = true then hyperlinks are added to the crumbs

    var path = document.location.pathname;
    path = tail(path);  // remove leading "/"

    // sort out the search string for the product images page
    var search = document.location.search;
    search = search.replace(/folder=\d*\&/, 'folder=1&');  
    
    var last = path.substring(path.lastIndexOf('/'), path.length);
    var checkIndex = last;

    if ( (last == "/index.htm") || (last.length == 1) ) {
      path = path.substring( 0, path.lastIndexOf('/') );
      //remove index if this is the last part of the path
    }
    else if (last.length > 1) {
      last = path.substring(path.lastIndexOf('.'), path.length); // remove file suffix - should be .htm

    path = path.substring(0,path.lastIndexOf('.'),path.length); // remove suffix from path

    }

    var crumbs = path.split('/');
    var href = "";
    var crumbs_real_path = "";
    
    //crumbs[0] = "<a href='/'>Home</a>";
    for ( var i = 0; i<crumbs.length; i++ ) {
      if (crumbs[i].length > 0 ) {

        crumbs_real_path += "/" + crumbs[i];

        if ( (crumbs.length > 0 ) && (i == crumbs.length-1) ) {
          if (last != "index.htm") {
            href = crumbs_real_path + last + search; // put the file suffix back on - should be .htm, or /index.htm if default page for folder
        }
        }
        else if (crumbs.length > 0) {
          href = crumbs_real_path;
        }

        // replace '_' with ' '
        crumbs[i] = replaceChar(crumbs[i], '_', ' ');

        crumbs[i] = replaceChar(crumbs[i], 'Products and services', '>');
		
		//crumbs[i] = crumbs[i].toProperCase();
        crumbs[i] ="<a href='" + href + "'>" + crumbs[i] + "</a>";
	
      }
    }
    crumbs = crumbs.join(c);
    // join the links up to form the breadcrumb trail
    var theCrumb ="<font size=1><b>You are here:</b></font> <a href='/'>Home</a>";
    if (crumbs.length > 0) {
      theCrumb = theCrumb+c+crumbs;
    }
    var theDiv = document.getElementById(div);
    var newP = document.createElement('p');
    newP.innerHTML = theCrumb;
    theDiv.appendChild(newP);
    //document.write(theCrumb);


  }


/*
var str="Home >   >";

document.write(str.replace(/>   >/gi, ">"));
*/

/*
var dom_load = new domFunction(function()
{
    ie6fix(); // Handle IE 6 double margin not possible by display:inline
    activateMenus();
    attachEvents();
    activePopupLinks();
    initRollovers();
    openMenu();


	
} 
{ 'last_div' : 'id' }); // Once the last div has been detected
*/
