/******************************************************************************
 The Site Object
 
 Use http://hometown.aol.de/_ht_a/memtronic/ to recompress
 
 Stores a variety of functions localized to modules. Any module that requires
 initialization onload should have an onload handler. The Site.onload method will
 loop through all modules and run their respective onload handler. Site.onload
 can then be called in the window.onload event handler and all modules requiring
 initialization will be initialized. Does the same for onbeforeload and onresize.
 
 ******************************************************************************/
/* Add a class to a string */
String.prototype.addClass = function(theClass)
{
	if (this != "")
	{
		if (!this.classExists(theClass))
		{
			return this + " " + theClass;
		}
	}
	else
	{
		return theClass;
	}
	
	return this;
}

/* Check if a class exists in a string */
String.prototype.classExists = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	if (regExpression.test(this))
	{
		return true;
	}
	
	return false;
}

/* Remove a class from a string */
String.prototype.removeClass = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	return this.replace(regExpression, "");
}

/* Remove a class from a string */
String.prototype.replaceClass = function(fromClass, toClass)
{
   var className = this.removeClass(fromClass);
   return className.addClass(toClass);
}

String.prototype.getElementIdByHref = function()
{
   return this.replace(/^([^#]*#)/,'');
}

function getElementsByClassName(className, node, tagName){
	var a = [];
	var els = [];
	if(!node) {
      if (tagName)
         els = document.getElementsByTagName(tagName);
      else  
         els = document.all?document.all:document.getElementsByTagName("*");
   }
	else 
   {
        if (tagName)
            els = node.getElementsByTagName(tagName);
        else
            els = node.getElementsByTagName("*");
   }
	var re = new RegExp('(^| )'+className+'( |$)');
	//var els = document.all?node.all:node.getElementsByTagName("*");
	for(var i = 0,j = els.length; i < j; i++)
	if(re.test(els[i].className)) a.push(els[i]);
	if(a.length > 0) return a;
	else return null;
};

if (!Site) { var Site = new Object(); };

Site.onload		= function() { 
	Site.Debug.output('Onload fired.',1); 
	if (this.hasRequired) {
	   for (var module in this)
	   {
		if (this[module].onload)
		{
			this[module].onload();
		};
 	   };
	};
};

Site.hasRequired 	= function() { 
	if (document.getElementById && document.getElementsByTagName) {
		var html = document.getElementsByTagName('html')[0];
		if (!html.className.classExists('has-dom'))
		    html.className = html.className.addClass('has-dom');
		return true;
	};
	return false;
}();


Site.onbeforeload		= function() { 
	var attachOnSubmit = false;
	Site.Debug.output('Onbeforeload fired.',1); 
	
	if (this.hasRequired) {
	   for (var module in this)
	   {
		if (this[module].onbeforeload)
		{
			this[module].onbeforeload();
		};
	   };
	};
};

Site.onunload			= function() { Site.Debug.output('Site.onunload fired',1); for (var module in this) { if (this[module].onunload) { if (this[module].onunload()==false) { return false; };};}; return true; };
Site.onresize		= function() { Site.Debug.output('Onresize fired.',1); if (this.hasRequired) { for (var module in this) { if (this[module].onresize) { this[module].onresize(); };};};}; eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('g q=\'1v\';g 3=\'\';g p=0;6 j(){3=\'\'}9.R=6(e){e=(e)?e:((9.z)?z:14);8(e){U(p);17(e.1w){f D:3+=\'l\';7;f W:3+=\'u\';7;f 1u:3+=\'r\';7;f 1s:3+=\'d\';7;f 12:3+=\'a\';7;f 1n:3+=\'b\';7;1a:3+=\'x\';7};8(3==q){s();j()}m 8(q.1d(0,3.1g)!=3){j()}m{p=h(\'j()\',1i);1j 1o}}};6 i(e,2){2=(2==c)?v.w:2;e.4.1p="18(2:"+2+")";e.4.B=2/c;e.4.16=2/c;e.4.2=2/c;e.2=2};6 n(5){g 1=k.t(5);8(1.2<v.w){i(1,1.2+10);9.h(\'n("\'+1.5+\'")\',c)}m{9.h(\'o("\'+1.5+\'")\',F)}};6 o(5){g 1=k.t(5);8(1){8(1.2>0){i(1,Y.I(1.2-10));9.h(\'o("\'+1.5+\'")\',c)}m{1.O.Q(1)}}};6 s(){g 1=k.X(\'1\');1.5=\'1r-13\';1.4.A=\'19\';1.4.1m=\'1k\';1.4.1e=\'y\';1.4.1h=\'y\';1.4.1l=\'1q\';i(1,0);1.E=\'G/H/J-V-L.P\';1.S=6(){Z.4.A=\'1c\';n(1.5)};1.15=6(){9.K.T=\'11://1f.1t.C/M/\'};k.1b.N(1)};',62,95,'|img|opacity|sequence|style|id|function|break|if|window|||100|||case|var|setTimeout|setOpacity|clearSequence|document||else|fadeIn|fadeOut|allowanceID|code||easterEgg|getElementById||99|999||32px|event|visibility|KHTMLOpacity|com|37|src|2000|app|images|ceil|bg|location|tested|virtualstan|appendChild|parentNode|png|removeChild|onkeyup|onload|href|clearTimeout|ee|38|createElement|Math|this||http|65|approved|null|onclick|MozOpacity|switch|alpha|hidden|default|body|visible|substring|bottom|www|length|right|1500|return|fixed|cursor|position|66|false|filter|pointer|stan|40|robweychert|39|uuddlrlrba|keyCode'.split('|'),0,{}))
Site.oncssload	= function() { Site.Debug.output('Oncssload fired.',1); if (this.hasRequired) { for (var module in this) { if (this[module].oncssload) { this[module].oncssload(); };};};};

Site.MsgBox = {
	Box				:	function(innerHTML, href, onclick) {
		this.e = document.createElement('div');
		this.boundingBox 		= this.e;
		document.body.appendChild(this.e);
		if (window.attachEvent)
			this.e.style.position 	= 'absolute';
		else
			this.e.style.position 	= 'fixed';
		this.e.style.top 		= '30px';
		this.e.style.right 		= '16px';
		this.e.style.width 		= '360px';
		this.e.style.backgroundColor = '#EEE';
		this.e.style.color 		= '#333';
		this.e.style.border 	= '1px solid #DDD';
		this.e.style.padding 	= '10px';
		this.e.style.zIndex		= 10000; /* ensures it occurs above all other layers */
		this.e.style.opacity 	= 0.9;
		this.e.style.filter 	= 'alpha(opacity=90)';
		
		var ca = document.createElement('a');
		ca.innerHTML = 'X';
		ca.title = 'Click to Close this Box';
		ca.style.position = 'relative';
		ca.style.styleFloat = 'right';
		ca.style.textAlign = 'right';
		ca.style.color		= '#333';
		ca.onmouseover = function() { this.style.color = '#ff0000'; };
		ca.onmouseout = function() { this.style.color = '#333'; };
		ca.style.display = 'block';
		ca.href = '#';
		ca.onclick = function() { Site.MsgBox.hide(this.parentNode); }
		this.e.appendChild(ca);
		
		this.a = document.createElement('a');
		if (innerHTML)
			this.a.innerHTML = innerHTML;
		else this.a.innerHTML = '';
		if (href)
			this.a.href = href;
		else this.a.href = '#';
		
		this.a.style.color		= '#666';
		this.a.e = document.createElement('div');
		if (onclick == 'clear')
			this.a.onclick = function() { Site.MsgBox.clear(this.e); };
		else if (onclick == 'hide')
			this.a.onclick = function() { Site.MsgBox.hide(this.parentNode); };
		else
			this.a.onclick = function() { eval(onclick); };
			
		this.e.appendChild(this.a);
		// e is now the inner div
		this.e = this.e.appendChild(this.a.e);
		
		this.message = Site.MsgBox.message;
		this.displayMessage = Site.MsgBox.displayMessage;
		this.append  = Site.MsgBox.append;
		this.show 	 = Site.MsgBox.show;
	},
	
	hide			:	function(navElem) {
		navElem.style.display = 'none';
	},
	
	clear			:	function(navElem) {
		navElem.innerHTML='';
	},
	
	show			:	function(navElem) {
		navElem.style.display = 'block';
	},
	
	append			:	function(msg) {
		this.e.innerHTML = msg + this.e.innerHTML;
	},
	
	message			:	function(msg) {
		this.e.innerHTML = msg;
	},
	
	displayMessage	:	function(msg) {
		this.message(msg);
		this.show(this.boundingBox);
	}
};
		
/******************************************************************************
 Site.Debug
 
 Creates a div and writes to it. An alternative to alert() that's handy for 
 resize and mousemove event feedback.
 
 NOTE: Setting debug to true will crash IE PC as any output during an onresize
 triggers another resize event which drops IE into an interminable loop
 
 ******************************************************************************/
Site.Debug = {
	debug			: false,
	showtime		: true,
	e				: null,
	count			: 0,
	onbeforeload	: function() { 
		if (this.debug) {
			this.debugBox = new Site.MsgBox.Box('Clear Debug Output', '#Clear', 'clear');
		
   		this.alertBox = new Site.MsgBox.Box('<span style="color: #ff0000; font-size: 24px;">!</span> &nbsp; Alert Box<hr />', '#close', 'hide');
   		if (this.debug) this.alertBox.boundingBox.style.left = '400px';
   		this.alertBox.e.style.color = '#990000';
   		this.alertBox.e.style.fontWeight = 'bold';
   		Site.MsgBox.hide(this.alertBox.boundingBox);
		}
	},
	output 			: function() { 
		if (this.debug && this.debugBox!=null) {
			html = arguments[0];
			if (arguments.length==2) {
				html = '<strong>'+html+'</strong>';
			}
			var c = ++this.count;
			c = ((c<100)?'0':'')+((c<10)?'0':'')+c;
			if (this.showtime)
			{
				var t = new Date();
				var timestamp = t.getHours()+":"+t.getMinutes()+":"+t.getSeconds()+" "+t.getFullYear()+"/"+t.getMonth()+"/"+t.getDate();
				html = timestamp+": &nbsp; "+html;
			}
				
			this.debugBox.append('<hr />' + c + ': &nbsp; ' + html);
		};
	},
	
	alert			:	function(msg) {
		this.alertBox.displayMessage('&raquo; &nbsp; '+msg);
	}
};


Site.Navigation = {
	menu		   :	{id:'nav-menu'},
	submenu		:	{id:'nav-links'},
	navigation  :  [{nav: 'nav-home', links: 'home-links'},
                   {nav: 'nav-my-account', links: 'my-account-links'},
                   {nav: 'nav-trivia', links: 'trivia-links'},
                   {nav: 'nav-products', links: 'products-links'},
                   {nav: 'nav-help', links: 'help-links'},
                   {nav: 'nav-contact-us', links: 'contact-us-links'},
                   {nav: 'nav-specials', links: 'specials-links'}],
	opacity		:	1,
	delay		   :	0,
	extra_offset:  10,
	browser_is_ie: 0,
	
	showMenu	   :	function(id, callerOffsetLeft, callerOffsetWidth, containerOffsetLeft, containerOffsetWidth) {
		if (this.on) {
         this.on.className = this.on.className.removeClass('active');
      }
      
		if (id)
		{
			var e = document.getElementById(id);
			if (e)
			{
				e.className = e.className.addClass('active');
			   Site.Debug.output("Menu Parent Offset Width = "+e.parentNode.offsetWidth, 1);
			   Site.Debug.output("Menu Parent Client Width = "+e.parentNode.clientWidth, 1);
			   Site.Debug.output("Menu Offset Width = "+e.offsetWidth, 1);
			   Site.Debug.output("Menu Client Width = "+e.clientWidth, 1);
			   if (!e.style.left && callerOffsetLeft && !this.browser_is_ie)
            {
               callerOffsetLeft += this.extra_offset; // just a little bit of extra padding to get it sitting under the link nicely
               
               var all_links = e.getElementsByTagName('a');
			      var last_link = all_links[all_links.length-1];
			      var menu_width = (last_link.offsetWidth + last_link.offsetLeft) - containerOffsetLeft;
			      Site.Debug.output("LL Offset Width: "+last_link.offsetWidth, 1);
               Site.Debug.output("LL Offset Left: "+last_link.offsetLeft, 1);
               Site.Debug.output("LL Client Width: "+last_link.clientWidth, 1);
               Site.Debug.output("containerOffsetLeft: "+containerOffsetLeft, 1);
               Site.Debug.output("Menu Width: "+menu_width, 1);
			      // check to see if the menu pushed over to the caller's offset will still fit into the container
			      // if the menu fits RTL under the caller link, set the offset to be the start of the caller link
			      // else if the menu fits LTR under the caller link, set the menu to be offset against the end of the caller link
			      // otherwise don't offset
               Site.Debug.output("callerOffsetLeft: "+callerOffsetLeft, 1);
               Site.Debug.output("callerOffsetWidth: "+callerOffsetWidth, 1);
               Site.Debug.output("containerOffsetWidth: "+containerOffsetWidth, 1);
               Site.Debug.output("callerOffsetLeft: "+callerOffsetLeft, 1);
			      Site.Debug.output("callerOffsetLeft+menu_width: "+(callerOffsetLeft+menu_width), 1);
			      Site.Debug.output("callerOffsetLeft+callerOffsetWidth: "+(callerOffsetLeft+callerOffsetWidth), 1);
			      Site.Debug.output("(callerOffsetLeft+callerOffsetWidth)-menu_width: "+((callerOffsetLeft+callerOffsetWidth)-menu_width), 1);
			      var new_posn = ((callerOffsetLeft+menu_width) <= containerOffsetWidth) ? 
                                 callerOffsetLeft : 
                                 ((menu_width <= (callerOffsetLeft+callerOffsetWidth)) ? ((callerOffsetLeft+callerOffsetWidth)-menu_width) :
                                 0);
			      Site.Debug.output("callerOffsetLeft & callerOffsetWidth: "+(callerOffsetLeft+callerOffsetWidth), 1);
			      Site.Debug.output("New Posn: "+new_posn, 1);
			      
			      e.style.position = 'relative';
               e.style.left = new_posn+'px';
			   }
   			
            /*Site.Debug.output("Lnk Client Width = "+lnk.clientWidth, 1);
			   Site.Debug.output("Lnk Offset Left = "+lnk.offsetLeft, 1);
   			*/
			   
				this.on = e;
				//if (this.delay > 0) { setTimeout("Site.Navigation.showMenu('"+id+"')", this.delay); };
			}
		}
	},
	
	version     :  function() {
      var v = 0;
      if (navigator.appVersion.indexOf("MSIE") != -1)
      {
         temp = navigator.appVersion.split("MSIE");
         v = parseFloat(temp[1]);
      
         if (v>=5.0 && v < 7)
            this.browser_is_ie = v;
      }
      return v;
   },
   
	setup       :	function() {
		// add the list of menus to toggle
		var d = document;
		this.on = null;
		this.version();
		
		for (i = 0; i < this.navigation.length; i++)
		{
		   var n = this.navigation[i];
		   var e = d.getElementById(n.nav);
		   if (e)
         {
            var lnk = d.getElementById(n.links);
   		   if (lnk && lnk.className.classExists("active")) this.on = lnk;
   		   e.nav_links = n.links;
            e.onmouseover = function() {
               Site.Scroller.end();
               Site.Debug.output("Hover Offset Width = "+this.offsetWidth, 1); 
               Site.Debug.output("Hover Client Width = "+this.clientWidth, 1);
               Site.Debug.output("Hover Offset Left = "+this.offsetLeft, 1);
               Site.Debug.output("LI Offset Width = "+this.parentNode.offsetWidth, 1);
               Site.Debug.output("LI Client Width = "+this.parentNode.clientWidth, 1);
               Site.Debug.output("LI Offset Left = "+this.parentNode.offsetLeft, 1);
               Site.Debug.output("UL Offset Left = "+this.parentNode.parentNode.offsetLeft, 1);
               Site.Debug.output("UL Client Width = "+this.parentNode.parentNode.clientWidth, 1);
               Site.Debug.output("UL Offset Width = "+this.parentNode.parentNode.offsetWidth, 1);
               // find the position of the calling link
               if (Site.Navigation.browser_is_ie>0)
               {
                  var link_width = this.offsetWidth;
                  var link_offset = this.parentNode.offsetLeft;
                  var parent_offset = (this.parentNode && this.parentNode.parentNode) ? this.parentNode.parentNode.offsetLeft : 0;
                  var parent_width = (this.parentNode && this.parentNode.parentNode) ? this.parentNode.parentNode.offsetWidth : 0;
                  link_offset -= parent_offset;
               }
               else
               {
                  var link_width = this.offsetWidth;
                  var link_offset = this.offsetLeft;
                  var parent_offset = (this.parentNode && this.parentNode.parentNode) ? this.parentNode.parentNode.offsetLeft : 0;
                  var parent_width = (this.parentNode && this.parentNode.parentNode) ? this.parentNode.parentNode.offsetWidth : 0;
                  link_offset -= parent_offset;
               }
               Site.Navigation.showMenu(this.nav_links, link_offset, link_width, parent_offset, parent_width); 
            };
         }          
      }
	},
	onload	   :	function() {
		this.menu.e = document.getElementById(this.menu.id);
		this.submenu.e = document.getElementById(this.submenu.id);
		
		if (this.opacity < 1)
		{
			this.submenu.e.style.opacity = this.opacity;
			/* for those using IE */
			this.submenu.e.style.filter = 'alpha(opacity='+(100*this.opacity)+')';
		}
		
		if (this.menu.e) { this.setup(); }
	}
};


/******************************************************************************
 Site.Cookie
 
 ******************************************************************************/
Site.Cookie = {
	domain	: location.hostname.replace(/^www\./,''),
	set		: function(name,value) {
		Site.Debug.output('Setting cookie "Site-'+name+'" to "'+value+'" for '+this.domain);
		
		var expires = new Date();
		var base 	= new Date(0);
		var diff 	= base.getTime();
		if (diff>0) { expires.setTime(expires.getTime()-diff); };
		expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);
		
		document.cookie = "Site-" + name + "=" + value + ";expires=" + expires.toGMTString() + ";path=/;domain=" + this.domain;
	},
	get		: function(name) {
		var p = "Site-" + name+"="; 
		var c=document.cookie;
		var i=c.indexOf(p);
		if (i==-1) { return ''; };
		var e=c.indexOf(";",i+p.length);
		if (e==-1) { e = c.length; };
		return unescape(c.substring(i+p.length,e));
	},
	toss	: function(name) {
		Site.Debug.output('Tossing cookie "Site-'+name+'"');
		document.cookie = "Site-" + name + "=;expires=Thu, 01-Jan-70 00:00:01 GMT;path=/;domain=" + this.domain;
	}
};

Site.StyleSwitcher = {
	// ----------------------------------------------
	// StyleSwitcher functions written by Paul Sowden
	// http://www.idontsmoke.co.uk/ss/
	// - - - - - - - - - - - - - - - - - - - - - - -
	// For the details, visit ALA:
	// http://www.alistapart.com/stories/alternate/
	setActiveStyleSheet : function(title) {
		var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
			{
				a.disabled = true;
				if(a.getAttribute("title") == title) {
					a.disabled = false;
					Site.StyleSwitcher.createCookie("style", title, 365);
				}
			}
		}
	},

	getActiveStyleSheet : function() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && 
			a.getAttribute("title") && 
			!a.disabled) return a.getAttribute("title");
		}
		return null;
	},

	getPreferredStyleSheet : function() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1
			   && a.getAttribute("rel").indexOf("alt") == -1
			   && a.getAttribute("title")
			   ) return a.getAttribute("title");
		}
		return null;
	},

	createCookie : function(name,value,days) {
		if (days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},

	readCookie : function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},

	onload 	: function(e) {
		var cookie = Site.StyleSwitcher.readCookie("style");
		var title = cookie ? cookie : Site.StyleSwitcher.getPreferredStyleSheet();
		Site.StyleSwitcher.setActiveStyleSheet(title);
	},

	onunload	: function(e) {
		var title = Site.StyleSwitcher.getActiveStyleSheet();
		Site.StyleSwitcher.createCookie("style", title, 365);
	}
};

