



ZeroClipboard.setMoviePath('/cat300/catalog/zeroclipboard/ZeroClipboard.swf');
var doLocking = false;

dataName = 'crate_and_barrel';
var wic = null;

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function parseText(s) {
	return s.replace(/&apos;/gi, '\'');
}

function formatRSSTime(s) {
	if (!s) return s;
	var p = s.lastIndexOf(':')+3;
	if (p < s.length) return s.substring(0, p);
	return s;
}

function formNum(nStr) {
	
	if (nStr && nStr != 0) {
		nStr = (typeof nStr == 'string') ? nStr.replace(/,/gi, '') : nStr;
		nStr = parseFloat(nStr);
		nStr = nStr.toFixed(2);

		var x = nStr.split('.')[1];
		var y = parseFloat(x) == 0;

		nStr = (y) ? parseFloat(nStr).toFixed(0) : nStr;
		nStr = parseFloat(nStr) !== 0 ? nStr : null;

	} else {
		nStr = null;
	}
	
	return nStr;
}

var validateField = function(value) {
	return value.length > 0;
}

var validateEmail = function(value) {
	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
}

var detailSpinner = 'http://widget-images.catalogchoice.org/ajax-loader-3.gif'.trim();
if (detailSpinner.length < 1 || detailSpinner == 'null') detailSpinner = 'pixel.gif';

var dataLinkBaseURL = 'http://www.crateandbarrel.com/';
if (dataLinkBaseURL.indexOf('http://') != 0) dataLinkBaseURL = '';

var sldata = [];
var GM = {instance:{}, profile:{}, defstore: [213,20,1,"Alpine","Jewel_logo.gif","616-364-6281", "43.007579803467","-85.6884765625","2425 Alpine Avenue NW","Grand Rapids","MI","49544","Kent","2008-11-10 19:40:35.0","2006-01-01 00:00:01.0"]};

var emailRegex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
var zipRegex = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

var cookieCache = {};
var dirtyCookie = true;
var ck = cookieKey + '|' + embedId;
function getCookie(k) {
	if (dirtyCookie) {
		cookieCache = $cookie.get(ck);
		if (!cookieCache) cookieCache = {};
		dirtyCookie = false;
	}
	return cookieCache[k];
}
function setCookie(k,o) {
	if (dirtyCookie) {
		cookieCache = $cookie.get(ck);
		if (!cookieCache) cookieCache = {};
		dirtyCookie = false;
	}
	cookieCache[k] = o;

	setTimeout(function() {
		$cookie.set(ck, cookieCache);
		if (loggedIn) synchServer();
	}, 100);
}

function synchServer() {
	if (embedId && loggedIn) {
		var r = {};
		r.action = "saveInstance";
		r.embedId = embedId;
		r.widgetKey = cookieKey;
		r.listTitle = getCookie('listTitle');
		r.loadMyList = getCookie('listOnLoad');
		r.publish = getCookie('pubMyList');
		r.cookie = $json.toString(cookieCache);
		r.name = loggedIn.name;
		r.email = loggedIn.email;
		r.zip = loggedIn.zip;

		$ajax.jsonPost('/' + webappRoot + '/gxsvc/profile-service', r, {callback:function(r) {}});
	}
}

var showLockList;
var hideLockList;

var footerLinkText = null;
var footerLinkUrl = null;

var activeFooterMenu = ('true'.trim() == 'true');
var activeSearch = ('true'.trim() == 'true');

if (!activeFooterMenu) {
	footerLinkText = '';
	footerLinkUrl = '';
}


function startGM300() {
	trackEvent(GA.act['start'], GA.lab['load']);

	var lst = getCookie('catalog-mylist');
	if (!lst) lst = [];
	else if (lst.length > 0 && typeof(lst[0]) == 'object') setCookie('catalog-mylist', []);
	GM.mylist = lst;

	GM.ready = false;

	GM.store = getCookie('catalog-store');

	_create('bounder').innerHTML = '&nbsp;';
	GM.sprite = _img('sprite', 'images/go-button.gif');


	var imgLogo = 'http://widget-images.catalogchoice.org/CrateBarrel-Images/logo.jpg'.trim();
	if (imgLogo.length <= 0) imgLogo = 'pixel.gif'

	if (!passIphoneBlock && navigator.userAgent.match(/iPhone/i)) {
		_create('iphoneButton').innerHTML = '<a href="frame.jsp?key=' + cookieKey + (embedId?'&eid=' + embedId:'') + '&iph=true" target="iphoneyWindow"><div style="border:0px;width:302px;height:252px;" onClick="">&nbsp;</div></a>';
		_moveTo('iphoneButton', {x:-1,y:-1});
		_show('iphoneButton')
	}

	var widgetSplash = ('').trim();
	var widgetSplash2 = ('').trim();
	var widgetSplashGA = 'trackEvent(GA.act[\'splash\'], GA.lab[\'splash_hide\']);';
	if (widgetSplash2.length > 0 && widgetSplash2 != 'null') {
		_create('widgetSplash2').innerHTML = '<div onMouseOver="_amove(\'widgetSplash2\',{x:-300,y:0},300, function(){_hide(\'widgetSplash2\');});' + widgetSplashGA + '"><img src="' + widgetSplash2 + '"></div>';
		_show('widgetSplash2');
	} else if (widgetSplash.length > 0 && widgetSplash != 'null') {
		_create('widgetSplash').innerHTML = '<div onMouseOver="_amove(\'widgetSplash2\',{x:-300,y:0},300, function(){_hide(\'widgetSplash\');}); ' + widgetSplashGA + '"><img src="' + widgetSplash + '"></div>';
		_show('widgetSplash');
	}

	_create('backLogo').innerHTML = '<img src="' + imgLogo + '" style="cursor:pointer;" onClick="splashMe()">';
	_create('back01').innerHTML = '&nbsp;';
	_create('back02').innerHTML = '&nbsp;';
	_create('back03').innerHTML = '&nbsp;';
	_create('back04').innerHTML = '&nbsp;';
	_create('back05');
	
	_moveTo('backLogo', {x:2,y:2});
	_moveTo('back01', {x:150,y:0});
	_moveTo('back02', {x:0,y:233});
	
	_show('backLogo');
	_show('back01');
	_show('back02');
	_show('back03');
	_show('back04');
	//_show('back05');

	_create('logoLink').innerHTML = '<div style="width:150px;height:33px;" onClick="splashMe()">&nbsp;</div>';
	_moveTo('logoLink', {x:2,y:2});
	_show('logoLink');


	$('backing-box').innerHTML = '<div id="titleArea"> &nbsp; </div>';


	$comp.create(new mainLogo(), "mainLogo");

	var x = ((75 - 2)-(135/2))+2;
	var y = 13-2;
	_fondl('mainLogo', {x:2, y:2},true);

	$comp.create(new loginBox(), "loginBox", {x:155, y:2});
	if (!GM.store) _show('loginBox');

	$comp.create(new selectors(), "selectors", {x:20, y:70});

	$comp.create(new stores(), "stores", {x:150, y:2, w:150-2, h:235-2});

	$comp.create(new results(), "results", {x:2, y:90});


	var boxSize = {x:2, y:2+33, w:300-(2*2), h:197-2};

	var spl = 'http://widget-images.catalogchoice.org/CrateBarrel-Images/body_080409.jpg'.trim();
	var engaging = '<img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/body_080409.jpg" >';
	if (engaging.indexOf('<img') < 0 || (spl.length > 0 && spl != 'null')) {
		if ((GM.mylist && GM.mylist.length > 0 && getCookie('listOnLoad')) || !spl || spl.trim().length <= 0) $comp.create(new splashBox(), "splashBox", boxSize);
		else $comp.present(new splashBox(), "splashBox", boxSize);

	} else {
		GM.nosplash = true;
		showSelectors();
	}

	$comp.create(new myList(boxSize), "myList", boxSize);
	$comp.create(new subCats(boxSize), "subCats", boxSize);
	$comp.create(new profile(boxSize), "profile", boxSize);
	$comp.create(new listBox(boxSize), "listBox", boxSize);
	GM.boxSize = boxSize;

	$comp.create(new loginSignup(), "loginSignup", {x:2, y:2+33, w:300-(2*2), h:214-2});

	$comp.present(new footer(), "footer", {x:0, y:230});

	_create('resultsLeft').innerHTML = '<img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/navLeft.png" onClick="resultsLeft()" style="cursor:pointer;">';
	_moveTo('resultsLeft', {x:2+1, y:68});

	_create('resultsRight').innerHTML = '<img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/navRight.png" onClick="resultsRight()" style="cursor:pointer;">';
	_moveTo('resultsRight', {x:285-2, y:68});

	_create('catsLeft').innerHTML = '<img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/arrow_L.png" onClick="catsLeft()" style="cursor:pointer;">';
	//_moveTo('catsLeft', {x:2+1, y:58});
	_moveTo('catsLeft', {x:2+1, y:50});

	_create('catsRight').innerHTML = '<img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/arrow_R.png" onClick="catsRight()" style="cursor:pointer;">';
	//_moveTo('catsRight', {x:285-2, y:58});
	_moveTo('catsRight', {x:285-2, y:50});


	$comp.create(GM.r1 = new resultItem(), "resOne");
	$comp.create(GM.r2 = new resultItem(), "resTwo");

	GM.cur = GM.r2;

	showLockList = function () {
		GM.lockListUp = true;
		if (!c$('lockList')) {
		var p = {x:boxSize.x,y:boxSize.x+33,w:boxSize.w,h:250-(boxSize.x*2)-30};
//		var p = {x:boxSize.x,y:boxSize.x,w:boxSize.w,h:250-(boxSize.x*2)+3};
		$comp.create(new lockList(p), "lockList", p);
		}
		c$('footer').repaint();
		c$('loginBox').repaint();
		_show('lockList');
	}

	hideLockList = function () {
		GM.lockListUp = false;
		c$('lockList').close();
		c$('footer').repaint();
	}

	if (doLocking && !lockDenied) {
		var pq = {x:boxSize.x,y:boxSize.x,w:boxSize.w,h:250-(boxSize.x*2)};
		$comp.create(new regIntercept(pq), "regIntercept", pq);
		_show('regIntercept');
	}


	if (widgetInst) eval("wic = " + widgetInst.cookie);
	if (doLocking && wic && wic['catalog-mylist'] && wic['pubMyList']) {
		//var p = {x:boxSize.x,y:boxSize.x,w:boxSize.w,h:250-(boxSize.x*2)};
		//$comp.create(new lockList(p), "lockList", p);
		//_show('lockList');
		showLockList();
	} else if (GM.mylist && GM.mylist.length > 0 && getCookie('listOnLoad')) {
		c$('myList').primeLoad = true;
		showMyList();
	}

	if (1==1) {
		var p = {x:boxSize.x,y:boxSize.x,w:boxSize.w,h:250-(boxSize.x*2)};
		$comp.create(new searchBox({x:p.x,y:188,w:p.w,h:44}), "searchBox", {x:p.x,y:188,w:p.w,h:44});
		$comp.create(new resultsBox(p), "resultsBox", {x:p.x,y:p.y,w:p.w,h:p.h-17});
//		_show('searchBox');
	}

	trackEvent(GA.act['start'], GA.lab['start']);

	//	else c$('selectors').load();
	c$('selectors').load();
	c$('footer').repaint();

	// preload the RSS icon
	var img = new Image();
	img.src = 'images/rss_icon.gif';
}

function showSearch() {
	_show('searchBox');
	//var input = $('searchInput');
	//input.value = '';
	//input.focus();
	trackEvent(GA.act['search'], GA.lab['search_view']);
}

function splashMe() {
	if (logoLinkURL !== null && logoLinkURL !== ''){
		window.open(logoLinkURL);
		trackEvent(GA.act['logo'], logoLinkURL);

	} else splashMeAgain();

}
function splashMeAgain() {
	GM.prof = false;
	GM.my = false;
	_hide('zoomer');
	_hide('catsLeft');
	_hide('catsRight');
	_hide('resOne');
	_hide('resTwo');
	_hide('subCats');
	_hide('profile');
	_hide('myList');
	if(c$('runGetAndShare')) c$('runGetAndShare').hide();
	c$('loginBox').topCat = null;
	c$('loginBox').subCat = null;
	c$('loginBox').repaint();

		if (!GM.nosplash) {
			_show('splashBox');
			trackEvent(GA.act['splash'], GA.lab['splash_show']);
		} else {
			showSelectors();
		}
}

function showSelectors() {
	if (!GM.ready) setTimeout(showSelectors, 100);
	else c$('selectors').present();
}

function showMyList() {
	var c;
	
	if (!loggedIn && (c = c$('lockList')) && c.data && c.data.length > 0) {
		showLockList();
	} else {
		_show('myList');
	}

	if(c$('runGetAndShare')) c$('runGetAndShare').hide();
	_hide('resultsBox');
	_hide('searchBox');
	_hide('zoomer');
	//_hide('splashBox');
	
	if (c$('sendDialog')) c$('sendDialog').hide();
	if (c$('shareDialog')) c$('shareDialog').hide();
	
	GM.prof = false;
	GM.my = true;
	_hide('profile');
	c$('loginBox').repaint();
	_show('loginBox');
	c$('footer').repaint();
	
	trackEvent(GA.act['mylist'], GA.lab['mylist_view'], x[1]);
}
function signOut() {
	var r = {};
	r.action = 'logout';
	r.embedId = embedId;
	r.widgetKey = cookieKey;

	$ajax.jsonPost('/' + webappRoot + '/gxsvc/profile-service', r, {callback:function(r) {
		if (r.result == "logged-out") {
			var c = c$('footer');
			c.subOpenForLunch --;
			c$('profile').diff = loggedIn = null;
			c$('profile').repaint();
			c$('myList').repaint();
			c$('submenu').repaint();
			c.repaint();
		}
	}});
}

function showProfile() {
//	c$('footer').subOpenForLunch = 0;
//	c$('footer').hideSubmenu();
	if(c$('runGetAndShare')) c$('runGetAndShare').hide();
	_hide('lockList');
	_hide('zoomer');
	if (c$('sendDialog')) c$('sendDialog').hide();
	//_hide('splashBox');
	_hide('searchBox');
	c$('profile').load();
	GM.prof = true;
	GM.my = false;
	_hide('myList');
	c$('loginBox').repaint();
	_show('loginBox');
//	_hide('subCats');
	c$('footer').repaint();
}

function catsLeft() {
	c$('selectors').prevPage();
}

function catsRight() {
	c$('selectors').nextPage();
}

function resultsLeft() {
	_hide('zoomer');

	GM.dex --;
	if (GM.dex < 0) {
		GM.dex = sldata.results.length -1;
		overLeft();
	}

	var nxt = (GM.cur == GM.r1 ? GM.r2 : GM.r1);

	nxt.loadItem(sldata.fork(GM.dex));
//	if (!GM.my) nxt.loadItem(sldata.fork(GM.dex));
//	else nxt.loadItem(GM.mylist[GM.dex]);


	GM.thus = nxt;
	c$('loginBox').repaint();
	_moveTo(nxt, {x:-280, y:34});
	_amove(nxt, {x:2, y:34}, 300);
	_show(nxt);
}

function resultsRight() {
	_hide('zoomer');

	GM.dex ++;

	//if (!GM.my && GM.dex >= sldata.results.length) GM.dex = 0;
	//else if (GM.my && GM.dex >= GM.mylist.length) GM.dex = 0;
	
	if ((!GM.my && GM.dex >= sldata.results.length) || (GM.my && GM.dex >= GM.mylist.length)) {
		GM.dex = 0; overRight();
	}

	var nxt = (GM.cur == GM.r1 ? GM.r2 : GM.r1);

	nxt.loadItem(sldata.fork(GM.dex));
//	if (!GM.my) nxt.loadItem(sldata.fork(GM.dex));
//	else nxt.loadItem(GM.mylist[GM.dex]);

	GM.thus = nxt;
	c$('loginBox').repaint();
	_moveTo(nxt, {x:305, y:34});
	_amove(nxt, {x:2, y:34}, 300);
	_show(nxt);
}


function overLeft() {
	var c = c$('subCats');
	if (c.curPos <= 0) c.curPos = c.subs.length;
	c.curPos = c.curPos - 1;
	c.loadPosition(c.curPos, 'l');
}


function overRight() {
	var c = c$('subCats');
	if (c.curPos >= c.subs.length-1) c.curPos = -1;
	c.curPos = c.curPos + 1;
	c.loadPosition(c.curPos);
}




var imgId = 0;
var buyNowButton = ('').trim();
if (buyNowButton.length < 1 || buyNowButton == 'null') buyNowButton = null;

