var loading = '<div id="loading_div" style="top:0; left:0; opacity:0.7; filter:alpha(opacity=70); cursor:wait; position:absolute; width:100%; height:100%"><table width="100%" height="100%" border="0"><TR><TD valign="middle" align="center" style="background: #eee;"><img src="/img/frontend/preloader.gif" style="opacity:0.5; filter:alpha(opacity=50); margin:0 auto"></TD></TR></table></div>';
var cookie_shop_name = 'weg';
$(document).ready(function() {

	//** Basket functionality **//
	$('.addBasket').click(function(event){
		$("#basket").append(loading);

		event.preventDefault();
		var id = $(this).attr('single_price');
		var branded = $(this).attr('branded');
		var max_qty = $(this).attr('max_qty');
		var cookie_str;

		cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_products]');
		if(cookie_str != null && cookie_str != ''){
			cookie_arr = cookie_str.split('-');
			tmp_id_arr = new Array();
			tmp_qty_arr = new Array();
			for(var i = 0; i<cookie_arr.length;i++){
				tmp_arr = new Array();
				tmp_arr = cookie_arr[i].split('p');
				tmp_id_arr[tmp_id_arr.length] = tmp_arr[0];
				tmp_qty_arr[tmp_arr[0]] = tmp_arr[1];
			}
			
			if(!in_array(id,tmp_id_arr)){
				var qty = 1;
				var str = id+'p'+qty;
				$.cookie('Weg[' + cookie_shop_name + '_basket_products]', cookie_str+"-"+str, { expires: 365 , path: '/'});
				var res = cookie_arr.length % 2;
				var odd = true;
				if(res){
					odd = false;
				}
				addItem(id,odd,qty,branded);
			}else{
				var qty = Number(tmp_qty_arr[id]) + 1;
				if (qty > max_qty)
					qty = max_qty;
				update_qty(id,qty);

				cookie_arr = cookie_str.split('-');
				for(var i = 0; i<cookie_arr.length;i++){
					tmp_arr = new Array();
					tmp_arr = cookie_arr[i].split('p');
					if(tmp_arr[0] == id){
						tmp_arr[1] = qty;
					}
					cookie_arr[i] = implode('p',tmp_arr);
				}
				cookie_str = implode('-',cookie_arr);
				$.cookie('Weg[' + cookie_shop_name + '_basket_products]', cookie_str, { expires: 365 , path: '/'});
			}
		}else{
			var qty = 1;
			var str = id+'p'+qty;
			$.cookie('Weg[' + cookie_shop_name + '_basket_products]', str, { expires: 365 , path: '/'});
			addItem(id,true,qty,branded);
		}
		
		updateBasketAmount();
		basketTotal();
		$('#loading_div').remove();
	});

	$('.checkall').live('click', function(event) {
		event.preventDefault();
		//$(this).attr('class','uncheckall');
		//$(this).html('Kies Niks');
		$("#basketElements").find('input:checkbox').each(function(){
			$(this).attr('checked','checked');
		});
	});

	$('.uncheckall').live('click', function(event) {
		event.preventDefault();
		//$(this).attr('class','checkall');
		//$(this).html('Kies Alles');
		$("#basketElements").find('input:checkbox').each(function(){
			$(this).attr('checked',false);
		});
	});

	$('.checkremove').live('click', function(event){
		$("#basket").append(loading);
		event.preventDefault();
		ids = new Array();
		ids2 = new Array();
		$("#basketElements").find('input:checkbox').each(function(){
			if($(this).attr('checked')){
				var id = $(this).attr('rel');
				if($(this).attr('id') == 'check_'+id){
					ids[ids.length] = $(this).attr('rel');
				}else{
					ids2[ids2.length] = $(this).attr('rel');
				}
				$(this).parent().parent().parent().parent().parent().remove();
			}
		});

		updateCookie(ids,'remove');
		updateCookie2(ids2,'remove');
		updateBasketAmount();
		basketTotal();
		$('#loading_div').remove();
	});

	$('.amount_update').change(function(event){
		event.preventDefault();
		var amount = $(this).val();
		var str_id = $(this).attr('id');
		var org_amount = $('#hidden_'+str_id).val();
		
		arr_ids = new Array();
		arr_ids = str_id.split('_');
		
		update_qty(arr_ids[1],amount);
		update_qty2(amount,org_amount,str_id);
		update_amount(arr_ids[1],amount);
		update_grand_amount(arr_ids[1]);
		update_packaging_total();
		updateCookieQty(arr_ids[1],amount);
	});

	$('.amount2_update').change(function(event){
		event.preventDefault();
		var amount = $(this).val();
		var str_id = $(this).attr('id');
		var org_amount = $('#hidden2_'+str_id).val();

		arr_ids = new Array();
		arr_ids = str_id.split('_');

		update2_qty(arr_ids[1],amount);
		update2_qty2(amount,org_amount,str_id);
		update2_amount(arr_ids[1],amount);
		update2_grand_amount(arr_ids[1]);
		update_packaging_total();
		update2CookieQty(arr_ids[1],amount);
	});

	$('.remove_comp').click(function(event){
		event.preventDefault();
		var id = $(this).attr('rel');
		var org_amount = $('#hidden_amount_'+id).val();
		ids = new Array();
		ids[ids.length] =id;

		update_qty3(org_amount);
		update_grand_amount2(id);
		updateCookie(ids,'remove');
		updateBasketAmount();
		$('.basket_row_'+id).remove();
		packaging_remove(id,'');
		$(this).parent().parent().remove();
	});

	$('.remove_comp2').click(function(event){
		event.preventDefault();
		var id = $(this).attr('rel');
		var org_amount = $('#hidden2_amount2_'+id).val();
		ids = new Array();
		ids[ids.length] =id;
		update_qty3(org_amount);
		update2_grand_amount2(id);
		updateCookie2(ids,'remove');
		updateBasketAmount();

		$('.basket_row2_'+id).remove();
		packaging_remove(id,'2');
		$(this).parent().parent().remove();
	});

	$('.a_submit').click(function(event){
		event.preventDefault();
		$('#personalDetails').submit();
	});

	$('.confirm').click(function(event){
		event.preventDefault();
		$('#confirmationForm').submit();
	});

	$('#Ecom_Payment_Card_ExpDate_Month').change(function(){
		validateMonthCC();
	});
	$('#Ecom_Payment_Card_ExpDate_Year').change(function(){
		validateMonthCC();
	});


	$('.authorise').click(function(event){
		event.preventDefault();
		if(validateMonthCC()){
			$('#OnlinePaymentForm').submit();
		}
	});
	function validateMonthCC(){
		var sub = true;
		var month = Number($('#Ecom_Payment_Card_ExpDate_Month').val());
		var year = Number($('#Ecom_Payment_Card_ExpDate_Year').val());
		var date = $('#formDate').val();
		date_arr = date.split('-');
		var cur_year = Number(date_arr[0]);
		var cur_month = Number(date_arr[1]);

		$('#custom_date_error').remove();
		if(cur_year == year){
			if(month < cur_month){
				var str = '<span id="custom_date_error" htmlfor="Ecom_Payment_Card_ExpDate_Month" generated="true" class="error">Verval maand is verkeerd.</span>';
				$('#month_cc').append(str);
				sub = false;
			}
		}

		return sub;
	}

	$('.done').click(function(event){
		event.preventDefault();
		$.cookie('Weg[' + cookie_shop_name + '_basket_products]',null);
		document.location.href='/winkel';
	});

	//** Basket functionality **//
	$('.addBasket2').click(function(event){
		$("#basket").append(loading);

		event.preventDefault();
		var id = $(this).attr('single_price');
		var max_qty = $(this).attr('max_qty');
		var cookie_str;
		cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_issues]');
		if(cookie_str != null && cookie_str != ''){
			cookie_arr = cookie_str.split('-');
			tmp_id_arr = new Array();
			tmp_qty_arr = new Array();
			for(var i = 0; i<cookie_arr.length;i++){
				tmp_arr = new Array();
				tmp_arr = cookie_arr[i].split('p');
				tmp_id_arr[tmp_id_arr.length] = tmp_arr[0];
				tmp_qty_arr[tmp_arr[0]] = tmp_arr[1];
			}

			if(!in_array(id,tmp_id_arr)){
				var qty = 1;
				var str = id+'p'+qty;
				$.cookie('Weg[' + cookie_shop_name + '_basket_issues]', cookie_str+"-"+str, { expires: 365 , path: '/'});
				var res = cookie_arr.length % 2;
				var odd = true;
				if(res){
					odd = false;
				}
				addItem2(id,odd,qty);
			}else{

				var qty = Number(tmp_qty_arr[id]) + 1;
				if (qty > max_qty)
					qty = max_qty;
				update2_qty(id,qty);

				cookie_arr = cookie_str.split('-');
				for(var i = 0; i<cookie_arr.length;i++){
					tmp_arr = new Array();
					tmp_arr = cookie_arr[i].split('p');
					if(tmp_arr[0] == id){
						tmp_arr[1] = qty;
					}
					cookie_arr[i] = implode('p',tmp_arr);
				}
				cookie_str = implode('-',cookie_arr);
				$.cookie('Weg[' + cookie_shop_name + '_basket_issues]', cookie_str, { expires: 365 , path: '/'});
			}
		}else{
			var qty = 1;
			var str = id+'p'+qty;
			$.cookie('Weg[' + cookie_shop_name + '_basket_issues]', str, { expires: 365 , path: '/'});
			addItem2(id,true,qty);
		}

		updateBasketAmount();
		basketTotal();
		$('#loading_div').remove();
	});

	$('.currency-select,#currency_switch').livequery('change', function() {
		switch($(this).val()) {
			case 'ZAR':
				var new_currency_value = '1';
				var new_currency_symbol = 'R';
			break;
			case 'USD':
				var new_currency_value = '7.8575';
				var new_currency_symbol = '$';
			break;
			case 'GBP':
				var new_currency_value = '12.9164';
				var new_currency_symbol = '&pound;';
			break;
			case 'EUR':
				var new_currency_value = '11.5722';
				var new_currency_symbol = '&euro;';
			break;
		}

		$('#featured-accomodation').find('span.money').each(function() {
			var currency_value = $(this).next().html();
			var updated_value = (currency_value/new_currency_value);
			if(updated_value>0){
				$(this).html(updated_value.toFixed(2));
			}else{
				$(this).html('0.00');
			}

		});

		$('#featured-accomodation').find('span.symbol').each(function() {
			$(this).html(new_currency_symbol);
		});

		$("select.currency-select").selectOptions($(this).val());

	});
});

