//
function addwl(productID){
    text = "<span style='color: rgb(253, 122, 0); font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: bold; font-size: 11px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;'>Товар добавлен в список ожидания</span>";
    //send ajax
    $.get('/cart.php?addwl='+productID);
    $('#mvotefrm_'+productID).removeClass('btnz').html(text).attr('href', '/'+lng+'index.php?shopping_cart=yes');
    document.getElementById('mvotefrm_'+productID).onclick='';
}

function addcart(price, name, productID, mode){
    var text = '';

    var cc = document.getElementById('current_currency');
			var _cc = " грн.";
			switch (cc.value) {
				case "2": _cc = "грн.";
					break;
				case "3": _cc = "$";
					break;
				case "4": _cc = "€";
					break;
				case "5": _cc = "руб.";
					break;
				case "6": _cc = "WMZ";
					break;
			}

    //add to cart_info
    //check exist product in cart
    if ($('#ci'+productID).length > 0){
        var cq = parseInt($('#ci'+productID+' span').html()) + 1;
        $('#ci'+productID+' span').html(cq+' x ');
    }else{
        $('#cart_info').append('<a href="/category_alias/product_alias-'+productID+'.html" id="ci'+productID+'"><span>1 x </span>'+name+'</a>');
    }

    //send ajax
   //$.get('/cart.php?addproduct='+productID);
    $.get("/"+lng+"index.php", {'shopping_cart': 'yes', 'add2cart': productID, 'ajx': 1}, function(response){
        $('#mvotefrm_'+productID).removeClass('btn').html(response).attr('href', '/'+lng+'index.php?shopping_cart=yes');
        document.getElementById('mvotefrm_'+productID).onclick='';
    });

    var total = parseFloat($('#csum').html().replace(_cc, ''));
    var new_total = (total + price).toFixed(2);

    if ( $('#discount').length ){
     	  var discount = $('#discount').html().replace('%', '');

          var new_price = parseFloat(price);
          var discount_in_summ = (total + new_price) * (discount/100);
          var total_with_discount = (total + new_price - discount_in_summ);
          $('#discount_in_summ').html(discount_in_summ.toFixed(2)+' '+_cc);
          $('#total_with_discount').html(total_with_discount.toFixed(2)+' '+_cc);
    }

    $('#crt').html(parseInt($('#crt').html())+1);
    $('#csum').html(new_total+' '+_cc);

    return false;
}

function show_div(id,id1,id2, txtmode, usr)
{
var cc = document.getElementById('current_currency');
var _cc=" грн.";
switch (cc.value)
	{
	case "2": _cc=" грн.";
			break;
	case "3": _cc="$ ";
			break;
	case "4": _cc="€ ";
			break;
	case "5": _cc=" руб.";
			break;
	}

 
 var t = "Товар добавлен в корзину.\n Перейти к оформлению заказа?";
 if(txtmode=="wait")
 	{
	t = "<span style='color: rgb(253, 122, 0); font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: bold; font-size: 11px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;'>Товар добавлен в список ожидания</span>";
    $('#mvotefrm_'+id).removeClass('btnz');
    $.get('/cart.php?addproduct='+id+'&i='+usr);
	}
	else if(id1=="wait2"){
	  //alert('cart.php?addproduct='+id+'&i='+usr+'&so=1');
	//t = "<span style='color: rgb(253, 122, 0); font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: bold; font-size: 11px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;'>Товар добавлен в список ожидания</span>";

	//$.get('/cart.php?addproduct='+id+'&i='+usr+'&so=1');
	}else{
	    $.get('/cart.php?addproduct='+id);
	}
    $('#mvotefrm_'+id).removeClass('btn').html(t).attr('href', '/'+lng+'index.php?shopping_cart=yes');
 //document.getElementById('mvotefrm_'+id).innerHTML=t;
 //document.getElementById('mvotefrm_'+id).href='/index.php?shopping_cart=yes';
    document.getElementById('mvotefrm_'+id).onclick='';
 if(txtmode!="wait")
 	{
 	  if ( $('#discount').length ){
     	  var discount = $('#discount').html().replace('%', '');
     	  var total = parseFloat($('#csum').html().replace(_cc, ''));
          var new_price = parseFloat(id2.replace(_cc, ''));
          var discount_in_summ = (total + new_price) * (discount/100);
          var total_with_discount = (total + new_price - discount_in_summ);
          $('#discount_in_summ').html(discount_in_summ.toFixed(2)+' '+_cc);
          $('#total_with_discount').html(total_with_discount.toFixed(2)+' '+_cc);
      }


	 document.getElementById('crt').innerHTML = eval(document.getElementById('crt').innerHTML)+1;
	 var summ_html=new String(document.getElementById('csum').innerHTML.replace(",",""));
	 var new_summ=(parseFloat(summ_html.replace(_cc,""))+parseFloat(id2.replace(_cc,""))).toFixed(2);
	 if((cc.value=='2') || (cc.value=='5'))
		{
		document.getElementById('csum').innerHTML = new_summ+""+_cc;
		}
		else
		{
		document.getElementById('csum').innerHTML =  _cc+""+new_summ;
		}
	}
}
function set_reserve(id){
    $.get('/cart.php?reserve='+id);
}