var SAMPLE_POST = 'http://mapq.st';
var url, vs;

function showBasicURL(txtId) {
    url = SAMPLE_POST;
	
	//if user selected to map a location
	if (document.getElementById('locationType').checked) {
		//display the correct divs
		document.getElementById('routingDiv').style.display = "none";
		document.getElementById('searchDiv').style.display = "none";
		document.getElementById('bizDiv').style.display = "none";
		document.getElementById('streetTR').style.display = "none";
		document.getElementById('cityTR').style.display = "none";
		document.getElementById('stateTR').style.display = "none";
		document.getElementById('postalCodeTR').style.display = "none";
		document.getElementById('countryTR').style.display = "none";
		document.getElementById('singlelineTR').style.display = "none";
		document.getElementById('locationCenterTR').style.display = "none";
		document.getElementById('locationLabelTR').style.display = "none";
		document.getElementById('locationZoomTR').style.display = "none";
		document.getElementById('locationMaptypeTR').style.display = "none";
		document.getElementById('locationLayerTR').style.display = "none";
		document.getElementById('locationStaticTR').style.display = "none";
		document.getElementById('locationStaticKeyTR').style.display = "none";
		document.getElementById('locationStaticSizeTR').style.display = "none";
		document.getElementById('qType').checked = false;
		document.getElementById('addrType').checked = false;
		document.getElementById('toType').checked = false;
		document.getElementById('searchLocationType').checked = false;
		document.getElementById('searchSICType').checked = false;
		document.getElementById('searchRouteType').checked = false;
		document.getElementById('locationDiv').style.display = "";
		
		//initialize options and url
		url += '/map?';
		var label = document.getElementById('txtLocationLabel').value;
		var center = document.getElementById('txtLocationCenter').value;
		var zoom = document.getElementById('locationZoom').value;
		var maptype = document.getElementById('locationMaptype').value;
		var layer = document.getElementById('locationLayer').value;
		var locStaticMap = document.getElementById('locationStatic').value;
		var locStaticKey = document.getElementById('locationStaticKey').value;
		var locStaticSize = document.getElementById('locationStaticSize').value;
		
		//if a user is entering a single line address
		if (document.getElementById('singlelineType').checked) {
			//display the correct table rows
			document.getElementById('streetTR').style.display = "none";
			document.getElementById('cityTR').style.display = "none";
			document.getElementById('stateTR').style.display = "none";
			document.getElementById('postalCodeTR').style.display = "none";
			document.getElementById('countryTR').style.display = "none";
			document.getElementById('singlelineTR').style.display = "";
			document.getElementById('locationCenterTR').style.display = "";
			document.getElementById('locationLabelTR').style.display = "";
			document.getElementById('locationZoomTR').style.display = "";
			document.getElementById('locationMaptypeTR').style.display = "";
			document.getElementById('locationLayerTR').style.display = "";
			document.getElementById('locationStaticTR').style.display = "";
			document.getElementById('locationStaticKeyTR').style.display = "";
			document.getElementById('locationStaticSizeTR').style.display = "";

			//get the location text
			var location = document.getElementById('txtLocation').value;
			
			//put the url together
			
			if (url == SAMPLE_POST + '/map?') {
				url += 'q=' + location;
				if (label.length != 0) {
					url += ' (' + label + ')';
				}
			}
			else {
				url += '&q=' + location;
				if (label.length != 0) {
					url += ' (' + label + ')';
				}
			}
			if (center.length != 0) {
				if (url == SAMPLE_POST + '/map?') {
					url += 'center=' + center;
				}
				else {
					url += '&amp;center=' + center;
				}
			}
			if (zoom.length != 0) {
				if (url == SAMPLE_POST + '/map?') {
					url += 'zoom=' + zoom;
				}
				else {
					url += '&zoom=' + zoom;
				}
			}
			if (maptype.length != 0) {
				if (url == SAMPLE_POST + '/map?') {
					url += 'maptype=' + maptype;
				}
				else {
					url += '&maptype=' + maptype;
				}
			}
			if (layer.length != 0) {
				if (url == SAMPLE_POST + '/map?') {
					url += 'layer=' + layer;
				}
				else {
					url += '&layer=' + layer;
				}
			}
			if (locStaticMap == 'yes'){
				if (zoom.length == 0) {
					zoom = '11';
				}
				
				//get the text
				var location = document.getElementById('txtLocation').value;
				location = location.split(",");
				
				if (location.length == 2){
					var latLong = location[0]*location[1];
				}
			
				if (isNaN(latLong) == true){
					newURL = url;
					url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getplacemap?showicon=1&type=map&key=' + locStaticKey + '&location=' + location + '&zoom=' + zoom + '&size=' + locStaticSize + '" border="0"></a>';
				}
				else {
					newURL = url;
					url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getmap?type=map&key=' + locStaticKey + '&mcenter=' + location[0] + ',' + location[1] + '&size=' + locStaticSize + '" border="0"></a>';
				}
			}

			
			document.getElementById('routeStatic').value = "no";
			document.getElementById('staticSearch').value = "no";
			
		} //end of single line address
		
		//if a user is entering a fielded address
		else if (document.getElementById('fieldedType').checked) {
			//dispaly the correct tables rows
			document.getElementById('singlelineTR').style.display = "none";
			document.getElementById('streetTR').style.display = "";
			document.getElementById('cityTR').style.display = "";
			document.getElementById('stateTR').style.display = "";
			document.getElementById('postalCodeTR').style.display = "";
			document.getElementById('countryTR').style.display = "";
			document.getElementById('locationCenterTR').style.display = "";
			document.getElementById('locationLabelTR').style.display = "";
			document.getElementById('locationZoomTR').style.display = "";
			document.getElementById('locationMaptypeTR').style.display = "";
			document.getElementById('locationLayerTR').style.display = "";
			document.getElementById('locationStaticTR').style.display = "";
			document.getElementById('locationStaticKeyTR').style.display = "";
			document.getElementById('locationStaticSizeTR').style.display = "";
			
			//get the form text
			var street = document.getElementById('txtStreet').value;
			var city = document.getElementById('txtCity').value;
			var state = document.getElementById('txtState').value;
			var postalCode = document.getElementById('txtPostalCode').value;
			var country = document.getElementById('txtCountry').value;
			
			//put together the url
			if (url == SAMPLE_POST + '/map?') {
				url += 'q=';
			}
			else {
				url += '&q=';
			}
			if (street.length != 0) {
				url += "addr: " + street + " ";
			}
			if (city.length != 0) {
				url += "city: " + city + " ";
			}
			if (state.length != 0) {
				url += "state: " + state + " ";
			}
			if (postalCode.length != 0) {
				url += "postalCode: " + postalCode + " ";
			}
			if (country.length != 0) {
				url += "country: " + country + " ";
			}
			if (label.length != 0) {
				url += ' (' + label + ')';
			}
			if (center.length != 0) {
				if (url == SAMPLE_POST + '/map?') {
					url += 'center=' + center;
				}
				else {
					url += '&amp;center=' + center;
				}
			}
			if (zoom.length != 0) {
				if (url == SAMPLE_POST + '/map?') {
					url += 'zoom=' + zoom;
				}
				else {
					url += '&zoom=' + zoom;
				}
			}
			if (maptype.length != 0) {
				if (url == SAMPLE_POST + '/map?') {
					url += 'maptype=' + maptype;
				}
				else {
					url += '&maptype=' + maptype;
				}
			}
			if (layer.length != 0) {
				if (url == SAMPLE_POST + '/map?') {
					url += 'layer=' + layer;
				}
				else {
					url += '&layer=' + layer;
				}
			}
			var street = document.getElementById('txtStreet').value;
			var city = document.getElementById('txtCity').value;
			var state = document.getElementById('txtState').value;
			var postalCode = document.getElementById('txtPostalCode').value;
			var country = document.getElementById('txtCountry').value;
			if (locStaticMap == 'yes'){
				if (zoom.length == 0) {
					zoom = '11';
				}
				newURL = url;
				url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getplacemap?showicon=1&type=map&key=' + locStaticKey + '&location=' + street + ' ' + city + ' ' + state + ' ' + postalCode + ' ' + country + '&zoom=' + zoom + '&size=' + locStaticSize + '" border="0"></a>';
			}
			document.getElementById('routeStatic').value = "no";
			document.getElementById('staticSearch').value = "no";
		}//end of fielded address section
	} // end of mapping a location section
	
	//if user selected to map a route
	else if (document.getElementById('routeType').checked) {
		//display the correct div
		document.getElementById('locationDiv').style.display = "none";
		document.getElementById('searchDiv').style.display = "none";
		document.getElementById('bizDiv').style.display = "none";
		document.getElementById('saddrTR').style.display = "none";
		document.getElementById('daddrTR').style.display = "none";
		document.getElementById('toTR').style.display = "none";
		document.getElementById('qTR').style.display = "none";
		document.getElementById('directionLabelTR').style.display = "none";
		document.getElementById('routeCenterTR').style.display = "none";
		document.getElementById('routeZoomTR').style.display = "none";
		document.getElementById('routeMaptypeTR').style.display = "none";
		document.getElementById('routeLayerTR').style.display = "none";
		document.getElementById('routeStaticTR').style.display = "none";
		document.getElementById('routeStaticKeyTR').style.display = "none";
		document.getElementById('routeStaticSizeTR').style.display = "none";
		document.getElementById('routeStaticGeneralizationTR').style.display = "none";
		document.getElementById('singlelineType').checked = false;
		document.getElementById('fieldedType').checked = false;
		document.getElementById('searchLocationType').checked = false;
		document.getElementById('searchSICType').checked = false;
		document.getElementById('searchRouteType').checked = false;
		document.getElementById('routingDiv').style.display = "";
		
		//set up the url and options
		url += '/directions?';
		var center = document.getElementById('txtRouteCenter').value;
		var zoom = document.getElementById('routeZoom').value;
		var maptype = document.getElementById('routeMaptype').value;
		var layer = document.getElementById('routeLayer').value;
		var routeStaticMap = document.getElementById('routeStatic').value;
		var routeStaticKey = document.getElementById('routeStaticKey').value;
		var routeStaticSize = document.getElementById('routeStaticSize').value;
		var routeStaticGeneralization = document.getElementById('routeStaticGeneralization').value;
		
		//if using q parameter
		if (document.getElementById('qType').checked) {
			//display the correct tables rows
			document.getElementById('saddrTR').style.display = "none";
			document.getElementById('daddrTR').style.display = "none";
			document.getElementById('toTR').style.display = "none";
			document.getElementById('qTR').style.display = "";
			document.getElementById('directionLabelTR').style.display = "";
			document.getElementById('routeCenterTR').style.display = "";
			document.getElementById('routeZoomTR').style.display = "";
			document.getElementById('routeMaptypeTR').style.display = "";
			document.getElementById('routeLayerTR').style.display = "";
			document.getElementById('routeStaticTR').style.display = "";
			document.getElementById('routeStaticKeyTR').style.display = "";
			document.getElementById('routeStaticSizeTR').style.display = "";
			document.getElementById('routeStaticGeneralizationTR').style.display = "";
			
			//get the text
			var locations = document.getElementById('txtQ').value;
			locations = locations.split("|");
			var labels = document.getElementById('txtDirectionLabel').value;
			labels = labels.split("|");
			
			
			//form the url
			for (i=0;i<locations.length;i++) {
				if (i == 0 && url == SAMPLE_POST + '/directions?') {
					url += 'q' + (i+1) + '=' + locations[i];
					if (labels[i] != null && labels[0] != 0) {
						url += ' (' + labels[i] + ')';
					}
				}
				else {
					url += '&q' + (i+1) + '=' + locations[i];
					if (labels[i] != null && labels[0] != 0) {
						url += ' (' + labels[i] + ')';
					}
				}
			}
			if (center.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'center=' + center;
				}
				else {
					url += '&amp;center=' + center;
				}
			}
			if (zoom.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'zoom=' + zoom;
				}
				else {
					url += '&zoom=' + zoom;
				}
			}
			if (maptype.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'maptype=' + maptype;
				}
				else {
					url += '&maptype=' + maptype;
				}
			}
			if (layer.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'layer=' + layer;
				}
				else {
					url += '&layer=' + layer;
				}
			}
			if (routeStaticMap == 'yes'){
				getQDirections();
				newURL = url;
				
				url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getmap?key=' + routeStaticKey + '&type=map&scenter=' + startPoint + '&ecenter=' + endPoint + '&declutter=false&shapeformat=cmp&shape=' + routePoints + '&vias=' + viaPoints + '&size=' + routeStaticSize + '" border="0"></a>';
			}
			document.getElementById('locationStatic').value = "no";
			document.getElementById('staticSearch').value = "no";
		} // end of q parameter section
		
		//the addr parameters sections
		else if (document.getElementById('addrType').checked) {
			//display the correct table rows
			document.getElementById('qTR').style.display = "none";
			document.getElementById('toTR').style.display = "none";
			document.getElementById('saddrTR').style.display = "";
			document.getElementById('daddrTR').style.display = "";
			document.getElementById('directionLabelTR').style.display = "";
			document.getElementById('routeCenterTR').style.display = "";
			document.getElementById('routeZoomTR').style.display = "";
			document.getElementById('routeMaptypeTR').style.display = "";
			document.getElementById('routeLayerTR').style.display = "";
			document.getElementById('routeStaticTR').style.display = "";
			document.getElementById('routeStaticKeyTR').style.display = "";
			document.getElementById('routeStaticSizeTR').style.display = "";
			document.getElementById('routeStaticGeneralizationTR').style.display = "";
			
			//get the text
			var saddr = document.getElementById('txtSaddr').value;
			var daddr = document.getElementById('txtDaddr').value;
			
			var labels = document.getElementById('txtDirectionLabel').value;
			labels = labels.split("|");
			

			//form the url
			if (url == SAMPLE_POST + '/directions?') {
				url += 'saddr=' + saddr;
				if (labels[0] != null && labels[0] != 0) {
					url += ' (' + labels[0] + ')';
				}
				url += '&daddr=' + daddr;
				if (labels[1] != null && labels[1] != 0) {
					url += ' (' + labels[1] + ')';
				}
			}
			else {
				url += '&saddr=' + saddr;
				if (labels[0] != null) {
					url += ' (' + labels[0] + ')';
				}
				url += '&daddr=' + daddr;
				if (labels[1] != null) {
					url += ' (' + labels[1] + ')';
				}
			}
			if (center.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'center=' + center;
				}
				else {
					url += '&amp;center=' + center;
				}
			}
			if (zoom.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'zoom=' + zoom;
				}
				else {
					url += '&zoom=' + zoom;
				}
			}
			if (maptype.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'maptype=' + maptype;
				}
				else {
					url += '&maptype=' + maptype;
				}
			}
			if (layer.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'layer=' + layer;
				}
				else {
					url += '&layer=' + layer;
				}
			}
			if (routeStaticMap == 'yes'){
				getAddrDirections();
				newURL = url;
				
				url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getmap?key=' + routeStaticKey + '&type=map&scenter=' + startPoint + '&ecenter=' + endPoint + '&declutter=false&shapeformat=cmp&shape=' + routePoints + '&vias=' + viaPoints + '&size=' + routeStaticSize + '" border="0"></a>';
			}
			document.getElementById('locationStatic').value = "no";
			document.getElementById('staticSearch').value = "no";
		} // end of addr parameters section
		
		//if using the to parameter
		else if (document.getElementById('toType').checked) {
			//display the correct table rows
			document.getElementById('qTR').style.display = "none";
			document.getElementById('saddrTR').style.display = "none";
			document.getElementById('daddrTR').style.display = "none";
			document.getElementById('toTR').style.display = "";
			document.getElementById('directionLabelTR').style.display = "";
			document.getElementById('routeCenterTR').style.display = "";
			document.getElementById('routeZoomTR').style.display = "";
			document.getElementById('routeMaptypeTR').style.display = "";
			document.getElementById('routeLayerTR').style.display = "";
			document.getElementById('routeStaticTR').style.display = "";
			document.getElementById('routeStaticKeyTR').style.display = "";
			document.getElementById('routeStaticSizeTR').style.display = "";
			document.getElementById('routeStaticGeneralizationTR').style.display = "";
			
			//get the text
			var locations = document.getElementById('txtTo').value;
			locations = locations.split("|");
			
			var labels = document.getElementById('txtDirectionLabel').value;
			labels = labels.split("|");
			
			
			//form the url
			for (i=0;i<locations.length;i++) {
				if (i==0 && url == SAMPLE_POST + '/directions?') {
					url += 'q=' + locations[i];
					if (labels[0] != null && labels[0] != 0) {
						url += ' (' + labels[0] + ')';
					}
				}
				else if (i==0) {
					url += '&q=' + locations[i];
					if (labels[0] != null && labels[0] != 0) {
						url += ' (' + labels[0] + ')';
					}
				}
				else {
					url += ' to: ' + locations[i];
					if (labels[i] != null && labels[0] != 0) {
						url += ' (' + labels[i] + ')';
					}
				}
			}
			if (center.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'center=' + center;
				}
				else {
					url += '&amp;center=' + center;
				}
			}
			if (zoom.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'zoom=' + zoom;
				}
				else {
					url += '&zoom=' + zoom;
				}
			}
			if (maptype.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'maptype=' + maptype;
				}
				else {
					url += '&maptype=' + maptype;
				}
			}
			if (layer.length != 0) {
				if (url == SAMPLE_POST + '/directions?') {
					url += 'layer=' + layer;
				}
				else {
					url += '&layer=' + layer;
				}
			}
			if (routeStaticMap == 'yes'){
				getToDirections();
				newURL = url;
				
				url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getmap?key=' + routeStaticKey + '&type=map&scenter=' + startPoint + '&ecenter=' + endPoint + '&declutter=false&shapeformat=cmp&shape=' + routePoints + '&vias=' + viaPoints + '&size=' + routeStaticSize + '" border="0"></a>';
			}
			document.getElementById('locationStatic').value = "no";
			document.getElementById('staticSearch').value = "no";
		}//end of to parameter section
	} //end of routing section
	
	//if user selected to search
	else if(document.getElementById('searchType').checked) {
		//display the correct div
		document.getElementById('locationDiv').style.display = "none";
		document.getElementById('routingDiv').style.display = "none";
		document.getElementById('bizDiv').style.display = "none";
		document.getElementById('singlelineSearchTR').style.display = "none";
		document.getElementById('searchLabelTR').style.display = "none";
		document.getElementById('searchTermTR').style.display = "none";
		document.getElementById('routeSearch1TR').style.display = "none";
		document.getElementById('searchTerms1TR').style.display = "none";
		document.getElementById('routeSearch2TR').style.display = "none";
		document.getElementById('searchTerms2TR').style.display = "none";
		document.getElementById('searchTermSICTR').style.display = "none";
		document.getElementById('centerSearchTR').style.display = "none";
		document.getElementById('zoomSearchTR').style.display = "none";
		document.getElementById('maptypeSearchTR').style.display = "none";
		document.getElementById('layerSearchTR').style.display = "none";
		document.getElementById('staticSearchTR').style.display = "none";
		document.getElementById('staticSearchKeyTR').style.display = "none";
		document.getElementById('staticSearchSizeTR').style.display = "none";
		document.getElementById('singlelineType').checked = false;
		document.getElementById('fieldedType').checked = false;
		document.getElementById('qType').checked = false;
		document.getElementById('addrType').checked = false;
		document.getElementById('toType').checked = false;
		document.getElementById('searchDiv').style.display = "";
		
		//initialize options and url
		url += '/?';
		var label = document.getElementById('txtSearchLabel').value;
		var center = document.getElementById('txtLocationCenterSearch').value;
		var zoom = document.getElementById('locationZoomSearch').value;
		var maptype = document.getElementById('locationMaptypeSearch').value;
		var layer = document.getElementById('locationLayerSearch').value;
		var staticSearch = document.getElementById('staticSearch').value;
		var staticSearchKey = document.getElementById('staticSearchKey').value;
		var staticSearchSize = document.getElementById('staticSearchSize').value;
		
		
		//if user is searching a single location
		if (document.getElementById('searchLocationType').checked) {
			//dispaly the correct table rows
			document.getElementById('routeSearch1TR').style.display = "none";
			document.getElementById('routeSearch2TR').style.display = "none";
			document.getElementById('searchTerms1TR').style.display = "none";
			document.getElementById('searchTerms2TR').style.display = "none";
			document.getElementById('searchTermSICTR').style.display = "none";
			document.getElementById('singlelineSearchTR').style.display = "";
			document.getElementById('searchTermTR').style.display = "";
			document.getElementById('centerSearchTR').style.display = "";
			document.getElementById('zoomSearchTR').style.display = "";
			document.getElementById('maptypeSearchTR').style.display = "";
			document.getElementById('layerSearchTR').style.display = "";
			document.getElementById('staticSearchTR').style.display = "";
			document.getElementById('staticSearchKeyTR').style.display = "";
			document.getElementById('staticSearchSizeTR').style.display = "";
			
			//get the location text
			var location = document.getElementById('txtLocationSearch').value;
			var search = document.getElementById('txtSearchTerm').value;
			
			//put the url together
			if (url == SAMPLE_POST + '/?') {
				url += 'q=' + search + ' near: ' + location;
			}
			else {
				url += '&q=' + search + ' near: ' + location;
			}
			if (center.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'center=' + center;
				}
				else {
					url += '&amp;center=' + center;
				}
			}
			if (zoom.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'zoom=' + zoom;
				}
				else {
					url += '&zoom=' + zoom;
				}
			}
			if (maptype.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'maptype=' + maptype;
				}
				else {
					url += '&maptype=' + maptype;
				}
			}
			if (layer.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'layer=' + layer;
				}
				else {
					url += '&layer=' + layer;
				}
			}
			
			url = url.replace("/?", "/map?");
			
			if (staticSearch == 'yes'){
				if (zoom.length == 0) {
					zoom = '11';
				}
				
				//get the text
				var location = document.getElementById('txtLocationSearch').value;
				location = location.split(",");
				
				if (location.length == 2){
					var latLong = location[0]*location[1];
				}
			
				if (isNaN(latLong) == true){
					newURL = url;
					url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getplacemap?showicon=1&type=map&key=' + staticSearchKey + '&location=' + location + '&zoom=' + zoom + '&size=' + staticSearchSize + '" border="0"></a>';
				}
				else {
					newURL = url;
					url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getmap?type=map&key=' + staticSearchKey + '&mcenter=' + location[0] + ',' + location[1] + '&size=' + staticSearchSize + '" border="0"></a>';
				}
			}
			document.getElementById('locationStatic').value = "no";
			document.getElementById('routeStatic').value = "no";
		}
		//if user is searching a single location with SIC
		if (document.getElementById('searchSICType').checked) {
			//dispaly the correct table rows
			document.getElementById('routeSearch1TR').style.display = "none";
			document.getElementById('routeSearch2TR').style.display = "none";
			document.getElementById('searchTerms1TR').style.display = "none";
			document.getElementById('searchTerms2TR').style.display = "none";
			document.getElementById('searchTermTR').style.display = "none";
			document.getElementById('singlelineSearchTR').style.display = "";
			document.getElementById('searchLabelTR').style.display = "";
			document.getElementById('searchTermSICTR').style.display = "";
			document.getElementById('centerSearchTR').style.display = "";
			document.getElementById('zoomSearchTR').style.display = "";
			document.getElementById('maptypeSearchTR').style.display = "";
			document.getElementById('layerSearchTR').style.display = "";
			document.getElementById('staticSearchTR').style.display = "";
			document.getElementById('staticSearchKeyTR').style.display = "";
			document.getElementById('staticSearchSizeTR').style.display = "";
			
			//get the location text
			var location = document.getElementById('txtLocationSearch').value;
			var search = document.getElementById('txtSearchSICTerm').value;
				
				
			//put the url together
			if (url == SAMPLE_POST + '/?') {
				url += 'q=' + search + ' type: sic ' + ' near: ' + location;
				if (label.length != 0) {
					url += '(' + label + ')';
				}
			}
			else {
				url += '&q=' + search + ' type: sic ' + ' near: ' + location;
				if (label.length != 0) {
					url += '(' + label + ')';
				}
			}
			if (center.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'center=' + center;
				}
				else {
					url += '&amp;center=' + center;
				}
			}
			if (zoom.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'zoom=' + zoom;
				}
				else {
					url += '&zoom=' + zoom;
				}
			}
			if (maptype.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'maptype=' + maptype;
				}
				else {
					url += '&maptype=' + maptype;
				}
			}
			if (layer.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'layer=' + layer;
				}
				else {
					url += '&layer=' + layer;
				}
			}
			
			url = url.replace("/?", "/map?");
			
			if (staticSearch == 'yes'){
				if (zoom.length == 0) {
					zoom = '11';
				}
				
				//get the text
				var location = document.getElementById('txtLocationSearch').value;
				location = location.split(",");
				
				if (location.length == 2){
					var latLong = location[0]*location[1];
				}
			
				if (isNaN(latLong) == true){
					newURL = url;
					url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getplacemap?showicon=1&type=map&key=' + staticSearchKey + '&location=' + location + '&zoom=' + zoom + '&size=' + staticSearchSize + '" border="0"></a>';
				}
				else {
					newURL = url;
					url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getmap?type=map&key=' + staticSearchKey + '&mcenter=' + location[0] + ',' + location[1] + '&size=' + staticSearchSize + '" border="0"></a>';
				}
			}
			document.getElementById('locationStatic').value = "no";
			document.getElementById('routeStatic').value = "no";
		}
		//if user is searching route stop(s)
		else if (document.getElementById('searchRouteType').checked) {
			//dispaly the correct table rows
			document.getElementById('routeSearch1TR').style.display = "";
			document.getElementById('routeSearch2TR').style.display = "";
			document.getElementById('singlelineSearchTR').style.display = "none";
			document.getElementById('searchTermTR').style.display = "none";
			document.getElementById('searchTerms1TR').style.display = "";
			document.getElementById('searchTerms2TR').style.display = "";
			document.getElementById('centerSearchTR').style.display = "";
			document.getElementById('zoomSearchTR').style.display = "";
			document.getElementById('maptypeSearchTR').style.display = "";
			document.getElementById('layerSearchTR').style.display = "";
			document.getElementById('staticSearchTR').style.display = "";
			document.getElementById('staticSearchKeyTR').style.display = "";
			document.getElementById('staticSearchSizeTR').style.display = "";
			
			//get the location text
			var location1 = document.getElementById('txtRouteSearch1').value;
			var search1 = document.getElementById('txtSearchTerms1').value;
			var location2 = document.getElementById('txtRouteSearch2').value;
			var search2 = document.getElementById('txtSearchTerms2').value;
			
			//put the url together
			if (url == SAMPLE_POST + '/?') {
				url += 'q1=';
			}
			else {
				url += '&q1=';
			}
			
			url = url.replace("/?", "/directions?");
			
			//location and search item 1
			if (location1.length != 0 && search1.length != 0) {
				url += search1 + ' near: ' + location1;
			}
			else if (location1.length != 0) {
				url += location1;
			}
			else if (search1.length != 0) {
				url += search1;
			}
			
			//location and search item 2
			if (location2.length != 0 && search2.length != 0) {
				url += '&q2=' + search2 + ' near: ' + location2;
			}
			else if (location2.length != 0) {
				url += '&q2=' + location2;
			}
			else if (search2.length != 0) {
				url += '&q2=' + search2;
			}
			
			if (center.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'center=' + center;
				}
				else {
					url += '&amp;center=' + center;
				}
			}
			if (zoom.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'zoom=' + zoom;
				}
				else {
					url += '&zoom=' + zoom;
				}
			}
			if (maptype.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'maptype=' + maptype;
				}
				else {
					url += '&maptype=' + maptype;
				}
			}
			if (layer.length != 0) {
				if (url == SAMPLE_POST + '/?') {
					url += 'layer=' + layer;
				}
				else {
					url += '&layer=' + layer;
				}
			}
			if (staticSearch == 'yes'){
				getSearchDirections();
				newURL = url;
				
				url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getmap?key=' + staticSearchKey + '&type=map&scenter=' + startPoint + '&ecenter=' + endPoint + '&declutter=false&shapeformat=cmp&shape=' + routePoints + '&vias=' + viaPoints + '&size=' + staticSearchSize + '" border="0"></a>';
			}
			document.getElementById('locationStatic').value = "no";
			document.getElementById('routeStatic').value = "no";
		}

	} // end of search section
	
	
	//if user selected to map a route
	else if (document.getElementById('bizType').checked) {
		//display the correct div
		document.getElementById('locationDiv').style.display = "none";
		document.getElementById('searchDiv').style.display = "none";
		document.getElementById('routingDiv').style.display = "none";
		document.getElementById('bizCatTR').style.display = "";
		document.getElementById('bizSinglelineTR').style.display = "";
		document.getElementById('bizLabelTR').style.display = "";
		document.getElementById('bizZoomTR').style.display = "";
		document.getElementById('bizMaptypeTR').style.display = "";
		document.getElementById('bizLayerTR').style.display = "";
		document.getElementById('bizStaticTR').style.display = "";
		document.getElementById('bizStaticKeyTR').style.display = "";
		document.getElementById('bizStaticSizeTR').style.display = "";
		document.getElementById('singlelineType').checked = false;
		document.getElementById('fieldedType').checked = false;
		document.getElementById('searchLocationType').checked = false;
		document.getElementById('searchSICType').checked = false;
		document.getElementById('searchRouteType').checked = false;
		document.getElementById('qType').checked = false;
		document.getElementById('addrType').checked = false;
		document.getElementById('toType').checked = false;
		document.getElementById('bizDiv').style.display = "";
		
		//set up the url and options
		url += '/?';
		var category = document.getElementById('txtBizCat').value;
		var location = document.getElementById('txtBiz').value;
		var label = document.getElementById('txtBizLabel').value;
		var zoom = document.getElementById('bizZoom').value;
		var maptype = document.getElementById('bizMaptype').value;
		var layer = document.getElementById('bizLayer').value;
		var bizStatic = document.getElementById('bizStatic').value;
		var bizStaticKey = document.getElementById('bizStaticKey').value;
		var bizStaticSize = document.getElementById('bizStaticSize').value;

		//form the url
		if (category.length != 0) {
			if (url == SAMPLE_POST + '/?') {
				url += 's=name:' + category;
			}
			else {
				url += '&s=name:' + category;
			}
		}
		
		if (url.length !=0) {
			if (url == SAMPLE_POST + '/?') {
				url += 'q=' + location;
				if (label.length != 0) {
					url += ' (' + label + ')';
				}
			}
			else {
				url += '&q=' + location;
				if (label.length != 0) {
					url += ' (' + label + ')';
				}
			}
		}
		if (zoom.length != 0) {
			if (url == SAMPLE_POST + '/?') {
				url += 'zoom=' + zoom;
			}
			else {
				url += '&zoom=' + zoom;
			}
		}
		if (maptype.length != 0) {
			if (url == SAMPLE_POST + '/?') {
				url += 'maptype=' + maptype;
			}
			else {
				url += '&maptype=' + maptype;
			}
		}
		if (layer.length != 0) {
			if (url == SAMPLE_POST + '/?') {
				url += 'layer=' + layer;
			}
			else {
				url += '&layer=' + layer;
			}
		}
		if (bizStatic == 'yes'){
			var location = document.getElementById('txtBiz').value;
			location = location.split(",");
			if (location.length == 2){
				var latLong = location[0]*location[1];
			}
		
			if (isNaN(latLong) == true){
				newURL = url;
				url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getplacemap?showicon=1&type=map&key=' + bizStaticKey + '&location=' + location + '&zoom=' + zoom + '&size=' + bizStaticSize + '" border="0"></a>';
			}
			else {
				newURL = url;
				url = '<a href="' + newURL + '"><img src="http://www.mapquestapi.com/staticmap/v3/getmap?type=map&key=' + bizStaticKey + '&mcenter=' + location[0] + ',' + location[1] + '&size=' + bizStaticSize + '" border="0"></a>';
			}
		}
		document.getElementById('locationStatic').value = "no";
		document.getElementById('staticSearch').value = "no";

	} //end of biz locator section
		
	
	if (vs == 'embed') {
		url = url.replace('/?','/embed?');
		url = url.replace('/map?','/embed?');
		url = url.replace('/directions?','/embed?');
	}
	else if (vs == 'print') {
		url = url.replace('/?','/print?');
		url = url.replace('/map?','/print?');
		url = url.replace('/directions?','/print?');
	}
	
    document.getElementById('sampleUrl').innerHTML = url.replace(/</g, '&lt;').replace(/>/g, '&gt;');
	
	if (txtId && txtId != '') {
		document.getElementById(txtId).focus();
	}
};

