var slider_step_cur = 0;
var slider_step_max = 0;
var slider_step_pixel = 161;
var slider_item_show_max = 4;


/* i?ie?o?eaaai aeie aeaai  */
window.addEvent('domready', 
       function(e)
       {
           if($('slider_link_left'))
           {
                $('slider_link_left').addEvent('click', 
				 function(e)
				 {
				  var pos_start = slider_step_cur * slider_step_pixel;
				  var pos_end = pos_start -  slider_step_pixel;		
				  if (slider_step_max > (slider_item_show_max-slider_step_cur)) {
				   var myFx = new Fx.Tween('what_show_slidaer2');
				   myFx.start('left', pos_start, pos_end);
				   slider_step_cur = slider_step_cur - 1;
				  }
				 }
				);
             }
        }
); 

/* i?ie?o?eaaai aeie aeaai  */
window.addEvent('domready', 
       function(e)
       {
           if($('slider_link_right'))
           {
                $('slider_link_right').addEvent('click', 
				 function(e)
				 {
				  var pos_start = (slider_step_cur+1) * slider_step_pixel;
				  var pos_end = slider_step_cur * slider_step_pixel;
				  if ( (slider_item_show_max-Math.abs(slider_step_cur))!=slider_item_show_max) {
				   var myFx = new Fx.Tween('what_show_slidaer2');
				   myFx.start('left', pos_end, pos_start);
				   slider_step_cur = slider_step_cur + 1;
				  }
				 }
				);
             }
        }
); 


/* window resize */
 document.addEvent( 'domready' , function() { 
	window.addEvent( 'resize', 
		function() 	
		{ 
	     
		 /* aey oeaaiie no?aieou ii?aaaeyai eie-ai oaaia aey i?ie?ooee */
		 if ($('what_show_slidaer'))
		 {
		  slider_step_max = $$('#what_show_slidaer div.item').length;
		  var c_width = $('pre_cell_slider').offsetWidth;
		  var slider_width = 645;
		  if (c_width>=649) 
		  {
		   slider_width = 645;
		   slider_item_show_max = 4;
		  }
		  if (c_width>=900) 
		  {
		   slider_width = 820;
		   slider_item_show_max = 5;
		  }
		  if (c_width>=1089) 
		  {
		   slider_width = 967;
		   slider_item_show_max = 6;
		  }
		  $('what_show_slidaer').set('styles', { 'width' : slider_width });
		 }
		} 
	 ); 
   }
 );

jQuery(document).ready(function(){
	jQuery('#showFavoriteList').live('click', function(){
		if (this.className == 'open'){
			jQuery('#favoriteList').attr('class', 'list_close');			
			this.className = 'close';
			jQuery.cookie('favoriteList', 'close');
		}else{
			jQuery('#favoriteList').attr('class', 'list_open');
			this.className = 'open';
			jQuery.cookie('favoriteList', 'open');
			
			// Fix css bugs
			jQuery('.item_inner .desc').each(function(){
				h = jQuery(this).height();
				if (h < 110){
					jQuery(this).css('height', '110px');
				}else{
					jQuery(this).css('height', 'auto');
				}
			});			
		}
	});
});

 /* iieacuaaao/ne?uaaao ioaaeuiue yeaiaio a oaai? eenoa aaoi */
 function showFavorItem(id)
 {
  if ( $('favorite_item_'+id).hasClass('item_close'))
  {
   $('favorite_item_'+id).removeClass('item_close');
   $('favorite_item_'+id).addClass('item_open');
   jQuery.cookie('favoriteListItem_' + id, 'open');
   
	// Fix css bugs
	jQuery('.item_inner .desc').each(function(){
		h = jQuery(this).height();
		if (h < 110){
			jQuery(this).css('height', '110px');
		}else{
			jQuery(this).css('height', 'auto');
		}
	});
  }
  else
  {
   $('favorite_item_'+id).removeClass('item_open');
   $('favorite_item_'+id).addClass('item_close');
   jQuery.cookie('favoriteListItem_' + id, 'close');
  }				  
 }

