function print_r(theObj){
   if(theObj.constructor == Array || theObj.constructor == Object){
      document.write("<ul>")
      for(var p in theObj){
         if(theObj[p].constructor == Array || theObj[p].constructor == Object){
            document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
            document.write("<ul>")
            print_r(theObj[p]);
            document.write("</ul>")
         } else {
            document.write("<li>["+p+"] => "+theObj[p]+"</li>");
         }
      }
      document.write("</ul>")
   }
}

$(document).ready(function(){
	$(".left_menu A").click(function () {
		addCookie('delCookie',true,1);
	});
	
	$('.use_button').click(function () {
		//window.location.href = window.location.href.replace(/_page(\d)/,'');
		//window.location.reload();
		addCookie('delCookie',true,1);
		window.location.reload();
	})
	$(".reset_filters").click(function () {
		addCookie('delCookie',true,1);
		window.location.reload();
	});
	$('#category_filters A').click(function () {
		addCookie('page',1,1);
	})
	

	$('#tooltip[title]').qtip({
	position: {
		adjust: {
			method: "flip flip"
		},
		my: "top left",
		at: "bottom right",
		viewport: $(window)
	}
   });
})




$(document).ready(function(){
	var faderHeight = $("#main").height()+$(".top_panel").height()+15;
	$('#fader').css({opacity:"0.6",	"height": faderHeight});
	$(".open_popup").click(function(){
		Height = $("#main").height()+$(".top_panel").height()+15;
		$('#fader').fadeIn();
		if (document.getElementById(this.rel)) {
			$("#" + this.rel).fadeIn("slow");
		}
		Div = $("#" + this.rel);
		Left = $(this).parent().offset().left;
		Top = $(this).parent().offset().top;
		Div.css(
			{
			"left":Left,
			"top":Top
			}
		)
		
		$("#fader").click(function(){
			$('.popup').fadeOut();
			$(this).fadeOut();
		});
		$(".clouse_popup").click(function(){
			$('.popup').fadeOut();
			$("#fader").fadeOut();
		});
		
	});
	
	
});

