$("document").ready(function(){
	$(".review_ul li:last").css("background", "none");
	$(document).keypress(function(e){
  		if(e.which == 13){
        return false;  		
  		}
  	});
	   $("#loading-overlay").hide();

	   /*defaults*/
		$('#catalogItems').load("/kernel/modules/pages/catalog.php");
		//basket protection
		var cart_max_qty = parseInt($(".top_card").attr("id")),
		order_min = parseInt($(".top_card2").attr("id"));

		$("#basketTitleWrap").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300);
		
		/*defaults*/
		  var Qty = 1;
		  $(".pinput").val("1");
		  $(".zinput").val("1");
		  var totalPrice = parseInt($("#totalPrice").html())
		  if(totalPrice < order_min){
			  $(".nvopr").fadeOut();
			  $("#totalPrice").html(totalPrice + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
//			  $(".err").html("<b style='font-weight:normal; font-size:14px;'> ( ! ) сумма заказа меньше " + order_min + "р.</b>").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300).fadeIn();
//			  $(".err").animate({opacity:0}, 5000, function(){}).fadeOut();
		  }	  
//		 $("#metro").live("click", function(){
//			 $(this).css("color", "#000");
//			$(this).children("option").each(function(){
//				$(this).css("color", "#000");
//				$(".press").hide();
//			});
//		 });
                 
                 $("#reg_metro, #reg_metro1, #reg_metro2").live("click", function(){
			 $(this).css("color", "#000");
                         $(this).css("font-size", "14px");
                         $(this).css("font-style", "normal");
			 $(this).children("option").each(function(){
				$(this).css("color", "#000");
                                $(this).css("font-size", "14px");
                                $(this).css("font-style", "normal");
				$(".press").hide();
			});
		 });
	/////////////////////////////////////////////////////
	//////////////////  BASKET  /////////////////////////
	/////////////////////////////////////////////////////
		  $('.tc_but, #cart').click(function() {
			  if(parseInt($("#totalPrice").html())>0){
                              // Yandex open basket
                              try { yaCounter9891505.reachGoal('ya_open_basket'); }
                              catch (err) {}
				$('#example-placeholder').load("/kernel/modules/pages/cart.php");
			  };
		  });
		  $('.card_hide').live("click", function() { 
				var cont_height=$(".container").height();
				var cart_height = $(".pcard_table").height();
			  $(".pcard_table").fadeOut();
				 $(".container").css("height", $(".pc_table").attr("id")+"px"); 

				  return false;  
			  });

	
	/////////////////////////////////
	///////CART COUNTER WRAPPERS/////
	/////////////////////////////////
		  
		  $('.plus').live("click", function() {
				if(parseInt($("#totalItems").html())<=cart_max_qty-1){
				  var productIDValSplitter 	= (this.id).split("_");
				  var productIDVal 			= productIDValSplitter[1];
				  var orig_cost = parseInt($(this).parent("td").next("td").children("p").html());
				  var group_cost = parseInt($(this).parent("td").next("td").children("b").html());
				  $(this).parent("td").next("td").children("b").html(group_cost+orig_cost);
				  var productCost = parseInt($(this).parent("td").parent("tr").children(".td4").children(".orig_cost").html());	
				  var n =  $(this).prev("input").val();
				  n=parseInt(n);
				  var nn=n+1;
				  Qty = nn;
				  var productQty = nn;
				  $(this).prev("input").val(nn);
				  $.ajax({
					  type: "POST",  
					  url: "/kernel/include/functions.php",  
					  data: {productID: productIDVal, productID: productIDVal, productCost: productCost, productQty: nn, action: "add"},
					  		success: function(theResponse) {
							var qty = parseInt($("#totalItems").html());
							var total_cost = parseInt($("#totalPrice").html());	
												
							if(qty > 0){
								$("#totalItems").html(qty+1);
								$("#totalPrice").html(total_cost+orig_cost + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
								var cost_recount = total_cost+orig_cost;
								$(".itog").html("Общая сумма заказа " + cost_recount + "<strong style='font-size:12px; font-weight:bold;'>.00</strong> руб.<br />");
								
								 if(parseInt($("#totalPrice").html())>=order_min-1){
										$(".nvopr").fadeIn();
									}else{
										$(".nvopr").fadeOut();
									}
							}
							$("#basketTitleWrap").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300);
				  }});
				}else{$(".err").html(" ( ! ) вы не можете заказать более " + cart_max_qty + " товаров за 1 раз."); $(".err").animate({opacity:0}, 5000, function(){$(".err").fadeOut();});}
				  return false;
		  }); 
		  
		  $('.minus').live("click", function() {
			  $(".err").html("");
			  var productIDValSplitter 	= (this.id).split("_");
			  var productIDVal 			= productIDValSplitter[1];
			  var orig_cost = parseInt($(this).parent("td").next("td").children("p").html());
			  var n =  $(this).parent("td").children("input").val();
			  var group_cost = parseInt($(this).parent("td").next("td").children("b").html());
			  var productCost = parseInt($(this).parent("td").parent("tr").children(".td4").children(".orig_cost").html());	
			  if(group_cost > orig_cost){
			  	$(this).parent("td").next("td").children("b").html(group_cost-orig_cost);
			  }
			  n=parseInt(n);
			  var nn=n-1;
			  if(nn>0){
				  $(this).parent("td").children("input").val(nn);
				  $.ajax({
					  type: "POST",  
					  url: "/kernel/include/functions.php",  
					  data: {productID: productIDVal, productCost: productCost, productQty: nn, action: "rem"},
					  success: function(theResponse) {
					  Qty = nn;
					  var qty = parseInt($("#totalItems").html());
					  var total_cost = parseInt($("#totalPrice").html());
					  if(qty > 0){
							$("#totalItems").html(qty-1);
							if(total_cost > orig_cost){
								$("#totalPrice").html(total_cost-orig_cost + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
								var cost_recount = total_cost-orig_cost;
								$(".itog").html("Общая сумма заказа " + cost_recount + "<strong style='font-size:12px; font-weight:bold;'>.00</strong> руб.<br />");
							}
							if(parseInt($("#totalPrice").html())>=order_min-1){
								$(".nvopr").fadeIn();
							}else{
								$(".nvopr").fadeOut();
							}
						}
						$("#basketTitleWrap").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300);
			  }});
			  return false;
			}});
			
		  	/////////////////////////////////
			////CART ITEM DROPPER WRAPPER////
			/////////////////////////////////
				
		  			$(".a_img").live('click', function(){
					var productIDValSplitter 	= (this.id).split("_");
					var productIDVal 			= productIDValSplitter[2];
					var productCost = parseInt($(this).parent("td").parent("tr").children(".td4").children(".orig_cost").html());
					/// drop item itself
					$(this).parent("td").parent("tr").next("div").fadeOut({opacity: 0}, 1000);
					$(this).parent("td").parent("tr").next("div").next(".tr_dob").remove();
					$(this).parent("td").parent("tr").fadeOut({opacity: 0}, 1000);
					/// drop item optionst group
					$(this).parent("td").parent("tr").next("tr").fadeOut({opacity: 0}, 1000);
					$(this).parent("td").parent("tr").next("tr").next(".tr_dob").remove();

				  	var group_cost = parseInt($(this).parent("td").prev("td").children("b").html());
				  	var group_qty = parseInt($(this).parent("td").prev("td").prev("td").children("input").val());
					$.ajax({
						type: "POST",  
						url: "/kernel/include/functions.php",  
						data: {productID: productIDVal, productCost: productCost, action: "dropitem"},
						success: function(theResponse) {
						var price = parseInt($('#totalPrice').html());
						var qty = parseInt($('#totalItems').html());
					  	if(price > 0){new_cost = price-group_cost;}else{new_cost=0}
					  	if(qty > 0){new_qty = qty-group_qty;}else{new_qty=0}
						$('#totalPrice').html(new_cost  + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
						$('#totalItems').html(new_qty);
						if(new_qty == 0){$(".pcard_table").fadeOut();$('#totalPrice').html(new_cost+" <b style='font-weight:normal; font-size:13px;' class='message'>  ( ! )сумма заказа меньше " + order_min + "</b>");  $(".message").animate({opacity:0}, 5000, function(){$(this).fadeOut();});}
						parseInt($(".itog").html("Общая сумма заказа " + new_cost + "<strong style='font-size:12px; font-weight:bold;'>.00</strong> руб.<br />"));
						 var totalPrice = parseInt($("#totalPrice").html())
							if(totalPrice < order_min){
							  $(".nvopr").fadeOut();
							  $("#totalPrice").html(totalPrice + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
							  $(".err").html("<b style='font-weight:normal; font-size:14px;'> ( ! ) сумма заказа меньше " + order_min + "р.</b>").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300).fadeIn();
							  $(".err").animate({opacity:0}, 5000, function(){}).fadeOut();						  
						}
					}});
				});

		///////////////////////////////////
		//AJAXED FLY TO CART ITEM WRAPPER//
		///////////////////////////////////
//		$(".productPriceWrapRight a div, .tlink").mouseover(function(){$(".pcard_table").animate({opacity: 0.2}, 600);});
//		$(".productPriceWrapRight a div, .tlink").mouseout(function(){$(".pcard_table").animate({opacity: 1}, 800);});

		
		///////////////////////////////////////////////////////////////////
		////////////////////////// CLOSE BASKET WRAPPER////////////////////
		///////////////////////////////////////////////////////////////////
		
		$(".tc_close").click(function() {
			if(parseInt($("#totalPrice").html())>0){
			$(".err").html("");
			$.ajax({  
				type: "POST",  
				url: "/kernel/include/functions.php",  
				data: {action: "removeall"},  
				success: function(theResponse) {
					$("#totalItems").html(0);
					$("#totalPrice").html(0 + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
					 var totalPrice = parseInt($("#totalPrice").html());
						if(totalPrice < order_min){
						  $(".nvopr").fadeOut();
//						  $(".tc_close").fadeOut();
						  $(".pcard_table").fadeOut(); 
						  $("#totalPrice").html(totalPrice + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
						  $(".err").html("<b style='font-weight:normal; font-size:14px;'> ( ! ) сумма заказа меньше " + order_min + "р.</b>").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300).fadeIn();
						  $(".err").animate({opacity:0}, 5000, function(){}).fadeOut();					  }
					$("#basketTitleWrap").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300);
				}
			});  
			}	
		});
		
		
		
		///////////////////////////////////////////////////////////////////
		//////////////////////////  FLY BASKET WRAPPER CONTROLLER//////////
		///////////////////////////////////////////////////////////////////
		
		$(".productPriceWrapRight a div, .pay_subm").live("click", function add_to_bask() {	
			var input_val1 = parseInt($(this).parent("a").parent("div").prev("div").children("input").val());
			var inp = parseInt($(this).parent("a").parent("div").parent("form").children("input").val());
			//if(input_val1<=cart_max_qty && parseInt($("#totalItems").html())+input_val1<=cart_max_qty || inp<=cart_max_qty && parseInt($("#totalItems").html())+inp<=cart_max_qty){
			$(".err").html("");
			var Qty = 1,
				cost = 0;
				Qty = parseInt($(this).parent("a").parent("div").prev("input").val());
				cost = parseInt($(this).parent("a").parent("div").prev("input").prev("div").prev("b").html());
				
			var productIDValSplitter 	= (this.id).split("_");
			var productIDVal 			= productIDValSplitter[1];
			var productQty				= Qty;
			var productX 				= $("#productImageWrapID_" + productIDVal).offset().left;
			var productY 				= $("#productImageWrapID_" + productIDVal).offset().top;
			if( $("#productID_" + productIDVal).length > 0){
				var basketX 		= $("#productID_" + productIDVal).offset().left;
				var basketY 		= $("#productID_" + productIDVal).offset().top;			
			} else {
				var basketX 		= $("#basketTitleWrap").offset().left;
				var basketY 		= $("#basketTitleWrap").offset().top;
			}
			var gotoX 			= basketX - productX;
			var gotoY 			= basketY - productY;
			var newImageWidth 	= $("#productImageWrapID_" + productIDVal).width() / 20;
			var newImageHeight	= $("#productImageWrapID_" + productIDVal).height() / 20;
                    
                    try { yaCounter9891505.reachGoal('ya_add_to_basket'); }
                    catch (err) {}

				$.ajax({  
					type: "POST",  
					url: "/kernel/include/functions.php",  
					data: { productID: productIDVal, productQty:productQty, action: "addToBasket"},  
					success: function(theResponse) {
						var qty = parseInt($("#totalItems").html());
							var total_cost = parseInt($("#totalPrice").html());
							if(qty > 0){
								$("#totalItems").html(qty+Qty);
								$("#totalPrice").html(total_cost + cost * Qty + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
							}else{
								$("#totalItems").html(Qty);
								$("#totalPrice").html(cost * Qty + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");	
							}
							 var totalPrice = parseInt($("#totalPrice").html());
							  if(totalPrice > order_min){
								  $(".tc_but").fadeIn();
								  $(".tc_close").fadeIn();
							  }else{
								  $("#totalPrice").html(totalPrice + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
								  $(".err").html("<b style='font-weight:normal; font-size:14px;'> ( ! ) сумма заказа меньше " + order_min + "р.</b>").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300).fadeIn();
								  $(".err").animate({opacity:0}, 5000, function(){}).fadeOut();
							}
							$("#basketTitleWrap").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300);
							$("#productImageWrapID_" + productIDVal + " img").animate({opacity:0},5)
							.clone()
							.prependTo("#productImageWrapID_" + productIDVal)
							.css({'position' : 'absolute'})
							.animate({opacity: 0.7}, 200 )
							.animate({opacity: 0.1, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1000, function() {
							$(this).remove();
							$("#productImageWrapID_" + productIDVal + " img").animate({opacity:0}, 1400).animate({opacity:1}, 500);

								$("#notificationsLoader").html('<img src="images/loader.gif">');
							});
					}
			});
//		}else{
//			$(".err").html(" ( ! ) вы не можете заказать более " + cart_max_qty + " товаров за 1 раз.");
//			 $(".err").animate({opacity:0}, 5000, function(){$(".err").fadeOut();});
//		}
	});
		
		
//////////////////////////////////////////
		////////////// GETTING ORDER//////////////
		//////////////////////////////////////////
		  var Qty = 1;
		  var order_min = parseInt($(".top_card2").attr("id"));
		  var cart_max_qty = parseInt($(".top_card").attr("id"));
		  $(".pinput").val("1");
		  $(".zinput").val("1");
		  var cod = "код";
		  var number = "номер";
	  	  order_limit = parseInt($(".item_name").attr("id"));
	  	  
	  	$("#qbut").live("click", function(){
                    try { yaCounter9891505.reachGoal('ya_send_request'); }
                    catch (err) {}
                    order(); return false;
                });
		  	$(document).keypress(function(e){
		  		if(e.which == 13){
		  			order();
		  		
		  		}
		  	});
	  	
		  	function order(){
//				if(order_limit>0){

	                            var adress = '';
	                            var street	= $("#street").val();
	                            if(street=='Улица*' || street == ''){
	                                street = '' ;
	                            }
	                            else
	                            {
	                                adress 	= street+',';
	                            }

	                            var home		= $("#homes").val();
	                            if(home=='Дом*' || home == ''){
	                                home = '' ;
	                            }else{
	                                adress 	+= ' д.'+home+',';
	                            }

	                            var korpus		= $("#korpus").val();
	                            if(korpus=='Корпуc' || korpus == '' ){
	                                korpus = '' ;
	                            }else{
	                                adress 	+= ' корп. '+korpus+',';
	                            }

	                            var stroenie		= $("#stroenie").val();
	                            if(stroenie=='Строение' || stroenie == '' ){
	                                stroenie = '' ;
	                            }else{
	                                adress 	+= ' стр. '+stroenie+',';
	                            }

	                            var flat		= $("#flat").val();
	                            if(flat=='Квартира' || flat == ''){
	                                flat = '' ;
	                            }else{
	                                adress 	+= ' кв.'+flat+',';
	                            }

	                            var podezd		= $("#podezd").val();
	                            if(podezd=='Подъезд' || podezd == ''){
	                                podezd = '' ;
	                            }else{
	                                 adress += ' подъезд '+podezd+',';
	                            }

	                            var floor		= $("#floor").val();
	                            if(floor=='Этаж' || floor == ''){
	                                floor = '' ;
	                            }else{
	                                adress += ' этаж '+floor+',';
	                            }

	                            var intercom	= $("#intercom").val();
	                            if(intercom=='Домофон' || intercom == '' ){
	                                intercom = '' ;
	                            }else{
	                                adress += ' домофон '+intercom;
	                            } 

				    var customer 	= $("#customer").val();
	                            if(customer == 'Ваше имя*') customer = '';
//				    var adress 		= $("#adress").val();
				    var phone 		= "8("+$("#cod").val()+")"+$("#number").val();
				    var mail 		= $("#mail").val();
				    var dop 		= $("#dop").val();
				    var metro		= $("#metro").val();
				    if(metro=='mst') metro = '' ;
	                            var cod 		= /^([0-9]{3})$/;
	                            var num 		= /^([0-9]{7})$/;
//	                            var adress 		= street+', д.'+home+', корп/стр '+korpus+', кв.'+flat+', подъезд '
//	                            +podezd+', этаж '+floor+', домофон '+intercom;
	                            
	                            if(street!='' && home!='' && metro!='' && customer !='')
	                            {
	                                
	                                var msg 		= "error";
	                                if(cod.test($('#cod').val()) && num.test($('#number').val())){
	                                        $("#opts").remove();
	                                        $(".th5").remove();
	                                        $(".td5").remove();
	                                        $(".th3").css("width", "120px");
	                                        $(".th4").css("width", "120px");
	                                        $(".pc .td3").css("width", "120px");
	                                        $(".pc .td4").css("width", "120px").css("text-align", "center");
	                                        $(".pc .td4 b").css("font-size", "20px");
	                                        $("#dob_ingr").remove();
	                                        $(".selects").remove();
	                                        $(".dop").remove();
	                                        $(".full, .thin, .half, .same").css("height", "27px");
	                                        $(".dop_img_table").css("width", "100%");
	                                        $(".tr_do .it").html("<strong style='font-size:12px;'>дополнительно к товару:</strong>");
	                                        $(".tr_do .it").css("width", "240px");
	                                        $(".tr_do .td3").remove();
	                                        $(".optionCost").css("width","100px");

	                                        $(".it").css("padding-left", "20px");
	                                        $(".itog").css("text-align", "right").css("font-size", "24px");
	                                        $("#itog").css("font-size", "28px");
	                                        $(".card_input").css("width", "90%").css("text-align", "center").css("border", "none").css("font-size", "16px").css("font-weight", "bold").css("background-color", "transparent").css("padding-top", "14px");
	                                        $(".pc_table").next("div").hide();
	                                        $(".pc_table").css("width", "100%");
	                                        $(".card_paginate img, .card_paginate a").remove();
	                                        $(".tr_do").css("font-size", "13px");
	                                        $(".nvopr").hide();
	                                        $(".pc .td1").css("width", "130px");
	                                        $(".pc_table a").css("font-size", "13px");
	                                        $(".pc_table a").css("margin-left", "5px");
	                                        $(".pc_table a").next("img").css("height", "15px");
	                                        $(".be").hide();
	    //				    $(".f").children("#tit").remove();
	    //				    $(".t").children("#tit").remove();
	                                        $(".td2, .last_line, .td4").css("border", "none");
	                                        //mail content settings
	                                        $(".card_paginate").css("font-weight", "bold").css("font-size", "16px").css("margin-top", "16px");
	                                        $(".check_p").each(function(){
	                                            if($(this).css("text-decoration")=="underline"){
	                                                    $(this).parent("div").parent("td").remove();
	                                                    $(this).next("img").remove();
	                                            }else{
	                                                    $(this).next("img").remove();
	                                                    $(this).parent("div").parent("td").prev("td").css("width", "150px");
	                                            }
	                                            $(".thin").remove();
	                                            $(".t").children("td").children("div").css("margin", "0");
	                                            $(".new_check_p").css("margin", "0");
	                                            $(this).parent("div").css("margin", "0px");
	                                            $(this).parent("div").parent("td").prev("td").children("div").css("margin", "0px");
	                                            $(this).parent("div").parent("td").parent("div").css("margin", "0px");

	                                        });

	                                        $(".pc .td1").css("width", "120px");
	                                        $(".pc .td2").css("border", "none").css("width", "68%");
	                                        $("#q_answer").hide();
	                                        $(".q_answ1").each(function(){
	                                            $(this).next("div").remove();
	                                            $(this).remove();
	                                        });
	                                        $(".tr_s_dob .td1").css("width", "100px");
	                                        $(".pc_table").parent("td").css("colspan","6");
	                                        $(".pc_table").parent("td").parent("tr").next("tr").next("tr").children("td").css("colspan","6");
//	                                        var content = $(".pt_td_center").html();
//	                                        $(".pc .td2").css("border", "none").css("width", "72%");
//	                                    $(".tr_do").children("td").css("border-bottom", "solid 1px #dddddd");
//	                                        $(".pc").children(".it, .td1, .td2, .td3, .td4").css("border-bottom", "solid 1px #dddddd");
//	                                        $(".tr_s_dob .td1").html("").css("width", "20px");
//	                                        $(".card_paginate").next("p").next("br").remove();
//	                                        $(".card_paginate").next("p").remove();
//	                                        $(".tr_s_dob").children(".td1").children("img").remove();
//	                                        $(".tr_s_dob").children(".td1").css("width","10px");

	                                        var mailcontent = '';//$(".pt_td_center").html();
	                                        var content = '';
	                                        $(".pc_table, .itog").hide();
	    //				    $("#q_answer").show();
	    //				    $("#q_answer11").html("Обрабатывается запрос...");
	                                        $(".pcard_table").css("opacity", "0");
	                                        $(".agree").fadeIn(800);
	                                        $.post("/ajax/question.php",{'customer':customer,'adress':adress,'phone':phone,'mail':mail, 'dop':dop, 'content':content, 'mailcontent':mailcontent, 'metro':metro},function(msg){
	                                           if(street!='' && home!='' && metro!='')
	                                           {
	                                           if((customer!="" && phone!="")||(customer!="" && mail!="")){
	                                               msg = 'Ваш заказ принят, оставайтесь на связи'; 
	                                               order_limit = order_limit-1;
	                                               $.ajax({  
	                                                            type: "POST",  
	                                                            url: "/kernel/include/functions.php",  
	                                                            data: {action: "removeall"},  
	                                                            success: function(theResponse) {
	                                                                    $("#totalItems").html(0);
	                                                                    $("#totalPrice").html(0 + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
	                                                                     var totalPrice = parseInt($("#totalPrice").html());
	                                                                      if(totalPrice < order_min){
	                                                                              $("#totalPrice").html(totalPrice + "<strong style='font-size:12px; font-weight:bold;'>.00</strong>");
	                                                                              $(".err").html("<b style='font-weight:normal; font-size:14px;'> ( ! ) сумма заказа меньше " + order_min + "р.</b>").fadeIn().animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300);
	                                                                              $(".err").animate({opacity:0}, 5000, function(){}).fadeOut();
	                                                                      }
	                                                                    $("#basketTitleWrap").animate({opacity: 0.3}, 500).animate({opacity: 1}, 300).animate({opacity: 0.4}, 400).animate({opacity: 1}, 300);
	                                                                      $(".pcard_table").animate({opacity: 0}, 3000, function(){
	                                                                            $(this).fadeOut(600);
	                                                                        $(".agree").fadeOut(800);
	                                                                      });
	                                                            }
	                                                    });    
	                                           }else{
	                                               msg = 'Заполните, пожалуйста, обязательные поля!';
	                                               }
	                                           }else{
	                                               msg = 'Заполните, пожалуйста, обязательные поля!';
	                                           }
	                                            $("#q_answer11").html(msg);
	                                       });
	                                }else{
	                                    if(!cod.test($('#cod').val()))
	                                    {
	                                        $('#cod').addClass('req_border');
	                                        $('#cod').css('color','red');
	                                    }
	                                    if(!num.test($('#number').val()))
	                                    {
	                                        $('#number').addClass('req_border');
	                                        $('#number').css('color','red');
	                                    }
	                                    $("#q_answer").html('Заполните, пожалуйста, обязательные поля!');
	                                }
	                            }else{
	                                if(street=='')
	                                {
	                                    $('#street').addClass('req_border');
	                                    $('#street').css('color','red');
	                                }
	                                if(home=='')
	                                {
	                                    $('#homes').addClass('req_border');
	                                    $('#homes').css('color','red');
	                                }
	                                if(metro=='')
	                                {
	                                    $('#metro').addClass('req_border');
	                                    $('#metro').css('color','red');
	                                }
	                                if(customer=='')
	                                {
	                                    $('#customer').addClass('req_border');
	                                    $('#customer').css('color','red');
	                                }
	                                if(!cod.test($('#cod').val()))
	                                {
	                                    $('#cod').addClass('req_border');
	                                    $('#cod').css('color','red');
	                                }
	                                if(!num.test($('#number').val()))
	                                {
	                                    $('#number').addClass('req_border');
	                                    $('#number').css('color','red');
	                                }
	                                $("#q_answer").html('Заполните, пожалуйста, обязательные поля!');
	                            }
	                             
				    return false;
			};
			// CART INPUT SECURITY
			$("#customer, #cod, #number, #street, #homes, #korpus, #flat, #podezd, #floor, #intercom, #mail, #dop, #stroenie").live("focus", function(){
	                    if($(this).val() != '')
	                    {
	                        $(this).attr('name',$(this).val());
	                    }
	                    if($(this).attr("name") == 'Ваше имя*' || $(this).attr("name") == 'код*' || $(this).attr("name") == 'телефон*'
	                         || $(this).attr("name") == 'Улица*' || $(this).attr("name") == 'Дом*' || $(this).attr("name") == 'Строение'
	                         || $(this).attr("name") == 'Корпуc' || $(this).attr("name") == 'Подъезд' || $(this).attr("name") == 'Домофон'
	                         || $(this).attr("name") == 'Этаж' || $(this).attr("name") == 'Квартира' || $(this).attr("name") == 'Электронная почта'
	                         || $(this).attr("name") == 'Примечание'
	                    ){
	                        $(this).val("");
	                        $(this).removeClass('req_border');
	                    }
	                    $(this).css("color", "#000000");
	                });
			$("#cod").live("change", function(){var cod = /^([0-9]{3})$/;if(cod.test($('#cod').val())){}else{$(this).val("код*").css("color", "red");}});
			$("#number").live("change", function(){var num = /^([0-9]{7})$/;if(num.test($('#number').val())){}else{$(this).val("телефон*").css("color", "red");}});
			$("#mail").live("change", function(){var mail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;if(mail.test($('#mail').val())){}else{$(this).val("ошибка").css("color", "red");}});
//		    $("#home").live("change", function(){var cod = /^([0-9]+)$/;if(cod.test($('#home').val())){}else{$(this).val("Дом").css("color", "red");}});
//		    $("#korpus").live("click", function(){var cod = /^([0-9]+)$/;if(cod.test($('#korpus').val())){}else{$(this).val("корп/стр").css("color", "red");}});
		    $("#flat").live("change", function(){var cod = /^([0-9]+)$/;if(cod.test($('#flat').val())){}else{$(this).val("Квартира").css("color", "red");}});
		    $("#podezd").live("change", function(){var cod = /^([0-9]+)$/;if(cod.test($('#podezd').val())){}else{$(this).val("Подъезд").css("color", "red");}});
		    $("#floor").live("change", function(){var cod = /^([0-9]+)$/;if(cod.test($('#floor').val())){}else{$(this).val("Этаж").css("color", "red");}});

		
		$(".ab_img").live("click", function(){
			$(".nvopr").fadeIn();
			return false;
		});
		$('.acc_img').live("click", function() {
			$(this).parent("td").parent("tr").fadeOut();
			return false;
		});
		
////////////////////////////////////////////////////////////
		//////////////////////FAQ ( simple pagination)////////////
		//////////////////////////////////////////////////////////
		$(".arr_left_n").hide();
		$(".arr_right_g").hide();
		
		// if items == items on page

		page = parseInt($(".idkeeper").attr("id"));
		items = parseInt($(".count").attr("id"));
		if(page==items){
			$(".arr_right_n").hide();
			$(".arr_right_g").fadeIn();
		}
		
		$(".arr_right_n").live("click", function(){
			$(this).animate({opacity: '0' }, 200);
			$(this).animate({opacity: '1' }, 300);
			$(".arr_left_g").hide();
			$(".arr_left_n").fadeIn();
			page = parseInt($(".idkeeper").attr("id"));	
			items = parseInt($(".count").attr("id"));
			$(".review_ul").animate({opacity: '0' }, 800, function(){
				$.ajax({
					type: "POST",
					url: "/ajax/faq_paging.php",
					data: "page="+page,
					success: function(data){
						$(".review_ul").animate({opacity: '1'}, 800);	
						$(".review_ul").html(data);
						$(".review_ul li:last").css("background", "none");
						page = parseInt($(".idkeeper").attr("id"));	
						count = parseInt($(".arr_right").attr("id"));
						if(page>=items-5){
							$(".arr_right_n").hide();
							$(".arr_right_g").fadeIn();
						}
					}
				});
			});
		});
		
		$(".arr_left_n").live("click", function(){
			$(this).animate({opacity: '0' }, 200);
			$(this).animate({opacity: '1' }, 300);
			$(".review_ul").animate({opacity: '0' }, 800);
			$(".arr_right_n").fadeIn();
			$(".arr_right_g").hide();	
		
			page = parseInt($(".rev_left").attr("id"));
				$(".review_ul").animate({opacity: '0'}, 800, function(){
					$.ajax({
						type: "POST",
						url: "/ajax/faq_paging.php",
						data: "page="+page,
						success: function(data){
							$(".review_ul").animate({opacity: '1' }, 800);		
							$(".review_ul").html(data);	
							$(".review_ul li:last").css("background", "none");
						}
					});
				});
				if(page==0){
					$(".arr_left_n").hide();
					$(".arr_left_g").fadeIn();
				}
		});
		
		////////////////////////////////////////////////////////////////////
		//////////////////////// BANNERS ////////////////////////////////////
		//////////////////////////////////////////////////////////////////////
                
                
               $("#metro").live("click", function(){
                        $(".press").remove();
                        $(this).removeClass('req_border');
                        $("#metro").css('color', '#000')
                });
                
//                $(".cabinet_cover .nvopr_input").blur(function(){
//                    if($(this).val()==""){
//                            $(this).val($(this).attr("sname"));
//                            var val = $(this).val();
//                            if(val == 'логин (e-mail)*' || val == 'пароль*' || val == 'имя*'
//                             || val == 'телефон*' || val == 'метро*' || val == 'улица'
//                             || val == 'дом' || val == 'корпус' || val == 'стр.'
//                             || val == 'подъезд' || val == 'домофон' || val == 'этаж'
//                             || val == 'квартира'
//                            ){
//                                $(this).css("color", "#bbb"); 
//                                $(this).css("font-size", "12px"); 
//                            }
//                            else
//                                $(this).css("color", "#000");
//                    }
//                });
    
//    $(".cabinet_cover .nvopr_input").focus(function(){
//	if($(this).val()!=""){
//		var val = $(this).val();
//                if(val == 'логин (e-mail)*' || val == 'пароль*' || val == 'имя*'
//                 || val == 'телефон*' || val == 'метро*' || val == 'улица'
//                 || val == 'дом' || val == 'корпус' || val == 'стр.'
//                 || val == 'подъезд' || val == 'домофон' || val == 'этаж'
//                 || val == 'квартира'
//                ){
//                    $(this).val('');
//                    $(this).css("color", "#000"); 
//                    $(this).css("font-size", "14px"); 
//                }
//	}
//
//    });
    
    $('#reg_passwd2').blur(function(){
        if($(this).val() == ''){
            $(this).parent('div').hide();
            $('#reg_pass2').parent('div').show();
        }
    })
    $('#reg_passwd').blur(function(){
        if($(this).val() == ''){
            $(this).parent('div').hide();
            $('#reg_pass1').parent('div').show();
        }
    })
    
    $('#cab_info_page input').live('click',function(){
        var val = $(this).val();
        var sname = $(this).attr('sname');
        $('#cab_info_page input').each(function(){
            var val1 = $(this).val();
            var sname1 = $(this).attr('sname');
            if(val1 == '')
            {
                $(this).val(sname1);
                $(this).css('color','#bbb');
                $(this).css("font-size", "12px");
            }
        });
        if(val == sname)
        {
            $(this).val('');
            $(this).css('color','#000');
            $(this).css("font-size", "14px");
        }
        
    });

    $('#cab_info_page input').live('blur',function(){
        var val = $(this).val();
        var sname = $(this).attr('sname');
        if(val == '')
        {
            $(this).val(sname);
        }
    });
		
});

function show_reg(){
            $('#auth_line').hide();
            $('.cabinet_cover').animate({
               height: 'toggle'
             });
             return false;
 }
 
 function reg_user(){
     var email = $('#reg_email').val();
     var pass1 = $('#reg_passwd').val();
     var pass2 = $('#reg_passwd2').val();
     var name = $('#reg_name').val();
     var phone = $('#reg_phone').val();
     var metro = $('#reg_metro').val();
     var street = $('#reg_street').val();
     var home = $('#reg_home').val();
     var korpus = $('#reg_korpus').val();
     var str = $('#reg_stroenie').val();
     var podezd = $('#reg_podezd').val();
     var intercom = $('#reg_intercom').val();
     var floor = $('#reg_floor').val();
     var flat = $('#reg_flat').val();
     
     if($('#subscribe').attr('checked'))
         var subscribe = 1;
     else
         subscribe = 0;

     if(pass1 != pass2)
     {
         alert('Пароли не совпадают, попробуйте еще раз');
         $('#reg_passwd').val('');
         $('#reg_passwd2').val('');
         $('.pass2_inp').hide();
         $('.pass1_inp').hide();
         $('#reg_pass2').parent('div').show();
         $('#reg_pass1').parent('div').show();
         return false
     }
     
     if(email && pass1 && name && metro && phone)
     {
         if(email == 'логин (e-mail)*'  || name == 'имя*'
         || phone == 'телефон*'  || street == 'улица'){
            alert('Заполните все обязательные поля!');
            return false;
        }
        $.ajax({  
                type: "POST",  
                url: "/ajax/auth.php",  
                data: {act: "regist", email:email, name:name, passwd:pass1, login:email, 
                    phone:phone, metro:metro, street:street, home:home, korpus:korpus, 
                    stroenie:str, podezd:podezd, intercom:intercom, floor:floor, flat:flat,subscribe:subscribe},  
                success: function(theResponse) {
                       if(theResponse == 'redirect')
                       {
                           alert('Вы успешно зарегистрированы!');
                           document.location = '/';
                       }
                       else
                       {
                           if(theResponse == 'mail')
                           {
                               alert('Неправильно заполнен адрес электронной почты');
                               $('#reg_email').val($('#reg_email').attr("sname"));
                               $('#reg_email').css("color", "#bbb"); 
                               $('#reg_email').css("font-size", "12px"); 
                           }else{
                               if(theResponse == 'name')
                               {
                                   alert('Поле имени не заполнено');
                               }else{
                                   if(theResponse == 'pass')
                                   {
                                       alert('Поле с паролем не заполнено');
                                   }else{
                                       alert('Ошибка при регистрации');
                                   }
                               }
                                
                           }
                       }
                }
        }); 
//         $('#user_registration').submit();
     }
     else
     {
         alert('Заполните все обязательные поля!');
         return false;
     }
 }
 
 function pass_appear(el)
 {
     $(el).parent('div').hide();
     if($(el).attr('id') == 'reg_pass1')
         var obj = $('.pass1_inp');
     else
         var obj = $('.pass2_inp');
     
     $(obj).show();
     $(obj).children('input').focus();
 }
 
 function openlk(act,first)
 {
     $.ajax({  
            type: "POST",  
            url: "/ajax/cabinet.php",  
            data: {act: act, first:first},  
            success: function(theResponse) {
                  $('.cabinet_cover').html('');
                  $('#auth_line,.auth_inputs,.auth_reg').hide();
                  $('.cabinet_cover').html(theResponse);
                  $('.cabinet_cover').animate({
                            height: 'toggle'
                      });
                  $('.cabinet_cover input').css('color','#000');
                  $('.cabinet_cover input').css("font-size", "14px");
                  $('.cabinet_cover select').css('color','#000');
                  $('.cabinet_cover select').css("font-size", "14px")
                  $('.cabinet_cover').css("padding-top","20px");
                  if($('#id1').val() != 0 )
                      opendopadr(1);
                  if($('#id2').val() != 0 )
                      opendopadr(2);
                  $('.cabinet_cover input').each(function(){
                      if($(this).val() == '' || $(this).val() == $(this).attr('sname'))
                      {
                          $(this).val($(this).attr('sname'));
                          $(this).css('color','#bbb');
                          $(this).css("font-size", "12px");
                      }
                      else
                      {
                          $(this).css('color','#000');
                          $(this).css("font-size", "14px");
                      }
                  });

            }
    });
 }
 
 function auth_user(){
     var login = $('#auth_login').val();
     var pass = $('#auth_pass').val();
     var cookie = $('input[name = cookie]').attr('checked');
     
     $.ajax({  
            type: "POST",  
            url: "/ajax/auth.php",  
            data: {act: "auth", login:login, passwd:pass, cookie:cookie},  
            success: function(theResponse) {
                   var data=theResponse.split("!#!");
                   if(data[0] == 'redirect')
                   {
                      if(data[2] == '')
                          var u_name = 'пользователь';
                      else
                          var u_name = data[2];
                      $('#auth_line,.auth_inputs,.auth_reg').hide();
                      var str = '<style>';
                      str += '#us_in {font-size: 12px}';
                      str += '#us_in a {color:#fff; margin-left: 10px; margin-right: 10px}';
                      str += '</style>';
                      str += '<font id="us_in">';
                      str += 'Здравствуйте, '+u_name+'! <a href="#" onclick="return openlk(\'sale\',1)">специальные акции</a> | ';
                      str += '<a href="#" onclick=" return openlk(\'history\',1);">история заказов</a> | ';
                      str += '<a href="#" onclick="return openlk(\'li\', 1);">личная информация</a> | ';
                      str += '<a href="#" onclick="return go_out();">Выйти</a>';
                      str += '</font>';
                      $('.auth_tit').html(str);
                      $('.cabinet_cover').html(data[1]);
                      $('.cabinet_cover').animate({
                            height: 'toggle'
                      });
                      $('.cabinet_cover input').css('color','#000');
                      $('.cabinet_cover input').css("font-size", "14px");
                      $('.cabinet_cover select').css('color','#000');
                      $('.cabinet_cover select').css("font-size", "14px")
                      $('.cabinet_cover').css("padding-top","20px");
                      
                      if($('#id1').val() != 0 )
                      opendopadr(1);
                     if($('#id2').val() != 0 )
                      opendopadr(2);
                  
                      
                      
                      $('.cabinet_cover input').each(function(){
                          if($(this).val() == '' || $(this).val() == $(this).attr('sname'))
                          {
                              $(this).val($(this).attr('sname'));
                              $(this).css('color','#bbb');
                              $(this).css("font-size", "12px");
                          }
                          else
                          {
                              $(this).css('color','#000');
                              $(this).css("font-size", "14px");
                          }
                      });
                   }
                   else
                   {
                       alert('Логин либо пароль указаны не верно');
                   }
            }
    }); 
 }
 function refresh_page()
 {
     location.reload();
 }
 
 function go_out() 
 {
     $.ajax({  
            type: "POST",  
            url: "/ajax/auth.php",  
            data: {act: "logout"},  
            success: function(theResponse) {
                   if(theResponse == 'ok')
                   {
                      document.location = '/';
                   }
            }
    });
 }
 
 function auth_line_close(el)
 {
     $(el).parent('div').hide();
     $.ajax({  
            type: "POST",  
            url: "/ajax/auth.php",  
            data: {act: "auth_line_close"}
    }); 
 }
 
 function opendopadr(num)
 {
     if(num == 1)
     {
         $('.add2adr1').replaceWith('<h4 style="color:#fff; margin-top:-16px" class="add_h1">Второй адрес  <a id="deladrr" href="#" onclick="return deldopadr(1);">удалить</a></h4>');
         $('.dop_adress .pre_img').hide();
         $('.dop_adress .input_skin').show();
         $('.dop_adress .add2adr1').hide();
//         $('.dop_adress').css('padding-top', '15px');
         $('.dop_adress .input_skin input').css('color','#bbb');
         $('.dop_adress .input_skin input').css('font-size','12px');
         $('.dop_adress .input_skin select').css('font-size','12px');
         $('.dop_adress .input_skin select').css('color','#bbb');
     }
     if(num == 2)
     {
         $('.add2adr2').replaceWith('<h4 style="color:#fff; margin-top:-16px" class="add_h2">Третий адрес <a id="deladrr" href="#" onclick="return deldopadr(2);">удалить</a></h4>');
         $('.dop_adress2 .pre_img').hide();
         $('.dop_adress2 .input_skin').show();
         $('.dop_adress2 .add2adr2').hide();
//         $('.dop_adress2').css('padding-top', '25px');
         $('.dop_adress2 .input_skin input').css('color','#bbb');
         $('.dop_adress2 .input_skin input').css('font-size','12px');
         $('.dop_adress2 .input_skin select').css('font-size','12px');
         $('.dop_adress2 .input_skin select').css('color','#bbb');
     }
     
 }
 
 function deldopadr(num)
 {
     if(num == 1)
     {
         $('.dop_adress .pre_img').show();
         $('.dop_adress .input_skin').hide();
         $('.dop_adress .add2adr1').show();
         $('.dop_adress').css('padding-top', '15px');
         $('.add_h1').replaceWith('<a href="#" onclick="opendopadr(1);" id="add2adr" class="add2adr1">Добавить второй адрес</a>');
     }
     if(num == 2)
     {
         $('.dop_adress2 .pre_img').show();
         $('.dop_adress2 .input_skin').hide();
         $('.dop_adress2 .add2adr2').show();
         $('.dop_adress2').css('padding-top', '15px');
         $('.add_h2').replaceWith('<a href="#" onclick="opendopadr(2);" id="add2adr" class="add2adr2">Добавить третий адрес</a>');
     }
 }
 
 function lc_page(pg,el)
 {
     $.ajax({  
            type: "POST",  
            url: "/ajax/cabinet.php",  
            data: {act: pg, sh:0},  
            success: function(theResponse) {
                  $('#cab_info_page').html('');
                  $('#cab_info_page').html(theResponse);
                  $('.cabinet_opt li').removeClass('act');
                  $(el).parent().addClass('act');
                  $('.cabinet_cover input').css('color','#000');
                  $('.cabinet_cover input').css("font-size", "14px");
                  $('.cabinet_cover select').css('color','#000');
                  $('.cabinet_cover select').css("font-size", "14px")
                  $('.cabinet_cover').css("padding-top","20px");
                  if($('#id1').val() != 0 )
                      opendopadr(1);
                  if($('#id2').val() != 0 )
                      opendopadr(2);
                  $('.cabinet_cover input').each(function(){
                      if($(this).val() == '' || $(this).val() == $(this).attr('sname'))
                      {
                          $(this).val($(this).attr('sname'));
                          $(this).css('color','#bbb');
                          $(this).css("font-size", "12px");
                      }
                      else
                      {
                          $(this).css('color','#000');
                          $(this).css("font-size", "14px");
                      }
                  });

            }
    }); 
    return false;
 }
 
 function save_user_info ()
 {
     var mail = $('#reg_email').val();
     if(mail == '' || mail == $('#reg_email').attr('sname'))
     {
         alert('Не введен адрес электронной почты');
         return false;
     }
     var pass = $('#reg_passwd').val();
     if(pass == '' || pass != $('#reg_passwd2').val())
     {
         alert('Пароль либо не введен, либо введеные пароли не совпадают');
         return false;
     }
     var name = $('#reg_name').val();
     if( name == $('#reg_name').attr('sname'))
     {
         name = '';
     }
     var phone = $('#reg_phone').val();
     if( phone == $('#reg_phone').attr('sname'))
     {
         phone = '';
     }
     var metro = $('#reg_metro').val();
     var street = $('#reg_street').val();
     if( street == $('#reg_street').attr('sname'))
     {
         street = '';
     }
     var home = $('#reg_home').val();
     if( home == $('#reg_home').attr('sname'))
     {
         home = '';
     }
     var korpus = $('#reg_korpus').val();
     if( korpus == $('#reg_korpus').attr('sname'))
     {
         korpus = '';
     }
     var stroenie = $('#reg_stroenie').val();
     if( stroenie == $('#reg_stroenie').attr('sname'))
     {
         stroenie = '';
     }
     var podezd = $('#reg_podezd').val();
     if( podezd == $('#reg_podezd').attr('sname'))
     {
         podezd = '';
     }
     var intercom = $('#reg_intercom').val();
     if( intercom == $('#reg_intercom').attr('sname'))
     {
         intercom = '';
     }
     var floor = $('#reg_floor').val();
     if( floor == $('#reg_floor').attr('sname'))
     {
         floor = '';
     }
     var flat = $('#reg_flat').val();
     if( flat == $('#reg_flat').attr('sname'))
     {
         flat = '';
     }
     
     if($('#subscribe').attr('checked'))
         var subscribe = 1;
     else
         subscribe = 0;
     
     var str = "act: 'saveinfo'"+"email:"+mail+","+"pass:"+pass+","+"name:"+name+","+"phone:"+phone+","+"metro:"+metro+","+"street:"+street+","+
         "home:"+home+","+"korpus:"+korpus+","+"stroenie:"+stroenie+","+"podezd:"+podezd+","+"intercom:"+intercom+","+"floor:"+floor+","+"flat:"+flat;
     
     if($('.dop_adress .input_skin').css('display') == 'block')
     {
         var metro1 = $('#reg_metro1').val();
         var street1 = $('#reg_street1').val();
         if( street1 == $('#reg_street1').attr('sname') || street1 == 'undefined')
         {
             street1 = '';
         }
         var home1 = $('#reg_home1').val();
         if( home1 == $('#reg_home1').attr('sname') || home1 == 'undefined')
         {
             home1 = '';
         }
         var korpus1 = $('#reg_korpus1').val();
         if( korpus1 == $('#reg_korpus1').attr('sname') || korpus1 == 'undefined')
         {
             korpus1 = '';
         }
         var stroenie1 = $('#reg_stroenie1').val();
         if( stroenie1 == $('#reg_stroenie1').attr('sname') || stroenie1 == 'undefined')
         {
             stroenie1 = '';
         }
         var podezd1 = $('#reg_podezd1').val();
         if( podezd1 == $('#reg_podezd1').attr('sname') || podezd1 == 'undefined')
         {
             podezd1 = '';
         }
         var intercom1 = $('#reg_intercom1').val();
         if( intercom1 == $('#reg_intercom1').attr('sname') || intercom1 == 'undefined')
         {
             intercom1 = '';
         }
         var floor1 = $('#reg_floor1').val();
         if( floor1 == $('#reg_floor1').attr('sname') || floor1 == 'undefined')
         {
             floor1 = '';
         }
         var flat1 = $('#reg_flat1').val();
         if( flat1 == $('#reg_flat1').attr('sname') || flat1 == 'undefined')
         {
             flat1 = '';
         }
         
         str += ",metro1:"+metro1+","+"street1:"+street1+","+"home1:"+home1+","+"korpus1:"
             +korpus1+","+"stroenie1:"+stroenie1+","+"podezd1:"+podezd1+","+"intercom1:"+intercom1+","+"floor1:"+floor1+","+"flat1:"+flat1;
     
     }
     
     if($('.dop_adress2 .input_skin').css('display') == 'block')
     {
         var metro2 = $('#reg_metro2').val();
         var street2 = $('#reg_street2').val();
         if( street2 == $('#reg_street2').attr('sname') || street2 == 'undefined')
         {
             street2 = '';
         }
         var home2 = $('#reg_home2').val();
         if( home2 == $('#reg_home2').attr('sname') || home2 == 'undefined')
         {
             home2 = '';
         }
         var korpus2 = $('#reg_korpus2').val();
         if( korpus2 == $('#reg_korpus2').attr('sname') || korpus2 == 'undefined')
         {
             korpus2 = '';
         }
         var stroenie2 = $('#reg_stroenie2').val();
         if( stroenie2 == $('#reg_stroenie2').attr('sname') || stroenie2 == 'undefined')
         {
             stroenie2 = '';
         }
         var podezd2 = $('#reg_podezd2').val();
         if( podezd2 == $('#reg_podezd2').attr('sname') || podezd2 == 'undefined')
         {
             podezd2 = '';
         }
         var intercom2 = $('#reg_intercom2').val();
         if( intercom2 == $('#reg_intercom2').attr('sname') || intercom2 == 'undefined')
         {
             intercom2 = '';
         }
         var floor2 = $('#reg_floor2').val();
         if( floor2 == $('#reg_floor2').attr('sname') || floor2 == 'undefined')
         {
             floor2 = '';
         }
         var flat2 = $('#reg_flat2').val();
         if( flat2 == $('#reg_flat2').attr('sname') || flat2 == 'undefined')
         {
             flat2 = '';
         }
         
         str += ",metro2:"+metro2+","+"street2:"+street2+","+"home2:"+home2+","+"korpus2:"
             +korpus2+","+"stroenie2:"+stroenie2+","+"podezd2:"+podezd2+","+"intercom2:"+intercom2+","+"floor2:"+floor2+","+"flat2:"+flat2;
     }
     $.ajax({  
            type: "POST",  
            url: "/ajax/cabinet.php",  
            data: {act: 'saveinfo', email:mail, pass:pass, name:name, phone:phone, metro:metro, street:street, 
                home:home, korpus:korpus, stroenie:stroenie, podezd:podezd, intercom:intercom, floor:floor, flat:flat,  
                metro1:metro1, street1:street1, home1:home1, korpus1:korpus1, 
                stroenie1:stroenie1, podezd1:podezd1, intercom1:intercom1, floor1:floor1, flat1:flat1,
                metro2:metro2, street2:street2, home2:home2, korpus2:korpus2, 
                stroenie2:stroenie2, podezd2:podezd2, intercom2:intercom2, floor2:floor2, flat2:flat2, id1:$('#id1').val(),id2:$('#id2').val(),subscribe:subscribe
            },
            success: function(theResponse) {
                  if(theResponse == 'ok')
                  {
                      alert('Данные сохранены');
                  }
                  else
                  {
                      alert('Ошибка при сохранении данных');
                  }

            }
    }); 
    return false;
 }
 
