/* Popular phrases - VERMONTTEDDYBEAR - 22:10:54, Fri Mar 19, 2010 */
__SLI_ClientDefaults =
[
    ['TextBoxIDCustom', ['wSearchText'] ],
    ['TargetURL', ['http://great-gifts.vermontteddybear.com/search?ts=v2&w='] ]
];
var asPhrases=new Array ('design your own bear','birthday','get well','custom','army','nurse','outfits','military','classic','angel','romance your valentine bear','pirate','biker bear','doctor','valentine','pregnant','biker','teacher','easter','princess','valentines day','panda','ballerina','donations','baseball','broken arm bear','elvis','tattoo','star trek','bear hospital','classic bear','knight','crutch','prince charming','angel bear','soft bears','police','loverboy','sale','classic teddy bear','life time guarantee','broken leg','army bear','i heart you','anniversary','baby','motorcycle','get well bear','hospital','love bandit','snowboard','panda bear','cancer','koala','bears on sale','say anything','pink bear','broken leg bear','chocolate','nurse bear','cast','wedding','superhero','camo','personalized','fishing','bears','ski','bat mitzvah','new baby','i love you','firefighter','cheerleader','emt','pajamas','vermonter','football','navy','bear cubs','soccer','birthday bear','expecting mother','military bear','grandmother','pajama bear','red rose bouquet bear','all bears','bowtie','plain bear','bride and groom','basketball','easter bear','fishing bear','premium','purple','motorcycle bear','doctor bear','tatoo','cow','prince charming teddy bear','princess bear','business','good wishes','playboy','mother','marine','hockey','sash','i heart','air force','cubs','horse','romeo','twins','golf','cancer bear','cowboy','pilot','guitar bear','lawyer','1st birthday','accessories','pregnant bear','pink','dance','mothers day','cheerleader bear','chef','scrubs','huggable hunk','mother bear','blue','irish','polar bear','graduation','fireman','thank you','birthday suit','gift tag','pirate bear','coupon','big hug bears','handy bear','accountant','spock','wizard','stand','clothes for bears','fire','bandit','hooked on you','personalized bears','juliet','valentines day bear','navy bear','karate','ballerina bear','guitar','pajama gram','misfit','get well soon','sweetheart','alien','bear gram','fairy','leopard','sailor','garden','broken arm','premium fur','tennis','big bear','soldier bear','artist','make your own','tattoo bear','cooking','playboy bunny bear','premium collection','delivery status','feel better','t-shirt','christmas','superstar','redneck bear','volleyball','grandma','i love you bear','redneck','holstein','pregnancy','mamacita','knight in shining armor','puppy','cupid','super hero','22','bunny','pillow','big hug','nurse teddy bear','soldier','misfit bear','roses','pharmacist','police bear','cowboy bear','marine bear','aviator','heart throb','teddy bears','kirk','grandma bear','new baby bear','koala bear','hatch','kaleidoscope bear','cowgirl','birthday suit bear','yoga','secretary','huggable','mom to be','sports','hare','train','tracking','dog','bowling','dentist','love','harley','baby bear','fisherman','scrapbook','big brother','bear-gram','big sister','mom','fur colors','peeps','golfing teddy bears','good wishes fairy','snowboard bear','36','elvis bear','st patricks day','fairytale princess','patchwork','red hat','soccer bear','bear stand','st patrick','swimming bear','kirk and spock bear','coco','cat','graduation bear','fairy bear','puppy love','i heart you bear','feel better bear','basic','prince','purple bear','great catch','tennis bear','workout','shamrock','fallen for you','happy anniversary','create a bear','tuxedo','laptop','red','lacrosse','black bear','workout bear','happy birthday','tough guy','papi chulo','sewing bear','rock','spa bear','birthday cards','flag','custom bears','birthday cake','i love you beary much','music','polar','t shirt','pastel','patchwork bear','wedding bears','twin bears','employment','camouflage','equestrian','star','over the hill','police officer','sweetheart bear','bowtie bear','alien bear','army teddy bear','sunglasses','ive fallen for you','mma bear','grandmother bear','fireman teddy bears','chocolate bear','wildlife bears','basketball bear','teacher bear','tshirt bear','birthday parties','ballet','student','summer','elvis presley','salt','halloween','vet','computer','prince charming bear','swim','golfer bear','snow bear','country','hunk','farmer','hiker','groom','bride','giant bears','country bear','princess teddy bear','pink roses','yellow','loverboy bear','hero','skateboard','race car','motorcycle mama','tool belt','jean bear','beautician','knitting','peace','tshirt','business man','jail bear','football bear','baseball bear','teacher teddy bear','canada','navy teddy bear','harley bear','20','witch','super','romeo and juliet','quilting bear','star trek bear','devil','coco bear','race','yoga bear','chemosabe','leather jacket','dancer','winter','good luck','business woman','camouflage bear','crazy','dancing bears','farmer bear','mama','hiker bear','jacket','society','vermont bear','knight in shining armor bear','sundress','sister','love bandit bear','love rider','purple teddy bear','boots','cow bear','white bear','bib','ems','returns','green','valentine bear','dentist bear','sweater','t shirt bear','mom bear','clown','shirt','construction','bow tie bear','geek','bears that care','jeans','hug','15 bear','name','rattle','valentine day gift card','friend','tag','teddy gram','giant teddy bears','wizard bear','sympathy','hockey bear','fairytale','gardening bear','musician','card messages','chef bear','day at the spa','huggable bear','secretary bear','brown bear','coast guard','desert','tennis racket','name tag','purple passion','flowers','mma','romeo bear','monkey','i heart grandma','udderly in love','carpenter bear','crazy for you vermont teddy bear','hair dresser','bowling bear','ski bear','nascar','anything bear','baptism','suit','fathers day','business bear','softball','get well bear with cast','sailor bear','blue bear','bingo','actress','pink rose bouquet','playboy bunny','engagement','thanksgiving','tooth fairy','crutch bear','fight','ultimate lover','bbq','green bear','playbear','hunting bear','construction bear','smiley','tatoo bear','order','i love you bowtie','sled','waitress','latino bear','plumber bear','life saver','music bear','bearfoot and pregnant','anniversary bear','ballet bear','groom bear','celebration bear','bike','martial','fallen','rocker','hospital bracelet','engagement bear','country lovin','juliet bear','bunny bear','new baby teddy bear','kaleidoscope','pilot teddy bear','art','ballet dancer','pride','sling','small bears','classic teddy','gauze','equestrian bear','maternity bear','bear outfits','big brother bear','hiking bear','lifesaver','bowler','scrapbooking bear','free','desert camo','1st birthday bear','large','fashionista','rocker bear','bearfoot','cello','marry','big sister bear','clown care bear','15 angel bear','make a friend for life bear','i heart tshirt bear','knitting bear','sky blue','hunting','attorney','factory','volleyball bear','patriotic','camping','premium bears','first birthday','balloons','new job','yellow bear','picture','stamp','get well gram','bear with crutches','chickie','cocobear','my hero','prison','train engineer','martial arts','shopping bear','clown care','painter','i love you mom','jewish','gift set','go green','dog bear','hooked on you bear','dad','36 bear','toughguy','pharmacist bear','glasses','bandit bear','st patricks day bear','irish bear','3 feet','knight bear','mother to be','heart throb bear','top hat','red bear','grinch','pregnancy bear','cheer','espresso','mexico','camo bear','delivery','horse lover','plain teddy bear','trek','im sorry','i heart bear','norway','ruby red','fire man','teddy bear of the month','shaggy bear','easter chick','crochet bear','super hero bear','bride and groom bear','woolen','kiss me im irish','hair stylist bear','bare bear','beargram','leopard bear','hard hat','pilot bear','engineer','prices','spa','gauze bandage','60 birthday','grizzly','ring bearer','artist bear','sorry','scrubs bear','plum','golfer','baker','amor','country lovin bear','sewing','15 pastel patchwork bear','lady lawyer','quilt','dancer bear','maple','boat','holiday hunk','15 baby bears','easter teddy bears','easter bunny','papichulo','boo bear','moving','i love grandpa','good wishes fairy outfit','graduation teddy bear','bear sweaters','retired bears','fatigues','woolen bear','scuba diving','bedtime','race car driver','cop','lifetime guarantee','white','romantic at heart','karate bear','cancer survivor','fisherman bear','captain kirk','puppy bear','white t shirt','hare bear','cupid bear','ruby','red velvet','veterinarian','cooking bear','spanish','witch bear','emt bear','teeth','papa bear','mother goose','rainbow','christmas redneck','holiday','virgo','red devil bear','easter basket','bad','rainbow bear','conversation','spa teddy bear','jumbo','friendship','alien teddy bear','blue without you','lumberjack','moon','get well teddy bear','love biker','babys first birthday','wedding anniversary','red neck','playboy bear','get well soon tag','valentine outfits','hockey player','biker mama','skateboard bear','hockey teddy bear','society lady','heartthrob','mohair','bears with flags','wings','hiking','nametag','rebel','beary','shopping','15','spock bear','congratulations bear','high society','red hot redneck','sash bear','superstar student','polka dot','teddy','bunting','crown','writer','bear t-shirts','candle','chemo','recycle','work out bear','birthday cake hottie','blue without','hair','train engineer bear','valentine tag','valentine teddy bears','motorcycle mom','lumberjack bear','basket','luck','valentine bear for him','barack','i love you beary','romantic','blanket','lover','valentine\'s bear','scottish bear','birthday hottie','hottie','birthday hunk','lawyer bear','fifty birthday','bahama mama','pink rose bouquet bear','santa claus bear','fairytale princess outfit','black','classic christmas bear','moments to remember','extra large bears','new home bear','under $5','new home','black tie','clown doctor','get well kids','scarecrow','lawyer teddy bear','valentine big bear','hooked','100','pink bouquet','vermont maple syrup','embroider','valentines day outfits','design a bear','boxing teddy bear','valentines teddy bear for him','new mom','greece','cell phone','i\'ve fallen for you bear','shopper','german','premium teddy bear','babys first christmas','attitude','valentines day gifts','valentine cards','chef outfit','birthday cake hunk','toys','bear in a suit','baby sweater bear','momma bear','fun at one','shopper bear','bare','sick','army teddy','birthday sash bear','valentine birthday','ted head','fashion bear','valentines for her','love you','valentine bears for mom','over the hill bear','best friend','backpack','baby sweater','brother','valentine\'s outfits','valentine shorts','bow-tie birthday bear','writer bear','chef hat','goose','boxing gloves','football player','valentine gifts for a man','life size','baby first valentine','i\'ve fallen','valentine gifts','racecar','lady golfer','rose bear','hobbies','valentines day for her','bride bear','renaissance','broken arm get well bear','valentines day delivery','cancer sucks','monkey bear','party','shamrock sweetheart','i love you beary much bear','father to be','black and white bear','bewitching bear','celebration','snow day','te amo','ultimate','cupcake','scuba bear','happy camper','smiley scrubs','cat lover','birthday cake bear','all american','chemo bear','prayer','bear on crutches','mom\'s birthday','new baby gift','poker player','good luck bear','skier bear','snow day family','panda teddy bear','superstar bear','christmas bears','service','get','chic','cuddly','martial arts outfit','tattooed tough guy','small heart box','construction worker','get well soon bear','guarantee','peace sign bear','high school graduation','pot of gold','blue vermont teddy bear','heart beat teddy bear','broken bear','valentine\'s for mom','tattooed toughguy','st.patrick','pcnch0073','papi','mom for president','india','plush','business lady','cake hottie','blue and green bear','your special','xmas bears','i heart you t-shirt','small box of chocolates','order a bear gram','you had me at cello','8','custom teddy bear','blank','partner','black pants','smiley scrubs bear','i heart t-shirt bear','babys first valentine bear','prayer bear','patchwork teddy bear','i heart you personalized t shirt','bear foot and pregnant','chef teddy bear','softball player','pink rose bear','birthday hat','bear and chocolates set','birthday gift tag','barefoot','prego bear','birthday outfit','birthday clip art','prisoner of love','tank top','high society bear','buddy','baby\'s first valentine','bib outfit','happy birthday bowtie','ballerina teddy bear','bear in a cast','horse shirts','sweetest bear','children\'s','spain','birthday bowtie','baby birthday','chanukah bear','black hat','snow family cub bear','bicycle','smile bear','greece flag','say anything t-shirt bear','happy birthday bowtie bear','star trek spock bear','santa\'s helper','birthday cake hunk gift set','baby safe bears','civil union','snow owl','christmas hunk bear','happy birthday gift tag','birthday accessories','huge','soldier teddy bear','baby first valentine day','say anything tshirt','heart t-shirt','personalized card','st pat','blue floral','child','bear shirt','bear in birthday suit','bear with flowers','get well teddy','happy first birthday','great','birthday tshirt','brown birthday bear','crutch accessory','birthday skin','buddha','big teddy','bear fur','german shepherd','bear-gram gift','happy valentines day gift tag','helper','gifts for him','baby 1st birthday','bear-foot and pregnant','sweden','bears for guys','big sister t-shirt','happy valentines day bear','heartthrob bear with tatoo','break a leg','birthday gifts','personal message','personalize tshirt bear','tattooed tough','personalized t-shirt teddy','mom valentine','say anything t shirt bear','pink teddy bear s rose','button','birthday one','baby bear with bib','circus bear','first valentine bear','presidential','bear with tatoo','my valentine','boston terrier','prisoner of love bear','pink valentine bears','get better soon','pink shirt','register','green mountain bears','baby valentine','happy valentines day tag','cat lovers teddy bears','pink bear with roses','bears for children','happy valentines tag','bear foot and pregnant bear','passion bear','horses tshirt','bear glasses','card playing bear','special needs bear','bowtie teddy bear','birthday valentine s day','camo outfit','rose quartz','marine teddy','heart you','baby\'s 1st birthday','papa chulo','free valentine cards','papi bear','cupcake bear','say any','babys first valentine\'s day','colors for bears','babys first birthday bear','hef','classic bear colors','pink bouquet bear','line man bear','say anything t shirt','personalized t-shirts','banana bear','i love you personalized t shirt bear','maple fur','motorcycle teddy bear','st valentine','plain tshirt','i heart shirt','grey','cupid teddy','to from tag','cell phone bear','lacrosse player','big brother t shirt bear','bear kits','baby\'s first bear','i heart you teddy bear','gloves','bear in scrubs','i heart you beary much','pastell','her','birthday dress','grace','bear with guitar','baby\'s 1st birthday bear','milk','birthday t shirt','bow tie teddy bear','happy valentine\'s','heart personalized','bears for dance lovers','lets get bear','session proof love','i fallen for you bear','bear paws','rescue','lilac','special offers','get well soon pillow','paisley','teddy t-shirt','gift','heart throb bear with tattoo','mixed martial arts','personalized football bear','lace','bears for kids','tiny','make own','purplepassion','card playing teddy bear','fallen bear','free teddy bears','send a bear gram','ms bear','superstar outfit','physician','i love you t shirt bear','i love you bowtie teddy','treasure','birthday princess','train engineer outfit','christmas sweetheart outfit','boxers for bears','cub set','super soft','rock bear','service bear','bears for soldiers','review order','fallen for','bears for dogs','pop','t shirt bear marine','golden bear','health and hope bears','chateux','mexico bear','cloud','marine tshirt','bowtie teddy','fatigue bear','i ve fallen for you bear','for teachers','teddy bears for guys','men bears','backpack bear','smile','christmas tree lumberjack','sun flower','his and hers','submissive bear','sage','i\'ve','biker mom','black tshirt','t-shirt bear custom','camo pants','valentine\'s day messages','i love you tshirt bear','scuba diving bear','mourning','personalized teddy','biker motorcycle','heart shorts','personize order','felt tags','gardening hat','gift box','construction hat','bow-tie','bears for horse lovers','globe','personalized items','cyclist bear','scrub teddy bear','simple','pirate teddy','best bear','bear sized red velvet','bear with shirt','bears on the air','bear with baby','mom valentine bear','biker teddy bear','motor','personalized tshirt','military teddy','valentine anniversary','valentine boxes','valentine\'s card','harley teddy','get well bow tie bear','i love heart','hygenist','poker player bear','red fur bears','police teddy','bear in camo','cake hat','birthday t-shirt','personalized bear shirt','for guys','blue valentines bear','teddy bear shop','shamrock sweetheart outfit','fisherman outfit','team','bears with wings','cookingbear','mom-to-be bear','bear eye color','classic bow tie','cupid t shirt bear','flower tag','star bear','biggest','stuffing','make up','cocoa wool','rolling','satin','valentine accessories','carrie','chocolate roses','collectable bears','bear in blue dress','bear with name on it','i feel','star of david necklace','psychedelic peace sign','i horses','sailor suit','convers','better','birthday cake slice','baby christmas','bride outfit','pregnant teddy','baby bear bib','baby bear bunting','heart get well','poland','bear with pink bow','bridal shower bear','bears with t-shirts','cream bear','chef\'s hat','sundress bear','bear with tie','send a bear card','biggest teddy bear','santa little','bearfoot and pregnant bear','chefbear','shag fur bears','snow cub','snow bear family','harley motorcycles','barack t-shirt','st patricks day gifts bears','sending a gram','shag fur','sage go green','boo boo','bears with stars','present','pcnch0075','christmas puppy','santa\'s hat','christmas clothes','classic colors','best boss','cribbage','heart christmas bear','baby bear outfits','snow fur','spanish valentine','bears breaking news','stuffed pandas','christmas angel','cake candle','special coupons','birthdaygirl','classicteddybear','bears under 50','pink bib','painting bear','bear list','bear in bikini','category','baker hat','bear cap','can i wash my bear','bear bunting','special birthday','bear in tuxedo','career woman','blue floral dress','#1 fan','bear hug bear','pgf334','pink top','big brother 2009','bridge playing bear','black sunglasses','box candy','christmas elvis','#1 dad','baby valentine bear','personalized gift tag','pink shorts','survive','perfect overall','childrens clothing','she works hard','baby 1 year','capoeira','be my bear','cupidbear','babys first valentine\'s','sash i love','bear for a baby birthday','separate boxes','#36');
/* $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);
    }