/*
Ambiguities javascript file.
This file contains the necessary functions for displaying and resolving
Ambiguities for all types of ambiguities(orig,dest,loc...) along with the
displaying and generating of the status messages.
*/


//function used to output an ambigious address form
//takes ambiguities in the form a location collection
//and a prefix - orig or dest or "" for location
function mq_output_ambiguities(locations,prefix,template,av) {
	//output address

	if (eval(locations.count > 0) && mq_ParamExists(locations.getAt[0]) &&
		mq_ParamExists(locations.getAt[0].country) && locations.getAt[0].country.length) {
		document.write("<input type=hidden name=" + prefix + "country value=\"");
		document.write(locations.getAt[0].country);
		document.write("\" />");
	}
	var county = (locations.getAt[0]) && mq_ParamExists(locations.getAt[0].county) ? (locations.getAt[0]).county : "";
	document.write("<input type=\"hidden\" name=" + prefix + "county	 value=\"" + county + "\" />");
	mqAmbAddrRow(locations,prefix,av);
	mqAmbCityRow(locations,prefix);
	mqAmbStateZipRow(locations,prefix,template);
}//function mq_output_ambiguities(locations,prefix) {

//function used to generate hidden values necessary for form submittal to the driving directions results page from the ambiguities page
//parameter - parameters object of advantage response
//map - map object to use to display the map for the print page
//loc - the location object containing the address info to display on the print page
function mq_output_ddir_ambiguities_hidden(parameters) {
	if(!mq_ParamExists(parameters))
		return;

	if(mq_ParamExists(parameters.transaction) && parameters.transaction.length)
		document.write("<input type=\"hidden\" name=\"transaction\" value=\"" + parameters.transaction + "\">");

	if(mq_ParamExists(parameters.pheight) && parameters.pheight.length)
		document.write("<input type=\"hidden\" name=\"pheight\" value=\"" + parameters.pheight + "\">");

	if(mq_ParamExists(parameters.pwidth) && parameters.pwidth.length)
		document.write("<input type=\"hidden\" name=\"pwidth\" value=\"" + parameters.pwidth + "\">");

	if(mq_ParamExists(parameters.pheight) && parameters.sheight.length)
		document.write("<input type=\"hidden\" name=\"sheight\" value=\"" + parameters.sheight + "\">");

	if(mq_ParamExists(parameters.pwidth) && parameters.swidth.length)
		document.write("<input type=\"hidden\" name=\"swidth\" value=\"" + parameters.swidth + "\">");

	if(mq_ParamExists(parameters.latw) && parameters.latw.length)
		document.write("<input type=\"hidden\" name=\"latw\" value=\"" + parameters.latw + "\">");

}// end function mq_output_search_ambiguities_hidden(av) {

//creates an ambiguities table for origin and destination
//contains calls to mq_output_ambiguities for both origin and destination
//as well as the outputting of the status text.
function mq_output_ddir_ambiguities_table(av, code) {

	document.write('<div id="origForm_route" style="width:50%;float:left;">');

	if(code == 0 && mq_ParamExists(av.origin.status) &&	eval(av.origin.status) != 1900)
		mq_output_geo_status(av.input.origin.getAt[0],av.origin.status);
	else {
		document.write('<h2>From</h2>');
		document.write('Enter as much information as you know:');
	}
	document.write('<div class="form">');

	if(code == 0) {
		mq_output_ambiguities(av.origin,"orig","",av);
	} else {
		mq_output_ambiguities(av.input.origin,"orig","",av);
	}

	document.write('</div>');
	document.write('</div>');
	document.write('<div id="destForm_route" style="float:right;">');

	if(code == 0 && mq_ParamExists(av.destination.status) && eval(av.destination.status) != 1900)
		mq_output_geo_status(av.input.destination.getAt[0],av.destination.status);
	else {
		document.write('<h2>To</h2>');
		document.write('Enter as much information as you know:');
	}
	document.write('<div class="form">');

	if(code == 0) {
		mq_output_ambiguities(av.destination,"dest","",av);
	} else {
		mq_output_ambiguities(av.input.destination,"dest","",av);
	}
	
	document.write('</div>');
	document.write('</div>');
	if(av.template=="route") {
		document.write('<div style="clear:both;text-align:center;padding-top:1em;clear:both;width:100%;"><input type="submit" name="getDrivingDirections" value="Get Directions" class="button" /></div>');
	}

}//function mq_output_ddir_ambiguities_table(av) {

//function used to generate hidden values necessary for form submittal to the search results page from the ambiguities page
//parameter - parameters object of advantage response
function mq_output_search_ambiguities_hidden(parameters) {
	if(!mq_ParamExists(parameters))
		return;
	template=parameters.transaction;
	radius = parameters.radius;
	if(mq_ParamExists(parameters.transaction) && parameters.transaction.length)
		document.write("<input type=\"hidden\" name=\"transaction\" value=\"" + parameters.transaction + "\">");

	if(mq_ParamExists(parameters.pheight) && parameters.pheight.length)
		document.write("<input type=\"hidden\" name=\"pheight\" value=\"" + parameters.pheight + "\">");

	if(mq_ParamExists(parameters.pwidth) && parameters.pwidth.length)
		document.write("<input type=\"hidden\" name=\"pwidth\" value=\"" + parameters.pwidth + "\">");

}// end function mq_output_search_ambiguities_hidden(av) {