function updateCookie(ids,action){
	if(ids.length){
		var cookie_str;
		cookie_arr = new Array();
		cookie_ids_arr = new Array();
		tmp_arr = new Array();
		cookie_qty_arr = new Array();
		
		cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_products]');
		cookie_arr = cookie_str.split('-');
		for(var i =0; i < cookie_arr.length; i++){
			tmp_arr = cookie_arr[i].split('p');
			cookie_ids_arr[cookie_ids_arr.length] = tmp_arr[0];
			cookie_qty_arr[cookie_qty_arr.length] = tmp_arr[1];
		}

		if(action == 'add'){
			for(var i =0; i < ids.length; i++){
				if(!in_array(ids[i],cookie_arr)){
					cookie_arr[cookie.length] = ids[i];
				}
			}
		}else if(action == 'remove'){
			for(var i = 0; i < cookie_ids_arr.length; i++){
				if(in_array(cookie_ids_arr[i],ids)){
					cookie_ids_arr[i] = false;
				}
			}
		}
		new_cookie_arr = new Array();
		for(var i = 0; i<cookie_ids_arr.length;i++){
			if(cookie_ids_arr[i]){
				new_cookie_arr[new_cookie_arr.length] = cookie_ids_arr[i]+'p'+cookie_qty_arr[i];
			}
		}
		var new_cookie_str = implode('-',new_cookie_arr);
		$.cookie('Weg[' + cookie_shop_name + '_basket_products]', new_cookie_str, { expires: 365 , path: '/'});
	}
}

