// JavaScript Document

/* Følgende scripts ligger i filen:
Produktkategorier: venstremenu hentes ind i Produktoversigt
Smoth scrolling: Blød scrolling ved brug af interne ankre i en side. Bruges i Nyheder og Produktoversigt
Zoomfunktion: Gør det muligt at se et billede i større udgave med mouse-over. Bruges i Produktkoversigt
Zoom Search Engine highlighting. Mærker søgeord op på den side man har fundet via søgning.
*/


/*Produktkategorier – venstremenu*/

// JavaScript Document
function produktkategorier(){
document.write("<h1>Kategorier</h1><h2 style='margin-bottom:0px;'><a href='produktoversigt-1.html#indhold'>Malebøger</a></h2><h3 style='margin-top:0px;'><strong><a href='produktoversigt-1.html#indhold'>Dansk</a></strong></h3>")
document.write("<p><a href='produktoversigt-1.html#mandalasdenfantastiskemalebog' id='mandalasdenfantastiskemalebogdanskmenu'>Mandalas – den fantastiske malebog</a></p>")
document.write("<p><a href='produktoversigt-1.html#mandalasynglingsmotiver' id='mandalasynglingsmotivermenu'>Mandalas yndlingsmotiver</a></p>")
document.write("<p><a href='produktoversigt-1.html#findromedmandalas' id='findromedmandalasmenu'>Find ro med Mandalas</a></p>")
document.write("<p><a href='produktoversigt-1.html#aarstidernesgangmedmandalas' id='aarstidernesgangmedmandalasmenu'>Årstidernes gang med Mandalas</a></p>")
document.write("<p><a href='produktoversigt-1.html#mandalasmedfeerogalfter' id='mandalasmedfeerogalfermenu'>Mandalas med feer og alfer</a></p>")
document.write("<p><a href='produktoversigt-1.html#mandalasmeddyr' id='mandalasmeddyrmenu'>Mandalas med dyr</a></p>")
document.write("<p><a href='produktoversigt-1.html#minimandalas' id='minimandalasmenu'>Mini Mandalas</a></p>")
document.write("<p><a href='produktoversigt-1.html#eventyrligeenhjørninger' id='eventyrligeenhjørningermenu'>Eventyrlige enhjørninger</a></p>")
document.write("<p><a href='produktoversigt-1.html#eventyrligeprinsesser' id='eventyrligeprinsessermenu'>Eventyrlige prinsesser</a></p>")
document.write("<p><a href='produktoversigt-1.html#hca' id='hcamenu'>Mandalas med H.C. Andersens<br /><span class='uden-understregning'>&nbsp;&nbsp;&nbsp;</span>papirklip</a></p>")
document.write("<p><a href='produktoversigt-1.html#mandalasmedfantasifuldevæsener' id='mandalasmedfantasifuldevæsenermenu'>Mandalas med fantasifulde væsener</a></p>")
document.write("<p><a href='produktoversigt-1.html#lærbogstavermedmandalas' id='lærbogstavermedmandalasmenu'>Lær bogstaver med Mandalas</a></p>")
document.write("<p><a href='produktoversigt-1.html#lærattællemedmandalas' id='lærattællemedmandalasmenu'>Lær at tælle med Mandalas</a></p>")
document.write("<p><a href='produktoversigt-1.html#24mandalasidecember' id='24mandalasidecembermenu'>24 Mandalas i december</a></p>")

document.write("<h3><strong><a href='produktoversigt-2.html#indhold'>Svenska</a></strong></h3>")
document.write("<p><a href='produktoversigt-2.html#indhold' id='mandalasdenfantastiskamaalarbokenmenu'>Mandalas – den fantastiska<br /><span class='uden-understregning'>&nbsp;&nbsp;&nbsp;</span>målarboken</a></p>")
document.write("<p><a href='produktoversigt-2.html#mandalasfavoritmotiv' id='mandalasfavoritmotivmenu'>Mandalas Favoritmotiv</a></p>")
document.write("<p><a href='produktoversigt-2.html#årstidernasgångIogII' id='årstidernasgångIogIImenu'>Årstidernas gång med Mandalas<br /><span class='uden-understregning'>&nbsp;&nbsp;&nbsp;</span>Band I + II</a></p>")
document.write("<p><a href='produktoversigt-2.html#mandalasmeddjur' id='mandalasmeddjurmenu'>Mandalas med djur</a></p>")
document.write("<p><a href='produktoversigt-2.html#mandalasmedfeerochnaturväsen' id='mandalasmedfeerochnaturväsenmenu'>Mandalas med feer och naturväsen</a></p>")

document.write("<h3><strong><a href='produktoversigt-3.html#indhold'>Norsk</a></strong></h3>")
document.write("<p><a href='produktoversigt-3.html#mandalasdenfantastiskemalebok' id='mandalasdenfantastiskemalebokmenu'>Mandalas – den fantastiske malebok</a></p>")
document.write("<p><a href='produktoversigt-3.html#mandalasynglingsmotiverno' id='mandalasynglingsmotivernomenu'>Mandalas yndlingsmotiver</a></p>")
document.write("<p><a href='produktoversigt-3.html#lærbokstavermedmandalas' id='lærbokstavermedmandalasmenu'>Lær bokstaver med Mandalas</a></p>")
document.write("<p><a href='produktoversigt-3.html#læråtellemedmandalas' id='læråtellemedmandalasmenu'>Lær å telle med Mandalas</a></p>")
document.write("<p><a href='produktoversigt-3.html#24adventmandalasidesember' id='24adventmandalasidesembermenu'>24 advent Mandalas i desember</a></p>")
document.write("<p><a href='produktoversigt-3.html#minimandalas' id='minimandalasmenu'>Mini Mandalas</a></p>")

document.write("<h3><strong><a href='produktoversigt-4.html#indhold'>English</a></strong></h3>")
document.write("<p><a href='produktoversigt-4.html#thefantasticcolouringbook' id='thefantasticcolouringbookmenu'>The fantastic colouring book</a></p>")
document.write("<p><a href='produktoversigt-4.html#myfavouritemotifs' id='myfavouritemotifsmenu'>My favourite motifs</a></p>")
document.write("<p><a href='produktoversigt-4.html#fairytaleunicornmandalas' id='fairytaleunicornmandalasmenu'>Fairytale unicorn Mandalas</a></p>")
document.write("<p><a href='produktoversigt-4.html#fairytaleprincessmandalas' id='fairytaleprincessmandalasmenu'>Fairytale princess Mandalas</a></p>")
document.write("<p><a href='produktoversigt-4.html#hcauk' id='hcaukmenu'>Fairytale Mandalas – after papercuts<br /><span class='uden-understregning'>&nbsp;&nbsp;&nbsp;</span>by Hans Christian Andersen</a></p>")
document.write("<p><a href='produktoversigt-4.html#minimandalasuk' id='minimandalasukmenu'>Mini Mandalas</a></p>")

document.write("<h2><a href='produktoversigt-4.html#musik'>Musik</a></h2>")
document.write("<p><a href='produktoversigt-4.html#mandalamoods' id='mandalamoodsmenu'>Mandala Moods</a></p>")

document.write("<h2><a href='produktoversigt-4.html#boeger'>Bøger</a></h2>")
document.write("<p><a href='produktoversigt-4.html#envagmedhjarta' id='envagmedhjartamenu'>En väg med hjärta</a></p>")
}