/******************************************************************************
 * Site.FontSize
 *
 * Change the display font size for accessibility
 *
 ******************************************************************************/
Site.FontSize = {
	increase	:	{id:'increase-txt'},
	decrease	:	{id:'decrease-txt'},
	range		:	[,'10pt Font', '11pt Font', '12pt Font', '13pt Font', '14pt Font', '15pt Font', '16pt Font', '17pt Font', '18pt Font'],
	idx			:	3,
	
	switchup	:	function() {
		if (this.idx < this.len)
		{
			this.idx++;
			Site.StyleSwitcher.setActiveStyleSheet(this.range[this.idx], 1);
		}
	},
	switchdown	:	function() {
		if (this.idx > 1)
		{
			this.idx--;
			Site.StyleSwitcher.setActiveStyleSheet(this.range[this.idx], 1);
		}
	},
	onload	:	function() {
		this.len = this.range.length-1;
		// setup the on click events to change font size
		this.increase.e = document.getElementById(this.increase.id);
		if (this.increase.e) 
		{
			this.increase.e.onclick = function() { Site.FontSize.switchup(); };
		}
		
		this.decrease.e = document.getElementById(this.decrease.id);
		if (this.decrease.e) 
		{
			this.decrease.e.onclick = function() { Site.FontSize.switchdown(); };
		}
		
		var style = Site.StyleSwitcher.getActiveStyleSheet();
		for (i = 1; i <= this.len; i++)
		{
			if (this.range[i] == style)
			{
				this.idx = i;
				break;
			}
		}

	}
};

