﻿//Java Script applying to the Locator.aspx file


window.onload=LoadPage; //On page load, perform the setup functions
window.onresize=resizeCenter; //When the window is resized perform the resize function
document.onkeypress = checkEnter; //When a key is pressed, check for the enter key

if (document.layers) document.captureEvents(Event.KEYPRESS);

//method checkEnter
//checks to see if the enter key was pressed and if so attempts to geocode the address and
//display it.
//Parameter: e - event code
function checkEnter(e)
{
	var pK = e ? e.which : window.event.keyCode;
	if(pK == 13)
		FindMachines();
	if(BrowserDetect.browser = 'Safari' && pK == 3)
	{
		FindMachines();
	}
		
	return pK != 13;
}

//method LoadPage
//performs all the required tasks to display the page correctly
function LoadPage()
{
	try
	{
		//If the client's browser is not a supported one then 
		//direct them over to the MapPoint webpage instead of the Virtual Earth
		if(BrowserDetect.browser != 'Firefox' && 
			(BrowserDetect.browser != 'Explorer' || 
				(BrowserDetect.version != '7' && BrowserDetect.version != '6' && BrowserDetect.version != '8') ) &&
			BrowserDetect.browser != 'Safari' )
		{
			//alert('Browser does not support Virtual Earth, redirecting to the MapPoint website.  If you think this is an error please use the link at the top of the page to alert the developers.');
			window.location = 'MapPoint/locator.aspx';
		}
		else
		{
			setMasterOptions();	//based on the country and language selected display the correct items
			clearProgError();	//Clear any errors displayed
			setMenuLoc();
			onCountryChange();	//display the correct input options for the selected country
			onSearchChange();	//display the correct search option (onload defaults to search by # of machines)
			
			toggleOff('ProductOptions', true);	//turn off the product selection display
			toggle('AdDisplay', true);	//turn on the display of the add
			resizeCenter();	//Setup the initial size of the the display
			
			//Do not display the quick locator when in the advanced locator
			var quick = document.getElementById('quickSearch');
			var link = document.getElementById('lnkAdvSearch');
			
			quick.style.display = "none";
			link.style.display = "none";
			
			//Set version display to MapPoint version
			var version = document.getElementById('version');
			var versionMP = document.getElementById('versionMP');
			version.style.display = 'inline';
			versionMP.style.display = 'none';
			
			var error = getKey('error');
			if(error != null && error != "")
			{
				setProgError(getError(error));
			}
		}
	}
	catch(e)
	{
		setProgError('an error occured loading the search page.', 'LoadPage', e.message);
	}
}

//Method getError
//returns the string for an error code
//Parameters: error - error code number
function getError(error)
{
	switch(error)
	{
		case "0":
			return "";
		case "1":
			return "Unable to find address, please try again!";
		default:
			return "Unknown Error occured";
	}
}

//Method resizeCenter
//resizes the ad or the product options display to fit the size of the window
function resizeCenter()
{
	try
	{
		//get the adspot div
		var centerDiv = document.getElementById('adspot');
		
		if(centerDiv.style.display == 'none')
		//If the adspot is not displayed get the product display and make it 100% size
		{
			centerDiv = document.getElementById('products');
			
			//Get the coordinates of the adspot
			centerCoords = findPos(centerDiv);
			//Get the size of the window
			size_window = windowSize();
			//Calculate the size to make the adspot
			var width = (size_window[0] - centerCoords[0] - 60);
			//if the size is too small in either direction, set the size to the minimum
			if(width < 500)
				width = 500;
			centerDiv.style.width = width + 'px';
			centerDiv.style.height = '100%';
		}
		else
		{
			//Get the coordinates of the adspot
			centerCoords = findPos(centerDiv);
			
			//Get the size of the window
			size_window = windowSize();
			//Calculate the size to make the adspot
			var width = (size_window[0] - centerCoords[0] - 60);
			var height = (size_window[1] - centerCoords[1] - 150);
			//if the size is too small in either direction, set the size to the minimum
			if(width < 500)
				width = 500;
			if(height < 428)
				height = 428;
				
			centerDiv.style.width = width + "px";
			centerDiv.style.height = height + "px";
		}
	}
	catch(e)
	{
		setProgError('an error occured resizing the ad panel.', 'resizeMap', e.message);
	}
}

