﻿// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function () {
    log.history = log.history || [];   // store logs to an array for reference
    log.history.push(arguments);
    if (this.console) {
        arguments.callee = arguments.callee.caller;
        console.log(Array.prototype.slice.call(arguments));
    }
};
// make it safe to use console.log always
(function (b) { function c() { } for (var d = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","), a; a = d.pop(); ) b[a] = b[a] || c })(window.console = window.console || {});

/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (e, b, a) {
    if (arguments.length > 1 && String(b) !== "[object Object]") { a = jQuery.extend({}, a); if (b === null || b === void 0) a.expires = -1; if (typeof a.expires === "number") { var d = a.expires, c = a.expires = new Date; c.setDate(c.getDate() + d) } b = String(b); return document.cookie = [encodeURIComponent(e), "=", a.raw ? b : encodeURIComponent(b), a.expires ? "; expires=" + a.expires.toUTCString() : "", a.path ? "; path=" + a.path : "", a.domain ? "; domain=" + a.domain : "", a.secure ? "; secure" : ""].join("") } a = b || {}; c = a.raw ? function (a) { return a } :
decodeURIComponent; return (d = RegExp("(?:^|; )" + encodeURIComponent(e) + "=([^;]*)").exec(document.cookie)) ? c(d[1]) : null
};

