
//start common functions

function setCSS()
{
	var custFontSize = getSubCookie('JSUtilities', 'fontSize', '&');
	if (custFontSize == '') custFontSize = 14;
	dw("<style  type='text/css'>");
	dw("form {margin-top: 0px; margin-bottom: 0px}");
	dw("body {font-family:arial;font-size:" + custFontSize + "px}");
	dw("A:link {color: #089494; text-decoration: none}");
	dw("A:visited {color: #089494; text-decoration: none}");
	dw("A:active {color: brown; text-decoration: none}");
	dw("A:hover {color: red; text-decoration: underline}");
	dw("td {font-family:arial;font-size:" + custFontSize + "px}");
	dw("</style>");
}
setCSS();

var isDemo = false;
var isSafe2Exit = true;
function confExit(evt)
{
	var str = '';

	if (isDemo)
	{
		str += "\n\n--------------------------------\n";
		str +=	"Here you would be able to save this page and print it arranged by aisle for fast shopping";
		str += "\n--------------------------------\n\n";
	}
	else
	{
		str += "\n\n--------------------------------\n";
		str += "You made changes in this page.\nClick Cancel and update current changes. ";
		str += "Or click OK to leave this page without saving.\n";
		str += "\n--------------------------------\n\n";
	}
	if (!isSafe2Exit)
	{
		return str;
	}
}
window.onbeforeunload = confExit;


function brr(theNr)
{
	var i;
	for (i = 0; i < theNr; i++)
	{
		dw("<br>");
	}
}


function findStrong(chkMyVal)	//for shoppingList and recipe in function guess()
{
	var i = 0;
	var chkVal = new Array();

	if (inStr(chkMyVal, " ") == -1)
		chkVal[0] = chkMyVal;
	else
		chkVal = chkMyVal.split(" ");
	for (i = 0; i < chkVal.length; i++)
	{
		if (LCase(chkVal[i]) == "pot" || LCase(chkVal[i]) == "pan" || LCase(chkVal[i]) == "kettle" || LCase(chkVal[i]) == "utensil" || LCase(chkVal[i]) == "spoon" || LCase(chkVal[i]) == "fork" || LCase(chkVal[i]) == "knife")
		{
			return "Cookware";
		}

		if (LCase(chkVal[i]) == "wash")
		{
			return "Health and beauty";
		}

		if (LCase(chkVal[i]) == "toilet")
		{
			return "Household products";
		}
				
		if (LCase(chkVal[i]) == "frozen")
		{
			return "Frozen foods";
		}

		if (LCase(chkVal[i]) == "cat" || LCase(chkVal[i]) == "cats" || LCase(chkVal[i]) == "dog" || LCase(chkVal[i]) == "dogs" || LCase(chkVal[i]) == "hamster" || LCase(chkVal[i]) == "hamsters" || LCase(chkVal[i]) == "pig" || LCase(chkVal[i]) == "pigs" || LCase(chkVal[i]) == "canary" || LCase(chkVal[i]) == "canaries" || LCase(chkVal[i]) == "parrot" || LCase(chkVal[i]) == "parrots" || LCase(chkVal[i]) == "pet" || LCase(chkVal[i]) == "pets")
		{
			return "Pet supplies";
		}
				
		if (LCase(chkVal[i]) == "cocoa")
		{
			return "Coffee and tea";
		}

		if (LCase(chkVal[i]) == "mix" || LCase(chkVal[i]) == "extract")
		{
			return "Baking supplies";
		}
					
		if (LCase(chkVal[i]) == "pen" || LCase(chkVal[i]) == "pens" || LCase(chkVal[i]) == "pencil" || LCase(chkVal[i]) == "pencils")
		{
			return "School and office supplies";
		}

		if (LCase(chkVal[i]) == "cough" || LCase(chkVal[i]) == "fever" || LCase(chkVal[i]) == "headache" || LCase(chkVal[i]) == "pain" || LCase(chkVal[i]) == "flu" || LCase(chkVal[i]) == "medicine" || LCase(chkVal[i]) == "drug" || LCase(chkVal[i]) == "infection")
		{				
			return "Pharmacy";
		}

		if (LCase(chkVal[i]) == "clove" || LCase(chkVal[i]) == "cloves" || LCase(chkVal[i]) == "fresh" || LCase(chkVal[i]) == "freshly")
		{	
			return "Produce";
		}
	}	
	return "not specified";
}

//end common functions



//start pages *Recipies*.html

function saveStoreID(ID)
{
	var i = 0;
	myStoreID = ID;
	setSubCookie('Util', 'myStoreID', ID, '&');
	for (i = 0; i < storeIDs.length; i++)
	{
		if (storeIDs[i] == ID)
		{
			setSubCookie('Util', 'defStore', i, '&');
			return;
		}
	}
}


function sterowanieZAjaxu()
{
	parent.showObject('msgFromAjax');
	parent.hideObject('div_editRecipe');
	parent.hideObject('getMyStores');
	if (navigator.userAgent.indexOf("Safari")==-1)
		parent.location.href = "add2shoppingList.html";
}



function criterium4recipeCart(a, b)
{
	if(LCase(a.aisle) > LCase(b.aisle))
		return 1;
	if(LCase(a.aisle) == LCase(b.aisle))
	{
		if(LCase(a.ingr) > LCase(b.ingr))
			return 1;
		if(LCase(a.ingr) < LCase(b.ingr))
			return -1;
	}
	return -1
}
	

function recipeCart()
{
	this.counter = 0;
	this.arrIngr10 = new Array();
	this.arrIngr = new Array();
	this.frm_sterownik = window.document.formSterownik;


	function Init()
	{
		this.writeGrid();
		this.sortData();
	}
	this.init = Init;


	function SortData()
	{
		var recipe = new Array();
		var i = 0;
		for (i = 0; i < this.counter; i++)
		{	
			recipe[i] = new this.data2sort(i);	
		}
		recipe.sort(criterium4recipeCart);
		this.writeSortedData(recipe);
		this.deleteFromGrid();
	}
	this.sortData = SortData;


	function Data2sort(i)
	{
		var f = window.document.formWykonawcza;
		this.storeID = eval("f.storeID_" + i).value;
		this.storeName = eval("f.storeName_" + i).value;
		this.recipeID = eval("f.recipeID_" + i).value;
		this.recipeTitle = eval("f.recipeTitle_" + i).value;
		this.ingr = eval("f.ingr_" + i).value;
		this.quantity = eval("f.quantity_" + i).value;
		this.brand = eval("f.brand_" + i).value;
		this.aisle = eval("f.aisle_" + i).value;
	}
	this.data2sort = Data2sort;


	function WriteSortedData(theData)
	{
		var f = window.document.formWykonawcza;
		var i = 0;
		for (i = 0; i < theData.length; i++)
		{
			eval("f.storeID_" + i).value = theData[i].storeID;
			eval("f.storeName_" + i).value = theData[i].storeName;
			eval("f.recipeID_" + i).value = theData[i].recipeID;
			eval("f.recipeTitle_" + i).value = theData[i].recipeTitle;
			eval("f.ingr_" + i).value = theData[i].ingr;
			eval("f.quantity_" + i).value = theData[i].quantity;
			eval("f.brand_" + i).value = theData[i].brand;
			eval("f.aisle_" + i).value = theData[i].aisle;
		}
	}
	this.writeSortedData = WriteSortedData;


	function GenerateStoreSelects(counter, theStore_ID)
	{
		var i = 0;
		
		var str = "<Select name = 'storeSelects_" + counter + "'";
		str += " onChange = 'grid.resetSelects(" + counter + ");'";
		str += ">";

		for (i = 0; i < storeIDs.length; i++)
		{
			str += "<option value = '" + storeIDs[i] + "'";
			if (theStore_ID + "" == storeIDs[i] + "")
			{
				str += " selected "
			}
			str += ">";
			str += storeNames[i];
			str += "</option>";
		}
		str += "</select>";
		return str;
	}
	this.generateStoreSelects = GenerateStoreSelects;


	function ResetSelects(i)
	{	
		var selectedItem = eval("window.document.formWykonawcza.storeSelects_" + i).selectedIndex;
		var selectedText = eval("window.document.formWykonawcza.storeSelects_" + i).options[selectedItem].value;
		eval("window.document.formWykonawcza.storeID_" + i).value = selectedText;
		eval("window.document.formWykonawcza.storeName_" + i).value = selectedText;
	}	
	this.resetSelects = ResetSelects;


	function FrmHead()
	{
		var str = '';
		str += "<form name = 'formWykonawcza' method = 'post' action = 'add2shoppingList.html'>";
		str += "<input type = 'hidden' name = 'numOfItems'>";
		str += "<input type = 'hidden' name = 'myFormName' value = 'formWykonawcza'>";
		str += "<table border = '0'><tr><td bgcolor = '#c2f2b3'>del</td><td bgcolor = '#c2f2b3'>Item</td>";
		str += "<td bgcolor = '#c2f2b3'>";
		str += "Recipe</td><td bgcolor = '#c2f2b3'>Quantity</td><td bgcolor = '#c2f2b3'>Brand</td>";
		str += "<td bgcolor = '#c2f2b3'>Aisle</td><td bgcolor = '#c2f2b3'>Store</td></tr>";
		return str;
	}
	this.frmHead = FrmHead;


	function FrmTail()
	{
		var str = '';
		str += "</table>";
		str += "</form>";
		str += "<form>"
		str += "<input type = 'Submit' value = 'Save to Shopping List' onClick =";
		str += " 'grid.deleteFromGrid(); window.document.formWykonawcza.submit(); return false;'>";
		str += "</form>";
		return str;
	}
	this.frmTail = FrmTail;
	

	function WriteGrid()
	{
			//!!!!!!!!!!!!!!
		//this function only introduces data! For Look use DeleteFromGrid().
			//!!!!!!!!!!!!!!
		var  i = 0;
		var ii = 0;
		var str = "";
		var len = 0;
		this.counter = 0;
		str += this.frmHead();
		for (i = 0; i < this.frm_sterownik.numOfItems.value; i++)
		{
			this.arrIngr10 = eval("this.frm_sterownik.ingredients_" + i).value.split(chr(10));
			for (ii = 0; ii < this.arrIngr10.length ; ii++)
			{
				this.arrIngr = this.arrIngr10[ii].split(chr(9));
				if (this.arrIngr[0] != "")
				{
					str += "<tr><td>";
					str += "<input type = 'hidden' name = 'storeID_" + this.counter + "' value = '";
					str += eval("this.frm_sterownik.storeID_" + i).value + "'>";
					str += "<input type = 'hidden' name = 'storeName_" + this.counter + "' value = \"";
					str += userStores[eval("this.frm_sterownik.storeID_" + i).value] + "\">";
					str += "<input type = 'hidden' name = 'ID_" + this.counter + "' value = '";
					str += eval("this.frm_sterownik.ID_" + i).value + "'>";
					str += "<input type = 'hidden' name = 'recipeID_" + this.counter + "' value = '";
					str += eval("this.frm_sterownik.recipeID_" + i).value + "'>";
					str += "<input type = 'hidden' name = 'recipeTitle_" + this.counter + "' value = \"";
					str += eval("this.frm_sterownik.recipeTitle_" + i).value + "\">";

					str += "<input type = 'checkbox' name = 'chkBox_" + this.counter + "' value = '";
					str += this.counter + "' onClick = 'grid.deleteFromGrid(" + this.counter +"); return true'>";

					str += "</td><td>";
					str += "<input type = 'hidden' name = 'ingr_" + this.counter + "' value = \"";
					str += this.arrIngr[0];	
					str += "\">";
					str += this.arrIngr[0];	
					str += "</td><td>";
					str += eval("this.frm_sterownik.recipeTitle_" + i).value;
					str += "</td><td>";
					str += "<input type = 'text' name = 'quantity_" + this.counter + "' value = \"";
					str += this.arrIngr[2];
					str +="\">";
					str += "</td><td>";
					str += "<input type = 'text' name = 'brand_" + this.counter + "' value = \"";
					str += this.arrIngr[1];
					str +="\">";
					str += "</td><td>";
					str += "<input type = 'hidden' name = 'aisle_" + this.counter + "' value = \"";
					str += this.arrIngr[3];
					str +="\">";
					str += this.arrIngr[3];
					str += "</td></tr>";
					this.counter++;
				}
			}
		}
		str += this.frmTail();
		document.getElementById('spanWykonawczy').innerHTML = str;
		window.document.formWykonawcza.numOfItems.value = this.counter;
	}
	this.writeGrid = WriteGrid;
	

	function DeleteFromGrid()
	{
		var str = '';
		var i = 0;
		var numOfItems = this.counter;
		var kolor = "'green'";
		this.counter = 0;
		str += this.frmHead();
		for (i = 0; i < numOfItems; i++)
		{
			if (!eval("window.document.formWykonawcza.chkBox_" + i).checked)
			{	
				if (this.counter % 2 == 0)
					kolor = "'#c6f7de'";	//kolor = "'#c0d9b0'";
				else
					kolor = "'#c6e7de'";
				str += "<tr><td bgcolor = " + kolor + ">";
				str += "<input type = 'hidden' name = 'storeID_" + this.counter + "' value = '";
				str += eval("window.document.formWykonawcza.storeID_" + i).value + "'>";
				str += "<input type = 'hidden' name = 'storeName_" + this.counter + "' value = \"";
				str += userStores[eval("window.document.formWykonawcza.storeID_" + i).value] + "\">";
				str += "<input type = 'hidden' name = 'ID_" + this.counter + "' value = '";
				str += eval("window.document.formWykonawcza.ID_" + i).value + "'>";
				str += "<input type = 'hidden' name = 'recipeID_" + this.counter + "' value = '";
				str += eval("window.document.formWykonawcza.recipeID_" + i).value + "'>";
				str += "<input type = 'hidden' name = 'recipeTitle_" + this.counter + "' value = \"";
				str += eval("window.document.formWykonawcza.recipeTitle_" + i).value + "\">";
				str += "<input type = 'checkbox' name = 'chkBox_" + this.counter + "' value = '";
				str += this.counter + "'>";
				str += "</td><td bgcolor = " + kolor + ">";
				str += "<input type = 'text' size = '40' name = 'ingr_" + this.counter + "' value = \"";
				str += eval("window.document.formWykonawcza.ingr_" + i).value;
				str += "\">";
				str += "</td><td bgcolor = " + kolor + ">";
				str += "<font size = '-1'>";
				str += eval("window.document.formWykonawcza.recipeTitle_" + i).value;
				str += "</font>";
				str += "</td><td bgcolor = " + kolor + ">";
				str += "<input type = 'text' name = 'quantity_" + this.counter + "' value = \"";
				str += eval("window.document.formWykonawcza.quantity_" + i).value;
				str +="\">";
				str += "</td><td bgcolor = " + kolor + ">";
				str += "<input type = 'text' name = 'brand_" + this.counter + "' value = \"";
				str += eval("window.document.formWykonawcza.brand_" + i).value;
				str +="\">";
				str += "</td><td bgcolor = " + kolor + ">";
				str += "<input type = 'hidden' name = 'aisle_" + this.counter + "' value = \"";
				str += eval("window.document.formWykonawcza.aisle_" + i).value;
				str +="\">";
				str += "<font size = '-1'>";
				str += eval("window.document.formWykonawcza.aisle_" + i).value;
				str += "</font>";
				str += "</td><td bgcolor = " + kolor + ">";
				str += this.generateStoreSelects(this.counter, eval("window.document.formWykonawcza.storeID_" + i).value);
				str += "</td></tr>";
				this.counter++;
			}
		}
		str += this.frmTail();
		document.getElementById('spanWykonawczy').innerHTML = str;
		window.document.formWykonawcza.numOfItems.value = this.counter;
	}
	this.deleteFromGrid = DeleteFromGrid;
}	//end class recipeCart