function updateCookie2(ids,action){
	
	if(ids.length){
		var cookie_str;
		cookie_arr = new Array();
		cookie_ids_arr = new Array();
		tmp_arr = new Array();
		cookie_qty_arr = new Array();

		cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_issues]');
		cookie_arr = cookie_str.split('-');
		for(var i =0; i < cookie_arr.length; i++){
			tmp_arr = cookie_arr[i].split('p');
			cookie_ids_arr[cookie_ids_arr.length] = tmp_arr[0];
			cookie_qty_arr[cookie_qty_arr.length] = tmp_arr[1];
		}

		if(action == 'add'){
			for(var i =0; i < ids.length; i++){
				if(!in_array(ids[i],cookie_arr)){
					cookie_arr[cookie.length] = ids[i];
				}
			}
		}else if(action == 'remove'){
			for(var i = 0; i < cookie_ids_arr.length; i++){
				if(in_array(cookie_ids_arr[i],ids)){
					cookie_ids_arr[i] = false;
				}
			}
		}
		new_cookie_arr = new Array();
		for(var i = 0; i<cookie_ids_arr.length;i++){
			if(cookie_ids_arr[i]){
				new_cookie_arr[new_cookie_arr.length] = cookie_ids_arr[i]+'p'+cookie_qty_arr[i];
			}
		}
		var new_cookie_str = implode('-',new_cookie_arr);
		
		$.cookie('Weg[' + cookie_shop_name + '_basket_issues]', new_cookie_str, { expires: 365 , path: '/'});
	}
}

