  function lookupCountry(countryStr,suggestionBoxFieldName,listFieldName,codeFieldName,fieldName) {
		if(countryStr.length == 0) {
			// Hide the suggestion box, set the code to blank
			$('#'+suggestionBoxFieldName).hide();
			$('#'+codeFieldName).val("");
		} else {
			/*$.post("countryautocomplete/country.php", {countryString:countryStr, suggestionBoxFieldNameString:suggestionBoxFieldName, codeFieldNameString:codeFieldName, fieldNameString:fieldName }, function(data){
				if(data.length >0) {
					$('#'+suggestionBoxFieldName).show();//field
					$('#'+listFieldName).html(data);
				}
			});*/
			$.ajax({
			url : 'http://www.code20.com/countryautocomplete/country.php',
			type : 'post',
			data :  {countryString:countryStr, suggestionBoxFieldNameString:suggestionBoxFieldName, codeFieldNameString:codeFieldName, fieldNameString:fieldName },
			dataType : 'text',
			timeout : 20000,
			tryCount : 0,
			retryLimit : 3,
			success : function(data) {
				$('#'+suggestionBoxFieldName).show();
				$('#'+listFieldName).html(data);
			},
			error : function(xhr, textStatus, errorThrown ) {
				
					this.tryCount++;
					if (this.tryCount <= this.retryLimit) {
						//try again
						$.ajax(this);
						return;
					}
					//1/25/2012: not sure what to do...just leave response to be blank (I. Ukpo)
					//alert('We have tried ' + this.retryLimit + ' times and it is still not working. We give in. Sorry.');
					/*add_remove_class('success','error',errfield);
					jQuery('#'+errfield).html("Cannot redirect to upload media page. Please try again later.");
					return;*/
					else
					{
						err_str=xhr.status+" Server internal error. Please try again.";
						add_remove_class('success','error',errfield);
						jQuery('#'+errfield).html(err_str);
					}
				
				}
		});
		}
	}
	
	function fillCountry(thisValue,thisCode,fieldName,suggestionBoxFieldName,codeFieldName) 
	{
		$('#'+fieldName).val(thisValue);
		$('#'+codeFieldName).val(thisCode);

		setTimeout(function(){ $('#'+suggestionBoxFieldName).hide(); }, 200);
	}

	

	function lookupCity(countryStr,cityStr,suggestionFieldName,suggestionListFieldName,asciiCityFieldName,fieldName,stateFieldCodeName) 
	{

		//If state not known, use city.php. Else, use city_with_region.php.
		var fieldCodeLength=document.getElementById(stateFieldCodeName).value.length;
		
		if (fieldCodeLength==0)
		{
			if(cityStr.length == 0) {
			// Hide the suggestion box, set the ASCII city to blank.
			$('#'+suggestionFieldName).hide();
			$('#'+asciiCityFieldName).val("");
			} else {
				/*$.post("countryautocomplete/city.php", {countryString:countryStr, cityString:cityStr, suggestionFieldNameString:suggestionFieldName, asciiCityFieldNameString:asciiCityFieldName, fieldNameString:fieldName, suggestionListFieldNameString:suggestionListFieldName}, function(data){
					if(data.length >0) {
						$('#'+suggestionFieldName).show();
						$('#'+suggestionListFieldName).html(data);
					}
				});*/
				$.ajax({
					url : 'http://www.code20.com/countryautocomplete/city.php',
					type : 'post',
					data :  {countryString:countryStr, cityString:cityStr, suggestionFieldNameString:suggestionFieldName, asciiCityFieldNameString:asciiCityFieldName, fieldNameString:fieldName, suggestionListFieldNameString:suggestionListFieldName },
					dataType : 'text',
					timeout : 20000,
					tryCount : 0,
					retryLimit : 3,
					success : function(data) {
						$('#'+suggestionFieldName).show();
						$('#'+suggestionListFieldName).html(data);
					},
					error : function(xhr, textStatus, errorThrown ) {
							this.tryCount++;
							if (this.tryCount <= this.retryLimit) {
								//try again
								$.ajax(this);
								return;
							}
							else
							{
								err_str=xhr.status+" Server internal error. Please try again.";
								add_remove_class('success','error',errfield);
								jQuery('#'+errfield).html(err_str);
							}
						}
				});
			}
		}

		else
		{
			if(cityStr.length == 0) {
				// Hide the suggestion box, set the ASCII city to blank.
				$('#'+suggestionFieldName).hide();
				$('#'+asciiCityFieldName).val("");
			} else {
				/*$.post("countryautocomplete/city_with_region.php", {countryString:countryStr, cityString:cityStr, suggestionFieldNameString:suggestionFieldName, asciiCityFieldNameString:asciiCityFieldName, fieldNameString:fieldName, suggestionListFieldNameString:suggestionListFieldName, stateFieldCodeNameVal:document.getElementById(stateFieldCodeName).value}, function(data){
					if(data.length >0) {
						$('#'+suggestionFieldName).show();
						$('#'+suggestionListFieldName).html(data);
					}
				});*/
				$.ajax({
					url : 'http://www.code20.com/countryautocomplete/city_with_region.php',
					type : 'post',
					data :  {countryString:countryStr, cityString:cityStr, suggestionFieldNameString:suggestionFieldName, asciiCityFieldNameString:asciiCityFieldName, fieldNameString:fieldName, suggestionListFieldNameString:suggestionListFieldName, stateFieldCodeNameVal:document.getElementById(stateFieldCodeName).value },
					dataType : 'text',
					timeout : 20000,
					tryCount : 0,
					retryLimit : 3,
					success : function(data) {
						$('#'+suggestionFieldName).show();
						$('#'+suggestionListFieldName).html(data);
					},
					error : function(xhr, textStatus, errorThrown ) {
							this.tryCount++;
							if (this.tryCount <= this.retryLimit) {
								//try again
								$.ajax(this);
								return;
							}
							//alert('We have tried ' + this.retryLimit + ' times and it is still not working. We give in. Sorry.');
							/*add_remove_class('success','error',errfield);
							jQuery('#'+errfield).html("Cannot redirect to upload media page. Please try again later.");
							return;*/
							else
							{
								err_str=xhr.status+" Server internal error. Please try again.";
								add_remove_class('success','error',errfield);
								jQuery('#'+errfield).html(err_str);
							}
						}
				});
				
			}
		}
		
	}
	
	function fillCity(thisValue,thisASCIIValue,cityFieldName,asciiCityFieldName,suggestionFieldName) {
		$('#'+cityFieldName).val(thisValue);
		$('#'+asciiCityFieldName).val(thisASCIIValue);
		setTimeout(function(){ $('#'+suggestionFieldName).hide(); }, 200);
	}

	
	
	/*9/20/2011: original implementation when it went country-city-state. Did not work because of getRegionsByCityAndCountry query (it took too long: thus choking DB). Here on out, state is informally optional: if the state is not known, it will be filled in on the backend by post processing PHP. If more than one answer, nothing will be put in.*/

	/*
	function lookupState(countryStr,cityStr,stateFieldName,stateSuggestionsFieldName,stateSuggestionsFieldListName) {
		if((cityStr.length == 0)&&(countryStr.length==0)) {
			// Hide the suggestion box.
			$('#'+stateSuggestionsFieldName).hide();
		} else {
			$.post("state.php", {countryString:countryStr, cityString:cityStr, stateFieldNameStr:stateFieldName, stateSuggestionsFieldNameStr:stateSuggestionsFieldName}, function(data){
				if(data.length >0) {
					$('#'+stateSuggestionsFieldName).show();
					$('#'+stateSuggestionsFieldListName).html(data);
				}
			});
		}
	}*/

	function lookupState(countryStr,cityStr,stateFieldName,stateSuggestionsFieldName,stateSuggestionsFieldListName,stateStrName,stateCodeFieldName) {
		if (countryStr.length==0) {
			// Hide the suggestion box, set the code to blank.
			$('#'+stateSuggestionsFieldName).hide();
			$('#'+stateCodeFieldName).val("");
		} else {
			/*$.post("countryautocomplete/state.php", {countryString:countryStr, cityString:cityStr, stateFieldNameStr:stateFieldName, stateSuggestionsFieldNameStr:stateSuggestionsFieldName,stateStrNameStr:stateStrName,stateCodeFieldNameStr:stateCodeFieldName}, function(data){
				if(data.length >0) {
					$('#'+stateSuggestionsFieldName).show();
					$('#'+stateSuggestionsFieldListName).html(data);
				}
			});*/
			$.ajax({
					url : 'http://www.code20.com/countryautocomplete/state.php',
					type : 'post',
					data :  {countryString:countryStr, cityString:cityStr, stateFieldNameStr:stateFieldName, stateSuggestionsFieldNameStr:stateSuggestionsFieldName,stateStrNameStr:stateStrName,stateCodeFieldNameStr:stateCodeFieldName },
					dataType : 'text',
					timeout : 20000,
					tryCount : 0,
					retryLimit : 3,
					success : function(data) {
						$('#'+stateSuggestionsFieldName).show();
						$('#'+stateSuggestionsFieldListName).html(data);
					},
					error : function(xhr, textStatus, errorThrown ) {
							this.tryCount++;
							if (this.tryCount <= this.retryLimit) {
								//try again
								$.ajax(this);
								return;
							}
							//alert('We have tried ' + this.retryLimit + ' times and it is still not working. We give in. Sorry.');
							/*add_remove_class('success','error',errfield);
							jQuery('#'+errfield).html("Cannot redirect to upload media page. Please try again later.");
							return;*/
							else
							{
								err_str=xhr.status+" Server internal error. Please try again.";
								add_remove_class('success','error',errfield);
								jQuery('#'+errfield).html(err_str);
							}
						
						}
				});
		}
	}
	
	function fillState(thisValue,stateFieldName,stateSuggestionFieldName,stateCodeVal,stateCodeFieldName) {
		$('#'+stateFieldName).val(thisValue);
		$('#'+stateCodeFieldName).val(stateCodeVal);
		setTimeout(function(){ $('#'+stateSuggestionFieldName).hide(); }, 200);
	}

	//Blanks field name if country name not set.
	function clearCountryCode(countryFieldName, countryCodeFieldName)
	{
		var val=$('#'+countryFieldName).val();
		var length=val.length;
		if (length==0)
		{
			$('#'+countryCodeFieldName).val("");
		}
		//alert($('#'+countryCodeFieldName).val());
	}

	//Blanks field name if state name not set.
	function clearStateCode(stateFieldName, stateCodeFieldName)
	{
		var val=$('#'+stateFieldName).val();
		var length=val.length;
		if (length==0)
		{
			$('#'+stateCodeFieldName).val("");
		}
		//alert($('#'+stateCodeFieldName).val());
	}

	//Blanks field name if city not set.
	function clearASCIICity(cityFieldName, asciiCityFieldName)
	{
		var val=$('#'+cityFieldName).val();
		var length=val.length;
		if (length==0)
		{
			$('#'+asciiCityFieldName).val("");
		}
		//alert($('#'+asciiCityFieldName).val());
	}

	//12/23/2011: Sets country code according to value of country box. 
	function setCountryCode(countryval, countrycodeval)
	{
		/*$.post("countryautocomplete/countrycode.php", {countryValue:countryval}, function(data){
				if(data.length >0) 
				{
					$('#'+countrycodeval).val(data);
				}
			});*/
			$.ajax({
					url : 'http://www.code20.com/countryautocomplete/countrycode.php',
					type : 'post',
					data :  {countryValue:countryval },
					dataType : 'text',
					timeout : 20000,
					tryCount : 0,
					retryLimit : 3,
					success : function(data) {
						$('#'+countrycodeval).val(data);
					},
					error : function(xhr, textStatus, errorThrown ) {
							this.tryCount++;
							if (this.tryCount <= this.retryLimit) {
								//try again
								$.ajax(this);
								return;
							}
							else
							{
								err_str=xhr.status+" Server internal error. Please try again.";
								add_remove_class('success','error',errfield);
								jQuery('#'+errfield).html(err_str);
							}
						
						}
				});
	}

	//12/23/2011: Sets state code according to value of country box. 
	function setStateCode(stateval, countrycodeval, statecodeval)
	{
		/*$.post("countryautocomplete/statecode.php", {stateValue:stateval, countryCodeValue:countrycodeval}, function(data){
				if(data.length >0) {
					$('#'+statecodeval).val(data);
				}
			});*/
			$.ajax({
					url : 'http://www.code20.com/countryautocomplete/statecode.php',
					type : 'post',
					data :  {stateValue:stateval, countryCodeValue:countrycodeval },
					dataType : 'text',
					timeout : 20000,
					tryCount : 0,
					retryLimit : 3,
					success : function(data) {
						$('#'+statecodeval).val(data);
					},
					error : function(xhr, textStatus, errorThrown ) {
							this.tryCount++;
							if (this.tryCount <= this.retryLimit) {
								//try again
								$.ajax(this);
								return;
							}
							else
							{
								err_str=xhr.status+" Server internal error. Please try again.";
								add_remove_class('success','error',errfield);
								jQuery('#'+errfield).html(err_str);
							}
						}
				});
	}

	function setCountryAndStateCode(countryval, countrycodeval, stateval, statecodeval)
	{
		$.post("countryautocomplete/countryandstatecode.php", {stateValue:stateval, countryValue:countryval}, function(data){
				if(data.length >0)
				{
					var rslt=data.split("-");
					//Break string into country and city parts
					$('#'+statecodeval).val(rslt[1]);
					$('#'+countrycodeval).val(rslt[0]);
				}
			});
	}

