function ch_razm(){
	var sel_el = document.getElementById('vid_hal').value;
	
	var vzr_el = document.getElementById('razm');
	var det_el = document.getElementById('vozr');
	/*мужской - 46, женский - 47, детский - 36 */
	vzr_el.style.display = 'none';
	det_el.style.display = 'none';
	if(sel_el != '36'){
		vzr_el.style.display = '';
		vzr_el.value = '0';
	}
	if(sel_el == '36'){
		det_el.style.display = '';
		det_el.value = '0';
	}
}

function ch_pod()
{
	var sel_el = document.getElementById('razm');
	var pod_el = document.getElementById('pod');
	pod_el.style.display='none';
	if(sel_el.value == '188')
	{
		pod_el.style.display = '';
		pod_el.value = '0';
	}
}

function prepare()
{
	if(document.fil_form && document.fil_form.RAZMER_OBSHIJ__6)
	document.fil_form.RAZMER_OBSHIJ__6.options[0].innerHTML = 'Все размеры';
	
	$('select.acsess option').first().text('Все аксессуары');
	$('select.napolnit option').first().text('Наполнитель');
	
	if(document.fil_form && document.fil_form.PROIZVODITEL__14)
	document.fil_form.PROIZVODITEL__14.options[0].innerHTML = 'Все производители';



if(document.fil_form && document.fil_form.RAZMER_ODEYALA__88)
	document.fil_form.RAZMER_ODEYALA__88.options[0].innerHTML = 'Все размеры';


if(document.fil_form && document.fil_form.RAZMER_PODUSHKI__89)
	document.fil_form.RAZMER_PODUSHKI__89.options[0].innerHTML = 'Все размеры';


if(document.fil_form && document.fil_form.RAZMER_PLEDI__90)
	document.fil_form.RAZMER_PLEDI__90.options[0].innerHTML = 'Все размеры';


	
	if(document.fil_form && document.fil_form.TCVET_11)
	document.fil_form.TCVET_11.options[0].innerHTML = 'Цвет';
	
	if(document.fil_form && document.fil_form.NAPOLNITEL__16)
	document.fil_form.NAPOLNITEL__16.options[0].innerHTML = 'Все наполнители';
	
	if(document.fil_form && document.fil_form.PORYADOK_TCENI_83)
	document.fil_form.PORYADOK_TCENI_83.options[0].innerHTML = 'Цена';
	
	if(document.fil_form && document.fil_form.SOSTAV_10)
	document.fil_form.SOSTAV_10.options[0].innerHTML = 'Все составы';
	
	if(document.fil_form && document.fil_form.KOLICHESTVO_PREDMETOV_29)
	document.fil_form.KOLICHESTVO_PREDMETOV_29.options[0].innerHTML = 'Кол-во';
	
	if(document.fil_form && document.fil_form.VOZRAST_REB_NKA_35)
	document.fil_form.VOZRAST_REB_NKA_35.options[0].innerHTML = 'Все возрасты';
	
	if(document.fil_form && document.fil_form.VID_HALATA_34)
	document.fil_form.VID_HALATA_34.options[0].innerHTML = 'Все виды';

	if(document.fil_form && document.fil_form.PODODEYAL_NIK_22)
	document.fil_form.PODODEYAL_NIK_22.options[0].innerHTML = 'Все размеры пододеяльников';

	if(document.fil_form && document.fil_form.RAZMER_OBSHIJ__6){
		if(document.fil_form && document.fil_form.RAZMER_OBSHIJ__6.value == '188'){
			document.fil_form.PODODEYAL_NIK_22.style.display = '';
		}
	}
}

window.onload = prepare;

var myhash = window.location.hash;

if(myhash.substr(1,1) == '?'){

	window.location = "/catalog/list.php"+myhash.substr(1);

}