//Method buildProductSelection
//Builds the product selection list based on the country and language selected
function buildProductSelection()
{
	try
	{
		//Get the country and language selection
		var countryList = document.getElementById('_ctl0_cphLeftNav_ddlCountry');
		var country = countryList.options[countryList.selectedIndex].value;
		var language = document.getElementById('_ctl0_txtMasterLanguage').value;
		
		var productText = "";
		//Get the appropriate values sent up by the server based on the language
		if(language == 'EN')
		{
			if(country == 'EN' || country == 'ES')
				productText = document.getElementById('_ctl0_cphCenterContent_txtENUSProducts').value;
			else if(country == 'IN')
				productText = document.getElementById('_ctl0_cphCenterContent_txtENUKProducts').value;
			else if(country == 'IE')
				productText = document.getElementById('_ctl0_cphCenterContent_txtENIEProducts').value;
			else
				productText = document.getElementById('_ctl0_cphCenterContent_txtENCAProducts').value;
		}
		else if(language == 'ES')
		{
			if(country == 'EN' || country == 'ES')
				productText = document.getElementById('_ctl0_cphCenterContent_txtESUSProducts').value;
			else if(country == 'IN')
				productText = document.getElementById('_ctl0_cphCenterContent_txtESUKProducts').value;
			else if(country == 'IE')
				productText = document.getElementById('_ctl0_cphCenterContent_txtESIEProducts').value;
			else
				productText = document.getElementById('_ctl0_cphCenterContent_txtESCAProducts').value;
		}
		else
		{
			if(country == 'EN' || country == 'ES')
				productText = document.getElementById('_ctl0_cphCenterContent_txtFRUSProducts').value;
			else if(country == 'IN')
				productText = document.getElementById('_ctl0_cphCenterContent_txtFRUKProducts').value;
			else if(country == 'IE')
				productText = document.getElementById('_ctl0_cphCenterContent_txtFRIEProducts').value;
			else
				productText = document.getElementById('_ctl0_cphCenterContent_txtFRCAProducts').value;
		}
		
		//variables to store the NPO section since displayed differently
		var NPOSection = '';
		var NPOTypeId;
		var NPOPos;
		var NPOTypeName;
		
		//variables to store the Coin counting section since displayed differently
		var CoinSection = '';
		var CoinTypeId;
		var CoinPos;
		var CoinTypeName;
		
		//Split the product list into the types
		var types = productText.split('~~');
		var typeArray = new Array();
		var prodArray = new Array();
		//for each type create the html code to display
		for(var type = 0; type < types.length; type++)
		{
			//Split the type list into products
			var products = types[type].split('~');
			var prodAndId = '';
			var tempSection = '';
			//Create the html for the product table rows
			for(var product = 1; product < products.length; product++)
			{
				prodAndId = products[product].split(';'); //Get product name and id
				tempSection += '<tr><td valign="top" align="left"><input type="checkbox" value="' + prodAndId[1] + '" id="chk' + type + '_' + product + 
					'" onclick="onProviderClick(\'chk' + type + '\')" /></td><td align="left">' + prodAndId[0] + '</td></tr><tr style="height:3px;"></tr>';
			}
			prodAndId = products[0].split(';'); //Get type name and id
			
			if(prodAndId[0] == 'Non-Profit Organizations' || prodAndId[0] == 'Organisations à but non lucratif' ||
				prodAndId[0] == 'Organizaciones sin fines de lucro')
			//if the product type is NPO set the NPO variables
			{
				NPOSection = tempSection;
				NPOTypeId = prodAndId[1];
				NPOTypeName = prodAndId[0];
				NPOPos = type;
			}
			else if(prodAndId[0] == 'Coin Counting' || prodAndId[0] == 'Conteo de monedas' ||
				prodAndId[0] == 'Comptage de pièces de monnaie')
			//if the product type is coin counting set the coin variables
			{
				CoinSection = tempSection;
				CoinTypeId = prodAndId[1];
				CoinTypeName = prodAndId[0];
				CoinPos = type;
			}
			else
			//for all other types add the product section to the product array and add the
			//type section to the type array
			{
				prodArray.push(tempSection);
				typeArray.push('<tr>' + 
					'<td valign="top" align="left"><input type="checkbox" id="chk' + type + '_type" value="' + prodAndId[1] + '" onclick="onTypeHeaderClick(\'chk' + type + '\')" /></td>' + 
					'<td align="left"><b>' + prodAndId[0] + ':</b></td>' + 
					'<td align="left"><img src="images/_clear.gif" alt="" height="1px" width="5px" /></td>' + 
					(getIcon(prodAndId[0]) == '' ? '' : '<td align="left"><img src="images/legend/service_icon_' + getIcon(prodAndId[0]) + '.png" alt="" width="20px" height="17px" /></td>') +
					'<td align="left"><img src="images/_clear.gif" alt="" height="1px" width="20px" /></td>' + 
					'</tr></table></td>');
					
					
			}
		}
		
		//create the html table for the products
		var products = '';
		products += '<table cellpadding="0" cellspacing="1" width="100%">';
		products += '<tr style="height:10px;"></tr>';
		products += '<tr><td colspan="3" align="left"><table cellpadding="0" cellspacing="0"><tr><td style="width:15px;" align="left"></td><td>'
		if(language == 'EN')
		{
			products += 'To find a specific product or service check the appropriate box then hit the "Locate" button on the left.</td></tr>';
			products += '<td style="width:15px;" align="left"></td></tr></table><tr style="height:10px;"></tr>';
			products += '<tr><td align="left"><span style="cursor:pointer; text-decoration: underline;" onclick="selectAllProds(true);">Select All</span></td></tr>';
			products += '<tr><td align="left"><span style="cursor:pointer; text-decoration: underline;" onclick="selectAllProds(false);">Deselect All</span></td></tr>';
		}
		else if(language == 'ES')
		{
			products += 'Para encontrar un producto o productos específicos, marque al lado del los productos que quiera y luego oprima "Localize" usando el botón a la izquierda.</td></tr>';
			products += '<td style="width:15px;" align="left"></td></tr></table><tr style="height:10px;"></tr>';
			products += '<tr><td align="left"><span style="cursor:pointer; text-decoration: underline;" onclick="selectAllProds(true);">Seleccione Todos</span></td></tr>';
			products += '<tr><td align="left"><span style="cursor:pointer; text-decoration: underline;" onclick="selectAllProds(false);">Deseleccione Todos</span></td></tr>';
		}
		else
		{
			products += 'Pour trouver un produit ou un service particulier, cocher la case appropriée et cliquer sur &lt;&lt;Chercher&gt;&gt; à gauche.</td></tr>';
			products += '<td style="width:15px;" align="left"></td></tr></table><tr style="height:10px;"></tr>';
			products += '<tr><td align="left"><span style="cursor:pointer; text-decoration: underline;" onclick="selectAllProds(true);">Sélectionner tout</span></td></tr>';
			products += '<tr><td align="left"><span style="cursor:pointer; text-decoration: underline;" onclick="selectAllProds(false);">Effacer tout</span></td></tr>';
		}
		
		//based on the the number of types and if there is an NPO section determine the width of the table
		var width;
		if(NPOSection != '' && typeArray.length > 1)
			width = '33';
		else if((NPOSection != '' && typeArray.length == 1) || (NPOSection == '' && typeArray.length > 1))
			width = '50';
		else
			width = '100';
		
		if(CoinSection != '')
		//if there is a coin section add the HTML
		{
			products += '<tr><td valign="middle" align="left" colspan="3" style="background-color: silver; width:' + width + '%;">';
			products += '<table cellpadding="0" cellspacing="0" style="padding: 2px;">';
			products += '<tr><td valign="top" align="left"><input type="checkbox" id="chk' + CoinPos + '_type" value="' + CoinTypeId + '" onclick="onTypeHeaderClick(\'chk' + CoinPos + '\')" /></td>' + 
					'<td align="left"><b>' + CoinTypeName + ':</b></td>' + 
					'<td align="left"><img src="images/_clear.gif" alt="" height="1px" width="5px" /></td>' + 
					(getIcon(CoinTypeName) == '' ? '' : '<td align="left"><img src="images/legend/service_icon_' + getIcon(CoinTypeName) + '.png" alt="" width="20px" height="17px" /></td>') +
					'<td align="left"><img src="images/_clear.gif" alt="" height="1px" width="20px" /></td>' + 
					'</tr></table></td></tr>'
			
			products += '<tr><td colspan="3" style="width:' + width + '%;" valign="top" align="left">';
			products += '<table cellpadding="0" cellspacing="0" style="padding: 2px;">';
			products += CoinSection + '</table></td>';
		}
		
		for(var times = 0; times < typeArray.length; times = times + 2)
		//Add the type sections and product list
		{
			products += '<tr>';
			
			products += '<td valign="middle" align="left" style="background-color: silver; width:' + width + '%;">';
			products += '<table cellpadding="0" cellspacing="0" style="padding: 2px;">';
			products += typeArray[times];
			if(typeArray.length > times + 1)
			{
				products += '<td valign="middle" align="left" style="background-color: silver; width:' + width + '%;">';
				products += '<table cellpadding="0" cellspacing="0" style="padding: 2px;">';
				products += typeArray[times + 1];
			}
				
			if(NPOSection != '' && times == 0)
			{
				products += '<td valign="middle" align="left" style="background-color: silver; width:' + width + '%;">';
				products += '<table cellpadding="0" cellspacing="0" style="padding: 2px;"><tr>';
				products += '<td align="left"><input type="checkbox" id="chk' + NPOPos + '_type" value="' + NPOTypeId + '" onclick="onTypeHeaderClick(\'chk' + NPOPos + '\')" /></td>';
				if(language == 'EN')
					products += '<td align="left"><b>Non-Profit Organizations:</b></td>';
				else if(language == 'ES')
					products += '<td align="left"><b>Organizaciones sin fines de lucro:</b></td>';
				else
					products += '<td align="left"><b>Organisations à but non lucratif:</b></td>';
				
				products += '<td align="left"><img src="images/_clear.gif" alt="" height="1px" width="5px" /></td>';
				products += '<td align="left"><img src="images/legend/service_icon_donate.png" alt="" width="20px" height="17px" /></td>';
				products += '<td align="left"><img src="images/_clear.gif" alt="" height="1px" width="20px" /></td>';
				products += '</tr></table></td>';
			}
			products += '</tr>';
		
			products += '<tr>';
			products += '<td style="width:' + width + '%;" valign="top" align="left">';
			products += '<table cellpadding="0" cellspacing="0" style="padding: 2px;">';
			products += prodArray[times];
			
			if(prodArray.length > times + 1)
			{
				products += '</table></td>';
				products += '<td style="width:' + width + '%;" valign="top" align="left">';
				products += '<table cellpadding="0" cellspacing="0" style="padding: 2px;">';
				products += prodArray[times + 1];
			}
			products += '</table></td>';
			
			if(NPOSection != '' && times == 0)
			{
				products += '<td style="width:' + width + '%;" valign="top" align="left" rowspan="8">';
				products += '<table cellpadding="0" cellspacing="0" style="padding: 2px;">';
				products += NPOSection;
				products += '</table></td>';
			}
			products += '</tr>';
		}
		products += '<tr id="productBuffer" style="height:10px;"></tr></table>';
		document.getElementById('products').innerHTML = products;
		
		var buffer = document.getElementById('productBuffer');
		if(NPOSection != '')
		//If there is an NPO create a blank row to fill up the space between the last product 
		//and the end of the NPO list.
		{
			var prodCount = 1;
			var product = null;
			while(product = document.getElementById('chk' + (typeArray.length + 1) + '_' + prodCount))
				prodCount++;
			prodCount--;
			product = document.getElementById('chk' + (typeArray.length + 1) + '_' + prodCount)
			
			prodCount = 1;
			var lastNPO = null;
			while(lastNPO = document.getElementById('chk' + NPOPos + '_' + prodCount))
				prodCount++;
			prodCount--;
			lastNPO = document.getElementById('chk' + NPOPos + '_' + prodCount)
			
			var prodCoords = findPos(product);
			var npoCoords = findPos(lastNPO);
			
			var diff = npoCoords[1] - prodCoords[1];
			
			if(diff > 0)
			{
				buffer.style.height = (diff + 20) + 'px';
			}
			else
			{
				buffer.style.height = '0px';
			}
		}
		else
			buffer.style.height = '0px';
		
	}
	catch(e)
	{
		setProgError('an error occured getting the product types.', 'buildProductSelection', e.message);
	}
}