(function (g) { var q = { vertical: !1, rtl: !1, start: 1, offset: 1, size: null, scroll: 3, visible: null, animation: "normal", easing: "swing", auto: 0, wrap: null, initCallback: null, setupCallback: null, reloadCallback: null, itemLoadCallback: null, itemFirstInCallback: null, itemFirstOutCallback: null, itemLastInCallback: null, itemLastOutCallback: null, itemVisibleInCallback: null, itemVisibleOutCallback: null, animationStepCallback: null, buttonNextHTML: "<div></div>", buttonPrevHTML: "<div></div>", buttonNextEvent: "click", buttonPrevEvent: "click", buttonNextCallback: null, buttonPrevCallback: null, itemFallbackDimension: null }, m = !1; g(window).bind("load.jcarousel", function () { m = !0 }); g.jcarousel = function (a, c) { this.options = g.extend({}, q, c || {}); this.autoStopped = this.locked = !1; this.buttonPrevState = this.buttonNextState = this.buttonPrev = this.buttonNext = this.list = this.clip = this.container = null; if (!c || c.rtl === void 0) this.options.rtl = (g(a).attr("dir") || g("html").attr("dir") || "").toLowerCase() == "rtl"; this.wh = !this.options.vertical ? "width" : "height"; this.lt = !this.options.vertical ? this.options.rtl ? "right" : "left" : "top"; for (var b = "", d = a.className.split(" "), f = 0; f < d.length; f++) if (d[f].indexOf("jcarousel-skin") != -1) { g(a).removeClass(d[f]); b = d[f]; break } a.nodeName.toUpperCase() == "UL" || a.nodeName.toUpperCase() == "OL" ? (this.list = g(a), this.clip = this.list.parents(".jcarousel-clip"), this.container = this.list.parents(".jcarousel-container")) : (this.container = g(a), this.list = this.container.find("ul,ol").eq(0), this.clip = this.container.find(".jcarousel-clip")); if (this.clip.size() === 0) this.clip = this.list.wrap("<div></div>").parent(); if (this.container.size() === 0) this.container = this.clip.wrap("<div></div>").parent(); b !== "" && this.container.parent()[0].className.indexOf("jcarousel-skin") == -1 && this.container.wrap('<div class=" ' + b + '"></div>'); this.buttonPrev = g(".jcarousel-prev", this.container); if (this.buttonPrev.size() === 0 && this.options.buttonPrevHTML !== null) this.buttonPrev = g(this.options.buttonPrevHTML).appendTo(this.container); this.buttonPrev.addClass(this.className("jcarousel-prev")); this.buttonNext = g(".jcarousel-next", this.container); if (this.buttonNext.size() === 0 && this.options.buttonNextHTML !== null) this.buttonNext = g(this.options.buttonNextHTML).appendTo(this.container); this.buttonNext.addClass(this.className("jcarousel-next")); this.clip.addClass(this.className("jcarousel-clip")).css({ position: "relative" }); this.list.addClass(this.className("jcarousel-list")).css({ overflow: "hidden", position: "relative", top: 0, margin: 0, padding: 0 }).css(this.options.rtl ? "right" : "left", 0); this.container.addClass(this.className("jcarousel-container")).css({ position: "relative" }); !this.options.vertical && this.options.rtl && this.container.addClass("jcarousel-direction-rtl").attr("dir", "rtl"); var j = this.options.visible !== null ? Math.ceil(this.clipping() / this.options.visible) : null, b = this.list.children("li"), e = this; if (b.size() > 0) { var h = 0, i = this.options.offset; b.each(function () { e.format(this, i++); h += e.dimension(this, j) }); this.list.css(this.wh, h + 100 + "px"); if (!c || c.size === void 0) this.options.size = b.size() } this.container.css("display", "block"); this.buttonNext.css("display", "block"); this.buttonPrev.css("display", "block"); this.funcNext = function () { e.next() }; this.funcPrev = function () { e.prev() }; this.funcResize = function () { e.resizeTimer && clearTimeout(e.resizeTimer); e.resizeTimer = setTimeout(function () { e.reload() }, 100) }; this.options.initCallback !== null && this.options.initCallback(this, "init"); !m && g.browser.safari ? (this.buttons(!1, !1), g(window).bind("load.jcarousel", function () { e.setup() })) : this.setup() }; var f = g.jcarousel; f.fn = f.prototype = { jcarousel: "0.2.8" }; f.fn.extend = f.extend = g.extend; f.fn.extend({ setup: function () { this.prevLast = this.prevFirst = this.last = this.first = null; this.animating = !1; this.tail = this.resizeTimer = this.timer = null; this.inTail = !1; if (!this.locked) { this.list.css(this.lt, this.pos(this.options.offset) + "px"); var a = this.pos(this.options.start, !0); this.prevFirst = this.prevLast = null; this.animate(a, !1); g(window).unbind("resize.jcarousel", this.funcResize).bind("resize.jcarousel", this.funcResize); this.options.setupCallback !== null && this.options.setupCallback(this) } }, reset: function () { this.list.empty(); this.list.css(this.lt, "0px"); this.list.css(this.wh, "10px"); this.options.initCallback !== null && this.options.initCallback(this, "reset"); this.setup() }, reload: function () { this.tail !== null && this.inTail && this.list.css(this.lt, f.intval(this.list.css(this.lt)) + this.tail); this.tail = null; this.inTail = !1; this.options.reloadCallback !== null && this.options.reloadCallback(this); if (this.options.visible !== null) { var a = this, c = Math.ceil(this.clipping() / this.options.visible), b = 0, d = 0; this.list.children("li").each(function (f) { b += a.dimension(this, c); f + 1 < a.first && (d = b) }); this.list.css(this.wh, b + "px"); this.list.css(this.lt, -d + "px") } this.scroll(this.first, !1) }, lock: function () { this.locked = !0; this.buttons() }, unlock: function () { this.locked = !1; this.buttons() }, size: function (a) { if (a !== void 0) this.options.size = a, this.locked || this.buttons(); return this.options.size }, has: function (a, c) { if (c === void 0 || !c) c = a; if (this.options.size !== null && c > this.options.size) c = this.options.size; for (var b = a; b <= c; b++) { var d = this.get(b); if (!d.length || d.hasClass("jcarousel-item-placeholder")) return !1 } return !0 }, get: function (a) { return g(">.jcarousel-item-" + a, this.list) }, add: function (a, c) { var b = this.get(a), d = 0, p = g(c); if (b.length === 0) for (var j, e = f.intval(a), b = this.create(a); ; ) { if (j = this.get(--e), e <= 0 || j.length) { e <= 0 ? this.list.prepend(b) : j.after(b); break } } else d = this.dimension(b); p.get(0).nodeName.toUpperCase() == "LI" ? (b.replaceWith(p), b = p) : b.empty().append(c); this.format(b.removeClass(this.className("jcarousel-item-placeholder")), a); p = this.options.visible !== null ? Math.ceil(this.clipping() / this.options.visible) : null; d = this.dimension(b, p) - d; a > 0 && a < this.first && this.list.css(this.lt, f.intval(this.list.css(this.lt)) - d + "px"); this.list.css(this.wh, f.intval(this.list.css(this.wh)) + d + "px"); return b }, remove: function (a) { var c = this.get(a); if (c.length && !(a >= this.first && a <= this.last)) { var b = this.dimension(c); a < this.first && this.list.css(this.lt, f.intval(this.list.css(this.lt)) + b + "px"); c.remove(); this.list.css(this.wh, f.intval(this.list.css(this.wh)) - b + "px") } }, next: function () { this.tail !== null && !this.inTail ? this.scrollTail(!1) : this.scroll((this.options.wrap == "both" || this.options.wrap == "last") && this.options.size !== null && this.last == this.options.size ? 1 : this.first + this.options.scroll) }, prev: function () { this.tail !== null && this.inTail ? this.scrollTail(!0) : this.scroll((this.options.wrap == "both" || this.options.wrap == "first") && this.options.size !== null && this.first == 1 ? this.options.size : this.first - this.options.scroll) }, scrollTail: function (a) { if (!this.locked && !this.animating && this.tail) { this.pauseAuto(); var c = f.intval(this.list.css(this.lt)), c = !a ? c - this.tail : c + this.tail; this.inTail = !a; this.prevFirst = this.first; this.prevLast = this.last; this.animate(c) } }, scroll: function (a, c) { !this.locked && !this.animating && (this.pauseAuto(), this.animate(this.pos(a), c)) }, pos: function (a, c) { var b = f.intval(this.list.css(this.lt)); if (this.locked || this.animating) return b; this.options.wrap != "circular" && (a = a < 1 ? 1 : this.options.size && a > this.options.size ? this.options.size : a); for (var d = this.first > a, g = this.options.wrap != "circular" && this.first <= 1 ? 1 : this.first, j = d ? this.get(g) : this.get(this.last), e = d ? g : g - 1, h = null, i = 0, k = !1, l = 0; d ? --e >= a : ++e < a; ) { h = this.get(e); k = !h.length; if (h.length === 0 && (h = this.create(e).addClass(this.className("jcarousel-item-placeholder")), j[d ? "before" : "after"](h), this.first !== null && this.options.wrap == "circular" && this.options.size !== null && (e <= 0 || e > this.options.size))) j = this.get(this.index(e)), j.length && (h = this.add(e, j.clone(!0))); j = h; l = this.dimension(h); k && (i += l); if (this.first !== null && (this.options.wrap == "circular" || e >= 1 && (this.options.size === null || e <= this.options.size))) b = d ? b + l : b - l } for (var g = this.clipping(), m = [], o = 0, n = 0, j = this.get(a - 1), e = a; ++o; ) { h = this.get(e); k = !h.length; if (h.length === 0) { h = this.create(e).addClass(this.className("jcarousel-item-placeholder")); if (j.length === 0) this.list.prepend(h); else j[d ? "before" : "after"](h); if (this.first !== null && this.options.wrap == "circular" && this.options.size !== null && (e <= 0 || e > this.options.size)) j = this.get(this.index(e)), j.length && (h = this.add(e, j.clone(!0))) } j = h; l = this.dimension(h); if (l === 0) throw Error("jCarousel: No width/height set for items. This will cause an infinite loop. Aborting..."); this.options.wrap != "circular" && this.options.size !== null && e > this.options.size ? m.push(h) : k && (i += l); n += l; if (n >= g) break; e++ } for (h = 0; h < m.length; h++) m[h].remove(); i > 0 && (this.list.css(this.wh, this.dimension(this.list) + i + "px"), d && (b -= i, this.list.css(this.lt, f.intval(this.list.css(this.lt)) - i + "px"))); i = a + o - 1; if (this.options.wrap != "circular" && this.options.size && i > this.options.size) i = this.options.size; if (e > i) { o = 0; e = i; for (n = 0; ++o; ) { h = this.get(e--); if (!h.length) break; n += this.dimension(h); if (n >= g) break } } e = i - o + 1; this.options.wrap != "circular" && e < 1 && (e = 1); if (this.inTail && d) b += this.tail, this.inTail = !1; this.tail = null; if (this.options.wrap != "circular" && i == this.options.size && i - o + 1 >= 1 && (d = f.intval(this.get(i).css(!this.options.vertical ? "marginRight" : "marginBottom")), n - d > g)) this.tail = n - g - d; if (c && a === this.options.size && this.tail) b -= this.tail, this.inTail = !0; for (; a-- > e; ) b += this.dimension(this.get(a)); this.prevFirst = this.first; this.prevLast = this.last; this.first = e; this.last = i; return b }, animate: function (a, c) { if (!this.locked && !this.animating) { this.animating = !0; var b = this, d = function () { b.animating = !1; a === 0 && b.list.css(b.lt, 0); !b.autoStopped && (b.options.wrap == "circular" || b.options.wrap == "both" || b.options.wrap == "last" || b.options.size === null || b.last < b.options.size || b.last == b.options.size && b.tail !== null && !b.inTail) && b.startAuto(); b.buttons(); b.notify("onAfterAnimation"); if (b.options.wrap == "circular" && b.options.size !== null) for (var c = b.prevFirst; c <= b.prevLast; c++) c !== null && !(c >= b.first && c <= b.last) && (c < 1 || c > b.options.size) && b.remove(c) }; this.notify("onBeforeAnimation"); if (!this.options.animation || c === !1) this.list.css(this.lt, a + "px"), d(); else { var f = !this.options.vertical ? this.options.rtl ? { right: a} : { left: a} : { top: a }, d = { duration: this.options.animation, easing: this.options.easing, complete: d }; if (g.isFunction(this.options.animationStepCallback)) d.step = this.options.animationStepCallback; this.list.animate(f, d) } } }, startAuto: function (a) { if (a !== void 0) this.options.auto = a; if (this.options.auto === 0) return this.stopAuto(); if (this.timer === null) { this.autoStopped = !1; var c = this; this.timer = window.setTimeout(function () { c.next() }, this.options.auto * 1E3) } }, stopAuto: function () { this.pauseAuto(); this.autoStopped = !0 }, pauseAuto: function () { if (this.timer !== null) window.clearTimeout(this.timer), this.timer = null }, buttons: function (a, c) { if (a == null && (a = !this.locked && this.options.size !== 0 && (this.options.wrap && this.options.wrap != "first" || this.options.size === null || this.last < this.options.size), !this.locked && (!this.options.wrap || this.options.wrap == "first") && this.options.size !== null && this.last >= this.options.size)) a = this.tail !== null && !this.inTail; if (c == null && (c = !this.locked && this.options.size !== 0 && (this.options.wrap && this.options.wrap != "last" || this.first > 1), !this.locked && (!this.options.wrap || this.options.wrap == "last") && this.options.size !== null && this.first == 1)) c = this.tail !== null && this.inTail; var b = this; this.buttonNext.size() > 0 ? (this.buttonNext.unbind(this.options.buttonNextEvent + ".jcarousel", this.funcNext), a && this.buttonNext.bind(this.options.buttonNextEvent + ".jcarousel", this.funcNext), this.buttonNext[a ? "removeClass" : "addClass"](this.className("jcarousel-next-disabled")).attr("disabled", a ? !1 : !0), this.options.buttonNextCallback !== null && this.buttonNext.data("jcarouselstate") != a && this.buttonNext.each(function () { b.options.buttonNextCallback(b, this, a) }).data("jcarouselstate", a)) : this.options.buttonNextCallback !== null && this.buttonNextState != a && this.options.buttonNextCallback(b, null, a); this.buttonPrev.size() > 0 ? (this.buttonPrev.unbind(this.options.buttonPrevEvent + ".jcarousel", this.funcPrev), c && this.buttonPrev.bind(this.options.buttonPrevEvent + ".jcarousel", this.funcPrev), this.buttonPrev[c ? "removeClass" : "addClass"](this.className("jcarousel-prev-disabled")).attr("disabled", c ? !1 : !0), this.options.buttonPrevCallback !== null && this.buttonPrev.data("jcarouselstate") != c && this.buttonPrev.each(function () { b.options.buttonPrevCallback(b, this, c) }).data("jcarouselstate", c)) : this.options.buttonPrevCallback !== null && this.buttonPrevState != c && this.options.buttonPrevCallback(b, null, c); this.buttonNextState = a; this.buttonPrevState = c }, notify: function (a) { var c = this.prevFirst === null ? "init" : this.prevFirst < this.first ? "next" : "prev"; this.callback("itemLoadCallback", a, c); this.prevFirst !== this.first && (this.callback("itemFirstInCallback", a, c, this.first), this.callback("itemFirstOutCallback", a, c, this.prevFirst)); this.prevLast !== this.last && (this.callback("itemLastInCallback", a, c, this.last), this.callback("itemLastOutCallback", a, c, this.prevLast)); this.callback("itemVisibleInCallback", a, c, this.first, this.last, this.prevFirst, this.prevLast); this.callback("itemVisibleOutCallback", a, c, this.prevFirst, this.prevLast, this.first, this.last) }, callback: function (a, c, b, d, f, j, e) { if (!(this.options[a] == null || typeof this.options[a] != "object" && c != "onAfterAnimation")) { var h = typeof this.options[a] == "object" ? this.options[a][c] : this.options[a]; if (g.isFunction(h)) { var i = this; if (d === void 0) h(i, b, c); else if (f === void 0) this.get(d).each(function () { h(i, this, d, b, c) }); else for (var a = function (a) { i.get(a).each(function () { h(i, this, a, b, c) }) }, k = d; k <= f; k++) k !== null && !(k >= j && k <= e) && a(k) } } }, create: function (a) { return this.format("<li></li>", a) }, format: function (a, c) { for (var a = g(a), b = a.get(0).className.split(" "), d = 0; d < b.length; d++) b[d].indexOf("jcarousel-") != -1 && a.removeClass(b[d]); a.addClass(this.className("jcarousel-item")).addClass(this.className("jcarousel-item-" + c)).css({ "float": this.options.rtl ? "right" : "left", "list-style": "none" }).attr("jcarouselindex", c); return a }, className: function (a) { return a + " " + a + (!this.options.vertical ? "-horizontal" : "-vertical") }, dimension: function (a, c) { var b = g(a); if (c == null) return !this.options.vertical ? b.outerWidth(!0) || f.intval(this.options.itemFallbackDimension) : b.outerHeight(!0) || f.intval(this.options.itemFallbackDimension); else { var d = !this.options.vertical ? c - f.intval(b.css("marginLeft")) - f.intval(b.css("marginRight")) : c - f.intval(b.css("marginTop")) - f.intval(b.css("marginBottom")); g(b).css(this.wh, d + "px"); return this.dimension(b) } }, clipping: function () { return !this.options.vertical ? this.clip[0].offsetWidth - f.intval(this.clip.css("borderLeftWidth")) - f.intval(this.clip.css("borderRightWidth")) : this.clip[0].offsetHeight - f.intval(this.clip.css("borderTopWidth")) - f.intval(this.clip.css("borderBottomWidth")) }, index: function (a, c) { if (c == null) c = this.options.size; return Math.round(((a - 1) / c - Math.floor((a - 1) / c)) * c) + 1 } }); f.extend({ defaults: function (a) { return g.extend(q, a || {}) }, intval: function (a) { a = parseInt(a, 10); return isNaN(a) ? 0 : a }, windowLoaded: function () { m = !0 } }); g.fn.jcarousel = function (a) { if (typeof a == "string") { var c = g(this).data("jcarousel"), b = Array.prototype.slice.call(arguments, 1); return c[a].apply(c, b) } else return this.each(function () { var b = g(this).data("jcarousel"); b ? (a && g.extend(b.options, a), b.reload()) : g(this).data("jcarousel", new f(this, a)) }) } })(jQuery);