function recGrid()
{
	this.counter = 0;
	this.active = -1;
	this.edit = true;
	this.checkAllRecipeBool = false;
	this.recipeTitle = "";
	this.recipeID = -1;

	function Init()
	{
		this.writeGrid();
		if (this.edit == true)
			this.setAisles();
	}
	this.init = Init;

	function WriteGrid()
	{
		var str = window.document.editRecipe.i_Ingredients.value;
		var i = 0;
		var s = '';
		var arrIngrBrandQuantity;
		var arrInter;

		s = "<br><font color = 'green'>Ingredients:</font><br>";
		s += "<noBR>";
		if (!this.edit)
		{
			s += "<input type = 'checkbox' name = 'mainCheck' onClick = 'grid.checkAllRecipe();return true;'>";
		}
		s += "<input type = 'text' value = 'ingredient' name = 'itemHeader' size = '30' onFocus = 'blur();' style = 'color:green;'>";
		s += "<input type = 'text' value = 'brand' name = 'brandHeader' size = '10' onFocus = 'blur();' style = 'color:green;'>";
		s += "<input type = 'text' value = 'quantity' name = 'quantityHeader' size = '10' onFocus = 'blur();' style = 'color:green;'>";
		s += "<input type = 'text' value = 'aisle' name = 'aisleHeader' size = '15' onFocus = 'blur();' style = 'color:green;'>";
		s += "</noBr>";
		s += "<span id = 'insertPoint'></span>";
		document.getElementById('recipeGrid').innerHTML += s;
		if (str != '')
		{
			arrIngrBrandQuantity = str.split(chr(10));
			for (i = 0; i < arrIngrBrandQuantity.length; i++)
			{
				arrInter = arrIngrBrandQuantity[i].split(chr(9));
				if (arrInter[0] != "")
				{
					this.addEmptyEntry();
					eval("window.document.editRecipe.ingr_" + i).value = arrInter[0];
					eval("window.document.editRecipe.brand_" + i).value = arrInter[1];
					eval("window.document.editRecipe.quantity_" + i).value = arrInter[2];
					eval("window.document.editRecipe.aisle_" + i).value = arrInter[3];
				}
			}
		}
		else
		{
			if (this.edit)
			{
				this.addEmptyEntry();
			}
		}
		if (!this.edit)
		{
			window.document.editRecipe.i_Ingredients.focus();
			if (this.counter == 0)
			{
				hideObject('div_editRecipe');
				hideObject('getMyStores');
			}
		}
	}
	this.writeGrid = WriteGrid;


	function AddEmptyEntry()
	{
		var s = '<br>';
		var f = '';
		var myNode = document.createElement("span");
		s += "<noBr>";
		if (this.edit)
			f = "onFocus = 'grid.active = " + this.counter + ";'";
		else
		{
			s += "<input type = 'checkbox' name = '" + this.counter + "'>";
			f = "onFocus = blur();";
		}
		s += "<input type = 'text' name = 'ingr_" + this.counter + "' " + f + " size = '30'>";
		s += "<input type = 'text' name = 'brand_" + this.counter + "' " + f + " size = '10'>";
		s += "<input type = 'text' name = 'quantity_" + this.counter + "' " + f + " size = '10'>";
		s += "<input type = 'text' name = 'aisle_" + this.counter + "' " + f + " size = '15'>";
		s += "</noBr>";
		myNode.setAttribute("id", "SpanIngr_" + this.counter);
		myNode.innerHTML = s;
		document.getElementById('recipeGrid').insertBefore(myNode, document.getElementById('insertPoint'));
		eval("window.document.editRecipe.ingr_" + this.counter).focus();
		this.counter++;
	}
	this.addEmptyEntry = AddEmptyEntry;


	function OnSubmit2List()
	{
		var f = window.document.editRecipe;
		var p = window.frame4add2list.document.editRecipe;
		try
		{
			p.theStoreID.value = myStoreID;
		}
		catch(e)
		{
			alert("Please set up your store list first by Clicking on 'Shopping List' link from the menu above");
			return false;
		}
		var chkd = this.isRecipeChecked(f);
		var elem;
		if (chkd == false)
			return false;
		var i = 0;
		f.i_Ingredients.value = "";
		for (i = 0; i < f.elements.length; i++)
		{
			elem = f.elements[i];
			if (elem.type == 'checkbox' && elem.checked == true && elem.name != 'mainCheck')
			{
				p.i_Ingredients.value += eval("f.ingr_" + elem.name).value + chr(9);
				p.i_Ingredients.value += eval("f.brand_" + elem.name).value + chr(9);
				p.i_Ingredients.value += eval("f.quantity_" + elem.name).value + chr(9);
				p.i_Ingredients.value += eval("f.aisle_" + elem.name).value + chr(9);
				p.i_Ingredients.value += chr(10);
			}
		}
		p.recipeTitle.value = this.recipeTitle;
		p.recipeID.value = this.recipeID;
		p.submit();
		hideObject('ajaxArea1');
		showObject('ajaxArea2');
		return false;
	}
	this.onSubmit2List = OnSubmit2List;


	function ProcessOnSubmit()
	{
		var i = 0;
		var str = '';
		var aisle = '';
		for (i = 0; i < this.counter; i++)
		{
			if (eval("window.document.editRecipe.ingr_" + i).value != "")
			{
				str += replace(eval("window.document.editRecipe.ingr_" + i).value, "'", "`") + chr(9);
				str += replace(eval("window.document.editRecipe.brand_" + i).value, "'", "`") + chr(9); 
				str += replace(eval("window.document.editRecipe.quantity_" + i).value, "'", "`") + chr(9);
				aisle = replace(eval("window.document.editRecipe.aisle_" + i).value, "'", "`");
				if (aisle == "")
					aisle = "not specified";
				str += aisle + chr(9) + chr(10); 
			}
		}
		str = replace(str, chr(92), "/");
		window.document.editRecipe.i_Ingredients.value = str;
		window.document.editRecipe.submit();
	}
	this.processOnSubmit = ProcessOnSubmit;


	function SetAisles()
	{
		var i;
		var str = '';
		var recentLetter = '';
		var checkLetter = '';

		for (i = 0; i < customAisles2display.length; i++)
		{
			if (customAisles2display != "")
			{
				aisles2display[aisles2display.length] = customAisles2display[i];
			}
		}
		aisles2display.sort(noCaseCriterium);

		str += "<br><table border = '0'>";
		for (i = 0; i < aisles2display.length; i++)
		{
			if (aisles2display[i] != "")
			{
				checkLetter = UCase(Character(aisles2display[i], 0));
				if (checkLetter != recentLetter)
				{
					recentLetter = checkLetter
					str += "<tr><td><b><font style = 'font-size:14;'>";
					str += recentLetter + "</font></b><td width = '5'></td>";
				}
				else
				{
					str += "<tr><td><td width = '5'></td>";
				}
				str += "<td><a href = '#' onClick = 'grid.insertAisle(\"" + i + "\");return false;'>";
				str += "<font style = 'font-size:12;'>";
				str += aisles2display[i];
				str += "</font>";
				str += "</a>"
				if (i < aisles2display.length)
					str += "</td></tr>";
			}
		}
		str += "</table>";
		document.getElementById("aisles").innerHTML = str;
		return '';
	}
	this.setAisles = SetAisles;

	function InsertAisle(i)
	{
		eval("window.document.editRecipe.aisle_" + grid.active).value = aisles2display[i];
	}
	this.insertAisle = InsertAisle;


	function IsRecipeChecked(frm)
	{
		var ch = false;
		var i;
		for (i = 0; i < frm.elements.length; i++)
		{
			if (frm.elements[i].type == 'checkbox')
			{
				if (frm.elements[i].checked == true)
					ch = true;
			}
		}
		if (ch == false)
		{
			alert("You must choose ingriedents to add to shopping list");
			return false;
		}
		return true;
	}
	this.isRecipeChecked = IsRecipeChecked;



	function CheckAllRecipe()
	{
		var i = 0;
		var frm = window.document.editRecipe;
		this.checkAllRecipeBool = frm.mainCheck.checked;	
		for (i = 0; i < frm.elements.length; i++)
		{
			if (frm.elements[i].type == 'checkbox')
			{
				frm.elements[i].checked = this.checkAllRecipeBool;
			}
		}
	}
	this.checkAllRecipe = CheckAllRecipe;
	
}	//end class recGrid()





function viewRecipeGrid(){}
viewRecipeGrid.prototype = new recGrid();

viewRecipeGrid.prototype.addEmptyEntry = function()
{
	var s = '<br>';
	var f = '';
	var myNode = document.createElement("span");
	s += "<noBr>";
	if (this.edit)
		f = "onFocus = 'grid.active = " + this.counter + ";'";
	else
	{
		s += "<input type = 'checkbox' name = '" + this.counter + "'>";
		f = "onFocus = blur();";
	}
	if (this.edit)
		s += "<input type = 'text' name = 'quantity_" + this.counter + "' " + f + " size = '10'>";
	else
		s += "<input type = 'text' name = 'quantity_" + this.counter + "' " + f + " size = '15'>";
	s += "<input type = 'text' name = 'ingr_" + this.counter + "' " + f + " size = '70'>";
	s += "<input type = 'text' name = 'brand_" + this.counter + "' " + f + " size = '20'>";
	s += "<input type = 'hidden' name = 'aisle_" + this.counter + "'>";
	s += "</noBr>";
	myNode.setAttribute("id", "SpanIngr_" + this.counter);
	myNode.innerHTML = s;
	document.getElementById('recipeGrid').insertBefore(myNode, document.getElementById('insertPoint'));
	eval("window.document.editRecipe.ingr_" + this.counter).focus();
	this.counter++;
}


viewRecipeGrid.prototype.writeGrid = function()
{
	var str = window.document.editRecipe.i_Ingredients.value;
	var i = 0;
	var s = '';
	var arrIngrBrandQuantity;
	var arrInter;

	s += "<br><font color = 'green'>Ingredients:</font>";
	s += "<br>";
	s += "<noBR>";
	if (!this.edit)
	{
		s += "<input type = 'checkbox' name = 'mainCheck' onClick = 'grid.checkAllRecipe();return true;'>";
	}
	if (this.edit)
		s += "<input type = 'text' value = 'quantity' name = 'quantityHeader' size = '10' onFocus = 'blur();' style = 'color:green;'>";
	else
		s += "<input type = 'text' value = 'quantity' name = 'quantityHeader' size = '15' onFocus = 'blur();' style = 'color:green;'>";
	s += "<input type = 'text' value = 'ingredient' name = 'itemHeader' size = '70' onFocus = 'blur();' style = 'color:green;'>";
	s += "<input type = 'text' value = 'brand' name = 'brandHeader' size = '20' onFocus = 'blur();' style = 'color:green;'>";
	s += "<input type = 'hidden' value = 'aisle' name = 'aisleHeader'>";
	s += "</noBr>";
	s += "<span id = 'insertPoint'></span>";
	document.getElementById('recipeGrid').innerHTML += s;
	if (str != '')
	{
		arrIngrBrandQuantity = str.split(chr(10));
		for (i = 0; i < arrIngrBrandQuantity.length; i++)
		{
			arrInter = arrIngrBrandQuantity[i].split(chr(9));
			if (arrInter[0] != "")
			{
				this.addEmptyEntry();
				eval("window.document.editRecipe.ingr_" + i).value = arrInter[0];
				eval("window.document.editRecipe.brand_" + i).value = arrInter[1];
				eval("window.document.editRecipe.quantity_" + i).value = arrInter[2];
				eval("window.document.editRecipe.aisle_" + i).value = arrInter[3];
			}
		}
	}
	else
	{
		if (this.edit)
		{
			this.addEmptyEntry();
		}
	}
	if (!this.edit)
	{
		dw("<br><font color = 'green'>Cooking Procedure:</font>");
		window.document.editRecipe.i_Ingredients.focus();
		if (this.counter == 0)
		{
			hideObject('div_editRecipe');
			hideObject('getMyStores');
		}
	}
}




function addRecipeGrid(){}
addRecipeGrid.prototype = new recGrid();
addRecipeGrid.prototype.insertAisle = function(i)
{
	eval("window.document.editRecipe.aisle_" + grid.active).value = aisles2display[i];
	if (grid.active == grid.counter - 1)
	{
		if (eval("window.document.editRecipe.ingr_" + grid.active).value != "")
			grid.addEmptyEntry();
	}
}

addRecipeGrid.prototype.addEmptyEntry = function()
{
	if (eval("window.document.editRecipe.ingr_" + grid.active).value != "")
	{
		var s = '<br>';
		var f = '';
		var myNode = document.createElement("span");
		s += "<noBr>";
		if (this.edit)
			f = "onFocus = 'grid.active = " + this.counter + ";'";
		else
		{
			s += "<input type = 'checkbox' name = '" + this.counter + "'>";
			f = "onFocus = blur();";
		}
		s += "<input type = 'text' name = 'ingr_" + this.counter + "' " + f + " size = '30'>";
		s += "<input type = 'text' name = 'brand_" + this.counter + "' " + f + " size = '10'>";
		s += "<input type = 'text' name = 'quantity_" + this.counter + "' " + f + " size = '10'>";
		s += "<input type = 'text' name = 'aisle_" + this.counter + "' " + f + " size = '15'>";
		s += "</noBr>";
		myNode.setAttribute("id", "SpanIngr_" + this.counter);
		myNode.innerHTML = s;
		document.getElementById('recipeGrid').insertBefore(myNode, document.getElementById('insertPoint'));
		eval("window.document.editRecipe.ingr_" + this.counter).focus();
		this.counter++;
	}
}





function addSimpleRecipe()
{
	this.keepCount = 0;
}

addSimpleRecipe.prototype = new addRecipeGrid();

addSimpleRecipe.prototype.initSimple = function()
{
	this.init();
	this.prepareSimple();
}

addSimpleRecipe.prototype.prepareSimple = function()
{
	this.keepCount = 0;
	hideObject('recipeGrid');
	hideObject('addNewIngrSubmit');
	hideObject('finalSubmit');
	hideObject('aisleContainer');
	hideObject('s_back');
	showObject('ingr');
	showObject('s_next');
}

addSimpleRecipe.prototype.prepareFull = function()
{
	showObject('recipeGrid');
	showObject('addNewIngrSubmit');
	showObject('finalSubmit');
	showObject('aisleContainer');
	hideObject('ingr');
	hideObject('s_next');
	showObject('s_back');
	this.transfer2Full();
}

addSimpleRecipe.prototype.transfer2Full = function()
{
	var str = window.document.editRecipe.i_Ingredients.value;
	var i = 0;
	for (i = 0; i < this.counter; i++)
	{
		eval("window.document.editRecipe.ingr_" + i).value = '';
		eval("window.document.editRecipe.brand_" + i).value = '';
		eval("window.document.editRecipe.quantity_" + i).value = '';
		eval("window.document.editRecipe.aisle_" + i).value = '';
	}
	if (str == '')
		return;

	str = replace(str, "nbsp;", " ");
	str = replace(str, "  ", " ");
	str = replace(str, "'", "`");
	var arrIngr = str.split(chr(10));
	var i = 0;
	for (i = 0; i < arrIngr.length; i++)
	{
		this.placeIngredients(arrIngr[i]);
	}
}

addSimpleRecipe.prototype.getRidOfFrontSpace = function(txt)
{
	var arrTxt = charArray(txt);
	var newTxt = new Array();
	var startTxt = false;
	var i = 0;
	for (i = 0; i < arrTxt.length; i++)
	{
		if (arrTxt[i] != " ")
			startTxt = true;
		if (startTxt)
			newTxt[i] = arrTxt[i];
	}
	return newTxt.join("");
}

