/*
 * shoppingcart.js
 * This file contains all the routeens needed by the ShoppingCart application.
 * Load this with <SCRIPT type="text/javascript" SRC="shoppingcart.js"></SCRIPT>.
 */


// create the cookie
function createCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/" + ";domain=.borealimagery.com";
}

// read the cookie
function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

// erase the cookie
function eraseCookie(name) {
        createCookie(name,"",-1);

}

/* The setupshop function is to be added to the  body tag, using onload on the index page of the website
 * <body onload ="setupshop">
 * it creates a blank cookie named 'ShoppingCart' that will be used to store the selections in.
 */

function setupshop () {

//var allcookies = document.cookie;
//var pos = allcookies.indexOf("ShoppingCart=");
//if(pos = -1)
 //  {
//     createCookie('ShoppingCart','',1);
//    }
return null;

}

// Append the cookie with new selections, see if it's empty before appending.

function appendCookie (INV) {

var currentvalue = readCookie('ShoppingCart');
var appendValue = INV + '|' ;
var newvalue ;
var msg ="Place item in Cart?";


if(confirm(msg))
{
  if(!currentvalue ) {
	newvalue = appendValue ;
        createCookie('ShoppingCart',newvalue,1) ;
     }else
	{
         newvalue = currentvalue + appendValue ;
          createCookie('ShoppingCart',newvalue,1) ;
         }
}else { return null ; }
}


// empty the cookie
function emptyCookie()
{
eraseCookie('ShoppingCart') ;
createCookie('ShoppingCart','',1);

}