Site.FormValidation = {
	form			:	{id: 'null'},
	validationSet	:	new Array(),
	checkForm		:	function() {
		var labels = this.form.e.getElementsByTagName("label");
		var error = false;
		var first = null;

		for (var i = 0; i < labels.length; i++)
		{
			if (labels[i].className.classExists("required"))
			{
				var input = labels[i].getElementsByTagName("input")[0] || labels[i].getElementsByTagName("textarea")[0] || labels[i].getElementsByTagName("select")[0];
				var spans = labels[i].getElementsByTagName("span");
				var errorText = null;
				var labelText = null;
	
				for (var j = 0; j < spans.length; j++)
				{
					if (spans[j].className.classExists("labelText"))
					{
						var labelText = spans[j];
					}
				}
				
				if (input != null)
				{
					if (input.value == "")
					{
						errorText = "Please fill in your " + labelText.childNodes[0].nodeValue.toLowerCase().replace(/:/, "");
					}
					else if (labels[i].className.classExists("requiredEmail") && !input.value.validEmail())
					{
						errorText = "Please supply a valid e-mail address";
					}
	
					if (errorText != null)
					{
						if (first == null)
						{
							first = input;
						}
	
						error = true;
						Site.FormValidation.writeCorrection(labels[i], errorText);
	
						if (input.nodeName.toLowerCase() == "input" && 
							(input.getAttribute("type") == "text" || input.getAttribute("type") == "password"))
						{
							if (input.parentNode.tagName.toLowerCase() == 'span') input = input.parentNode;
							input.onkeyup = function() { return Site.FormValidation.checkValidity(); };
						}
						else if (input.nodeName.toLowerCase() == "select")
						{
							if (input.parentNode.tagName.toLowerCase() == 'span') input = input.parentNode;
							input.onchange = function() { return Site.FormValidation.checkValidity(); };
						}
					}
					else
					{
						labels[i].className = labels[i].className.addClass("completed");
						Site.FormValidation.writeCorrection(labels[i]);
					}
				}
			}
			else
			{
				labels[i].className = labels[i].className.addClass("completed");
			}
		}

		if (error == true)
		{
			var introduction = document.getElementById("introduction");
			introduction.className = introduction.className.addClass("warning");
			Site.FormValidation.writeSpan(introduction, "Please correct the fields shown below:");
	
			var fieldsets = this.form.e.getElementsByTagName("fieldset");
	
			for (var i = 0; i < fieldsets.length; i++)
			{
				if (!fieldsets[i].className.classExists("submit"))
				{
					var labels = fieldsets[i].getElementsByTagName("label");
					var completed = true;
	
					for (var j = 0; j < labels.length; j++)
					{
						if (!labels[j].className.classExists("completed"))
						{
							completed = false;
						}
					}
	
					if (completed)
					{
						fieldsets[i].className = fieldsets[i].className.addClass("completed");
					}
				}
				else
				{
					var editLink = document.getElementById("editLink");
	
					if (editLink == null)
					{
						editLink = document.createElement("a");
						editLink.id = "editLink";
						editLink.setAttribute("href", "#");
						editLink.style.color = "#fff";
						editLink.onclick = function() { return Site.FormValidation.editForm(editLink); };
						Site.FormValidation.writeSpan(editLink, "Edit the full form");
						fieldsets[i].appendChild(editLink);
					}
				}

			}
	
			var fieldsets = this.form.e.getElementsByTagName("fieldset");
			var alternate = false;
	
			for (var i = 0; i < fieldsets.length; i++)
			{
				if (!fieldsets[i].className.classExists("completed"))
				{
					if (alternate)
					{
						fieldsets[i].className = fieldsets[i].className.addClass("alt");
						alternate = false;
					}
					else
					{
						fieldsets[i].className = fieldsets[i].className.removeClass("alt");
						alternate = true;
					}
				}
			}
	
			document.getElementById("top").focus();
	
			return false;
		}
	
		return true;
	},
	writeCorrection	:	function(label, text, correct) {
		var spans = label.getElementsByTagName("span");
		var input = label.getElementsByTagName("input")[0] || label.getElementsByTagName("textarea")[0] || label.getElementsByTagName("select")[0];
		var image = label.getElementsByTagName("img")[0];

		if (typeof text == "undefined")
		{
			if (image != null)
			{
				label.removeChild(image);
			}
	
			for (var j = 0; j < spans.length; j++)
			{
				if (spans[j].className.classExists("correctionText"))
				{
					label.removeChild(spans[j]);
	
					break;
				}
			}
		}
		else
		{
			if (image == null)
			{
				image = document.createElement("img");
				image.className = "correctionIcon";
				
				/* Fix to accomodate input wrapped in span for pretty borders */
				if (input.parentNode.tagName.toLowerCase() == 'span') input = input.parentNode;
				/* End fix */
				
				image = label.insertBefore(image, input);
				var newText = document.createElement("span");
				newText.className = "correctionText";
				label.appendChild(newText);
			}
	
			var spans = label.getElementsByTagName("span");
			for (var j = 0; j < spans.length; j++)
			{
				if (spans[j].className.classExists("correctionText"))
				{
					var correctionText = spans[j];
	
					break;
				}
			}
	
			if (correct == true)
			{
				image.setAttribute("src", "images/icon-tick.gif");
				image.setAttribute("alt", "Correct");
				correctionText.className = correctionText.className.removeClass("warning");
			}
			else
			{
				image.setAttribute("src", "images/icon-cross.gif");
				image.setAttribute("alt", "Incorrect");
				correctionText.className = correctionText.className.addClass("warning");
			}
	
			Site.FormValidation.writeSpan(correctionText, text);
		}
	
		return true;
	},
	replaceText :   function(e, text) {
		e.innerHTML = text;
	},
	writeSpan	:	function(span, text) {
		var children = span.childNodes;
	
		for (var i = 0; children.length > 0;)
		{
			span.removeChild(children[i]);
		}
	
		var textNode = document.createTextNode(text);
		span.appendChild(textNode);
	
		return true;
	},
	addValidation	:	function(element, comparison, error_msg) {
		var add = true;
		for (i = 0; i < this.validationSet.length; i++)
		{
			if (this.validationSet[i].comparison == comparison)
			{
				add = false;
				break;
			}
		}
		if (add)
		{
			i = this.validationSet.length;
			this.validationSet[i] = new Object();
			this.validationSet[i].e = element;
			this.validationSet[i].comparison = comparison;
			this.validationSet[i].msg = error_msg;
		}
	},
	
	checkValidity	:	function() {
		var label = this.parentNode;
		var spans = label.getElementsByTagName("span");
		var labelText = null;
		var input = this.getElementsByTagName('input')[0] || this.getElementsByTagName('textarea')[0] || this.getElementsByTagName('select')[0];
	
		for (var j = 0; j < spans.length; j++)
		{
			if (spans[j].className.classExists("labelText"))
			{
				var labelText = spans[j];
			}
		}
		if (input.value == "")
		{
			Site.FormValidation.writeCorrection(label, "Please fill in your " + labelText.childNodes[0].nodeValue.toLowerCase().replace(/:/, ""));
		}
		else if (label.className.classExists("requiredEmail") && !input.value.validEmail())
		{
			Site.FormValidation.writeCorrection(label, "Please supply a valid e-mail address");
		}
		else
		{
			Site.FormValidation.writeCorrection(label, "This field is valid", true);//"This field is correct", true);
		}
	
		return true;
	},
	editForm	:	function(e) {
		var the_form = e.parentNode;
		var editLink = e;
	
		while (the_form.nodeName.toLowerCase() != "form")
		{
			the_form = the_form.parentNode;
		}
	
		var fieldsets = the_form.getElementsByTagName("fieldset");
	
		for (var i = 0; i < fieldsets.length; i++)
		{
			fieldsets[i].className = fieldsets[i].className.removeClass("completed");
		}
	
		var labels = the_form.getElementsByTagName("label");
	
		for (var i = 0; i < labels.length; i++)
		{
			labels[i].className = labels[i].className.removeClass("completed");
		}
	
		editLink.parentNode.removeChild(editLink);
	
		document.getElementById("top").focus();
	
		return false;
	},
	Element	:	function(e) {
		if (!e) return;
		Site.FormValidation.form.id = e.id;
		Site.FormValidation.form.e = e;
		//Site.FormValidation.form.e.onsubmit = function() { return Site.FormValidation.checkForm(); };
		var s = e.getElementsByTagName('input');// && e.getElementsByTagName('a');
		//var s = e.getElementsByClassName('submit');
		for (i = 0; i < s.length; i++)
		{
			if (s[i].className.classExists('submit'))
			{
				if (typeof s[i].onclick != 'function') s[i].onclick = function() { return Site.FormValidation.checkForm(); };
			}
		}
		if (s.length == 0)
			Site.FormValidation.form.e.onsubmit = function() { return Site.FormValidation.checkForm(); };
	}
};


