// [phony.js](http://neocotic.com/phony.js) 1.0.1
// (c) 2011 Alasdair Mercer
// Freely distributable under the MIT license.
// For all details and documentation:
// http://neocotic.com/phony.js
(function(a){function u(a,b){if(typeof a==="string"){a=s(a.trim());if(!a||!/\s+/.test(a)){throw new Error("Invalid translation: "+a)}}else if(b&&a!==null){throw new TypeError("Invalid translation: "+a)}return a}function t(a,b,c,d){if(typeof b==="string"){if(c&&m(a)===-1){b=b.toLowerCase()}return b}var e=b.length>d?b[d]:b[0];e=e||b[0];return t(a,e||"",c)}function s(a){return a[0].toUpperCase()+a.substring(1).toLowerCase()}function r(a,b,c){try{var d=a.apply(c||this);if(typeof b==="function")return b(null,d);return d}catch(e){if(typeof b==="function")return b(e);throw e}}function q(a,b,c){if(typeof a!=="string"){throw new TypeError("Invalid value type: "+typeof a)}var d=a.trim().split(b);for(var e=0;e<d.length;e++){d[e]=d[e].split(c)}return d}function p(){for(var a=arguments.length;a>=0;--a){if(typeof arguments[a]==="function")return arguments[a]}}function o(a,b,c){var d=0;if(typeof c!=="number"||c<0)c=0;a=a.toUpperCase();for(var e=0;e<k.length;e++){if(typeof k[e][b]==="string"){if(k[e][b].toUpperCase()===a){if(d>=c)return k[e];d++}}else{for(var f=0;f<k[e][b].length;f++){if(k[e][b][f]&&k[e][b][f].toUpperCase()===a){if(d>=c)return k[e];d++;break}}}}}function n(a){if(typeof a==="string"){a=a.toUpperCase();if(typeof b[a]==="number")return b[a]}return b[d]}function m(a){switch(a){case a.toLowerCase():return-1;case a.toUpperCase():return 1;default:return 0}}var b={ANSI:3,FAA:2,ICAO:1,ITU:0},c=" ",d="ITU",e="Hundred",f=/([\d,]+)\.(\d+)$/,g=/^([1-9])0{2}$/,h=/^([1-9]\d{0,2}),?(\d{3})$/,i="Thousand",j="Space";var k=[["A",["Alfa",null,null,"Alpha"]],["B","Bravo"],["C","Charlie"],["D","Delta"],["E","Echo"],["F","Foxtrot"],["G","Golf"],["H","Hotel"],["I","India"],["J",["Juliett",null,null,"Juliet"]],["K","Kilo"],["L","Lima"],["M","Mike"],["N","November"],["O","Oscar"],["P","Papa"],["Q","Quebec"],["R","Romeo"],["S","Sierra"],["T","Tango"],["U","Uniform"],["V","Victor"],["W","Whiskey"],["X","X-ray"],["Y","Yankee"],["Z","Zulu"],["0",["Nadazero",null,"Zero"]],["1",["Unaone",null,"One"]],["2",["Bissotwo",null,"Two"]],["3",["Terrathree",null,"Three"]],["4",["Kartefour",null,"Four"]],["5",["Pantafive",null,"Five"]],["6",["Soxisix",null,"Six"]],["7",["Setteseven",null,"Seven"]],["8",["Oktoeight",null,"Eight"]],["9",["Novenine","Niner","Nine"]],["0"+"0","Hundred"],["0"+"0"+"0","Thousand"],[".","Stop"],[".",["Decimal",null,"Point"]],["-","Dash"]],l=a.phony;var v={ALPHABETS:function(){var a=[];for(var c in b){if(b.hasOwnProperty(c))a.push(c)}return a}(),VERSION:"1.0.1",from:function(a,b){b=p(a,b);return r(function(){switch(typeof a){case"object":break;case"string":a={message:a};break;default:a={};break}var b=n(),d=typeof a.caseSensitive==="undefined"?true:a.caseSensitive,e=d?c.toLowerCase():c,f="",g=typeof a.round==="undefined"?true:a.round,h=a.message||"",k=d?j.toLowerCase():j;h=q(h,new RegExp(k,"i"),new RegExp(e,"i"));if(h){for(var l=0;l<h.length;l++){if(l>0)f+=" ";for(var m=0;m<h[l].length;m++){var p=o(h[l][m],1);if(p){if(!g||p[1]!==i||m===h[l].length-1){f+=t(h[l][m],p[0],d,b)}}}}}return f},b,this)},to:function(a,b){b=p(a,b);return r(function(){function u(a,c){if(!c){var j=[],l=typeof a==="string"?a:a.join("");if(f.test(l)){j=l.match(f);if(j&&j.length===3){u(j[1].replace(/,/g,""),true);m+=k;m+=t(".",o(".",0,1)[1],d,b);m+=k;u(j[2],true);return}}if(p){if(g.test(l)){j=l.match(g);if(j&&j.length===2){u(j[1],true);m+=k;m+=t(e.toLowerCase(),e,d,b);return}}if(h.test(l)){j=l.match(h);if(j&&j.length===3){u(j[1]);m+=k;m+=t(i.toLowerCase(),i,d,b);if(j[2]!=="000"){m+=k;u(j[2])}return}}}}for(var n=0;n<a.length;n++){var q=o(a[n],0);if(q){if(n>0)m+=k;m+=t(a[n],q[1],d,b)}}}switch(typeof a){case"object":break;case"string":a={message:a};break;default:a={};break}var b=n(a.alphabet),d=typeof a.caseSensitive==="undefined"?true:a.caseSensitive,k=d?c.toLowerCase():c,l=!!a.omitSpace,m="",p=typeof a.round==="undefined"?true:a.round,r=q(a.message||"",/\s+/,""),s=d?j.toLowerCase():j;if(r){for(var v=0;v<r.length;v++){if(v>0){m+=k;if(!l)m+=s+k}u(r[v])}}return m},b,this)},defineChar:function(a,b,c){return r(function(){if(typeof a!=="string"){throw new TypeError("Invalid character type: "+typeof a)}else if(typeof b!=="string"||typeof b!=="object"||typeof b.length!=="number"){throw new TypeError("Invalid translation type: "+typeof b)}if(a.length>1){throw new Error("Invalid character length: "+a.length)}if(typeof b==="string"){b=u(b)}else{for(var c=0;c<b.length;c++){b[c]=u(b[c],true);if(c===0&&!b[c]){throw new Error("Invalid default translation: "+transation[c])}}}a=a.toUpperCase();var d=o(a,0);if(d){d[1]=b}else{k.push([a,b])}},c,this)},noConflict:function(b){return r(function(){a.phony=l;return this},b,this)}};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports){exports=module.exports=v}exports.phony=v}else if(typeof define==="function"&&define.amd){define("phony",function(){return v})}else{a.phony=v}})(this)