function changeTab(n){
	
	el = document.getElementById('search-menu-1');
	el.style.display = 'none';
	el = document.getElementById('search-menu-2');
	el.style.display = 'none';
	el = document.getElementById('search-menu-3');
	el.style.display = 'none';
	el = document.getElementById('search-menu-4');
	el.style.display = 'none';
	
	
	el = document.getElementById('search-menu-' + n);
	el.style.display = '';
	setCookie("search_div", n); 
}

function setFormAction(obj){
	
	$(obj).getParent('form').setProperty('action', obj.value);
	obj.getParent('form').getElement('input[name=submit]').disabled = false;
}




function divSelect(obj){
	
	var div = document.getElement('div.textSelect');
	
	// спрятать окно
	if (div) return div.destroy();
	
	var pos = $(obj).getCoordinates(false);
	
	div = new Element('div',{
		'html': '<font color="#ffffff">Загрузка...</font>',
		'styles':{
			'width':'500px',
			'left': pos.left,
			'top' : pos.bottom
		},
		'class': 'textSelect'
	}).inject(document.body);
	
	new Request.JSON({
		'url': "/search_menu_action/", 
		'onComplete': function(json_data, html_data){
			
			if (!json_data) return ;
			
			div.empty();
			
			$H(json_data).each(function(el, k){
				
				new Element('a',{
					'href': 'javascript:void(0)',
					'styles': {'width':'100px','float':'left'},
					'events':{
						'click': function(){
							
							// сброс переменных
							divSelectData = {
								'model': null,
								'brand': null,
								'modif': null
							};
							
							// сброс текста
							$('sm_model').getElement('a').set('html', 'не указана');
							$('sm_modif').getElement('a').set('html', 'не указана');
							
							// вывести производителя
							$('sm_maker').getElement('a').set('html', el);
							
							//скрыть окно
							div = div.destroy();
							
							// показать выбор модели
							$('sm_model').setStyle('display', '');
							$('sm_model_d').setStyle('display', 'none');
							$('sm_modif').setStyle('display', 'none');
							$('sm_modif_d').setStyle('display', '');
							$('search_in_cat').disabled = true;
							
							divSelectData.brand = k;
						}
					}
				}).appendText(el).inject(div);
				
			});
		}
	}).get(); 
	
}
function divSelect2(obj){
	
	var div = document.getElement('div.textSelect');
	
	// спрятать окно
	if (div) return div.destroy();
	
	var pos = $(obj).getCoordinates(false);
	
	div = new Element('div',{
		'html': '<font color="#ffffff">Загрузка...</font>',
		'styles':{
			'width':'500px',
			'left': pos.left,
			'top' : pos.bottom
		},
		'class': 'textSelect'
	}).inject(document.body);
	
	
	new Request.JSON({
		'url': "/search_menu_action/", 
		'onComplete': function(json_data, html_data){
			
			if (!json_data) return ;
			
			div.empty();
			
			$H(json_data).each(function(el, k){
				
				new Element('a',{
					'href': 'javascript:void(0)',
					'styles':{'display':'block'},
					'events':{
						'click': function(){
							
							// сброс переменных
							divSelectData.modif = null;
							
							// сброс текста
							$('sm_modif').getElement('a').set('html', 'не указана');
							
							div = div.destroy();
							$('sm_model').getElement('a').set('html', el);
							$('sm_modif').setStyle('display', '');
							$('sm_modif_d').setStyle('display', 'none');
							$('search_in_cat').disabled = true;
							
							divSelectData.model = k;
							
							
						}
					}
				}).appendText(el).inject(div);
				
			});
		}
	}).get({'action': 'model', 'brand':divSelectData.brand}); 
	
}
function divSelect3(obj){
	
	var div = document.getElement('div.textSelect');
	
	// спрятать окно
	if (div) return div.destroy();
	
	var pos = $(obj).getCoordinates(false);
	
	div = new Element('div',{
		'html': '<font color="#ffffff">Загрузка...</font>',
		'styles':{
			'width':'500px',
			'left': pos.left,
			'top' : pos.bottom
		},
		'class': 'textSelect'
	}).inject(document.body);
	
	
	new Request.JSON({
		'url': "/search_menu_action/", 
		'onComplete': function(json_data, html_data){
			
			if (!json_data) return ;
			
			div.empty();
			
			//$H(json_data);
			//alert(json_data.getLength());
			//if (json_data.getLength() == 1);
			
			$H(json_data).each(function(el, k){
				
				
				new Element('a',{
					'href': 'javascript:void(0)',
					'styles':{'display':'block'},
					'events':{
						'click': function(){
							div = div.destroy();
							$('sm_modif').getElement('a').set('html', el);
							divSelectData.modif = k;
							
							//alert(divSelectData.modif);
							$('search_in_cat').disabled = false;
							
							new Request.JSON({
								'url': '/search_menu_action/',
								'onComplete': function(json_data, html_data){
									//alert(ac);
									//if (json_data) ac.update($H(json_data)); 
									ac.tokens = $H(json_data);
								}
							}).get({'action':'tree', 'modif': divSelectData.modif});
						}
					}
				}).appendText(el).inject(div);
				
			});
		}
	}).get({'action': 'modif', 'model':divSelectData.model}); 
	
}