function resultItem() {
	this.d = null;
	this.drawHtml = function() {
		if (!this.d) return '';

		var p, img = this.d['image_link'];
		var video = this.d['video_url'];
		if (video) {
			video = video.trim();
			if (video.length < 1 || video == 'null') video = null;
		}

		if (lsn_eid && this.d.link) this.d.link = this.d.link.replace(/\@lsn_eid\@/gi, lsn_eid);
		if (extraParams['AID'] && this.d.link) this.d.link = this.d.link.replace(/\@AID\@/gi, extraParams['AID']);
		if (extraParams['PID'] && this.d.link) this.d.link = this.d.link.replace(/\@PID\@/gi, extraParams['PID']);
		if (extraParams['SID'] && this.d.link) this.d.link = this.d.link.replace(/\@SID\@/gi, extraParams['SID']);

		GM.curimage = img;

		var h = '';

		var article = (this.d['item_type'] == 'article');

		var price;
		var samePrice = (this.d.price == this.d.sale_price);
		
		if (this.d.price && (this.d.price = this.d.price.trim()) != '' && (this.d.price+'') != 'null') {
			price = this.d.price;
			var x = (typeof price == 'string') ? price.split('$') : price;
			price = (typeof x == 'object' && x.length == 2) ? formNum(x[1]) : formNum(price);
			
			if (isNaN(price)) {
				var p = this.d.price;
				var a = (p.split('$').length > 2) ? p.replace(/\$/gi,'').split(' - ') : null;
				
				a[0] = formNum(a[0]);
				a[1] = formNum(a[1]);
				
				price = '$' + a[0] + ' - $' + a[1];
				
			} else {
				price = '$' + price;
				
			}
			
		} else {
			price = '';
		}

		
		var sale_price = null;
		if (!samePrice && this.d.sale_price && this.d.sale_price != 0) {
			sale_price = parseFloat(this.d.sale_price);
			sale_price = sale_price.toFixed(2);
	
			var x = sale_price.split('.')[1];
			var y = parseFloat(x) == 0;
	
			sale_price = (y) ? parseFloat(sale_price).toFixed(0) : sale_price;
			sale_price = parseFloat(sale_price) !== 0 ? sale_price : null;
			
		}
		
		var bgImage = 'http://widget-images.catalogchoice.org/CrateBarrel-Images/grad_bg-4.jpg'.trim();
		if (bgImage != '' && bgImage != 'null') bgImage = ' background-image:url(' + bgImage + ');'
		else bgImage = '';

		var chopTitle = this.d.title;
		chopTitle = parseText(chopTitle);
		if (chopTitle.length > 40) chopTitle = chopTitle.substring(0,40) + '...';

		var desc = this.d.description;
		desc = parseText(desc);
		desc = desc.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/a href.\"(?!http)/gi, 'a target="offsite" href="' + dataLinkBaseURL);
		var resImgId = 'resImg' + $chr.fromNum(imgId++);

		var saved = false;
		// Hide "save" link for anonymous users if the "featured list" is enabled.
		if (((embedId && !loggedIn) || (!embedId && widgetInst && !loggedIn)) && !(embedId && !c$('lockList'))) {
			saved = true;
		} else {
			for(i in GM.mylist) {
				if (GM.mylist[i] == this.d['sku'])
					saved = true;
			}
		}

		h += '<table cellpadding=0 cellspacing=0 border=0 width="296" height="' + (article ? '55' : '196') + '" border=1><tr><td style="background-color:#E2E2E2; ' + bgImage + '" colspan=2 height=35 valign=middle>' +
		     '<table cellpadding=0 cellspacing=0 width=100%><tr>' +
		     '<td style="padding-right:3px;cursor:pointer;width:11px;" onClick="' + (c$('loginBox').subCat[3] > 1 ? 'results' : 'over') + 'Left();"><img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/navLeft.png" border=0></td>' +
		     '<td>' +
		     '<div style="width:268px;overflow:hidden;">' +
		     '<div style="white-space:nowrap;"><font style="font-size:13px; font-weight:bold;"><font style="color:#000000">' + chopTitle + '</font></font></div>' +
		     '&nbsp;<font style="color:#000000;font-size:11px;">' + (!article ? price : formatRSSTime(this.d['publish_date'])) + '</font>' +
			 (!article && sale_price !== null ? '&nbsp; <font style="color:#000000;font-size:11px;"> Now on Sale $' + sale_price + '</font>' : '') +
		     '</div>' +
		     '</td>' +
		     '<td style="padding-left:3px;cursor:pointer;width:11px;" onClick="' + (c$('loginBox').subCat[3] > 1 ? 'results' : 'over') + 'Right();"><img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/navRight.png" border=0></td>' +
		     '</tr></table>' +
		     '</td></tr><tr><td valign=middle align=center>';

		if (article) {
			h += '<div style="width:145px;height:14px;overflow:hidden;">&nbsp;</div>';

		} else {
			h += '<div id="' + resImgId + 'c" style="width:145px;height:144px;overflow:hidden;position:relative;">';
				h += '<div id="' + resImgId + '"><img src="' + detailSpinner + '" border=0></div>';
				
				if (video) {
					h += '<div id="video"></div>';
					h += '<a id="video-link" href="' + video + '" onClick="doClick(this, \'video\'); return false;">Video</a>';
				}
			h += '</div>';
		}

		h += '</td><td valign=top width=143>' +
		     '<div style="' + (!article?(buyNowButton?'height:40px;':'height:35px;'):'') + 'padding-bottom:5px;padding-top:3px;" class="actnBox">' +
			 '<font style="font-size:11px;color:#848484;">' +
		     '<a href="' + this.d.link + '" target="offwidget" onclick="doClick(this, \'buy\'); return false;"><font style="color:#0F7ECD;font-size:11px;">' + (!article && price.length > 0 ? (buyNowButton ? '<img src="' + buyNowButton + '" border=0 vspace=3>' : 'Buy Now') : ('Buy Now' != 'Buy Now' ? 'Buy Now' : 'More Info')) + '</a></font>' +
		       (article? '<font style="color:#848484;font-size:11px;">&nbsp;&nbsp;|&nbsp;&nbsp;' : '<br>') +
			   (!saved && activeFooterMenu ? '<a href="javascript:void(0);" onClick="doClick(this, \'list' + (article?'a':'') + '\')" style="color:#848484">Save' + (!article ? ' to My List' : '') + '</a>' + '&nbsp;&nbsp;|&nbsp;&nbsp;' : '') +
		       '<a href="javascript:void(0);" onClick="doClick(this, \'share\')" style="color:#848484">Share</a></font>' +
			 '</div>';

		if (!article) {
			h += '<div style="width:143px; height:' + (buyNowButton?119:126) + 'px; overflow-y:auto; overflow-x:hidden; font-size:10px;">' +
		     '<font style="color:#555555">' + desc + '</font></div>';
		}

		h += '</td></tr></table>';

		if (article) {
			h += '<div style=" width:288px; height:140px; overflow-y:auto; overflow-x:hidden; font-size:10px;"><div style="padding-left:4px;padding-right:4px;">' +
		     '<font style="color:#555555">' + desc + '</font></div></div>';
		}


		dinger.id = resImgId;
		var zoomPopup = 'link';
		if (zoomPopup == 'zoom') dinger.lnk = '  onClick="presentZoom(this,\'' + this.d.link + '\',' + (price.length > 0 ? 'true' : 'false') + ')"';
		else if (zoomPopup == 'link') dinger.lnk = ' onClick="doClick(this, \'buy\')" ';
		else  dinger.lnk = '  onClick="doClick(this, \'print\')"';

		var imgD = new Image();
		imgD.onload = function() {
			dinger.src = this.src;
			dinger.w = this.width;
			dinger.h = this.height;
			this.onload = null;
			dingImage();
		}
		imgD.src = img;

		if (this.log) {
			trackEvent(GA.act['ads'], GA.lab['ad_detail'], this.d['sku']);
		if (typeof Affiliate !== 'undefined') Affiliate.redirect('impression');
		} else {
			this.log = true;
		}
		
		return h;
	}


	this.handleClick = function(e, x) {
		if (x == 'list' || x == 'lista') {
			for(i in GM.mylist) {
				if (GM.mylist[i] == GM.thus.d['sku']) return;
			}

			var self = this;
			self.log = false;
			GM.sprite.src = (x == 'list' ? GM.curimage : 'images/rss_icon.gif'.trim());

			_moveTo(GM.sprite, {x:175,y:60});
			_resize(GM.sprite, {w:60,h:60});
			_show(GM.sprite);

			if (!GM.thus.d.id) GM.thus.d.id = 'y' + GM.mylist.length;
			GM.mylist[GM.mylist.length] = GM.thus.d['sku'];
			setCookie('catalog-mylist', GM.mylist);
			c$('myList').repaint();

			setTimeout(function() {_amove(GM.sprite, {w:3,h:3,x:150, y:242}, 300, function() { _hide(GM.sprite); self.repaint(); });}, 400);

			c$('footer').repaint();
			trackEvent(GA.act['ads'], GA.lab['ad_save'], GM.thus.d['sku']);

		} else if (x == 'back') {
			_hide('subCats');
			
			_hide('resOne');
			_hide('resTwo');
			
			var o = c$('loginBox').topCat;
			if (o !== null) {
				GA.category = o[1];
				trackEvent(GA.act['browse'], GA.lab['category'], o[1]);
			} else {
			c$('selectors').present();
			}

		} else if (x == 'print') {
			GM.popper = GM.thus.d;
			popDetails();
			trackEvent(GA.act['ads'], GA.lab['ad_print'], GM.thus.d['sku']);

		} else if (x == 'send') {
			runDialog('sendDialog',null,GM.thus.d);
			trackEvent(GA.act['ads'], GA.lab['ad_share_email'], GM.thus.d['sku']);

		} else if (x == 'share') {
			runDialog('shareDialog',null,GM.thus.d);
			trackEvent(GA.act['share'], GA.lab['ad_share_open'], GM.thus.d['sku']);

		} else if (x == 'buy') {
			if (typeof openUrl !== 'undefined') {
				openUrl(this.d.link);
			} else if (typeof widget !== 'undefined' && typeof widget.openURL !== 'undefined') {
				widget.openURL(this.d.link);
			} else if (typeof window !== 'undefined' && typeof window.open !== 'undefined') {
				window.open(this.d.link);
			}
			
			if (typeof Affiliate !== 'undefined') Affiliate.redirect('click');
			trackEvent(GA.act['ads'], GA.lab['ad_buy'], GM.thus.d['sku']);
		
		} else if (x == 'video') {
			var url = (this.d['video_url'] + '').trim();
			if (url != '' && url != 'null') {
				if (url.indexOf('v=') > -1 && url.indexOf('youtube') > -1) {
					url = 'http://www.youtube.com/watch_popup?' + url.substring(url.indexOf('v='));
				}
				var win = window.open(url, '_blank', 'scrollbars=no,menubar=no,resizable=yes,width=640,height=385');
				if (!win) {
					alert('Popup windows are blocked by your browser.');
				}
			}
		}
	}

	this.loadItem = function(item) {
		this.d = item;
		this.repaint();
	}
	
	this.log = true;
}


var zoomer = null;
var zoomImg = null;
function presentZoom(img, lnk, buyNow) {

	if (!zoomer) zoomer = _create('zoomer');
	zoomImg = img;

	var d = _dim(img);
	_moveTo('zoomer',{x:2,y:69});
	zoomer.style.overflowX = 'hidden';
	zoomer.style.overflowY = 'scroll';
	zoomer.innerHTML = '<div style="height:17px;background-color:#fff">&nbsp;<div><div style="width:296px;text-align:left;"><img src="' + img.src + '" width=281 onClick="hideZoom()" style="cursor:pointer;"></div>';

	_resize('zoomer',d);
	_show('zoomer');
	_amove('zoomer', {w:296,h:161},300, function() {
		zoomer.style.overflowY = 'hidden';
		zoomer.innerHTML = '<div style="height:17px;padding:3px;background-color:#fff;text-align:right;" class="actnBox"><font style="font-size:11px;">' +
		                   '<table cellpadding=0 cellspacing=0><tr>' +
		                   '<td onClick="hideZoom()" style="cursor:pointer;padding-left:5px;" width="145">' +
		                     '<font style="color:#848484;font-size:11px;">Back to details</font>' +
		                   '</td><td nowrap>' +
		                     '<a href="' + lnk + '" onclick="c$(\'resOne\').handleClick(this,\'buy\');" target="offwidget"><font style="color:#0F7ECD;font-size:11px;">' + (buyNow ? 'Buy Now' : ('Buy Now' != 'Buy Now' ? 'Buy Now' : 'More Info')) + '</a>&nbsp;&nbsp;|&nbsp;&nbsp;' +
							 '<a href="javascript:void(0);" style="color:#848484;" onClick="GM.cur.handleClick(null, \'list\')">Save</a>&nbsp;&nbsp;|&nbsp;&nbsp;' +
							 '<a href="javascript:void(0);" style="color:#848484;" onClick="GM.cur.handleClick(null, \'share\')">Share</a></font>' +
		                   '</tr></table>' +
		                   '</div>' +
		                   '<div style="overflow-x:hidden;overflow-y:scroll;width:296px;height:147px;text-align:left;">' +
		                   '<img src="' + zoomImg.src + '" width=281 onClick="hideZoom(this)">' +
		                   '</div>';
	});
	
	trackEvent(GA.act['ads'], GA.lab['ad_zoom'], GM.thus.d.sku);
}

function hideZoom() {
	_amove('zoomer', {w:145,h:145},300, function() {_hide('zoomer')});
}

function trimBack(t,c) {
	if (!c) c = 100;
	if (t.length < c) return t;
	t = t.substring(0,c);
	var p = t.length -1;
	while (t.charAt(p) != ' ') p--;
	return t.substring(0,p) + '...';
}
function priceTitle(t) {
	if (t && t.length > 0) {
		if (t.charAt(0) != '$') return '$' + t;
	}
	return t;
}

function printItem(d) {
	var lnks = true;
	var p, img = d['image_link'];
	GM.curimage = img;

	return '<div style="border-top:1px solid #ccc;padding-top:3px;padding-bottom:3px;"><table cellpadding=0 cellspacing=0 border=0 width="265"><tr><td valign="top">' +
		   '<img src="' + img + '" width=60 height=60 border=0 style="padding-left:5px;padding-right:10px;">' +
		   '</td><td valign="top" style="padding:2px;">' +
		   '<font style="font-size:11px; color:#009;">' + d.description + '</font><br>' +
		   '<div style="padding-top:5px;"><font style="color:#e00;font-size:13px; font-weight:bold;">' + d.title + '</font><br>' +
		   (GM.store ? '<div style="padding-top:3px;"><font style="font-size:11px;font-weight:normal;color:#aaa">' + d.original_price + '</font></div>' : '') +
		   (GM.store ? '<div style="padding-top:2px;"><font style="font-size:11px;font-weight:normal;color:#000">' + d.additional + '</font></div>' : '') +
		 '</td><td valign=top width=50>' +
		 (!lnks?'<br><a href="javascript:void(0)" onClick="doClick(this,\'' + d['promotion_id'] + '\')" style="color:#00f;">remove</a>':'') +
		   '</td></tr></table>' +
		   (lnks? '<div style="font-size:11px;">' + d['listing_deal'] + '</div>':'') +
		   '</div>';
}











curDialog = null;
function runDialog(id,e,dat,f) {
	if(curDialog) _hide(curDialog); //curDialog.shieldOver(true);

	var c = c$(id);
	if (!c) {
		_create(id, 'component');
		eval('c = new ' + id + '()');
		_inject(c, dialogSuper);
		$comp.register(c, id);
	}
	c.data = dat;

	if (f) {
		var fullBoxSize = {};
		fullBoxSize.x = 2;
		fullBoxSize.y = 2;
		fullBoxSize.h = GM.boxSize.h + 34;
		fullBoxSize.w = GM.boxSize.w;
		
		_moveTo(c, fullBoxSize);
		_resize(c, fullBoxSize);
		
		c.fullscreen = true;
	} else {
//	_moveTo(c,{x:7, y:(y != null? y:38)});
	_moveTo(c, {x:2,y:35});
	_resize(c, GM.boxSize);
		c.fullscreen = null;
	}
	c.repaint();
	_show(c);

	this.curDialog = c;
}

var dialogSuper = {
	parent:null,
	autohide:false,
	shieldOver:function(doIt) {
		if(this.autohide || doIt) _hide(this);
		return true;
	},
//	cancelBut:function() {
//		return '<div style="float:right;"><a href="javascript:;" onClick=\'doClick(this,"cancel");\'>' +
//			'<img src="images/close-blue.gif" width=14 height=13 style="border:0px;"></a></div>';
//	}
	cancelBut:function() {
		return '<div style="float:right;font-size:11px;"><a href="javascript:;" onClick="doClick(this,\'cancel\');" style="color:#848484">' +
			'[ x ]</a></div>';
	}
}





function drawSendDialog() {
	var name = getCookie('profName');
	if (!name) name = '';

	var email = getCookie('profEmail');
	if (!email) email = '';

	return '<div class="dialogBox">' +
//	         this.cancelBut() + '' +
	         '<div style="padding-bottom:3px;">' +
	            '<div style="background-color:#E2E2E2"><div style="width:100%;height:17px;line-height:15px;">' +
		       '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
		       '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;" width=240>Share via Email</td>' +
		       '<td style="font-size:11px;line-height:11px;color:#000000;" align=right>' +
		       '<a href="javascript:void(0)" style="color:#000000" onClick="doClick(this,\'cancel\');">[ x ]</a>' +
		       '</td>' +
		       '</tr></table>' +
		       '</div></div>' +
	           '<div id="dialogsender" style="padding:7px;font:normal 11px arial;">' +
			   	 '<form type="post" action="#" onSubmit="doClick(this,\'send\'); return false;">' +
	             'We respect that you simply want to share product finds. We do not use your information for marketing purposes.<br>' +
	             '<table style="padding-top:3px;">' +
	             '<tr><td style="font:normal 10px arial;text-align:right;">To:</td><td><input id="sendEntry" type="text" value="" style="width:185px;padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;"></td></tr>' +
	             '<tr><td style="font:normal 10px arial;text-align:right;">Your&nbsp;Name:</td><td><input id="sendName" type="text" value="' + name + '" style="width:185px;padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;"></td></tr>' +
	             '<tr><td style="font:normal 10px arial;text-align:right;">Your&nbsp;Email:</td><td><input id="sendEmail" type="text" value="' + email + '" style="width:185px;padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;"></td></tr>' +
	             '<tr><td style="font:normal 10px arial;text-align:right;">Subject:</td><td><input id="sendNote" type="text" value="' + (this.data == 'widget' ? 'check out this widget...' : 'look what I found...') + '" style="width:185px;padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;"></td></tr>' +
	             '<tr><td>&nbsp;</td><td><font size=1><br></font>' +
					//'<a href="javascript:void(0)" onClick="doClick(this,\'send\');" style="color:#848484">Send</a>' +
					'<input type="submit" value="Send" style="background-color:#E2E2E2;color:#000000;padding-left:4px;font-size:11px;border:0;height:18px;">' +
					'</td></tr>' +
	             '</table>' +
				 '</form>' +
	           '</div>' +
	         '</div>' +
	       '</div>';
//	       '<center><div class="dialog"><br>Mobile Phone or Email<br><input id="sendEntry" type="text" style="width:130px; font:normal 10px arial;" value="' +
//		email + '" onFocus="this.style.background=\'#FFB\'" onBlur="this.style.background=\'#FFF\'"><input type=button style="font:normal 10px arial; ' +
//		'margin-bottm:3px;" onClick=\'doClick(this,"send");\' value="Send"><span style="font:normal 9px arial;">' +
//		'<br><br>You may send listings either to an email address or to a U.S. cell phone. Simply enter the email address and hit SEND. ' +
//		'Or enter a U.S. cell phone number (please include the area code) and hit SEND. You do not need to specify a carrier. This service is free ' +
//	       'but charges from your phone carrier for usage may apply. We do not use this information for marketing purposes.' +
//		'</span></div></center></div></div>';
}



function sendDialog() {
	this.metricStr = "";

	this.drawHtml = drawSendDialog;

	this.doHide = function() {
		GM.sendList = false;
		return true;
	}

	this.handleClick = function(e,x) {
		if(x == 'cancel') {
			_hide(this.id);

		} else if (x == 'send') {
			var to = $$('sendEntry').value;
			var name = $$('sendName').value;
			var email = $$('sendEmail').value;
			var note = $$('sendNote').value;

			if (to.length > 0) {
//				if (to.indexOf('@') > 0) {
					if (!emailRegex.test(to)) {
						alert('Please enter a valid email address.');
						return;
					}
					if ((name = name.trim()).length <= 0) {
						alert('Please enter a name.');
						return;
					}
					if (!emailRegex.test(email)) {
						alert('Please enter a valid email address for yourself.');
						return;
					}
					if ((note = note.trim()).length <= 0) {
						alert('Please enter a note for the email subject.');
						return;
					}

					if (this.data == 'widget') {
						cont = '' +  serviceReference + '/cat300/catalog/frame.jsp?key=' + cookieKey + (embedId ? '&eid=' + embedId : '') + (extraQS.length > 0 ? '&' + extraQS : '');

					} else if (GM.sendList) {
						GM.sendList = false;
						cont = '<font style="font-family:arial, sans-serif">';
						var myListComp = c$('myList');
						for (i in myListComp.data) cont += drawAdListing(myListComp.data[i]);
						cont += '</font>';
					} else {
						cont = drawAdListing(this.data);
						cont = '<font style="font-family:arial, sans-serif">' + cont + '</font>';
					}

					var data = this.data;

				if (to.length > 0) {
						$ajax.jsonPost('/' + webappRoot + '/gxsvc/send-template', {fromEmail:email, target:to, subject:note, content:$json.toString({key:cookieKey, template:(this.data == 'widget' ? 'widget' : 'products'), name:name, content:cont})}, {
							callback: function(r) {
								_hide('sendDialog');

								if ('ok' == r.result) {
									trackEvent(GA.act['ads'], GA.lab['ad_share_sent'], data.sku);
								} else {
									trackEvent(GA.act['ads'], GA.lab['ad_share_fail'], data.sku);
								}
							}
						});
				}
			} else {
				alert('Please enter a valid email address.');
				return;
			}
		}
	}
}