$(document).ready(function(){
	$(".open_box").click(function () {
		$(this).toggleClass ("open_box_active");
		$(".form_us_drop").slideToggle("slow");
	});
	
	/* for menu*/
	Hdv = $("#Obernds").height();
	$("#Obernds").css("height","94px").css("overflow", "hidden");
	$("#left_column a.more").click(function (){
		$("#Obernds").animate({height:Hdv}).show("slow");
		$(this).css("display","none");
	});
	
	$("#search_form_tx a").click(function (){
		$(this).parent().find("a").removeClass ("active");
		$(this).addClass ("active");
	});
	
	
	$(document).ready(function() {
		for (var i=0; i<$('#catalog_sections li').size(); i+=3) {
			$('#catalog_sections li:eq('+i+')').css('clear', 'both');
		}
		$("#feedbacks div").hide();
		$("#feedbacks div").first().show();
		$("#next_feedback").click(function (){
			$("#feedbacks").find("div:visible").hide("slow").addClass("hidden_feedback").next("div:hidden").show("slow");
			if ($('#feedbacks div:last').hasClass("hidden_feedback")) {
				$("#feedbacks div").first().show("slow");
				$("#feedbacks div").removeClass("hidden_feedback");
			}
		});
		
	});
	$(document).ready(function() {
		for (var i=0; i<$('#sort_result li').size(); i+=5) {
			$('#sort_result li').eq(i).css('clear', 'both');
		}
	});
	$(document).ready(function() {
		for (var i=0; i<$('#right_column .feedbacks li').size(); i+=2) {
			$('#right_column .feedbacks li').eq(i).css('clear', 'both');
		}
	});
});
$(document).ready(function(){


	$("#category_filters .filters a, .category_pages li ul li a, #cabinet_navigation li a").live("click", function() {
		//$(this).parent().parent().find("a").removeClass("current");
		//$(this).addClass("current");
	});
	$("#category_filters a.reset_filters").click(function() {
		$("#category_filters .filters a").removeClass("current");
	});
	$("#category_filters .filters.addition").toggle();
	$("#category_filters a.addition_switch").click(function() {
		if ($(this).hasClass("showed")) {
			$(this).text("Дополнительные параметры").removeClass("showed");
		}
		else {
			$(this).text("Базовые параметры").addClass("showed");
		}
		$("#category_filters .filters.addition").toggle("slow");
	});
	
	/* Catalog Sort Result Title Hover */
	
	$("#sort_result li").mouseover(function (){
		$(this).find(".title a").css("color", "#363636");
	});
	$("#sort_result li").mouseleave(function (){
		$(this).find(".title a").css("color", "#6b6b6b");
	});
	
	/* Catalog Foto Hover */
	
	$(".catalog_big_img_box").hide().css("position", "absolute");
	$(".catalog_big_img_box img").css("width", "350").css("height", "350").css("z-index", "35000");;
	//$("#sort_result img, #sort_result_table img").live("mouseover",function() {
	$("#sort_result img, #sort_result_table img").mouseover(function() {
		jQuery('.catalog_big_img_box').find('img').attr('src',this.src.replace('w110h110t2', 'w350h350t2wm1')); 
		$(".catalog_big_img_box").stop(true, true);;
		$(".catalog_big_img_box").delay(400).show(0);
		$(this).mousemove(function(event) {
			$(".catalog_big_img_box").show(0);
			var x = event.clientX;
			var y = event.clientY;
			var x1 = window.innerWidth;
			var y1 = window.innerHeight;
			var x2 = event.pageX;
			var y2 = event.pageY;
			if (y1 - y < 260) {
				y2 -= 240;
			}
			if (x1 - x < 400) {
				x2 -= 400;
			}
			$(".catalog_big_img_box").css("left", Number(x2) + Number(20)).css("top", Number(y2) - Number(100));
		//	$(".catalog_big_img_box").css({top:event.pageY-20,left:event.pageX+20});
		});
		$(this).mouseleave(function() {
			$(".catalog_big_img_box").delay(0).hide(0);
		});
	});
	
	/* Catalog Result View Switcher */
/*	
	$("#sort_result").hide();
	$(".category_pages .view_switch a.foto").click(function (){
		$(".category_pages .view_switch a.table").removeClass("current");
		$(".category_pages .view_switch a.foto").addClass("current");
		$("#sort_result").show();
		$("#sort_result_table").hide();
	});
	$(".category_pages .view_switch a.table").click(function (){
		$(".category_pages .view_switch a.foto").removeClass("current");
		$(".category_pages .view_switch a.table").addClass("current");
		$("#sort_result").hide();
		$("#sort_result_table").show();
	});
*/	
	/* Catalog Buy Form */
	
	$("#sort_result .buy_form .text, #sort_result_table .buy_form .text, .lot_purchase_form .text").live("click", function() {
		$(this).select();
	});
	
	$('#sort_result .buy_form .text, #sort_result_table .buy_form .text, .lot_purchase_form .text').live("keydown", function(e){
     if(e.keyCode==13)
     {
          //alert('нажал клавишу enter');
		 // alert($(this).parent().find(".to_cart").attr("value"));
	//	  $(this).parent().find(".to_cart").attr("value","000");
		  $(this).parent().parent().find(".to_cart").click();
		  $(this).parent().find(".to_cart").click();
		//  e.keyCode=9;
	 }
	});
////////////////////////
// первоначальный просчет корзины
	$(this).find("#formbas .goodsItem").each(function(){
		str = $(this).find(".main_price span").text();
		x = $(this).find(".text").val();
		str = str.replace(',','.');
		str = str.replace(' ','');
		var allPrice = str * x;
//		allPrice = Math.floor(allPrice) + ',' + Math.round((allPrice - Math.floor(allPrice))*100);
		allPrice = getAllPrice(allPrice);
		$(this).find(".all_price span").text(allPrice);

	});
	fullPriceCalc();
// первоначальный просчет корзины
////////////////////////

	var priceCalcTimeout;
	$("#sort_result .buy_form .more, #sort_result_table .buy_form .more, .lot_purchase_form .more").live("click", function() {
		var x = Number($(this).parent().children(".text").val()) + Number(1);
		if (x > 0) {

		str=$(this).parent().parent().parent().find(".main_price span").text();
		str = str.replace(',','.');
		str = str.replace(' ','');

			$(this).parent().children(".text").val(x);
			var el = $(this);
			var allPrice = str * x;
			//allPrice = Math.floor(allPrice) + ',' + Math.floor((allPrice - Math.floor(allPrice))*100);
			allPrice = getAllPrice(allPrice);
			var name = $(this).parent().children(".text").attr("name");
			clearTimeout(priceCalcTimeout);
			priceCalcTimeout = setTimeout (function () {
				allP(el, allPrice);
				fullPriceCalc();
				changeCount(name, x);
			}, 200);
		}
	});
	
	$("#sort_result .buy_form .less, #sort_result_table .buy_form .less, .lot_purchase_form .less").live("click", function() {
		var x = Number($(this).parent().children(".text").val()) - Number(1);
		if (x > 0) {

		str=$(this).parent().parent().parent().find(".main_price span").text();
		str = str.replace(',','.');
		str = str.replace(' ','');

			$(this).parent().children(".text").val(x);
			var el = $(this);
			var allPrice = str * x;
			//allPrice = Math.floor(allPrice) + ',' + Math.round((allPrice - Math.floor(allPrice))*100);
			allPrice = getAllPrice(allPrice);
			var name = $(this).parent().children(".text").attr("name");
			clearTimeout(priceCalcTimeout);
			priceCalcTimeout = setTimeout (function () {
				allP(el, allPrice);
				fullPriceCalc();
				changeCount(name, x);
			}, 200);
		}
	});
	function allP(el, allPrice) {
		$(el).parent().parent().parent().find(".all_price span").text(allPrice);
	}

	$('.buy_form .text').bind('keypress', function(e) 
	{
     if(e.keyCode==13)
     {
          //alert('нажал клавишу enter');
		 // e.keyCode=9;
	$("#formbas .goodsItem").each(function(){
		str = $(this).find(".main_price span").text();
		x = $(this).find(".text").val();
		str = str.replace(',','.');
		str = str.replace(' ','');
		var allPrice = str * x;
//		allPrice = Math.floor(allPrice) + ',' + Math.round((allPrice - Math.floor(allPrice))*100);
		allPrice = getAllPrice(allPrice);
		$(this).find(".all_price span").text(allPrice);

	});
	fullPriceCalc();


	 return false;
     }
	});

	function changeCount(name,x){
		//alert(name + ' ' + x);
		///basket/col_31_100.html
		if($("#formbas .goodsItem").html()){
			$.ajax({
			   type: "GET",
			   url: "/basket/"+name+"_"+x+".html",
			   data: "",
			   success: function(msg){
				//alert(msg);
			   }
			 });
		}
	}




/*	$("#sort_result .buy_form .text, #sort_result_table .buy_form .text, .lot_purchase_form .text").live("focusout", (function () {
		if (isNaN ($(this).val()) || $(this).val() <= 0 || $(this).val() != Math.floor($(this).val())) {
			alert("В качестве количества товара может быть только целое положительное число");
		}
		else {
			str = $(this).parent().parent().parent().find(".main_price span").text();
			str = str.replace(',','.');
			str = str.replace(' ','');
			var allPrice = str * $(this).val();
			//allPrice = Math.floor(allPrice) + ',' + Math.round((allPrice - Math.floor(allPrice))*100);
			allPrice = getAllPrice(allPrice);
			$(this).parent().parent().parent().find(".all_price span").text(allPrice);
			var name = $(this).attr("name");
			fullPriceCalc();
			changeCount(name, $(this).val());
		}
	});
	*/
	$("#cart a.flashing").hide();
	$("#cart a.window_flashing").hide();


	$("#sort_result .buy_form .to_cart, #sort_result_table .buy_form .to_cart, .lot_purchase_form .to_cart").live("click", function() {
		if (isNaN ($(this).parent().find(".text").val()) || $(this).parent().find(".text").val() <= 0 || $(this).parent().find(".text").val() != Math.floor($(this).parent().find(".text").val())){
			alert("В качестве количества товара может быть только целое положительное число");
		}
		else {
		/*	var c = Number ($(this).parent().children(".text").val());
			var x = Number($(this).parent().parent().parent().parent().find(".main_price span").text()) * Number(c);
			var y = Math.floor(x);
			var z = Math.floor((Number(x) - Number(y)) * Number(100) + Number($("#cart i").text()));
		*/	/*y += Number($("#cart strong").text());
			if (z >= 100) {
				y += Math.floor(Number(z) / 100);
				z = Math.round((Number(z) / 100 - Math.floor(Number(z) / 100)) * 100);
			}*/
			//c += Number($("#cart span").text());
			/*$("#cart strong").text(y);
			$("#cart i").text(z);
			$("#cart span").text(c);
			*/

			$.ajax({
			   type: "GET",
			   url: "/basket/add_"+$(this).attr("id")+"_"+$(this).parent().find(".text").val()+".html",
			   data: "",
			   success: function(msg){
				$("#cart a.cart_info").html(msg);
			   }
			 });

			
			/* Animate */
			
			if ($(document).scrollTop() > 150) {
				$("#cart a.window_flashing").stop(true, true);
				$("#cart a.window_flashing").fadeIn(1500).fadeOut(1500).hide(0);
			}
			else {
			//	$("#cart a.cart_info").stop(true, true);
			//	$("#cart a.flashing").stop(true, true);
			//	$("#cart a.cart_info").hide(0).delay(3000).show(0);
			//	$("#cart a.flashing").fadeIn(1500).fadeOut(1500).hide(0);
			$("#cart a.cart_info").stop(true, true);
			$("#cart a.flashing").stop(true, true);
			$("#cart a.cart_info").hide(0).delay(1000).show(0);
			$("#cart a.flashing").fadeIn(500).fadeOut(500).hide(0);
			}
		}
	});
	
	/* Bottom Panel */
	if ($(".personal_cabinet #sort_result_table tr").size() < 6) {
		//$(".personal_cabinet .purchase_panel.bottom").hide();
	}
	
	/* Delivery Form */
	function noRegPurchaseFormHider() {
		$(".no_reg_purchase_form .phis_not_delivery_form").hide();
		$(".no_reg_purchase_form .phis_delivery_form").hide();
		$(".no_reg_purchase_form .yur_delivery_form").hide();
		$(".no_reg_purchase_form .yur_not_delivery_form").hide();
	}
	noRegPurchaseFormHider();
	$(".no_reg_purchase_form .phis_not_delivery_form").show();
	$(".no_reg_purchase_form .not_delivery").click(function (){
		if ($(".no_reg_purchase_form .phis").attr("checked").valueOf("checked")) {
			noRegPurchaseFormHider();
			$(".no_reg_purchase_form .phis_not_delivery_form").show();
		}
		else {
			noRegPurchaseFormHider();
			$(".no_reg_purchase_form .yur_not_delivery_form").show();
		}
	});
	$(".no_reg_purchase_form .delivery").click(function (){
		if ($(".no_reg_purchase_form .phis").attr("checked").valueOf("checked")) {
			noRegPurchaseFormHider();
			$(".no_reg_purchase_form .phis_delivery_form").show();
		}
		else {
			noRegPurchaseFormHider();
			$(".no_reg_purchase_form .yur_delivery_form").show();
		}
	});
	$(".no_reg_purchase_form .phis").click(function (){
		if ($(".no_reg_purchase_form .not_delivery").attr("checked").valueOf("checked")) {
			noRegPurchaseFormHider();
			$(".no_reg_purchase_form .phis_not_delivery_form").show();
		}
		else {
			noRegPurchaseFormHider();
			$(".no_reg_purchase_form .phis_delivery_form").show();
		}
	});
	$(".no_reg_purchase_form .yur").click(function (){
		if ($(".no_reg_purchase_form .delivery").attr("checked").valueOf("checked")) {
			noRegPurchaseFormHider();
			$(".no_reg_purchase_form .yur_delivery_form").show();
		}
		else {
			noRegPurchaseFormHider();
			$(".no_reg_purchase_form .yur_not_delivery_form").show();
		}
	});


	/* Catalog Gallery */
	var lotPhotosCurrent=1;
	var x = $('.lot_info_box .lot_photos a.current').parent().size();
	$('.lot_info_box .lot_photos li').eq(x).children("a").addClass("current");
	$('#lot_big_photo .left').hide();
			if($('.lot_info_box .lot_photos li img').size() == 0){
				//alert(0);/photo_modules/nojpg.jpg
				$('.lot_info_box .img_box img').attr("src", '/images/w350h350t2/350x250.png');
			}else if($('.lot_info_box .lot_photos li img').size() == 1){
				$('#lot_big_photo .right').hide();
			}
			$('.lot_info_box .lot_photos li a').removeClass('current');
			$('.lot_info_box .lot_photos li').eq(0).children("a").addClass("current");
//alert($('.lot_info_box .lot_photos li img').size());

	if ($('.lot_info_box .lot_photos a.current img').index() >= 0) {

		var mainFileSrc = $('.lot_info_box .lot_photos a.current img').attr("src");

//		var mainFileType = "." + mainFileSrc.charAt(mainFileSrc.length - 3) + mainFileSrc.charAt(mainFileSrc.length - 2) + mainFileSrc.charAt(mainFileSrc.length - 1);
	//	$('.lot_info_box .img_box img').attr("src", mainFileSrc.replace(mainFileType, "_big" + mainFileType));

		$('.lot_info_box .lot_photos img').click(function (){

			$('.lot_info_box .lot_photos a').removeClass("current");
			$(this).parent().addClass("current");
			//var fileSrc = $(this).attr("src");
			//var fileType = "." + fileSrc.charAt(fileSrc.length - 3) + fileSrc.charAt(fileSrc.length - 2) + fileSrc.charAt(fileSrc.length - 1);
			$('.lot_info_box .img_box img').attr("src", this.src.replace('w45h45t2', 'w350h350t2wm1'));
			setCurrent($(this).parent().parent().index());
		});
		$('#lot_big_photo').hide();

		$('.lot_info_box .img_box IMG').click(function () {
			$("#fader").fadeIn();
			//$("#lot_big_photo .main_photo img").attr("src", $(this).attr("src"));
			$("#lot_big_photo .main_photo img").attr("src", this.src.replace('w350h350t2wm1', 'w600h600t2wm1'));
			$('#lot_big_photo').show();
			return false;
		});
		$('#lot_big_photo .main_photo img, #fader, #lot_big_photo .close').click(function() {
			$("#fader").hide();
			$("#lot_big_photo").hide();	
		});
		$('#lot_big_photo .left').click(function() {
			var x = $('.lot_info_box .lot_photos a.current').parent();
			$('.lot_info_box .lot_photos').find(".current").removeClass("current")
			$('.lot_info_box .lot_photos li').eq(x - 1).children("a").addClass("current");
			setCurrent(lotPhotosCurrent - 1);
		});
		$('#lot_big_photo .right').click(function() {
			var x = $('.lot_info_box .lot_photos a.current').parent().size();
			$('.lot_info_box .lot_photos').find(".current").removeClass("current")
			$('.lot_info_box .lot_photos li').eq(x + 1).children("a").addClass("current");
			setCurrent(lotPhotosCurrent + 1);
		});
		
		var lotPhotosCurrent = $('.lot_info_box .lot_photos a.current').parent().index();
		function setCurrent(i) {
			lotPhotosCurrent = i;
			//alert(lotPhotosCurrent + ($('.lot_info_box .lot_photos li').size() - 1));
			if (lotPhotosCurrent == 0) {
				$('#lot_big_photo .left').hide();
			}else{
				$('#lot_big_photo .left').show();
			}
			if (lotPhotosCurrent == $('.lot_info_box .lot_photos li').size() - 1) {
				lot_photosCurrent = $('.lot_info_box .lot_photos li').size() - 1;
				$('#lot_big_photo .right').hide();
			}
			else {
				$('#lot_big_photo .right').show();	
			}
			$('.lot_info_box .lot_photos li a').removeClass('current');
			$('.lot_info_box .lot_photos li:eq('+lotPhotosCurrent+') a').addClass('current');
			//var fileSrc = $(".lot_info_box .lot_photos li a.current img").attr("src");
			//var fileType = "." + fileSrc.charAt(fileSrc.length - 3) + fileSrc.charAt(fileSrc.length - 2) + fileSrc.charAt(fileSrc.length - 1);
			//alert($(".lot_info_box .img_box img").attr("src").replace('w350h350t2', 'w600h600t2'));
			$('.lot_info_box .img_box img').attr("src", $(".lot_info_box .lot_photos li a.current img").attr("src").replace('w45h45t2', 'w350h350t2wm1'));
			$("#lot_big_photo .main_photo img").attr("src", $(".lot_info_box .img_box img").attr("src").replace('w350h350t2', 'w600h600t2'));
		}
	}	
	
});

	/* Full Price */
	
	
	function getAllPrice(allPrice){
		a1 =  Math.round((allPrice - Math.floor(allPrice))*100) + '';
		if(a1.length<2){a1=a1+'0';};
		if(a1.length<2){a1=a1+'0';};
		a0 = Math.floor(allPrice)+'';
		if(a0.length==6){a0 = a0.substr(0,3) +' '+ a0.substr(3,3);};
		if(a0.length==5){a0 = a0.substr(0,2) +' '+ a0.substr(2,3);};
		if(a0.length==4){a0 = a0.substr(0,1) +' '+ a0.substr(1,3);};
		return  a0 + ',' + a1;
	}