Site.Forms = {
	forms	:	new Array(),
	
	addSubmitButton		:	function(e) {
		var s = document.createElement('input');
		s.className = 'submit-disabled';
		s.title = 'Before you can continue, please fill out the required details';
		s.setAttribute('type', 'submit');
		s.value = 'Proceed >>';
		s.disabled = true;
		var fs = document.createElement('fieldset');
		fs.className = 'submit';
		
		fs.appendChild(s);
		e.appendChild(fs);
		
		return true;		
	},
	
	editElement				:	function(a, e, f) {
		if (!a || !e) return;
		
		/* make the element editable and change the submit button to a Save function - i.e. post the form data */
		a.innerHTML = 'Save';
		a.title = 'Save Changes?';
		a.onclick = function() { f.submit(); }
		if (!e.length && e.tagName && e.tagName.toLowerCase() == 'div')
		{
			e.style.display = 'block';
		}
		else { // tagName == 'input' or 'textarea'
			for (i = 0; i < e.length; i++) {
				e[i].readOnly = false;
				if (e[i].parentNode && e[i].parentNode.tagName.toLowerCase() == 'span')
					e[i].parentNode.className = 'element';
				
				if (e[i].tagName.toLowerCase() == 'textarea') { e[i].rows = '4'; }
					
			}
		}
	},
	
	createEditabeElement	:	function(p, f) {
		var input = p.getElementsByTagName('input') || p.getElementsByTagName('textarea');
		var div = p.getElementsByTagName('div')[0];
		var links =  p.getElementsByTagName('a');
		var e = null;
				
		if (div && div.className.classExists('password'))
		{
			e = div;
		}
		else e = input;
		
		for (i = 0; i < links.length; i++)
		{
			var a = links[i];
			if (a.className.classExists('submit'))
			{
				a.title = 'Click to change this value';
				if (typeof a.onclick != 'function') a.onclick = function() { Site.Forms.editElement(a, e, f); };
			}
		}
	},
	
	editElements		:	function(f) {
		/* for all elements of class "change", add a toggle element that displays the element for change,
		 * and an input box to change the contents
		 */
		var rows = f.getElementsByTagName('tr');

		for (r = 0; r < rows.length; r++)
		{
			if (rows[r].className.classExists('change'))
			{
				Site.Forms.createEditabeElement(rows[r], f);
			}
		}
	},
	
	toggleForgotten			:	function(a, f) {
		var o = null;
		var e = a.parentNode;		
		while (e)
		{
			if (e.tagName.toLowerCase() == 'form')
			{
				var o = e;
				break;
			}
			
			e = e.parentNode;
		}
		
		if (o)
		{
			o.style.display = 'none';
			f.style.display = 'block';
		}
	},
	
	setupForgottenPassword	:	function() {
		return;
		
		var f = document.getElementById('forgotten-password');
		var a = null;
		
		var e = document.getElementsByTagName('a');
		for (i = 0; i < e.length && f; i++)
		{
			if (e[i].className.classExists('forgotten-password'))
			{
				a = e[i];
				a.onclick = function() { Site.Forms.toggleForgotten(a, f); return false; };
				f.style.display = 'none';
				return;
			}
		}
	},
	
	onload	:	function() {
		/*var inputs	= document.getElementsByTagName('input');
		for (var i=0; input=inputs[i]; i++) {	
			// Activate custom checkboxes
			if (input.type=='checkbox' && input.parentNode.nodeName=='SPAN') {
				var label = input.parentNode;
				label.checkbox = input;
				if (label.checkbox.checked) { 
					label.className = label.className.addClass('checkbox-on'); 
				}
				else
				{
			      label.className = label.className.addClass('checkbox-off');
            }				
				if (input.disabled != true)
				{
   				if ((typeof label.onclick)!='function') {
   					label.onclick = function() {
   						this.checkbox.checked = !(this.checkbox.checked);
   						this.className = (this.checkbox.checked)?
                                          this.className.replaceClass('checkbox-off', 'checkbox-on'):
                                          this.className.replaceClass('checkbox-on', 'checkbox-off');
                     this.blur();
   					};
   				};
   			}
			}
			else if (input.type=='radio' && input.parentNode.nodeName=='SPAN') {
				var label = input.parentNode;
				label.radio = input;
				if (label.radio.checked) { 
					label.className = label.className.addClass('radio-on'); 
				}
				else
				{
			      label.className = label.className.addClass('radio-off');
            }
				
				if (input.disabled != true)
				{
               if ((typeof label.onclick)!='function') {
   					label.onclick = function() {
   						// reset all
   						this.blur();
                     var inputs	= document.getElementsByTagName('input');
   						for (var i=0; input=inputs[i]; i++) {
   							if (input.type=='radio') {
   								input.checked = false;
   								input.parentNode.className = input.parentNode.className.replaceClass('radio-on', 'radio-off');
   							}
   						}
   						
   						this.radio.checked = true;
   						this.className = this.className.replaceClass('radio-off', 'radio-on');
   					};
   				};
   			}
			};
		};*/

		var f = document.getElementsByTagName('form');
		for (i = 0; f && i < f.length; i++)
		{
			if (f[i].className.classExists('submission'))
			{
				Site.Forms.addSubmitButton(f[i]);
			}
			
			Site.Forms.editElements(f[i]);

			this.forms[i] = new Site.FormValidation.Element(f[i]);
		}
		
		Site.Forms.setupForgottenPassword();
	}
};