var launchUrl = function(url){
	if (window.widget) widget.openURL(url); // OSX dashboard
	else {
		if (!$$('launcher')) {
			var a = document.createElement('a');
			a.id = 'launcher';
			a.target = '_blank';
			a.onclick = function() {
				if(!window.open(this.href)) {
					alert('Popup windows are blocked by your browser.');
				}
			};
			document.body.appendChild(a);
		}

		$$('launcher').href = url;
		$$('launcher').onclick();

		return url;
	}
};

var Bitly = {
	temp: null,
	urls: null,
	callback: function(data) {
		var r, t = this.temp;
		
		for (var i in data.results) {
			r = data.results[i];
			break;
		}
		
		if (this.urls == null)
			this.urls = new Object();
		
		var url = this.urls[t.sku] = r.shortUrl;
		t.callback(url, t.title);
		
		this.temp = null;
	}
};

var Sharer = {
	facebook: function(u, t){
		launchUrl('http://www.facebook.com/sharer.php?src=bm&v=4&i=1243034241&u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t));
	},
	myspace: function(u, t){
		launchUrl('http://www.myspace.com/Modules/PostTo/Pages/?c=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t));
	},
	delicious: function(u, t){
		launchUrl('http://delicious.com/save?url=' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t) + '&v=5&noui=1&jump=doclose');
	},
	twitter: function(u, t){
		launchUrl('http://twitter.com/home?status=' + encodeURIComponent(t) + ' - ' + encodeURIComponent(u));
	}
};

function drawShareDialog(data) {
	return '<div class="dialogBox">' +
//	         this.cancelBut() + '' +
			 '<div style="padding-bottom:3px;">' +
				'<div style="background-color:#E2E2E2"><div style="width:100%;height:17px;line-height:15px;">' +
				'<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
				'<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;" width=240>Share Details</td>' +
				'<td style="font-size:11px;line-height:11px;color:#000000;" align=right>' +
				'<a href="javascript:void(0)" style="color:#000000" onClick="doClick(this,\'cancel\');">[ x ]</a>' +
				'</td>' +
				'</tr></table>' +
				'</div></div>' +
				
				'<div style="padding:7px;font:normal 11px arial;">' +
				'How would you like to share <strong>' + data.title + '</strong>? Choose an icon to share it with your friends.<br>' +
				
				'<div class="share-icons">' +
					'<a onclick="doClick(this,\'email\')"><img alt="Send to Email" title="Send to Email" src="images/email.png" width="16" height="16" /> Email to Friend</a>' +
					'<a onclick="doClick(this,\'facebook\')"><img alt="Send to Facebook" title="Send to Facebook" src="images/facebook.png" width="16" height="16" /> Facebook</a>' +
					'<a onclick="doClick(this,\'myspace\')"><img alt="Send to MySpace" title="Send to MySpace" src="images/myspace.png" width="16" height="16" /> MySpace</a>' +
					'<br>' +
					'<a onclick="doClick(this,\'delicious\')"><img alt="Send to Delicious" title="Send to Delicious" src="images/delicious.png" width="16" height="16" /> Delicious</a>' +
					'<a onclick="doClick(this,\'twitter\')"><img alt="Send to Twitter" title="Send to Twitter" src="images/twitter.png" width="16" height="16" /> Twitter</a>' +
				'</div>' +
				
				'</div>' +
			'</div>' +
		   '</div>';
	
}

function shareDialog() {
	this.metricStr = "";

	this.drawHtml = function(){
		if (typeof this.data == 'undefined')
			return '';
		else
			return drawShareDialog(this.data);
	}

	this.doHide = function() {
		GM.sendList = false;
		return true;
	}

	this.handleClick = function(e,x) {
		var d = this.data;
		
		if (x == 'cancel') {
			_hide(this.id);
			trackEvent(GA.act['share'], GA.lab['ad_share_close'], d.sku);

		} else if (x == 'email') {
			runDialog('sendDialog',null,d,this.fullscreen);
			trackEvent(GA.act['share'], GA.lab['ad_share_email'], d['sku']);
			
		} else {
			var xx = {'facebook':true, 'myspace':true, 'delicious':true, 'twitter':true};
			if (typeof xx[x] !== 'undefined') {
				d.link = d.link.trim();
				var fb = (x == 'facebook') ? FB_Bitly : true;
				var bitlyURL = (Bitly.urls !== null && typeof Bitly.urls[d.sku] !== 'undefined') ? Bitly.urls[d.sku] : null;
				
				if (useBitly && fb && bitlyURL) {
					Sharer[x](bitlyURL, d.title);
					
				} else if (useBitly && fb && !bitlyURL) {
					Bitly.temp = { sku: d.sku, title: d.title, url: d.link, callback: Sharer[x] };
					BitlyClient.shorten(d.link, 'Bitly.callback');
					
				} else {
					Sharer[x](d.link, d.title);
					
				}
				
				trackEvent(GA.act['share'], GA.lab['ad_share_' + x], d['sku']);
			}
		}
	}
}


function drawAdListing(a) {
	function str(s) {
		if (!s || s == 'null') return '';
		s = new String(s);
		s = s.replace(/\//g,'/ ').replace(/\\/g,'\\ ').replace(/\n/g, '').replace(/\t/g, '').replace(/,/g, ', ');
		return s !== '' ? s : '';
	}
	function blockStr(bef, s, aft) {
		s = str(s);
		if (s == '' || s == 'null') return '';
		return bef + s + aft;
	}
	
	var img = a['image_link'];
	if (img) {
		var p = img.indexOf('?');
		if (p > -1) img = img.substring(0,p);
	}
	
	a.title = parseText(a.title);
	
	var desc = a.description;
	desc = parseText(a.description);
	desc = desc.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/a href.\"(?!http)/gi, 'a target="offsite" href="' + dataLinkBaseURL);

	return '<div class="listing"><a href="' + a.link + '" target="job-' + a.id + '"><div>'
 		+ (img ? '<img src="' + img + '" width=75 border=0><br>' : '')
		+ '<div class="oodAttr" style="font-weight:bold; color:null">' + a.title + '</div>'
		+ '<div class="oodAttr" style="font-size:11px; font-style:italic;">$' + a.price + '</div>'
		+ '<div class="oodDet" style="font-size:10px;">' + desc + '</div>'
		+ '</div></a></div>';
	
}



function launchWindow(title,content, w, h) {
	var win = window.open('','_blank','scrollbars=yes,menubar=yes,resizable=yes,width='+w+',height='+h);
	if(win) {
		if(title) win.document.title = title;
		win.document.open("text/html");
		win.document.write(content);
		win.document.close();
		return win;
	} else {
		showMessage("Popup windows are blocked by your browser.");
	}
}

var get_menu = null;
function getWidget() {
	trackEvent(GA.act['getwidget']);
	if (c$('sendDialog')) c$('sendDialog').hide();
	_hide('resultsBox');
	GM.getshare = true;
	c$('loginBox').repaint();
	runDialog('runGetAndShare', null, {});
}


function popDetails() {
	var t = 'Catalog Widget | Product Zoom';

	var w = 250;
	var h = 500;
	var scrolly = true;

	var win = window.open('popup.jsp?data=' + escape(dataName) + '&sku=' + escape(GM.popper.sku) + (lsn_eid?'&lsn_eid=' + lsn_eid : ''),'_blank','scrollbars=' + (scrolly?'yes':'no') + ',menubar=no,resizable=yes,width=' + w + ',height=' + h);
	try { win.location.href = 'popup.jsp?key=' + cookieKey + '&data=' + escape(dataName) + '&sku=' + escape(GM.popper.sku) + (lsn_eid?'&lsn_eid=' + lsn_eid : ''); } catch (e) {}
	if(!win) {
		alert('popups appear to be blocked.\ndetails window not shown.');
	}
}

var dinger = {};
function dingImage() {
	var rat;
	var t = $$(dinger.id);

	if (!t) {
		setTimeout(dingImage, 500);

	} else {
		var h = '<a href="javascript:void(0)"><img src="' + dinger.src + '" ';
		if (dinger.h > dinger.w) {
			rat = dinger.w / dinger.h;
			h += 'height="144" width="' + (144 * rat) + '"';
		} else {
			rat = dinger.h / dinger.w;
			h += 'height="' + (145 * rat) + '" width="145"';
		}
		h += dinger.lnk + '  border=0></a>';
		t.innerHTML = h;
//		t.src = dinger.src;
	}
}

function slugify(s) {
	if (typeof s == 'undefined' || s == null)
		return s;
	
	var s2 = '', nodiac = { '?': 'a', 'c': 'c', 'd': 'd', '?': 'e', 'e': 'e', '?': 'i', 'n': 'n', '?': 'o', 'r': 'r', '?': 's', 't': 't', '?': 'u', 'u': 'u', '?': 'y', '?': 'z' };
	s = s.toLowerCase();
	
	for (var i = 0; i < s.length; i++) {
		s2 += (typeof nodiac[s.charAt(i)] != 'undefined' ? nodiac[s.charAt(i)] : s.charAt(i));
	}
	
	return s2.replace(/[^a-z0-9_\|\-]+/g, '+').replace(/^\+|\+$/g, '');
}

function checkTextWidth(s,w) {
	var el = $$('stringTest');
	if (!el) {
		el = _create('stringTest');
	}
	
	el.innerHTML = s;
	var width = el.clientWidth;
	//var offset = (w/2) < s.length ? w/2 : s.length;
	var offset = 20;
	var string = s;
	
	if (width > w) {
		for (var i = offset + 0; i >= 10; i--) {
			
			offset = i + 0;
			string = s.substring(0,i);
			el.innerHTML = string;
			width = el.clientWidth;
			
			if (width <= w)
				break;
		}
	}
	
	return { width: width, offset: offset, string: string };
}






function getAndShareTitle() {
	var lnks = c$('footer').lnks;
	if (lnks && lnks.length > 0) {
		for (i in lnks) {
			if ((lnks[i])[0].indexOf('getWidget()') > -1) return (lnks[i])[1];
		}
	}
	return "Get &amp; Share";
}

function getWidgetUrl() {
	return serviceReference + '/cat300/catalog/frame.jsp?key=' + cookieKey + ((doLocking) ? '&eid=' + $rnd.str(32) : '') + (extraQS.length > 0 ? '&' + extraQS : '');
}

function drawGetAndShare(d) {
	var tmp = extraQS.length > 0 ? extraQS : '';
	if (tmp.indexOf('%2F') > -1) tmp = tmp.replace(/%2F/g,'%28%28');
	var extraParams = '+' + tmp.replace(/=/g,'__').replace(/&/g,'/+') + '/';

	var title = getAndShareTitle();
	var widgetUrl = getWidgetUrl();

	var linkColor =  ' style="color:#555555"';
	var imgStyle =  ' style="border: medium none;vertical-align: middle;margin:1px;"';

	return '<div class="dialogBox">' +
			 '<div style="padding-bottom:3px;">' +
				'<div style="background-color:#E2E2E2"><div style="width:100%;height:17px;line-height:15px;">' +
				'<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
				'<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;" width=240>' + title + '</td>' +
				'</tr></table>' +
				'</div></div>' +

				'<div style="padding:7px;font:normal 11px arial;width:150px;float:right">' +
					'<a onclick="doClick(this,\'myspace\')" ' + linkColor + '><img src="images/sharing_myspace.gif" width=22 height=22 border=0 ' + imgStyle + '> MySpace<br>' +
					'<a onclick="doClick(this,\'delicious\')" ' + linkColor + '><img src="images/sharing_delicious.gif" width=22 height=22 border=0 ' + imgStyle + '> Delicious<br>' +
					'<a href="' + serviceReference + '/cat300/osxdashboard/' + extraParams + ((doLocking) ? escape('eid_' + $rnd.str(32)) + '/' : '') + 'key_' + cookieKey + '/' + escape(widgetName) + '.wdgt.zip" target="osxdashboard" ' + linkColor + '><img src="images/sharing_osx.gif" width=22 height=22 border=0 ' + imgStyle + '> Mac Dashboard</a><br>' +
	            '</div>' +
				'<div style="padding:7px;font:normal 11px arial;width:100px">' +
					'<a onclick="doClick(this,\'email\')" ' + linkColor + '><img src="images/sharing_email.gif" width=22 height=22 border=0 ' + imgStyle + '> Email</a><br>' +
					'<a onclick="doClick(this,\'facebook\')" ' + linkColor + '><img src="images/sharing_facebook.gif" width=22 height=22 border=0 ' + imgStyle + '> Facebook<br>' +
					'<a onclick="doClick(this,\'twitter\')" ' + linkColor + '><img src="images/sharing_twitter.gif" width=22 height=22 border=0 ' + imgStyle + '> Twitter</a><br>' +
	                '<a href="http://www.google.com/ig/adde?moduleurl=' + serviceReference.substring(7) + '/cat300/gadget/' + extraParams + ((doLocking) ? 'eid_' + $rnd.str(32) + '/' : '') + cookieKey + '.xml" target="igoogly" ' + linkColor + '><img src="images/sharing_google.gif" width=22 height=22 border=0 ' + imgStyle + '> iGoogle</a><br>' +
	            '</div>' +
				'<div style="padding:7px;padding-top:25px;font:normal 11px arial">' +
	                'Use this code to add the widget to your website or blog:' +
					'<table cellspacing=0 cellpadding=0 style="margin-top:4px;"><tr><td><input id="sendEntry" type="text" style="width:205px;padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;" ' +
	       'value=\'<script type="text/javascript" src="' + widgetUrl.replace("frame.jsp", "embed.jsp") + '"></script>\'></td>' +
	       '<td align=right style="padding-left:3px"><input id="copy_btn" type="button" value="Copy code" style="background-color:#E2E2E2;color:#000000;padding-left:4px;font-size:11px;border:0;height:18px;"></td></tr></table>' +
				'</div>' +
			'</div>' +
		   '</div>';

}


var clip = null;
function runGetAndShare() {
	this.metricStr = "";

	this.drawHtml = function() {
		if (typeof this.data == 'undefined')
			return '';
		else {
			if (clip == null) {
				clip = new ZeroClipboard.Client();
				clip.setText('<script type="text/javascript" src="' + getWidgetUrl().replace("frame.jsp", "embed.jsp") + '"></script>');
				clip.setHandCursor( true );
				clip.addEventListener('complete', function(client, text) {
					alert("Embed code copied!");
					trackEvent(GA.act['getwidget'], GA.lab['sharewidget_embed']);
				});
				
				setTimeout(function(){
					clip.glue('copy_btn');
					$(clip.movieId).parentNode.style.zIndex = 1000;
				}, 500);
				
			} else {
				setTimeout(function(){
					$(clip.movieId).parentNode.style.display = 'block';
				}, 500);
			}
			
			return drawGetAndShare(this.data);
		}
	}

	this.doHide = function() {
		GM.sendList = false;
		return true;
	}

	this.handleClick = function(e,x) {
		var d = this.data;

		if (x == 'cancel') {
			_hide(this.id);
			$(clip.movieId).parentNode.style.display = 'none';

		} else if (x == 'email') {
			runDialog('sendDialog',null,'widget',this.fullscreen);
			trackEvent(GA.act['getwidget'], GA.lab['sharewidget_email'], d['sku']);

		} else {
			var xx = {'facebook':true, 'myspace':true, 'delicious':true, 'twitter':true};
			if (typeof xx[x] !== 'undefined') {
				var link = serviceReference + '/cat300/catalog/frame.jsp?key=' + cookieKey + (embedId ? '&eid=' + embedId : '') + (extraQS.length > 0 ? '&' + extraQS : '');
				var title = widgetName + ' - iCatalog Widget';

				var fb = (x == 'facebook') ? FB_Bitly : true;
				var bitlyURL = (Bitly.urls !== null && typeof Bitly.urls['widget'] !== 'undefined') ? Bitly.urls['widget'] : null;

				if (useBitly && fb && bitlyURL) {
					Sharer[x](bitlyURL, title);

				} else if (useBitly && fb && !bitlyURL) {
					Bitly.temp = { sku: 'widget', title: title, url: link, callback: Sharer[x] };
					BitlyClient.shorten(link, 'Bitly.callback');

				} else {
					Sharer[x](link, title);

				}

				trackEvent(GA.act['getwidget'], GA.lab['sharewidget_' + x], d['sku']);
			}
		}
	}
}

function mainLogo() {
	this.drawHtml = function() {
		return '&nbsp;';
//		return '<img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/logo.jpg" border=0 width="135" height="22" >';
	}
}




function loginBox() {
	this.drawHtml = function() {

		if (GM.getshare || GM.my || GM.prof) {
			var backOtherButton = ('').trim();
			if (backOtherButton.length < 1 || backOtherButton == 'null') backOtherButton = null;

			return '<div>' +
				   '<table cellpadding=0 cellspacing=0 border=0 align=right><tr>' +
				   '<td style="color:#0F7ECD;font-size:13px;padding:2px;width:135px;height:29px;cursor:pointer;" align=center valign=middle onClick="doClick(this,\'home\')" style="font-size:11px;cursor:pointer;color:#0F7ECD;">' +
			            (backOtherButton ? '<img src="' + backOtherButton + '" border=0>' : '&#9668; Back to products') +
			       '</td>' +
				   '</tr></table>' +
				   '</div>';
		}

		if (this.topCat) {
			var backBreadButton = ('').trim();
			if (backBreadButton.length < 1 || backBreadButton == 'null') backBreadButton = null;

			var topcat = this.topCat[1];
			if (topcat.length > 17) topcat = topcat.substring(0,15) + '...';

			var backLink = (this.subCat ? 'doClick(this,\'topcat\')' : 'doClick(this,\'back\')');

			return '<div>' +
				   '<table cellpadding=0 cellspacing=0 border=0 align=right><tr>' +
				   '<td style="color:#0F7ECD;font-size:13px;padding:2px;width:135px;height:29px;overflow:hidden;cursor:pointer;" align=center valign=middle onClick="' + backLink + '" style="font-size:11px;cursor:pointer;color:#0F7ECD;">' +
			            (backBreadButton ? '<img src="' + backBreadButton + '" border=0>' : '&#9668; Back') +
			       '</td>' +
				   '</tr></table>' +
				   '</div>';
		}

		var name = getCookie('profName');
		if (name || this.loginName || (!this.signup && !GM.my && !GM.prof)) {

			if (GM.lockListUp) {
				var title = widgetInst.listTitle + '';
				if (title == '' || title == 'null') title = 'Check This Out!';
				return '<table cellpadding=0 cellspacing=0 style="width:140px;height:30px;"><tr><td valign=middle align=center style="font-size:13px;color:#0F7ECD;">' + title + '</td></tr></table>';
			}

			var welink = "http://www.crateandbarrel.com".trim();
			if (welink && welink.length > 0 && welink != 'null') {
				if (welink.indexOf('http://') != 0) welink = '<a href="javascript:void(0);" onClick="' + welink + '" style="color:#0F7ECD;">';
				else welink = '<a href="' + welink + '" onclick="doClick(this, \'welcome\');" style="color:#0F7ECD;" target="offpage">'; 
			}
			else welink = '';

			if (!name) {
				return '<table cellpadding=0 cellspacing=0 style="width:140px;height:30px;"><tr><td valign=middle align=center style="font-size:13px;color:#0F7ECD;">' + welink + 'Shop Our Website ></a></td></tr></table>';
			} else {
				return '<table cellpadding=0 cellspacing=0 style="width:140px;height:30px;"><tr><td valign=middle align=center style="font-size:11px;color:#0F7ECD;">' + welink + 'Shop Our Website > ' + name + '</a></td></tr></table>';
			}

		} else if (GM.my) {
			return '' +
		       '<div style="padding-top:2px;width:140px;color:#000;font-size:11px;font-weight:bold;">My List</div>';

		} else if (GM.prof) {
			return '' +
		       '<div style="padding-top:2px;width:140px;color:#000;font-size:11px;font-weight:bold;"></div>';

		} else {
			return '<a href="javascript:void(0)" onClick="doClick(this,\'back\')" style="color:#FF7B00">Go Back</a>' +
		       '<div style="padding-top:2px;width:140px;color:#000;font-size:11px;font-weight:bold;">Log In or Sign Up</div>';
		}
	}

	this.handleClick = function(e, x) {
		if (x == 'home') {
			if (c$('shareDialog')) c$('shareDialog').hide();
			_hide('lockList');
			GM.lockListUp = false;
			c$('footer').repaint();
//			this.topCat = null;
//			this.subCat = null;
			this.signup = false;
			GM.my = false;
			GM.prof = false;
			GM.getshare = false;
			this.repaint();
			_hide('myList');
			if(c$('sendDialog')) c$('sendDialog').hide();
			if(c$('runGetAndShare')) c$('runGetAndShare').hide();
			_hide('profile');
			_hide('zoomer');
//			GM.cur.handleClick(this,'back');
			return;


		} else if (x == 'topcat') {
			this.subCat = null;
			_hide('listBox');
			GM.cur.handleClick(this,'back');
			if(c$('sendDialog')) c$('sendDialog').hide();
			_show('subCats');
			_hide('zoomer');
			this.repaint();
			return;

		} else if ('back' == x) {
			if(c$('sendDialog')) c$('sendDialog').hide();
			_hide('zoomer');
			this.topCat = null;
			this.subCat = null;
			this.signup = false;
			this.repaint();
			_hide('listBox');
			GM.cur.handleClick(this,'back');

		} else if ('login' == x) {
			_show('loginSignup');
			this.signup = true;
			this.repaint();

		} else if ('logout' == x) {
			this.signup = false;
			this.loginName = null;
			this.repaint();
			c$('footer').repaint();

		} else if ('welcome' == x) {
			var welink = "http://www.crateandbarrel.com".trim();
			trackEvent(GA.act['welcome'], welink);

		} else {
			_hide(this);
			$ajax.jsonGet('/' + webappRoot + '/svc/query-service?{qry:%22storeLookup%22,criteria:{},params:{dbname:"'+dataName+'",zipCode:' + $('zipperbox').value + '},engine:%22catalog-engine%22}', this);
		}
	}

	this.callback = function(r) {
		var c = c$('stores');
		c.data = r.results;
		c.repaint();
		c.show();
	}
}


function actionBox () {
	this.drawHtml = function() {
		return '<font style="font-size:11px;"><a href="javascript:void(0);" onClick="doClick(this, \'print\')">Buy Now</a>&nbsp;&nbsp;&nbsp;' +
		       '<a href="javascript:void(0);" onClick="doClick(this, \'list\')">Save</a>&nbsp;&nbsp;&nbsp;' +
		       '<a href="javascript:void(0);" onClick="doClick(this, \'share\')">Share</a></font>';
//		return '<font style="font-size:11px;"><a href="javascript:void(0);" onClick="doClick(this, \'list\')">Save to My List</a>&nbsp;&nbsp;&nbsp;' +
//		       '<a href="javascript:void(0);" onClick="doClick(this, \'print\')">print</a>&nbsp;&nbsp;&nbsp;' +
//		       '<a href="javascript:void(0);" onClick="doClick(this, \'send\')">send</a></font>';
	}

	this.handleClick = function(e,x) {
		if (x == 'list') {
			GM.sprite.src = GM.curimage;

			_moveTo(GM.sprite, {x:113,y:130});
			_resize(GM.sprite, {w:75,h:75});
			_show(GM.sprite);

			GM.mylist[GM.mylist.length] = GM.thus.d;
			setCookie('catalog-mylist', GM.mylist);
			c$('myList').repaint();

			setTimeout(function() {_amove(GM.sprite, {w:3,h:3,x:70, y:240}, 300, function() {_hide(GM.sprite);});}, 400);

			c$('footer').repaint();


		} else if (x == 'print') {
			launchWindow('Print Window', '<html><style type="text/css">body, td, div {font-family:arial, sans-serif;}</style><body>' + printItem(GM.thus.d) + '<br><br><script type="text/javascript">setTimeout(function(){window.print();},300);</script></body></html>', 400, 600);

		} else if (x == 'share') {
			runDialog('shareDialog',null,GM.thus.d);

		} else {
			GM.dex = x-2;
			resultsRight();
		}
	}
}
var selData = [
	[11, "Baby Toys", 123],
	[22, "Barbie & Ken", 156],
	[33, "Construction Toys", 34],
	[44, "Electronic Toys", 77],
	[55, "Games", 93],
	[66, "Learning Toys & Games", 75],
	[77, "Model Kits", 33],
	[88, "Musical Instruments", 78],
	[99, "Science & Nature", 99],
	[101,"Sports Toys",80],
	[202, "Stuffed Animals", 20],
	[303, "Cars & Trucks", 27]
];

function selectors() {

	this.buttonCount = 6;
	if (this.buttonCount != 2) this.buttonCount = 6;

	//this.y = (this.buttonCount == 6) ? 53 : 76;
	this.y = (this.buttonCount == 6) ? 50 : 66;
	this.x = (this.buttonCount == 6) ? 22 : 19;

	this.pge = 0;
	
	this.drawHtml = function() {
		return this.drawGrid();
	}

	function dex(i) {
		return i;
	}

	this.drawGrid = function() {
		var dx = (this.pge * this.buttonCount) % selData.length;

		if (this.buttonCount == 6) {
			return '<table cellpadding="0" cellspacing="2" border="0">' +
				   '<tr>'
				   + this.doButton(selData[dex(dx)])
				   + this.doButton(selData[dex(dx+1)])
			       + this.doButton(selData[dex(dx+2)])
				   + '</tr>'
				   + '<tr>'
			       + this.doButton(selData[dex(dx+3)])
			       + this.doButton(selData[dex(dx+4)])
			       + this.doButton(selData[dex(dx+5)])
			       + '</tr>'
				   + '</table>';
		} else {
			return '<table cellpadding="0" cellspacing="4" border="0" width=262 height=133>' +
				   '<tr>'
				   + this.doButton(selData[dex(dx)])
				   + this.doButton(selData[dex(dx+1)])
				   + '</tr>'
				   + '</table>';
		}
	}

	this.prevPage = function() {
		this.pge --;
		_show('catsRight');
		if (this.pge == 0) {
			_hide('catsLeft');
		}
		this.repaint();

		_moveTo('selectors', {x:-300, y:this.y});
		_amove('selectors',  {x:this.x, y:this.y}, 300);
		
		trackEvent(GA.act['browse'], GA.lab['browse_prev']);
	}

	this.nextPage = function() {
		this.pge ++;
		this.repaint();

		_show('catsLeft');
		_show('catsRight');

		if (selData.length <= (this.pge+1) * this.buttonCount) _hide('catsRight');

		_moveTo('selectors', {x:300, y:this.y});
		_amove('selectors',  {x:this.x, y:this.y}, 300);
		
		trackEvent(GA.act['browse'], GA.lab['browse_next']);
	}

	this.doButton = function(r) {
		if (!r || !r[0]) return '<td>&nbsp;</td>';
		var img = r[4];

		var showTitle = 'Y' == r[5];
		var showCount = 'Y' == r[6];
		if (!img || (img = img.trim()).length <= 0) img = null;

		var theId = r[0] + '';
		theId = theId.replace(/\'/g,'\\\'');

		if (this.buttonCount == 6) {
			if (r[1] == 'specials' ) return '<td class="selectorOn selectorItem" onClick="' + (r[7] == 'category-link' ?'launchUrl(\'' + r[8] + '\')':'doClick(this, \'' + theId + '\')') + '" ' + (img ? 'style="background-image:url(' + img + ');"' : '') + '><div style="padding-left:3px;padding-right:3px;font-size:12px;font-family:Arial,sans-serif;">' + (showTitle ? r[1] : '&nbsp;') + '<br><span class="selectorCountOn">' + (showCount && r[3] > 1 ?'(' + r[3] + ')':'&nbsp;') + '</span></div></td>';
			return '<td class="selector selectorItem" onClick="' + (r[7] == 'category-link' ?'launchUrl(\'' + r[8] + '\')':'doClick(this, \'' + theId + '\')') + '" ' + (img ? 'style="background-image:url(' + img + ');"' : '') + '><div style="padding-left:8px;padding-right:3px;font-size:14px;text-align:left;font-size:12px;font-family:Arial,sans-serif;">' + (showTitle ? r[1] : '&nbsp;') + '<br><span class="selectorCount" style="font-size:11px;">' + (showCount && r[3] > 1 ? r[3] + ' items':'&nbsp;') + '</span></div></td>';
		} else {
			if (r[1] == 'specials' ) return '<td class="tile2x1 selectorOn selectorItem" onClick="' + (r[7] == 'category-link' ?'launchUrl(\'' + r[8] + '\')':'doClick(this, \'' + theId + '\')') + '" style="' + (img ? 'background-image:url(' + img + ');' : '') + '"><div style="padding-left:3px;padding-right:3px;font-size:12px;font-family:Arial,sans-serif;">' + (showTitle ? r[1] : '&nbsp;') + '<br><span class="selectorCountOn">' + (showCount && r[3] > 1 ?'(' + r[3] + ')':'&nbsp;') + '</span></div></td>';
			return '<td class="tile2x1 selector selectorItem" onClick="' + (r[7] == 'category-link' ?'launchUrl(\'' + r[8] + '\')':'doClick(this, \'' + theId + '\')') + '" ' + (img ? 'style="background-image:url(' + img + ');"' : '') + '><div style="padding-left:8px;padding-right:3px;font-size:14px;text-align:left;font-size:12px;font-family:Arial,sans-serif;">' + (showTitle ? r[1] : '&nbsp;') + '<br><span class="selectorCount" style="font-size:11px;">' + (showCount && r[3] > 1 ? r[3] + ' items':'&nbsp;') + '</span></div></td>';
		}
	}

	this.handleClick = function(e, x) {
		var o = null;
		for (var i = 0; i < selData.length; i++) {
			if (x == selData[i][0]) {
				o = selData[i];
				break;
			}
		}
		if (!o) return;

//		this.sw = true;

		c$('subCats').loadTopCat(o);

		c$('loginBox').topCat = o;
		c$('loginBox').repaint();
		
		GA.category = o[1];
		trackEvent(GA.act['browse'], GA.lab['category'], o[1]);
	}

	this.load = function(storeId) {
		var req = {qry:'categoryLookup', criteria:{}, params:{}, engine:'catalog-engine'};
		req.params.dbname = dataName;
		req.params.storeId = storeId;
		$ajax.jsonPost('/' + webappRoot + '/svc/query-service', req, this);
	}

	this.callback = function(r) {
		if (!this.dataCall) {
			var catCookie = (doLocking && wic) ? wic['catalogshows'] : getCookie('catalogshows');

			if (getCookie('catalogshowAll') || !catCookie || catCookie.length <= 0) {
				selData = r.results;

			} else {
				selData = r.results;

				var newAry = [];
				var temper = r.results;
				for (i in temper) {
					if (catCookie[temper[i][0]]) $a.add(newAry, temper[i]);
				}
				selData = newAry;
			}

			this.pge = 0;
			if ((selData[5] && selData[5][1] != 'specials') || selData[selData.length - 1][1] != 'specials') {
				for (i in selData) {
					if (selData[i][1] == 'specials') {
						var s = $a.removeAt(selData, i);
						if (selData.length < this.buttonCount) $a.add(SelData, s);
						else $a.insert(selData, 5, s);
						break;
					}
				}
			}
			this.repaint();
			GM.ready = true;

		} else {

			this.dataCall = false;
			sldata = r;
			resultsRight();
		}
	}

	this.present = function() {
		_show('back05');
		
		if (this.pge == 0) _hide('catsLeft');
		else _show('catsLeft');

		if (selData.length > this.buttonCount && (selData.length > (this.pge+1) * this.buttonCount)) _show('catsRight');

		_moveTo('selectors', {x:300, y:this.y});
		_amove('selectors',  {x:this.x, y:this.y}, 300);
		
		trackEvent(GA.act['browse']);
	}
}
function signInButton(base) {
	if (base) {
		if (!loggedIn) return '<div class="footerButton" onClick="showProfile()" style="line-height:16px;height:16px;width:61px;overflow:hidden"><a href="javascript:void(0);">Sign In</a></div>';
		else return '<div class="footerButton" onClick="signOut();" style="line-height:16px;height:16px;width:61px;overflow:hidden"><a href="javascript:void(0);">Sign Out</a></div>';
	}
	return '';
}

function buttonMarkup(d, short) {
	var h = '';
	if (d[1] == 'More...') h += '<a href="javascript:void(0);" onMouseOver="doMouseOver(this,\'more\')" onMouseOut="doMouseOut(this,\'more\')">';
	else
	if (d[0].indexOf('http://') != 0) h += '<a href="javascript:void(0);" onClick="' + d[0] + '">';
	else h += '<a href="' + d[0] + '" target="offwidget" onClick="doClick(this, \'url\');">';


	return h + '<div class="footerButton" style="height:16px;width:' + (short==1?60:short==2?59:62) + 'px;overflow:hidden;line-height:16px;">' + d[1] + '</div></a>';

}

var searchInputText = ' Search all products';

function footer() {
	this.subOpenForLunch = 0;

	this.drawHtml = function() {
		var lnks = [];
		var tmp = 'http://www.keyboardmonkey.com';
		var tmp = 'getWidget()';
		if (tmp && tmp != '' && tmp != 'null') $a.add(lnks, [tmp,'Get & Share']);
		tmp = 'http://www.crateandbarrel.com/Customer-Service/About-Us/';
		if (tmp && tmp != '' && tmp != 'null') $a.add(lnks, [tmp,'About']);
		tmp = '';
		if (tmp && tmp != '' && tmp != 'null') $a.add(lnks, [tmp,'']);

		var bc = 1; // 1 for the "my list"
		if (widgetInst) bc++;
		bc += lnks.length;
		this.buttonCount = bc;

		this.lnks = lnks;

		if (!footerLinkText && this.buttonCount > 3 && !c$('submenu')) $comp.create(new submenu(this), "submenu");

		h = '<div style="background-color:#E2E2E2;">' +
		       '<form onsubmit="doClick(this,\'search\'); return false;">' +
		       '<table cellpadding=0 cellspacing=0 width="100%" style="padding-left:2px;"><tr>';

		if (activeSearch) {
			h += '<td style="font-size:9px;line-height:8px;height:10px;overflow:hidden;width:116px">' +
		         '<input type=text id="footerSearch" value="' + searchInputText + '" onFocus="if(this.value == \'' + searchInputText + '\') this.value = \'\';" onBlur="if(this.value == \'\') this.value = \'' + searchInputText + '\';" style="margin:0;border-width:0;font-size:9px;height:16px;width:92px;font-style:italic;color:#000;" ></td>';
		}
		h += '<td>';

		if (!footerLinkText) {
		       h += '<table cellpadding=0 cellspacing=2><tr>' +
		       '<td>' + buttonMarkup([(GM.lockListUp?'hideLockList()':'showMyList()'),(c$('lockList') ? (GM.lockListUp ? 'Browse All' : 'Featured') : 'My List' )], 1) + '</td>' +
		       (this.buttonCount > 1 ?
		            '<td>' + buttonMarkup(this.lnks[0]) + '</td>' +
		            (this.buttonCount > 2 ? '<td>' + (this.buttonCount > 3 ? buttonMarkup(['doClick(this,\'more\');', 'More...']) : (widgetInst ? signInButton(true) : buttonMarkup(this.lnks[1]))) + '</td>' : '')
				: '') +
		       '</tr></table></td></tr></table>';
		} else {
		       h += '<table cellpadding=0 cellspacing=2><tr><td><div class="footerLink" style="padding-left:4px;line-height:16px;height:16px;width:100%;overflow:hidden;"><a href="' + footerLinkUrl + '" target="offsite" onClick="doClick(this, \'url\');">' + footerLinkText + '</a></div></td></tr></table></td></tr></table>';
		}
		if (activeSearch){
			h += '<img src="images/search-button.gif" onClick="doClick(this,\'search\')" style="position:relative;top:-18px;left:94px;cursor:pointer;">';
		}
		return h + '</div></form>';
	}

	this.handleMouseOver = function(e,x) {
		this.showSubmenu();
		trackEvent(GA.act['more']);
	}
	this.handleMouseOut = function(e,x) {
		this.hideSubmenu();
	}

	this.handleClick = function(e,x) {
		if (x == 'more') {
			this.toggleSubmenu();

		} else if ('mylist' == x) {
			showMyList();

		} else if ('share' == x) {
			getWidget();

		} else if ('search' == x) {
			var s = (($$('footerSearch').value + '').replace(/<\/?[^>]+(>|$)/g, "")).trim();
			if (s != '' && s != searchInputText) {
				var c = c$('resultsBox');
				c.title = s;
				c.runSearch(s);
				c.repaint();
				_show('resultsBox');
			}
		} else if ('url' == x) {
			trackEvent(GA.act['footer'], e.href);
		}
	}

	this.toggleSubmenu = function() {
		if (!this.subby) {
			this.subby = true;
			this.showSubmenu();
		} else {
			this.subby = false;
			this.hideSubmenu();
		}
	}

	this.subIntent = 0;
	this.subPos = 0;
	this.showSubmenu = function() {
		this.subIntent = 2;
		$obj.timeout(this, 'runSub', 50);
	}
	this.hideSubmenu = function() {
		this.subIntent = 0;
		$obj.timeout(this, 'runSub', 50);
	}
	this.runSub = function() {
		if (this.subPos == this.subIntent) return;

		if (this.subPos == 1) {
			$obj.timeout(this, 'runSub', 50);

		} else if (this.subIntent == 2) {
			this.subPos = 1;
			_moveTo('submenu',{x:234,y:250});
			_show('submenu');
			_amove('submenu',{x:234,y:218-((this.buttonCount-2)*19)},300, function() {
				setTimeout(function() {c$('footer').subPos = 2;}, 200);
			});

		} else {
			if (this.subPos < 2) return;
			this.subPos = 1;
			_amove('submenu',{x:234,y:250},300, function() {
				_hide('submenu');
				setTimeout(function() {c$('footer').subPos = 0;}, 200);
			});
		}
	}

	function submenu(p) {
		this.p = p;

		this.drawHtml = function() {
			var tmp = this.p.buttonCount;
			if (widgetInst) tmp --;

			var h = '<div onMouseOver="doMouseOver(this)" onMouseOut="doMouseOut(this)"><div style="padding:2px;font-size:9px;width:65px;text-align:center;"><a href="http://www.catalogchoice.org/icatalogs" onClick="doClick(this, \'url\');" target="offWidget" class="title">iCatalog</a></div>' +
			       '<table cellspacing=2 cellpadding=0 width=65>' +
			       (widgetInst ? '<tr><td class="subButton">' + signInButton(true) + '</td></tr>':'');

			for (var i = 1; i < tmp-1; i++) {
				h += '<tr><td class="subButton">' + buttonMarkup(this.p.lnks[i]) + '</td></tr>';
			}

			h += '</table></div>';
			return h;
		}

		this.handleMouseOver = function() {
			c$('footer').showSubmenu();
		}

		this.handleMouseOut = function() {
			c$('footer').hideSubmenu();
		}
		
		this.handleClick = function(e, x) {
			if ('url' == x) {
				trackEvent(GA.act['footer'], e.href);
			}
		}
	}

	if (this.buttonCount > 3) $comp.create(new submenu(this), "submenu");

}


function footerOff() {

	var lnks = [['showSearch()','Search']];
	var tmp = 'showMyList()';
	if (tmp && tmp != '' && tmp != 'null') $a.add(lnks, [tmp,'My List']);
	tmp = 'showProfile()';
	if (tmp && tmp != '' && tmp != 'null') $a.add(lnks, [tmp,'Preferences']);
	tmp = 'getWidget()';
	if (tmp && tmp != '' && tmp != 'null') $a.add(lnks, [tmp,'Get & Share']);
	tmp = 'http://www.crateandbarrel.com/Customer-Service/About-Us/';
	if (tmp && tmp != '' && tmp != 'null') $a.add(lnks, [tmp,'About']);

	this.lnks = lnks;

	this.drawHtml = function() {
		var h = '<div  style="padding-left:10px;">';
		var hx = '';
		for (var i = 0; i < this.lnks.length; i++) {
			var x = '';
			var link = this.lnks[i];
			var noGetWidget = !showGetShare && link[0].trim() == 'getWidget()';
			
			if (!doLocking) {
				if (noGetWidget) {
					continue;
				} else {
					if (link[0].indexOf('http://') != 0) {
						x += '<a href="javascript:void(0);" onClick="' + link[0] + '">' + link[1] + '</a>';
					} else {
						x += '<a href="' + link[0] + '" target="offwidget">' + link[1] + '</a>';
					}
				}

			} else {
				if (link[0].trim() == 'showProfile()') {
					if (!embedId) continue;
					x += '<a href="javascript:void(0);" onClick="' + link[0] + '">'
							+ ((embedId && !widgetInst && !loggedIn) ? 'Register' : (loggedIn ? link[1] : 'Sign In'))
							+ '</a>';
				} else if (link[0].trim() == 'showMyList()') {
					x += '<a href="javascript:void(0);" onClick="' + link[0] + '">'
							+ ((embedId && !loggedIn) || (!embedId && widgetInst && !loggedIn) ?
									((embedId && !c$('lockList')) ? link[1] : 'Featured List') : link[1])
							+ '</a>';
				
				} else if (noGetWidget) {
					continue;

				} else if (link[0].indexOf('http://') != -1) {
					x += '<a href="' + link[0] + '" target="_blank">' + link[1] + '</a>';

				} else {
					x += '<a href="javascript:void(0);" onClick="' + link[0] + '">' + link[1] + '</a>';
				}
			}
		    
		    if (hx.trim() !== '') x = '&nbsp;&nbsp;|&nbsp;&nbsp;' + x;
			hx += x;
		}
		return h + hx + '</div>';
	}

	this.handleClick = function(e, x) {
		if (GM.prof && GM.dirtyCats) {
			GM.dirtyCats = false;
			c$('selectors').load();
			_hide('resOne');
			_hide('resTwo');
		}

		GM.my = false;
		GM.prof = false;
		c$('selectors').repaint();
		if (c$('selectedBox').store) _hide('loginBox');
		_hide('myList');
		_hide('profile');
		_show('selectedBox');
		c$('loginBox').repaint();
		this.repaint();
	}
}

function results() {
	this.drawHtml = function() {
		var w = 300-(2*2);
		var h = 235-67;
		return '<div align="center" style="width:' + w + 'px;height:' + h + 'px;"></div>';
	}
}




function searchBox(box) {
	this.box = box;

	this.drawHtml = function(lnks) {
		var h = '<form onsubmit="doClick(this,\'search\'); return false;"><div style="background-color:#444444"><div style="width:' + this.box.w + 'px;height:17px;line-height:15px; position:relative;">' +
		       '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
		       '<td style="font-size:12px;line-height:11px;color:#FFFFFF;font-weight:bold;" width=120>Search</td>' +
		       '<td style="font-size:11px;line-height:11px;color:#FFFFFF; width:25px;text-align:right;"><a href="javascript:void(0)" style="color:#FFFFFF; position:absolute; top:0; right:2px; _top:2px; _right:4px;" onClick="doClick(this,[\'close\'])">[ x ]</a>' +
		       '</td>' +
		       '</tr></table>' +
		       '<div style="width:' + this.box.w + 'px;background-color:#fff"><div style="padding:5px;">' +
		        '<table><tr><td><input type=text id="searchInput" value="Please enter keyword." onFocus="if(this.value == \'Please enter keyword.\') this.value = \'\';" onBlur="if(this.value == \'\') this.value = \'Please enter keyword.\';" style="color:#000;font-size:10px;padding-left:4px;border:1px solid #aaa;height:18px;width:250px;" ></td>' +
		        '<td><input type=submit value="GO" style="background-color:#444444;color:#FFFFFF;border:0;cursor:pointer;margin-left:4px;font-size:10px;padding-left:4px;height:18px;width:24px;" ></td></tr></table>' +
		       '</div></div>' +
				'</div></div></form>';

		return h;
	}

	this.handleClick = function(e, x) {
		if ('search' == x) {
			if(c$('runGetAndShare')) c$('runGetAndShare').hide();
			var s = (($$('searchInput').value + '').replace(/<\/?[^>]+(>|$)/g, "")).trim();
			if (s != 'Enter search term here' && s != '') {
				var c = c$('resultsBox');
				c.title = s;
				c.runSearch(s);

				c.repaint();

				_show('resultsBox');
				_hide(this);
				
				trackEvent(GA.act['search'], GA.act['search'], s);
			}

		} else if ('close' == x) {
			_hide(this);
			trackEvent(GA.act['search'], GA.lab['search_close']);
		}
	}
}

function resultsBox(box) {
	this.box = box;
	this.flink = [];

	this.drawHtml = function(lnks) {
		if (this.resultData) return this.drawHtmlWithData(this.resultData);
		var title = this.title;
		if (title && title.length > 25) title = title.substring(0,25) + '...';


		var detailSpinner = 'http://widget-images.catalogchoice.org/ajax-loader-3.gif'.trim();
		if (detailSpinner.length < 1 || detailSpinner == 'null') detailSpinner = 'pixel.gif';

		var h = '<div style="background-color:#E2E2E2"><div style="width:' + this.box.w + 'px;height:17px;line-height:15px;">' +
		       '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
		       '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;">Searching for \'' + title + '\'...</td>' +
		       '<td style="font-size:11px;line-height:11px;color:#000000;width:25px;text-align:right;"><a href="javascript:void(0)" style="color:#000000" onClick="doClick(this,[\'close\'])">[ x ]</a>' +
		       '</td>' +
		       '</tr></table>' +
		       '<div style="width:' + this.box.w + 'px;height:' + (this.box.h - 33) + 'px;overflow-y:scroll;">' + '<div id="myListDoc" align=center>' +
		        '<br><br><img src="' + detailSpinner + '">' +
		       '</div></div>' + '</div></div>';

		return h;
	}

	this.handleClick = function(e, x) {
		if ('more' == x) {
			this.page ++;
			var req = {
				page: this.page,
				sourceName: dataName,
				search:this.searchTerm
			};
			this.more = e;
			$ajax.jsonPost('/' + webappRoot + '/gxsvc/search', req, {callback:function(rslt) {
				try {
				if (!rslt || rslt.result != "ok")  return;

				var r = {headers:["item_id","cat_id","product_category","subcat_id","product_type","sku","title","link","image_link","price","description","tile_url","show_title","show_count","cat_order","sale_price","subcat_order", "item_type", "publish_date", "short_description"],results:[]};
				r.fork = function dat(i) {
					var o = {};
					var d = this.results[i];
					if (d) {
						for (i in r.headers) o[r.headers[i]] = d[i];
					}
					return o;
				}


				for (i in rslt.hits) {
					var h = rslt.hits[i];
					var d = [h.itemId, 0, null, 0, null, h.sku, h.title, h.link, h.imageLink, h.price, h.description, null, null, 0, 0, h.salePrice, 0, h.itemType, h.publishDate, h.shortDescription];
					$a.add(r.results, d);
				}

				var c = c$('resultsBox');
				var elem = $$('searchResultsDiv');

				for (i in r.results) {

					c.resultData.results[c.resultData.results.length] = r.results[i];

					var d = r.fork(i);
					c.data[c.data.length] = d;

					GM.curimage = d['image_link'];

					var deev = document.createElement('div');
					elem.insertBefore(deev, c.more);

					deev.innerHTML = drawSearchResult(d, c.lnks);
				}

				if (rslt.remain <= 0) _hide(c.more);
				} catch (e) {
					if (extraParams['arron']) alert(e);
				}

			}});

			trackEvent(GA.act['search'], GA.lab['search_more']);

		} else if ('close' == x) {
			_hide(this);
			trackEvent(GA.act['search'], GA.lab['search_close']);

		} else if (x[0] == 'list') {
			for (i in this.data) {
				if (this.data[i]['item_id']+'' == x[1]) {
					var item = this.data[i];

					GM.sprite.src = item['image_link'];
					_moveTo(GM.sprite, {x:175,y:60});
					_resize(GM.sprite, {w:75,h:75});
					_show(GM.sprite);

					GM.mylist[GM.mylist.length] = item['sku'];
					setCookie('catalog-mylist', GM.mylist);
					c$('myList').repaint();

//					setTimeout(function() {_amove(GM.sprite, {w:3,h:3,x:20, y:245}, 300, function() { _hide(GM.sprite); self.repaint(); });}, 400);
					setTimeout(function() {_amove(GM.sprite, {w:3,h:3,x:150, y:245}, 300, function() { _hide(GM.sprite); });}, 400);

					c$('footer').repaint();
					trackEvent(GA.act['ads'], GA.lab['ad_save'], item['sku']);

				}
			}
			e.parentNode.innerHTML = '';

		} else if (x[0] == 'share') {
			for (i in this.data) {
				if (this.data[i]['item_id']+'' == x[1]) {
					runDialog('shareDialog',null,this.data[i],true);
					trackEvent(GA.act['share'], GA.lab['ad_share_open'], this.data[i].sku);
					return;
				}
			}

		} else if (x[0] == 'print') {
			for (i in this.data) {
				if (this.data[i]['item_id'] == x[1]) {
					GM.popper = this.data[i];
					popDetails();
					trackEvent(GA.act['ads'], GA.lab['ad_print'], this.data[i].sku);
					return;
				}
			}
		
		} else if (x[0] == 'buy') {
			for (i in this.data) {
				if (this.data[i]['item_id'] == x[1]) {
					var link = this.data[i].link;
					if (lsn_eid && link) link = link.replace(/\@lsn_eid\@/gi, lsn_eid);
					if (extraParams['AID'] && link) link = link.replace(/\@AID\@/gi, extraParams['AID']);
					if (extraParams['PID'] && link) link = link.replace(/\@PID\@/gi, extraParams['PID']);
					if (extraParams['SID'] && link) link = link.replace(/\@SID\@/gi, extraParams['SID']);

					var sku = this.data[i].sku;

					if (typeof openUrl !== 'undefined') {
						openUrl(link);
					} else if (typeof widget !== 'undefined' && typeof widget.openURL !== 'undefined') {
						widget.openURL(link);
					} else if (typeof window !== 'undefined' && typeof window.open !== 'undefined') {
						window.open(link);
					}

					if (typeof Affiliate !== 'undefined') Affiliate.redirect('click');
					trackEvent(GA.act['ads'], GA.lab['ad_buy'], sku);

					return;
				}
			}
		}
	}

	this.runSearch = function(s) {
			this.searchTerm = s;
			this.page = 0;
			var req = {
				search:s,
				sourceName: dataName
			};
			$ajax.jsonPost('/' + webappRoot + '/gxsvc/search', req, this);
		trackEvent(GA.act['search'], GA.lab['search_query'], s);
	}



	this.callback = function(rslt) {
		if (!rslt || rslt.result != "ok")  return;

		var r = {headers:["item_id","cat_id","product_category","subcat_id","product_type","sku","title","link","image_link","price","description","tile_url","show_title","show_count","cat_order","sale_price","subcat_order", "item_type", "publish_date", "short_description"],results:[]};
		r.fork = function dat(i) {
			var o = {};
			var d = this.results[i];
			if (d) {
				for (i in r.headers) o[r.headers[i]] = d[i];
			}
			return o;
		}


		if (rslt.hitCount <= 0) {
			this.count = 0;

		} else {
			this.count = rslt.hitCount;

			for (i in rslt.hits) {
				var h = rslt.hits[i];
				var d = [h.itemId, 0, null, 0, null, h.sku, h.title, h.link, h.imageLink, h.price, h.description, null, null, 0, 0, h.salePrice, 0, h.itemType, h.publishDate, h.shortDescription];
				$a.add(r.results, d);
			}
		}
		this.resultData = r;
		this.container().innerHTML = this.drawHtmlWithData(r);
	}

	this.drawHtmlWithData = function(r) {
		var lnks = this.lnks;
		this.lnks = null;
		this.data = [];

		var drawn = [];

		var h = '';
		for (i in r.results) {
			var d = r.fork(i);
			this.data[i] = d;

			if ($a.indexOf(drawn, d['sku']) > -1) continue;
			$a.add(drawn, d['sku']);

			GM.curimage = d['image_link'];

			h += drawSearchResult(d, lnks);
		}

		if (h.trim() == '') {
			h = '<div style="text-align:left; padding:10px;">'
				+ '<p style="margin:0 0 10px;">Your search for <strong>"' + this.title + '"</strong> did not match any results.</p>'
				+ '<ul style="margin:0 0 10px 20px; padding:0;">'
				+ '<li>Please make sure all words are spelled correctly.</li>'
				+ '<li>Try different keywords.</li>'
				+ '<li>Or try more general keywords.</li>'
				+ '</ul>'
				+ '</div>';
		}

		var title = this.title;
		if (title && title.length > 25) title = title.substring(0,20) + '...';

		return '<div style="background-color:#E2E2E2"><div style="width:' + this.box.w + 'px;height:17px;line-height:15px;">' +
		       '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
		       '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;" >Found ' + this.count + ' for \'' + title + '\'</td>' +
		       '<td nowrap style="font-size:11px;line-height:11px;color:#000000;width:25px;text-align:right;"><a href="javascript:void(0)" style="color:#000000" onClick="doClick(this,[\'close\'])">[ x ]</a>' +
		       '</td>' +
		       '</tr></table>' +
		       '</div></div>' +

		       '<div style="width:' + this.box.w + 'px;height:' + (this.box.h - 37) + 'px;overflow-y:scroll;">' +
				        '<div id="searchResultsDiv" align=center>' + h +
		       (this.count > 50 ? '<div onClick="doClick(this, \'more\');" style="padding:5px; font-size:12px; color:#555555; cursor:pointer;">Show more...</div>' : '') +
		       '</div></div>' +
				'</div></div>';
	}
}


function drawSearchResult(d, lnks) {
	var h = '';
	var p, img = d['image_link'];
	GM.curimage = img;

	d['title'] = parseText(d['title']);
	
	var desc = d.description;
	desc = parseText(desc);
	desc = desc.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/<\/?[^>]+>/gi," ");
	if (desc.length > 150) {
		desc = desc.substring(0,100);
		while (desc.charAt(desc.length-1) != ' ') desc = desc.substring(0,desc.length-1);
		desc += '...'
	}

	var article = (d['item_type'] == 'article');

	var price = d.price;
	if (d.price && (d.price = d.price.trim()) != '' && (d.price+'') != 'null') {
		price = d.price;
		var x = (typeof price == 'string') ? price.split('$') : price;
		price = (typeof x == 'object' && x.length == 2) ? formNum(x[1]) : formNum(price);

		if (isNaN(price)) {
			var p = d.price;
			var a = (p.split('$').length > 2) ? p.replace(/\$/gi,'').split(' - ') : null;

			a[0] = formNum(a[0]);
			a[1] = formNum(a[1]);

			price = '$' + a[0] + ' - $' + a[1];

		} else {
			price = '$' + price;

		}

	} else {
		price = '';
	}


	var sale_price = null;
	var samePrice = (d.price == d.sale_price);
	if (!samePrice && d.sale_price && d.sale_price != 0) {
		sale_price = parseFloat(d.sale_price);
		sale_price = sale_price.toFixed(2);

		var x = sale_price.split('.')[1];
		var y = parseFloat(x) == 0;

		sale_price = (y) ? parseFloat(sale_price).toFixed(0) : sale_price;
		sale_price = parseFloat(sale_price) !== 0 ? sale_price : null;
	}

	var saved = false;

	// Hide "save" link for anonymous users if the "featured list" is enabled.
	if (((embedId && !loggedIn) || (!embedId && widgetInst && !loggedIn)) && !(embedId && !c$('lockList'))) {
		saved = true;
	} else {
	for(i in GM.mylist) {
			if (GM.mylist[i] == d['sku'])
			saved = true;
	}
	}
	
	var zoomPopup = 'link';
	var detailClick = '';

	if (zoomPopup == 'link') detailClick = ' onClick="doClick(this, [\'buy\', ' + d['item_id'] + '])" ';
	else detailClick = ' onClick="doClick(this, [\'print\', ' + d['item_id'] + '])" ';
	

			h += '<div class="search-item"' + (!article?' style="height:122px;"' : '') + '>' +
		 '<div style="padding:3px;padding-left:7px;">' +
		 '<font style="font-size:12px; color:#555555; font-weight:bold;">' + d.title + '</font>' +
		 '</div>' +
		 '<table cellpadding=0 cellspacing=0 border=0 width="265"><tr><td valign="top">' +
		 (!article?'<div style="width:85px;height:75px;overflow:hidden;"><a ' + detailClick + '><img src="' + img + '" width=75 border=0 style="padding-left:5px;padding-right:5px;"></a></div>' : '&nbsp;') +
		 '</td><td valign="top" style="padding:2px; font-size:11px;">' +
		 '<font color="#848484">' +
		 '<a onclick="doClick(this, [\'buy\', ' + d['item_id'] + ']); return false;" href="' + d.link + '" target="offwidget" style="color:#0F7ECD">' + (price.length > 0 ? 'Buy Now' : 'More Info') + '</a>' +
		 ' | ' +
		 (!article?'<a href="javascript:void(0)" ' + detailClick + ' style="color:#848484">Details</a> | ' : '') +
		 '<a href="javascript:void(0)" onClick="doClick(this,[\'share\',\'' + d['item_id'] + '\'])" style="color:#848484;">Share</a> ' +
		 (!saved && activeFooterMenu ? '<span>| <a href="javascript:void(0)" onClick="doClick(this,[\'list\',\'' + d['item_id'] + '\'])" style="color:#848484;">Save</a></span>' : '' ) +
		 '</font><br>' +
		 '<div style="padding-top:0px;">' +
		 '<div style="padding-top:2px;"><font style="font-size:11px;font-weight:normal;color:#555555"><font style="color:#000000;">' +
			     (!article && price.length > 0 ? price  + (sale_price ? '</font><font style="color:#000000"> Now on Sale $' + sale_price : '') : '') + '</font><br>' + desc + '</font></div>' +
		 '</td></tr></table>' +
		   (lnks? '<div style="font-size:11px;">' + d['listing_deal'] + '</div>':'') +
		   '</div>';

	return h;
}














//"store_id","unit_id","chain_id","name","image","phone","latitude","longitude","address","city","state","zip","county","last_update","created",

function stores() {
	this.drawHtml = function() {
		var h = '';
		if (this.data) {
			for (var i = 0; i < this.data.length; i++) {
				var d = this.data[i];
				var addr = d[8] + ', ' + d[9] + ', ' + d[10] + ', ' + d[11];
				h += '<div class="storeOpt" onClick="doClick(this,' + d[0] + ')">' + d[3] + '<br><div class="address">' + addr + '</div></div>'
			}
		}
		return h;
	}

	this.handleClick = function(e, x) {
		_hide(this);

		for (var i = 0; i < this.data.length; i++) {
			if (this.data[i][0] == x) {
				GM.store = this.data[i];
				setCookie('catalog-store', GM.store);
				c$('selectedBox').selected = null;
				c$('selectedBox').repaint();
				break;
			}
		}

		this.storeId = x;

//		_hide('actionBox');
		_hide('results');
		_hide(GM.r1);
		_hide(GM.r2);
		_hide('splashBox');
		c$('selectors').load(x);
		_show('selectedBox');
	}

	this.show = function() {
		var b = $('bounder');
		var w = 150-2+1;
		_fondl(b, {x:150, y:2-2, w:w, h:2}, true);

		_amove(b, {w:w, h:250}, 300, function() {
			_hide('bounder');
			_show('stores');
		});
	}
}



function splashBox() {
	this.drawHtml = function() {
		var splashImage = 'http://widget-images.catalogchoice.org/CrateBarrel-Images/body_080409.jpg';
		var engaging = '<img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/body_080409.jpg" >';

		var lc = splashImage.toLowerCase();
		if (lc.indexOf('.gif') < 0 && lc.indexOf('.jpg') < 0 && lc.indexOf('.png') < 0 && engaging.indexOf('<img') == 0) {
			return '<div onMouseOver="doMouseOver(this)">http://widget-images.catalogchoice.org/CrateBarrel-Images/body_080409.jpg</div>';

		} else return '<div onMouseOver="doMouseOver(this)"><img src="http://widget-images.catalogchoice.org/CrateBarrel-Images/body_080409.jpg" ></div>';
	}

	this.handleMouseOver = function() {
		if (GM.ready) {
			c$('selectors').present();
			_hide(this);
			trackEvent(GA.act['splash'], GA.lab['splash_hide']);
		}
	}
}
function myListActions() {
	if (!GM.mylist || GM.mylist.length <= 0) return '<table cellpadding=0 cellspacing=2 class="myListButtons"><tr><td  height=13 width=61 >&nbsp;</td></tr></table>';
	return '<table cellpadding=0 cellspacing=2 class="myListButtons"><tr>' +
		       (widgetInst && doLocking && loggedIn ? '<td style="background-color:#E2E2E2;color:#000000;font-size:9px;cursor:pointer;" height=13 width=61 align=center valign=middle  onClick="c$(\'profile\').handleClick(this,\'publist\');c$(\'myList\').repaint();"><a href="javascript:void(0);">' +
		                                (getCookie('pubMyList') ? 'Don\'t Feature' : 'Feature List') + '</a></td>':'') +
		       '<td style="background-color:#E2E2E2;color:#000000;font-size:9px;cursor:pointer;" onClick="doClick(this,[\'shareall\'])" height=13 width=61 align=center valign=middle><a href="javascript:void(0);">Share All</a></td>' +
		       '<td style="background-color:#E2E2E2;color:#000000;font-size:9px;cursor:pointer;" onClick="doClick(this,[\'removeAll\'])" height=13 width=61 align=center valign=middle><a href="javascript:void(0);">Remove All</a></td>' +
		       '</tr></table>';
}

function myList(box) {
	this.box = box;

	this.drawHtml = function(lnks) {
		var h = '';

		if (!GM.mylist || GM.mylist.length <= 0) {
			h = '<div style="padding:10px;text-align:left;color:#555555">Your list is empty!<br><br>It\'s easy to make a list - just click "Save" when you view a product you like, and it will be added to this list. Once you\'ve built a list, you can share it with others or send it to yourself in an email!</div>';

		} else {
			h = '<div style="padding:10px;text-align:left;color:#555555">Loading...</div>';

			var numList = $json.toString(GM.mylist);
			numList = numList.substring(1,numList.length-1);
			var req = {
				qry: "itemsBySku",
				criteria: {},
				params: { dbname:dataName, skus:numList },
				engine: 'catalog-engine'
			};

			this.lnks = lnks;
			$ajax.jsonPost('/' + webappRoot + '/svc/query-service', req, this);
		}

		if (lnks) return h;
		else h = '<div style="width:' + this.box.w + 'px;height:' + (this.box.h - 16) + 'px;overflow-y:scroll;">' +
		        '<div id="myListDoc" align=center>' + h;


		h += '</div></div>';
		return '<div style="background-color:#E2E2E2"><div style="width:' + this.box.w + 'px;height:17px;line-height:15px;">' +
		       '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
		       '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;">My List</td>' +
		       '<td style="font-size:11px;line-height:11px;color:#000000;" align=right>' +
		       myListActions() +
		       '</td>' +
		       '</tr></table>' +
		       '</div></div>' + h;
	}

	this.handleClick = function(e, x) {
		if (x == 'publist') {
			//setCookie('pubMyList', e.checked);
			var flag = !getCookie('pubMyList');
			setCookie('pubMyList', flag);
			setCookie('listOnLoad', flag);
			c$('profile').repaint();

//			if (flag) showLockList();

			this.repaint();
//			var t = e.innerHTML + '';
//			if (t.indexOf("Stop") > -1) e.innerHTML = 'Feature List';
//			else e.innerHTML = 'Stop Feature';

		} else if (x[0] == 'shareall') {
		 	if (typeof GM.mylist == 'object' && GM.mylist.length > 0) {
			GM.sendList = true;
			runDialog('sendDialog',null,null);
				trackEvent(GA.act['share'], GA.lab['ad_share_email'], GM.mylist.join('|'));
			} else {
				alert('There are no items in your list yet!');
			}
			return;

		} else if (x[0] == 'close') {
			//if (this.primeLoad) {
			//	c$('selectors').present();
			//	splashMe();
			//	this.primeLoad = false;
			//}

			GM.my = false;
			c$('loginBox').repaint();
			_hide(this);

		} else if (x[0] == 'print') {
			for (i in this.data) {
				if (this.data[i]['item_id'] == x[1]) {
					GM.popper = this.data[i];
					popDetails();
					trackEvent(GA.act['ads'], GA.lab['ad_print'], this.data[i].sku);
					return;
				}
			}
		
		} else if (x[0] == 'buy') {
			for (i in this.data) {
				if (this.data[i]['item_id'] == x[1]) {
					var link = this.data[i].link;
					var sku = this.data[i].sku;
					
					if (typeof openUrl !== 'undefined') {
						openUrl(link);
					} else if (typeof widget !== 'undefined' && typeof widget.openURL !== 'undefined') {
						widget.openURL(link);
					} else if (typeof window !== 'undefined' && typeof window.open !== 'undefined') {
						window.open(link);
					}
					
					if (typeof Affiliate !== 'undefined') Affiliate.redirect('click');
					trackEvent(GA.act['ads'], GA.lab['ad_buy'], sku);
					
					return;
				}
			}
		
		} else if (x[0] == 'removeAll') {
			var skus = GM.mylist.join('|');
			GM.mylist = [];
			this.repaint();
			c$('resOne').repaint();
			setCookie('catalog-mylist', []);
			trackEvent(GA.act['mylist'], GA.lab['mylist_removeall'], skus);

		} else if (x[0] == 'share') {
			for (i in this.data) {
				if (this.data[i]['item_id']+'' == x[1]) {
					runDialog('shareDialog',null,this.data[i]);
					trackEvent(GA.act['share'], GA.lab['ad_share_open'], this.data[i].sku);
					return;
				}
			}

		} else if (x[0] == 'remove') {
			var mod = false;
			for (i in GM.mylist) {
				if (GM.mylist[i] == x[1]) {
					$a.remove(GM.mylist, GM.mylist[i]);
					mod = true;
				}
			}
			if (mod) {
				this.repaint();
				c$('resOne').log = false;
				c$('resOne').repaint();
				setCookie('catalog-mylist', GM.mylist);
				trackEvent(GA.act['mylist'], GA.lab['mylist_remove'], x[1]);
			}
		
		//} else if (x[0] == 'buy') {
		//	if (typeof Affiliate !== 'undefined') Affiliate.redirect('click');
		//	trackEvent(GA.act['ads'], GA.lab['ad_buy'], x[1]);
		}
	}

	this.callback = function(r) {
		if (!r || !r.results || !r.results.length >0) return;

		var lnks = this.lnks;
		this.lnks = null;
		this.data = [];

		var drawn = [];

		var h = '';
		for (i in r.results) {
			var d = r.fork(i);
			this.data[i] = d;

			if ($a.indexOf(drawn, d['sku']) > -1) continue;
			$a.add(drawn, d['sku']);

			var p, img = d['image_link'];
			GM.curimage = img;

			var article = (d['item_type'] == 'article');

			d['title'] = parseText(d['title']);
	
			var desc = d.description;
			desc = parseText(desc);
			desc = desc.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/<\/?[^>]+>/gi," ");
			if (desc.length > 150) {
				desc = desc.substring(0,150);
				while (desc.charAt(desc.length-1) != ' ') desc = desc.substring(0,desc.length-1);
				desc += '...'
			}

			if (lsn_eid && d.link) d.link = d.link.replace(/\@lsn_eid\@/gi, lsn_eid);
			if (extraParams['AID'] && d.link) d.link = d.link.replace(/\@AID\@/gi, extraParams['AID']);
			if (extraParams['PID'] && d.link) d.link = d.link.replace(/\@PID\@/gi, extraParams['PID']);
			if (extraParams['SID'] && d.link) d.link = d.link.replace(/\@SID\@/gi, extraParams['SID']);

			var price;
			if (d.price && d.price.trim().length > 0) price = '$' + formNum(d.price);
			else price = '';

			var zoomPopup = 'link';
			var detailClick = '';
			
			if (zoomPopup == 'link') detailClick = ' onClick="doClick(this, [\'buy\', ' + d['item_id'] + '])" ';
			else detailClick = ' onClick="doClick(this, [\'print\', ' + d['item_id'] + '])" ';

			h += '<div style="border-bottom:1px solid #ccc;padding-top:3px;padding-bottom:3px;text-align:left;">' +
			     '<div style="padding:3px;padding-left:7px;">' +
			     '<font style="font-size:12px; color:#555555; font-weight:bold;">' + d.title + '</font>' +
			     '</div>' +
			     '<table cellpadding=0 cellspacing=0 border=0 width="265"><tr>' +
			        (!article ? '<td valign="top"><div style="width:85px;height:75px;overflow:hidden;"><a ' + detailClick + '><img src="' + img + '" width=75 border=0 style="padding-left:5px;padding-right:5px;"></a></div></td>' : '') +
			     '<td valign="top" style="padding:2px;' + (article ? 'padding-left:8px;' : '') + '">' +
			     '<font color="#848484">' +
			     '<a href="' + d.link + '" onClick="doClick(this,[\'buy\',\'' + d['sku'] + '\'])" target="offwidget" style="color:#0F7ECD">' + (price.length > 0 ? 'Buy Now' : 'More Info') + '</a>' +
			     ' | ' +
			     (!article?'<a href="javascript:void(0)" ' + detailClick + ' style="color:#848484">Details</a> | ' : '') +
			     '<a href="javascript:void(0)" onClick="doClick(this,[\'share\',\'' + d['item_id'] + '\'])" style="color:#848484;">Share</a> | ' +
			     '<a href="javascript:void(0)" onClick="doClick(this,[\'remove\',\'' + d['sku'] + '\'])" style="color:#848484">Remove</a>' +
			     '</font><br>' +
			     '<div style="padding-top:0px;">' +
			     '' +
				   '<div style="padding-top:2px;"><font style="font-size:11px;font-weight:normal;color:#555555">' + desc + '</font></div>' +
			     '</td></tr></table>' +
			       (lnks? '<div style="font-size:11px;">' + d['listing_deal'] + '</div>':'') +
				   '</div>';
		}

		if (lnks) return h;
		else h = '<div style="width:' + this.box.w + 'px;height:' + (this.box.h - 16) + 'px;overflow-y:scroll;">' +
		        '<div id="myListDoc" align=center>' + h;


		h += '</div></div>';

		this.container().innerHTML = '<div style="background-color:#E2E2E2"><div style="width:' + this.box.w + 'px;height:' + (doLocking && loggedIn && getCookie('pubMyList') ? '34' : '17') + 'px;line-height:15px;">' +
		       '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
		       '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;">My List</td>' +
		       '<td style="font-size:11px;line-height:11px;color:#000000;" align=right>' +

		       myListActions() +

		       '</td>' +
		       '</tr></table>' +
		           (doLocking && loggedIn && getCookie('pubMyList') ? '<input type=text id="mylistTitleInput" value="' + (getCookie('listTitle')?getCookie('listTitle'):'') + '" onBlur="c$(\'profile\').handleClick(this,\'dotitle\')" onChange="c$(\'profile\').handleClick(this,\'dotitle\')" style="margin-left:7px;border-width:0;color:#000;font-size:9px;height:14px;width:97%;" >' : '') +
		       '</div></div>' + h;
	}
}


