/**
 * Scalena_QuickSearch extension
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 * @category   Scalena
 * @package    Scalena_QuickSearch
 * @copyright  Copyright (c) 2010 Scalena Agency SA
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 *
 * @category   Scalena
 * @package    Scalena_QuickSearch
 * @author     Anthony Charrex <anthony@scalena.com>
 */

if (typeof Scalena == 'undefined') {
	var Scalena = {};
}

/**************************** QUICK SEARCH **************************/
Scalena.QuickSearch = Class.create();
Scalena.QuickSearch.prototype = {

	initialize: function () { },

	loadModels: function (field, manufacturer, fieldToReset, isCustomer) {

		this._removeChildren(field);
		this._removeChildren(fieldToReset);

		isCustomer = (typeof isCustomer !== 'boolean') ? false : true;

		new Ajax.Updater(field, BASE_URL + 'quicksearch/ajax/models', {
			parameters: { manufacturer: manufacturer, customer: isCustomer }
		});

	},

	loadYears: function (field, manufacturer, model, isCustomer) {

		this._removeChildren(field);

		isCustomer = (typeof isCustomer !== 'boolean') ? false : true;

		new Ajax.Updater(field, BASE_URL + 'quicksearch/ajax/years', {
			parameters: { manufacturer: manufacturer, model: model, customer: isCustomer }
		});

	},

	_removeChildren: function (field) {

		var children = $(field).childNodes;
		for ( var i = 0 ; i < children.length ; i++ ) {
			if ( i > 2 ) {
				$(field).removeChild(children[i]);
			}
		}

	}
};