/*Produktkategorier – venstremenu optraeder på siderne om de enkelte produkter*/

// JavaScript Document
function produktkategorierprodukt(){
document.write("<h1>Kategorier</h1><h2 style='margin-bottom:0px;'><a href='../produktoversigt-1.html#indhold'>Malebøger</a></h2><h3 style='margin-top:0px;'><strong><a href='../produktoversigt-1.html#indhold'>Dansk</a></strong></h3>")
document.write("<p><a href='../produktoversigt-1.html#mandalasdenfantastiskemalebog' id='mandalasdenfantastiskemalebogdanskmenu'>Mandalas – den fantastiske malebog</a></p>")
document.write("<p><a href='../produktoversigt-1.html#mandalasynglingsmotiver' id='mandalasynglingsmotivermenu'>Mandalas yndlingsmotiver</a></p>")
document.write("<p><a href='../produktoversigt-1.html#findromedmandalas' id='findromedmandalasmenu'>Find ro med Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-1.html#aarstidernesgangmedmandalas' id='aarstidernesgangmedmandalasmenu'>Årstidernes gang med Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-1.html#mandalasmedfeerogalfter' id='mandalasmedfeerogalfermenu'>Mandalas med feer og alfer</a></p>")
document.write("<p><a href='../produktoversigt-1.html#mandalasmeddyr' id='mandalasmeddyrmenu'>Mandalas med dyr</a></p>")
document.write("<p><a href='../produktoversigt-1.html#minimandalas' id='minimandalasmenu'>Mini Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-1.html#eventyrligeenhjørninger' id='eventyrligeenhjørningermenu'>Eventyrlige enhjørninger</a></p>")
document.write("<p><a href='../produktoversigt-1.html#eventyrligeprinsesser' id='eventyrligeprinsessermenu'>Eventyrlige prinsesser</a></p>")
document.write("<p><a href='../produktoversigt-1.html#hca' id='hcamenu'>Mandalas med H.C. Andersens<br /><span class='uden-understregning'>&nbsp;&nbsp;&nbsp;</span>papirklip</a></p>")
document.write("<p><a href='../produktoversigt-1.html#mandalasmedfantasifuldevæsener' id='mandalasmedfantasifuldevæsenermenu'>Mandalas med fantasifulde væsener</a></p>")
document.write("<p><a href='../produktoversigt-1.html#lærbogstavermedmandalas' id='lærbogstavermedmandalasmenu'>Lær bogstaver med Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-1.html#lærattællemedmandalas' id='lærattællemedmandalasmenu'>Lær at tælle med Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-1.html#24mandalasidecember' id='24mandalasidecembermenu'>24 Mandalas i december</a></p>")

document.write("<h3><strong><a href='../produktoversigt-2.html#indhold'>Svenska</a></strong></h3>")
document.write("<p><a href='../produktoversigt-2.html#indhold' id='mandalasdenfantastiskamaalarbokenmenu'>Mandalas – den fantastiska<br /><span class='uden-understregning'>&nbsp;&nbsp;&nbsp;</span>målarboken</a></p>")
document.write("<p><a href='../produktoversigt-2.html#mandalasfavoritmotiv' id='mandalasfavoritmotivmenu'>Mandalas Favoritmotiv</a></p>")
document.write("<p><a href='../produktoversigt-2.html#årstidernasgångIogII' id='årstidernasgångIogIImenu'>Årstidernas gång med Mandalas<br /><span class='uden-understregning'>&nbsp;&nbsp;&nbsp;</span>Band I + II</a></p>")
document.write("<p><a href='../produktoversigt-2.html#mandalasmeddjur' id='mandalasmeddjurmenu'>Mandalas med djur</a></p>")
document.write("<p><a href='../produktoversigt-2.html#mandalasmedfeerochnaturväsen' id='mandalasmedfeerochnaturväsenmenu'>Mandalas med feer och naturväsen</a></p>")

document.write("<h3><strong><a href='../produktoversigt-3.html#indhold'>Norsk</a></strong></h3>")
document.write("<p><a href='../produktoversigt-3.html#mandalasdenfantastiskemalebok' id='mandalasdenfantastiskemalebokmenu'>Mandalas – den fantastiske malebok</a></p>")
document.write("<p><a href='../produktoversigt-3.html#mandalasynglingsmotiverno' id='mandalasynglingsmotivernomenu'>Mandalas yndlingsmotiver</a></p>")
document.write("<p><a href='../produktoversigt-3.html#lærbokstavermedmandalas' id='lærbokstavermedmandalasmenu'>Lær bokstaver med Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-3.html#læråtellemedmandalas' id='læråtellemedmandalasmenu'>Lær å telle med Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-3.html#24adventmandalasidesember' id='24adventmandalasidesembermenu'>24 advent Mandalas i desember</a></p>")
document.write("<p><a href='produktoversigt-3.html#minimandalas' id='minimandalasmenu'>Mini Mandalas</a></p>")

document.write("<h3><strong><a href='../produktoversigt-4.html#indhold'>English</a></strong></h3>")
document.write("<p><a href='../produktoversigt-4.html#thefantasticcolouringbook' id='thefantasticcolouringbookmenu'>The fantastic colouring book</a></p>")
document.write("<p><a href='../produktoversigt-4.html#myfavouritemotifs' id='myfavouritemotifsmenu'>My favourite motifs</a></p>")
document.write("<p><a href='../produktoversigt-4.html#fairytaleunicornmandalas' id='fairytaleunicornmandalasmenu'>Fairytale unicorn Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-4.html#fairytaleprincessmandalas' id='fairytaleprincessmandalasmenu'>Fairytale princess Mandalas</a></p>")
document.write("<p><a href='../produktoversigt-4.html#hcauk' id='hcaukmenu'>Fairytale Mandalas – after papercuts<br /><span class='uden-understregning'>&nbsp;&nbsp;&nbsp;</span>by Hans Christian Andersen</a></p>")
document.write("<p><a href='../produktoversigt-4.html#minimandalasuk' id='minimandalasukmenu'>Mini Mandalas</a></p>")

document.write("<h2><a href='../produktoversigt-4.html#musik'>Musik</a></h2>")
document.write("<p><a href='../produktoversigt-4.html#mandalamoods' id='mandalamoodsmenu'>Mandala Moods</a></p>")

document.write("<h2><a href='../produktoversigt-4.html#iboeger'>Bøger</a></h2>")
document.write("<p><a href='../produktoversigt-4.html#envagmedhjarta' id='envagmedhjartamenu'>En väg med hjärta</a></p>")
}