//function used to generate a status display table based on statuscode passed in.
function mq_output_geo_status(loc, statusCode, transaction) {
	if(!document.location.search.match('getDirections')) {
		document.write('<div class="error">');
		document.write(getGeoStatusTxt(loc,statusCode, transaction));
		document.write('</div>');
	}
} //function mq_output_geo_status(loc, statusCode) {

//function used by mq_output_ambiguities function to display the address information in a map/search
// ambiguities form
//locations - the locations collection containing the ambiguous information
function mqAmbAddrRow(locations,prefix,av) {
	document.write('<div class="row_route"><label for="origaddr">Address or Intersection:</label>');
	document.write('<br />');

	if(code==0 && locations.status >= 1100 && locations.status < 1120) {
		 document.write("<img src=\"images/icons/icon_warning_small.gif\" width=\"17\" height=\"17\">&nbsp;");
		 document.write("<input type=\"hidden\" name=\"" + prefix + "address\" value=\"" + locations.getAt[0].address + "\">");
		 document.write("<select class=\"mqFont\" name=\"" + prefix + "UnparsedAddress\" onChange=\"mq_parse_Select('" + prefix + "', this.options[this.selectedIndex].value)\">");
		 for (x=0;x<locations.count;x++) {
			var l = locations.getAt[x];
			document.write("<option value=\""+ l.city + "|" + l.stateProvince + "|" + l.county + "|" + l.latitude + "|" + l.longitude + "|" + l.postalCode + "|" + l.address + "\" >");
			document.write(l.address);
		 }
		 document.write("</select>");
		} else {
		 if(code==0 && (locations.status == 1000 || locations.status == 1010 || locations.status == 1011)) {
			document.write("<td	class=\"mqTd\"><img src=\"images/icons/icon_warning_small.gif\" width=\"17\" height=\"17\">&nbsp;");
		 }
		 document.write("<input class=\"mqInput\" type=\"text\" name=\"" + prefix + "address\" size=\"30\" maxlength=\"80\" value=\"");
		 if (eval(locations.count > 0) && mq_ParamExists(locations.getAt[0]) && locations.getAt[0].address)
			document.write(locations.getAt[0].address);
		 else
			if (mq_ParamExists(av.parameters) && locations.status != 1020 && locations.status != 1022 && locations.status != 1030 && locations.status != 1031) {
				if(eval("av.parameters."+prefix+"address"))
					document.write(eval("av.parameters."+prefix+"address"));
			}
		 document.write("\" >");
	}
	document.write('</div>');
}//function mqAmbAddrRow(locations,prefix) {


//function used by mq_output_ambiguities function to display the city information in a map/search
// ambiguities form
//locations - the locations collection containing the ambiguous information
function mqAmbCityRow(locations,prefix) {
	document.write('<div class="row_routeCity"><label for="origcity">City or Town:</label>');
	document.write('<br />');
	if(code ==0 & locations.status >= 1130 && locations.status < 1140) {
		document.write("<img src=\"images/icons/icon_warning_small.gif\" width=\"17\" height=\"17\">&nbsp;");
		var city = (locations.getAt[0]) && mq_ParamExists(locations.getAt[0].city)? (locations.getAt[0]).city : "";
		document.write("<input type=\"hidden\" name=\"" + prefix + "city\" value=\"" + city + "\">");
		document.write("<select class=\"mqFont\" name=\"" + prefix + "UnparsedCity\" style=\"width:244\" onChange=\"mq_parse_Select('" + prefix + "', this.options[this.selectedIndex].value)\">");
		for (x=0;x<locations.count;x++) {
			//output the option value section, use city,county,state as value then parse
			l = locations.getAt[x];
			document.write("<option value=\""+ l.city + "|" + l.stateProvince + "|" + l.county + "|" + l.latitude + "|" + l.longitude	+ "\" >");
			document.write(l.city);
			if(l.county && l.county.length)
				document.write(", (" + l.county + ")");
			if(l.stateProvince && l.stateProvince.length)
				document.write(", " + l.stateProvince);
		}
		document.write("</select>");
	} else {
	 document.write("<input class=\"mqInput\" type=\"text\" name=\"" + prefix + "city\" size=\"30\" maxlength=\"50\" value=\"");
	 if (eval(locations.count > 0) && mq_ParamExists(locations.getAt[0]) && locations.getAt[0].city)
		document.write(locations.getAt[0].city);
	 document.write("\" >");
	}
	document.write('</div>');
}//function mqAmbCityRow(locations,prefix)