addSimpleRecipe.prototype.placeIngredients = function(ingr)
{
	if (ingr == '')
	{
		return;
	}
	if (inStr(ingr, " ") == -1)
	{
		eval("window.document.editRecipe.ingr_" + this.keepCount).value = ingr;
		eval("window.document.editRecipe.aisle_" + this.keepCount).value = "not specified"
		grid.addEmptyEntry();
		this.keepCount++;
		return;
	}
	
	var units = new Array("can", "pinch", "stick", "bunch", "piece", "stalk", "g", "dag", "kg", "lb", "pound", "tsp", "tbsp", "tb", "tbl", "tblsp", "oz", "ounce", "cup", "clove", "pack", "package", "bag", "teaspoon", "tablespoon", "gallon");
	var val = '';
	var initIndex = 0;
	var i = 0;
	var quantSpecifier = 0;
	var quant = '';
	ingr = grid.getRidOfFrontSpace(ingr);
	var arrIngr = ingr.split(" ");
	if (isNumeric(charArray(ingr)[0]))
	{
		quantSpecifier = 1;
		quant = arrIngr[0];
		initIndex++;
		if (isNumeric(charArray(arrIngr[1])[0]))
		{
			if (inStr(arrIngr[1], "/") || inStr(arrIngr[1], "\\"))
			{
				quantSpecifier = 2;
				quant = arrIngr[0] + " " + arrIngr[1] + "";
				initIndex++;
			}
		}
		else
		{
			
		}
		for (i = 0; i < units.length; i++)
		{		
			if (LCase(arrIngr[quantSpecifier]) == units[i])
			{
				quant += " " + arrIngr[quantSpecifier];
				initIndex++;
			}
			if (LCase(arrIngr[quantSpecifier]) == units[i] + ".")
			{
				quant += " " + arrIngr[quantSpecifier];
				initIndex++;
			}
			if (LCase(arrIngr[quantSpecifier]) == units[i] + "s")
			{
				quant += " " + arrIngr[quantSpecifier];
				initIndex++;
			}
			if (LCase(arrIngr[quantSpecifier]) == units[i] + "s.")
			{
				quant += " " + arrIngr[quantSpecifier];
				initIndex++;
			}
			if (LCase(arrIngr[quantSpecifier]) == units[i] + "es")
			{
				quant += " " + arrIngr[quantSpecifier];
				initIndex++;
			}
			if (LCase(arrIngr[quantSpecifier]) == units[i] + "e")
			{
				quant += " " + arrIngr[quantSpecifier];
				initIndex++;
			}
		}
		if (LCase(arrIngr[initIndex]) == "of")
			initIndex++; 
	}
	eval("window.document.editRecipe.quantity_" + this.keepCount).value = quant;
	for (i = initIndex; i < arrIngr.length; i++)
	{
		val += arrIngr[i];
		if (i < arrIngr.length - 1)
			val += " ";		
	}
	eval("window.document.editRecipe.ingr_" + this.keepCount).value = val;
	eval("window.document.editRecipe.aisle_" + this.keepCount).value = "not specified"
	grid.addEmptyEntry();
	this.keepCount++;
}



//end pages *Recipies*.html



// start pages displayShoppingList.html, editPantry.html

function sortGridData()
{
	function sortGrid()
	{
		var myData = new Array();
		var i = 0;

		function myArrs(counter)
		{
			this.product = theGridData[product][counter];
			this.brand = theGridData[brand][counter];
			this.quantity = theGridData[quantity][counter];
			this.comments = theGridData[comments][counter];
			this.store = theGridData[store][counter];
			this.uid = theGridData[uid][counter];
			this.theDate = theGridData[theDate][counter];
			this.theTime = theGridData[theTime][counter];
			this.aisle = theGridData[aisle][counter];
		}

		for (i = 0; i < theGridData[product].length; i++)
		{
			myData[i] = new myArrs(i);
		}

		myData.sort(gridAisleSortCriterium);

		for (i = 0; i < theGridData[product].length; i++)
		{
			theGridData[product][i] = myData[i].product;
			theGridData[brand][i] = myData[i].brand;
			theGridData[quantity ][i] = myData[i].quantity ;
			theGridData[comments][i] = myData[i].comments;
			theGridData[store][i] = myData[i].store;
			theGridData[uid][i] = myData[i].uid;
			theGridData[theDate][i] = myData[i].theDate;
			theGridData[theTime][i] = myData[i].theTime;
			theGridData[aisle][i] = myData[i].aisle;
		}
	}

	function gridAisleSortCriterium(a, b)
	{
		if(LCase(a.aisle) > LCase(b.aisle))
			return 1;
		if(LCase(a.aisle) == LCase(b.aisle))
		{
			if(LCase(a.product) > LCase(b.product))
			return 1;
			if(LCase(a.product) < LCase(b.product))
				return -1;
		}
		return -1
	}
	sortGrid();
}


function autosuggest()
{
	var arrIndex = -1;
	this.display = "text";
	this.enter = false;
	this.processedFirstletter = '';
	this.firstindex = -1;
	this.nextindex = -1;


	function settings()	//private
	{
		var str = "<div id = 'div_autocomplete' style = 'border-color:BLACK;border-width:1px;border-style:solid;";
		str += "background:yellow; position:absolute; left:0; top:0;'";
		str+= "></div>";
		dw(str);
	}
	settings();	


	function HideDisplay()
	{
		hideObject('div_autoS');
		hideObject('div_autocomplete');
	}
	this.hideDisplay = HideDisplay;


	function SugestTxt()
	{
		if (arrProduct.length == 0)
			return true;
		var counter = 0;
		var firstSelectedIndex = -1;
		var str = "";
		var strHead = '';
		var pr = '';
		var offset = 13;
		document.getElementById('div_autocomplete').innerHTML = "";
		var theTxt = replace(eval("window.document.frmGrid.Product_" + grid.active).value, "'", "`");
		var ltxt = '';
		var selectLen = window.document.frmGrid.txt2sugest.length;
		var pos;
		var i;
		arrIndex = -1;
		as.hideDisplay();
		if (this.enter)
			return true;
		if (eval("window.document.frmGrid.Product_" + grid.active).value == "")
			return true;

		for(i = 0; i < selectLen; i++)
		{
			window.document.frmGrid.txt2sugest.options[i].selected = false;
		}

		if (arrHintForm.length == 0)
		{
			for (i = 0; i < arrProduct.length; i++)
			{	
				if (window.document.frmGrid.txt2sugest.options[i].text != '')
				{	
					arrHintForm[i] = LCase(window.document.frmGrid.txt2sugest.options[i].text);
				}
			}
		}

			
		ltxt = Character(LCase(theTxt), 0);
		if (this.processedFirstletter != ltxt)
		{
			this.processedFirstletter = ltxt;
			for (i = 0; i < arrAutoFirstletter.length; i++)
			{
				if (ltxt == arrAutoFirstletter[i])
				{
					this.firstindex = arrAutoFirstIndex[i];
					if (i < arrAutoFirstIndex.length - 1)
					{	
						this.nextindex = arrAutoFirstIndex[i + 1]
					}
					else
					{
						this.nextindex = selectLen - 1;
					}
					break;
				}
			}
		}


		pos = findPos('span_theTxt_' + grid.active);
		moveElem('div_autoS', pos[0], pos[1] + offset);
		moveElem('div_autocomplete', pos[0], pos[1] + offset);
		ltxt = LCase(theTxt);

		str = '';

		for(i = this.firstindex; i < this.nextindex; i++)
		{
			if (inStr(arrHintForm[i], ltxt) == 0)
			{
				arrIndex = i;
				if (counter == 0)
				{
					firstSelectedIndex = i;
					counter++;
				}
				str += "<a href = '#' onClick = \"as.enter=true;";
				str += "as.writeTxt2TextBox('" + i + "');as.setBlur();grid.makeNewEntry();grid.guess();";
				str += "return false; \">";
				str += arrProduct[i];
				str += "</a><br>";
			}
		}

		if (str != '')
		{
			strHead = "<font color = 'red' size = '-1'>Click below to choose:<br></font>";
		}
		document.getElementById('div_autocomplete').innerHTML = strHead + str;

		if (counter > 0)
			window.document.frmGrid.txt2sugest.options[firstSelectedIndex].selected = true;
		if (as.display == "text")
		{
			showObject('div_autocomplete');
		}
		else
		{
			showObject('div_autoS');
		}
		return true;
	}
	this.sugestTxt = SugestTxt;



	function WriteTxt2TextBox(index)
	{
		if (isVisible('div_autoS') == false && isVisible('div_autocomplete') == false)
			return '';
		var i = 0;
		if (index != null)
		{
			var selectedText = window.document.frmGrid.txt2sugest.options[index].value;
		}
		else
		{
			var selectedItem = window.document.frmGrid.txt2sugest.selectedIndex;
			var selectedText = window.document.frmGrid.txt2sugest.options[selectedItem].value;
		}
		eval("window.document.frmGrid.Product_" + grid.active).value = replace(eval("window.document.frmGrid.Product_" + grid.active).value, "'", "`");
		var theTxt = eval("window.document.frmGrid.Product_" + grid.active).value;
		var selectLen = window.document.frmGrid.txt2sugest.length;
		for(i = 0; i < selectLen; i++)
		{
			if (inStr(LCase(window.document.frmGrid.txt2sugest.options[i].text), LCase(theTxt)) == 0)
			{
				eval("window.document.frmGrid.Product_" + grid.active).value = selectedText;
				synchBoxes();
				document.getElementById('div_autoS').style.display = 'none';
				eval("window.document.frmGrid.Brand_" + grid.active).value = arrBrand[arrIndex];
				eval("window.document.frmGrid.Quantity_" + grid.active).value = arrQuantity[arrIndex];
				eval("window.document.frmGrid.Comments_" + grid.active).value = arrComments[arrIndex];
				eval("window.document.frmGrid.aisle_" + grid.active).value = arrAisles[arrIndex];
				break;
			}
		}
		return '';
	} 
	this.writeTxt2TextBox = WriteTxt2TextBox;


	function SetBlur()
	{
		eval("window.document.frmGrid.Product_" + grid.active).blur();
	}
	this.setBlur = SetBlur;


	function synchBoxes()	//private
	{
		var i;
		for (i = 0; i < arrProduct.length; i ++)
		{
			if (LCase(eval("window.document.frmGrid.Product_" + grid.active).value) == LCase(arrProduct[i]))
			{
				arrIndex = i;
				break;
			}
		}
	}
}	//end class autosuggest
var as = null;
var arrAutoFirstletter = null;
var arrAutoFirstIndex = null;
var arrHintForm = null;


