// This function is called upon completion of the form. // Since JavaScript is obviously running, adjust the form accordingly - load new stylesheets, kill certain sections and add content to others... function MK_activateJsFunctionality() { LET_replaceClass(document.getElementById(currentPanel), 'section', 'currentSection'); LET_replaceClass(document.getElementById(currentPanel + '_Tab'), 'sectionTab', 'currentSectionTab'); LET_appendStylesheet('/css/myntpriser_screen_js.css'); LET_appendStylesheet('/css/myntpriser_print_js.css', 'print'); el = document.getElementById('hook1'); if (el) { el.innerHTML = 'Inköpsvärdet beräknas automatiskt av formuläret.'; } el = document.getElementById('hook2'); if (el) { el.innerHTML = ''; } el = document.getElementById('navigationPrefix'); if (el) { el.innerHTML = 'Välj flik: '; } for (var itemId in panelVarsArray) { el = document.getElementById(itemId); if (el) { if (panelVarsArray[itemId]['Total']) { LET_setClass(el, el.className + ' print'); } else { LET_setClass(el, el.className + ' noPrint'); } } el = document.getElementById(itemId+'_ButtonSection'); if (el) { newP = document.createElement('p'); LET_setClass(newP, 'noPrint'); newP.innerHTML = " Skriv ut enbart denna flik"; el.parentNode.replaceChild(newP, el); } } el = document.getElementById('hook5'); if (el) { el.innerHTML = " Skriv ut formuläret"; } MK_updateTabs(); } function MK_addRow(panelId) { el = document.getElementById(panelId+'_Counter'); if (el) { el.value = parseInt(el.value) + 1; tableEl = document.getElementById(panelId+'_Table'); if (tableEl) { var newRow=document.createElement('tr'); var rowId = panelId + el.value; newRow.setAttribute('id', rowId+'_Row'); var modifier = 0; var modifierEl = document.getElementById(panelId+'_Modifier'); if (modifierEl) { modifier = modifierEl.value; } var newCell1=document.createElement('td'); LET_setClass(newCell1, 'descriptionBox'); var newHtml = "

 

