function AutoCompleteDB()
{
	// set the initial values.
	this.bEnd = false;
	this.nCount = 0;
	this.aStr = new Object;
}
 
AutoCompleteDB.prototype.add = function(str)
{
	// increment the count value.
	this.nCount++;
 
	// if at the end of the string, flag this node as an end point.
	if ( str == "" )
	{
		this.bEnd = true;
	}
	else
	{
		// otherwise, pull the first letter off the string
		var fletter = str.substring(0,1);
		var rest = str.substring(1,str.length);
		
		// and either create a child node for it or reuse an old one.
		if ( !this.aStr[fletter] ) this.aStr[fletter] = new AutoCompleteDB();
		this.aStr[fletter].add(rest);
	}
}
 
AutoCompleteDB.prototype.getCount = function(str, bExact)
{
	// if end of search string, return number
	if ( str == "" )
		if ( this.bEnd && bExact && (this.nCount == 1) ) return 0;
		else return this.nCount;
	
	// otherwise, pull the first letter off the string
	var fletter = str.substring(0,1);
	var rest = str.substring(1,str.length);
	
	// and look for case-insensitive matches
	var nCount = 0;
	var lLetter = fletter.toLowerCase();
	if ( this.aStr[lLetter] )
		nCount += this.aStr[lLetter].getCount(rest, bExact && (fletter == lLetter));
	
	var uLetter = fletter.toUpperCase();
	if ( this.aStr[uLetter] )
		nCount += this.aStr[uLetter].getCount(rest, bExact && (fletter == uLetter));
	
	return nCount;	
}
 
AutoCompleteDB.prototype.getStrings = function(str1, str2, outStr)
{
	if ( str1 == "" )
	{
		// add matching strings to the array
		if ( this.bEnd ) 
			outStr.push(str2);
 
		// get strings for each child node
		for ( var i in this.aStr )
			this.aStr[i].getStrings(str1, str2 + i, outStr);
	}
	else
	{
		// pull the first letter off the string
		var fletter = str1.substring(0,1);
		var rest = str1.substring(1,str1.length);
		
		// and get the case-insensitive matches.
		var lLetter = fletter.toLowerCase();
		if ( this.aStr[lLetter] )
			this.aStr[lLetter].getStrings(rest, str2 + lLetter, outStr);
 
		var uLetter = fletter.toUpperCase();
		if ( this.aStr[uLetter] )
			this.aStr[uLetter].getStrings(rest, str2 + uLetter, outStr);
	}
}
 
 
function AutoComplete(aStr, oText, oDiv, nMaxSize)
{
	// initialize member variables
	this.oText = oText;
	this.oDiv = oDiv;
	this.nMaxSize = nMaxSize;
	
	// preprocess the texts for fast access
	this.db = new AutoCompleteDB();
	var i, n = aStr.length;
	for ( i = 0; i < n; i++ )
	{
		this.db.add(aStr[i]);
	}
			
	// attach handlers to the text-box
	oText.AutoComplete = this;
	oText.onkeyup = AutoComplete.prototype.onTextChange;
	oText.onblur = AutoComplete.prototype.onTextBlur;
}
 
AutoComplete.prototype.onTextBlur = function()
{
	this.AutoComplete.onblur();
}
 
AutoComplete.prototype.onblur = function()
{
	this.oDiv.style.visibility = "hidden";
}
 
AutoComplete.prototype.onTextChange = function()
{
	this.AutoComplete.onchange();
}
 
AutoComplete.prototype.onDivMouseDown = function()
{
	this.AutoComplete.oText.value = this.firstChild.nextSibling.innerHTML+' - '+this.firstChild.nextSibling.nextSibling.nextSibling.innerHTML;
}
 
AutoComplete.prototype.onDivMouseOver = function()
{
	this.className = "AutoCompleteHighlight";
}
 
AutoComplete.prototype.onDivMouseOut = function()
{
	this.className = "AutoCompleteBackground";
}
 