//function used by mq_output_ambiguities function to display the state zip information
// ambiguities form
//locations - the locations collection containing the ambiguous information
function mqAmbStateZipRow(locations,prefix,template) {
	document.write('<div class="row_routeCity">');
	if(code == 0 && locations.status >= 1130 && locations.status < 1140) {
		document.write('<label for="origzip">ZIP Code:</label>');
	} else {
		document.write('<label for="origstate">State:</label> &nbsp; <label for="origzip">ZIP Code:</label>');
	}
	document.write('<br />');

//this section outputs the state zipcode text boxes or select boxes
//based on the status code.

		 //ambiguous state
	if(code == 0 && locations.status >= 1140 && locations.status < 1150) {
		document.write("<img src=\"images/icons/icon_warning_small.gif\" width=\"17\" height=\"17\">&nbsp;");
		document.write("<select class=\"mqFont\" style=\"width:60\" name=\"" + prefix + "stateProvince\">");
		for (x=0;x<locations.count;x++) {
		 document.write("<option value=\""+ locations.getAt[x].stateProvince + "\" >");
		 document.write(locations.getAt[x].stateProvince);
		}
		document.write("</select>");
		document.write("<input class=\"mqInput\" type=\"text\" name=\"" + prefix + "postalCode\" size=\"15\" maxlength=\"10\" value=\"");
		if (locations.getAt[0].postalCode)
		document.write(locations.getAt[0].postalCode);
		document.write("\" >");

		//ambiguous address of some kind or invalid state
	} else if(code == 0 && ((locations.status >= 1100 && locations.status < 1120) ||
		locations.status == 1902 || locations.status == 1903)) {
		document.write("<input class=\"mqInput\" type=\"text\" name=\"" + prefix + "stateProvince\" size=\"4\" maxlength=\"2\" value=\"");
		if (eval(locations.count > 0) && mq_ParamExists(locations.getAt[0]) && locations.getAt[0].stateProvince)
		 document.write(locations.getAt[0].stateProvince);
		document.write("\" >");
		document.write("<input class=\"mqInput\" type=\"text\" name=\"" + prefix + "postalCode\" size=\"15\" maxlength=\"10\" value=\"");
		if (eval(locations.count > 0) && mq_ParamExists(locations.getAt[0]) && locations.getAt[0].postalCode)
		 document.write(locations.getAt[0].postalCode);
		document.write("\" >");
		//ambiguous zipcode
		} else if(locations.status >= 1120 && locations.status < 1130) {
		 document.write("<input class=\"mqInput\" type=\"text\" name=\"" + prefix + "stateProvince\" size=\"4\" maxlength=\"2\" value=\"");
		 if (locations.getAt[0].stateProvince)
			document.write(locations.getAt[0].stateProvince);
		 document.write("\" >");
		 document.write("<img src=\"images/icons/icon_warning_small.gif\" width=\"17\" height=\"17\">&nbsp;");
		 document.write("<select class=\"mqFont\" name=\"" + prefix + "postalCode\" style=\"width:120px;\">");
		 for (x=0;x<locations.count;x++) {
			document.write("<option value=\""+ locations.getAt[x].postalCode + "\" >");
			document.write(locations.getAt[x].postalCode);
		 }
		 document.write("</select>");
		 //else
			}
		else if(code==0 && (locations.status == 1050 || locations.status == 1010) || (locations.status == 1000) || (locations.status == 1030) || (locations.status == 1020) || (locations.status==1040)|| (locations.status==1022) || (locations.status==1041)) {
			var state = (locations.getAt[0]) && mq_ParamExists(locations.getAt[0].stateProvince)? (locations.getAt[0]).stateProvince : "";
		 // this is where the change has been made for the state text box
			document.write("<input class=\"mqInput\" style=\"margin-right:4px\"type=\"text\" size=\"4\" name=\"" + prefix + "stateProvince\" maxlength=\"2\" value=\"" + state + "\">");
			document.write("<input class=\"mqInput\" type=\"text\" name=\"" + prefix + "postalCode\" size=\"15\" maxlength=\"10\" value=\"");
		 if (locations.getAt[0].postalCode)
			document.write(locations.getAt[0].postalCode);
		 document.write("\" >");
	} else {
		var state = (locations.getAt[0]) && mq_ParamExists(locations.getAt[0].stateProvince)? (locations.getAt[0]).stateProvince : "";
		if(code ==0 && locations.status != 1900) {
		 document.write("<input class=\"mqInput\" type=\"hidden\" name=\"" + prefix + "stateProvince\" maxlength=\"2\" value=\"" + state + "\">");
		}
		else {
			// this is where the change has been made for the state text box
			document.write("<input class=\"mqInput\" type=\"text\" size=\"4\" name=\"" + prefix + "stateProvince\" maxlength=\"2\" value=\"" + state + "\">");
		}
		document.write("<input class=\"mqInput\" type=\"text\" name=\"" + prefix + "postalCode\" size=\"15\" maxlength=\"10\" value=\"");
		if (locations.getAt[0].postalCode)
			document.write(locations.getAt[0].postalCode);
		document.write("\" >");
	}
	document.write('</div>');
}//function mqAmbStateZipRow(locations,prefix) {