function addItem(id,odd,qty,branded){
	branded_info_icon = typeof(branded) != 'undefined' ? '/frontend/'+branded : '';
	branded = typeof(branded) != 'undefined' ? '/winkels/'+branded : '';
	$.ajax({
		type: 'GET',
		url: '/shop_features/basket_detail/'+id,
		async: false,
		dataType: 'html',
		success: function(html) {
			return_arr = new Array;
			return_arr = html.split('|');
			var name = return_arr[0];
			if(name.length > 50){
				name = name.substr(0,45)+'...';
			}
			var price = return_arr[1];
			var slug = return_arr[2];
			var max_quantity = return_arr[3];
			if (qty > max_quantity)
				qty = max_quantity;

			var class_str = '';
			if(odd){
				class_str += "class='rowA'";
			}
			var str = "<tr "+class_str+"><td><table><tr><td valign='top' width='13px'><input rel='"+id+"' type='checkbox' class='checkbox' id='check_"+id+"' />&nbsp;</td><td><label for='check_"+id+"'>"+name+"</label><br><span style='float:left;'><span class='red'>R "+price+"</span><br /><span id='qty_"+id+"' class='qty'>Hoeveelheid "+qty+"</span></span><a href='"+branded+"/produk/"+slug+"' class='info'><img src='/img"+branded_info_icon+"/i.gif' /></a></td></tr></table></td></tr>";

			$('#basketElements').append(str);
		}
	});

}

function addItem2(id,odd,qty){
	$.ajax({
		type: 'GET',
		url: '/shop/issue_detail/'+id,
		async: false,
		dataType: 'html',
		success: function(html) {
			return_arr = new Array;
			return_arr = html.split('|');
			var name = return_arr[0];
			if(name.length > 50){
				name = name.substr(0,45)+'...';
			}
			var price = return_arr[1];
			var max_quantity = return_arr[2];
			if (qty > max_quantity)
				qty = max_quantity;
			
			var class_str = '';
			if(odd){
				class_str += "class='rowA'";
			}
			var str = "<tr "+class_str+"><td><table><tr><td valign='top' width='13px'><input rel='"+id+"' type='checkbox' class='checkbox' id='check2_"+id+"' />&nbsp;</td><td><label for='check_"+id+"'>"+name+"</label><br><span style='float:left;'><span class='red'>R "+price+"</span><br /><span id='qty2_"+id+"' class='qty'>Hoeveelheid "+qty+"</span></span></td></tr></table></td></tr>";
			$('#basketElements').append(str);
		}
	});
}

function basketTotal(){
	var cookie_str;
	cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_products]');
	cookie_str2 = $.cookie('Weg[' + cookie_shop_name + '_basket_issues]');
	
	if((cookie_str != null && cookie_str != '') || (cookie_str2 != null && cookie_str2 != '')){
		$.ajax({
			type: 'GET',
			url: '/shop_features/basket_total/'+cookie_str+'/'+cookie_str2,
			async: false,
			dataType: 'html',
			success: function(html) {
				$('#totalCost').html("R "+html);
			}
		});
	}else{
		$('#totalCost').html("R 0.00");
	}
}