/*****
 * jQuery Uploadify
 */
if (jQuery) { (function (a) { a.extend(a.fn, { uploadify: function (b) { a(this).each(function () { var f = a.extend({ id: a(this).attr("id"), uploader: "uploadify.swf", script: "uploadify.php", expressInstall: null, folder: "", height: 30, width: 120, cancelImg: "cancel.png", wmode: "opaque", scriptAccess: "sameDomain", fileDataName: "Filedata", method: "POST", queueSizeLimit: 999, simUploadLimit: 1, queueID: false, displayData: "percentage", removeCompleted: true, onInit: function () { }, onSelect: function () { }, onSelectOnce: function () { }, onQueueFull: function () { }, onCheck: function () { }, onCancel: function () { }, onClearQueue: function () { }, onError: function () { }, onProgress: function () { }, onComplete: function () { }, onAllComplete: function () { } }, b); a(this).data("settings", f); var e = location.pathname; e = e.split("/"); e.pop(); e = e.join("/") + "/"; var g = {}; g.uploadifyID = f.id; g.pagepath = e; if (f.buttonImg) { g.buttonImg = escape(f.buttonImg) } if (f.buttonText) { g.buttonText = escape(f.buttonText) } if (f.rollover) { g.rollover = true } g.script = f.script; g.folder = escape(f.folder); if (f.scriptData) { var h = ""; for (var d in f.scriptData) { h += "&" + d + "=" + f.scriptData[d] } g.scriptData = escape(h.substr(1)) } g.width = f.width; g.height = f.height; g.wmode = f.wmode; g.method = f.method; g.queueSizeLimit = f.queueSizeLimit; g.simUploadLimit = f.simUploadLimit; if (f.hideButton) { g.hideButton = true } if (f.fileDesc) { g.fileDesc = f.fileDesc } if (f.fileExt) { g.fileExt = f.fileExt } if (f.multi) { g.multi = true } if (f.auto) { g.auto = true } if (f.sizeLimit) { g.sizeLimit = f.sizeLimit } if (f.checkScript) { g.checkScript = f.checkScript } if (f.fileDataName) { g.fileDataName = f.fileDataName } if (f.queueID) { g.queueID = f.queueID } if (f.onInit() !== false) { a(this).css("display", "none"); a(this).after('<div id="' + a(this).attr("id") + 'Uploader"></div>'); swfobject.embedSWF(f.uploader, f.id + "Uploader", f.width, f.height, "9.0.24", f.expressInstall, g, { quality: "high", wmode: f.wmode, allowScriptAccess: f.scriptAccess }, {}, function (i) { if (typeof (f.onSWFReady) == "function" && i.success) { f.onSWFReady() } }); if (f.queueID == false) { a("#" + a(this).attr("id") + "Uploader").after('<div id="' + a(this).attr("id") + 'Queue" class="uploadifyQueue"></div>') } else { a("#" + f.queueID).addClass("uploadifyQueue") } } if (typeof (f.onOpen) == "function") { a(this).bind("uploadifyOpen", f.onOpen) } a(this).bind("uploadifySelect", { action: f.onSelect, queueID: f.queueID }, function (k, i, j) { if (k.data.action(k, i, j) !== false) { var l = Math.round(j.size / 1024 * 100) * 0.01; var m = "KB"; if (l > 1000) { l = Math.round(l * 0.001 * 100) * 0.01; m = "MB" } var n = l.toString().split("."); if (n.length > 1) { l = n[0] + "." + n[1].substr(0, 2) } else { l = n[0] } if (j.name.length > 20) { fileName = j.name.substr(0, 20) + "..." } else { fileName = j.name } queue = "#" + a(this).attr("id") + "Queue"; if (k.data.queueID) { queue = "#" + k.data.queueID } a(queue).append('<div id="' + a(this).attr("id") + i + '" class="uploadifyQueueItem"><div class="cancel"><a href="javascript:jQuery(\'#' + a(this).attr("id") + "').uploadifyCancel('" + i + '\')"><img src="' + f.cancelImg + '" border="0" /></a></div><span class="fileName">' + fileName + " (" + l + m + ')</span><span class="percentage"></span><div class="uploadifyProgress"><div id="' + a(this).attr("id") + i + 'ProgressBar" class="uploadifyProgressBar"><!--Progress Bar--></div></div></div>') } }); a(this).bind("uploadifySelectOnce", { action: f.onSelectOnce }, function (i, j) { i.data.action(i, j); if (f.auto) { if (f.checkScript) { a(this).uploadifyUpload(null, false) } else { a(this).uploadifyUpload(null, true) } } }); a(this).bind("uploadifyQueueFull", { action: f.onQueueFull }, function (i, j) { if (i.data.action(i, j) !== false) { alert("The queue is full.  The max size is " + j + ".") } }); a(this).bind("uploadifyCheckExist", { action: f.onCheck }, function (n, m, l, k, p) { var j = new Object(); j = l; j.folder = (k.substr(0, 1) == "/") ? k : e + k; if (p) { for (var i in l) { var o = i } } a.post(m, j, function (s) { for (var q in s) { if (n.data.action(n, s, q) !== false) { var r = confirm("Do you want to replace the file " + s[q] + "?"); if (!r) { document.getElementById(a(n.target).attr("id") + "Uploader").cancelFileUpload(q, true, true) } } } if (p) { document.getElementById(a(n.target).attr("id") + "Uploader").startFileUpload(o, true) } else { document.getElementById(a(n.target).attr("id") + "Uploader").startFileUpload(null, true) } }, "json") }); a(this).bind("uploadifyCancel", { action: f.onCancel }, function (n, j, m, o, i, l) { if (n.data.action(n, j, m, o, l) !== false) { if (i) { var k = (l == true) ? 0 : 250; a("#" + a(this).attr("id") + j).fadeOut(k, function () { a(this).remove() }) } } }); a(this).bind("uploadifyClearQueue", { action: f.onClearQueue }, function (k, j) { var i = (f.queueID) ? f.queueID : a(this).attr("id") + "Queue"; if (j) { a("#" + i).find(".uploadifyQueueItem").remove() } if (k.data.action(k, j) !== false) { a("#" + i).find(".uploadifyQueueItem").each(function () { var l = a(".uploadifyQueueItem").index(this); a(this).delay(l * 100).fadeOut(250, function () { a(this).remove() }) }) } }); var c = []; a(this).bind("uploadifyError", { action: f.onError }, function (m, i, l, k) { if (m.data.action(m, i, l, k) !== false) { var j = new Array(i, l, k); c.push(j); a("#" + a(this).attr("id") + i).find(".percentage").text(" - " + k.type + " Error"); a("#" + a(this).attr("id") + i).find(".uploadifyProgress").hide(); a("#" + a(this).attr("id") + i).addClass("uploadifyError") } }); if (typeof (f.onUpload) == "function") { a(this).bind("uploadifyUpload", f.onUpload) } a(this).bind("uploadifyProgress", { action: f.onProgress, toDisplay: f.displayData }, function (k, i, j, l) { if (k.data.action(k, i, j, l) !== false) { a("#" + a(this).attr("id") + i + "ProgressBar").animate({ width: l.percentage + "%" }, 250, function () { if (l.percentage == 100) { a(this).closest(".uploadifyProgress").fadeOut(250, function () { a(this).remove() }) } }); if (k.data.toDisplay == "percentage") { displayData = " - " + l.percentage + "%" } if (k.data.toDisplay == "speed") { displayData = " - " + l.speed + "KB/s" } if (k.data.toDisplay == null) { displayData = " " } a("#" + a(this).attr("id") + i).find(".percentage").text(displayData) } }); a(this).bind("uploadifyComplete", { action: f.onComplete }, function (l, i, k, j, m) { if (l.data.action(l, i, k, unescape(j), m) !== false) { a("#" + a(this).attr("id") + i).find(".percentage").text(" - Completed"); if (f.removeCompleted) { a("#" + a(l.target).attr("id") + i).fadeOut(250, function () { a(this).remove() }) } a("#" + a(l.target).attr("id") + i).addClass("completed") } }); if (typeof (f.onAllComplete) == "function") { a(this).bind("uploadifyAllComplete", { action: f.onAllComplete }, function (i, j) { if (i.data.action(i, j) !== false) { c = [] } }) } }) }, uploadifySettings: function (f, j, c) { var g = false; a(this).each(function () { if (f == "scriptData" && j != null) { if (c) { var i = j } else { var i = a.extend(a(this).data("settings").scriptData, j) } var l = ""; for (var k in i) { l += "&" + k + "=" + i[k] } j = escape(l.substr(1)) } g = document.getElementById(a(this).attr("id") + "Uploader").updateSettings(f, j) }); if (j == null) { if (f == "scriptData") { var b = unescape(g).split("&"); var e = new Object(); for (var d = 0; d < b.length; d++) { var h = b[d].split("="); e[h[0]] = h[1] } g = e } } return g }, uploadifyUpload: function (b, c) { a(this).each(function () { if (!c) { c = false } document.getElementById(a(this).attr("id") + "Uploader").startFileUpload(b, c) }) }, uploadifyCancel: function (b) { a(this).each(function () { document.getElementById(a(this).attr("id") + "Uploader").cancelFileUpload(b, true, true, false) }) }, uploadifyClearQueue: function () { a(this).each(function () { document.getElementById(a(this).attr("id") + "Uploader").clearFileUploadQueue(false) }) } }) })(jQuery) };

