

var searchforms_cnt = 2;
var section_id = 0;
var mark_id = '';
var model_id = 0;


function searchforms_initialize(isection_id,imark_id,imodel_id)
{
	section_id = isection_id
	mark_id = imark_id;
	model_id = imodel_id;
	if (section_id == 0)  section_id = 1;

	for (var formid = 1; formid<=searchforms_cnt; formid++)
	{
		if (!(selectsection = document.getElementById('selectsection'+formid))) continue;

		while(selectsection.options.length>0) selectsection.options[0] = null;

		for (var i = 0; i < all_sections.length; i++)
		{
			var oOption = new Option(all_sections[i][1],all_sections[i][0]);
			selectsection.options.add(oOption);
			if ((section_id > 0) && (section_id == all_sections[i][0]))
			{
				selectsection.selectedIndex = selectsection.options.length-1;
			}
		}


		var selectmark = document.getElementById('selectmark'+formid);
		while (selectmark.options.length>0) selectmark.options[0] = null;

		var oOption = new Option('Все марки','all');
		selectmark.options.add(oOption);
		if (section_id)
		{
			for (var i = 0; i < all_marks[section_id].length; i++)
			{
				var oOption = new Option(all_marks[section_id][i],all_marks[section_id][i]);
				selectmark.options.add(oOption);
				if (mark_id == all_marks[section_id][i])
				{
					selectmark.selectedIndex = selectmark.options.length-1;
				}
			}
		}


		var selectmodel = document.getElementById('selectmodel'+formid);
		while (selectmodel.options.length>0) selectmodel.options[0] = null;
		var oOption = new Option('Все модели','all');
		selectmodel.options.add(oOption);
		if (mark_id != '')
		{
			for (var i = 0; i < all_models[section_id].length; i++)
			{
				if (all_models[section_id][i][0] == mark_id)
				{
					for (j = 0; j < all_models[section_id][i][1].length; j++)
					{
						var oOption = new Option(all_models[section_id][i][1][j][1],all_models[section_id][i][1][j][0]);
						selectmodel.options.add(oOption);

						if (model_id == all_models[section_id][i][1][j][0])
						{
							selectmodel.selectedIndex = selectmodel.options.length-1;
						}
					}
				}
			}
		}
	}
}


function searchforms_changesection(isection_id)
{
	section_id = isection_id;
	mark_id = '';
	model_id = 0;

	for (var formid = 1; formid<=searchforms_cnt; formid++)
	{
		var selectsection = document.getElementById('selectsection'+formid);
		if (selectsection)
		for (i = 0; i < selectsection.options.length; i++)
		{
			if (selectsection.options[i].value == section_id)
			{
				selectsection.selectedIndex = i;
			}
		}
		
		var selectmodel = document.getElementById('selectmodel'+formid);
		if (selectmodel)
		{
			while (selectmodel.options.length>0) selectmodel.options[0] = null;

			var oOption = new Option('Все модели',0);
			selectmodel.options.add(oOption);
		}

		var selectmark = document.getElementById('selectmark'+formid);
		if (selectmark)
		{
			while (selectmark.options.length>0) selectmark.options[0] = null;
			var oOption = new Option('Все марки',0);
			selectmark.options.add(oOption);
			if (section_id)
			{
				for (var i = 0; i < all_marks[section_id].length; i++)
				{
					var oOption = new Option(all_marks[section_id][i],all_marks[section_id][i]);
					selectmark.options.add(oOption);
				}
			}
		}
	}
}
	

function searchforms_changemark(mark_id)
{
	model_id = 0;

	for (var formid = 1; formid<=searchforms_cnt; formid++)
	{
		var selectmark = document.getElementById('selectmark'+formid);
		if (selectmark)
		for (i = 0; i < selectmark.options.length; i++)
		{
			if (selectmark.options[i].value == mark_id)
			{
				selectmark.selectedIndex = i;
			}
		}

		var selectmodel = document.getElementById('selectmodel'+formid);
		if (selectmodel)
		{
		while (selectmodel.options.length>0) selectmodel.options[0] = null;
		var oOption = new Option('Все модели',0);
		selectmodel.options.add(oOption);
		if (mark_id != '')
		{
			for (var i = 0; i < all_models[section_id].length; i++)
			{
				if (all_models[section_id][i][0] == mark_id)
				{
					for (j = 0; j < all_models[section_id][i][1].length; j++)
					{
						var oOption = new Option(all_models[section_id][i][1][j][1],all_models[section_id][i][1][j][0]);
						selectmodel.options.add(oOption);
					}
				}
			}
		}
		}
	}
}


