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 =
[
"Ava drape top - 190906AJ","Black dress with lace detail - 490907CD","Black halter dress - 491001AY","Black keyhole dress - 471001AA","Black lace leggings - 291001AD","Black satin shorts - 290907AA","Black sequin dress - 490907AP","Black stretch cami - 190903AU","Black tank with brooch - 190907AT","Body con LBD - 490906AD","Brenda glitter tank set - 190902AI","Butterfly charm necklace - 790901AJ","Cream floral dress - 491002AM","Cream floral skirt - 291001AA","Drape dress - 490906AZ","Floral earrings - 790901AQ","Floral earrings - 790901AT","Floral earrings - 790901AU","Fuschia sweetheart dress - 491002BO","Hipster miniskirt - 290801AJ","Houndstooth play dress - 490906AI","Josie polka dress set - 490904BN","Kai embroidered dress - 491002BL","Leah camisole - 190905AT","Magenta ribbed camisole - 190801AG","Manda lace lbd - 491002BN","Meghan lace camisole - 190801AB","Mei strapless dress - 471001AK","Mich floral skirt - 291002AB","Nat lace babydoll dress - 471001AR","Obi waist strapless dress - 490906AS","Paige geometric print dress - 490904BH","Pearl drape necklace - 791001AE","Plaid strapless dress - 490903AB","Polka minidress - 490802AM","Rainbow striped dress - 491002AG","Rosette jersey dress - 491001BL","Satin lace corset - 190907AO","Siet tank top - 190907BH","Skull trim shorts - 290801AN","Sky blue linen shorts - 290802AG","Sofia Skirt - 290901AA","Solid cami set - 190903AT","Solid knit camisole - 190904AZ","Solid lace camisole - 190904AV","Solid racerback cami - 190903AV","Strapless floral dress - 491002BP","Striped maxi dress - 491001AZ","Tri-button career dress - 490907CG","Vienna chiffon minidress - 490801CN","Vienna chiffon minidress - 490801CP","Vienna obi dress - 490905AU","adeline black top - 691001AG","alexa lace dress - 491002BD","anchor printed skirt - 291003AH","ange mixed fabrics dress - 491007BJ","anne khaki halter dress  - 491006AL","anya striped top - 191004AP","bar satin and chiffon dress - 491006AA","basic knit cardigan - 191004AS","basic slub tank - 191003BF","beige chiffon dress - 491006BC","beige lace dress - 491003CB","beige swing vest - 191002AO","belle floral dress - 491004AI","black and silver tunic - 191004AJ","black bodycon mini - 291003AF","black chiffon romper - 291004AI","black corsage chiffon dress - 491006BF","black cutout crop tee - 171004BA","black dress with shoulder detail - 491001BO","black racerback cut out dress - 471002AE","black satin cutout dress - 491007BE","black shimmer dress - 491007AL","black slip with scarf - 491006AI","black tiered trapeze dress - 491007AF","black trapeze dress - 491006AD","blair linen blouse - 191006AA","blue slouchy tee - 191007AD","blue swing vest - 191003AP","boyfriend cardigan - 191003AV","braided one shoulder swing dress - 691001AF","bree striped dress - 491004AR","brit punk tank - 191003AR","brittany denim jacket - 191003BE","bronze oversized bag - 791003AG","brooke striped dress - 491007BC","bunny jumper set - 291006AF","butterfly crochet tank top - 191004AV","caged bodycon dress - 491007AI","caged neckline dress - 471002AN","campbell's printed tank - 191003BA","capri pants with suspenders - 291007AM","christie eyelet dress - 491004AG","classic black cotton sheath - 491006BO","classic black sheath - 471004AJ","colorblock dress - 491003AT","contrast beads and chain necklace - 791003AB","contrast bustier dress - 491006AX","contrast chiffon skirt  - 291006AL","contrast collar top - 191006AG","contrast obi waist dress in blue  - 491006BP","contrast obi waist dress in pink  - 491006BQ","cream buttoned tank dress - 491007AV","cream waisted mini  - 291007AD","crochet white slub tank - 191003BC","cutout shoulder black dress - 491003AS","daisy printed babydoll dress - 491004AA","dallas black bodycon dress  - 471004BH","daneel brown dress - 491007BA","dark brown tote bag - 791003AI","elena black dress - 491006AK","elise printed tank - 191003AT","elle oversized tee - 191007AN","embellished earthy tank - 191003AS","embellished longline top in blue - 191004AQ","embellished longline top in lilac - 191004AR","embossed silver bangle - 791003AD","evana 2-piece set - 491004AL","faith knit sweater - 191002AX","faith tunic top - 491006BM","faux fur cropped vest - 191001AD","faux ribbon monochrome top - 191006AD","flora maxi dress - 491006AT","floral chiffon mini dress - 491007AD","floral maxi dress - 491002AB","gerri career dress - 491004AM","glitter black tights - 791004AB","graffiti-inspired tee - 191004AY","graphic print heart tee - 191007AC","hayley floral dress - 491007AT","heart print dress - 491003AU","hot pink skirt - 291003AB","islandic charm necklace - 791003AA","jenna cream skirt - 291004AG","kaitlyn drape dress - 491006AE","kari denim dress - 491006AN","kelly pink tunic - 491003AM","kerry pink dress  - 491006BH","kitty charm necklace - 791002AF","knit vest with striped inner - 191003AI","kristina cropped jacket - 191003AJ","lace one shoulder dress - 491002BM","lace overlay black slip - 491003CA","lace panel navy dress  - 491006AR","lace paneled black dress - 691001AH","lace paneled leggings - 291003AG","lace up black mini - 291006AM","lace up satin dress - 491006BR","laine monochrome dress - 491004AW","leaves charm necklace - 791006AA","linen shirtdress - 491003AN","liz satin skirt - 291006AE","long black knit vest - 191003BB","love to drive necklace - 791003AF","manda skirt - 291003AE","mandy tiered dress - 491003AL","megan linen dress - 491004AH","mesh back lbd - 471002AD","mesh tulle skirt - 291006AC","mesh waist lbd - 471001AB","military inspired parka - 191004AN","military tag necklace - 791006AB","milla mixed fabrics dress - 491007BK","mint eyelet cardigan - 191003AY","monochrome bodycon skirt - 291006AA","monochrome chiffon blouse - 191007AK","monochrome chiffon dress - 471002AA","monochrome floral dress  - 491006AJ","monochrome floral dress - 491002AA","monochrome printed top  - 191006AC","monochrome satin and chiffon dress - 491007AQ","monochrome toga dress - 471001AJ","nancy structured dress  - 491006BX","nautical bodycon dress  - 491006AF","nautical inspired sleeveless top - 191006AF","navy bodycon dress - 491006BK","navy chiffon dress - 491003AJ","navy contrast bodycon dress - 491006AW","navy cutout back dress - 491003AR","navy obi waist dress - 491003AX","navy strapless romper  - 291006AN","navy structured dress - 491006AY","necklace print tank dress - 491003BB","newsprint babydoll dress - 491003AH","noir drape necklace - 791002AG","nude lace dress - 491004AU","nude lace tiered skirt - 291004AM","one shoulder black top - 171004BB","over the waist shorts - 291004AA","oversized knit sweater - 191003AN","pastel lace panel dress - 691001AJ","pastel tweed skirt - 291006AK","peach full skirt - 691001AD","penny boho skirt - 291004AB","peyton floral dress - 491006AM","pink cherry babydoll dress - 491002AJ","pink corsage chiffon dress  - 491006BE","pink pearl drape necklace - 791001AK","pink ruffled blouse - 191003AZ","pinstripe cuffed shorts - 291006AO","pleated black romper - 291006AH","pleated cuffed shorts - 291007AB","pleated lace dress - 471004AM","pleated one shoulder dress - 471001AF","pleated satin dress - 491007BI","pleated satin shorts - 291004AJ","pleated tunic top - 491002AV","prim grey high socks - 791004AC","printed chiffon tiered dress - 491006AO","printed cutout back dress - 491003AK","purple chiffon maxi dress - 491004AO","purple wild vest - 191002AD","rae floral strapless dress - 491003BK","red floral embroidered top - 191002AJ","red roses chiffon dress - 491006AC","red satin halter dress - 491003BI","reese black chiffon tunic - 491006BD","rock n' roll graphic tank - 191002AR","rose beaded necklace - 791002AC","ruched black dress - 491007AZ","ruffled black belted dress - 491007AN","ruffled white blouse - 191002AI","sandra tulle dress - 491003CD","satin and chiffon dress - 491006AS","sequins and stars tee - 191007AB","shannon structured dress  - 491006BN","sheer ruffled blouse - 191003AA","sheryn plaid dress - 491002AY","silk-blend boyfriend blazer - 191004AI","silver stripe tunic - 191001AK","sparrow charm necklace - 791002AI","speccy crop tee - 191007AP","strapless bodycon dress - 491006BU","strapless gold satin dress - 491003AA","strapless grey panel dress - 491006BA","strapless ruched dress - 491007AJ","striped chiffon top - 191007AH","striped cowl jumper - 291007AI","striped halter romper  - 291006AB","striped halter top - 191003AL","striped mini dress  - 491006BI","striped mini dress - 491007AA","striped tank dress - 491007AY","studded handbag - 791003AH","suede ruffle dress - 491003AE","sunshine strapless dress - 491003BF","tessa colorblock dress - 471004BD","test product 2 - TEST2","tiffany lace dress - 491004AT","turqouise chiffon dress  - 491006BB","tweed cuffed shorts - 291006AP","velt knit dress - 491002AE","vera floral dress - 491004AF","vicky summer dress - 491003AW","vienna shine dress - 491006BJ","watercolor printed skirt - 291004AK","white boho skirt - 291004AC","white draped back dress - 471001AI","white ripped crop tee - 191007AG","wild fox tunic - 191003AX","willow skater dress - 491006BL","yuni pinstripe dress - 491007BL"];