/* Smooth scrolling

   Changes links that link to other parts of this page to scroll
   smoothly to those links rather than jump to them directly, which
   can be a little disorienting.
   
   sil, http://www.kryogenix.org/
   
   v1.0 2003-11-11
   v1.1 2005-06-16 wrap it up in an object
*/

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
  
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
  
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
    if (!destinationLink) destinationLink = document.getElementById(anchor);

    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
  
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
  
    cypos = ss.getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
  
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}

ss.STEPS = 25;

ss.addEvent(window,"load",ss.fixAllLinks);




/*Zoom-funktion*/
function setZoom(img, dir, width, height, margin, zIndex, delay) {
  setTimeout(function() {
    if (img.dir==dir) {
      img.style.width=width;
      img.style.height=height;
      img.style.margin=margin;
      img.style.zIndex=zIndex;
      img.parentNode.parentNode.style.zIndex=zIndex;
    }
  }, delay);
}

function larger(img, width, height) {
  img.dir='rtl';
  now=parseInt(img.style.zIndex);
  for (i=now+1; i<=10; i++) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'rtl', w, h, m, i, 20*(i-now));
  }
}

function smaller(img, width, height) {
  img.dir='ltr';
  now=parseInt(img.style.zIndex);
  for (i=now-1; i>=0; i--) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'ltr', w, h, m, i, 40*(now-i)); /*40 angiver hastighed*/
  }
}
function stortbilledelarger(img, width, height) {
  img.dir='rtl';
  now=parseInt(img.style.zIndex);
  for (i=now+1; i<=5; i++) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'rtl', w, h, m, i, 30*(i-now));
  }
}

