//### Session-Cookie Component ###

SessionCookie = function() {
	
	UserID = 0, CountryID = 0, ShipToID = 0, BillToID = 0, SubMenuLevel = 0, 
		CurrentProductID = 0, ProductsOnPage = 0, CatID = 0, SubCatID = 0;
	JSessionID = "", CurrentManufacturer = "", ProductsSortBy = "";
	
	
	this.setSessionID = function(sid) {JSessionID = sid;}
	this.setUserID = function(uid) {UserID = uid;}
	this.setCountryID = function(cid) {CountryID = cid;}
	this.setShipToID = function(stid) {ShipToID = stid;}
	this.setBillToID = function(btid) {BillToID = btid;}
	this.setCatID_old = function(cid) {CatID = cid;}
	this.setCatID = function(cid) {CatID = cid;}
	this.setSubCatID = function(cid) {SubCatID = cid;}
	this.setSubMenuLevel = function(sml) {SubMenuLevel = sml;}
	this.setCurrentProductID = function(pid) {CurrentProductID = pid;}
	this.setProductsOnPage = function(pop) {ProductsOnPage = pop;}
	this.setCurrentManufacturer = function(s_man) {CurrentManufacturer = s_man;}
	this.setProductsSortBy = function(sort) {ProductsSortBy = sort;}
	
	
	this.getSessionID = function() {return JSessionID;}
	this.getUserID = function() {return UserID;}
	this.getCountryID = function() {return CountryID;}
	this.getShipToID = function() {return ShipToID;}
	this.getBillToID = function() {return BillToID;}
	this.getCatID_old = function() {return CatID;}
	this.getCatID = function() {return CatID;}
	this.getSubCatID = function() {return SubCatID;}
	this.getSubMenuLevel = function() {return SubMenuLevel;}
	this.getCurrentProductID = function() {return CurrentProductID;}
	this.getProductsOnPage = function() {return ProductsOnPage;}
	this.getCurrentManufacturer = function() {return CurrentManufacturer;}
	this.getProductsSortBy = function() {return ProductsSortBy;}
	
	
	this.saveCookie = function() {
		cookie_value =  "\"" +
			"SessionID=" + JSessionID + ", " +
			"UserID=" + UserID + ", " +
			"CountryID=" + CountryID + ", " +
			"ShipToID=" + ShipToID + ", " +
			"BillToID=" + BillToID + ", " +
			"CatID=" + CatID + ", " +
			"SubCatID=" + SubCatID + ", " +
			"SubMenuLevel=" + SubMenuLevel + ", " +
			"CurrentProductID=" + CurrentProductID + ", " +
			"ProductsOnPage=" + ProductsOnPage + ", " +
			"CurrentManufacturer=" + CurrentManufacturer + ", " +
			"ProductsSortBy=" + ProductsSortBy + "\"";
		
		exp_date = new Date();
		exp_date.setYear(exp_date.getFullYear() + 1);
		
		document.cookie = "session=" + cookie_value + "; expires=" + exp_date.toGMTString() + "; path=/";
	}
	
	
	this.loadCookie = function() {
		c_val = getCookieValue("session");
		if (c_val.substr(0, 1)=="\"" && c_val.substr(c_val.length-1, c_val.length)=="\"") c_val = c_val.substr(1, c_val.length-2);
		
		c_vars = c_val.split(", ");
		for (i=0; i<c_vars.length; i++) {
			if (c_vars[i].indexOf("=")>-1) {
				cur_var = c_vars[i].split("=");
				
				if (cur_var[0]=="SessionID") this.setSessionID(cur_var[1]);
				if (cur_var[0]=="UserID") this.setUserID(cur_var[1]);
				if (cur_var[0]=="CountryID") this.setCountryID(cur_var[1]);
				if (cur_var[0]=="ShipToID") this.setShipToID(cur_var[1]);
				if (cur_var[0]=="BillToID") this.setBillToID(cur_var[1]);
				if (cur_var[0]=="CatID") this.setCatID(cur_var[1]);
				if (cur_var[0]=="SubCatID") this.setSubCatID(cur_var[1]);
				if (cur_var[0]=="SubMenuLevel") this.setSubMenuLevel(cur_var[1]);
				if (cur_var[0]=="CurrentProductID") this.setCurrentProductID(cur_var[1]);
				if (cur_var[0]=="ProductsOnPage") this.setProductsOnPage(cur_var[1]);
				if (cur_var[0]=="CurrentManufacturer") this.setCurrentManufacturer(cur_var[1]);
				if (cur_var[0]=="ProductsSortBy") this.setProductsSortBy(cur_var[1]);
			}
		}
	}
	
	
	this.loadCookie();
	
}

SessionCookie = new SessionCookie();
//### Session-Cookie - END ###