/*****
 * Underscore.js 1.1.7
 * (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.
 * Underscore is freely distributable under the MIT license.
 * Portions of Underscore are inspired or borrowed from Prototype,
 * Oliver Steele's Functional, and John Resig's Micro-Templating.
 * For all details and documentation:
 * http://documentcloud.github.com/underscore
 */
(function () {var p = this, C = p._, m = {}, i = Array.prototype, n = Object.prototype, f = i.slice, D = i.unshift, E = n.toString, l = n.hasOwnProperty, s = i.forEach, t = i.map, u = i.reduce, v = i.reduceRight, w = i.filter, x = i.every, y = i.some, o = i.indexOf, z = i.lastIndexOf; n = Array.isArray; var F = Object.keys, q = Function.prototype.bind, b = function (a) { return new j(a) }; typeof module !== "undefined" && module.exports ? (module.exports = b, b._ = b) : p._ = b; b.VERSION = "1.1.7"; var h = b.each = b.forEach = function (a, c, b) {if (a != null) if (s && a.forEach === s) a.forEach(c, b); else if (a.length ===+a.length) for (var e = 0, k = a.length; e < k; e++) { if (e in a && c.call(b, a[e], e, a) === m) break } else for (e in a) if (l.call(a, e) && c.call(b, a[e], e, a) === m) break}; b.map = function (a, c, b) { var e = []; if (a == null) return e; if (t && a.map === t) return a.map(c, b); h(a, function (a, g, G) { e[e.length] = c.call(b, a, g, G) }); return e }; b.reduce = b.foldl = b.inject = function (a, c, d, e) {var k = d !== void 0; a == null && (a = []); if (u && a.reduce === u) return e && (c = b.bind(c, e)), k ? a.reduce(c, d) : a.reduce(c); h(a, function (a, b, f) { k ? d = c.call(e, d, a, b, f) : (d = a, k = !0) }); if (!k) throw new TypeError("Reduce of empty array with no initial value");return d}; b.reduceRight = b.foldr = function (a, c, d, e) { a == null && (a = []); if (v && a.reduceRight === v) return e && (c = b.bind(c, e)), d !== void 0 ? a.reduceRight(c, d) : a.reduceRight(c); a = (b.isArray(a) ? a.slice() : b.toArray(a)).reverse(); return b.reduce(a, c, d, e) }; b.find = b.detect = function (a, c, b) { var e; A(a, function (a, g, f) { if (c.call(b, a, g, f)) return e = a, !0 }); return e }; b.filter = b.select = function (a, c, b) { var e = []; if (a == null) return e; if (w && a.filter === w) return a.filter(c, b); h(a, function (a, g, f) { c.call(b, a, g, f) && (e[e.length] = a) }); return e };b.reject = function (a, c, b) { var e = []; if (a == null) return e; h(a, function (a, g, f) { c.call(b, a, g, f) || (e[e.length] = a) }); return e }; b.every = b.all = function (a, c, b) { var e = !0; if (a == null) return e; if (x && a.every === x) return a.every(c, b); h(a, function (a, g, f) { if (!(e = e && c.call(b, a, g, f))) return m }); return e }; var A = b.some = b.any = function (a, c, d) { c = c || b.identity; var e = !1; if (a == null) return e; if (y && a.some === y) return a.some(c, d); h(a, function (a, b, f) { if (e |= c.call(d, a, b, f)) return m }); return !!e }; b.include = b.contains = function (a, c) {var b = !1; if (a == null) return b; if (o && a.indexOf === o) return a.indexOf(c) != -1; A(a, function (a) { if (b = a === c) return !0 }); return b}; b.invoke = function (a, c) { var d = f.call(arguments, 2); return b.map(a, function (a) { return (c.call ? c || a : a[c]).apply(a, d) }) }; b.pluck = function (a, c) { return b.map(a, function (a) { return a[c] }) }; b.max = function (a, c, d) { if (!c && b.isArray(a)) return Math.max.apply(Math, a); var e = { computed: -Infinity }; h(a, function (a, b, f) { b = c ? c.call(d, a, b, f) : a; b >= e.computed && (e = { value: a, computed: b }) }); return e.value }; b.min = function (a,c, d) { if (!c && b.isArray(a)) return Math.min.apply(Math, a); var e = { computed: Infinity }; h(a, function (a, b, f) { b = c ? c.call(d, a, b, f) : a; b < e.computed && (e = { value: a, computed: b }) }); return e.value }; b.sortBy = function (a, c, d) { return b.pluck(b.map(a, function (a, b, f) { return { value: a, criteria: c.call(d, a, b, f)} }).sort(function (a, b) { var c = a.criteria, d = b.criteria; return c < d ? -1 : c > d ? 1 : 0 }), "value") }; b.groupBy = function (a, b) { var d = {}; h(a, function (a, f) { var g = b(a, f); (d[g] || (d[g] = [])).push(a) }); return d }; b.sortedIndex = function (a, c, d) {d ||(d = b.identity); for (var e = 0, f = a.length; e < f; ) { var g = e + f >> 1; d(a[g]) < d(c) ? e = g + 1 : f = g } return e}; b.toArray = function (a) { if (!a) return []; if (a.toArray) return a.toArray(); if (b.isArray(a)) return f.call(a); if (b.isArguments(a)) return f.call(a); return b.values(a) }; b.size = function (a) { return b.toArray(a).length }; b.first = b.head = function (a, b, d) { return b != null && !d ? f.call(a, 0, b) : a[0] }; b.rest = b.tail = function (a, b, d) { return f.call(a, b == null || d ? 1 : b) }; b.last = function (a) { return a[a.length - 1] }; b.compact = function (a) {return b.filter(a,function (a) { return !!a })}; b.flatten = function (a) { return b.reduce(a, function (a, d) { if (b.isArray(d)) return a.concat(b.flatten(d)); a[a.length] = d; return a }, []) }; b.without = function (a) { return b.difference(a, f.call(arguments, 1)) }; b.uniq = b.unique = function (a, c) { return b.reduce(a, function (a, e, f) { if (0 == f || (c === !0 ? b.last(a) != e : !b.include(a, e))) a[a.length] = e; return a }, []) }; b.union = function () { return b.uniq(b.flatten(arguments)) }; b.intersection = b.intersect = function (a) {var c = f.call(arguments, 1); return b.filter(b.uniq(a),function (a) { return b.every(c, function (c) { return b.indexOf(c, a) >= 0 }) })}; b.difference = function (a, c) { return b.filter(a, function (a) { return !b.include(c, a) }) }; b.zip = function () { for (var a = f.call(arguments), c = b.max(b.pluck(a, "length")), d = Array(c), e = 0; e < c; e++) d[e] = b.pluck(a, "" + e); return d }; b.indexOf = function (a, c, d) { if (a == null) return -1; var e; if (d) return d = b.sortedIndex(a, c), a[d] === c ? d : -1; if (o && a.indexOf === o) return a.indexOf(c); d = 0; for (e = a.length; d < e; d++) if (a[d] === c) return d; return -1 }; b.lastIndexOf = function (a,b) { if (a == null) return -1; if (z && a.lastIndexOf === z) return a.lastIndexOf(b); for (var d = a.length; d--; ) if (a[d] === b) return d; return -1 }; b.range = function (a, b, d) { arguments.length <= 1 && (b = a || 0, a = 0); d = arguments[2] || 1; for (var e = Math.max(Math.ceil((b - a) / d), 0), f = 0, g = Array(e); f < e; ) g[f++] = a, a += d; return g }; b.bind = function (a, b) { if (a.bind === q && q) return q.apply(a, f.call(arguments, 1)); var d = f.call(arguments, 2); return function () { return a.apply(b, d.concat(f.call(arguments))) } }; b.bindAll = function (a) {var c = f.call(arguments, 1);c.length == 0 && (c = b.functions(a)); h(c, function (c) { a[c] = b.bind(a[c], a) }); return a}; b.memoize = function (a, c) { var d = {}; c || (c = b.identity); return function () { var b = c.apply(this, arguments); return l.call(d, b) ? d[b] : d[b] = a.apply(this, arguments) } }; b.delay = function (a, b) { var d = f.call(arguments, 2); return setTimeout(function () { return a.apply(a, d) }, b) }; b.defer = function (a) { return b.delay.apply(b, [a, 1].concat(f.call(arguments, 1))) }; var B = function (a, b, d) {var e; return function () {var f = this, g = arguments, h = function () {e = null;a.apply(f, g)}; d && clearTimeout(e); if (d || !e) e = setTimeout(h, b)} }; b.throttle = function (a, b) { return B(a, b, !1) }; b.debounce = function (a, b) { return B(a, b, !0) }; b.once = function (a) { var b = !1, d; return function () { if (b) return d; b = !0; return d = a.apply(this, arguments) } }; b.wrap = function (a, b) { return function () { var d = [a].concat(f.call(arguments)); return b.apply(this, d) } }; b.compose = function () { var a = f.call(arguments); return function () { for (var b = f.call(arguments), d = a.length - 1; d >= 0; d--) b = [a[d].apply(this, b)]; return b[0] } }; b.after =function (a, b) { return function () { if (--a < 1) return b.apply(this, arguments) } }; b.keys = F || function (a) { if (a !== Object(a)) throw new TypeError("Invalid object"); var b = [], d; for (d in a) l.call(a, d) && (b[b.length] = d); return b }; b.values = function (a) { return b.map(a, b.identity) }; b.functions = b.methods = function (a) { var c = [], d; for (d in a) b.isFunction(a[d]) && c.push(d); return c.sort() }; b.extend = function (a) { h(f.call(arguments, 1), function (b) { for (var d in b) b[d] !== void 0 && (a[d] = b[d]) }); return a }; b.defaults = function (a) {h(f.call(arguments,1), function (b) { for (var d in b) a[d] == null && (a[d] = b[d]) }); return a}; b.clone = function (a) { return b.isArray(a) ? a.slice() : b.extend({}, a) }; b.tap = function (a, b) { b(a); return a }; b.isEqual = function (a, c) {if (a === c) return !0; var d = typeof a; if (d != typeof c) return !1; if (a == c) return !0; if (!a && c || a && !c) return !1; if (a._chain) a = a._wrapped; if (c._chain) c = c._wrapped; if (a.isEqual) return a.isEqual(c); if (c.isEqual) return c.isEqual(a); if (b.isDate(a) && b.isDate(c)) return a.getTime() === c.getTime(); if (b.isNaN(a) && b.isNaN(c)) return !1;if (b.isRegExp(a) && b.isRegExp(c)) return a.source === c.source && a.global === c.global && a.ignoreCase === c.ignoreCase && a.multiline === c.multiline; if (d !== "object") return !1; if (a.length && a.length !== c.length) return !1; d = b.keys(a); var e = b.keys(c); if (d.length != e.length) return !1; for (var f in a) if (!(f in c) || !b.isEqual(a[f], c[f])) return !1; return !0}; b.isEmpty = function (a) { if (b.isArray(a) || b.isString(a)) return a.length === 0; for (var c in a) if (l.call(a, c)) return !1; return !0 }; b.isElement = function (a) {return !!(a && a.nodeType ==1)}; b.isArray = n || function (a) { return E.call(a) === "[object Array]" }; b.isObject = function (a) { return a === Object(a) }; b.isArguments = function (a) { return !(!a || !l.call(a, "callee")) }; b.isFunction = function (a) { return !(!a || !a.constructor || !a.call || !a.apply) }; b.isString = function (a) { return !!(a === "" || a && a.charCodeAt && a.substr) }; b.isNumber = function (a) { return !!(a === 0 || a && a.toExponential && a.toFixed) }; b.isNaN = function (a) { return a !== a }; b.isBoolean = function (a) { return a === !0 || a === !1 }; b.isDate = function (a) {return !(!a || !a.getTimezoneOffset ||!a.setUTCFullYear)}; b.isRegExp = function (a) { return !(!a || !a.test || !a.exec || !(a.ignoreCase || a.ignoreCase === !1)) }; b.isNull = function (a) { return a === null }; b.isUndefined = function (a) { return a === void 0 }; b.noConflict = function () { p._ = C; return this }; b.identity = function (a) { return a }; b.times = function (a, b, d) { for (var e = 0; e < a; e++) b.call(d, e) }; b.mixin = function (a) { h(b.functions(a), function (c) { H(c, b[c] = a[c]) }) }; var I = 0; b.uniqueId = function (a) { var b = I++; return a ? a + b : b }; b.templateSettings = { evaluate: /<%([\s\S]+?)%>/g, interpolate: /<%=([\s\S]+?)%>/g };b.template = function (a, c) { var d = b.templateSettings; d = "var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('" + a.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(d.interpolate, function (a, b) { return "'," + b.replace(/\\'/g, "'") + ",'" }).replace(d.evaluate || null, function (a, b) { return "');" + b.replace(/\\'/g, "'").replace(/[\r\n\t]/g, " ") + "__p.push('" }).replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/\t/g, "\\t") + "');}return __p.join('');"; d = new Function("obj", d); return c ? d(c) : d };var j = function (a) { this._wrapped = a }; b.prototype = j.prototype; var r = function (a, c) { return c ? b(a).chain() : a }, H = function (a, c) { j.prototype[a] = function () { var a = f.call(arguments); D.call(a, this._wrapped); return r(c.apply(b, a), this._chain) } }; b.mixin(b); h(["pop", "push", "reverse", "shift", "sort", "splice", "unshift"], function (a) { var b = i[a]; j.prototype[a] = function () { b.apply(this._wrapped, arguments); return r(this._wrapped, this._chain) } }); h(["concat", "join", "slice"], function (a) {var b = i[a]; j.prototype[a] = function () {return r(b.apply(this._wrapped,arguments), this._chain)} }); j.prototype.chain = function () { this._chain = !0; return this }; j.prototype.value = function () { return this._wrapped } })();

/*****
 * Doubleclick spotlight tagging
 */
var dblClickSrc = '1869704';
var dblClickGroup = 'yopla867';

var spotlight = function(category) {
		var axel = Math.random() + "";
		var a = axel * 1000000000000000000;

		var doPing = new Image();
		// the URL below is a spotlight tag for page
		doPing.src = 'http://ad.doubleclick.net/activity;src=' + dblClickSrc + ';type=' + dblClickGroup + ';cat=' + category + ';ord=1;num=' + a + '?';
		doPing.onload = function() { 
			// $.noop() does nothing, but the presence of a 
			// function call here will ensure the dblclick tracking
			// image is downloaded everytime
			$.noop(); 
		};
};

jQuery(document).ready(function () {

	$('table.striped tbody tr:even').css('background-color', '#fef6f9');

  $('#resend-verification').bind('click', function(){
    $.ajax({
      url: '/save-lids-save-lives/services/json/resend-email/',
      data: { email: $(this).attr('data-email') },
      success: function (data) {
        log('in success');
        if (data.status) {
          $('#sent').text(emailSent); //'The email has been sent.');
        }
      },
      error: function () {
        log('a problem happened sending the verification email');
      }
    });
  });

  $('#ageCheck').bind('change', function () {
    log('make this click the Add Dedication button');
    if (stepOneIsValid(this)) {
        //$('#form1').trigger('submit');
        $('#add-dedication').val('true');
        $('#age').val($(this).val());
        $('#step-1').hide();
        $('#step-2').show();
        window.scrollTo(0, 0);
    }
  });

  // global "submit button". must set class to submit-btn and provide data-action attr on tag
  $('.submit-btn').bind('click', function () {
    var action = $(this).attr('data-action');
    if ((typeof action !== 'undefined') && action !== '') {
      switch (action) {
        case 'submit':
          log('submit action');
          $('#form1').submit();
          break;
        case 'unknown-user':
          break;
        case 'redeem-more':
          log('redeem more action');
          $('#rs').val(5);
          document.forms[0].action = '/save-lids-save-lives/redeem-lids-online/';
          document.forms[0].submit();
          break;
      }
    } else {
      log('no action on the submit-btn');
    }
  });

  $('#products-link').bind('click', function () {
    addOverlayShadow();
    $('#products').show();
  });

  $('.about-slsl.faqs dt, .partners dt').bind('click', function () {
    var dd = $(this).next('dd');
    if (!dd.is(':visible')) {
      log($(this).parent().children('dt').not(this));
      $(this).removeClass('closed');
      $(this).parent().children('dt').not(this).addClass('closed');
      dd.show();
      $('img', this).attr('src', '/ui/img/slsl/arrow-up.gif');
      $(this).parent().children('dt').not(this).each(function () {
        $('img', this).attr('src', '/ui/img/slsl/arrow-down.gif');
      });
      $(this).parent().children('dd').not(dd).hide();
    }
  });

  /* enter lid codes events */
  $('#dedication').bind('keyup', function () {
    var len = $(this).val().length;
    $('#chars-left').text(len);
    if (len >= 165) {
      $('#chars-left-wrap').toggleClass('red');
    }
  });

  $('#whats-this-dedicate').bind('click', function () {
    addOverlayShadow();
    $('#dedicate-explain').show();
  });

  $('#promo-code-link').bind('click', function () {
    addOverlayShadow();
    $('#promo-code-explain').show();
  });

  $('#same-code').bind('click', function () {
    $('#where-do-i-find').css('height', '220px');
    $('#same-code-ans').show();
  });

  $('.ded-agree.link').bind('click', function () {
    addOverlayShadow();
    $('#agreement').show();
  });

  $('#where-link').bind('click', function () {
    addOverlayShadow();
    $('#where-do-i-find').show();
  });

  $('#img-upload').uploadify({
    'uploader': '/ui/flash/slsl/uploadify.swf',
    'script': '/save-lids-save-lives/services/json/upload/',
    'cancelImg': '/ui/img/slsl/cancel.png',
    'buttonImg': '/ui/img/slsl/browse.png',
    'folder': '/uploads',
    'width': 86,
    'height': 25,
    'auto': true,
    'fileExt': slsl.upload.IMAGE_EXTENSIONS,
    'fileDesc': 'Web Image Files (.JPG, .GIF, .PNG)',
    'sizeLimit': slsl.upload.IMAGE_SIZE,
    'onComplete': function (event, ID, fileObj, response, data) {
      var jsonData = $.parseJSON(response);
      log(jsonData);
      $('#imgId').attr('value', jsonData.assetId);
      alert('Photo Upload Complete');
    },
    'onError': function () {
      log('what happened to img upload');
    }
  });

  $('#view-sample').bind('click', function () {
    addOverlayShadow();
    $('#dedication-sample').show();
  });

  $('#ageCheck').bind('change', function () {
    if ($(':selected', this).index() === 1) {
      $('.dedicate-btn').data('disabled-age', 'true');
      $('.dedicate-btn').css('opacity', '0.2');
      $('[data-valid-for="ageCheck"]').show();
    } else if ($(':selected', this).index() > 1) {
      $('.dedicate-btn').data('disabled-age', 'false');
      $('.dedicate-btn').css('opacity', '1');
      $('[data-valid-for="ageCheck"]').hide();
    }
  });

	$('#same-link').bind('click', function () { 
		addOverlayShadow(); 
		$('#im-seeing-same-code').show();
	});
	
  $('#are-you-sure').bind('click', function (evt) {
    if (!$.cookie('dont_show_again')) {
      $('#dedicate-overlay').show();
      evt.preventDefault();
    } else {
      document.forms[0].submit();
    }
  });

  $('#are-you-sure-es').bind('click', function (evt) {
    if (stepOneIsValid(this)) {
      document.forms[0].submit();
    }
  });

  $('#add-more').bind('click', function () {
    var start = $('.lid-code-entry').filter(':visible').length;
    buildLidCodesRow(start);
    if ($.browser.msie && $.browser.version === '7.0') {
      console.log('in this css thing');
      $('.page-content.centered-container.clear-after.full-height').css({
        'visibility': 'visible'
      });
      /* 
       * NONE OF THIS SEEMS TO WORK 
       *  The idea is to force a refresh of the DOM, by adding an element and then reading a property of that new element
       * 
       * $('.page-content-bg').css('height','10000px');
       * log('adding somethign to the DOM to force redraw');
       * var newDiv = document.createElement('div');
       * newDiv.id = 'badIE-'+start;
       * $('.page-content.centered-container.clear-after.full-height').append(newDiv);
       * var ieIsStoopid = document.getElementById('badIE-'+start).id;
       * log(ieIsStoopid);
       */
    }
  });

  if ($('.lid-codes-form').length > 0) {
    buildLidCodesRow();
  }

  $('.close-btn').bind('click', function () {
    $(this).parent().hide();
    $('#slsl-shadow').remove();
  });

  $('#open-schedule').bind('click', function () {
    addOverlayShadow();
    $('#adamari-schedule').show();
  });

  $('#mail-open').bind('click', function () {
    if ($('.mail-redemption').is(':visible')) {
      $('.mail-redemption').hide();
    } else {
      if ($('.online-redemption').is(':visible')) {
        $('.online-redemption').hide();
      }
      $('.mail-redemption').show();
      goToByScroll('mail-redemption');
      $('.clear-after, .page-footer.clear-after.centered-container, .clear-after.page-legal-footer').css('visibility', 'visible');
      if ($.browser.msie && $.browser.version === '7.0') {
        $('.clear-after').css('position', 'absolute');
        $('.clear-after').css('position', 'relative');
      }
    }
  });

  $('#online-open').bind('click', function () {
    if ($('.online-redemption').is(':visible')) {
      $('.online-redemption').hide();
    } else {
      if ($('.mail-redemption').is(':visible')) {
        $('.mail-redemption').hide();
      }
      $('.online-redemption').show();
      goToByScroll('online-redemption');
      $('.clear-after, .page-footer.clear-after.centered-container, .clear-after.page-legal-footer').css('visibility', 'visible');
      if ($.browser.msie && $.browser.version === '7.0') {
        $('.clear-after').css('position', 'absolute');
        $('.clear-after').css('position', 'relative');
      }
    }
  });

  if ($('#races').length > 0) {
    // fill in the races tabs
    var raceData = $.ajax({
      url: "/save-lids-save-lives/services/json/races/",
      success: function (data) {
        buildRacesTabs(data);
      },
      error: function () {
        log('an error occurred while building races tabs');
      }
    });
    if ($.browser.msie && $.browser.version === '7.0') {
      $('.clear-after').css('position', 'absolute');
      $('.clear-after').css('position', 'relative');
    }
  }

  $('#month-tab-0, #month-tab-1, #month-tab-2').live('click', function () {
    $('#month-tab-0, #month-tab-1, #month-tab-2').removeClass('active');
    $(this).addClass('active');
    $('.races-nav p').removeClass('pink');
    $('p', this).addClass('pink');
    var id = this.id.substring(10);
    $('table').hide();
    $('#month-' + id).show();
    if ($.browser.msie && $.browser.version === '7.0') {
      console.log('in this css thing');
      $('.page-content.centered-container.clear-after.full-height').css('visibility','visible');
    }
  });

	
	/* Start of onblur events which make client-side validation happen */
	// email (unknown user)
  $('#email').bind('blur', function () {
    log('entering email.bind()');
    if (!isEmail(this)) {
      log('not valid email');
      if ($(this).val() !== '') {
        setErrMsg(this, 'INVALID_FORMAT');
        $('[data-valid-for="email"]').show();
        //$(this).trigger('focus');
      }
    } else {
      log('valid email');
       $('#email').val($('#email').val().toLowerCase());
      $('[data-valid-for="email"]').hide();
    }
  });

  $('#email-confirm').bind('blur', function () {
    log('entering email-confirm.bind');
    if (!isEmail(this)) {
      if ($(this).val() !== '') {
        setErrMsg(this,'INVALID_FORMAT');
        $('[data-valid-for="email-confirm"]').show();
        //$(this).trigger('focus');
      }
    } else if (!emailsMatch(this, $('#email')[0])) {
      setErrMsg(this, 'NO_MACTH');
      $('[data-valid-for="email-confirm"]').show();
    } else {
      $('#email').val($('#email').val().toLowerCase());
      $('[data-valid-for="email-confirm"]').hide();
    }
  });

  // lid codes
  $('.lid-code').live('blur', function () {
    if (!lidCodeIsValid(this)) {
      if ($(this).val() !== '') {
        setErrMsg(this, 'INVALID_LID_CODE');
        $('[data-valid-for="' + this.id + '"]').show();
        // prevent losing focus
        //$(this).trigger('focus');
      } else {
        $('[data-valid-for="' + this.id + '"]').hide();
      }
    } else {
      // hide the thing
      $('[data-valid-for="' + this.id + '"]').hide();
    }
  });

  $('#zip-code').bind('blur', function () {
    if (isZip($(this)[0])) {
      $('[data-valid-for="zip-code"]').hide();
      // not validation logic, but putting here elminates a 2nd evt handler
    } else {
      setErrMsg(this,'INVALID_FORMAT');
      $('[data-valid-for="zip-code"]').show();
      //$(this).trigger('focus');
    }
  });

  $('#zip-code').bind('change', function(){
    if (/^\d{5}$/.test($(this).val())) {
      log('finding an affiliate');
      var zip = $('#zip-code').val();
      $.ajax({
        url: "/save-lids-save-lives/services/json/affiliates/",
        data: { "zip": zip },
        success: function (data) {
          if (data.data.length > 0) {
            $('#selected-affiliate').val(data.data[0].locationId);
          }
        },
        error: function () {
          window.log('an error on find-affil');
        }
      });
    } else {
        window.log('not looking up empty zip code');
    }
  });

  $('#promo-code').bind('blur', function() {
    if ($.trim($('#promo-code').val())!== '' && (!_.contains(promoCodes, $('#promo-code').val()))) {
      setErrMsg(this, 'INVALID_FORMAT');
      $('[data-valid-for="' + this.id + '"]').show();
      //$(this).trigger('focus');
    } else {
      $('[data-valid-for="' + this.id + '"]').hide();
    }
  });

  // the blur handlers for 2nd page
  $('#first-name').bind('blur', function () {
    log('in here, first-name');
    if ($(this).val() !== '') {
      $('[data-valid-for="first-name"]').hide();
    } else {
      setErrMsg(this,'INVALID_FORMAT');
      $('[data-valid-for="first-name"]').show();
      if ($.trim($(this).val())!=='') {
        //$(this).trigger('focus');
      }
    }
  })

  $('#city').bind('blur', function () {
    log('in here, city');
    if ($(this).val() !== '') {
      $('[data-valid-for="city"]').hide();
    } else {
      setErrMsg(this,'INVALID_FORMAT');
      $('[data-valid-for="city"]').show();
      if ($.trim($(this).val())!=='') {
        //$(this).trigger('focus');
      }
    }
  });

  $('#states').bind('blur', function () {
    log('in here, sttes');
    if ($('option:selected', this).index() > 0) {
      $('[data-valid-for="states"]').hide();
    } else {
      setErrMsg(this,'INVALID_FORMAT');
      $('[data-valid-for="states"]').show();
    }
  });

  $('#dedication').bind('blur', function () {
    if ($(this).val() !== '') {
      $('[data-valid-for="dedication"]').hide();
    } else {
      setErrMsg(this,'INVALID_FORMAT');
      $('[data-valid-for="dedication"]').show();
      if ($.trim($(this).val())!=='') {
        //$(this).trigger('focus');
      }
    }
  });
	/* end of the onblur handlers, which enable client-side validations */
	
	/* Form submits, these call the client-side validations */
  $('.unknown-user .submit-btn').bind('click', function (evt) {
    evt.preventDefault();
    log('inside unknown-user.click');
    if (unknownUserLoginIsValid()) {
      $('#form1').submit();
    }
  });
	
  //console.assert($.cookie('donor_age')!='0');
  //$('.dedicate-btn').bind('click', function (evt) {
  $('#add-dedication-btn, #dedicate-from-overlay').bind('click', function (evt) {
    evt.preventDefault();
    // close the overlay if it is open
    if ($.cookie('donor_age')=='0') {
      log('found a 0 cookie');
      $.cookie('donor_age', '', {  path: '/' })
    }
    if ($(this).data('disabled-age') !== 'true') {
			log('in here a');
      // check if they're cookied for age-verification, if not...
      var age = $.cookie('donor_age');
      if (typeof age !== 'undefined' && age !== null && age !== '' && (!isNaN(parseInt(age)))) {
				log('in here b');
				log('found age in cookie');
        // set the hidden
        $('#age').val(age);
				// if under 18 pop the age block and error message
				if (age < 18) {
					log('in here c');
					//show the age check
          if (this.id === 'dedicate-from-overlay') {
            $(this).parent().parent().hide();
          }
					$('#ageBlock').show();
					$('#ageErr').show();
					return false;
				}
      } else if ($('#ageCheck option:selected').index() > 1) {
				log('in here d');
        age = parseInt($('#ageCheck option:selected').val());
        if (isNaN(age)) {
					log('in here e');
          if (this.id === 'dedicate-from-overlay') {
            $(this).parent().parent().hide();
          }
          $('#ageBlock').show();
          return false;
        } else if (age < 18) {
					log('in here f');
          // the button SHOULD be disabled by here
          if (this.id === 'dedicate-from-overlay') {
            $(this).parent().parent().hide();
          }
					$('#ageBlock').show();
					$('#ageErr').show();
					return false;
          log('Underage dedication')
        } else {
					log('in here g');
          log('found valid age, setting hidden');
          if (age >= 18) {
						log('in here h');
						// set a cookie
						$('#age').val(age);
            $.cookie('donor_age', age, {  path: '/' });
          } else {
						log('in here i');
						log('not supposed to happen');
					}
        }
      } else {
				log('in here j');
          if (this.id === 'dedicate-from-overlay') {
            $(this).parent().parent().hide();
          }
        $('#ageBlock').show();
        return false;
      }
      var isValid = stepOneIsValid(this);
      if (isValid) {
        // spotlight for the Dedicate button on 1st step
        spotlight('yopsl958');
				log('in here k');
        //if the "you didnt dedicate, do you want to" is open, close it
        $('#add-dedication').val('true');
        $('#step-1').hide();
        $('#step-2').show();
        $('.clear-after, .page-footer.clear-after.centered-container, .clear-after.page-legal-footer').css('visibility', 'visible');
        window.scrollTo(0, 0);
      }
    }
  });
	
  $('.dedicate-form .submit-btn').bind('click', function (evt) {
    evt.preventDefault();
    var isValid = stepTwoIsValid();
    if (isValid) {
      // submitting the actual dedication
      $('#submit-with-ded').bind('click',function () {spotlight('yopsl552');});
      $('#form1').submit();
    }
  });

	// calls stepOneIsValid()
  $('#no-dedicate').bind('click', function (evt) {
    evt.preventDefault();
    // check if they want to never dedicate, set cookie
    if ($('#dont-show-again:checked').length > 0) {
      $.cookie('dont_show_again', 'true', { expires: 120 });
    }
    if (stepOneIsValid(this)) {
      $('#spinner').show();
      // spotlight tags for the Submit Lids link on 1st step
      spotlight('yopsl814');
      document.forms[0].submit();
    } else {
      $(this).parent().parent().hide();
      $('#slsl-shadow').remove();
    }
  });

  // server-side validation handling (this needs to be here, so lid rows are built b4 popping err msgs
  if ((typeof validationResult) !== 'undefined' && !validationResult.status) {
    log('there was a server-side validation failure');
    // because all error bubbles use data-valid-for attr matching the field name, this works
    log(validationResult.errors);
    for (var ii = 0; ii < validationResult.errors.length; ii++) {
      log(validationResult.errors[ii].field);
      var html = getServerErrText(validationResult.errors[ii]);
      log(html);
      $('[data-valid-for="' + validationResult.errors[ii].field + '"] .inner').html(html);
      $('[data-valid-for="' + validationResult.errors[ii].field + '"]').show();
    }
  }

  /*****
   * spotlight tagging
   *
   * Note: there are also some spotlight() calls in other places, namely anywhere we need to first validate
   * a form before we can fire the spotlight() call.
   */

  // for the login button on UnknownUser page
  $('#continue-unknown').bind('click', function () {spotlight('yopsl681');});
  // for the same button on ReturningUser page
  $('#continue-returning').bind('click', function () {spotlight('yopsl681');});
  // clicking join link in races schedule
  $('#races td.link a').bind('click',function () {spotlight('yopsl383');});
  // yoplait header
  $('img [src="yoplait-logo.png"]').bind('click',function () {spotlight('yopsl981');});
  // twitter click spotlight
  $('.tat a').bind('click', function () {spotlight('yopsl890');});
  // facbook click spotlight
  $('.fb a').bind('click', function () {spotlight('yopsl567');});
  // products item in nav
  $('#navProducts').bind('click', function () {spotlight('yopsl619');});
  // living healthy nav item
  $('#navLivingHealthy').bind('click', function () {spotlight('yopsl892');});
  // doing good nav item
  $('#navDoingGood').bind('click', function () {spotlight('yopsl865');});
  // recipes menu item
  $('#navRecipes').bind('click', function () {spotlight('yopsl137');});
  // new at yoplait nav item
  $('#navNewAtYoplait').bind('click', function () {spotlight('yopsl634');});
});

function goToByScroll(cls) {
	$('html,body').animate({ scrollTop: $("." + cls).offset().top }, 'slow');
}

/* functions for building form(s) for entering lid codes */
function buildLidCodesRow(start) {
  if (typeof quota !== 'undefined' && quota !== null && quota !== '' && quota !== 0) {
    var numPrinted = quota;
    var row = Array();
    //log('start is: ' + start);
    if (typeof start === 'undefined' || start === null) {
      var start = 0;
    }
    for (var ii = 0; start < quota && ii < 5; ii++, start++) {
      var lidCode = $('#lidCodeTmpl').tmpl({ "ordinal": start, "label": start+1 });
      if (start > 9) {
        lidCode.addClass('two-digit');
      }
      //workaround for shoddy outerHTML support
      row.push($(lidCode[0]).clone().wrap('<div></div>').parent().html());
    }
    $('.lid-codes-form').append(row.join(''));
  } else if (quota === 0) {
      // print out a message
      $('this').html(limitReached);
  }
}

function buildRacesTabs(data) {
  var data = data.data;
  var today = new Date();
  var threeMonthsAhead = today.getTime() + 7889231490;

  //remove entries with date before today's date, and more than 3 months into the future
  var data = _.reject(data, function (item) {
    var dt = new Date(item.date);
    if (dt.getTime() < today.getTime()) {
      return true;
    } else if (dt.getTime() > threeMonthsAhead) { // today + 3month
      return true;
    } else {
      return false;
    }
  });

  var month = null;
  var groupedData = _.groupBy(data, function (item) {
    var asDate = new Date(item.date);
    return asDate.getMonth();
  })

  firstKey = _.keys(groupedData)[0];
  var mm = [getMonthName(firstKey++), getMonthName(firstKey++), getMonthName(firstKey)];
    
  // set the tabs
  $('#racesTabs').tmpl({
    month1: mm[0], 
    month2: mm[1], 
    month3: mm[2]}).appendTo('#races');

  for (var ii=0;ii<_.keys(groupedData).length;ii++) {
    var key = _.keys(groupedData)[ii];
    var dates = groupedData[key];
    month = $('<table cellpadding="15" cellspacing="15"><thead></thead><tbody></tbody></table>')
      .attr('id', 'month-' + ii)
      .addClass('striped');
    if (ii > 0) {
      month.attr('style', 'display: none'); // hide the 2nd and 3rd months
    }
    _.each(dates, function (race, idx) {
      log(idx);
      var placeName = race.city + ',' + race.state;

      var row = $('#raceEntryTmpl').tmpl({
        date: race.date,
        place: placeName,
        title: race.affiliateName,
        link: race.url
      });
      $('tbody', month).append(row);
    });
    $('#races').append(month);
  }
}

function getMonthName(num) {
  var months = {
    0: 'January',
    1: 'February',
    2: 'March',
    3: 'April',
    4: 'May',
    5: 'June',
    6: 'July',
    7: 'August',
    8: 'September',
    9: 'October',
    10: 'November',
    11: 'December'
  }
  return months[num];
}

function addOverlayShadow() {
  if (!($.browser.msie && $.browser.version === '7.0')) {
    var shadowDiv = $('##705');
    if (shadowDiv.length === 0) {
      shadowDiv = $('<div id="slsl-shadow"></div>').appendTo('.page-content');
    }
    $(shadowDiv).css({
      'background-image': 'url(/ui/img/slsl/shadow.png)',
      'position': 'fixed',
      'left': 0,
      'top': 0,
      'width': '100%',
      'height': '100%',
      'z-index': 450
    });
  }
}

function lidCodeIsValid(elem) {
	var retval = false;
	$(elem).val($(elem).val().toUpperCase());
	$.ajax({
		async: false,
		url: '/save-lids-save-lives/services/json/validate-lid-code/',
		data: {'lidCode': $(elem).val()},
		success: function (data) {
			if (data.errors.length === 0) {
				retval = true;
			}
		},
		error: function() {
			log('this fails');
		}
	});
	return retval;
}

function isEmail(elem) {		
    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($(elem).val())
}

function emailsMatch(elem1, elem2) {
  var elem1 = $(elem1).val().toLowerCase();
  var elem2 = $(elem2).val().toLowerCase();
	return (elem1 === elem2);
}

function isZip(elem) {
	return /^\d{5}$/.test($(elem).val());
}

function unknownUserLoginIsValid() {
	log('inside unknownUserLoginIsValid()');
	var isValid = false;
	if (isEmail($('#email')[0]) && isEmail($('#email-confirm')[0]) && emailsMatch($('#email')[0],$('#email-confirm')[0])) {
		isValid = true;
	}
	if (!isEmail($('#email')[0])) {
    setErrMsg($('#email')[0], 'INVALID_FORMAT');
		$('[data-valid-for="email"]').show();
	}
	if (!isEmail($('#email-confirm')[0])) {
    setErrMsg($('#email-confirm')[0],'INVALID_FORMAT');
		$('[data-valid-for="email-confirm"]').show();
	} else if (!emailsMatch($('#email')[0],$('#email-confirm')[0])) {
    setErrMsg($('#email-confirm')[0],'NO_MACTH');
		$('[data-valid-for="email-confirm"]').show();
	}
	return isValid;
}

// step-1 (call on button click)
function stepOneIsValid(elem) {
  log(elem);
    // check at least one lid code
    var filledInCodes = $('.lid-code').filter(function () {
        if ($.trim($(this).val()) !== '') {
            return true; //just returning true for the filter() func, NOT validity
        }
    })
    if (filledInCodes.length < 1) {
			log('condition one');
        // show a lid-code bubble with diff message
        //$('[data-valid-for="lid-0"] .inner').html(validationMsgs.atLeastOneCode.baseMsg);
        setErrMsg($('#lid-0')[0],'INVALID_LID_CODE');
        $('[data-valid-for="lid-0"]').show();
	    return false;
	}
	// check all lid codes
	$.each(filledInCodes, function () {
		if (!lidCodeIsValid(this)) {
      setErrMsg(this,'INVALID_LID_CODE');
			log('found a non-empty lid code which did not validate');
		    return false;
		}
	});
	// check zipcode
	if (!isZip($('#zip-code')[0])) {
		log('condition zippy');
    setErrMsg($('#zip-code')[0], 'INVALID_FORMAT');
		$('[data-valid-for="zip-code"]').show();
	  return false;
	}
  if ($.trim($('#promo-code').val())!== '' && (!_.contains(promoCodes, $('#promo-code').val()))) {
		log('invalid because invalid promo code');
    setErrMsg($('#promo-code')[0], 'INVALID_FORMAT');
		$('[data-valid-for="promo-code"]').show();
		return false;
  }
	//if ($('#selected-affiliate').val()==='') {
		//log('invalid because no affiliate selected');
    //setErrMsg($('#zip-code')[0], 'INVALID_FORMAT');
		//$('[data-valid-for="zip-code"]').show();
		//return false;
	//}
	// check age if dedicate
	if (elem.id === 'add-dedication-btn') {
		if ($('#age').val() < 18) {
      // SHOW THE AGE BLOCK HERE?
      $('#ageBlock').show()
      setErrMsg($('#age')[0],'TOO_YOUNG');
			log('returning false because of age');
			return false;
		}
	}
	return true;
}

function stepTwoIsValid() {
	var isValid = false;
	if ($('#first-name').val()!=='' && $('#city').val()!=='' 
			&& $.trim($('#dedication').val())!=='' && $('#states option:selected').index() > 0 
			&& $('#agree:checked').length > 0) {
		isValid = true;
	}
	if ($('#first-name').val()==='') {
    setErrMsg($('#first-name')[0],'INVALID_FORMAT');
		$('[data-valid-for="first-name"]').show();
	} else {
		$('[data-valid-for="first-name"]').hide();
	}
	if ($('#city').val()==='') {
    setErrMsg($('#city'),'INVALID_FORMAT');
		$('[data-valid-for="city"]').show();
	} else {
		$('[data-valid-for="city"]').hide();
	}
	if ($('#states option:selected').index() < 1) {
    setErrMsg($('#states')[0],'INVALID_FORMAT');
		$('[data-valid-for="states"]').show();
	} else {
		$('[data-valid-for="states"]').hide();
	} 
	if ($.trim($('#dedication').val())==='') {
    setErrMsg($('#dedication')[0],'INVALID_FORMAT');
		$('[data-valid-for="dedication"]').show();
	} else {
		$('[data-valid-for="dedication"]').hide();
	}
	if ($('#agree:checked').length < 1) {
    // this one doesn't fit into the scheme so nicely, don't call setErrMsg(), just show it.
		$('[data-valid-for="agree"]').show();
	} else {
		$('[data-valid-for="agree"]').hide();
	}
  return isValid;
}

function setErrMsg(elem, code) {
  $.template('myTemplate', validationMsgs[code].baseMsg);
  var msg = $.tmpl('myTemplate', { field: validationMsgs[code][elem.id] });
  // check length and add line breaks
  var fixedText = $(msg).text();
  if (fixedText.length > 60) {
    for (var ii = 0; ii < fixedText.length; ii++) {
      if (ii % 40 === 0 && ii !== 0) {
        fixedText = fixedText.substring(0, ii) + '<br/>' + fixedText.substring(ii);
      }
    }
  }
  $('[data-valid-for="'+elem.id+'"] .inner').html(fixedText);
}

function getServerErrText(err) {
  log('entering getServerErrText: ');
  log(err);
  $.template('myTemplate', validationMsgs[err.code].baseMsg);
  var retval = $.tmpl('myTemplate', { field: validationMsgs[err.code][err.field] });
  // check length and add line breaks
  var fixedText = retval[0].innerText;
  for (var ii = 0; ii < fixedText.length; ii++) {
    if (ii % 40 === 0 && ii !== 0) {
      fixedText = fixedText.substring(0, ii) + '<br/>' + fixedText.substring(ii);
    }
  }
  $(retval[0]).html(fixedText);
  return retval;
}
