     function serialize_form(form){
       var rez = '';
       var i = 0;
   //    var t_c = $(form+" input").length + $(form+" select").length;
       $(form+" input").each(function(){
           if($(this).attr("type") == "checkbox"){
             if($(this).attr("checked")){
                 rez += $(this).attr("name")+"="+escape($(this).val())+"&";
             }
             else{
                 rez += $(this).attr("name")+"=0&";
		     }
		   }
		   else if($(this).attr("type") == "radio"){
			 if ($(this).attr("checked")){
             	rez += $(this).attr("name")+"="+escape($(this).val())+"&";
			 }
		   }
	       else{
	       	  rez += $(this).attr("name")+"="+escape($(this).val())+"&";
	       }
       })
       $(form+" textarea").each(function(){
             rez += $(this).attr("name")+"="+escape($(this).val())+"&";
       })
       $(form+" select").each(function(){
         rez += $(this).attr("name")+"="+escape($(this).val())+"&";
       })

       return (rez);
     }

    function send_(data)
      {
        data = "ajaz=1&"+data;
        $.ajax({
          url: document.location.href,
          type: "POST",
          beforeSend: function(){$(".ajax_loading").show()},
          data: data,
          success: function(msg){
            eval(msg);
            $(".ajax_loading").hide();
           }
        });
      }

    function send_order_form(){
        send_("src=shop&function=send_order_form&type=d&"+serialize_form('#callback'));
    }

    function send_order_form(){
        send_("src=shop&function=send_order_form&type=d&"+serialize_form('#callback'));
    }

    function send_feedback(){
        send_("src=shop&function=send_feedback_form&type=d&"+serialize_form('#feedback'));
    }

	function alert_(msg){
	    jAlert(msg,"");
	}

   function confirm_(msg,eval_){
       jConfirm(msg, " ", function(r) {if (r) eval(eval_)});
   }

   function save_basket(){
        send_("src=shop&function=save_basket&type=d&"+serialize_form('.table_wrap'));
   }

   function resetError(form){
       var rez = '';
       var i = 0;
   //    var t_c = $(form+" input").length + $(form+" select").length;
       $(form+" input").each(function(){
			$(this).css('border-color','#8f8e67');
       })
   }

   function addTovar(code,sec,count,h)
     {
        $("#loading").show();
       /* if (h)
			var bigcolors = $("input[name=bigcolors]:checked").val()
        var color = $("input[name=colors]:checked").val()
        if (bigcolors)
          	color = bigcolors*/
        $.ajax({
          type: "POST",
          url: document.location.href,
          //data: "id="+code+"&count="+count+"&color="+color+"&ajaz=1&src=shop&function=add_to_basket",
          data: "id="+code+"&count="+count+"&ajaz=1&src=shop&function=add_to_basket",
          success: function(msg){
			eval(msg);
          }
        });
     }

	 function letsOrder(){
	 	send_("src=shop&function=send_order_form&type=d");
	 }

     function updateCaptcha(){
       data = "ajaz=1&src=registration&function=captcha&captcha=1&type=d";
       $.ajax({
         url: document.location.href,
         type: "POST",
         beforeSend: function(){$(".ajax_loading").show()},
         data: data,
         success: function(msg){
         	$("#captcha").attr("src","");
           $("#captcha").attr("src","/images/ll_items/code.jpg");
                  //alert("!");
          }
       });
     }

    $(document).ready(function() {

        $("#subs_email").blur(function(){
            if(this.value == '') this.value = 'E-mail';
        });
        $("#subs_email").focus(function(){
            if(this.value == 'E-mail') this.value = '';
        });


    	if ($("#captcha")){
        	//updateCaptcha();
    	}

        $(document).ready(function() {
            $(".item_big_img a").fancybox();
        });

        $(document).ready(function() {
            $(".list_img a").fancybox();
        });

        $(".preview").click(function () {
          $(".preview").css({'border-color':'#eeeeee'});
          $(this).css({'border-color':'#f03025'});
        });

        $(".item_img_bar ul li img").click(function(event){
    		$(".item_big_img").html('<a href="'+($(this).attr('src').split('50_')[0] + $(this).attr('src').split('50_')[1])+ '" alt=""><img src="'+($(this).attr('src').split('50_')[0] + '285_' + $(this).attr('src').split('50_')[1])+'" alt="" /></a>');
			$("#color").html($(this).attr('alt'));
            $(".item_big_img a").fancybox();
    	});

        $("#add_bookmark").jFav();

        $(".addTovar").click(function(){
            send_("src=shop&function=add_to_basket&type=d&id="+$(this).attr('rel')+"&count=1"+"&color=undefined");
        });
        $("#add_to_basket").click(function(){
            send_("src=shop&function=add_to_basket&type=d&id="+$(this).attr('rel')+"&count="+$("#item_counts").val()+"&color=undefined");
        });
        $("#letspreorder").click(function(){
            send_("src=shop&function=letspreorder&type=d&id="+$(this).attr('rel')+"&email="+$("#preorder_email").val());
        });
    	$(".del_tovar").click(function(event){
    	    /*confirm_("Вы точно хотите удалить товар из корзины?","$('tr#"+$(this).attr('rel')+"').fadeOut('slow');send_('src=shop&function=deleteItem&type=d&item_id="+$(this).attr('rel')+"&color="+$(this).attr('color')+"&key="+$(this).attr('key')+"');");*/
    	    confirm_("Вы точно хотите удалить товар из корзины?","$('tr#"+$(this).attr('rel')+"').fadeOut('slow');send_('src=shop&function=deleteItem&type=d&item_id="+$(this).attr('rel')+"&key="+$(this).attr('key')+"');");
    	});

    	$("span.clear_basket").click(function(event){
            confirm_("Вы точно хотите очистить корзину?","send_('src=shop&function=empty_basket&type=d');");
    	});

		/*
    	$(".item_conf").click(function(){
			var itemID = $(this).attr("rel");
            jConfirm1("<span>Этого товара временно нет в наличии, но мы можем сообщить о его поступлении, если Вы оставите свой e-mail</span>",null,null,function(r){send_("src=shop&function=letspreorder&type=d&id="+itemID+"&email="+r);});
			//jConfirm1("<span>Этого товара временно нет в наличии, но мы можем сообщить о его поступлении, если Вы оставите свой e-mail</span>");
            $("#popup_container").addClass("study");
            $("#popup_container").css({'max-width':'411px','min-width':'411px', 'border':'none'});
            $("#popup_container #popup_ok").attr('value','');
    	});
        */

    	$(".item_conf").click(function(){
			var itemID = $(this).attr("rel");
            jCustom("<span>Этого товара временно нет в наличии, но мы можем сообщить о его поступлении, если Вы оставите свой e-mail</span>",null,null,function(r){send_("src=shop&function=letspreorder&type=d&id="+itemID+"&email="+r);});
			//jCustom("<span>Этого товара временно нет в наличии, но мы можем сообщить о его поступлении, если Вы оставите свой e-mail</span>");
            $("#popup_container").addClass("study");
			$("#popup_container").css({'max-width':'411px','min-width':'411px', 'border':'none'});
		});

        $("input.digital").keypress(function (e){
            if( e.which!=13 && e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)){
                return false;
            }
        });

		$(".face").click(function(){
		   	switch ($(this).val()){
            	case '0': $("#phis").fadeIn("fast"); $("#ur").hide(); break;
            	case '1': $("#ur").fadeIn("fast"); $("#phis").hide();
			}
		});

		$("#reg_me").click(function(){
        	send_("src=registration&function=regNewUser&type=d&"+serialize_form('#register'));
		});

		$("#enter_button").click(function(){
        	send_("src=registration&function=loginUser&type=d&"+serialize_form('#login_box'));
		});

		$("#edit_profile").click(function(){
        	send_("src=registration&function=editProfile&type=d&"+serialize_form('#register'));
		});

		$("#exit").click(function(){
        	send_("src=registration&function=logout&type=d");
		});

   		$("#recover").click(function(){
        	send_("src=registration&function=lostPswd&type=d&"+serialize_form('#register'));
		});

      	$("#order").click(function(){
        	send_("src=shop&function=send_order_form&type=d");
		});

      	$("#vote").click(function(){
        	send_("src=poll&type=d&"+serialize_form('#poll'));
		});

		$(".order_ico").click(function(){
			id = "#items_" + $(this).attr("rel");
			$(id).slideToggle("normal");
			if ($(this).hasClass("expand")){
            	$(this).removeClass("expand");
				$(this).addClass("collapse");
			}
			else {
            	$(this).removeClass("collapse");
				$(this).addClass("expand");
			}
		});

		$("#login_box input[name='login']").focus(function(){
			if ($(this).val() == "E-mail"){
            	$(this).val("");
			}
		})
		$("#login_box input[name='login']").blur(function(){
			if ($(this).val() == ""){
            	$(this).val("E-mail");
			}
		})
		$("#login_box input[name='pass']").focus(function(){
			if ($(this).val() == "Пароль"){
            	$(this).val("");
			}
		})
		$("#login_box input[name='pass']").blur(function(){
			if ($(this).val() == ""){
            	$(this).val("Пароль");
			}
		})
        $("#login_box input").keypress(function (e){
            if(e.which == 13){
                send_("src=registration&function=loginUser&type=d&"+serialize_form('#login_box'));
            }
        });
    });
