


function zipcode(){
    var searchTimeout;
    var option;
    this.init = function(options){
        option = options;
        option.zipfield.observe("keyup", this.searchKeyUpEvent.bind(this, option));
    };

    this.searchKeyUpEvent = function(option){
        zipcode = option.zipfield.value;
        if (searchTimeout) window.clearTimeout(searchTimeout);
        searchTimeout = window.setTimeout(option.jself + ".requestCityByZipCode('" + zipcode + "')",500);
    };

    this.requestCityByZipCode = function(zip){
        if (zip != ""){
            new Ajax.Request("/ajax/resolve-zip/?zip=" + zip + "&self=" + option.jself, {
                method: 'get',
                onSuccess: function(transport) {
                    eval(transport.responseText);
                }
            });
        }
    };

    this.responseCityName = function(cityObj){
        option.outputfield.update(" ");
        cityObj.each(function(city){
            optionField = new Element("option", { 'value' : city }).update(city);
            option.outputfield.appendChild(optionField);

        }.bind(this));
        camaoFormValidationObj.checkValid(option.outputfield);
    };

}