function updateBasketAmount(){
	var cookie_str, amount;
	cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_products]');
	amount = 0;
	if(cookie_str != null && cookie_str != ''){
		cookie_arr = cookie_str.split('-');
		for(var i =0;i<cookie_arr.length;i++){
			var tmp_arr = cookie_arr[i].split('p');
			amount += Number(tmp_arr[1]);
		}
	}

	cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_issues]');
	if(cookie_str != null && cookie_str != ''){
		cookie_arr = cookie_str.split('-');
		for(var i =0;i<cookie_arr.length;i++){
			var tmp_arr = cookie_arr[i].split('p');
			amount += Number(tmp_arr[1]);
		}
	}

	
	$('#itemAmount').html(amount);
}
	
function initiateBasket(){
	
	var cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_products]');
	if(cookie_str != null){
		cookie_arr = cookie_str.split('-');
		for(var i = 0; i < cookie_arr.length ; i++){
			var res = i % 2;
			var odd = true;
			if(res){
				odd = false;
			}
			addItem(cookie_arr[i],odd);
		}
	}
	updateBasketAmount();
	basketTotal();
}

function in_array (needle, haystack, argStrict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false

    var key = '', strict = !!argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }

    return false;
}

function implode(glue, pieces) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Waldo Malqui Silva
    // +   improved by: Itsacon (http://www.itsacon.net/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: implode(' ', {first:'Kevin', last: 'van Zonneveld'});
    // *     returns 2: 'Kevin van Zonneveld'

    var i = '', retVal='', tGlue='';
    if (arguments.length === 1) {
        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) {
            return pieces.join(glue);
        }
        else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];
                tGlue = glue;
            }
            return retVal;
        }
    } else {
        return pieces;
    }
}

function update_qty(id,qty){
	$("#qty_"+id).html('Hoeveelheid '+qty);
}

function update2_qty(id,qty){
	$("#qty2_"+id).html('Hoeveelheid '+qty);
}

function update_qty2(amount,org_amount,str_id){
	var diff = amount-org_amount;
	var amount2 = Number($('#total_amount').html());
	amount2 += diff;
	$("#total_amount").html(amount2);
	$('#hidden_'+str_id).val(amount);

	$('#itemAmount').html(amount2);
}

function update2_qty2(amount,org_amount,str_id){
	var diff = amount-org_amount;
	var amount2 = Number($('#total_amount').html());
	amount2 += diff;
	
	$("#total_amount").html(amount2);
	$('#hidden2_'+str_id).val(amount);

	$('#itemAmount').html(amount2);
}

function update_qty3(org_amount){
	var old_amount = Number($("#total_amount").html());
	var new_amount = old_amount - org_amount;
	$("#total_amount").html(new_amount);
}

function update_amount(id,amount){
	var value = Number($('#price_'+id).html());
	var final_amount = ((value*amount)*100);
	final_amount = Math.round(final_amount);
	final_amount = (final_amount/100);
	$('#total_price_'+id).html(final_amount.toFixed(2));
	$('#sup_basket_total_'+id).html('R '+final_amount.toFixed(2));
	
	// packaging costs
	update_packaging(id, amount, '');
}

function update2_amount(id,amount){
	var value = Number($('#price2_'+id).html());
	var final_amount = ((value*amount)*100);
	final_amount = Math.round(final_amount);
	final_amount = (final_amount/100);
	$('#total2_price_'+id).html(final_amount.toFixed(2));
	$('#sup_basket_total_'+id).html('R '+final_amount.toFixed(2));
	
	// packaging costs
	update_packaging(id, amount, '2');
}

function update_grand_amount(id){
	var org_price = Number($('#hidden_total_price_'+id).val());
	var price = Number($('#total_price_'+id).html());
	var total_price = Number($('#main_amount').html());
	var diff = price - org_price;

	total_price += diff;
	total_price = (total_price*100);
	total_price = Math.round(total_price);
	total_price = (total_price/100);
	
	$('#main_amount').html(total_price.toFixed(2));
	$('#hidden_total_price_'+id).val(price);
	$('#totalCost').html('R '+total_price.toFixed(2));
}