function fullPriceCalc() {
	if($(".step2").text()){return;}
	var fullPrice = 0;
	for (var i=1; i<$('#sort_result_table tr').size(); i++) {
		str=$("#sort_result_table tr").eq(i).find(".all_price span").text();
		//alert(str);
		str = str.replace(',','.');
		str = str.replace(' ','');
		fullPrice += Number(str);
	}
	//formatSumm = Math.floor(fullPrice) + ',' + Math.round((fullPrice - Math.floor(fullPrice))*100);
	//alert(formatSumm);
	formatSumm = getAllPrice(fullPrice) + '';
	
	
	var salePrice=0;
	$(".goodsItem").each(function(){
		str = $(this).find(".sale_price").text();
		if(str > ''){
			x = $(this).find(".text").val();
			salePrice = salePrice + str * x;
		}
	});
	
	//$(".purchase_panel p strong b.prices").text(Math.floor(fullPrice));
	$(".purchase_panel p strong b.prices").text('');
	//$(".purchase_panel p strong span.prices").text((fullPrice - Math.floor(fullPrice)) * 100);

	var x = $(".purchase_panel p strong b.prices").text().length;
	var y = $(".purchase_panel p strong b.prices").text().charAt(x - 1);
	var z = $(".purchase_panel p strong b.prices").text().charAt(x - 2);
	var x1 = $(".purchase_panel p strong span.prices").text().length;
	var y1 = $(".purchase_panel p strong span.prices").text().charAt(x - 1);
	var z1 = $(".purchase_panel p strong span.prices").text().charAt(x - 2);

			$.ajax({
			   type: "GET",
			   url: "/summ_sale_block.php?salesumm="+salePrice,
			   data: "",
			   success: function(msg){
				$("#formbas .action").html(msg);
			   }
			 });

			$.ajax({
			   type: "GET",
			   url: "/summ_sale_block.php?type=price&summ="+fullPrice+"&salesumm="+salePrice,
			   data: "",
			   success: function(msg){
				$(".purchase_panel p").html(msg);
			   }
			 });

	/*if (y == 0 || y >= 5 || z == 1) {
		$(".purchase_panel p strong b.text").text("рублей")
	}
	else if (y == 1) {
		$(".purchase_panel p strong b.text").text("рубль")
	}
	else if (y > 1 && y <= 4) {
		$(".purchase_panel p strong b.text").text("рубля")
	}
	if (y1 == 0 || y1 >= 5 || z1 == 1) {
		$(".purchase_panel p strong span.text").text("копеек")
	}
	else if (y1 == 1) {
		$(".purchase_panel p strong span.text").text("копейка")
	}
	else if (y1 > 1 && y1 <= 4) {
		$(".purchase_panel p strong span.text").text("копейки")
	}
	*/
};













