<!DOCTYPE html>
<html ng-app="example">

  <head>
    <link data-require="bootstrap@*" data-semver="3.3.1" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
    <link rel="stylesheet" href="autocomplete.min.css" />
    <link rel="stylesheet" href="style.css" />
    <script data-require="jquery@*" data-semver="2.1.3" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script data-require="bootstrap@*" data-semver="3.3.1" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    <script data-require="angular.js@1.3.11" data-semver="1.3.11" src="https://code.angularjs.org/1.3.11/angular.js"></script>
    <script data-require="angular-animate@1.3.11" data-semver="1.3.11" src="https://code.angularjs.org/1.3.11/angular-animate.js"></script>
    <script data-require="lodash.js@*" data-semver="2.4.1" src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBInJctfq-xJYfMCPLzZumRacDQgr1cKlw"></script>
    <script src="autocomplete.min.js"></script>
    <script src="LocationTool.js"></script>
    <script src="script.js"></script>
  </head>

  <body ng-controller="DemoCtrl">
    <div class="container">
      <div class="row">
        <div class="col-md-12">
          <h1>Basic Usage</h1>
          <form class="form">
            <input class="form-control" g-places-autocomplete="" ng-model="place" />
          </form>
          <h5>Result: {{ changes }} </h5>
          <pre>{{ addressArray | json}}</pre>
        </div>
      </div>
      <br />
      <hr />
      <div class="row">
        <div class="col-md-12">
          <h1>Raw Usage</h1>
          <form class="form">
                          Search:             <input class="form-control" ng-model="searchTerm" />
            <button type="button" class="btn btn-primary" ng-click="search(searchTerm)">Search</button>
          </form>
          <hr />
          <div class="row">
            <div class="col-xs-6">
              <h5>PLACES Result:</h5>
              <pre>{{ searchResults | json}}</pre>
              <h5>PLACES History: </h5>
              <pre>{{ searchHistory | json}}</pre>
            </div>
            <div class="col-xs-6">
              <h5>GEO Result:</h5>
              <pre>{{ geoResults | json}}</pre>
              <h5>GEO History: </h5>
              <pre>{{ geoHistory | json}}</pre>
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>

</html>
// Code goes here
 angular.module('example', ['google.places'])
                // Setup a basic controller with a scope variable 'place'
  .controller('DemoCtrl', function ($scope) {
      $scope.place = null;
      // 191 West George Street, Glasgow
      
     $scope.auto =  new google.maps.places.AutocompleteService();
     $scope.geocoder =  new google.maps.Geocoder();
     $scope.searchStatus = null;
     $scope.results = [];
     $scope.searchHistory = [];
     $scope.searchTerm = '112 Essex Ave,  Altamonte Springs, FL';
     $scope.currentTerm = '';
     $scope.searchResults = null;
     $scope.geoHistory = [];
     $scope.geoResults = [];
     $scope.addressPlace = null;
     $scope.changes = 0;
     $scope.addressArray = {};
     $scope.gettables = [];
     $scope.$watch('place', function(newValue, oldValue){
  
        if (newValue !== null && typeof newValue === 'object' ){
          $scope.changes++; 
          $scope.addressPlace = new LocationTool.Address(newValue);
          $scope.gettables = $scope.addressPlace.gettableFields(true);
          $scope.addressRaw = $scope.addressPlace.getRaw();
          $scope.addressPlace.toArray(true)
                .then(function(result){
                  $scope.addressArray = result;
          });
        }
       
     });
    
     $scope.search = function(term){
      var searchCallback = function(predictions, status){
        
      $scope.$apply(function(){
         $scope.searchResults = [];
          $scope.searchStatus = status;
          $scope.searchHistory.push({term: $scope.currentTerm, status: status, results: predictions});
          $scope.searchResults = predictions;
          if (status != google.maps.places.PlacesServiceStatus.OK) {
            console.log("NOT OK");
            return;
          }
          
        })
     
      };
       $scope.searchStatus = null;
      
       $scope.searchResults = [];
        $scope.geoResults = [];
      $scope.geoStatus = null;
       $scope.currentTerm = term;
      
        $scope.geocoder.geocode( { 'address': term}, function(results, status) {
          $scope.$apply(function(){
             $scope.geoHistory.push({term: term, results: results, status: status})
              if (status == google.maps.GeocoderStatus.OK) {
                  $scope.geoResults = results;
                  $scope.geoStatus = status;
              } else {
                alert('Geocode was not successful for the following reason: ' + status);
              }
            
          }, 1)
         
        });
       
       
       // $scope.geocoder.geocode({ address: term }, searchCallback );
       $scope.auto.getPlacePredictions({ input: term, types: ['geocode'] }, searchCallback );
       
     };
     
  });
/* Styles go here */

/*
 * angular-google-places-autocomplete
 *
 * Copyright (c) 2014 "kuhnza" David Kuhn
 * Licensed under the MIT license.
 * https://github.com/kuhnza/angular-google-places-autocomplete/blob/master/LICENSE
 */

 'use strict';

