/* Popular phrases - VERMONTTEDDYBEAR - 22:24:43, Sat Jan 28, 2012 */
__SLI_ClientDefaults =
[
    ['TextBoxIDCustom', ['wSearchText'] ],
    ['TargetURL', ['http://great-gifts.vermontteddybear.com/search?ts=v2&w='] ]
];
var asPhrases=new Array ('valentinesdaymobile','design your own bear','giant bears','outfits','panda','bears','newbabymobile','get well','donations','valentine','birthday','angel','big bear','biker bear','pregnant','princess','nurse','valentines day','tattoo','panda bear','cow','all bears','broken leg bear','black bear','large bears','polar bear','getwellmobile','biker','teddy bears','classic','emt','classic bear','marine','angel bear','military','hospital','broken arm bear','karate','koala','teacher','ballerina','bear gram','nurse bear','big hunka love bear','fur colors','pirate','cowboy','doctor','frog','hoodie footie','chef','police','plain bear','pink bear','princess bear','devil','classic teddy bear','misfit bear','cancer bear','hockey','graduation','bowtie bear','premium fur','cancer','custom','pregnant bear','snowboard','bear colors','grizzly','frog prince','ballerina bear','pillow','army','pharmacist bear','wedding','coupon','personalized bears','get well bear','prince charming','blue bear','i love you','football','misfit','babys first valentines day bear','pajama gram','valentine bear','prince','motorcycle bear','bear with crutches','bear hospital','baby','motorcycle','big hunka','koala bear','cast','overalls','spa bear','premium','martial arts bear','fishing','puppy love','puppy','crazy for you','birthday bear','vampire','accessories','big teddy bears','firefighter','fairy','colors','bear with roses','white teddy bear','mohair','equestrian','bear with broken arm','bride and groom','grandma','broken leg','tuxedo','knight','cat','24','custom bears','holstein','mohair bears','tatoo','4.5 foot bear','wildlife bears','15 bear','pride','music','returns','personalized','soft bears','redneck','construction bear','music bear','sports','big hunka love','giant teddy bears','snowman','hoodie','snowboard bear','cheerleader','devil bear','grizzly bear','polar','make a bear','religious','crutch','doctor bear','design a bear','fireman','bunny','24 bear','playboy','broken arm','sailor','pregnancy bear','pajamas','jumbo','ski bear','mom and cubs','mom','big','air force','huggable hunk','love at first bite','scrubs','boxing','1st birthday','wildlife collection','kids','equestrian bear','christmas kisses','sale','baby bear','green bear','hoodie footie bear','country','anniversary','grandmother bear','penguin','milk chocolate bear','jobs','baseball','navy','pregnant teddy bear','artist','chocolate','first birthday','pink','hoodie footie pajamas','police bear','christmas','army teddy bear','stand','cow bear','employment','chocolate bear','christmas bears','football bear','biggest bear','super hero','ski','black','guitar','graduation bear','coco','mothers day','lab coat','wool','new baby','bear pillow','baby boy','i\'ve fallen for you bear','horse','get well soon','pilot','construction','love','fallen for you','twins','sling','bandit','red teddy bear','happy birthday','lawyer bear','dance','basketball bear','birthday suit bear','hockey player','chef bear','shoes','pink teddy bear','special edition','snowshoe bear','hunka','lawyer','mixed','big hug','premium collection','bride','basketball','hair stylist','giant','ufc bear','golf','navy teddy bear','rainbow','grandmother','create a bear','mother to be','white bear','swim','i love you bear','retirement','softball','spa','fisherman','pregnancy','15 classic','soccer','vermonter','coast guard bear','army bear','birthday suit','harley bear','valentine teddy bears','lifetime guarantee','cop','big brother','romeo','spanish','huge bear','20','nurse teddy bear','marine teddy bear','6 bear','soccer bear','boxing bear','grandma bear','superhero','bedtime','father bear','boxing gloves','monkey','cowboy bear','devil angel','knight in shining armor bear','ballet','office','birthday parties','gardening bear','halloween','36 bear','everything grows with love bear','be mine','premium bears','bow','woolen','fallen for you bear','teddy bear donations','bowtie','i\'ve fallen for you','cowgirl','artist bear','emt bear','knight in shining armor','fairy bear','loverboy bear','green','dancing bears','valentine bear outfits','puppy love bear with puppy','udderly','bingo','pink rose bouquet bear','navy bear','weight lifter','bear outfits','chef\'s outfit','woolen bear','easter','leopard','shopping bear','chemo bear','hunting bear','train engineer bear','red bear','retired bears','mom time spa bear','teacher bear','fishing bear','black and white bear','hope bear','snow','holstein bear','cheerleader bear','new baby bear','crazy for you bear','overall bear','pirate bear','skateboard','bear-gram','camo','frog prince bear','all','st patricks day','nascar','cooking','big sister','mixed bear','fashion bear','6 giant bear','tattoo bear','clown bear','fallen','teddy bear hospital','trucker','boots','camo bear','thinking of you','heart','careers','wrestling','hunka love bear','beach bear','loverboy teddy bear','sapphire','pajama bear','blue hoodie bear','first birthday boy','jointed teddy bear','sympathy','cop bear','farmer','farmer bear','harley','police officer bear','beach','firefighter bear','accountant','boy','air force bear','will you marry me','expecting','bar mitzvah','jeans','15','hero','vest','good wishes','scuba','vet','36','cowgirl bear','snowman bear','golf bear','new','sick bear','ring bearer','udderly in love','gift card','pajama pillow','taekwondo','prince charming bear','huggable hunk bear','i love you teddy bear','bandage','volleyball bear','red','train','casino bear','yellow bear','salt and pepper bear','horseback riding','knight bear','train engineer','valentines day bear','i love mom','basketball outfit','blue hoodie footie bear','happy birthday bear','handcuffs','large','garden','loverboy','mother and cubs','soldier','huge','love bandit','bow tie','gay bear','fireman teddy bears','ultimate lover','winter','eye color','baptism bear','fireman bear','hope','roses','hair','bat mitzvah','tattooed tough guy','pilgrim','lacrosse bear','skier','pride bear','new mom','sorry','4.5 bear','sun bear','i love you bow tie bear','tuxedo bear','red neck bear','pajamajeans','hunk','wedding bears','thank you bear','tracking','black teddy bear','peace bear','tough','you\'re a knockout bear','bingo bear','engagement','librarian','electrician','recycle','t shirt bear','fairytale','bride and groom bear','painter','mom bear','orange','guarantee','save the bear collection','bear with cast','bear with arm cast','causes','animal bears','bun','conversation heart bear','feet','2012 bears','good fairy bear','on sale','phone','rabbit','softball bear','pregancy','you\'re a knockout','bears for children','huggable','gym bear','4.5','handy','quilt','communion','aviator','clothes for bears','hug','20 bears','robe','beach babe','family','tennis bear','personalize paw','lover boy','sweetheart','volleyball','always on the go','martial arts','i heart you bear','school','bare bear','we love you','prison bear','lollipop','romantic','marathon','catch','custom teddy','cartoon','add a name','stuffed penguin','mother bear and cubs','10 birthday','custom teddy bear','my heart pounds for you','valentine gifts','bears with dresses','proposal','personalizable','mommas boy','big sister big brother','tool belt bear','baptism','miss you','yoga','peace','6','computer','bow tie bear','t shirt','western','aviator bear','engineer','bunny bear','karate bear','mother bear','hypoallergenic','hoodie bear','flowers','prices','hair dresser','panda hoodie footie','mother','bear with wings','buttercream bears','thank you','sailing','beard','red neck','15 premium bear','running','irish','bar mitzvah bear','go green','caramel','pink rose bear','comfort','miniature teddy bears','kids bears','small teddy','chemosabe bear','children\'s pjs','ka0108','i ve fallen for you bear','first valentine','love rider','child teddy bears','hobbies','chinese','dark chocolate','sweetheart hoodie','bow bear','exercise bear','friend for life','eskimo','tee shirt','clown','mothers day bear','sister','bikini','st patrick','football teddy bear','jewish bear','sweatshirt','arctic bear','heart throb','shamrock','prison','fire','digital camo','honey bear','calculator','dental','rose bouquet bear','congratulations','blue sapphire','fairy wishes','tie','baby\'s first valentine','bandit bear','country teddy bears','dental hygenists','teddy t-shirt','chocolate fur','fire man','guys','jewel tone fur colors','weight lifting','heart t-shirt bear','marriage','mma bear','winter whimsy','4.5 foot','bowler','dental hygenist bear','sage','red hat bear','christmas teddy bears','blue hoodie footie','snowshoe','car','sweetheart bear','elephant','wild style panda hoodie-footie','personalize bear paws','4.5 feet','kinds of bears','italy','groom bear','st patricks day bear','binary','fly','with crutches','love struck love bandit','seal','mother to be bear','heart pillow','camouflage bear','traditional bear','make up bear','plain','glasses','anniversary bear','get well gifts ideas','tiara','mother goose','soccer teddy bear','50th birthday','plumber','factory','tutu','zodiac bear','bib','baker','engineer bear','hard hat','field hockey','candy','cyclist','handyman','bicycle bear','apple','tough guy bear','free vermont cards','motor','hoodie footie bear with pink roses','spanish bear','name','handy no tools bear','hoody footy teddy bear','hoodie-footie bear','gay','6 teddy bear','toddler pajamas','birthday gifts','large teddy bear','white t shirt','fathers day gifts','knight armor','personalization on paws','boat','dentist','10 bears','yellow','graduation cap','on the go bear','race car','kung fu','movie','music box bear','brush','tattoo personalization','edition','medium teddy bear','crazy for you vermont teddy bear','i love you pillow','100% wool','marriage proposal','fire bear','farmer teddy bear','15 lover boy teddy bear','plain teddy bear','scrubs bear','casino','fabric teddy bear','bearfoot and pregnant','swimming bear','nightie','basic bear','chanukah bear','american','honey','shirt','love struck','old bears','tough bear','heart racer','stylist','black dress','sibling','valentine outfits','chemotherapy','tuxedo outfit','spa ma bear','struck','goatee','gambling bear','santa bear','duck','spa day bear','shopper','ice cream','patrick','good well','monkey bear','send bear to hospital','care bear','knitting bear','sewing','11','say anything bear','knitting','pink hoodie footie','skateboard bear','bracelet','soft teddy bears','bowling bear','ive fallen for you outfit','take along','grad','neck tie','angel bear outfit','vermont premium collection','first birthday bear','yoga bear','prince charming teddy bear','embroidery','chef hat','lucky','hockey jersey','personalized shirt','grandma teddy bear','hunk of love','brownstone bear','feel better','velvet dress','grandfather bear','all american','black fur bear','bride teddy bear','embroider','veterinarian bear','i heart','germany','vermont teddy bear pjs','bike','bear with christmas tree','pink fur teddy bear','wish bear','l','plastic','get well bears for kids','baby\'s 1st birthday','sports teddy bears','addison','biggest','biggest teddy bear','beautician bear','red bow','15 love at first bite bear','giant grizzly bear','new baby teddies','baby teddy','maple syrup','addison bear','necklace','big teddy','purple outfits','cub bear outfits','lacrosse','first christmas','bears for him','equestrian outfit','make a friend for life','bridal veil','your my hero','teddy bear with crutch','broken arm get well','larger bears','floral','love tattoo bear','greece','poland','happy anniversary','pink hoodie','construction hat','all natural','good wishes bear','holstein cow','happy day bear','snow man bear','3 teddy bear','mohair bears addison bear','all american bear','cupcake bear','15 biker bear','#1 mom','prego','christmas outfits','babys first christmas','valentine\'s','snowmanbear','gay teddy bear','i love you personalized t-shirt bear','snowman outfit','vermont teddy bear hospital','waitress','babies first bear','thank','let it snow man','sweetest bear','baby bib','15 hoodie footie bear','club','cancer awareness','broken right leg','bear in a cast','infant pjs','crazy for christmas','christmas gifts','birthday cards','programmer','grandkids','st nick','birthday outfit','hair bow','sail boat','christmas present pillow','pj for bear','christmas cow','christmas bedtime bear','christmas sweetheart bear','st.nick bear','christmas accessories','chicken soup','smile bear','shoes for bears','bedtime bear with puppy','bear with chocolate','christmas cards','sailor teddy','christmas pajamas','christmas cow bear','bear ears','birthday hat','premium teddy bear','suede','baby\'s 1st christmas','babys first christmas bear','st nick bear with reindeer','bear holding flowers','christmas delivery','birthday christmas','super soft','christmas elf bear','barbecuing','christmas bedtime bear with puppy','bear with penguin','be bear','salt bear','bear with bow tie','christmas big hug','bear size flowers','blue christmas bear','pin','christmas stocking bear','softest','christmas sweetheart','big bear collection','babys first birthday','cinnamon bear','chanukah sweater','pajamas only','classic large','bed time','birthday teddy','bear with a pocket','spirit bear','sweden','send a bear-gram','present','ballerinabear','clip art t-shirt','snowman teddy bear','premium fur colors','birthday t-shirt','christmas bear outfits','snowman bear outfit','christmas bedtime','babies first teddy bear','buddha bear','birthday cake','classic bowtie','blue hoodie-footie bear','plain teddy','babys first xmas','cow teddy','personalized bib','christmas sweater','boston terrier','cancer survivor bear','capoeira','present pillow','christmas pillow','sweet bear','sweet 16 birthday','birthday suit teddy bear','bear accessories','birthday cake candle','plaid bear','survivor bear','plain white tee shirt','send a birthday card','pink ribbon bear','birthday bear with sash','black tie','be appy','birthday cake hottie','clogs','christmas hunk','christmas hat','bow-tie birthday bear','christmas redneck','birthday cake bear','blue christmas','bearbones','born in vermont','blue for you bear','cast on leg','baby boy teddy bear','bow colors','christmas family','baby birthday','pencil','bear paws','baby shower bear','bear in shining armor','birthday shirt','buddha','bear with vest','personalized teddy','bears for women','puerto rico','christmas bear hug','country western bear','baby blue','baby 1st christmas','baby 1st birthday','baby get well','baby boy first birthday','baby\'s','presidential','bear with heart beat','bowtie teddy','black mask','bear of the month','be mine valentine bear','birthday pillow','bear with white dress','bride-bride','birthday candle','baby first valentine','babe','burglar','bear with sunglasses','bear in love','birthday princess','big hug maple','birthday bear with necklace','personalized birthday bear','bear with overalls','bear in bathing suit','broken bone bear','birthday for men','birthday hunk','birthday cake hat','bubbles','comfort bear','peace sign shirts','blocks','plain t-shirt','bear pads','be my valentine bear','personalized valentine bears','baby first valentine day','baby valentine','babys first valentine\'s day','child\'s bear','sign up','birthday bowtie bear','be mine valentine','bandit mask','button eyes','capricorn bear','sweetheart bear with roses','cottage collectables','bear with pj','parrot bear','salsa bear','birthday hottie','pregnant baby','boobear','big and tall','prince charming with glass slipper','band aid bear','bear with a cane','bear parts','blue apron','super soft bear','pink rose bouquet bear with small box of chocolates','classis bear','bedtime outfit','personalized tatoo','​valentines day gifts','babys first birthday bear','by price','bear in birthday suit','personalized sash','baby\'s first valentines day','bear sweatshirt','blue valentines bear','basics with jeans','birthday quotes with flowers','shirts for bears','christmas sets','blow dryer','pajama teddy','pregnant outfit','christmas sweetheart outfit','christmas greetings','christmas personalized bears','christmas classic bear','board shorts','baby christmas','snow day dad','christmas mom','send back bear');
/* $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);
    }
