$.id = function(x){ return document.getElementById(x); };
function pngFix(){};
function embedVideo(){
	swfobject.embedSWF("/resources/suavePlayer.swf", "myContent", "640", "388", "9.0.0");
}
(function(slice){
Function.prototype.bind = function(){
	var method = this, args = slice.call(arguments), src = args.shift();
  return function() {
		return method.apply(src, args.concat(slice.call(arguments)));
	};
};
})([].slice);

// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License

$.fx.step["backgroundColor"] = function(fx){
	if (fx.state === 0) {
		fx.start = $.getColor(fx.elem, "backgroundColor");
		fx.end = $.getRGB(fx.end);
	}
	var rgb = [], M = Math;
	for (var i = 0; i < 3; i++) {
		rgb.push(M.max(M.min(parseInt((fx.pos * (fx.end[i] - fx.start[i])) + fx.start[i], 10), 255), 0));
	}
	fx.elem.style["backgroundColor"] = "rgb(" + rgb.join(",") + ")";
};

if ($.validator)
	$.validator.messages.required = "This is a required field.";

$.extend({
	getRGB : function(color){
		var result;
		if (color && color.constructor == Array && color.length == 3)
			return color;
		if ((result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)))
			return [parseInt(result[1], 10), parseInt(result[2], 10), parseInt(result[3], 10)];
		if ((result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color)))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
		if ((result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
		if ((result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
	},
	
	getColor : function(elem, attr){
		var color;
		do {
			color = $.curCSS(elem, attr);
			if (color !== '' && color != 'transparent' || $.nodeName(elem, "body"))
				break; 
			attr = "backgroundColor";
		} while ((elem = elem.parentNode));
		return $.getRGB(color);
	},
	
	classes : {},
	
	classify : function(name, object, parent){
		function klass(){	
			this.init.apply(this, arguments);
		}
		if (parent && $.classes[parent]) {
			function subklass(){};
			subklass.prototype = $.classes[parent].prototype;
			klass.prototype = new subklass;
		}
		for (var y in object)
			klass.prototype[y] = object[y];
		if (!klass.prototype.init)
			klass.prototype.init = function(){};
		klass.prototype.constructor = klass;
		$.classes[name] = klass;
		$.fn[name] = function(){
			return this.each(function(i, element){
				element.classBehaviors = element.classBehaviors || {};
				if (element.classBehaviors[name]) return;
				function behavior(){};
				function klassBehavior(){
					this.element = element;
					this.init.apply(this, arguments);
					for (var attr in this) {
						if (attr.indexOf("on") === 0) {
							var handler = attr.substr(2);
							if ($.fn[handler])
								$(this.element)[handler](this[attr].bind(this));
						}
					}
				}
				behavior.prototype = $.classes[name].prototype;
				klassBehavior.prototype = new behavior;
				element.classBehaviors[name] = new klassBehavior();
				return element.classBehaviors[name];
			});
		};
		return klass;
	}
});

$.classify("dhtmlmenu", {
	
	hide_timeout : null,
	last_menu    : null,
	hide_time    : 300,
	hover_class  : "Hover",
	
	init : function(){
		this.submenus = {};
		this.menus = $(">li", this.element);
		this.menus.each(function(i, menu){
			$(menu).hover(this.mouseOverHandler.bind(this, menu), this.mouseOutHandler.bind(this, menu));
		}.bind(this));
	},
	
	mouseOverHandler : function(menu, e){
		clearTimeout(this.hide_timeout);
		this.showMenu(menu);
	},
	
	mouseOutHandler : function(menu, e){
		clearTimeout(this.hide_timeout);
		this.hide_timeout = setTimeout(this.hideMenu.bind(this, menu), this.hide_time);
	},
	
	showMenu : function(menu){
		if (this.last_menu !== null)
			this.hideMenu(this.last_menu);
		$(menu).addClass(this.hover_class);
		this.last_menu = menu;
	},
	
	hideMenu : function(menu){
		$(menu).removeClass(this.hover_class);
		this.last_menu = null;
	}
	
});

$.classify("dhtmlmenunew", {

	show_time : 150,
	hide_time    : 300,
	hover_class  : "Hover",
	visible : false,
	last_menu : null,
	submenus : {},
	menu_alignments : {},
	menu_offsets : {},
	submenu_widths : {},
	submenu_heights : {},
	
	init : function(){
		this.menus = $(">li", this.element);
		$("<li class='dhtml-menu'><div class='dhtml-viewport'><div class='dhtml-window'><div class='dhtml-wrapper'></div></div></div></li>").appendTo(this.element)[0];
		this.viewport = $(".dhtml-viewport", this.element)[0];
		this.wrapper = $(".dhtml-wrapper", this.element)[0];
		var fromTop = 0;
		this.menus.each(function(i, menu){
			$(menu).hover(this.mouseOverHandler.bind(this, menu), this.mouseOutHandler.bind(this, menu));
			var id = menu.id;
			var sub = this.submenus[id] = $(".Menu", menu)[0];
			if (!sub) return;
			$(sub).hover(this.mouseOverHandler.bind(this, menu), this.mouseOverHandler.bind(this, menu));
			this.menu_alignments[id] = menu.offsetLeft;
			this.wrapper.appendChild(sub);
			var height = $(sub).height();
			this.submenu_widths[id] = $(sub).width();
			this.submenu_heights[id] = height;
			this.menu_offsets[id] = fromTop;
			fromTop += (height + 1);
		}.bind(this));
		this.toggleViewport(false);
	},
	
	mouseOverHandler : function(menu, e){
		clearTimeout(this.hide_timeout);
		clearTimeout(this.show_timeout);
		this.show_timeout = setTimeout(this.activateMenu.bind(this, menu), this.show_time);
	},
	
	mouseOutHandler : function(menu, e){
		clearTimeout(this.hide_timeout);
		clearTimeout(this.show_timeout);
		this.hide_timeout = setTimeout(this.toggleVisibility.bind(this, false), this.hide_time);
	},
	
	activateMenu : function(menu){
		if (this.last_menu)
			this.hideMenu(this.last_menu);
		$(menu).addClass(this.hover_class);
		if (!this.visible)
			this.toggleVisibility(true);
		this.last_menu = menu;
		if (this.all_hidden) {
			$(this.viewport).css({ left : this.menu_alignments[menu.id], height : this.submenu_heights[menu.id], width : this.submenu_widths[menu.id] });
			$(this.wrapper).css({ left : this.menu_alignments[menu.id] });
			this.all_hidden = false;
		} else {
			$(this.viewport).animate({ left : this.menu_alignments[menu.id], height : this.submenu_heights[menu.id], width : this.submenu_widths[menu.id] }, 120);
			$(this.wrapper).animate({ marginTop : "-"+this.menu_offsets[menu.id]+"px" }, 120);
		}
	},
	
	toggleVisibility : function(visible){
		this.visible = visible;
		$(this.viewport).animate({ opacity : visible ? 1 : 0 }, 250, this.toggleViewport.bind(this, visible));
		if (!visible && this.last_menu)
			this.hideMenu(this.last_menu);
	},
	
	toggleViewport : function(visible){
		$(this.viewport).css({ display : visible ? "block" : "none" });
		if (!visible)
			this.all_hidden = true;
	},
	
	hideMenu : function(menu){
		$(menu).removeClass(this.hover_class);
		this.last_menu = null;
	}
	
});

$.classify("carousel", {
	
	index : 0,
	dots : [],
	active_carousel : "Activated",
	active_item : "Active",
	current_dot : "CurrentDot",
	dot_width : 17,
	dot_align : 470,
	item_width : 843,
	scrolling : false,
	item_class : "CarouselItems",
	item_tag : "ul",
	
	init : function(){
		this.wrapper = $("." + this.item_class, this.element)[0];
		if (!this.wrapper) return;
		this.items = $(this.item_tag, this.wrapper);
		if (this.items.length > 1) {
		  $(this.element).addClass(this.active_carousel);
  		this.right = $("<div id='carousel-right'></div>").appendTo(this.element);
  		this.left = $("<div id='carousel-left'></div>").appendTo(this.element);
		  $(this.right).click(this.calculateIndex.bind(this, 1));
  		$(this.left).click(this.calculateIndex.bind(this, -1));
  		this.total = this.items.length * this.item_width;
  		$(this.wrapper).css({ width : this.total + "px" });
  		this.initDotNavigation();
  		window["currentCarousel"] = this;
		}
	},
	
	calculateIndex : function(change){
		if (this.scrolling) return;
		var index = this.index + change;
		if (index >= this.items.length)
			index = 0;
		else if (index < 0)
			index = this.items.length - 1;
		this.scrollCarousel(index);
		this.setCurrentDot();
	},
	
	initDotNavigation : function(){
		this.dots = [];
		this.dot_wrapper = $("<div id='dot-navigation'></div>").appendTo(this.element);
		for (var i = 0, item, dot; item = this.items[i]; i++) {
			dot = $("<div class='Dot'></div>").appendTo(this.dot_wrapper);
			$(dot).click(this.dotClickHandler.bind(this, i));
			this.dots.push(dot[0]);
		}
		var width = (this.dot_width * this.dots.length);
		$(this.dot_wrapper).css({ left : (this.dot_align - (width / 2)) + "px" });
		this.setCurrentDot();
	},
	
	dotClickHandler : function(index){
		if (this.scrolling) return;
		this.scrollCarousel(index);
		this.setCurrentDot();
	},
	
	setCurrentDot : function(){
		if (this.active_dot)
			$(this.active_dot).removeClass(this.current_dot);
		this.active_dot = this.dots[this.index];
		$(this.active_dot).addClass(this.current_dot);
	},
	
	scrollCarousel : function(index){
		if (index === this.index || this.scrolling) return;
		this.scrolling = true;
		var diff = Math.abs(this.index - index);
		this.index = index;
		$(this.wrapper).animate({
			left :  "-" + (this.index * this.item_width) + "px"
		}, diff * 600, function(){
			this.scrolling = false;
		}.bind(this));
	},
	
	scrollOutOfSight : function(){
		$(this.wrapper).animate({
			left  : "-"+(this.item_width * this.items.length)+"px"
		}, 750);
	},
	
	scrollIntoSight : function(){
		$(this.wrapper).css({ left : this.total + "px" });
		$(this.wrapper).animate({
			left : "0px"
		}, 750);
	}
	
});

$.classify("productCarousel", {
	item_width : 696,
	dot_align : 350
}, "carousel");

$.classify("search", {
	
	text : "Search",
	active_class : "Searching",
	hovering : false,
	
	init : function(search) {
		this.query = $(".TextInput", this.element)[0];
		this.help = $(".Help", this.element)[0];
		if (!this.query || !this.help) return;
		$(this.element).hover(this.focusHandler.bind(this), this.blurHandler.bind(this));
		if ($.trim(this.query.value).length === 0)
			this.query.value = this.text;
	},
	
	focusHandler : function(){
		this.query.focus();
		$(this.element).addClass(this.active_class);
		$(this.help).fadeIn(200);
		if (this.query.value === this.text)
			this.query.value = "";
	},
	
	blurHandler : function(e){
		$(this.element).removeClass(this.active_class);
		$(this.help).fadeOut(150);
		if ($.trim(this.query.value).length === 0)
			this.query.value = this.text;
	}
	
});

$.classify("pageloader", {
	
	hashes : {},
	loaded_pages : {},
	current_link : "",
	
	init : function(){
		if ($.browser.msie) return;
		if (typeof $.fn.ask_the_professionals === "function") return;
		this.findLiveLinksIn(this.element);
		this.wrapper = $.id("wrapper");
		this.wrapper_class = this.wrapper.className;
		$("<div id='stage-wrapper'><div id='stage'></div></div>").appendTo(this.element);
		this.stage = $.id("stage");
		this.slug = this.sliceHashFromHref(document.location.href);
		setInterval(this.pollCurrentHash.bind(this), 500);
		var hash = document.location.hash.substring(1);
		if (hash.length > 0)
			document.location = hash;
	},
	
	pollCurrentHash : function(){
		var hash = document.location.hash.substring(1);
		if (!this.loading && hash.length > 0 && hash !== this.slug)
			this.checkForPage(this.sliceHashFromHref(hash));
	},

    parseUri: function(str) {

    	var	o   = {
            	strictMode: false,
            	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
            	q:   {
            		name:   "queryKey",
            		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
            	},
            	parser: {
            		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
            		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
            	}
            },
    		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
    		uri = {},
    		i   = 14;
    
    	while (i--) uri[o.key[i]] = m[i] || "";
    
    	uri[o.q.name] = {};
    	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
    		if ($1) uri[o.q.name][$1] = $2;
    	});
    
    	return uri;

    },

	
	sliceHashFromHref : function(href){

        var last = this.parseUri(href).path;

		return last.split("#")[0];
	},
	
	findLiveLinksIn : function(scope){
		var host = document.location.host;
		$("a", scope).each(function(i, link){
			if (!link.scannedByPageLoader && !link.className.match("NoTransition")) {
				link.scannedByPageLoader = true;
				if (link.href && link.href.indexOf(host) > -1 && !link.href.indexOf("asktheprofessionals") > -1) {
					$(link).click(this.liveLinkClickHandler.bind(this, link.href));
				}
			}
		}.bind(this));
	},
	
	liveLinkClickHandler : function(href, e){
        if (!(e && e.currentTarget && e.currentTarget.target == '_blank')) {
    		e.preventDefault();
    		if (this.loading || this.current_link === href) return;
    		this.loading = true;
    		this.checkForPage(href);            
        }
	},
	
	checkForPage : function(href){
		if (this.loaded_pages[href])
			this.startTransition(this.loaded_pages[href]);
		else
			this.fetchPage(href);
		document.location.hash = this.slug = this.sliceHashFromHref(href);
	},
	
	fetchPage : function(href){
		$.ajax({
			url : href,
			success : this.successHandler.bind(this, href),
			error : this.errorHandler.bind(this, href)
		});
	},
	
	successHandler : function(href, html){
		this.loaded_pages[href] = html;
		this.startTransition(html);
	},
	
	errorHandler : function(href){
		document.location = href;
	},
	
	startTransition : function(html){
		this.prior_class = this.wrapper_class;
		var matching_classes = html.match(/wrapper(?:.*)?class="(\w+)(?:.*)?\>/);
		if (matching_classes && matching_classes[1]) {
		  this.wrapper_class = matching_classes[1];
		  this.swapOutMarkup(html);
		}
	},
	
	swapOutMarkup : function(html){
		$(this.stage).css({ opacity : 0 });
		this.stage.innerHTML = html;
		this.fadeElementsOut(html);
		initPageBehaviors();
		setTimeout(this.fadeElementsIn.bind(this), 1000);
	},
	
	fadeElementsOut : function(html){
		if (window.currentCarousel) {
			setTimeout(currentCarousel.scrollOutOfSight.bind(currentCarousel), 250);
			$(">div:first-child", currentCarousel.element).animate({ opacity : 0 }, 750);
		}
		if ($(".Carousel", html).length < 1) {
			setTimeout(function(){ $(".Carousel").animate({ opacity : 0 }, 750); }.bind(this), 350);
			setTimeout(function(){ $(".Twitter").animate({ opacity : 0 }, 750); }.bind(this), 350);
		}
		setTimeout(function(){ $(".Landing", this.wrapper).animate({ opacity : 0 }, 750); }.bind(this), 350);
		if (this.prior_class !== this.wrapper_class)
			setTimeout(function(){ $(".Layout", this.wrapper).animate({ opacity : 0 }, 750); }.bind(this), 550);
	},
	
	fadeElementsIn : function(){
		initPageBehaviors();
		$(this.stage).animate({ opacity : 1 }, 750, this.finishFading.bind(this));
		$(".CarouselItems", this.stage).css({ opacity : 0 });
		$(".Carousel", this.wrapper).empty();
		if (this.prior_class !== this.wrapper_class)
			$(".Layout", this.stage).css({ opacity : 0 });
	},
	
	finishFading : function(){
		this.wrapper.className = this.wrapper_class;
		this.wrapper.innerHTML = $("div", this.stage)[0].innerHTML;
		$(".CarouselItems", this.wrapper).css({ opacity : 0.5 }).animate({ opacity : 1 }, 400);
		$(".Landing", this.wrapper).animate({ opacity : 1 }, 1000);
		$(".Layout", this.wrapper).animate({ opacity : 1 }, 1000);
		initPageBehaviors();
		if (window.currentCarousel)
			currentCarousel.scrollIntoSight();
		this.findLiveLinksIn(this.element);
		this.loading = false;
		this.stage.innerHTML = "";
		$(".DHTMLMenu").dhtmlmenu();
		$(".ScrollingContent").scrollingContent();
		$(".ResultsColumn").searchScrollingContent();
		$(".Slideshow").slideshow();
	}
	
});

$.classify("scrollingContent", {
	
	current_scroll : 0,
	height : 320,
	increment : 200,
	arrows : "<hr/><div class='scroll-down'></div><div class='scroll-up'></div>",
	extra_styles : "",
	
	init : function(){
	//	if ($.browser.msie && $.browser.version < 7) return;
		var el = $(this.element);
		this.el_height = el.height();
		this.total_height = this.el_height - this.height + 20;
		if (this.total_height < 0) return;
		el.wrap("<div style='height:"+this.height+"px;width:100%;overflow:hidden;position:relative;" + this.extra_styles + "' />");
		el.css({ position : "absolute", top : "0", left : "0" });
		var parent = this.element.parentNode.parentNode;
		$(this.arrows).appendTo(parent);
		$("<div class='scrollbar'></div>").appendTo(this.element.parentNode);
		this.bar = $(".scrollbar", parent);
		this.bar.css({ display : "block", opacity : 0, height : ((this.height / this.el_height * this.height) + "px") });
		this.up = $(".scroll-up", parent);
		this.down = $(".scroll-down", parent);
		this.up.click(this.scroll.bind(this, true));
		this.down.click(this.scroll.bind(this, false));
		this.toggleScrollingIcons();
	},
	
	scroll : function(up){
		if (this.current_scroll === 0 && up) return;
		var target = up ? (this.current_scroll - this.increment) : (this.current_scroll + this.increment);
		if (target < 0) target = 0;
		if (target > this.total_height) target = this.total_height;
		this.current_scroll = target;
		this.animateScrollIndicator();
		$(this.element).animate({ top : "-" + target + "px" });
		this.toggleScrollingIcons();
	},
	
	toggleScrollingIcons : function(){
		this.up[this.current_scroll === 0 ? "removeClass" : "addClass"]("Link");
		this.down[this.current_scroll === this.total_height ? "removeClass" : "addClass"]("Link");
	},
	
	animateScrollIndicator : function(){
		this.bar.animate({ opacity : 0.25, top : ((this.current_scroll / this.el_height) * this.height) + "px" }, 500);
		setTimeout(function(){
			this.bar.animate({ opacity : 0 }, 400);
		}.bind(this), 500);
	}
	
});

$.classify("searchScrollingContent", {
	height : 385,
	arrows : "<div class='scroll-down'></div><div class='scroll-up'></div>",
	extra_styles : "margin-bottom:1.5em;"
}, "scrollingContent");

$.classify("sparkles", {
	
	low_opacity : 0.05,
	high_opacity : 0.36,
	duration : 2500,
	
	init : function(){
		if ($.browser.msie) return;
		for (var i = 0; i < 3; ++i)
			$("<div id='sparkle-" + i + "' class='Sparkle'></div>").appendTo(this.element);
		this.initSparkleMovement();
	},
	
	initSparkleMovement : function(index){
		$(".Sparkle").each(function(i, sparkle){
			var s = $(sparkle);
			s.css({ opacity : 0, display : "block" });
			setTimeout(this.twinkleIn.bind(this, s), i * 1200);
		}.bind(this));
	},
	
	twinkleIn : function(s){
		s.animate({ opacity : this.high_opacity }, this.duration);
		setTimeout(this.twinkleOut.bind(this, s), this.duration * 1.2);
	},
	
	twinkleOut : function(s){
		s.animate({ opacity : this.low_opacity}, this.duration);
		setTimeout(this.twinkleIn.bind(this, s), this.duration * 1.2);
	}
	
});

$.classify("slideshowCarousel", {
	item_width: 635,
	item_class : "SlideshowList",
	item_tag : "li",
	dot_align : 328,
	
	scrollCarousel : function(index){
		if (index === this.index || this.scrolling) return;
		this.scrolling = true;
		var diff = Math.abs(this.index - index);
		this.index = index;
		$(this.element).animate({
			marginLeft :  "-" + (this.index * this.item_width) + "px"
		}, diff * 600, function(){
			this.scrolling = false;
		}.bind(this));
	}
}, "carousel");

$.classify("slideshow", {
	
	init : function(){
		this.images = $("img", this.element);
		$("<div class='SlideshowWrapper'><ul class='SlideshowList'></ul><div class='ClearFix'></div></div>").appendTo(this.element);
		this.slideshow = $(".SlideshowList", this.element);
		this.images.each(function(i, img){
			var li = document.createElement("li");
			li.appendChild(img);
			$(li).appendTo(this.slideshow);
		}.bind(this));
		$(".SlideshowWrapper").slideshowCarousel();
		$("p", this.element).remove();
	}
	
});

function initPageBehaviors(){
	$(".Carousel").carousel();
	$(".SearchForm").search();
	$(".ProductCarousel").productCarousel();
	$(".Sparkles").sparkles();
	
	     $('#ingredients_list').click(function() {
		$('#ingredient_pop_up2').hide();
$('#ingredient_pop_up').show();
  $('#overlay').fadeIn('slow');
});
   
      $('.popup_head').click(function() {
	$('#ingredient_pop_up').hide();
  $('#overlay').fadeOut('slow');
});
   

   $('#ingredients_list2').click(function() {
$('#ingredient_pop_up').hide();
	$('#ingredient_pop_up2').show();
  $('#overlay2').fadeIn('slow');
});
   
      $('.popup_head2').click(function() {
	$('#ingredient_pop_up2').hide();
  $('#overlay2').fadeOut('slow');
});
	  
	if ($.validator){
		$("#SubmitForm").click(function(e){
			validateForm(e);
		});
		$("#submit").click(function(e){
			testSearchField(e);
		});
	}
	if(document.location.href.match(/contact-us|index.php|register|atp-coupon|coupon-signup/)){
		$("a").each(function(){
			var newClass = this.getAttribute("class") + " NoTransition";
			this.setAttribute("class", newClass);
		})
	}
}

$(function(){
	initPageBehaviors();
	$("body").pageloader();
	$(".Slideshow").slideshow();
	$(".DHTMLMenu").dhtmlmenu();
	$(".ScrollingContent").scrollingContent();
	$(".ResultsColumn").searchScrollingContent();
	
});

function validateForm(e){
	var formIsValid = true;
	// check that a valid email address has been entered
	var emailRegExp = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/;
	if(!emailRegExp.test(String($("#edit-submitted-email-address").val()).toUpperCase())){
		addError("edit-submitted-email-address", "Please enter a valid email address.");
		formIsValid = false;
	} else {
		removeError("edit-submitted-email-address");
	}
	
	// check that first name has one or more characters
	if($("#edit-submitted-first-name").val().length<1){
		addError("edit-submitted-first-name", "This field is required.");
		formIsValid = false;
	} else {
		removeError("edit-submitted-first-name");
	}
	// check that last name has one or more characters
	if($("#edit-submitted-last-name").val().length<1){
			addError("edit-submitted-last-name", "This field is required.");
			formIsValid = false;
		} else {
			removeError("edit-submitted-last-name");
		}
	// check that address is...
	if($("#edit-submitted-address").val().length<1){
			addError("edit-submitted-address", "This field is required.");
			formIsValid = false;
		} else {
			removeError("edit-submitted-address");
		}
	// check that city name has one or more characters
	if($("#edit-submitted-city").val().length<1){
			addError("edit-submitted-city", "This field is required.");
			formIsValid = false;
		} else {
			removeError("edit-submitted-city");
		}
	// check that a state has been selected
	if($("#edit-submitted-state").val() == ""){
			addError("edit-submitted-state", "This field is required.");
			formIsValid = false;
		} else {
			removeError("edit-submitted-state");
		}
	// check that a valid zip code of 5-9 numbers is entered
	var zipRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	if(!zipRegExp.test($("#edit-submitted-zip-code").val())){
			addError("edit-submitted-zip-code", "Please enter a valid zip code.");
			formIsValid = false;
		} else {
			removeError("edit-submitted-zip-code");
		}
	// check that a valid day time phone number is entered
	var phoneRegExp = /^\(?[1-9]\d{2}\)?\s?\-?\.?\d{3}\s?\-?\.?\d{4}$/;
	if(!phoneRegExp.test($("#edit-submitted-daytime-phone-number").val())){
			addError("edit-submitted-daytime-phone-number", "Valid phone number required.");
			formIsValid = false;
		} else {
			removeError("edit-submitted-daytime-phone-number");
		}
	// check that a valid evening time phone number is entered
	if(!phoneRegExp.test($("#edit-submitted-evening-phone-number").val())){
			addError("edit-submitted-evening-phone-number", "Valid phone number required.");
			formIsValid = false;
		} else {
			removeError("edit-submitted-evening-phone-number");
		}
	// calculate users date and determine if they are 18 years old
	if($("#edit-submitted-birthday-month").val() == "" || $("#edit-submitted-birthday-day").val() == "" || $("#edit-submitted-birthday-year").val() == ""){
		addError("edit-submitted-birthday-month", "This field is required.");
		formIsValid = false;
	} else {
		var currentDate = new Date();
		var userAge = currentDate.getFullYear() - Number($("#edit-submitted-birthday-year").val());
		if(((currentDate.getMonth()+1) < Number($("#edit-submitted-birthday-month").val())) || (((currentDate.getMonth()+1) == Number($("#edit-submitted-birthday-month").val())) && (currentDate.getDate() < Number($("#edit-submitted-birthday-day").val())))) {
			// user hasn't had birthday - subtract one year from age
			userAge--;
		}
		if(userAge < 18 && currentDate.getFullYear()){
			// +++ display an error message that user is not 18 years old
			addError("edit-submitted-birthday-month", "You must be 18 years old.");
			formIsValid = false;
		} else {
			removeError("edit-submitted-birthday-month");
		}
	}
	if(!formIsValid) {
		e.preventDefault();
	}
}

function testElement(id, exp, msg) {
	if(!exp.test($("#"+id).val())){
		addError(id, msg);
		return false;
	} else {
		removeError(id);
		return true;
	}
}

function addError(id, msg) {
	if($("#"+id).parent().find("label[class=error]").attr("generated") == "true"){
		$("#"+id).parent().find("label[class=error]").css("display", "block");
	} else {
		$("#"+id).parent().append('<label for="'+id+'" generated="true" class="error">'+msg+'</label>').css("display", "block");
	}
}

function removeError(id) {
	$("#"+id).parent().find("label[class=error]").css("display", "none");
}

function testSearchField(e) {
	if($("#query").val().length<1) {
		e.preventDefault();
	} else {
		pageTracker._trackEvent('Search Form', 'Submit', $("#query").val());
	}
}