function lockList(box) {
	this.box = box;
	var flink = [];

	var tmp = null;
//	var tmp = 'showMyList()';
//	if (tmp && tmp != '' && tmp != 'null') $a.add(flink, [tmp,'My List']);
//	tmp = 'showProfile()';
	if (tmp && tmp != '' && tmp != 'null') $a.add(flink, [tmp,'Preferences']);
	tmp = 'getWidget()';
	if (tmp && tmp != '' && tmp != 'null') $a.add(flink, [tmp,'Get & Share']);
	tmp = 'http://www.crateandbarrel.com/Customer-Service/About-Us/';
	if (tmp && tmp != '' && tmp != 'null') $a.add(flink, [tmp,'About']);

	this.flink = flink;

	this.drawHtml = function(lnks) {
		var h = '';

		var numList = null;
		try {
			numList = $json.toString(wic['catalog-mylist']);
			numList = numList.substring(1,numList.length-1);
		} catch (e) {}


		if (!numList || numList.length <= 0) {
			h = '<div style="padding:10px;text-align:left;color:#555555">Your list is empty!<br><br>It\'s easy to make a list - just click "Save" when you view a product you like, and it will be added to this list. Once you\'ve built a list, you can share it with others or send it to yourself in an email!</div>';

		} else {
			h = '<div style="padding:10px;text-align:left;color:#555555">Loading...</div>';

			var req = {
				qry: "itemsBySku",
				criteria: {},
				params: { dbname:dataName, skus:numList },
				engine: 'catalog-engine'
			};

			this.lnks = lnks;
			$ajax.jsonPost('/' + webappRoot + '/svc/query-service', req, this);
		}

		if (lnks) return h;
		else h = '<div style="width:' + this.box.w + 'px;height:' + (this.box.h - 16) + 'px;overflow-y:scroll;">' +
		        '<div id="myListDoc" align=center>' + h;


		h += '</div></div>';
		return '<div style="background-color:#E2E2E2">' +
//		       '<div style="width:' + this.box.w + 'px;height:17px;line-height:15px;">' +
//		       '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
//		       '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;">' + widgetInst.listTitle + '</td>' +
//		       '<td style="font-size:11px;line-height:11px;color:#000000; width:25px;" align=right><a href="javascript:void(0)" style="color:#000000" onClick="doClick(this,[\'close\'])">[ x ]</a>' +
//		       '</td>' +
//		       '</tr></table>' +
//		       '</div>' +
		       '</div>' + h;
	}

	this.handleClick = function(e, x) {
		  if (x == 'dotitle') {
			if (e.value != this.listtitle) {
				var title = ((e.value + '').replace(/<\/?[^>]+(>|$)/g, "")).trim();
				if (title.length > 0) {
					setCookie('listTitle', e.value);
					this.listtitle = e.value;
				}
			}

		} else if (x[0] == 'shareall') {
			if (typeof GM.mylist == 'object' && GM.mylist.length > 0) {
			GM.sendList = true;
			runDialog('sendDialog',null,null);
				trackEvent(GA.act['share'], GA.lab['ad_share_email'], GM.mylist.join('|'));
			} else {
				alert('There are no items in your list yet!');
			}

		} else if (x[0] == 'close') {
			this.close();

		} else if (x[0] == 'print') {
			for (i in this.data) {
				if (this.data[i]['item_id'] == x[1]) {
					GM.popper = this.data[i];
					popDetails();
					trackEvent(GA.act['ads'], GA.lab['ad_print'], x[1]);
					return;
				}
			}
		
		} else if (x[0] == 'buy') {
			for (i in this.data) {
				if (this.data[i]['item_id'] == x[1]) {
					var link = this.data[i].link;
					var sku = this.data[i].sku;

					if (typeof openUrl !== 'undefined') {
						openUrl(link);
					} else if (typeof widget !== 'undefined' && typeof widget.openURL !== 'undefined') {
						widget.openURL(link);
					} else if (typeof window !== 'undefined' && typeof window.open !== 'undefined') {
						window.open(link);
					}

					if (typeof Affiliate !== 'undefined') Affiliate.redirect('click');
					trackEvent(GA.act['ads'], GA.lab['ad_buy'], sku);

					return;
				}
			}
		
		} else if (x[0] == 'removeAll') {
			GM.mylist = [];
			this.repaint();
			c$('resOne').repaint();
			setCookie('catalog-mylist', []);

		} else if (x[0] == 'share') {
			for (i in this.data) {
				if (this.data[i]['item_id']+'' == x[1]) {
					runDialog('shareDialog',null,this.data[i],true);
					return;
				}
			}

		} else if (x[0] == 'remove') {
			var mod = false;
			for (i in GM.mylist) {
				if (GM.mylist[i] == x[1]) {
					$a.remove(GM.mylist, GM.mylist[i]);
					mod = true;
				}
			}
			if (mod) {
				this.repaint();
				c$('resOne').repaint();
				setCookie('catalog-mylist', GM.mylist);
			}
		//} else if (x[0] == 'buy') {
		//	if (typeof Affiliate !== 'undefined') Affiliate.redirect('click');
		//	trackEvent(GA.act['ads'], GA.lab['ad_buy'], x[1]);
		}
	}

	this.close = function() {
		//c$('selectors').present();
		splashMeAgain();
		GM.my = false;
		_hide(this);
	}

	this.callback = function(r) {
		if (!r || !r.results || !r.results.length >0) return;

		var lnks = this.lnks;
		this.lnks = null;
		this.data = [];

		var drawn = [];

		var h = '';
		for (i in r.results) {
			var d = r.fork(i);
			this.data[i] = d;

			if ($a.indexOf(drawn, d['sku']) > -1) continue;
			$a.add(drawn, d['sku']);

			var article = (d['item_type'] == 'article');
			
			var p, img = d['image_link'];
			GM.curimage = img;

			d['title'] = parseText(d['title']);
			
			var desc = d.description;
			desc = parseText(desc);
			desc = desc.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/<\/?[^>]+>/gi," ");
			if (desc.length > 150) {
				desc = desc.substring(0,150);
				while (desc.charAt(desc.length-1) != ' ') desc = desc.substring(0,desc.length-1);
				desc += '...'
			}

			if (lsn_eid && d.link) d.link = d.link.replace(/\@lsn_eid\@/gi, lsn_eid);
			if (extraParams['AID'] && d.link) d.link = d.link.replace(/\@AID\@/gi, extraParams['AID']);
			if (extraParams['PID'] && d.link) d.link = d.link.replace(/\@PID\@/gi, extraParams['PID']);
			if (extraParams['SID'] && d.link) d.link = d.link.replace(/\@SID\@/gi, extraParams['SID']);

			var price;
			if (d.price && d.price.trim().length > 0) price = '$' + formNum(d.price);
			else price = '';

			var zoomPopup = 'link';
			var detailClick = '';

			if (zoomPopup == 'link') detailClick = ' onClick="doClick(this, [\'buy\', ' + d['item_id'] + '])" ';
			else detailClick = ' onClick="doClick(this, [\'print\', ' + d['item_id'] + '])" ';

			h += '<div style="border-bottom:1px solid #ccc;padding-top:3px;padding-bottom:3px;text-align:left;">' +
			     '<div style="padding:3px;padding-left:7px;">' +
			     '<font style="font-size:12px; color:#555555; font-weight:bold;">' + d.title + '</font>' +
			     '</div>' +
			     '<table cellpadding=0 cellspacing=0 border=0 width="265"><tr>' +
			        (!article ? '<td valign="top"><div style="width:85px;height:75px;overflow:hidden;"><a ' + detailClick + '><img src="' + img + '" width=75 border=0 style="padding-left:5px;padding-right:5px;"></a></div></td>' : '') +
			     '<td valign="top" style="padding:2px;' + (article ? 'padding-left:8px;' : '') + '">' +
			     '<font color="#848484">' +
			     '<a href="' + d.link + '" onClick="doClick(this,[\'buy\',\'' + d['sku'] + '\'])" target="offwidget" style="color:#0F7ECD">' + (price.length > 0 ? 'Buy Now' : 'More Info') + '</a>' +
			     ' | ' +
			     (!article?'<a href="javascript:void(0)" ' + detailClick + ' style="color:#848484">Details</a> | ':'') +
			     '<a href="javascript:void(0)" onClick="doClick(this,[\'share\',\'' + d['item_id'] + '\'])" style="color:#848484;">Share</a>' +
			     '</font><br>' +
			     '<div style="padding-top:0px;">' +
			     '' +
				   '<div style="padding-top:2px;"><font style="font-size:11px;font-weight:normal;color:#555555">' + desc + '</font></div>' +
			     '</td></tr></table>' +
			       (lnks? '<div style="font-size:11px;">' + d['listing_deal'] + '</div>':'') +
				   '</div>';
		}

		if (lnks) return h;
		else {
			h = '<div style="width:' + this.box.w + 'px;height:' + (this.box.h - 20) + 'px;overflow-y:scroll;">' +
		        '<div id="myListDoc" align=center>' + h + '</div></div>' +
		         '<div class="footer" style="border-top:2px solid #E2E2E2"><span style="float:right;padding-right:5px">';

			for (var i = 0; i < this.flink.length; i++) {
				var link = this.flink[i];
				if (link[0].indexOf('http://') != 0) h += '<a href="javascript:void(0);" onClick="' + link[0] + '">' + link[1] + '</a>';
				else h += '<a href="' + link[0] + '" target="offwidget">' + link[1] + '</a>';
				if (i < this.flink.length - 1) h += '&nbsp;&nbsp;|&nbsp;&nbsp;';
			}

			h += '</span></div>';
		}


		h += '</div></div>';
		var title = widgetInst.listTitle + '';
		if (title == '' || title == 'null') title = 'Welcome to My List';
		this.container().innerHTML = '<div style="background-color:#E2E2E2">' +
		                           '<div style="width:' + this.box.w + 'px;height:2px;line-height:2px;">' +
//								   '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
//								   '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;">' + title + '</td>' +
//								   '<td style="font-size:11px;line-height:11px;color:#000000;" align=right><a href="javascript:void(0)" style="color:#000000" onClick="doClick(this,[\'close\'])">[ x ]</a>' +
//								   '</td>' +
//								   '</tr></table>' +
								   '</div>' +
		                           '</div>' + h;
	}
}