AutoComplete.prototype.onchange = function()
{
	var txt = this.oText.value;
	
	// count the number of strings that match the text-box value
	var nCount = this.db.getCount(txt, true);
	
	// if a suitable number then show the popup-div
	if ( (this.nMaxSize == -1 ) || ((nCount < this.nMaxSize) && (nCount > 0)) )
	{
		// clear the popup-div.
		while ( this.oDiv.hasChildNodes() )
			this.oDiv.removeChild(this.oDiv.firstChild);
			
		// get all the matching strings from the AutoCompleteDB
		var aStr = new Array();
		this.db.getStrings(txt, "", aStr);
		
		// add each string to the popup-div
		var i, n = aStr.length;
		for ( i = 0; i < n; i++ )
		{
			var pdtarr = aStr[i].split("-");
			var sku = pdtarr[pdtarr.length - 1].replace(' ', '');
			var pdtname = aStr[i].replace(' - '+sku, '');
			var oDiv = document.createElement('div');
			this.oDiv.appendChild(oDiv);
			oDiv.innerHTML = '<img src="/pdt_imgs/small_images/'+sku+'-1.jpg" width="40" height="52" align="absmiddle" /><span class="pdtname">'+pdtname+'</span>(<span class="sku">'+sku+'</span>)';
			oDiv.onmousedown = AutoComplete.prototype.onDivMouseDown;
			oDiv.onmouseover = AutoComplete.prototype.onDivMouseOver;
			oDiv.onmouseout = AutoComplete.prototype.onDivMouseOut;
			oDiv.AutoComplete = this;
		}
		this.oDiv.style.visibility = "visible";
		this.oDiv.style.display = "block";
	}
	else // hide the popup-div
	{
		this.oDiv.innerHTML = "";
		this.oDiv.style.visibility = "hidden";
		this.oDiv.style.display = "none";
	}
}