//function used to set the ambiguities form values if an ambiguous city was parsed
function mq_parse_citySelect ()	{

	if(typeof(document.ambiguities.unparsedorigCity) != "undefined") {
		var tokens = document.ambiguities.unparsedorigCity.value.split(",");
		document.ambiguities.origcity.value = tokens[0];
		document.ambiguities.origcounty.value = tokens[1];
		document.ambiguities.origstateProvince.value = tokens[2];
	}

	if(typeof(document.ambiguities.unparseddestCity) != "undefined") {
		var tokens = document.ambiguities.unparseddestCity.value.split(",");
		document.ambiguities.destcity.value = tokens[0];
		document.ambiguities.destcounty.value = tokens[1];
		document.ambiguities.deststateProvince.value = tokens[2];
	}

	return true;
}//function mq_parse_citySelect ()
function mq_parse_Select (pre, value)	{
	if(value) {
		var valText = value.split("|");
		if(valText[0]) eval("document.ambiguities." + pre + "city").value			= valText[0];
		if(valText[1]) eval("document.ambiguities." + pre + "stateProvince").value = valText[1];
		if(valText[2]) eval("document.ambiguities." + pre + "county").value		= valText[2];
		//if(valText[3]) eval("document.ambiguities." + pre + "latitude").value	= valText[3];
		//if(valText[4]) eval("document.ambiguities." + pre + "longitude").value	= valText[4];
		if(valText[5]) eval("document.ambiguities." + pre + "postalCode").value	= valText[5];
		if(valText[6]) eval("document.ambiguities." + pre + "address").value		= valText[6];
	}

}


function mq_route_geocode_check() {

	mq_geocode_check("orig");
	mq_geocode_check("dest");

}

function mq_geocode_check (pre)	{

	var ambig = "document.ambiguities." + pre;
	var city;
	var stateProvince;
	var postalCode;
	var lat;
	var lng;


	if(eval("document.ambiguities." + pre + "latitude") != undefined) {
		document.ambiguities.removeChild(eval("document.ambiguities." + pre + "latitude"));
	}
	if(eval("document.ambiguities." + pre + "longitude") != undefined) {
		document.ambiguities.removeChild(eval("document.ambiguities." + pre + "longitude"));
	}

	if(eval(ambig + "UnparsedAddress") != undefined) {
		var dirtyFlag = false;
		var valText = (eval(ambig + "UnparsedAddress").value).split("|");
		if(valText[0]) city = valText[0];
		if(valText[1]) stateProvince = valText[1];
		if(valText[3]) lat = valText[3];
		if(valText[4]) lng = valText[4];
		if(valText[5]) postalCode = valText[5];
		if((eval(ambig + "city").value != city) || (eval(ambig + "stateProvince").value != stateProvince)
			|| (eval(ambig + "postalCode").value != postalCode)) {
		 dirtyFlag = true;
		}
		if(!dirtyFlag) {
			if(lat) createHiddenInput (document.ambiguities, pre + 'latitude', pre + 'latitude', lat);
			if(lng) createHiddenInput (document.ambiguities, pre + 'longitude', pre + 'longitude', lng);
		}

	}

	if(eval(ambig + "UnparsedCity") != undefined) {
		var dirtyFlag = false;
		var valText = (eval(ambig + "UnparsedCity").value).split("|");
		if(valText[3]) lat = valText[3];
		if(valText[4]) lng = valText[4];
		if((eval(ambig + "address").value != "") || (eval(ambig + "postalCode").value != "")) {
		 dirtyFlag = true;
		}
		if(!dirtyFlag) {
			if(lat) createHiddenInput (document.ambiguities, pre + 'latitude', pre + 'latitude', lat);
			if(lng) createHiddenInput (document.ambiguities, pre + 'longitude', pre + 'longitude', lng);
		}
	}

}