//Method getIcon
//retrieves the icon name for the given type
//Parameters: type - the type name to get the icon name for
function getIcon(type)
{
	//Create the array of possible type names in the given language of the page
	var language = document.getElementById('_ctl0_txtMasterLanguage').value;
	var types = new Array();
		if(language == 'FR')
			types = new Array('Cartes de cadeau', 'Certificats électroniques', 
				'Comptage de pièces de monnaie', 'Organisations à but non lucratif', 
				'Enquête de livre de paie et rapport de salaire', 
				'Cartes d\'argent comptant', 'Temps d\'antenne', 
				'Longue distance', 'Bon d\'argent comptant de livre de paie');
		else if(language == 'ES')
			types = new Array('Tarjeta de Regalo', 'eCertificate', 'Conteo de monedas', 
				'Organizaciones sin fines de lucro', 'Saldo de Nomina y Resumen de Sueldo', 
				'Tarjeta de Efectivo', 'Tiempo de conexión', 'Larga distancia',
				'Comprobante de efectivo de nòmina');
		else
			types = new Array('Gift Cards', 'eCertificate', 'Coin Counting', 
				'Non-Profit Organizations', 'Payroll Balance Inquiry and Wage Statement', 
				'Cash Cards', 'Wireless Airtime', 'Long Distance',
				'Payroll Cash Voucher');

	if(type == types[4] || type == types[8])
		return 'payroll';
	else if(type == types[3])
		return 'donate';
	else if(type == types[2])
		return 'coin';
	else if(type == types[5])
		return 'cashc';
	else if(type == types[1])
		return 'eCert';
	else if(type == types[0])
		return 'giftc';
	else if(type == types[6])
		return 'wireless';
	else if(type == types[7])
		return 'longdist';
	return '';
}