var aNames =
[
"Abeni eyelet dress - 490902AF","Abstract mini skirt - 290801AD","Adara chiffon dress - 490802AH","Addy satin blouse - 190905AC","Adelina polka skirt - 290901AB","Adia star studded dress - 490905BH","Adrina knit dress with belt - 490905AM","Aicel lace back tank - 190905AL","Aiden top with sash tie - 190905AP","Alair fancy jacket - 190906AD","Alexis top - 190906AL","Alizeh top - 190903AI","Amanda party dress - 490802AS","Amber lace skirt - 290904AA","Anna jumper dress  - 490907AO","Ariena skirt - 290906AD","Asher dress with scarf - 490905AI","Ashley floral dress - 490904BA","Autumn bangle - 790902AH","Autumn tree tee - 190906AR","Ava drape top - 190906AJ","Barton career blouse - 190905AI","Basic floral tank - 190907AX","Beadwork drape necklace - 790903AG","Biker jacket - 190905AK","Biker skirt - 290907AB","Bird in cage necklace - 790901AE","Black and gold bangle set - 790901AF","Black heart tank - 190903AP","Black mini shorts - 290904AC","Black satin shorts - 290907AF","Black sequin dress - 490907AP","Black stretch cami - 190903AU","Blackjack tee - 190802AA","Bloom earrings - 790901AR","Blue mini skirt with belt - 290801AG","Body con skirt - 290907AE","Brenda glitter tank - 190902AI","Brie linen shirt dress - 490904AE","Brynne off shoulder dress - 490906ZD","Butterfly charm necklace - 790901AJ","Butterfly necklace - 790901AB","Butterfly tunic - 490906ZI","Camden floral dress - 490904AI","Carmen knit vest - 190905AS","Carter sweater dress - 490905BG","Chain necklace top - 190906AH","Charm bracelet - 790901AI","Chelle halter dress - 490907BA","Cherilyn party dress - 490903AJ","Chiffon top - 190907BG","Chloe knit vest - 190905AM","Chrie tunic - 490906AO","Christie shirt dress - 490903AI","Classic black shrug - 190906ZB","Classic burn out tunic - 490903AG","Classic hot shorts - 290801AP","Classic hot shorts - 290801AQ","Claudine party LBD - 490905AE","Clie slip dress - 490905BE","Coby miniskirt - 290802AF","Constrast cropped cardigan - 190907AU","Contrast woven dress - 490802AR","Coral waistcoat with tank - 190907AZ","Cowl neck fitted dress - 490801BE","Cowl neck lbd - 490907AI","Cropped fancy jacket - 190906AC","Crown locket watch necklace - 790901AD","Crown pendant necklace - 790902AD","Danse strapless dress - 490906AG","Deep purple snakeskin clutch - 790903AC","Delfi tank dress - 490905AJ","Denim dress with sash tie - 490904AQ","Denim skirt - 290907AC","Destination Paris necklace - 790901AC","Destry skirt - 290903AD","Draped chain tank top - 190904AL","Dusty pink babydoll top - 190907BF","Elin floral dress set - 490904BO","Ellie floral tea dress - 490905AY","Embellishment necklace - 790903AI","Emilia casual shirt - 190905AD","Eva satin halter dress - 490903AL","Floral brooch - 790901AN","Floral brooch - 790901AO","Floral earrings - 790901AQ","Floral earrings - 790901AT","Floral earrings - 790901AU","Floral hoodie - 190906AK","Floral mini skirt - 290906AF","Freda bustier dress - 490902AL","Fringe LBD with embellishments - 490906AE","Fronda floral dress - 490905AX","Gabrielle floral dress - 490907BR","Gabrielle jumpsuit - 290802AJ","Garden cutout necklace - 790901AH","Gem dress with sash tie - 490801AQ","Geometric chain necklace - 790902AE","Geometric maxi dress - 490801AO","Georgina belted dress - 490906AK","Giselle floral dress - 490903AE","Glitter woven tank - 190907AB","Goddess chiffon dress - 490906AW","Gold dust top - 190906AB","Gold leather detail bangle - 790902AB","Gold zipper LBD - 490905AD","Gold zipper lbd - 490907BV","Graphic print loose tank - 190907AR","Halter jersey dress - 490802AI","Hearts camisole - 190801AI","Helen dress in blue - 490907BU","Heuer strapless dress - 490801BP","High-waisted shorts - 290802AH","Hipster miniskirt - 290801AJ","Houndstooth play dress - 490906AI","Houndstooth printed dress - 490907AW","Houndstooth skirt - 290907AD","Isabella skirt - 290901AC","Izzy minidress - 490802AN","Jane eyelet dress - 490907CO","Jayla ruffle blouse  - 190802AN","Jillette ruffle blouse - 190903AF","Jive career dress - 490907AK","Jodie sequin dress - 490802AU","Jolene strapless dress - 490905BF","Jolie party dress - 490904BK","Josie polka dress set - 490904BN","Kali ruffle blouse  - 190801BK","Karla blouse - 190906AX","Kate pencil skirt - 290802AC","Kate tunic - 190905AU","Keri floral dress - 490907BX","Knit tank dress with lace vest - 490907BO","Knit tunic tank - 490904BQ","Knit vest with scarf - 190905AO","Kyle tank dress - 490905AC","Lace applique dress - 490906BF","Lace boudoir dress - 490905AR","Lace corset top - 190906AF","Lace minidress - 490802AA","Lace tank - 190905AA","Lace tank - 190905AB","Lace tank - 190906AA","Lace tank top - 190907AM","Lace trim camisole - 190801AQ","Ladybird timepiece necklace - 790901AA","Laine knit dress - 490907AY","Leah camisole - 190905AT","Leather bracelet - 790901AM","Leigh silver LBD - 490905AS","Leigh tunic with diamond belt - 490904BL","Leight knit top - 190906AN","Liam dress in black - 490907BC","Lucky clover necklace - 790901AG","Madison cardigan - 190905AJ","Madison career skirt - 290906AE","Magenta lace corset - 190907AE","Magenta ribbed camisole - 190801AG","Manhattan pencil skirt - 290802AB","Marina Floral Dress - 490907BY","Marykate tunic - 490905AZ","Maya pocket dress - 490906ZF","Meghan lace camisole - 190801AB","Metallic body con dress - 490906AM","Metallic sleeveless dress - 490801BL","Military jacket - 190904AD","Misha skirt - 290905AC","Monochrome bangle - 790902AA","Monochrome roses dress - 490907BI","Monochrome strapless dress - 490906AU","Myca floral dress - 490907AV","Nautical cardigan - 190906AQ","Navy dress with front zip - 490907BH","Navy striped tank - 190907AV","Neon stretch camisole - 190801AH","Nicole mini swing skirt - 290802AE","Nikki military career blouse - 190904AB","Northern star earrings - 790901AS","Nude snakeskin clutch - 790903AD","Off shoulder jersey dress - 490906ZA","Off shoulder jersey dress - 490906ZB","Open back dress with lace detail - 490907CC","Paige geometric print dress - 490904BH","Peach mini skirt with belt - 290801AH","Pearl flower necklace - 790903AE","Pearl neckline dress with sash - 490907AJ","Picadilly dress - 490905BA","Pink key ring - 790901AP","Pinstripe detail dress - 490802AK","Plaid shorts - 290903AC","Plaid tube dress - 490903AB","Pleated organza miniskirt - 290801AM","Polka dot party dress - 490905AK","Polka minidress - 490802AM","Prim dress with embellished belt - 490906AL","Print babydoll dress - 490907BL","Print babydoll dress - 490907CK","Printed Leggings - 290906AC","Racy pink party dress - 490906BD","Rebecca floral dress - 490905AV","Ribbed tank - 190906AZ","Rose beaded necklace - 790902AI","Rose mini skirt - 290801AE","Ruched sleeved dress - 490907AF","Ruffle front floral dress - 490907BP","Ryder skirt - 290903AA","Safari dress with belt - 490905AL","Saffy floral dress set - 490904BM","Samantha linen shorts - 290902AB","Sandra skirt - 290905AB","Satin bustier corset top - 190905AF","Satin corset with sequins - 190907AF","Satin floral shift dress - 490903AT","Satin lace camisole - 190802AI","Satin lace camisole - 190802AJ","Satin lace corset - 190907AO","Satin pleated corset - 190907AG","Saville strapless dress - 490904AK","Scarlet lace dress - 490905AQ","Sequin tank dress - 490906AV","Shaina plaid miniskirt - 290802AL","Sharlize floral dress set - 490904BP","Shimmer striped cardigan - 190904AI","Shoulder detail knit dress - 490906AQ","Shoulder detail knit dress - 490906AR","Silk dress - 490903AM","Silk dress - 490904BE","Silver necklace cocktail dress - 490906AN","Simone skirt - 290903AB","Sky blue linen shorts - 290802AG","Sofia Skirt - 290901AA","Sofia kimono dress - 490901AL","Soft knit striped tank - 190904AO","Soft knit striped tank - 190905AN","Solid 2 piece basic - 190905AH","Solid cami set - 190903AT","Solid knit camisole - 190904AZ","Solid lace camisole - 190904AV","Solid racerback cami - 190903AV","Spring crotchet sundress - 490801AB","Starry Print Dress - 490907AG","Stella pendant necklace - 790901AL","Strapless black dress - 490907BJ","Strapless denim dress - 490906AH","Strapless floral tiered dress - 490907CN","Strapless peach lace dress - 490907CL","Striped shorts - 290801AR","Suede biker jacket - 190906AI","Sugar shift dress - 490906BA","Sweater lbd with necklace - 490907AT","Sylvia LBD with diamond belt - 490903BD","Tie dye dress - 490906BB","Tiered chiffon skirt - 290906AA","Timeless party dress - 490906AF","Tori striped dress - 490907BF","Tri-button black dress - 490907BQ","Trixie play tank - 190907AW","Tropical sundress - 490802AG","Tulle overlay floral dress - 490907BW","Vienna chiffon minidress - 490801CN","Vienna chiffon minidress - 490801CP","Vienna obi dress - 490905AU","Vienna satin dress - 490801CL","White mini shorts - 290904AB","colosseum loose tank - 190907AC","embellished collar jacket - 190907AH","gold trim top - 190907BB","jaime double breasted coat - 190907AN","silver glitter bangle - 790903AH","strapless lace tiered dress - 490907CE"];
