var pathname = '/';
var largeExpDate = new Date ();
largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000));
var convert=1;
$(document).ready(function(){
 
	$(".sliderkit").sliderkit({
		//mousewheel:true,
		shownavitems:1,
		//navfx:"none",
		//panelbtnshover:true,
		auto:false,
		circular:true,
		navscrollatend:true
	});				
	$(".sliderkit-go-btn a").focus(function () {this.blur()});

    $("#Slidergradus").slider({
		from: -40, 
		to: 40, 
		scale: [-40, -30, -20, -10,  0,  +10,  +20, +30, +40], 
		limits: false, 
		step: 1, 
		//dimension: '---', 
		skin: "blue",
		callback: function(  ){
			$('#form_filter').submit();
		}
	});
    $("#Slidersize").slider({
		from: 16, 
		to: 44, 
	//	scale: [-40, -30, -20, -10,  0,  +10,  +20, +30, +40], 
		limits: false, 
		step: 0.5, 
		round: 1,
		//dimension: '---', 
		skin: "sizes",
		callback: function(  ){
			$('#form_filter').submit();
		}
	});
	
	
    $("#input_convert").focus(function () {
        var val=$(this).val();
        var reld=$(this).attr('rel');
		if(val==reld) $(this).val('');
    }).blur(function () {
        var val=$(this).val();
		var reld=$(this).attr('rel');
		if(val=='') $(this).val(reld);
    });

	$("#convert_title_1").click(function () { 
		$('.convert_title_2').removeClass('activ'); 
		$('.convert_title_1').addClass('activ');
		$('.convet_info_2').hide();
		$('.convert_text2').hide();
		$('.convet_info_1').show();
		var reld="длина стельки"
		$('#input_convert').val(reld);
		$('#input_convert').attr('rel',reld);
		convert=1;
	});
	$("#convert_title_2").click(function () { 
		$('.convert_title_1').removeClass('activ'); 
		$('.convert_title_2').addClass('activ');
		$('.convet_info_1').hide();
		$('.convet_info_2').show();
		$('#input_convert_brend').val('str');
		var reld="размер EUR"
		$('#input_convert').val(reld);
		$('#input_convert').attr('rel',reld);
		convert=2;
    });
	
	$('#top_float_menu_0_box_1').click(function () { 
		if( $('.top_float_menu_1').is(':hidden') ) {
			$('#top_float_menu_0_box_1').addClass('activ');	
			$('#top_float_menu_0_box_1 img').attr('src','/images/fl_menu_1_activ.png');
 			$('.top_float_menu_1').show();
			$('.top_float_menu_2').show();

			if ( $('.top_float_menu_0').hasClass('m3') ){
				$('.top_float_menu_1').hide();
				$('.top_float_menu_2').hide();
				$('#top_float_menu_3').show();

			
			
			}

		}
	});
	
//	$('.funk, .selectpog .funk_radio').click(function () { 
	//	$(this).toggleClass('activ');
//	});
	$('.selectpog .funk_radio').click(function () { 
		$('.selectpog .funk_radio').removeClass('activ'); 
		$(this).addClass('activ');
	});
	$('.grsizes .funk_radio').click(function () { 
		$('.grsizes .funk_radio').removeClass('activ'); 
		$(this).addClass('activ');
	});
	$('#filter_hide').click(function () { 
		$('#box_filtr').slideUp('slow');
		$('.filter_hide').hide();		
		$('.filter_show').show();		
	});
	$('#filter_show').click(function () { 
		$('#box_filtr').slideDown('slow');
		$('.filter_show').hide();		
		$('.filter_hide').show();		
	});
	
	$('#form_filter input, #form_filter select').change(function() {
	  $('#form_filter').submit();
	});
	$('#a_enter_lk').click(function () { 
		if( $('.box_login').is(':hidden') ) {
			$('.box_login').slideDown();
			$('#a_enter_lk').text('Свернуть панель входа');
			$('#TB_overlay').show();
		}else {
			$('.box_login').slideUp();
			$('#a_enter_lk').text('Войти в личный кабинет');
			$('#TB_overlay').hide();
		}
	});
	
	// -------------------------------
	
	$('#select_accessories').click(function(){
		$('#shoes_box').hide();
		$('#accessories_box').show();
		$('#catalog_item_shoes').removeClass();
		$('#catalog_item_shoes').addClass('catalog_word');
		$('#catalog_item_accessories').removeClass();
		$('#catalog_item_accessories').addClass('catalog_item_class');
		$('#select_shoes').removeClass();
		$('#select_shoes').addClass('a_green_dashed');
		$('#select_accessories').removeClass();
		$('#select_accessories').addClass('a_clear');
	});
	$('#select_shoes').click(function(){
		$('#accessories_box').hide();
		$('#shoes_box').show();
		$('#catalog_item_shoes').removeClass();
		$('#catalog_item_shoes').addClass('catalog_item_class');
		$('#catalog_item_accessories').removeClass();
		$('#catalog_item_accessories').addClass('catalog_word');
		$('#select_shoes').removeClass();
		$('#select_shoes').addClass('a_clear');
		$('#select_accessories').removeClass();
		$('#select_accessories').addClass('a_green_dashed');
	});
	
	// -------------------------------
	
	
	if(!jQuery("body").find("#TB_overlay").is("div")) /* если фон уже добавлен не добавляем повторно */
	{
	   if(!jQuery.browser.msie) /* если браузер не ИЕ фоном будет div */
	   jQuery("body").append("<div id='TB_overlay'></div>");
	   else /* иначе добавляем iframe */
	   jQuery("body").append("<div id='TB_overlay'><iframe scrolling='no' frameborder='0' style='position: absolute; top: 0; left: 0; width: 100%; height: 100%; filter:alpha(opacity=0)'></iframe></div>");
	}

	$('#input_convert').keyup(function(event){
		var val=this.value;
		val=val.replace(/,/g, ".")
		val=parseFloat(val);
		if(!val) val='';
		var dat='';
	//	this.value=val;
		if(val){
			if(convert==1){
				dat= "type=5&val="+val;
			}else{
				var brend=$('#input_convert_brend').val();
				var brendus=$('#input_convert_brend_us').val();
				dat= "type=6&val="+val+"&brend="+brend+"&brendus="+brendus;
			}
			$.ajax({
				type: "POST",
				url: "/data/data.php",
				data: dat,
				success: function(msg){
					$('#convert_rezult').html($.trim(msg));
					if(membersize==1){
						SetCookie('membersize',$.trim(msg),largeExpDate,pathname);	
						SetCookie('membersizeinput',val,largeExpDate,pathname);	
						var msg=$('#convert_rezult').html();
						msg=parseFloat(msg);
						if(msg){
							var from=Math.floor(msg);
							var to=Math.floor(msg+1);
							$('#Slidersize').slider( 'value', from, to );
							$('#Slidersize').slider( 'value', from, to );
						}
					}
				}
			 });
		}
	});
	$('#member_size').change(function() {
		if(this.checked){
			membersize=1;
			var msg=$('#input_convert').val();
			if(parseInt(msg)) SetCookie('membersizeinput',parseInt(msg),largeExpDate,pathname);	
			var msg=$('#convert_rezult').html();
			SetCookie('membersize',$.trim(msg),largeExpDate,pathname);	
			SetCookie('membersizecheck',1,largeExpDate,pathname);	
			tmpsize=$('#Slidersize').val();
			var msg=$('#convert_rezult').html();
			msg=parseInt(msg);
			if(msg){
				var from=Math.floor(msg);
				var to=Math.floor(msg+1);
				$('#Slidersize').slider( 'value', from, to );
				$('#Slidersize').slider( 'value', from, to );
			}
		}else{
			membersize=0;
			DelCookie('membersize');
			DelCookie('membersizeinput');
			DelCookie('membersizecheck');
		}
	});

	cklabel()
});
var tmpsize;
var membersize=GetCookie('membersizecheck')?1:0;
function go_to_reg(){
	$('.box_login').slideDown();
	$('#a_enter_lk').text('Свернуть панель входа');
	$('#TB_overlay').show();
		
	$('#lost_pwd_form').hide();
	$('#sign_in_form').hide();
	$('#registration_form').show('slow');
}
function cklabel(){
	var ids=$('#form_filter input:checkbox:checked');
	jQuery.each(ids, function() {
		$('label[for='+this.id+']').addClass('activ');
    });

}
function filtr_change_brand(){
	var val=$('#input_convert_brend').val();
	if(val.search('_us')>0){
		$('#box_convert_brend_us').show();
		var reld="размер US"
		$('#input_convert').val(reld);
		$('#input_convert').attr('rel',reld);
		
	}else{
		$('#box_convert_brend_us').hide();
		var reld="размер EUR"
		$('#input_convert').val(reld);
		$('#input_convert').attr('rel',reld);
	
	}

}
function top_filter_size(num){
	$('#filtr_size').val(num);
	$('#filtr_cat').val('1');
	$('#top_filter').submit();
}
function top_filter_age(num){
	$('#filtr_age').val(num);
	$('#filtr_cat').val('1');
	$('#top_filter').submit();
}
function top_filter_cat(num){
	$('#filtr_cat').val(num);
	$('#top_filter').submit();
}
function top_filter_menu(num){
//	$('.top_float_menu_0').removeClass('m1 m2 m3'); 
	var old=$('#filtr_body').val();
//	if(num!=3&&num!=4) 
		$('#filtr_body').val(num);
	var clas='m'+num;
/*	$('.top_float_menu_0').addClass(clas);
	if( $('.top_float_menu_0').is(':hidden') ) {
        $('.top_float_menu_0').show();
	}else{
		if(old==num){
			$('.top_float_menu_0').hide();
			$('.top_float_menu_1').hide();
			$('.top_float_menu_2').hide();
			$('#top_float_menu_0_box_1').removeClass('activ');	
			$('#top_float_menu_0_box_1 img').attr('src','/images/fl_menu_1.png');
		}
	}		
	if(num==3){
		$('.top_float_menu_1').hide();
		$('.top_float_menu_2').hide();
		$('#top_float_menu_0_box_1').removeClass('activ');	
		$('#top_float_menu_0_box_1 img').attr('src','/images/fl_menu_1.png');
	}*/
}

