window.addEvent( 'domready', function() {
    if( typeof Autocompleter != 'undefined')
    {
        var completr = new Autocompleter.Request.HTML($('city'), '/ajax/city.xl', {
            'indicatorClass': 'autocompleter-loading',
            'maxChoices': 10,
            'width':400,
            minlength:2,
            autoSubmit:true,
            forceSelect:true,
            delay:400,
//            selectFirst:true,
            'injectChoice': function(choice) 
            {
                var text = choice.getFirst();
                var value = text.innerHTML;
                choice.inputValue = value;
                text.set('html', this.markQueryValue(value));
                this.addChoiceEvents(choice);
            }
        });
        completr.addEvent( 'select', function( e, s) 
        {
        });
        completr.addEvent( 'selection', function( e, s) 
        {
            $('cityId').value=s.id;
        });
    }
});


function selectChanged( el)
{
    if(el.value > 0)
    { 
        $('cityId').value=el.value;
        el.getParent().submit();
    }
    if( el.value == -1)
    { 
        $('cityholder').addClass( 'visible');
        $('city').focus();
    }
    else 
        $('cityholder').removeClass( 'visible');
    $( 'city').fireEvent( 'blur');
}
function checkBuyForm()
{
    value=$('cityId').value;
    if(  value && value > 0)
        return true;
    alert( 'Выберите город из списка или введите первые несколько букв города в поле "Другой город" и дождитесь появления подсказки. Если вашего города нет в списке - введите ближайший крупный город');
    return false;
}

function offerSelected( name, id, site, retail, partners, filial, txtId)
{
    if( $('type'))
        $('type').value = name;
    $('preview').set( 'class', 'p'+id);
    var className = '';
    if( site)
        className+='site ';
    if( retail)
        className+='retail ';
    if( partners)
        className+='partners ';
    if( filial)
        className+='filial ';
    $( 'variants').set( 'class', className);
    $( 'variants').addClass( txtId);
}
