
/* ####################################################
   ####################################################
   ##                                                ##
   ## THE SHOPPING CART		                          ##
   ## Version 1.1                                    ##
   ## Written by Dane Moodie                         ##
   ## (c)2000                                        ##
   ## Please do not claim any of this code as your   ##
   ## own.                                           ##
   ## If you make any interesting modifications      ##
   ## to the code, I am always interested in seeing  ##
   ## them. Email me at: milhous@paradise.net.nz     ##
   ##                                                ##
   ##                                                ##
   ####################################################
   ####################################################

The code is written entirely in HTML and Java Script. It functions exactly the same on
either Internet Explorer or Netscape. This program represents a basic shell for an
e-shop. It can easily be extened by adding extra pages, and extra products to each page.
There is really no maximum to the number of products you can display with this site, although
it will begin to become more unmanagable as the number goes over a couple of a hundred.
All processing takes place on the users computer. The server is only used to receive the
order form once the user has finished their shopping.
All functions are commented. Also the HTML representing Product One on Page One is commented
and explains exactly how to add a new product to a page.
*/

/* --------------------------------------------------------------------------------- 

	This function is used to create instances of products. Each product must be
    represented by an object in the following form. The parameters are all self-
    explainatory - the PRICE of the product - the NAME of the product - the URL
    of the product on your site - the ID of the product. The product ID is essencial
    because this is sent back to you rather than the name of the product.*/
    
function product(price, name, isbn, location, id) {
   this.price = price; 
   this.name = name;
   this.isbn = isbn;
   this.location = location;
   this.id = id;
}

/* --------------------------------------------------------------------------------------------

	This code creates instances of the nine demo products on this site. It is recommended
   that you maintain a naming system similar to the one below to avoid confusion as the
   size of your site increases. (eg pgone_prone means page one - product one (the first
   product displayed on the first page)).*/

// ***INSERT HERE***

pgtwo_prone = new product(16.00, "Lifes Riddle", "1557001308", "02.php", 10);

pgthree_prone = new product(12.90, "Die Stimme der Stille", "3930623005", "03.php", 11);
pgthree_prtwo = new product(5.90, "Die Stimme der Stille - Paperback", "3930623013", "03.php", 12);

pgfour_prone = new product(4.90, "H.P.Blavatsky an die Amerikanischen Konvente 1888-1891", "3930623021", "04.php", 13);

pgfive_prone = new product(84.90, "Die Geheimlehre", "---", "05.php", 14);

pgsix_prone = new product(64.90, "Isis entschleiert", "---", "06.php", 15);

pgeight_prone = new product(24.80, "H. P. Blavatsky und die SPR", "3930623218", "08.php", 16);

pgnine_prone = new product(14.80, "Das Meer der Theosophie - Leinen", "393062303X", "09.php", 17);
pgnine_prtwo = new product(9.80, "Das Meer der Theosophie - Paperback", "3930623048", "09.php", 18);
pgnine_prthree = new product(24.80, "Das Meer der Theosophie - Kassetten", "---", "09.php", 19);

pgten_prone = new product(14.80, "Dhammapada", "3930623145", "10.php", 20);

pgeleven_prone = new product(12.80, "Bewusstsein ohne Grenzen", "3930623331", "11.php", 21);

pgtwelve_prone = new product(26.00, "The Secret Doctrine Index - Gebunden", "1557000034", "12.php", 22);
pgtwelve_prtwo = new product(18.00, "The Secret Doctrine Index - Paperback", "1557000042", "12.php", 23);

pgthirteen_prone = new product(7.90, "Der Smaragddrache", "3596120136", "13.php", 24);

pgfourteen_prone = new product(12.80, "Der Pfad", "---", "14.php", 25);

pgfifteen_prone = new product(12.50, "Okkultes Woerterbuch", "3930623072", "15.php", 26);

pgsixteen_prone = new product(16.80, "Der Wind des Geistes - Gebunden", "3930623161", "16.php", 27);
pgsixteen_prtwo = new product(9.80, "Der Wind des Geistes - Paperback", "3930623153", "16.php", 28);