$(document).ready(function(){
	
	
	$('.tov_list_inner').live('mouseover',function(e){
		
		var x = e.pageX - this.offsetLeft;
		var y = e.pageY - this.offsetTop;
		
		$(this).children('.tov_el_desc').show().css('left',(x+17)+'px').css('top',(y-16)+'px');
		
	});
	
	$('.tov_list_inner').live('mousemove',function(e){
		
		var x = e.pageX - this.offsetLeft;
		var y = e.pageY - this.offsetTop;
		
		$(this).children('.tov_el_desc').css('left',(x+17)+'px').css('top',(y-16)+'px');
		
	});
	
	
	$('.tov_list_inner').live('mouseenter',function(){
		
		$('.tov_el_desc').hide();
		$(this).children('.tov_el_desc').show();
		
	});
	
	$('.tov_list_inner').live('mouseleave',function(){
		
		$(this).children('.tov_el_desc').hide();
		
	});
	
	$('.filt_sel').live('change',function(){
		 
		var getparams = '';
		
		if($('input.rurbrid').length){
		
			getparams = '&'+$('input.rurbrid').attr('name')+'='+$('input.rurbrid').val();
		
		}
		
		
		//значения поиска
		if($('input.srch_inp').val() != ''){
			
			getparams = getparams+'&BINN_CATALOG_1_ELEMENT_TITLE='+$('input.srch_inp').val();
			
		}
		
		//собираем значения селектов
		$('select.filt_sel').each(function(){
				getparams = getparams+'&'+$(this).attr('name')+'='+$(this).val();
		});

		//отпровляем запрос на вывод элементиов 
		var cont_wid = document.body.clientWidth;
		if(cont_wid < 1200){
			cont_wid  = 1200;
		}

		$('.prodlist .listload').show();
		$(".prodlist").addClass('loading');
                                
			$.ajax({
																	
				url: "/catalog/list-ajax.php?ajax=1&cont_wid=" + cont_wid + getparams,
				success: function(data){
				$(".prodlist").html(data).removeClass('loading');
				$('.prodlist .listload').hide();
				
				window.location.hash = "#?ajax=1&cont_wid="+cont_wid+getparams; 
				
				}
				
			});   
    
	});

	var myhash = window.location.hash;
	
	/* if(myhash.substr(1,1) == '?'){
		$.ajax({
			url: "/catalog/list-ajax.php"+myhash.substr(1),
			success: function(data){
				$(".prodlist").html(data);
			}
		});
		
	} */
	
                
                $.validity.setup({ outputMode:"summary" });

	$('#order_form').submit(function(){

		$.validity.start();
			$(".ord_fio").require('Введите ФИО;');
			$(".ord_phone").require('Введите номер телефона;');
			$(".ord_address").require('Введите адрес;');
		var result = $.validity.end();
		if(!result.valid)
                                {
			return false;
		}
                                                if($(".ord_email").val() != '' && $('#mallist').is(':checked')==false)
                                                {
                                                        $.ajax({
                                                                        type:"POST",
                                                                        url: "/catalog/order.php",
                                                                        data:"&maillist_email="+$(".ord_email").val(),
                                                                        success: function(data){
                                                                        }
                                                        });

                                                }

	});

                     $('#subscr_form').bind("submit", function() {	
$.validity.setup({ outputMode:"summary" });

		$.validity.start();
			
        		    $('#subscr_mail').require('Введите E-mail для рассылки;').match('email', 'Введите корректный E-mail;');

		var result = $.validity.end();
		
		
		if(!result.valid){
			$.fancybox($("#subscr_error").html());  
		    return false;
		}

}); 





	//добавление товара в корзину
	$('.bascLink').live('click',function(){
		
		if($(this).hasClass('added')){
			
			return false;
			
		}
		
		var tekel = $(this);
		
		var needurl = $(this).attr('href');
		
		$.ajax({
			url: needurl,
			success: function(data){
				
				tekel.addClass('added'); 
				
				$.fancybox(
					'<div class="fance_cont"><a href="" class="closefance">Продолжить покупки</a><a href="/catalog/basket.php">Перейти к оформлению заказа</a></div>',
					{
						'autoDimensions' : false,
						'height' : 'auto',
						'width' : 400,
						'transitionIn' : 'none',
						'transitionOut' : 'none'
					}
				);
		
				$('.korz_col').html($('.korz_col').html()*1+1);
				
				
			}
		});
		
		return false;
	});
	
	$('.closefance').live('click',function(){
		
		$.fancybox.close();
		return false;
	});
	
	
});

function bookmark(a)
{
	var url = window.document.location;
	var title = window.document.title;
	if ($.browser.msie && 7 > $.browser.version && $.browser.version >= 4) window.external.AddFavorite(url, title);
	else if ($.browser.opera) {
		a.href = url;
		a.rel = "sidebar";
		a.title = url + ',' + title;
		return true;
	}
	else if ($.browser.mozilla) window.sidebar.addPanel(title, url, "");
	else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
	return false;
}
