/* Popular phrases - INCOSTUME - 17:43:21, Tue Feb 9, 2010 */
var asPhrases=new Array ('predator','playboy','cowboy','indian','gorilla','vampire','hippie','alien','referee','nurse','batman','angel wings','bullet belt','ua2305','baterina','alice','vampiress','monk','gangster','cop','strawberry shortcake','pink ladies','king tut','amidala','indian costumes','peacock','mardi gras','old man','kasper','petticoat','queen of hearts','red riding','cabaret','fishnet stockings','antoinette','police','donnie darko','jester','barney','tutu','cute','little bo peep','gypsy','jedi','clown','jeannie','grecian goddess','bakugan','costume','freddy','creature','kermit','goth spider princess','nun costume','bee','saloon','mad hatter','keystone cop','kangaroo','peter rottentail','af005','fw8002','werewolf','60\'s','sparrow','hot dog','fire','alice in wonderland','jason','70\'s','doctor','davey jones','pebbles','miss piggy','woody','glow in the dark','luau','fairy witch','school','snow white','helmet','sailor','saw pig','saw','popeye','hats','gretel','teen pirate','spirit gum remover','wildcats','cat','shrek','flapper','boot covers','tween','webcaster','devil','prisoner','power rangers','clown shoes','beer','catwoman','army','bear','race','watchmen','fedora hat','bratz costumes','magician','militant','devo','50\'s','donny','can can','wizard of oz','valentines','jack sparrow','bunny','poodle skirt','poodle','wolfman','dr seuss','scarf','pirate','ballerina','viking','v for vendetta','stockings','crown','food','hippie wigs','cute costumes','cowboy boots','dipsy','kitty','nylon mask','v for','pirate shirt','tinker bell','super sperm','policeman costume','star wars','hannah montana','convict','french maid pink','rabbit','wicked dark fairy','edward','burlesque babe','wolf','dorothy','leg avenue','belle','rasta','gogo costumes','teletubbies','orange','cancan','horror costumes','cinderella','strawberry costume','slave princess','spiderman','prince charming','apron','pirate sword','jockey','cowboy hat','dg2801','greek','70','witch','wonder woman','pimp','tinky winky','toga','ironman','corpse bride','cape','super woman','spurs','nile','flamenco','xs','peter pan','jack','navy','starwars','ariel','ua1911bk','ua1049','ua9047','ua6255ww','ua8375bk','ua8670','ua5000r','go go','anita','grave reaper','minnie mouse','sumo','fireman','red cape','ua8993','captain','davey','cheerleader','ladybug','jungle costumes','olive oyl','star trek costume','badge','thigh','kilt','princess belle','french kiss','pig nose','monkey','mater','vendetta','adam and eve','easy score','family guy','king of hearts','witch broom','pokemon','elephant','snow white costume','chicken','aurora','wall-e costumes','boxer','bow and arrow','zoot suit','big foot','robin hood','barbarian babe','tiana','belly dancer','willy wonka','nymph','strawberry','adam','bob','matrix','grinch','king','scooby','roman','chucky','illusion','sumo wrestler','batarina','turtle','grim reaper','devil horns','maleficent','feet','panda','darko','clown feet','queen elizabeth','oompa loompa','austin powers','halo 3','astronaut','barbie','devil costumes','tiger','jigsaw','chewbacca','business women','frank','moose','he man','santa belt','rubber wig','nosferatu','eskimo','green goblin','harry potter','bug','wolverine','humorous','mushroom alice','beetlejuice','guns','oscar','pimp costumes','leg avenue french maid','killer','raggedy ann','slipknot','cave woman','santa\'s helper','pirate beard','80','belt','thigh high stockings','train','ninja','axe','civil war','prince','mummy','camo','walking illusion','mummy mamma','frankenstein costumes','rl5129','bride wig','granny','zombie prom queen','marilyn','shackles','thigh high boots','dp9011','rl5248','wonka','gypsy costume','inflatable','swords','moulin rouge','pig','glasses','zebra','pig tail','dollar','go diego go','hannah','snow','condom','sesame street','fan','bride and groom','spike','lashes','fur','20\'s','scarecrow','tea','white wigs','cyborg','zombie full face foam','christmas','supergirl','ta299','shoes','skull costume','club','bone','froggles','ta229','ta218','burn','ta253','guyver','elvis glasses','ta458','cheshire cat costume','robot','pin-up','hulk','dr phealphine','ta489','du328','fire extinguisher','shepherd','ta335','fw8507s','ta520','ta423','mi7092','ta337','christmas outfits','lipstick','du5014','ta355','ta507','fw8842','rainbow','green lantern','flail','fw8576pirate','rl0067','fw8445p','horror women','csez013','mi8031','elf costumes','rl5076','wiseman','du2103','darth vader','starburst','sugar babies','magic wand','magician hat','ia905','ia132','holiday','ma811','va478','ta331','va213','fw8453','va666','mrs claus','go go boots','noel','spider costume','leg avenue christmas','ha59ry','ta460c','lightsaber','satin','spider web','fw8029r','gc4096','wig pink shimmerring bob','spongebob','ja45','fw8443','du1121','helper','du700','va536','va239','du1030','fa127','fw8496','slipknot mask','mouse nose','goblin mask','vampire makeup','grey wig','feather duster','va915','va964','va963','du2005','va345','zorro','du2210','va560','va731','va768','du1161','du2220','va236','mushroom','socks','rb161','ta379','va479','lederhosen','green wig','daredevil','sleeping beauty','samurai','slave','shield','skirts','corn pipe','gandalf','ranger','gothic makeup','diego','teeth','spider web ghost','opaque','pencil','star','daphne','wonderland','nurses uniform','velma','yoda','red nose','santa glove','shaggy','pasties','dr satan','driver','dr.satan','tux','sorcerer','chimp','kooky','chuckles','thor','holster','rose','hannibal','knight','ryu','monroe','street fighter','moss','mexican','chef','jetsons','ken','sesame','decay','gretchen','pink','goretraits','pharoah','pen','eyeballs','elvira','flight','wednesday','gumby','under construction','fedora','leopard','phantom','otis','ketchup','eskimo cutie','swat','clinger','hellboy','reacher','staff','sugar daddy','headless','sally nightmare','couples','maternity','sunglasses','princess pocahontas','star magazine','smoke','stethoscope','cha cha','prom king','scarface','gnome','chun li','chatterer','street fighter ryu','plaid skirt','elizabeth','lips','tequila','chick magnet','side burns','muse','plug and socket','medals','sorcerer\'s staff','harajuku','countess carmella','mustard','lantern','red','farmer','green fairy','venom','droopers','strawberry teens','pebbles costume','corpse bride wig','skeleterror costume','sensei','olive','couples costume','goth ann','goddess of love','punk rock','zorro hat','nerd costumes','goth witch','frisky','hunchback','ring','prom nightmare','mad','purple wigs','spongebob mask','historical','rose vampiress','sexaquita','uncle sam lady','monster hands','sassy victorian vampiress','stoner schools fool','emperor','secret service','mary ann','foxxy','gold member','syringe','deluxe','undead stalker','man pirate','reversible','obama','beer man','claws','cookie trooper','big loco','cave women','skeleton leggings','service','bingo','temptress','child devil costume','kronos','jailbait','marabou','jailbird','scythe','chainmail','bloodstone','spirit gum','fw1184','foam appliance','plus size police','extinguisher','goatee','execution','slash','mens navy sailor','enchantress','phantom of the opera','pig ears','inmate','cowardly lioness','black tie','gentlemans officer','beer belly','mens viking','margarita','fun','vixen','danny','model','skinned alive mask','clark kent','pope','guitar','vital','wendy','gorilla mask','corrections officer','midnight fairy','yellow wig','camera','brick house','gunslinger','bloddy eyes','magazine','tacky','flesh eater','mehron','rotted','department','cat whiskers','secret wishes','fade','criminal','medical','farm','general','green m&m','undead','sheik','peter','zoot','go-go','giggles','immortal','incredibles','lola','shoulder holster','skull cap','department of corrections','mullet wigs','tatoo','hef','geisha wig','bun in the oven','pantyhose','sister','legwarmers','courage','peoples','pearls','security','oversized','snow princess','unitard','storybook','neverland','exorcist','feather','marie wig','plus size sailor','ref','scary','sailor hat','black widow man eater','group costumes','merchants wife','beetle','fighter','triton','bd16 scythe','man eater','fw5168','fw5774','fw5778','dg6415','gothic slayer','big bad wolf mask','fw5760','fw5780','maid marian','bob the builder','daisy bee','pink spidergirl','pink fairy','monster hdpc and bolts w hair','punker','keg','gold leaf','black shoes','dickens','back rider','goddess wigs','red makeup','rabbit costumes','chimp hands','handsome','mystery hero','peep','pith helmet','foot','men vampire','goblin','ripunzel','good ash','playboy devilish hottie','scrubs','scar','fw1433','ruffled','glow','dr','medallion','cat headband','corpse bride costume','baseball mask','chin','makeup blue','m m costume','mob','peanut','george jetson','toddler vampire','major trouble','blues clues','wax','fw1109','jessie','checkered','doin hard time','cane sword','teardrop','fire women','pantaloons','elsa','plus size stocking','plus size fishnet','piggy','uncle sam hat','suit','kit','goat','brain','skin and bones','popcorn','bandana','partial face mask','renaissance witch','freak','punk rock teen costume','tween dress costumes','sperm','bee sunflower teen','homerun','pit','sutured werewolf mask','tin man axe','couple costume set','dr coat','border','priestess','big kahuna','silver screen','monty python','devil costumes for teens','pig mask','erection','pipe','unicorn','pizza','childrens gloves','half mask','pie','flasher','mayhem','carmen miranda','cherry pie','machete','bow tie','woodsman','playing card hat','guido wig','pirate treasure','money bag','teenagers','wheaties','babe','strobe lights','rat','beer bottle','stitch tights','bowling ball','clip on earrings','fiona wig','first mate','dolphin','sash','banshee','flapper red','bone hands','molten','darth maul','crystal ball','ball and chain','stripe thigh','street fighter chun li','skellington','shady slim','red gloves','creature hoodie','tattoo','fake blood','blonde bob wig','thong','tool','shaggy costume','barbie and ken','pirate flag','hanging eyeball','trojan','love guru','bunny ears','bobble head','sweet vampiress','surgical mask','bart simpson masks','flip wig','french pinup','tea party host','gorilla feet','watch','wanda','pot of gold','cat eye glasses','boxing gloves','bull','fisherman','groove','troy','dangle','gilligan','slashed eye','g.i joe costumes','wound','wolf hands','doll box','sharpay','cheshire','m&m\'s','classic','games','red tights','blueberry pie','tatoo sleeves','drive','baby devil','darth vader light saber','chocolate','dino','straight black wigs','toddler dinosaur','spiderman gloves','wet t-shirt','blue marie costume','blurp charlie latex mask','black heels','butcher mask','fw9908','captain booty','sam','lucky lady','giggles creature reacher','french maid bunny','mistress','pirate cutie','carnival','dagger','undertaker','caretaker','hello sailor plus sized','spiderman 3','slim jim','demonette wings','monk robe','black red nurse','g i joe','vampiretta','bee costume for teens','frankenstein mask','west','dr.evil','child ghost','fog juice','high school','gas mask','shorty','rag','teen skull fairy','bleeding candles','southern','uncle harry','brown makeup','dark sorcerer','devil tail','groppin','light up witch','rottentail','future rock star','red costumes','leg avenue fairy','spiderella','matador','mickey','blue alice','cigar','womens jumpsuits','demon head','cape black lace with wings','saw costumes','hello sailor','creepy cloth','black and orange costume','roulette','mega corpse','bumble bee wings','puppy costumes','raspberry','south park','dwarf','insect','corset maid','hello kitty','cross','bunny rabbit','brothers smite','widow gore','bad seed','chest','biohazard','pink eyelash','batarina toddler costume','french maid pink teens','trixie speed racer','corrupt','witch tween costumes','poncho','trash can','skeleton hand wine glass','weird','bunting','poker','sausage','women\'s costumes','black dress','humorous costumes','manhunter costume','men leg avenue','butcher knife','lightning mcqueen','straw hat','scene setter','stapled','ha99','sightless','peeled face','dg1803','men pirate costumes','camper','mens convict','doctor toddler','biker costumes','susan','blue dress','fw5077','size thongs','mother in law','chest piece','miami','sassy lassie','tie','plus size thongs','pentagram','clifford','sherlock holmes','liberty','lenore','bob wig','skullzor','strawberry tights','colonial wigs','famine','bunny outfit','gc4094','size 6','retro swirl costume','studded gloves','scary men','big tex pistol','little lion','pantyhose stitch white child','hottie','high seas','web','trinity','bee outfits','halloween cat','red queen','bo peep leg avenue','fogger','bumble bee toddler','opera','pairs costume','stewie mask','brown wig','haunted mistress','skinned arm','theme costumes','oompa','charming','foam horror masks','spider jewelry','howdy partner','winter nymph','children skeleton bride','butcher apron','s t','wich','child tights','bounty','hotpants','big top','sweetheart','gc9029','toddler pirate','hockey mask white','bat mask','pacifier','leg avenue child','tribal costume','gabriella','bag of bones','blue gloves','child queen of hearts','mother superior','guts','shadow','foxxy cleopatra wig','toddler ninja','leg avenue angel','glamour witch child costume','samurai wig','slim','toddler witch costume','home','teen sailor costume','leather capes','dg6431','fw1541','dobson','geisha teen costumes','bloody shower curtain','gstring','rabbi','pharrah','plus vampiress','grillin gabby','constuction','spark fence','teen zombie','playful kitty','fw5731','presto','berry costumes','fairy kids','red and black wig','scot','fw5136','teen wig','fairy yellow','cavalier','s.w.a.t','black nurse','cuts','superman wig','walle','black lipstick','hot wheel','barbed wire','pirate captain','women medieval','count child','body paint','punk fairy','gossamer ghost','bone collector','grecian','crypt','skipper','bracelet','pod','hobbit','gilligan\'s island','skin paint','flesh','dvd','spider rings','spring','sleigh','fall','pioneer','minister','bell bottoms','priss','child boxer','tulle petticoat','castanets','whisper mask','toddler elephant','private','ti01','lord dark skull','dr killjoy','toddler boxer','child cinderella','piercings','gabriella dress','wizard wanda','holy','teens boots','dr doom','white shirt','sabre tooth','pirate mask','tony montana','oyl','leg avenue lion','green makeup','hanging head','cyclops','harry','short jacket','fw9663','gc4056','gc4118','gc6506','gc6090','ru9139','white bride','bandit boots','ru8630','spatula','black makeup','fw8487c','rl5981','skull sword','ru8781','ru4507','ru8152','ru8780','fw8317sp','du2286','dp0001','fw8487r','fw5714xl','ha87','brown afro','light bulb','rl5921','cut off head','rl5249','dg6473','dg6446','fw5714','dg6472','under','swan','shredded','blood squirt','clown makeup','chronicles of narnia','shiek');
/* $Revision: 3828 $
 *
 */

