var selectedProducts;
var dto;
var advancedSearchTemplate;
var searchResults;
var searchCheckBoxIds;
var awardImages;
var payedUser;

function initialize()
{
	//searchCheckBoxIds is an array of the ids of each checkbox/radio button at the top of the page for searching.
	//It's used in function like, clearSearchCriteria() which loops through this array and unchecks each one.
	searchCheckBoxIds = [ "pfcopy", "pfprint", "pffax", "pfdocumentscanners", "pfdigitalduplicators",
		"sfcopy", "sfprint", "sffax", "sfscantoemail", "coloryes", "colorno", "colornopref",
		"environmenthome", "environmentdesktop", "environmentsmallworkgroup", "environmentlargeworkgroup",
		"environmentdepartmental", "environmententerprise", "volumeunder22", "volume23to49", "volume50to135",
		"papersizeletter", "papersizelegal", "papersizeledger", "papersizeledgerwbleed", "lqtyes", "lqtno",
		"staplingyes", "staplingno", "autoduplexingyes", "autoduplexingno" ];
		
	/*
	String inside brackets( the array index) should be the value in BBBD0120.Value for the award.
	Award constructor parameters:
	1.  String: file name
	2.  Int: sort order (when sorting by award)
	3.  String: alt and title tooltip (when hovering over the image)
	*/
	awardImages = new Array();
	awardImages[ "2010 Editor's Choice" ] = new Award( "2010-Tri-EC-logo.gif", 1, "2010 Editor's Choice" );
	awardImages[ "2009 Editor's Choice" ] = new Award( "2009-Tri-EC-logo.gif", 2, "2009 Editor's Choice" );
	awardImages[ "2009 Worth Watching" ] = new Award( "2009-Tri-WW-logo.gif", 3, "2009 Worth Watching" );
	awardImages[ "2008 Editor's Choice" ] = new Award( "2008-Tri-EC-logo.gif", 4, "2008 Editor's Choice" );
	awardImages[ "2007 Editor's Choice" ] = new Award( "2007-Tri-EC-logo.gif", 5, "2007 Editor's Choice" );
	awardImages[ "2007 Worth Watching" ] = new Award( "2007-Tri-WW-logo.gif", 6, "2007 Worth Watching" );
	awardImages[ "2006 Editor's Choice" ] = new Award( "2006-Tri-EC-logo.gif",7, "2006 Editor's Choice"  );
	awardImages[ "2006 Worth Watching" ] = new Award( "2006-Tri-WW-logo.gif", 8, "2006 Worth Watching"  );
	
	//create the data object that does every Ajax call
	dto = new dataObject();
	
	//attach DHTML functions to our select boxes and buttons
	gEBI( "sortSelect" ).onchange = sortAndDisplay;
	gEBI( "ascdescsortasc" ).onchange = sortAndDisplay;
	gEBI( "ascdescsortdesc" ).onchange = sortAndDisplay;
	gEBI( "pfcopy" ).onclick = updateAdvanced;
	gEBI( "pfprint" ).onclick = updateAdvanced;
	gEBI( "pffax" ).onclick = updateAdvanced;
	gEBI( "pfdocumentscanners" ).onclick = updateAdvanced;
	gEBI( "pfdigitalduplicators" ).onclick = updateAdvanced;
	gEBI( "advancedSearchHeader" ).onclick = toggleAdvancedSearch;
	gEBI( "sfallSecondary" ).onclick = selectAllSecondary;
	gEBI( "searchButton" ).onclick = doNewSearch;
	gEBI( "saveThisButton" ).onclick = saveSearch;
	gEBI( "saveSearchOK" ).onclick = saveSearchOK;
	gEBI( "saveSearchCancel" ).onclick = saveSearchCancel;
	gEBI( "clearSearchCriteriaButton" ).onclick = clearSearchCriteria;
	gEBI( "cancelSubscriptionForm" ).onclick = cancelSubscriptionForm;
	
	//these buttons don't exist if the user is already payed and logged in, that's why the "if" check is required
	if( gEBI( "continueLink" ) )
		gEBI( "continueLink" ).onclick = continueLink;
	if( gEBI( "joinButton" ) )
		gEBI( "joinButton" ).onclick = userJoins;
	if( gEBI( "subscribeNowButton" ) )
		gEBI( "subscribeNowButton" ).onclick = validateAndSubmitSubscriptionForm;
	
	if( gEBI( "compareButton1" ) )
		gEBI( "compareButton1" ).onclick = tryCompare;
	if( gEBI( "compareButton2" ) )
		gEBI( "compareButton2" ).onclick = tryCompare;
	
	gEBI( "interruptOK" ).onclick = interruptOK;
	gEBI( "interruptCancel" ).onclick = interruptCancel;

	/*SearchResults is an object that holds the search results.  It is defined near the bottom of this document.
	
	The enabled flag was used during the first iteration(s) of iGuide when we had a VictoriaSecretesque cover over the search results.
	When this is set to false, sorting fails, the compare buttons fail, and the search results don't link to productdetails.asp.
	
	The show variable controls how many search results appear on each page.  This also was something that was used during first iterations
	of iGuide.  At the beginning, this value started at 4 before the user purchased iGuide, and it was set to 10 upon purchasing.  Nowadays it's always 10.
	*/
	searchResults = new SearchResults();
	searchResults.enabled = true;
	searchResults.show = 10;
	
	/*payedUser is a global variable that is used throughout the app.  If it's true, the user has payed, if it's false, the user has not payed.  What this means
	changes with each iteration.  For example, in iteration 1, the VS screen covered the search results when payedUser was false.  In iteration 2, users were interrupted
	periodically when using the site if they weren't logged in.
	*/
	payedUser = false;
	
	//this function gets the cookie'd ONLU0110Id and determines whether this user is paid or not.
	getUserState();
	
	//perform a search when a user comes back to this page from the productcomparison.asp or productdetails.asp so they're presented with their previous search results.
	if( gEBI( "automaticSearch" ) && gEBI( "automaticSearch" ).value != "" )
	{
		doAutoSearch();
	}
	
	//this is where the sign up page is presented to non-paid users.
	if( payedUserCheck() )
	{
		showHideById( "show", "leftContent" );
		showHideById( "show", "entireSearchContainer" );
		showHideById( "hide", "subscribeNow2" );
	}
	else
	{
		gEBI( "pfcopy" ).checked = true;
		gEBI( "environmentdepartmental" ).checked = true;
		gEBI( "coloryes" ).checked = true;
		
		showHideById( "hide", "leftContent" );
		showHideById( "hide", "entireSearchContainer" );
		showHideById( "show", "subscribeNow2" );
	}
	/*
	if( payedUserCheck() )
	{
		showHideById( "show", "leftContent" );
		showHideById( "show", "entireSearchContainer" );
		//searchResults.enabled = true;
		//searchResults.show = 10;
		getSavedSearches();
	}
	else
	{
		//showHideById( "show", "subscribeNow1" );
		if( gEBI( "from" ) && gEBI( "from" ).value == "splash" )
		{
			userJoins();
		}
		else
		{
			showHideById( "show", "entireSearchContainer" );
			showHideById( "show", "marketingBannerImage" );
			
			//gEBI( "pfcopy" ).checked = true;
			//gEBI( "environmentdepartmental" ).checked = true;
			//gEBI( "coloryes" ).checked = true;
			//doNewSearch();
			
		}
	}
	*/
}
function getUserState()
{
	var ONLU0110Id = readCookie( "ONLU0110Id" );
	if( ONLU0110Id )
	{
		var page = "ajax/ONLU0110GetUserState.asp?";
		var args = "ONLU0110Id=" + ONLU0110Id;
		if( dto.newTable( "userState", page + args ) )
		{
			var table = dto.Tables[ "userState" ];
			var isPayed = table.Rows[ 0 ][ 0 ];
			var firstName = table.Rows[ 0 ][ 1 ];
			var lastName = table.Rows[ 0 ][ 2 ];
			var emailAddress = table.Rows[ 0 ][ 3 ];
			
			if( isPayed == "true" )
				payedUser = true;
			else
				payedUser = false;
			
			
			gEBI( "firstName" ).value = firstName;
			gEBI( "lastName" ).value = lastName;
			gEBI( "email" ).value = emailAddress;
			gEBI( "confirmEmail" ).value = emailAddress;
		}
		else
		{
			alert( "Error getting user state: " + dto.Tables[ "userState" ].Errors[ 0 ].Description );
		}
	}
	else
		payedUser = false;
}
function userJoins()
{
	/*this is triggered when a user types his name/email into the box on the left.  It closes that left panel, opens the main sign up panel, and populates
	the supplied information into the main subscribe form.
	*/
	if( gEBI( "firstName" ).value == "" )
		gEBI( "firstName" ).value = gEBI( "firstName1" ).value;
	
	if( gEBI( "lastName" ).value == "" )
		gEBI( "lastName" ).value = gEBI( "lastName1" ).value;
	
	if( gEBI( "email" ).value == "" )
	{
		gEBI( "email" ).value = gEBI( "email1" ).value;
		gEBI( "confirmEmail" ).value = gEBI( "email1" ).value;
	}
	
	showHideById( "hide", "entireSearchContainer" );
	//showHideById( "hide", "subscribeNow1" );
	showHideById( "show", "subscribeNow2" );
	showHideById( "hide", "marketingBannerImage" );
	
	var page = "ajax/Vist0110LogPageRequest.asp?";
	var args = "context=openJoinPage";

	if( dto.newTable( "logPageRequest", page + args ) )
	{
		var table = dto.Tables[ "logPageRequest" ];
		var SessionToken = table.Rows[ 0 ][ 0 ];
		//var ONLU0110Id = table.Rows[ 0 ][ 1 ];
		
		createCookie( "ST", SessionToken );
		//createCookie( "ONLU0110Id", ONLU0110Id );  
		
	}
	else
		alert( "Error logging page request: " + dto.Tables[ "logPageRequest" ].Errors[ 0 ].Description );
}
/*function showSubscriptionForm()
{
	showHideById( "hide", "subscribeNowButton1" );
	showHideById( "show", "formWrapper" );
	say( "subscribeMessage", "Subscribe today!" );
}*/
function tryCompare()
{
	//tryCompare used to fail when a user was not paid.  This constraint has been commented out in the line below, so a user can compare as long as at least one product is selected.
	if( canCompare() )//&& payedUserCheck() )
	{
		document.compareForm.submit();
	}
}
function canCompare()
{
	/*productList is the id of a hidden text field inside the form that gets submitted to productcomparison.asp.  Whenever a device in the search results gets selected or
	deselected (that is, whenever that device's box becomes checked or unchecked), the device's id is added or removed from the the productList.  At any given time, productList
	should correlate to the selected devices.  This allows the user to compare products on multiple pages of the search results.
	*/
	if( gEBI( "productList" ).value != "" )
	{
		return true;
	}
	else
	{
		alert( "You must choose at least 1 product to compare." );
		return false;
	}
}
function doNewSearch()
{
	var ONLU0110Id = readCookie( "ONLU0110Id" );
	var page = "ajax/ONLU0110IncreaseSearchCount.asp?";
	var args = "ONLU0110Id=" + ONLU0110Id;
	if( dto.newTable( "increaseSearchCount", page + args ) )
	{
		var table = dto.Tables[ "increaseSearchCount" ];
		//say( "output", table.Rows[ 0 ][ 0 ] );
		var searchCount = parseInt( table.Rows[ 0 ][ 0 ] );
		var expired = table.Rows[ 0 ][ 1 ];
	}
	if( !payedUserCheck() )
	{
		if( ( searchCount == 2 || searchCount == 3 ) && expired != "true" )
		{
			doInterrupt();
		}
		else if( searchCount > 3 || expired == "true" )
		{
			say( "interruptHead", "Your free search pass has expired!" );
			say( "interruptOK", "Click here to sign up and continue your service" );
			showHideById( "hide", "interruptCancel" );
			showHideById( "hide", "cancelSubscriptionForm" );
			doInterrupt();
		}
	}
	gEBI( "productList" ).value = "";
	gEBI( "page" ).value = "";
	gEBI( "latestPageAccessed" ).value = "";
	//searchResults.start = 0;
	doSearch();
}
function doInterrupt()
{
	showHideById( "hide", "entireSearchContainer" );
	showHideById( "show", "interrupt" );
	//showHideById( "hide", "subscribeNow1" );
	showHideById( "hide", "marketingBannerImage" );
}
function interruptOK()
{
	showHideById( "hide", "interrupt" );
	showHideById( "show", "subscribeNow2" );
}
function interruptCancel()
{
	showHideById( "hide", "interrupt" );
	showHideById( "show", "entireSearchContainer" );
	//showHideById( "show", "subscribeNow1" );
	showHideById( "show", "marketingBannerImage" );
}
function doAutoSearch()
{
	if( gEBI( "automaticSearch" ).value != "" )
	{
		populateFromComparator();
		doSearch();
	}
}
function payedUserCheck()
{
	return payedUser;
}
function validateAndSubmitSubscriptionForm()
{
	/*this function validates the subscription form.
	
	formIsValid begins as true, and if any field is invalid, it is set to false and an appropriate error message is set.  If formIsValid is false at the end of the
	series of checks, the form does not submit.
	*/
	var formIsValid = true;
	var message = "";
	var currentDate = new Date();
	var currentYear = currentDate.getFullYear();
	var currentMonth = currentDate.getMonth() + 1;
	if( gEBI( "firstName" ).value.replace( /\s/gi, "" ) == "" )
	{
		formIsValid = false;
		message = "Please enter your first name.";
	}
	else if( gEBI( "lastName" ).value.replace( /\s/gi, "" ) == "" )
	{
		formIsValid = false;
		message = "Please enter your last name.";
	}
	else if( gEBI( "email" ).value.replace( /\s/gi, "" ) == "" )
	{
		formIsValid = false;
		message = "Please enter your email address.";
	}
	else if( gEBI( "email" ).value.indexOf( "@" ) == -1 ||
		gEBI( "email" ).value.indexOf( "." ) == -1 ||
		gEBI( "email" ).value.replace( /\s/gi, "" ).length < 5
	)
	{
		formIsValid = false;
		message = "Please enter a valid email address.";
	}
	else if( gEBI( "email" ).value != gEBI( "confirmEmail" ).value )
	{
		formIsValid = false;
		message = "Confirm email address must match email address.";
	}
	else if( gEBI( "password1" ).value.replace( /\s/gi, "" ) == "" )
	{
		formIsValid = false;
		message = "Please enter a password.";
	}
	else if( gEBI( "password1" ).value != gEBI( "password2" ).value )
	{
		formIsValid = false;
		message = "Confirm password must match password.";
	}
	/*var payNow = gEBI( "payNow" ).checked;
	
	if( payNow )
	{
		if( gEBI( "cardType" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please choose your card type.";
		}
		else if( gEBI( "cardNumber" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please enter your card number.";
		}
		else if( !isCardTypeCorrect( gEBI( "cardNumber" ).value, gEBI( "cardType" ).value ) )
		{
			formIsValid = false;
			message = "Invalid " + gEBI( "cardType" ).value + " number.";
		}
		else if( gEBI( "expireMonth" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please choose an expiration month.";
		}
		else if( gEBI( "expireYear" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please choose an expiration year.";
		}
		else if( gEBI( "expireYear" ).value <= currentYear && gEBI( "expireMonth" ).value < currentMonth )
		{
			formIsValid = false;
			message = "Card is expired.";
		}
	}
	else
	{}
		if( gEBI( "birthMonth" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please enter your birth month.";
		}
		else if( gEBI( "birthDay" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please enter your birth day.";
		}
		else if( gEBI( "birthYear" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please enter your birth year.";
		}
	*/
		else if( gEBI( "address1" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please enter your address.";
		}
		else if( gEBI( "city" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please enter your city.";
		}
		else if( gEBI( "state" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please center your state.";
		}
		else if( gEBI( "zip" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please enter your zip code.";
		}
		//else if( ( gEBI( "daytimePhone" ).value.replace( /\s/gi, "" ) == "" ) || (gEBI( "daytimePhone" ).value.replace( /[\d]/gi, "" ) != "" ) )
		else if(!(/\d{3}[\d-]+/).test(gEBI( "daytimePhone" ).value))
		{
			formIsValid = false;
			message = "Please provide your daytime phone number like(8007776666 or 800-777-6666).";
		}
	    else if( gEBI( "title" ).value.replace( /\s/gi, "" ) == "" )
		{
			formIsValid = false;
			message = "Please provide your title.";
		}
	
	/*else if( gEBI( "subscriptionType" ).value.replace( /\s/gi, "" ) == "" )
	{
		formIsValid = false;
		message = "Please choose a subscription type.";
	}*/
	if( !gEBI( "agreetoterms" ).checked )
	{
		formIsValid = false;
		message = "You must agree to the terms and conditions.";
	}
	
	if( !formIsValid )
	{
		alert( message );
		return false;
	}
	else
	{
		//if all form fields are valid, check to see if the supplied email address is already in use by an existing customer
		var page = "ajax/Ordr0100CheckEmailExistence.asp?";
		var args = "emailAddress=" + gEBI( "email" ).value;
		if( dto.newTable( "checkEmailExistence", page + args ) )
		{
			var table = dto.Tables[ "checkEmailExistence" ];
			var output = "";
			var exists = table.Rows[ 0 ][ 0 ];
			if( exists == "true" )
			{
				alert( "That email address is being used by an existing user." );
				formIsValid = false;
			}
		}
		else
		{
			//alert( "Error checking for email existence: " + dto.Tables[ "checkEmailExistence" ].Errors[ 0 ].Description );
			return false;
		}
	}
	
	if( formIsValid )
	{
		//finally, all fields are valid and email address isn't already being used, submit the form.
		var firstName = gEBI( "firstName" ).value;
		var lastName = gEBI( "lastName" ).value;
		var company = gEBI( "company" ).value;
		var email = gEBI( "email" ).value;
		var password1 = gEBI( "password1" ).value;
		//var cardType = gEBI( "cardType" ).value;
		//var cardNumber = gEBI( "cardNumber" ).value;
		//var expireMonth = selectGetValue( gEBI( "expireMonth" ), 0 );
		//var expireYear = selectGetValue( gEBI( "expireYear" ), 0 );
		
		
		var address1 = gEBI( "address1" ).value;
		var address2 = gEBI( "address2" ).value;
		var city = gEBI( "city" ).value;
		var state = gEBI( "state" ).value;
		var zip = gEBI( "zip" ).value;
		var daytimePhone = gEBI( "daytimePhone" ).value;
		var title = gEBI( "title" ).value;
		//var birthMonth = selectGetValue( gEBI( "birthMonth" ), 0 );
		//var birthDay = selectGetValue( gEBI( "birthDay" ), 0 );
		//var birthYear = selectGetValue( gEBI( "birthYear" ), 0 );
		
		//var subscriptionType = gEBI( "subscriptionType" ).value;
		//var subscriptionType = 5;
		//var subscriptionText = gEBI( "subscriptionType" ).options[ gEBI( "subscriptionType" ).selectedIndex ].text;
		//var subscriptionText = "iGuide $79/3 months unlimited access auto-renew";
		
		var page = "ajax/Ordr0100CaptureIGuideOrder.asp?";
		var args = "firstName=" + escape( firstName ) +
		"&lastName=" + lastName +
		"&company=" + company +
		"&email=" + email +
		"&password=" + password1;
		
	
		args += "&address1=" + address1 +
			"&address2=" + address2 +
			"&city=" + city +
			"&state=" + state +
			"&zip=" + zip +
			"&daytimePhone=" + daytimePhone +
			"&title=" + title;
	
		
		if( dto.newTable( "captureOrder", page + args ) )
		{
			var table = dto.Tables[ "captureOrder" ];
			var output = "";
			var ONLU0110Id = table.Rows[ 0 ][ 0 ];
			//var referenceNumber = table.Rows[ 0 ][ 1 ];
			
			//say( "orderSubscriptionType", subscriptionText );
			//say( "orderReferenceNumber", referenceNumber );
			
			
			//var confirmationOutput = "<table>";
			//confirmationOutput += confirmationCreateRow( "Name", firstName + " " + lastName ) +
			//	confirmationCreateRow( "Company", company ) +
			//	confirmationCreateRow( "Email", email );
			/*
			if( payNow )
			{
				confirmationOutput += confirmationCreateRow( "Card Type", cardType ) +
					confirmationCreateRow( "Card Number", "************" + cardNumber.substring( cardNumber.length - 4 ) ) +
					confirmationCreateRow( "Card Expiration", expireMonth + " / " + expireYear );
			}
			else
			{
				confirmationOutput += confirmationCreateRow( "Address", address1 + "<br />" + address2 + "<br />" +
					city + ", " + state + " " + zip ) +
					confirmationCreateRow( "Date of Birth", birthMonth + "/" + birthDay + "/" + birthYear ) +
					confirmationCreateRow( "Phone Number", daytimePhone );
			}
			*/
			//confirmationOutput += "</table>";
			//gEBI( "confirmationTableDiv" ).innerHTML = confirmationOutput;
			
			//say( "timeLeftAmount", timeRemaining );
			createCookie( "ONLU0110Id", ONLU0110Id );
			createCookie( "firstName", firstName );
			//orderSuccessful();
			// if "order" is succesful, do not show the confirmation page, direct to the search page
			continueApp();
		}
		else
		{
			alert( "Error capturing order: " + dto.Tables[ "captureOrder" ].Errors[ 0 ].Description );
			return false;
		}
	}
}
function confirmationCreateRow( label, value )
{
	return "<tr class='confirmationTableRow'><td class='confirmLabel'>" + label + ":</td><td>" + value + "</td></tr>";
}
function cancelSubscriptionForm()
{
	/*In the past there was a "close" button on the subscription form.  Users were able to close the sign up page and go back to the
	product search.
	*/
	showHideById( "hide", "subscribeNow2" );
	showHideById( "show", "marketingBannerImage" );
	//showHideById( "show", "subscribeNow1" );
	showHideById( "show", "entireSearchContainer" );
	
	var page = "ajax/Vist0110LogPageRequest.asp?";
	var args = "context=closeJoinPage";
	dto.newTable( "logPageRequest", page + args );
}
/*
function orderSuccessful()
{
	//user successfully payed.
	payedUser = true;
	showHideById( "hide", "subscribeNow2" );
	showHideById( "show", "orderSuccessOptions" );
	scroll( 0, 0 );
}
*/
function continueApp()
{
	payedUser = true;
	showHideById( "hide", "subscribeNow2" );

	searchResults.enabled = true;
	searchResults.show = 10;
	searchResults.displayPaging();
	searchResults.display();
	//showHideById( "hide", "orderSuccessOptions" );
	showHideById( "show", "leftContent" );
	showHideById( "show", "entireSearchContainer" );
	var firstName = readCookie( "firstName" );
	say( "customerName", "Hi, <div id='headerusername' class='inline'>" + firstName + "</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
		"<a href='formhandler.asp?resetSessionAndCookies=true'>Logout</a>" );
	//populateFromSignup();
	doSearch();
}
function isDigit (c) {
   var strAllowed = "1234567890";
   return (strAllowed.indexOf (c) != -1);
}
/*function isCardTypeCorrect (strNum, type) {
	var cardtype = type.toUpperCase().replace(/ -/g,"")
	var nLen = 0;
	for (n = 0; n < strNum.length; n++) {
		if (isDigit (strNum.substring (n,n+1))) {
			++nLen;
			} // if
		} // for

	switch(cardtype) {
		case '3' :
		case 'VISA' :
			return	((strNum.substring(0,1) == '4') 
					&& 
					(nLen == 13 
						|| 
						nLen == 16));
			break
		case '5' :	
		case 'AMEX' :
		   return	((strNum.substring(0,2) == '34' 
						|| 
						strNum.substring(0,2) == '37') 
					&&
					(nLen == 15));
			break
		case '4' :	
		case 'MASTERCARD' :
			return	((strNum.substring(0,2) == '51' 
						|| 
						strNum.substring(0,2) == '52'
						||
						strNum.substring(0,2) == '53'
						|| 
						strNum.substring(0,2) == '54'
						||
						strNum.substring(0,2) == '55')
					&& 
					(nLen == 16));
			break
		case '6' :	
		case 'DISCOVER' :
			return	((strNum.substring(0,4) == '6011')
					&&
					(nLen == 16));
			break
			
		default :
			return false
		} // switch
	} // function
	*/
function sortAndDisplay()
{
	searchResults.sort( this.id );
}
function getSavedSearches()
{
	//this function populates the saved searches box on the left with the user's previously saved searches
	if( payedUserCheck() )
	{
		var page = "ajax/ONLU0110GetSavedSearches.asp?a=b";
		if( dto.newTable( "getSavedSearches", page ) )
		{
			var table = dto.Tables[ "getSavedSearches" ];
			var output = "";
			for( var i = 0; i < table.Rows.length; i++ )
			{
				var savedSearchName = table.Rows[ i ][ 0 ];//Saved Search Name
				var idList = table.Rows[ i ][ 1 ];//Saved Search Name
				output += "<a onclick=\"doSavedSearch('" + idList + "');\">" + savedSearchName + "</a><br/>";
			}
			if( output != "" )
				say( "savedSearches", output );
		}
		else
			alert( "Error retrieving saved searches: " + dto.Tables[ "getSavedSearches" ].Errors[ 0 ].Description );
	}
}
function doSavedSearch( idList )
{
	clearSearchCriteria();
	gEBI( "searchparams" ).value = idList;
	populateFromSignup();
	doSearch();
}
function clearSearchCriteria()
{
	for( var i = 0; i < searchCheckBoxIds.length; i++ )
	{
		if( gEBI( searchCheckBoxIds[ i ] ) )
			gEBI( searchCheckBoxIds[ i ] ).checked = false;
	}
}
function persistSearchParams()
{
	var params = "";
	var atLeastOneChecked = false;
	for( var i = 0; i < searchCheckBoxIds.length; i++ )
	{
		if( gEBI( searchCheckBoxIds[ i ] ).checked == true )
		{
			params += searchCheckBoxIds[ i ] + ",";
			atLeastOneChecked = true;
		}
	}
	if( atLeastOneChecked )
		params = params.substring( 0, params.length - 1 );
	return params;
}
function saveSearch()
{
	//if user is logged in, open the save search name dialog panel
	if( payedUserCheck() )
	{
		showHideById( "show", "savedSearchDialog" );
		gEBI( "savedSearchNameInput" ).focus();
	}
	else
	{
		alert( "You must be logged in to save a search." );
	}
}
function saveSearchOK()
{
	//save the search
	var searchName = gEBI( "savedSearchNameInput" ).value;
	var searchIds = persistSearchParams();
	var page = "ajax/ONLU0110SaveSearch.asp?";
	var args = "searchName=" + searchName + "&searchIds=" + searchIds;
	//alert( "searchIds: " + searchIds );
	if( dto.newTable( "saveSearch", page + args ) )
	{
		getSavedSearches();
		alert( "Search saved." );
		saveSearchCancel();
	}
	else
		alert( "Error saving search: " + dto.Tables[ "saveSearch" ].Errors[ 0 ].Description );
}
function saveSearchCancel()
{
	//cancel saving the search
	showHideById( "hide", "savedSearchDialog" );
	gEBI( "savedSearchNameInput" ).value = "";
}
function toggleAdvancedSearch()
{
	//toggle the advanced search panel
	if( gEBI( "advancedSearch" ).className.indexOf( "gone" ) < 0 ) //it's currently shown , so hide it
	{
		showHideById( "hide", "advancedSearch" );
		say( "advancedSearchShowHide", " (click here to show)" );
	}
	else //show it
	{
		showHideById( "show", "advancedSearch" );
		say( "advancedSearchShowHide", " (click here to hide)" );
	}
}
function selectAllSecondary()
{
	//"All of the above" checkbox
	if( gEBI( "sfallSecondary" ).checked == true )
	{
		gEBI( "sfcopy" ).checked = true;
		gEBI( "sfprint" ).checked = true;
		gEBI( "sffax" ).checked = true;
		gEBI( "sfscantoemail" ).checked = true;
	}
	else
	{
		gEBI( "sfcopy" ).checked = false;
		gEBI( "sfprint" ).checked = false;
		gEBI( "sffax" ).checked = false;
		gEBI( "sfscantoemail" ).checked = false;
	}
	updateAdvanced();
}
function updateAdvanced()
{
	var pfcopyChecked = gEBI( "pfcopy" ).checked;
	var pfprintChecked = gEBI( "pfprint" ).checked;
	var pffaxChecked = gEBI( "pffax" ).checked;
	var pfdocumentscannersChecked = gEBI( "pfdocumentscanners" ).checked;
	var pfdigitalduplicatorsChecked = gEBI( "pfdigitalduplicators" ).checked;
	
	if( !pfcopyChecked && !pfprintChecked && !pfdigitalduplicatorsChecked )
	{
		if( pfdocumentscannersChecked && !pffaxChecked )
		{
			showHideById( "hide", "laserQualityTechnologyGroup" );
			showHideById( "hide", "staplingGroup" );
		}
		else if( pffaxChecked && !pfdocumentscannersChecked )
		{
			showHideById( "hide", "staplingGroup" );
		}
		else
		{
			showHideById( "show", "laserQualityTechnologyGroup" );
			showHideById( "show", "staplingGroup" );
		}
	}
	else
	{
		showHideById( "show", "laserQualityTechnologyGroup" );
		showHideById( "show", "staplingGroup" );
	}
}
function populateFromSignup()
{
	var searchIds = new Array();
	searchIds = gEBI( "searchparams" ).value.split( "," );
	for( var i = 0; i < searchIds.length; i++ )
	{
		if( gEBI( searchIds[ i ] ) )
			gEBI( searchIds[ i ] ).checked = true;
	}
}
function populateFromComparator()
{
	var searchIds = new Array();
	searchIds = gEBI( "automaticSearch" ).value.split( "," );
	for( var i = 0; i < searchIds.length; i++ )
	{
		if( gEBI( searchIds[ i ] ) )
			gEBI( searchIds[ i ] ).checked = true;
	}
}
function doSearch()
{
	showHideById( "hide", "results" );
	say( "resultsCount", "" );
	if( gEBI( "prodList" ).value != "" )
	{
		gEBI( "productList" ).value = gEBI( "prodList" ).value;
		gEBI( "prodList" ).value = "";
	}
	say( "searchingMessage", "Searching..." );
	showHideById( "hide", "pageLinks" );
	showHideById( "hide", "saveThisButton" );
	gEBI( "searchparams" ).value = persistSearchParams();
	gEBI( "searchParams2" ).value = gEBI( "searchparams" ).value;
	gEBI( "automaticSearch" ).value = gEBI( "searchparams" ).value;
	setTimeout( doSearchContinue, 1 );
}
function doSearchContinue()
{
	/*this is where the actual search is performed.  All the checkboxes are evaluated and passed as parameters.
	*/
	showHideById( "show", "postSearch" );
	var primaryCopyChecked = gEBI( "pfcopy" ).checked;
	var primaryPrintChecked = gEBI( "pfprint" ).checked;
	var primaryFaxChecked = gEBI( "pffax" ).checked;
	var primaryDocumentScannersChecked = gEBI( "pfdocumentscanners" ).checked;
	var primaryDigitalDuplicatorsChecked = gEBI( "pfdigitalduplicators" ).checked;
	
	var secondaryCopyChecked = gEBI( "sfcopy" ).checked;
	var secondaryPrintChecked = gEBI( "sfprint" ).checked;
	var secondaryFaxChecked = gEBI( "sffax" ).checked;
	var secondaryScanToEmailChecked = gEBI( "sfscantoemail" ).checked;
	
	var colorYesChecked = gEBI( "coloryes" ).checked;
	var colorNoChecked = gEBI( "colorno" ).checked;
	var colorNoPref = gEBI( "colornopref" ).checked;
	
	var environmentHomeChecked = gEBI( "environmenthome" ).checked;
	var environmentDesktopChecked = gEBI( "environmentdesktop" ).checked;
	var environmentSmallWorkgroupChecked = gEBI( "environmentsmallworkgroup" ).checked;
	var environmentLargeWorkgroupChecked = gEBI( "environmentlargeworkgroup" ).checked;
	var environmentDepartmentalChecked = gEBI( "environmentdepartmental" ).checked;
	var environmentEnterpriseChecked = gEBI( "environmententerprise" ).checked;
	
	var Volume1Checked = gEBI( "volumeunder22" ).checked;
	var Volume2Checked = gEBI( "volume23to49" ).checked;
	var Volume3Checked = gEBI( "volume50to135" ).checked;
	
	var PaperSize1Checked = gEBI( "papersizeletter" ).checked;
	var PaperSize2Checked = gEBI( "papersizelegal" ).checked;
	var PaperSize3Checked = gEBI( "papersizeledger" ).checked;
	var PaperSize4Checked = gEBI( "papersizeledgerwbleed" ).checked;
					
	var LaserQuality1Checked = gEBI( "lqtyes" ).checked;
	var LaserQuality2Checked = gEBI( "lqtno" ).checked;
					
	var Stapling1Checked = gEBI( "staplingyes" ).checked;
	var Stapling2Checked = gEBI( "staplingno" ).checked;
					
	var Duplexing1Checked = gEBI( "autoduplexingyes" ).checked;
	var Duplexing2Checked = gEBI( "autoduplexingno" ).checked;
	
	var page = "ajax/BBBD0100Search.asp?";
	var args = "cache=" + gEBI( "cache" ).value +
		"&primary=" +
		( primaryCopyChecked == true ? "Copy," : "" ) +
		( primaryPrintChecked == true ? "Print," : "" ) +
		( primaryFaxChecked == true ? "Fax," : "" ) +
		( primaryDocumentScannersChecked == true ? "Scan," : "" ) +
		( primaryDigitalDuplicatorsChecked == true ? "Duplicator," : "" ) +
		"&secondary=" +
		( secondaryCopyChecked == true ? "Copy," : "" ) +
		( secondaryPrintChecked == true ? "Print," : "" ) +
		( secondaryFaxChecked == true ? "Fax," : "" ) +
		( secondaryScanToEmailChecked == true ? "Scan," : "" ) +
		"&color=" +
		( colorNoPref == true ? "" : ( colorYesChecked == true ? "Yes," : "" ) + ( colorNoChecked == true ? "No," : "" ) ) +
		"&environment=" +
		( environmentHomeChecked == true ? "Home," : "" ) +
		( environmentDesktopChecked == true ? "Desktop," : "" ) +
		( environmentSmallWorkgroupChecked == true ? "Small Workgroup," : "" ) +
		( environmentLargeWorkgroupChecked == true ? "Large Workgroup," : "" ) +
		( environmentDepartmentalChecked == true ? "Departmental," : "" ) +
		( environmentEnterpriseChecked == true ? "Enterprise," : "" ) +
		"&volume=" +
		( Volume1Checked == true ? "22 and under," : "" ) +
		( Volume2Checked == true ? "23-49," : "" ) +
		( Volume3Checked == true ? "50 and over," : "" ) +
		
		"&papersize=" +
		( PaperSize1Checked == true ? "Letter," : "" ) +
		( PaperSize2Checked == true ? "Legal," : "" ) +
		( PaperSize3Checked == true ? "Ledger," : "" ) +
		( PaperSize4Checked == true ? "Bleed," : "" ) +
		
		"&laserquality=" +
		( LaserQuality1Checked == true ? "Laser Quality," : "" ) +
		( LaserQuality2Checked == true ? "Ink Jet," : "" ) +
		
		"&stapling=" +
		( Stapling1Checked == true ? "Yes," : "" ) +
		( Stapling2Checked == true ? "No," : "" ) +
		
		"&duplexing=" +
		( Duplexing1Checked == true ? "Yes," : "" ) +
		( Duplexing2Checked == true ? "No," : "" );
	
	if( dto.newTable( "deviceSearch", page + args ) )
	{
		var table = dto.Tables[ "deviceSearch" ];
		searchResults.clear();
		if( table.Rows.length > 0 )
		{
			say( "resultsCount", "Your search has " + table.Rows.length + " matches" );
			showHideById( "show", "results" );
			showHideById( "show", "saveThisButton" );
			for( var i = 0; i < table.Rows.length; i++ )
			{
				var BBBD0100Id = table.Rows[ i ][ 0 ];
				var DeviceName = table.Rows[ i ][ 1 ];
				var PrimaryType = table.Rows[ i ][ 2 ];
				var award = table.Rows[ i ][ 3];
				var price = table.Rows[ i ][ 4 ];
				var speed = table.Rows[ i ][ 5 ];
				if( !PrimaryType )
					PrimaryType = "N/A";
				
				//the device object is created
				var device = new Device( BBBD0100Id, DeviceName, PrimaryType );
				device.addAward( award );
				device.addPrice( price );
				device.addSpeed( speed );
				//the device object is added to the searchResults object
				searchResults.addDevice( device );
			}
		}
		else
		{
			say( "resultsCount", "Sorry, your search did not return any results." );
		}
	}
	else
	{
		alert( "Error trying to search: " + dto.Tables[ "deviceSearch" ].Errors[ 0 ].Description );
		//say( "output", "\nPage: " + page + "\nargs: " + args );
	}
	//sort the search results initially
	searchResults.sort();
	say( "searchingMessage", "" );
	searchResults.displayPaging();
	searchResults.display();
	searchResults.showProductFinder();
	
	//if user came back to this page from the comparator or the device details page, take them to the page they were at when they navigated away
	if( gEBI( "page" ).value != "" )
	{
		changeStart( gEBI( "page" ).value );
		gEBI( "page" ).value = "";
	}
}
/* The device object implementation.  Each device has an id (literally it's the BBBD0100Id).  Devices are instantiated when a user performs a search.
The device starts out with fetched = false.  A device is fetched when it needs to be displayed.  Essentially devices are fetched a page at a time.

The primary type of the device is what appears in the product finder, currently in the left column.
*/
function Device( id, name, primaryType )
{
	this.fetched = false;
	this.id = id;
	this.name = name;
	this.primaryType = primaryType;
	this.image = "/img/Noimagecopiersmall.jpg";
	this.award = "";
	this.price = -1;
	this.speed = -1;
	this.pairs = new Array();
	this.addPair = deviceAddPair;
	this.toString = deviceToString;
	this.attachImage = deviceAttachImage;
	this.addAward = deviceAddAward;
	this.addPrice = deviceAddPrice;
	this.addSpeed = deviceAddSpeed;
}
function deviceAttachImage( image )
{
	if( image != "" )
	{
		var periodIndex = image.lastIndexOf( "." )
		var subdir = image.substring( periodIndex - 3, periodIndex );
		this.image = "/img/b120/" + subdir + "/" + image;
	}
}
function deviceAddAward( award )
{
	if( award != "" && award != "None" && award != "none" )
	{
		this.award = awardImages[ award ];
	}
}
function deviceAddPrice( price )
{
	if( price != "" )
		this.price = parseInt( price );
}
function deviceAddSpeed( speed )
{
	if( speed != "" )
		this.speed = parseInt( speed );
}
function deviceAddPair( pair )
{
	this.pairs[ this.pairs.length ] = pair;
}
function deviceToString()
{
	var output = "id: " + this.id + "<br/>";
	output += "name: " + this.name + "<br/>";
	output += "price: " + this.price + "<br/>";
	output += "<br/><br/>";
	return output;
}
function Pair( name, value )
{
	this.name = name;
	this.value = value;
}
function updatelist( deviceId )
{
	var currentList = gEBI( "productList" ).value;
	var idAndComma = deviceId + ",";
	var myregexp = new RegExp( idAndComma );
	if( gEBI( "c" + deviceId ).checked )
	{
		if( currentList.indexOf( idAndComma ) == -1 )
			currentList = currentList + idAndComma;
	}
	else
		currentList = currentList.replace( myregexp, "" );
	gEBI( "productList" ).value = currentList;
}
function changeStart( startIndex )
{
	setTimeout( "", 1 );
	changeStartContinue( startIndex );
}
function changeStartContinue( startIndex )
{
	if( searchResults.enabled )
	{
		gEBI( "page" ).value = startIndex;
		gEBI( "latestPageAccessed" ).value = startIndex;
		searchResults.start = startIndex;
		searchResults.display();
		searchResults.displayPaging();
	}
}
/*
	This is the SearchResults object implementation.  The enabled flag determines whether the user is authorized to sort and compare search results.
*/
function SearchResults()
{
	this.enabled = false;
	this.devices = new Array(); //array of devices
	this.productFinder = new Array(); //devices in the product finder (currently shown in the left div)
	this.deviceCount = 0; //number of devices in the search results
	this.addDevice = searchResultsAddDevice;
	this.display = searchResultsDisplay; //function that iterates the devices array and creates the markup
	this.clear = searchResultsClear;
	this.displayPaging = displayPaging; //displays the pagination of the search results
	this.showProductFinder = showProductFinder; //displays the product finder
	this.show = 10; //how many devices should be shown per page
	this.start = 0; //which device is first
	this.pageCushion = 3; //how many page links should be displayed prior to the current page
	this.pagesToDisplay = this.pageCushion * 2 + 1;
	this.sort = function()
	{
		//if( this.enabled )
		{
			var ascOrDesc;
			var sortField = gEBI( "sortSelect" ).value;
			ascOrDesc = ( gEBI( "ascdescsortasc" ).checked ? "asc" : "desc" );
			if( sortField == "awardwinners" )
			{
				if( ascOrDesc == "asc" )
					this.devices.sort( awardAsc );
				else
					this.devices.sort( awardAsc );
			}
			else if( sortField == "manufacturer" )
			{
				if( ascOrDesc == "asc" )
					this.devices.sort( manufacturerAsc );
				else
					this.devices.sort( manufacturerDesc );
			}
			else if( sortField == "price" )
			{
				if( ascOrDesc == "asc" )
					this.devices.sort( priceAsc );
				else
					this.devices.sort( priceDesc );
			}
			else if( sortField == "speed" )
			{
				if( ascOrDesc == "asc" )
					this.devices.sort( speedAsc );
				else
					this.devices.sort( speedDesc );
			}
			else
			{
				alert( "unknown sort field: " + sortField );
			}
			this.display();
		}
	}
	function awardAsc( a, b )
	{
		if( a.award && !b.award )
			return -1;
		else if( !a.award && b.award )
			return 1;
		else if( !a.award && !b.award )
			return 0;
		else
			return ( a.award.sortOrder + a.name.toUpperCase() < b.award.sortOrder + b.name.toUpperCase() ? -1 : ( b.award.sortOrder + b.name.toUpperCase() < a.sortOrder + a.name.toUpperCase() ? 1 : 0 ) );
	}
	function manufacturerAsc( a, b )
	{
		return ( a.name.toUpperCase() < b.name.toUpperCase() ? -1 : ( b.name.toUpperCase() < a.name.toUpperCase() ? 1 : 0 ) );
	}
	function manufacturerDesc( a, b )
	{
		return ( a.name.toUpperCase() < b.name.toUpperCase() ? 1 : ( b.name.toUpperCase() < a.name.toUpperCase() ? -1 : 0 ) );
	}
	function priceAsc( a, b )
	{
		if( a.price == -1 && b.price != -1 )
			return 1;
		else if( a.price != -1 && b.price == -1 )
			return -1;
		else if( a.price == -1 && b.price == -1 )
			return 0;
		else
			return ( a.price < b.price ? -1 : ( a.price > b.price ? 1 : 0 ) );
	}
	function priceDesc( a, b )
	{
		if( a.price == -1 && b.price != -1 )
			return 1;
		else if( a.price != -1 && b.price == -1 )
			return -1;
		else if( a.price == -1 && b.price == -1 )
			return 0;
		else
			return ( a.price < b.price ? 1 : ( a.price > b.price ? -1 : 0 ) );
	}
	function speedAsc( a, b )
	{
		if( a.speed == -1 && b.speed != -1 )
			return 1;
		else if( a.speed != -1 && b.speed == -1 )
			return -1;
		else if( a.speed == -1 && b.speed == -1 )
			return 0;
		else
			return ( a.speed < b.speed ? -1 : ( a.speed > b.speed ? 1 : 0 ) );
	}
	function speedDesc( a, b )
	{
		if( a.speed == -1 && b.speed != -1 )
			return 1;
		else if( a.speed != -1 && b.speed == -1 )
			return -1;
		else if( a.speed == -1 && b.speed == -1 )
			return 0;
		else
			return ( a.speed < b.speed ? 1 : ( a.speed > b.speed ? -1 : 0 ) );
	}
}
function searchResultsAddDevice( device )
{
	this.devices[ device.id ] = device;
	this.deviceCount++;
	if( !this.productFinder[ device.primaryType ] )
		this.productFinder[ device.primaryType ] = 1;
	else
		this.productFinder[ device.primaryType ]++;
}
function searchResultsDisplay()
{
	var output = "";
	say( "searchResults", output );
	var currentDevice = 0;
	var currentList = gEBI( "productList" ).value;
	output += "<table id='searchResultsTable' cellSpacing='0' cellPadding='0'><tr><th colspan='2' class='borderedTableCell color1 title'>Product Name</th><th class='borderedTableCell color1 title' colspan='2'>Details</th></tr>";
	for( var index in this.devices )
	{
		if( typeof this.devices[ index ] != "function" )
		{
			if( currentDevice >= this.start && currentDevice < this.start + this.show )
			{
				if( !this.devices[ index ].fetched )
				{
					if( dto.newTable( "deviceDetails", "ajax/BBBD0100GetDataByClusterTemplateAndGroup.asp?" +
					"BBBD0100Id=" + this.devices[ index ].id +
					"&ClusterName=Web Cluster" +
					"&TemplateName=iGuide - Device Search" +
					"&GroupName=iGuide - Device Search Results"
					) )
					{
						var innerTable = dto.Tables[ "deviceDetails" ];
						if( innerTable.Rows.length > 0 )
						{
							for( var j = 0; j < innerTable.Rows.length; j++ )
							{
								var PropertyName = innerTable.Rows[ j ][ 1 ];
								var Value = innerTable.Rows[ j ][ 2 ];
								var Prop0100Id = innerTable.Rows[ j ][ 3 ];
								if( PropertyName == "iGuide Image 75x75" )
								{
									this.devices[ index ].attachImage( Value );
								}
								else
								{
									var pair = new Pair( PropertyName, Value );
									this.devices[ index ].addPair( pair );
								}
							}
						}
						this.devices[ index ].fetched = true;
					}
					else
						alert( "Error getting details: " + dto.Tables[ "deviceDetails" ].Errors[ 0 ].Description );
				}
				output += "<tr>";
				var checked = "";
				var idAndComma = this.devices[ index ].id + ",";
				if( currentList.indexOf( idAndComma ) > -1 )
					checked = "checked ";
				output += "<td class='borderedTableCell'><input " + checked + "type='checkbox' id='c" + this.devices[ index ].id + "' onclick='updatelist(" + this.devices[ index ].id + ");' name='products' value='" + this.devices[ index ].id + "'/></td>";
				output += "<td class='borderedTableCell label1 imageAndNameCell'>";
				//if( payedUserCheck() )//this check was used to prevent non-paying customers from accessing the product details
					output += "<form method='POST' action='productdetails.asp'>";
				output += "<input type='hidden' value='" + this.devices[ index ].id + "' name='deviceId' />";
				output += "<input type='image' height='75' width='75' src='" + this.devices[ index ].image + "'/><br />";
				output += this.devices[ index ].name;
				//if( payedUserCheck() )
					output += "</form>";
				output += "</td>";
				output += "<td class='borderedTableCell'>";
				output += "<div class='detailsCell'>";
				for( var index2 in this.devices[ index ].pairs )
				{
					if( typeof this.devices[ index ].pairs[ index2 ] != "function" )
					{
						if( this.devices[ index ].pairs[ index2 ].value != "-1" )
							//this.devices[ index ].pairs[ index2 ].value = "N/A";	
							output += "<div class='details'>" + this.devices[ index ].pairs[ index2 ].name + " : " +
								( this.devices[ index ].pairs[ index2 ].name == "Price" ? "$" : "" ) +
								this.devices[ index ].pairs[ index2 ].value +
								( this.devices[ index ].pairs[ index2 ].name == "Speed (black & white)" || this.devices[ index ].pairs[ index2 ].name == "Speed (color)" ? "ppm" : "" ) + "</div>";
					}
				}
				output += "</div>";
				output += "</td><td class='borderedTableCell awardCell'>";
				if( this.devices[ index ].award )
					output += "<img src='img/" + this.devices[ index ].award.imageFile + "' title='" + this.devices[ index ].award.text + "' alt='" + this.devices[ index ].award.text + "'/>";
				else
					output += "&nbsp;";
				output += "</td></tr>";
			}
			currentDevice++;
		}
	}
	output += "</table>";
	say( "searchResults", output );
}
function displayPaging()//this function displays the pagination links for search results
{
	var output = "";
	var totalPages = Math.ceil( this.deviceCount / this.show );
	var lowestShownPage = 0;
	var highestShownPage = totalPages;
	if( ( this.start / this.show ) - this.pageCushion > 0 )
		lowestShownPage = ( this.start / this.show ) - this.pageCushion;
	if( 1 + ( this.start / this.show ) + this.pageCushion < totalPages )
		highestShownPage = 1 + ( this.start / this.show ) + this.pageCushion;
		
	if( totalPages == 1 )
		say( "pageLinks", "<div id='pageLeft'></div><div id='pages'></div><div id='pageRight'></div>" );
	else
	{
		if( this.start != 0 )
			say( "pageLeft", "<a class='blueLink' onclick='changeStart(" + ( parseInt( this.start ) - parseInt( this.show ) ) + ");'>&lt;&lt;</a> &nbsp;&nbsp;" );
		else
			say( "pageLeft", "" );
		for( var i = lowestShownPage; i < highestShownPage; i++ )
		{
			if( this.start == (i * this.show) )
				output += ( i + 1 ) + " | ";
			else
				output += "<a class='blueLink' onclick='changeStart(" + (i * this.show) + ");'>" + ( i + 1 ) + "</a> | ";
		}
		output = output.substring( 0, output.length - 2 )
		if( 1 + ( this.start / this.show ) < totalPages )
			say( "pageRight", "&nbsp;&nbsp;<a class='blueLink' onclick='changeStart(" + ( parseInt( this.start ) + parseInt( this.show ) ) + ");'>&gt;&gt;</a>" );
		else
			say( "pageRight", "" );
		say( "pages", output );
	}
	showHideById( "show", "pageLinks" );
}
function showProductFinder()
{
	var data = "";
	var total = 0;
	for( var index in this.productFinder )
	{
		if( typeof this.productFinder[ index ] != "function" )
		{
			data += "<li>" + index + " (" + this.productFinder[ index ] + ")</li>";
			total += this.productFinder[ index ];
		}
	}
	var output = "<ul class='plainList'><li id='productFinderTotal' class='heading'>Total Products (" + total + ")</li>" + data + "</ul>";
	say( "productFinderData", output );
}
function searchResultsClear()
{
	say( "searchResults", "" );
	this.devices = new Array();
	this.productFinder = new Array();
	this.deviceCount = 0;
	this.start = 0;
}
function Award( imageFile, sortOrder, text )
{
	this.imageFile = imageFile;
	this.sortOrder = sortOrder;
	this.text = text;
}
function debug(aMsg) {
   setTimeout(function() { throw new Error("[debug] " + aMsg); }, 0);
}