function addCookie(szName,szValue,dtDaysExpires) 
{
   var dtExpires = new Date();
   var dtExpiryDate = "";

   dtExpires.setTime(dtExpires.getTime() + 
     dtDaysExpires * 24 * 60 * 60 * 1000);

   dtExpiryDate = dtExpires.toGMTString();

   document.cookie = 
    szName + "=" + szValue + "; expires=" + dtExpiryDate + "; path=/;";
}

function findCookie(szName) 
{
  var i = 0;
  var nStartPosition = 0;
  var nEndPosition = 0;  
  var szCookieString = document.cookie;  

  while(i <= szCookieString.length) 
  {
    nStartPosition = i;
    nEndPosition = nStartPosition + szName.length;

    if(szCookieString.substring( 
        nStartPosition,nEndPosition) == szName) 
    {
      nStartPosition = nEndPosition + 1;
      nEndPosition = 
        document.cookie.indexOf(";",nStartPosition);

      if(nEndPosition < nStartPosition)
        nEndPosition = document.cookie.length;

      return document.cookie.substring( 
          nStartPosition,nEndPosition);  
      break;    
    }
    i++;  
  }
  return "";
}

function removeCookie(szName) 
{
  var dtExpires = new Date();
  dtExpires.setTime(dtExpires.getTime() - 1000);

  var szValue = findCookie(szName);

  document.cookie = szName + "=" + szValue +
    "; expires=" + dtExpires.toGMTString();
}

