var PB = {
	toString:   function()  { return 'Photobooks, Inc.'; },
	JumpSelect: function(o) { if (o.value && o.value !== '') { document.location.href = o.value; } },
	CloseChild: function(o) { o.close(); },
	KWSearch: function(o) { if (o.value.length == 0){alert('You must enter at least one key word for this search.');return false;} },
	ContentClass: 'layout_eWEP'
};

PB.Loader = {
	toString: function() { return 'Photobooks Dynamic Script Loader'; },
	onLoaded: new YAHOO.util.CustomEvent('Loaded'),
	Loaders: [ ],
	Root: null,
	Timer: null,
	Status: 'ready',
	LoadScript: function(strName, strSrc) {
		var oNode, i;
		if (this.Root === null) { this.Root = document.getElementsByTagName('head')[0]; }
		// Make sure we haven't already loaded this.
		i = this.Loaders.length; while (i--) { if (this.Loaders[i].Source === strSrc) { return this.Loaders[i]; } }
		i = this.Loaders.length;
		oNode = document.createElement('script');
			oNode.setAttribute('type', 'text/javascript');
			oNode.setAttribute('src', strSrc);
			Event.addListener(oNode, 'readystatechange', this.LoadedFile, this, true);
			Event.addListener(oNode, 'load',             this.LoadedFile, this, true);
		this.Root.appendChild(oNode);
		this.Loaders[i] = {
			Name: strName,
			Source: strSrc,
			Status: 'loading',
			Node: oNode,
			Type: 'script'
		};
		if (this.Timer !== null) { window.clearTimeout(this.Timer); }
		this.Status = 'waiting';
		return this.Loaders[i];
	},
	LoadCSS: function(strName, strSrc, blnRequire) {
		var oNode, i = this.Loaders.length;
		if (this.Root === null) { this.Root = document.getElementsByTagName('head')[0]; }
		// Prevent reloading the same CSS file.
		i = this.Loaders.length; while (i--) { if (this.Loaders[i].Source === strSrc) { return this.Loaders[i]; } }
		i = this.Loaders.length;
		oNode = document.createElement('link');
			oNode.setAttribute('rel', 'stylesheet');
			oNode.setAttribute('type', 'text/css');
			oNode.setAttribute('href', strSrc);
			// Firefox lte 1.5.0.3 does not support this method on the link element. re-evaluate as necessary, this is preferred.
			// Opera gte 9.03 supports both methods and doesn't mind using both at once.
			// IE lte 6 supports only this method.
			if (blnRequire === true) {
				Event.addListener(oNode, 'readystatechange', this.LoadedFile, this, true);
				Event.addListener(oNode, 'load',             this.LoadedFile, this, true);
			}
		this.Root.appendChild(oNode);
		var ToReturn = {
			Name: strName,
			Source: strSrc,
			Status: 'loading',
			Node: oNode,
			Type: 'css'
		};
		if (blnRequire === true) {
			this.Loaders[i] = ToReturn;
			if (this.Timer !== null) { window.clearTimeout(this.Timer); }
			this.Status = 'waiting';
		}
		return ToReturn;
	},
	LoadedFile: function(e) {
		var oTarget = e.currentTarget || e.srcElement;
		var i = this.Loaders.length; while (i--) {
			if (this.Loaders[i].Node === oTarget) { break; }
		}
		var oNode = this.Loaders[i].Node;
		if ((e.type === 'readystatechange') && (oNode.readyState) && (oNode.readyState === 'loaded')) { this.Loaders[i].Status = 'ready'; }
		if (e.type === 'load') { this.Loaders[i].Status = 'ready'; }
		if (this.Loaders[i].Status === 'ready') { Event.purgeElement(oNode); }
	},
	StartLoading: function() {
		if (this.Timer !== null) { window.clearTimeout(this.Timer); }
		if (this.Loaders.length === 0) { this.onLoaded.fire(); return; }
		this.Status = 'loading';
		this.CheckStatus(0);
	},
	CheckStatus: function(iteration) {
		var i, blnDone = true;
		var oNode;
		iteration++;
		if (iteration > 100) { alert('Could not load necessary files.\nPlease reload the page and try again.'); return; }
		i = this.Loaders.length; while (i--) {
			oNode = this.Loaders[i];
			if ((oNode.Type === 'css') && (oNode.Status !== 'ready')) {
				try { // Necessary for Firefox, works on Opera, no effect on IE.
					if (oNode.Node.sheet.cssRules) { oNode.Status = 'ready'; Event.purgeElement(oNode.Node); }
				} catch(Nope) { }
			}
			if (oNode.Status !== 'ready') { blnDone = false; break; }
		}
		if (blnDone === false) {
			window.setTimeout(function() { PB.Loader.CheckStatus(iteration); }, 100);
			return;
		} else {
			this.Status = 'ready';
			this.onLoaded.fire();
		}
	}
};
PB.Error = {
	Throw: function() {
		try { console.error(arguments); } catch(NoFirebug) { alert(arguments[0]); }
	}
};
PB.ToolTips = {
	toString: function() { return 'Photobooks Auto-Tooltip Manager'; },
	ToolTip: null,
	Constants: {
		ScriptReady: 1,
		WindowReady: 2
	},
	Status: 0,
	ScriptReady: function() {
		this.Status |= this.Constants.ScriptReady;
		var iMask = this.Constants.ScriptReady | this.Constants.WindowReady;
		if (this.Status & iMask === iMask) { this.Init(); }
	},
	WindowLoaded: function () {
		this.Status |= this.Constants.WindowLoaded;
		var iMask = this.Constants.ScriptReady | this.Constants.WindowReady;
		if (this.Status & iMask === iMask) { this.Init(); }
	},
	Enable: function() {
		Event.addListener(window, 'load', this.WindowLoaded, this, true);
		PB.Loader.LoadScript('yuiContainer', '/glibrary/yui_2.2.1/build/container/container-min.js');
		PB.Loader.LoadCSS('yuiContainerCSS', '/glibrary/yui_2.2.1/build/container/assets/container.css', false);
		PB.Loader.onLoaded.subscribe(this.ScriptReady, this, true);
		PB.Loader.StartLoading();
	},
	Init: function() {
		var oRoot = $('layout_eWEP'); if (!oRoot) { return; }
		var Elements = Dom.getElementsBy(function(o) { return (o.attributes.title && o.attributes.title.specified) ? true : false; }, 'a', oRoot);
		if (Elements.length === 0) { return; }
		this.ToolTip = new YAHOO.widget.Tooltip('tt', {
			context: Elements,
			monitorresize: false,
			iframe: false,
			width: '20em'
		} );
	}
};
PB.FormFill = {
	toString: function() { return 'Photobooks Form Repopulation Manager'; },
	Load: function(strFormID, strFormField, strValue) {
		if (strValue === null) { return; }
		var i, intValCounter;
		var oForm = $(strFormID);
		var oField;
		if (oForm) { oField = oForm[strFormField]; }
		if (oField) {
			
			switch (oField.type) {
				case 'select-one':
					i = oField.options.length;
					while (i--) {
						if ((oField[i].value === strValue) || (oField[i].text === strValue)) { oField.selectedIndex = i; }
					}
					break;
				case 'select-multiple':
					i = oField.options.length;
					while (i--) {
						for (intValCounter = 0; intValCounter < strValue.split(', ').length; intValCounter++) {
							if ((oField[i].value === strValue.split(', ')[intValCounter]) || (oField[i].text === strValue.split(', ')[intValCounter])) {
								oField.options[i].selected = true;
							}
						}
					}
					break;
				case 'radio':
				case 'checkbox':
					if (oField.value === strValue) { oField.checked = true; }
					break;
				case 'file': break;
				case undefined:
					// The form element is likely a nodelist.
					if ((oField.length) && (oField.length > 0)) {
						switch (oField[0].type) {
							case 'radio':
								i = oField.length;
								while (i--) {
									if (oField[i].value === strValue) { oField[i].checked = true; }
								}
								break;
							case 'checkbox':
								i = oField.length;
								strValue = strValue.split(', ');
								while (i--) {
									intValCounter = strValue.length;
									while (intValCounter--) {
										if (oField[i].value === strValue[intValCounter]) { oField[i].checked = true; }
									}
								}
								break;
						}
					}
					break;
				default:
					oField.value = strValue;
					break;
			}
		}
	}
};
PB.TreeView = {
	toString: function() { return 'Photobooks TreeView Manager'; },
	Forest: [ ],
	Draw: function() { var i = this.Forest.length; while (i--) { this.Forest[i].draw(); } },
	Load: function(strID) {
		var oXML = $(strID);
		var oEl  = oXML.parentNode;
		var oTree, oRoot, oBranch, oNode;
		var i;
		if (!oXML) { return; }
		if (!oEl) { return; }
		oXML = oXML.getElementsByTagName('li');
		if (!oXML) { PB.Error.Throw('Nothing to load', strID); return; }

		// Read data into memory
		var strTID, strLabel, strHref, strParent, blnExpanded, strDate, oData = [ ];
		i = oXML.length; while(i--) {
			strTID      = oXML[i].getAttribute('id');
			strDate     = oXML[i].getAttribute('Date');
			strLabel    = (oXML[i].firstChild) ? oXML[i].firstChild.nodeValue : null;
			strHref     = oXML[i].getAttribute('href');
			strParent   = oXML[i].getAttribute('parent');
			blnExpanded = (oXML[i].getAttribute('expanded') === '1') ? true : false;
			oNode       = { id: strTID, expanded: blnExpanded };
			oNode.label = (strLabel) ? strLabel : 'Branch ' + i;
			if (strDate)   { oNode.label = strDate.substr(0, 10)  + ' - ' + oNode.label; }
			if (strHref)   { oNode.href = strHref; }
			if (strParent) { oNode.parent = strParent; }
			oData.push(oNode);
		}

		while (oEl.hasChildNodes()) { oEl.removeChild(oEl.firstChild); }
		Dom.setStyle(oEl, 'display', 'block');
		oTree = new YAHOO.widget.TreeView(oEl);
		oRoot = oTree.getRoot();

		function fnAddChildren(oParent, strParentID) {
			var oChildNode, oChild;
			var x = oData.length; while (x--) {
				oChildNode = oData[x];
				if (oChildNode.parent !== strParentID) { continue; }
				oChild = new YAHOO.widget.TextNode(oChildNode, oParent, oChildNode.expanded);
				fnAddChildren(oChild, oChildNode.id);
			}
		}

		i = oData.length; while(i--) {
			oNode = oData[i];
			if (oNode.parent) { continue; }
			oBranch = new YAHOO.widget.TextNode(oNode, oRoot, oNode.expanded);
			fnAddChildren(oBranch, oNode.id);
		}

		this.Forest.push(oTree);
	}
};
PB.MouseOvers = {
	toString:    function() { return 'Photobooks Mouseover Manager'; },
	Preloads:    [ ],
	HoverNavs:   { },
	Elements:    [ ],
	EventLoaded: false,
	Load: function(strNormal, strHover) {
		this.HoverNavs[strNormal] = strHover;
		this.HoverNavs[strHover]  = strNormal;
	},
	LoadBatch: function(arrToLoad) {
		for (var i = 0; i < arrToLoad.length; i += 2) {
			if (i + 1 === arrToLoad.length) { break; }
			this.Load(arrToLoad[i], arrToLoad[i + 1]);
		}
	},
	DoRollover: function() {
		var CurSrc = this.src.match(/[^\\\/]+\.(gif|jpg|png)/i); if (!CurSrc) { return; }
		var NewSrc = PB.MouseOvers.HoverNavs[CurSrc[0]];    if (!NewSrc) { return; }
		this.src   = this.src.slice(0, 0 - CurSrc[0].length) + NewSrc;
	},
	Apply: function() {
		if (this.Elements.length === 0) { return; }
		if (this.EventLoaded === true) { return; }
		var i, x;
		for (i = 0; i < this.Preloads.length; i++) {
			x = this.Preloads[i];
			this.Preloads[i]     = new Image();
			this.Preloads[i].src = x;
		}
		Event.addListener(this.Elements, 'mouseover', this.DoRollover);
		Event.addListener(this.Elements, 'mouseout',  this.DoRollover);
		this.EventLoaded = true;
	}
};
PB.FontResizer = {
	toString: function() { return 'Photobooks Font Resizer'; },
	Icon: '/images/Icons/font_resize_btn.gif',
	ContentID: 'layout_Main',
	Content: null,
	ContainerID: 'FontResizer',
	Container: null,
	ActiveState: null,
	DefaultState: 'Size1',
	DefaultDisplay: 'none',
	Visible: false,
	Icons: [ ],
	Animate: true,
	showAnim: null,
	hideAnim: null,
	Hide: function() {
		if (this.Animate === true) {
			this.hideAnim.animate();
		} else {
			Dom.setStyle(this.Container, 'display', 'none');
			this.Visible = false;
		}
	},
	Show: function() {
		if (this.Animate === true) {
			this.showAnim.animate();
		} else {
			Dom.setStyle(this.Container, 'display', 'block');
			this.Visible = true;
		}
	},
	Toggle: function() { if (this.Visible === true) { this.Hide(); } else { this.Show(); } },
	FindActiveState: function() {
		var sSize    = '';
		var sCookies = document.cookie;
		var aCookies = sCookies.split('; ');
		var sCookieN, i;
		for (i = 0; i < aCookies.length; i++) {
			sCookieN = aCookies[i].substr(0, aCookies[i].indexOf('='));
			if (sCookieN !== 'FontSize') { continue; }
			sSize = aCookies[i].substring(aCookies[i].indexOf('=') + 1);
			break;
		}
		switch (sSize.toLowerCase()) {
			case 'size1': sSize = 'Size1'; break;
			case 'size2': sSize = 'Size2'; break;
			case 'size3': sSize = 'Size3'; break;
			case 'size4': sSize = 'Size4'; break;
			default:      sSize = this.DefaultState; break;
		}
		this.ActiveState = sSize;
		document.cookie  = 'FontSize=' + sSize;
	},
	Render: function() {
		var oItem;
		var i;

		for (i = 4; i > 0; i--) {
			oItem = document.createElement('a');
			oItem.href = 'javascript: void(0);'; // JS URLs are bad. This one is ok.
			oItem.id = this.ContainerID + i;     // IE lte 6 needs a url to use a:hover
			Dom.addClass(oItem, 'Icon');
			Dom.addClass(oItem, 'Size' + i);
			if (this.ActiveState === 'Size' + i) {
				Dom.addClass(oItem, 'Active');           // For JS
				Dom.addClass(oItem, 'S' + i + 'Active'); // For CSS in IE lte 6
			}
			this.Icons.push(oItem);
			this.Container.appendChild(oItem);
		}

		Event.addListener(this.Container, 'click', this.onClick, this, true);
	},
	Init: function() {
		this.Animate = (this.Animate && YAHOO && YAHOO.util && YAHOO.util.Anim) ? true : false;
		this.Container = $(this.ContainerID); if (!this.Container) { return; }
		this.Content   = $(this.ContentID);
		this.FindActiveState();
		this.Render();
		if (this.ActiveState !== this.DefaultState) { this.ChangeSize(this.ActiveState); }
		if (this.Animate === true) {
			Dom.setStyle(this.Container, 'display', 'block');
			Dom.setStyle(this.Container, 'height', '0px');
			this.showAnim = new YAHOO.util.Anim(this.Container, { height: { to: 33 } }, 0.5, YAHOO.util.Easing.easeOut);
			this.hideAnim = new YAHOO.util.Anim(this.Container, { height: { to:  0 } }, 0.5, YAHOO.util.Easing.easeOut);
			this.showAnim.onComplete.subscribe(function() { this.Visible = true;  }, this, true);
			this.hideAnim.onComplete.subscribe(function() { this.Visible = false; }, this, true);
		} else {
			Dom.setStyle(this.Container, 'display', this.DefaultDisplay);
		}

	},
	onClick: function(e, o) {
		var oTarget = Event.getTarget(e);
		if (!oTarget.nodeName || oTarget.nodeName.toLowerCase() !== 'a') { return; }
		if (Dom.hasClass(oTarget, 'Active') === true) { return; }
		var sID     = oTarget.id;
		var iSize   = sID.substring(this.ContainerID.length);
		var sSize   = 'Size' + iSize;
		var i;
		Dom.removeClass(this.Icons, 'Active');
		for (i = 1; i <= 4; i++) { Dom.removeClass(this.Icons, 'S' + i + 'Active'); }
		Dom.addClass(oTarget, 'Active');
		Dom.addClass(oTarget, 'S' + iSize + 'Active');
		this.ChangeSize(sSize);
	},
	ChangeSize: function(sSize) {
		var sNewSize;
		switch (sSize) {
			case 'Size1' : sNewSize = 'small';   break;
			case 'Size2' : sNewSize = 'medium';  break;
			case 'Size3' : sNewSize = 'large';   break;
			case 'Size4' : sNewSize = 'x-large'; break;
			default      : return;
		}
		Dom.setStyle(this.Content, 'fontSize', sNewSize);
		this.ActiveState = sSize;
		document.cookie = 'FontSize=' + sSize;
	}
};
PB.HoverPanels = {
	// This function requires YAHOO.widget.Container
	toString:      function() { return 'Photobooks Panel Manager'; },
	Panels:        { },
	InitPanels:    function(strMapID, strAnchorID) {
		var i, pID, eID, aID;
		var oMap   = $(strMapID);                       if (!oMap)   { return; }
		var oAreas = oMap.getElementsByTagName('area'); if (!oAreas) { return; }
		var oProps = {
			width: '300px',
			visible: false,
			constraintoviewport: true,
			draggable: false,
			close: false,
			context: [strAnchorID, 'bl', 'br'],
			iframe: false
		};
		i = oAreas.length; while (i--) {
			aID = oAreas[i].id;  if (!aID) { continue; }
			pID = 'p' + aID.substring(1);
			eID = 'e' + aID.substring(1);
			this.Panels[pID] = new YAHOO.widget.Panel(eID, oProps);
			this.Panels[pID].render();
		}
		Event.addListener(oAreas, 'mouseover', this.PopUp, this, true);
		Event.addListener(oAreas, 'mouseout',  this.Hide,  this, true);
	},
	PopUp: function(e, o) {
		var oTarget = e.target || e.srcElement; if (!oTarget)          { return; }
		var strID = oTarget.id;                 if (!strID)            { return; }
		var pID   = 'p' + strID.substring(1);   if (!this.Panels[pID]) { return; }
		this.Panels[pID].show();
	},
	Hide: function(e, o) {
		var oTarget = e.target || e.srcElement; if (!oTarget)          { return; }
		var strID = oTarget.id;                 if (!strID)            { return; }
		var pID   = 'p' + strID.substring(1);   if (!this.Panels[pID]) { return; }
		this.Panels[pID].hide();
	}
};
PB.Maps = {
	toString: function() { return 'Photobooks hCard to Map Manager'; },
	MapURL: 'http://map2.photobooks.com/s/m.asp?transaction=locMap',
	DirURL: 'http://map2.photobooks.com/s/m.asp?dir=true&transaction=locMap',
	vCards: [ ],
	init: function() {
		// Search for vCards.
		// Extract useful data for map-making.
		// Create "View Map / Driving Directions" Link.
		var oVCards  = Dom.getElementsByClassName('vcard');
		var i = oVCards.length; while (i--) { this.vCards.push(this.ParseHCard(oVCards[i])); }
		this.CreateLinks();
	},
	Popup: function(e) {
		var oTarget = Event.getTarget(e);
		var sURL    = oTarget.href;
		Event.stopEvent(e);
		window.open(sURL, 'Map', 'menubar=yes,scrollbars=yes,width=900,height=600');
	},
	ParseHCard: function(oCard) {
		// Need name, phone, address, city, state, and zip
		// Will use lat, lng if available
		var oName    = Dom.getElementsByClassName('fn',             null, oCard)[0];
		var oPhone   = Dom.getElementsByClassName('tel',            null, oCard)[0];
		var oAddress = Dom.getElementsByClassName('street-address', null, oCard)[0];
		var oCity    = Dom.getElementsByClassName('locality',       null, oCard)[0];
		var oState   = Dom.getElementsByClassName('region',         null, oCard)[0];
		var oZip     = Dom.getElementsByClassName('postal-code',    null, oCard)[0];
		var oLat     = Dom.getElementsByClassName('latitude',       null, oCard)[0];
		var oLng     = Dom.getElementsByClassName('longitude',      null, oCard)[0];
		var sName    = this.trimString(this.getInnerText(oName));
		var sPhone   = this.trimString(this.getInnerText(oPhone));
		var sAddress = this.trimString(this.getInnerText(oAddress));
		var sCity    = this.trimString(this.getInnerText(oCity));
		var sState   = this.trimString(this.getInnerText(oState));
		var sZip     = this.trimString(this.getInnerText(oZip));
		var sLat     = this.trimString(this.getInnerText(oLat));
		var sLng     = this.trimString(this.getInnerText(oLng));
		return {
			Name    : sName,
			Phone   : sPhone,
			Address : sAddress,
			City    : sCity,
			State   : sState,
			Zip     : sZip,
			Lat     : sLat,
			Lng     : sLng,
			Node    : oCard
		}
	},
	CreateLinks: function() {
		var oNode, oLink, iBottomMargin;
		var i = this.vCards.length; while(i--) {
			oNode = document.createElement('p');
			oNode.appendChild(document.createTextNode('View '));
				oLink = document.createElement('a');
				oLink.href = this.MapHREF(this.vCards[i]);
				oLink.appendChild(document.createTextNode('map'));
				Event.addListener(oLink, 'click', this.Popup);
			oNode.appendChild(oLink);
			oNode.appendChild(document.createTextNode(' / '));
				oLink = document.createElement('a');
				oLink.href = this.DirHREF(this.vCards[i]);
				oLink.appendChild(document.createTextNode('driving directions'));
				Event.addListener(oLink, 'click', this.Popup);
			oNode.appendChild(oLink);
			Dom.setStyle(oNode, 'marginTop', '0px');
			this.vCards[i].Node.appendChild(oNode);
		}
	},
	MapHREF: function(oCard) {
		var sURL = this.MapURL;
		if (oCard.Name.length > 0)  { sURL += '&user1=' + escape(oCard.Name);  }
		if (oCard.Phone.length > 0) { sURL += '&user2=' + escape(oCard.Phone); }
		if (oCard.Lat.length > 0 && oCard.Lng.length > 0) {
			sURL += '&lat=' + escape(oCard.Lat) + '&lng=' + escape(oCard.Lng);
		}
		sURL += '&address=' + escape(oCard.Address);
		sURL += '&city=' + escape(oCard.City);
		sURL += '&stateProvince=' + escape(oCard.State);
		sURL += '&postalCode=' + escape(oCard.Zip);
		sURL += '&HeaderFile=';
		sURL += '&StyleSheetfile=';
		sURL += '&documentTitle=' + escape(oCard.Name || 'Maps');
		return sURL;
	},
	DirHREF: function(oCard) {
		var sURL = this.DirURL;
		if (oCard.Name.length > 0)  { sURL += '&user1=' + escape(oCard.Name);  }
		if (oCard.Phone.length > 0) { sURL += '&user2=' + escape(oCard.Phone); }
		if (oCard.Lat.length > 0 && oCard.Lng.length > 0) {
			sURL += '&lat=' + escape(oCard.Lat) + '&lng=' + escape(oCard.Lng);
		}
		sURL += '&address=' + escape(oCard.Address);
		sURL += '&city=' + escape(oCard.City);
		sURL += '&stateProvince=' + escape(oCard.State);
		sURL += '&postalCode=' + escape(oCard.Zip);
		sURL += '&Headerfile=';
		sURL += '&StyleSheetfile=';
		sURL += '&documentTitle=' + escape(oCard.Name || 'Driving Directions');
		return sURL;
	},
	getInnerText: function(o) { // Utility function. Probably should be looking for title attributes too.
		if (!o) { return; }
		if (o.innerText) { return o.innerText; }
		var s = '';
		for (var i = 0; i < o.childNodes.length; i++) {
			switch(o.childNodes[i].nodeType) {
				case 1 : s += this.getInnerText(o.childNodes[i]); break;
				case 3 : s += o.childNodes[i].nodeValue;          break;
			}
		}
		return s.replace(/\xA0/g, ' '); // convert non-breaking spaces to spaces.
	},
	trimString: function(s) { // Utility function. Prolly should be somewhere else.
		if (!s) { return ''; }
		s = s.replace( /^\s+/g, '' );
		return s.replace( /\s+$/g, '');
	}
};