function runSample(viewSpecifier) {
	vs = viewSpecifier;
	showBasicURL();
	if ((document.getElementById('locationStatic').value == 'yes') || (document.getElementById('routeStatic').value == 'yes' || (document.getElementById('staticSearch').value == 'yes')) || (document.getElementById('bizStatic').value == 'yes')) {
		OpenWindow=window.open("", "newwin");
		OpenWindow.document.write("<TITLE>Sample Link to MapQuest Request</TITLE>");
		OpenWindow.document.write("<BODY>");
		OpenWindow.document.write(url);
		OpenWindow.document.write("<p>(click above image for interactive map)</p>")
		OpenWindow.document.write("</BODY>");
		OpenWindow.document.write("</HTML>");

		OpenWindow.document.close()
		self.name="main"	
	}
	else {
		window.open(url);
	}
};


function showLogoUrl() {
	var logo = document.getElementById('logoSelect').value;
	
	switch (logo) {
		case "large":
			document.getElementById('logoUrl').innerHTML = "&lt;a href='" + HOST_URL + "/cdn/common/images/large-logo.png' target='_blank'&gt;&lt;img border='0' alt='large-logo.png' src='" + HOST_URL + "/cdn/common/images/large-logo.png'/&gt;&lt;/a&gt;";
			document.getElementById('logoDiv').innerHTML = "<a href='" + HOST_URL + "/cdn/common/images/large-logo.png' target='_blank'><img border='0' alt='large-logo.png' src='" + HOST_URL + "/cdn/common/images/large-logo.png'/></a>";
			break;
		case "medium":
			document.getElementById('logoUrl').innerHTML = "&lt;a href='" + HOST_URL + "/cdn/common/images/medium-logo.png' target='_blank'&gt;&lt;img border='0' alt='medium-logo.png' src='" + HOST_URL + "/cdn/common/images/medium-logo.png'/&gt;&lt;/a&gt;";
			document.getElementById('logoDiv').innerHTML = "<a href='" + HOST_URL + "/cdn/common/images/medium-logo.png' target='_blank'><img border='0' alt='medium-logo.png' src='" + HOST_URL + "/cdn/common/images/medium-logo.png'/></a>";
			break;
		case "small":
			document.getElementById('logoUrl').innerHTML = "&lt;a href='" + HOST_URL + "/cdn/common/images/small-logo.png' target='_blank'&gt;&lt;img border='0' alt='small-logo.png' src='" + HOST_URL + "/cdn/common/images/small-logo.png'/&gt;&lt;/a&gt;";
			document.getElementById('logoDiv').innerHTML = "<a href='" + HOST_URL + "/cdn/common/images/small-logo.png' target='_blank'><img border='0' alt='small-logo.png' src='" + HOST_URL + "/cdn/common/images/small-logo.png'/></a>";
			break;
		case "favicon":
			document.getElementById('logoUrl').innerHTML = "&lt;a href='" + HOST_URL + "/cdn/common/images/favicon.ico' target='_blank'&gt;&lt;img border='0' alt='favicon.ico' src='" + HOST_URL + "/cdn/common/images/favicon.ico'/&gt;&lt;/a&gt;";
			document.getElementById('logoDiv').innerHTML = "<a href='" + HOST_URL + "/cdn/common/images/favicon.ico' target='_blank'><img border='0' alt='favicon.ico' src='" + HOST_URL + "/cdn/common/images/favicon.ico'/></a>";
			break;
	}
}


