﻿function fnAddExtraItemToBasketHolder(itemReference, itemType, add) {
	var paramList = '{"itemReference":' + itemReference + ', "itemType":"' + itemType + 
		'", "add":"' + add + '"}';

	$.ajax({
		type: "POST",
		url: "/Default.aspx/AddToExtraItemBasketHolder",
		data: paramList,
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function(data) {
//			var action;
//			if (add)
//				action = "Adding";
//			else
//				action = "Removing"
//				
//			alert(action + " of itemReference '" + itemReference + "' of type '" + itemType + "' => " + data.d);
		}
	});
}

function fnAddExtraItemToBasketHolder2(itemReference, itemType, add) {
    PageMethods.AddToExtraItemBasketHolder(itemReference, itemType, add);
}
function fnSetSelectedTransporter(transporterData) {
	var paramList = '{"transporterData":"' + transporterData +'"}';

	$.ajax({
		type: "POST",
		url: "/Default.aspx/SetSelectedTransporter",
		data: paramList,
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function(data) {
		}
	});
}
function fnSetSelectedTransporter2(transporterData) {
    PageMethods.SetSelectedTransporter(transporterData);
}


function fnSetSelectedPaymentMethod(paymentMethod) {
	var paramList = '{"paymentMethod":' + paymentMethod + '}';

	$.ajax({
		type: "POST",
		url: "/Default.aspx/SetSelectedPaymentMethodToBasket",
		data: paramList,
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function(data) {
		}
	});
}
function fnSetSelectedPaymentMethod2(paymentMethod) {
    PageMethods.SetSelectedPaymentMethodToBasket(paymentMethod);
}

function fnGiftwrapProduct(productID, combinationID, languageCode, itemIndex) {
	var paramList = '{"productID":' + productID + ', "combinationID":' + combinationID +
		', "languageCode":"' + languageCode + '", "itemIndex":' + itemIndex + '}';

	$.ajax({
		type: "POST",
		url: "/Default.aspx/GiftwrapProduct",
		data: paramList,
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function(data) {
		}
	});
}

function fnGiftwrapProduct2(productID, combinationID, languageCode, itemIndex) {
    PageMethods.GiftwrapProduct(productID, combinationID, languageCode, itemIndex);
}

function changeQuantityInAddToBagUrl(textbox, productId, addToBagLinkId) {    
    var quantity = 1;
    if (textbox.value > 0)
        quantity = textbox.value;
    var text = document.getElementById(addToBagLinkId).href;
    text = text.replace(/Quantity=[0-9]*/, 'Quantity=' + Math.round(quantity));
    text = text.replace(/ProductID=[0-9]*/, 'ProductID=' + Math.round(productId));
    document.getElementById(addToBagLinkId).href = text;
}
function changeTotalPrice(textbox, hiddenPriceId, totalPriceId) {
    var quantity = 1;
    if (textbox.value > 0)
        quantity = textbox.value;
    var price = document.getElementById(hiddenPriceId).value;
    var total = quantity * price / 100;
    document.getElementById(totalPriceId).innerHTML = "&euro;&nbsp;" + total.toFixed(2);
    //document.getElementById('TotalPriceTextTD').innerHTML = document.getElementById('TotalPriceTextTD').innerHTML.replace(".", ",");

}