angular.module('google.places', [])
	/**
	 * DI wrapper around global google places library.
	 *
	 * Note: requires the Google Places API to already be loaded on the page.
	 */
	.factory('googlePlacesApi', ['$window', function ($window) {
        if (!$window.google) throw 'Global `google` var missing. Did you forget to include the places API script?';

		return $window.google;
	}])

	/**
	 * Autocomplete directive. Use like this:
	 *
	 * <input type="text" g-places-autocomplete ng-model="myScopeVar" />
	 */
	.directive('gPlacesAutocomplete',
        [ '$parse', '$compile', '$timeout', '$document', 'googlePlacesApi',
        function ($parse, $compile, $timeout, $document, google) {

            return {
                restrict: 'A',
                require: '^ngModel',
                scope: {
                    model: '=ngModel',
                    options: '=?',
                    forceSelection: '=?',
                    customPlaces: '=?'
                },
                controller: ['$scope', function ($scope) {}],
                link: function ($scope, element, attrs, controller) {
                    var keymap = {
                            tab: 9,
                            enter: 13,
                            esc: 27,
                            up: 38,
                            down: 40
                        },
                        hotkeys = [keymap.tab, keymap.enter, keymap.esc, keymap.up, keymap.down],
                        autocompleteService = new google.maps.places.AutocompleteService(),
                        placesService = new google.maps.places.PlacesService(element[0]);

                    (function init() {
                        $scope.query = '';
                        $scope.predictions = [];
                        $scope.input = element;
                        $scope.options = $scope.options || {};

                        initAutocompleteDrawer();
                        initEvents();
                        initNgModelController();
                    }());

                    function initEvents() {
                        element.bind('keydown', onKeydown);
                        element.bind('blur', onBlur);

                        $scope.$watch('selected', select);
                    }

                    function initAutocompleteDrawer() {
                        // Drawer element used to display predictions
                        var drawerElement = angular.element('<div g-places-autocomplete-drawer></div>'),
                            body = angular.element($document[0].body),
                            $drawer;

                        drawerElement.attr({
                            input: 'input',
                            query: 'query',
                            predictions: 'predictions',
                            active: 'active',
                            selected: 'selected'
                        });

                        $drawer = $compile(drawerElement)($scope);
                        body.append($drawer);  // Append to DOM
                    }

                    function initNgModelController() {
                        controller.$parsers.push(parse);
                        controller.$formatters.push(format);
                        controller.$render = render;
                    }

                    function onKeydown(event) {
                        if ($scope.predictions.length === 0 || indexOf(hotkeys, event.which) === -1) {
                            return;
                        }

                        event.preventDefault();

                        if (event.which === keymap.down) {
                            $scope.active = ($scope.active + 1) % $scope.predictions.length;
                            $scope.$digest();
                        } else if (event.which === keymap.up) {
                            $scope.active = ($scope.active ? $scope.active : $scope.predictions.length) - 1;
                            $scope.$digest();
                        } else if (event.which === 13 || event.which === 9) {
                            if ($scope.forceSelection) {
                                $scope.active = ($scope.active === -1) ? 0 : $scope.active;
                            }

                            $scope.$apply(function () {
                                $scope.selected = $scope.active;

                                if ($scope.selected === -1) {
                                    clearPredictions();
                                }
                            });
                        } else if (event.which === 27) {
                            event.stopPropagation();
                            clearPredictions();
                            $scope.$digest();
                        }
                    }

                    function onBlur(event) {
                        if ($scope.predictions.length === 0) {
                            return;
                        }

                        if ($scope.forceSelection) {
                            $scope.selected = ($scope.selected === -1) ? 0 : $scope.selected;
                        }

                        $scope.$digest();

                        $scope.$apply(function () {
                            if ($scope.selected === -1) {
                                clearPredictions();
                            }
                        });
                    }

                    function select() {
                        var prediction;

                        prediction = $scope.predictions[$scope.selected];
                        if (!prediction) return;

                        if (prediction.is_custom) {
                            $scope.model = prediction.place;
                            $scope.$emit('g-places-autocomplete:select', prediction.place);
                        } else {
                            placesService.getDetails({ placeId: prediction.place_id }, function (place, status) {
                                if (status == google.maps.places.PlacesServiceStatus.OK) {
                                    $scope.$apply(function () {
                                        $scope.model = place;
                                        $scope.$emit('g-places-autocomplete:select', place);
                                    });
                                }
                            });
                        }

                        clearPredictions();
                    }

                    function parse(viewValue) {
                        var request;

                        if (!(viewValue && isString(viewValue))) return viewValue;

                        $scope.query = viewValue;

                        request = angular.extend({ input: viewValue }, $scope.options);
                        autocompleteService.getPlacePredictions(request, function (predictions, status) {
                            $scope.$apply(function () {
                                var customPlacePredictions;

                                clearPredictions();

                                if ($scope.customPlaces) {
                                    customPlacePredictions = getCustomPlacePredictions($scope.query);
                                    $scope.predictions.push.apply($scope.predictions, customPlacePredictions);
                                }

                                if (status == google.maps.places.PlacesServiceStatus.OK) {
                                    $scope.predictions.push.apply($scope.predictions, predictions);
                                }

                                if ($scope.predictions.length > 5) {
                                    $scope.predictions.length = 5;  // trim predictions down to size
                                }
                            });
                        });

                        return viewValue;
                    }

                    function format(modelValue) {
                        var viewValue = "";

                        if (isString(modelValue)) {
                            viewValue = modelValue;
                        } else if (isObject(modelValue)) {
                            viewValue = modelValue.formatted_address;
                        }

                        return viewValue;
                    }

                    function render() {
                        return element.val(controller.$viewValue);
                    }

                    function clearPredictions() {
                        $scope.active = -1;
                        $scope.selected = -1;
                        $scope.predictions.length = 0;
                    }

                    function getCustomPlacePredictions(query) {
                        var predictions = [],
                            place, match, i;

                        for (i = 0; i < $scope.customPlaces.length; i++) {
                            place = $scope.customPlaces[i];

                            match = getCustomPlaceMatches(query, place);
                            if (match.matched_substrings.length > 0) {
                                predictions.push({
                                    is_custom: true,
                                    custom_prediction_label: place.custom_prediction_label || '(Custom Non-Google Result)',  // required by https://developers.google.com/maps/terms ยง 10.1.1 (d)
                                    description: place.formatted_address,
                                    place: place,
                                    matched_substrings: match.matched_substrings,
                                    terms: match.terms
                                });
                            }
                        }

                        return predictions;
                    }

                    function getCustomPlaceMatches(query, place) {
                        var q = query + '',  // make a copy so we don't interfere with subsequent matches
                            terms = [],
                            matched_substrings = [],
                            fragment,
                            termFragments,
                            i;

                        termFragments = place.formatted_address.split(',');
                        for (i = 0; i < termFragments.length; i++) {
                            fragment = termFragments[i].trim();

                            if (q.length > 0) {
                                if (fragment.length >= q.length) {
                                    if (startsWith(fragment, q)) {
                                        matched_substrings.push({ length: q.length, offset: i });
                                    }
                                    q = '';  // no more matching to do
                                } else {
                                    if (startsWith(q, fragment)) {
                                        matched_substrings.push({ length: fragment.length, offset: i });
                                        q = q.replace(fragment, '').trim();
                                    } else {
                                        q = '';  // no more matching to do
                                    }
                                }
                            }

                            terms.push({
                                value: fragment,
                                offset: place.formatted_address.indexOf(fragment)
                            });
                        }

                        return {
                            matched_substrings: matched_substrings,
                            terms: terms
                        };
                    }

                    function isString(val) {
                        return toString.call(val) == '[object String]';
                    }

                    function isObject(val) {
                        return toString.call(val) == '[object Object]';
                    }

                    function indexOf(array, item) {
                        var i, length;

                        if (array == null) return -1;

                        length = array.length;
                        for (i = 0; i < length; i++) {
                            if (array[i] === item) return i;
                        }
                        return -1;
                    }

                    function startsWith(string1, string2) {
                        return toLower(string1).lastIndexOf(toLower(string2), 0) === 0;
                    }

                    function toLower(string) {
                        return (string == null) ? "" : string.toLowerCase();
                    }
                }
            }
        }
    ])


    .directive('gPlacesAutocompleteDrawer', ['$window', '$document', function ($window, $document) {
        var TEMPLATE = [
            '<div class="pac-container" ng-if="isOpen()" ng-style="{top: position.top+\'px\', left: position.left+\'px\', width: position.width+\'px\'}" style="display: block;" role="listbox" aria-hidden="{{!isOpen()}}">',
            '  <div class="pac-item" g-places-autocomplete-prediction index="$index" prediction="prediction" query="query"',
            '       ng-repeat="prediction in predictions track by $index" ng-class="{\'pac-item-selected\': isActive($index) }"',
            '       ng-mouseenter="selectActive($index)" ng-click="selectPrediction($index)" role="option" id="{{prediction.id}}">',
            '  </div>',
            '</div>'
        ];

        return {
            restrict: 'A',
            scope:{
                input: '=',
                query: '=',
                predictions: '=',
                active: '=',
                selected: '='
            },
            template: TEMPLATE.join(''),
            link: function ($scope, element) {
                element.bind('mousedown', function (event) {
                    event.preventDefault();  // prevent blur event from firing when clicking selection
                });

                $scope.isOpen = function () {
                    return $scope.predictions.length > 0;
                };

                $scope.isActive = function (index) {
                    return $scope.active === index;
                };

                $scope.selectActive = function (index) {
                    $scope.active = index;
                };

                $scope.selectPrediction = function (index) {
                    $scope.selected = index;
                };

                $scope.$watch('predictions', function () {
                    $scope.position = getDrawerPosition($scope.input);
                });

                function getDrawerPosition(element) {
                    var domEl = element[0],
                        rect = domEl.getBoundingClientRect(),
                        docEl = $document[0].documentElement,
                        body = $document[0].body,
                        scrollTop = $window.pageYOffset || docEl.scrollTop || body.scrollTop,
                        scrollLeft = $window.pageXOffset || docEl.scrollLeft || body.scrollLeft;

                    return {
                        width: rect.width,
                        height: rect.height,
                        top: rect.top + rect.height + scrollTop,
                        left: rect.left + scrollLeft
                    };
                }
            }
        }
    }])

    .directive('gPlacesAutocompletePrediction', [function () {
        var TEMPLATE = [
            '<span class="pac-icon pac-icon-marker"></span>',
            '<span class="pac-item-query" ng-bind-html="prediction | highlightMatched"></span>',
            '<span ng-repeat="term in prediction.terms | unmatchedTermsOnly:prediction">{{term.value | trailingComma:!$last}}&nbsp;</span>',
            '<span class="custom-prediction-label" ng-if="prediction.is_custom">&nbsp;{{prediction.custom_prediction_label}}</span>'
        ];

        return {
            restrict: 'A',
            scope:{
                index:'=',
                prediction:'=',
                query:'='
            },
            template: TEMPLATE.join('')
        }
    }])

    .filter('highlightMatched', ['$sce', function ($sce) {
        return function (prediction) {
            var matchedPortion = '',
                unmatchedPortion = '',
                matched;

            if (prediction.matched_substrings.length > 0 && prediction.terms.length > 0) {
                matched = prediction.matched_substrings[0];
                matchedPortion = prediction.terms[0].value.substr(matched.offset, matched.length);
                unmatchedPortion = prediction.terms[0].value.substr(matched.offset + matched.length);
            }

            return $sce.trustAsHtml('<span class="pac-matched">' + matchedPortion + '</span>' + unmatchedPortion);
        }
    }])

    .filter('unmatchedTermsOnly', [function () {
        return function (terms, prediction) {
            var i, term, filtered = [];

            for (i = 0; i < terms.length; i++) {
                term = terms[i];
                if (prediction.matched_substrings.length > 0 && term.offset > prediction.matched_substrings[0].length) {
                    filtered.push(term);
                }
            }

            return filtered;
        }
    }])

    .filter('trailingComma', [function () {
        return function (input, condition) {
            return (condition) ? input + ',' : input;
        }
    }]);


