/***************************
* Copyright (c) GrocerySavings.ca
* All Rights Reserved.
*
* Author: Ben Cho
* Website: grocerysavings.ca, localgrocerydeals.com
* CopyRight: 2007
*
* Functions that are only specific to the home page (default.asp)
* -- Functions for validating store selection, option 1 and option 2 searches
* -- Functions responsible for creating scrolling images effect
****************************/

	/****************************************************
	** default.asp - validates option 1 search by typed list 
	** check to see that the search words entered are not empty and do not contain two quotes in one word
	****************************************************/
	function checkSearchByTypedList(myForm)
	{
		var tempSearchWord = myForm.searchWord;

		// visible postal code textbox field
		var postalCodeTB = document.getElementById("postalCodeTB");

		// hidden postal code field for option 1
		var postalCode = myForm.postalCode;

		// check postal code
		if (validatePostalCode(postalCode) == false)
		{
			postalCodeTB.focus();
			return false;
		}

		if (validateTypeInGroceryList(1, tempSearchWord) == false)
			return false;

		// check to make sure that the user has selected at least one store to search
		if (atLeastOneStore("default.asp") == true)
			return true;

		return false;
	}

	/****************************************************
	** default.asp - validates option 1 by uploaded file containing grocery list
	** check to see that the a path of the file exists
	****************************************************/
	function checkSearchByUploadedFile(myForm)
	{
		var uploadedFilePath = myForm.groceryListFile.value;

		// should i test for empty string or let empty string be search everything
		if (trimString(uploadedFilePath) == "")
		{
			alert("You have not specified the location of your grocery list file. Click on help if you need further detail.");				
			document.getElementById('groceryListFile').focus();
			return false;
		} 

		// regular expression to test that the user has selected a file on their hard drive
		// eg. C:
		var filePathRegex = /[A-Za-z]+:/;
		if (!uploadedFilePath.match(filePathRegex))
		{
			alert("You need to specify the location of your grocery list file on your hard drive.  Click on help if you need further detail.");
			return false;
		}

		// check to make sure that the user has selected at least one store to search
		if (atLeastOneStore("default.asp") == true)
			return true;
		else 
			return false;
	}

	// function is called on blur of visible postal code textbox field
	function setPostalCode(postalCodeTB)
	{
		var postalCode = document.getElementById("postalCode");
		var postalCode1 = document.getElementById("postalCode1");

		postalCode.value = postalCodeTB.value;
		postalCode1.value = postalCodeTB.value;

		// save postal code to cookie
		savePostalCode();
	}

	/****************************************************
	** default.asp - keeps track of what stores the user has checked 
	** submits the store selections through the form's hidden values
	** therefore we have 5 hidden values, one for each store, set the value to "on" if the store is selected
	** since we need to submit these values to two forms, we have 5 hidden values per form, total of 10 hidden values
	****************************************************/
	function addStore(storeName)
	{
		// id name of the checkbox, use 'CB' to differentiate the same name and id attribute
		var tempStoreName = storeName + "CB";
	
		// get the store checkbox object
		var temp = document.getElementById(tempStoreName);

		// search by option 1: get the hidden value for the given store name
		// name of the hidden boxes in the search by keyword form
		var tempName = document.getElementsByName(storeName);

		// the hidden inputs in the search by checkbox form
		var storeName2 = storeName + "1";
		// search by option 2: get the hidden value for the given store name
		var tempName1 = document.getElementsByName(storeName2);

		// user checks this checkbox
		if (temp.checked == true)
		{
			tempName[0].value = 'on';
			tempName1[0].value = 'on';
		}
		else
		{
			tempName[0].value = 'off';
			tempName1[0].value = 'off';
		}
	}

	// check the browser type, currently only supports IE
	function checkBrowserType()
	{
		//if (navigator.appName != "Microsoft Internet Explorer" && navigator.appVersion.indexOf("Mac") != -1)
		// site operates normally only under Microsoft Internet Explorer 
/*		if (navigator.appName != "Microsoft Internet Explorer")
			alert("Sorry, you are currently not using Microsoft Internet Explorer and this site can only be displayed properly in Microsoft Internet Explorer.  Sorry for the inconvience, we are working towards fixing this issue to allow Mozzilla Firefox");
*/
	}

	// check to see if javascript and cookies are enabled on the user's browser
	function checkEnabledCookieAndJavascript()
	{
		if (navigator.cookieEnabled == false)
			document.write("WARNING: cookies are disabled, cookies must be enabled for this site to fully function.  For more info, go to help.");

		if (navigator.javaEnabled() == false)
			document.write("WARNING: scripting is disabled, scripting must be enabled for this site to fully function.  For more info, go to help.");
	}

	function searchWithTypedList()
	{
		var searchOption1Type = document.getElementById("searchOptionOneType");
		searchOption1Type.value = "1";

		// save grocery store selections into cookies 
		saveGroceryStoreSelectionsCookie();

		// save manually typed in grocery list into cookies
		saveTypedInGroceryList();

		var searchWordForm = document.forms["textbox"];
		
		var typedInGroceryList = searchWordForm.searchByKeywords.value;

		var hiddenDomTypedInGroceryList = document.getElementById("typedInGroceryList");

		// escape any characters b/c it is being passed through url
//		hiddenDomTypedInGroceryList.value = escape(searchWordForm.searchByKeywords.value);

		hiddenDomTypedInGroceryList.value = generateInterchangeableAndMisspelledWords(typedInGroceryList);

//alert(hiddenDomTypedInGroceryList.value);
//		searchWordForm.searchByKeywords.value = escape(searchWordForm.searchByKeywords.value);

		// validate option 1 form, search by typing in keywords
		if (checkSearchByTypedList(searchWordForm))
			document.forms["textbox"].submit();
	}

	function generateInterchangeableAndMisspelledWords(typedInGroceryList)
	{
		// this will hold the additional grocery names that I've added depending on what the user typed in
		// add the singular term, interchangeable words, commonly misspelled words
		var	autoGeneratedGroceryNames = "";

		var aReg = /,/;
		var parsedSearchWordArray = typedInGroceryList.split(aReg);

		// an array to hold the word(s) of a single grocery name
		var groceryWords;
		// array to hold the interchangeable words
		var interchangeableWords;

		// the full name of the entered grocery
		var groceryName = "";
		var tempGroceryName = "";
		var lastGroceryWord = "";

		var lastThreeLetters = "";
		var lastTwoLetters = "";
		var lastLetter = "";

		var foundPlural = false;

		var interchangedGroceryName = "";
		var groceryWord = "";

		// loop through each entered grocery 
		for (i=0; i<parsedSearchWordArray.length; i++)
		{
			groceryName = parsedSearchWordArray[i];
			groceryName = trimString(groceryName);

			// skip empty grocery names
			if (groceryName == "")
			{
				continue;
			}


			//	start of checking the last word for plural


			// get the index of the last space
			indexLastSpace = groceryName.lastIndexOf(" ");

			// entered grocery name only contains one word
			if (indexLastSpace == -1 )
			{
				lastGroceryWord = groceryName;
			}
			else
			{
				// get the last word
				lastGroceryWord = groceryName.substr(indexLastSpace);
			}

			lastThreeLetters = lastGroceryWord.substr(lastGroceryWord.length - 3);
			lastTwoLetters = lastGroceryWord.substr(lastGroceryWord.length - 2);
			lastLetter = lastGroceryWord.substr(lastGroceryWord.length - 1);

			foundPlural = false;

			// get the singular versions of the last word
			if (lastThreeLetters == "ies")
			{
				switch (lastGroceryWord)
				{
					case 'cookies': 
					case 'pies': 
					case 'rice krispies': 
					case 'brownies': 
					case 'freezies':
						groceryName = groceryName.substr(0, groceryName.length - 1);			
						break;
					default:
						groceryName = groceryName.substr(0, groceryName.length - 3) + "y";
				}

				foundPlural = true;
			}
			else if (lastTwoLetters == "es")
			{
				groceryName = groceryName.substr(0, groceryName.length - 2);
				foundPlural = true;
			}
			else if (lastLetter == "s")
			{
				// do not auto generate words ending with 's
				if (lastTwoLetters != "\'s")
				{
					groceryName = groceryName.substr(0, groceryName.length - 1);			
					foundPlural = true;
				}
			}

			// only add the extra word if we found a plural word
			if (foundPlural)
			{
				autoGeneratedGroceryNames += groceryName + ",";
			}


			//	start of checking every single word for substitutes or misspells


			groceryWords = groceryName.split(" ");

			for (j=0; j<groceryWords.length; j++)
			{
				switch (groceryWords[j])
				{
					case 'cola' :
						groceryWord = 'coke, pepsi';
						break;
					case 'coca-cola' :
						groceryWord = 'coke';
						break;

					case 'cheesestring':
					case 'cheesestrings':
						groceryWord = 'cheestring';
						break;

					case 'filet' :
					case 'filets' :
						groceryWord = 'fillet';
						break;
// pattie
					case 'hamburger' :
						groceryWord = 'burger';
						break;

					case 'hotdog' :
					case 'hotdogs' :
					case 'weiner' :
					case 'weiners' :
						groceryWord = 'wiener';
						break;

					case 'hunts' :
						groceryWord = 'hunt\'s';
						break;
				

					case 'infant' :
					case 'toddler' :
						groceryWord = 'baby';
						break;

					case 'jello' :
						groceryWord = 'jell-o';
						break;

					case 'kebap' :
					case 'kebab' :
					case 'kibob' :
						groceryWord = 'kabob';
						break;					

					case 'kool' :
						groceryWord = 'kool-aid';
						groceryWords[j+1] = '';
						break;
					case 'koolaid' :
						groceryWord = 'kool-aid';
						break;

					case 'kellogg':
					case 'kelloggs':
						groceryWord = 'kellogg\'s'
						break;

					case 'kolbassa':
						groceryWord = 'kielbasa'
						break;

					case 'meatless':
					case 'vegetarian':
						groceryWord = 'veggie'
						break;

					case 'pamper':
					case 'pamper\'s':
						groceryWord = 'pampers'
						break;

					case 'panzarotti':
						groceryWord = 'panzerotti'
						break;

					case 'porketta':
					case 'porquetta':					
						groceryWord = 'porchetta'
						break;

					case 'striploin':
						groceryWord = 'strip loin'
						break;

					case 'yogourt':
						groceryWord = 'yogurt'
						break;

					default:
						groceryWord = groceryWords[j];
				
				}
				
				// last word
				if ((j + 1) == groceryWords.length)
				{
					interchangedGroceryName += groceryWord;
				}
				// first word
				else if (j== 0)
				{
					interchangedGroceryName = groceryWord + " ";
				}
				else
				{
					interchangedGroceryName += groceryWord + " ";
				}
			}	// end for

//alert(interchangedGroceryName + ":" + groceryName);
			// found a word to interchange
			if (interchangedGroceryName != groceryName)
			{
				autoGeneratedGroceryNames += interchangedGroceryName + ",";
			}

			// always initialize for each grocery word
			interchangedGroceryName = "";

// have an array 

// function that takes an array, and a word to substitue

			// single words
			switch (groceryName)
			{
				case '7-up':
				case 'seven up':
					tempGroceryName = '7up';
					break;

				case 'airwick':
					tempGroceryName = 'air wick';
					break;

				case 'back bacon':
				case 'pork back':
					tempGroceryName = 'peameal bacon';
					break;

				case 'bar soap':
					tempGroceryName = 'soap bar';
					break;

				case 'bathroom paper':
				case 'toilet paper':
				case 'toilet tissue':
				tempGroceryName = 'bathroom tissue';
					break;

				case 'bottled water':
				case 'natural spring water':
				case 'water':
					tempGroceryName = 'spring water';
					break;

				case 'coca cola':
					tempGroceryName = 'coke';
					break;

				case 'coleslaw':
				case 'coleslaws':
					tempGroceryName = 'cole slaw';
					break;

				case 'dish soap':
				case 'dish soaps':
					tempGroceryName = 'dish detergent';
					break;

				case 'dishwashing soap':
				case 'dishwashing soaps':
					tempGroceryName = 'dishwasher detergent';
					break;

				case 'frozen dinner':
				case 'frozen dinners':
					tempGroceryName = 'frozen entree';
					break;

				case 'hot dog':
				case 'hot dogs':
					tempGroceryName = 'wiener';
					break;

				case 'honey dew':
				case 'honey dews':
					tempGroceryName = 'honeydew';
					break;

				case 'laundry soap' :
				case 'laundry soaps' :
					tempGroceryName = 'laundry detergent';
					break;

				case 'jell o' :
					tempGroceryName = 'jell-o';
					break;

				case 'kleenex' :
				case 'tissue paper' :
				case 'tissue' :
					tempGroceryName = 'facial tissue';
					break;

				case 'mini carrot' :
					tempGroceryName = 'baby carrot';
					break;

				case 'sir loin':
					tempGroceryName = 'sirloin'
					break;

				case 'soft drink':
				case 'soft drinks':
					tempGroceryName = 'pop';
					break;

				default:
					tempGroceryName = groceryName;
			}

			// found a word to interchange
			if (tempGroceryName != groceryName)
			{
				autoGeneratedGroceryNames += tempGroceryName + ",";	
			}

		} // end of for loop
		// get rid of the last ","
		autoGeneratedGroceryNames = autoGeneratedGroceryNames.substr(0, autoGeneratedGroceryNames.length - 1);

		var INTERCHANGEABLE_WORDS_DELIMITER = "@#@";

		// only add the interchange words if there was any found
		if (autoGeneratedGroceryNames != "")
		{
			typedInGroceryList += "," + INTERCHANGEABLE_WORDS_DELIMITER + autoGeneratedGroceryNames;
		}
		
		return typedInGroceryList;
	}

	function searchWithTypedList1()
	{

		var searchOption1Type = document.getElementById("searchOptionOneType");
		searchOption1Type.value = "1";

		// save grocery store selections into cookies 
		saveGroceryStoreSelectionsCookie();

		// save manually typed in grocery list into cookies
		saveTypedInGroceryList();

		var searchWordForm = document.forms["textbox"];
		
		var typedInGroceryList = searchWordForm.searchByKeywords.value;

		var hiddenDomTypedInGroceryList = document.getElementById("typedInGroceryList");

		// escape any characters b/c it is being passed through url
//		hiddenDomTypedInGroceryList.value = escape(searchWordForm.searchByKeywords.value);
		
		hiddenDomTypedInGroceryList.value = findInterchangeableOrMisspelledWords(typedInGroceryList + "");

//@@
alert(hiddenDomTypedInGroceryList.value);


//		searchWordForm.searchByKeywords.value = escape(searchWordForm.searchByKeywords.value);

/*
		// validate option 1 form, search by typing in keywords
		if (checkSearchByTypedList(searchWordForm))
			document.forms["textbox"].submit();
*/
	}


	/**
		check for misspelled words and interchangeable words
		correct misspelled words and append interchangeable words
	**/
	function findInterchangeableOrMisspelledWords(typedInGroceryList)
	{
		// this will hold the additional grocery names that I've added depending on what the user typed in
		// add the singular term, interchangeable words, commonly misspelled words
		var	autoGeneratedGroceryNames = "";

		// holds the list of entered words 
		var resultArray;

		// convert all to lower case
		typedInGroceryList = typedInGroceryList.toLowerCase();
		var aReg = /,/;
		var groceryArray = typedInGroceryList.split(aReg);

		// an array to hold the word(s) of a single grocery name
		var groceryWords;

		var temp = new Array();
		// ******** INTERCHANGEABLE WORDS ********		
		// array to hold the interchangeable words
//		var interchangeableWordsTupleArray = new Array();
		// add an element for each word to check for misspelling or interchangeable
		temp.push(new Array(new Array("cola"), "coke, pepsi")); 
		temp.push(new Array(new Array("kellogg", "kelloggs"), "kellogg's")); 

		var interchangeableWordsArray;
		var interchangeableWord = "";

		// ******** MISSPELLED WORDS ********
		// array to hold the misspelled words
		var misspelledWordsTupleArray = new Array();
		misspelledWordsTupleArray.push(new Array("7-up", "seven up"), "7up");
		var misspelledWordsArray;
		var misspelledWord = "";


		// the full name of the entered grocery
		var groceryName = "";
		var lastGroceryWord = "";

		var tempGroceryName = "";
		var interchangedGroceryName = "";
		var groceryWord = "";

		var startingIndex = -1;
		var endingIndex = -1;

		// loop through each entered grocery 
		for (var i=0; i<groceryArray.length; i++)
		{
			/*****************************
				handle plural words, if found add singular term to end
			******************************/
			groceryName = groceryArray[i];
			groceryName = trimString(groceryName);

			// skip empty grocery names
			if (groceryName == "")
			{
				continue;
			}
			// returned singular is in form "grocery, " (note "," at the end)
			autoGeneratedGroceryNames += findSingularWord(groceryName);
// ??? why am I finding singular words


// ??? have one array for interchangeable and one for misspells
// b/c adding to the end for interchangeable and replacing for misspells

			interchangeableWordsTupleArray = temp[0];
//alert(interchangeableWordsTupleArray.length)
			// loop through all words to check for interchangeability
			for (var j=0; j<interchangeableWordsTupleArray.length; j++)
			{
				// get the list of interchangeable words
				interchangeableWordsArray = interchangeableWordsTupleArray[j];

//alert(interchangeableWordsArray)


//alert(interchangeableWordsTupleArray[j])

				// loop through each interchanageable word
				for (var k=0; k<interchangeableWordsArray.length; k++)
				{
					interchangeableWord = interchangeableWordsArray[k];
//alert(interchangeableWord)
					// found interchangeable word in entered grocery name
					if (groceryName.indexOf(interchangeableWord) != -1)
					{
//		alert(interchangeableWord);
						// add the correct word to the end
						autoGeneratedGroceryNames += interchangeableWordsTupleArray[j][1];
					}
				}
			}
//alert(autoGeneratedGroceryNames);
			// reinitialize
			startingIndex = -1;
			endingIndex = -1;

			// loop through all words to check for misspells 
			for (var j=0; j<misspelledWordsTupleArray.length; j++)
			{
				misspelledWordsArray = misspelledWordsTupleArray[j][0];
				// loop through each interchanage word
				for (var k=0; k<misspelledWordsArray.length; k++)
				{
					misspelledWord = misspelledWordsArray[k];

					startingIndex = groceryName.indexOf(misspelledWord);
					// found misspelled word in entered grocery name
					if (startingIndex != -1)
					{
						endingIndex = startingIndex + groceryName.length;
						// replace misspelled word with correct spelling
						groceryArray[i] = groceryName.substring(0, startingIndex) + 
							misspelledWordsTupleArray[j][1] + 
							groceryName.substr(endingIndex + 1);
//							groceryName.substring(startingIndex + 1, endingIndex) + 
					}
				}
			}			
		}
		// let's correct spelling errors by replacing with correct spelling

		// return correctly spelled words and add hidden interchangeable words to end
		return groceryArray.toString() + "#@#" + autoGeneratedGroceryNames;
	}

	/**
		returns the singular form of a possible plural form word
	**/
	function findSingularWord(groceryName)
	{
		var lastThreeLetters = "";
		var lastTwoLetters = "";
		var lastLetter = "";

		var foundPlural = false;

		/*********************
		*	start of checking the last word for plural
		*********************/

		// get the index of the last space
		var indexLastSpace = groceryName.lastIndexOf(" ");

		// entered grocery name only contains one word
		if (indexLastSpace == -1 )
		{
			lastGroceryWord = groceryName;
		}
		else
		{
			// get the last word
			lastGroceryWord = groceryName.substr(indexLastSpace);
		}

		lastThreeLetters = lastGroceryWord.substr(lastGroceryWord.length - 3);
		lastTwoLetters = lastGroceryWord.substr(lastGroceryWord.length - 2);
		lastLetter = lastGroceryWord.substr(lastGroceryWord.length - 1);

		foundPlural = false;

		// get the singular versions of the last word
		if (lastThreeLetters == "ies")
		{
			switch (lastGroceryWord)
			{
				case 'cookies': 
				case 'pies': 
				case 'rice krispies': 
				case 'brownies': 
				case 'freezies':
					groceryName = groceryName.substr(0, groceryName.length - 1);			
					break;
				default:
					groceryName = groceryName.substr(0, groceryName.length - 3) + "y";
			}
			foundPlural = true;
		}
		else if (lastTwoLetters == "es")
		{
			groceryName = groceryName.substr(0, groceryName.length - 2);
			foundPlural = true;
		}
		else if (lastLetter == "s")
		{
			// do not auto generate words ending with 's
			if (lastTwoLetters != "\'s")
			{
				groceryName = groceryName.substr(0, groceryName.length - 1);			
				foundPlural = true;
			}
		}

		// only add the extra word if we found a plural word
		if (foundPlural)
		{
			return groceryName + ",";
		}

		return "";
	}

	function searchWithUploadedFile()
	{
//		var searchOption1Type = document.getElementById("searchOptionOneType");
//		searchOption1Type.value = "2";

		var searchWordForm = document.forms["textbox"];
		if (checkSearchByUploadedFile(searchWordForm))
			searchWordForm.submit();
//			document.forms["textbox"].submit();

	}

	/**
		insert sample list into grocery seach box
	**/
	function insertSampleList()
	{
		var domSearchWord = document.getElementById("searchWord");
		domSearchWord.value = "cereal, spring water, nestle ice cream, " + domSearchWord.value
	}

	/* ======================== START of scrolling animations functions ===================*/
	var browserVersion;
	var direction;
	scrolltimer = null;