if(typeof(_sli_init )!='object'){var _sli_init=new Array();}
if(typeof(sli_init )!='function'){function sli_init(){ for(var x=0;x<_sli_init.length;x++) _sli_init[x]();}}
if(typeof(asPhrases)!='object'){ var asPhrases = new Array(); }
if(typeof(__SLI_customisations)!='object'){var __SLI_customisations = new Object();}
if(typeof(__SLI_ClientDefaults)!='object'){ var __SLI_ClientDefaults=[]; }
if(typeof(__SLI_validSearchBoxes)!='object'){ var __SLI_validSearchBoxes = new Array(); }
if(typeof(__SLI_asug_used_flag)!='object'){ var __SLI_asug_used_flag = false; }
if(typeof(__SLI_width)!='object'){ var __SLI_width = 0; }
if(typeof(sli_targeturl)!='object'){ var sli_targeturl = ""; }


    __AutoComplete = new Object(); //namespace...
    __AutoComplete_mouseMoved=false;

    // Basic UA detection
    isIE = document.all ? true : false;
    isGecko = navigator.userAgent.toLowerCase().indexOf('gecko') != -1;
    isOpera = navigator.userAgent.toLowerCase().indexOf('opera') != -1;

    /* defaults and options */

    var __SLI_ApplicationName = 'AutoSuggest';
        __SLI_customisations[ 'AutoSuggest' ] =
                {
                    'ShowBrandingFooter' : true
                    ,
                    'TextBoxIDPrefix' : 'sli_search_'
                    ,
                    'BrandingFooterImagePath' : 'http://assets.resultspage.com/autosuggest/sli_systems-powered_150_15.gif'
                    ,
                    'BrandingFooterTitleTooltip' : 'AutoSuggest Powered by SLI Systems'
                    ,
                    'DropListMinWidth' : 150
                    ,
                    'MaxListItems' : 10
                    ,
                    'Alignment' : true
                    ,
                    'TextBoxIDCustom' : []
                    ,
                    'ValidSearchBoxes' : false 
                    ,
                    'IE6SelectBox' : false 
                    ,
                    'IE6SelectBoxPadding' : 0
                    ,
                    'TargetURL' : ''
                    ,
                    'IframeAlignment' : false
                    ,
                    'AlignmentBorderBug' : false
                    ,
                    'IE6OnFocus' : false
                };
    /* 0 = keyname, 1 = value */
    for( defaultValuePair in __SLI_ClientDefaults )
    {
        __SLI_customisations[__SLI_ApplicationName][__SLI_ClientDefaults[defaultValuePair][0]]=__SLI_ClientDefaults[defaultValuePair][1];
    }

    /* pre-fetch branding footer image if being used...
     */
    if( __SLI_customisations[ __SLI_ApplicationName ][ 'ShowBrandingFooter' ] )
    {
        
        if(location.protocol == "https:")
        {
            __SLI_customisations[ __SLI_ApplicationName ][ 'BrandingFooterImagePath' ] = __SLI_customisations[ __SLI_ApplicationName ][ 'BrandingFooterImagePath' ].replace(/http:/i, 'https:');
        }
    
        var __AutoCompleteBranding = new Image();
        __AutoCompleteBranding.src=__SLI_customisations[ __SLI_ApplicationName ][ 'BrandingFooterImagePath' ];
    }


    function AutoComplete_init()
    {
        if(!isOpera)
        {
            var oldonresize=function(){};
            if(typeof(window.onresize)=='function')
                oldonresize = window.onresize;//play nicely with other people's toys
            window.onresize= function(){ oldonresize(); AutoComplete_HideAll(); AutoComplete_Create( asPhrases ); }

            AutoComplete_Create( asPhrases );
            
            var els = document.getElementsByTagName('input');
            if(els)
            {
               for ( i = 0; i < els.length; i++ )
               {
                  if(els[i].name == "asug")
                  {
                     els[i].disabled = true;
                  }
               }
            }
        }
    }




    /**
    * Attachs the autocomplete object to a form element. Sets
    * onkeypress event on the form element.
    *
    * @param string formElement Name of form element to attach to
    * @param array  data        Array of strings of which to use as the autocomplete data
    */
    //function AutoComplete_Create (id, data)
    /*
     * iterate over 'sli_search_*' assumes one or more search boxes numbered from 1...
    */
    function AutoComplete_Create( data )
    {
        var idx=1, e, id, searchBoxPrefix=__SLI_customisations[ __SLI_ApplicationName ][ 'TextBoxIDPrefix' ];
        while( e = document.getElementById(searchBoxPrefix+idx) )
        {
            AutoComplete_AttachHandlers(e, data);
            if( __SLI_customisations[ __SLI_ApplicationName ][ 'ValidSearchBoxes' ] )
            {
                __SLI_validSearchBoxes.push(searchBoxPrefix+idx);
            }
            idx++;
        }
        
        
        //this array comes from the customised list
        var otherTextBoxIdList = __SLI_customisations[ __SLI_ApplicationName ][ 'TextBoxIDCustom' ];
        if( otherTextBoxIdList)
        {
            for(idx=0;idx<otherTextBoxIdList.length;idx++)
            {
                e = document.getElementById(otherTextBoxIdList[idx]);
                if(e)
				{
					if( __SLI_customisations[ __SLI_ApplicationName ][ 'ValidSearchBoxes' ] )
                	{
	                    __SLI_validSearchBoxes.push( otherTextBoxIdList[idx] );
                	}
					AutoComplete_AttachHandlers(e, data);
				}
            }
        }
        
    } 

    function AutoComplete_AttachHandlers(e, data){
        var iframe,id;
        id=e.id;


        __AutoComplete[id] = {'data':data,
                              'isVisible':false,
                              'element':document.getElementById(id),
                              'dropdown':null,
                              'highlighted':null};

        __AutoComplete[id]['element'].setAttribute('autocomplete', 'off');
        __AutoComplete[id]['element'].onkeydown = function(e) {if (!e) e = window.event; return AutoComplete_KeyDown(this.getAttribute('id'), e);}
        __AutoComplete[id]['element'].onkeyup = function(e) {if (!e) e = window.event; return AutoComplete_KeyUp(this.getAttribute('id'), e);}
        // The function call on the next line was changed by Andrew Grieve April 2008
        __AutoComplete[id]['element'].onkeypress = function(e) {if (!e) e = window.event; return AutoComplete_KeyPress(this.getAttribute('id'), e);}
        __AutoComplete[id]['element'].onclick = function(e)
        {
            if( __SLI_customisations[ __SLI_ApplicationName ][ 'IE6OnFocus' ] )
            {
                __AutoComplete[id]['element'].focus();
            }
            if (!e) e = window.event; e.cancelBubble = true; e.returnValue = false;
        }



        // Hides the dropdowns when document clicked
        var docClick = function()
        {
            if( __SLI_customisations[ __SLI_ApplicationName ][ 'ValidSearchBoxes' ] )
            {
               for(var i=0; i < __SLI_validSearchBoxes.length; i++)
               {
                   if(document.getElementById(__SLI_validSearchBoxes[i]))
                   {
                       AutoComplete_HideDropdown(__SLI_validSearchBoxes[i]);
                   }
               }
            }
            else
            {
                for (id in __AutoComplete)
                {
                   AutoComplete_HideDropdown(id);
                }
            }
        }

        if (document.addEventListener) {
            document.addEventListener('click', docClick, false);
        } else if (document.attachEvent) {
            document.attachEvent('onclick', docClick, false);
        }


        // Max number of items shown at once
        if (arguments[2] != null) {
            __AutoComplete[id]['maxitems'] = arguments[2];
            __AutoComplete[id]['firstItemShowing'] = 0;
            __AutoComplete[id]['lastItemShowing'] = arguments[2] - 1;
        }

        AutoComplete_CreateDropdown(id);

        // Prevent select dropdowns showing thru
        if (isIE) {
            iframe = document.createElement('iframe');
            __AutoComplete[id]['iframe'] = iframe;
                iframe.id = id +'_iframe';
                iframe.style.position = 'absolute';
                iframe.style.top = '0';
                iframe.style.left = '0';
                iframe.style.width = '0px';
                iframe.style.height = '0px';
                iframe.style.zIndex = '98';
                iframe.style.visibility = 'hidden';
                
                if(location.protocol == "https:")
                {
                   iframe.src = 'https://assets.resultspage.com/autosuggest/blank.html';
                }
                
                if( __SLI_customisations[ __SLI_ApplicationName ][ 'IE6SelectBox' ] )
                {
                  iframe.style.width = __SLI_width  + __SLI_customisations[ __SLI_ApplicationName ][ 'IE6SelectBoxPadding'];
                }

            if( __SLI_customisations[ __SLI_ApplicationName ][ 'IframeAlignment' ] )
            {
                document.body.insertBefore( iframe );
            }
            else
            {
                __AutoComplete[id]['element'].parentNode.insertBefore( iframe, __AutoComplete[id]['element'] );
            }
        }
    }

    /**
    * Creates the dropdown layer
    *
    * @param string id The form elements id. Used to identify the correct dropdown.
    */
    function AutoComplete_CreateDropdown(id)
    {
        var theSearchbox = __AutoComplete[id]['element'];
        var theDropDown;
        var left_top = AutoComplete_getPos( theSearchbox );
        var left  = left_top[0];
        var top   = left_top[1] + theSearchbox.offsetHeight;
        var width = theSearchbox.offsetWidth;

        if ( width < __SLI_customisations[ __SLI_ApplicationName ][ 'DropListMinWidth' ] )
        {
            width = __SLI_customisations[ __SLI_ApplicationName ][ 'DropListMinWidth' ];
        }

        theDropDown = document.createElement('div');
        theDropDown.className = 'autocomplete'; // Don't use setAttribute()


        if(__SLI_customisations[ __SLI_ApplicationName ][ 'Alignment' ] == true && document.body)
        {
            theDropDown.style.position = 'absolute';
            document.body.insertBefore(theDropDown, document.body.nextSibling);
            
            // Position it
            theDropDown.style.visibility = 'hidden';
            theDropDown.style.left       = left + 'px';
            theDropDown.style.top        = top + 'px';
            theDropDown.style.width      = width + 'px';
            theDropDown.style.zIndex     = '99999';
        }
        else if(__SLI_customisations[ __SLI_ApplicationName ][ 'Alignment' ] == "offsetrelative" && document.body)
        {
          theSearchbox.parentNode.insertBefore(theDropDown, theSearchbox);
          // Position it
          if(sli_getStyle(theSearchbox.offsetParent, 'position') != "absolute")
          {
            theSearchbox.offsetParent.style.position = 'relative';
          }
          theDropDown.style.position = 'absolute';
          theDropDown.style.left = (theSearchbox.offsetLeft) + 'px';
          theDropDown.style.top = (theSearchbox.offsetTop + theSearchbox.offsetHeight) + 'px';
          theDropDown.style.width = (theSearchbox.clientWidth) + 'px';
          theDropDown.style.visibility = 'hidden';
          theDropDown.style.zIndex     = '99999999';
        }
        else
        {
            theSearchbox.parentNode.insertBefore(theDropDown, theSearchbox);
            // Position it
            theDropDown.style.visibility = 'hidden';
            theDropDown.style.left       = left + 'px';
            theDropDown.style.top        = top + 'px';
            theDropDown.style.width      = width + 'px';
            theDropDown.style.zIndex     = '99999';
        }
        

        __AutoComplete[id]['dropdown'] = theDropDown;
        __SLI_width = width;
    }

    function /* array [ left, top ] */ AutoComplete_getPos( obj )
    {
        var curleft = curtop = 0;
        var sli_flag = 0;

        if (obj.offsetParent)
        {
           do
           {
              if ( __SLI_customisations[ __SLI_ApplicationName ][ 'AlignmentBorderBug' ] )
              {         
                
                if(sli_flag == 1)
                {
                    var clientTop = (obj.offsetHeight - obj.clientHeight) / 2;
                    curtop += clientTop;

                    var clientLeft = (obj.offsetWidth - obj.clientWidth) / 2;
                    curleft += clientLeft;
                }
                sli_flag = 1;
              }
           
              curleft += obj.offsetLeft;
              curtop += obj.offsetTop;
           }
           while (obj = obj.offsetParent);
        }
        return [curleft,curtop];
    }

    /**
    * Shows the dropdown layer
    *
    * @param string id The form elements id. Used to identify the correct dropdown.
    */
    function AutoComplete_ShowDropdown(id)
    {

        AutoComplete_HideAll();



        var value = __AutoComplete[id]['element'].value;
        var toDisplay = new Array();
        var newDiv    = null;
        var text      = null;
        var numItems  = __AutoComplete[id]['dropdown'].childNodes.length;

        __AutoComplete_mouseMoved=false;
        // SLI Code Modification - Start - Andrew Grieve April 08
        // Trim the textbox so that if is starts with a space then the feature will still work
        //value = value.replace(/^\s+|\s+$/g,"");
        value = value.replace(/^\s+/g,"");

        if(value.length == "")
        {
            // If Textbox length is nothing (after the trim) then don't show dropdown.
            return;
        }
        // SLI Code Modification - End

        // Remove all child nodes from dropdown
        while (__AutoComplete[id]['dropdown'].childNodes.length > 0) {
            __AutoComplete[id]['dropdown'].removeChild(__AutoComplete[id]['dropdown'].childNodes[0]);
        }


        var count=0;
        // Go thru data searching for matches
        for (i=0; i<__AutoComplete[id]['data'].length; ++i)
        {
            // SLI Code Modification - Start - Andrew Grieve April 08 - Added lower casing
            if (__AutoComplete[id]['data'][i].substr(0, value.length).toLowerCase() == value.toLowerCase())
            {
                // SLI Code Modification - End
                toDisplay[toDisplay.length] = __AutoComplete[id]['data'][i];
                count++;
                /* how many to display? */
                if(count == __SLI_customisations['AutoSuggest']['MaxListItems'] ) /* Code inserted to keep list to a maximum of 10 values (was 20 or 30) */
                {
                    break;
                }
            }
        }

        // No matches?
        if (toDisplay.length == 0) {
            AutoComplete_HideDropdown(id);
            return;
        }



        // Add data to the dropdown layer
        for (i=0; i<toDisplay.length; ++i) {
            newDiv = document.createElement('div');
            newDiv.className = 'autocomplete_item'; // Don't use setAttribute()
            newDiv.setAttribute('id', 'autocomplete_item_' + i);
            newDiv.setAttribute('index', i);
            newDiv.style.zIndex = '99999';

             // Scrollbars are on display ?
            if (toDisplay.length > __AutoComplete[id]['maxitems'] && navigator.userAgent.indexOf('MSIE') == -1) {
                newDiv.style.width = __AutoComplete[id]['element'].offsetWidth - 22 + 'px';
            }

            newDiv.onmouseover =
        function()
        {
            if( __AutoComplete_mouseMoved )
                AutoComplete_HighlightItem(__AutoComplete[id]['element'].getAttribute('id'), this.getAttribute('index'));
        };

            newDiv.onclick     =    function()
                                    {
                                    	  __SLI_asug_used_flag = true;
                                                                           
                                        AutoComplete_SetValue(__AutoComplete[id]['element'].getAttribute('id'));
                                        AutoComplete_HideDropdown(__AutoComplete[id]['element'].getAttribute('id'));
                                        AutoComplete_submitForm(id);
                                    }



            text   = document.createTextNode(toDisplay[i]);
            newDiv.appendChild(text);
            newDiv.title='Search for ' + toDisplay[i];

            /* ellipsis for IE only */
            if( isIE )
            {
                newDiv.style.textOverflow = 'ellipsis';
                newDiv.style.width = '100%';
                newDiv.style.whiteSpace = 'nowrap';
                newDiv.style.overflow = 'hidden';

            }
            __AutoComplete[id]['dropdown'].appendChild(newDiv);
        }
        /*
         * append DIV containing footer branding...
         */
        if(__SLI_customisations['AutoSuggest']['ShowBrandingFooter'])
        {
            i = toDisplay.length;
            newDiv = document.createElement('div');
            newDiv.className = 'autocomplete_footer'; // Don't use setAttribute()
            newDiv.setAttribute('id', 'autocomplete_item_' + i);
            newDiv.setAttribute('index', i);
            newDiv.style.zIndex = '99999';
            newDiv.innerHTML = '<a href="http://www.sli-systems.com/powered-by.php" title="' +
                                __SLI_customisations[ __SLI_ApplicationName ][ 'BrandingFooterTitleTooltip' ] +
                                '"><img class="autocomplete_footer_branding" src="'+__AutoCompleteBranding.src+'" /></a>';

            __AutoComplete[id]['dropdown'].appendChild(newDiv);
        }


        // Too many items?
        if (toDisplay.length > __AutoComplete[id]['maxitems']) {
            __AutoComplete[id]['dropdown'].style.height = (__AutoComplete[id]['maxitems'] * 15) + 2 + 'px';

        } else {
            __AutoComplete[id]['dropdown'].style.height = '';
        }


        /**
        * Set left/top in case of document movement/scroll/window resize etc
        */
        if(__SLI_customisations[ __SLI_ApplicationName ][ 'Alignment' ] == "true" || __SLI_customisations[ __SLI_ApplicationName ][ 'Alignment' ] == "false")
        {
            var left_top = AutoComplete_getPos( __AutoComplete[id]['element'] );
            __AutoComplete[id]['dropdown'].style.left = left_top[0];
            __AutoComplete[id]['dropdown'].style.top  = left_top[1] + __AutoComplete[id]['element'].offsetHeight;
        }


        // Show the iframe for IE
        if (isIE) {
            
            if(!__SLI_customisations[ __SLI_ApplicationName ][ 'Alignment' ] == true)
            {
               __AutoComplete[id]['iframe'].style.width  = __AutoComplete[id]['dropdown'].offsetWidth;
            }
            
            
            __AutoComplete[id]['iframe'].style.top    = __AutoComplete[id]['dropdown'].style.top;
            __AutoComplete[id]['iframe'].style.left   = __AutoComplete[id]['dropdown'].style.left;
            __AutoComplete[id]['iframe'].style.height = __AutoComplete[id]['dropdown'].offsetHeight;

            __AutoComplete[id]['iframe'].style.visibility = 'visible';
        }

    e =  __AutoComplete[id]['dropdown'];

    e.onmousemove =
        function()
        {
            if(!__AutoComplete_mouseMoved){__AutoComplete_mouseMoved=true;}
            this.onmousemove = null;
        }

        // Show dropdown
        if (!__AutoComplete[id]['isVisible']) {
            __AutoComplete[id]['dropdown'].style.visibility = 'visible';
            __AutoComplete[id]['isVisible'] = true;
        }


        // If now showing less items than before, reset the highlighted value
        if (__AutoComplete[id]['dropdown'].childNodes.length != numItems) {
            __AutoComplete[id]['highlighted'] = null;
        }
    }



    /**
    * Hides the dropdown layer
    *
    * @param string id The form elements id. Used to identify the correct dropdown.
    */
    function AutoComplete_HideDropdown(id)
    {
        if (__AutoComplete[id]['iframe'])
        {
            __AutoComplete[id]['iframe'].style.visibility = 'hidden';
        }
        
        if (__AutoComplete[id]['dropdown'])
        {
            __AutoComplete[id]['dropdown'].style.visibility = 'hidden';
        }

        __AutoComplete[id]['highlighted'] = null;
        __AutoComplete[id]['isVisible']   = false;
    }


    /**
    * Hides all dropdowns
    */
    function AutoComplete_HideAll()
    {
         if( __SLI_customisations[ __SLI_ApplicationName ][ 'ValidSearchBoxes' ] )
         {
               for(var i=0; i < __SLI_validSearchBoxes.length; i++)
               {
                   if(document.getElementById(__SLI_validSearchBoxes[i]))
                   {
                       AutoComplete_HideDropdown(__SLI_validSearchBoxes[i]);
                   }
               }
         }
         else
         {
                for (id in __AutoComplete)
                {
                   AutoComplete_HideDropdown(id);
                }
         }
    }


    /**
    * Highlights a specific item
    *
    * @param string id    The form elements id. Used to identify the correct dropdown.
    * @param int    index The index of the element in the dropdown to highlight
    */
    function AutoComplete_HighlightItem(id, index) // mouseover, index is the list element index, zero-based
    {
        if (__AutoComplete[id]['dropdown'].childNodes[index]) {
            for (var i=0; i<__AutoComplete[id]['dropdown'].childNodes.length; ++i) {
                if (__AutoComplete[id]['dropdown'].childNodes[i].className == 'autocomplete_item_highlighted') {
                    __AutoComplete[id]['dropdown'].childNodes[i].className = 'autocomplete_item';
                }
            }

            __AutoComplete[id]['dropdown'].childNodes[index].className = 'autocomplete_item_highlighted';
            __AutoComplete[id]['highlighted'] = index;

            //also see below...
            //__AutoComplete[id]['element'].value = __AutoComplete[id]['dropdown'].childNodes[index].innerHTML;
            //AutoComplete_SetValue(id);
        }
    }


    /**
    * Highlights the menu item with the given index
    *
    * @param string id    The form elements id. Used to identify the correct dropdown.
    * @param int    index The index of the element in the dropdown to highlight
    */
    function AutoComplete_Highlight(id, index) // keyboard up/down - index is the direction of travel, 1==down,-1=up
    {
        var childNodes = __AutoComplete[id]['dropdown'].childNodes;
        if(childNodes.length)
        {
	        var lastItem = ( ( childNodes[ childNodes.length - 1 ].className != 'autocomplete_footer' ) ? childNodes.length - 1 : childNodes.length - 2 );

            // Out of bounds checking
            //if (index == 1 && __AutoComplete[id]['highlighted'] == __AutoComplete[id]['dropdown'].childNodes.length - 1) {
            if (index == 1 && __AutoComplete[id]['highlighted'] == lastItem ) {
                childNodes[__AutoComplete[id]['highlighted']].className = 'autocomplete_item';
                __AutoComplete[id]['highlighted'] = null;

            } else if (index == -1 && __AutoComplete[id]['highlighted'] == 0) {
                childNodes[0].className = 'autocomplete_item';
                __AutoComplete[id]['highlighted'] = lastItem;
                index = 0;//hack!
            }

            // Nothing highlighted at the moment
            if (__AutoComplete[id]['highlighted'] == null) {

                childNodes[0].className = 'autocomplete_item_highlighted';
                __AutoComplete[id]['highlighted'] = 0;
                newIndex = 0;
                
            } else {

                if (childNodes[__AutoComplete[id]['highlighted']]) {
                
                    childNodes[__AutoComplete[id]['highlighted']].className = 'autocomplete_item';
                }

                var newIndex = parseInt( __AutoComplete[id]['highlighted'] ) + parseInt(index);

                if (childNodes[newIndex]) {

                    childNodes[newIndex].className = 'autocomplete_item_highlighted';

                    __AutoComplete[id]['highlighted'] = newIndex;
                }
            }

            //populate textbox with currently highlighted term...
            //__AutoComplete[id]['element'].value = __AutoComplete[id]['dropdown'].childNodes[newIndex].innerHTML;
            AutoComplete_SetValue(id);
        }
    }


    /**
    * Sets the input to a given value
    *
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
    function AutoComplete_SetValue(id)
    {
        __AutoComplete[id]['element'].value = __AutoComplete[id]['dropdown'].childNodes[__AutoComplete[id]['highlighted']].innerHTML.replace(/&amp;/, "&");
    }


    /**
    * Checks if the dropdown needs scrolling
    *
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
    function AutoComplete_ScrollCheck(id)
    {
        // Scroll down, or wrapping around from scroll up
        if (__AutoComplete[id]['highlighted'] > __AutoComplete[id]['lastItemShowing']) {
            __AutoComplete[id]['firstItemShowing'] = __AutoComplete[id]['highlighted'] - (__AutoComplete[id]['maxitems'] - 1);
            __AutoComplete[id]['lastItemShowing']  = __AutoComplete[id]['highlighted'];
        }

        // Scroll up, or wrapping around from scroll down
        if (__AutoComplete[id]['highlighted'] < __AutoComplete[id]['firstItemShowing']) {
            __AutoComplete[id]['firstItemShowing'] = __AutoComplete[id]['highlighted'];
            __AutoComplete[id]['lastItemShowing']  = __AutoComplete[id]['highlighted'] + (__AutoComplete[id]['maxitems'] - 1);
        }

        __AutoComplete[id]['dropdown'].scrollTop = __AutoComplete[id]['firstItemShowing'] * 15;
    }


    /**
    * Function which handles the keypress event
    *
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
    function AutoComplete_KeyDown(id, e)
    {
        var result = true;

       var event;
       event = e;
       if(!event) event = window.event;

        var keyCode = event.keyCode;

        switch (keyCode) {

            // Return/Enter
            case 13:
                if (__AutoComplete[id]['highlighted'] != null) {
                    AutoComplete_SetValue(id);
                    AutoComplete_HideDropdown(id);
					
                    __SLI_asug_used_flag = true;
					
                    if( e = __AutoComplete[id]['element'].form['asug'] )
                    {
                        
                        e.disabled=false;
                        e.value = __AutoComplete[id]['asug'];
                    }

                }

                result = AutoComplete_submitForm(id);

                break;

            // Escape
            case 27:
                AutoComplete_HideDropdown(id);
                event.returnValue = false;
                event.cancelBubble = true;
                break;

            // Up arrow
            case 38:
                if (!__AutoComplete[id]['isVisible']) {
                    AutoComplete_ShowDropdown(id);
                }

                AutoComplete_Highlight(id, -1);
                AutoComplete_ScrollCheck(id, -1);
                
                if( e = __AutoComplete[id]['element'].form['asug'] )
                {
                   e.disabled=false;
                   e.value = __AutoComplete[id]['asug'];
                }

                                
                result = false;
                break;

            // Tab
            case 9:
                if (__AutoComplete[id]['isVisible']) {
                    AutoComplete_HideDropdown(id);
                }
                return;

            // Down arrow
            case 40:

                if (!__AutoComplete[id]['isVisible']) {
                    AutoComplete_ShowDropdown(id);
                }

                AutoComplete_Highlight(id, 1);
                //AutoComplete_ScrollCheck(id, 1);

                if( e = __AutoComplete[id]['element'].form['asug'] )
                {
                   e.disabled=false;
                   e.value = __AutoComplete[id]['asug'];
                }

                result = false;
                break;
        }
        return result;
    }


    /**
    * Function which handles the keyup event
    *
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
    function AutoComplete_KeyUp(id, e)
    {
       var event;
       event = e;
       if(!event) event = window.event;

        var keyCode = event.keyCode;

        switch (keyCode) {
            case 13:
                event.returnValue = false;
                event.cancelBubble = true;
                
                break;

            case 27:
                AutoComplete_HideDropdown(id);
                event.returnValue = false;
                event.cancelBubble = true;
                break;

            case 38:
            case 40:
                return false;
                break;

            default:
                AutoComplete_ShowDropdown(id);
                
                __AutoComplete[id]['asug']=__AutoComplete[id]['element'].value;

                if( e = __AutoComplete[id]['element'].form['asug'] )
                {
                   e.disabled=true;
                   e.value = "";
                }  
                
                break;
        }
    }

    /**
    * Function which handles the keypress event
    * This function added April 2008 by Andrew Grieve
    *
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */

    // SLI Code Modification - Start - Andrew Grieve April 08
    function AutoComplete_KeyPress(id, e)
    {
        var event = e;
        if(!event) event = window.event;
        var keyCode = event.keyCode;

        if (keyCode == 13 && isGecko || isOpera)
        {
            return false;
        }
        
        if( __SLI_customisations[ __SLI_ApplicationName ][ 'TargetURL' ] )
        {
            if (keyCode == 13 && isIE)
            {
                return false;
            }
        }
        
    }
    // SLI Code Modification - End

    /**
    * Returns whether the dropdown is visible
    *
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
    function AutoComplete_isVisible(id)
    {
        return __AutoComplete[id]['dropdown'].style.visibility == 'visible';
    }

    function AutoComplete_submitForm(id)
    {
        var e, f, result=true;
        if( f = __AutoComplete[id]['element'].form )
        {
            if( __AutoComplete[id]['element'].value != '' )
            {
            	if(__SLI_asug_used_flag == true)
            	{
                   if( e = f['asug'])
                   {
                      e.value = __AutoComplete[id]['asug'];
                      e.disabled=false;
                   }
                }
                
                if( __SLI_customisations[ __SLI_ApplicationName ][ 'TargetURL' ] )
                {
                	asugvar = "";
                	if(__SLI_asug_used_flag == true)
                	{
                	  asugvar = '&asug=' + __AutoComplete[id]['asug'];
                  	}
                    
                    sliRegex = /resultsdemo\.com/;
                    if(sliRegExArray = sliRegex.exec(document.domain))
                    {
                    	sliRegex = /^http:\/\/(.*)\//;
                    	sliTargetDomain = sliRegex.exec(__SLI_customisations[__SLI_ApplicationName ][ 'TargetURL' ]);
                    	__SLI_customisations[__SLI_ApplicationName ][ 'TargetURL' ] = __SLI_customisations[__SLI_ApplicationName ][ 'TargetURL' ].replace(sliTargetDomain[1], document.domain);
                    }
                    
                	document.location.href = __SLI_customisations[__SLI_ApplicationName ][ 'TargetURL' ] + __AutoComplete[id]['element'].value + asugvar;
                }
                else
                {
                	f.submit();
                }
                
                AutoComplete_HideAll();
            }
            else
                result = false;
        }
        return result;
    }
    
    // get the style that will be applied by the browser, including stylesheets
    function sli_getStyle(el,styleProp)
    {
      if (el.currentStyle)
        var y = el.currentStyle[styleProp];
      else if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
      return y;
    }

    // register with onLoad(er...
    _sli_init.push( AutoComplete_init );
    
    function sli_addEvent(obj, evType, fn) {
    	if (obj.addEventListener) {
    		obj.addEventListener(evType, fn, false);
    		return true;
    	} else if (obj.attachEvent) {
    		var r = obj.attachEvent("on" + evType, fn);
    		return r;
    	} else {
    		return false;
    	}
    }
    
    function sli_load()
    {
    	sli_addEvent(window, 'load', sli_init);
    }