var codeResultsPageSize = 1;

function subCats(box) {
	this.box = box;

	this.drawHtml = function() {
		if (!this.subs) return '&nbsp;';

		var h = '<div style="width:' + this.box.w + 'px;height:' + this.box.h + 'px;overflow-y:scroll;">';

		for (i in this.subs) {
			if ('article' == this.subs[i][5]) {
				h += '<div class="subcat" onClick="doClick(this,\'' + this.subs[i][0] + '\')"><table cellpadding=0 cellspacing=0><tr>' +
					 '<td style="padding-left:15px;padding-top:5px;padding-bottom:5px;color:#333333" valign=middle><b>' + this.subs[i][1] + '</b> <br> ' +
					 '<div style="padding:3px;"><font style="color:#333333">' + formatRSSTime(this.subs[i][6]) + '</font></div></td>' +
				     '</tr></table></div>';
			} else {
				var img = (typeof this.subs[i][9] !== 'undefined' && this.subs[i][9] !== null && (this.subs[i][9]+'').trim() !== '') ? this.subs[i][9] : this.subs[i][4];
				h += '<div class="subcat" onClick="doClick(this,[\'' + this.subs[i][0] + '\',' + this.subs[i][3] + '])"><table cellpadding=0 cellspacing=0><tr>' +
				     '<td valign=middle width="60"><img src="' + img + '" height=50 border=0></td>' +
					 '<td style="padding-left:15px;color:#333333" valign=middle><b>' + this.subs[i][1] + '</b> &nbsp; ' + (this.subs[i][3] > 1 ? '<font style="color:#333333">(' + this.subs[i][3] + ')</font>' : '' ) + '</td>' +
				     '</tr></table></div>';
			}
		}

		h += '</div>';

		return h;
	}

	this.handleClick = function(e, x) {
		this.subCount = x[1];
		for (var i = 0; i < this.subs.length; i++) {
			if (x[0] == this.subs[i][0]) {
				this.loadPosition(i);
				this.curPos = i;
				break;
			}
		}
	}

	this.loadPosition = function(pos,dir) {
		var o = this.subs[pos];

		c$('loginBox').subCat = o;

		this.sw = true;

		GM.my = false;
		GM.dex = -1;

		this.dataCall = true;
		this.dir = (dir) ? dir : null;

		var storeId = (GM.defstore ? GM.defstore[0] : c$('stores').storeId);
		var req = {qry:'promotions', criteria:{}, params:{}, engine:'catalog-engine'};
		if (codeResultsPageSize > 1) {
			req.pge = codeResultsPageSize;
			req.skp = 0;
		}
		req.params.dbname = dataName;
		req.params.catId = o[0];
		req.params.storeId = storeId;
		this.subReq = req;
		$ajax.jsonPost('/' + webappRoot + '/svc/query-service', req, this);
		
		GA.subcat = o[1];
		trackEvent(GA.act['browse'], GA.lab['subcat'], o[1]);
	}

	this.loadTopCat = function(cat) {
		var r = {};
		r.params = {dbname:dataName, cat:cat[0]};
		r.criteria = {};
		r.qry = "subCategoryLookup";
		r.engine = "catalog-engine";

		$ajax.jsonPost('/' + webappRoot + '/svc/query-service?', r, this);
	}

	this.callback = function(r) {
		var dirLeft = this.dir && this.dir == 'l' ? true : false;
		this.dir = null;
		
		if (this.dataCall) {
			this.dataCall = false;
			sldata = r;
			
			_hide(this);
			_hide('catsLeft');
			_hide('catsRight');
			_hide('selectors');


			if (codeResultsPageSize > 1) {
				c$('listBox').subCount = this.subCount;
				c$('listBox').callback(r);
				_show('listBox');
				c$('loginBox').repaint();
			} else if (dirLeft) {
				GM.dex = r.length;
				resultsLeft();
			} else {
				resultsRight();
			}

		} else {
			this.subs = (r && r.results) ? r.results : null;
			this.repaint();
			_show(this);
			_hide('back05');
		}
	}
}



