// fixDate
function fixDate(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}
// alterError - fixes a rounding bug in Netscape 2
function alterError(value) {
if (value<=0.99) {
newPounds = '0';
} else {
newPounds = parseInt(value);
}
newPence = parseInt((value+.0008 - newPounds)* 100);
if (eval(newPence) <= 9) newPence='0'+newPence;
newString = newPounds + '.' + newPence;
return (newString);
}
// getCookieVal
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
// getCookie
function getCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
// Fin funciones comunes
// deleteCookie
function deleteCookie(name) {
thisPath = "/sites/vcanas/virtualstore.nsf/";
vacio = " " ;
document.cookie="TheBasket" + "=" + vacio + " ;path=" + thisPath;
}
// showItems
function showBasket() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('
');
}
// showContent
function showContent() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('');
document.writeln('| Su Carretilla |
');
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
thisitem = 1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
totprice = totprice + itemtotal;
itemlist=itemlist+1;
} else if (fulllist.substring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substring(itemstart, i);
if (thisitem==2) theprice = fulllist.substring(itemstart, i);
thisitem++;
itemstart=i+1;
}
}
total = eval(alterError(totprice)*1);
document.writeln('| '+itemlist+' Producto(s) | Ver |
');
document.writeln('| Total:$ '+total+' |
| >>Proceder al pago |
');
document.writeln('
');
document.writeln('
');
}
// amendItem
function amendItem(itemno, newquant) {
newItemList = '';
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
fullstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
itemlist=itemlist+1;
if (itemlist != itemno) {
newItemList =
newItemList+'['+fulllist.substring(fullstart, itemend)+']';
} else {
newItemList = newItemList + '['+theitem+'|'+theprice+'|'+newquant+']';
} } else if (fulllist.substring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substring(itemstart, i);
if (thisitem==2) theprice = fulllist.substring(itemstart, i);
thisitem++;
itemstart=i+1;
}
}
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket="+newItemList;
self.location = "/sites/vcanas/virtualstore.nsf/carretilla.html";
}
// removeItem
function removeItem(itemno) {
newItemList = '';
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
theitem = fulllist.substring(itemstart, itemend);
itemlist=itemlist+1;
if (itemlist != itemno) {
newItemList =
newItemList+'['+fulllist.substring(itemstart, itemend)+']';
}
}
}
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket="+newItemList;
self.location = "/sites/vcanas/virtualstore.nsf/carretilla.html";
}
// clearBasket
function clearBasket() {
if (confirm('Desea limpiar su carretilla?')) {
deleteCookie('TheBasket');
self.location = "/sites/vcanas/virtualstore.nsf/carretilla.html";
}
}
// deleteContents
function deleteContent() {
deleteCookie('TheBasket');
}