var startPoint;
var endPoint;
var routePoints;
var viaPoints;

function getQDirections() {
	var script = document.createElement('script');
    script.type = 'text/javascript';
	
	var key = document.getElementById('routeStaticKey').value
	var routeStaticGeneralization = document.getElementById('routeStaticGeneralization').value;
	var getQDirectionsURL = 'http://www.mapquestapi.com/directions/v1/route?key=' + key + '&shapeFormat=cmp&generalize=' + routeStaticGeneralization;
	
	var locations = document.getElementById('txtQ').value;
	locations = locations.split("|");
	
	for (i=0;i<locations.length;i++) {
		if (i == 0) {
			getQDirectionsURL += '&from=' + locations[i];
		}
		else {
			getQDirectionsURL += '&to=' + locations[i];
		}
	}
	getQDirectionsURL += '&callback=displayResponse';
    
	script.src = getQDirectionsURL;
    document.body.appendChild(script);
}

function getAddrDirections() {
	var script = document.createElement('script');
    script.type = 'text/javascript';

	var saddr = document.getElementById('txtSaddr').value;
	var daddr = document.getElementById('txtDaddr').value;
	
	var key = document.getElementById('routeStaticKey').value
	var getAddrDirectionsURL = 'http://www.mapquestapi.com/directions/v1/route?key=' + key + '&shapeFormat=cmp&generalize=50' + '&from=' + saddr + '&to=' + daddr + '&callback=displayResponse';
    
	script.src = getAddrDirectionsURL;
    document.body.appendChild(script);
}