var Caritas = {
	Init: function() {
		Event.addListener(['layout_MapsDir', 'layout_QuickLinks'], 'change', PB.JumpSelect);
	}
}

Event.onDOMReady(Caritas.Init, Caritas, true);

function trimString(s) 
{ 
    if (!s) { return ''; }
        s = s.replace( /^\s+/g, '' );
        return s.replace( /\s+$/g, '');
}  

function validate_kw(frm)
{
    var keyWord = frm.layout_SearchField.value;
    
	if (trimString(keyWord).length < 2 )
		{
		if (trimString(keyWord).length == 1)
			{alert('Keywords must contain at least 2 characters.');
			 return false;}
		else {alert('You must enter at least one key word for this search.');
		     return false;}
		}
	return true;
}

function reasonForVisit(elem)
{
	if ( elem.options[elem.selectedIndex].value === 'Other, please specify')
	{
		document.getElementById('otherField').style.display = 'block';
	}
	else
	{
		document.getElementById('otherField').style.display = 'none';
	}
}

function checkAll(field)
{
	var x = field.length; while (x--) {
		field[x].checked = true;
	}
}

function uncheckAll(field)
{
	var x = field.length; while (x--) {
		field[x].checked = false;
	}
}

function querySt(name)
{
    var qStr = window.location.search.substring(1);
    var splitStr = qStr.split('&');
    for (i = 0; i < splitStr.length; i++) 
    {
        var ft = splitStr[i].split('=');
        if (ft[0] === name)
        {
            return ft[1];
        }
    }
}

