/*
   Author: Hari Khalsa
   Date: 09.26.02
   Description:
   Contains JavaScript functions for reading the cookie value to get the number of items in the bag,
   hand switches of item added status for bag and wish list.
   
   getBagCount()	  - Gets the value of the shopping bag item count from cookie.
   getWishCount()	  - Gets the value of the wish list count from the cookie.
   getBagStatus()	  - Gets the value of the bag status flag ( "S" || "W" ) from cookie.
   getCompBagCount()  - Gets the value of the bag count on the client-side cookie
   getCompWishCount() - Gets the valu of the wish list count on the client-side cookie.
   initCookie()		  - Checks for existance of values in estore cookie, 
   					    if values exist calls corresponding "get" functions above.
*/

//set global vars
var intBagCount = 0;
var intWishCount = 0;
var compBagCount = 0;
var compWishCount = 0;
var strBagStatus = "";

var strBagCountName = "BAG_COUNT";
var strWishCountName = "WISH_COUNT";
var strBagStatusName = "BAG_STATUS";
var strCompBagCountName = "COMP_BAG_NUM";
var strCompWishCountName = "COMP_WISH_NUM";

var cookieString = document.cookie;

var bagCountExists = cookieString.indexOf(strBagCountName);
var bagStatusExists = cookieString.indexOf(strBagStatusName);
var wishCountExists = cookieString.indexOf(strWishCountName);
var compBagCountExists = cookieString.indexOf(strCompBagCountName);
var compWishCountExists = cookieString.indexOf(strCompWishCountName);


function getBagCount(){
	var start = cookieString.indexOf(strBagCountName) + strBagCountName.length + 1;
	var end = cookieString.indexOf(";",start);
	if (end == -1){
		end = cookieString.length;
	}
	intBagCount = parseInt(cookieString.substring(start,end));
	//alert("cookie value of bag count is:" +  intBagCount );
}

function getWishCount(){
	var start = cookieString.indexOf(strWishCountName) + strWishCountName.length + 1;
	var end = cookieString.indexOf(";",start);
	if (end == -1){
		end = cookieString.length;
	}
	intWishCount = parseInt(cookieString.substring(start,end));
	//alert("cookie value of bag count is:" +  intBagCount );
}

function getBagStatus(){
	var start = cookieString.indexOf(strBagStatusName) + strBagStatusName.length + 1;
	var end = cookieString.indexOf(";",start);
	if (end == -1){
		end = cookieString.length;
	}
	strBagStatus = cookieString.substring(start,end);
	strBagStatus = strBagStatus.toString();
	//alert("cookie value of bag count is:" +  intBagCount );
}

function getCompBagCount(){
	var start = cookieString.indexOf(strCompBagCountName) + strCompBagCountName.length + 1;
	var end = cookieString.indexOf(";",start);
	if (end == -1){
		end = cookieString.length;
	}
	compBagCount = parseInt(cookieString.substring(start,end));
	//alert("cookie value of bag count is:" +  intBagCount );
}

function getCompWishCount(){
	var start = cookieString.indexOf(strCompWishCountName) + strCompWishCountName.length + 1;
	var end = cookieString.indexOf(";",start);
	if (end == -1){
		end = cookieString.length;
	}
	compWishCount = parseInt(cookieString.substring(start,end));
	//alert("cookie value of bag count is:" +  intBagCount );
}

function initCookie(){
	if(bagCountExists != -1){
		getBagCount();
	}
	if(bagStatusExists != -1){
		getBagStatus();
	}
	if(wishCountExists != -1){
		getWishCount();
	}
	if(compBagCountExists != -1){
		getCompBagCount();
	}
	if(compWishCountExists != -1){
		getCompWishCount();
	}
}