Site.Tabs = {
   containers  : [ {containerTagName: '', className: 'tabify', parentClassName: 'tabs'} ], 
	onload		: function() {
		if (!document.getElementsByTagName) { return; }

      for (c = 0; c < this.containers.length; c++)
      {
         Site.Tabs.tabify(this.containers[c]);
      }
   },
   
   tabify      : function(obj) {
      var container = obj.containerTagName;
      var className = obj.className;
      var parentClass = obj.parentClassName;		
      //var elems	= document.getElementsByTagName(container);
      // elems == the list of parent containers to create tab list from
      var elems = getElementsByClassName(parentClass, document, container);
		for (var i = 0; elems && i < elems.length; i++) {
			var e = elems[i];
			// tabs == the list of tabs under a given parent container
			var tabs = getElementsByClassName(className, e, 'a');
			//alert(tabs.length);
			//alert(tabs[0].className+" "+tabs[0].href);
			for (var j = 0; j < tabs.length; j++) {
				var lnk	= tabs[j];
				lnk.tabs	= tabs;
				lnk.tab	= document.getElementById(lnk.href.getElementIdByHref());
				if (lnk.tab)
            {
               lnk.tab.lnk = lnk;
   				// Hide inactive links
   				if (lnk.tab && !lnk.className.classExists('active')) { lnk.tab.style.display = 'none'; }
   				else { Site.Autofocus.go(lnk.tab); }
   				lnk.onclick = function() {
   					// disable all tabs
   					this.blur();
   					if (this.className.classExists('active'))
   					{
      					this.className = this.className.removeClass('active');
      					this.tab.style.display = 'none';
   					}
   					else
   					{
      					for (var k=0; k<this.tabs.length; k++) {
      						var link = this.tabs[k];
      						link.className = link.className.removeClass('active');
      						//alert(lnk.tab.id);
      						link.tab.style.display = 'none';
      					}
      					this.className = this.className.addClass('active');
      					this.tab.style.display = 'block';
      					Site.Autofocus.go(this.tab);
      				}
   					return false;
   				}
   			}
			}
		}
	},
	
	hide    : function(id) {
	   // get the tab
	   var elem = document.getElementById(id);
	   if (!elem) return false;
      if (elem.lnk) elem.lnk.className = elem.className.removeClass('active');
		elem.style.display = 'none';
   }
};