function update2_grand_amount(id){
	var org_price = Number($('#hidden2_total_price_'+id).val());
	var price = Number($('#total2_price_'+id).html());
	var total_price = Number($('#main_amount').html());
	var diff = price - org_price;
	
	total_price += diff;
	total_price = (total_price*100);
	total_price = Math.round(total_price);
	total_price = (total_price/100);
	$('#main_amount').html(total_price.toFixed(2));
	$('#hidden2_total_price_'+id).val(price);
	$('#totalCost').html('R '+total_price.toFixed(2));
}

function update_grand_amount2(id){
	var org_price = Number($('#hidden_total_price_'+id).val());
	//var price = Number($('#total_price_'+id).html());
	var total_price = Number($('#main_amount').html());
	total_price -= org_price;

	total_price = (total_price*100);
	total_price = Math.round(total_price);
	total_price = (total_price/100);

	$('#main_amount').html(total_price.toFixed(2));
	$('#totalCost').html('R '+total_price.toFixed(2));
}

function update2_grand_amount2(id){
	var org_price = Number($('#hidden2_total_price_'+id).val());
	//var price = Number($('#total_price_'+id).html());
	var total_price = Number($('#main_amount').html());
	total_price -= org_price;

	total_price = (total_price*100);
	total_price = Math.round(total_price);
	total_price = (total_price/100);

	$('#main_amount').html(total_price.toFixed(2));
	$('#totalCost').html('R '+total_price.toFixed(2));
}

function update_packaging(id, amount, number) {
	var orig_amount = Number($('#hidden'+number+'_total_packaging_'+id).val());
	value = Number($('#hidden'+number+'_packaging_'+id).val());
	var new_amount = ((value*amount)*100);
	new_amount = Math.round(new_amount);
	new_amount = (new_amount/100);
	var diff = new_amount - orig_amount;
	$('#hidden'+number+'_total_packaging_'+id).val(new_amount);
	var total = Number($('#main_packaging_amount').html());
	total = total + diff;
	$('#main_packaging_amount').html(total.toFixed(2));
}

function update_packaging_total() {
	var total_price = Number($('#main_amount').html());
	var total = Number($('#main_packaging_amount').html());
	total_price = total_price + total;
	total_price = (total_price*100);
	total_price = Math.round(total_price);
	total_price = (total_price/100);
	$('#main_total').html(total_price.toFixed(2));
}

function packaging_remove(id, number) {
	var orig_amount = Number($('#hidden'+number+'_total_packaging_'+id).val());
	var total = Number($('#main_packaging_amount').html());
	total = total - orig_amount;
	$('#main_packaging_amount').html(total.toFixed(2));
	update_packaging_total();
}

function updateCookieQty(id,qty){
	var new_cookie_str = '';
	cookie_arr = new Array();
	new_cookie_arr = new Array();

	var cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_products]');
	cookie_arr = cookie_str.split('-');

	for(var i =0; i < cookie_arr.length; i++){
		tmp_arr = cookie_arr[i].split('p');
		if(tmp_arr[0] == id){
			tmp_arr[1] = qty;
		}
		new_cookie_arr[new_cookie_arr.length] = implode("p",tmp_arr);
	}
	new_cookie_str = implode("-",new_cookie_arr);
	$.cookie('Weg[' + cookie_shop_name + '_basket_products]', new_cookie_str, { expires: 365 , path: '/'});
}

function update2CookieQty(id,qty){
	var new_cookie_str = '';
	cookie_arr = new Array();
	new_cookie_arr = new Array();

	var cookie_str = $.cookie('Weg[' + cookie_shop_name + '_basket_issues]');
	cookie_arr = cookie_str.split('-');

	for(var i =0; i < cookie_arr.length; i++){
		tmp_arr = cookie_arr[i].split('p');
		if(tmp_arr[0] == id){
			tmp_arr[1] = qty;
		}
		new_cookie_arr[new_cookie_arr.length] = implode("p",tmp_arr);
	}
	new_cookie_str = implode("-",new_cookie_arr);
	$.cookie('Weg[' + cookie_shop_name + '_basket_issues]', new_cookie_str, { expires: 365 , path: '/'});
}

