function getHTTPObject() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); if (!xmlhttp) { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } } return xmlhttp; } var xmlHttp = getHTTPObject(); function checkStock(product_ids) { var url = "/checkstock_ajax.php?products=" + escape(product_ids); xmlHttp.open("GET", url, true); xmlHttp.onreadystatechange = alertOnStock; xmlHttp.send(null); } function checkBasketStock(product_ids) { var url = "/checkstock_ajax.php?products=" + escape(product_ids); xmlHttp.open("GET", url, true); xmlHttp.onreadystatechange = alertOnBasketStock; xmlHttp.send(null); } function alertOnStock() { if (xmlHttp.readyState == 4) { var tool = xmlHttp.responseText; stocks = tool.split('*-*'); for(loop=0;loop parseInt(indStock[1]) && parseInt(indStock[1]) != -1) { alert(indStock[2]+'\n\nSorry, we currently only have '+indStock[1]+' of this item in stock - your basket has been updated accordingly'); document.getElementById('qty['+indStock[0]+']').value = indStock[1]; } } } } } function alertOnBasketStock() { if (xmlHttp.readyState == 4) { var tool = xmlHttp.responseText; stocks = tool.split('*-*'); for(loop=0;loop parseInt(indStock[1]) && parseInt(indStock[1]) != -1) { alert(indStock[2]+'\n\nSorry, we currently only have '+indStock[1]+' of this item in stock - your basket has been updated accordingly'); document.getElementById('qty['+indStock[0]+']').value = indStock[1]; } } } document.frmBasket.submit(); } }