//Method FindMachines
//sets the appropriate values and submits the form to find the machines and redirect to the map page
function FindMachines()
{
	try
	{
		//Validate the address input
		var isError = validate();
		
		//If it is a valid address...
		if(isError == 0)
		{
			//left over from using Virtual Earth!
			var lat = document.getElementById('_ctl0_cphCenterContent_txtLatitude');
			var lon = document.getElementById('_ctl0_cphCenterContent_txtLongitude');
			lat.value = "0";
			lon.value = "0";
			
			
			//Get the main form
			var frmMain;
			for(var times = 0; times < document.forms.length; times++)
			{
				if(document.forms[times].id == "aspnetForm")
					frmMain = document.forms[times];
			}
			
			//Get the list of types and providers selected by the user
			var provider = document.getElementById('_ctl0_cphCenterContent_txtSelectedProviderValue');
			var type = document.getElementById('_ctl0_cphCenterContent_txtSelectedTypeValue');
			provider.value = '';
			type.value = '';
			
			var typeCheckArray = new Array();
			var typeCheck = null;
			var count = 0;
			var all = true;
			while(typeCheck = document.getElementById('chk' + count + '_type'))
			{
				typeCheckArray.push(typeCheck);
				if(typeCheck.checked == false)
					all = false;
				count++;
			}
			
			//broken here
			
			//typeCheckArray = reverseArray(typeCheckArray);
			//typeCheckArray.reverse();
			
			//Currently only an or search is performed.
			var orSearch = true;//document.getElementById('_ctl0_cphLeftNav_radMultipleOr').checked;
			
			if(document.getElementById('products').style.display != 'none' && (!all || !orSearch))
			{
				var provID = '';
				var typeID = '';
				var between = '';
				var betweenType = '';
				var skipType = '';
				for(var times = 0; times < typeCheckArray.length; times++)
				{
					if(typeCheckArray[times].checked == true)
					{
						typeID += betweenType + typeCheckArray[times].value;
						betweenType = ', ';
					}
					else
					{
						count = 1;
						var prodCheck = null;
						while(prodCheck = document.getElementById('chk' + times + '_' + count))
						{
							if(prodCheck.checked == true)
							{
								provID += between + prodCheck.value;
								between = ', ';
							}
							count++;
						}
					}
				}
				provider.value = provID;//providers.options[providers.selectedIndex].value;
				type.value = typeID;
			}
			
			//If no types or providers are selected set the ids to 0
			if(type.value == '')
				type.value = '0';
			if(provider.value == '')
				provider.value = '0';
			
			//Submit the form
			frmMain.submit();
		}
	}
	catch(e)
	{
		setProgError('an error occured geocoding the address.', 'FindMachines', e.message);
	}
}