function onsubmit3(obj){
	
	var spid = ac.tokens.keyOf(ac.element.value);
	var url = '/catalogs/index.html?brid='+ divSelectData.brand + '&mdl=' + divSelectData.model + '&mdf=' + divSelectData.modif + '&spid=' + spid ;
	obj.action = url;

}

function changeFormAction(obj){
	
	$(obj).getParent('form').setProperty('action', '/d_catalog3/' + obj.value + '/');
	
}

function change(){
			
			var ser     = getCookie('ser');
			var ser_val = getCookie('ser_val');
			var ser_val_name = getCookie('ser_val_name');
			
			if (ser == 1){	
							
				var el = document.getElementById("code");			

				el.innerHTML = '<a href="" onclick="setCookie(\'ser\', 0);change();return false;" >по коду детали</a> / <a href="" onclick="return false;" style="border-bottom:1px solid white;">по производителю</a>';

				el = document.getElementById("search_o");
				el.style.display = "none";
				el = document.getElementById("search_t");
				el.style.display = "block";
			
				document.getElementById("search_in_cat_brand").value=ser_val;
				document.getElementById("name_s").value=ser_val_name;

				
			}else{				
				var el = document.getElementById("code");
				el.innerHTML = '<a href="" onclick="return false;" style="border-bottom:1px solid white;">по коду детали</a> / <a href="" onclick="setCookie(\'ser\', 1); change();return false;">по производителю</a>';
				el = document.getElementById("search_t");
				el.style.display = "none";
				el = document.getElementById("search_o");
				el.style.display = "block";
			}

			
			return false
}

function send_f(obj){
		if(ac_brand.element.value && (document.getElementById("name_s").value && document.getElementById("name_s").value !='введите наименование')){

				var prd = ac_brand.tokens.keyOf(ac_brand.element.value).substr(0,ac_brand.tokens.keyOf(ac_brand.element.value).length-5);		
   				prd = '&prd='+prd;		
   				setCookie('ser_val', ac_brand.element.value);
    			
				var name_el = '&name='+document.getElementById("name_s").value;
				var url = '/search.html?sort___search_results_by=final_price&term=0&smode=E'+prd+''+name_el;
				setCookie('ser_val_name', document.getElementById("name_s").value);
    			
				obj.action = url;

				return true;

		}else{
			
			if(!ac_brand.element.value){
			alert('Введите производителя');	
			obj.search_in_cat_brand.focus();
			return false;
			
			}else{
			
			alert('Введите наименование');
			obj.name_s.focus();
			return false;
			}

		}
}