function listBox(box) {
	this.box = box;
	this.flink = [];

	this.drawHtml = function(lnks) {
		if (this.resultData) return this.drawHtmlWithData(this.resultData);

		var detailSpinner = 'http://widget-images.catalogchoice.org/ajax-loader-3.gif'.trim();
		if (detailSpinner.length < 1 || detailSpinner == 'null') detailSpinner = 'pixel.gif';

		var h = '<div style="background-color:#E2E2E2"><div style="width:' + this.box.w + 'px;height:17px;line-height:15px;">' +
		       '<div style="width:' + this.box.w + 'px;height:' + (this.box.h) + 'px;overflow-y:scroll;">' + '<div id="myListDoc" align=center>' +
		        '<br><br><img src="' + detailSpinner + '">' +
		       '</div></div>' + '</div></div>';

		return h;
	}

	this.handleClick = function(e, x) {
		if ('more' == x) {
			this.more = e;

			var req = c$('subCats').subReq;
			if (codeResultsPageSize > 1) {
				req.skp = this.page * codeResultsPageSize;
				req.pge = codeResultsPageSize;
			}
			this.page ++;
			$ajax.jsonPost('/' + webappRoot + '/svc/query-service', req, {callback:function(rslt) {
				if (!rslt || !rslt.results || rslt.results.length <= 0)  return;
				var elem = $$('itemResultsDiv');
				var c = c$('listBox');
				for (i in rslt.results) {
					c.resultData.results[c.resultData.results.length] = rslt.results[i];

					var d = rslt.fork(i);
					c.data[c.data.length] = d;

					GM.curimage = d['image_link'];

					var deev = document.createElement('div');
					elem.insertBefore(deev, c.more);

					deev.innerHTML = drawSearchResult(d, c.lnks);
				}
				c.showCount = c.showCount + rslt.results.length;

				if (c.subCount <= c.showCount) _hide(c.more);
			}});

			trackEvent(GA.act['search'], GA.lab['search_more']);

		} else if ('close' == x) {
			_hide(this);
			trackEvent(GA.act['search'], GA.lab['search_close']);

		} else if (x[0] == 'list') {
			for (i in this.data) {
				if (this.data[i]['item_id']+'' == x[1]) {
					var item = this.data[i];

					GM.sprite.src = item['image_link'];
					_moveTo(GM.sprite, {x:175,y:60});
					_resize(GM.sprite, {w:75,h:75});
					_show(GM.sprite);

					GM.mylist[GM.mylist.length] = item['sku'];
					setCookie('catalog-mylist', GM.mylist);
					c$('myList').repaint();

					setTimeout(function() {_amove(GM.sprite, {w:3,h:3,x:150, y:245}, 300, function() { _hide(GM.sprite); });}, 400);

					c$('footer').repaint();
					trackEvent(GA.act['ads'], GA.lab['ad_save'], item['sku']);

				}
			}
			e.parentNode.innerHTML = '';

		} else if (x[0] == 'share') {
			for (i in this.data) {
				if (this.data[i]['item_id']+'' == x[1]) {
					runDialog('shareDialog',null,this.data[i],true);
					trackEvent(GA.act['share'], GA.lab['ad_share_open'], this.data[i].sku);
					return;
				}
			}

		} else if (x[0] == 'print') {
			for (i in this.data) {
				if (this.data[i]['item_id'] == x[1]) {
					GM.popper = this.data[i];
					popDetails();
					trackEvent(GA.act['ads'], GA.lab['ad_print'], this.data[i].sku);
					return;
				}
			}

		} else if (x[0] == 'buy') {
			for (i in this.data) {
				if (this.data[i]['item_id'] == x[1]) {
					var link = this.data[i].link;
					if (lsn_eid && link) link = link.replace(/\@lsn_eid\@/gi, lsn_eid);
					if (extraParams['AID'] && link) link = link.replace(/\@AID\@/gi, extraParams['AID']);
					if (extraParams['PID'] && link) link = link.replace(/\@PID\@/gi, extraParams['PID']);
					if (extraParams['SID'] && link) link = link.replace(/\@SID\@/gi, extraParams['SID']);

					var sku = this.data[i].sku;

					if (typeof openUrl !== 'undefined') {
						openUrl(link);
					} else if (typeof widget !== 'undefined' && typeof widget.openURL !== 'undefined') {
						widget.openURL(link);
					} else if (typeof window !== 'undefined' && typeof window.open !== 'undefined') {
						window.open(link);
					}

					if (typeof Affiliate !== 'undefined') Affiliate.redirect('click');
					trackEvent(GA.act['ads'], GA.lab['ad_buy'], sku);

					return;
				}
			}
		}
	}

	this.callback = function(rslt) {
		if (!rslt || !rslt.results || rslt.results.length <= 0)  return;
		this.page = 1;
		this.showCount = rslt.results.length;

		this.resultData = rslt;
		this.container().innerHTML = this.drawHtmlWithData(rslt);
	}

	this.drawHtmlWithData = function(r) {
		var lnks = this.lnks;
		this.lnks = null;
		this.data = [];

		var drawn = [];

		var h = '';
		for (i in r.results) {
			var d = r.fork(i);
			this.data[i] = d;

			if ($a.indexOf(drawn, d['sku']) > -1) continue;
			$a.add(drawn, d['sku']);

			GM.curimage = d['image_link'];

			h += drawSearchResult(d, lnks);
		}

		if (h.trim() == '') {
			h = '<div style="text-align:left; padding:10px;">'
				+ '<p style="margin:0 0 10px;">Your search for <strong>"' + this.title + '"</strong> did not match any results.</p>'
				+ '<ul style="margin:0 0 10px 20px; padding:0;">'
				+ '<li>Please make sure all words are spelled correctly.</li>'
				+ '<li>Try different keywords.</li>'
				+ '<li>Or try more general keywords.</li>'
				+ '</ul>'
				+ '</div>';
		}

		var title = this.title;
		if (title && title.length > 25) title = title.substring(0,20) + '...';

		return '<div style="width:' + this.box.w + 'px;height:' + (this.box.h) + 'px;overflow-y:scroll;">' +
				        '<div id="itemResultsDiv" align=center>' + h +
		       (this.showCount < this.subCount ? '<div onClick="doClick(this, \'more\');" style="padding:5px; font-size:12px; color:#555555; cursor:pointer;">Show more...</div>' : '') +
		       '</div></div>' +
				'</div></div>';
	}
}