//Method reverseArray
//reverses the array positions
//Parameters: oriArray - the original array to reverse
//Returns: the original array in reverse order
//function reverseArray(oriArray)
//{
//	var revArray = new Array();
//	var item = null;
//	while(item = oriArray.pop())
//		revArray.push(item);
//	return(revArray);
//}

//Method selectAllProds
//select/deselect all products
//Parameters: select - if true select all products, otherwise deselect all products
function selectAllProds(select)
{
	var typeCount = 0;
	var type = null;
	while(type = document.getElementById('chk' + typeCount + '_type'))
	{
		type.checked = select;
		var prodCount = 1;
		var product = null;
		while(product = document.getElementById('chk' + typeCount + '_' + prodCount))
		{
			product.checked = select;
			prodCount++;
		}
		typeCount++;
	}
}

//Method onTypeHeaderClick
//when a type is selected select/deselect all products of that type
//Parameters: type - The type to select/delselect
function onTypeHeaderClick(type)
{
	var typeChecked = document.getElementById(type + '_type').checked;
	var product = null;
	var number = 1;
	var productArray = new Array();
	while(product = document.getElementById(type + '_' + number))
	{
		productArray.push(product);
		number++;
	}
	if(typeChecked == true)
	//Check all subproducts
	{
		for(var times = 0; times < productArray.length; times++)
		{
			productArray[times].checked = true;
		}
	}
	else
	//uncheck all subproducts
	{
		for(var times = 0; times < productArray.length; times++)
		{
			productArray[times].checked = false;
		}
	}
}