pgseventeen_prone = new product(19.80, "Quelle des Okkultismus Band I", "3930623080", "17.php", 29);
pgseventeen_prtwo = new product(19.80, "Quelle des Okkultismus Band II", "3930623099", "17.php", 30);
pgseventeen_prthree = new product(19.80, "Quelle des Okkultismus Band III", "3930623102", "17.php", 31);
pgseventeen_prfour = new product(8.90, "Quelle des Okkultismus Indexband", "3930623110", "17.php", 32);
pgseventeen_prfive = new product(64.50, "Quelle des Okkultismus", "3930623129", "17.php", 33);
pgseventeen_prsix = new product(165.00, "Quelle des Okkultismus - Kassetten", "---", "17.php", 34);

pgeighteen_prone = new product(8.80, "Goldene Regeln der Esoterik", "3930623064", "18.php", 35);
pgeighteen_prtwo = new product(11.00, "Goldene Regeln der Esoterik - Kassetten", "---", "18.php", 36);

pgnineteen_prone = new product(7.90, "Die vier heiligen Jahreszeiten", "3930623137", "19.php", 37);

pgtwenty_prone = new product(10.80, "Theosophische Perspektiven Band 1", "3930623803", "20.php", 38);
pgtwenty_prtwo = new product(10.80, "Theosophische Perspektiven Band 2", "3930623811", "20.php", 39);
pgtwenty_prthree = new product(10.80, "Theosophische Perspektiven Band 3", "393062382X", "20.php", 40);
pgtwenty_prfour = new product(10.80, "Theosophische Perspektiven Band 4", "3930623838", "20.php", 41);
pgtwenty_prfive = new product(10.80, "Theosophische Perspektiven Band 5", "3930623846", "20.php", 42);
pgtwenty_prsix = new product(10.80, "Theosophische Perspektiven Band 6", "3930623854", "20.php", 43);
pgtwenty_prseven = new product(10.80, "Theosophische Perspektiven Band 7", "3930623862", "20.php", 44);
pgtwenty_preight = new product(10.80, "Theosophische Perspektiven Band 8", "3930623870", "20.php", 45);
pgtwenty_prnine = new product(10.80, "Theosophische Perspektiven Band 9", "3930623889", "20.php", 46);
pgtwenty_prten = new product(10.80, "Theosophische Perspektiven Band 10", "3930623897", "20.php", 47);
pgtwenty_preleven = new product(52.00, "Theosophische Perspektiven - Komplett", "3930623900", "20.php", 48);

pgtwentyone_prone = new product(19.80, "Die Masken Odins", "3930623196", "21.php", 49);

pgtwentytwo_prone = new product(9.80, "Die Goetter Warten", "393062317X", "22.php", 50);

pgtwentythree_prone = new product(7.90, "Die Mysterien-Schulen", "393062379X", "23.php", 51);

postage = 5.0;

/* ----------------------------------------------------------------------------------------

	This function sets a cookie. When a customer buys a product, the quantity is stored in 
	a cookie represented by the products name. Each product bought has its own cookie.
	These are destoyed automatically when the customer leaves the site because they have
	no expiry date. There is nothing to stop you adding an expiry date to these cookies
	however. */

function setCookie(name, value) {
document.cookie = name + "=" + escape(value);
}


/* ------------------------------------------------------------------------------------

	This function gets a cookie that had previously been set with the function above.
   It accepts a parameter representing the name of a product, which you will recall
   is also the name of that products cookie. If it finds a cookie it returns the value
   representing the quantity of that product the customer has bought. */

function getCookie(name){
var Search = name + "=";
if (document.cookie.length > 0) {
	offset = document.cookie.indexOf(Search)
	if (offset != -1) {
		offset += Search.length;
		end = document.cookie.indexOf(";", offset);
		if (end == -1)
			end = document.cookie.length;
		return unescape(document.cookie.substring(offset, end));
		}
	}
}

/* -------------------------------------------------------------------------------------

	This function is called everytime you want to convert a number into a currency.
   For instance, if you send it 8.87634 it will return 8.88. If you send it 45.5 it
   will return 45.50. */

function roundToCents(n)
{
cents = n * 100;
cents = Math.round(cents);
strCents = "" + cents;
len = strCents.length;
	
first = strCents.substring(0, len - 2) + ".";
last = strCents.substring(len - 2, len);
	
	if (first == "."){
	   first = "0.";
  	}
	
	if (last.length == 1){
	   last += "0";
	}
	
return first+last;
}