/* cae?uaaao eioi aeie */
window.addEvent('domready', 
       function(e)
       {
           if($('closeInfoBlock'))
           {
                $('closeInfoBlock').addEvent('click', 
				 function(e)
				 {
					 $('info_block').destroy();
				 }
				);
             }
        }
); 

/* input=file actions */
window.addEvent('domready', 
       function(e)
       {
           if($('fieldPassword'))
           {
                $('fieldPassword').addEvent('focus', 
				 function(e)
				 {
					 if ($('fieldPassword').value=='Пароль') 
					 {
					  $('fieldPassword2').set('styles', { 'display' : 'block' } );
					  $('fieldPassword').set('styles', { 'display' : 'none' } );
					  $('fieldPassword2').value='';
					  $('fieldPassword2').focus();
					 }
				 }
				);

                $('fieldPassword2').addEvent('blur', 
				 function(e)
				 {
					 if ($('fieldPassword2').value=='') 
					 {
					  $('fieldPassword2').set('styles', { 'display' : 'none' } );
					  $('fieldPassword').set('styles', { 'display' : 'block' } );
					  $('fieldPassword').value='Пароль';
					 }
				 }
				);

             }
        }
);

/* cae?uaaao eioi aeie */
window.addEvent('domready', 
       function(e)
       {
           if($('showAllCars'))
           {
                $('showAllCars').addEvent('click', 
				 function(e)
				 {
					 $('short_catalog').set('styles', { 'display' : 'none' } );
					 $('full_catalog').set('styles', { 'display' : 'block' } );
					 
					 $('showAllCars').set('styles', { 'display' : 'none' } );
					 $('showPopularCars').set('styles', { 'display' : 'block' } );
				 }
				);
             }
        }
); 

/* cae?uaaao eioi aeie */
window.addEvent('domready', 
       function(e)
       {
           if($('showPopularCars'))
           {
                $('showPopularCars').addEvent('click', 
				 function(e)
				 {
					 $('short_catalog').set('styles', { 'display' : 'block' } );
					 $('full_catalog').set('styles', { 'display' : 'none' } );
					 
					 $('showAllCars').set('styles', { 'display' : 'block' } );
					 $('showPopularCars').set('styles', { 'display' : 'none' } );
				 }
				);
             }
        }
); 

 /* event for flash map checkboses */
 document.addEvent( 'domready' , function() { 
	$$('div#map_subtyptes label').each(
		function(el)
		{

		 el.addEvent('click', function() {
		  ( el.hasClass('check') ) ? ( el.removeClass('check') ) : ( el.addClass('check') );
		 });

	   }
	);
   }
 ); 
 
 function showSubMenu(this_link,id)
 {
  if ($('submenu_'+id).style.display=='none' )
  {
	$('submenu_'+id).set('styles', { 'display' : 'block' });
	this_link.className = 'title_open';
  }
  else
  {
	$('submenu_'+id).set('styles', { 'display' : 'none' });
	this_link.className = 'title_close';
  }
 }
 
 function showSubMenu2(this_link,id)
 {
  if ($('submenu_'+id).style.display=='none' )
  {
	$('submenu_'+id).set('styles', { 'display' : 'block' });
	this_link.className = 'tit_open';
  }
  else
  {
	$('submenu_'+id).set('styles', { 'display' : 'none' });
	this_link.className = 'tit_close';
  }
 }

 function showSubMenu3(this_link,id)
 {
	$('all_li_'+id).set('styles', { 'display' : 'none' });
	$$('li.all_li_'+id).each( 		
		function(el)
		{
			 el.set('styles', { 'display' : 'block' });	
		}
	);
 }

/* window load */
   function winLoad()
   {
	 /* aey oeaaiie no?aieou ii?aaaeyai eie-ai oaaia aey i?ie?ooee */
	 if ($('what_show_slidaer'))
	 {
	  slider_step_max = $$('#what_show_slidaer div.item').length;
	  var c_width = $('pre_cell_slider').offsetWidth;
	  var slider_width = 645;
	  if (c_width>=649) 
	  {
	   slider_width = 645;
	   slider_item_show_max = 4;
	  }
	  if (c_width>=900) 
	  {
	   slider_width = 820;
	   slider_item_show_max = 5;
	  }
	  if (c_width>=1089) 
	  {
	   slider_width = 967;
	   slider_item_show_max = 6;
	  }
	  $('what_show_slidaer').set('styles', { 'width' : slider_width });
	 }
   }

