$(document).ready(function()
{

    $('.js-action').click(function(){
        
        $("#take_material_frame").attr("disabled",false); 
       
        $("#range_price").attr("disabled",false);     
        $("#weight").attr("disabled",false);  
        
        $(this).ajaxAction();   
       
       
        if($("#take_material_frame").val()==0)
        {
         $("#range_price").attr("disabled",true);     
         $("#weight").attr("disabled",true);  
        }
        
        if($("#range_price").val()=="0-0")
        {
           $("#weight").attr("disabled",true);          
        }
        
        
       if($("#range_price").val()!="0-0")
       {
                 $("#take_material_frame").attr("disabled",true);   
        }
        
        
        
        
       
       return false;       
    });

     $('.js-action2').click(function(){
        $(this).ajaxAction();
        return false;
    });
});

var ajaxActionKeeper = false;
 (function( $ ){

  $.fn.ajaxAction = function() {
       if(!ajaxActionKeeper)
       {
           ajaxActionKeeper = true;

           var js_link = '';
           var deffun = null;
           if(this.attr('href') != undefined) js_link = this.attr('href');
           else
           {
               deffun = this.parents('form').attr('id');

               if(window[deffun+'(\''+this.attr('id')+'\')'] != undefined) eval(deffun+'(\''+this.attr('id')+'\')');
               js_link = this.parents('form').attr('action');
           }

           var fun = this.attr('rel');

           if(fun == "") fun = this.parents('form').attr('rel');
           var sep = '?';
           if(strpos(js_link, '?') !== false) sep = '&';
           var pos = strpos(js_link, '#');
           if(pos === false) pos = js_link.length;

           $.post(js_link.substr(0,pos)+sep+'js=true', this.parents('form').serialize() , function(data) {

                ajaxActionKeeper = false;
              

                if(data.substr(0,1) != '1')
                {
                    if(data.substr(0,2) == '0!') data = '0';
                    if(data.substr(0,2) == '0+') data = data.substr(2);
                    if(deffun)
                    {
                           deffun = 'post'+deffun;
                           if(window[deffun] != undefined) eval(deffun+'(\''+data.replace(/[ \s]+/g, " ").replace(/'/g,"\\'")+'\')');
                    }

                    if(fun !== '' && fun !== undefined)
                    {
                          var afun = fun.split('var_data');
                          if(afun.length == 2) fun = afun[0]+"'"+data.replace(/[ \s]+/g, " ").replace(/'/g,"\\'")+"'"+afun[1];
                          setTimeout(fun, 0);
                    }

                }
           });

       }
       return false;
  };
})( jQuery );


function strpos (haystack, needle, offset) {
  var i = (haystack+'').indexOf(needle, (offset || 0));
  return i === -1 ? false : i;
}