function editableShoppingList()
{
	as = new autosuggest();
	sortGridData();
	this.automaticUpdate = false;
	this.hintCounter = arrProduct.length;
	this.goAhead = '';
	this.active = -1;
	this.storeCounter = 0;
	this.stores = new Array();
	this.displayStore = "";
	this.NumOfEntries = 0;
	
	this.userAction = false;
	this.submiting = false;
	this.dels = true;
	this.boughts = true;
	this.delBoughtWidth = 0;
	this.initSize = 0;  //for ie

	this.d = null;
	this.l = null;
	this.start = null;
	this.end = null;
	this.duration = null;
	this.notifWin = null;
	
	

	function InitGrid()
	{
		this.d = new Date();
		this.start = (this.d.getSeconds() * 1) + (this.d.getMinutes() * 60) + (this.d.getHours() * 3600);
		var i = 0;

/*
		if (isVB)
		{
			if (!this.notifWin || this.notifWin.closed)
			{
				this.notifWin = window.open("page4ie.html", '', 'width=300,height=150');
				try
				{
					this.notifWin.focus();
					this.notifWin.document.getElementById('div4IE').innerHTML = "Loading the list";
				}
				catch(e){}
			}
		}
*/
		grid.synchHints();
		grid.sortHints();
		grid.firstLetterHints();
		
		if (grid.editType == 'pantry')
		{
			this.delBoughtWidth = 85;
		}
		else
		{
			if (grid.editType == 'shoppingList')
			{
				this.delBoughtWidth = 50;
			}
		}
		this.keepEditSingle();	
		for(i = 0; i < this.gridData[stores][storeNames].length; i++)
		{
			this.addStore(i);
		}
		if (this.gridData[product].length == 0)
		{	
			this.setGrid();
		}	
		else
		{
			this.setGridData();
		}
		try
		{
			this.setList2Store(this.getDefStore());
		}
		catch(e)
		{
			this.setList2Store(0);
		}
		this.addFromPantry2shoppingList();
		return '';
	}
	this.initGrid = InitGrid;


	function KickIE(i)
	{
		var c = parseInt(i / 4);
		var str = '';
		if (c % 2 == 0)
			str = "<img src =  'images/wizard_kick.gif'>";
		else
			str = "<img src =  'images/wizard_stand.gif'>";
		return str;	
	}
	this.kickIE = KickIE;


	function FirstLetterHints()
	{
		arrAutoFirstletter = new Array();
		arrAutoFirstIndex = new Array();
		arrHintForm = new Array();
		var counter = 0;
		var letter = '';
		var oldLetter = '';
		var i = 0;
		for (i = 0; i < arrProduct.length; i++)
		{
			if (arrProduct[i] != '')
			{
				letter = Character(arrProduct[i], 0);
				if (letter != '')
				{
					letter = LCase(letter);
					if (oldLetter != letter)
					{
						oldLetter = letter;
						arrAutoFirstletter[counter] = letter;
						arrAutoFirstIndex[counter] = i;
						counter++;
					}
				}
			}
		}
	}
	this.firstLetterHints = FirstLetterHints;


	function SynchHints()
	{
		var chkHints = chr(9) + LCase(arrProduct.join(chr(9))) + chr(9);
		var i = 0;
		var chk = '';
		var val = 0;

		for (i = 0; i < arrDefProduct.length; i++)
		{
			chk = LCase(chr(9) + arrDefProduct[i] + chr(9));
			if (inStr(chkHints, chk) == -1)
			{
				val = arrProduct.length - 1;
				arrProduct[val] = arrDefProduct[i];
				arrProduct[val + 1]  = "";
				arrBrand[val] = arrDefBrand[i];
				arrBrand[val + 1]  = "";
				arrQuantity[val] = arrDefQuantity[i];
				arrQuantity[val + 1]  = "";
				arrComments[val] = arrDefComments[i];
				arrComments[val + 1]  = "";
				arrAisles[val] = arrDefAisles[i];
				arrAisles[val + 1]  = "";
			}
		}
	}
	this.synchHints = SynchHints


	function Guess()
	{
		var str = '';
		var c = this.NumOfEntries - 2;
		if (c < 0)
			return;
		if (eval("window.document.frmGrid.aisle_" + (c)).value != "not specified")
			return;
		str = replace(eval("window.document.frmGrid.Product_" + (c)).value, ",", " ");
		str = replace(str, ".", " ");
		str = replace(str, ";", " ");
		str = replace(str, "(", " ");
		str = replace(str, ")", " ");
		str = replace(str , "  ", " ");
		if (replace(str, " ", "") == '')
			return;
		str = trim(str);
		eval("window.document.frmGrid.Product_" + (c)).value = replace(eval("window.document.frmGrid.Product_" + (c)).value, "  ", " ");
		eval("window.document.frmGrid.Product_" + (c)).value = trim(eval("window.document.frmGrid.Product_" + (c)).value);
		if (eval("window.document.frmGrid.aisle_" + (c)).value != '')
		{
			if (replace(eval("window.document.frmGrid.aisle_" + (c)).value, " ", "") != '')
			{
				eval("window.document.frmGrid.aisle_" + (c)).value = replace(eval("window.document.frmGrid.aisle_" + (c)).value, "  ", " ");
				eval("window.document.frmGrid.aisle_" + (c)).value = trim(eval("window.document.frmGrid.aisle_" + (c)).value);
			}
			else
			{
				eval("window.document.frmGrid.aisle_" + (c)).value = '';
			}
		}

		function makePlural(prd, theHint, counter)
		{
			if (LCase(prd) == LCase(theHint))
			{	
				eval("window.document.frmGrid.aisle_" + (c)).value = arrAisles[counter];
				return;
			}
			if (LCase(prd) == LCase(theHint + "s"))
			{	
				eval("window.document.frmGrid.aisle_" + (c)).value = arrAisles[counter];
				return;
			}
			if (LCase(prd) == LCase(theHint + "e"))
			{	
				eval("window.document.frmGrid.aisle_" + (c)).value = arrAisles[counter];
				return;
			}
			if (LCase(prd) == LCase(theHint + "es"))
			{	
				eval("window.document.frmGrid.aisle_" + (c)).value = arrAisles[counter];
				return;
			}
		}

		function findAisle(s)
		{
			var i = 0;
			var ies = "";
			var pr = s;
			if (pr == null)
				pr = str;

			for (i = 0; i < arrProduct.length; i++)
			{
				makePlural(pr, arrProduct[i], i);
				if (eval("window.document.frmGrid.aisle_" + (c)).value != "not specified")
					return;
			}

			ies = strawberry(pr);
			if (ies != "")
			{
				for (i = 0; i < arrProduct.length; i++)
				{
					if (LCase(arrProduct[i]) == LCase(ies))
					{
						eval("window.document.frmGrid.aisle_" + (c)).value = arrAisles[i];
						return;
					}
				}						
			}
		}

		function strawberry(s)
		{
			var chk = '';
			var i = 0;
			if (s == null)
				s = eval("window.document.frmGrid.Product_" + (c)).value;
			if (s.length >= 4)
			{
				chk +=s.charAt(s.length -3);
				chk += s.charAt(s.length -2);
				chk += s.charAt(s.length -1);
			}
			if (LCase(chk) == 'ies')
			{
				chk = '';
				for (i = 0; i < s.length -3; i++)
				{
					chk += s.charAt(i);
				}
				chk += "y"
				return chk;						
			}
			return "";
		}

		function findInItem()
		{
			var chkStr = '';
			var i = 0;
			var ii = 0;
			var chkPr = '';
			var ies = '';
			var arrPr = str.split(" ");

			if (eval("window.document.frmGrid.aisle_" + (c)).value != "not specified")
				return;	

			chkPr = findStrong(str);
			if (chkPr != "not specified")
			{
				eval("window.document.frmGrid.aisle_" + (c)).value = chkPr;
				return;
			}
			chkPr = '';
			
			arrPr = arrPr.reverse();
			for (ii = 0; ii < arrPr.length; ii++)
			{
				for (i = 0; i < arrProduct.length; i++)
				{
					if (arrProduct[i] != '')
					{
						if (inStr(arrProduct[i], " ") == -1)
							chkPr = arrProduct[i];
						else
						{
							chkPr = arrProduct[i].split(" ");
							chkPr = chkPr[chkPr.length - 1];
						}
						
						if (LCase(chkPr) == LCase(arrPr[ii]))
						{
							if (ii == 0)
							{
								eval("window.document.frmGrid.aisle_" + (c)).value = arrAisles[i];
								return;	
							}
						}
						
						makePlural(arrPr[ii], chkPr, i);
						if (ii == 0)
						{
							if (eval("window.document.frmGrid.aisle_" + (c)).value != "not specified")
								return;
						}

						ies = strawberry(arrPr[ii]);
						if (ies != '')
						{
							if (inStr(LCase(chkPr), LCase(ies)) != -1)
							{
								if (ii == 0)
								{
									eval("window.document.frmGrid.aisle_" + (c)).value = arrAisles[i];
									return;
								}
							}
						}
					}
				}
			}
		}

		function spelling()
		{
			var spellStr = str;
			var oldStr = str;

			spellStr = spellStr.replace("k", "c");
			findAisle(spellStr);
			spellStr = oldStr;
			if (eval("window.document.frmGrid.aisle_" + (c)).value != "not specified")
			{
				return;	
			}
			spellStr = replace(LCase(spellStr), "k", "c");
			findAisle(spellStr);
			spellStr = oldStr;
			if (eval("window.document.frmGrid.aisle_" + (c)).value != "not specified")
			{
				return;	
			}
		
		}
		
		findAisle();
		if (eval("window.document.frmGrid.aisle_" + (c)).value != "not specified")
			return;	
		if (inStr(str, " ") != -1)
		{
			findInItem();
			if (eval("window.document.frmGrid.aisle_" + (c)).value != "not specified")
				return;
		}
		spelling();
	}
	this.guess = Guess;
	

	function GetDefStore()
	{
		var index = getSubCookie('Util', 'defStore', '&');
		if (index == '')
			return 0;
		return index * 1;
	}
	this.getDefStore = GetDefStore;

	function SetDefStore(index)
	{
		if (grid.displayStore == '')
			return;
		setSubCookie('Util', 'defStore', index, '&');
		setSubCookie('Util', 'myStoreID', grid.gridData[stores][storeIDs][index], '&');
	}
	this.setDefStore = SetDefStore;


	function ForIE()
	{
		if (isVB)
		{
			if (buildGrid == true)
			{
				//grid.repopulateGridData();
			}
		}

/*
		if (isVB)
		{
			try
			{
				this.notifWin.close();
			}
			catch(e){}
		}
*/
		isSafe2Exit = true;
		this.l = new Date();
		this.end = (this.l.getSeconds() * 1) + (this.l.getMinutes() * 60) + (this.l.getHours() * 3600);
		this.duration = this.end - this.start;
		window.status = (grid.NumOfEntries - 1) + " items in a list. Duration " + this.duration + " seconds";
	}
	this.forIE = ForIE;


	function ReStoreGrid()
	{
		var i = 0;
		var input = null;
		var product = null;
		//alert("in ReStoreGrid");
		window.status = 'setting display for list elements';
		for (i = 0; i < grid.NumOfEntries; i++)
		{
/*
			if (isVB)
			{
				try
				{
					this.notifWin.focus();
					this.notifWin.document.getElementById('div4IE').innerHTML = "drawing form element " + i + this.kickIE(i);
				}
				catch(e){}
			}
*/		
			if (grid.displayStore == "")
			{	
				showObject("SpanProduct_" + i);
				showObject("StoreInputSpan_" + i);	
			}
			else
			{	
				input = eval("window.document.frmGrid.Store_" + i);
				product = eval("window.document.frmGrid.Product_" + i);
				if(input.value != '')
				{
					var str = '';
					str = "window.document.frmGrid.Product_" + i;
					str += "\n" + LCase(grid.displayStore);
					str += "\n" + LCase(input.value);
					if(LCase(grid.displayStore) == LCase(input.value))
					{
						showObject("SpanProduct_" + i);	
					}
					else
					{
						hideObject("SpanProduct_" + i);
					}
				}
			}
		}
		//alert("out of  ReStoreGrid");
		window.status = 'Drawing display.';
	}
	this.reStoreGrid = ReStoreGrid;


	function SetGrid()
	{
		grid.addHeaders();
		var myNode = document.createElement("span");
		myNode.setAttribute("id", "insertPoint");
		document.getElementById('DivProducts').appendChild(myNode);
		grid.initSize = 0;
		grid.NumOfEntries = 0;
		grid.makeEntry();
		grid.setProductFocus();
	}
	this.setGrid = SetGrid;


	function PopulateGrid()
	{
		//alert("in PopulateGrid()");
		window.status = 'populating list with data';
		var i = 0;
		var counter = 0;
		var tmp = '';
		for (counter = 0; counter < grid.gridData[product].length; counter++)
		{
			window.status = 'populating list with data ' + counter;
/*
			if (isVB)
			{
				try
				{
					this.notifWin.focus();
					this.notifWin.document.getElementById('div4IE').innerHTML = "entering list element " + counter + this.kickIE(counter);
				}
				catch(e){}
			}
*/
			if (grid.gridData[product][counter] != "")
			{
				if (inStr(grid.gridData[comments][counter], "~t~") == -1)
				{
					eval("window.document.frmGrid.Product_" + i).value = replace(grid.gridData[product][counter], chr(9), ",");
					eval("window.document.frmGrid.Product_" + i).value = replace(eval("window.document.frmGrid.Product_" + i).value, "'", "`");
					eval("window.document.frmGrid.Brand_" + i).value = replace(grid.gridData[brand][counter], chr(9), ",");
					eval("window.document.frmGrid.Quantity_" + i).value = replace(grid.gridData[quantity][counter], chr(9), ",");
					eval("window.document.frmGrid.Comments_" + i).value = replace(grid.gridData[comments][counter], chr(9), ",");
					eval("window.document.frmGrid.Store_" + i).value = replace(grid.gridData[store][counter], chr(9), ",");
					eval("window.document.frmGrid.uid_" + i).value = grid.gridData[uid][counter];
					eval("window.document.frmGrid.theDate_" + i).value = grid.gridData[theDate][counter];
					eval("window.document.frmGrid.theTime_" + i).value = grid.gridData[theTime][counter];
					tmp = grid.gridData[aisle][counter];
					tmp = replace(tmp, ';', ',');
					eval("window.document.frmGrid.aisle_" + i).value = tmp;
					i++;
				}
			}
		}
	}
	this.populateGrid = PopulateGrid;


	function SetGridData()
	{
		var i = 0;
		var dummy;
		var counter = 0;
		grid.addHeaders();
		grid.initSpans();
		var myNode = document.createElement("span");
		myNode.setAttribute("id", "insertPoint");
		document.getElementById('DivProducts').appendChild(myNode);
		grid.NumOfEntries = 0;
		for (counter = 0; counter < grid.gridData[product].length; counter++)
		{
			if (inStr(grid.gridData[comments][counter], "~t~") == -1)
			{
				dummy = this.makeEntry();
			}
		}
		grid.populateGrid();
		grid.setProductFocus();
	}
	this.setGridData = SetGridData;

	
	function RepopulateGridData()
	{
		grid.populateGrid();
	}
	this.repopulateGridData = RepopulateGridData;


	function CheckBought()
	{
		var i;
		for (i = 0; i < grid.NumOfEntries - 1; i++)
		{
			if (LCase(eval("window.document.frmGrid.Store_" + i).value) == LCase(grid.displayStore))
			{
				eval("window.document.frmGrid.del_" + i).checked = false;
				eval("window.document.frmGrid.bought_" + i).checked = grid.boughts;
			}
		}	
		if (grid.boughts == false)
			grid.boughts = true;
		else
			grid.boughts = false;
		grid.dels = true
	}
	this.checkBought = CheckBought;


	function CheckDelete()
	{
		var i;
		for (i = 0; i < grid.NumOfEntries - 1; i++)
		{
			if (LCase(eval("window.document.frmGrid.Store_" + i).value) == LCase(grid.displayStore))
			{
				eval("window.document.frmGrid.bought_" + i).checked = false
				eval("window.document.frmGrid.del_" + i).checked = grid.dels;
			}
		}
		if (grid.dels == false)
			grid.dels = true;
		else
			grid.dels = false;
		grid.boughts = true;
	}
	this.checkDelete = CheckDelete;


	function UncheckB(i)
	{
		eval("window.document.frmGrid.bought_" + i).checked = false;
	}
	this.uncheckB = UncheckB;


	function UncheckD(i)
	{
		eval("window.document.frmGrid.del_" + i).checked = false;
	}
	this.uncheckD = UncheckD;


	function AddHeaders()
	{
		var newHTML = "";
		var i = 0;
		var tmp = '';
		newHTML = "<table border = '0' cellpadding = '0' cellspacing = '0'><tr><td width = '";
		newHTML += grid.delBoughtWidth;
		newHTML += "'>";
		if (grid.editType == 'pantry')
		{
			newHTML += "<a href = '#' onClick = 'grid.checkBought(); return false;' title = 'Check\\Uncheck all Bought for this store'";
			newHTML += ">bought</a>";
			newHTML += "&nbsp;&nbsp;&nbsp;"
			newHTML += "<a href = '#' onClick = 'grid.checkDelete(); return false;' title = 'Check\\Uncheck all Delete for this store'";
			newHTML += ">del</a>";
		}
		else
		{
			if (grid.editType == 'shoppingList')
			{
				newHTML += "delete";
			}
		}
		newHTML += "</td><td>";	
		newHTML += '<input type = "text" value = "Item*" size = "19" onFocus = "blur();" style = "color:green;font-weight:bold;">';
		newHTML += '<input type = "text" value = "Brand" size = "12" onFocus = "blur();" style = "color:green;font-weight:bold;">';
		newHTML += '<input type = "text" value = "Quantity" size = "7" onFocus = "blur();" style = "color:green;font-weight:bold;">';
		if (grid.editType == 'shoppingList')
		{
			newHTML += '<input type = "text" value = "Notes" size = "20" onFocus = "blur();" style = "color:green;font-weight:bold;">';
			newHTML += "<span id = 'storeHeader'>";
			newHTML += '<!-- <input type = "text" value = "Store" size = "20" onFocus = "blur();" style = "color:green;font-weight:bold;"> -->';
			newHTML += "</span>";
		}
		else
		{
			if (grid.editType == 'pantry')
			{
				newHTML += '<input type = "hidden" value = "Notes" size = "20" onFocus = "blur();" style = "color:green;font-weight:bold;">';
				newHTML += "<span id = 'storeHeader'>";
				newHTML += '<!-- <input type = "text" value = "Store" size = "20" onFocus = "blur();" style = "color:green;font-weight:bold;"> -->';
				newHTML += "</span>";
			}
		}
		newHTML += "<input type = 'text' value = 'Aisle' size = '12' onFocus = 'blur();' style = 'color:green;font-weight:bold;'>";
		newHTML += '';
		newHTML += "<div id = 'div_autoS' style = 'position:absolute;top:0;left:0;'>";
		newHTML += "<select name = 'txt2sugest' onChange = 'as.writeTxt2TextBox(); return false;' size = '1'>";
		for (i = 0; i < arrProduct.length; i++)
		{
			tmp = replace(arrProduct[i], "'", "`");
			newHTML += "<option value = '" + tmp + "'>";
			newHTML += tmp + "</option>";
		}
		newHTML += "</select></div>&nbsp;&nbsp;</td></tr></table>";
		document.getElementById('DivProducts').innerHTML = newHTML;
		grid.setAisles();
		animato.IntID['id4aisles'] = setInterval("grid.stickyAisle()", 50);
	}
	this.addHeaders = AddHeaders;


	function StickyAisle()
	{
		var currentPos = findTop("SpanProduct_" + this.active);
		if (currentPos < 300)
		{
			currentPos = currentPos - 30;
		}
		else
		{
			currentPos = currentPos - 150;
		}
		moveElem('aisleContainer', ObjLeft('aisleContainer'), currentPos);
	}
	this.stickyAisle = StickyAisle;


	function SetAisles()
	{
		var i;
		var str = '';
		var recentLetter = '';
		var checkLetter = '';

		for (i = 0; i < customAisles2display.length; i++)
		{
			if (customAisles2display != "")
			{
				aisles2display[aisles2display.length] = customAisles2display[i];
			}
		}
		aisles2display.sort(noCaseCriterium);

		str += "<br><table border = '0'>";
		for (i = 0; i < aisles2display.length; i++)
		{
			if (aisles2display[i] != "")
			{
				checkLetter = UCase(Character(aisles2display[i], 0));
				if (checkLetter != recentLetter)
				{
					recentLetter = checkLetter
					str += "<tr><td><b><font style = 'font-size:14;'>";
					str += recentLetter + "</font></b><td width = '5'></td>";
				}
				else
				{
					str += "<tr><td><td width = '5'></td>";
				}
				str += "<td><a href = '#' onClick = 'grid.insertAisle(\"" + i + "\");return false;'>";
				str += "<font style = 'font-size:12;'>";
				str += aisles2display[i];
				str += "</font>";
				str += "</a>"
				if (i < aisles2display.length)
					str += "</td></tr>";
			}
		}
		str += "</table>";
		document.getElementById("aisles").innerHTML = str;
		return '';
	}
	this.setAisles = SetAisles;


	function InsertAisle(i)
	{
		eval("window.document.frmGrid.aisle_" + grid.active).value = aisles2display[i];
		grid.makeNewEntry();
	}
	this.insertAisle = InsertAisle;


	function SetProductFocus()
	{
		window.document.frmGrid.Product_0.focus();
	}
	this.setProductFocus = SetProductFocus;


	function NewHTML()
	{
		var newHTML = "";
		newHTML += "<table border = '0' cellpadding = '0' cellspacing = '0'><tr><td width = '";
		newHTML += grid.delBoughtWidth;
		newHTML += "'>";
		newHTML += "<span id = 'boughtDelete_"  + grid.NumOfEntries + "'>";
		if (grid.editType == 'pantry')
		{
			newHTML += "<table width = '100%'><tr><td>";
			newHTML += "<input type = 'checkbox' name = 'bought_" + grid.NumOfEntries + "' ";
			newHTML += "onClick = 'grid.uncheckD(" + grid.NumOfEntries + ")'>";
			newHTML += "</td><td align = 'center'>"
			newHTML += "<input type = 'checkbox' name = 'del_" + grid.NumOfEntries + "' ";
			newHTML += "onClick = 'grid.uncheckB(" + grid.NumOfEntries + ")'>";
			newHTML += "</td></tr></table>";
		}
		else
		{
			if (grid.editType == 'shoppingList')
			{
				newHTML += "<input type = 'checkbox' name = 'del_" + grid.NumOfEntries + "' ";
				newHTML += ">";
			}
		}
		newHTML += "</span>";
		newHTML += "</td><td>";
		newHTML += "<span id = 'span_theTxt_" + grid.NumOfEntries + "'>";
		newHTML += '<input type = "text" size = "19" name = "Product_' + grid.NumOfEntries;
		newHTML += '" value = ""  style = "color:black;font-weight:bold;" ';
		newHTML += 'onBlur = "grid.guess();as.enter = false;" ';
		newHTML += 'onKeyUp = "as.enter = false; as.sugestTxt();" ';
		newHTML += 'onFocus = "grid.active = ' + grid.NumOfEntries;
		newHTML += '; as.enter = false;as.sugestTxt();">';
		newHTML += "</span>";
		newHTML += '<input type = "text" size = "12" name = "Brand_' + grid.NumOfEntries;
		newHTML += '" value = ""  style = "color:black;font-weight:bold;" onFocus="as.hideDisplay();">';
		newHTML += '<input type = "text" size = "7" name = "Quantity_' + grid.NumOfEntries;
		newHTML += '" value = ""  style = "color:black;font-weight:bold;" onFocus="as.hideDisplay();">';
		newHTML += "<span id = 'StoreInputSpan_" + grid.NumOfEntries + "'>";
		newHTML += '<input type = "hidden" name = "Store_' + grid.NumOfEntries;
		newHTML += '" value = "">';
		newHTML += "</span>";
		newHTML += '<input type = "hidden" name = "uid_' + grid.NumOfEntries;
		newHTML += '" value = "">';
		newHTML += '<input type = "hidden" name = "theDate_' + grid.NumOfEntries;
		newHTML += '" value = "">';
		newHTML += '<input type = "hidden" name = "theTime_' + grid.NumOfEntries;
		newHTML += '" value = "">';
		if (grid.editType == 'shoppingList')
		{
			newHTML += '<input type = "text" size = "20" name = "Comments_' + grid.NumOfEntries;
			newHTML += '" value = ""  style = "color:black;font-weight:bold;"  onFocus="as.hideDisplay();">';
		}
		else
		{
			if (grid.editType == 'pantry')
			{
				newHTML += '<input type = "hidden" size = "20" name = "Comments_' + grid.NumOfEntries;
				newHTML += '" value = ""  style = "color:black;font-weight:bold;"  onFocus="as.hideDisplay();">';
			}
		}
		newHTML += '<input type = "text" size = "12" name = "aisle_' + grid.NumOfEntries;
		newHTML += '" value = ""  style = "color:black;font-weight:bold;"  onFocus="as.hideDisplay();grid.active = ' + grid.NumOfEntries + '">';
		newHTML += "</td></tr></table>";
		return newHTML;
	}
	this.newHTML = NewHTML;


	function SortHints()
	{
		var hints = new Array();
		var i = 0;
		var counter = 0;
		var pr = new Array();
		var br = new Array();
		var q = new Array()
		var c = new Array();
		var a = new Array();
	
		for (i = 0; i < arrProduct.length; i++)
		{
			if (arrProduct[i] != '')
			{
				pr[counter] = arrProduct[counter];
				br[counter] = arrBrand[counter];
				q[counter] = arrQuantity[counter];
				c[counter] = arrComments[counter];
				a[counter] = arrAisles[counter];
				counter ++;
			}
		}

		arrProduct = pr;
		arrBrand = br;
		arrQuantity = q;
		arrComments = c;
		arrAisles = a;
	
		function myArrs(counter)
		{
			this.pr = arrProduct[counter];
			this.br = arrBrand[counter];
			this.q = arrQuantity[counter];
			this.c = arrComments[counter];
			this.a = arrAisles[counter];
		}

		for (i = 0; i < arrProduct.length; i++)
		{	
			hints[i] = new myArrs(i);
		}

		hints.sort(grid.hintsCriterium);
		for (i = 0; i < arrProduct.length; i++)
		{
			arrProduct[i] = hints[i].pr;
			arrBrand[i] = hints[i].br;
			arrQuantity[i] = hints[i].q;
			arrComments[i] = hints[i].c;
			arrAisles[i] = hints[i].a;
		}
		var addQIndex = arrProduct.length;
		arrProduct[addQIndex] = "";
		arrBrand[addQIndex] = "";
		arrQuantity[addQIndex] = "";
		arrComments[addQIndex] = "";
		arrAisles[addQIndex] = "";
	}
	this.sortHints = SortHints;


	function HintsCriterium(a, b)
	{
		if (LCase(a.pr) > LCase(b.pr))
			return 1;
		return -1;		
	}
	this.hintsCriterium = HintsCriterium;


	function AddHints()
	{
		var pr = arrProduct.join(chr(9));
		var tmp = '';
		var br = arrBrand.join(chr(9));
		var q = arrQuantity.join(chr(9));
		var c = arrComments.join(chr(9));
		var a = arrAisles.join(chr(9));
		var i = 0;
		
		for (i = 0; i < grid.NumOfEntries; i++)
		{			
			if(eval("window.document.frmGrid.Product_" + i).value != "")
			{
				tmp = eval("window.document.frmGrid.Product_" + i).value;
				if (pr == "")
				{
					pr += eval("window.document.frmGrid.Product_" + i).value + chr(9);
					br += eval("window.document.frmGrid.Brand_" + i).value + chr(9);
					q += eval("window.document.frmGrid.Quantity_" + i).value + chr(9);
					c += eval("window.document.frmGrid.Comments_" + i).value + chr(9);
					a += eval("window.document.frmGrid.aisle_" + i).value + chr(9);
				}
				else
				{
					if(inStr(chr(9) + LCase(pr) + chr(9), chr(9) + LCase(tmp) + chr(9)) == -1)
					{
						pr += eval("window.document.frmGrid.Product_" + i).value + chr(9);
						br += eval("window.document.frmGrid.Brand_" + i).value + chr(9);
						q += eval("window.document.frmGrid.Quantity_" + i).value + chr(9);
						c += eval("window.document.frmGrid.Comments_" + i).value + chr(9);
						a += eval("window.document.frmGrid.aisle_" + i).value + chr(9);
					}
				}
			}
		}
		window.document.frmGrid.ProductHints.value = pr;
		window.document.frmGrid.BrandHints.value = br;
		window.document.frmGrid.QuantityHints.value = q;
		window.document.frmGrid.CommentHints.value = c;
		window.document.frmGrid.AisleHints.value = a;
	
		arrProduct = pr.split(chr(9));
		arrBrand = br.split(chr(9));
		arrQuantity = q.split(chr(9));
		arrComments = c.split(chr(9));
		arrAisles = a.split(chr(9));
		grid.updateHints();
	}
	this.addHints = AddHints;


	function UpdateHints()
	{
		var tmp = '';
		var i = 0;
		var ii = 0;
		var p, b, q, c, a;
		var arrlpr = new Array();
		for (i = 0; i < arrProduct.length; i++)
		{
			arrlpr[i] = LCase(arrProduct[i]);
		}
		for (i = 0; i < grid.NumOfEntries; i++)
		{
			if(eval("window.document.frmGrid.Product_" + i).value != "")
			{
				p = LCase(eval("window.document.frmGrid.Product_" + i).value);
				b = eval("window.document.frmGrid.Brand_" + i).value;
				q = eval("window.document.frmGrid.Quantity_" + i).value;
				c = eval("window.document.frmGrid.Comments_" + i).value;
				a = eval("window.document.frmGrid.aisle_" + i).value;
				for (ii = 0; ii < arrProduct.length; ii++)
				{
					if (arrProduct[ii] != "")
					{
						if (arrlpr[ii] == p) 
						{
							arrBrand[ii] = b;
							arrQuantity[ii] = q;
							arrComments[ii] = c;
							arrAisles[ii] = a;
						}
					}
				}	
			}		
		}
		window.document.frmGrid.ProductHints.value = arrProduct.join(chr(9));
		window.document.frmGrid.BrandHints.value = arrBrand.join(chr(9));
		window.document.frmGrid.QuantityHints.value = arrQuantity.join(chr(9));
		window.document.frmGrid.CommentHints.value = arrComments.join(chr(9));
		window.document.frmGrid.AisleHints.value = arrAisles.join(chr(9));
	}
	this.updateHints = UpdateHints;


	function MakeEntry()	
	{
		var isVBS = isVB;
		var str = "Adding new items? It's easy!";
		str += '\nClick on the store name to add this item and click on "Add New Item" button.';
		if (grid.userAction)
		{
			if (grid.displayStore == '')
			{
				if (!grid.submiting)
				{
					alert(str);
					return '';
				}
			}
			if (eval("window.document.frmGrid.Product_" + (grid.NumOfEntries - 1)).value == '')
			{
				if (!grid.submiting)
				{
					str = "You cannot add an empty entry.";
					str += '\nType product name you want to buy and click on "Add New Item" button.';
					return '';
				}
			}
		}
		str = "The list is exceeding allowed limit of " + grid.NumOfEntries + " entries. ";
		str += "Save this list and open it again, that may eliminate some empty entries."
		if (grid.NumOfEntries > 998)
		{
			alert(str);
			return '';
		}
		if (grid.NumOfEntries >= grid.initSize)
		{
			window.status = 'adding form element ' + grid.NumOfEntries;
			if (!isVBS)
			{
				var myNode = document.createElement("span");
				myNode.setAttribute("id", "SpanProduct_" + grid.NumOfEntries);
				myNode.innerHTML = NewHTML();
				document.getElementById('DivProducts').insertBefore(myNode, document.getElementById('insertPoint'));
			}
			else
			{
				str = '';
				str += "<span id = 'SpanProduct_" + grid.NumOfEntries + "'>";
				str += NewHTML();
				str += "</span>";
				document.getElementById('DivProducts').innerHTML += str;
			}
		}
		else
		{
			window.status = 'updating form element ' + grid.NumOfEntries;
		}
		eval("window.document.frmGrid.Product_" + grid.NumOfEntries + ".focus();");
		window.document.frmGrid.NumOfEntry.value = "" + grid.NumOfEntries + "";
		eval("window.document.frmGrid.Store_" + (grid.NumOfEntries -1)).value = grid.displayStore;
		if (eval("window.document.frmGrid.aisle_" + (grid.NumOfEntries -1)).value == "")
		{
			if (eval("window.document.frmGrid.Product_" + (grid.NumOfEntries -1)).value != "")
				eval("window.document.frmGrid.aisle_" + (grid.NumOfEntries -1)).value = "not specified";
		}
		if(grid.submiting)
		{
			grid.addHints();
		}
		hideObject('boughtDelete_'  + grid.NumOfEntries);
		if (grid.NumOfEntries != 0)
			showObject('boughtDelete_'  + (grid.NumOfEntries - 1));
		grid.NumOfEntries++;
		return '';
	}
	this.makeEntry = MakeEntry;


	function InitSpans()
	{
		var i = 0;
		var str = '';
		if (isVB)
		{
			this.initSize = theGridData[product].length - 2;
			for (i = 0; i < theGridData[product].length; i++)
			{
				if (inStr(theGridData[comments][i], "~t~") != -1)
					this.initSize--;
				if (theGridData[product][i] == '')
					this.initSize--;
			}
			if (this.initSize < 0)
				this.initSize = 0;
			window.status = 'init form elems';
			for (i = 0; i < grid.initSize; i++)
			{
				str += "<span id = 'SpanProduct_" + grid.NumOfEntries + "'>";
				str += NewHTML();
				str += "</span>";
				grid.NumOfEntries++;			
			}
			document.getElementById('DivProducts').innerHTML += str;
			grid.NumOfEntries = 0;
		}
		else
		{
			grid.initSize = 0;
		}
	}
	this.initSpans = InitSpans;


	function MakeNewEntry()
	{
		grid.userAction = true;	
		if (grid.NumOfEntries == 0)
		{
			this.makeEntry();
			return '';
		}
		eval("window.document.frmGrid.Product_" + (grid.NumOfEntries - 1)).value = replace(eval("window.document.frmGrid.Product_" + (grid.NumOfEntries - 1)).value, "'", "`");
		grid.makeEntry();
		isSafe2Exit = false;
		eval("window.document.frmGrid.Product_" + (grid.NumOfEntries - 1)).focus();
		if (grid.editType == 'pantry')
		{
			eval("window.document.frmGrid.bought_" + (grid.NumOfEntries - 2)).checked = true;
		}
	}
	this.makeNewEntry = MakeNewEntry;


	this.addFromPantry2shoppingList = function()
	{
		var i, arrEls;
		grid.userAction = true;	
		for (i = 0; i < addFromPantry.length; i++)
		{
			arrEls = addFromPantry[i].split(chr(9));
			if (arrEls.length = 4)
			{
				eval("window.document.frmGrid.Product_" + (grid.NumOfEntries - 1)).value = arrEls[0];
				eval("window.document.frmGrid.Brand_" + (grid.NumOfEntries - 1)).value = arrEls[1];
				eval("window.document.frmGrid.Quantity_" + (grid.NumOfEntries - 1)).value = arrEls[2];
				eval("window.document.frmGrid.aisle_" + (grid.NumOfEntries - 1)).value = arrEls[3];
				this.makeEntry();			
			}	
		}
		if (addFromPantry.length > 0)
		{
			repSListVals(document.frmGrid); 
			this.updateList();
		}
	}


	function DisplayStores(gridData, editType)
	{
		var i;
		grid.editType = editType;
		grid.gridData = gridData;
		for (i = 0; i < grid.gridData[stores][storeNames]; i++)
		{
			dw("<span id = 'Add" + grid.gridData[stores][storeNames][i] + "'>");
			dw("<a href = '#' onClick = 'grid.addStore(" + i + "); return false;'>");
			dw(grid.gridData[stores][storeNames][i]);
			dw("</a>");
			dw("<br></span>");
		}
	}
	this.displayStores = DisplayStores;

	
	function SetList2Store(index)
	{
		//alert('setting stores');
		window.status = 'setting stores to list elements';
		var i;
		for (i = 0; i < grid.storeCounter; i++)
		{
			hideObject(grid.gridData[stores][storeNames][grid.stores[i]] + "2");
			showObject(grid.gridData[stores][storeNames][grid.stores[i]]);
		}
		grid.displayStore = grid.gridData[stores][storeNames][index];
		grid.setDefStore(index);
		toggle(grid.gridData[stores][storeNames][index]);
		toggle(grid.gridData[stores][storeNames][index] + "2");
		this.reStoreGrid();
		eval("window.document.frmGrid.Product_" + (grid.NumOfEntries -1)).focus();
	}
	this.setList2Store = SetList2Store;


	function UnsetList2Store()
	{
		var i;
		for (i = 0; i < grid.storeCounter; i++)
		{
			hideObject(grid.gridData[stores][storeNames][grid.stores[i]] + "2");
			showObject(grid.gridData[stores][storeNames][grid.stores[i]]);
		}
		grid.displayStore = "";
		this.reStoreGrid();
	}
	this.unsetList2Store = UnsetList2Store;

	
	function AddStore(index)
	{

		var str = '';
		var breakingPoint = grid.gridData[stores][storeNames].length - grid.storeCounter - 1;
		str = document.getElementById('storeNames').innerHTML;
		str += " <span id = \"";
		str += grid.gridData[stores][storeNames][index];
		str += "\" ";
		str += "style = 'background:white'>";

		str += "&nbsp;&nbsp;<a href = '#'";
		str += "onClick = 'grid.setList2Store(" + index + ");return false;'><b><font color = 'black'>";
		str += grid.gridData[stores][storeNames][index];
		str += "</font></b></a>&nbsp;&nbsp;";
		
		str += "</span>"
		str += "<span id = \"";
		str += grid.gridData[stores][storeNames][index];
		str += "2\" ";
		str += "style = 'background:#c2f2b3;'>";
		str += "&nbsp;&nbsp;<b><font color = '#FF9933;'>";
		str += grid.gridData[stores][storeNames][index];
		str += "</font></b>&nbsp;&nbsp;"

		str += "</span> "
		if ((breakingPoint) % 4 == 0)
			str += "<br>";
		document.getElementById('storeNames').innerHTML = str;
		hideObject(grid.gridData[stores][storeNames][index] + "2");
		grid.stores[grid.storeCounter] = index;
		grid.storeCounter++;
	}
	this.addStore = AddStore;


	function KeepEditSingle()
	{
		dw("<div id = 'frame4ajax'><div>");
		animato.IntID['msg4ajax'] = '';
		animato.IntID['ajaxTimer'] = setInterval("grid.ajax()", 60000); 	
	}
	this.keepEditSingle = KeepEditSingle;

	function Ajax()
	{
		animato.ajax('ajax4EditShoppingList.html', 'frame4ajax', animato.IntID['msg4ajax']);
	}
	this.ajax = Ajax;


	function UpdateList()
	{
		showObject("gridHolder");
		var p = eval("window.document.frmGrid.Product_" + (this.NumOfEntries - 1)).value;
		var s = eval("window.document.frmGrid.Store_" + (this.NumOfEntries - 1)).value;
		var str = "Cannot update list when entry is not finished.";
		str += "\nClick on the store name and then on \"Add New Item\"";
		if (p != '' && s == '' && grid.displayStore == '')
		{
			alert(str);
			return false;
		}
		for (i = 0; i < grid.NumOfEntries; i++)
		{
			if (inStr(eval("window.document.frmGrid.Comments_" + i).value, '~t~') != -1 || inStr(eval("window.document.frmGrid.Product_" + i).value, '~t~') != -1)
			{
				eval("window.document.frmGrid.Product_" + i).value = "";
				eval("window.document.frmGrid.Brand_" + i).value = "";
				eval("window.document.frmGrid.Quantity_" + i).value = "";
				eval("window.document.frmGrid.Quantity_" + i).value = "";
				eval("window.document.frmGrid.Comments_" + i).value = "";
			}
		}
		for (i = 0; i < grid.NumOfEntries; i++)
		{
			eval("window.document.frmGrid.Product_" + i).value = replace(replace(eval("window.document.frmGrid.Product_" + i).value, ",", ";" ), "'", "`");
			eval("window.document.frmGrid.Brand_" + i).value = replace(replace(eval("window.document.frmGrid.Brand_" + i).value, ",", ";"), "'", "`");
			eval("window.document.frmGrid.Quantity_" + i).value = replace(replace(eval("window.document.frmGrid.Quantity_" + i).value, ",", ";"), "'", "`");
			eval("window.document.frmGrid.Quantity_" + i).value = replace(replace(eval("window.document.frmGrid.Quantity_" + i).value, chr(92), "/"), "'", "`");
			eval("window.document.frmGrid.Comments_" + i).value = replace(replace(eval("window.document.frmGrid.Comments_" + i).value, ",", ";"), "'", "`");
			if (eval("window.document.frmGrid.Product_" + i).value != '')
			{
				if (eval("window.document.frmGrid.aisle_" + i).value == '')
				{
					eval("window.document.frmGrid.aisle_" + i).value = "not specified";
				}
			}
			eval("window.document.frmGrid.aisle_" + i).value = replace(replace(eval("window.document.frmGrid.aisle_" + i).value, ";", ","), "'", "`");
		}
		grid.submiting=true;
		grid.makeNewEntry();
		hideObject('div_main');
		isSafe2Exit = true;
		setSubCookie('Ut', 'pantryUpdated', 'yes', '&');
		window.document.frmGrid.submit();
		return false;
	}
	this.updateList = UpdateList;


	function UpdateAll()
	{
		if (this.automaticUpdate == false)
			return;
		var i = 0;
		for (i = 0; i < grid.NumOfEntries; i++)
		{
			if (eval("window.document.frmGrid.Product_" + i).value != "")
			{
				eval("window.document.frmGrid.bought_" + i).checked = true;
			}
		}
		this.updateList();
	}
	this.updateAll = UpdateAll;
	
}	//end editableShoppingList class