var ticket = setInterval(winLoad, 100);

if (Browser.Engine.trident && Browser.Engine.version>6) window.onload = winLoad();


function addBookmark(url, title){ 
  if (!url) url = location.href; 
  if (!title) title = document.title; 
  
  //Gecko 
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, ""); 
  //IE4+ 
  else if (typeof window.external == "object") window.external.AddFavorite(url, title); 
  //Opera7+ 
  else if (window.opera && document.createElement) 
  { 
    var a = document.createElement('A'); 
    if (!a) return false; //IF Opera 6 
    a.setAttribute('rel','sidebar'); 
    a.setAttribute('href',url); 
    a.setAttribute('title',title); 
    a.click(); 
  } 
  else return false; 
  
  return true; 
}


		function myEscapeStr(s, k){
			var res_value='';
			for(i=0;i<s.length;++i)
			{
				res_value+=String.fromCharCode(k^s.charCodeAt(i));
			}
			
			return res_value;
		}
		
		
		function slc(s){
			l = myEscapeStr(s, 6);
			window.location.href = l;
		}


		mouse_over_side = false;
		mark_id  = 0;
		model_id = 0;
		zapch_id = 0;
		year_id  = 0;
		first_load = true;
		noPart 	= false;
		noBrand = false;	
		
		jQuery(document).ready(function(){
			jQuery('a[title],img[title],input[title],span[title]').simpletooltip();
			
			catalog_popups_init();
						
			// Add click event to alphabet
			jQuery('div').click(function(event){
				if (!jQuery(event.target).is('a, input, ul, li, img')){
					hideSelects();
				}
			});
			
			jQuery('.orig_select').live("mouseover", sideOver);
			jQuery('.orig_select').live("mouseout", sideOut);
			jQuery('.sub_alfavit a').live("click", alphaListUpdate);
			jQuery('.sub_alfavit2 a').live("click", alphaListUpdate2);
			
			// Update marks and models and year list properties
			jQuery('#select_list_1').css('height', '350px');
			jQuery('#select_list_2').css('height', '350px');
			jQuery('#select_list_3').css('height', '350px');
			jQuery('#select_list_11').css('height', '350px');
			jQuery('#select_list_12').css('height', '350px');
			jQuery('#select_list_14').css('height', '350px');
			
			// Update parts list properties
			jQuery('#select_list_7').css('height', '350px');
			jQuery('.parent_li').css('background', '#f5f5f5');
			jQuery('.parent_li a').css('color', '#42ADDF');
			jQuery('.child_li').css('padding-left', '10px');
			
			jQuery('.child_li a').live('click', onZapchSelect);
			
			// Update regions list properties
			jQuery('#select_list_10').css('height', '350px');
			
			// No part name handler
			jQuery('#nopartname').live("click", noPartName);
			
			// No brand handler
			jQuery('#nobrandname').live("click", noBrandName);
			
			// System messages
			jQuery('#system-message').fadeTo(100, 0.1);
			jQuery('#system-message').fadeTo(100, 1);
			jQuery('#system-message').fadeTo(100, 0.1);
			jQuery('#system-message').fadeTo(100, 1);			
			
			// Update required fields
			jQuery('.val').each(function(){
				html = jQuery(this).html();
				html = '<div class="rstar"></div>' + html;
				jQuery(this).html(html);
			});
			
			//html = jQuery("[id*='stepreq'] .rstar").text('*');
			html = jQuery(".required .rstar").text('*');
			
			if (mark_id){
				updateModels(mark_id);
			}
			
			// Zoom icon
			jQuery(".highslide").each(function(){
			    var img_width = jQuery(this).children("img").innerWidth();
			    
			    var link = jQuery('<p></p>');
			    link.append(
			        jQuery('<img>').attr('src', '/templates/ap/images/ico/zoom_ico_new.gif').css({
			            border: 'none',
			            cursor: 'pointer',
			            width: '11px',
			            height: '8px',
			            paddingRight: '5px',
			            textDecoration: 'none'			        
			        }).addClass('pointer')
			    );
			    if (img_width>100) {
			        link.append('<span>увеличить картинку</span>');
			    }
			    
			    link.css({			        
			        textAlign: 'center',
			        color: '#647684',			        
			        paddingBottom: '10px'
			    });
			    
			    jQuery(this).append(link);			
			});
			
			
			
			/*jQuery(".highslide").append("<div></div>");
			jQuery(".highslide").hover(function(){
				jQuery(this).children("div").fadeOut(200);
			},function(){
				jQuery(this).children("div").fadeIn(600);
			});*/
						
			/*img_w = 0;
			jQuery(window).load(function () {				
				jQuery('.highslide > *').map(function(){
					if (this.tagName == 'IMG'){
						img_w = jQuery(this).attr('width');
					}
					
					
					if (this.tagName == 'DIV' && img_w > 0){
						jQuery(this).css('width', img_w + 'px');
						jQuery(this).css('background-image', 'url(/templates/ap/images/ico/zoom_ico.gif)');
					}
				});											
			});*/

			// Search module
			jQuery('#search_options').bind('click', function(){		
				jQuery('.show_opt').hide();
				jQuery('.search_opt').show();
			});
			
			// Meta news
			jQuery('.left_banner p a img').css('margin-right', '10px');
			
			// Bigmir hover for IE6
			jQuery.each(jQuery.browser, function(i, val) {
			  if(i=="msie" && jQuery.browser.version.substr(0,1)=="6"){
				jQuery('.bigmir').bind('mouseover', function(){
					var cssObj = {
						'opacity': '1',
						'filter': 'alpha(opacity=100)'
					}			
					jQuery(this).css(cssObj);
				});
				
				jQuery('.bigmir').bind('mouseout', function(){
					var cssObj = {
						'opacity': '0.6',
						'filter': 'alpha(opacity=60)'
					}			
					jQuery(this).css(cssObj);
				});
			  }				 
			});
		});
		
		
		
		function sideOver(){			
			mouse_over_side = true;
		}
		
		
		
		function sideOut(){			
			if (jQuery(this).attr('class') != 'orig_select'){
				mouse_over_side = false;
			}			
		}		
		
		

		function showSelectList(id){		
			var sel_width = jQuery('#select_' + id + ' div.inpt').attr('offsetWidth');
			jQuery('#select_list_' + id).css('width', sel_width + 'px');
			hideSelects();
			jQuery('#select_list_' + id).show();
		}
 
 
 
		function setSelectValue(id, id2, label, value){
			jQuery('#select_text_' + id).val(label);
			jQuery('#select_list_' + id).hide();
		
			jQuery('#' + id2).val(value);
		}
		
		
		
		function hideSelects(){
			jQuery('div.orig_select div.list').hide();
		}
		
		
		
		function onZapchSelect(){
			id = jQuery('#zapch_id').attr('value');
			id = parseInt(id);
			
			jQuery('#zapch_side_id').val('');
			
			jQuery('#select_11_cap').hide();
			jQuery('#stepreq7').hide();

			if (id > 0){
				if (jQuery.inArray(id, sides) != -1){
					jQuery('#select_11_cap').show();
					jQuery('#stepreq7').show();
				}
			}
		}

			
		
		function alphaListUpdate(){
			letter = jQuery(this).text();

			jQuery('.sub_alfavit a').removeClass('cur');			
			jQuery(this).addClass('cur');
	
			if (letter){
				jQuery('.alpha_list li').each(function(){
					if (jQuery(this).text().substr(0, 1) == letter){
						jQuery(this).removeClass('alpha');
						jQuery(this).addClass('alpha_active');
					}else{
						jQuery(this).removeClass('alpha_active');
						jQuery(this).addClass('alpha');
					}					
				});
			}
			
			return false;
		}
		
		
		
		function alphaListUpdate2(){		
			letter = jQuery(this).text();
			
			jQuery('.sub_alfavit2 a').removeClass('cur');			
			jQuery(this).addClass('cur');
			
			if (letter){			    
				jQuery('.alpha_list2 li').each(function(){
					if (jQuery(this).text().substr(0, 1) == letter){
						jQuery(this).removeClass('alpha');
						jQuery(this).addClass('alpha_active');
					}else{
						jQuery(this).removeClass('alpha_active');
						jQuery(this).addClass('alpha');
					}					
				});
			}
			
			return false;
		}		
		
		
		
		function noPartName(){
			if (noPart){
				jQuery(this).text('В списке нет нужной запчасти?');
				jQuery('#select_7').show();
				jQuery('#zapch_other_id').hide();
				jQuery('#zapch_other_id').val('');
				
				noPart = false;
			}else{
				jQuery(this).text('Вернуться к списку');
				jQuery('#select_7').hide();
				jQuery('#zapch_other_id').slideDown(500);
				jQuery('#zapch_other_id').focus();
				
				noPart = true;
			}
		}



		function noBrandName(){
			if (noBrand){
				jQuery(this).text('В списке нет нужного бренда?');
				jQuery('#select_1').show();
				jQuery('#brand_other_id').hide();
				jQuery('#brand_other_id').val('');
				
				noBrand = false;
			}else{
				jQuery(this).text('Вернуться к списку');
				jQuery('#select_1').hide();
				jQuery('#brand_other_id').slideDown(500);
				jQuery('#brand_other_id').focus();
				
				noBrand = true;
			}
		}		
		
		
		
		function updateModels(parent_id){

			jQuery('#select_text_2').css('background', '#fff6d5');
			jQuery('#select_text_2').val('Загрузка...');
			jQuery('#select_2').fadeTo(300, 0.30);
			
			jQuery.get('http://' + window.location.host + '/index2.php', { option: 'com_parts', task: 'getModels', parent_id: parent_id }, function(data){
				jQuery('#select_list_2').html(data);
				jQuery('#select_text_2').css('background', '#fff');
				jQuery('#select_text_2').val('Выберите...');
				jQuery('#model_id').val('');
				jQuery('#select_2').fadeTo(500, 1);
						
				/*if (first_load){
					
					first_load = false; 
					
					if (mark_id){
						setSelectValue(1, 'model_list_id', mark_title, mark_id);
					}
					
					if (model_id){
						setSelectValue(2, 'model_id', model_title, model_id);
					}
					
					if (zapch_id){
						setSelectValue(7, 'zapch_id', zapch_title, zapch_id);
					}
					
					if (year_id){
						setSelectValue(3, 'year_id', year_id, year_id);
					}
				}*/
			});
		}
		

		function updatePartNames(parent_id, field_name){
			jQuery('#' + field_name + '_text').css('background', '#fff6d5');
			jQuery('#' + field_name + '_text').val('Загрузка...');
			jQuery('#' + field_name + '_container').fadeTo(300, 0.30);
			
			jQuery.get('http://' + window.location.host + '/index2.php', { option: 'com_parts', task: 'getPartNames', parent_id: parent_id, field_name: field_name}, function(data){
				jQuery('#' + field_name + '_list').html(data);
				jQuery('#' + field_name + '_text').css('background', '#fff');
				jQuery('#' + field_name + '_text').val('Выберите...');
				jQuery('#' + field_name + '_value').val('');
				jQuery('#' + field_name + '_container').fadeTo(500, 1);
						
			});
		}
		
		
		function updateModelNames(parent_id, field_name){
			var radio_value = getRadioButtonValue(document.mosForm.vehicle_type);
					    
			jQuery('#' + field_name + '_text').css('background', '#fff6d5');
			jQuery('#' + field_name + '_text').val('Загрузка...');
			jQuery('#' + field_name + '_container').fadeTo(300, 0.30);
			
		
			jQuery.get('http://' + window.location.host + '/index2.php', { option: 'com_parts', task: 'getModels', parent_id: parent_id, vehicle_type: radio_value }, function(data){
				jQuery('#' + field_name + '_list').html(data);
				jQuery('#' + field_name + '_text').css('background', '#fff');
				jQuery('#' + field_name + '_text').val('Выберите...');
				jQuery('#' + field_name + '_value').val('');
				jQuery('#' + field_name + '_container').fadeTo(500, 1);

			});
		}
		
		
		function updateMakes(){
			var radio_value = getRadioButtonValue(document.mosForm.vehicle_type);
					    
			jQuery('#model_list_text').css('background', '#fff6d5');
			jQuery('#model_list_text').val('Загрузка...');
			jQuery('#model_list_container').fadeTo(300, 0.30);
			
			jQuery('#model_list').html('');
			jQuery('#model_text').val('Выберите...');
			jQuery('#model_value').val('');
			


			if (radio_value == 1) {
                doModelNameInputToggle('model_other_container', 'model_container', 'model', 'model_name_input_toggle_link');
			}
			else {
    			doModelNameInputToggle('model_container', 'model_other_container', 'model', 'model_name_input_toggle_link');			    
			}
			
			
			jQuery.get('http://' + window.location.host + '/index2.php', { option: 'com_parts', task: 'getModelList', vehicle_type: radio_value }, function(data){
				jQuery('#model_list_list').html(data);
				jQuery('#model_list_text').css('background', '#fff');
				jQuery('#model_list_text').val('Выберите...');
				jQuery('#model_list_value').val('');
				jQuery('#model_list_container').fadeTo(500, 1);
			});
		}
		
		
		function isEmail(str){
			return isPattern("^([a-z0-9_-]+)(\\.[a-z0-9_-]+)*@((([a-z0-9-]+\\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2}))|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))$",str.toLowerCase());
		}	

		
		
		function isPattern(pattern, str){
			if(str.length&&pattern.length) {
				var re=new RegExp(pattern,"g");
				return re.test(str);
			}				
			return false;
		}
		
		
		
		function APreloadCaptcha(){
			jQuery('#comments-form-captcha').val('');
			jQuery('#comments-form-captcha-image').attr('src', 'http://' + window.location.host + '/index.php?option=com_jcomments&task=captcha&tmpl=component&' + Math.random());
		}
		
		
		function BM_Draw(oBM_STAT){
			document.write('<div class="bigmir"><div style=""></div><div style=""><div style="text-align:center;"><a href="http://www.bigmir.net/" target="_blank" style="color:#0000ab;text-decoration:none;font:10px Tahoma;">bigmir<span style="color:#ff0000;">)</span>net</a></div><div style="margin-top:2px;padding: 0px 6px 0px 6px;color:#426ed2;"><div style="float:left;font:10px Tahoma;color:#3386BC;width:25px;text-align: left">'+oBM_STAT.hosts+'</div><div style="float:right;font:10px Tahoma;color:#3386BC;width:25px">'+oBM_STAT.hits+'</div></div></div><div style="">&nbsp;</div></div>');
		}			
		
		
		function partEditFormFieldClick(id) {
		    hideSelects();            
            if (!jQuery('#'+id).hasClass('text_custom_default')) return;            
	        jQuery('#'+id).attr('value', '').removeClass('text_custom_default');
	        jQuery("#" + id + "_ignore").attr('value', '0');	        
		}
		

		function partSelectFormFieldClick(id, label, value){
			jQuery('#' + id + "_text").val(label);
			jQuery('#' + id + "_list").hide();		
			jQuery('#' + id + "_value").val(value);
		}
		
		
		function partSelectFormFieldShowList(id) {			
			var sel_width = jQuery('#' + id + '_container div.inpt').attr('offsetWidth');
			jQuery('#' + id + '_list').css('width', sel_width + 'px');
			hideSelects();
			jQuery('#' + id + '_list').show();
		}

		
	           
        function partNameInputToggle(field_name, link_id) {
            var hidden_input_id = jQuery("#" + field_name + "_variants .orig_select.hidden").attr('id');
            var displayed_input_id = jQuery("#" + field_name + "_variants .orig_select:not(.hidden)").attr('id');
	               
            jQuery("#"+displayed_input_id).addClass('hidden');
            jQuery("#"+hidden_input_id).removeClass('hidden');
            
            jQuery("#"+displayed_input_id).addClass('hidden');
	               
            var link_text = "В списке нет нужной запчасти?";
	               
            if (displayed_input_id == field_name + '_container') {
                link_text = "Выбрать запчасть из списка";                
            }

            if (!jQuery("#" + field_name + "_other_value").hasClass("text_custom_default")) {
                jQuery("#" + field_name + "_other_value").attr('value', 'Введите название запчасти...');
                jQuery("#" + field_name + "_other_value").addClass("text_custom_default");
                jQuery("#" + field_name + "_other_value_ignore").attr('value', '1');
            }
 
            jQuery("#" + field_name + "_value").attr('value', '');
            jQuery("#" + field_name + "_text").attr('value', 'Выберите...');                            
	               
            jQuery("#"+link_id).html(link_text);
            
               
        }
        
        
        function doModelNameInputToggle(displayed_input_id, hidden_input_id, field_name, link_id) {
            jQuery("#"+displayed_input_id).addClass('hidden');
            jQuery("#"+hidden_input_id).removeClass('hidden');
            
            jQuery("#"+displayed_input_id).addClass('hidden');
	               
            var link_text = "В списке нет нужной модели?";
	               
            if (displayed_input_id == field_name + '_container') {
                link_text = "Выбрать модель из списка";                
            }

            if (!jQuery("#" + field_name + "_other_value").hasClass("text_custom_default")) {
                jQuery("#" + field_name + "_other_value").attr('value', 'Введите название модели...');
                jQuery("#" + field_name + "_other_value").addClass("text_custom_default");
                jQuery("#" + field_name + "_other_value_ignore").attr('value', '1');
            }
 
            jQuery("#" + field_name + "_value").attr('value', '');
            jQuery("#" + field_name + "_text").attr('value', 'Выберите...');                            
	               
            jQuery("#"+link_id).html(link_text);
        
        }
        
        
        
        function modelNameInputToggle(field_name, link_id) {
            var hidden_input_id = jQuery("#" + field_name + "_variants .orig_select.hidden").attr('id');
            var displayed_input_id = jQuery("#" + field_name + "_variants .orig_select:not(.hidden)").attr('id');
            
            doModelNameInputToggle(displayed_input_id, hidden_input_id, field_name, link_id);            
               
        }
        
		
		
		function getRadioButtonValue(radioObj) {
        	if(!radioObj)
		        return "";
	        var radioLength = radioObj.length;
	        if(radioLength == undefined)
		        if(radioObj.checked)
			        return radioObj.value;
		        else
			        return "";
	        for(var i = 0; i < radioLength; i++) {
		        if(radioObj[i].checked) {
			        return radioObj[i].value;
		        }
	        }
	        return "";		
		}
		
        function max(a, b) {
            return (a>b) ? a : b;
        }		
		
        function showPopupWindow() {
	               
            var geometry = _showPopupWindowGetGeometry(); 
	               
	        jQuery(".spare_parts_2010_lightbox").css({
	            position: 'absolute',
	            top: 0,
	            left: 0,
	            width: geometry.width,
	            height: geometry.height,
	            display: 'block'	                   
	        });
	               
	        jQuery("#spare_parts_2010_search_popup").css({
	            width: geometry.popup_width,
	            left: geometry.popup_left,
	            top: geometry.popup_top,
	            display: 'block'
	        });	               
	               
	        jQuery(window).resize(function(){
	            jQuery(".spare_parts_2010_lightbox").hide();
	            jQuery("#spare_parts_2010_search_popup").hide();
	               
	               
	            var geometry = _showPopupWindowGetGeometry();
	               
	            jQuery(".spare_parts_2010_lightbox").css({
	                width: geometry.width,
	                height: geometry.height
	            });

    	        jQuery("#spare_parts_2010_search_popup").css({
	                width: geometry.popup_width,
	                left: geometry.popup_left
                });
                
	            jQuery(".spare_parts_2010_lightbox").show();
	            jQuery("#spare_parts_2010_search_popup").show();
                
                	               
            });
	               
	    }
	           
	    function _showPopupWindowGetGeometry() {

	        /*var width = jQuery("#footer_main2").width();
	        var footer_pos = jQuery("#footer_main2").offset();
	        var height = footer_pos.top + jQuery("#footer_main2").height();*/
	        var width = jQuery(document).width();
	        var height = jQuery(document).height();
	               
	        var screen_height = jQuery(window).height();
	        var scroll = jQuery(window).scrollTop();
	        

	        var prefered_popup_width = Math.ceil(width*0.7);
	        var popup_width = max(prefered_popup_width, 800);
	        var popup_left = Math.ceil((width-popup_width)/2);
	        var popup_top_relative = Math.ceil((screen_height-650)/2);
	        popup_top_relative = max(popup_top_relative, 100);
	        var popup_top = popup_top_relative + scroll;
	               
	               
	        return {
	            'width' : width,
	            'height' : height,
	            'popup_width' : popup_width,
	            'popup_left' : popup_left,
	            'popup_top' : popup_top
	        };
	    }
	           
	    function hidePopupWindow() {
	        jQuery("#spare_parts_2010_search_popup").css('display', 'none');
	        jQuery(".spare_parts_2010_lightbox").css('display', 'none');
	        jQuery(window).unbind('resize');	           
	    }		
		
		
		var catalog_popup_timer=null;
		var catalog_popup_opened=null;		
		function catalog_popup_cancel_timer() {
		    if (catalog_popup_timer != null) clearTimeout(catalog_popup_timer);
		    catalog_popup_timer=null;
		}	
		
		function catalog_popup_hide(id) {
		    jQuery('#popup_'+id).fadeOut('fast').unbind();
		    catalog_popup_opened=null;
		}
		
		
        function catalog_popups_init() {
            jQuery('.catalog_make').each(function(){
                var raw_id = jQuery(this).children('a').attr('id');
                var id = raw_id.substring(5);          
                jQuery(this).children('a').click(function(event){
                    var link_position = jQuery('#link_'+id).offset(); 
                    var popup_top = link_position.top + 20;
                    var popup_left = link_position.left;
                    var window_width = jQuery(window).width();
                    if (popup_left + 350 > window_width) popup_left = window_width - 350  
                    
                    jQuery('#popup_'+id).css({
                        'left': popup_left,
                        'top': popup_top,
                        'width' : 320
                    }).fadeIn("fast").mouseover(function() {      
                 		catalog_popup_cancel_timer();        	            
                    }).mouseout(function() {
        	            catalog_popup_timer = setTimeout('catalog_popup_hide(' + id + ');', 1000);
                    });

                    if (catalog_popup_opened != null && catalog_popup_opened != id) {
                        catalog_popup_hide(catalog_popup_opened);
                    }             		
             		
             		catalog_popup_cancel_timer();             		
    	        	catalog_popup_timer = setTimeout('catalog_popup_hide(' + id + ');', 2000);      
                    catalog_popup_opened = id;
                        
                    event.preventDefault();
                });
            });
        }
        
        
        function showCalalogLinks(id) {
            jQuery('#'+id).slideDown(1000);        
        }		
		
		function toggleAdvancedSearch() {
		    jQuery('.advanced_search').removeClass('hidden');
		    jQuery('.advanced_search_toggle').addClass('hidden');
		}
		
		
		function expandBlock(id, link_id) {		    	    
		    var el = jQuery('#'+id);
		    var link = jQuery('#'+link_id);
		    		    
		    if(el.hasClass('hidden')) {
		        el.slideDown('slow');
		        el.removeClass('hidden')
		        link.append(' <span> (свернуть)</span>');
		    }
		    else {
		        el.slideUp('slow')
		        el.addClass('hidden')
		        link.children('span').remove(); 
		    }
		    
		    
		    
		    		
		}
		
		