function buyItem(ItemNo,NeedsPic) { var amount, input; for (var i=0; i<7; i++){ inputField = document.getElementById('amount'+i+'_'+ItemNo); if (inputField == null || inputField == '') continue; amount = inputField.value; if (amount != null && amount != '' && amount != 0){ if (i == 0) doBuyItem(ItemNo, '', amount, NeedsPic); else doBuyItem(ItemNo, i, amount, NeedsPic); inputField.value = ''; } } $.ajax({ method:'post', async: false, url: "http://www.posten.ax/webshop/lib/ajaxServer.con", data: 'LangCode=2&function=GetCartPrice&debug=1', success:updateCartPrice, error: errFunc }); } function doBuyItem(ItemNo, vCode, amount, NeedsPic) { $.ajax({ method:'post', async: false, url: "http://www.posten.ax/webshop/lib/ajaxServer.con", data: 'LangCode=2&ItemNo='+ItemNo+ '&vCode='+vCode+ '&amount='+amount+ '&NeedsPic='+NeedsPic+ '&function=AddItemToCart&debug=1', success:updateCart, error: errFunc }); } var errFunc = function(t) { alert('Error ' + t.status + ' -- ' + t.statusText); } var updateCart = function(t) { //var xmlDoc = t.responseXML.documentElement; var xmlDoc = t; //Handle data. var ItemCategoryCode = getXMLValue('ItemCategoryCode', xmlDoc, 1); var Items = xmlDoc.getElementsByTagName('item'); var CartList = document.getElementById('CartList'); CartList.innerHTML = ''; if(Items.length > 0) { aProduct = new Array() //document.getElementById('btnEditBasket').disabled=false; document.getElementById('btnCheckout').disabled=false; //alert("length: "+Items.length); var table = document.createElement("table"); var tbody = document.createElement("tbody"); table.appendChild(tbody); var mod = 0; for(i=0;i'; tr.appendChild(td); var td = document.createElement("td"); td.className = 'cartAmount'; td.innerHTML = Amount; tr.appendChild(td); var td = document.createElement("td"); td.className = 'cartDesc'; td.innerHTML = Description; tr.appendChild(td); var td = document.createElement("td"); td.className = 'cartPrice'; checkDecimal(td, AllPrice); tr.appendChild(td); tbody.appendChild(tr); } //Logga till servern att produkten lagts till logToServer('addToCart', aProduct); //log to giosg _giosg(function () { giosg.api.shoppingCart.submit(aProduct).then( function () {logToServer('addToCart success', '')}, function () {logToServer('addToCart error', '')} ); }); CartList.appendChild(table); if(Items.length == 1) $('#headerCartItems').text("Ostoskorini: " + Items.length + " tuote"); else $('#headerCartItems').text("Ostoskorini: " + Items.length + " tuotteet"); $("#basket").slideDown(); $('html').animate({scrollTop : 0},'slow'); var basketHide = setTimeout('$("#basket").slideUp()', 4000); } else { CartList.innerHTML = "

Ostoskorisi on tyhjä

"; $('#headerCart').text(Items.length + "Ostoskorisi on tyhjä"); } } function updateCartPrice(t) { //var xmlDoc = t.responseXML.documentElement; var xmlDoc = t; //var data = xmlDoc.getElementsByTagName('data'); var price = getXMLValue('result', xmlDoc, 1); $('#CartPrice').text(price + "€"); $('#headerCartPrice').text(price + "€"); } function checkDecimal(obj, objStr){ var objNumber; if(isNaN(objStr) && objStr!=''){ //alert('Värdet är ej nummeriskt'); objNumber = objStr; } if(objStr==''){ objNumber = ''; } else if(objStr.indexOf(',')!=-1){ if(((objStr.length) - (objStr.indexOf(',')))>3){ objStr = objStr.substr(0,((objStr.indexOf(','))+3)); } if(objStr.indexOf(',')==0){ objStr = '0' + objStr; } var sLen = objStr.length; var TChar = objStr.substr(sLen-3,3); if(TChar.indexOf(',')==0){ objNumber = objStr; } else if(TChar.indexOf(',')==1){ objNumber = objStr + '0'; } else if(TChar.indexOf(',')==2){ objNumber = objStr + '00'; } } else{ objNumber = objStr + ',00'; } obj.innerHTML = objNumber; } // datatype 1 - text // 2 - int // 3 - float function getXMLValue(fieldname, dataset, datatype) { var result; if (!dataset.getElementsByTagName(fieldname)[0] || dataset.getElementsByTagName(fieldname)[0].firstChild == null) result = ''; else result = dataset.getElementsByTagName(fieldname)[0].firstChild.nodeValue; return result; } function removeCartItem(uCode) { document.getElementById('uCode').value = uCode; document.getElementById('action').value = 'remove'; document.getElementById('basketForm').submit(); } function destroyBasket() { var answer = confirm("Oletko varma, että haluat poistaa kaikki tuotteet ostoskoristasi"); if(answer) { alert("Ostoskorisi on nyt tyhjä"); document.getElementById('Action').value = 'Destroy'; document.getElementById('ItemActionForm').submit(); } } function updateAmounts() { document.getElementById('UpdateAction').value = 'Update'; document.getElementById('ItemUpdateForm').submit(); } function checkout(CashOnly) { /*if(CashOnly && document.getElementById('PaymentMethod_INVOICE').checked == true) { document.getElementById('checkoutButton').disabled = false; alert("SSN is needed for invoice payment!"); return; }*/ document.getElementById('ItemUpdateForm').action = 'shop_checkout.con'; document.getElementById('ItemUpdateForm').submit(); //window.location='CheckOut.con'; } function payment() { document.getElementById('ItemUpdateForm').action = 'shop_payment.con'; document.getElementById('ItemUpdateForm').submit(); //window.location='CheckOut.con'; }