function getToDirections() {
	var script = document.createElement('script');
    script.type = 'text/javascript';
	
	var key = document.getElementById('routeStaticKey').value
	var getToDirectionsURL = 'http://www.mapquestapi.com/directions/v1/route?key=' + key + '&shapeFormat=cmp&generalize=50';
	
	var locations = document.getElementById('txtTo').value;
	locations = locations.split("|");
	
	//form the url
	for (i=0;i<locations.length;i++) {
		if (i==0) {
			getToDirectionsURL += '&from=' + locations[i];
		}
		else {
			getToDirectionsURL += '&to=' + locations[i];
		}
	}
	
	getToDirectionsURL += '&callback=displayResponse';
    
	script.src = getToDirectionsURL;
    document.body.appendChild(script);
}


function getSearchDirections() {
	var script = document.createElement('script');
    script.type = 'text/javascript';
	
	var key = document.getElementById('staticSearchKey').value
	var getSearchDirectionsURL = 'http://www.mapquestapi.com/directions/v1/route?key=' + key + '&shapeFormat=cmp&generalize=50';
	
	var location1 = document.getElementById('txtRouteSearch1').value;
	var location2 = document.getElementById('txtRouteSearch2').value;
	
	//form the url
	getSearchDirectionsURL += '&from=' + location1;
	getSearchDirectionsURL += '&to=' + location2;
	
	getSearchDirectionsURL += '&callback=displayResponse';
    
	script.src = getSearchDirectionsURL;
    document.body.appendChild(script);
}


function displayResponse(response) {	
	var leg = response.route.legs;
	var i = leg.length - 1;
	var mLength = response.route.legs[i].maneuvers.length;
	var j = mLength - 1;
	
	startPoint = leg[0].maneuvers[0].startPoint.lat + ',' + leg[0].maneuvers[0].startPoint.lng + ',';
	endPoint = leg[i].maneuvers[j].startPoint.lat + ',' + leg[i].maneuvers[j].startPoint.lng;
	viaPoints = '';
	
	if(i>=1){
		for(i=0; i<leg.length-1; i++) {
			var mLength2 = response.route.legs[i].maneuvers.length;
			var m = mLength2 - 1;
			if(i == 0) {
				viaPoints = 'red,'
				viaPoints += leg[i].maneuvers[m].startPoint.lat + ',' + leg[i].maneuvers[m].startPoint.lng;
			}
			else {
				viaPoints += '|red,'
				viaPoints += leg[i].maneuvers[m].startPoint.lat + ',' + leg[i].maneuvers[m].startPoint.lng;
			}	
		}
	}
	routePoints = response.route.shape.shapePoints;
}
