function dkTal(n){ n += ""; if(!n.match(/^-?\d+([,\.]\d+)*$/)){ alert("fejl"); return ""; } decs = (Math.pow(10,2)+"").substring(1); if(n.indexOf(".")>n.indexOf(",") && n.indexOf(",")>-1 || n.indexOf(",")!=n.lastIndexOf(",")){ n = n.replace(/,/g,""); }else if(n.indexOf(",")>-1 || n.indexOf(".")!=n.lastIndexOf(".")){ n = n.replace(/\./g,"").replace(/,/g,"."); } if(n.indexOf(".")==-1 && n.indexOf(",")==-1){ return ins1000Sep(n + "," + decs); } n = Math.round(+n*Math.pow(10,2))/Math.pow(10,2)+""; n += n.indexOf(".")>-1 ? decs : "." + decs; n = n.substring(0,n.indexOf(".") + 3); return ins1000Sep(n.replace(/\./,",")); } function ins1000Sep(v){ v = v.split(","); v[0] = v[0].split("").reverse().join(""); v[0] = v[0].replace(/(\d{3})/g,"$1."); v[0] = v[0].split("").reverse().join(""); v[0] = v[0].replace(/^(-?)\./,"$1"); return v.join(","); } var flyingSpeed = 10; if (navigator.appName=="Microsoft Internet Explorer" && (navigator.userAgent.indexOf("compatible; MSIE 8.0")>0)) { flyingSpeed = 20; } var url_addProductToBasket = 'handleProduct.asp?sid='+Math.random(); var url_removeProductFromBasket = 'handleProduct.asp?sid='+Math.random(); var shopping_cart_div = false; var flyingDiv = false; var currentProductDiv = false; var shopping_cart_x = false; var shopping_cart_y = false; var slide_xFactor = false; var slide_yFactor = false; var diffX = false; var diffY = false; var currentXPos = false; var currentYPos = false; var ajaxObjects = new Array(); function shoppingCart_getTopPos(inputObj) { var returnValue = inputObj.offsetTop; while((inputObj = inputObj.offsetParent) != null){ if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop; } return returnValue; } function shoppingCart_getLeftPos(inputObj) { var returnValue = inputObj.offsetLeft; while((inputObj = inputObj.offsetParent) != null){ if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft; } return returnValue; } function pausecomp(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < millis); } function addToBasket(productId, antal,md5value) { if ( navigator.userAgent.indexOf("Safari") > 0 ) { pausecomp(100); } //alert(" addToBasket( " + productId + " , " + antal + " , "+ md5value + ")");//DEBUG if(isNaN(antal)){ alert('Ikke gyldig værdi du vil ligge i kurven'); return false; } if(!shopping_cart_div) shopping_cart_div = document.getElementById('shopping_cart'); if(!flyingDiv){ flyingDiv = document.createElement('DIV'); flyingDiv.style.position = 'absolute'; flyingDiv.style.zIndex = 5; document.body.appendChild(flyingDiv); } shopping_cart_x = shoppingCart_getLeftPos(shopping_cart_div); shopping_cart_y = shoppingCart_getTopPos(shopping_cart_div); currentProductDiv = document.getElementById('slidingProduct' + productId); currentXPos = shoppingCart_getLeftPos(currentProductDiv); currentYPos = shoppingCart_getTopPos(currentProductDiv); diffX = shopping_cart_x - currentXPos; diffY = shopping_cart_y - currentYPos; //Her springer vi flyveturen over var shoppingContentCopy = currentProductDiv.cloneNode(true); shoppingContentCopy.id=''; flyingDiv.innerHTML = ''; flyingDiv.style.left = currentXPos + 'px'; flyingDiv.style.top = currentYPos + 'px'; flyingDiv.appendChild(shoppingContentCopy); flyingDiv.style.display='block'; flyingDiv.style.width = currentProductDiv.offsetWidth + 'px'; flyToBasket(productId, antal,md5value); } var temp = 0; function flyToBasket(productId,antal,md5value) { if (temp==0){ //alert("flyToBasket("+ productId +" , " + antal + " , " + md5value + ")"); temp = 1; } var maxDiff = Math.max(Math.abs(diffX),Math.abs(diffY)); var moveX = (diffX / maxDiff) * flyingSpeed;; var moveY = (diffY / maxDiff) * flyingSpeed; currentXPos = currentXPos + moveX; currentYPos = currentYPos + moveY; flyingDiv.style.left = Math.round(currentXPos) + 'px'; flyingDiv.style.top = Math.round(currentYPos) + 'px'; if(moveX>0 && currentXPos > shopping_cart_x){ flyingDiv.style.display='none'; } if(moveX<0 && currentXPos < shopping_cart_x){ flyingDiv.style.display='none'; } if(flyingDiv.style.display=='block') setTimeout('flyToBasket("' + productId + '","'+antal+'","'+md5value+'")',10); else opdaterKurv(productId,md5value,antal) } function showAjaxBasketContent(ajaxIndex,antal,md5value) { //alert("showAjaxBasketContent("+ajaxIndex+" , "+ antal + " , " +md5value + ")"); // Getting a reference to the shopping cart items table var itemBox = document.getElementById('shopping_cart_items'); alert("AJAX: " + ajaxObjects[ajaxIndex]); alert("URLString: " + ajaxObjects[ajaxIndex].URLString); alert("response: " + ajaxObjects[ajaxIndex].response); alert("responseXML: " + ajaxObjects[ajaxIndex].responseXML); alert("responseStatus[0]: " + ajaxObjects[ajaxIndex].responseStatus[0]); alert("responseStatus[1]: " + ajaxObjects[ajaxIndex].responseStatus[1]); var productItems = ajaxObjects[ajaxIndex].response.split('|||'); // Breaking response from Ajax into tokens if(document.getElementById('shop_produkt' + productItems[0])){ // A product with this id is allready in the basket - just add number items var row = document.getElementById('shop_produkt' + productItems[0]); // var prices = row.cells[2].innerHTML; items = productItems[2]; // prices = productItems[3] row.cells[2].innerHTML = parseFloat(productItems[3]).toFixed(2);; row.cells[1].innerHTML = items; }else{ // Product isn't allready in the basket - add a new row var tr = itemBox.insertRow(-1); tr.id = 'shop_produkt' + productItems[0] /* DEDUG alert(productItems[0]);//id alert(productItems[1]);//beskrivelse alert(productItems[2]);//antal alert(productItems[3]);//sum alert(productItems[4]);//md5 */ var td = tr.insertCell(-1); td.className ='kurvprodukt'; td.innerHTML = productItems[1]; // Description var td = tr.insertCell(-1); td.className ='kurvantal'; td.innerHTML = antal; // Number of items var td = tr.insertCell(-1); td.className ='kurvpris'; myprice=parseFloat(productItems[3]).toFixed(2); td.innerHTML = myprice; // Price var td = tr.insertCell(-1); //alert(td.innerHTML); td.innerHTML = ''; } updateTotalPrice(); ajaxObjects[ajaxIndex] = false; alert("slutter"); } function updateTotalPrice() { //alert("updateTotalPrice"); var itemBox = document.getElementById('shopping_cart_items'); // Calculating total price and showing it below the table with basket items var totalPrice = 0; if($('.shopping_cart_totalprice')){ var myCount = 0 for(var no=myCount;no-1) function deleteallRows(mytable) { var myCount = 0 var rowCount = mytable.rows.length; for(i=rowCount-1; i >= myCount; i--) mytable.deleteRow(i); } function updKurvProduktLinie(produktid, produktnavn, antal, liniepris,md5value){ //document.getElementById("kurvliniestatus").innerHTML="updKurvProduktLinie()"; //alert("updKurvProduktLinie "+produktid+', '+ produktnavn+', '+ antal+', '+ liniepris); var itemBox = document.getElementById('shopping_cart_items'); if(md5value.length<=3){ alert('Du har desværre ikke aktiveret cookies, som indkøbskurven kræver\n\nDu kan aktiverer cookies på følgende måde:\n\n1.) Vælg Internetindstillinger i menuen Funktioner. \n\n2.) Klik på fanen Beskyttelse af personlige oplysninger for at ændre dine cookie-indstillinger.\n\n3.) Klik på knappen Standard, eller flyt skyderen til indstillingen -Mellem-\n\n4.) Når du ser siden igen skal du trykke opdater eller "F5" for at genindlæse siden.'); } else if(antal<=0 && produktid==0){ deleteallRows(itemBox); // alert('Kurven er blevet tømt'+antal+'-'+produktid); } else if(antal<=0){ var productRow = document.getElementById('shop_produkt' + produktid); var numberOfItemCell = productRow.cells[1]; //alert(numberOfItemCell.innerHTML); productRow.parentNode.removeChild(productRow); } else{ if(document.getElementById('shop_produkt' + produktid)){ // A product with this id is allready in the basket - just add number items var row = document.getElementById('shop_produkt' + produktid); row.cells[0].innerHTML = antal+'x'; row.cells[1].innerHTML = produktnavn.substring(0,12)+'..'; row.cells[2].innerHTML = liniepris; } else{ var tr = itemBox.insertRow(-1); tr.id = 'shop_produkt' + produktid var td = tr.insertCell(-1); td.className ='kurvantal'; td.innerHTML = String(antal) + 'x'; var td = tr.insertCell(-1); td.className ='kurvprodukt'; td.title =produktnavn; td.innerHTML = produktnavn.substring(0,12)+'..'; var td = tr.insertCell(-1); td.className ='kurvpris'; td.innerHTML = liniepris; var td = tr.insertCell(-1); td.className ='kurvfjern'; td.innerHTML = ''; } } }