/*
	Hear me, ye unfortunate soul that must this file comprehend!
	
	By default, Prototype.js catches and swallows ALL errors that occur in an Ajax callback.
	This horrible decision makes this ill-begotten monstrosity of a file that much more difficult to debug.
	To temporarily disable this behavior, uncomment the call to Ajax.Responders.register() below.
	I would advise against deploying this to production, as I shudder to think what would become of the
	house of cards that is this front-end code were all errors suddenly to come to light.
*/

//Ajax.Responders.register({
//	onException: function(request, error) {
//		console.error(error);
//	}
//});

	var getServerTime = function () {
		
		new Ajax.Request('/ajax/date.jsp', {
				asynchronous:false,
				parameters:'nC='+noCache(),
				onComplete: function(xhr){
					var firstNode = get_firstchild(xhr.responseXML.documentElement);
					var dt = getNodeValue(firstNode);
					getServerTime = function () { return dt };
				}
			}
		);
	};
	getServerTime();
	/*-------------------------------GLOBAL VARIABLES------------------------------------*/
	var cc = {US:'UA-2242866-1', CA:'UA-2242866-2'};
	//var bucketObj={};
	var cart;
	var cartLightBox;
	
	var topNavParams = {
		signin: 'showsignin',
		myaccount: 'gotomyaccount',
		wishlist: 'gotowishlist',
		catalog: 'showrequestcatalog'
	};
	
	/* start lightbox global variables */
	var detect = navigator.userAgent.toLowerCase();
	var OS,browser,version,total,thestring;
	/* end lightbox global variables */
	/*-----------------------------------------------------------------------------------*/
 	Event.observe(window,'load', 
		function() {
			if(document.domain.indexOf('.ca')>0) { //FOR USERS THAT Enter through .CA - get redirected to .COM - NALH
			    var nwDomain = document.domain.replace('.ca','.com');
			    document.location.href = document.location.href.replace(document.domain,nwDomain);
			}
			
			//this piece of code fixes the ie issue on checkout.html
			$$('.logo a').each(function(item){
			  item.href = 'http://' + document.location.host;
			  return false;
			});
			
			(window.attachEvent && navigator.appVersion.substr(22,3)=="6.0") ? sfIeHover() : sfHover();
			loadScript('/ipui/ip_demandlet.js',function(){demandletManager.load()});
			loadScript('/ipui/ip_notifier.js');
			cart = new cartManager; 
   			$$('.viewcart').each(function(item){
				cartLightBox = new lightbox(item,{oncomplete:function(){
					IPUI.listen('cart:item:removed', showCartLoyaltyMsg);
					IPUI.listen('cart:item:update', showCartLoyaltyMsg);
					showCartLoyaltyMsg();
					cart.show();
				}});
			});
			
			function showCartLoyaltyMsg(){
				var loggedInUser = new userManager();
				$('loyalty-member').hide();
				if(loggedInUser.check()) {					
					$$('#loyalty-member .returing-member')[0].hide();
					$$('#loyalty-member .non-member')[0].hide();
					$$('#loyalty-member .member')[0].hide();
					
					if(loggedInUser.isReturningLoyal()){
						$$('#loyalty-member .returing-member')[0].show();
						$('loyalty-member').show();
					} else if(loggedInUser.isLoyaltyMember()) {
						$$('#loyalty-member .member')[0].show();
						$('loyalty-member').show();
					} else if(loggedInUser.isAlmostLoyaltyMember()) {
						var leftToSpend = loggedInUser.getLeftToSpend();
						$('$left_to_spend').innerHTML = leftToSpend;
						$$('#loyalty-member .non-member')[0].show();
						$('loyalty-member').show();
					} else {
						$('loyalty-member').hide();
					}
				}
			}
			
			if(document.getElementById('ccMain')){$('ccMain').innerHTML=cart.count();};
			if ($('suggest_title'))	$('suggest_title').style.backgroundImage="url('/media/global/suggest-a-title-"+(Math.floor(Math.random()*3)+1)+".jpg')";
			$$('.rotate').each( //rotate class
						function(item){
							var rItems 	= $A(item.getElementsByTagName('div')).each(function(option){Element.hide(option);});
							var element	= rItems[(Math.floor(Math.random()*(rItems.length))+1)-1];
							if (typeof element == 'undefined') return;
							var imageHTML   = '<a href="' + element.getAttribute('link') + '"';
							if (element.getAttribute('newwindow'))
								imageHTML += ' target="_blank"';
							imageHTML += '"><img src="' +  element.getAttribute('background') + '"></a>';
							new Insertion.After(item, imageHTML);
						});
			changeCountryLinks($$('.helpusca'));
			if ($('footer')) { changeCountryLinks([$('footer')]); }
			addWishListLink();
			initiate_reqCatalog();
			initiate_rss();
			if ($('myaccount')) myAccountLink();
			//if (getCountry()== 'CA') $('accountbar').down(1).next('li', 1).hide();
			hideTracking();

			prepareSearch();
			
			// if a "source" attribute was defined in the URL, save it in a cookie
			var source = getURLParam('source');
			if (source && source.length) { createCookie('source', source); }
		}
	);
	
	/*-----------------------------------------------------------------------------------*
	 * RequestManager
	 *
	 *		This class exposes a single static method request() used by all demandlets to 
	 *		make Ajax calls.  request() takes a settings object with the following properties:
	 *		
	 *			url (required)
	 *				URL of the desired request
	 *			callback (required)
	 *				function to be invoked when a response is available (response is
	 *				provided as an argument)
	 *			method
	 *				HTTP method ('GET' or 'POST') of the desired request (default is 'GET')
	 *			params
	 *				object containing key-value pairs to be provided with request as 
	 *				query params (method = 'GET') or form field (method = 'POST')
	 *		
	 *		To prevent a resource from being fetched from the server more than once, it 
	 *		caches responses and queues identical requests when a response is pending.
	 *		
	 *		Instances of the Bucket class (eg: shopping cart) do not use RequestManager, 
	 *		as they specifically require fresh, uncached data.
 	 *-----------------------------------------------------------------------------------*/
			
	var RequestManager = (function() {
	
		/*--- initialize private data structures ----------------------------------------*/
	
		var responseCache = {};
		var callbackQueue = {};
		var pendingRequests = {};
	
	
		/*--- define RequestManager private methods -------------------------------------*/
	
		function validateRequest(options) {
			// set request's default properties and override with options provided
			var request = Object.extend({
				method: 'GET', 	// default HTTP method is 'GET'
				params: {}		// default params object is empty
			}, options || {});
	
			// validate existence and type of url and callback properties
			if (!request.url || typeof request.url != 'string') {
				throw 'RequestManager.request() expected an object with a "url" property of type string.';
			}		
			if (!request.callback || typeof request.callback != 'function') {
				throw 'RequestManager.request() expected an object with a "callback" property of type function.';
			}
			
			return request;
		}
		
		// generates a key that uniquely and consistently identifies a request based on its 
		// URL, HTTP method, and params (params are sorted alphabetically by key to ensure 
		// the same key is generated for requests providing the same params in a different order)
		function generateRequestKey(request) {
			// inner function to sort a hash's contents alphabetically by key
			function sortByKey(hash) {
				var keys = [], sorted = {};
				for (var key in hash) keys.push(key);
				keys.sort();
				for (var i = 0; i < keys.length; i++) {
					key = keys[i];
					sorted[key] = hash[key];
				}
				return sorted;
			}
			
			// sort request's params alphabetically by key
			var params = sortByKey(request.params);
	
			// convert params to a JSON-encoded string
			params = $H(params).toJSON();
	
			// return a key for this request
			return request.url + ' ' + request.method + ' ' + params;
		}
	
		function cacheResponse(key, response) {
			responseCache[key] = response;
		}
	
		function isResponseCached(key) {
			return typeof responseCache[key] != 'undefined';
		}	
	
		function getCachedResponse(key) {
			return responseCache[key];
		}
	
		function isPending(key) {
			// if key is defined in pendingRequests, the request is pending
			return typeof pendingRequests[key] != 'undefined';
		}
	
		function setPending(key, pending) {
			if (pending) {
				pendingRequests[key] = true;	// pending: add key to pendingRequests
			} else {
				delete pendingRequests.key;		// not pending: delete key from pendingRequests
			}
		}
	
		function addCallbackToQueue(key, callback) {
			if (!callbackQueue[key]) callbackQueue[key] = [];
			callbackQueue[key].push(callback);
		}
	
		function fireCallbacksInQueue(key, response) {
			if (callbackQueue[key]) {
				var queue = callbackQueue[key];
				for (var i = 0; i < queue.length; i++) {
					queue[i](response);
				}
			}
		}
	
		/*--- define RequestManager class -------------------------------------------------*/
		return {
			request: function(options) {
				// validate request's properties and set defaults
				var request = validateRequest(options);
				
				// generate a key to identify this request, as well as any subsequent 
				// requests that share the same URL, HTTP method, and params
				var key = generateRequestKey(request);
				
				if (isResponseCached(key)) {
					request.callback(getCachedResponse(key));
				} else if (isPending(key)) {
					addCallbackToQueue(key, request.callback);
				} else {
					setPending(key, true);
					addCallbackToQueue(key, request.callback);
					new Ajax.Request(request.url, {
						method: request.method,
						parameters: request.params,
						onComplete: function(response) {
							cacheResponse(key, response);
							setPending(key, false);
							fireCallbacksInQueue(key, response);
						}
					});
				}	
			}
		};
	
	})();



	/*-----------------------------------------------------------------------------------*
	 *	Persistent Storage Mechanism 													 *
	 *-----------------------------------------------------------------------------------*/
		
	var Bucket = Class.create();
	
	Bucket.prototype = {
	    initialize: function(cookieName, options) {
	    	this.cookieName = cookieName;
	    	this.options = options;
	    	this.bucketObj = {};
	
			if (readCookie(this.cookieName)) {
				this.read();
			} else {
				this.create();
			}
			
			if (this.options && this.options.onComplete) {
				this.options.onComplete(this);
			}
		 },
	
		 create: function() {
		 	var _this = this;
		 	var daysToStore = 7;
	 	
			new Ajax.Request('/bucket/create.jsp', {
				asynchronous: false,
				parameters: { nc: noCache() }, 
				onComplete: function(xhr){
					_this.bucketObj = eval('(' + xhr.responseText + ')');
					createCookie(_this.cookieName, _this.bucketObj.id, daysToStore);	
				}
			});			
		},
		
		read: function() {
			var _this = this;
			
			new Ajax.Request('/bucket/read.jsp', {
				method: 'get',
				asynchronous: false,
				parameters: {
					bucket: readCookie(this.cookieName),
			 		nc: noCache()
			 	},
				onComplete: function(xhr){
					_this.bucketObj = eval('(' + xhr.responseText + ')');
					if(document.getElementById('ccMain')){
						$('ccMain').innerHTML=cart.count();
					};
			     }
			});
			
			return this.bucketObj;			
		},
		
		put: function(name, value) {
			switch(typeof value) {
			  case 'undefined':
			  case 'function' :
			  case 'unknown'  : return false;
			  case 'boolean'  : 
			  case 'string'   : 
			  case 'number'   : value = value.toString();
			};			
	
			try {
				this.bucketObj.content[name] = value;
				this.update();
			} catch (err) {
				console.info(err);
			}
		},
		
		update: function(optionalParams) {
			var _this = this;
			new Ajax.Request('/bucket/update.jsp',{
				method: 'post',
				parameters: {
					bucket: this.bucketObj.id,
					content: Object.toJSON(this.bucketObj.content),
					nc: noCache()
				},
			    onComplete:function(xhr){
					_this.read();
			     }	
			});
		},
		
		remove: function(name){			
		    try {
		        delete this.bucketObj.content[name];
				this.update();			
			} catch (err) {
				return false;
			};   
		},
	
		empty: function() {
			var keys = this.getKeys();
			var size = keys.size();
			for (var i = 0; i < size; i++) {
				this.remove(keys[i]);
			}
		},
		
		get: function(name) {
			try{
				if (this.bucketObj.content[name]) {
					return this.bucketObj.content[name];
				} else {
					return null;
				}
			} catch(e) {
				BBCS.error.report("Page: " + location.href + " ---Error:" + e.message + " ---COOKIES: " + document.cookie);
				return null;
			}
		},
	
		getKeys: function() {
			var content = this.bucketObj.content;
			var keys = [];
			for (var value in content) {
			     keys.push(value);
			}
			return keys;
		},
	
		getPack: function() {
			var pack = {};
			var keys = this.getKeys();
			var size = keys.size();
			for (var i = 0; i < size; i++) {
				pack[keys[i]] = this.get(keys[i]);
			}
			return pack;
		}
	};

	// CookieJar Manager - ip_cookiejar.js 											 
	var CookieJar = Class.create();
	CookieJar.prototype = {
		initialize: function(name,options) {
			this.appendString=name+'_';
			this.options = {
				expires: dateAdd('d', 90, new Date() ),		
				path: '',			// cookie path
				domain: '',			// cookie domain
				secure: ''			// secure ?
			};
			Object.extend(this.options, options || {});
			if (this.options.expires != '') {
				var date = new Date();
				date = new Date(date.getTime() + (this.options.expires * 1000));
				this.options.expires = '; expires=' + date.toGMTString();
			}
			if (this.options.path != '')
				this.options.path = '; path=' + escape(this.options.path);
			if (this.options.domain != '')
				this.options.domain = '; domain=' + escape(this.options.domain);
			if (this.options.secure == 'secure')
				this.options.secure = '; secure';
			else
				this.options.secure = '';
		},
	
		put: function(name, value) {
			name 		= this.appendString + name;
			cookie 		= this.options;
			var type 	= typeof value;
			switch(type) {
			  case 'undefined':
			  case 'function' :
			  case 'unknown'  : return false;
			  case 'boolean'  : 
			  case 'string'   : 
			  case 'number'   : value = String(value.toString());
			}
			var cookie_str = name + "=" + escape(Object.toJSON(value));
			try {
				document.cookie = cookie_str + cookie.expires + cookie.path + cookie.domain + cookie.secure;
			} 
			catch (e) {
				return false;
			}
			return true;
		},
	
		remove: function(name) {
			name = this.appendString + name;
			cookie = this.options;
			try {
				var date = new Date();
				date.setTime(date.getTime() - (3600 * 1000));
				var expires = '; expires=' + date.toGMTString();
				document.cookie = name + "=" + expires + cookie.path + cookie.domain + cookie.secure;
			} 
			catch (e) {
				return false;
			}
			return true;
		},
	
		get: function(name) {
			name = this.appendString + name;
			var cookies = document.cookie.match(name + '=(.*?)(;|$)');
			if (cookies)
				return (unescape(cookies[1])).evalJSON();
			else
				return null;
		},
	
		empty: function() {
			keys = this.getKeys();
			size = keys.size();
			for(i=0; i<size; i++)
				this.remove(keys[i]);
		},
	
		getPack: function() {
			pack = {};
			keys = this.getKeys();
			size = keys.size();
			for(i=0; i<size; i++)
				pack[keys[i]] = this.get(keys[i]);
			return pack;
		},
	
		getKeys: function() {
			keys = $A();
			keyRe= /[^=; ]+(?=\=)/g;
			str  = document.cookie;
			CJRe = new RegExp("^" + this.appendString);
			while((match = keyRe.exec(str)) != undefined) {
				if (CJRe.test(match[0].strip()))
					keys.push(match[0].strip().gsub("^" + this.appendString,""));
			}
			return keys;
		}
	};

	function evalWhere(query,dataObj) {
		try {
			var response=false;var reason='No Error';var error=false;
			if(query.indexOf('!=')>-1)
				whereArray=query.split('!='),operator='!=';
			else if(query.indexOf('=')>-1)
				whereArray=query.split('='),operator='==';
			else if(query.indexOf('>')>-1)
				whereArray=query.split('>'),operator='>';
			else if(query.indexOf('<')>-1)
				whereArray=query.split('<'),operator='<';
			else if(query.indexOf(' is ')>-1)
				whereArray=query.split(' is '),operator='is';
			if(isArray(whereArray)) {
				(isString(whereArray[1].replace(/\'/g,''))) ? than=whereArray[1] : than=parseFloat(whereArray[1].replace(/\'/g,''));
				var condition = {member:whereArray[0], is:operator, than:than};
				if(condition.is=='is' && condition.than=='null') {
					((condition.member in dataObj)==false) ? response=true : response=false;
				}
				else if(condition.member in dataObj) {
               		(eval('dataObj[\'' + condition.member + '\']' + condition.is + condition.than)==true) ? response=true : response=false;
				}
				else {
					(condition.is == '!=') ? response=true : response=false;
					error=true;reason='No data member (' + condition.member + ') found. Query (' + query + ')';
				}
			}
			else {
				error=true;reason='Incorrect query (' + query + ')';
			}
			return {result:response,reason:reason,error:error};		
		}
		catch(err) {
			return {result:false,reason:err,error:true};			
		}	
	};	

	// Painter() Class  - ip_painter.js
	var painter = Class.create();
	painter.prototype = {
		initialize: function(params) {
			this.keeper = new CookieJar('keeper',{  
			    expires:dateAdd('d', 90, new Date() ),     
			    path:'/'
			}); 
			this.params = {};
			Object.extend(this.params, params || {});
		},
	
		repeat: function(targetElement, dataObj, optionalParams) {
			try {
				options = {};Object.extend(options, optionalParams || {});
				var itemId;
				(targetElement.getAttribute('id')) ? itemId=targetElement.attributes['id'].value : itemId = '_' + uniqueId();
				if(targetElement.getAttribute('where')) options.where=targetElement.attributes['where'].value;
				targetElement.setAttribute('id',itemId);
				Element.hide(targetElement);	
				if(!document.getElementById(targetElement.id + '_content'))
					new Insertion.After(targetElement,'<div id="' + targetElement.id + '_content"></div>');
				if(!options.clear)
			  		$(targetElement.id + '_content').innerHTML='';
				var LayoutTemplate 	= SearchAndReplace(SearchAndReplace(SearchAndReplace(SearchAndReplace($(targetElement.id).innerHTML,'&gt;','>'),'&lt;','<'),'%3E','>'),'%3C','<');
				var LayoutRslt		= '';
				for (var member in dataObj) {
					if(options.where)
						(evalWhere(options.where,dataObj[member]).result==true) ? show=true: show=false;
					else 
						show=true;
					if(show==true) {
						if(typeof(dataObj[member])=='string' || typeof(dataObj[member])=='number') {
							if(LayoutRslt.length<1) LayoutRslt = LayoutTemplate;
							var dataNode 		= '<data:' + member + '></data:' + member + '>';
							var propertyVlue 	= dataObj[member];
							if(LayoutTemplate.toLowerCase().indexOf(dataNode.toLowerCase())>0)
								LayoutRslt = SearchAndReplace(LayoutRslt, dataNode, propertyVlue);
						}
						else if(typeof(dataObj[member])=='object') {
							LayoutRslt = LayoutTemplate;
							for(var property in dataObj[member]) {
									var dataNode 		= '<data:' + property + '></data:' + property + '>';
									var propertyVlue 	= dataObj[member][property];
									if(LayoutTemplate.toLowerCase().indexOf(dataNode.toLowerCase())>0)
										LayoutRslt = SearchAndReplace(LayoutRslt, dataNode, propertyVlue);
							}
							this.renderRepeat($(targetElement.id+'_content'),LayoutRslt,options.insert);
							LayoutRslt = '';
						}
					}
				}
				if(LayoutRslt!='') this.renderRepeat($(targetElement.id+'_content'),LayoutRslt,options.insert);
				this.fixImgOnIE($(targetElement.id + '_content'));
				this.textarea_setMaxLength($(targetElement.id + '_content'));
				if(options.onComplete) eval(options.onComplete); 
				return true;
			}
			catch(err) {
				return false;	
			}
		},
		
		loadLayout: function(url,options) {
			var _this = this;
			this.options = {};Object.extend(this.options, options || {});
			if (!this.options.target) this.options.target = 'return';
			
			new Ajax.Request(url, { 
					parameters: this.options.params, 
					onComplete: this.loadLayout_complete.bindAsEventListener(this,{target:this.options.target,callback:this.options.onComplete})
				});	
		},

		renderRepeat: function(templateObj, newContent, insert) {
			if(insert) {
				var origHTML = templateObj.innerHTML;
				switch(insert) {
				  	case 'before': 
				  		templateObj.innerHTML = newContent + origHTML;
						break;
				  	case 'after': 
				  		templateObj.innerHTML += newContent;
						break;
				  	default: 
						templateObj.innerHTML += newContent;
				}
			}
			else
				templateObj.innerHTML += newContent;
		},
				
		loadLayout_complete: function(response,optionalParams) {
			var options = {};Object.extend(options, optionalParams || {});
			if(options.target!='return') {
				$(options.target).innerHTML = response.responseText;
				if(options.callback) eval(options.callback);
			} 
			else 
				if(options.callback) eval(options.callback); 
		},
		
		xml2json: function(xml,options) {
			var x 	= xml.responseXML.getElementsByTagName(get_firstchild(xml.responseXML.documentElement).nodeName);
			this.options = {};Object.extend(this.options, options || {});
			if(!this.options.start) this.options.start = 0;
			if(!this.options.end) this.options.end
			var jsonEntry = new Object();
			for (var i=this.options.start; i<x.length; i++) {  
				for(var j=0;j<x[i].childNodes.length;j++) {
					jsonEntry[getNodeAttribute(x[i].childNodes[j],'name')] =  getPropertyNodeByName(x[i],getNodeAttribute(x[i].childNodes[j],'name'));
				}	
				this.keeper.put(getPropertyNodeByName(x[i],getNodeAttribute(x[i],'pk')),jsonEntry);
			}
			return this.keeper.getPack();
		},
		
		fixImgOnIE: function(elem) {
			$A($(elem).getElementsByTagName('img')).each(function(image) {
				if (image.src) {
					var pieces = image.src.split('://');
					if (pieces.length > 1) {
						var subpieces = pieces[1].split('//');
						if (subpieces.length > 1) {
							var newSrc = '';
							for (var i = 1; i < subpieces.length; i++) {
								newSrc += '/' + subpieces[i];
							}
							image.src = newSrc;
						}
					}
				}
			});
		},
		
		textarea_setMaxLength: function(elem) {
			var counter 		= document.createElement('div');
			counter.className 	= 'counter';
			$A($(elem).getElementsByTagName('textarea')).each(function(item) {textarea_maxlength(item,counter);});
		}	
	};
	
	// cartManager() Class - ip_cart.js													
	var cartManager = Class.create();
	cartManager.prototype = {
		initialize: function(options) {
			this.bucketId = setBucketId('shoppingCart');
			this.bucket = new Bucket(this.bucketId);
			this.trolley = new CookieJar('_basket_',{  
			    expires:dateAdd('d', 90, new Date() ),     
			    path:'/'
			}); 
			this.truck = new CookieJar('shipping',{  
			    expires:dateAdd('d', 90, new Date() ),     
			    path:'/'
			}); 
			this.elementArray 	= {};				//dynamic form elements hashtable 
			this.ready			= true;				//class state - used to decide action for checkout/update
			this.targetRepeater = 'repeater';		//specified repeater object to render - TO DO - pass in as option or use selector...			
			this.shippingLoaded	= false;
			this.shippingXML	= '';
			this.loadShipping();
			if(getCountry()=='US')
				this.shippingMethod	= {name:'U.S Mail',code:'1'}; //default US
			else if(getCountry()=='CA')
				this.shippingMethod = {name:'Standard Mail',code:'4'}; //default CA
			else
				this.shippingMethod	= {name:'U.S Mail',code:'1'}; //default US if no country returned
		},
		
		check: function(id) {
			if(this.bucket.get(id))
				return true;
			else	
				return false;
		},
		/**
		 * The flash module tries to format the product xml in a wierd way and some inconsitencies happen during the process.
		 * This function will try to fix those inconsitencies.
		 */
		_fixProductFromFalsh: function(id, object) {
			//add product number same as the id
			object['product_number'] = id;
			
			//convert the product_availability_date from string to date object.
			if((typeof object['product_availability_date']).toLowerCase() == 'string')
				object['product_availability_date'] =  new Date(object['product_availability_date']);
			
			
			//remove any key from object that contains '$p' as value
			for(var p in object) {
			  if((typeof object[p]).toLowerCase() == 'string' && object[p].indexOf('$p') > -1)
				delete object[p];
			}
			
			//delete product_id key/value. doesn't seem to be needed by the cart.add function
			delete object['product_id'];
			
		},
		
		add: function(id,object) {
      if(object['product_id'])
        BBCS.cart.add_product(object['product_id'], (object['product_facet'] || null));
      else if (object['product_number'])
        BBCS.cart.add_product_by_item(object['product_number'], (object['product_facet'] || null));
      else
        BBCS.error.report('ipui-packer.js, line: 762; page: ' + location.href + '; id:' + id + '; object:' + jQuery.param(object));
      return;
			//if(!object['product_price'] || !(parseFloat(object['product_price']) > 0)) return false;
			
			//flash module seems to be consisten and passing 'product_shipping' value as '$pshipping'.
			//This will be used as the flag that the product is comming from the flash module.
			if(object['product_shipping'] && object['product_shipping'].indexOf('$p') > -1)
				this._fixProductFromFalsh(id, object);
			
			this.object = {};
				Object.extend(this.object, object || {});
				
			if (getCountry() ==  'ca') {
				var phoneNum = '1-800-435-5685';
			}
			else {
				var phoneNum  = '1-800-898-4921';
			}						
			if (this.count() >= 500) {
				alert('Your shopping cart is now full! We ' +
				'cannot accept more items to your cart. If you would like to order additional products, you can place your ' +
				'full order by phone (' +
				phoneNum +'). We\'re sorry for this inconvenience.');	
				return true;
			}
			else {		
				try {
				
					if (this.check(id)) {
						var item = this.getItemByID(id);
						this.object.quantity = parseInt(item.quantity) + 1;
					}
					else {
						this.object.quantity = 1;
					}
					this.object.product_id = id;
					if (this.set(id, this.object)) {
						if (document.getElementById('ccMain')) 
							$('ccMain').innerHTML = this.count();
						if (!this.object.hideCart) 
							cartLightBox.activate(); // proper way to show lightbox on IE6. -clam
					}
				} 
				catch (err) {
					return false;
				};
			};			
		},
		
		add_mybuys:function(product_id, callback) {
      if(product_id)
        BBCS.cart.add_product(product_id);
      else
        BBCS.error.report('ipui-packer.js, around line: 815; page: ' + location.href + '; product_id:' + product_id);
      
      return;
			var that = this;
			loadScript('/ipui/product-utils.js', function(){
				ProductUtils.getProductById(product_id, function(product){
					if(product && product.item_number) {
						if(!product.name) product.name = product.title;
						
						var cart_product = ProductUtils.createCartProduct(product);
						cart_product.product_image = product.thumbnail_image;
						
						var country = (getCountry().toLowerCase() == 'us' ? 'us' : 'canada');
						
						
						
						
						if (parseInt(product['drop_ship_'+country]) > 0) {
							cart_product.product_ship_cost = product['drop_ship_'+country];
							cart_product.product_shipping = 'dropship';
						}
						if (/magazine/i.test(product.type)) cart_product.product_shipping = 'subscription';
						
						if (/back/i.test(product.availTxt)) cart_product.product_availability_date = product['back_order_date_'+country]; 
						else cart_product.product_availability_date = product['availability_date_'+country];
						
						cart_product.product_availability_date = new Date(cart_product.product_availability_date);
						that.add(cart_product.product_number, cart_product);
					}
				});
			}); 
		},
	
		remove: function(id,all) {
			if(!all) all=false;
			if(all==true)
				this.bucket.remove(id);
			else {
				if(this.check(id)==true) {
					var item = this.getItemByID(id);
					item.quantity = parseInt(item.quantity)-1;
					if(item.quantity<1)
						this.bucket.remove(id);
					else 
						this.set(id,item);
					
				}
			}
		},

		updateQuantity: function(id,quantity) {
			try	{
				if(this.check(id)==true) {
					var object = this.getItemByID(id);
					object.quantity = quantity;
					this.set(id,object);
					IPUI.notify('cart:item:update');
					return true;
				}	
			}
			catch(err){		
				return false;
			}
		},
		
		set: function(id,object) {
			try {
				this.object = {};
				Object.extend(this.object, object || {});
				if(this.object.quantity<1) {
					this.remove(id,true);
					return true;
				}
				else {
					this.bucket.put(id, this.object);
					return true;
				}
			}
			catch(err) {
				return false;
			}
		},
	
		empty: function() {
			try {
				this.bucket.empty();
				return true;
			}
			catch(err) {
				return false;
			}
		},
		
		count: function(id) {
			if(id) {
				if(this.check(id)==true) 
					return this.bucket.get(id).quantity;
				else
					return 0;
			}
			else {
				var itemCount	= 0;
				var dataObject 	= this.getContentObj();				
				for (var member in dataObject)
					itemCount += parseInt(dataObject[member].quantity);
				return itemCount;
			}
		},
		
		getItems: function() {
			return this.bucket.getKeys();
		},
		getContentObj: function() {
			return this.bucket.getPack()
		},
		
		getItemByID: function(id) {
			return this.bucket.get(id);
		},

		getSubTotal: function(optionalParams) {
			var options = {};Object.extend(options, optionalParams || {});
			var price = 0; var cart = this;
			$A(this.getItems()).each(function(re) {
					var item = cart.getItemByID(re);
					if(options.where) {
						if(evalWhere(options.where,item).result==true) 
							price = price + (item.quantity * item.product_price)-0;
					}
					else 		
						price = price + (item.quantity * item.product_price)-0;
				});
			return (Math.round(price*100)/100);
		},

		getDropshipTotal: function(optionalParams){
			var options = {};Object.extend(options, optionalParams || {});
			var total = 0; var cart = this;
			$A(this.getItems()).each(function(re) {
					var item = cart.getItemByID(re);
					if(options.where) {
						if(evalWhere(options.where,item).result==true) {
							total = total + (item.quantity * item.product_ship_cost)-0;
						}
					}
					else {				
						total = total + (item.quantity * item.product_ship_cost)-0;
					}
				});
			return (Math.round(total*100)/100);
		},
							
		setState: function(state) {
			this.ready 	= state;
			var mode	= '';
			var itemObj	= '';
			if(document.getElementById('checkout')) {
				itemObj 	= $('checkout');
				mode	= 'checkout';
			}
			if(document.getElementById('continue')) {
				itemObj 	= $('continue');
				mode	= 'continue';
			}
			if(document.getElementById('review')) {
				itemObj 	= $('review');
				mode	= 'review';
			}

			if(this.ready==false) {
				if(mode=='continue') {
					itemObj.addClassName('btn-update-large');
					itemObj.removeClassName('btn-continue-large');
				}
				else if(mode=='checkout') {
					itemObj.addClassName('btn-update-large');
					itemObj.removeClassName('btn-checkout-large');
				}
				else if(mode=='review') {
					itemObj.addClassName('btn-update-large');
					itemObj.removeClassName('btn-review-large');
				}
			}
			else {
				if(mode=='continue') {
					itemObj.addClassName('btn-continue-large');
					itemObj.removeClassName('btn-update-large');
				}
				else if(mode=='checkout') {
					itemObj.addClassName('btn-checkout-large');
					itemObj.removeClassName('btn-update-large');
				}
				else if(mode=='review') {
					itemObj.addClassName('large-btn-review');
					itemObj.removeClassName('btn-update-large');
				}
			}
		},
		
		calculateGiftWrapping: function() {
			try {
				var itemsInCart = this.getContentObj();
				var giftTotal	= 0;
				var giftRate	= 4;
				if(orderObject) {
					for(var item in itemsInCart) {
						if('product_id' in itemsInCart[item]) {
							var product_id = itemsInCart[item].product_id;
							if('giftwrap-'+product_id in orderObject) {
								if(orderObject['giftwrap-'+product_id])
									giftTotal += parseFloat(itemsInCart[item].quantity*giftRate);
							}
						}
					}
				}
			}
			catch(err){}			
			finally {
				return giftTotal;
			}
		},
		
		calculateDetails: function(optionalParams) {
			try {
				var options = {};Object.extend(options, optionalParams || {});
				var gift 					= new giftManager();
				var giftTotal				= parseFloat(gift.getTotal());
				var cartTotal 				= parseFloat(this.getSubTotal()); 
				var cartTotal_standard  	= parseFloat(this.getSubTotal({where:'product_shipping is null'})); 
				var cartTotal_dropship		= parseFloat(this.getDropshipTotal({where:'product_shipping=\'dropship\''}));
				var cartTotal_digital		= parseFloat(this.getSubTotal({where:'product_shipping=\'digital\''}));
				var cartTotal_subscription 	= parseFloat(this.getSubTotal({where:'product_shipping=\'subscription\''}));
				var cartTotal_promoApplcble	= cartTotal-cartTotal_digital-0;
				(options.shippingMethod) ? shippingMethod = options.shippingMethod : shippingMethod = '';
				var shippingCost	= 0;
				var shippingName	= '';
				var shippingDesc	= '';
				var shippingObj		= '';
				var promoRslt 		= this.calculatePromotion(cartTotal_promoApplcble);
				var freeShipping;
				(promoRslt.amount=='freestandardshipping') ? freeShipping=true : freeShipping=false;	
				try { //see if the user has selected a shipping method
					if(orderObject) {
						if('shippingAddress' in orderObject)
							shippingMethod = orderObject['shippingAddress'].shippingMethod;
					}
				}
				catch(err){}
				var user = new userManager();
				if(cartTotal>=100 || user.isLoyaltyMember()) { //Cart total is 100 or over
					shippingObj	 	= this.getShippingRate({price:cartTotal,code:shippingMethod,freestandard:freeShipping});
					shippingCost 	= shippingObj.price;
					shippingName	= shippingObj.name;
					shippingDesc	= shippingObj.description;
				}
				else {
					if(cartTotal_standard==0) {
						shippingObj 	= this.getShippingRate({price:cartTotal_standard,code:shippingMethod,freestandard:true});
						shippingCost 	= shippingObj.price;
						shippingName	= shippingObj.name;
						shippingDesc	= shippingObj.description;
					}
					else {
						shippingObj 	= this.getShippingRate({price:cartTotal_standard,code:shippingMethod,freestandard:freeShipping});
						shippingCost 	= shippingObj.price;
						shippingName	= shippingObj.name;
						shippingDesc	= shippingObj.description;
					}
				} 
				var grandTotal			= 0;
				var giftWrappingTotal 	= this.calculateGiftWrapping();
				if(promoRslt.amount=='freestandardshipping') {
					grandTotal 			= cartTotal;
					promoRslt.amount	= 0;
				}
				else if(promoRslt.amount>0)
					grandTotal = (Math.round(parseFloat(cartTotal-promoRslt.amount)*100)/100);
				else 
					grandTotal = cartTotal;
				grandTotal = grandTotal + shippingCost;
				if(giftWrappingTotal>0) grandTotal = grandTotal + giftWrappingTotal;
				if(cartTotal_dropship>0) grandTotal = grandTotal + cartTotal_dropship;
				var grandTotal_all = (Math.round(parseFloat(grandTotal)*100)/100);
				if(giftTotal>=grandTotal) {
					giftTotal = grandTotal;
					grandTotal=0;
				}
				else 
					grandTotal = (Math.round(parseFloat(grandTotal - giftTotal)*100)/100);		
				var ccTotal = parseFloat(cartTotal + shippingCost - giftTotal - promoRslt.amount);
				if(options.padding) {
					if(options.padding=='false') {
						return  {
							cartTotal: cartTotal,
							cartTotal_standard: cartTotal_standard,
							cartTotal_dropship: cartTotal_dropship,
							cartTotal_promoApplcble: cartTotal_promoApplcble,
							shippingCost: shippingCost,
							shippingName: shippingName,
							shippingDesc: shippingDesc,
							giftTotal: giftTotal,
							promoTotal: promoRslt.amount,
							grandTotal: grandTotal,
							promoTitle: promoRslt.title,
							giftWrappingTotal: giftWrappingTotal,
							ccTotal: ccTotal,
							freestandard: freeShipping,
							grandTotal_all: grandTotal_all
						};	
					}
				}
				else {
					return  {
						cartTotal: cartTotal.toFixed(2),
						cartTotal_standard: cartTotal_standard.toFixed(2),
						cartTotal_dropship: cartTotal_dropship.toFixed(2),
						cartTotal_promoApplcble: cartTotal_promoApplcble.toFixed(2),
						shippingCost: shippingCost.toFixed(2),
						shippingName: shippingName,
						shippingDesc: shippingDesc,
						giftTotal: giftTotal.toFixed(2),
						promoTotal: promoRslt.amount.toFixed(2),
						grandTotal: grandTotal.toFixed(2),
						promoTitle: promoRslt.title,
						giftWrappingTotal: giftWrappingTotal.toFixed(2),
						ccTotal: ccTotal.toFixed(2),
						freestandard: freeShipping,
						grandTotal_all: grandTotal_all.toFixed(2)
					};	
				}
			}
			catch(err){}
		}, 

		show: function(targetObj) {
			if(!targetObj) targetObj=$(this.targetRepeater);
			var display	= new painter();
			display.repeat(targetObj, this.getContentObj(), {insert:'after'});
			if (this.getSubTotal()>0) {
				if (this.shippingLoaded != true) {
					this.loadShipping({onComplete:'cart.show_complete()'});
				} else {
					this.show_complete();
				}
			} else {
				if(document.getElementById('continue'))  {
					Element.hide('continue');
				}
				this.show_complete();
			}
		},
							
		show_complete: function() {
			try {
				var display 	= new painter();
				var details 	= this.calculateDetails();
				var detailsInt 	= this.calculateDetails({padding:'false'});
				if(document.getElementById('cartTotal')) $('cartTotal').innerHTML 			= '$' + details.cartTotal;
				(detailsInt.shippingCost==0 || details.freeShipping==true) ? shippingText 	= 'Free' : shippingText = '$' + details.shippingCost;
				if(document.getElementById('shippingTotal')) $('shippingTotal').innerHTML 	= shippingText;
				if(document.getElementById('totalPrice')) $('totalPrice').innerHTML			= '$' + details.grandTotal;
				if(document.getElementById('cartitems')) $('cartitems').innerHTML 			= this.count() + ' Item(s)';
				
				if(detailsInt.giftTotal>0) {
					if(document.getElementById('giftCertificate')) {
						Element.show('giftCertificate');
						$('giftcertificateTotal').innerHTML = '$-' + details.giftTotal;
					}
				}
				else if(document.getElementById('giftCertificate'))
					Element.hide('giftCertificate');

				if(detailsInt.promoTitle!='') {
					if(document.getElementById('promotion')){
						Element.show('promotion');
						if(document.getElementById('promotionDescription')) {
							$('promotionDescription').innerHTML = details.promoTitle;
						}
						if(document.getElementById('promotionTotal')) {
							if(details.promoTotal != 0)  {
								Element.show('promotionTotal');
								$('promotionTotal').innerHTML = '-$' + details.promoTotal;	
							}
							else
								Element.hide('promotionTotal');
						}
					}
					else if(document.getElementById('promotion')){
						Element.hide('promotion');
					}
				}
				else {
					if(document.getElementById('promotion')) Element.hide('promotion');
				}
				if(document.getElementById('giftwrapTotal')) {
					if(details.giftWrappingTotal=='') 
						$('giftwrapTotal').innerHTML = '$0';
					else
						$('giftwrapTotal').innerHTML = '$' + details.giftWrappingTotal;
				}
				if(document.getElementById('dropshipInfo')) {
					var dropShipObject 	= {};
					var cartContents   	= cart.getContentObj();
					var dsCount			= 0;	
					for(var member in cartContents) {
						var cartItem = cart.getItemByID(member);
						if('product_shipping' in cartItem) {
							if(cartItem.product_shipping=='dropship') {
								dsCount++;
								dropShipObject[member] = cartItem;
								dropShipObject[member].dropShipTotal = (Math.round(parseFloat(cartItem.quantity*cartItem.product_ship_cost)*100)/100).toFixed(2);
							}
						}
					}
					if(dsCount>0) {
						display.repeat($('dropshipInfo'), dropShipObject, {insert:'after'});
					}
					else
						Element.hide('dropshipInfo');
				}
			}
			catch(err){}
		},
		
		calculatePromotion: function(cartTotal,shippingTotal) {
			
			
			function cartHasEligibleProduct(promo){
				var match = promo.combine;
				var products = promo.products;
				
			 	var inCart = cart.getContentObj();
			 	var matchedProduct_length = 0;
			 	var promoProduct_length = 0;
			 	for(product in products){
			 		for(var item in inCart) {
						if(inCart[item].product_number==products[product]) {
							if(match == 'any'){
								return true;
							}else{
								matchedProduct_length++;
							}
						}
					}
					promoProduct_length++;
				}
				if((promoProduct_length == matchedProduct_length) && (match == 'all')){
					return true;
				}  
				
				return false;
			}
			try {
			
				var promo 		= new promoManager();
				var promoCodes	= promo.getContentObj();
				var promoAmount	= 0;
				var newTotal	= 0;
				var promoTitle 	= '';
				var response	= '';
				var errFlag		= false;
				for(var member in promoCodes) {
					var promoObj 	= promoCodes[member];
					promoTitle	 	= promoObj.description;
	                if((isDate(promoObj.valid_from) && (dateDiff('n',promoObj.valid_from,getServerTime())>0)) || (isDate(promoObj.valid_from)==false)   ) { //started?                                 
	                	if((isDate(promoObj.valid_until) && (dateDiff('n',promoObj.valid_until,getServerTime())<1) || (isDate(promoObj.valid_until)==false)) ) {//expired?                                                                   
							if(promoObj.country==getCountry()) {//valid country                                        
	                            if((promoObj.min_purchase<cartTotal || promoObj.min_purchase=='' )){
	                            		if(promoObj.type=='discount'){                    
	                                        if(promoObj.unit=='percent') {
												if(promoObj.apply_to=='product'){
													var discountTotal = this.calculateProductDiscount(promoObj);
													if(discountTotal==0) {
														errFlag = true;
														promo.empty();
														response = {error:'true',message:'Promotion doesn\'t apply to the items in your cart.',amount:0};
													}
													else {
														newTotal 	= cartTotal - parseFloat(discountTotal);
														promotTitle = promoObj.description;
														promoAmount	= discountTotal;
													}
												}
												else if(promoObj.apply_to=='subtotal'){
	                                            	newTotal 	= cartTotal - parseFloat((cartTotal/100)*promoObj.amount);
													promoTitle 	= promoObj.description;
													promoAmount	= (Math.round(parseFloat((cartTotal/100)*promoObj.amount)*100)/100);
	                                      		}
												break;
										    }
	                                        else {
												if(promoObj.apply_to=='product'){
													var discountTotal = this.calculateProductDiscount(promoObj);
													if(discountTotal==0) {
														errFlag = true;
														promo.empty();
														response = {error:'true',message:'Promotion doesn\'t apply to the items in your cart.',amount:0};
													}
													else {
														newTotal 	= cartTotal - parseFloat(discountTotal);
														promotTitle = promoObj.description;
														promoAmount	= discountTotal;
													}
												}
												else if(promoObj.apply_to=='subtotal'){
		                                        	newTotal 	= (cartTotal - parseFloat(promoObj.amount));
													promoTitle 	= promoObj.description;
													promoAmount	= parseFloat(promoObj.amount);
												}
												break;
		                                    }
	                                 	}
	                                    else if(promoObj.type=='free'){
	                                    	newTotal 	= cartTotal;
											promoTitle 	= promoObj.description;
											promoAmount	= 'freestandardshipping';
											break;
	                                    }else if(promoObj.type=='free-gift'){
	                                    	if(cartHasEligibleProduct(promoObj)){
            									newTotal 	= cartTotal;
		                                    	promoTitle 	= promoObj.description;
												promoAmount	= 0;
												break;	
            								}else{
            									errFlag = true;
												promo.empty();
												response = {error:'true',message:'Promotion doesn\'t apply to the items in your cart.',amount:0};
												break;
            								}                      		
	                                    }
	                                    
	                                    
	                                    
	                         	}
								else {
									errFlag = true;
									promo.empty();
									response = {error:'true',message:'The promotion code you entered only applies to orders over '+promoObj.min_purchase,amount:0};
									break;
								}//end min purchase
							}
							else {
								errFlag = true;
								promo.empty();
								response = {error:'true',message:'The promotion code you entered only applies in ' + getCountry() + '.',amount:0};
								break;
							}//end country
						}
						else {
							errFlag = true;
							promo.empty();
							response = {error:'true',message:'The promotion code you entered is no longer valid',amount:0};
							break;
						}//until date
					}
					else {
						errFlag = true;
						promo.empty();
						response = {error:'true',message:'The promotion code you entered is only valid after ' + promoObj.valid_from + '.',amount:0};
						break;
					}//start date
				}//end loop
				if(errFlag==false)
					return {result:newTotal,title:promoTitle,amount:promoAmount};
				else 
					return response;
			}
			catch(err){}
		},

		calculateProductDiscount: function(promoObj){
				var discountTotal			= 0;
				var promoProduct_length 	= 0;
				var matchedProduct_length 	= 0;
				var promoProduct_total		= 0;	
				var inCart = this.getContentObj();
				for(product in promoObj.products){
					for(var item in inCart) {
						if(inCart[item].product_number==promoObj.products[product]) {
							matchedProduct_length++;
							promoProduct_total += inCart[item].product_price-0;
						}
					}
					promoProduct_length++;
				}	
				if(promoObj.combine=='any' || (promoObj.combine !='any' && (matchedProduct_length==promoProduct_length)) ) {					
					if(promoObj.unit=='percent') 
						discountTotal += ((promoProduct_total/100) * promoObj.amount);
					else if(promoObj.unit=='dollar')
						discountTotal += (promoObj.amount);
					return Math.round(discountTotal*100)/100;
				}
				else
					return 0;
		},

		edit: function(element) {
			this.elementArray[element.id]='clicked';
			this.setState(false);
		},
		
		update: function() {
			for (var member in this.elementArray) {
				if(this.elementArray[member]!=null) {
				 	if(checkFormElement($(member))) {
						var elValue  = $F(member);
						if(member.indexOf('quantity_')>-1) {
							var product_id = member.replace('quantity_','');
							this.updateQuantity(product_id,elValue);
							this.elementArray[member] = null;
							this.setState(true);
							this.show();
						}
						else if(member=='giftcert'){
							if(elValue!='') {
								this.showNotifier('Checking Gift Certificate, please wait...');
								var gift = new giftManager();
								var storeID = (getCountry()=='US') ? 'US' : 'CA';
								gift.balance($F(member),storeID,{onSuccess:'cart.addGC(amount,code);',onFailure:'cart.hideNotifier();cart.failGC();'});
		
							}
							else
								this.setState(true);
							$(member).value	= '';
							this.elementArray[member] = null;
						}
						else if(member=='promocode'){
							if(elValue!='') {
								this.showNotifier('Checking Promotion Code, please wait...');
								var promo = new promoManager();
								promo.add($F(member),{onSuccess:'cart.hideNotifier();showLoyaltyMsg_Preview();',onFailure:'cart.hideNotifier();cart.failPromo();'});
							}
							else
								this.setState(true);
							$(member).value	= '';
							this.elementArray[member] = null;
						}
					}
					else {
						this.setState(true);
						this.elementArray[member]=null;
						$(member).value = '';
					}
				}
			}
		},
		
		showNotifier: function(text) {
			if(document.getElementById('notifier')) {
				$('notifier').innerHTML = '<img src="/media/global/loading.gif" border=0 />&nbsp;' + text;
				Element.show('notifier');
				if(document.getElementById('continue'))
					Element.hide('continue');	
				if(document.getElementById('review'))
					Element.hide('review');	
			} 	
		},
		
		hideNotifier: function() {
			if(document.getElementById('notifier')) {
				Element.hide('notifier');
				if(document.getElementById('continue'))
					Element.show('continue');	
				if(document.getElementById('review'))
					Element.show('review');	
			} 
			this.setState(true);
			this.show();
		},
		
		failPromo: function() {
			alert('There\'s a slight problem with your entry. The promotion code is not recognised. Please try again.');
			this.setState(true);
		},
	
		addGC: function(amount,code){
			if(amount==0) 
				alert('Sorry, there is no balance on this gift certificate.');
			else {
				var gift = new giftManager();
				gift.add(amount,code);
			}
			this.hideNotifier();
		},
		
		failGC: function() {
			alert('The gift certificate number is not recognized. Please try again.');
			this.setState(true);
		},
		
		checkout: function(callback) {
			if(this.ready==false)
				this.update();
			else
				if(callback) eval(callback);
		},
		
		loadCheckout:function() {
			// if this production, switch user to https
			var protocol = isProduction() ? 'https://' : 'http://';
			if(this.count()>0) document.location.href = protocol + document.location.host + '/checkout.html';
		},
		
		updateCartIcon: function(dObj) {
			if(document.getElementById(dObj.id))
				$(dObj).innerHTML = this.count();
		},
		
		loadShipping: function(paramObj) {
			var options = {};Object.extend(options, paramObj || {});
			//new Ajax.Request('/ajax/data/shipping.xml',{method:'post',onSuccess:this.setShippingXML.bindAsEventListener(this,{onComplete:options.onComplete})});
			
			try{
				var _this = this;
				RequestManager.request({
					url:'/ajax/data/shipping.xml',
					method:'POST',
					callback:function(xhr){
						_this.setShippingXML(xhr,{onComplete:options.onComplete});
					}
				});
				
			}catch(err){
				alert(err)
			}
		
			
		},
		
		setShippingXML: function(xml,paramObj){
			var options = {};Object.extend(options, paramObj || {});
			this.shippingXML 	= xml;
			this.shippingLoaded	= true;
			if(options.onComplete) eval(options.onComplete);
		},
		
		getShippingRate: function(paramObj) {
			try {
				var options = {};Object.extend(options, paramObj || {});
				
				var user = new userManager();
				if(!options.code || options.code=='') //If no NFS shipping code specified, use default for country
					(getCountry()=='US') ? options.code='1' : options.code='4';
				if(options.price>=100 || user.isLoyaltyMember()) //Current rules dictate that any amount in the cart $100 or over qualifies for free standard shipping
					options.freestandard=true;
				var firstNode 		= get_firstchild(this.shippingXML.responseXML.documentElement);
				var x 				= this.shippingXML.responseXML.getElementsByTagName(firstNode.nodeName);
				for(var i=0;i<x.length;i++) {
					if(getNodeValueByChildName(x[i],'nfs_code')==options.code) {
						for(var j=0;j<x[i].childNodes.length;j++) {
							var currentNode = x[i].childNodes[j];
							var name		= getNodeValueByChildName(x[i],'name');
							if(x[i].childNodes[j].nodeName=='ship_option') {
								var priceRange 		= getNodeValueByChildName(currentNode,'price_range').split('-');
								var rate			= 0;
								if(options.price>=parseFloat(priceRange[0])&&options.price<=parseFloat(priceRange[1])) {
									if(options.freestandard && (options.freestandard==true && (getNodeValueByChildName(x[i],'nfs_code')=='1' || getNodeValueByChildName(x[i],'nfs_code')=='4'))) 
										rate=0;
									else
										rate = getNodeValueByChildName(currentNode,'rate')-0;
									return {price:rate, name:getNodeValueByChildName(x[i],'name'), description:getNodeValueByChildName(x[i],'description')};
									break;
								}
							}
						}	
					}
				}
			}
			catch(err){}
		}
	};

	function isArray(obj){return obj.constructor == Array;};
	function isString(strValue){return (typeof strValue == 'string' && strValue != '' && isNaN(strValue));};
	function isNumber(strValue){return (!isNaN(strValue) && strValue != '');};
	
	var giftManager = Class.create();
	giftManager.prototype = {
		initialize: function(options) {
			this.basket = new CookieJar('gift',{  
			    expires:dateAdd('d', 90, new Date() ),     
			    path:'/'
			}); 
			this.url = '/ajax/order.jsp';
		},
	
		add: function(amount,code) {
			this.basket.put(code, {code:code,amount:amount});
		},

		create: function(formObj) {},
		
		getType: function(item_number) {
			var giftDetails = {};
			switch(item_number) {
			  case '70002':
				giftDetails = {amount:'20',name:'Gift Certificate $20'};
				break;
			  case '70003':
				giftDetails = {amount:'30',name:'Gift Certificate $30'};
				break;
			  case '70004':
				giftDetails = {amount:'40',name:'Gift Certificate $40'};
				break;
			  case '70005':
				giftDetails = {amount:'50',name:'Gift Certificate $50'};
				break;				
			  case '70006':
				giftDetails = {amount:'60',name:'Gift Certificate $60'};
				break;				
			  case '70007':
				giftDetails = {amount:'70',name:'Gift Certificate $70'};
				break;				
			  case '70008':
				giftDetails = {amount:'80',name:'Gift Certificate $80'};
				break;
			  case '70009':
				giftDetails = {amount:'90',name:'Gift Certificate $90'};
				break;				
			  case '70010':
				giftDetails = {amount:'100',name:'Gift Certificate $100'};
				break;				
			  case '70011':
				giftDetails = {amount:'110',name:'Gift Certificate $110'};
				break;
			  case '70012':
				giftDetails = {amount:'120',name:'Gift Certificate $120'};
				break;				
			  case '70013':
				giftDetails = {amount:'130',name:'Gift Certificate $130'};
				break;				
			  case '70014':
				giftDetails = {amount:'140',name:'Gift Certificate $140'};
				break;				
			  case '70015':
				giftDetails = {amount:'150',name:'Gift Certificate $150'};
				break;				
			  case '70016':
				giftDetails = {amount:'160',name:'Gift Certificate $160'};
				break;				
			  case '70017':
				giftDetails = {amount:'170',name:'Gift Certificate $170'};
				break;				
			  case '70018':
				giftDetails = {amount:'180',name:'Gift Certificate $180'};
				break;				
			  case '70019':
				giftDetails = {amount:'190',name:'Gift Certificate $190'};
				break;				
			  case '70020':
				giftDetails = {amount:'200',name:'Gift Certificate $200'};
				break;					
			  case '70021':
				giftDetails = {amount:'210',name:'Gift Certificate $210'};
				break;					
			  case '70022':
				giftDetails = {amount:'220',name:'Gift Certificate $220'};
				break;					
			  case '70023':
				giftDetails = {amount:'230',name:'Gift Certificate $230'};
				break;					
			  case '70024':
				giftDetails = {amount:'240',name:'Gift Certificate $240'};
				break;					
			  case '70025':
				giftDetails = {amount:'250',name:'Gift Certificate $250'};
				break;					
			  case '70026':
				giftDetails = {amount:'300',name:'Gift Certificate $300'};
				break;								
			}
			return giftDetails;
		},
		
		balance: function(gift_code,storeID,options) {
			this.options = {};Object.extend(this.options, options || {});
			var storeID = (storeID=='US') ? 'USA' : 'CAN';
			var formParams = 'gCCheck=1&Code='+gift_code+'&StoreID='+storeID;
			new Ajax.Request(this.url, {
					parameters: formParams + '&nc='+noCache(), 
					onComplete: this.balance_complete.bindAsEventListener(this,{onSuccess:this.options.onSuccess,onFailure:this.options.onFailure,code:gift_code})
				});	
		},
		
		balance_complete: function(response,parameterOptions) {
			var options = {};Object.extend(options, parameterOptions || {});
			try {
	            var amount 	= 0;
				var code	= options.code;
				var x 		= response.responseXML.getElementsByTagName('Amount');
				if(x.length>0) {
					amount = getNodeValue(x[0]);
					if(options.onSuccess) eval(options.onSuccess);
				}
				else {
					if(options.onFailure) eval(options.onFailure);
				}
			}
			catch(err) {
				if(options.onFailure) eval(options.onFailure);
			}
		},
	
		empty: function() {
			try {
				this.basket.empty();
				return true;
			}
			catch(err) {
				return false;
			}
		},	
	
		getItems: function() {
			return this.basket.getKeys();
		},
		
		getContentObj: function() {
			return this.basket.getPack()
		},
		
		getItemByCode: function(code) {
			return this.basket.get(code);
		},
				
		getTotal: function() {
			var gcList 	= this.getItems();
			var total	= 0;
			for(var i=0;i<gcList.length;i++) {
				obj	= this.getItemByCode(gcList[i]);
				total = total + parseFloat(obj.amount);
			}
			return total;
		}
	};

	var promoManager = Class.create();
    promoManager.prototype = {
    initialize: function(options) {
        this.basket = new CookieJar('promotion',{ 
            expires:dateAdd('d', 90, new Date() ),    
            path:'/'
        });
        this.url = '/media/promo/';      
    	},
       
            add: function(code,optionalParams) {
                var options = {};Object.extend(options, optionalParams || {});
                new Ajax.Request(
                this.url+'promo_'+code.toLowerCase()+'.xml', {
                    onSuccess: this.process_success.bindAsEventListener(this,options),
                    onFailure: this.process_fail.bindAsEventListener(this,options)
                    });
            },
       
            getItemByCode: function(code) {
            	return this.basket.get(code);
            },
   
            getContentObj: function() {
            	return this.basket.getPack();
            },
                       
	        process_success: function(xml,optionalParams) {
	            try {
	            	var options = {};Object.extend(options, optionalParams || {});
					var products	= {};
	                var rules       = xml.responseXML.getElementsByTagName('rules');
	                var identity    = xml.responseXML.getElementsByTagName('identity');
					var productsTag	= xml.responseXML.getElementsByTagName('id');
					if(productsTag.length>0) for(var i=0;i<productsTag.length;i++) products[i] = getNodeValue(productsTag[i]); //add product codes for discount calculation
					
	                if(rules.length>0 && identity.length>0) {
	                	this.empty();//no promo combinations so clear out previously entered promo codes
	                    if(getNodeValueByChildName(rules[0],'country')==getCountry() || getNodeValueByChildName(rules[0],'country')=='') {
	                        this.basket.put(getNodeValueByChildName(identity[0],'code'),{
	                            min_purchase: getNodeValueByChildName(rules[0],'min-purchase') ,
	                            country: getCountry(),
	                            uses: getNodeValueByChildName(rules[0],'uses'),           
	                            type: getNodeValueByChildName(rules[0],'type'),
	                            unit: getNodeValueByChildName(rules[0],'unit'),
	                            amount: getNodeValueByChildName(rules[0],'amount'),
	                            apply_to: getNodeValueByChildName(rules[0],'apply-to'),
	                            valid_from: getNodeValueByChildName(rules[0],'valid-from'),
	                            valid_until: getNodeValueByChildName(rules[0],'valid-until'),
	               				description: getNodeValueByChildName(identity[0],'description'),
	               				combine: getNodeAttribute(xml.responseXML.getElementsByTagName('products')[0],'match'),
	               				products: products
							 });
	                        var display              = new painter();
	                        var promoValid           = cart.calculatePromotion(cart.getSubTotal({where:'product_shipping!=\'digital\''}));
	                        if('error' in promoValid){
	                                this.empty();
	                                alert(promoValid.message);
	                        }
	                    }
	                }
	                if(options.onSuccess) eval(options.onSuccess);
	            }
	        	catch(err) {}
	        },
               
            process_fail: function(xml,optionalParams) {
            	var options = {};Object.extend(options, optionalParams || {});
                if(options.onFailure) eval(options.onFailure);
            },
           
            empty: function() {
	            try {
                    this.basket.empty();
                    return true;
                }
                catch(err) {
                    return false;
                }
            } 
        };


	/*
	Created By: Chris Campbell
	Website: http://particletree.com
	Date: 2/1/2006
	Inspired by the lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
	*/	
	//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/
	function getBrowserInfo() {
		if (checkIt('konqueror')) {
			browser = "Konqueror";
			OS = "Linux";
		}
		else if (checkIt('safari')) browser 	= "Safari";
		else if (checkIt('omniweb')) browser 	= "OmniWeb";
		else if (checkIt('opera')) browser 		= "Opera";
		else if (checkIt('webtv')) browser 		= "WebTV";
		else if (checkIt('icab')) browser 		= "iCab";
		else if (checkIt('msie')) browser 		= "Internet Explorer";
		else if (!checkIt('compatible')) {
			browser = "Netscape Navigator";
			version = detect.charAt(8);
		}
		else browser = "An unknown browser";
	
		if (!version) version = detect.charAt(place + thestring.length);
	
		if (!OS) {
			if (checkIt('linux')) OS 		= "Linux";
			else if (checkIt('x11')) OS 	= "Unix";
			else if (checkIt('mac')) OS 	= "Mac";
			else if (checkIt('win')) OS 	= "Windows";
			else OS 								= "an unknown operating system";
		}
	};
	
	function checkIt(string) {
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	};
	
	/*-----------------------------------------------------------------------------------------------*/
	
	Event.observe(window, 'load', initialize, false);
	Event.observe(window, 'load', getBrowserInfo, false);
	Event.observe(window, 'unload', Event.unloadCache, false);
	
	var lightbox = Class.create();
	
	lightbox.prototype = {
		yPos : 0,
		xPos : 0,
		that : this,
		
		initialize: function(ctrl, params) {
			this.content = ctrl.href;
			this.params = {};
			this.elem = ctrl;
			this.activateRef = this.activate.bindAsEventListener(this);
			if (ctrl.lbEvtQueue == undefined) {
				ctrl.lbEvtQueue = [this.activateRef];
			} else {
				ctrl.lbEvtQueue.push(this.activateRef);
			}
			if (ctrl.onclick) {	this.oldonclick = ctrl.onclick;	}
			Object.extend(this.params, params || {});
			Event.observe(ctrl, 'click', this.activateRef, false);
			ctrl.onclick = function(){return false;};
		},
		
		// Turn everything on - mainly the IE fixes
		activate: function(event) {
			//if (browser == 'Internet Explorer' && navigator.appVersion.substr(22,3) == "6.0") {
				this.getScroll();
				this.prepareIE('100%', 'hidden');
				this.prepareIE('100%', 'hidden');
				this.setScroll(0,0);
				this.hideSelects('hidden');
			//}
			this.displayLightbox("block");
		},
		
		// Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
		prepareIE: function(height, overflow) {
			bod = document.getElementsByTagName('body')[0];
			bod.style.height = height;
			bod.style.overflow = overflow;
			htm = document.getElementsByTagName('html')[0];
			htm.style.height = height;
			htm.style.overflow = overflow; 
		},
		
		// In IE, select elements hover on top of the lightbox
		hideSelects: function(visibility) {
			selects = document.getElementsByTagName('select');
			for(i = 0; i < selects.length; i++) {
				selects[i].style.visibility = visibility;
			}
		},
		
		// Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
		getScroll: function() {
			if (self.pageYOffset) {
				this.yPos = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){
				this.yPos = document.documentElement.scrollTop; 
			} else if (document.body) {
				this.yPos = document.body.scrollTop;
			}
		},
		
		setScroll: function(x, y) {
			window.scrollTo(x, y); 
		},
		
		displayLightbox: function(display) {
			$('overlay').style.display = display;
			if (!this.params.nodisplay || display == 'none') {
				if (display == 'none') {
					$('lightbox').style.top = null;
					$('lightbox').style.left = null;
					$('lightbox').style.width = null;
					$('lightbox').style.height = null;
				}
				$('lightbox').style.display = display;
			}
			if (this.params.nodisplay && display == 'block') {
				centerElem($('lightbox'));
				$('lightbox').style.display = 'block'; 
			}
			if (!this.params.noOverlayClick && display != 'none') {
				$('overlay').className = 'lbAction';
				$('overlay').rel = 'deactivate';
			}
			if (this.params.noOverlayClick) {
				$('overlay').className = '';
				$('overlay').rel = null;
				$('overlay').onclick = null;
			}
			if (display != 'none' && !this.params.noAjax) {
				this.loadInfo();
			}		
		},
		
		// Begin Ajax request based off of the href of the clicked linked
		loadInfo: function() {
			var myAjax = new Ajax.Request( this.content,
	        	{method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)});
		},
		
		// Display Ajax response and Close Button
		processInfo: function(response) {
			if (this.params.nodisplay) $('lightbox').style.display = 'none';
			if ($('lbContent')) Element.remove($('lbContent'));
			info = "<div id='lbContent'>"+response.responseText+"</div>";
			if (screen.height <= 600) {
				var tmp = document.createElement('div');
				tmp.innerHTML = info;
				var close = $(tmp).getElementsByClassName('close')[0];
				close.next().addClassName('win800x600');
				$('lightbox').style.left = '50%';
				info = tmp.innerHTML;
			}
			new Insertion.Before($('lbLoadMessage'), info);
			$('lightbox').className = "done";
			if (this.params.oncomplete) { this.params.oncomplete(); }
			this.actions();			
		},
		
		// Search through new links within the lightbox, and attach click event
		actions: function() {
			lbActions = $$('.lbAction');
			for(i = 0; i < lbActions.length; i++) {
				if (lbActions[i].id == 'overlay') {
					lbActions[i].onclick = this[lbActions[i].rel].bindAsEventListener(this);
				} else {
					Event.observe(lbActions[i], 'mousedown', this[lbActions[i].rel].bindAsEventListener(this), false);
					lbActions[i].onclick = function(){return false;};
				}
			}
	
		},
		
		// Example of creating your own functionality once lightbox is initiated
		insert: function(e) {
		   var link = Event.element(e).parentNode;
		   Element.remove($('lbContent'));
		 
		   var myAjax = new Ajax.Request(
				  link.href,
				  {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)}
		   );
		 
		},
		
		// Example of creating your own functionality once lightbox is initiated
		deactivate: function(e) {
			
			//if there are magic zooms stop them!
			if(typeof(MagicZoom_zooms) != 'undefined' && MagicZoom_zooms.length > 0){
				MagicZoom_stopZooms();
			}	
									
			if ($('lbContent')) Element.remove($('lbContent'));
			
			//if (browser == "Internet Explorer" && navigator.appVersion.substr(22,3) == "6.0"){
				this.setScroll(0,this.yPos);
				this.prepareIE("auto", "auto");
				this.hideSelects("visible");
			//}
			this.displayLightbox("none");
			$('lightbox').className = 'loading';
			
			
			
		},
		
		removeListener: function (restoreOld) {
			Event.stopObserving(this.elem, 'click', this.activateRef, false);
			if (restoreOld && this.oldonclick) {
				this.elem.onclick = this.oldonclick;
			}
		},
		
		flush: function () {
			while (this.elem.lbEvtQueue.length) {
				Event.stopObserving(this.elem, 'click', this.elem.lbEvtQueue.shift(), false);
			}
		}
	};
	/*-----------------------------------------------------------------------------------------------*/
	
	// Onload, make all links that need to trigger a lightbox active
	function initialize(){
		addLightboxMarkup();
		lbox = $$('.lbOn');
		for(i = 0; i < lbox.length; i++) {
			valid = new lightbox(lbox[i]);
		}
	};
	
	// Add in markup necessary to make this work. Basically two divs:
	// Overlay holds the shadow
	// Lightbox is the centered square that the content is put into.
	function addLightboxMarkup() {
		bod 				= document.getElementsByTagName('body')[0];
		overlay 			= document.createElement('div');
		overlay.id		= 'overlay';	
		lb					= document.createElement('div');
		lb.id				= 'lightbox';
		lb.className 	= 'loading';
		lb.innerHTML	= '<div id="lbLoadMessage">' +
							  '<p>Loading</p>' +
							  '</div>';
		bod.appendChild(overlay);
		bod.appendChild(lb);
	};
	// ************** end of lightbox ************** //
	
	//cdaCommon.js
	function addMetaNode(name, content) {
		if (!name || !content) return;
		var head = document.getElementsByTagName('head');
		if (head.length) {
			var metaTag = document.createElement('meta');
			metaTag.setAttribute('name', name);
			metaTag.setAttribute('content', content);
			head[0].appendChild(metaTag);
		}
	};
	function sfHover(){
		if(document.getElementById('main_navigation')){
			new Ajax.Request('/global/subnav.xml',{
				method: 'get',
				parameters:'nC='+noCache(),
				onSuccess:function(t){
					var mainNav = $('main_navigation');
					mainNav.innerHTML=renderMainNavigation(t,0);
					mainNav.firstChild.lastChild.firstChild.className += ' last';
				}
			});
		}
	};
	function sfIeHover(){
		if(document.getElementById('main_navigation')){
			new Ajax.Request('/global/subnav.xml',{
				method: 'get',
				parameters:'nC='+noCache(),
				onSuccess:function(t){
					$('main_navigation').innerHTML=renderMainNavigation(t,0);
					$('main_navigation').firstChild.lastChild.firstChild.className += ' last';
					// Support the standard nav without a class of nav.
					var el = document.getElementById("nav");
					if(!/\bnav\b/.test(el.className) && el.tagName == "UL")
						setIeHover(el);
				
					// Find all unordered lists.
					var ieNavs = document.getElementsByTagName('ul');
					for(i=0; i<ieNavs.length; i++) {
						var ul = ieNavs[i];
						// If they have a class of nav add the menu hover.
						if(/\bnav\b/.test(ul.className))
							setIeHover(ul);
					}
				}
			});	
		}
	};
	function setIeHover(nav) {
		var ieULs = nav.getElementsByTagName('ul');
		if (navigator.appVersion.substr(22,3)!="5.0") {
			// IE script to cover <select> elements with <iframe>s
			for (j=0; j<ieULs.length; j++) {
			}
			// IE script to change class on mouseover
			var ieLIs = nav.getElementsByTagName('li');
			for (var i=0; i<ieLIs.length; i++) {
				if (ieLIs[i]) { 
					// Add a sfhover class to the li
					ieLIs[i].onmouseover=function() { 
						if(!/\bsfhover\b/.test(this.className)) {
							this.className+=" sfhover";
						}
					};
					ieLIs[i].onmouseout=function() {
						if(!this.contains(event.toElement)) {
							this.className=this.className.replace(' sfhover', '');
						}
					};
				}
			}
		}
	};

	function sendmailSubmit(fObj) {
		if (checkForm(fObj)) {
			fObj.submit();
		}
	};
		   	
	function ajaxRequest_Error(){alert("An error occurred during the process");};
	function search_Submit(sObj){
		if($F(sObj)!=''){
			if(document.getElementById('page_id')) 
				document.location.href='/search.jsp?kword='+$F(sObj)+'&page_id='+$F('page_id');
			else 
				document.location.href='/search.jsp?kword='+$F(sObj);
		}
		else{
			alert('Please enter a keyword');
		}
	};
	
	function search_Page(pNum,sObj){$('page_id').value=pNum;search_Submit(sObj);};							
	function renderMainNavigation(req,parent_id){
		var tmp			= '';
		var subTmp		= '';
		var subNodes	= '';
		var k			= req.responseXML.getElementsByTagName('nav');
		var navLen		= k.length;
		var topLevelCnt	= 0;
		for(var j=0;j<k.length;j++){
			tmp					= '';
			subNodes			= '';
			var nLabel			= getNodeAttribute(k[j],'label');
			var nUrl			= getNodeAttribute(k[j],'url');
			var popup			= getNodeAttribute(k[j],'popup');
			var popupWidth		= getNodeAttribute(k[j],'width');
			var popupHeight		= getNodeAttribute(k[j],'height');
			var popupScroll		= getNodeAttribute(k[j],'scroll');
			var popupToolbar	= getNodeAttribute(k[j],'toolbar');
			var popupResize		= getNodeAttribute(k[j],'resize');
			var nParent			= getNodeAttribute(k[j],'parent_id');
			var nOrder			= getNodeAttribute(k[j],'order');
			var nId				= getNodeAttribute(k[j],'nav_id');
			var topImg			= 'top_'+nId;
			if(nParent==parent_id){
				if(parent_id==0){
					topLevelCnt++;
					if(popup=='1') {
						tmp+='<a class="item'+ topLevelCnt + '" href="#" onclick="open_win('
							+ '\'' + nUrl + '\','+'\''+nLabel+'\','
							+ '\'toolbar=' + popupToolbar
							+ ',scrollbars='+popupScroll+','
							+ 'location=0,resizable='+popupResize+','
							+ 'width='+popupWidth
							+ ',height='+popupHeight
							+ '\');this.blur();return false;">';
					} else {
						if (/seating/i.test(nLabel)) {
							tmp += '<a id="seating-menu" class="item'+ topLevelCnt + '" href="'+nUrl+'">';
						} else { 
							tmp += '<a class="item'+ topLevelCnt + '" href="'+nUrl+'">';
						}
					}
					tmp += '<span>' + nLabel + '</span></a>';
					subNodes = renderMainNavigation_sub1(req,nId,topImg);
					if(subNodes!='')
						tmp+='<ul>'+subNodes+'</ul>';
				}
			}
			if(tmp!='')
				subTmp += '<li class="item'+ topLevelCnt + '">'+tmp+'</li>';
		}
		return '<ul id="nav" class="nav">'+subTmp+'</ul>';
	};
	
	function renderMainNavigation_sub1(req,parent_id,mainImage){
		var tmp			= '';
		var subTmp		= '';
		var subNodes	= '';
		var k			= req.responseXML.getElementsByTagName('nav');
		for(var j=0;j<k.length;j++){
			tmp	='';
			subNodes='';
			var nLabel			= getNodeAttribute(k[j],'label');
			var nUrl			= getNodeAttribute(k[j],'url');
			var popup			= getNodeAttribute(k[j],'popup');
			var popupWidth		= getNodeAttribute(k[j],'width');
			var popupHeight		= getNodeAttribute(k[j],'height');
			var popupScroll		= getNodeAttribute(k[j],'scroll');
			var popupToolbar	= getNodeAttribute(k[j],'toolbar');
			var popupResize		= getNodeAttribute(k[j],'resize');
			var nParent			= getNodeAttribute(k[j],'parent_id');
			var nOrder			= getNodeAttribute(k[j],'order');
			var nId				= getNodeAttribute(k[j],'nav_id');
			if(nParent==parent_id){
				tmp+='<li>';
				if(popup=='1')
					tmp+='<a href="#" '
					 + 'onclick="open_win(\'' + nUrl + '\',\''+nLabel+'\',\'toolbar='
					 + popupToolbar+',scrollbars='+popupScroll+',location=0,resizable='
					 + popupResize+',width='+popupWidth+ ',height='+popupHeight
					 + '\');this.blur();return false;">' + nLabel + '</a>';
				else
					tmp+='<a href="'+nUrl+'">' + nLabel + '</a>';
					
				subNodes=renderMainNavigation_sub2(req,nId);
				if(subNodes!='')
					tmp+='<ul>'+subNodes+'</ul>\n';
			}
			if(tmp!='')
				subTmp+=tmp+'</li>\n';
		}
		return subTmp;
	};
	
	function renderMainNavigation_sub2(req,parent_id){
		var tmp='';
		var subTmp='';
		var k=req.responseXML.getElementsByTagName('nav');
		for (var j=0;j<k.length;j++){
			tmp='';
			var nLabel=getNodeAttribute(k[j],'label');
			var nUrl=getNodeAttribute(k[j],'url');
			var popup=getNodeAttribute(k[j],'popup');
			var popupWidth=getNodeAttribute(k[j],'width');
			var popupHeight=getNodeAttribute(k[j],'height');
			var popupScroll=getNodeAttribute(k[j],'scroll');
			var popupToolbar=getNodeAttribute(k[j],'toolbar');
			var popupResize=getNodeAttribute(k[j],'resize');
			var nParent=getNodeAttribute(k[j],'parent_id');
			var nOrder=getNodeAttribute(k[j],'order');
			var nId=getNodeAttribute(k[j],'nav_id');
			if(nParent==parent_id){
				tmp+='<li>';
				if(popup=='1'){
					tmp += '<a href="#" onclick="open_win('+'\''+nUrl+'\','+'\''+nLabel+'\','
					+ '\'toolbar='+popupToolbar+','+'scrollbars='+popupScroll+','+'location=0,'
					+ 'resizable='+popupResize+','+'width='+popupWidth+','+'height='+popupHeight
					+ '\');this.blur();return false;">' + nLabel + '</a>';
				}
				else{
					tmp+='<a href="'+nUrl+'">' + nLabel + '</a>';
				}
				if(tmp!=''){
					tmp+='</li>\n';
				}
			}
			if(tmp!=''){
				subTmp+=tmp;
			}
		}
		return subTmp;
	};
		
	//ip_common.js
	function newWindow(wURL,wName,wWidth,wHeight,wScroll,wResizable,wCentered){
		var settings = 'height='+wHeight+',width='+wWidth+'scrollbars='+wScroll+',resizable='+wResizable;
		if(wCentered==true){
			lPosition	= (screen.width) ? (screen.width-wWidth)/2 : 0;
			tPosition	= (screen.height) ? (screen.height-wHeight)/2 : 0;	
			settings	+= ',left=' + lPosition + ',top=' + tPosition;
		}
		var nWindow	= window.open(wURL,wName,settings);
		nWindow.focus();
	};
	
	function disableContextMenu(event) {
		Event.stop(event); 
    	event.oncontextmenu = function(){return false;}
	};
		
	function truncateText_Append(txtString,len,append){
		  var trunc = txtString;
		  if (trunc.length > len){
		    trunc = trunc.substring(0, len);
		    trunc = trunc.replace(/\w+$/, '');
		    trunc += append;
		  }
		  return trunc;
	};

	function getPage(url){return url.substring(url.lastIndexOf('/') + 1);};
	function hasZero(value){return (value+0<10) ? '0' + value : '' + value;};
	function noCache(){return Math.random(0, 1000)+'='+Math.random(0,1000);};
	function uniqueId(){var rndId = Math.random(0, 1000)+'';return rndId.replace('.','');};
	function addDays(myDate,days){return new Date(myDate.getTime() + days*24*60*60*1000);};	

	function getMetaValue(metaName){
		var metaArray = document.getElementsByTagName('meta');
		for(m=0;m<metaArray.length;m++){
			if(metaArray[m].name==metaName) {
				return metaArray[m].content;
				break;
			}	
		}
		return false;
	};
					
	function getFileExtension(fileName){
		if( fileName.length == 0 ) return ''; 
		var dot = fileName.lastIndexOf('.'); 
		if( dot == -1 ) return ''; 
		return fileName.substr(dot,fileName.length); 
	};

	function SearchAndReplace(Content, SearchFor, ReplaceWith){
	   var tmpContent = Content;
	   var tmpBefore = new String();   
	   var tmpAfter = new String();
	   var tmpOutput = new String();
	   var intBefore = 0;
	   var intAfter = 0;
	   if (SearchFor.length == 0) return;
	   while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {
	      intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
	      tmpBefore = tmpContent.substring(0, intBefore);
	      tmpOutput = tmpOutput + tmpBefore;
	      tmpOutput = tmpOutput + ReplaceWith;
	      intAfter = tmpContent.length - SearchFor.length + 1;
	      tmpContent = tmpContent.substring(intBefore + SearchFor.length);
	   }
	   return tmpOutput + tmpContent;
	};
	
	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=/';
	};
	
	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;
	};
	
	function eraseCookie(name){createCookie(name,'',-1);};
	
	function parseCookie() {
		var x = new Object();
		var y = readCookie('olio');
		if (y) {
			var tmp = y.split("|");
			if (tmp.length == 5) {
				x['userid'] = tmp[0]; 
				x['username'] = tmp[1];
				x['email'] = tmp[2];
				x['fname'] = tmp[3];
				x['lname'] = tmp[4];
			}
		}
		return x;
	};
	
	function loadScript(url, callback) {
		var f = arguments.callee;
		if (!("queue" in f))
			f.queue = {};
		var queue =  f.queue;
		if (url in queue) {
			if (callback) {
				if (queue[url])
					queue[url].push(callback);
				else
					callback();
			}
			return;
		}
		queue[url] = callback ? [callback] : [];
		var script = document.createElement("script");
		script.type = "text/javascript";
		if ((/WebKit/i.test(navigator.userAgent)) || (/opera/i.test(navigator.userAgent))) {
			var _timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					clearInterval(_timer);
					while (queue[url].length) {
						queue[url].shift()();
					}
					queue[url] = null;
				}
			}, 1000);
		} else {
			script.onload = script.onreadystatechange = function() {
				if (script.readyState && script.readyState != "loaded" && script.readyState != "complete")
					return;
				script.onreadystatechange = script.onload = null;
				while (queue[url].length) {
					queue[url].shift()();
				}
				queue[url] = null;
			};
		}
		script.src = url;
		document.getElementsByTagName("head")[0].appendChild(script);
	};

	// ip_xml.js
	function getPropertyNodeByName(object,name){try{var propertyNode=object.getElementsByTagName(get_firstchild(object).nodeName);var propertyLen=propertyNode.length;for(var j=0;j<propertyLen;j++){switch(getNodeAttribute(propertyNode[j],'name')){case name:return getNodeValue(propertyNode[j]);break;}}}catch(err){return '';}};
	function getNodeValueByChildName(node,childname){var tmpString='';try{if(node.getElementsByTagName(childname)[0].firstChild.nodeValue=='null'){return '';}else{for(var i=0;i<node.getElementsByTagName(childname)[0].childNodes.length;i++){tmpString+=node.getElementsByTagName(childname)[0].childNodes[i].nodeValue;}return tmpString;}}catch(err){return '';}};
	function getNodeValue(node){var tmpString='';try{for(var i=0;i<node.childNodes.length;i++){tmpString+=node.childNodes[i].nodeValue;}return tmpString;}catch(err){return '';}};
	function getNodeChildObj(obj,tag){var tmpString='';try{if(obj.getElementsByTagName(tag)[0].firstChild.nodeValue=='null')return '';else{return obj.getElementsByTagName(tag);}}catch(err){return '';}};
	function getNodeName(obj){return obj.firstChild.nodeName;};
	function getNodeAttribute(obj,attr){try{return obj.getAttribute(attr);}catch(err){return '';}};
	function get_firstchild(n){try{var x=n.firstChild;while(x.nodeType!=1){x=x.nextSibling;}return x;}catch(err){return '';}};
	function hasChildElements(rootNode){try{for(var i=0;i<rootNode.childNodes.length;i++){if(rootNode.childNodes[i].nodeType == 1){return true;}}return false;}catch(err){return '';}};

	//ip_select.js
	function hasOptions(obj){if(obj!=null&&obj.options!=null){return true;}else{return false};};
	function selectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,'select',false);};
	function selectOnlyMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,'select',true);};
	function unSelectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,'unselect',false);};
	function selectUnselectMatchingOptions(obj,regex,which,only){if(window.RegExp){if(which=='select'){var selected1=true;var selected2=false;}else if(which=='unselect'){var selected1=false;var selected2=true;}else{return;}var re=new RegExp(regex);if(!hasOptions(obj))return;for(var i=0;i<obj.options.length;i++){if(re.test(obj.options[i].value))obj.options[i].selected=selected1;else {if(only==true) obj.options[i].selected=selected2;}}}};
	function removeSelectedOptions(from){if(!hasOptions(from)){return;}if(from.type=="select-one"){from.options[from.selectedIndex]=null;}else{for(var i=(from.options.length-1);i>=0;i--){var o=from.options[i];if(o.selected)from.options[i]=null;}}from.selectedIndex=-1;};
	function removeAllOptions(from){if(!hasOptions(from))return;for(var i=(from.options.length-1);i>=0;i--){from.options[i]=null;}from.selectedIndex=-1;};
	function addOption(obj,text,value,selected){if(obj!=null&&obj.options!=null)obj.options[obj.options.length]=new Option(text,value,selected);};
	function removeOption(fOBJ,value){for(i=0;i<fOBJ.options.length;i++){if(fOBJ.options[i].value==value)fOBJ.options[i]=null;}};
	function getSelectList(fOBJ){var pars='';for(i=0;i<fOBJ.length;i++){if(i>0)pars=pars+',';pars=pars+fOBJ.options[i].value;}return pars;};
	function getSelectListSelected(fOBJ){var pars='';var count=0;for(i=0;i<fOBJ.length;i++){if(fOBJ.options[i].selected==true){if(count>0)pars=pars+',';count++;pars=pars+fOBJ.options[i].value;}}return pars;};
	function display_Select(sOptions,sSelected){var tmpData='';var x=sOptions.split(',');for(var i=0;i<x.length;i++){var sltcd='';var items=x[i].split('|');if(items[0]==sSelected)sltcd='selected="selected"';tmpData+='<option value="'+items[0]+'" '+sltcd+'>'+items[1]+'</option>';}return tmpData;};
		
	// ip_form.xml
	var dfltValue   = '**NO VALUE**';
	var dfltChars   = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.?-()[]+=_-;:/#@$%&!,*<>\"\'\n\r ';
	var dfltMethod  = 'POST';
	function checkForm(object){var response=true;for(var i=0;i<object.elements.length;i++){if(checkFormElement(object.elements[i])==false){response=false;break;}}return response;};
	
	function checkFormElement(elementObj,options) {
		this.options = {};
		Object.extend(this.options, options || {});
		var response = true;
		if(elementObj.attributes['id']) {
			theO		= $(elementObj);
			oType		= theO.type;
	        oName  		= theO.getAttribute('id');
			if(!elementObj.getAttribute('name')) {
				theO.setAttribute('name',oName);
			}
	        oValue 		= $F(theO);
			if(this.options.required=='true') {
				oReqd=true;
			}
			else {
				(theO.attributes["required"]) ? oReqd=true : oReqd=false;
			}
		   	(theO.attributes["alert"]) ? oAlert=theO.attributes['alert'].value : oAlert ='';
			(theO.attributes["highlight"]) ? oHighlight=theO.attributes['highlight'].value : oHighlight='';
	       	(theO.attributes["chars"]) ? oChars=theO.attributes['chars'].value : oChars=dfltChars;
	        (theO.attributes["editor"]) ? oEditor=true : oEditor=false;
	        (theO.attributes["parent"]) ? oParent=theO.attributes['parent'].value : oParent='';
			(theO.attributes["minLen"]) ? oMin=theO.attributes['minLen'].value : oMin=1;
	        (theO.attributes["maxLen"]) ? oMax=theO.attributes['maxLen'].value : oMax=100;
			if(oReqd==true||(document.getElementById(oParent)&&oParent!=''&&$(oParent).checked==true)||oAlert!='') {
	        	if(oEditor==true) {
					var tmpValue = getEditor(oName);
					if(tmpValue.length<oMin || tmpValue.length>oMax) {
						response=false;
						if(oHighlight!='') theO.className = oHighlight;
						if(oAlert!='') alert(oAlert);
					}
	        	}
				else if(oType.indexOf('select-single')>-1 && oValue=="") {
					response=false;
					if(oHighlight!='') {
						theO.addClassName(oHighlight);
					}
					if(oAlert!='') alert(oAlert);
				}
				else if(oType.indexOf('select-multiple')>-1) {
					if(oValue=='') {
						response=false;
						if(oHighlight!='') {
							theO.addClassName(oHighlight);
						}
						if(oAlert!='') alert(oAlert);
					}
					else {
						if(oValue.indexOf(',')>-1 && oMin>1) {}
					}
				}
	        	else {
		            if(oName.toLowerCase().indexOf('email')>-1) { 
		                if(isValidEmail(oValue)==false) {
		                	response=false;
							if(oHighlight!='') theO.addClassName(oHighlight);
							if(oAlert!='') alert(oAlert);
		                }
		             } 
		             else if(validate(oValue,oChars)==false||oValue.length<oMin||oValue.length>oMax) {
		             	response=false;
						if(oHighlight!='') {
							theO.addClassName(oHighlight);
						}
						if(oAlert!='') alert(oAlert);
		             }
		             //credit card validation 
		             else if(oName.toLowerCase().indexOf('cardnumber')>-1){
		             	if(isValidCC(oValue)==false){
		             		if(oHighlight!='') theO.addClassName(oHighlight);
							if(oAlert!='') alert(oAlert);
							response=false;
		             	}
		             	
		             }
		             //security code
		             else if(oName.toLowerCase().indexOf('cardsecuritycode')>-1){
		             	if(isVaildSC(oValue)==false){
		             		if(oHighlight!='') theO.addClassName(oHighlight);
							if(oAlert!='') alert(oAlert);
							response=false;
		             	}
		             }
		     	}
	        }
		}	
		return response;
	};

	function isValidEmail(string){	if(string.length<1)return false; if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1){	return true; } else{ return false;	} };
	
	function validate(strVl,strChrs){if(!strVl) return false;if(strVl==dfltValue)return false;if(strVl.length<1)return false;if(!strChrs) strChrs=dfltChars;for(i=0;i<strVl.length;i++){if(strChrs.indexOf(strVl.charAt(i))==-1)return false;}return true;};	
	
	function isValidCC(string){	if(string.length<1)return false; if(string.search(/^[0-9]{13,16}$/)!=-1){ return true;	} else{	return false; } };
	
	function isVaildSC(string){	if(string.length<1)return false; if(string.search(/^[0-9]{3,4}$/)!=-1){ return true;	}else{	return false; } };
		
	//ip_date.js
	function isDate(p_Expression){return !isNaN(new Date(p_Expression));};

	function dateAdd(p_Interval, p_Number, p_Date){
		if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
		if(isNaN(p_Number)){return "invalid number: '" + p_Number + "'";}	
		p_Number = new Number(p_Number);
		var dt = new Date(p_Date);
		switch(p_Interval.toLowerCase()){
			case "yyyy": 
				dt.setFullYear(dt.getFullYear() + p_Number);
				break;
			case "q": 
				dt.setMonth(dt.getMonth() + (p_Number*3));
				break;
			case "m": 
				dt.setMonth(dt.getMonth() + p_Number);
				break;
			case "y":
			case "d":
			case "w": 
				dt.setDate(dt.getDate() + p_Number);
				break;
			case "ww": 
				dt.setDate(dt.getDate() + (p_Number*7));
				break;
			case "h": 
				dt.setHours(dt.getHours() + p_Number);
				break;
			case "n": 
				dt.setMinutes(dt.getMinutes() + p_Number);
				break;
			case "s": 
				dt.setSeconds(dt.getSeconds() + p_Number);
				break;
			case "ms": 
				dt.setMilliseconds(dt.getMilliseconds() + p_Number);
				break;
			default: 
				return "invalid interval: '" + p_Interval + "'";
		}
		return dt;
	};
	
	function dateDiff(p_Interval, p_Date1, p_Date2, p_firstdayofweek, p_firstweekofyear){
		if(!isDate(p_Date1)){return "invalid date: '" + p_Date1 + "'";}
		if(!isDate(p_Date2)){return "invalid date: '" + p_Date2 + "'";}
		var dt1 = new Date(p_Date1);
		var dt2 = new Date(p_Date2);
		var iDiffMS = dt2.valueOf() - dt1.valueOf();
		var dtDiff = new Date(iDiffMS);
		var nYears  = dt2.getUTCFullYear() - dt1.getUTCFullYear();
		var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
		var nQuarters = parseInt(nMonths/3);	
		var nMilliseconds = iDiffMS;
		var nSeconds = parseInt(iDiffMS/1000);
		var nMinutes = parseInt(nSeconds/60);
		var nHours = parseInt(nMinutes/60);
		var nDays  = parseInt(nHours/24);
		var nWeeks = parseInt(nDays/7);
		var iDiff = 0;		
		switch(p_Interval.toLowerCase()){
			case "yyyy": return nYears;
			case "q": return nQuarters;
			case "m": return nMonths;
			case "y": 
			case "d": return nDays;
			case "w": return nDays;
			case "ww":return nWeeks;	
			case "h": return nHours;
			case "n": return nMinutes;
			case "s": return nSeconds;
			case "ms":return nMilliseconds;
			default: return "invalid interval: '" + p_Interval + "'";
		}
	};

	function datePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear){
		if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
		var dtPart = new Date(p_Date);
		switch(p_Interval.toLowerCase()){
			case "yyyy": return dtPart.getFullYear();
			case "q": return parseInt(dtPart.getMonth()/3)+1;
			case "m": return dtPart.getMonth()+1;
			case "y": return dateDiff("y", "1/1/" + dtPart.getFullYear(), dtPart);			// day of year
			case "d": return dtPart.getDate();
			case "w": return dtPart.getDay();	// weekday
			case "ww":return dateDiff("ww", "1/1/" + dtPart.getFullYear(), dtPart);		// week of year
			case "h": return dtPart.getHours();
			case "n": return dtPart.getMinutes();
			case "s": return dtPart.getSeconds();
			case "ms":return dtPart.getMilliseconds();	// millisecond	// <-- extension for JS, NOT available in VBScript
			default: return "invalid interval: '" + p_Interval + "'";
		}
	};
	// REQUIRES: isDate()
	// NOT SUPPORTED: firstdayofweek (does system default)
	function weekdayName(p_Date, p_abbreviate){
		if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
		var dt = new Date(p_Date);
		var retVal = dt.toString().split(' ')[0];
		var retVal = Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[dt.getDay()];
		if(p_abbreviate==true){retVal = retVal.substring(0, 3)}	// abbr to 1st 3 chars
		return retVal;
	};
	// REQUIRES: isDate()
	function monthName(p_Date, p_abbreviate){
		if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
		var dt = new Date(p_Date);	
		var retVal = Array('January','February','March','April','May','June','July','August','September','October','November','December')[dt.getMonth()];
		if(p_abbreviate==true){retVal = retVal.substring(0, 3)}	// abbr to 1st 3 chars
		return retVal;
	};
	
	function DateAdd(p_Interval, p_Number, p_Date){return dateAdd(p_Interval, p_Number, p_Date);};
	function DateDiff(p_interval, p_date1, p_date2, p_firstdayofweek, p_firstweekofyear){return dateDiff(p_interval, p_date1, p_date2, p_firstdayofweek, p_firstweekofyear);};
	function DatePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear){return datePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear);};
	function getTimeFromDate(date_time){return hasZero(datePart('h', date_time)) + ":" + hasZero(datePart('n', date_time));};
	
	function parseDateObj(dateobj){
		var x = new Object();
		x['month'] = hasZero(dateobj.getMonth()-1);
		x['day'] = hasZero(dateobj.getDate());
		x['year'] = dateobj.getYear();
		x['hour'] = hasZero(dateobj.getHours());
		x['minute'] = hasZero(dateobj.getMinutes());
		x['second'] = hasZero(dateobj.getSeconds());
		return x;
	};
	
	function createDateObj(date_time){return new Date(Date.parse(date_time));};
	
	function convertTimeZone(dateObj, diff){
		var tmp = "";
		var plusminus = 1;
		if (diff.split("-").length > 1){
			tmp = diff.split("-")[1];
			plusminus = -1;
		} else if (diff.split("+").length > 1){
			tmp = diff.split("+")[1];
			plusminus = 1;
		}
		if (tmp.length){
			dateObj = dateAdd('n', plusminus * tmp.split(":")[1], dateObj);
			dateObj = dateAdd('h', plusminus * tmp.split(":")[0], dateObj);
		}
		return dateObj;
	};
	
	function convertToGMT(dateObj, diff){
		var tmp = "";
		var plusminus = 1;
		if (diff.split("-").length > 1){
			tmp = diff.split("-")[1];
			plusminus = 1;
		} else if (diff.split("+").length > 1){
			tmp = diff.split("+")[1];
			plusminus = -1;
		}
		if (tmp.length){
			dateObj = dateAdd('n', plusminus * tmp.split(":")[1], dateObj);
			dateObj = dateAdd('h', plusminus * tmp.split(":")[0], dateObj);
		}
		return dateObj;
	};
	function convertHours(p_Date) {
	    if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
	    var regHr = p_Date.getHours();
	    if (regHr == 0) regHr = 12;
	    else if (regHr > 12) regHr -= 12;
	    return regHr;
	};
	function showAMPM(p_Date) {
		if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
	    var amPM;
	    if (p_Date.getHours() < 12) amPM = 'AM';
	    else amPM = 'PM';
	    return amPM;
	};
	function dateInRange(dx, begin, end) {
	    if (!isDate(dx) || !isDate(begin) || !isDate(end)) { return false; }
	    return (dateDiff('n', begin, dx) >= 0 && dateDiff('n', dx, end) >= 0)?true:false;
	};
	/**
	 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
	 *
	 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
	 * http://www.opensource.org/licenses/mit-license.php
	 *
	 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
	 *   legal reasons.
	 */
	if(typeof deconcept=="undefined"){var deconcept=new Object();}
	if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
	if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
	deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;};
	this.DETECT_KEY=_b?_b:"detectflash";
	this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params=new Object();
	this.variables=new Object();
	this.attributes=new Array();
	if(_1){this.setAttribute("swf",_1);}
	if(id){this.setAttribute("id",id);}
	if(w){this.setAttribute("width",w);}
	if(h){this.setAttribute("height",h);}
	if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
	this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
	if(c){this.addParam("bgcolor",c);}
	var q=_8?_8:"high";
	this.addParam("quality",q);
	this.setAttribute("useExpressInstall",_7);
	this.setAttribute("doExpressInstall",false);
	var _d=(_9)?_9:window.location;
	this.setAttribute("xiRedirectUrl",_d);
	this.setAttribute("redirectUrl","");
	if(_a){this.setAttribute("redirectUrl",_a);}};
	deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
	this.attributes[_e]=_f;
	},getAttribute:function(_10){
	return this.attributes[_10];
	},addParam:function(_11,_12){
	this.params[_11]=_12;
	},getParams:function(){
	return this.params;
	},addVariable:function(_13,_14){
	this.variables[_13]=_14;
	},getVariable:function(_15){
	return this.variables[_15];
	},getVariables:function(){
	return this.variables;
	},getVariablePairs:function(){
	var _16=new Array();
	var key;
	var _18=this.getVariables();
	for(key in _18){_16.push(key+"="+_18[key]);}
	return _16;},getSWFHTML:function(){var _19="";
	if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
	if(this.getAttribute("doExpressInstall")){
	this.addVariable("MMplayerType","PlugIn");}
	_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
	_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
	var _1a=this.getParams();
	for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
	var _1c=this.getVariablePairs().join("&");
	if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";
	}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
	_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
	_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
	var _1d=this.getParams();
	for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
	var _1f=this.getVariablePairs().join("&");
	if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
	return _19;
	},write:function(_20){
	if(this.getAttribute("useExpressInstall")){
	var _21=new deconcept.PlayerVersion([6,0,65]);
	if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
	this.setAttribute("doExpressInstall",true);
	this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
	document.title=document.title.slice(0,47)+" - Flash Player Installation";
	this.addVariable("MMdoctitle",document.title);}}
	if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
	var n=(typeof _20=="string")?document.getElementById(_20):_20;
	n.innerHTML=this.getSWFHTML();return true;
	}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
	return false;}};
	deconcept.SWFObjectUtil.getPlayerVersion=function(){
	var _23=new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins&&navigator.mimeTypes.length){
	var x=navigator.plugins["Shockwave Flash"];
	if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
	}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
	catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
	_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
	catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
	catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
	return _23;};
	deconcept.PlayerVersion=function(_27){
	this.major=_27[0]!=null?parseInt(_27[0]):0;
	this.minor=_27[1]!=null?parseInt(_27[1]):0;
	this.rev=_27[2]!=null?parseInt(_27[2]):0;
	};
	deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
	if(this.major<fv.major){return false;}
	if(this.major>fv.major){return true;}
	if(this.minor<fv.minor){return false;}
	if(this.minor>fv.minor){return true;}
	if(this.rev<fv.rev){
	return false;
	}return true;};
	deconcept.util={getRequestParameter:function(_29){
	var q=document.location.search||document.location.hash;
	if(q){var _2b=q.substring(1).split("&");
	for(var i=0;i<_2b.length;i++){
	if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
	return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
	return "";}};
	deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
	var _2d=document.getElementsByTagName("OBJECT");
	for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){
	if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};
	deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};
	__flash_savedUnloadHandler=function(){};
	if(typeof window.onunload=="function"){
	var _30=window.onunload;
	window.onunload=function(){
	deconcept.SWFObjectUtil.cleanupSWFs();_30();};
	}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};
	if(typeof window.onbeforeunload=="function"){
	var oldBeforeUnload=window.onbeforeunload;
	window.onbeforeunload=function(){
	deconcept.SWFObjectUtil.prepUnload();
	oldBeforeUnload();};
	}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
	if(Array.prototype.push==null){
	Array.prototype.push=function(_31){
	this[this.length]=_31;
	return this.length;};}
	var getQueryParamValue=deconcept.util.getRequestParameter;
	var FlashObject=deconcept.SWFObject;
	var SWFObject=deconcept.SWFObject;

	/**
	* Control.Tabs
	* @author Ryan Johnson <http://syntacticx.com/>
	* @copyright 2008 PersonalGrid Corporation <http://personalgrid.com/>
	* @package LivePipe UI
	* @license MIT
	* @url http://livepipe.net/
	*/
	eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('5(k(l)==\'I\')l={};8 $1M=4(a){6 k(a)==\'4\'?a:4(){6 a}};8 $1N=4(a){6 k(a)==\'4\'?a():a};B.w={C:4(d){d.q=4(a){2.g=2.g||{};2.g[a]=2.g[a]||[]};d.r=4(a,b){5(k(a)==\'15\'&&k(b)!=\'I\'){2.q(a);5(!2.g[a].16(b))2.g[a].x(b)}n S(8 e 1f a)2.r(e,a[e])};d.J=4(a,b){2.q(a);5(a&&b)2.g[a]=2.g[a].1O(b);n 5(a)2.g[a]=[];n 2.g={}};d.T=4(a,b){8 c=4(){b.D(2,K);2.J(a,c)}.s(2);2.q(a);2.g[a].x(c)};d.E=4(a){2.q(a);8 b=[];8 c=$A(K).17(1);1g{S(8 i=0;i<2.g[a].1h;++i)b.x(2.g[a][i].D(2.g[a][i],c)||18)}1i(e){5(e==$U)6 o;n t e;}6 b};5(d.F){d.F.q=d.q;d.F.r=d.r;d.F.J=d.J;d.F.T=d.T;d.F.E=4(a){5(d.E){8 b=$A(K).17(1);b.1j(2);b.1j(a);d.E.D(d,b)}2.q(a);8 b=$A(K).17(1);8 c=[];1g{5(2.7&&2.7[a]&&k(2.7[a])==\'4\')c.x(2.7[a].D(2,b)||18);S(8 i=0;i<2.g[a].1h;++i)c.x(2.g[a][i].D(2.g[a][i],b)||18)}1i(e){5(e==$U)6 o;n t e;}6 c}}}};u.1P({T:4(a,b,c){8 d=4(){c.D(2,K);u.J(a,b,d)};u.r(a,b,d)}});(4(){4 V(a){8 b,h,19;5(a.1k){b=a.1k/1Q}n 5(a.1l){b=-a.1l/3}5(!b){6}h=w.C(a).1R;h=u.C(h.1S===1T.1U?h.1a:h);19=h.1V(\'1W:V\',{1X:b});5(19.1Y){w.1m(a);6 o}}W.r(\'1Z\',V);W.r(\'20\',V)})();8 21=1n.1o({1p:4(){2.h=22 u(\'23\',{24:\'25:26;27:28:29.2a.2b(2c=0);2d:2e\',2f:\'2g:2h(0);\',2i:0});$(W.2j).2k(2.h)},X:4(){2.h.X();6 2},Y:4(){2.h.Y();6 2},2l:4(a){8 a=$(a);8 b=a.2m();8 c=a.2n();2.h.1q({2o:b[0]+\'L\',2p:b[1]+\'L\',1r:c.1r+\'L\',1s:c.1s+\'L\',1t:a.2q(\'1t\')-1}).Y();6 2},2r:4(a){S(1u 1f a)a[1u]+=\'L\';2.h.1q(a);6 2},2s:4(){5(2.h)2.h.2t();6 2}});5(k(M)=="I"){t"l.p 1v M 1w 1x 1y.";}5(k(B.w)=="I"){t"l.p 1v B.w 1w 1x 1y.";}l.p=1n.1o({1p:4(d,e){5(!$(d)){t"l.p 2u 1z N 1A h: "+d;}2.O=o;2.Z=o;2.v=$H({});2.9=[];l.p.1b.x(2);2.7={1B:M.1C,1D:M.1C,1E:o,10:\'2v a\',1c:o,1d:\'2w\',11:\'P\',1F:2x,1G:/#(.+)$/,1H:u.Y,1I:u.X};B.C(2.7,e||{});(k(2.7.10==\'15\')?$(d).2y(2.7.10):2.7.10($(d))).2z(4(a){6(/^#/).1J((M.2A.2B?2C(a.y):a.y).12(G.13.y.Q(\'#\')[0],\'\'))}).z(4(a){2.1K(a)}.s(2));2.v.2D().z(u.X);5(2.7.11==\'P\'){2.j(2.9.P())}n 5(2.7.11==\'R\'){2.j(2.9.R())}n{2.j(2.7.11)}8 f=2.7.1G.1J(G.13);5(f&&f[1]){f[1].Q(\',\').z(4(b){2.j(2.9.N(4(a){6 a.m==b}))}.s(2))}5(2.7.1F){$A(W.2E(\'a\')).z(4(a){5(!2.9.16(a)){8 c=a.y.12(G.13.y.Q(\'#\')[0],\'\');5(c.1e(0,1)==\'#\'){5(2.v.2F().16(c.1e(1))){$(a).r(\'2G\',4(a,b){2.j(b.1e(1))}.2H(2,c))}}}}.s(2))}},1K:4(b){2.9.x(b);b.m=b.2I(\'y\').12(G.13.y.Q(\'#\')[0],\'\').Q(\'#\').R().12(/#/,\'\');8 c=$(b.m);5(!c){t"l.p: #"+b.m+" 2J 1z 2K 2L 1A 2M.";}2.v.2N(b.m,c);b[2.7.1E?\'2O\':\'2P\']=4(a){5(G.1L){w.1m(G.1L)}2.j(a);6 o}.s(2,b)},j:4(b){5(!b&&k(b)==\'I\'){6}5(k(b)==\'15\'){2.j(2.9.N(4(a){6 a.m==b}))}n 5(k(b)==\'2Q\'){2.j(2.9[b])}n{5(2.E(\'1B\',2.O,2.v.14(b.m))===o){6}5(2.O){2.7.1I(2.O)}2.9.z(4(a){(2.7.1c?$(a.1a):a).2R(2.7.1d)}.s(2));(2.7.1c?$(b.1a):b).2S(2.7.1d);2.O=2.v.14(b.m);2.Z=b;2.7.1H(2.v.14(b.m));2.E(\'1D\',2.v.14(b.m))}},2T:4(){2.9.z(4(a,i){5(2.Z==a&&2.9[i+1]){2.j(2.9[i+1]);t $U;}}.s(2))},2U:4(){2.9.z(4(a,i){5(2.Z==a&&2.9[i-1]){2.j(2.9[i-1]);t $U;}}.s(2))},P:4(){2.j(2.9.P())},R:4(){2.j(2.9.R())}});B.C(l.p,{1b:[],2V:4(c){6 l.p.1b.N(4(b){6 b.9.N(4(a){6 a.m==c})})}});B.w.C(l.p);',62,182,'||this||function|if|return|options|var|links|||||||_observers|element||setActiveTab|typeof|Control|key|else|false|Tabs|_objectEventSetup|observe|bind|throw|Element|containers|Event|push|href|each||Object|extend|apply|notify|prototype|window||undefined|stopObserving|arguments|px|Prototype|find|activeContainer|first|split|last|for|observeOnce|break|wheel|document|hide|show|activeLink|linkSelector|defaultTab|replace|location|get|string|include|slice|null|custom_event|parentNode|instances|setClassOnContainer|activeClassName|substring|in|try|length|catch|unshift|wheelDelta|detail|stop|Class|create|initialize|setStyle|width|height|zIndex|prop|requires|to|be|loaded|not|the|beforeChange|emptyFunction|afterChange|hover|autoLinkExternal|targetRegExp|showFunction|hideFunction|exec|addTab|event|proc|value|without|addMethods|120|target|nodeType|Node|TEXT_NODE|fire|mouse|delta|stopped|mousewheel|DOMMouseScroll|IframeShim|new|iframe|style|position|absolute|filter|progid|DXImageTransform|Microsoft|Alpha|opacity|display|none|src|javascript|void|frameborder|body|insert|positionUnder|cumulativeOffset|getDimensions|left|top|getStyle|setBounds|destroy|remove|could|li|active|true|select|findAll|Browser|WebKit|decodeURIComponent|values|getElementsByTagName|keys|click|bindAsEventListener|getAttribute|was|found|on|page|set|onmouseover|onclick|number|removeClassName|addClassName|next|previous|findByTabId'.split('|'),0,{}));

	function centerElem(elem) {
		if (!elem) return false;
		var w = getWidth(elem);
		var h = getHeight(elem);
		var position = getStyle(elem, 'position');
		if (/WebKit/i.test(navigator.userAgent)) {
			elem.style.position = 'fixed';
		}
		if (position && position == 'fixed') {
			var t = (windowHeight() /2) - (h/2);
			var l = (windowWidth() / 2) - (w/2);
		} else {
			var t = scroll_Y() +(windowHeight() /2) - (h/2);
			var l = scroll_X() + (windowWidth() / 2) - (w/2);
		}
		if (t < 0) t = 0;
		if (l < 0) l = 0;
		elem.style.top = t + "px";
		elem.style.left = l + "px";
	};
	function getStyle(elem, name) {
	        if (elem.style[name]) return elem.style[name];
	        else if (elem.currentStyle) return elem.currentStyle[name];
	        else if (document.defaultView && document.defaultView.getComputedStyle) {
	                name = name.replace(/([A-Z])/g,"-1$");
	                name = name.toLowerCase();
	                var s = document.defaultView.getComputedStyle(elem,"");
	                return s && s.getPropertyValue(name);
	        } else return null;
	};

	function pageHeight() {
		return document.body.scrollHeight;
	};
	function pageWidth() {
		return document.body.scrollWidth;
	};
	function scroll_X() {
        var de = document.documentElement;
        return self.pageXOffset || (de && de.scrollLeft) || document.body.scrollLeft;
	};
	function scroll_Y() {
	        var de = document.documentElement;
	        return self.pageYOffset || ( de && de.scrollTop) || document.body.scrollTop;
	};
	function getHeight(elem) {
	        if (getStyle(elem, 'display') != 'none')
	                return elem.offsetHeight || parseInt(getStyle(elem, 'height'));
	        var old = resetCSS(elem, {display:'block', visibility:'hidden', position:'absolute'});
	        var h = elem.clientHeight || parseInt(getStyle(elem, 'height'));
	        restoreCSS(elem, old);
	        return h;
	};
	function getWidth(elem) {
	        if (getStyle(elem, 'display') != 'none')
	                return elem.offsetWidth || parseInt(getStyle(elem, 'width'));
	        var old = resetCSS(elem, {display:'block', visibility:'hidden', position:'absolute'});
	        var w = elem.clientWidth || parseInt(getStyle(elem, 'width'));
	        restoreCSS(elem, old);
	        return w;
	};
	function resetCSS(elem, prop) {
	        var old = {};
	        for (var i in prop) {
	                old[i] = elem.style[i];
	                elem.style[i] = prop[i];
	        }
	        return old;
	};
	function restoreCSS(elem, prop) {
	        for (var i in prop)
	                elem.style[i] = prop[i];
	};
	function windowHeight() {
	        var de = document.documentElement;
	        return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
	};
	function windowWidth() {
	        var de = document.documentElement;
	        return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};
	function fadeUp(element,red,green,blue) {
		if (element.fade) {
			clearTimeout(element.fade);
		}
		element.style.backgroundColor = "rgb("+red+","+green+","+blue+")";
		if (red == 255 && green == 255 && blue == 255) {
			return;
		}
		var newred = red + Math.ceil((255 - red)/10);
		var newgreen = green + Math.ceil((255 - green)/10);
		var newblue = blue + Math.ceil((255 - blue)/10);
		var repeat = function() {
			fadeUp(element,newred,newgreen,newblue)
		};
		element.fade = setTimeout(repeat,50);
	};

	function stripTags(originalString) {
		if ( originalString ) {
			var regex_tags = /<\/?[^>]+(>|$)/g;
			var strippedString = originalString.replace(regex_tags,'');
			return strippedString;
		}
		else
			return '';
	};
	
	function prepareSearch() {
		try{
			
		if(RequestManager){
			RequestManager.request({
				url:'/ajax/data/department.xml',
				callback:function(xhr){
					var searchselect = $('searchselect');
			        if (xhr && xhr.responseXML) {
		                var rows = xhr.responseXML.documentElement.getElementsByTagName('row');
		                for (var i = 0; i < rows.length; i++) {
		                    var name = getNodeValueByChildName(rows[i], 'name');
		                    var category_id = getNodeValueByChildName(rows[i], 'cat_id');
		                    addOption(searchselect, name, category_id, false);
		                }
			        }
					var searchfor = $('searchfor');
					searchfor.onkeydown = function (e) {
						if (e && e.keyCode == 13) {
							var cleaned = this.value.strip();
							cleaned = stripTags(cleaned);
							if (cleaned.length > 2) {
								var cat_id = (searchselect.value)?searchselect.value:'';
						    	document.location.href='/search-results.html?kword='+cleaned+'&cat_id='+cat_id;
							} else {
								 alert('Please specify at least three characters');
							}
						}
					};
			        $('search-submit').onclick = function () {
						var cleaned = searchfor.value.strip();
						cleaned = stripTags(cleaned);
						if (cleaned.length > 2) {
						    var cat_id = (searchselect.value)?searchselect.value:'';
						    document.location.href='/search-results.html?kword='+cleaned+'&cat_id='+cat_id;
						} else {
						    alert('Please specify at least three characters');
						}
			        };
				}
			});
		}	
			
			
		}catch(err){
			alert(err);
			
		}
	};
	function removeDemandlet() {
		for (var i = 0; i < arguments.length; i++) {
			arguments[i].remove();
		}
	};
	var getSiteName = function () {
		var siteName = window.location.href.split('://')[1].split('/')[0];
		getSiteName = function () {
			return siteName;
		};
		return getSiteName();
	};
	function hasSiteName(kw) {
		var siteName = getSiteName();
		return ((siteName.toLowerCase().indexOf(kw.toLowerCase()) > -1)?true:false);
	};
	var getCountry = function () {
		var list = {
			CA: /(canada)/i,
			US: /(america)/i
 		};
		var cc = null;
		var siteName = getSiteName();
		for (var country in list) {
			if (siteName.match(list[country])) {
				cc = country;
				break;
			}
		}
		if(cc==null) cc='US';
		getCountry = function () { return cc; };
		return cc;
	};
	function changeFileName(pathname, prefix) {
		var arr = '';
		if (typeof pathname != 'undefined') {
			arr = pathname.split('/');
			if (arr.length) {
				arr[arr.length-1] = [prefix, arr[arr.length-1]].join('_');
				arr = arr.join('/');
			} else {
				arr = '';
			}
		}
		return arr;
	};

	function textarea_maxlength(txtObj,counter) {
		if(txtObj.getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = txtObj;
			txtObj.setAttribute('maxLen',txtObj.getAttribute('maxlength'));
			counterClone.innerHTML = '<span>0</span>/'+txtObj.getAttribute('maxlength') + ' Character Limit';
			txtObj.parentNode.insertBefore(counterClone,txtObj.nextSibling);
			txtObj.relatedElement = counterClone.getElementsByTagName('span')[0];
			txtObj.onkeyup = txtObj.onchange = check_maxlength;
			txtObj.onkeyup();
		}
	};
		
	function check_maxlength() {
		var maxLength = this.getAttribute('maxlength');
		var currentLength = this.value.length;
		if (currentLength > maxLength) {
			this.setAttribute('alert','Exceeded allowed character limit.');
			this.relatedElement.className = 'toomuch';
		}
		else {
			this.removeAttribute('alert');
			this.relatedElement.className = '';
		}
		this.relatedElement.firstChild.nodeValue = currentLength;
	};
	
	function dataCheck(resp, cbFn) {
		if (!resp || !resp.responseXML) {
			this.remove();
		} else {
			cbFn(this, resp.responseXML.documentElement);
		}
	};
	(function () {
		var site = {};
		site['US'] = {
	        title: 'America'
		};
		site['CA'] = {
	        title: 'Canada',
	        stylesheet: '/media/global/global-canada.css'
		}
		//modify title only if it's not in cart or checkout
		if (!location.href.match(/\/cart/) && !location.href.match(/\/checkout/))
			document.title = ['BBC ', site[getCountry()].title, ' Shop - ', document.title].join('');
			
		if (getCountry().toLowerCase() == 'ca') {
			var lnk = document.createElement('link');
			lnk.rel='stylesheet';
			lnk.type='text/css';
			lnk.href=site.CA.stylesheet;
			var headTag = document.getElementsByTagName('head')[0];
			headTag.appendChild(lnk);
		}
	})();
	//News Letter Sign-up
	function newsletter_signup(f_panel,f_field,s_resp){
		if(!f_panel) return false;
		else submit_newLetter(f_panel,s_resp);
	};

	var newsletterEmail;
	
	function submit_newLetter(formObj,responseElem){

		if (!formObj) return false;
		var params = formObj.serialize(true);

	

		if (isValidEmail(params.fromEmail)) {

				params.nC=noCache();
				params.email=params.fromEmail;
				params.site_id = (getCountry()=='US') ? 1 : 2;

				new Ajax.Request(

					'/ajax/newsLetterSignup.jsp',

					{

						parameters: params,
						onComplete: function(xml){

							Element.hide(formObj);

							if (responseElem){

								if(!xml.responseXML) {
									responseElem.innerHTML = responseElem.innerHTML.replace('<!--response-->','Sorry there was a problem with your request. Please try again later.');
								} else {

									var xmlNode = xml.responseXML.documentElement;
									var responseContent = responseElem.innerHTML;
									
									if (xmlNode.firstChild.nodeValue.toLowerCase().indexOf('success') > -1) {

										responseElem.innerHTML = responseContent.replace('<!--response-->','Thank you for signing up for the newsletter!');
										
										var suggestAccount = $('suggest-account-creation');
										suggestAccount.show();
										
											newsletterEmail = params.fromEmail;
											
											$('create-acct-btn').observe('click', function(e) {
												
												Event.stop(e);
												
												var lk = $('create-acct-btn');
												var lb = new lightbox(lk, {oncomplete: function () {
										
													$('new_email').value 			= newsletterEmail;
													$('new_email_confirm').value	= newsletterEmail;
										
													var optinInput = document.createElement('input');
													optinInput.type = 'hidden';
															
													$('cform').appendChild(optinInput);
												
													var createBtn = $('create-btn');
														if (createBtn) {
															createBtn.onclick = function () {
																createAccount(this.form);
														}
												}
												}});
										
												lb.activate();
												lb.removeListener(true);
												
											});	
											
									}
									
									else { 
										responseElem.innerHTML = responseContent.replace('<!--response-->','Sorry there was a problem with your request. Please try again later.');
										$('#suggest-account-creation').hide();
									}

								}
								Element.show(responseElem);

							}
						}
					}
				);

		} else {
			alert('Email is not a valid email address.');
		}

	};
	// end of News Letter Sign-up
	
	// Suggest a title
	function submit_SuggestTitle(formObj,responseElem){
		if (!formObj) return false;
		var params = formObj.serialize(true);
		params.nC=noCache();
		params.site_id = (getCountry()=='US')? 1 : 2;
		params.type='suggestTitle';
		if (checkForm(formObj)){
			new Ajax.Request(
				'/ajax/sendEmail.jsp',
				{
				parameters: params,
				onComplete: function(xml){
					Element.hide(formObj);
					if (responseElem) {
						if(!xml.responseXML) responseElem.innerHTML = responseElem.innerHTML.replace('<!--response-->','Sorry there was a problem with your request. Please try again later.');
						else {
							var response = xml.responseXML.getElementsByTagName(get_firstchild(xml.responseXML.documentElement).nodeName);
							var responseContent = responseElem.innerHTML;
							if (getNodeValue(response[0]) == 'success') responseElem.innerHTML = responseContent.replace('<!--response-->','Thank you, your suggestion has been sent.');
							else responseElem.innerHTML = responseContent.replace('<!--response-->','Sorry there was a problem with your request. Please try again later.');
							}
						Element.show(responseElem);
						}
					}
				}
			);
		}
	};
	//Submit Send To Friend
   function submit_FriendPopup(formObj,responseElem){
		if (!formObj) return false;
		if (checkForm(formObj)) {
			var params = formObj.serialize(true);
			params.nC = noCache();
			var loc = window.opener.location.href;
	        params.link = loc;
	        params.site_id = (getCountry()=='US')? 1 : 2;
			new Ajax.Request(
				'/ajax/sendFriend.jsp', 
				{
					parameters: params,
					onComplete: function(xml){
						Element.hide(formObj);
						if (responseElem) {
							if(!xml.responseXML){
								responseElem.innerHTML = responseElem.innerHTML.replace('<!--response-->','Sorry there was a problem with your request. Please try again later.');
								}
								else {
									var response = xml.responseXML.getElementsByTagName(get_firstchild(xml.responseXML.documentElement).nodeName);
									var responseContent = responseElem.innerHTML;
									if (getNodeValue(response[0]) == 'success') 
										responseElem.innerHTML = responseContent.replace('<!--response-->','Thank you, your message has been sent.');
									else
										responseElem.innerHTML = responseContent.replace('<!--response-->','Sorry there was a problem with your request. Please try again later.');
									}
								Element.show(responseElem);
						}
					}
				});
		}
	};
	//Contact Us
	function submit_ContactUs(formObj,responseElem, errorElemnt){
		if(!formObj) return false;
		var params = formObj.serialize(true);
		if ($F('subject')=="Question about my order"){
			params.service_by='nfs';			
		}else{
			params.service_by='customerservice';			
		};
		params.nc=noCache();
		params.site_id = (getCountry()=='US')? 1 : 2;
		params.type='contactUs';
		if(checkForm(formObj)){		
			new Ajax.Request(
				'/ajax/sendEmail.jsp',{
				parameters: params,
				onComplete: function(xml){
					Element.hide(formObj);
					if(!xml.responseXML){
							Element.show(errorElemnt);
						} Element.show(responseElem);
					
					}
				}
			);
		}
	};
	//end of Contact Us

	function changeControlScans(elem, type) {
		if ($(elem)) {
			var o = {};
			o.US = {};
			o.CA = {};
			o.US.checkout = {
				anchor: 'https://www.controlscan.com/seal/verify5.php?id=149&dom=32A6091C',
				img: 'https://www.controlscan.com/seal/sealx5.php?id=149&dom=32A6091C'
			};
			o.CA.checkout = {
				anchor: 'https://www.controlscan.com/seal/verify5.php?id=149&dom=AA27AAFE',
				img: 'https://www.controlscan.com/seal/sealx5.php?id=149&dom=AA27AAFE'
			};
			o.US.noncheckout = {
				anchor: 'http://www.controlscan.com/seal/verify5.php?id=149&dom=32A6091C',
				img: 'http://www.controlscan.com/seal/sealx5.php?id=149&dom=32A6091C'
			};
			o.CA.noncheckout = {
				anchor: 'http://www.controlscan.com/seal/verify5.php?id=149&dom=AA27AAFE',
				img: 'http://www.controlscan.com/seal/sealx5.php?id=149&dom=AA27AAFE'
			};
			//if(document.getElementById('cscan-seal')) $('cscan-seal').style.visibility='hidden';
			$(elem).href = o[getCountry()][type]['anchor'];
			if ($(elem).firstChild) {
				$(elem).firstChild.src = o[getCountry()][type]['img'];
			}
		}
	};
	function changeCountryLinks(elems) {
		if (elems && elems.length) {
			$A(elems).each(function(elem) {
				if (elem.href) {
					var pieces = elem.href.split('.');
					pieces[pieces.length-2] = pieces[pieces.length-2]+'_'+getCountry().toLowerCase();
					elem.href = pieces.join('.');	
				} else {
					var lnks = elem.getElementsByTagName('a');
					$A(lnks).each(function(lnk) {
						if (lnk.id != 'cscan_country') {
							var pieces = lnk.href.split('.');
							pieces[pieces.length-2] = pieces[pieces.length-2]+'_'+getCountry().toLowerCase();
							lnk.href = pieces.join('.');
						}	
					});
				}
			});
		}
	};
	function createOrder(orderNode) {
		var order = {};
		order['OrderNumb'] = getNodeValueByChildName(orderNode, 'OrderNumb');
		order['Clubid'] = getNodeValueByChildName(orderNode, 'Clubid');
		order['AddressInfo'] = {};
		order['OrderStatus'] = {};
		order['OrderStatus']['Item'] = {};
		var orderStatus = orderNode.getElementsByTagName('OrderStatus');
		orderStatus = orderStatus.length && orderStatus[0];
		if (orderStatus) {
			order['OrderStatus']['Response'] = getNodeValueByChildName(orderStatus, 'Response');
			if (order['OrderStatus']['Response'] && /failure/i.test(order['OrderStatus']['Response'])) {
				order['OrderStatus']['Reason'] = getNodeValueByChildName(orderStatus, 'Reason');
				return order;
			}
			for (var i = 0; i < orderStatus.childNodes.length; i++) {
				if (orderStatus.childNodes[i].nodeType == 1) {
					var child = orderStatus.childNodes[i];
					if (child.nodeName == 'Tracking') {
						if (!order['OrderStatus']['Tracking']) {
							order['OrderStatus']['Tracking'] =  [];
						}
						order['OrderStatus']['Tracking'].push(new XmlToObj(child));
					} else if (child.nodeName == 'Item') {
						var itemNum = child.getAttribute('num');
						if (itemNum) {
							order['OrderStatus']['Item'][itemNum] = new Item(child);
						}
					} else {
						order['OrderStatus'][child.nodeName] = getNodeValueByChildName(orderStatus, child.nodeName);
					}
				}
			}
		}
		$A(orderNode.getElementsByTagName('AddressInfo')).each(function (addr) {
			var addrType = addr.getAttribute('type');
			if (addrType) {
				order['AddressInfo'][addrType] = new XmlToObj(addr);
			}
		});
		return order;
	};
	function XmlToObj(rootNode) {
		var x = rootNode.getElementsByTagName('*');
		for (var i = 0; i < x.length; i++) {
			if (x[i].nodeType == 1) 
				this[x[i].nodeName] = x[i].firstChild && x[i].firstChild.nodeValue;
		}
	};
	function Item(rootNode) {
		var x = rootNode.getElementsByTagName('*');
		for (var i = 0; i < x.length; i++) {
			if (x[i].nodeType == 1) 
				this[x[i].nodeName] = x[i].firstChild && x[i].firstChild.nodeValue;
		}
	};
	Item.prototype.getStatusMsg = function () {
		var statusMsg = '';
		switch (this.Status) {
			case '01':
			case '02':
			case '03':
			case '04':
			case '05':
			case '06':
			case '07':
				statusMsg = "Your order is being processed.";
				break;
			case '08':
				statusMsg = "There's a slight problem with your order. Your billing address does not match the credit card information provided. Please check your e-mail for a message from us with instructions for correcting this problem.";
				break;
			case '09':
				statusMsg = "There's a slight problem with your order. We were unable to process your payment due to an insufficient balance on your credit card. Please check your e-mail for a message from us with instructions for correcting this problem.";
				break;
			case '12':
			case '13':
				statusMsg = "Your order is being processed.";
				break;
			case '20':
			case '22':
			case '23':
			case '24':
			case '25':
				var d = new Date(this.BKODate.split('T').join(' ').split('-').join('/'));
				statusMsg = "This item will be available after "+ monthName(d) + ' ' + d.getDate() + ', ' + d.getFullYear()
				break;
			case '21':
				statusMsg = "Shipment delayed. One or more items on backorder will be available soon, so we will ship the order once all items are in stock.";
				break;
			case '28':
			case '29':
				statusMsg = "This order has been successfully cancelled.";
				break;
			case '30':
			case '31':
			case '32':
			case '33':
				statusMsg = "This order is being processed.";
				break;
			case '40':
			case '42':
			case '43':
				statusMsg = "Your order has been shipped.";
				break;
			case '50':
				statusMsg = "Your exchange item has been received. ";
				break;
			case '60':
				statusMsg = "Your return item has been received and your account has been credited.";
				break;
			case '61':
				statusMsg = "Your exchange item has been received."
				break;
		}
		return statusMsg;
	};
	
	function renderOptins(dObj) {
		try{
			RequestManager.request({
				url:'/ajax/data/optin.xml',
				callback:function(xhr){
					if (xhr && xhr.responseXML) {
						var rows =  xhr.responseXML.documentElement.getElementsByTagName('row');
						for (var i = 0; i < rows.length; i++) {
							var optin = (function (row) {
											var optinObj = {};
											var fields = row.getElementsByTagName('*');
											for (var i = 0; i < fields.length; i++) {
												optinObj[fields[i].nodeName] = getNodeValueByChildName(row, fields[i].nodeName);
											}
											return optinObj;
										})(rows[i]);
							dObj.appendChild(Builder.node('input', { type: 'checkbox', id:'optin_'+optin.optin_id }));
							dObj.appendChild(Builder.node('span', {className:'optin-text'}, [optin.display_text]));
							if (optin.is_required == 1) {
								var req = Builder.node('span', {className:'required'}, ["(required)"]);
								dObj.insertBefore(req, $('optin_'+optin.optin_id));
								$('optin_'+optin.optin_id).setAttribute('required', 'required');
								$('optin_'+optin.optin_id).setAttribute('alert', 'You must check the '+optin.name+' checkbox');
							}
						}
					}
				}	
			});
		}catch(err){
			alert(err)
		}
		
	};
	
	//ip_human.js
	var userManager = Class.create();
	userManager.prototype = {
		initialize: function(options) {
			this.person = new CookieJar('life',{  
			    expires:dateAdd('d', 90, new Date() ),     
			    path:'/'
			}); 
			this.url 		= '/ajax/account.jsp';
			this.cookieName = 'credentials';
			this.$required 	= 500.00;
		},
	
		create: function(formObj,options) {
			var storeId = getCountry();
			var today = new Date(getServerTime());
			var minDate = today.getFullYear() - 110;
			var maxDate = today.getFullYear() - 13;
			storeId = (storeId=='US') ? 'USA' : 'CAN' ;	
			this.options = {};Object.extend(this.options, options || {});
			var formParams = Form.serialize(formObj, true);
			if(checkForm(formObj)) {
				var errFlag = false;
				if($F('new_email')!=$F('new_email_confirm')) {
					alert('The email addresses do not match. Please try again.');
					errFlag = true;
				}
				else if($F('new_password')!=$F('new_password_confirm')) {
					alert('The passwords do not match. Please try again.');
					errFlag = true;
				} else if((formParams.birthday_mm != 'MM' && formParams.birthday_mm != '')
						  || (formParams.birthday_dd != 'DD' && formParams.birthday_dd != '')
						  || (formParams.birthday_yyyy != 'YYYY' && formParams.birthday_yyyy != '')) {
					if(!(parseInt(formParams.birthday_mm) <= 12) || !(parseInt(formParams.birthday_mm) > 0)) {
						alert('Month must be between 1 and 12.');
						errFlag = true;
					} else if(!(parseInt(formParams.birthday_dd) <= 31) || !(parseInt(formParams.birthday_dd) > 0)) {
						alert('Day must be between 1 and 31.');
						errFlag = true;
					} else if(!(parseInt(formParams.birthday_yyyy) <= maxDate) || !(parseInt(formParams.birthday_yyyy) > minDate)) {
						alert('Year must be between ' + minDate + ' and ' + maxDate + '.');
						errFlag = true;
					} else {
						formParams['birthday'] = formParams.birthday_yyyy + '-' + formParams.birthday_mm + '-' + formParams.birthday_dd;
						delete formParams.birthday_yyyy;
						delete formParams.birthday_mm;
						delete formParams.birthday_dd;
					}
				}
				
				if(errFlag==false) {
					var optinIds = [];
					$H(formParams).keys().each( function (key) {
						if (key.indexOf('optin_') > -1)
							optinIds.push(key.split('_')[1]);
					});
					if (optinIds.length) 
						formParams.optin_ids = optinIds.join(',');
					formParams.newAccount = 1;
					formParams.nc = noCache();
					formParams.StoreID = storeId;
					new Ajax.Request(this.url, {
							parameters: formParams,
							onComplete: this.create_complete.bindAsEventListener(this,
																					{
																					onComplete:this.options.onComplete,
																					onFailure:this.options.onFailure
																					})
						});
				}
			}
		},

		create_complete: function(response,options) {
			this.options = {};Object.extend(this.options, options || {});
			var x = response.responseXML.getElementsByTagName('user_id');
			if(x.length>0) {
				var email		= $F('new_email');
        var password = $F('new_password');
				this.login_with_rails(email, password, false, options);
			}
			else {
				if(this.options.onFailure) 
					eval(this.options.onFailure);
				else {
					var x = response.responseXML.getElementsByTagName('response');
					alert(getNodeValue(x[0]));
				}	
			}
		},	

		createGuest: function(formObj) {
			if(checkForm(formObj)) {
				var errFlag = false;
				if($F('new_email')!=$F('new_email_confirm')) {
					alert('The email addresses do not match. Please try again.');
					errFlag = true;
				}
				else if($F('new_password')!=$F('new_password_confirm')) {
					alert('The passwords do not match. Please try again.');
					errFlag = true;
				}
				if(errFlag==false) {
					var formParams = Form.serialize(formObj) + '&email='+$F('new_email')+'&password='+$F('new_password');
					new Ajax.Request(
					  this.url, {method: 'post', parameters: formParams + 'newAccount=1&nc='+noCache(), onComplete: this.create_complete.bindAsEventListener(this)}
			   		);
				}
			}
		},
						
		update: function(formObj,options) {
			this.options = {};Object.extend(this.options, options || {});	
			if (checkForm(formObj)) {
				var param_str = '';
				var emailStr = $('new_email').value.strip();
				if (emailStr.length > 0) {
					if (isValidEmail(emailStr)) {
						param_str += ('&newEmail='+emailStr);
					} else {
						alert('Email is not a valid email address.');
						return;
					}
				}
				var newPasswd = $('new_password').value.strip();
				if (newPasswd.length > 5 && newPasswd.length < 16) {
					var confirmPasswd = $('new_password_confirm').value;
					if (newPasswd == confirmPasswd) {
						param_str += ('&newPassword='+newPasswd);
					} else {
						alert('Make sure Confirm Password matches Password.');
						return;
					}
				} else if (newPasswd.length > 0) {
					alert('Password must be between 6 to 15 characters.');
					return;
				}
				var optinIds = [];
				var optinCount = 0;
				formObj.getInputs('checkbox').each( function(chkbox) {
					if (chkbox.id.indexOf('optin_') > -1) {
						++optinCount;
					 	if (chkbox.checked) {
							optinIds.push(chkbox.id.split('_')[1]);
						}
					}
				});
				if (optinCount > 0 && optinIds.length == 0) {
					param_str += '&optin_ids=';
				} else if (optinIds.length) {
					param_str += ('&optin_ids='+optinIds.join(','));
				}
				if (param_str) {
					var updateParams = param_str +'&email=' + this.getEmail();
					new Ajax.Request(this.url, {
							parameters: updateParams + '&modifyAccount=1&nc='+noCache(), 
							onComplete: this.update_complete.bindAsEventListener(this,
																					{
																					onComplete:this.options.onComplete,
																					onFailure:this.options.onFailure
																					})
						});
				}
			}
		},
		
		update_complete: function(response,options) {
			this.options = {};
			Object.extend(this.options, options || {});
			var userid = this.getUserId();
			var x = response.responseXML.getElementsByTagName('user_id');
			var y = response.responseXML.getElementsByTagName('response');
			var firstName	= this.getFirstName();
			var lastName	= this.getLastName();
			if((x.length>0) || (getNodeValue(y[0]) == "Updated Successfully")) {				
				this.set(this.cookieName,{
						id:userid,
						firstname:firstName,
			 			lastname:lastName,
						email:$F('new_email') || this.getEmail()
					});
				
				var totalSpent = parseFloat(this._getSpentAmount());
				//don't allow negative values.
				totalSpent = (totalSpent > 0 ? totalSpent : 0);
				
				var leftToSpend	= ((totalSpent > this.$required) ? 0 : (this.$required - totalSpent));
				
				this.set(this.cookieName,{
						id:userid,
						firstname:firstName,
			 			lastname:lastName,
						email:$F('new_email') || this.getEmail(),
						leftToSpend: leftToSpend
					});
					alert(getNodeValue(y[0]));
				if(this.options.onComplete) eval(this.options.onComplete);
			}
			else  {
				if(this.options.onFailure) 
					eval(this.options.onFailure);
				else {
					var x = response.responseXML.getElementsByTagName('response');
					alert(getNodeValue(x[0]));
				}	
			}
		},	

		display: function(id) {},

		login: function(formObj,optionalParams) {
			if(checkForm(formObj)) {
				var options = {};Object.extend(options, optionalParams || {});
        var email = formObj.email.value;
        var password = formObj.password.value;
        var remember = formObj['remember-me'].checked
        this.login_with_rails(email, password, remember, options);
			}
		},
    
    login_with_rails: function(email, password, remember, options) {
      var data = {email: email, password: password, cachee: noCache()};
      if (remember) data['remember'] = true;
      
      new Ajax.Request('/login', {
					parameters:  data, 
					onComplete: this.login_complete.bindAsEventListener(this,
																		{
																			onComplete: options.onComplete,
																			onFailure: options.onFailure
																		})}
		   		);
    },
		
		login_complete: function(response,optionalParams) {
      if (response.responseJSON)
        response = response.responseJSON;
			
			if(response.error == null) {
				if(options.onComplete) { eval(options.onComplete); }
        else { location.href = location.pathname; }
			} else {
				if(options.onFailure) 
					eval(options.onFailure);
				else {
					alert(response.error.message);
				}	
			}
		},
					
		logout: function(optionalParams) {
			/**var options = {};Object.extend(options, optionalParams || {});
			this.person.remove(this.cookieName);
			if(options.onComplete) eval(options.onComplete);
      */
      location.href = '/login/logout';
		},

		check: function() {
			if(this.person.get(this.cookieName))
				return true;
			else	
				return false;
		},
		
		_getSpentAmount: function(){
			var amountSpend = 0;
			
			new Ajax.Request('/ajax/order.jsp', {
				parameters: ('loyaltyMemberCheck=1&StoreID=' + (getCountry()=='US' ? 'USA' : 'CAN') + '&nc='+noCache()),
				asynchronous: false,
				onComplete: function(xhr){
					amountSpend = getNodeValue(xhr.responseXML.getElementsByTagName('response')[0]);
				}
			});
			
			amountSpend = (Math.round(parseFloat(amountSpend) * 100) / 100).toFixed(2);
			return amountSpend;
		},
		
		getUserId: function() {
			return this.person.get(this.cookieName).id;
		},
		
		getFirstName: function() {
			return this.person.get(this.cookieName).firstname;
		},
		
		getLastName: function() {
			return this.person.get(this.cookieName).lastname;
		},
		
		getPenname: function () {
			return this.person.get(this.cookieName).penname;
		},
		
		getName: function() {
			return this.person.get(this.cookieName).firstname + ' ' + this.person.get(this.cookieName).lastname;
		},
		
		getEmail: function() {
			return this.person.get(this.cookieName).email;
		},
		
		isReturningLoyal: function() {
			return (parseFloat(this._getSpentAmount()) >= this.$required);
		},
		
		getLeftToSpend: function(refresh){
			var leftToSpend = this.person.get(this.cookieName).leftToSpend;
			if(leftToSpend == undefined)
				leftToSpend = this.$required;
			//recalculate
			if(refresh){
				var totalSpent = parseFloat(this._getSpentAmount());
				totalSpent = (totalSpent > 0 ? totalSpent : 0);
				
				leftToSpend	= ((totalSpent > this.$required) ? 0 : (this.$required - totalSpent));
				
			}
			if(cart){
				var promoAmount = 0;
				var promo = new promoManager();
				var promoObjects = promo.getContentObj();
				for(var promoName in promoObjects)
					promoAmount += parseFloat(promoObjects[promoName].amount);
					
				leftToSpend -= (parseFloat(cart.getSubTotal()) - parseFloat(promoAmount));
			}
			leftToSpend = (Math.round(leftToSpend * 100) / 100).toFixed(2);
			return (leftToSpend <= 0 ? 0 : leftToSpend);
		},
		
		isAlmostLoyaltyMember:function(refresh){
			//utility function to show if user is close to qualify as loyalty member
			return (this.check() && this.getLeftToSpend(refresh) <= 100);
		},
		
		isLoyaltyMember: function(refresh){
			return (this.check() && this.getLeftToSpend(refresh) <= 0);
		},
		
		forgotPassword: function() {
			var hrf = $('forgotpass');		
			new lightbox(hrf, {oncomplete: function () {				
				var resetBtn = $('resetpw-btn');
				if (resetBtn) {
					resetBtn.onclick = function () {								
						submitPasswordReset(this.form);
					}
				}
						
			}});
			
		},
		
		resetPassword: function(formObj,optionalParams) {
			var storeIds=(getCountry()=='US') ? 'USA' : 'CAN';		
			if(checkForm(formObj)) {
				var options = {};Object.extend(options, optionalParams || {});
				new Ajax.Request('/ajax/account.jsp',  { 
					parameters: Form.serialize(formObj)+'&resetPaswd=1&StoreID=' + storeIds + '&nc='+noCache(), 
					onComplete: this.resetPass_complete.bindAsEventListener(this,{
						onComplete: options.onComplete,
						onFailure: options.onFailure})
					});
			}
		},

		resetPass_complete: function(response,options) {			
			this.options = {};			
			Object.extend(this.options, options || {});			
			var x = response.responseXML.getElementsByTagName('response');		
			if(getNodeValue(x[0]) == 'Password has been sent in e-mail'){				
				if(this.options.onComplete) eval(this.options.onComplete);
			}
			else {				
				if(this.options.onFailure) {	
					eval(this.options.onFailure);
				} 
				else {
					var x = response.responseXML.getElementsByTagName('response');
					alert(getNodeValue(x[0]));
					 //$('errEmailResponse').innerHTML= getNodeValue(x[0])
				}	
			}
			
		},
		
		getCountry: function() {
			return this.person.get(this.cookieName).country;
		},
				
		set: function(id,object) {
			try {	
				this.object = {};
				Object.extend(this.object, object || {});
				if(this.person.put(id,this.object))
					return true;
				else
					return false;
			}
			catch(err) {
				return false;
			}
		}	
	};

	//sign.js
	function myAccountLink() {
		var user= new userManager();
		if (user.check()){
			
			$("myaccount").innerHTML = '<a href="/my-account/">My Account</a>|';
			if (window.location.href.indexOf('my-account') > -1) {
				if ($("left_myaccount")) 
					$("left_myaccount").innerHTML = '<h3><a href="/my-account/">MY ACCOUNT</a></h3>';
			}else if(urlHasParam(topNavParams.myaccount))
				window.location.href = '/my-account/';
			else if(urlHasParam(topNavParams.wishlist))
				window.location.href = '/my-account/?loadWish=_all';
			
			var wishlistLnk = $('mywishlist-link');
			if (wishlistLnk) 
				wishlistLnk.innerHTML = '<a href="/help/free-shipping_' + getCountry().toLowerCase() + '.html">FREE Shipping for Life</a><span>|</span>';
		}
		else {
			$("myaccount").innerHTML = '<a id="accountSignIn" class="account-signinlnk" href="/ajax/layouts/signinGeneralLayout.html">My Account</a>|';
			var wishlistLnk = $('mywishlist-link');
			if (wishlistLnk) 
				wishlistLnk.innerHTML = '<a class="account" rel="wishlist" href="/help/free-shipping_' + getCountry().toLowerCase() + '.html">FREE Shipping for Life</a><span>|</span>';
			var dummyLink = '<a style="display:none;" rel="wishlist" class="account-signinlnk" href="/ajax/layouts/signinGeneralLayout.html">Dummy</a>';
			$("myaccount").innerHTML += dummyLink;
			
			var signins = $('accountbar').getElementsByClassName('account-signinlnk');
			var signinsLightBoxes = {
				'myAccount': '',
				'wishList':''
			}
			for (var i = 0; i < signins.length; i++) {
				var thislnk = signins[i];
				var signInLightBox = new lightbox(thislnk, {	oncomplete: (function () {
					var rel = thislnk.rel;
					return function () {
						Form.Element.focus('email');
						var loginBtn = $('login-btn');
						if (loginBtn) {
							loginBtn.onclick = function () {
								var flag = true;
								if (rel == 'wishlist') {
									var loadWish = true;
								}
								signInSubmit(this.form, flag, loadWish);
							};
							var lk = $('createaccount');	
							new lightbox(lk, {oncomplete: function () {						
								Form.Element.focus('FirstName');
								var createBtn = $('create-btn');
								if (createBtn) {
									createBtn.onclick = function () { 
										var flag = true;	
										createAccount(this.form, flag);
									}
								}
							}});
							var hrf = $('forgotpass');		
							new lightbox(hrf, {oncomplete: function () {						
								Form.Element.focus('email');		
								var resetBtn = $('resetpw-btn');
								if (resetBtn) {
									resetBtn.onclick = function () {								
										submitPasswordReset(this.form);
									}
								}
							}});
						} // following line breaking close functionality - id trying to set returns null
						//   $('errEmailResponse').innerHTML= getNodeValue(x[0]);
					
					} 
				})()
			}); // lighbox
			
				if(thislnk['rel'] != 'wishlist')
					signinsLightBoxes['myAccount'] = signInLightBox;
				else
					signinsLightBoxes['wishList'] = signInLightBox;
					
				//show myaccount light box if url contains #gotomyaccount
				if(urlHasParam(topNavParams.myaccount))
					forceShowLightBox(signinsLightBoxes['myAccount']);
				else if(urlHasParam(topNavParams.wishlist))
					forceShowLightBox(signinsLightBoxes['wishList']);
				
			}  // for loop 
		}
		signInTxt();
	};
	
	function signInTxt(){
		var user= new userManager();
		if (user.check()==true){
			$("signin").innerHTML = '<span style="color:#fff">Welcome ' + user.getFirstName() + '!</span>|' +
				'<a href="#" id="log-out" onclick="signOut()">Logout</a>|';		
		}
		else {
			var shop=(getCountry()=='US') ? 'America' : 'Canada';
			$("signin").innerHTML = '<a id="sign-in" href="/ajax/layouts/signinGeneralLayout.html" class="btn-hdrsignin">Login</a>|' +
				'<a id="create-account" href="/ajax/layouts/createAccount.html" >Register</a>|';
			var lk = $('create-account');		
			new lightbox(lk, {oncomplete: function () {
				Form.Element.focus('FirstName');
				var createBtn = $('create-btn');
				if (createBtn) {
					createBtn.onclick = function () { 
						createAccount(this.form);
					}
				}
			}});	
			var lnk = $('sign-in');
			var signInLightBox = new lightbox(lnk, {oncomplete: function () {
				Form.Element.focus('email');	
				var loginBtn = $('login-btn');
				if (loginBtn) {
					loginBtn.onclick = function () { 
						signInSubmit(this.form);
					}
				
					var lk = $('createaccount');		
					new lightbox(lk, {oncomplete: function () {
					Form.Element.focus('FirstName');	
						var createBtn = $('create-btn');
						if (createBtn) {
							createBtn.onclick = function () { 
								createAccount(this.form);
							}
						}
					}});
						
					var hrf = $('forgotpass');		
					new lightbox(hrf, {oncomplete: function () {
						Form.Element.focus('email');	
						var resetBtn = $('resetpw-btn');
						if (resetBtn) {
							resetBtn.onclick = function () { 								
								submitPasswordReset(this.form);
							}
						}
								
					}});			
				}
			}});
			
			//expose global function to show sign in modal.
			window['showUserSignInModal'] = function(){
				if(user.check()==false)
					signInLightBox.activate();
			}
			
			//show sign in light box if url contains #showsignin
			if(urlHasParam(topNavParams.signin))
				forceShowLightBox(signInLightBox);
		}	
	};
	
	function urlHasParam(searchParam){
		if(searchParam[0] !== '#')
			searchParam = '#'+searchParam;
		var urlParam = location.href.match(/\#\w+/g);
		
		if(!urlParam) return false;
		
		for(var param = 0; param < urlParam.length; param++)
			if(urlParam[param] === searchParam)
				return true;
			
		return false;
	}
	
	function forceShowLightBox(lightboxInstance){
		try{
			lightboxInstance.activate();
		}catch(e){
			setTimeout(function(){forceShowLightBox(lightboxInstance)}, 0);
		}
	}
	
	function signinComplete(){		
		signInTxt();
		myAccountLink();
		deactivateLBinstance();	
	};
	
	function signInSubmit(fObj, flag, loadWish) {
		var user= new userManager();
		if (loadWish) {
			user.login($('loginForm'),{onComplete:'signinComplete(); if ('+flag+') window.location.href="/my-account/?loadWish=_all"'});
		} else {
			user.login($('loginForm'),{onComplete:'signinComplete(); if ('+flag+') window.location.href="/my-account/"'});
		}
		return true;
	};
	
	function signOut() {
		var user= new userManager();
		user.logout();
		signInTxt();
		myAccountLink();
		if (window.location.href.indexOf('my-account') > -1) 
			signOutRedir();
	};
	
	function signOutRedir() {
		window.location.href='/';
	};
		
	function signCreate() {
		var lk = $('createaccount');	
		new lightbox(lk, {oncomplete: function () {
			var createBtn = $('create-btn');
			if (createBtn) {
				createBtn.onclick = function () { 
					createAccount(this.form);
				}
			}
		}});
		if(cartLightBox) cartLightBox.deactivate();
		return false;
	};
	
	function createAccount(fObj, flag) {
		var user = new userManager();
		user.create($('cform'),{onComplete:'createComplete(); if ('+flag+') window.location.href="/my-account/"'});
		return false;
	};
	
	function createComplete(){		
		signInTxt();
		myAccountLink();
		deactivateLBinstance() 
	};
	
	function deactivateLBinstance() {
		if(cartLightBox) cartLightBox.deactivate(this);		
	};
	
	function submitPasswordReset(fObj) {
		var user = new userManager();
		$('errEmailResponse').setStyle({display: 'block'});
		
		user.resetPassword($('fpForm') ,{
			onComplete:'submitPasswordResetComplete()',
			onFailure: '$(\'errEmailResponse\').innerHTML = \'<p>Sorry but we did not recognize that e-mail address. Please try again.</p>\';'
			});
		return false;
	};
	
	function submitPasswordResetComplete(){
		$$('.forgotpassword-container')[0].innerHTML = '<h1>Thank you</h1><p>Your password has been sent.</p>';		
		setTimeout ( "if(cartLightBox) cartLightBox.deactivate(this);", 5000 );
	};

// track Shipping Order
function checkGuestOrders(container) {
	if ($(container)) {
		var formObj = $('non-registered');
		if (formObj) {
			var errorMsg = [];
			formObj.getInputs('text').each(function(input) {
				if (/email/i.test(input.name)) {
					if (!isValidEmail(input.value)) 
						errorMsg.push(input.name + ' is not valid.');
				}
				if (input.value.length == 0) 
					errorMsg.push(input.name + ' is blank.');
			});
			if (errorMsg.length) {
				alert('Please correct the following:\n' + (function() {
					var txt = '';
					for (var i = 0; i < errorMsg.length; i++) {
						txt += (i+1)+') The '+ errorMsg[i] + '\n';
					}
					return txt;
				})());
			} else {
				var params = formObj.serialize(true);
				params = {email: params['email address'].strip(), order_number: params['order number'].strip()};
				checkOrderStatus(params, $(container));
				
			}
		}
	} else
		alert("Sorry we're unable to process your request at this time."); 
};
function checkOrderStatus(params, container) {
	var storeIds = { US: 'USA', CA: 'CAN' };
	var orderParams = {
		orderStatus: 1,
		StoreID: storeIds[getCountry()]
	};
	orderParams.email = params['email'];
	orderParams.OrderNumb = params['order_number'];
	orderParams.is_guest = 1;
	new Ajax.Request(
		'/orders/status',
		{
			parameters: orderParams,
			onLoading: function () {
				showLbLoading();
			},
			onComplete: function (xhr) {
				if (xhr && xhr.responseXML) {
					var rootNode = xhr.responseXML.documentElement;
					if (/order/i.test(rootNode.nodeName)) {
						var order = createOrder(xhr.responseXML.documentElement);
						if (order.OrderStatus.Response && /failure/i.test(order.OrderStatus.Response)) {
							removeLbLoading();
							alert('Order number not found.');
						}
						else {
							renderMarkup(container, function(){
								displayContents(order);
							});
						}
					}
					else {
						removeLbLoading();
						alert('Account information not found.');
					}
				} else {
					removeLbLoading();
				}
			}
		}
	);
};
function renderMarkup(container, cb) {
	
	new Ajax.Request('/ajax/layouts/trackOrderLayout.html', {
			onSuccess: function (xhr) {
				if (xhr && xhr.responseText) {
					container.innerHTML = xhr.responseText;
					if (cb) cb();
				} 
			},
			onComplete: function () {
				removeLbLoading();
			}
		}
	);
};
function displayContents(order) {
	displayOrderInfo(order);
	displayAddress(order.AddressInfo.ship, 'shipping_address');
	displayAddress(order.AddressInfo.bill, 'billing_address');
	displayCreditCard(order, 'paymentDetails');
	displayShippingMethod(order);
	setPrintInvoice();
	displayItems(order);
	displayTotals(order);
};
function setTrackingLink(tracking) {
    var lnk = $$('a[class*="trackshipment"]');
	if (tracking.CarrierLink) {
    	lnk[0].href = tracking.CarrierLink;
    	lnk[0].onclick = function() { window.open(this.href); return false; }
	} else {
		lnk[0].remove();
	}
};
function setPrintInvoice() {
	$$('a[class*="printinvoice"]').each(function (lnk) {
		lnk.onclick = function () {
			window.print();
			return false;
		}
	});
};
function displayCreditCard(order, container) {
	var cc = { 'V':'Visa', 'M':'Mastercard', 'A':'American Express', 'D': 'Discover' };
	var ccList = document.createElement('ul');
	if (order.OrderStatus.CCType) {
		var li = document.createElement('li');
                li.innerHTML = '<strong>'+cc[order.OrderStatus.CCType]+': </strong> ************'+order.OrderStatus.CCNum;
		ccList.appendChild(li);
		ccList.appendChild(Builder.node('li', ['Exp: ' +order.OrderStatus.CCExp]));
	}
	if ($(container) && ccList.childNodes.length) {
		$(container).innerHTML ='';
		$(container).appendChild(ccList);
	}
};
function displayOrderInfo(order) {
	if ($('order_number')) $('order_number').innerHTML = order.OrderNumb.replace(/^0+/, '');
	var d = new Date(order.OrderStatus.OrderDate.split('T').join(' ').split('-').join('/'));
	if ($('order_date')) $('order_date').innerHTML = monthName(d) + ' ' + d.getDate() + ', ' + d.getFullYear(); 
};
function displayAddress(address, container) {
	var addr = document.createElement('ul');
	var name = '';
	if (address.FirstName) {
		name += address.FirstName + ' ';
	}
	if (address.LastName) {
		name += address.LastName;
	}
	addr.appendChild(Builder.node('li', [name]));
	if (address.Address1) {
		addr.appendChild(Builder.node('li', [address.Address1]));
	}
	addr.appendChild(Builder.node('li', [
		(address.City || '') + ' ' + (address.State || '') + ' ' + (address.Zip || '')]));
	if ($(container) && addr.childNodes.length) {
		$(container).innerHTML = '';
		$(container).appendChild(addr);
	}
};
function displayShippingMethod(order) {
	function htmlToNode(html) {
		var div = document.createElement('div');
		div.innerHTML = html;
		return div.firstChild;
	}

	var method = document.createElement('ul');
	var trackings = order.OrderStatus.Tracking;
	if (trackings) {
		for (var i = 0; i < trackings.length; i++) {
	        if (trackings[i].ShipDate) {
                var d = new Date(trackings[i].ShipDate.split('T').join(' ').split('-').join('/'));
                var shipdate = Builder.node('li', ['Shipped ' +
                                                monthName(d) + ' ' + d.getDate() + ', ' + d.getFullYear() +
                                                ' via ' + trackings[i].Carrier]);
                if (trackings[i].TrackingNum) {
                        shipdate.appendChild(document.createTextNode(' with tracking number '));
                        if (trackings[i].CarrierLink) {
                                var clnk = htmlToNode(trackings[i].CarrierLink);
                        }
                        shipdate.appendChild(clnk || document.createTextNode(trackings[i].TrackingNum));
                } else {
                        shipdate.appendChild(document.createTextNode('. Tracking number is not available.'));
                }
                method.appendChild(shipdate);
	        }
		}
	} else {
		// Bug 3089: for USPS orders, NFS includes the shipping method per-item, and only provides the carrier (eg: "USPS")
		// Just in case they use this format for other providers, we are displaying all the shipping methods sent by NFS
		// rather than hardcoding "USPS" for each item.
		var items = order.OrderStatus.Item;
		var shippingMethods = [];
		for (var i in items) {
			shippingMethods.push(items[i].ShipMethod);
		}
		shippingMethods.uniq().each(function(m) {
			var node = Builder.node('li', [m]);
			method.appendChild(node);
		});
	}

	$('shipping_method').innerHTML = '';
	$('shipping_method').appendChild(method);
};
function getTotals(order, field) {
	var items = $H(order.OrderStatus.Item);
	var total = 0.0;
	items.keys().each(function (key) {
		total += parseFloat(items.toObject()[key][field] || 0);
	});
	return total.toFixed(2);
};
function displayItems(order) {
	var statusHash = {
		"ATWH":  "Item has been released to the warehouse",
		"BKO":   "Item is on back order",
		"CANC":  "Item has been cancelled",
		"CCPRB": "Item has credit card problems (declines ect)",
		"POS":   "Item is permanently out of stock",
		"RET":   "Item returned",
		"RSV":   "Item reserved",
		"SHP":   "Item shipped"
	};

	var table = document.createElement('table');
	table.className = 'chkout-table';
	var tbody = document.createElement('tbody');
	table.appendChild(tbody);
	var items = $H(order.OrderStatus.Item);
	items.keys().each(function (key) {
		var item  = order.OrderStatus.Item[key];
		var itemno = Builder.node('td', {className:'itemno'}, [item.Id]);
		var desc = Builder.node('td', {className:'desc'}, [Builder.node('h4', item.Description)]);
		var options = Builder.node('td', {clasName: 'options'}, [Builder.node('span', [statusHash[item.TextStatus] || ''] )]);
		var qty = Builder.node('td', {className: 'qty'}, [item.Quantity]);
		item.totalPrice = parseFloat(item.UnitPrice).toFixed(2);
		var price = Builder.node('td', {className:'price'}, ['$'+item.totalPrice]);
		var row = Builder.node('tr', [itemno, desc, options, qty, price]);
		tbody.appendChild(row);
	});
	if ($('order-header')) {
		var tableHeader = $('order-header');
		if (tableHeader.nextSibling) {
			tableHeader.parentNode.insertBefore(table, tableHeader.nextSibling);
		} else {
			tableHeader.parentNode.appendChild(table);
		}
	}
};
function displayTotals(order){
	function monetize(string) {
		return parseFloat(string).toFixed(2);
	}
	
	var costs = {};
	var total = monetize(order.OrderStatus.TotalPaid);	
	costs.subtotal    = monetize(order.OrderStatus.SubTotal);
	costs.shipping    = monetize(order.OrderStatus.Handling);
	costs.taxes       = monetize(order.OrderStatus.Tax);
	costs.promotional =	monetize(order.OrderStatus.DiscountAmt);
	costs.wrapcost    = getTotals(order, 'WrapCost');
	
	$('sub_total').innerHTML = '$' + costs.subtotal;
	$('shipping_handling').innerHTML = '$' + costs.shipping;
	
	if (costs.promotional > 0) {
		$('promotional_discount').innerHTML = '-$' + costs.promotional;
	} else {
		$('promotional_discount').up('tr').remove();
	}
	
	if (costs.wrapcost > 0) {
		$('giftwrap').innerHTML = '$' + costs.wrapcost;
	} else {
		$('giftwrap').up('tr').remove();
  }
	
	if (costs.taxes > 0) {
		$('taxes').innerHTML = '$' + costs.taxes;
	} else {
		$('taxes').up('tr').remove();
	}
	
	$A($('centercolumn').getElementsByClassName('total_cost')).each(function (elem) {
		elem.innerHTML = '$' + total;
	});
};
function showLbLoading() {
	centerElem($('lightbox'));
	cartLightBox.params.noAjax = true;
	cartLightBox.params.noOverlayClick = true;
	cartLightBox.activate();
};
function removeLbLoading(){
	cartLightBox.deactivate();
	cartLightBox.params.noAjax = null;
	cartLightBox.params.noOverlayClick = null;
};

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
};

