function formTextSubmit2(inputText, inputForm){

	// regular expressions
	var invalidchars = /([^A-Z0-9\s])/gi;
	var extrawhite = /(^[\s\t]+|[\s\t]+([\s\t]|$))/g
	var uszip = /([0-9]{5})([-]*[0-9]{4})?/i;
	var canzip = /([A-Z]{1}[0-9]{1}[A-Z]{1}[\s]*[0-9]{1}[A-Z]{1}[0-9]{1})/i;
	var numbers = /([0-9])/;
	var firstletter = /(^|\b|\s|-)([a-z]{1})([a-z]*)/g;
	// initiate variables
	var searchText = "";
	var testlimit = 0;
	var stateName = "";
	var stateIndex = 0;
	var cityName = "";
	var zipCode = "";
	var uniqueId = "";
	var words = new Array();
	var msg = new Array();
	// gather form references
	var formToSubmit = document.getElementById(inputForm);
	var routeToSubmit = formToSubmit.action;
	if(formToSubmit.elements["route"]){
		routeToSubmit = formToSubmit.elements["route"].value;
	}
	// clean up input
	searchText = inputText.replace(invalidchars, "");
	searchText = searchText.replace(extrawhite, "$2");
	//$('#' + inputForm).append(inputText + " to " + searchText + " ... ");
	
	// break user input into words
	words = searchText.split(" ");
	var wordsCnt = words.length;
	//$('#' + inputForm).append(wordsCnt + " ");
	// loop through words
	for(var i = 0; i < wordsCnt; i++){
		// word has to be at least 2 chars, non-numeric, & no state yet
		if(
		   (words[i].length > 1) && 
		   (!words[i].search(numbers) >= 0) && 
		   (!stateName.length)
		){
		    // fix fuzzy search for two-word states, ie "new york"
		    if(
		            (
		                (words[i].toLowerCase() == "new") ||
		                (words[i].toLowerCase() == "south") ||
		                (words[i].toLowerCase() == "north") 
		            ) && 
		            (
		                (i+1) < wordsCnt
		            )
		       ){
		        words[i] = words[i] + " " + words[i+1];
		        wordsCnt = wordsCnt - 1;
			}
			// only test as much of name as is entered (unless 2 char abbrev)
			if(words[i].length > 2){
		        testlimit = words[i].length;
			}
			stateName = getStateName2(words[i], testlimit);
			stateIndex = i;
		}
		//$('#' + inputForm).append(i + ": " + stateName + ", ");
	} // for words.length loop
	
	// get zip codes
	if(
	    (searchText.match(uszip) !== null) ||
	    (searchText.match(canzip) !== null)
	){
	    usZipCode = searchText.match(uszip);
	    canZipCode = searchText.match(canzip);
	    if(usZipCode !== null){
		    zipCode = usZipCode[0];
		}else{
		    zipCode = canZipCode[0];
		}
		routeToSubmit = formToSubmit.action;		
		addNewInput("searchtext", zipCode, inputForm);
	}
	
	// get id
	if(formToSubmit.elements["uniqueId"]){
		uniqueId = formToSubmit.elements["uniqueId"].value;
	}
	
	// Errors
	if(routeToSubmit.match("{state}") !== null){
		if(!stateName.length){
			msg.push("Please include the name or abbreviation of a state or province in your search.");
		}
	}
	if(routeToSubmit.match("{id}") !== null){
		if(!uniqueId.length){
			msg.push("Please make a selection to continue searching.");
		}
	}
	if(msg.length){
		alert(msg);
		return false;
	}

	// Build Action
	stateName = stateName.replace(/[\s]/g, "-");
	cityName = words.slice(0, stateIndex).join("-").replace(firstletter, function(a,br1,br2,br3){return br1 + br2.toUpperCase() + br3.toLowerCase();});
	// ID
	if(routeToSubmit.match("{id}") !== null){
		routeToSubmit = routeToSubmit.replace("{id}", uniqueId);
	}
	// State
	if(routeToSubmit.match("{state}") !== null){
		routeToSubmit = routeToSubmit.replace("{state}", stateName);
	}
	// City
	if(routeToSubmit.match("{city}") !== null){
		if(cityName.length){
			routeToSubmit = routeToSubmit.replace("{city}", cityName);
		}else{
			routeToSubmit = routeToSubmit.replace("{city}/", "");
		}
	}
	// Zip
	if(routeToSubmit.match("{zip}") !== null){
	    if(zipCode.length){
		    routeToSubmit = routeToSubmit.replace("{zip}", zipCode);
		}else{
		    routeToSubmit = routeToSubmit.replace("{zip}/", "");
		}
	}
	// Page
	if(routeToSubmit.match("{pg}") !== null){
		if(pageNum.length){
			routeToSubmit = routeToSubmit.replace("{pg}", pageNum);
		}else{
			routeToSubmit = routeToSubmit.replace("Page{pg}/", "");
		}
	}
	
	// Set Action
	formToSubmit.action = routeToSubmit;
	
	// Submit Form
	formToSubmit.submit();

	return true;

} // formTextSubmit2