//Method onProviderClick
//if a product is selected/deselected, deselect the type
//Parameters: type - the type to deselect
function onProviderClick(type)
{
	document.getElementById(type + '_type').checked = false;
}

//Method setMasterOtions
//Toggle the language values based on the values set by the Masterpage
function setMasterOptions()
{
	try
	{
		//Get the set language and country
		var language = document.getElementById('_ctl0_txtMasterLanguage').value;
		var country = document.getElementById('_ctl0_txtMasterCountry').value;
		
		//Toggle the language changes
		if(language == 'EN')
		{
			toggle('masterEN');
			toggleOff('masterES');
			toggleOff('masterFR');
		}
		else if(language == 'ES')
		{
			toggle('masterES');
			toggleOff('masterEN');
			toggleOff('masterFR');
		}
		else
		{
			toggle('masterFR');
			toggleOff('masterES');
			toggleOff('masterEN');
		}
		//Toggle the country changes and set the appropriate country selection
		if(country == 'EN' || country == 'ES')
		{
			toggle('masterUS');
			toggleOff('masterCA');
			toggleOff('masterIN');
			toggleOff('masterIE');
		}
		else if(country == 'CE' || country == 'CF')
		{
			toggle('masterCA');
			toggleOff('masterUS');
			toggleOff('masterIN');
			toggleOff('masterIE');
		}
		else if(country == 'IN')
		{
			toggle('masterIN');
			toggleOff('masterCA');
			toggleOff('masterUS');
			toggleOff('masterIE');
		}
		else
		{
			toggle('masterIE');
			toggleOff('masterCA');
			toggleOff('masterUS');
			toggleOff('masterIN');
		}
		setCountryOptions(country, language);
	}
	catch(e)
	{
		setProgError('an error occured setting the language and country options.', 'setMasterOptions', e.message);
	}
}

//Method setCountryOptions
//includes the appropriate countries in the correct language in the country selection drop down list.
function setCountryOptions(page, language)
{
	try
	{				
		var ENText = 'United States - English';
		var ESText = 'United States - Spanish';
		var INText = 'United Kingdom';
		var IEText = 'Ireland';
		var CEText = 'Canada - English';
		var CFText = 'Canada - French';
		if(language == 'FR')
		{
			ENText = 'Les Etats-Unis - Anglais';
			ESText = 'Les Etats-Unis - Español';
			INText = 'Le Royaume-Uni';
			IEText = 'L\'Irlande';
			CEText = 'Canada - English';
			CFText = 'Canada - Français';
		}
		else if(language == 'ES')
		{
			ENText = 'Estados Unidos - Inglés';
			ESText = 'Estados Unidos - Español';
			INText = 'Reino Unido';
			IEText = 'Irlanda';
			CEText = 'Canadá - Inglés';
			CFText = 'Canadá - Francés';
		}
		else
		{
			ENText = 'United States - English';
			ESText = 'United States - Spanish';
			INText = 'United Kingdom';
			IEText = 'Ireland';
			CEText = 'Canada - English';
			CFText = 'Canada - French';
		}
		var countrySel = document.getElementById('_ctl0_cphLeftNav_ddlCountry');
		for(var times = countrySel.length - 1; times >= 0; times--)
			countrySel.remove(times);
		
		var newOpt = document.createElement('option');
		newOpt.text = ENText;
		newOpt.value = 'EN';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		newOpt = document.createElement('option');
		newOpt.text = ESText;
		newOpt.value = 'ES';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		newOpt = document.createElement('option');
		newOpt.text = '---------------------------------------------';
		newOpt.value = '';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		newOpt = document.createElement('option');
		newOpt.text = INText;
		newOpt.value = 'IN';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		newOpt = document.createElement('option');
		newOpt.text = '---------------------------------------------';
		newOpt.value = '';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		
		newOpt = document.createElement('option');
		newOpt.text = IEText;
		newOpt.value = 'IE';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		newOpt = document.createElement('option');
		newOpt.text = '---------------------------------------------';
		newOpt.value = '';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		newOpt = document.createElement('option');
		newOpt.text = CEText;
		newOpt.value = 'CE';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		newOpt = document.createElement('option');
		newOpt.text = CFText;
		newOpt.value = 'CF';
		try{
		countrySel.add(newOpt, null);} //Standards complient, not IE.
		catch(e){
		countrySel.add(newOpt);} //IE Only
		
		if(page == 'CE')
			countrySel.options[7].selected = true;
		else if(page == 'CF')
			countrySel.options[8].selected = true;
		else if(page == 'IE')
			countrySel.options[5].selected = true;
		else if(page == 'ES')
			countrySel.options[1].selected = true;
		else if(page == 'IN')
			countrySel.options[3].selected = true;
		else
			countrySel.options[0].selected = true;
	}
	catch(e)
	{
		alert(e.message);
		setProgError('an error occured setting the country options.', 'setCountryOptions', e.message);
	}
}

