//$(document).ready(init);

function addToBasket( id, type ){
//    var cnt = prompt("Количество (шт.)/Cantitatea (buc.)?", "1");
//    if ( cnt > 0 ){
        var cnt = 1;
        var url = ''+document.location;
	urlarr = url.split('#');
	url = urlarr[0];
        if ( url.indexOf( '?' ) > 0 )  sep = '&'; else sep = '?';
        $.getJSON(url+sep+'ajax_action=basketadd&item_id='+id+'&item_col='+cnt+'&item_type='+type,
      {}, 
      function(json){ 
        $( '#basket_price_lbl' ).html(''+json.price);
        $( '#basket_cnt_lbl' ).html(''+json.count);
        $( '#item_fcnt_'+json.type+'_'+json.id ).html(''+json.it_cnt);
      } 
    )
//    }
}

function delFromBasket( id, type ){
        var url = ''+document.location;
	urlarr = url.split('#');
	url = urlarr[0];
        if ( url.indexOf( '?' ) > 0 )  sep = '&'; else sep = '?';
        $.getJSON(url+sep+'ajax_action=basketdel&item_id='+id+'&item_type='+type,
      {}, 
      function(json){ 
        $( '#basket_price_lbl' ).html(''+json.price);
        $( '#basket_cnt_lbl' ).html(''+json.count);
        $( '#basket_price_tot_1' ).html(''+json.prices[1]);
        $( '#basket_price_tot_2' ).html(''+json.prices[2]);
        $( '#basket_price_tot_3' ).html(''+json.prices[3]);
        $( '#basket_price_tot_4' ).html(''+json.prices[4]);
        $( '#trow_'+json.type+'_'+json.id ).remove(  );
      } 
    )
}

function basketcalc(  ) {
        var queryString = $('#basketform :text, :radio, :checkbox').fieldSerialize();
        var url = ''+document.location;
	urlarr = url.split('#');
	url = urlarr[0];
        if ( url.indexOf( '?' ) > 0 )  sep = '&'; else sep = '?';
   $.getJSON(document.location+sep+'ajax_action=basketcalc&'+queryString, 
  {}, 
  function(json){ 
        $( '#basket_price_lbl' ).html(''+json.price);
        $( '#basket_cnt_lbl' ).html(''+json.count);
        $( '#basket_currency_lbl' ).html(''+json.currency);
        $( '#basket_price_tot_1' ).html(''+json.prices[1]);
        $( '#basket_price_tot_2' ).html(''+json.prices[2]);
        $( '#basket_price_tot_3' ).html(''+json.prices[3]);
        $( '#basket_price_tot_4' ).html(''+json.prices[4]);
  } 
);

function onlynum() {
   var k; 
   k=event.keyCode;
   if( (k >= 48 && k <= 57) ) return k
   else return false
}
}