"; newCell1.innerHTML = newHtml; var newCell2=document.createElement('td'); LET_setClass(newCell2, 'finenessBox'); var newKeyupScript = "recalcSum(\"" + panelId + "\", \"" + rowId + "\", " + (panelId == 'GoldObjects' ? '24' : '100') + ", "; newKeyupScript += modifierEl.value + ", true, " + (panelId == 'GoldObjects' ? '1.00' : '1.00') + ");" var newHtml = "

"; newCell2.innerHTML = newHtml; var newCell3=document.createElement('td'); LET_setClass(newCell3, 'weightBox'); var newHtml = "

"; newHtml += "

"; newCell3.innerHTML = newHtml; var newCell4=document.createElement('td'); LET_setClass(newCell4, 'sum'); newCell4.innerHTML = "

0,00 kr

"; itemTotalsArray[panelId][rowId] = 0; newRow.appendChild(newCell1); newRow.appendChild(newCell2); newRow.appendChild(newCell3); newRow.appendChild(newCell4); tableEl.appendChild(newRow); } } } function MK_deleteRow(panelId, rowId) { rowEl = document.getElementById(rowId+'_Row'); row = parseInt(rowId.substring(panelId.length)); itemTotalsArray[panelId][panelId+row] = 0; rowEl.parentNode.removeChild(rowEl); updateSectionTotal(panelId); } function MK_printSection(section) { for (var itemId in panelVarsArray) { if (itemId == section) { LET_replaceClass(document.getElementById(itemId), 'noPrint', 'print'); } else { LET_replaceClass(document.getElementById(itemId), 'print', 'noPrint'); } } LET_setClass(document.getElementById('hook3'), 'noPrint'); LET_setClass(document.getElementById('hook4'), 'print'); window.print(); LET_setClass(document.getElementById('hook3'), ''); LET_setClass(document.getElementById('hook4'), ''); for (var itemId in panelVarsArray) { if (panelVarsArray[itemId]['Total'] > 0) { LET_replaceClass(document.getElementById(itemId), 'noPrint', 'print'); } else { LET_replaceClass(document.getElementById(itemId), 'print', 'noPrint'); } } } function MK_updateTabs() { for (var itemId in panelVarsArray) { el = document.getElementById(itemId+'_Tab'); if (el) { hrf = el.href; if (hrf.indexOf('javascript:') == 0) { hrf = hrf.slice(11); } else { hrf = ';'; } hrefParts = hrf.split(';'); lng = hrefParts.length; if (itemId == currentPanel) { LET_replaceClass(el, 'sectionTab', 'currentSectionTab'); hrefParts[lng -2] = 'return false'; } else { LET_replaceClass(el, 'currentSectionTab', 'sectionTab'); hrefParts[lng -2] = 'MK_switchTab("'+itemId+'")'; } el.href = 'javascript:' + hrefParts.join(';'); } } } function MK_switchTab(newTab) { currentPanel = newTab; for (var itemId in panelVarsArray) { el = document.getElementById(itemId); if (el) { if (itemId == newTab) { LET_replaceClass(el, 'section', 'currentSection'); } else { LET_replaceClass(el, 'currentSection', 'section'); } } } MK_updateTabs(); } function recalcSum(panelId, itemId, units, mod, allowDecimals, roundingModifier) { if (document.getElementById(itemId+'_Fineness')) { var finenessEl = document.getElementById(itemId+'_Fineness'); var fineness = finenessEl.value; var searchVal = fineness; } else { var finenessEl = null; var fineness = units; var searchVal = itemId; } if ((typeof modList !== 'undefined') && (typeof modList[searchVal] !== 'undefined')) { mod = modList[searchVal]; fineness = 24; } if (document.getElementById(itemId+'_Qty')) { var qtyEl = document.getElementById(itemId+'_Qty'); } else if (document.getElementById(itemId+'_Weight')) { var qtyEl = document.getElementById(itemId+'_Weight'); } else { var qtyEl = null; } if (qtyEl) { if ((!allowDecimals) && ((qtyEl.value.indexOf(',') != -1) || (qtyEl.value.indexOf('.') != -1))) { var price = -2; } else { var price = recalcPrice(qtyEl.value, fineness, units, mod, roundingModifier); } if ((price < 0) && (-price & 2)) { LET_setClass(qtyEl, 'inputError'); } else { LET_setClass(qtyEl, 'inputOK'); } if (finenessEl) { if ((price < 0) && (-price & 4)) { LET_setClass(finenessEl, 'inputError'); } else { LET_setClass(finenessEl, 'inputOK'); } } updateItemTotal(panelId, itemId, price); } } function recalcPrice(quantity, fineness, finenessUnits, modifier, rounding) { // Failsafes to filter out spaces and to replace (the Swedish) decimal commas with decimal points; if ((typeof(quantity) == 'string') && isNaN(quantity)) { quantity = quantity.split(' ').join('').split(',').join('.'); } if ((typeof(fineness) == 'string') && isNaN(fineness)) { fineness = fineness.split(' ').join('').split(',').join('.'); } if ((typeof(modifier) == 'string') && isNaN(modifier)) { modifier = modifier.split(' ').join('').split(',').join('.'); } // Of course, values may still be incomprehensible. var response = 0; if (isNaN(finenessUnits) || isNaN(modifier) || isNaN(rounding)) { response += -1; } if (isNaN(quantity)) { response += -2; // ...or out of range } else if (quantity < 0) { response += -2; } if (isNaN(fineness)) { response += -4; // ...or out of range } else if ((fineness < 0) || (fineness > finenessUnits)) { response += -4; } if (response) { return response; } else { if ( finenessUnits == 24) { return (parseFloat(quantity) * Math.round(((parseFloat(fineness) / parseFloat(finenessUnits)) * parseFloat(modifier) - 1.5) / 5) * 5); } else { return roundPrice(parseFloat(quantity) * (parseFloat(fineness) / parseFloat(finenessUnits)) * parseFloat(modifier), parseFloat(rounding)); } } } function updateItemTotal(panelId, itemId, price) { var tot = document.getElementById(itemId+'_Total'); if (price < 0) { price = 0; } itemTotalsArray[panelId][itemId] = price; if (tot) { tot.innerHTML = formatPrice(price); } updateSectionTotal(panelId); } function updateSectionTotal(panelId) { if (itemTotalsArray[panelId] instanceof Object) { var sum = 0; for (var id in itemTotalsArray[panelId]) { if (!isNaN(itemTotalsArray[panelId][id])) { sum = sum + itemTotalsArray[panelId][id]; } } if (sum > 0) { LET_replaceClass(document.getElementById(panelId), 'noPrint', 'print'); } else { LET_replaceClass(document.getElementById(panelId), 'print', 'noPrint'); } var sectTotal = document.getElementById(panelId+'_SectionTotal'); if (sectTotal) { sectTotal.innerHTML = formatPrice(sum); } var grandTotal = document.getElementById('grandTotal'); if ((panelVarsArray instanceof Object) && (grandTotal)) { if (panelVarsArray[panelId] instanceof Object) { panelVarsArray[panelId]['Total'] = sum; var sum = 0; for (var id in panelVarsArray) { if (!isNaN(panelVarsArray[id]['Total'])) { sum = sum + panelVarsArray[id]['Total']; } } grandTotal.innerHTML = formatPrice(sum); } } } } function setNamedCookie(cName, value) { var cName = "TestCookie"; var cValue = escape(value); document.cookie = cName + '=' + cValue; } function getNamedCookie(cName) { var i, x, ARRcookies = document.cookie.split(';'); var foundVal = ''; for (i = 0; i < (ARRcookies.length); i++) { tempCookie = ARRcookies[i].split('='); x = tempCookie[0].replace(/^\s+|\s+$/g, ''); if (x == cName) { if ( tempCookie.length > 1 ) { foundVal = tempCookie[1].replace(/^\s+|\s+$/g, ''); return foundVal; } return ''; } } return null; }