function transferList()
{
	this.base = editableShoppingList;
	this.base();
	this.frm = null;

	function AfterLoading()
	{
		this.forIE();
		hideObject('gridHolder');
		hideObject('aisleContainer');
		this.writeTransferHTML();
		this.writeTransferData();
		animato.myErrors();
	}
	this.afterLoading = AfterLoading;

	function WriteTransferHTML()
	{
		var str = '';
		var i = 0;
		str += "<form name = 'frmTransfer'><table>";
		str += "<tr><td>";
		str += grid.generateStoreSelect(0)
		str += "</td><td></td><td align = 'right'>";
		str += grid.generateStoreSelect(1)
		str += "</td></tr><tr><td><font color = 'green'>List Items:</font>";
		str += "<div id  = 'storeList_0' style = 'position:relative;width:200;height:280;overflow:auto;background:white;border:1px brown solid;'>";
		str += "no store selected</div>";
		str += "</td><td align = 'center'>";
		str += "<img src = 'images/customstore_arrow.gif' border = '0' alt = ''>";
		str += "</td><td><font color = 'green'>List Items:</font>";
		str += "<div id  = 'storeList_1' style = 'position:relative;width:200;height:280;overflow:auto;background:white;border:1px brown solid;'>";
		str += "no store selected</div>";
		str += "</td></tr><tr><td>"
		str += "<input type = 'submit' value = 'Transfer All >>' onClick = 'grid.transferAll(0,1); return false;'>";
		str += "</td><td></td><td align = 'right'>";
		str += "<input type = 'submit' value = '<< Transfer All' onClick = 'grid.transferAll(1,0); return false;'>";
		str += "</td></tr><tr><td></td><td>";
		str += '<input type = "Submit" value = "Done" onClick = "isSafe2Exit=true;return grid.updateList();">';
		str += "</td><td></td></tr>";
		str += "</table></form>";
		document.getElementById('s_transferHtml').innerHTML = str;		
		grid.frm = window.document.frmTransfer;
	}
	this.writeTransferHTML = WriteTransferHTML;

	function GenerateStoreSelect(selNr)
	{
		var str = '';
		var i = 0;
		var defStore = getSubCookie("Util", "defStore", "&");
		if (selNr != 0)
			defStore = '';
		str += "<select name = 'chooseStore_" + selNr + "' onChange = 'grid.writeTransferData();'>";
		if (defStore == '')
		{
			defStore = -10;
			str += "<option value = '-1' selected >choose store " + (selNr + 1) + "</option>";
		}
		else
		{
			try
			{
				defStore = defStore * 1;
			}
			catch(e){};
			str += "<option value = '-1'>choose store " + (selNr + 1) + "</option>";
		}
		for (i = 0; i < grid.gridData[stores][storeNames].length; i++)
		{
			if (defStore == i)
			{
				str += "<option value = '" + i + "' selected >" + grid.gridData[stores][storeNames][i] + "</option>";
			}
			else
			{
				str += "<option value = '" + i + "'>" + grid.gridData[stores][storeNames][i] + "</option>";
			}
		}
		str += "</select>";
		return str;
	}
	this.generateStoreSelect = GenerateStoreSelect;

	function TransferAll(storeFromIndex, storeToIndex)
	{
		var ind_0 = grid.frm.chooseStore_0.selectedIndex;
		var ind_1 = grid.frm.chooseStore_1.selectedIndex;
		var tmpS = null;
		var storeFrom = null;
		var storeTo = null;
		var storeFromSelInd = null;
		var storeToSelInd = null;
		var i = 0;
		var str = '';
		if (ind_0 == 0 || ind_1 == 0)
		{
			if (ind_0 == 0)
				alert("Please choose store 1");
			if (ind_1 == 0)
				alert("Please choose store 2");
			return false;
		}
		else
		{
			storeFromSelInd = eval("grid.frm.chooseStore_" + storeFromIndex).selectedIndex;
			storeFrom = eval("grid.frm.chooseStore_" + storeFromIndex).options[storeFromSelInd].text;
			storeToSelInd = eval("grid.frm.chooseStore_" + storeToIndex).selectedIndex;
			storeTo = eval("grid.frm.chooseStore_" + storeToIndex).options[storeToSelInd].text;
			for (i = 0; i < theGridData[product].length; i++)
			{
				tmpS = eval("window.document.frmGrid.Store_" + i).value;
				if (tmpS == storeFrom || tmpS == storeTo)
				{
					eval("window.document.frmGrid.Store_" + i).value = grid.frm.chooseStore_0.options[storeToSelInd].text;
				}
			}
			this.writeTransferData();
			isSafe2Exit = false;
		}
	}
	this.transferAll = TransferAll;

	function WriteTransferData()
	{
		var errMsg = '';
		var errCounter = 0;
		var str = '';
		var emptyMsg = "this store's shopping list is empty";
		var notSelected = "no store selected";
		var i = 0;
		var ind_0 = grid.frm.chooseStore_0.selectedIndex;
		var ind_1 = grid.frm.chooseStore_1.selectedIndex;
		var sName_0 = grid.frm.chooseStore_0.options[ind_0].text;
		var sName_1 = grid.frm.chooseStore_1.options[ind_1].text;

		for (i = 0; i < grid.NumOfEntries; i++)
		{
			try
			{
				if (eval("window.document.frmGrid.Store_" + i).value == sName_0)
				{	
					str += this.writeTransferLinks(i, ind_1);
				}
			}
			catch(e)
			{
				if (errCounter < 5)
				{
					errMsg += "Error occured loading the data.";
					errMsg += "\nInformation for technical support:\n";
					errMsg += "Cannot load store info variable sName_0 for product store index: " + i;
					errMsg += "\n" + e.description + "\n----------------\n";
					errCounter++;
				}
			}
		}
		if (str == '')
			str = emptyMsg;
		document.getElementById('storeList_0').innerHTML = str;
		str = '';
		if (ind_1 == 0)
		{
			document.getElementById('storeList_1').innerHTML = notSelected;
		}
		else
		{
			for (i = 0; i < grid.NumOfEntries; i++)
			{
				try
				{
					if (eval("window.document.frmGrid.Store_" + i).value == sName_1)
					{	
						str += this.writeTransferLinks(i, ind_0);
					}
				}
				catch(e)
				{
					if (errCounter < 5)
					{
						errMsg += "Error occured loading the data.";
						errMsg += "\nInformation for technical support:\n";
						errMsg += "Cannot load store info variable sName_1 for product store index: " + i;
						errMsg += "\n" + e.description + "\n----------------\n";
						errCounter++;
					}
				}
			}
			if (str == '')
				str = emptyMsg;
			document.getElementById('storeList_1').innerHTML = str;
			if (errCounter != 0)
				alert(errMsg)
		}
	}
	this.writeTransferData = WriteTransferData;

	function WriteTransferLinks(i, indexStore2move2)
	{
		var str = '';
		str += "<a href = '#' onClick = \"grid.changeFormValue(" + i + ", " + indexStore2move2 + ");return false;\" ";
		str += "title = 'click to move this item to another store' >";
		str += eval("window.document.frmGrid.Product_" + i).value;
		str += "</a><br>";
		return str;
	}
	this.writeTransferLinks = WriteTransferLinks;

	function ChangeFormValue(i, indexStore2move2)
	{
		var ind_0 = grid.frm.chooseStore_0.selectedIndex;
		var ind_1 = grid.frm.chooseStore_1.selectedIndex;
		if (ind_0 == 0 || ind_1 == 0)
		{
			if (ind_0 == 0)
				alert("Please choose store 1");
			if (ind_1 == 0)
				alert("Please choose store 2");
			return false;
		}
		eval("window.document.frmGrid.Store_" + i).value = grid.frm.chooseStore_0.options[indexStore2move2].text;
		grid.writeTransferData();
		isSafe2Exit = false;
		return false;
	}
	this.changeFormValue = ChangeFormValue;

}	//end of class transferList