function profile(box) {
	this.box = box;
	this.diff = {};

	this.drawHtml = function() {
		if (!doLocking || loggedIn) {
			if (!this.catData || this.catData.length <= 0) {
				return "";
			}

			var cook = getCookie('catalogshows');
			if (!cook || cook == 'everything') cook = {};

			var name = getCookie('profName');
			if (!name) name = '';

			var email = getCookie('profEmail');
			if (!email) email = '';

			var catCookie = getCookie('catalogshows');

			var h = '<div style="background-color:#E2E2E2"><div style="width:' + this.box.w + 'px;height:17px;line-height:15px;">' +
				   '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
				   '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;" width=240>' + (this.runReminder ? 'Password Reminder' : 'My Preferences') + '</td>' +
				   '<td style="font-size:11px;line-height:11px;color:#000000;" align=right>' +
				   '<a href="javascript:void(0)" style="color:#000000" onClick="doClick(this,[\'close\'])">[ x ]</a>' +
				   '</td>' +
				   '</tr></table>' +
				   '</div></div>' +
					'' +
					'' +
					'<div style="width:' + this.box.w + 'px;height:' + (this.box.h -18) + 'px;overflow-y:scroll;padding-left:3px;">';
			if (doLocking) {
				h += '<div style="padding:5px">' +
					'<font style="color:#555;font-size:12px;font-weight:normal;">' +
			        'Welcome. You have successfully signed in. You can now publish your list and filter product categories!' +
					'<div>' +
					'<table><tr><td align=right><b>Name:</b></td><td><input type=text id="regName" style="padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;width:200px;" value="' + (loggedIn.name? loggedIn.name:'') + '" onBlur="doClick(this,\'doname\')" onChange="doClick(this,\'doname\')" ></td></tr>' +
					'<tr><td align=right><b>Email:</b></td><td><input type=text id="regEmail" style="padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;width:200px;" value="' + (loggedIn.email? loggedIn.email:'') + '" onBlur="doClick(this,\'doemail\')" onChange="doClick(this,\'doemail\')" ></td></tr>' +
					'</table>' +
				    '</div>';
			} else {
			h += '<div style="border-top:1px solid #ddd;"><br>' +
					'<input type="checkbox" style="padding:0px;margin:0px;" id="myListOnly" onClick="doClick(this,\'mylist\')" value="myListOnly" ' + (getCookie('listOnLoad')?'checked':'') + '> &nbsp;Show my list on load<br><br>' +
					'</div>';
			}
				h += '</font>' +
					'</div>' +

					 '</div>';
			return h;
		}


		hx = '';
		if (this.runReminder) {
			t = 'Password Reminder';
			hx += 'Enter your email adress below, click submit, and we will email your password reminder.';

		} else if (widgetInst && !loggedIn) {
			t = 'Sign in';
			hx += 'This widget is already registered. If you are the registered user, please sign in now to edit Featured List and filter product categories.';

		} else if (widgetInst) {
			t = 'My Preferences';
			hx += 'Welcome. You have successfully signed in. You can now publish your list and filter product categories!';

		} else {
			t = 'Register';
			hx += 'Register this widget to save the contents of your list and select categories that interest you. You can even name and publish your list so other people can see it!';
		}


		var h = '<div style="background-color:#E2E2E2"><div style="width:' + this.box.w + 'px;height:17px;line-height:15px;">' +
			   '<table cellpadding=0 cellspacing=0 style="padding-left:7px;height:15px;" width="100%"><tr>' +
			   '<td style="font-size:12px;line-height:11px;color:#000000;font-weight:bold;" width=240>' + t + '</td>' +
			   '<td style="font-size:11px;line-height:11px;color:#000000;" align=right>' +
			   '<a href="javascript:void(0)" style="color:#000000" onClick="doClick(this,[\'close\'])">[ x ]</a>' +
			   '</td>' +
			   '</tr></table>' +
			   '</div></div>' +
				'<div style="width:' + this.box.w + 'px;height:' + (this.box.h -18) + 'px;overflow-y:auto;padding-left:3px;">' +
				'<div style="padding:5px">' +
				'<font style="color:#555; font-weight:normal;">';

			h += hx;

				h += '<div>' +
				'<table>' +
				(!widgetInst ? '<tr><td align=right><b>Name:</b></td><td><input type=text id="regName" style="padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;width:200px;"></td></tr>' : '') +
				'<tr><td align=right><b>Email:</b></td><td><input type=text id="regEmail" style="padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;width:200px;"></td></tr>' +
				(!this.runReminder?'<tr><td align=right><b>Password:</b></td><td><input type=password id="regPass" style="padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;width:100px;"><span style="float:right;font-size:10px;line-height:18px"><a href="javascript:void(0)" onClick="doClick(this,\'forgot\');" style="color:#0F7ECD;">forgot password?</a></span></td></tr>':'') +
				(!widgetInst ? '<tr><td align=right><b>Confirm:</b></td><td><input type=password id="regConf" style="padding-left:4px;font-size:11px;border:1px solid #aaa;height:18px;width:100px;"></td></tr>' : '') +
				'<tr><td align=right>&nbsp;</td><td><input type=button value="' +(!widgetInst ? 'Register!' : (this.runReminder?'Submit':'Sign In')) + '" onClick="doClick(this,\'signin\');" style="background-color:#E2E2E2;color:#000000;padding-left:4px;font-size:11px;border:0;height:18px;width:100px;"></td></tr>' +
				'</table>';
		if (widgetInst && !this.runReminder) {
			h += 'If you are NOT the registered user of this widget, just click the widget link below to grab your own copy and register it.'
		}
		h += '</div></font></div></div>';
		return h;
	}

	this.handleClick = function(e, x) {
		var ding = false;
		if (x == 'doname' && this.diff.name != e.value) {
			ding = true;
			this.diff.name = e.value

		} else if (x == 'doemail' && this.diff.email != e.value) {
			ding = true;
			this.diff.email = e.value

		//} else if (x == 'dozip' && this.diff.zip != e.value) {
		//	ding = true;
		//	this.diff.zip = e.value
		} else if (x == 'forgot') {
			this.runReminder = true;
			this.repaint();
		}

		//if ((x == 'doname' || x == 'doemail' || x =='dozip') && ding) {
		if ((x == 'doname' || x == 'doemail') && ding) {
			var r = {};
			r.action = 'saveProfile';
			r.profileId = loggedIn.id;

			r.name = $$('regName').value;
			r.email = $$('regEmail').value;
			//r.zip = $$('regZip').value;

			r.embedId = embedId;
			r.widgetKey = cookieKey;
			r.cookie = $json.toString(cookieCache);

			$ajax.jsonPost('/' + webappRoot + '/gxsvc/profile-service', r, {callback:function(r) {
				var d = c$('profile').diff;
				loggedIn.name = d.name;
				loggedIn.email = d.email;
				//loggedIn.zip = d.zip;
			}});

		} else if (x == 'dotitle') {
			if (e.value != this.listtitle) {
				var title = ((e.value + '').replace(/<\/?[^>]+(>|$)/g, "")).trim();
				if (title.length > 0) {
					setCookie('listTitle', e.value);
					this.listtitle = e.value;
				}
			}

		} else if (x == 'close') {
			this.runReminder = false;
			this.repaint();
			GM.prof = false;
			c$('loginBox').repaint();
			_hide(this);

			var blankScreen = $('selectors').style.display = 'none' && $('resOne').style.display == 'none' && $('subCats').style.display == 'none';
			if (blankScreen) {
				c$('selectors').present();
			}

			trackEvent(GA.act['profile'], GA.lab['profile_close']);

		} else if (x == 'signin') {
			if (this.runReminder) {
				if (!validateEmail($$('regEmail').value)) {
					alert('Please enter a valid email');
					return;
				}

				$ajax.jsonPost('/' + webappRoot + '/gxsvc/profile-service', {action:'reminder',email:$$('regEmail').value}, {callback:function(r) {
					if (r.result == "ok") {
						alert('Email has been sent');
						c$('profile').runReminder = false;
						c$('profile').repaint();
						_hide('profile');
					}
				}});

				return;
			}

			if (!widgetInst) {
				if(!validateField($$('regName').value)) {
					alert('Please enter a name');
					return;
				}

				if (!validateEmail($$('regEmail').value)) {
					alert('Please enter a valid email');
					return;
				}

				if (!validateField($$('regPass').value)) {
					alert('Please enter a password');
					return;
				}

				if ($$('regPass').value != $$('regConf').value) {
				alert('Password and confirmation must be the same');
				return;
			}
			}

			var r = {};
			r.action = (widgetInst) ? 'login' : 'register';
			if (!widgetInst) r.name = $$('regName').value;
			r.email = $$('regEmail').value;
			r.password = $$('regPass').value;

			r.embedId = embedId;
			r.widgetKey = cookieKey;

			// set a default title
			if (!widgetInst) {
				var listTitle = 'Check This Out!';
				cookieCache.listTitle = listTitle;
				r.cookie = $json.toString(cookieCache);
				setCookie('listTitle', listTitle);
				this.listtitle = listTitle;
				//cookieCache.listTitle = null;
			} else {
				cookieCache = $json.parse(widgetInst.cookie);

				var lst = getCookie('catalog-mylist');
				if (!lst) lst = [];
				else if (lst.length > 0 && typeof(lst[0]) == 'object') setCookie('catalog-mylist', []);
				GM.mylist = lst;

				c$('myList').repaint();
			}

			$ajax.jsonPost('/' + webappRoot + '/gxsvc/profile-service', r, {callback:function(r) {
				if (r.result == "login-failed") {
					alert('Username and/or password is incorrect, please try again');
				} else if (r.result == "owner-failed") {
					alert('This widget is locked by a different user.\nTo create your own, please click the \'Get Widget!\' link below.');
				} else if (r.result == "duplicate") {
					alert('That email address is already taken, please try again');

				} else if (r.result == "loggedin") {
					c$('profile').diff = loggedIn = r.profile;
					c$('loginBox').handleClick({},'home');
					c$('profile').repaint();

				} else if (r.result == "saved") {
					alert('Congratulations! You have\nsuccessfully registered this\nwidget!');
					c$('profile').diff = loggedIn = r.profile;
					c$('loginBox').handleClick({},'home');
					c$('profile').repaint();
				}
				c$('submenu').repaint();
				c$('footer').repaint();
			}});
		} else if (x == 'publist') {
			//setCookie('pubMyList', e.checked);
			var flag = !getCookie('pubMyList');
			setCookie('pubMyList', flag);
			setCookie('listOnLoad', flag);
			c$('profile').repaint();

//			if (flag)
//				showLockList();

		} else if (x == 'mylist') {
			setCookie('listOnLoad', e.checked);

		} else if (x == 'print') {
			launchWindow('Print Window', '<html><style type="text/css">body, td, div {font-family:arial, sans-serif;}</style><body>' + this.drawHtml(true) + '<br><br><script type="text/javascript">setTimeout(function(){window.print();},300);</script></body></html>', 400, 600);

		} else if (x == 'share') {
			runDialog('sendDialog',null,GM.thus.d);

		} else {
			if (e.id == 'profEvry' && e.checked) {
				this.uncheckAll();
				setCookie('catalogshows', false);
				setCookie('catalogshowAll', true);
				GM.dirtyCats = true;

			} else if ((e.id+'').indexOf('show') == 0) {
				setCookie('catalogshowAll', false);
				$('profEvry').checked = false;
				$('profSelect').checked = true;

				var cook = getCookie('catalogshows');
				if (!cook) cook = {};
				cook[x] = e.checked;
				setCookie('catalogshows', cook);

				GM.dirtyCats = true;

			} else {
				var mod = false;
				for (i in GM.mylist) {
					if (GM.mylist[i]['promotion_id']+'' == x) {
						$a.remove(GM.mylist, GM.mylist[i]);
						mod = true;
					}
				}
				if (mod) {
					this.repaint();
					setCookie('catalog-mylist', GM.mylist);
				}
			}
		}
	}

	this.load = function() {
		if (!this.catData || this.catData.length <= 0) {
			$ajax.jsonGet('/' + webappRoot + '/svc/query-service?{qry:%22categoryLookup%22,criteria:{},params:{dbname:"'+dataName+'"},engine:%22catalog-engine%22}', {callback:function(r) {
				c$('profile').catData = r.results;
				if (!doLocking || loggedIn) c$('profile').repaint();
			}});
		}
		_show(this);
		trackEvent(GA.act['profile'], GA.lab['profile_view']);
	}

	this.checkAll = function() {
		for (i in this.catData) {
			$$('show' + i).checked = true;
		}
	}

	this.uncheckAll = function() {
		for (i in this.catData) {
			$$('show' + i).checked = false;
		}
	}
}