//function used to return the status text for a given status number
function getGeoStatusTxt(loc, statusCode, transaction) {
	var strStatus = "Cannot find";

	//geocoding return codes
	//non exact single match
	if (eval(statusCode) >= 1000 && eval(statusCode) < 1200) {

		if(mq_ParamExists(loc.address) && loc.address.length)
		{
		 strStatus += " ";
		 strStatus += loc.address;
		 strStatus += ",";
		}

		if(mq_ParamExists(loc.city) && loc.city.length)
		{
		 strStatus += " ";
		 strStatus += loc.city;
		 strStatus += ",";
		}

		if(mq_ParamExists(loc.stateProvince) && loc.stateProvince.length)
		{
		 strStatus += " ";
		 strStatus += loc.stateProvince;
		}

		if(mq_ParamExists(loc.postalCode) && loc.postalCode.length)
		{
		 strStatus += " ";
		 strStatus += loc.postalCode;
		}

		strStatus += ". ";
	}



	//single string return codes
	switch (eval(statusCode))
	{
		case 200 :
				return "Client is not enabled to receive maps.	Please contact customer support.";
				break;


		case 201 :
				return "Client is not enabled to receive search results.	Please contact customer support.";
				break;

		case 202 :
				 return "Client is not enabled to receive search results from specified table.	Please contact customer support.";
				 break;

		case 203 :
				 return "Client is not enabled to receive route results.	Please contact customer support.";
				 break;

		case 250 :
				 return "Client ID required.";
				 break;

		case 251 :
				 return "Invalid or Missing Client ID";
				 break;

		case 252 :
				 return "Client ID expired";
				 break;

		case 253 :
				 return "Unauthorized";
				 break;

		case 254 :
				 return "Invalid Password ";
				 break;

		case 400 :
				 return "Transaction Required ";
				 break;

		case 500 :
				 return "Server Error";
				 break;
		case 900 :
				 return " Invalid Latitude";
				 break;
		case 901 :
				 return "Invalid Longitude ";
				 break;
		case 902 :
				 return " Error Parsing Input Parameters";
				 break;


		case 903 :
				 return "Invalid Param Name.	Params can only contains numbers, letters, and underscores and cannot begin with a number.";
				 break;

		//No Location Matches
		case 1901 :
		 return "Cannot identify this location.	Please provide additional information or modify the information your entered.";
		 break;
		//Invalid State
		case 1902 :
		 switch(temp)
		 {
			case "map" :
				return "Invalid state abbreviation.	Please enter a valid state abbreviation and click the \"Get Map\" button.";
				break;
			case "search" :
				return "Invalid state abbreviation.	Please enter a valid state abbreviation and click the \"Find Locations\" button.";
				break;
			case "route" :
				return "Invalid state abbreviation.	Please enter a valid state abbreviation and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				return "Invalid state abbreviation.	Please enter a valid state abbreviation and click the \"Find Locations\" button.";
				break;
		 }
		//Invalid Country Code
		case 1903 :
		 return "Mapping is unavailable for the country specified.";
		 break;
		//Invalid Inputs
		case 9000 :
		 return "Cannot identify this location without additional information.	Please enter at least a city and state or postal code.";
		 break;
		//Single Non-Exact Address Match
		case 1000 :
		 switch(temp)
		 {
			case "map" :
				strStatus+="Found a similar address.	Click the \"Get Map\" button to map this address, or modify the information you entered.";
				break;
			case "search" :
				strStatus+="Found a similar address.	Click the \"Find Locations\" button to map this address, or modify the information you entered.";
				break;
			case "route" :
				strStatus+="Found a similar address.	Click the \"GET DIRECTIONS\" button to map this address, or modify the information you entered.";
				break;
			case "route_search" :
				strStatus+="Found a similar address.	Click the \"Find Locations\" button to map this address, or modify the information you entered.";
				break;
		 }

		 return strStatus;
		 break;
		//Multiple Non-Exact Address Matches
		case 1100 :
		 switch(temp)
		 {
			case "map" :
				strStatus+="Found similar addresses.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				strStatus+="Found similar addresses.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				strStatus+="Found similar addresses.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				strStatus+="Found similar addresses.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 return strStatus;
		 break;
		//Single Non-Exact Street Block Match
		case 1010 :
		 switch(temp)
		 {
			case "map" :
				strStatus+="Found a similar address.	Click the \"Get Map\" button to map this address, or modify the information you entered.";
				break;
			case "search" :
				strStatus+="Found a similar address.	Click the \"Find Locations\" button to map this address, or modify the information you entered.";
				break;
			case "route" :
				strStatus+="Found a similar address.	Click the \"GET DIRECTIONS\" button to map this address, or modify the information you entered.";
				break;
			case "route_search" :
				strStatus+="Found a similar address.	Click the \"Find Locations\" button to map this address, or modify the information you entered.";
				break;
		 }

		 return strStatus;
		 break;
		//Multiple Non-Exact Street Block Matches
		case 1110 :
		 switch(temp)
		 {
			case "map" :
				strStatus+="Found similar addresses.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				strStatus+="Found similar addresses.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				strStatus+="Found similar addresses.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				strStatus+="Found similar addresses.	Please select one and click the \"Find Locations\" button.";
				break;
		 }

		 return strStatus;
		 break;
		//Single Exact Street Block Match
		case 1011 :
		switch(temp)
		 {
			case "map" :
				strStatus+="Found a similar address.	Click the \"Get Map\" button to map this address, or modify the information you entered.";
				break;
			case "search" :
				strStatus+="Found a similar address.	Click the \"Find Locations\" button to map this address, or modify the information you entered.";
				break;
			case "route" :
				strStatus+="Found a similar address.	Click the \"GET DIRECTIONS\" button to map this address, or modify the information you entered.";
				break;
			case "route_search" :
				strStatus+="Found a similar address.	Click the \"Find Locations\" button to map this address, or modify the information you entered.";
				break;
		 }

		 return strStatus;
		 break;
		//Multiple Exact Street Block Matches
		case 1111 :
		 switch(temp)
		 {
			case "map" :
				strStatus+="Found similar addresses.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				strStatus+="Found similar addresses.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				strStatus+="Found similar addresses.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				strStatus+="Found similar addresses.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 return strStatus;
		 break;
		//Single Zip+4 Fallback from Address
		case 1020 :
		 switch(temp)
		 {
			case "map" :
				strStatus+="Click the \"Get Map\" button to map the ZIP+4 code, or modify the information you entered.";
				break;
			case "search" :
				strStatus+="Click the \"Find Locations\" button to map the ZIP+4 code, or modify the information you entered.";
				break;
			case "route" :
				strStatus+="Click the \"GET DIRECTIONS\" button to map the ZIP+4 code, or modify the information you entered.";
				break;
			case "route_search" :
				strStatus+="Click the \"Find Locations\" button to map the ZIP+4 code, or modify the information you entered.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple Zip+4 Fallback from Address

		 case 1050 :
				strStatus="Cannot find";
				if(mq_ParamExists(loc.postalCode) && loc.postalCode.length)
				{
				 strStatus += " ";
				 strStatus += loc.postalCode;
				}
				 strStatus+=". Please enter a valid Postal Code or City, State combination.";
				 return strStatus;
		 break;
		//Multiple Zip+4 Fallback from Address

		case 1120 :
		 switch(temp)
		 {
			case "map" :
				strStatus+="Found multiple ZIP+4 codes.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				strStatus+="Found multiple ZIP+4 codes.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				strStatus+="Found multiple ZIP+4 codes.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				strStatus+="Found multiple ZIP+4 codes.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 return strStatus;
		 break;
		//Single Zip+2 Fallback from Address
		case 1021 :
			switch(temp)
			{
			 case "map" :
				strStatus+="Click the \"Get Map\" button to map the ZIP+2 code, or modify the information you entered.";
				break;
			 case "search" :
				 strStatus+="Click the \"Find Locations\" button to map the ZIP+2 code, or modify the information you entered.";
				 break;
			 case "route" :
				 strStatus+="Click the \"GET DIRECTIONS\" button to map the ZIP+2 code, or modify the information you entered.";
				 break;
			 case "route_search" :
				strStatus+="Click the \"Find Locations\" button to map the ZIP+2 code, or modify the information you entered.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple Zip+2 Fallback from Address
		case 1121 :
			switch(temp)
			{
			 case "map" :
				strStatus+="Found multiple ZIP+2 codes.	Please select one and click the \"Get Map\" button."
				break;
			 case "search" :
				 strStatus+="Found multiple ZIP+2 codes.	Please select one and click the \"Find Locations\" button."
				 break;
			 case "route" :
				 strStatus+="Found multiple ZIP+2 codes.	Please select one and click the \"GET DIRECTIONS\" button."
				 break;
			 case "route_search" :
				strStatus+="Found multiple ZIP+2 codes.	Please select one and click the \"Find Locations\" button."
				break;
		 }
		 return strStatus;
		 break;
		//Single Zip Fallback from Address
		case 1022 :
		 switch(temp)
			{
			 case "map" :
				strStatus+="Click the \"Get Map\" button to map the ZIP code, or modify the information you entered.";
				break;
			 case "search" :
				 strStatus+="Click the \"Find Locations\" button to map the ZIP code, or modify the information you entered.";
				 break;
			 case "route" :
				 strStatus+="Click the \"GET DIRECTIONS\" button to map the ZIP code, or modify the information you entered.";
				 break;
			 case "route_search" :
				strStatus+="Click the \"Find Locations\" button to map the ZIP code, or modify the information you entered.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple Zip Fallback from Address
		case 1122 :
			switch(temp)
			{
			 case "map" :
				strStatus+="Found multiple ZIP codes.	Please select one and click the \"Get Map\" button.";
				break;
			 case "search" :
				 strStatus+="Found multiple ZIP codes.	Please select one and click the \"Find Locations\" button.";
				 break;
			 case "route" :
				 strStatus+="Found multiple ZIP codes.	Please select one and click the \"GET DIRECTIONS\" button.";
				 break;
			 case "route_search" :
				strStatus+="Found multiple ZIP codes.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple Zips US
		case 1123 :
		switch(temp)
		{
			 case "map" :
				strStatus+="Found multiple ZIP codes.	Please select one and click the \"Get Map\" button.";
				break;
			 case "search" :
				 strStatus+="Found multiple ZIP codes.	Please select one and click the \"Find Locations\" button.";
				 break;
			 case "route" :
				 strStatus+="Found multiple ZIP codes.	Please select one and click the \"GET DIRECTIONS\" button.";
				 break;
			 case "route_search" :
				strStatus+="Found multiple ZIP codes.	Please select one and click the \"Find Locations\" button.";
				break;
		 }

		 return strStatus;

		 break;
		//Single Fallback from Address to City
		case 1030 :
		switch(temp)
		{
			 case "map" :
				strStatus+="Click the \"Get Map\" button to map the city, or modify the information you entered.";
				break;
			 case "search" :
				 strStatus+="Click the \"Find Locations\" button to map the city, or modify the information you entered.";
				 break;
			 case "route" :
				 strStatus+="Click the \"GET DIRECTIONS\" button to map the city, or modify the information you entered.";
				 break;
			 case "route_search" :
				strStatus+="Click the \"Find Locations\" button to map the city, or modify the information you entered.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple Fallback from Address to City
		case 1130 :
		switch(temp)
		 {
			case "map" :
				return strStatus + "Found multiple cities.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				return strStatus + "Found multiple cities.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				return strStatus + "Found multiple cities.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				return strStatus + "Found multiple cities.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 break;
		//Single Fallback from Zip to City
		case 1031 :
		 strStatus="Cannot find";
		 if(mq_ParamExists(loc.postalCode) && loc.postalCode.length)
		 {
			strStatus += " ";
			strStatus += loc.postalCode;
		 }
		 switch(temp)
		 {
			case "map" :
				strStatus+= ".	Click the \"Get Map\" button to map the city, or modify the information you entered.";
				break;
			case "search" :
				strStatus+= ".	Click the \"Find Locations\" button to map the city, or modify the information you entered.";
				break;
			case "route" :
				strStatus+= ".	Click the \"GET DIRECTIONS\" button to map the city, or modify the information you entered.";
				break;
			case "route_search" :
				strStatus+= ".	Click the \"Find Locations\" button to map the city, or modify the information you entered.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple Fallback from Zip to City
		case 1131 :
		 strStatus="Cannot find";
		 if(mq_ParamExists(loc.postalCode) && loc.postalCode.length)
		 {
			strStatus += " ";
			strStatus += loc.postalCode;
		 }
		 switch(temp)
		 {
			case "map" :
				strStatus+="Found multiple cities.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				strStatus+="Found multiple cities.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				strStatus+="Found multiple cities.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				strStatus+="Found multiple cities.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple City Match No Fallback
		case 1132 :
		 switch(temp)
		 {
			case "map" :
				return "Found multiple cities.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				return "Found multiple cities.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				return "Found multiple cities.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				return "Found multiple cities.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 break;

		//Single Fallback from Address to State
		case 1040 :

			switch(temp)
		 {
			case "map" :
				strStatus+="Click the \"Get Map\" button to map the state, or modify the information you entered.";
				break;
			case "search" :
				strStatus+="Click the \"Find Locations\" button to map the state, or modify the information you entered.";
				break;
			case "route" :
				strStatus+="Click the \"GET DIRECTIONS\" button to map the state, or modify the information you entered.";
				break;
			case "route_search" :
				strStatus+="Click the \"Find Locations\" button to map the state, or modify the information you entered.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple Fallback from Address to State
		case 1140 :

		 switch(temp)
		 {
			case "map" :
				strStatus+="Found multiple states.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				strStatus+="Found multiple states.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				strStatus+="Found multiple states.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				strStatus+="Found multiple states.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 return strStatus;

		 break;
		//Single Fallback from Zip to State
		case 1041 :
		 strStatus="Cannot find";
		 if(mq_ParamExists(loc.postalCode) && loc.postalCode.length)
		 {
			strStatus += " ";
			strStatus += loc.postalCode;
		 }
		 switch(temp)
		 {
			case "map" :
				strStatus+=".	Click the \"Get Map\" button to map the state, or modify the information you entered.";
				break;
			case "search" :
				strStatus+=".	Click the \"Find Locations\" button to map the state, or modify the information you entered.";
				break;
			case "route" :
				strStatus+=".	Click the \"GET DIRECTIONS\" button to map the state, or modify the information you entered.";
				break;
			case "route_search" :
				strStatus+=".	Click the \"Find Locations\" button to map the state, or modify the information you entered.";
				break;
		 }
		 return strStatus;
		 break;
		//Multiple Fallback from Zip to State
		case 1141 :
		 strStatus="Cannot find";
		 if(mq_ParamExists(loc.postalCode) && loc.postalCode.length)
		 {
			strStatus += " ";
			strStatus += loc.postalCode;
		 }
		 switch(temp)
		 {
			case "map" :
				strStatus+=".	Click the \"Get Map\" button to map the state, or modify the information you entered.";
				break;
			case "search" :
				strStatus+=".	Click the \"Find Locations\" button to map the state, or modify the information you entered.";
				break;
			case "route" :
				strStatus+=".	Click the \"GET DIRECTIONS\" button to map the state, or modify the information you entered.";
				break;
			case "route_search" :
				strStatus+=".	Click the \"Find Locations\" button to map the state, or modify the information you entered.";
				break;
		 }
		 strStatus+=".	Found multiple states.	Please select one and click the \"Get Map\" button.";
		 return strStatus;
		 break;
		//Multiple State Match No Fallback
		case 1142 :
		 switch(temp)
		 {
			case "map" :
				return "Found multiple states.	Please select one and click the \"Get Map\" button.";
				break;
			case "search" :
				return "Found multiple states.	Please select one and click the \"Find Locations\" button.";
				break;
			case "route" :
				return "Found multiple states.	Please select one and click the \"GET DIRECTIONS\" button.";
				break;
			case "route_search" :
				return "Found multiple states.	Please select one and click the \"Find Locations\" button.";
				break;
		 }
		 return strStatus;
		 break;

		case 9001 :
		 if(typeof(transaction) != 'undefined' && transaction=="route")
			strStatus="We are unable to calculate driving directions at this time.	Please try again shortly";
		 else
			strStatus="We are unable to generate a map at this time.	Please try again shortly.";
		 return strStatus;

		case 9002 :
			strStatus="No locations were found within the specified radius ";
			if(mq_ParamExists(loc.radius)) strStatus += loc.radius + ".00 mi.";
			strStatus +=" Please expand your search."
			return strStatus;

		case 9003 :
			strStatus="No locations were found within "
			if(mq_ParamExists(loc.latwWidth)) strStatus += loc.latwWidth + ".00 mi.";
			if(mq_ParamExists(loc.radius)) strStatus += loc.radius + ".00 mi.";
			strStatus += " Please expand your search or modify your search criteria.";
			return strStatus;



	}

	return "An Unknown error occurred";
}//function getGeoStatusTxt(loc, statusCode) {
function mq_output_ddir_ambiguities_additional(parameters){
	var checked1="";
	var checked2="";
	var checked3="";
	var latwWidth1 ="";
	var latwWidth2 = "";
	var latwWidth5 = "";
	var latwWidth10 = "";
	if(mq_ParamExists(parameters))
	{
	 if(parameters.search1=="1")
		checked1 = "checked";
	 if(parameters.search2=="1")
		checked2 = "checked";
	 if(parameters.search3=="1")
		checked3= "checked";
	 if(parameters.latwWidth=="1")
		latwWidth1="selected";
	 if(parameters.latwWidth=="2")
		latwWidth2="selected";
	 if(parameters.latwWidth=="5")
		latwWidth5="selected";
	 if(parameters.latwWidth=="10")
		latwWidth10="selected";
	}
	document.write("<td style=\"width: 350px;\" class=\"mqBar\"> Options </td>");
	document.write("<span class=\"mqEmp\"> Additional Information: </span>");
	document.write("<br /> Specify additional information to narrow your search: <br />");
	document.write("<input class=\"mqInput\" value=\"AND\" name=\"searchQuantifier\" type=\"hidden\">");
	document.write("<input class=\"mqInput\" name=\"search1\" value=\"1\" type=\"checkbox\" "+checked1+"> Choice 1&nbsp;&nbsp;");
	document.write("<input class=\"mqInput\" name=\"search2\" value=\"1\" type=\"checkbox\" "+checked2+"> Choice 2&nbsp;&nbsp;");
	document.write("<input class=\"mqInput\" name=\"search3\" value=\"1\" type=\"checkbox\" "+checked3+"> Choice 3 </td></tr>");
	document.write("<select class=\"mqSelect\" style=\"width:45px;\" name=\"latwWidth\" "+latwWidth1+"> <option value=\"1\"> 1 </option>");
	document.write("<option value=\"2\" "+latwWidth2+"> 2 </option> <option value=\"5\" "+latwWidth5+"> 5 </option>");
	document.write("<option value=\"10\" "+latwWidth10+"> 10 </option> </select> miles of my route. </td></tr>");
	document.write("<input class=\"mqInput\" src=\"images/findlocation.gif\" height=\"21\" type=\"image\" width=\"113\">");
}
function mq_output_search_ambiguities_additional(parameters)
{

	var checked1="";
	var checked2="";
	var checked3="";
	var radius = parameters.radius;
	if(mq_ParamExists(parameters))
	{
		if(parameters.search1=="1")
		 checked1 = "checked";
		if(parameters.search2=="1")
		 checked2 = "checked";
		if(parameters.search3=="1")
		 checked3= "checked";

	}
	document.write("<table class=\"mqTable\" width=\"100%\">");
	document.write("<tr>");
	document.write("<td height=\"30px\" style=\"padding-left:24px;\">");
	document.write("Show locations within: ");
	document.write("<select name=radius class=\"mqSelectopt\">");
	if(radius=="5")
		document.write("<option value=5 selected >5 miles&nbsp;</option>");
	else
		document.write("<option value=5 >5 miles&nbsp;</option>");

	if(radius=="10")
		document.write("<option value=10 selected>10 miles&nbsp;</option>");
	else
		document.write("<option value=10>10 miles&nbsp;</option>");

	if(radius=="15")
		document.write("<option value=15 selected>15 miles&nbsp;</option>");
	else
		document.write("<option value=15>15 miles&nbsp;</option>");

	if(radius=="20")
		document.write("<option value=20 selected>20 miles&nbsp;</option>");
	else
		document.write("<option value=20>20 miles&nbsp;</option>");

	document.write("</select>");
	document.write("</td>");
	document.write("</tr>");

	document.write("<tr>");
	document.write("<td class=\"mqTd\">");
	document.write("<hr style=\"width:80%\" class=\"mqHr\" >");
	document.write("</td>");
	document.write("</tr>");

	document.write("<tr>");
	document.write("<td height=\"20px\"> ");
	document.write("<span class=\"mqEmp\">");
	document.write("Additional Information");
	document.write("</span>");
	document.write("</td>");
	document.write("</tr>");

	document.write("<tr>");
   document.write("<td class=\"mqTd\">")
   document.write("Specify additional information to narrow your search: ");
   document.write("<input type=checkbox name=search1 value=1 "+checked1+">  Choice1&nbsp;&nbsp; ");
   document.write("<input type=checkbox name=search2 value=1 "+checked2+">  Choice2&nbsp;&nbsp; ");
   document.write("<input type=checkbox name=search3 value=1 "+checked3+">  Choice3&nbsp;&nbsp; ");
   document.write("</td>");
   document.write("</tr>")

   document.write("<tr>");
   document.write("<td height=\"40px\">");
   document.write("<hr style=\"width:80%\" class=\"mqHr\" >");
   document.write("</td>");
   document.write("</tr>");
   document.write("</table>");


}

function createHiddenInput (form, id, name, value) {
    var input;
    input = document.createElement ('input');
    input.type  = 'hidden';
    input.name  = name;
    if (id != '') {
        input.id    = id;
    }
    if (value != '') {
        input.value = value;
    }
    form.appendChild (input);
}