function addFilter(cname){
	if(findCookie(cname) == "")
	{
		// cookie  не установлен
		addCookie(cname,true,1);
		//$("#"+cname).addClass( "menu_inside_active" );
	//alert("add "+cname);
	}
	else
	{
		// cookie  установлен
		removeCookie(cname);
		//$("#"+cname).removeClass( "menu_inside_active" );
	//alert("remove "+cname);
	}
}

function getFilter(cname, obj){
	if(findCookie(cname) != "")
	{ 

		//$("#"+cname).addClass( "menu_inside_active" );
		var ob = document.getElementById(cname);
				/*ob.style.border="1px solid #C4C4C4";
				ob.style.backgroundColor="#FFF9DD";
				ob.style.color="#A80B0F";*/
				$(ob).addClass("current");
				ob.chStatus=true;
	//alert("remove "+cname);
	}
}

		function filt(ob){
		 var str = navigator.appVersion;
		 var reg = /MSIE[\s]([\d])/i;
		 var matches = str.match(reg);
			if(ob.chStatus!=true){
				/*ob.style.border="1px solid #C4C4C4";
				ob.style.backgroundColor="#FFF9DD";
				ob.style.color="#A80B0F";
				*/
				ob.chStatus=true;
				$(ob).addClass("current");
				//addFilter(ob.name);
				addCookie(ob.name,true,1);
				  if (str.indexOf('MSIE') > 0 && matches[1] < '7') {
					  window.location.reload();
				  }else{
					  getAjaxContent(window.location.href,'AjaxBody');
				  }
			}else{
				/*ob.style.border="0px";
				ob.style.backgroundColor="";
				ob.style.color="#369807";*/
				//alert('ggg');
				$(ob).removeClass("current");
				ob.chStatus=false;
				//addFilter(ob.name);
				removeCookie(ob.name);
				  if (str.indexOf('MSIE') > 0 && matches[1] < '7') {
					  window.location.reload();
				  }else{
					  getAjaxContent(window.location.href,'AjaxBody');
				  }
			}
			return false;
		};
		