function regIntercept(box) {
	this.box = box;

	this.drawHtml = function() {
		var h = '<div style="width:' + this.box.w + 'px;height:' + (this.box.h - 16) + 'px;overflow:hidden;">' +
		        '<div id="myListDoc" align=center>' + '<div style="padding:10px;text-align:left;color:#555555">' +
		        '<div align=center>' +
		        '<div style="font-size:19px;font-weight:bold;">Welcome to your iCatalog!</div>' +
		        '<div style="font-size:11px;">Registration lets you share and feature your<br>favorite stuff so other people can see it.</div>' +
		        '<div>' +
		        '<table width=250 align=center cellpadding=0 cellspacing=3 border=0><tr><td colspan=2 id="intRepEmail">' +
		        '<input type=text value="Email Address" onFocus="c$(\'regIntercept\').repEmail()" style="color:#BBB;padding-left:4px;font-size:13px;border:1px solid #aaa;height:25px;width:100%;"></td></tr><td width=50% id="intRepPass">' +
		        '<input type=text value="Password" onFocus="c$(\'regIntercept\').repPassword()" style="color:#BBB;padding-left:4px;font-size:13px;border:1px solid #aaa;height:25px;width:100%;"></td><td width=50% id="intRepConf">' +
		        '<input type=text value="Confirm" onFocus="c$(\'regIntercept\').repConfirm()" style="color:#BBB;padding-left:4px;font-size:13px;border:1px solid #aaa;height:25px;width:100%;"></td>' +
		        '</tr></table>' +
		        '</div>' +

		        '<div style="font-size:10px;"><input id="interceptIAgree" type="checkbox" name="iagreegroup">I agree to <a href="http://www.catalogchoice.org/icatalogs/tos" target="offsite">iCatalog Terms & Conditions</a></div>' +
		        '<div style="padding:2px;"><input type="button" onClick="c$(\'regIntercept\').click(this,\'yesplease\')" value="Register this iCatalog" style="background-color:#E2E2E2;color:#000000;padding-left:4px;font-size:13px;border:0;height:25px;width:230px;"></div>' +
		        '<div style="padding:2px;"><input type="button" onClick="c$(\'regIntercept\').click(this,\'nothanks\')" value="No Thanks" style="background-color:#E2E2E2;color:#000000;padding-left:4px;font-size:13px;border:0;height:25px;width:230px;"></div>' +
		        '<div style="font-size:10px;">Just show me my widget...</div>' +
		        '</div>' +
		        '</div>' +
		        '</div></div>';
		return h;
	}


	this.click = function(e, x) {
		if ('yesplease' == x) {
			if (!$$('regIntEmail') || !validateEmail($$('regIntEmail').value)) alert('You need to enter a valid email address.');
			else if (!$$('regIntPass') || ($('regIntPass').value+'').trim().length <= 0
			         || !$$('regIntConf') || ($('regIntConf').value+'').trim().length <= 0
					|| ($('regIntConf').value != $('regIntPass').value)) alert('Password and password confirmation need to match.');
			else if (!$('interceptIAgree').checked) alert('You need to agree to the terms and conditions to register this widget.');
			else {
				var r = {};
				r.action = 'register';
				if (!widgetInst) r.name = '';
				r.email = $$('regIntEmail').value;
				r.password = $$('regIntPass').value;

				r.embedId = embedId;
				r.widgetKey = cookieKey;

				// set a default title
				if (!widgetInst) {
					var listTitle = 'Check This Out!';
					cookieCache.listTitle = listTitle;
					r.cookie = $json.toString(cookieCache);
					setCookie('listTitle', listTitle);
					this.listtitle = listTitle;
				}

				$ajax.jsonPost('/' + webappRoot + '/gxsvc/profile-service', r, {callback:function(r) {
					if (r.result == "login-failed") {
						alert('The email address and/or password you entered are incorrect. Please try again.');
					} else if (r.result == "owner-failed") {
						alert('This widget is locked by a different user.\nTo create your own, please click the \'Get Widget!\' link below.');
					} else if (r.result == "duplicate") {
						alert('That email address is already taken, please try again');

					} else if (r.result == "saved") {
						alert('Congratulations! You have\nsuccessfully registered this\nwidget!');
						c$('profile').diff = loggedIn = r.profile;
						widgetInst = r.instance;
						c$('profile').repaint();
						_hide('regIntercept');
					}
					c$('myList').repaint();
					c$('footer').repaint();
					c$('submenu').repaint();
				}});
			}
		} else if ('nothanks' == x) {
			if (!doLocking || lockDenied) return;

			var r = {};
			r.action = 'denyLock';
			r.embedId = embedId;
			$ajax.jsonPost('/' + webappRoot + '/gxsvc/profile-service', r, {callback:function(r) {
				_hide('regIntercept');
			}});
		}
	}

	this.repEmail = function() {
		$$('intRepEmail').innerHTML = '<input type=text id="regIntEmail" value="" style="padding-left:4px;font-size:13px;border:1px solid #aaa;height:25px;width:100%;">';
		setTimeout(function() {$$('regIntEmail').focus();}, 100);
	}

	this.repPassword = function() {
		$$('intRepPass').innerHTML = '<input type=password id="regIntPass" style="padding-left:4px;font-size:13px;border:1px solid #aaa;height:25px;width:100%;">';
		setTimeout(function() {$$('regIntPass').focus();}, 100);
	}

	this.repConfirm = function() {
		$$('intRepConf').innerHTML = '<input type=password id="regIntConf" style="padding-left:4px;font-size:13px;border:1px solid #aaa;height:25px;width:100%;">';
		setTimeout(function() {$$('regIntConf').focus();}, 100);
	}

	this.handleClick = function(e, x) {
	}
}
function loginSignup() {
	this.drawHtml = function() {
		

		return '<div style="height:30px;background-color:#fff;">&nbsp;</div>' +
		       '<div style="background-color:#fff;padding:5px;">' +
		       '<div>' +
		       '<span style="color:#FF7B00;float:right;font-size:10px;"><a href="javascript:void(0)" style="color:#FF7B00;">forgot your password?</a></span>' +
		       '<font style="color:#dd1322;font-size:14px;font-weight:bold;">LOG IN</font>' +
		       '</div>' +
		       '<table cellpadding=0 cellspacing=0 width="100%" style="padding-top:5px;"><tr>' +
		       '<td class="fieldTitle">Email:</td><td class="fieldTitle">Password:</td><td>&nbsp;</td></tr>' +
		       '<tr><td style="padding-right:4px;">' +
		            '<input type="text" class="zipBox" style="width:100%; height:20px;" id="emlBox" value="" onFocus="this.value = \'\'"></td>' +
		       '<td style="padding-right:4px;">' +
		            '<input type="password" class="zipBox" style="width:100%; height:20px;" value="" onFocus="this.value = \'\'"></td>' +
		       '<td valign=bottom><img src="images/go-button.png" style="float:right;padding-bottom:3px; cursor:pointer;" onClick="doClick(this,\'login\')"></td>' +
		       '</tr></table>' +
		       '</div>' +
		       '' +
		       '' +
		       '<div style="padding:5px;">' +
		       '<div>' +
		       '<span style="color:#FF7B00;float:right;font-size:10px;"><a href="javascript:void(0)" style="color:#FF7B00;">we respect your privacy!</a></span>' +
		       '<font style="color:#dd1322;font-size:14px;font-weight:bold;">SIGN UP</font>' +
		       '</div>' +
		       '<table cellpadding=0 cellspacing=0 width="100%" style="padding-top:5px;">' +
		       '<tr><td class="fieldTitle">Email:</td><td class="fieldTitle">Password:</td></tr>' +
		       '<tr><td style="padding-right:4px;">' +
		            '<input type="text" class="zipBox" style="width:100%; height:20px;" value="" onFocus="this.value = \'\'"></td>' +
		       '<td style="padding-right:4px;">' +
		            '<input type="password" class="zipBox" style="width:100%; height:20px;" value="" onFocus="this.value = \'\'"></td>' +
		       '</tr>' +
		       '<tr><td class="fieldTitle">Zip Code:</td></tr>' +
		       '<tr><td style="padding-right:4px;">' +
		            '<input type="text" class="zipBox" style="width:100%; height:20px;" value="" onFocus="this.value = \'\'"></td>' +
		       '<td valign=bottom><img src="images/continue-button.png" style="float:right;padding-bottom:3px; cursor:pointer;" onClick="doClick(this,\'login\')"></td>' +
		       '</tr>' +
		       '</table>' +
		       '</div>';
	}

	this.handleClick = function(e, x) {
		if (x == 'login') {
			var eml = $$('emlBox').value;
			if (eml.indexOf('@') > -1) eml = eml.substring(0,eml.indexOf('@'));
			eml = eml.substring(0,1).toUpperCase() + eml.substring(1);
			c$('loginBox').loginName = eml;
			c$('loginBox').repaint();
			c$('footer').repaint();
			_hide(this);
		}
	}
}