function stortbilledesmaller(img, width, height) {
  img.dir='ltr';
  now=parseInt(img.style.zIndex);
  for (i=now-1; i>=0; i--) {
    w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'ltr', w, h, m, i, 60*(now-i)); /*60 angiver hastighed*/
  }
}


// ----------------------------------------------------------------------------
// Zoom Search Engine 5.0 (16/Jan/2007)
// Highlight & auto-scroll script
//
// email: zoom@wrensoft.com
// www: http://www.wrensoft.com
//
// Copyright (C) Wrensoft 2007
// ----------------------------------------------------------------------------
// Use this script to allow your search matches to highlight and scroll to
// the matched word on the actual web page where it was found.
//
// You will need to link to this JS file from each page of your site
// which requires the "highlight/jump to matched word" feature.
//
// For example, you could paste the following HTML in your site's header or 
// footer:
//
//   <style>.highlight { background: #FFFF40; }</style>
//   <script type="text/javascript" src="highlight.js"></script>
//
// Note: You will need to specify the correct path to "highlight.js" depending
// on where the file is located.
//
// You will then need to modify the BODY tag on your page to include an "onLoad" 
// attribute, such as:
//
//   <body onload="highlight();">
//
// If for some reason you can not modify the body tag of your page, an alternative
// would be to put the following line after the </body> tag of your page:
//
//   <script type="text/javascript">highlight();</script>
//
// For more information, consult the Users Guide and our support website at:
// http://www.wrensoft.com/zoom/support
//
// This script is licensed for use with the Zoom Search Engine. Original
// development by Brett Alcock, VBasys Limited. To licence other applications 
// email highlight@vbasys.com with the subject "license".


// If you wish to disable the jump functionality which scrolls the browser
// to the first occurance of the matched word, change this setting to false
var JumpToFirstOccurance = true;

// For debugging purposes, disable the following
var CatchJSErrors = true;

function catcherror() { return true; }
if (CatchJSErrors)
{
    window.onerror = catcherror;
}

function QueryString(key)
{
    var value = null;
    for (var i=0;i<QueryString.keys.length;i++)
    {
        if (QueryString.keys[i]==key)
        {
            value = QueryString.values[i];
            break;
        }
    }
    return value;
}

function QueryString_Parse()
{
    var query = window.location.search.substring(1);
    var pairs = query.split("&");

    for (var i=0;i<pairs.length;i++)
    {
        var pos = pairs[i].indexOf('=');
        if (pos >= 0)
        {
            var argname = pairs[i].substring(0,pos);
            var value = pairs[i].substring(pos+1);
            QueryString.keys[QueryString.keys.length] = argname;
            QueryString.values[QueryString.values.length] = value;
        }
    }
}