// if starting logo goes backwards, then maxWidth is too big interms on -, so lower it
	//maxWidth = -580;
	//maxWidth = -570;

//	maxWidth = -630;

	maxWidth = -800;
	// controls the scrolling speed
	speed = 2;

	// starts the scrolling process, first loaded in the default.asp page in the first img onload
	function scrollStart()
	{
		if (document.layers) 
		{	// netscape 4.0 and up
			browserVersion = eval(document.divASContainer.document.contentLayer);
		}
		else 
		{
			if (document.getElementById) 
			{ // internet explorer 6.0 and netscape 6.0
				browserVersion= eval("document.getElementById('contentLayer').style");
			}
			else 
			{	
				if (document.all) 
				{ // internet explorer 4.0 and up
					browserVersion = eval(document.all.contentLayer.style);
				}
			}
		}
		verScroll();
	}

	// the actual scrolling process code which defines the direction and speed of scrolling
	function verScroll() 
	{
		// controls the direction of the scrolling
		direction = 'right';
		var xPos;

		xPos = parseInt(browserVersion.left);
		if (direction == "right" && xPos < 0) browserVersion.left = (xPos + (speed));
			else if (direction == "right") browserVersion.left = maxWidth;
		if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("Mac") != -1)
		{
			scrolltimer = setTimeout("verScroll()", 10);
		}
		else
		{
			scrolltimer = setTimeout("verScroll()", 24);
		}
	}

	// stop scrolling when mouse is over one of the items
	function stopScroll() 
	{
		clearTimeout(scrolltimer);
	}

	// starts scrolling again when mouse is not over one of the items
	function startAndStop() 
	{
		clearTimeout(scrolltimer);
		verScroll();
	}
	/* ======================== END of scrolling animations functions ===================*/


	/* ======================== START of managing tab panel display functions (function specific for DEFAULT.asp ONLY) ===================*/
	/**
		@param	tabFocus
					partial id of the tab to put focus on (show)

		@param	tabOffFocus
					partial id of the tab to take focus off from (hide)

		@param	contentFocus
					full id of the tab content to display (focus on, show)

		@param	contentOffFocus
					full id of the tab content to hide (focus off)
	**/
	function manageTabPanelDisplay(tabFocus, tabOffFocus, contentFocus, contentOffFocus) 
	{

		var domTabFocus = document.getElementById(tabFocus + "Focus");
		var domTabReady = document.getElementById(tabFocus + "Ready");

		var domTabOffFocus = document.getElementById(tabOffFocus + "Focus");
		var domTabOffFocusReady = document.getElementById(tabOffFocus + "Ready");

		var domContentFocus = document.getElementById(contentFocus);
		var domContentOffFocus = document.getElementById(contentOffFocus);

		domTabFocus.style.display = "block";
//		domTabFocus.style.zIndex =10 ;

		domTabReady.style.display = "none";
//		domTabReady.style.zIndex = 0;

		domTabOffFocus.style.display = "none";
//		domTabOffFocus.style.zIndex = 10;

		domTabOffFocusReady.style.display = "block";
//		domTabOffFocusReady.zIndex = 0;

		domContentFocus.style.display = "block";
		domContentOffFocus.style.display = "none";

		if (tabFocus == "tabOption1")
		{
			option1SearchTextAreaFocus();		
		}

		// save tab selection into cookie
		saveTabPanelSelectionInCookie();
	}

	/*
		put focus on the text area for option 1 on DEFAULT.asp
	*/
	function option1SearchTextAreaFocus()
	{
		// on page load of option 1, put cursor on search text box
		var domSearchByTextArea = document.getElementById("searchWord");

		if (domSearchByTextArea != null)
		{
			domSearchByTextArea.focus();
		}
	}

	/*
		get top deals of week from db
	*/
	function getWeeklyTopDeals()
	{
		var flag = getTopDealsFromDBFlag();
		// flag has expired
		if (flag == "" || flag == null)
		{
			// ajax call to get data from DB
			var html = getWeeklyTopDealsFromDB();
		}
	}