function mustInheritPrintList(gridData)
{
	sortGridData();
	this.storeCounter = 0;
	this.stores = new Array();
	this.displayStore = "";
	this.NumOfEntries = 0;
	this.gridData = gridData;

	this.index = -1;
	this.kolor = new Array();
	this.kolor[0] = 'yellow';
	this.kolor[1] = 'blue';
	this.kolor[2] = 'lightgreen';
	this.kolor[3] = 'olive';
	this.kolor[4] = 'red';
	this.headerK = '#c2f2b3';


	function InitGrid()
	{
		var i = 0;
		var areItems = false;
		for (i = 0; i < this.gridData[product].length; i++)
		{
			if (this.gridData[product][i] != "")
				areItems = true;
		}
		if (!areItems)
			dw("<br>You have no items in your shopping list<br>");

		for(i = 0; i < this.gridData[stores][storeNames].length; i++)
		{
			this.addStore(i);
		}
		this.reStoreGrid(0);
		this.setList2Store(0);
		return '';
	}
	this.initGrid = InitGrid;

	function AddStore(index)
	{
		var str = '';
		str = document.getElementById('storeNames').innerHTML;
		str += "<span id = \"";
		str += grid.gridData[stores][storeNames][index];
		str += "\" ";
		str += "style = 'background:white;'>&nbsp;&nbsp;";
		str += "<a href = '#'";
		str += "onClick = 'grid.setList2Store(" + index + ");return false;'><b><font color = 'black'>";
		str += grid.gridData[stores][storeNames][index];
		str += "</font></b></a>&nbsp;&nbsp;</span>"
		str += "<span id = \"";
		str += grid.gridData[stores][storeNames][index];
		str += "2\" ";
		str += "style = 'background:#c2f2b3'>&nbsp;&nbsp;";
		str += "<b><font color = '#FF9933'>";
		str += grid.gridData[stores][storeNames][index];
		str += "</font></b>&nbsp;&nbsp;</span>"
		document.getElementById('storeNames').innerHTML = str;
		hideObject(grid.gridData[stores][storeNames][index] + "2");
		grid.stores[grid.storeCounter] = index;
		grid.storeCounter++;
	}
	this.addStore = AddStore;
}
	//end mustInheritPrintList class


//start page PrintList.html

function printList(gridData)
{
	this.base = mustInheritPrintList;
	this.base(gridData);

	function SetList2Store(index)
	{
		var i;
		for (i = 0; i < grid.storeCounter; i++)
		{
			hideObject(grid.gridData[stores][storeNames][grid.stores[i]] + "2");
			showObject(grid.gridData[stores][storeNames][grid.stores[i]]);
		}
		grid.displayStore = grid.gridData[stores][storeNames][index];
		toggle(grid.gridData[stores][storeNames][index]);
		toggle(grid.gridData[stores][storeNames][index] + "2");
		grid.reStoreGrid(index);
	}
	this.setList2Store = SetList2Store;


	function ReStoreGrid(index)
	{
		var str = '';
		var i = 0;
		var isDataThere = false
		var checkKolor = '-1';
		var kolorIndex = 0;
		str += "<form>";
		str += "<table width = '90%' border = '1'><tr>";
		str += "<td bgcolor = '"+grid.headerK+"' width = '30' align = 'center'><img src = 'images/bought_icon.gif' alt = ''></td>";
		str += "<td bgcolor = '"+grid.headerK+"'  width = '30' align = 'center'><img src = 'images/del_icon.gif' alt = ''></td>";
		str += "<td bgcolor = '"+grid.headerK+"'><b>Product</b></td><td bgcolor = '"+grid.headerK+"'><b>Brand</b></td>";
		str += "<td bgcolor = '"+grid.headerK+"'><b>";
		str += "Quantity</b></td><td bgcolor = '"+grid.headerK+"'><b>Notes</b></td><td bgcolor = '"+grid.headerK+"'><b>Aisle</b>";
		str += "</td></tr>";
		for (i = 0; i < grid.gridData[product].length; i++)
		{
			if (grid.gridData[store][i] == grid.gridData[stores][storeNames][index])
			{
				if (grid.gridData[product][i] != "")
					isDataThere = true;
				if (checkKolor != LCase(grid.gridData[aisle][i]))
				{
					kolorIndex++;
					kolorIndex = kolorIndex % 5;
					checkKolor = LCase(grid.gridData[aisle][i]);
				}
				str += "<tr>";
				str += "<TD VALIGN = 'TOP'>";
				str += "<input type = 'checkbox'></td>"
				str += "<TD VALIGN = 'TOP'>";
				str += "<input type = 'checkbox'></td>"
				str += "<TD VALIGN = 'TOP'>";
				str += "<table><tr><td bgcolor = 'white'>";
				str += "<font color = '" + grid.kolor[kolorIndex] + "'>&#9733;</font></td><td>";
				str += "&nbsp;" + grid.gridData[product][i] + "&nbsp;</td></tr></table></td>";
				str += "<TD VALIGN = 'TOP'>";
				str += grid.gridData[brand][i] + "&nbsp;</td>";
				str += "<TD VALIGN = 'TOP'>" 
				str += grid.gridData[quantity][i] + "&nbsp;</td>";
				str += "<TD VALIGN = 'TOP'>";
				str += grid.gridData[comments][i] + "&nbsp;</td>";
				str += "<TD valign = 'top'>"
				str += grid.gridData[aisle][i] + "&nbsp;</td>";
				str += "</tr>";
			}
		}
		str += "</table>";
		str += "</form>";
		document.getElementById("ShoppingListData").innerHTML = str;
	}
	this.reStoreGrid = ReStoreGrid;
}

