$(document).ready(function(){
      $('input#zipcode').autocomplete({
            url:                    $.forumprofi.url('account/register/get-cities/', 'none'),
            dataType:               'html',
            minChars:               2,
            delay:                  20,
            cacheLength:            150,
            matchSubset:            true,
            matchCase:              false,
            matchContains:          false,
            mustMatch:              false,
            selectFirst:            false,
            extraParams:            {
                                          field:      'zipcode',
                                          country:    function() { return $('select#countryKey').val(); }
                                    },
            formatItem:             function(row, position, total, term) {
                                          eval('var object = ' + row + ';');
                                          
                                          return object.title;
                                    },
            formatResult:           function(data, position, total) {
                                          eval('var object = ' + data + ';');
                                          
                                          return object.zipcode;
                                    },
            multiple:               false,
            multipleSeparator:      ',',
            width:                  300,
            autoFill:               false,
            max:                    50,
            highlight:              function(value, term) {
                                          return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") +
                                                               ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<span style=\"font-weight: bold;\">$1</span>");
                                    },
            scroll:                 true,
            scrollHeight:           100
      }).autocomplete(
            'result',
            function(event, data) {
                  eval('var object = ' + data + ';');
                                          
                  $('input#city').val(object.city);
            }
      );
      
      $('input#city').autocomplete({
            url:                    $.forumprofi.url('account/register/get-cities/', 'none'),
            dataType:               'html',
            minChars:               2,
            delay:                  20,
            cacheLength:            150,
            matchSubset:            true,
            matchCase:              false,
            matchContains:          false,
            mustMatch:              false,
            selectFirst:            false,
            extraParams:            {
                                          field:      'title',
                                          country:    function() { return $('select#countryKey').val(); }
                                    },
            formatItem:             function(row, position, total, term) {
                                          eval('var object = ' + row + ';');
                                          
                                          return object.title;
                                    },
            formatResult:           function(data, position, total) {
                                          eval('var object = ' + data + ';');
                                          
                                          return object.city;
                                    },
            multiple:               false,
            multipleSeparator:      ',',
            width:                  300,
            autoFill:               false,
            max:                    50,
            highlight:              function(value, term) {
                                          return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") +
                                                               ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<span style=\"font-weight: bold;\">$1</span>");
                                    },
            scroll:                 true,
            scrollHeight:           100
      }).autocomplete(
            'result',
            function(event, data) {
                  eval('var object = ' + data + ';');
                                          
                  $('input#zipcode').val(object.zipcode);
            }
      );
      
      $('input#username').uacAttach(
            $.forumprofi.url('account/register/check-username/', 'none'),
            {
                  minimumLength:     3,
                  imagePath:         $.forumprofi.image('_general/jQuery/uac/') + '/',
                  imageTooLong:      'invalid.png',
                  imageInvalidChars: 'invalid.png',
                  imageBlacklisted:  'invalid.png'
            }
      );
      $('input#password_one').pscAttach({
            minimumLength: 6,
            imagePath:     $.forumprofi.image('_general/jQuery/psc/') + '/',
            imageShort:    'none'
      });
});