function physName()
{
    var fName = querySt('physician');
    var mName = querySt('middle');
    var lName = querySt('last');
    var txtPhysName = document.getElementById('PhysicianPreferred');

    if (mName === '')
    {
        txtPhysName.value = (fName + ' ' + lName);
    } 
        else
    {
        txtPhysName.value = (fName + ' ' + mName + ' ' + lName);
    }
}
    
if (querySt('PageID') === 'OTH000259')
{ 
    Event.onDOMReady(physName);
}

function setDocRight()
{
	var d = document.getElementById("docright");
	
	if ( d !== null )
	{
		d.setAttribute("value", "Yes");
	}
}

function setEmailResponse()
{
	var d = document.getElementById("emailResponse");
	
	if ( d !== null)
	{
		d.setAttribute("value", "Yes");
	}
}

function doRedirectCheck()
{
	var aCookies = document.cookie.split(';');
	var sCookie, i = aCookies.length; 
	var hasCookie = false;
	
	while (i--)
	{
		sCookie = aCookies[i];
		while (sCookie.charAt(0) === ' ') 
		{
			sCookie = sCookie.substr(1); 
		}
	
		if (sCookie.indexOf('welcome') === 0)
		{ 
			hasCookie = true;
			break; 
		}
	}
	
	var callback = 
	{
		success: function(o)
		{
			if ( o.responseText === 'found' )
			{
				window.location = "http://www.caritaschristi.org/welcome.html";
			}
			else
			{
				var e = document.getElementById('blankit');
				
				if ( e !== null )
				{
					e.style.display = 'none';
				}
				
				if ( window.doQuiz )
				{
					doQuiz();
				}
			}
		},
		
		failure: function(o)
		{
			
		}
	}
	
	if ( hasCookie === false )
	{
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/subsitecheckthem.asp', callback);
	}
}

function blankit()
{
	// Because AJAX is used for the re-direct there is a small delay. This function just
	// creates a blank div to take up the entire screen so you don't have the site show
	// then get a redirect.

	var aCookies = document.cookie.split(';');
	var sCookie, i = aCookies.length; 
	var hasCookie = false;
	
	while (i--)
	{
		sCookie = aCookies[i];
		while (sCookie.charAt(0) === ' ') 
		{
			sCookie = sCookie.substr(1); 
		}
	
		if (sCookie.indexOf('welcome') === 0)
		{ 
			hasCookie = true;
			break; 
		}
	}
	
	var newDiv = document.createElement('div');
	
	newDiv.innerHTML = 'Loading....Please Wait';
	newDiv.id = 'blankit';
	newDiv.style.position = 'absolute';
	newDiv.style.top = '0px';
	newDiv.style.left = '0px';
	newDiv.style.backgroundColor = 'white';
	newDiv.style.height = screen.height + 'px';
	newDiv.style.width = screen.width + 'px';
	newDiv.style.zIndex = '10';
	
	if ( hasCookie === false )
	{
		document.body.appendChild(newDiv);
	}
}
