var sendReq = getXmlHttpRequestObject();
var receiveReq = getXmlHttpRequestObject();
var receiveReqInfoBox = getXmlHttpRequestObject();
var file = 'getCart.php';
var loc = 'span_cart';
var tmp = ' Please wait...
';
var gids = '';
//Function for initializating the page.
function startCart(key,file,sid,loc,tmp)
{
//Start Showing Cart.
getCartText('',file,sid,loc,tmp);
}
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject()
{
if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.';
}
}
//Gets the current cart
function getCartText(key,file,sid,loc,tmp)
{
var url=file+"?"+sid+"&"+key;
if (sid && key)
{
url=file+"?"+sid+"&"+key;
}
else
{
if (sid)
{
url=file+"?"+sid;
}
else
{
if (key)
{
url=file+"?"+key;
}
else
{
url=file;
}
}
}
if (tmp) {getObject(loc).innerHTML = tmp;}
if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
{
receiveReq.open("GET", url+'&Cart=1', true);
receiveReq.onreadystatechange = handleReceiveCart;
receiveReq.send(null);
}
}
//Gets the current cart info box
function getCartInfoBoxText(key,file,sid,loc,tmp)
{
var url=file+"?"+sid+"&"+key;
if (sid && key)
{
url=file+"?"+sid+"&"+key;
}
else
{
if (sid)
{
url=file+"?"+sid;
}
else
{
if (key)
{
url=file+"?"+key;
}
else
{
url=file;
}
}
}
if (tmp) {getObject(loc).innerHTML = tmp;}
if (receiveReqInfoBox.readyState == 4 || receiveReqInfoBox.readyState == 0)
{
receiveReqInfoBox.open("GET", url+'&Cart=1', true);
receiveReqInfoBox.onreadystatechange = handleReceiveCartInfoBox;
receiveReqInfoBox.send(null);
}
}
//send change of stock to Cart.
function sendCartChangeQty(key,file,sid,loc,tmp,iElementId,product_id,qty)
{
if (typeof iElementId == "string" && iElementId.length > 0)
{
var element = document.getElementById(iElementId);
if (element)
{
//alert("name=" + element.name + " - id=" + element.id);
//return;
}
else
{
document.getElementById('p_status').innerHTML = 'Status: Could not find the requested element.';
return;
}
}
if (qty.length > 0)
{
qty_float = parseFloat(qty);
if (isNaN(qty_float))
{
document.getElementById('p_status').innerHTML = 'Status: You must enter a number for Quantity.';
return;
}
}
else
{
qty_float = 1;
}
// check if Quantity drops below 0
if (Number(element.value) + Number(qty) <= 0)
{
// Are you sure you want to remove this item
var fRet;
fRet = confirm('Are you sure you want to remove this item from your shopping cart?');
if (fRet == false)
{
return;
}
}
var url=file+"?"+sid+"&"+key;
if (sid && key)
{
url=file+"?"+sid+"&"+key;
}
else
{
if (sid)
{
url=file+"?"+sid;
}
else
{
if (key)
{
url=file+"?"+key;
}
else
{
url=file;
}
}
}
if (tmp) {getObject(loc).innerHTML = tmp;}
if (sendReq.readyState == 4 || sendReq.readyState == 0)
{
sendReq.open("POST", url+'&Cart=1', true);
sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
sendReq.onreadystatechange = handleSendCart;
var param = 'quantity=' + (Number(element.value) + Number(qty));
param += '&products_id=' + product_id;
sendReq.send(param);
}
}
//send change of stock to Cart.
function sendCartRemoveItem(key,file,sid,loc,tmp,iElementId,product_id)
{
if (typeof iElementId == "string" && iElementId.length > 0)
{
var element = document.getElementById(iElementId);
if (element)
{
//alert("name=" + element.name + " - id=" + element.id);
//return;
}
else
{
document.getElementById('p_status').innerHTML = 'Status: Could not find the requested element.';
return;
}
}
// check user wants to remove item
if (element.value != '')
{
// Are you sure you want to remove this item var fRet;
fRet = confirm('Are you sure you want to remove this item from your shopping cart?');
//alert(fRet);
if (fRet == false) { return; }
}
var url=file+"?"+sid+"&"+key;
if (sid && key)
{
url=file+"?"+sid+"&"+key;
}
else
{
if (sid)
{
url=file+"?"+sid;
}
else
{
if (key)
{
url=file+"?"+key;
}
else
{
url=file;
}
}
}
if (tmp) {getObject(loc).innerHTML = tmp;}
if (sendReq.readyState == 4 || sendReq.readyState == 0)
{
sendReq.open("POST", url+'&Cart=1', true);
sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
sendReq.onreadystatechange = handleSendCartRemoveItem;
var param = '&products_id=' + product_id;
param += '&cart_delete=Yes';
sendReq.send(param);
}
}
//When our stock change has been sent, update our page.
function handleSendCart()
{
getCartText('','getCart.php','osCsid=g5881cpj9spr003kidhfpq07d5','span_cart',tmp);
getCartInfoBoxText('','getCartBox.php','osCsid=g5881cpj9spr003kidhfpq07d5','span_cart_box',tmp);
}
function elmLoop()
{
for(i=0; i