function addWishListLink() {
	if ($('accountbar')) {
		var lis = $('accountbar').getElementsByTagName('li');
		if (lis.length) {
			var wishListLi = Builder.node('li', {id: 'mywishlist-link'});
			lis[0].parentNode.insertBefore(wishListLi, lis[lis.length-1]);
		}
	}
};

function hideTracking() {
	if (getCountry()== 'CA'){
		if ($('accountbar') && $('accountbar').down(1) && $('accountbar').down(1).next('li', 1)) {
			$('accountbar').down(1).next('li', 2).hide();
		}
		if ($('trackPack')) $('trackPack').hide();
		if ($('leftNavTack')) $('leftNavTack').hide();
	};
};

function initiate_rss() {
	var footer = $('footer');
	if (footer) {
		var footerList = footer.getElementsByTagName('ul')[0];
		if (footerList) {
			var listItems = footerList.getElementsByTagName('li');
			var rssLnk = Builder.node('a', {id: 'btn-rss', title: 'Upcoming Releases RSS', href: '/rss-widgets.html' }, [Builder.node('img', {src: '/media/global/icon_rss.gif', width: '36', height: '14', alt: 'Upcoming Releases RSS'})]);
			footerList.insertBefore(Builder.node('li', [rssLnk, '| ']), listItems[listItems.length-7]);
		}
	}
};

