// http://en.wikipedia.org/wiki/ISO_3166-1 // NEXT: MAKE SURE DATA IS FROM ISO 3166-1 not just 3166 // NEXT: Consolidate the data in uZipsAndStates and uZipsAndStates2 // NEXT: lat,long to zipcode via haversine formulla, miles between two latitudes. miles between two zips etc. function countryFrom3Digits p3DigitCode if not(p3DigitCode is a number) then return "ERROR: The parameter must be a 3 Digit Number" if not(the number of chars in p3DigitCode is 3) then return "ERROR: The parameter must be a 3 Digit Number" put "NOT FOUND" into tCountry set the itemdel to comma put the uCountryCodes of this stack into tCountries filter tCountries with ("*" & p3DigitCode) if the number of lines in tCountries is 1 then put item 1 of tCountries into tCountry \ else put "ERROR: Country Not Found" into tCountry return tCountry end countryFrom3Digits function countryFrom2Letters p2Letters if (p2Letters is a number) then return "ERROR: The parameter must be a 2 Letters" if not(the number of chars in p2Letters is 2) then return "ERROR: The parameter must be a 2 Letters" put "NOT FOUND" into tCountry set the itemdel to comma put the uCountryCodes of this stack into tCountries filter tCountries with ("*," & p2Letters & ",*") if the number of lines in tCountries is 1 then put item 1 of tCountries into tCountry \ else put "ERROR: Country Not Found" into tCountry return tCountry end countryFrom2Letters function countryFrom3Letters p3Letters if (p3Letters is a number) then return "ERROR: The parameter must be a 3 Letters" if not(the number of chars in p3Letters is 2) then return "ERROR: The parameter must be a 3 Letters" put "NOT FOUND" into tCountry set the itemdel to comma put the uCountryCodes of this stack into tCountries filter tCountries with ("*," & p3Letters & ",*") if the number of lines in tCountries is 1 then put item 1 of tCountries into tCountry \ else put "ERROR: Country Not Found" into tCountry return tCountry end countryFrom3Letters function countryCodesFromName pCountryName put "NOT FOUND" into tCountryCodesA["ERROR"] set the itemdel to comma put the uCountryCodes of this stack into tCountries filter tCountries with (pCountryName & ",*") if the number of lines in tCountries is 1 then put item 2 of tCountries into tCountryCodesA["2alpha"] put item 3 of tCountries into tCountryCodesA["3alpha"] put item 4 of tCountries into tCountryCodesA["3digit"] else put "ERROR: Country Not Found" into tCountryCodesA["ERROR"] end if return tCountryCodesA end countryCodesFromName function theCountriesList set the itemdel to comma put the uCountryCodes of me into tCountries put empty into tlist repeat for each Line thisRecord in tCountries put ((item 1 of thisRecord) & lf) after tList end repeat return tList end theCountriesList function ccTLDtoCountry pTLD // SINCE CC TLDS USE ISO 3166-1 alpha2 we siple use that: put countryFrom2Letters(pTLD) into tResponse return tResponse end ccTLDtoCountry function theStateName pZip set the wholematches to false set the itemdel to comma put the uZipsAndStates2 of me into tZipsAndStates put lineOffset(encloseInComma(pZip), tZipsAndStates) into tLine if tLine is 0 then return empty return item 6 of line tLine of tZipsAndStates end theStateName function theStateAbbr pZip set the wholematches to false set the itemdel to comma put the uZipsAndStates2 of me into tZipsAndStates put lineOffset(encloseInComma(pZip), tZipsAndStates) into tLine if tLine is 0 then return empty return item 1 of line tLine of tZipsAndStates end theStateAbbr function theLatLong pZip set the wholematches to false set the itemdel to comma put the uZipsAndStates2 of me into tZipsAndStates put lineOffset(encloseInComma(pZip), tZipsAndStates) into tLine if tLine is 0 then return empty put item 3 of line tLine of tZipsAndStates into tLocA["latitude"] put item 4 of line tLine of tZipsAndStates into tLocA["longitude"] return tLocA end theLatLong function theCity pZip set the wholematches to false set the itemdel to comma put the uZipsAndStates2 of me into tZipsAndStates put lineOffset(encloseInComma(pZip), tZipsAndStates) into tLine if tLine is 0 then return empty return item 5 of line tLine of tZipsAndStates end theCity function theGoogleMapsImageAPIURL pZip end theGoogleMapsImageAPIURL private function encloseInQuotes pX return (quote & pX & quote) end encloseInQuotes private function encloseInComma pX return (comma & pX & comma) end encloseInComma