QueryString.keys = new Array();
QueryString.values = new Array();

QueryString_Parse();

function getElement(id)
{
    if (document.getElementById)
        return(document.getElementById(id));
    else if (document.all)
        return(document.all[id]);
}

function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}


// regular expression version
function SearchHiLite(text)
{
    var SearchAsSubstring = 0;
    var hl;

    hl = QueryString("zoom_highlight");
    if (hl == "" || hl == null)
    {
        hl = QueryString("zoom_highlightsub");
        if (hl == "" || hl == null)
            return false;
        else
            SearchAsSubstring = 1;
    }
    if ((document.charset && document.charset == "utf-8") ||
    	(document.characterSet && document.characterSet == "UTF-8"))
    	hl = decodeURIComponent(hl);
    else
    	hl = unescape(hl);
    hl = hl.toLowerCase();
                
    // create array of terms        
    //var term = hl.split("+"); 
    var re = /\"(.*?)\"|[^\\+\"]+/g;
    var term = hl.match(re);    
   
    // convert terms in regexp patterns
    for (var i=0;i<term.length;i++) // take each term in turn
    {       
        if(term[i] != "")
        {                   
            if (term[i].indexOf("\"") != -1)
            {
                // contains double quotes               
                term[i]=term[i].replace(/\"/g,"");
                term[i]=term[i].replace(/\+/g," "); 
            }
            else
            {
                term[i]=term[i].replace(/\+/g,"");  
            }                           

            if (term[i].indexOf("*") != -1 || term[i].indexOf("?") != -1)
            {
                // convert wildcard pattern to regexp
                term[i] = term[i].replace(/\\/g, " ");
                term[i] = term[i].replace(/\^/g, " ");

                //term[i] = term[i].replace(/\+/g, " "); // split on this so no point in looking

                term[i] = term[i].replace(/\#/g, " ");
                term[i] = term[i].replace(/\$/g, " ");
                term[i] = term[i].replace(/\./g, " ");
                
                // check if search term only contains only wildcards
                // if so, we will not attempt to highlight this term
                var wildcards = /\w/;
                if (wildcards.test(term[i]))
                {
                	term[i] = term[i].replace(/\*/g, "[^\\s]*");
                	term[i] = term[i].replace(/\?/g, "[^\\s]"); // insist upon one non whitespace
                }                
                else                
                	term[i] = "";                
            }
			
			if (term[i] != "")
			{
	            if (SearchAsSubstring == 0)
	            {	                
	                term[i] = "(>[\\s]*|>[^<]+[\\b\\W])("+term[i]+")(<|[\\b\\W][^>]*<)";
	            }
	            else
	            {
	                // if term leads with wildcard then allow it to match preceeding text in word
	                var strWB="";
	                if(term[i].substr(0,7)=="[^\\s]*") strWB="\\b";
	                term[i] = "(>|>[^<]+)"+strWB+"("+term[i]+")([^>]*<)";
	            }
	        }	        
        }
    }

    text=text.replace(/&amp;/ig, '&');
    text=text.replace(/&nbsp;/ig, '');

    for (var i=0;i<term.length;i++) // take each term in turn
    {
        if(term[i] != "")
        {        	        	
            // we need a loop for the main search to catch all between ><
            // and we add  before each found to ignore those done etc
            // todo: develop reliable single pass regexp and dispose of loop
            var l = 0;
            re = new RegExp(term[i], "gi");
            var count = 0; // just incase
            text = ">" + text + "<"; // temporary tag marks
            do 
            {
                l=text.length;
                text=text.replace(re, '$1<span class="highlight" id="highlight" name="highlight">$2</span id="highlight">$3');
                count++;
            }
            //while(re.lastIndex>0 && count<100); lastIndex not set properly under netscape
            while(l!=text.length && count<100);
            text = text.substring(1, text.length-1); // remove temporary tags
        }
    }        
    text = text.replace(eval("//g"), '');        
    text = text.replace(eval("//g"), '&nbsp;');    
       
    return(text);
}

function jumpHL()
{
    var d=getElement("highlight");
    if(d)
    {
        var y=findPosY(d);
        // if element near top of page
        if(y < 100)
            window.scrollTo(0,0); // go to top of page
        else
            window.scrollTo(0,y-50); // show space of 50 above
    }
}

function highlight()
{	
	if (!"".match)	// check if browser supports regexp match() function
		return;	
    var x = document.body;
    if (x)
    {
        var strHTML=SearchHiLite(x.innerHTML);
        if (strHTML!=false) x.innerHTML = strHTML;
        if (JumpToFirstOccurance) jumpHL();
    }
}