function initiate_reqCatalog() {
	var accountBar = $('accountbar');
	if (accountBar) {
		var accountBarList = accountBar.getElementsByTagName('ul')[0];
		if (accountBarList) {
			var listItems = accountBarList.getElementsByTagName('li');
			var rcLnk = Builder.node('a', {href: '/ajax/layouts/catalogrequestLayout_'+getCountry().toUpperCase()+'.html'} ,['Request Catalog']);
			accountBarList.insertBefore(Builder.node('li', [rcLnk, '|']), listItems[listItems.length-1]);
      rcLnk.parentNode.className = 'request-catalog';
			new reqCatalog(rcLnk);
		}
	}
};
var reqCatalog = function (elem) {
	this.processUrl = '/ajax/catalog.jsp';
	var _this = this;
	if (elem) {
		var lb = new lightbox(elem, {oncomplete: function () { _this.prepareForm(lb); }});
		if(urlHasParam(topNavParams.catalog))
				forceShowLightBox(lb);
	}
};

reqCatalog.prototype = {
	handleResponse: function (resp, container) {
		var respCode = parseInt(resp.firstChild.nodeValue);
		Element.show(container);
		if (respCode == 1) {
			Element.show($('rcRespSuccess'));
		} else {
			Element.show($('rcRespError'));
		}
	},
	prepareForm: function (lb) {
		var formElem = $('reqCatalogForm');
		var rcResponse = $('reqCatalogResponse');
		var _this = this;
		var lnks = formElem.getElementsByTagName('a');
		for (var i = 0; i < lnks.length; i++) {
			if ($(lnks[i]).hasClassName('btn-cancel')) {
				lnks[i].onclick = function () { lb.deactivate(); return false; };
			}
			if ($(lnks[i]).hasClassName('btn-submit')) {
				lnks[i].onclick = function () {
					if (checkForm(formElem)) {
						_this.sendRequest(formElem.serialize(true));
					}
					return false;
				};
			}
		}
		var lnks = rcResponse.getElementsByTagName('a');
		lnks[0].onclick = function () { lb.deactivate(); return false; };
	},
	sendRequest: function (formParams) {
		var _this = this;
		formParams.site_id = (getCountry().toUpperCase() == 'US')?1:2;
		formParams.nC = noCache();
		new Ajax.Request(this.processUrl, {
			parameters: formParams, 
			onComplete: function (xhr) {
				if (xhr.responseXML) {
					Element.hide($('reqCatalogWrapper'));
					var resp = xhr.responseXML.getElementsByTagName('response')[0];
					var rcResponse = $('reqCatalogResponse');
					_this.handleResponse(resp, rcResponse);
				}
			}
		});
	}
};
function setBucketId(value){
	var bucketId = null;
	//check if cookie exists
	if(readCookie(value)){
		bucketId = readCookie(value);
	}else{
		bucketId = value+'_bucket_'+uniqueId();
		createCookie(value,bucketId,1);	
	}
	return bucketId;
}

function isProduction() {
	// the part of the hostname before the first dot 
	// eg: for 'www.bbcamericashop.com' it would be 'www'
	var host = document.location.host;
	var hostnameStartsWith = host.substring(0, host.indexOf('.'));

	// pattern describing the beginning of a hostname in production
	var pattern = /^(www|bbcamericashop|bbccanadashop)$/;

	return pattern.test(hostnameStartsWith);
}


