// shopping basket js code file // Kieran Metcalfe - Dec 2007 // setup an XMLHTTP Object - used for various things function getHTTP() { var xmlhttp=false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) // JScript gives us Conditional compilation, we can cope with old IE versions. // and security blocked creation of the objects. try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @end @*/ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp=false; } } if (!xmlhttp && window.createRequest) { try { xmlhttp = window.createRequest(); } catch (e) { xmlhttp=false; } } return xmlhttp; } var bskopen = 0 ; function toggleBasket() { obj = document.getElementById("container"); bask = document.getElementById("basketContainer"); bLink = document.getElementById("basketOpenLink"); if (obj.className == "container-basketclosed") { obj.className = "container-basketopen"; bask.className = "basket-open"; bLink.style.display = "none"; bskopen = 1; }else{ obj.className = "container-basketclosed"; bask.className = "basket-closed"; bLink.style.display = "block"; bskopen = 0; } // send ajax request xmlhttp = getHTTP(); if (!xmlhttp) { alert("Error creating AJAX request"); } else { xmlhttp.open("GET", "/basket/toggleBasket.php?open=" + bskopen,true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { //alert(xmlhttp.responseText) window.status = "Basket Toggled"; } } xmlhttp.send(null) } } var gType = ""; var gItem = ""; var gInstr = ""; var donePopup = false; function doAdd() { // send ajax request if (donePopup) { gInstr = processFields(); } else { gInstr = ""; } xmlhttp = getHTTP(); if (!xmlhttp) { alert("Error creating AJAX request"); } else { xmlhttp.open("POST", "/basket/basketAdd.php", true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { //alert(xmlhttp.responseText) setBasketSummary(xmlhttp.responseText); if (bskopen == 0) { toggleBasket(); } } } var content = "type=" + gType + "&itm=" + gItem + gInstr; //Send the proper header information along with the request xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", content.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(content) } } function basketAdd(type, item, dlg) { gType = type; gItem = item; pm = document.getElementById("popupMask"); if (pm == null) { dlg = false; } else { dlg = true; } if (dlg) { donePopup = true; showPopWin('/paypaltest.php', 400, 400, doAdd); } else { donePopup = false; doAdd(); } } function basketClear() { if (confirm("This will remove all items from your basket.\nAre you sure?")) { xmlhttp = getHTTP(); if (!xmlhttp) { alert("Error creating AJAX request"); } else { xmlhttp.open("GET", "/basket/basketClear.php", true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { //alert(xmlhttp.responseText) setBasketSummary(xmlhttp.responseText); } } xmlhttp.send(null) } } } function setBasketSummary(val) { objs = document.getElementsByName("basketSummary"); idx = val.indexOf(""); summary = val.substring(0, idx); for (i = 0;i < objs.length;i++) { objs[i].innerHTML = summary; } objs = document.getElementsByName("basketDetail"); for (i = 0;i < objs.length;i++) { objs[i].innerHTML = val; } } function removeItem(id) { xmlhttp = getHTTP(); if (!xmlhttp) { alert("Error creating AJAX request"); } else { xmlhttp.open("GET", "/basket/removeItem.php?itm=" + id, true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { //alert(xmlhttp.responseText) setBasketSummary(xmlhttp.responseText); } } xmlhttp.send(null) } } var instrFlds = new Array(); var instrLbls = new Array(); function registerField(name, label) { instrFlds.push(name); instrLbls.push(label); } function processFields() { var outStr = ""; for (i = 0; i < instrFlds.length;i++) { aryFlds = document.getElementsByName(instrFlds[i]); //alert (instrFlds[i] + " : " + aryFlds[0].type); valStr = ""; switch (aryFlds[0].type) { case "radio": for(j = 0;j < aryFlds.length;j++) { if (aryFlds[j].checked) { valStr += aryFlds[j].value; } } break; case "select-one": valStr += aryFlds[0].options[aryFlds[0].selectedIndex].text; break; case "text": valStr += aryFlds[0].value; break; case "textarea": valStr += aryFlds[0].value; break; default: alert("unknown type: " + aryFlds[0].type + " (" + instrLbls[i] + ")"); } /*if (valStr != "") { if (i > 0) { outStr += "\n"; }*/ //outStr += instrLbls[i] + ": " + valStr; outStr += "&" + instrFlds[i] + "=" + valStr + "&" + instrFlds[i] + "-lbl=" + instrLbls[i]; //} } return outStr; }