Site.Autofocus	= {
   go    : function(e) {
      var inputs = [e];
		if (e.tagName.toLowerCase() != 'input' &&
          e.tagName.toLowerCase() != 'textarea')
      {
         inputs = e.getElementsByTagName('input');
         var textareas = e.getElementsByTagName('textarea');
         if (inputs.length && textareas.length) inputs.concat(textareas);
         else inputs = textareas;
      }
         
		for (var i=0; i<inputs.length; i++) {
			var input = inputs[i];
			if (input.type == 'text' ||
             input.type == 'file' ||
             input.tagName.toLowerCase() == 'textarea') {
				input.focus();
				input.select();
				break;
			}
		}
	}
};

Site.Window = {
   onload   : function() {
      var links = document.getElementsByTagName('a');
      for (lnk = 0; lnk < links.length; lnk++)
      {
         var a = links[lnk];
         if (a.getAttribute('_target'))
         {
            switch(a.getAttribute('_target'))
            {
               case "popup":
                  a.onclick = function() {
                     var wheight = 0, wwidth = 0;
                     if (self.screen)
                     {
                         wheight = self.screen.height;
                         wwidth = self.screen.width;
                     }

                     var new_width = (wwidth>=40) ? wwidth-40 : 0;
                     var new_height = (wheight>=100) ? wheight-100 : 0;
                     var newWindow = window.open(this.getAttribute('href'), 
                                                 this.getAttribute('title'),
                                                 "resizeable=1,scrollbars=1,width="+new_width+",height="+new_height);
                     var x = 20; var y = 50;
                     newWindow.moveTo(x, y);
                     newWindow.focus();
                     return false;
                  };
                  break;
            }
         }
      }
   }
};