function priceChange(ob){
	addCookie(ob.name,ob.value,1);
}




	function getAjaxContent(url,ret){
		 var str = navigator.appVersion;
		 var reg = /MSIE[\s]([\d])/i;
		 var matches = str.match(reg);
		  if (str.indexOf('MSIE') > 0 && matches[1] < '7') {
			  return true;
		  }
		//alert( window.location.href);
	 			if ($(document).scrollTop() > 500) {window.location.href='#Ajax';}
		 		$("div.window_ajax").stop(true, true);
				$("div.window_ajax").fadeIn(250);
		$("#"+ret).html('<div style="height:700px;"></div>');
		
	/*		$.ajax({
			   type: "POST",
			   url: url,
			   data: {AjaxData: "true"},
			   success: function(msg){
				$("#"+ret).html(msg);
			   }
			 });
		*/	 
			
			$.post(url, { AjaxData: "true"},
					function(data){
						$("#"+ret).html(data);
						$("div.window_ajax").fadeOut(350).hide(0);
						//$(document).ready();
						dr();
		 //window.location.href='#Ajax';
			});
		 //$.post("test.php", { name: "John", time: "2pm" } );
		return false;
	}


function dr(){
	$('#sort_result .buy_form .text, #sort_result_table .buy_form .text, .lot_purchase_form .text').live("keypress", function(e){
     if(e.keyCode==13)
     {
          //alert('нажал клавишу enter');
		 // alert($(this).parent().find(".to_cart").attr("value"));
	//	  $(this).parent().find(".to_cart").attr("value","000");
		  $(this).parent().parent().find(".to_cart").click();
		  $(this).parent().find(".to_cart").click();
		//  e.keyCode=9;
		return false;
	 }
	});
};



