var AutoSite = Class.create( NetDirector, {

    initialize: function () {
    },


    ajaxGetSiteDetails: function ( combo, selectedId ) {

        new Ajax.Request( this.ajaxURL, {
            method:            this.ajaxMethod,
            parameters:        'type=jsonGetSiteDetails',
            onSuccess:        ( function ( r ) {

                this.jsonPopulateSelect({
                	combo: combo,
                    data: r.responseText,
                    labelField: 'site_name',
                    selectedId: selectedId,
                    valueField: 'id'
                });

            }).bind(this)
        });

    },


    ajaxGetSiteLocations: function ( combo, selectedId ) {

        new Ajax.Request( this.ajaxURL, {
            method:            this.ajaxMethod,
            parameters:        'type=jsonGetSiteLocations',
            onSuccess:        ( function ( r ) {

                this.jsonPopulateSelect({
                	combo: combo,
                    data: r.responseText,
                    labelField: 'name',
                    selectedId: selectedId,
                    valueField: 'id'
                });

            }).bind(this)
        });

    },


    cbGetModels: function ( list ) {

    	var field = $('model');

    	this.emptySelect( field, {keepFirst:true} );

    	for ( var i = 0; i < list.models.length; i++ ) {
			field.options[field.options.length] = new Option( list.models[i].model, list.models[i].model.toUpperCase() );
		}

	},


    cbPopulateAutoSearchForm: function ( search ) {

    	this.getModels( search.marqueDetailId );

    	this.populateForm( 'frmUsedCarSearch', {delay:0.5, fields:search} );

	},


	getModels: function ( marqueId ) {

		this.xhr({
			callback: 'cbGetModels',
			parameters: 'id=' + marqueId + '&doAdvancedSearch=' + $F('doAdvancedSearch') + '&groupBy=model',
			type: 'getModelsJson'
		});

	},


    populateAutoSearchForm: function () {

		this.xhr({
			callback: 'cbPopulateAutoSearchForm',
			type: 'populateAutoSearchForm'
		});

	},


    switchSearch: function () {
		$('advSearchWrapper').toggle();
		$('doAdvancedSearch').value = ($('advSearchWrapper').visible()) ? 1 : 0;
	}

});