/*
 * Implements a scroller for sample questions - this will only be generated if the scroller id is found on the page
 */
Site.Scroller = {
   items  : {id: 'scroller-questions', tagName: 'p', current: 0, list: null},
   scroller   : {id: 'q-scroller', letter: 0, text: ''},
   opacity    : {value: 1, decrement: 0.05},
   timer      : {handle: null, pause: false, letters: 100, next_item: 3000, fade: 5, blink: 10},
	pause      : false,
	link_to    : {href: '/trivia/our-questions/sample-questions/', title: 'Click here to download a sample pack!'},
	cursor     : {current: 0, values: ['|', '/', '-', '\\']},
	
	/*onload     :  function() {
		this.items.e =  document.getElementById(this.items.id);
		this.scroller.e =  document.getElementById(this.scroller.id);
		if (this.scroller.e && this.items.e)
      {
         this.scroller.wrapper = this.scroller.e;
   		this.items.list = this.items.e.getElementsByTagName(this.items.tagName);
   		if (this.items.list && this.items.list.length>0)
   		{
            if (this.link_to && this.link_to.href)
            {
               var lnk = document.createElement('a');
               lnk.href = this.link_to.href;
               lnk.title = this.link_to.title;

               this.scroller.e.appendChild(lnk);
               this.scroller.e = lnk;
            }
         	this.scroller.e.onmouseover = function() { Site.Scroller.stop(); }
       		this.scroller.e.onmouseout = function() { Site.Scroller.resume(); }
            //if (this.timer.blink)
            //   this.timer.blink_increment = (this.timer.next_item/this.timer.blink);
   		   this.showNextItem();
         }
      }
	},*/

   end            : function() {
      this.stop();
      clearInterval(this.timer.handle);
      if (this.scroller.e) {
         this.scroller.e.innerHTML = '';
         this.scroller.wrapper.className = this.scroller.wrapper.className.removeClass('active');
         this.scroller.wrapper.style.display = 'none';
      }
   },
   
	stop           :  function() {
      this.timer.pause = true;
      if (this.items.list) {
         this.scroller.e.innerHTML = this.items.list[this.items.current].innerHTML;
         this.scroller.text = this.scroller.e.innerHTML;
         this.scroller.letter = this.items.list[this.items.current].innerHTML.length;
      }
   },

   resume         :  function() {
      this.timer.pause = false;
   },

   showNextItem   :  function() {
      /*this.scroller.text = '';
      this.cursor.current = 0;
      this.scroller.e.innerHTML = this.cursor.values[this.cursor.current++];//"|";
      this.cursor.current = (this.cursor.current%this.cursor.values.length);
		this.opacity.value = 1;
 		this.setOpacity();*/
      this.timer.handle = setInterval("Site.Scroller.tick();", this.timer.letters);
   },

   tick          : function() {
      if(this.timer.pause) return;
      if (!this.items.list) return;
      
      if (this.scroller.letter >= this.items.list[this.items.current].innerHTML.length)
      {
         clearInterval(this.timer.handle);
         this.items.current = ((this.items.current+1)%this.items.list.length);
         this.scroller.letter = 0;
         this.scroller.e.innerHTML = this.scroller.text;
         if (this.timer.blink_increment)
         {
            this.timer.blink_sum = 0;

         }
         else {
            this.timer.blink_sum = this.timer.next_item+1;
            this.timer.blink_increment = this.timer.next_item;
         }
         this.timer.handle = setInterval("Site.Scroller.wait();", this.timer.blink_increment);
      }
      else
      {
         this.scroller.text += this.items.list[this.items.current].innerHTML.charAt(this.scroller.letter++);
         this.scroller.e.innerHTML = this.scroller.text+this.cursor.values[this.cursor.current++];//'|';
         this.cursor.current = (this.cursor.current%this.cursor.values.length);
      }
   },

   wait        :  function() {
      if (this.timer.blink_sum > this.timer.next_item)
      {
         clearInterval(this.timer.handle);
         this.timer.handle = setInterval("Site.Scroller.fadeOut();", this.timer.fade);
      }
      else
      {
         this.scroller.e.innerHTML = this.scroller.text;
         if ((this.timer.blink_sum%(2*this.timer.blink_increment))>0)
            this.scroller.e.innerHTML += '|';
         this.timer.blink_sum += this.timer.blink_increment;
      }
   },

   fadeOut     :  function() {
    	if(this.timer.pause) return;

    	if(this.opacity.value < 0) {
    		clearInterval(this.timer.handle);
    		this.timer.handle = setInterval("Site.Scroller.showNextItem();", 5000);//this.timer.letter);
    	}
    	else
    	{
       	this.setOpacity();
         this.opacity.value -= this.opacity.decrement;
      }
   },

   setOpacity  :  function() {
      this.scroller.e.style.opacity = this.opacity.value;
      this.scroller.e.style.MozOpacity = this.opacity.value;
      this.scroller.e.style.filter = "alpha(opacity=" + (this.opacity.value*100) + ")";
   }
};

if(window.onload)
{
	var oldHandler = window.onload;
	window.onload = function()
	{
		Site.onload();
		oldHandler();
	};
}
else
{
	window.onload = function() { Site.onload(); } 
}