//Method onSearchChange
//switch the appropriate values when changing from a distance search to a # machine search
function onSearchChange()
{
	try
	{
		var searchDist = document.getElementById('_ctl0_cphLeftNav_radSearchDist').checked;
		if(searchDist)
		{
			toggle('distSearch');
			toggleOff('numSearch');
		}
		else
		{
			toggleOff('distSearch');
			toggle('numSearch');
		}
	}
	catch(e)
	{
		setProgError('an error occured changing the search method.', 'onSearchChange', e.message);
	}
}

//method onCountryChange
//toggles the correct items to reflect the change of country
function onCountryChange()
{
	try
	{
		//Get the selected country
		var country = document.getElementById('_ctl0_cphLeftNav_ddlCountry');
		var selected = country.options[country.selectedIndex].value;
		var page = document.getElementById('_ctl0_txtMasterCountry').value;
		//Clear the errors
		clearErrors();
		
		if(selected == '')
		{
			if(page == 'CE')
				country.options[7].selected = true;
			else if(page == 'CF')
				country.options[8].selected = true;
			else if(page == 'IE')
				country.options[5].selected = true;
			else if(page == 'ES')
				country.options[1].selected = true;
			else if(page == 'IN')
				country.options[3].selected = true;
			else
				country.options[0].selected = true;
		}
		else if(selected != page)
		{
			window.location = "Locator.aspx?page=" + selected;
		}
		else
		{
			if(selected == 'EN' || selected == 'ES')
			{
				toggle('US');
				toggleOff('CA');
				toggleOff('UK');
				toggleOff('IE');
				toggle('notIE');
			}
			else if(selected == 'IN')
			{
				toggle('UK');
				toggleOff('CA');
				toggleOff('US');
				toggleOff('IE');
				toggle('notIE');
			}
			else if(selected == 'IE')
			{
				toggle('IE');
				toggleOff('CA');
				toggleOff('US');
				toggleOff('UK');
				toggleOff('notIE');
			}
			else
			{
				toggle('CA');
				toggleOff('US');
				toggleOff('UK');
				toggleOff('IE');
				toggle('notIE');
			}
			if(document.getElementById('products').style.display != 'none')
			{
				buildProductSelection();
				resizeCenter();
			}
		}
	}
	catch(e)
	{
		setProgError('an error occured changing the country.', 'onCountryChange', e.message);
	}
}

//Method clearErrors
//clears all errors from the screen
function clearErrors()
{
	try
	{
		toggleOff('genErr');
		toggleOff('cityErr');
		toggleOff('stateErr');
		toggleOff('zipErr');
		toggleOff('progErr');
		toggleOff('selectProdErr');
	}
	catch(e)
	{
		setProgError('an error occured clearing the address errors.', 'clearErrors', e.message);
	}
}