function itemincart(num,anc){
	var name='cart_item[i'+num+'][count]';
	var cok=GetCookie(name);
	if(!cok){
		SetCookie('cart_item[i'+num+'][count]',1,largeExpDate,pathname);	
		$(anc).html('В корзине')
		$(anc).parent().addClass('incart');
		var inc=$('#labelincart').html();
		if(inc=='пусто') inc=0;
		var count = parseInt(inc)+1;
		var str = count.toString( );
		var n=str.length-1;
		var str2='товар';	
		if(str[n]>1&&str[n]<5&&(str<10||str>20)) str2='товара';
		else if(str[n]!=1||(str>10&&str<20)) str2='товаров';		
		$('#labelincart').html(str+' '+str2);
		var size=$('#item_size').val();
		if(size){
			SetCookie('cart_item[i'+num+'][size]',size,largeExpDate,pathname);		
		}
	}
}
function deletefromcart(id){
	var num=$('#count_'+id).val();
	$('#item_'+id).remove();
	var name='cart_item['+id+'][count]';
	DelCookie(name);
	name='cart_item['+id+'][size]';
	DelCookie(name);
	var inc=$('#labelincart').html();
	var count = parseInt(inc)-num;
	if(count>0){
		var str = count.toString( );
		var n=str.length-1;
		var str2='товар';	
		if(str[n]>1&&str[n]<5&&(str<10||str>20)) str2='товара';
		else if(str[n]!=1||(str>10&&str<20)) str2='товаров';		
		$('#labelincart').html(str+' '+str2);
	}else  window.location = '/';

	var coun=$('input[id^=count_]');
	var totatcount=0;
	var totatprice=0;
	jQuery.each(coun, function() {
		var d=this.id.split('_');
		var id=d[1];
		price=$('#price_'+id).val();
		totatcount+=parseInt(this.value);
		totatprice+=parseInt(this.value)*parseInt(price);
		
    });
	var str = totatcount.toString( );
	var n=str.length-1;
	var str2='товар';	
	if(str[n]>1&&str[n]<5&&(str<10||str>20)) str2='товара';
	else if(str[n]!=1||(str>10&&str<20)) str2='товаров';		
	$('#labelincart, .labelincart').html(str+' '+str2);
	$('.totasumm').html(totatprice+' P');	
}
function cartchangecount(imp,id){
	var num=imp.value;
	if(!parseInt(num)) num=1;
	num=parseInt(num)
	imp.value=num;
	var price=$('#price_'+id).val();
	var tot=num*price;
	$('#totprice_'+id).html(tot+' P');
	SetCookie('cart_item['+id+'][count]',num,largeExpDate,pathname);
	
	var coun=$('input[id^=count_]');
	var totatcount=0;
	var totatprice=0;
	jQuery.each(coun, function() {
		var d=this.id.split('_');
		var id=d[1];
		price=$('#price_'+id).val();
		totatcount+=parseInt(this.value);
		totatprice+=parseInt(this.value)*parseInt(price);
		
    });
	var str = totatcount.toString( );
	var n=str.length-1;
	var str2='товар';	
	if(str[n]>1&&str[n]<5&&(str<10||str>20)) str2='товара';
	else if(str[n]!=1||(str>10&&str<20)) str2='товаров';		
	$('#labelincart, .labelincart').html(str+' '+str2);
	$('.totasumm').html(totatprice+' P');
}
function cartchangesize(imp,id){
	SetCookie('cart_item['+id+'][size]',imp.value,largeExpDate,pathname);
	
}
//----------------------------------------------------------------------------------
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}
function SetCookie (name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" +
expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}
function DelCookie (cookie_name) {
	var cookie_date = new Date ();
	cookie_date.setTime (cookie_date.getTime() - 1);
	document.cookie = cookie_name += "=; path=/; expires=" + cookie_date.toGMTString();
}
function getCookieIndex (offset) {
   var endstr = document.cookie.indexOf ("]", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
// -------------------------------------------------------------------------------
// ------------------------------------------------------------------------------- order
var orderstep=1;
function changeorderstep(){
	$('.order_paginav span').removeClass('activ');	
	$('#pag_st_'+orderstep).addClass('activ');	
	var error=0;
	switch(orderstep){
		case 2:
			$('.step_1').hide();	
			$('.step_2').show();	
			window.location.hash="step_2";
		break;
		case 3:
			if($('input[name=order_auth]:checked').val()=='2'){
				if($.trim($('#name_reg').val())&&$.trim($('#email_reg').val())){
					var rez="Покупатель: <span>"+$('#name_reg').val()+"</span> (электронная почта: <span>"+$('#email_reg').val()+"</span>).";
					$('#step_2_rez').html(rez);
				}else{
					error=1;
				}
			}
			if(error==0&&chkmail){
				$('.step_1').hide();
				$('.step_2').hide();	
				$('.step_3').show();	
				$('.step_4').hide();	
				$('.step_5').hide();	
				$('.step_6').hide();	
				window.location.hash="step_3";
			}
		break;
		case 4:
			var id=$('input[name=order_delivtype]:checked').val();
			var name='';
			var descr='';
			if(id==1) {name='Почтой России';descr='Осуществляется в течение 20 календарных дней с момента оплаты.<br>Стоимость доставки почтой России — <span>73 рубля 50 копеек.</span>';}
			if(id==2) {name='Курьером';descr=$('#order_delivtype_2').val();}
			if(id==0) {name='Самовывоз';descr=$('#order_delivtype_0').val();}
			$('#order_delivtype_rez').html(name);
			$('#order_delivtype_com').html(descr);
			var coun=$('input[name=tel\[\]]');
			var tel='';
			var i=1;
			jQuery.each(coun, function() {
				if($.trim(this.value)){
					tel=tel+"<div class='order_leftsel'><label>Телефон"+(i>1?' '+i:'')+":</label></div><div class='text_order_deliver_typeinf tel'>"+this.value+"</div><br class='clear'><br class='clear'>";
					i++;
				}
			});
			if(tel=='') error=1;
			
			$('#order_tels_rez').html(tel);
			var descr=$('#comment').val();
			if($.trim(descr)){
				$('#order_coms_rez').html('Комментарии по доставке:');
				$('#order_coms_rez2').html(descr);
			}else{
				$('#order_coms_rez').html('Вы не оставили никаких комментариев по доставке.');
				$('#order_coms_rez2').html(' ');
			
			}
			if(error==0){

				$('.step_1').hide();
				$('.step_2').hide();	
				$('.step_3').hide();	
				$('.step_4').show();	
				$('.step_5').hide();	
				$('.step_6').hide();
				
				$('.box_orderinfo.step_3').show();	
				$('.box_orderinfo_auth.step_3').show();	
				window.location.hash="step_4";
				
				if(id==0) {
					$('#order_addres_rez').html($('#order_delivtype_0').val());
					$('.step_1').hide();
					$('.step_2').hide();	
					$('.step_3').hide();	
					$('.step_4').hide();	
					$('.step_5').show();	
					$('.step_6').hide();
						
					$('.box_orderinfo.step_3').show();	
					$('.box_orderinfo_auth.step_3').show();	
					$('.box_orderinfo.step_4').show();	
					window.location.hash="step_5";
				}
			}
		break;
		case 5:
			var id=$('input[name=order_addres]:checked').val();
			var rez=$('#order_addres_text_'+id).val();
			$('#order_addres_rez').html(rez);
			$('.step_1').hide();
			$('.step_2').hide();	
			$('.step_3').hide();	
			$('.step_4').hide();	
			$('.step_5').show();	
			$('.step_6').hide();
				
			$('.box_orderinfo.step_3').show();	
			$('.box_orderinfo_auth.step_3').show();	
			$('.box_orderinfo.step_4').show();	
			window.location.hash="step_5";
			
		break;
		case 6:
			var id=$('input[name=order_paytype]:checked').val();
			var name='';
			var descr='';
			if(id==1) {name='Наличными';descr='Оплата наличными принимается при самовывозе из наших офисов или доставке курьером';}
			if(id==2) {name='Электронными деньгами';descr='Оплата с помощью Visa/MasterCard, Яндекс.Деньги, Интернет-банкинг и т.д.';}
			$('#order_paytype_rez').html(name);
			$('#order_paytype_com').html(descr);

			$('.step_1').hide();
			$('.step_2').hide();	
			$('.step_3').hide();	
			$('.step_4').hide();	
			$('.step_5').hide();
			$('.step_6').hide();
			if(id==1){
				$('.step_6.cash').show();
			}else{
				$('.step_6.pay').show();
			}	
			
			$('.box_orderinfo.step_3').show();	
			$('.box_orderinfo_auth.step_3').show();	
			$('.box_orderinfo.step_4').show();	
			$('.box_orderinfo.step_5').show();	
			$('.box_orderinfo.step_6').show();	
			window.location.hash="step_6";
		break;
	
	}

}
function orderaddtel(){
	ht="<br class='clear'><div class='input order_addresinput'><input type='text' name='tel[]' /><span class='right'></span></div>";
	$('#order_zoneinput_tels').append(ht);
}
function checklogin(){
	var login=$('#email_log').val();
	var psw=$('#pwd_log').val();
	$.ajax({
	   type: "POST",
	   url: "/data/data.php",
	   data: "type=1&email="+login+"&pwd="+psw,
	   success: function(msg){
		if($.trim(msg)!='<script language="JavaScript">window.location.reload(true)</script>'){
			$('#order_error_mail_log').html(msg);
			$('#order_error_mail_log').show();
		}else{
			window.location.reload(true);
		}
	   }
	 });

}
var chkmail=1;
function checkemail(){
	var login=$('#email_reg').val();
	$.ajax({
	   type: "POST",
	   url: "/data/data.php",
	   data: "type=4&email="+login,
	   success: function(msg){
		if($.trim(msg)!='ok'){
			$('#order_error_mail_reg').html(msg);
			$('#order_error_mail_reg').show();
			chkmail=0;
		}else{
			$('#order_error_mail_reg').hide();
			chkmail=1;
		}
	   }
	 });

}
// ------------------------------------------------------------------------------- /order