//end page PrintList.html


//start page PrintAllLists.html

function printAllLists(gridData)
{
	this.base = mustInheritPrintList;
	this.base(gridData);

	function SetList2Store(index)
	{
		var i;
		grid.html = '';
		gridData = '';
		for (i = 0; i < grid.storeCounter; i++)
		{
			hideObject(grid.gridData[stores][storeNames][grid.stores[i]] + "2");
			hideObject(grid.gridData[stores][storeNames][grid.stores[i]]);
		}
		grid.displayStore = grid.gridData[stores][storeNames][index];
		for (i = 0; i < grid.storeCounter; i++)
		{
			gridData = grid.reStoreGrid(i);
			if (gridData != "")
			{
				grid.html += "<br><b>" + grid.gridData[stores][storeNames][grid.stores[i]];
				grid.html += "</b><br>" + gridData;
			}
		}
		document.getElementById("ShoppingListData").innerHTML = grid.html;
	}
	this.setList2Store = SetList2Store;


	function ReStoreGrid(index)
	{
		var str = '';
		var i = 0;
		var isDataThere = false
		var checkKolor ='-1';
		var kolorIndex = 0;
		str += "<form>";
		str += "<table width = '90%' border = '1'><tr>";
		str += "<td bgcolor = '"+grid.headerK+"' width = '30' align = 'center'><img src = 'images/bought_icon.gif' alt = ''></td>";
		str += "<td bgcolor = '"+grid.headerK+"' width = '30' align = 'center'><img src = 'images/del_icon.gif' alt = ''></td>";
		str += "<td bgcolor='"+grid.headerK+"'><b>Product</b></td><td bgcolor='"+grid.headerK+"'><b>Brand</b></td>";
		str += "<td bgcolor = '"+grid.headerK+"'><b>";
		str += "Quantity</b></td><td bgcolor='"+grid.headerK+"'><b>Notes</b></td><td bgcolor='"+grid.headerK+"'><b>Aisle</b>";
		str += "</td></tr>";
		for (i = 0; i < grid.gridData[product].length; i++)
		{
			if (grid.gridData[store][i] == grid.gridData[stores][storeNames][index])
			{
				if (grid.gridData[product][i] != "")
					isDataThere = true;
				if (checkKolor != LCase(grid.gridData[aisle][i]))
				{
					kolorIndex++;
					kolorIndex = kolorIndex % 5;
					checkKolor = LCase(grid.gridData[aisle][i]);
				}
				str += "<tr>";
				str += "<TD VALIGN = 'TOP'>";
				str += "<input type = 'checkbox'></td>"
				str += "<TD VALIGN = 'TOP'>";
				str += "<input type = 'checkbox'></td>"
				str += "<TD VALIGN = 'TOP'>";
				str += "<table><tr><td bgcolor = 'white'>";
				str += "<font color = '" + grid.kolor[kolorIndex] + "'>&#9733;</font></td><td>";
				str += "&nbsp;" + grid.gridData[product][i] + "&nbsp;</td></tr></table></td>";
				str += "<TD VALIGN = 'TOP'>";
				str += grid.gridData[brand][i] + "&nbsp;</td>";
				str += "<TD VALIGN = 'TOP'>" 
				str += grid.gridData[quantity][i] + "&nbsp;</td>";
				str += "<TD VALIGN = 'TOP'>";
				str += grid.gridData[comments][i] + "&nbsp;</td>";
				str += "<TD valign = 'top'>"
				str += grid.gridData[aisle][i] + "&nbsp;</td>";
				str += "</tr>";
			}
		}
		str += "</table>";
		str += "</form>";
		if (isDataThere == false)
			str = '';
		return str;
	}
	this.reStoreGrid = ReStoreGrid;
}

//end page PrintAllLists.html




//start page myPantry.html


function myPantryData(product, quantity, theDate, aisle, brand, reminderDate, nrOfTimesBought, ID, firstBought, reminderInterval)
{
	var c = new JsCalendar();
	var fb = nr_to_date(firstBought);
	var firstBoughtDay = fb[0];
	var firstBoughtMonth = fb[1];
	var firstBoughtYear = fb[2];
	fb = nr_to_date(theDate);
	var dayBought = fb[0];
	var monthBought = fb[1];
	var yearBought = fb[2];
	var ddiff = c.dateDiff(firstBoughtDay,firstBoughtMonth,firstBoughtYear, dayBought,monthBought,yearBought);
	this.pantryUpdated = false;
	this.submit2shoppingList = '';
	this.product = product;
	this.quantity = quantity;
	this.theDate = theDate;
	this.aisle = aisle;
	this.brand = brand;
	this.reminderDate = reminderDate;
	var tmpDate  = new Array();
	if (reminderDate != "0")
	{
		tmpDate = nr_to_date(reminderDate);
		this.reminderDate = tmpDate[2] + ";" + tmpDate[1] + ";" + tmpDate[0];
	}
	this.nrOfTimesBought = nrOfTimesBought;
	this.ID = ID;
	this.firstBought = firstBought;
	this.discardItem = false;
	this.changed = false;
	this.reminderInterval = reminderInterval;
	if (nrOfTimesBought == 1)
		this.frequency = 0
	else
		this.frequency = ddiff / (nrOfTimesBought - 1);
	if (this.frequency > 0)
	{
		if (this.frequency < 1)
			this.frequency = Math.ceil(this.frequency)
		else
			this.frequency = Math.floor(this.frequency)
	}
}