/* 
	Get State Name
	Test string to see if it matches a state name, state abbreviation, or partial state name
	Return the state matching state name or abbreviation or an empty string
*/
function getStateName2(srch, limit){
    var finalState = "";
	var validStates = new Array(
		"AB", "Alberta", 
		"AK", "Alaska",
		"AL", "Alabama",
		"AR", "Arkansas",
		"AZ", "Arizona",
		"BC", "British Columbia",
		"CA", "California",
		"CO", "Colorado",
		"CT", "Connecticut",
		"DC", "District of Columbia",
		"DE", "Delaware",
		"FL", "Florida",
		"GA", "Georgia",
		"HI", "Hawaii",
		"IA", "Iowa",
		"ID", "Idaho",
		"IL", "Illinois",
		"IN", "Indiana",
		"KS", "Kansas",
		"KY", "Kentucky",
		"LA", "Louisiana",
		"MA", "Massachusetts",
		"MB", "Manitoba",
		"MD", "Maryland",
		"ME", "Maine",
		"MI", "Michigan",
		"MN", "Minnesota",
		"MO", "Missouri",
		"MS", "Mississippi",
		"MT", "Montana",
		"NB", "New Brunswick",
		"NC", "North Carolina",
		"ND", "North Dakota",
		"NE", "Nebraska",
		"NF", "New Foundland",
		"NH", "New Hampshire",
		"NJ", "New Jersey",
		"NM", "New Mexico",
		"NS", "Nova Scotia",
		"NT", "Northwest Territory",
		"NU", "Nunavat",
		"NV", "Nevada",
		"NY", "New York",
		"OH", "Ohio",
		"OK", "Oklahoma",
		"ON", "Ontario",
		"OR", "Oregon",
		"PA", "Pennsylvania",
		"PE", "Prince Edward Island",
		"QC", "Quebec",
		"RI", "Rhode Island",
		"SC", "South Carolina",
		"SD", "South Dakota",
		"SK", "Saskatchewan",
		"TN", "Tennessee",
		"TX", "Texas",
		"UT", "Utah",
		"VA", "Virginia",
		"VT", "Vermont",
		"WA", "Washington",
		"WI", "Wisconsin",
		"WV", "West Virginia",
		"WY", "Wyoming",
		"YT", "Yukon"
	);
	// don't test partial matches under 3 characters
	if(limit < 3){limit = srch.length;}
	for(i = 0; i < validStates.length; i++){
	    if(srch.toLowerCase() == validStates[i].toLowerCase().substring(0,limit)){
		    if(srch.length == 2){
		        if(validStates[i+1]){
			        finalState = validStates[i+1];
			    }else{
			        finalState = "";
			    }
		    }else{
		        if(validStates[i]){
			        finalState = validStates[i];
			    }else{
			        finalState = "";
			    }
		    }
	    }
	}
	return finalState;
} // getStateName2

/*
	Add New (Hidden) Input
	Add a new hidden input tag to the specified form
*/
function addNewInput(inName, inValue, inForm){
	var newInput = document.createElement('input');
	newInput.setAttribute('type', 'hidden');
	newInput.setAttribute('name', inName);
	newInput.setAttribute('value', inValue);
	newInput.setAttribute('class', 'dynamic');
	inForm = document.getElementById(inForm);
	var oldInput = inForm.getElementsByTagName("input")[0];
	oldInput.parentNode.insertBefore(newInput, oldInput);
}
