//auto generates by the storecreator and templates
var storeName="GreatShop";
var mainPage="intro.html";
var totalItems=18;
var ir = new Array(totalItems);
A(0, 0, 'Aptiva E6U Pentium II 400 MHz', 1799.97);
A(1, 1, 'Hand VivaPro Model LX2 Computer', 1299.97);
A(2, 2, 'HL-1660 17PPM Laser Printer 1600x1200 DPI', 1249.99);
A(3, 3, 'HP DeskJet 694c Color Inkjet Printer', 199.00);
A(4, 4, 'HP OfficeJet Pro 1175Cse Multifunction Printer ', 999.99);
A(5, 5, 'IBM ThinkPad 385D (6EU) All-in-One Design Notebook', 1499.99);
A(6, 6, 'Lifebook 985 TX 233MHz MMX / 32MB / 5.0GB /', 2799.99);
A(7, 7, 'Optra SC 1275 12PPM 600 dpi Color Laser', 3099.99);
A(8, 8, 'Portable battery for the Canon BJ-30, BJC-70, and BJC-80 (p/n 3', 109.99);
A(9, 9, 'Presario 1235 - AMD-K6 266 MHz ', 1799.97);
A(10, 10, 'Presario 1810 Pentium II 300 MHz / 64MB / 6.4GB / 13.3`` TFT / ', 3599.97);
A(11, 11, 'Presario 2266 Cyrix MII 300*MHz / 64MB / 4GB / 32X / 56K', 799.97);
A(12, 12, 'Presario 5630 - P-II 400 MHz Multimedia Computer', 1799.97);
A(13, 13, 'Presario 5660FT Full Tower Pentium II 450 MHz', 2299.97);
A(14, 14, 'TC/TR SPECIAL - VivaBook 1200L P-200 MMX', 1227.09);
A(15, 15, 'Tecra 780DVD Pentium II 266MHz', 4349.99);
A(16, 16, 'VivaBook Model 1200L Build-to-Order Notebook', 1399.97);
A(17, 17, 'VivaBook Model 910c - 200MHz', 999.97);
// ****************************************************************
// File :search.cpp
// Date: 19th Oct 1998
// Coder: Diing-Seng Toh, diing@ziron.com
//				note: I split this module out from the parent javascript module "Storecreator.cpp" so that
//						 we can have very fast speed for a visitor to browse and shop in the web site.  But the pay 
//						off is that the time taken for searching database will take much longer time. Each search
//						requires a complete download of the store database.  
//																																					Diing 19thOct1998.
//
// Ziron StoreCreator v1.5 Java Script for handling items searching
// Copyright (c) 1998 Ziron Multimedia,  All right reserved 
// http://www.ziron.com/
// ****************************************************************

//use short func name and var name so that it save time for downloading
function A(i, id, s, p)
{
	ir[i] = new RECORD();
	ir[i].itemID = id; 
	ir[i].itemName = s; 
	ir[i].price = p;
}


// ****************************************************************
// MakeArray
// Standard JAVA scription function to allocate an array like 
// memory
// ****************************************************************
function MakeArray(n) {
      this.length = n;
      for(var i = 0; i < n; i++){
            this[i] = 0;
      }
      return this;
}


// ****************************************************************
// Currency(money)
// Cast a value into a money type with 0 padding at the end
// coder : Diing-Seng Toh 2 Sept 1998.
// ****************************************************************
function Currency(money)
{
	//convert an value into a string
	money =  parseFloat(money);
	money += 0.005;
	money +=  "";           
	var monLen = money.length;
	var digPos = money.indexOf(".");
	if(digPos == -1) {
		if (money <=0) {
			money ="0.00";
		} else {
			money += ".00";
		}
		return money;
	} else {
		if (digPos + 3 > monLen) {
			money += "0";
		} else if (digPos + 3 != monLen) {
			money = money.substring(0, digPos+3);
		} 
		return money;
	}     
}


// ****************************************************************
// RECORD 
// this function initializes a shoping type record to zero
// coder : Diing-Seng Toh 2 Sept 1998 
// ****************************************************************
function RECORD()
{
	this.itemID = 0;
	this.itemName="";
	this.price=0;
	this.match=0;
	return this;
}



function CompareMatch(a, b) {
   return a.match < b.match;
}

//**************************************************************************
// function Search()
// Call this function to search keywords of items
// coder : Diing-Seng Toh 19 Oct 1998 
//**************************************************************************
function Search()
{
	var searchStr = parent.frames["cart"].document.forms[0].keywords.value;
	searchStr=searchStr.toLowerCase();
	//we first split the search string into search words.
	var space = " ";
	var searchWords = searchStr.split(space);

	searchWords.sort();
	//now we want to determine the start
	var searchStart =0;
	for (var i=0; i < searchWords.length; i++) {
		if (searchWords[i].length == 0) {
			searchStart++;
		} else {
			break;
		}
	}
	var totalSearchWord = searchWords.length - searchStart;
	if (totalSearchWord <= 0) {
		//empty string, don't do searching
		return;
	}
	var totalFound=0;
	var j;

	for (j=0;j<totalItems;j++) {
		var totalMatch=0;
		var str = ir[j].itemName.toLowerCase();
		for (var i=searchStart; i < searchWords.length; i++) {
			//now we want to check for there any matching?
			if (str.search(searchWords[i])>=0) totalMatch++;
		}
		if (totalMatch>0) totalFound++;
		ir[j].match=totalMatch;
	}


	//now sort it!
	ir.sort(CompareMatch);
	
	var cWin=parent.frames["shop"].document;
	
	cWin.open();
	cWin.write("<HTML><HEAD><TITLE> Ziron StoreCreator v1.5 Shopping Cart Viewer</TITLE></HEAD>");
	cWin.write("<BODY Text=#000000 BGCOLOR=#ffffff LINK=#ff0000 VLINK=#ff0000 alink=#222222 valign=top>");
	cWin.write("<strong>Search results are as show in the following table:["+totalFound+"]<br>");
	cWin.write("<table border=1><tr bgcolor=#aaa055><td><b>Match</td><td width=400><b>Item Name</td><td><b>Price</td></tr>");
	for (j=0;j<ir.length;j++) {
		if (ir[j].match<=0) break;
		cWin.write("<tr><td>"+ir[j].match+"</td><td><a href='item"+ir[j].itemID+".html'  target=shop>"+ir[j].itemName+"</a></td><td align=right>$"+Currency(ir[j].price)+"</td></tr>");
	}
	cWin.write("</table><hr size=1>");
	//cWin.write(searchStr);
	cWin.write("</body></html>");
	cWin.close();	
}


function PrintSearchPage()
{
	var cWin=parent.frames["shop"].document;
	cWin.open();
	cWin.write("<HTML><HEAD><TITLE> Ziron StoreCreator v1.5 Shopping Cart Viewer</TITLE></HEAD>");
	cWin.write("<BODY Text=#000000 BGCOLOR=#ffffff LINK=#ff0000 VLINK=#ff0000 alink=#222222 valign=top OnLoad='document.forms[0].elements[0].focus()'>");
	cWin.write("<table border=0> <tr><td><a href='"+mainPage+"'><Strong>Main Page</strong></a></td><td><a href='"+parent.returnHtmlPath+"'><Strong>Back</strong></a></td></tr></table><hr size=1 width=50%>");
	cWin.write("<input type=button size=40 value='Submit' onClick='parent.frames[\"cart\"].Search()'>");
	cWin.write("</form></td></tr></table>");
	cWin.write("</body></html>");
	cWin.close();	
}