.pac-container{background-color:#fff;position:absolute!important;z-index:1000;border-radius:2px;border-top:1px solid #d9d9d9;font-family:Arial,sans-serif;box-shadow:0 2px 6px rgba(0,0,0,.3);-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;overflow:hidden}.pac-container:after{content:"";padding:1px 1px 1px 0;height:16px;text-align:right;display:block;background-image:url(//maps.gstatic.com/mapfiles/api-3/images/powered-by-google-on-white2.png);background-position:right;background-repeat:no-repeat;background-size:104px 16px}.hdpi.pac-container:after{background-image:url(//maps.gstatic.com/mapfiles/api-3/images/powered-by-google-on-white2_hdpi.png)}.pac-item{cursor:default;padding:0 4px;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;line-height:30px;text-align:left;border-top:1px solid #e6e6e6;font-size:11px;color:#999}.pac-item:hover{background-color:#fafafa}.pac-item-selected,.pac-item-selected:hover{background-color:#ebf2fe}.pac-matched{font-weight:700}.pac-item-query{font-size:13px;padding-right:3px;color:#000}.pac-icon{width:15px;height:20px;margin-right:7px;margin-top:6px;display:inline-block;vertical-align:top;background-image:url(//maps.gstatic.com/mapfiles/api-3/images/autocomplete-icons.png);background-size:34px}.hdpi .pac-icon{background-image:url(//maps.gstatic.com/mapfiles/api-3/images/autocomplete-icons_hdpi.png)}.pac-icon-search{background-position:-1px -1px}.pac-item-selected .pac-icon-search{background-position:-18px -1px}.pac-icon-marker{background-position:-1px -161px}.pac-item-selected .pac-icon-marker{background-position:-18px -161px}.pac-placeholder{color:gray}.custom-prediction-label{font-style:italic}
var CountryCodes = window.CountryCodes || {};
(function(windowScope){
var CountriesData = [{"countryName":"Afghanistan","iso2":"AF","iso3":"AFG","phoneCode":"93"},{"countryName":"Albania","iso2":"AL","iso3":"ALB","phoneCode":"355"},{"countryName":"Algeria","iso2":"DZ","iso3":"DZA","phoneCode":"213"},{"countryName":"American Samoa","iso2":"AS","iso3":"ASM","phoneCode":"1 684"},{"countryName":"Andorra","iso2":"AD","iso3":"AND","phoneCode":"376"},{"countryName":"Angola","iso2":"AO","iso3":"AGO","phoneCode":"244"},{"countryName":"Anguilla","iso2":"AI","iso3":"AIA","phoneCode":"1 264"},{"countryName":"Antarctica","iso2":"AQ","iso3":"ATA","phoneCode":"672"},{"countryName":"Antigua and Barbuda","iso2":"AG","iso3":"ATG","phoneCode":"1 268"},{"countryName":"Argentina","iso2":"AR","iso3":"ARG","phoneCode":"54"},{"countryName":"Armenia","iso2":"AM","iso3":"ARM","phoneCode":"374"},{"countryName":"Aruba","iso2":"AW","iso3":"ABW","phoneCode":"297"},{"countryName":"Australia","iso2":"AU","iso3":"AUS","phoneCode":"61"},{"countryName":"Austria","iso2":"AT","iso3":"AUT","phoneCode":"43"},{"countryName":"Azerbaijan","iso2":"AZ","iso3":"AZE","phoneCode":"994"},{"countryName":"Bahamas","iso2":"BS","iso3":"BHS","phoneCode":"1 242"},{"countryName":"Bahrain","iso2":"BH","iso3":"BHR","phoneCode":"973"},{"countryName":"Bangladesh","iso2":"BD","iso3":"BGD","phoneCode":"880"},{"countryName":"Barbados","iso2":"BB","iso3":"BRB","phoneCode":"1 246"},{"countryName":"Belarus","iso2":"BY","iso3":"BLR","phoneCode":"375"},{"countryName":"Belgium","iso2":"BE","iso3":"BEL","phoneCode":"32"},{"countryName":"Belize","iso2":"BZ","iso3":"BLZ","phoneCode":"501"},{"countryName":"Benin","iso2":"BJ","iso3":"BEN","phoneCode":"229"},{"countryName":"Bermuda","iso2":"BM","iso3":"BMU","phoneCode":"1 441"},{"countryName":"Bhutan","iso2":"BT","iso3":"BTN","phoneCode":"975"},{"countryName":"Bolivia","iso2":"BO","iso3":"BOL","phoneCode":"591"},{"countryName":"Bosnia and Herzegovina","iso2":"BA","iso3":"BIH","phoneCode":"387"},{"countryName":"Botswana","iso2":"BW","iso3":"BWA","phoneCode":"267"},{"countryName":"Brazil","iso2":"BR","iso3":"BRA","phoneCode":"55"},{"countryName":"British Indian Ocean Territory","iso2":"IO","iso3":"IOT","phoneCode":""},{"countryName":"British Virgin Islands","iso2":"VG","iso3":"VGB","phoneCode":"1 284"},{"countryName":"Brunei","iso2":"BN","iso3":"BRN","phoneCode":"673"},{"countryName":"Bulgaria","iso2":"BG","iso3":"BGR","phoneCode":"359"},{"countryName":"Burkina Faso","iso2":"BF","iso3":"BFA","phoneCode":"226"},{"countryName":"Burma (Myanmar)","iso2":"MM","iso3":"MMR","phoneCode":"95"},{"countryName":"Burundi","iso2":"BI","iso3":"BDI","phoneCode":"257"},{"countryName":"Cambodia","iso2":"KH","iso3":"KHM","phoneCode":"855"},{"countryName":"Cameroon","iso2":"CM","iso3":"CMR","phoneCode":"237"},{"countryName":"Canada","iso2":"CA","iso3":"CAN","phoneCode":"1"},{"countryName":"Cape Verde","iso2":"CV","iso3":"CPV","phoneCode":"238"},{"countryName":"Cayman Islands","iso2":"KY","iso3":"CYM","phoneCode":"1 345"},{"countryName":"Central African Republic","iso2":"CF","iso3":"CAF","phoneCode":"236"},{"countryName":"Chad","iso2":"TD","iso3":"TCD","phoneCode":"235"},{"countryName":"Chile","iso2":"CL","iso3":"CHL","phoneCode":"56"},{"countryName":"China","iso2":"CN","iso3":"CHN","phoneCode":"86"},{"countryName":"Christmas Island","iso2":"CX","iso3":"CXR","phoneCode":"61"},{"countryName":"Cocos (Keeling) Islands","iso2":"CC","iso3":"CCK","phoneCode":"61"},{"countryName":"Colombia","iso2":"CO","iso3":"COL","phoneCode":"57"},{"countryName":"Comoros","iso2":"KM","iso3":"COM","phoneCode":"269"},{"countryName":"Cook Islands","iso2":"CK","iso3":"COK","phoneCode":"682"},{"countryName":"Costa Rica","iso2":"CR","iso3":"CRC","phoneCode":"506"},{"countryName":"Croatia","iso2":"HR","iso3":"HRV","phoneCode":"385"},{"countryName":"Cuba","iso2":"CU","iso3":"CUB","phoneCode":"53"},{"countryName":"Cyprus","iso2":"CY","iso3":"CYP","phoneCode":"357"},{"countryName":"Czech Republic","iso2":"CZ","iso3":"CZE","phoneCode":"420"},{"countryName":"Democratic Republic of the Congo","iso2":"CD","iso3":"COD","phoneCode":"243"},{"countryName":"Denmark","iso2":"DK","iso3":"DNK","phoneCode":"45"},{"countryName":"Djibouti","iso2":"DJ","iso3":"DJI","phoneCode":"253"},{"countryName":"Dominica","iso2":"DM","iso3":"DMA","phoneCode":"1 767"},{"countryName":"Dominican Republic","iso2":"DO","iso3":"DOM","phoneCode":"1 809"},{"countryName":"Ecuador","iso2":"EC","iso3":"ECU","phoneCode":"593"},{"countryName":"Egypt","iso2":"EG","iso3":"EGY","phoneCode":"20"},{"countryName":"El Salvador","iso2":"SV","iso3":"SLV","phoneCode":"503"},{"countryName":"Equatorial Guinea","iso2":"GQ","iso3":"GNQ","phoneCode":"240"},{"countryName":"Eritrea","iso2":"ER","iso3":"ERI","phoneCode":"291"},{"countryName":"Estonia","iso2":"EE","iso3":"EST","phoneCode":"372"},{"countryName":"Ethiopia","iso2":"ET","iso3":"ETH","phoneCode":"251"},{"countryName":"Falkland Islands","iso2":"FK","iso3":"FLK","phoneCode":"500"},{"countryName":"Faroe Islands","iso2":"FO","iso3":"FRO","phoneCode":"298"},{"countryName":"Fiji","iso2":"FJ","iso3":"FJI","phoneCode":"679"},{"countryName":"Finland","iso2":"FI","iso3":"FIN","phoneCode":"358"},{"countryName":"France","iso2":"FR","iso3":"FRA","phoneCode":"33"},{"countryName":"French Polynesia","iso2":"PF","iso3":"PYF","phoneCode":"689"},{"countryName":"Gabon","iso2":"GA","iso3":"GAB","phoneCode":"241"},{"countryName":"Gambia","iso2":"GM","iso3":"GMB","phoneCode":"220"},{"countryName":"Gaza Strip","iso2":"","iso3":"","phoneCode":"970"},{"countryName":"Georgia","iso2":"GE","iso3":"GEO","phoneCode":"995"},{"countryName":"Germany","iso2":"DE","iso3":"DEU","phoneCode":"49"},{"countryName":"Ghana","iso2":"GH","iso3":"GHA","phoneCode":"233"},{"countryName":"Gibraltar","iso2":"GI","iso3":"GIB","phoneCode":"350"},{"countryName":"Greece","iso2":"GR","iso3":"GRC","phoneCode":"30"},{"countryName":"Greenland","iso2":"GL","iso3":"GRL","phoneCode":"299"},{"countryName":"Grenada","iso2":"GD","iso3":"GRD","phoneCode":"1 473"},{"countryName":"Guam","iso2":"GU","iso3":"GUM","phoneCode":"1 671"},{"countryName":"Guatemala","iso2":"GT","iso3":"GTM","phoneCode":"502"},{"countryName":"Guinea","iso2":"GN","iso3":"GIN","phoneCode":"224"},{"countryName":"Guinea-Bissau","iso2":"GW","iso3":"GNB","phoneCode":"245"},{"countryName":"Guyana","iso2":"GY","iso3":"GUY","phoneCode":"592"},{"countryName":"Haiti","iso2":"HT","iso3":"HTI","phoneCode":"509"},{"countryName":"Holy See (Vatican City)","iso2":"VA","iso3":"VAT","phoneCode":"39"},{"countryName":"Honduras","iso2":"HN","iso3":"HND","phoneCode":"504"},{"countryName":"Hong Kong","iso2":"HK","iso3":"HKG","phoneCode":"852"},{"countryName":"Hungary","iso2":"HU","iso3":"HUN","phoneCode":"36"},{"countryName":"Iceland","iso2":"IS","iso3":"IS","phoneCode":"354"},{"countryName":"India","iso2":"IN","iso3":"IND","phoneCode":"91"},{"countryName":"Indonesia","iso2":"ID","iso3":"IDN","phoneCode":"62"},{"countryName":"Iran","iso2":"IR","iso3":"IRN","phoneCode":"98"},{"countryName":"Iraq","iso2":"IQ","iso3":"IRQ","phoneCode":"964"},{"countryName":"Ireland","iso2":"IE","iso3":"IRL","phoneCode":"353"},{"countryName":"Isle of Man","iso2":"IM","iso3":"IMN","phoneCode":"44"},{"countryName":"Israel","iso2":"IL","iso3":"ISR","phoneCode":"972"},{"countryName":"Italy","iso2":"IT","iso3":"ITA","phoneCode":"39"},{"countryName":"Ivory Coast","iso2":"CI","iso3":"CIV","phoneCode":"225"},{"countryName":"Jamaica","iso2":"JM","iso3":"JAM","phoneCode":"1 876"},{"countryName":"Japan","iso2":"JP","iso3":"JPN","phoneCode":"81"},{"countryName":"Jersey","iso2":"JE","iso3":"JEY","phoneCode":""},{"countryName":"Jordan","iso2":"JO","iso3":"JOR","phoneCode":"962"},{"countryName":"Kazakhstan","iso2":"KZ","iso3":"KAZ","phoneCode":"7"},{"countryName":"Kenya","iso2":"KE","iso3":"KEN","phoneCode":"254"},{"countryName":"Kiribati","iso2":"KI","iso3":"KIR","phoneCode":"686"},{"countryName":"Kosovo","iso2":"","iso3":"","phoneCode":"381"},{"countryName":"Kuwait","iso2":"KW","iso3":"KWT","phoneCode":"965"},{"countryName":"Kyrgyzstan","iso2":"KG","iso3":"KGZ","phoneCode":"996"},{"countryName":"Laos","iso2":"LA","iso3":"LAO","phoneCode":"856"},{"countryName":"Latvia","iso2":"LV","iso3":"LVA","phoneCode":"371"},{"countryName":"Lebanon","iso2":"LB","iso3":"LBN","phoneCode":"961"},{"countryName":"Lesotho","iso2":"LS","iso3":"LSO","phoneCode":"266"},{"countryName":"Liberia","iso2":"LR","iso3":"LBR","phoneCode":"231"},{"countryName":"Libya","iso2":"LY","iso3":"LBY","phoneCode":"218"},{"countryName":"Liechtenstein","iso2":"LI","iso3":"LIE","phoneCode":"423"},{"countryName":"Lithuania","iso2":"LT","iso3":"LTU","phoneCode":"370"},{"countryName":"Luxembourg","iso2":"LU","iso3":"LUX","phoneCode":"352"},{"countryName":"Macau","iso2":"MO","iso3":"MAC","phoneCode":"853"},{"countryName":"Macedonia","iso2":"MK","iso3":"MKD","phoneCode":"389"},{"countryName":"Madagascar","iso2":"MG","iso3":"MDG","phoneCode":"261"},{"countryName":"Malawi","iso2":"MW","iso3":"MWI","phoneCode":"265"},{"countryName":"Malaysia","iso2":"MY","iso3":"MYS","phoneCode":"60"},{"countryName":"Maldives","iso2":"MV","iso3":"MDV","phoneCode":"960"},{"countryName":"Mali","iso2":"ML","iso3":"MLI","phoneCode":"223"},{"countryName":"Malta","iso2":"MT","iso3":"MLT","phoneCode":"356"},{"countryName":"Marshall Islands","iso2":"MH","iso3":"MHL","phoneCode":"692"},{"countryName":"Mauritania","iso2":"MR","iso3":"MRT","phoneCode":"222"},{"countryName":"Mauritius","iso2":"MU","iso3":"MUS","phoneCode":"230"},{"countryName":"Mayotte","iso2":"YT","iso3":"MYT","phoneCode":"262"},{"countryName":"Mexico","iso2":"MX","iso3":"MEX","phoneCode":"52"},{"countryName":"Micronesia","iso2":"FM","iso3":"FSM","phoneCode":"691"},{"countryName":"Moldova","iso2":"MD","iso3":"MDA","phoneCode":"373"},{"countryName":"Monaco","iso2":"MC","iso3":"MCO","phoneCode":"377"},{"countryName":"Mongolia","iso2":"MN","iso3":"MNG","phoneCode":"976"},{"countryName":"Montenegro","iso2":"ME","iso3":"MNE","phoneCode":"382"},{"countryName":"Montserrat","iso2":"MS","iso3":"MSR","phoneCode":"1 664"},{"countryName":"Morocco","iso2":"MA","iso3":"MAR","phoneCode":"212"},{"countryName":"Mozambique","iso2":"MZ","iso3":"MOZ","phoneCode":"258"},{"countryName":"Namibia","iso2":"NA","iso3":"NAM","phoneCode":"264"},{"countryName":"Nauru","iso2":"NR","iso3":"NRU","phoneCode":"674"},{"countryName":"Nepal","iso2":"NP","iso3":"NPL","phoneCode":"977"},{"countryName":"Netherlands","iso2":"NL","iso3":"NLD","phoneCode":"31"},{"countryName":"Netherlands Antilles","iso2":"AN","iso3":"ANT","phoneCode":"599"},{"countryName":"New Caledonia","iso2":"NC","iso3":"NCL","phoneCode":"687"},{"countryName":"New Zealand","iso2":"NZ","iso3":"NZL","phoneCode":"64"},{"countryName":"Nicaragua","iso2":"NI","iso3":"NIC","phoneCode":"505"},{"countryName":"Niger","iso2":"NE","iso3":"NER","phoneCode":"227"},{"countryName":"Nigeria","iso2":"NG","iso3":"NGA","phoneCode":"234"},{"countryName":"Niue","iso2":"NU","iso3":"NIU","phoneCode":"683"},{"countryName":"Norfolk Island","iso2":"","iso3":"NFK","phoneCode":"672"},{"countryName":"North Korea","iso2":"KP","iso3":"PRK","phoneCode":"850"},{"countryName":"Northern Mariana Islands","iso2":"MP","iso3":"MNP","phoneCode":"1 670"},{"countryName":"Norway","iso2":"NO","iso3":"NOR","phoneCode":"47"},{"countryName":"Oman","iso2":"OM","iso3":"OMN","phoneCode":"968"},{"countryName":"Pakistan","iso2":"PK","iso3":"PAK","phoneCode":"92"},{"countryName":"Palau","iso2":"PW","iso3":"PLW","phoneCode":"680"},{"countryName":"Panama","iso2":"PA","iso3":"PAN","phoneCode":"507"},{"countryName":"Papua New Guinea","iso2":"PG","iso3":"PNG","phoneCode":"675"},{"countryName":"Paraguay","iso2":"PY","iso3":"PRY","phoneCode":"595"},{"countryName":"Peru","iso2":"PE","iso3":"PER","phoneCode":"51"},{"countryName":"Philippines","iso2":"PH","iso3":"PHL","phoneCode":"63"},{"countryName":"Pitcairn Islands","iso2":"PN","iso3":"PCN","phoneCode":"870"},{"countryName":"Poland","iso2":"PL","iso3":"POL","phoneCode":"48"},{"countryName":"Portugal","iso2":"PT","iso3":"PRT","phoneCode":"351"},{"countryName":"Puerto Rico","iso2":"PR","iso3":"PRI","phoneCode":"1"},{"countryName":"Qatar","iso2":"QA","iso3":"QAT","phoneCode":"974"},{"countryName":"Republic of the Congo","iso2":"CG","iso3":"COG","phoneCode":"242"},{"countryName":"Romania","iso2":"RO","iso3":"ROU","phoneCode":"40"},{"countryName":"Russia","iso2":"RU","iso3":"RUS","phoneCode":"7"},{"countryName":"Rwanda","iso2":"RW","iso3":"RWA","phoneCode":"250"},{"countryName":"Saint Barthelemy","iso2":"BL","iso3":"BLM","phoneCode":"590"},{"countryName":"Saint Helena","iso2":"SH","iso3":"SHN","phoneCode":"290"},{"countryName":"Saint Kitts and Nevis","iso2":"KN","iso3":"KNA","phoneCode":"1 869"},{"countryName":"Saint Lucia","iso2":"LC","iso3":"LCA","phoneCode":"1 758"},{"countryName":"Saint Martin","iso2":"MF","iso3":"MAF","phoneCode":"1 599"},{"countryName":"Saint Pierre and Miquelon","iso2":"PM","iso3":"SPM","phoneCode":"508"},{"countryName":"Saint Vincent and the Grenadines","iso2":"VC","iso3":"VCT","phoneCode":"1 784"},{"countryName":"Samoa","iso2":"WS","iso3":"WSM","phoneCode":"685"},{"countryName":"San Marino","iso2":"SM","iso3":"SMR","phoneCode":"378"},{"countryName":"Sao Tome and Principe","iso2":"ST","iso3":"STP","phoneCode":"239"},{"countryName":"Saudi Arabia","iso2":"SA","iso3":"SAU","phoneCode":"966"},{"countryName":"Senegal","iso2":"SN","iso3":"SEN","phoneCode":"221"},{"countryName":"Serbia","iso2":"RS","iso3":"SRB","phoneCode":"381"},{"countryName":"Seychelles","iso2":"SC","iso3":"SYC","phoneCode":"248"},{"countryName":"Sierra Leone","iso2":"SL","iso3":"SLE","phoneCode":"232"},{"countryName":"Singapore","iso2":"SG","iso3":"SGP","phoneCode":"65"},{"countryName":"Slovakia","iso2":"SK","iso3":"SVK","phoneCode":"421"},{"countryName":"Slovenia","iso2":"SI","iso3":"SVN","phoneCode":"386"},{"countryName":"Solomon Islands","iso2":"SB","iso3":"SLB","phoneCode":"677"},{"countryName":"Somalia","iso2":"SO","iso3":"SOM","phoneCode":"252"},{"countryName":"South Africa","iso2":"ZA","iso3":"ZAF","phoneCode":"27"},{"countryName":"South Korea","iso2":"KR","iso3":"KOR","phoneCode":"82"},{"countryName":"Spain","iso2":"ES","iso3":"ESP","phoneCode":"34"},{"countryName":"Sri Lanka","iso2":"LK","iso3":"LKA","phoneCode":"94"},{"countryName":"Sudan","iso2":"SD","iso3":"SDN","phoneCode":"249"},{"countryName":"Suriname","iso2":"SR","iso3":"SUR","phoneCode":"597"},{"countryName":"Svalbard","iso2":"SJ","iso3":"SJM","phoneCode":""},{"countryName":"Swaziland","iso2":"SZ","iso3":"SWZ","phoneCode":"268"},{"countryName":"Sweden","iso2":"SE","iso3":"SWE","phoneCode":"46"},{"countryName":"Switzerland","iso2":"CH","iso3":"CHE","phoneCode":"41"},{"countryName":"Syria","iso2":"SY","iso3":"SYR","phoneCode":"963"},{"countryName":"Taiwan","iso2":"TW","iso3":"TWN","phoneCode":"886"},{"countryName":"Tajikistan","iso2":"TJ","iso3":"TJK","phoneCode":"992"},{"countryName":"Tanzania","iso2":"TZ","iso3":"TZA","phoneCode":"255"},{"countryName":"Thailand","iso2":"TH","iso3":"THA","phoneCode":"66"},{"countryName":"Timor-Leste","iso2":"TL","iso3":"TLS","phoneCode":"670"},{"countryName":"Togo","iso2":"TG","iso3":"TGO","phoneCode":"228"},{"countryName":"Tokelau","iso2":"TK","iso3":"TKL","phoneCode":"690"},{"countryName":"Tonga","iso2":"TO","iso3":"TON","phoneCode":"676"},{"countryName":"Trinidad and Tobago","iso2":"TT","iso3":"TTO","phoneCode":"1 868"},{"countryName":"Tunisia","iso2":"TN","iso3":"TUN","phoneCode":"216"},{"countryName":"Turkey","iso2":"TR","iso3":"TUR","phoneCode":"90"},{"countryName":"Turkmenistan","iso2":"TM","iso3":"TKM","phoneCode":"993"},{"countryName":"Turks and Caicos Islands","iso2":"TC","iso3":"TCA","phoneCode":"1 649"},{"countryName":"Tuvalu","iso2":"TV","iso3":"TUV","phoneCode":"688"},{"countryName":"Uganda","iso2":"UG","iso3":"UGA","phoneCode":"256"},{"countryName":"Ukraine","iso2":"UA","iso3":"UKR","phoneCode":"380"},{"countryName":"United Arab Emirates","iso2":"AE","iso3":"ARE","phoneCode":"971"},{"countryName":"United Kingdom","iso2":"GB","iso3":"GBR","phoneCode":"44"},{"countryName":"United States","iso2":"US","iso3":"USA","phoneCode":"1"},{"countryName":"Uruguay","iso2":"UY","iso3":"URY","phoneCode":"598"},{"countryName":"US Virgin Islands","iso2":"VI","iso3":"VIR","phoneCode":"1 340"},{"countryName":"Uzbekistan","iso2":"UZ","iso3":"UZB","phoneCode":"998"},{"countryName":"Vanuatu","iso2":"VU","iso3":"VUT","phoneCode":"678"},{"countryName":"Venezuela","iso2":"VE","iso3":"VEN","phoneCode":"58"},{"countryName":"Vietnam","iso2":"VN","iso3":"VNM","phoneCode":"84"},{"countryName":"Wallis and Futuna","iso2":"WF","iso3":"WLF","phoneCode":"681"},{"countryName":"West Bank","iso2":"","iso3":"","phoneCode":"970"},{"countryName":"Western Sahara","iso2":"EH","iso3":"ESH","phoneCode":""},{"countryName":"Yemen","iso2":"YE","iso3":"YEM","phoneCode":"967"},{"countryName":"Zambia","iso2":"ZM","iso3":"ZMB","phoneCode":"260"},{"countryName":"Zimbabwe","iso2":"ZW","iso3":"ZWE","phoneCode":"263"}];

CountryCodes.lookupByIso2 = function(iso2){
   var term = iso2.toUpperCase();
    return _.find(CountriesData, function(c){
      return c.iso2 === term;
    });
 };
 CountryCodes.lookupByName = function(name){
   var term = name.toUpperCase();
    return _.find(CountriesData, function(c){
      return c.countrName.toUpperCase() === term;
    });
 };
 windowScope.CountryCodes = CountryCodes;
 
})(window);

var LocationTool = window.LocationTool || {};
 /** 
  Sample:
  
  {
  "address_components": [
    {
      "long_name": "112",
      "short_name": "112",
      "types": [
        "street_number"
      ]
    },
    {
      "long_name": "Essex Ave",
      "short_name": "Essex Ave",
      "types": [
        "route"
      ]
    },
    {
      "long_name": "Altamonte Springs",
      "short_name": "Altamonte Springs",
      "types": [
        "locality",
        "political"
      ]
    },
    {
      "long_name": "Seminole County",
      "short_name": "Seminole County",
      "types": [
        "administrative_area_level_2",
        "political"
      ]
    },
    {
      "long_name": "Florida",
      "short_name": "FL",
      "types": [
        "administrative_area_level_1",
        "political"
      ]
    },
    {
      "long_name": "United States",
      "short_name": "US",
      "types": [
        "country",
        "political"
      ]
    },
    {
      "long_name": "32701",
      "short_name": "32701",
      "types": [
        "postal_code"
      ]
    }
  ],
  "adr_address": "<span class=\"street-address\">112 Essex Ave</span>, <span class=\"locality\">Altamonte Springs</span>, <span class=\"region\">FL</span> <span class=\"postal-code\">32701</span>, <span class=\"country-name\">USA</span>",
  "formatted_address": "112 Essex Ave, Altamonte Springs, FL 32701, USA",
  "geometry": {
    "location": {
      "k": 28.661897,
      "D": -81.37717079999999
    }
  },
  "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
  "id": "c80e155495b3ede2f0f51296ac1fa7723d57ed58",
  "name": "112 Essex Ave",
  "place_id": "ChIJ_YTM6ptx54gReL7n0g0mlzE",
  "reference": "CqQBkwAAAM3kppTQPZ4VBphiY-0iWd26bg9ObnmsNv8nkP9qpETsmn3mlQGVLPYnff7okZC6waB8f79ck1ECbZgTscozhEW68MVTsdpi-t5BsANPOlq1hBO6gtXcJIZgRTiU5JzqWCvrg4_u15FhMmTWnu3g8Q9h6-rnKreif2jIcfZ05F3iWo6Vyv3sxTG-iDwh3_-tPO1qDapfam_RCp9PgJXBINkSEJ7l3HaYLt6-XTSS4xQFIWYaFK9UY8xWIimwdKCkksH5BUbcXf5n",
  "scope": "GOOGLE",
  "types": [
    "street_address"
  ],
  "url": "https://maps.google.com/maps/place?q=112+Essex+Ave,+Altamonte+Springs,+FL+32701,+USA&ftid=0x88e7719beacc84fd:0x3197260dd2e7be78",
  "vicinity": "Altamonte Springs",
  "html_attributions": []
}
  
  **/

(function(){
 
 
  function PostalAddress(data) {
      var that = this;
      data = data || {};
      var raw = $.extend({}, data);
      that.getRaw = function(){
        return raw;
      };
      that.data = that.parseData(data);
      that.preMapped = _.clone(that.data.preMapped);
      delete that.data.preMapped;
  }
  
  function hasAll(haystack, items){
    for (var k=0;k<items.length;k++){
        if (haystack.indexOf(items[k]) === -1) {
           return false;
        }
    }
    return true;
    
  }
  
  PostalAddress.findCountry = function(iso2) {
    var defer = $.Deferred();
    var match = window.CountryCodes.lookupByIso2(iso2);
    if (match === undefined) {
         defer.reject({message: 'COULD NOT FIND COUNTRY'});
    }
    else {
        defer.resolve(match);
    }
    return defer.promise();
  };
  PostalAddress.extractCountry = function(address){
    var iso2 = address.get('country', false);
    return PostalAddress.findCountry(iso2);
  };
  PostalAddress.typeMapper =  [
      {types: ['postal_code'], prop: 'postalCode'},
      {types: ['country','political'], prop: 'country'},
      {types: ["administrative_area_level_1","political"], prop: 'state'},
      {types: ["administrative_area_level_2","political"], prop: 'county'},
      {types: [ ["neighborhood","political"], ["locality","political"]], prop: 'city'},
      {types: ["route"], prop: '_streetName'},
      {types: ["street_number"], prop: '_streetNumber'}
    ];
    

  PostalAddress.builder = function(mapped,cnts){
    var preMapped = {};
    cnts = cnts || {};
     var out = {};
     out.preMapped = mapped;
    _.each(mapped, function(v,k){
      if (v) {
        preMapped[v.prop] = v;
        if (v.prop.indexOf("_") !== 0) {
          if (cnts.hasOwnProperty(v.prop) && v.data.matchPosition === cnts[v.prop] ){
            out[v.prop] = v;
          }
          else if (!cnts.hasOwnProperty(v.prop)){
            out[v.prop] = v;
          }
        }
      }
    });
    var street = preMapped._streetNumber || null;
    if (street) {
      street = street.value.trim();
    }
    var streetName = preMapped._streetName || null;
    if (streetName) {
      streetName = streetName.value.trim();
    }
    out.address1 = {'prop': 'address1',  'value':  (street + " " +  streetName).trim() , data: [preMapped._streetNumber, preMapped._streetName] };
    return out;
  };
    
  PostalAddress.componentMapper = function(component){
    var out = false;
   
    function findPropName(){
        for(var i=0; i<PostalAddress.typeMapper.length;i++){
          var theTypes = PostalAddress.typeMapper[i].types;
          var typeChecks = [theTypes];
          if (_.isArray(PostalAddress.typeMapper[i].types[0])){
              typeChecks = _.clone(theTypes);
          }
          for(var n=0; n<typeChecks.length; n++){
            if (hasAll(typeChecks[n], component.types )){
                return {position: n, prop: PostalAddress.typeMapper[i].prop};
            }
          }
          
        }
        return false;
    }
    
    var propName = findPropName();
    if (propName) {
      out = {
         prop: propName.prop, 
         value: component.short_name, 
         data: {
            long_name: component.long_name, 
            short_name: component.short_name, 
            types: component.types,
            matchPosition: propName.position
          }
      };
    }
    return out;
  };
  
  PostalAddress.prototype.parseData = function(data) {
     var cnts = {};
     var theData = _.map(data.address_components, function(v,k){
          var theResult = PostalAddress.componentMapper(v);
          if (theResult) {
            if (!cnts.hasOwnProperty(theResult.prop)) {
              cnts[theResult.prop] = 0;
            }
            cnts[theResult.prop] = Math.min(cnts[theResult.prop], theResult.data.matchPosition) ;
          }
          return theResult;
    });
    
    
     return PostalAddress.builder( 
         _.filter(theData), cnts
    );
  };
  
  PostalAddress.prototype.location = function(){
    var loc = this.getRaw().geometry.location;
    var out = {lat: loc.k, lng: loc.D};
    return out;
  };
  
  PostalAddress.prototype.toArray = function(full){
    var out = {};
    full = full || false;
    var that = this;
    var defer = $.Deferred();
    $.each(that.data, function(k,v){
        out[k] = v.value;
    });
    
    var geo = that.location();
    out.latitude = geo.lat;
    out.longitude = geo.lng;
    out.place_id = that.get('place_id');
    out.formatted = that.get('formatted_address');
    out.url = that.get('url');
    if (full) {
      out._raw = that.getRaw();
      out.preMapped = that.preMapped;
    }
   
    PostalAddress.extractCountry(that)
    .then(function(country){
     var theState = that.get('state', true, true);
      out.country = $.extend({}, country);
        out.country.name = country.countryName;
        delete out.country.countryName;
        delete out.country.phoneCode;
        if (theState){
          out.state = {'name': theState.value_long, 'code': theState.value, country: out.country };
        }  
      defer.resolve(out);
    }).fail(function(res){
      defer.resolve(out);
    });
    
    
    return defer.promise();
  };
  
  PostalAddress.prototype.get = function(fieldName, full,nonRecursive){
     full = full || false;
     nonRecursive = nonRecursive || false;
     var that = this;
     if (!that.data.hasOwnProperty(fieldName)){
       return that.getRaw()[fieldName];
     }
     else {
     if (!full) {
       return this.data[fieldName].value;
     }
     else {
        var out = { 'field': fieldName, value: this.data[fieldName].value, value_long: that.data[fieldName].data.long_name, related: {} }; 
        if (!nonRecursive) {
          switch(fieldName) {
            case 'postalCode': 
              out.related.state = that.get('state', true, true);
              out.related.country = that.get('country', true, true);
              break;
            case 'state':
              out.related.country = that.get('country', true, true);
              break;
            case 'city':
              out.related.postalCode = that.get('postalCode', true, true);
              out.related.state = that.get('state', true, true);
              out.related.country = that.get('country', true, true);
              break;
            default:
              break;
          }
        }
        return out;
     }
     
     }
  };
  
  PostalAddress.prototype.gettableFields = function(full) {
    full = full || false;
    var lst = _.keys(this.data);
    lst.sort();
    if (full) {
       var fullLst = [];
        _.each(this.getRaw(), function(v,k){
          fullLst.push(k);
        })
        fullLst.sort();
        lst = {basic: lst, raw: fullLst};
    }
    return lst;
  };
  
  LocationTool.Address = PostalAddress;
  
})()
var CountryCodes = window.CountryCodes || {};
(function(windowScope){
var CountriesData = [{"countryName":"Afghanistan","iso2":"AF","iso3":"AFG","phoneCode":"93"},{"countryName":"Albania","iso2":"AL","iso3":"ALB","phoneCode":"355"},{"countryName":"Algeria","iso2":"DZ","iso3":"DZA","phoneCode":"213"},{"countryName":"American Samoa","iso2":"AS","iso3":"ASM","phoneCode":"1 684"},{"countryName":"Andorra","iso2":"AD","iso3":"AND","phoneCode":"376"},{"countryName":"Angola","iso2":"AO","iso3":"AGO","phoneCode":"244"},{"countryName":"Anguilla","iso2":"AI","iso3":"AIA","phoneCode":"1 264"},{"countryName":"Antarctica","iso2":"AQ","iso3":"ATA","phoneCode":"672"},{"countryName":"Antigua and Barbuda","iso2":"AG","iso3":"ATG","phoneCode":"1 268"},{"countryName":"Argentina","iso2":"AR","iso3":"ARG","phoneCode":"54"},{"countryName":"Armenia","iso2":"AM","iso3":"ARM","phoneCode":"374"},{"countryName":"Aruba","iso2":"AW","iso3":"ABW","phoneCode":"297"},{"countryName":"Australia","iso2":"AU","iso3":"AUS","phoneCode":"61"},{"countryName":"Austria","iso2":"AT","iso3":"AUT","phoneCode":"43"},{"countryName":"Azerbaijan","iso2":"AZ","iso3":"AZE","phoneCode":"994"},{"countryName":"Bahamas","iso2":"BS","iso3":"BHS","phoneCode":"1 242"},{"countryName":"Bahrain","iso2":"BH","iso3":"BHR","phoneCode":"973"},{"countryName":"Bangladesh","iso2":"BD","iso3":"BGD","phoneCode":"880"},{"countryName":"Barbados","iso2":"BB","iso3":"BRB","phoneCode":"1 246"},{"countryName":"Belarus","iso2":"BY","iso3":"BLR","phoneCode":"375"},{"countryName":"Belgium","iso2":"BE","iso3":"BEL","phoneCode":"32"},{"countryName":"Belize","iso2":"BZ","iso3":"BLZ","phoneCode":"501"},{"countryName":"Benin","iso2":"BJ","iso3":"BEN","phoneCode":"229"},{"countryName":"Bermuda","iso2":"BM","iso3":"BMU","phoneCode":"1 441"},{"countryName":"Bhutan","iso2":"BT","iso3":"BTN","phoneCode":"975"},{"countryName":"Bolivia","iso2":"BO","iso3":"BOL","phoneCode":"591"},{"countryName":"Bosnia and Herzegovina","iso2":"BA","iso3":"BIH","phoneCode":"387"},{"countryName":"Botswana","iso2":"BW","iso3":"BWA","phoneCode":"267"},{"countryName":"Brazil","iso2":"BR","iso3":"BRA","phoneCode":"55"},{"countryName":"British Indian Ocean Territory","iso2":"IO","iso3":"IOT","phoneCode":""},{"countryName":"British Virgin Islands","iso2":"VG","iso3":"VGB","phoneCode":"1 284"},{"countryName":"Brunei","iso2":"BN","iso3":"BRN","phoneCode":"673"},{"countryName":"Bulgaria","iso2":"BG","iso3":"BGR","phoneCode":"359"},{"countryName":"Burkina Faso","iso2":"BF","iso3":"BFA","phoneCode":"226"},{"countryName":"Burma (Myanmar)","iso2":"MM","iso3":"MMR","phoneCode":"95"},{"countryName":"Burundi","iso2":"BI","iso3":"BDI","phoneCode":"257"},{"countryName":"Cambodia","iso2":"KH","iso3":"KHM","phoneCode":"855"},{"countryName":"Cameroon","iso2":"CM","iso3":"CMR","phoneCode":"237"},{"countryName":"Canada","iso2":"CA","iso3":"CAN","phoneCode":"1"},{"countryName":"Cape Verde","iso2":"CV","iso3":"CPV","phoneCode":"238"},{"countryName":"Cayman Islands","iso2":"KY","iso3":"CYM","phoneCode":"1 345"},{"countryName":"Central African Republic","iso2":"CF","iso3":"CAF","phoneCode":"236"},{"countryName":"Chad","iso2":"TD","iso3":"TCD","phoneCode":"235"},{"countryName":"Chile","iso2":"CL","iso3":"CHL","phoneCode":"56"},{"countryName":"China","iso2":"CN","iso3":"CHN","phoneCode":"86"},{"countryName":"Christmas Island","iso2":"CX","iso3":"CXR","phoneCode":"61"},{"countryName":"Cocos (Keeling) Islands","iso2":"CC","iso3":"CCK","phoneCode":"61"},{"countryName":"Colombia","iso2":"CO","iso3":"COL","phoneCode":"57"},{"countryName":"Comoros","iso2":"KM","iso3":"COM","phoneCode":"269"},{"countryName":"Cook Islands","iso2":"CK","iso3":"COK","phoneCode":"682"},{"countryName":"Costa Rica","iso2":"CR","iso3":"CRC","phoneCode":"506"},{"countryName":"Croatia","iso2":"HR","iso3":"HRV","phoneCode":"385"},{"countryName":"Cuba","iso2":"CU","iso3":"CUB","phoneCode":"53"},{"countryName":"Cyprus","iso2":"CY","iso3":"CYP","phoneCode":"357"},{"countryName":"Czech Republic","iso2":"CZ","iso3":"CZE","phoneCode":"420"},{"countryName":"Democratic Republic of the Congo","iso2":"CD","iso3":"COD","phoneCode":"243"},{"countryName":"Denmark","iso2":"DK","iso3":"DNK","phoneCode":"45"},{"countryName":"Djibouti","iso2":"DJ","iso3":"DJI","phoneCode":"253"},{"countryName":"Dominica","iso2":"DM","iso3":"DMA","phoneCode":"1 767"},{"countryName":"Dominican Republic","iso2":"DO","iso3":"DOM","phoneCode":"1 809"},{"countryName":"Ecuador","iso2":"EC","iso3":"ECU","phoneCode":"593"},{"countryName":"Egypt","iso2":"EG","iso3":"EGY","phoneCode":"20"},{"countryName":"El Salvador","iso2":"SV","iso3":"SLV","phoneCode":"503"},{"countryName":"Equatorial Guinea","iso2":"GQ","iso3":"GNQ","phoneCode":"240"},{"countryName":"Eritrea","iso2":"ER","iso3":"ERI","phoneCode":"291"},{"countryName":"Estonia","iso2":"EE","iso3":"EST","phoneCode":"372"},{"countryName":"Ethiopia","iso2":"ET","iso3":"ETH","phoneCode":"251"},{"countryName":"Falkland Islands","iso2":"FK","iso3":"FLK","phoneCode":"500"},{"countryName":"Faroe Islands","iso2":"FO","iso3":"FRO","phoneCode":"298"},{"countryName":"Fiji","iso2":"FJ","iso3":"FJI","phoneCode":"679"},{"countryName":"Finland","iso2":"FI","iso3":"FIN","phoneCode":"358"},{"countryName":"France","iso2":"FR","iso3":"FRA","phoneCode":"33"},{"countryName":"French Polynesia","iso2":"PF","iso3":"PYF","phoneCode":"689"},{"countryName":"Gabon","iso2":"GA","iso3":"GAB","phoneCode":"241"},{"countryName":"Gambia","iso2":"GM","iso3":"GMB","phoneCode":"220"},{"countryName":"Gaza Strip","iso2":"","iso3":"","phoneCode":"970"},{"countryName":"Georgia","iso2":"GE","iso3":"GEO","phoneCode":"995"},{"countryName":"Germany","iso2":"DE","iso3":"DEU","phoneCode":"49"},{"countryName":"Ghana","iso2":"GH","iso3":"GHA","phoneCode":"233"},{"countryName":"Gibraltar","iso2":"GI","iso3":"GIB","phoneCode":"350"},{"countryName":"Greece","iso2":"GR","iso3":"GRC","phoneCode":"30"},{"countryName":"Greenland","iso2":"GL","iso3":"GRL","phoneCode":"299"},{"countryName":"Grenada","iso2":"GD","iso3":"GRD","phoneCode":"1 473"},{"countryName":"Guam","iso2":"GU","iso3":"GUM","phoneCode":"1 671"},{"countryName":"Guatemala","iso2":"GT","iso3":"GTM","phoneCode":"502"},{"countryName":"Guinea","iso2":"GN","iso3":"GIN","phoneCode":"224"},{"countryName":"Guinea-Bissau","iso2":"GW","iso3":"GNB","phoneCode":"245"},{"countryName":"Guyana","iso2":"GY","iso3":"GUY","phoneCode":"592"},{"countryName":"Haiti","iso2":"HT","iso3":"HTI","phoneCode":"509"},{"countryName":"Holy See (Vatican City)","iso2":"VA","iso3":"VAT","phoneCode":"39"},{"countryName":"Honduras","iso2":"HN","iso3":"HND","phoneCode":"504"},{"countryName":"Hong Kong","iso2":"HK","iso3":"HKG","phoneCode":"852"},{"countryName":"Hungary","iso2":"HU","iso3":"HUN","phoneCode":"36"},{"countryName":"Iceland","iso2":"IS","iso3":"IS","phoneCode":"354"},{"countryName":"India","iso2":"IN","iso3":"IND","phoneCode":"91"},{"countryName":"Indonesia","iso2":"ID","iso3":"IDN","phoneCode":"62"},{"countryName":"Iran","iso2":"IR","iso3":"IRN","phoneCode":"98"},{"countryName":"Iraq","iso2":"IQ","iso3":"IRQ","phoneCode":"964"},{"countryName":"Ireland","iso2":"IE","iso3":"IRL","phoneCode":"353"},{"countryName":"Isle of Man","iso2":"IM","iso3":"IMN","phoneCode":"44"},{"countryName":"Israel","iso2":"IL","iso3":"ISR","phoneCode":"972"},{"countryName":"Italy","iso2":"IT","iso3":"ITA","phoneCode":"39"},{"countryName":"Ivory Coast","iso2":"CI","iso3":"CIV","phoneCode":"225"},{"countryName":"Jamaica","iso2":"JM","iso3":"JAM","phoneCode":"1 876"},{"countryName":"Japan","iso2":"JP","iso3":"JPN","phoneCode":"81"},{"countryName":"Jersey","iso2":"JE","iso3":"JEY","phoneCode":""},{"countryName":"Jordan","iso2":"JO","iso3":"JOR","phoneCode":"962"},{"countryName":"Kazakhstan","iso2":"KZ","iso3":"KAZ","phoneCode":"7"},{"countryName":"Kenya","iso2":"KE","iso3":"KEN","phoneCode":"254"},{"countryName":"Kiribati","iso2":"KI","iso3":"KIR","phoneCode":"686"},{"countryName":"Kosovo","iso2":"","iso3":"","phoneCode":"381"},{"countryName":"Kuwait","iso2":"KW","iso3":"KWT","phoneCode":"965"},{"countryName":"Kyrgyzstan","iso2":"KG","iso3":"KGZ","phoneCode":"996"},{"countryName":"Laos","iso2":"LA","iso3":"LAO","phoneCode":"856"},{"countryName":"Latvia","iso2":"LV","iso3":"LVA","phoneCode":"371"},{"countryName":"Lebanon","iso2":"LB","iso3":"LBN","phoneCode":"961"},{"countryName":"Lesotho","iso2":"LS","iso3":"LSO","phoneCode":"266"},{"countryName":"Liberia","iso2":"LR","iso3":"LBR","phoneCode":"231"},{"countryName":"Libya","iso2":"LY","iso3":"LBY","phoneCode":"218"},{"countryName":"Liechtenstein","iso2":"LI","iso3":"LIE","phoneCode":"423"},{"countryName":"Lithuania","iso2":"LT","iso3":"LTU","phoneCode":"370"},{"countryName":"Luxembourg","iso2":"LU","iso3":"LUX","phoneCode":"352"},{"countryName":"Macau","iso2":"MO","iso3":"MAC","phoneCode":"853"},{"countryName":"Macedonia","iso2":"MK","iso3":"MKD","phoneCode":"389"},{"countryName":"Madagascar","iso2":"MG","iso3":"MDG","phoneCode":"261"},{"countryName":"Malawi","iso2":"MW","iso3":"MWI","phoneCode":"265"},{"countryName":"Malaysia","iso2":"MY","iso3":"MYS","phoneCode":"60"},{"countryName":"Maldives","iso2":"MV","iso3":"MDV","phoneCode":"960"},{"countryName":"Mali","iso2":"ML","iso3":"MLI","phoneCode":"223"},{"countryName":"Malta","iso2":"MT","iso3":"MLT","phoneCode":"356"},{"countryName":"Marshall Islands","iso2":"MH","iso3":"MHL","phoneCode":"692"},{"countryName":"Mauritania","iso2":"MR","iso3":"MRT","phoneCode":"222"},{"countryName":"Mauritius","iso2":"MU","iso3":"MUS","phoneCode":"230"},{"countryName":"Mayotte","iso2":"YT","iso3":"MYT","phoneCode":"262"},{"countryName":"Mexico","iso2":"MX","iso3":"MEX","phoneCode":"52"},{"countryName":"Micronesia","iso2":"FM","iso3":"FSM","phoneCode":"691"},{"countryName":"Moldova","iso2":"MD","iso3":"MDA","phoneCode":"373"},{"countryName":"Monaco","iso2":"MC","iso3":"MCO","phoneCode":"377"},{"countryName":"Mongolia","iso2":"MN","iso3":"MNG","phoneCode":"976"},{"countryName":"Montenegro","iso2":"ME","iso3":"MNE","phoneCode":"382"},{"countryName":"Montserrat","iso2":"MS","iso3":"MSR","phoneCode":"1 664"},{"countryName":"Morocco","iso2":"MA","iso3":"MAR","phoneCode":"212"},{"countryName":"Mozambique","iso2":"MZ","iso3":"MOZ","phoneCode":"258"},{"countryName":"Namibia","iso2":"NA","iso3":"NAM","phoneCode":"264"},{"countryName":"Nauru","iso2":"NR","iso3":"NRU","phoneCode":"674"},{"countryName":"Nepal","iso2":"NP","iso3":"NPL","phoneCode":"977"},{"countryName":"Netherlands","iso2":"NL","iso3":"NLD","phoneCode":"31"},{"countryName":"Netherlands Antilles","iso2":"AN","iso3":"ANT","phoneCode":"599"},{"countryName":"New Caledonia","iso2":"NC","iso3":"NCL","phoneCode":"687"},{"countryName":"New Zealand","iso2":"NZ","iso3":"NZL","phoneCode":"64"},{"countryName":"Nicaragua","iso2":"NI","iso3":"NIC","phoneCode":"505"},{"countryName":"Niger","iso2":"NE","iso3":"NER","phoneCode":"227"},{"countryName":"Nigeria","iso2":"NG","iso3":"NGA","phoneCode":"234"},{"countryName":"Niue","iso2":"NU","iso3":"NIU","phoneCode":"683"},{"countryName":"Norfolk Island","iso2":"","iso3":"NFK","phoneCode":"672"},{"countryName":"North Korea","iso2":"KP","iso3":"PRK","phoneCode":"850"},{"countryName":"Northern Mariana Islands","iso2":"MP","iso3":"MNP","phoneCode":"1 670"},{"countryName":"Norway","iso2":"NO","iso3":"NOR","phoneCode":"47"},{"countryName":"Oman","iso2":"OM","iso3":"OMN","phoneCode":"968"},{"countryName":"Pakistan","iso2":"PK","iso3":"PAK","phoneCode":"92"},{"countryName":"Palau","iso2":"PW","iso3":"PLW","phoneCode":"680"},{"countryName":"Panama","iso2":"PA","iso3":"PAN","phoneCode":"507"},{"countryName":"Papua New Guinea","iso2":"PG","iso3":"PNG","phoneCode":"675"},{"countryName":"Paraguay","iso2":"PY","iso3":"PRY","phoneCode":"595"},{"countryName":"Peru","iso2":"PE","iso3":"PER","phoneCode":"51"},{"countryName":"Philippines","iso2":"PH","iso3":"PHL","phoneCode":"63"},{"countryName":"Pitcairn Islands","iso2":"PN","iso3":"PCN","phoneCode":"870"},{"countryName":"Poland","iso2":"PL","iso3":"POL","phoneCode":"48"},{"countryName":"Portugal","iso2":"PT","iso3":"PRT","phoneCode":"351"},{"countryName":"Puerto Rico","iso2":"PR","iso3":"PRI","phoneCode":"1"},{"countryName":"Qatar","iso2":"QA","iso3":"QAT","phoneCode":"974"},{"countryName":"Republic of the Congo","iso2":"CG","iso3":"COG","phoneCode":"242"},{"countryName":"Romania","iso2":"RO","iso3":"ROU","phoneCode":"40"},{"countryName":"Russia","iso2":"RU","iso3":"RUS","phoneCode":"7"},{"countryName":"Rwanda","iso2":"RW","iso3":"RWA","phoneCode":"250"},{"countryName":"Saint Barthelemy","iso2":"BL","iso3":"BLM","phoneCode":"590"},{"countryName":"Saint Helena","iso2":"SH","iso3":"SHN","phoneCode":"290"},{"countryName":"Saint Kitts and Nevis","iso2":"KN","iso3":"KNA","phoneCode":"1 869"},{"countryName":"Saint Lucia","iso2":"LC","iso3":"LCA","phoneCode":"1 758"},{"countryName":"Saint Martin","iso2":"MF","iso3":"MAF","phoneCode":"1 599"},{"countryName":"Saint Pierre and Miquelon","iso2":"PM","iso3":"SPM","phoneCode":"508"},{"countryName":"Saint Vincent and the Grenadines","iso2":"VC","iso3":"VCT","phoneCode":"1 784"},{"countryName":"Samoa","iso2":"WS","iso3":"WSM","phoneCode":"685"},{"countryName":"San Marino","iso2":"SM","iso3":"SMR","phoneCode":"378"},{"countryName":"Sao Tome and Principe","iso2":"ST","iso3":"STP","phoneCode":"239"},{"countryName":"Saudi Arabia","iso2":"SA","iso3":"SAU","phoneCode":"966"},{"countryName":"Senegal","iso2":"SN","iso3":"SEN","phoneCode":"221"},{"countryName":"Serbia","iso2":"RS","iso3":"SRB","phoneCode":"381"},{"countryName":"Seychelles","iso2":"SC","iso3":"SYC","phoneCode":"248"},{"countryName":"Sierra Leone","iso2":"SL","iso3":"SLE","phoneCode":"232"},{"countryName":"Singapore","iso2":"SG","iso3":"SGP","phoneCode":"65"},{"countryName":"Slovakia","iso2":"SK","iso3":"SVK","phoneCode":"421"},{"countryName":"Slovenia","iso2":"SI","iso3":"SVN","phoneCode":"386"},{"countryName":"Solomon Islands","iso2":"SB","iso3":"SLB","phoneCode":"677"},{"countryName":"Somalia","iso2":"SO","iso3":"SOM","phoneCode":"252"},{"countryName":"South Africa","iso2":"ZA","iso3":"ZAF","phoneCode":"27"},{"countryName":"South Korea","iso2":"KR","iso3":"KOR","phoneCode":"82"},{"countryName":"Spain","iso2":"ES","iso3":"ESP","phoneCode":"34"},{"countryName":"Sri Lanka","iso2":"LK","iso3":"LKA","phoneCode":"94"},{"countryName":"Sudan","iso2":"SD","iso3":"SDN","phoneCode":"249"},{"countryName":"Suriname","iso2":"SR","iso3":"SUR","phoneCode":"597"},{"countryName":"Svalbard","iso2":"SJ","iso3":"SJM","phoneCode":""},{"countryName":"Swaziland","iso2":"SZ","iso3":"SWZ","phoneCode":"268"},{"countryName":"Sweden","iso2":"SE","iso3":"SWE","phoneCode":"46"},{"countryName":"Switzerland","iso2":"CH","iso3":"CHE","phoneCode":"41"},{"countryName":"Syria","iso2":"SY","iso3":"SYR","phoneCode":"963"},{"countryName":"Taiwan","iso2":"TW","iso3":"TWN","phoneCode":"886"},{"countryName":"Tajikistan","iso2":"TJ","iso3":"TJK","phoneCode":"992"},{"countryName":"Tanzania","iso2":"TZ","iso3":"TZA","phoneCode":"255"},{"countryName":"Thailand","iso2":"TH","iso3":"THA","phoneCode":"66"},{"countryName":"Timor-Leste","iso2":"TL","iso3":"TLS","phoneCode":"670"},{"countryName":"Togo","iso2":"TG","iso3":"TGO","phoneCode":"228"},{"countryName":"Tokelau","iso2":"TK","iso3":"TKL","phoneCode":"690"},{"countryName":"Tonga","iso2":"TO","iso3":"TON","phoneCode":"676"},{"countryName":"Trinidad and Tobago","iso2":"TT","iso3":"TTO","phoneCode":"1 868"},{"countryName":"Tunisia","iso2":"TN","iso3":"TUN","phoneCode":"216"},{"countryName":"Turkey","iso2":"TR","iso3":"TUR","phoneCode":"90"},{"countryName":"Turkmenistan","iso2":"TM","iso3":"TKM","phoneCode":"993"},{"countryName":"Turks and Caicos Islands","iso2":"TC","iso3":"TCA","phoneCode":"1 649"},{"countryName":"Tuvalu","iso2":"TV","iso3":"TUV","phoneCode":"688"},{"countryName":"Uganda","iso2":"UG","iso3":"UGA","phoneCode":"256"},{"countryName":"Ukraine","iso2":"UA","iso3":"UKR","phoneCode":"380"},{"countryName":"United Arab Emirates","iso2":"AE","iso3":"ARE","phoneCode":"971"},{"countryName":"United Kingdom","iso2":"GB","iso3":"GBR","phoneCode":"44"},{"countryName":"United States","iso2":"US","iso3":"USA","phoneCode":"1"},{"countryName":"Uruguay","iso2":"UY","iso3":"URY","phoneCode":"598"},{"countryName":"US Virgin Islands","iso2":"VI","iso3":"VIR","phoneCode":"1 340"},{"countryName":"Uzbekistan","iso2":"UZ","iso3":"UZB","phoneCode":"998"},{"countryName":"Vanuatu","iso2":"VU","iso3":"VUT","phoneCode":"678"},{"countryName":"Venezuela","iso2":"VE","iso3":"VEN","phoneCode":"58"},{"countryName":"Vietnam","iso2":"VN","iso3":"VNM","phoneCode":"84"},{"countryName":"Wallis and Futuna","iso2":"WF","iso3":"WLF","phoneCode":"681"},{"countryName":"West Bank","iso2":"","iso3":"","phoneCode":"970"},{"countryName":"Western Sahara","iso2":"EH","iso3":"ESH","phoneCode":""},{"countryName":"Yemen","iso2":"YE","iso3":"YEM","phoneCode":"967"},{"countryName":"Zambia","iso2":"ZM","iso3":"ZMB","phoneCode":"260"},{"countryName":"Zimbabwe","iso2":"ZW","iso3":"ZWE","phoneCode":"263"}];

CountryCodes.lookupByIso2 = function(iso2){
   var term = iso2.toUpperCase();
    return _.find(CountriesData, function(c){
      return c.iso2 === term;
    });
 };
 CountryCodes.lookupByName = function(name){
   var term = name.toUpperCase();
    return _.find(CountriesData, function(c){
      return c.countrName.toUpperCase() === term;
    });
 };
 windowScope.CountryCodes = CountryCodes;
 
})(window)