";
function NumberOfItems(string, option_separating_char, item_separating_char) {
// returns the number of trolley items
if(string == "") {
alert("Your shopping trolley is currently empty.");
return 0;
}
//count the number of item separators
num_sep_found = 0;
num_fin_found = 0;
finished = -1;
pos = 0;
while(finished!=1)
{
if(string.charAt(pos) == option_separating_char) num_sep_found++;
if(string.charAt(pos) == item_separating_char)
{
num_fin_found++;
if(string.charAt(pos+1) != option_separating_char) finished=1;
}
pos++;
}
//divide by the number of 'ends' found
num_sep_found = num_sep_found - num_fin_found;
//if(num_fin_found >0) return num_sep_found/num_fin_found;
return num_fin_found;
}
function ClearTrolley() {
if (confirm("Clear the contents of your shopping trolley?"))
{
document.cookie="";
history.back();
}
}
function getElement(terminator,index,string) {
//find nth terminator
pos = 0;
for (inc=1; inc<index+1; inc++) {
pre_pos = pos+1;
pos = string.indexOf(terminator,pre_pos);
}
//return the substring between the index-1 and index
temp = string.substring(pre_pos,pos);
return temp;
}
function removeItem(terminator, itemN, string, form ) {
// removes item from list
//find nth element
//find nth terminator
posi = 0;
pre_posi=0;
for (inc=0; inc<itemN; inc++) {
pre_posi = posi+1;
posi = string.indexOf(terminator,pre_posi);
}
//return the substring between the pre_pos and pos
// split from 0 to pre_pos
temp_start = string.substring(0, pre_posi-1);
// split from pos to end
temp_end = string.substring(posi+1, string.length);
// join strings up
tempi = temp_start;
if (temp_start !="") tempi = tempi + "
关键词:cookie的技巧与购物车