
  number_format = function (number, decimals, dec_point, thousands_sep) {
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;        };
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }    return s.join(dec);
  }

  getFloat = function(value)
  {
	  
	  if (value.lastIndexOf(".") == -1)
	  {
		  // 1500,50		  
		  return parseFloat(value.replace(/,/, "."));		  
	  }
	  else
	  {
		  if (value.lastIndexOf(",") == -1)
		  {			  
			  // 1500.50
			  return parseFloat(value);
		  }		  
		  else 
		  {
			  if (value.lastIndexOf(",") > value.lastIndexOf("."))
			  {  
				  // 1.500,50				  
				  return parseFloat(value.replace(/\./, "").replace(/,/, "."));
			  }
			  else
			  {
				  // 1,500.50
				  return parseFloat(value.replace(/,/, ""));
			  }
		  }
	  }
	  
  }
  
  switchVari = function(p_id, v_id) { 
	 
	if (jQuery("#preis_" + p_id) == null) return;
	
  	jQuery("#preis_" + p_id).html( number_format(getFloat(jQuery("#gp_" + p_id).html()) + getFloat(jQuery("#var_preis_" + v_id).html()), 2, ',', '.') );
  	
  	if (jQuery("#stock_" + p_id) != null)
  	{
  		jQuery("#stock_" + p_id).html(jQuery("#var_stock_" + v_id).html());
  	}
  	   	
  	if (jQuery("#weight_" + p_id) != null && jQuery("#var_weight_" + v_id).html() != null)
  	{  		
  		jQuery("#weight_" + p_id).html( number_format(getFloat(jQuery("#weight_gp_" + p_id).html()) + getFloat(jQuery("#var_weight_" + v_id).html()), 2, ',', '.') );
  	}
  	
  }

  getVari = function(p_id)
  {
	  
	  var arRadio = jQuery("form[name='produkt_" + p_id + "'] input[type='radio']:checked");
	  
	  return arRadio.val();
	  
  }
  