$(document).ready(function()
{

	$('#phone').bind('paste', function(e){ 
		//alert(e.text) ;
		var el = $(this);
        setTimeout(function() {
            var text = $(el).val().replace(/\D/g, "");
			text=text.substr(-10)
			//alert(text);
			$(el).val(text)
        }, 0);
		})
	$('#phonef').bind('paste', function(e){ 
		//alert(e.text) ;
		var el = $(this);
        setTimeout(function() {
            var text = $(el).val().replace(/\D/g, "");
			text=text.substr(-10)
			//alert(text);
			$(el).val(text)
        }, 0);
		})

	$('#formbas000').submit(function(){ 
		//alert($("#phone").val().replace(/\D/g, "").length);
		if($("#phone").val().replace(/\D/g, "").length < 10 && $("#phone").val().replace(/\D/g, "").length > 0){
			alert('Проверьте номер телефона, он должен состоять из 10 цифр');
			return false;
		}
		if (!isValidEmail($("#email").val(),true) && $("#phone").val().replace(/\D/g, "").length != 10) {
			alert('Для отправки заказа наобходимо ввести Ваш корректный E-mail или телефон');
			return false;
		}
		})
});

jQuery(function($){
   $("#phone").mask("(999) 999-99-99");
   $("#phonef").mask("(999) 999-99-99");
   $("#zip").mask("999999");
});