function myPantry(pantryData)
{
	this.onMouseMoveOver = true;
	this.index = -1;

	function SortMyPantryCriterium(a, b)
	{
		if(LCase(a.product) > LCase(b.product))
			return 1;
		return -1	
	}

	aisles2display.sort(noCaseCriterium);
	this.bought = pantryData;
	this.bought.sort(SortMyPantryCriterium);


	function Init()
	{
		this.loadAisles();
		this.keepEditSingle();
	}
	this.init = Init;


	function CalAction()
	{
		var c = new JsCalendar();
		var today = new Date();
		var dayNow = today.getDate();
		var monthNow = today.getMonth() + 1;
		var yearNow = today.getFullYear();
		var diff = c.dateDiff(dayNow, monthNow, yearNow, calData.calDay, calData.calMonth, calData.calYear);
		if (diff >=0)
		{
			pantry.bought[pantry.index].reminderInterval = '0';
			eval("window.document.frmSelectWeek_" + pantry.index).selWeek.options[0].selected = true;
			pantry.bought[pantry.index].reminderDate = calData.calYear + ';' + calData.calMonth + ';' + calData.calDay;
			pantry.writeReminder();
			pantry.calClose();
		}
		else
		{
			alert("You chose the date before today.\nPlease choose a later date.");
		}
	}
	this.calAction = CalAction;


	function CalClose()
	{
		if (!calData.htmlSaved)
			return false;
		document.getElementById(calData.panel).innerHTML = calData.origInnerHTML;
		calData.htmlSaved = false;
		hideObject("spanDateOrInterval_" + pantry.index);
		return false;
	}
	this.calClose = CalClose;


	function CalPlay(m, y)
	{
		cal = new JsCalendar();
		cal.panel = 'displCal';
		calData.panel = cal.panel;
		if (m != null)
			cal.month = m;
		if (y != null)
		{	
			if (y > calData.max)
			{
				alert('year to big');
				return false;
			}
			if (y < calData.min)
			{
				alert('year to small');
				return false;
			}
			cal.year = y;
		}
		if (calData.htmlSaved == false)
		{
			calData.origInnerHTML = document.getElementById(cal.panel).innerHTML;
			calData.htmlSaved = true;
		}
		cal.display();
		showObject("spanDateOrInterval_" + pantry.index);
		return false;
	}
	this.calPlay = CalPlay;


	function AssignCalMonthFunctions()
	{
		calData.closeCalendar = this.calClose;
		calData.calendarFunction = this.calAction;
		calData.playCalendar = this.calPlay;
	}
	this.assignCalMonthFunctions = AssignCalMonthFunctions;


	function ReturnSelectByWeek(index)
	{
		var day, month, year = '';
		var t = '';
		var d = new Date();
		var i = 0;
		var str = "<form name = 'frmSelectWeek_" + index + "'>"
		str += "<select onChange = 'pantry.index = " + index + ";";
		str += "pantry.selectWeek(this, " + index + ");' name = 'selWeek'>";
		str += "<option value = ''>Choose Week</option>";

		for (i = 1; i <=10; i++)
		{
			d.setDate(d.getDate()  + 7);
			year = d.getFullYear();
			month = d.getMonth() + 1;
			day = d.getDate();
			t = year + ";" + month + ";" + day;
			str += "<option value = '" + t + "'>in " + i;
			if (i == 1)
				str += " week</option>";
			else
				str += " weeks</option>";
		}
		
		str += "</select></form>";
		return str;
	}
	this.returnSelectByWeek = ReturnSelectByWeek;


	function SelectWeek(frmField, index)
	{
		this.bought[index].reminderDate = frmField.value;
		this.writeReminder();
		hideObject("spanDateOrInterval_" + pantry.index);
		eval("window.document.frmSelectWeek_" + pantry.index).selWeek.options[0].selected = true;
		calData.closeCalendar();
	}
	this.selectWeek = SelectWeek;


	function ConvertRemDate(i)
	{ 
		var cal = new JsCalendar();
		var str = '';
		if (i == null)
			i = pantry.index;
		var rem = pantry.bought[i].reminderDate.split(';');
		str += cal.setMonthsNames()[rem[1] - 1];
		str += " " + rem[2] + ", " + rem[0];
		return str;
		
	}
	this.convertRemDate = ConvertRemDate;


	function WriteReminder()
	{
		var id = "reminderID_" + pantry.index;
		var diff = 0;
		var chkDiff = this.dateDiff();
		var str = '';
		var i = 0;
		var dateOrInt = '';
		for (i = 0; i < eval("window.document.frmDateOrInt_" + pantry.index).radioDateInt.length; i++)
		{
			if (eval("window.document.frmDateOrInt_" + pantry.index).radioDateInt[i].checked)
				dateOrInt = eval("window.document.frmDateOrInt_" + pantry.index).radioDateInt[i].value;
		}
		if (dateOrInt == "oneTime")
		{
			if (chkDiff < 0)
				alert("You chose the date before today");
			str += "Remind me on: ";
			str += this.convertRemDate();
		}
		else
		{
			diff = this.writeReminderInterval();
			if (diff > 0)
			{
				str += "Remind me every: "
				str += diff;
				this.bought[pantry.index].reminderInterval = diff;
				str += " days";
			}
			else
			{
				str += "Remind me on: ";
				str += this.convertRemDate();
			}
		}
		str += this.cancelReminderLink();
		document.getElementById(id).innerHTML = str;
		pantry.bought[pantry.index].changed = true;
		isSafe2Exit = false;
	}
	this.writeReminder = WriteReminder;


	function DateDiff(i)
	{
		if (i != null)
		{
			if (this.bought[i].reminderInterval != "0")
			{
				return this.bought[i].reminderInterval;
			}
		}
		else
		{
			i = pantry.index;
		}
		var c = new JsCalendar();	
		var today = new Date();
		var dayNow = today.getDate();
		var monthNow = today.getMonth() + 1;
		var yearNow = today.getFullYear();
		var rem = pantry.bought[i].reminderDate.split(';');
		var chosenDay = rem[2];
		var chosenMonth = rem[1];
		var chosenYear = rem[0];
		var diff = c.dateDiff(dayNow, monthNow, yearNow, chosenDay, chosenMonth, chosenYear);
		return Math.abs(diff);
	}
	this.dateDiff = DateDiff;


	function WriteReminderInterval()
	{
		if (this.bought[pantry.index].reminderDate == "0")
			return;
		var diff = this.dateDiff();
		if (diff < 0)
		{
			alert("Chosen value is " + diff + "; converting to " + diff * (-1));
			diff = diff * (-1);
		}
		return diff;
	}
	this.writeReminderInterval = WriteReminderInterval;


	function WriteRadioReminderDate()
	{
		if (this.bought[pantry.index].reminderDate == "0")
			return;
		var str = '';
		var id = "reminderID_" + pantry.index;
		str += "Remind me on: ";
		str += this.convertRemDate();
		str += this.cancelReminderLink();
		document.getElementById(id).innerHTML = str;
		pantry.bought[pantry.index].changed = true;
		isSafe2Exit = true;
		pantry.bought[pantry.index].reminderInterval = '0';
	}
	this.writeRadioReminderDate = WriteRadioReminderDate;


	function WriteRadioReminderInterval()
	{
		if (this.bought[pantry.index].reminderDate == "0")
			return;
		var str = '';
		var id = "reminderID_" + pantry.index;
		str += "Remind me every: "
		this.bought[pantry.index].reminderInterval = this.dateDiff();
		str += this.bought[pantry.index].reminderInterval;
		str += " days";
		str += this.cancelReminderLink();
		document.getElementById(id).innerHTML = str;
		pantry.bought[pantry.index].changed = true;
		isSafe2Exit = true;
	}
	this.writeRadioReminderInterval =  WriteRadioReminderInterval;


	function CancelReminder(i)
	{
		var id = "reminderID_" + i;
		this.bought[i].reminderDate = '0';
		this.bought[i].reminderInterval = '0';
		this.bought[i].changed = true;
		isSafe2Exit = false;
		document.getElementById(id).innerHTML = '';
		return false;
	}
	this.cancelReminder = CancelReminder;


	function CancelReminderLink()
	{
		var str = '';
		str += "<br><a href = '#' onClick = 'return pantry.cancelReminder(" + pantry.index + ");'>";
		str += "<noBr>Cancel Reminder</noBr></a>";
		return str;
	}
	this.cancelReminderLink = CancelReminderLink;
	

	function LoadAisles()
	{
		var i;
		var str = '';
		var isPantryEmpty = true;
		var recentLetter = '';
		var checkLetter = '';
		str += "<br>";
		str += "<table border = '0'>";
		str += "<tr><td width = '33'></td><td valign = 'top'>";
		str += "<table border = '0'>";
		for (i = 0; i < aisles2display.length; i++)
		{
			if (aisles2display[i] != "")
			{
				isPantryEmpty = false;
				checkLetter = UCase(Character(aisles2display[i], 0));
				if (checkLetter != recentLetter)
				{
					recentLetter = checkLetter
					str += "<tr><td><b><font style = 'font-size:14;'>";
					str += recentLetter + "</font></b><td width = '5'></td>";
				}
				else
				{
					str += "<tr><td><td width = '5'></td>";
				}
				str += "<td>";
				str += "<a href = '#' onClick = 'return pantry.loadCabinetClick(" + i + ");'";
				str += " onMouseOver = 'pantry.loadCabinet(" + i + ");'";
				str += ">";
				str += "<font style = 'font-size:12;'>";
				str += aisles2display[i];
				str += "</font>";
				str += "</a>"
				if (i < aisles2display.length)
					str += "</td></tr>";
			}
			
		}
		if (isPantryEmpty)
		{
			str += "<tr><td align = 'center' valign = 'top'><b>Your pantry</b></td></tr><tr><td valign = 'top'>";
			str += "<br><img src = 'images/prof.gif' alt = '' align = 'left''>";
			str += "<font color = 'green'><br>Have you gone shopping yet? ";
			str += "The items you bought would be here.";
			str += "<br><br>I calculate the frequency of each item in your virtual pantry and remind to buy it when needed.";
			str += "</font>"
		}
		str += "</table>";
		str += "</td></tr></table>";
		document.getElementById("aisles").innerHTML = str;
		return '';
	}
	this.loadAisles = LoadAisles;

	
	function LoadCabinet(index)
	{
		if (!pantry.onMouseMoveOver)
			return '';
		var str = '';
		str += this.writeCabinets(index);
		str += "<br>" + document.getElementById("dummyPantry").innerHTML;
		showObject('pantry');
		document.getElementById("pantry").innerHTML = str;
		return '';
	}
	this.loadCabinet = LoadCabinet;


	function SetReminder(index)
	{
		var str = '';
		var checkDate = false;
		var checkInt = false;
		if (this.bought[index].reminderDate == "0" && this.bought[index].reminderInterval == "0")
			checkInt = true;
		if (this.bought[index].reminderDate != "0" && this.bought[index].reminderInterval != "0")
			checkInt = true;
		if (this.bought[index].reminderDate != "0" && this.bought[index].reminderInterval == "0")
			checkDate = true;
		this.assignCalMonthFunctions();
		str += "<a href = '#' onClick = 'pantry.remToggle(" + index + ");return false;'>";
		str += "<noBr>Set Reminder</noBr></a>";
		str += "<span id = 'spanDateOrInterval_" + index + "' style = 'display:none'>";
		str += "<table bgcolor = '#e0e0e0'><tr><td>";
		str += "<table><tr><td>";
		str += this.returnSelectByWeek(index) + "</td><td>";
		str += "<a href = '#' onClick = 'pantry.index = " + index;
		str += ";return calData.playCalendar();' style = 'font-size:13;'>";
		str += "Calendar</a>";
		str += "</td></tr></table>";
		str += "<table><tr><td>"
		str += "<form name = 'frmDateOrInt_" + index + "'>";
		str += "one time: ";
		str += "<input type = 'radio' name = 'radioDateInt' value = 'oneTime'";
		if (checkDate == true)
			str += " checked";
		str += " onClick = 'pantry.index = " + index + ";";
		str += "pantry.writeRadioReminderDate();";
		str += "'>";
		str += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		str += "ongoing: ";
		str += "<input type = 'radio' name = 'radioDateInt' value = 'interval'";
		if (checkInt == true)
			str += " checked";
		str += " onClick = 'pantry.index = " + index + ";";
		str += "pantry.writeRadioReminderInterval();";
		str += "'>";
		str += "</form>";
		str += "</td></tr></table>";
		str += "</td></tr></table>";
		str += "</span>";
		return str;
	}
	this.setReminder = SetReminder;


	function RemToggle(idNr)
	{	
		document.getElementById(calData.panel).innerHTML = calData.origInnerHTML;
		if (pantry.bought[idNr].discardItem == true)
		{
			alert("You scheduled this item to be discarded.\nTo set the reminder again, uncheck the 'Discard item' checkbox.");
		}
		else
		{
			toggle("spanDateOrInterval_" + idNr);
		}
		return false;		
	}
	this.remToggle = RemToggle;


	function LoadCabinetClick(index)
	{
		var msg = '';
		if (pantry.onMouseMoveOver)
		{
			pantry.onMouseMoveOver = false;
			/*
			msg = "<font color = 'green' style = 'font-size:12;'>";
			msg += "By clicking on the pantry menu you can disable Fast View ";
			msg += "and make menu clickable.";
			msg += " To use Fast View again, just click 'Close' below.";
			msg += "</font><br>";
			*/
		}
		var str = msg;
		str += this.writeCabinets(index);
		str += "<br>" + document.getElementById("dummyPantry").innerHTML;
		showObject('pantry');
		document.getElementById("pantry").innerHTML = str;
		return false;
	}
	this.loadCabinetClick = LoadCabinetClick;


	this.add2shoppingListItems = function(i)
	{
		this.bought[i].changed = true;
		isSafe2Exit = false;
		if (this.bought[i].submit2shoppingList == '')
		{
			this.bought[i].submit2shoppingList = this.bought[i].ID;
		}
		else
		{
			this.bought[i].submit2shoppingList = '';
		}
	}


	function WriteCabinets(index)
	{
		var str = "<p align = 'center'><font color = 'red'>" + aisles2display[index] + "</font></p>";
		calData.closeCalendar();
		for (i = 0; i < this.bought.length; i++)
		{
			if (LCase(this.bought[i].aisle) == LCase(aisles2display[index]))
			{
				str += "<table bgcolor = '#e0e0e0'><tr><td>";
				str += "<table border = '0' bgcolor = 'white' width = '100%'><tr><td>";
				str += "<table border = '0' width = '100%'><tr><td valign = 'top'>";
				str += "Item:";
				str += "</td><td valign = 'top'><b><noBr>";
				str += this.bought[i].product;
				str += "</noBr></b></td><td valign = 'top'>";
				str += "<table border = '0'><tr><td valign = 'top'>";
				str += "<noBr>&nbsp;&nbsp;&nbsp;&nbsp;Discard item: </noBr>";
				str += "</td><td  valign = 'top'>"
				str += "<form name = 'frmDeleteItem_" + i + "'>";
				str += "<input type = 'checkbox' name = 'chkbDelItem' ";
				if (this.bought[i].discardItem == true)
					str += "checked ";
				str += "onClick = 'pantry.deleteEntry(" + i + ");'>";
				str += "</form>";
				str += "</td></tr></table>";
				str += "</td></tr></table>";

				str += "<table border = '0'><tr><td valign = 'top'>";
				str += "<noBr>Add to shopping list: </noBr>";
				str += "</td><td  valign = 'top'>"
				str += "<form name = 'frmSubmit2shoppinglist_" + i + "'>";
				str += "<input type = 'checkbox' name = 'chkbSubmit2ShoppingListItem' ";
				if (this.bought[i].submit2shoppingList != '')
				{
					str += "checked ";
				}
				str += "onClick = 'pantry.add2shoppingListItems(" + i + ");'>";
				str += "</form>";
				str += "</td></tr></table>";

				
				str += "</td></tr><tr><td>";
				str += "<table><tr><td>"
				if (this.bought[i].quantity != '')
					str += "Qty: " + this.bought[i].quantity + ";</td><td>";
				if (this.bought[i].brand != '')
					str += "Brand: " + this.bought[i].brand;
				str += "</td></tr></table></td></tr><tr><td>";
				str += "<noBr>";
				str += "bought: " + nr2date(this.bought[i].theDate);
				if (this.bought[i].frequency != 0)
				{
					str += ", frequency: ";
					str += this.bought[i].frequency;
					if (this.bought[i].frequency > 1)
					{
						str += " days";
					}
					else
					{
						str += " day";
					}
				}
				str += "</noBr>";
				str += "</td></tr><tr><td>";
				str += this.setReminder(i) + "</td></tr>";
				str += "</table></td></tr><tr><td>";
				str += "<span id = 'reminderID_" + i + "'>";
				if (this.bought[i].reminderDate != '0')
				{
					str += this.initReminders(i);
					str += "<br><a href = '#' onClick = 'return pantry.cancelReminder(" + i + ");'>";
					str += "Cancel Reminder</a>";
				}
				str += "</span>";
				str += "</td></tr></table>";
				str += "<br>";
			}
		}
		return str;
	}
	this.writeCabinets = WriteCabinets;


	function DeleteEntry(i)
	{
		this.bought[i].changed = true;
		this.cancelReminder(i);
		document.getElementById(calData.panel).innerHTML = calData.origInnerHTML;
		hideObject("spanDateOrInterval_" + i);
		if (this.bought[i].discardItem == true)
		{
			this.bought[i].discardItem = false;
		}
		else
		{
			this.bought[i].discardItem = true;
		}
	}
	this.deleteEntry = DeleteEntry;


	function InitReminders(i)
	{
		var str = '';
		if (this.bought[i].reminderInterval != "0")
		{
			str += "Reminder set every ";
			str += this.initReminderInterval(i);
			str += " days.";
		}
		else
		{
			if (this.bought[i].reminderDate != "0")
			{
				str += this.initRadioReminderDate(i);
			}
		}
		return str;
	}
	this.initReminders = InitReminders;


	function InitReminderInterval(i)
	{
		if (this.bought[i].reminderDate == "0")
			return;
		var diff = this.dateDiff(i);
		if (diff < 0)
		{
			alert("Chosen value is " + diff + "; converting to " + diff * (-1));
			diff = diff * (-1);
		}
		return diff;
	}
	this.initReminderInterval = InitReminderInterval;


	function InitRadioReminderDate(i)
	{
		if (this.bought[i].reminderDate == "0")
			return;
		var str = '';
		str += "Remind me on: ";
		str += this.convertRemDate(i);
		pantry.bought[i].changed = true;
		isSafe2Exit = true;
		return str;
	}
	this.initRadioReminderDate = InitRadioReminderDate;


	function KeepEditSingle()
	{
		dw("<div id = 'frame4ajax'><div>");
		animato.IntID['msg4ajax'] = '';
		animato.IntID['ajaxTimer'] = setInterval("pantry.ajax()", 60000); 	
	}
	this.keepEditSingle = KeepEditSingle;

	function Ajax()
	{
		animato.ajax('ajax4EditShoppingList.html', 'frame4ajax', animato.IntID['msg4ajax']);
	}
	this.ajax = Ajax;


	function SubmitChanges()
	{
		var i = 0;
		var f = window.document.frm2SubmitChanges;
		var remD = new Array();
		var d, m, y = '';
		var counter = 0;
		var str = '';
		var sList = '';
		for (i = 0; i < this.bought.length; i++)
		{
			if (this.bought[i].changed == true)
			{
				str += "<input type = 'hidden' name = 'reminderDate_" + counter + "'>";
				str += "<input type = 'hidden' name = 'ID_" + counter + "'>";
				str += "<input type = 'hidden' name = 'discardItem_" + counter + "'>";
				str += "<input type = 'hidden' name = 'reminderInterval_" + counter + "'>";
				str += "<input type = 'hidden' name = 'reminderSetOn_" + counter + "'>";
				if (this.bought[i].submit2shoppingList != '')	
				{	
					if (sList != '')
						sList += ",";
					sList += this.bought[i].submit2shoppingList;
				}
				counter++;
			}
		}
		if (counter == 0)
		{
			isSafe2Exit = true;
			alert("You have no changes to submit");
			return false;
		}
		else
		{
			isSafe2Exit = true;
			str += "<input type = 'hidden' name = 'ile' value = '" + counter + "'>";
			document.getElementById('span2submit').innerHTML = str;
			counter = 0;
			for (i = 0; i < this.bought.length; i++)
			{
				if (this.bought[i].changed == true)
				{
					if(this.bought[i].reminderDate == '0')
						f['reminderDate_' + counter].value = '0';
					else
					{
						remD = this.bought[i].reminderDate.split(";");
						y = remD[0];
						m = remD[1];
						d = remD[2];
						f['reminderDate_' + counter].value = date2Nr(d, m, y);
					}
					f['ID_' + counter].value = this.bought[i].ID;
					if (this.bought[i].discardItem == true)
						f['discardItem_' + counter].value = 'yes';
					else
						f['discardItem_' + counter].value = 'no';
					f['reminderInterval_' + counter].value = this.bought[i].reminderInterval;
					f['reminderSetOn_' + counter].value = this.bought[i].reminderSetOn;
					counter++;
				}
			}
		}
		f['pantry2shoppingList'].value = sList;
		return true;
	}
	this.submitChanges = SubmitChanges;
}	//end class myPantry

//end page myPantry.html


//start page home.html

function rems(product, quantity, dateBought, aisle, brand, reminderDate, reminderInterval, nrOfTimesBought, firstBought)
{
	this.product = product;
	this.quantity = quantity;
	this.dateBought = dateBought;
	this.aisle = aisle;
	this.brand = brand;
	this.reminderDate = reminderDate;
	this.reminderInterval = reminderInterval;
	this.nrOfTimesBought = nrOfTimesBought;
	this.firstBought = firstBought;
}  


function calendar4home()
{
	this.base = JsCalendar;
	this.base();

}	//end class calendar4home


function homePage()
{

	function NaSubmit2shoppingList(frm)
	{
		var count = frm.NumOfEntry.value;
		var i = 0;
		var storeSelection = '';
		var productSelection = '';
		frm.shoppingEveryDays.value= 7;
		//frm.shoppingEveryDays.value = window.document.frmSetShoppingInterval.selShoppingInt.selectedIndex + 2;
		for (i = 0; i < frm.userStores.length; i++)
		{
			if (frm.userStores[i].checked)
			{
				storeSelection = frm.userStores[i].value;
			}
		}
		if (storeSelection == '')
		{
			alert("Please choose the store");
			return false;
		}
		for (i = 0; i < count; i++)
		{
			if (eval("frm.ID_" + i).checked)
			{
				productSelection = eval("frm.ID_" + i).value;
				eval("frm.Store_" + i).value = storeSelection;
			}
		}
		if (productSelection == '')
		{
			alert("Please choose the product");
			return false;
		}
		return true;
	}
	this.naSubmit2shoppingList = NaSubmit2shoppingList;


	function setCalendar()
	{
		var cal = new calendar4home();
		cal.panel = 'displCal';
		cal.activeLinks = false;
		cal.allowClose = false;
		cal.display();
	}
	setCalendar();

	function DidShop()
	{
		var did = getSubCookie('Ut', 'didShop', '&');
		if (did == 'yes')
		{
			showObject('spanDidShop');
		}
	}
	this.didShop = DidShop;

}	//end class homePage

//end page home.html


//start page addNewStore.html

function inputStores(addOrRemove, value)
{
	this.addOrRemove = addOrRemove;
	this.value = value;
}


function criterium4EditStores(a, b)
{
	if(LCase(a.value) > LCase(b.value))
		return 1;
	return -1
}

function EditStores()
{
	this.stores = stores2edit.sort(criterium4EditStores);
	this.warn = true;
	function Init()
	{
		this.writeStores();
		if (document.getElementById('removeStores').innerHTML == '')
			this.warn = false;
	}
	this.init = Init;


	function WriteStores()
	{
		var i;
		var strAdd = '';
		var strRemove = '';
		for (i = 0; i < this.stores.length; i++)
		{
			if (this.stores[i].addOrRemove == 'add')
			{
				strAdd += "<a href = '#' onClick = 'editStores.add(" + i + ");return false;' title = ";
				strAdd += "'Click to add this store'>" + this.stores[i].value + "</a><br>";
			}
			else
			{
				strRemove += "<a href = '#' onClick = 'editStores.remove(" + i + ");return false;' title = ";
				strRemove += "'Click to remove this store'>" + this.stores[i].value + "</a><br>";
			}
		}
		document.getElementById('addStores').innerHTML = strAdd;
		document.getElementById('removeStores').innerHTML = strRemove;	
	}
	this.writeStores = WriteStores;


	function Add(i)
	{
		document.getElementById('addStores').innerHTML = '';
		document.getElementById('removeStores').innerHTML = '';			
		this.stores[i].addOrRemove = 'remove';
		this.writeStores();
	}
	this.add = Add;


	function Remove(i)
	{
		document.getElementById('addStores').innerHTML = '';
		document.getElementById('removeStores').innerHTML = '';	
		this.stores[i].addOrRemove = 'add';
		window.document.addNewStore.storeRemoved.value = 'yes';
		this.writeStores();
	}
	this.remove = Remove;


	function WarnRemove()
	{
		var msg = "";
		msg += "If you remove the store(s) from the list, your shopping list will be reset. ";
		msg += "Are you sure you want to proceed? \nClick Cancel if you want to keep your current shopping list.";
		return confirm(msg);
	}
	this.warnRemove = WarnRemove;


	function EsSubmit()
	{

		var i = 0;
		var c = 0;
		var str = '';
		for (i = 0; i < this.stores.length; i++)
		{
			if (this.stores[i].addOrRemove == 'remove')
			{
				str += "<input type = 'hidden' name = 'storeName_" + i + "' value = \"";
				str += this.stores[i].value;
				str += "\">";
				c++;
			}
		}
		str += "<input type = 'hidden' name = 'ile' value  = '" + c + "'>";
		document.getElementById('frmInput').innerHTML = str;
		if (this.warn == true)
		{
			if (window.document.addNewStore.storeRemoved.value == '')
				return true;
			else
			{
				return this.warnRemove();
			}
		}
		else
		{
			return true;
		}
	}
	this.esSubmit = EsSubmit;
}

//end page addNewStore.html