//Method showProductOptions
//toggles the display of the product options screen (check boxes)
function showProductOptions(obj)
{
	var language = document.getElementById('_ctl0_txtMasterLanguage').value;
	var notShownText = '';
	var ShownText = '';
	if(language == 'EN')
	{
		notShownText = 'Search for Specific Products &lt;&lt;'
		ShownText = 'Search for Specific Products &gt;&gt;'
	}
	else if(language == 'ES')
	{
		notShownText = 'Búsque productos específicos &lt;&lt;'
		ShownText = 'Búsque productos específicos &gt;&gt;'
	}
	else
	{
		notShownText = 'chercher un produit particulier &lt;&lt;'
		ShownText = 'chercher un produit particulier &gt;&gt;'
	}
		
	if(obj.innerHTML == notShownText)
	{
		toggleOff('ProductOptions', true);
		toggle('AdDisplay', true);
		resizeCenter();
		obj.innerHTML = ShownText;
		toggleOff('selectProdErr');
	}
	else
	{
		toggle('ProductOptions', true);
		toggleOff('AdDisplay', true);
		resizeCenter();
		obj.innerHTML = notShownText;
		toggleOff('selectProdErr');
		buildProductSelection();
	}
}

//Method validate
//validates the user inputs before submittion
function validate() 
{
	try
	{
		//Clear the errors
		clearErrors();
		
		var language = document.getElementById('_ctl0_txtMasterLanguage').value;
		
		//Get the current country
		var countryList = document.getElementById('_ctl0_cphLeftNav_ddlCountry');
		var country = countryList.options[countryList.selectedIndex].value;
		
		//retrieve the shared values
		var zip = document.getElementById('_ctl0_cphLeftNav_txtZip').value;
		var city;
		if(country == 'IE')
		{
			var loc = document.getElementById('_ctl0_cphLeftNav_ddlLocation');
			city = loc.options[loc.selectedIndex].value;
		}
		else
			city = document.getElementById('_ctl0_cphLeftNav_txtCity').value;
		var street = document.getElementById('_ctl0_cphLeftNav_txtStreet').value;
		
		var isError = 0;
		
		//check to see that at least one type and/or product is selected
		if(document.getElementById('products').style.display != 'none')
		{
			var noneChecked = true;
			var typeCount = 0;
			var type = null;
			while(type = document.getElementById('chk' + typeCount + '_type'))
			{
				if(type.checked == true)
				{
					noneChecked = false;
					break;
				}
				var prodCount = 1;
				var product = null;
				while(product = document.getElementById('chk' + typeCount + '_' + prodCount))
				{
					if(product.checked == true)
					{
						noneChecked = false;
						break;
					}
					prodCount++;
				}
				if(!noneChecked)
					break;
				typeCount++;
			}
			if(noneChecked)
			{
				toggle('selectProdErr');
				isError = 1;
			}
		}
		
		//If there is a zip then the address if valid if not continue checking
		if(zip == "")
		{
			if(country == 'EN' || country == 'ES')
			//If US check for City and State as a minimum
			{
				var objstate;
				if(language == 'FR')
					objstate = document.getElementById('_ctl0_cphLeftNav_ddlStateFR');
				else if(language == 'ES')
					objstate = document.getElementById('_ctl0_cphLeftNav_ddlStateES');
				else
					objstate = document.getElementById('_ctl0_cphLeftNav_ddlStateEN');
				var state = objstate.options[objstate.selectedIndex].text
				
				if(state == "" || state == "Choose a state")
				{
					toggle('stateErr');
					isError = 1;
				}
				else
				{
					if(city == "")
					{
						toggle('cityErr');
						isError = 1;
					}
				}
			}
			else if(country == 'IN' || country == 'IE')
			//If UK check for City as a minimum
			{
				if(city == "")
				{
					toggle('cityErr');
					isError = 1;
				}
			}
			else
			//If Canada check for City and Province as a minimum
			{
				var objprovince;
				if(language == 'FR')
					objprovince = document.getElementById('_ctl0_cphLeftNav_ddlProvinceFR');
				else if(language == 'ES')
					objprovince = document.getElementById('_ctl0_cphLeftNav_ddlProvinceES');
				else
					objprovince = document.getElementById('_ctl0_cphLeftNav_ddlProvinceEN');
				var province = objprovince.options[objprovince.selectedIndex].text
				
				if(province == "" || province == "Choose a province")
				{
					toggle('stateErr');
					isError = 1;
				}
				else
				{
					if(city == "")
					{
						toggle('cityErr');
						isError = 1;
					}
				}
			}
		}
		
		return isError
	}
	catch(e)
	{
		setProgError('an error occured validating the address.', 'validate', e.message);
		return 1;
	}
}