document.write('<style> .dummy {} </style>');	
document.write('<script src="/wwwroot/lib/csitools/2.0.2/slideshow.js"></script>');

Array.prototype.index = 0;
Array.prototype.incrementIndex = function(i) {
	if (!i) return this.index;
	if (this.length < 2)
		return this.index = 0;
	this.index = this.index+i;
	while (this.index < 0)
		this.index = this.length+this.index;
	while (this.index > (this.length-1))
		this.index = this.index - this.length;
	return this.index;
}

Number.prototype.format= function(d){
	var a,m,m2;
	var rgx = /(\d+)(\d{3})/;
	var d = d || 0;

	if (d){
		a = this.toString().split('.');
		a[1] = a[1] || '0'
		m = Math.pow(10,d)
		m2 = Math.pow(10,-(a[1].length-d))
		a[1] = (Math.round(a[1]*m2)/m).toString().substr(2)
		while (a[1].length < d) 
			a[1] += '0';
	}
 	else 
		a = [Math.round(this).toString()];

	while (rgx.test(a[0])) 
		a[0] = a[0].replace(rgx, '$1' + ',' + '$2');
	return a.join('.')
} 
CSI = {
	ding : function(){
		$('BGSOUND_ID').src = '/wwwroot/lib/csitools/2.0/ding/wav';
	}
	,print : function(str){
		var myWindow = window.open("", "myWindow", "toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width="+myAjaxBox.clientWidth+", height="+myAjaxBox.clientHeight)
		var myHtml = "<html><body onload='print();window.close();'>" + str + "</body></html>"
		myWindow.document.open()
		window.focus();
		myWindow.document.write(myHtml);
		myWindow.document.close();
	}
	,clearSelection : function(){
		if (document.selection)
			document.selection.clear();
		else if (window.getSelection)
			window.getSelection().removeAllRanges();
	}
	,domMethods : {
		scrollToView : function(elm){
			var telm = $(elm);
			var pause;
			var left=0;
			var top=0;
			outer:
			do {
				pause = telm;
				inner:
				while (telm && telm.tagName){
					if (telm.getStyle('overflowY')=='scroll')
						break outer;
					if (telm.parentNode == pause.offsetParent)
						break inner;
					telm = $(telm.parentNode);
				}
				left += pause.offsetLeft;
				top += pause.offsetTop;
				telm = $(telm.parentNode);
			} while (telm);
			
			if (telm){
				var x = (top+elm.offsetHeight) - ((telm.offsetHeight/2)+telm.scrollTop);
				if (x>0){
					telm.scrollTop += x;
				}
				else if (top < telm.scrollTop) {
					telm.scrollTop = top;
				}
			}
			return elm;
		}
	}
	,arrayMethods : {
		hasAll : function(val){
			if (typeof(val) == 'number')
				val = [val];
			if (!val.length)
				return false;
			for (var i = 0;i<val.length;i++)
				if (!(personAuths.indexOf(val[i])+1))
					return false;
			return true;
		}
		,uniq : function(property){
			var a = [];
			for (var i=0;i<this.length;i++)
				if (a.indexOf(this[i]) == -1)
					a.push(this[i]);
			return (a.length==this.length) ? this : a;
		}
	}
	,dateMethods : {
		startOfMonth : function(){
			return new Date(this.getFullYear(), this.getMonth(), 1)
		}
		,endOfMonth : function(){
			return new Date(this.getFullYear(), this.getMonth()+1, 0)
		}
		,add : function (sInterval, iNum){
			var d = new Date();
			d.setTime(this.getTime());
			if (sInterval && iNum){
				switch (sInterval.toLowerCase()){
					case "ms":
					case "millisecond":
						d.setMilliseconds(d.getMilliseconds() + iNum);
						break;
					case "s":
					case "second":
						d.setSeconds(d.getSeconds() + iNum);
						break;
					case "mi":
					case "minute":
						d.setMinutes(d.getMinutes() + iNum);
						break;
					case "h":
					case "hour":
						d.setHours(d.getHours() + iNum);
						break;
					case "d":
						d.setDate(d.getDate() + iNum);
						break;
					case "mo":
					case "month":
						d.setMonth(d.getMonth() + iNum);
						break;
					case "y":
						d.setFullYear(d.getFullYear() + iNum);
						break;
				}
				return d;
			}
			else
				return undefined;
		}
	}


	,updPrefs : function (aid,b){    // b = true = Option is on,   b = false = option is off.
		if (!window.aids) 
			return;
		new Ajax.Request('updPersonAttributes.php',{
			parameters : {aid : aid, on : b}
			,onException : function(t,e){alert(e.message)}
		});
		if (b)
			aids.push(aid);
		else
			aids = aids.without(aid);
	}
	
	,isEmpty : function(obj){
		return objToString(obj) == '{}'
	}

	,iMsgTillCancelled : function(){
		var msgs = [];
		var mtcf;
		var cancelCkBx;
		var button;
		
		return function (aid){
			if (aids.indexOf(aid) > -1){
				return;
			}
			
			var mtcf;
			if (!mtcf){
				mtcf = createForm();
				var b = mtcf.footer.getElementsByTagName('button')[0];
				b.innerHTML = 'OK'
				var cbDiv = mtcf.footer.insertBefore($(document.createElement('div')),b);
				cbDiv.innerHTML = '<input type="checkbox" class="cancel"><span onclick="this.previousSibling.click();" style="cursor:pointer">Don\'t Show this message Again</span>';
				cbDiv.style.lineHeight = '1px'
				cbDiv.style.cssFloat = cbDiv.style.styleFloat = 'left';
				var k = mtcf.cancelCkBx = cbDiv.getElementsByClassName('cancel')[0];
				k.setStyle({position:'relative',top:'3px'});
				mtcf.setTitle('<span style="color:#ff0033;fontWeight:bold">Important Information!</span>')
				cancelCkBx = mtcf.footer.getElementsByTagName('input')[0];
				button = mtcf.footer.getElementsByTagName('button')[0];
				mtcf.onEnterKey = function(){
					if (cancelCkBx.checked)
						CSI.updPrefs(aid,true);
					this.close()
				}
			}
			
			cancelCkBx.checked = false;
			
			if (msgs[aid]){
				mtcf.formBody.innerHTML = msgs[aid];
				setTimeout(function(){mtcf.push().center();button.focus();},170);
			}
			else {
				new Ajax.Request('getMsg.php',{
					parameters : {aid:aid}
					,onSuccess : function(t){
						msgs[aid] = t.responseText;
						mtcf.formBody.innerHTML = t.responseText;
						mtcf.push().center();
						setTimeout(function(){button.focus()},70);
					}
					,onException : function (t,e){alert('Xcept44:'+e.message)}
				})
			}
		}
		return;
	}()
	,jsToPhpDate : function(d){
		return d.getFullYear()+'-'+padZero((d.getMonth()+1),2)+'-'+padZero(d.getDate(),2);
	}
	,formatDate : function (d,optObj){
		optObj = optObj || {};
		var y;
		if (!d || !d.getDate) 
			return '';
		if (optObj.yr2digit){
			y = d.getFullYear().toString().substr(2,2);
		}
		
		else {
			y = d.getFullYear()
		}
		return padZero((d.getMonth()+1),2)+'/'+padZero(d.getDate(),2)+'/'+y
	}
	,formatTime : function (d){
		if (!d || !d.getDate) 
			return '';
		var h = d.getHours()
		var p = (h > 11) ? ' pm' : ' am';
		
		if (h > 12)
			h -= 12;
		if (h == 0)
			h = 12;
		return h+':'+ padZero(d.getMinutes(),2)+p
	}
	,formToPhpDate : function(formDate){
		if (formDate == 'mm/dd/yyyy' || formDate == 'mm/dd/yy' || formDate == "")
			return '';
		var a = formDate.split('/');
		var y;
		if ((y = parseInt(a[2])) < 100){
			if (y > 30)
				y += 1900;
			else
				y+= 2000;
		}
		return y+'-'+padZero(a[0],2)+'-'+padZero(a[1],2);
	}
	,getVisibility : function(elm){
		var v = false;
		var done = false;
		elm = $(elm);
		while (elm && elm.getStyle){  //!elm.readAttribute('visibility'))
			if (elm.getStyle('visibility') == 'hidden' || elm.getStyle('display') == 'none')
				return false
			else if (elm.getStyle('visibility') == 'visible' || elm.getStyle('display') == 'block')
				return true;
			elm = $(elm.parentNode)
		}	
		return true;
	}
	,mouseCoords : function(ev){
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	}
	,getMouseOffset : function (target, ev){
		e = ev || window.event;
		var docPos    = CSI.getPosition(target);
		var mousePos  = CSI.mouseCoords(ev);
		return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
	}
		
	,getPosition : function(e){
		var left = 0;
		var top  = 0;
		while (e.offsetParent){
			left += e.offsetLeft;
			top  += e.offsetTop;
			e     = e.offsetParent;
		}
		left += e.offsetLeft;
		top  += e.offsetTop;
		return {x:left, y:top};
	}
	
	,UP_ARROW : '&#9650'
	,DOWN_ARROW : '&#9660'
	,RIGHT_ARROW : '&#9658'
	,LEFT_ARROW : '&#9668'
	
	,getSelectedText : function () {
		return (document.selection) ? document.selection : (window.getSelection || document.getSelection)();
	}
	
	/* --------------------------------------------------------------------
	   Auto-Suggest feature:  optObj = {field:elementToAdd, searchFunction:localFunctionName} 
	   This will attach a results Div to the field you are adding auto-auggest for and attach the
	   event handlers for the different keypresses that are possible - Will Zablocki 12/2010

	   These are the different options that can be passed.
	   elm = element having auto-suggest added (required),
	   name = a name to assign to a hidden input to store the clicked result's value (optional),
	   searchFunction = local JS function that returns the result set for the autoSuggest box (required),
	   overrideCSS = override style sheet object for suggestion box results, pass highlightColor in the obj
		   to override the row highlight color.
	   suggestionHint = Pass the grayed out suggestion hint that will display in the subject elm
	   ---------------------------------------------------------------------
	*/
	,autoSuggest : function (optObj) {
		var elm = optObj.field;
		/* Cannot add an autoSuggest box twice, "overwrite" the first one */
		if (elm.getAttribute('autoSuggest')) $$('.autoSuggest')[0].remove();

		/* set up the element */
		elm.setAttribute('autoSuggest','true');
		elm.setAttribute('autocomplete','off');

		var elmHeight = elm.getHeight();
		var elmWidth = elm.getWidth();
		
		var widthCSStype = (elm.naturalWidth) ? 'minWidth' : 'width';

		/* Default CSS Attributes for Auto Suggest Results Div.  Can be overridden by passing overrideCSS to CSI.autoSuggest() */
		var autoSuggestCSS = {position:'absolute', backgroundColor:'#FFF', top:elmHeight+'px', 
						left:elm.offsetLeft+'px', zIndex:'+500', widthCSStype:(elmWidth-1)+'px', display:'inline',
						overflowY:'scroll', visibility:'hidden', whiteSpace:'nowrap', fontSize: '12px', 
						cursor: 'pointer', padding:'0px', maxHeight:(document.viewport.getHeight() - (elm.cumulativeOffset().top + elm.getHeight())) + 'px'};

		optObj.overrideCSS = optObj.overrideCSS || {};
		var autoSuggestCSS = Object.extend(autoSuggestCSS, optObj.overrideCSS);
		CSSRule('.autoSuggest', autoSuggestCSS);

		/* Handle the highlighting/unhighlighting of the result row */
			/*If they pass a highlightColor in the overrideCSS or use default */
		var highlightColor = optObj.overrideCSS.highlightColor || '#CCFFFF';
		CSSRule('.selectedElement', {backgroundColor:highlightColor});

		var searchFunction = optObj.searchFunction || {};
		elm.parentNode.style.position = elm.style.position = 'absolute';
		elm.parentNode.style.width = elm.style.width = 'auto';

		/* SET UP THE RESULTS DIV */
		var resultsDiv = document.createElement('div');
		resultsDiv.className = 'autoSuggest';
//			resultsDiv.setAttribute('height', (document.viewport.getHeight() - (elm.cumulativeOffset().top + elm.getHeight())) + 'px');
		$(elm.parentNode).insertBefore(resultsDiv, elm);

		/* If they pass a name, the record rows should set the value when clicked */
		if (optObj.valueField.name) {
			elm.setAttribute('valueField', optObj.valueField.name);
			var valueField = document.createElement('input');
			valueField.setAttribute('type', 'hidden');
			valueField.name = optObj.valueField.name;
			if (optObj.valueField.defaultVal) {
				valueField.setAttribute('value', optObj.valueField.defaultVal);
			}
			elm.parentNode.appendChild(valueField);
		}
		
		var suggestionHint = optObj.suggestionHint || 'Type to search';
		var suggestionCSS = {position:'absolute', backgroundColor:'transparent', top:elm.offsetTop+'px', left:elm.offsetLeft+'px', color:'#999999',
						height:elm.getHeight()+'px', width:elm.getWidth()+'px', cursor: 'selection', zIndex:+1, padding:'3px'};

		var suggestionDiv = document.createElement('div');
		CSSRule('.suggestionHint', suggestionCSS);
		suggestionDiv.className = 'suggestionHint';
		
		suggestionDiv.innerHTML = optObj.suggestionHint || 'Type to search';
		elm.parentNode.appendChild(suggestionDiv);
		Event.observe(suggestionDiv, 'click', function () {elm.focus()});

		/* if it already has a value hide the suggestionDiv */
		if (elm.value > '') {
			suggestionDiv.style.visibility = 'hidden';
		}

		/* Assign the Search function passed as a method of the input element */
		elm.search = function (searchString) {
			var recordSet = searchFunction(searchString);
			if (searchString > '' && recordSet) {
				this.innerHTML = '';
				this.style.visibility = 'visible';
				this.appendChild(recordSet);
				this.style.height = recordSet.getAttribute('totalHeight');
				this.style.width = recordSet.getAttribute('totalWidth');
				try{
					$(recordSet.firstChild).addClassName('selectedElement');
				}
				catch(err){
					/*For When no results are returned*/
				}
				for (var i=0;i<=recordSet.childNodes.length-1;i++) {
					/* this is for the event observes on the result row elements */
					Event.observe(recordSet.childNodes[i], 'click', function () {
						resultsDiv.nextSibling.value = this.getAttribute('rowText');
						if (elm.nextSibling) elm.nextSibling.value = this.getAttribute('value');
						resultsDiv.style.visibility = 'hidden';
						$$('.selectedElement')[0].removeClassName('selectedElement');
						if(optObj.callBackFunction){
							optObj.callBackFunction(this.getAttribute('value'));	
						}
					}.bind(recordSet.childNodes[i].firstChild));
					Event.observe(recordSet.childNodes[i], 'selection:enterKey', function () {
						resultsDiv.nextSibling.value = this.getAttribute('rowText');
						if (elm.nextSibling) elm.nextSibling.value = this.getAttribute('value');
						resultsDiv.style.visibility = 'hidden';
						$$('.selectedElement')[0].removeClassName('selectedElement');
						if(optObj.callBackFunction){
							optObj.callBackFunction(this.getAttribute('value'));	
						}
					}.bind(recordSet.childNodes[i].firstChild));
					Event.observe(recordSet.childNodes[i], 'mousemove', function () {
						if ($$('.selectedElement')[0]) $$('.selectedElement')[0].removeClassName('selectedElement');
						this.addClassName('selectedElement');
					}.bind(recordSet.childNodes[i]));
				}
			} else {
				resultsDiv.style.visibility = 'hidden';
				suggestionDiv.style.visibility = 'visible';
				if ($$('.selectedElement')[0]) $$('.selectedElement')[0].removeClassName('selectedElement');
			}
		}.bind(resultsDiv);

		/* Handle the keypress events for the tab and enter, these fire differently and need to be handled first */
		Event.observe(elm, 'keydown', function (event) {
			isShowingBox = (resultsDiv.style.visibility == 'visible') ? true : false;
			if(event.keyCode == 8 && elm.value == ''){
				resultsDiv.style.visibility = 'hidden';
				suggestionDiv.style.visibility = 'visible';
				return;
			}
			
			switch (event.keyCode) {
				case Event.KEY_RETURN:
					try{
						if (!isShowingBox) break;
						event.stop();//Cancel the enter key so we dont submit the form, then fire my own enter key event
						$$('.selectedElement')[0].fire('selection:enterKey');
						break;
					}
					catch(err){
						break;	
					}
				case Event.KEY_TAB:
					try{
						if (!isShowingBox) break;
						$$('.selectedElement')[0].fire('selection:enterKey');
						break;
					}
					catch(err){
						break;	
					}
				/* I created my own event observe above and fire a custom event called selection:enterKey for return and tab */
				case Event.KEY_DOWN:
					try{
						if (!isShowingBox) break;
						var nextElement = $$('.selectedElement')[0].nextSibling || $$('.selectedElement')[0];
						$$('.selectedElement')[0].removeClassName('selectedElement');
						nextElement.addClassName('selectedElement');
						if (nextElement.cumulativeOffset().top > resultsDiv.scrollTop + resultsDiv.cumulativeOffset().top +  resultsDiv.getHeight() - 14) {
							resultsDiv.scrollTop += nextElement.getHeight() +2;
						}
						break;
					}
					catch(err){
						break;	
					}
				case Event.KEY_UP:
					try{
						if (!isShowingBox) break;
						var prevElement = $$('.selectedElement')[0].previousSibling || $$('.selectedElement')[0];
						$$('.selectedElement')[0].removeClassName('selectedElement');
						prevElement.addClassName('selectedElement');
						if (prevElement.cumulativeOffset().top - resultsDiv.scrollTop < resultsDiv.cumulativeOffset().top) {
							resultsDiv.scrollTop -= prevElement.getHeight() + 2;
						}
						break;
					}
					catch(err){
						break;	
					}
				default:
					if ((event.keyCode >= 48 && event.keyCode <= 90) || (event.keyCode >= 186 && event.keyCode <= 222) || (event.keyCode >= 96 && event.keyCode <= 111)) {
						suggestionDiv.style.visibility = 'hidden';
					}
			}
		});

		/* Handle the keypress events for the records */
		Event.observe(elm, 'keyup', function (event) {
			isShowingBox = (resultsDiv.style.visibility == 'visible') ? true : false;
			if(event.keyCode == 8 && elm.value == ''){
				resultsDiv.style.visibility = 'hidden';
				suggestionDiv.style.visibility = 'visible';
				return;
			}
			
			switch (event.keyCode) {
				case Event.KEY_BACKSPACE:
					if(this.value != ''){
						this.search(elm.value.replace(/\\/gi,'\\\\'));
						break;
					}
				default:
					if ((event.keyCode >= 48 && event.keyCode <= 90) || (event.keyCode >= 186 && event.keyCode <= 222) || (event.keyCode >= 96 && event.keyCode <= 111) && this.value != '') {
						this.search(this.value.replace(/\\/gi,'\\\\'));
					}
					else if(event.keyCode == 40 && !isShowingBox){
						this.search(' ');   
					}
					break;
			}
		});
		Event.observe(document.body, 'click', function(){
			  resultsDiv.style.visibility = 'hidden';
			  //suggestionDiv.style.visibility = 'visible';
			  elm.value = '';
		});
	}
	,mailtoForm : function (optObj) {
		var optObj = optObj || {};
		//Email Required
		if(!optObj.email) {
			alert("mailtoForm must be passed an email");
			
		}
		//if sent a subject then text, if not inputbox
		if(!optObj.subject){
			var subject = '<tr><tr><td align="right" style="color: red; font-weight: bold; vertical-align: top;">*</td><td>Subject:</td><td align="right"><input id="subj" size="37" maxlength="50"></td></tr>';	
		} else {
			var subject ='<tr><td></td><td>Subject:</td><td id="subj"><b>'+optObj.subject+'</b></td></tr>';
		}
		//if show email is false email will be kept private
		var showEmail = '<center><tr><td></td><td colspan="2" align="right"><font size="3pt">To:&nbsp;&nbsp;</td><td id="mailTo"><b>'+optObj.email+'</b></font></td></tr></center><br><br>';
		if(optObj.showEmail){
			if(optObj.showEmail == 'false') showEmail = '';
		}
		if (!window.messageBox){
			if(!optObj.innerHTML) {
				var iHTML = ['<center>'];
				iHTML.push(showEmail);
				iHTML.push('<table style="font-family: Verdana,Arial; font-size: 11px; vertical-align: top;" cellspacing="0">');
				iHTML.push('<tr><td align="right" style="color: red; font-weight: bold;">*</td><td>Your Name:</td><td align="right"><input id="replyName" size="37" maxlength="50"></td></tr>');
				iHTML.push('<tr><td align="right" style="color: red; font-weight: bold;">*</td><td>Your Email:</td><td align="right"><input id="replyEmail" size="37" maxlength="50"></td></tr>');
				iHTML.push('<tr><td align="right" style="color: red; font-weight: bold;">*</td><td>Confirm Email:</td><td align="right"><input id="confirmReplyEmail" size="37" maxlength="50"></td></tr>');
				iHTML.push('<tr><td></td><td>Your Phone:</td><td align="right"><input id="replyPhone" size="37" maxlength="30"></td></tr>');
				iHTML.push('<tr><td>&nbsp;</td></tr>'+subject);
				iHTML.push('<tr><td align="right" style="color: red; font-weight: bold; vertical-align: top;">*</td><td colspan="2"><textarea rows="5" cols="40" id="msg"></textarea></td></tr></table><br>');
				iHTML.push('<div style="font-size: 10px; padding-bottom: 12px; text-align: center; font-style: italic;">Items marked with <span align="right" style="color: red; font-weight: bold;">*</span> are Required</div></center>');
	
				optObj.innerHTML = 	iHTML.join('');
				
			}	
			var messageBox = createForm(optObj);	
			messageBox.setTitle(optObj.title || 'Send Message');
			messageBox.button.innerHTML = optObj.buttontext || 'Send';
	
			if(optObj.width) messageBox.style.width = optObj.width;
			if(optObj.titleStyle) messageBox.setTitle(optObj.title || 'Send Message',optObj.titleStyle);
	
			messageBox.onEnterKey = function() {
				if((testEmails(messageBox.form.replyEmail.value) == false)&& messageBox.form.replyEmail.value != '' ){
					alert(messageBox.form.replyEmail.value + " is not a valid email address.Please correct");
				}
				else if(messageBox.form.replyEmail.value == ''){
					//test reply email
					alert("Please enter your email address");
				}
				else if(messageBox.form.replyEmail.value != messageBox.form.confirmReplyEmail.value){
					alert("The confirm email address does not match");
				}
				//test phone
				else if((testPhone(messageBox.form.replyPhone.value) == false)&& messageBox.form.replyPhone.value != '' ){
					alert(messageBox.form.replyPhone.value + " is not a valid phone number.\nPlease correct or leave the Phone Number box empty\n\n*Area code must be inside parentheses");
				}
				//if no message
				else if(messageBox.form.msg.value == ''){
					alert("Please enter a message");	
				}
				else{
					optObj.replyName = messageBox.form.replyName.value;
					optObj.replyEmail = messageBox.form.replyEmail.value;
					optObj.replyPhone = messageBox.form.replyPhone.value;
					if(!optObj.subject){
					optObj.subject = messageBox.form.subj.value;
					}
					optObj.message = messageBox.form.msg.value;
					var url ='/wwwroot/lib/ajax/sendEmail.cfm';
					var params = optObj;
					var myAjax = new Ajax.Request(url,{
						method: 'post',
						parameters: Object.toQueryString(params),
						onSuccess: function () {
							alert('Email sent successfully');
							if(!optObj.leaveOnSend) {
								messageBox.close();
							} else {
								history.go(-1);
							}
						}
					});
				}
			};
		}
		(optObj.position && optObj.postiton != 'center') ? messageBox.show().position(optObj.position) : messageBox.show().center();
		return messageBox;
	}
	,createMultiSelect : function (optArr, optObj) {
		var _cols		  = optObj.cols || 1;
		var _height 	  = optObj.height || 'auto';
		var _width   	  = optObj.width || '160px';
		var _name 		  = optObj.name || '';
		var _hint		  = optObj.hint || '';
		var _type		  = optObj.type || 'checkbox';
		var _selectAll    = optObj.selectAll || false;
		var _formStyle	  = {background: '#e3e4e8', border: '1px solid #0b2a32', overflowX: 'hidden', overflowY: 'auto'};
		var _cxSelStyle   = {background: '#576c86', color: '#fff'};
		var _cxOverStyle  = {background: '#bbb'};
		var _headerStyle  = {backgroundColor:'#143F4E',color:'white', padding: '0px 0px 0px 5px'};
		var _chkDivStyle  = {};
		var _onChange 	  = optObj.onChange || function () {};
		var _onClose   	  = optObj.onClose  || function () {};
		
		var d1	   = document.createElement('div');
		var hDiv   = document.createElement('div');
		var iWrap  = document.createElement('div');
		var input  = document.createElement('input');
		var cDiv   = document.createElement('div');
		var cDiv2  = document.createElement('div');
		var cTable = document.createElement('table');
		var cTr    = document.createElement('tr');
		
		d1.iVals 		= [];
		d1.selected 	= [];
		d1.unselected   = [];
		d1.prevSelected = [];
		
		Object.extend(_chkDivStyle, optObj.checkDivStyle || {});
		Object.extend(_formStyle  , optObj.formStyle || {});
		Object.extend(_cxOverStyle, optObj.mouseOverStyle || {});
		Object.extend(_cxSelStyle , optObj.selectedOptStyle || {});
		Object.extend(_headerStyle, optObj.headerStyle || {});
		
		CSSRule('.cxSelected', _cxSelStyle);
		CSSRule('.cxOver', _cxOverStyle);
		
		// wrapper div
		d1.style.position = 'relative';
		d1.style.fontSize = '0.9em';
		d1.style.width    = parseInt(_width, 10) - 20 + 'px';
		d1.optArr         = optArr;
		
		// input select arrow
		var selImg = new Image(17,20);
		selImg.src = 'http://dev.comsoftinc.com/remaint/publicsearch/images/selectButtonOut.png';
		var selImgOver = new Image(17,20);
		selImgOver.src = 'http://dev.comsoftinc.com/remaint/publicsearch/images/selectButtonOver.png';
		
		function addMouseEvents (elm) {
			Event.observe(elm, 'mouseenter', function () {
				selImg.src = 'http://dev.comsoftinc.com/remaint/publicsearch/images/selectButtonOver.png';
			});
			Event.observe(elm, 'mouseleave', function () {
				selImg.src = 'http://dev.comsoftinc.com/remaint/publicsearch/images/selectButtonOut.png';
			});
			
			Event.observe(elm, 'click', function () {
				if (cDiv.style.visibility == 'hidden') {
					
					hDiv.style.display = _selectAll == true ? 'block' : 'none';
					
					setTimeout(function () {
					
						var borderW = (parseInt(cDiv2.style.borderLeftWidth, 10) + parseInt(cDiv2.style.borderRightWidth, 10));
						var borderH = (parseInt(cDiv2.style.borderTopWidth, 10) + parseInt(cDiv2.style.borderBottomWidth, 10));
						
						if (cDiv.getWidth() < input.getWidth()) {
							var width = (parseInt(_width, 10) - borderW);
							cDiv2.style.width = cTable.style.width = width + 'px';
						} else {
							cDiv2.style.width = 'auto';
						}
						
						var headerH = hDiv.getHeight();
						var inputW  = input.getWidth();
						var inputH  = input.getHeight();
						var cDiv2W  = cDiv2.getWidth();
						var cDivW   = cDiv.getWidth();
						var cDivH   = cDiv.getHeight();
						var inputLeft   = Math.ceil(input.viewportOffset().left);
						var inputTop    = Math.ceil(input.viewportOffset().top);
						var inputRight  = Math.ceil(document.viewport.getWidth() - inputLeft);
						var inputBottom = Math.ceil(document.viewport.getHeight() - inputTop - inputH);
						
						// fit bottom
						if (cDivH < inputBottom) {
							cDiv.style.top = inputH + 'px';
						}
						// fit top
						else if (cDivH < inputTop) {
							cDiv.style.top = -(cDiv.getHeight()) + 'px';
						}
						// fit bottom with scrollbar
						else if (inputBottom > (document.viewport.getHeight() / 3)) {
							cDiv2.style.height = (inputBottom - borderH - headerH - 5) + 'px';
							cDiv2.style.width  = (cDiv2W + 15) + 'px';
							cDiv.style.top     = inputH + 'px';
						}
						// fit top with scrollbar
						else {
							cDiv2.style.height = (inputTop - borderH - headerH - 5) + 'px';
							cDiv2.style.width  = (cDiv2W + 15) + 'px';
							cDiv.style.top     = -(cDiv.getHeight()) + 'px';
						}
						
						// fit right
						if (cDivW < inputRight) {
							cDiv.style.left = '0px';
						}
						// fit left
						else if (cDivW <= (inputLeft + inputW)) {
							cDiv.style.left = -(cDiv2.getWidth() - inputW) + 'px';
						}
						
						cDiv.style.visibility = 'visible';
						
					}, 20);
					
				} else {
				
					cDiv.style.visibility = 'hidden';
					cDiv2.style.height    = 'auto';
					cDiv2.style.width     = 'auto';
					setTimeout(_close, 5);
				}
			});
		}
		addMouseEvents(input);
		addMouseEvents(selImg);
		
		d1.style.marginRight = (parseInt(selImg.width) + 5) + 'px';
		
		selImg.style.display = 'inline';
		selImg.style.margin  = '0px 0px -5px 0px';
		selImg.style.marginLeft = -parseInt(selImg.width, 10) + 'px';
		
		iWrap.style.whiteSpace = 'nowrap';
		iWrap.style.width = parseInt(_width, 10) + 'px';
		
		input.style.cursor = 'default';
		input.style.width  = (parseInt(_width, 10) - 6) + 'px';
		input.setAttribute('readonly','readonly');
		
		// header div
		hDiv.setStyle(_headerStyle);
		hDiv.style.display = 'none';
		
		// select all, select none, & done options
		var allSpan  = document.createElement('span');
		var noneSpan = document.createElement('span');
		var doneSpan = document.createElement('span');
		
		hDiv.style.paddingTop = '2px';
		hDiv.style.paddingBottom = '2px';
		
		noneSpan.style.marginLeft  = '10px';
		doneSpan.style.cssFloat    = 'right';
		doneSpan.style.styleFloat  = 'right';
		doneSpan.style.marginRight = '5px';
		allSpan.style.cursor  = 'pointer';
		noneSpan.style.cursor = 'pointer';
		doneSpan.style.cursor = 'pointer';
		allSpan.style.textDecoration  = 'underline';
		noneSpan.style.textDecoration = 'underline';
		doneSpan.style.textDecoration = 'underline';
		
		allSpan.innerHTML  = 'All';
		noneSpan.innerHTML = 'None';
		doneSpan.innerHTML = 'Done';

		hDiv.appendChild(allSpan);
		hDiv.appendChild(noneSpan);
		hDiv.appendChild(doneSpan);
		
		// select all
		Event.observe(allSpan, 'click', function () {
			d1.selected   = [];
			d1.unselected = [];
			d1.iVals      = [];
			
			// loop through check divs
			$A(cTr.getElementsByTagName('div')).each(function (chkDiv) {
				chkDiv.firstChild.checked = 'checked';
				chkDiv.firstChild.setAttribute('checked', 'checked');
				chkDiv.addClassName('cxSelected');
				d1.iVals.push(chkDiv.firstChild.nextSibling.innerHTML);
				
				var val = chkDiv.firstChild.value;
				// val should have the same type as the value in the input array
				for (var i=0;i<d1.optArr.length;i++){
					if (val == d1.optArr[i].value.toString()) {
						if (typeof d1.optArr[i].value == 'number'){
							val = Number(val);
						}
						break;
					}
				}
				d1.selected.push(val);
			});
			
			_setInput();
		});
		
		// deselect all
		Event.observe(noneSpan, 'click', function () {
			d1.selected   = [];
			d1.unselected = [];
			d1.iVals      = [];

			// loop through check divs
			$A(cTr.getElementsByTagName('div')).each(function (chkDiv) {
				chkDiv.firstChild.checked = false;
				chkDiv.firstChild.removeAttribute('checked');
				chkDiv.removeClassName('cxSelected');
				
				var val = chkDiv.firstChild.value;
				// val should have the same type as the value in the input array
				for (var i=0;i<d1.optArr.length;i++){
					if (val == d1.optArr[i].value.toString()) {
						if (typeof d1.optArr[i].value === 'number'){
							val = Number(val);
						}
						break;
					}
				}
				d1.unselected.push(val);
			});
			
			_setInput();
		});
		
		// close drop down menu
		Event.observe(doneSpan, 'click', function () {
			cDiv.style.visibility = 'hidden';
			cDiv2.style.height    = 'auto';
			cDiv2.style.width     = 'auto';
			setTimeout(_close, 5);
		});
		
		// div that holds the form & table
		cDiv.style.position = 'absolute';
		cDiv.style.zIndex = 1;
		
		// Chrome spacing issue
		if (Prototype.Browser.WebKit) {
			input.style.width = (parseInt(_width, 10) - 4) + 'px';
		}

		Object.extend(cDiv2.style, _formStyle);
		
		// table for the form
		cTable.setAttribute('cellspacing',0);
		cTable.setAttribute('cellpadding',0);
		cTable.style.width = cDiv2.style.width;
		
		iWrap.appendChild(input);
		iWrap.appendChild(selImg);
		d1.appendChild(iWrap);
		d1.appendChild(cDiv);
		cTable.appendChild(cTr);
		cDiv2.appendChild(cTable);
		cDiv.appendChild(hDiv);
		cDiv.appendChild(cDiv2);
		
		cDiv.style.visibility = 'hidden';

		function _buildForm (optArr) {

			var last = 0;
			var rows = Math.ceil(optArr.length / _cols);

			// loop through the specified number of columns
			for (var i = 0; i < _cols; i++) {
				
				var cTd    = document.createElement('td');
				cTd.setAttribute('valign', 'top');
				
				// loop through options array
				for (var ii = 0; ii < rows; ii++) {
					
					if (last >= optArr.length) continue;
					
					var elm = optArr[last];
					
					var d2   = document.createElement('div');
					var st   = document.createElement('span');
					var cx   = document.createElement('input');
					var str  = elm.text;
					var val  = elm.value;
					
					d2.style.paddingRight = '5px';
					d2.style.whiteSpace   = 'nowrap';
					d2.style.cursor 	  = 'pointer';
					st.style.cursor 	  = 'pointer';
					cx.style.cursor 	  = 'pointer';
					
					Object.extend(d2.style, _chkDivStyle);
					
					cx.type 	 = _type;
					cx.value 	 = val;
					st.innerHTML = str;
					if (_name && _name != '') {
						cx.setAttribute('name', _name);
					}
					
					if (elm.checked) {
						cx.checked = 'checked';
						cx.setAttribute('checked', 'checked');
						
						d2.addClassName('cxSelected');
						d1.iVals.push(str);
						d1.selected.push(val);
						d1.prevSelected.push(val);
					} else {
						d1.unselected.push(val);
					}
					
					d2.appendChild(cx);
					d2.appendChild(st);
					
					Event.observe(d2, 'click', function () {
						this.removeClassName('cxOver');
						this.toggleClassName('cxSelected');
						
						var elm = this.childElements()[1];
						var cx  = elm.previousSibling;
						var str = elm.innerHTML;
						var val = cx.value;
						
						// val should have the same type as the value in the input array
						for (var i=0;i<d1.optArr.length;i++){
							if (val == d1.optArr[i].value.toString()) {
								if (typeof d1.optArr[i].value == 'number'){
									val = Number(val);
								}
								break;
							}
						}

						var ckd = this.firstChild.checked = this.hasClassName('cxSelected');
						
						if (ckd) {
							if (d1.selected.indexOf(val) == -1) {
								d1.iVals.push(str);
								d1.selected.push(val)
								d1.unselected.splice(d1.unselected.indexOf(val), 1);
							}
						} else {
							if (d1.selected.indexOf(val) != -1) {
								d1.iVals.splice(d1.iVals.indexOf(str), 1);
								d1.selected.splice(d1.selected.indexOf(val), 1);
								d1.unselected.push(val);
							}
							this.addClassName('cxOver');
						}
						
						_setInput();
					});
					
					Event.observe(d2, 'mouseenter', function () {
						if (!this.firstChild.checked) {
							this.addClassName('cxOver');
						}
					});
					Event.observe(d2, 'mouseleave', function () {
						this.removeClassName('cxOver');
					});
					
					cTd.appendChild(d2);
					
					last++;
				}
				
				cTr.appendChild(cTd);
			}
			
			_setInput();
		}
		
		function _setInput () {
			var a1 = [];
			var a2 = [];
			var a3 = [];
			for (var i=0;i<d1.optArr.length;i++){
				if (d1.selected.indexOf(d1.optArr[i].value)+1){
					a1.push(d1.optArr[i].value);
					a2.push(d1.optArr[i].text);
				}
				else {
					a3.push(d1.optArr[i].value);
				}
			}
			d1.selected   = a1;
			d1.text       = d1.iVals = a2;
			d1.unselected = a3;
			
			// all selected
			if (d1.unselected.length == 0 && d1.selected.length != 0) {
				input.title = input.value = optObj.allHint || d1.iVals.join(', ');
				input.style.color = optObj.allHint ? 'gray' : '#000';
			}
			// some selected
			else if (d1.selected.length != 0) {
				input.value = d1.iVals.join(', ');
				input.title = input.value;
				input.style.color = '#000';
			}
			// none selected
			else {
				input.value = _hint;
				input.title = _hint;
				input.style.color = 'gray';
			}
		}
		
		function _resetOpt (optArr, optObj) {
			
			cTr.childElements().invoke('remove');
			d1.optArr = optArr;
			if (optObj) {
				_cols		 = optObj.cols || _cols;
				_type		 = optObj.type || _type;
				_selectAll   = optObj.selectAll != undefined ? optObj.selectAll : _selectAll;
				_headerStyle = {backgroundColor:'#143F4E',color:'white', padding: '0px 0px 0px 5px'};
				_chkDivStyle = {};

				Object.extend(_chkDivStyle, optObj.checkDivStyle || {});
				Object.extend(_headerStyle, optObj.headerStyle   || {});
			}
			
			cDiv2.style.width  = 'auto';
			cDiv2.style.height = 'auto';
			
			d1.iVals		= [];
			d1.prevSelected = [];
			d1.selected   	= [];
			d1.unselected 	= [];
			
			_buildForm(optArr);
			
			_onChange();
		}
		
		function _close () {
			
			if (_onClose) {
				_onClose();
			}
			
			var tempSelected = [];
			var changed = false;
			for (var i=0;i<d1.selected.length;i++){
				if (!(d1.prevSelected.indexOf(d1.selected[i])+1)) {
					changed = true;	
				}
				tempSelected.push(d1.selected[i]);
			}
			
			if (changed || (d1.prevSelected.length != d1.selected.length)){
				d1.prevSelected = tempSelected;
				_onChange();
			}
		}
		
		_buildForm(optArr);
		
		Object.extend(d1, {
			 onClose	  : _onClose
			,onChange	  : _onChange
			,resetOptions : _resetOpt
		});
		
		Event.observe(document, 'click', function (e) {

			// google maps street view throws an error ...
			try {
			var elm = Event.findElement(e);
				if (!($(elm).descendantOf(d1))){
					if (cDiv.style.visibility != 'hidden') {
						cDiv.style.visibility = 'hidden';
						setTimeout(_close, 5);
					}
				}
			} catch (e) {
				// do nothing
			}

		});
		
		return d1;
	}
	,createPromptInput : function (optObj) {
	
		var optObj = optObj || {};
		optObj.onChange = optObj.onChange || function(){};
		
		optObj.numericFormat = optObj.numericFormat || optObj.dollarFormat;
		
		if (optObj.numericFormat){
			optObj.validChars = '0123456789';
			optObj.maxLength = parseInt(optObj.maxLength) || 15;
		} 
		else {
			optObj.maxLength = parseInt(optObj.maxLength) || 20;
		}
		
		optObj.errorStyle = optObj.errorStyle || {}/*{backgroundColor:'#ffccff'}*/;
		
		//create wrapper element
		var inputWrapper = document.createElement('div');
		inputWrapper.style.display  = 'inline';
		inputWrapper.style.position ='relative';
		inputWrapper.style.whiteSpace = 'nowrap';
		inputWrapper.style.background = 'transparent';
		Object.extend(inputWrapper.style, optObj.wrapperStyle || {});
		
		inputWrapper.backupStyle={};
		for (i in inputWrapper.style){
			if (inputWrapper.style.hasOwnProperty(i)){
				inputWrapper.backupStyle[i] = inputWrapper.style[i];
			}
		}
		
		//create input element
		var inputElm = (optObj.isTextArea) ? document.createElement('textarea') : document.createElement('input');
		inputElm.length = optObj.length || '';
		inputElm.name   = optObj.name || optObj.id || '';
		inputElm.id     = optObj.name || optObj.id || '';
		inputElm.style.fontSize = '13px';
		
		if (optObj.length) 
			inputElm.style.width  = optObj.length;
		if (optObj.maxLength) 
			inputElm.maxLength = optObj.maxLength;
		Object.extend(inputElm.style, optObj.inputStyle || {});
		
		//create prompt element
		var promptElm = inputElm.promptElm = document.createElement('span');
		promptElm.innerHTML = optObj.prompt || '...';
		promptStyle = {
			fontStyle : 'italic'
			,color : 'gray'
			,position : 'absolute'
			,fontFamily : 'arial, helvetica, sans-serif'
			,fontSize : '13px'
			,paddingTop : '3px'
			,paddingLeft : '4px'
			,cursor : 'text'
		};
		Object.extend(promptStyle, optObj.promptStyle || {});
		Object.extend(promptElm.style, promptStyle);
		
		Event.observe(promptElm, "click", function () {
			inputElm.focus();
		});
		
		
		inputElm.formatNumeric = formatNumeric;
		function formatNumeric(code){
			var p = this.getCaretPosition();  //  position
			
			var myArray = this.value.split('');
			if (this.getAttribute('skip')){
				myArray.splice(p,1);
				this.value = myArray.join('');
				this.setAttribute('skip',null);
				this.setCaretPosition(p);
			}

			if (this.value[p]=='0' || this.value[p]==','){
				var foundNonZero = false;
				var i = p;
				while (--i>=0){
					if (this.value[i]>='1' && this.value[i]<='9'){
						foundNonZero = true;
						break;
					}
				}
				if (!foundNonZero){
					return;
				}
			};
			if (p>0 && p==this.value.length){
				if (this.value[p-1]=='.'){
					return;
				}
				//if (this.value[p-1]=='0' && myArray.indexOf('.')+1 ){
				//	return;
				//}
			}
			
			var dotPos = myArray.indexOf('.')+1;
			//var x = 0;
			//if (dotPos){
			//	x = this.value.length-dotPos;
			//}
			var x = dotPos ? this.value.length-dotPos : 0;
			
			var f = parseFloat(this.value.replace(/[$,]/g, '' ))
			
			var c = 0;  // commas before the insertion point
			for (var i=0;i<p;i++) {
				if (this.value[i] == ',' || this.value[i]=='$') {
					c++;
				}
			}

			var pAdj = 0; // adjust p for an inserted 0 before the decimal on numbers less than 1
			if (myArray[p]="." && f < 1 && f>0)
				if (p==0 || myArray[p-1]=="$")
					pAdj = 1;
			
			if (!dotPos){
				var fStr = this.value.replace(/[$,]/g, '' );
				if (fStr[0]=='0')  // leading 0
					pAdj = -1;
			}
			
			this.value = (optObj.dollarFormat && f ? '$' : '') + (f ? f.format(x) : '');
			this.parentNode.value = f || '';
			
			var d = 0;  // commas before the insertion point
			for (var i=0;i<p;i++){
				if (this.value[i] == ',' || this.value[i]=='$')
					d++;
			}
			
			p = p + (d-c) + pAdj;
			
			if (code==36)  // home
				p=0;
				
			if (code==35)  // end
				p = this.value.length;
				
			if (optObj.dollarFormat)
				p = Math.max(1,p);
			
			this.setCaretPosition(p);
		}
		
		inputElm.setPrompt = function(){
			if (this.value == '') {
				this.promptElm.style.display = 'inline';
			} else {
				this.promptElm.style.display = 'none';
			}
			Object.extend(this.style,optObj.errorStyle);
			return this;
		}
		
		Event.observe(inputElm, 'keyup', function (e) {
			var code = e.keyCode || e.which;
			//if (code==46)
			setTimeout(function () {  // this will execute after the .value property has been updated with latest keystroke
				// FireFox fix for arrow,  and tab keys ...
				if ([9,37,38,39,40,Event.KEY_RETURN].indexOf(code)+1)
					return;
					
				if (optObj.numericFormat){
					inputElm.formatNumeric(code);
				}
				else
					inputElm.parentNode.value = inputElm.value;
					
				optObj.onChange.call(inputElm.parentNode);
				inputElm.setPrompt();
			}, 0);
		});


		Event.observe(inputElm, 'keypress', function (e) {
			var code = e.keyCode || e.which;
			var p = this.getCaretPosition();
			var char = inputElm.value[p]; 
			if (code==46 && e.charCode == '46' && optObj.numericFormat){// decimal (.)
				if (char=='$' || char==',') {
					inputElm.setAttribute('skip',true);
				}
			}

			// FireFox fix for arrow, del, backspace, and tab keys ...
			if ([8,9,37,38,39,40].indexOf(code)+1)
				return;
			if (code == Event.KEY_RETURN) {
				return;
			}

			if (code==46 && e.charCode == '46'){ // decimal (period) (.)
				if (optObj.numericFormat){
					if (!optObj.decimals){
						Event.stop(e);
						return;
					}
					var myArray = inputElm.value.split('');
					var dotPos = myArray.indexOf('.')+1;
					if (dotPos){
						Event.stop(e);
						return;
					}
					return;
				}
			}
			if (code==46)
				return;
				
			// if it has a decimal
			// and cursor is to the right of decimal
			// and already have enough decimals
			// and tye keystroke would add another decimal digit
			if (code >= 48 && code <= 57 && optObj.numericFormat && optObj.decimals){
				var myArray = inputElm.value.split('');
				var dotPos = myArray.indexOf('.');
				var decimals = inputElm.value.length-dotPos;
				if (dotPos+1 && p>dotPos && decimals>optObj.decimals){
					Event.stop(e);
				}
			}
			
			if (optObj.validChars){
				if (optObj.validChars.indexOf(String.fromCharCode(code))== -1)
					Event.stop(e);
			}
		});

		inputWrapper.setValue = function (value) {
			//if (value == '') return;
			//promptElm.style.display = 'none';
			inputElm.value = value;
			inputElm.setPrompt();
		}
		
		inputWrapper.appendChild(promptElm);
		inputWrapper.appendChild(inputElm);
		
		if (optObj.target) {
			$(optObj.target).appendChild(inputWrapper);
		}

		inputElm.getCaretPosition = function() {
			if (this.createTextRange) {
				var r = document.selection.createRange().duplicate()
				r.moveEnd('character', this.value.length)
				if (r.text == '') return this.value.length
				return this.value.lastIndexOf(r.text)
			} else return this.selectionStart
		}
		inputElm.setCaretPosition = function(i) {
			if(this.setSelectionRange)	{
				this.setSelectionRange(i, i);
			}
			else if (this.createTextRange) {
				var range = this.createTextRange();
				range.moveStart('character', i);
				range.select();
			}	
		}
		
		return inputWrapper;
	}
};

Object.extend(Date.prototype,CSI.dateMethods);
Object.extend(Array.prototype,CSI.arrayMethods);
Element.addMethods(CSI.domMethods);


function getScroll(){
	if (window.pageYOffset) {
		scrollTop = window.pageYOffset;
		scrollLeft = window.pageXOffset;
	}
	else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
		scrollTop = document.documentElement.scrollTop;
		scrollLeft = document.documentElement.scrollLeft;
	}
	else if (document.body){
		scrollTop = document.body.scrollTop;
		scrollLeft = document.body.scrollLeft;
	}
	
	if (window.innerHeight){
		windowHeight = window.innerHeight
		windowWidth = window.innerWidth
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		windowHeight = document.documentElement.clientHeight
		windowWidth = document.documentElement.clientWidth
	}
	else if (document.body) {
		windowHeight = document.body.clientHeight;
		windowWidth = document.body.clientWidth;
	}
	
	return {Top:scrollTop, Left:scrollLeft, top:scrollTop, left:scrollLeft, width:windowWidth, height:windowHeight}
}



function padZero(n,totalDigits){
	n=n+'';
	while (n.length<totalDigits)
		n='0'+n
	return n;
}
function formatDate(d){
	if (!d || !d.getDate) 
		return '';
	return padZero((d.getMonth()+1),2)+'/'+padZero(d.getDate(),2)+'/'+d.getFullYear().toString().substr(2,2)
}
function iraStatus(adstatus,expiredate){
	switch (adstatus){
		case 'e':
			return 'Expired';
		case 'w':
			return 'Withdrawn';
		case 's':
			return 'Sold';
		case 'b':
			return 'Backup Offers';
		case 'p':
			return 'Pending';
		case 'c':
			return 'CMA';
		case 't':
			return 'Cancelled';
		case 'a':
			if (expiredate > new Date())
				return 'Active';
			else
				return 'Expired';
	}
	return '';
}
function getElmById(searchStr,elm){
	var returnElm;
	while (elm && !returnElm){
		if (elm.id == searchStr)
			returnElm = elm;
		else if (elm.childNodes.length)
			returnElm = getElmById(searchStr,elm.firstChild);
		elm = elm.nextSibling;
	}
	return returnElm;
}



function CSSRule(cName,styleObj,optObj){
	if (!optObj)
		var optObj = {};
	if(document.styleSheets.length == 0)
		return;
	for (var i=0;i<document.styleSheets.length;i++){
		var cx = document.styleSheets[i].cssRules || document.styleSheets[i].rules
		for (var x=0;x<cx.length;x++){
			if (cx[x].selectorText == cName){
				if (!optObj.insertOnly)
					Object.extend(cx[x].style,styleObj)
				else
					for (var y in styleObj){
						if (!cx[x].style[y])
							cx[x].style[y] = styleObj[y]
					}
				return;
			}
		}
	}
	var s='';
	delim = '';
	for (var i in styleObj){
		if (i == 'cssFloat' || i == 'styleFloat')
			s+= 'float:'+styleObj[i]+';';
		else
			s += i.underscore().dasherize()+':'+styleObj[i]+';';
	}
	var myStyle = document.styleSheets[0];
	if (myStyle.addRule){//ie
		try { x = myStyle.addRule(cName,s) }
		catch(err){
			alert(cName);
		}
	}
	else {
		myStyle.insertRule(cName+'{'+s+'}',  myStyle.cssRules.length-1)
	}

}

function debug(obj){
	var msg=[];
	for (i in obj){
		try {msg[msg.length] = i+':'+obj[i];}
		catch(e) {msg[msg.length] = i+':'}
	}
	if (!window.debugBox){
		debugBox = document.createElement('div')
		debugBox.style.position = 'absolute';
		debugBox.style.top="10px";
		debugBox.style.left="10px";
		debugBox.style.border="1px solid black";
		debugBox.style.height="100px";
		debugBox.style.padding="10px";
		debugBox.style.backgroundColor="lightblue";
		document.body.appendChild(debugBox);
		debugBox.onclick=function(){debugBox.style.visibility="hidden"};
	}
	
	debugBox.innerHTML = msg.join('<br>')
	debugBox.style.visibility='visible';
}
function getElmsByName(searchString,scope){
	var x = scope.all
	var a=[];
	for (var i=0;i<x.length;i++)
		if (x[i].name == searchString)
			a[a.length]=x[i]
	return a
}
function createCookie(name,value,days,mydomain) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
		var expires = "";

	if (!mydomain)
		var mydomain = '';
	else
		mydomain = 'domain='+mydomain;
		
	document.cookie = name+"="+value+expires+"; path=/; "+mydomain;
}

function readCookie(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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
//function isDate(a) {
//    return typeof a == 'date';
//}

function wait(millis) {
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); } 
		while(curDate-date < millis);
} 

function isFunction(a) {
    return typeof a == 'function';
}
function trim(str_var){
	return str_var.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}
function mainmenu(){
	window.location = '/wwwroot/remaint/index.cfm';
	return;
	//  the code below does not work in firefox!
	history.go('http://'+location.host+'/wwwroot/remaint/index.cfm');
	history.go('http://'+location.host+'/remaint/index.cfm');
	history.go('http://'+location.host+'/remaint/');
	setTimeout('window.location = "/wwwroot/remaint/index.cfm"',500);
}
function checklength(event, obj){
	setTimeout("updateCounter(textarea.value.length)",3);
	//var uselessKeys = /^9|16|17|35|36|37|8|46|91|38|66|39|40$/
	var uselessKeys = /^9|16|35|36|37|8|46|91|38|66|39|40$/
	if (uselessKeys.test(event.keyCode)) {
		return;
	}
	if (!event.keyCode == "17") {
		if (obj.value.length >= obj.maxlength) {
			return false;
		}
	}
}
function updateCounter(used){
	//if (!textarea.maxlength)
	textarea.maxlength=textarea.getAttribute('maxlength');

	if (textarea.value.length > textarea.maxlength){
		textarea.value = textarea.value.substring(0,textarea.maxlength);
		used = textarea.maxlength;
	}
	_from.innerHTML = 'used '+used+' ';
	_to.innerHTML = ' of '+textarea.maxlength;
}
function init_from_to(obj){
	textarea = obj;
	_from = document.getElementById(textarea.name+'_from');
	_to = document.getElementById(textarea.name+'_to');
	updateCounter(obj.value.length);
}

function testEmails(str){
	str = str.replace(/;/g,',')
	str = str.replace(/ /g,',')
	var r = /,,/;
	while (r.test(str))
		str=str.replace(r,',')
	var a = str.split(',')
	var v = true;
	for (var i=0;i<a.length;i++)
		if (!testEmail(a[i])){
			v = false;
			break;
		}
	return (v) ? str : v
}
function testEmail(str){
	var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	return emailRe.test(str)
}
CSSRule('.fLink',{cursor:'pointer',color:'blue',textDecoration:'underline'});

// End of CSITools.js                                           //


// start of dates.js by matt kruse:
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
/// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
//              | NNN (abbr.)        |
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2 || d1 == d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
	
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
function parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
	}

/*
					End of dates.js 				
					
					Start of Mybox.js
*/

CSSRule('.theBox',{fontSize:'12px',border:'1px solid black',padding:'6px',position:'absolute',backgroundColor:'#ffffef'});
CSSRule('.theBoxParent', {filter: 'alpha(opacity=100)', opacity:1});
//will create a box that on .show() will overlap the page
function createBox(optObj){
	optObj = optObj || {};
	if (optObj.hideOnBlur == 'undefined') optObj.hideOnBlur = true;
	
	var b = $(document.createElement('div'));
	b.className = 'theBox';
	b.overlay = optObj.overlay;
	
	var par = $(document.createElement('div'));
	par.setStyle({position:'absolute',visibility:'hidden',left:'0px',right:'0px'});
	//par.className = 'theBoxParent';
	par.appendChild(b);
	Object.extend(b,boxMethods);
	
	if (optObj.fullScreen){
		b.fullScreen = true;
		optObj.shadowWidth = 0;
	}

	// opacity //
	
	if (optObj.opacity){
		b.style.filter = 'alpha(opacity='+(optObj.opacity*100)+')';
		b.style.MozOpacity = b.style.KhtmlOpacity = b.style.opacity = optObj.opacity;
	}

	var shadowWidth = (optObj.shadowWidth != undefined) ? optObj.shadowWidth : 5;
	var shadowOpacity = optObj.shadowOpacity || 24;
	b.addShadow(shadowWidth,shadowOpacity);

	if (optObj.insert){
		b.inline = true;
		var elm = $(optObj.insert);
		if(elm.getStyle('position')=='static')
			elm.style.position = 'relative';
		b.parentNode.style.top = b.parentNode.style.left = '0px';
		elm.appendChild(par);
		return b;
	}
	document.body.appendChild(par);
	return b;
}

insertDivReg = function (){
	var dr = [];
	var fx = function(elm){
		var a=[];
		for (var i = 0;i<dr.length;i++){
			if (dr[i].close && (!elm || !$(elm).descendantOf(dr[i]))){
				//alert(1);
				dr[i].close();
			}
			else
				a.push(dr[i])
		}
		dr = a;
	}
	Event.observe(window,'load',function(){
		Event.observe(document,'click',function(ev){
			e = ev || event;
			t = $(e.srcElement || e.target);
			fx(t);
		})
	})
	return function(div){
		if (!div)
			fx();
		else if (dr.indexOf(div)==-1)
			dr.push(div)
	}
}();

boxMethods = {
	//displays the box on the screen
	show : function(focusElm){
		var oThis = this;
		if (oThis.overlay){
			if (!window.overlay){
				overlay = document.createElement('div');
				overlay.id = 'overlay';
				overlay.onclick='event.cancelBubble=true';
				overlay.style.position='absolute';
				overlay.style.top='0';
				overlay.style.left='0';
				overlay.style.display='none';
				overlay.style.opacity='.5';
				overlay.style.filter='Alpha(Opacity=50)';
				overlay.style.backgroundColor='black';
				document.body.appendChild(overlay); 
				overlay.style.zIndex = 0;
				overlayArray = [];
				overlay.onclick = 'return false';
			};
			if (oThis.overlay.color){
				overlay.style.backgroundColor = '#'+oThis.overlay.color;
			}
			if (oThis.overlay.opacity){
				overlay.style.opacity = oThis.overlay.opacity/100
				overlay.style.filter = 'alpha(opacity='+oThis.overlay.opacity+')';
			}
			overlay.style.zIndex = overlay.style.zIndex || 0;
			overlay.style.zIndex = parseInt(overlay.style.zIndex) + 10;
			//alert(overlay.style.zIndex);
			overlay.style.display = "block"
			overlay.style.width= $(document.body).getWidth()+'px';
			overlay.style.height= $(document.body).getHeight()+'px';
			oThis.parentNode.style.zIndex = parseInt(overlay.style.zIndex) + 5;
			overlayArray.push(oThis);
		}
		oThis.showTimeout = window.setTimeout(function(){
			oThis.parentNode.style.visibility = 'visible';
			if (focusElm && oThis.form[focusElm]){
				oThis.form[focusElm].focus();
			}
		},25);
		this.positionShadow();
		//alert(this.hideOnBlur)
		if (!oThis.inline && !oThis.pushed && oThis.hideOnBlur){
			setTimeout(function(){insertDivReg(oThis)},50);
		}
		if (this.saveValues){
			this.saveValues();
		}
		return this;
	}
	//closes the box
	,close : function(){
		this.parentNode.style.visibility = 'hidden';
		if (this.overlay){
			overlayArray.pop();
			if (overlayArray.length > 0){
				var myForm = overlayArray[overlayArray.length-1];
				overlay.style.display = "block"
				overlay.style.zIndex = parseInt(overlay.style.zIndex) - 10;
				overlay.style.width= $(document.body).getWidth()+'px';
				overlay.style.height= $(document.body).getHeight()+'px';
				myForm.parentNode.style.zIndex = parseInt(overlay.style.zIndex) + 5;
				myForm.focus();
			}
			else
				overlay.style.display = 'none';
		}
		return this;
	}
	,fadeOut : function(delay){
		delay = delay || 3000;
		var box = this;
		var opacity = 1;

		var elms = $(box.parentNode).descendants();
		if (box.fadeTimeout){
			//alert(box.fadeTimeout);
			clearTimeout(box.fadeTimeout);
			box.fadeTimeout = null;
			finishUp();
		}
		for (var i=0;i<elms.length;i++){
			elms[i].saveOpacity = elms[i].getStyle('opacity');
		}
		elms[0].setOpacity(.98);
		box.fadeTimeout = setTimeout(fade,delay);
		return this;
		function fade(){
			opacity = opacity - .02;
			for (var i=0;i<elms.length;i++){
				if (elms[i].saveOpacity > opacity){
					elms[i].setOpacity(opacity);
				}
			}
			if (opacity > 0){
				box.fadeTimeout = setTimeout(fade,40);
			}
			else {  // cleanup and finish
				finishUp();
			}
		}
		function finishUp(){
			for (var i=0;i<elms.length;i++){
				elms[i].setOpacity(elms[i].saveOpacity);
			}
			box.close();
		}
	}
	
	
	//will try to position in selected position under elm, default below/left
	,position : function(elm,optObj){
				
		var p, jA, kA, i, x, fits, top, otop, ttop, left, oleft, tleft, tElm, eWidth, eHeight, shadow;
		var validPlacements = ['below/right','above/left','above/right','right/top','right/bottom','left/top','left/bottom'];

		if (!optObj)
			optObj = {};

		getScroll();

		var bodyScroll = scrollTop;
		//alert(Prototype.Version);
		//alert(Element.cumulativeScrollOffset);
		var cumulativeScroll = $(elm).cumulativeScrollOffset();
		scrollTop = cumulativeScroll.top;
		scrollLeft = cumulativeScroll.left;

		if (optObj.placement == 'pointer'){
			var x = optObj.event.x || optObj.event.clientX || 0;
			var y = optObj.event.y || optObj.event.clientY || 0;
			
			if (x>windowWidth/2)
				left = (x-this.offsetWidth)+scrollLeft-3;
			else
				left = x+scrollLeft+3;
				
			if (y>windowHeight/2)
				top = (y-this.offsetHeight)+scrollTop-3;
			else
				top = y+scrollTop+3;
				
			if (y>windowHeight/2 && x>windowWidth/2){
				top-=4;
				left-=4;
			}		
			top = Math.max(top,0);
			left = Math.max(left,0);
			
			this.parentNode.style.top = top+'px';
			this.parentNode.style.left = left+'px';
			this.positionShadow()
			return this;
		}
		tElm = elm;
		tleft = ttop = 0;
		
		while (tElm && tElm.tagName != 'HTML' ){
			ttop += tElm.offsetTop;
			tleft += tElm.offsetLeft;
			tElm = tElm.offsetParent;
		}
		shadow = Element.select(this.parentNode,'.vShadow')[0];
		//shadow = this.parentNode.getElementsByClassName('vShadow')[0];
		if (shadow){
			eWidth = this.offsetWidth + shadow.offsetWidth 
			eHeight = this.offsetHeight  + shadow.offsetWidth 
		}
		else {
			eWidth = this.offsetWidth 
			eHeight = this.offsetHeight 
		}
			
		if (optObj.placement == 'below' || optObj.placement == 'above')
			optObj.placement += '/left'
		else if (optObj.placement == 'left' || optObj.placement == 'right')
			optObj.placement += '/top'
		
		if (!optObj.placement || validPlacements.indexOf(optObj.placement) == -1)
			optObj.placement = 'below/left'
		
		var p = optObj.placement.split('/')
		if (p[0] == 'below')
			jA = ['below','above','right','left']
		else if (p[0] == 'above')
			jA = ['above','below','right','left']
		else if (p[0] == 'right')
			jA = ['right','left','below','above']
		else if (p[0] == 'left')
			jA = ['left','right','below','above']
			
		outer_loop:
		for (i=0; i<jA.length; i++){
			if (jA[i] == 'above' || jA[i] == 'below')
				kA = (p[1] == 'left') ? ['left','right'] : ['right','left']
			else
				kA = (p[1] == 'top') ? ['top','bottom'] : ['bottom','top']

				
			if (optObj.cover) {
				if ( jA[i] == 'above') 
					otop = -eHeight;
				else if (jA[i] == 'below')
					otop = 0;
				else if (jA[i] == 'left')
					oleft = -eWidth;
				else if (jA[i] == 'right')
					oleft = elm.offsetWidth;
			}
			else {
				if ( jA[i] == 'above') 
					otop = -eHeight;
				else if (jA[i] == 'below')
					otop = elm.offsetHeight;
				else if (jA[i] == 'left')
					oleft = -eWidth;
				else if (jA[i] == 'right')
					oleft = elm.offsetWidth;
			}
			for (x=0;x<kA.length;x++){
				left = oleft;
				top = otop;
				if (kA[x] == 'left')
					left =  0;
				else if (kA[x] == 'right')
					left = (eWidth - elm.offsetWidth)*-1
				else if (kA[x] == 'top')
					top = 0
				else if (kA[x] == 'bottom')
					top = (eHeight - elm.offsetHeight)*-1
				
				top += ttop;
				left += tleft;
				
				fits = true;
				if (optObj.force)
					break outer_loop;
					
				if (((left + eWidth) - scrollLeft > windowWidth)
				|| ((top + eHeight) - scrollTop > windowHeight)
				|| (top - scrollTop < 0)
				|| (left - scrollLeft < 0)){
					fits = false;
				}
				else
					break outer_loop;
			}
				
		}
		if (!fits){
			for (var i=0;i<jA.length; i++){
				if ( jA[i] == 'above'){
					top = -eHeight+ttop;
					left = scrollLeft;
				}
				else if (jA[i] == 'below'){
					top = elm.offsetHeight+ttop;
					left = scrollLeft;
				}
				else if (jA[i] == 'left'){
					left = -eWidth+tleft;
					top = scrollTop;
				}
				else if (jA[i] == 'right'){
					left = elm.offsetWidth+tleft;
					top = scrollTop;
				}
				
				fits = true;
				if (((left + eWidth) - scrollLeft > windowWidth)
				|| ((top + eHeight) - scrollTop > windowHeight)
				|| (top - scrollTop < 0)
				|| (left - scrollLeft < 0)){
					fits = false;
				}
				else
					break;
			}
		}		
		//Only account if the body has not been scrolled
		top = (bodyScroll == 0) ? Math.max(top-scrollTop,0) : Math.max(top,0);
		left = (bodyScroll == 0) ? Math.max(left-scrollLeft,0) : Math.max(left,0);
		this.parentNode.style.top = top+'px';
		this.parentNode.style.left= left+'px';
		this.positionShadow()
		return this;
	}
	//centers the box based on the available space in the document.body
	,center : function(){
		var par = this.parentNode;
		if (par.style.position != 'absolute')
			return;
		getScroll();
		var divTop = Math.round(scrollTop+((windowHeight - this.offsetHeight)/2))
		var divLeft = Math.round(scrollLeft+((windowWidth - this.offsetWidth)/2))
		par.style.top = Math.max(divTop,0)+'px'
		par.style.left = Math.max(divLeft,0)+'px'

		getScroll();
		if (this.offsetHeight > windowHeight && this.formBody){
			var oThis = this;
			var fHeight = (oThis.footer) ? oThis.footer.offsetHeight : 0;
			oThis.formBody.style.height = (windowHeight - (oThis.hdr.offsetHeight + fHeight + parseInt(oThis.formBody.getStyle('paddingTop')) + parseInt(oThis.formBody.getStyle('paddingBottom')) ) )+'px';
			oThis.formBody.style.overflowY = 'scroll';
		}
		
		this.positionShadow()
		return this
	}
	,addShadow : function(width,opacity){
		if (width==0)
			return this;
		var par = this.parentNode
		var width = width || 3;
		var opacity = opacity || 28;
		var vShadow = $(document.createElement('div'))
		var hShadow = $(document.createElement('div'))
  
  		vShadow.className = 'vShadow';
  		hShadow.className = 'hShadow';
		var bb = parseInt(this.getStyle('borderBottomWidth')) || 0;
		var br = parseInt(this.getStyle('borderRightWidth')) || 0;
		var bt = parseInt(this.getStyle('borderTopWidth')) || 0;
		var bl = parseInt(this.getStyle('borderLeftWidth')) || 0;
  
		vShadow.setStyle({position:'absolute',backgroundColor:'black',opacity:opacity/100,filter:'alpha(opacity='+opacity+')'})
		hShadow.setStyle({overflow:'hidden',position:'absolute',backgroundColor:'black',opacity:opacity/100,filter:'alpha(opacity='+opacity+')'})
		hShadow.style.height = vShadow.style.width = width+'px';
		vShadow.style.top = ((2*width))+'px'
		hShadow.style.left = ((2*width))+'px';
		par.appendChild(vShadow);
		par.appendChild(hShadow);
		return this;
	}
	,positionShadow : function(){
		var shadowWidth = 0;
		//if (vShadow = this.parentNode.getElementsByClassName('vShadow')[0]){
		if (Element.select && (vShadow = Element.select(this.parentNode,'.vShadow')[0])){
			//var hShadow = this.parentNode.getElementsByClassName('hShadow')[0]
			var hShadow = Element.select(this.parentNode,'.hShadow')[0];
			shadowWidth = vShadow.offsetWidth;
			
			vShadow.style.height = (((this.offsetHeight)+shadowWidth)-2*shadowWidth)+'px';
			hShadow.style.width = ((this.offsetWidth)-2*shadowWidth)+'px';
			vShadow.style.left = (this.offsetWidth)+'px';
			hShadow.style.top = (this.offsetHeight)+'px';
		}
		if (this.inline){
			var offsetHeight = this.offsetHeight + shadowWidth;
			var offsetWidth = this.offsetWidth + shadowWidth;
			var par = this.parentNode.parentNode;
			var dims = par.getDimensions();
			par.style.height = Math.max(dims.height,offsetHeight)+'px';
			par.style.width = Math.max(dims.width,offsetWidth)+'px';
		}
		return this;
	}
	,adjLeft	: function(v){
		this.parentNode.style.left = (parseInt(this.parentNode.style.left)+v)+'px';
		return this
	}
	,adjTop	: function(v){
		this.parentNode.style.top = (parseInt(this.parentNode.style.top)+v)+'px';
		return this;
	}
}



/*							End of mybox.js
							
							
							
							Start of dmenu.js
*/

CSSRule('.dMenu',{padding:'2px',cursor:'pointer',border:'1px solid #aaa',fontFamily:'tahoma',fontSize:'.7em'});
CSSRule('.dMenu div',{position:'relative',color:'black',padding:'2px 16px 2px 3px',backgroundColor:'white',whiteSpace:'nowrap'});
CSSRule('.dMenu .sel',{color:'white',backgroundColor:'#3B46BF'});
CSSRule('.dMenu span',{position:'absolute',right:'5px',fontSize:'xx-small',paddingTop:'1px'});

if (!window.menuObject)
	menuObject = {};
if (!window.menuObject2)
	menuObject2 = {};

function showMenu(t,str,e){
	t=$(t);
	var o = {};
	if (!menuObject2[str])
		if (menuObject[str])
			menuObject2[str] = createMenu(str,t);
		else {
			alert('no menu')
			return;
		}

	var m = menuObject2[str];
	m.linkElm = t;
	
	if (!t.hasClassName('menuItem') && $(t.parentNode).hasClassName('menuItem')){
		t=$(t.parentNode);
	}
	if (t.hasClassName('menuItem')){
		m.instigator = t;
		m.parentMenu = t.parentNode;
	}
	if (m.parentMenu){
		m.parentMenu.subMenu = m;
		if (!m.parentMenu.horizontal)
			o = {placement:'right'};
	}
	if (m.placement)
		o = {placement:m.placement};
	
	m.show();
	if (m.placement == 'pointer' && e){
		x = e.x || e.clientX
		y = e.y || e.clientY
		o = {placement:'pointer',x:x,y:y}
		m.position(t,o);
	}
	else if (m.placement != 'inline')
		m.position(t,o);
	return m;
}

menuMethods = {
	closeSubMenu : function(){
		var m = this;
		var a = [];
		while (m.subMenu){
			if (a.indexOf(m)>-1){
				alert('error : circular reference')
				return;
			}
			a.push(m)
			if (m.subMenu.selectedItem){
				m.subMenu.selectedItem.removeClassName('sel');
				m.subMenu.selectedItem = null;
			}
			m.subMenu.close()
			m = m.subMenu;
			m.parentMenu.subMenu = null;
		}
	}
	,evaluate : function(){
		var divs = this.getElementsByTagName('div');
		for (var i=0;i<divs.length;i++){
			try {divs[i].disabld = !eval(divs[i].condition)}
			catch(err){divs[i].disabld = true;}
			if (divs[i].disabld)
				divs[i].style.color = 'lightgrey'
			else
				divs[i].style.color = ''
		}
	}
	,setTitle : function(str,styleObj){
		this.titleSpan.innerHTML = str;
		if (styleObj){
			$(this.titleSpan).setStyle(styleObj);
		}
		this.titleSpan.style.display = '';
		return this;
	}
	,onmouseover : function(e){
		var ev = (e) ? e : event;
		var t = $(ev.target || ev.srcElement)
		if (t.className == 'menuItem' && !t.disabld){
			var m = t.parentNode;
			m.selectItem(t);
		}
	}
	,onclick : function(e){
		var ev = (e) ? e : event;
		var t = $(ev.target || ev.srcElement)

		if (!t.hasClassName('menuItem'))
			t=t.parentNode;
		
		if (t.disabld){
			Event.stop(ev);
			return
		}
		
		var controlObj;
		
		if (t.hasClassName('menuItem')){
			var m = t;
			while (!controlObj && m){
				if (m.controlObj)
					controlObj = m.controlObj;
				else if (m.readAttribute && (controlObj = m.readAttribute('controlObj')))
					;
				else if (m == this)
					break;
				else
					m = m.parentNode;
			}
			controlObj = controlObj || {};			
		
			if (typeof(t.fx)=='function'){
				if (typeof (controlObj) == 'string')
					eval ('controlObj = '+ controlObj);
					
				t.fx(ev,controlObj);
			}
			else {
				if (m.autoOpen && m.subMenu){
					m.subMenu.close();
					m.autoOpen = false;
				}
				else{
					showMenu(t,t.fx);
					if (m.horizontal)
						m.autoOpen = true;
				}
			}
		}
	}

	,onmouseenter	:	function(){
		if (this.timeout)
			clearTimeout(this.timeout)
		if (this.instigator && this.parentMenu.selectedItem != this.instigator)
			this.parentMenu.selectItem(this.instigator);
	}
	,selectItem	:	function(t){
		var m = this;
		if (m.selectedItem){
			if (m.selectedItem == t)
				return;
			if (m.subMenu && m.subMenu.instigator == m.selectedItem && !m.autoOpen)
				m.subMenu.timeout = setTimeout(function(){m.closeSubMenu()},700);
			if (m.selectedItem.timeout)
				clearTimeout(m.selectedItem.timeout)
			m.selectedItem.removeClassName('sel')
		}
		t.addClassName('sel')
		m.selectedItem = t;
		if (m.subMenu && m.subMenu.instigator == t && m.subMenu.timeout)
			clearTimeout(m.subMenu.timeout);
			
		if (m.autoOpen){
			m.closeSubMenu()
			if (!t.disabld && typeof(t.fx)=='string')
				showMenu(t,t.fx);
		}
		else if (!m.horizontal && !t.disabld && typeof(t.fx)=='string')
			t.timeout = setTimeout(function(){showMenu(t,t.fx)},700)
	}
}

function createMenu(str,t){
	var optObj = {}
	optObj.shadowOpacity = menuObject[str].shadowOpacity || 24;
	optObj.shadowWidth = (menuObject[str].shadowWidth == undefined) ? 3 : menuObject[str].shadowWidth


	var x = t;
	var z = 0;
	while (x && x.getStyle){
		z = Math.max( x.getStyle('zIndex'),z)
		x = $(x.parentNode);
	}
	
	var box = createBox(optObj)
	box.parentNode.style.zIndex = z+1;
	box.placement = menuObject[str].placement || 'jj';

	
	if (menuObject[str].placement == 'inline'){
		t.appendChild(box.parentNode);
		box.style.position = box.parentNode.style.position = 'relative'
	}


	box.addClassName(menuObject[str].className || 'dMenu');
	box.dMenu = true;
	
	Object.extend(box,menuMethods);
	box.style.padding = '';
	
	box.hideOnClick = menuObject[str].hideOnClick || false;
	
	var d,h,arrow;
	var a;
	
	box.horizontal = !!menuObject[str].horizontal;
	var hideArrows = !!menuObject[str].hideArrows;
	
	arrow = (box.horizontal) ? '&#9660' : '&#9658';
	var left = parseInt(box.getStyle('paddingLeft'));
	var item;
	box.titleSpan = box.appendChild(document.createElement('div'));
	box.titleSpan.style.display='none';
	
	for (var i=0;i<menuObject[str].items.length;i++){
		item = menuObject[str].items[i];
		if (!item.length){
			if (!box.horizontal){
				box.appendChild(document.createElement('hr')).style.width='1px'
				var followhr = true;
			}
		}
		else{
			d = $(document.createElement('div'));
			d.className = 'menuItem';
			try{
				d.disabld = !eval(item[2]);
			}
			catch(err){
				d.disabld = true;
			}
			if (d.disabld)
				d.style.color = 'lightgrey'
			a=[item[0]]
			
			if (typeof(item[1])=='string' && !hideArrows)
				a.push('<span>'+arrow+'</span>');
			d.fx = item[1];
			d.condition = item[2];
			d.innerHTML = a.join('');
			box.appendChild(d)
			if(followhr){
				d.style.marginTop='-7px'
				followhr = false;
			}
			if(box.horizontal){
				d.style.position = 'absolute';
				d.style.left = left+(parseInt(d.getStyle('marginLeft') || 0))+'px';
				left += d.offsetWidth+(parseInt(d.getStyle('marginLeft') || 0))+(parseInt(d.getStyle('marginRight') || 0));
			}
		}
	}
	var hrs = box.getElementsByTagName('hr');
	var width = box.offsetWidth-12;

	for (var i=0;i<hrs.length;i++){
		hrs[i].style.width = width+'px';
		hrs[i].style.marginTop = '-4px'
	}
	if (box.horizontal){
		box.style.width = (left-parseInt(box.getStyle('paddingLeft')))+'px'
		box.style.height = d.offsetHeight+'px';
	}
	menuObject2[str] = box;
	return box;
}


function closeMenu(e){
	var t= $(e.srcElement || e.target);
	var elm = t;
	while (t && !$(t).dMenu && t.tagName != 'BODY'){
		t = $(t.parentNode);
	}

	var ea = [];
	if (t && t.selectedItem && t.selectedItem.subMenu){
		ea.push(t.selectedItem.subMenu)
	}
	
	while (t && t.dMenu && !t.hideOnClick){
		alert(t.innerHTML)
		ea.push(t)
		if (t.parentMenu){
			if (t == t.parentMenu){
				alert('error:circular reference')
				return;
			}
			t=t.instigator.parentNode
		}
		else
			t=null
	}
	var mo = menuObject2;
	var moi;
	for(var i in mo){
		moi = mo[i];
		if (mo.hasOwnProperty(i)){
			if (ea.indexOf(moi) == -1 && elm != moi.linkElm){
				if (moi.placement != 'inline'){
					moi.close();
				}
				moi.autoOpen = false;
				if (moi.selectedItem){
					moi.selectedItem.removeClassName('sel')
					moi.selectedItem = null;
				}
			}
		}
	}
}

// removed july 2009 tim obrien not needed for newspage at this time.
//Event.observe(window,'load',function(){
//	Event.observe(document.body,'click',closeMenu)
//})




/*
									End of dmenu.js
									
									
									Start of jsform.js
*/
CSSRule('.formHdr',{backgroundColor:'#eee',borderBottom:'1px solid #666',padding:'8px 24px 8px 8px'});
CSSRule('.jsForm .formBody',{padding:'8px',fontSize:'10px',fontFamily:'verdana'});
CSSRule('.formFooter',{backgroundColor:'#eee',borderTop:'1px solid #666',padding:'8px'});
CSSRule('.jsForm',{padding:'0px'});
CSSRule('.jsForm .icon',{padding:'4px 3px',position:'absolute',top:'6px',cursor:'pointer'});
CSSRule('.jsForm form',{margin:'0px',fontFamily:'Verdana',fontSize:'12px'});
CSSRule('.jsForm .error',{color:'red'});
CSSRule('.jsForm .title',{fontSize:'14px',fontWeight:'bold',whiteSpace:'nowrap'});
CSSRule('.jsForm .formFooter',{textAlign:'right',padding:'3px 8px',whiteSpace:'nowrap',fontSize:'.8em'});
CSSRule('.jsForm button',{backgroundColor:'#016066',color:'#eee'});

CSSRule('.resultsDiv',{padding:'1px',cursor:'pointer',fontSize:'12px',fontFamily:'verdana'});
CSSRule('.resultsDiv td',{padding:'3px 6px',whiteSpace:'nowrap'});
CSSRule('.resultsDiv .odd',{backgroundColor:'#bbb'});
CSSRule('.resultsDiv .highlight',{backgroundColor:'brown',color:'white'});
CSSRule('.msg',{padding:'6px',backgroundColor:'brown',color:'white',fontWeight:'bold',fontSize:'12px'});
CSSRule('.reportForm td',{padding:'0px 12px 0px 0px',whiteSpace:'nowrap',fontSize:'12px'});
CSSRule('.reportForm .noPad',{padding:'0px'});
CSSRule('.reportForm .colHdr',{fontWeight:'bold',whiteSpace:'nowrap'});
CSSRule('.filter',{cursor:'pointer',textDecoration:'underline'});
CSSRule('.notFound',{color:'red',fontSize:'1.2em'});
CSSRule('.b',{fontWeight:'bold'});
CSSRule('.foundText',{backgroundColor:'#007',color:'#ffd'});
/**************************************************************/
	CSI.png =  function(src){
		// returns either a div with a background image(ie <=6.0) or an image everything else
			
		var i = $(document.createElement('img'));
		i.src = src;
		//if (!window.XMLHttpRequest){
		//	var d = $(document.createElement('div'));
			//d.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/lib/icons/printer.png",sizingMethod="image")';
		//	d.style.height = (i.height+8)+'px';
		//	d.style.width = (i.width+8)+'px';
		//	i = d;
		//}
		i.className = 'icon';
		return i;
	}



///            Drag Drop                              ///
var dragObject;
Event.observe(window,'load',function(){
	Event.observe(document.body,'mousemove',function(event){
		if(dragObject){
			var mousePos = CSI.mouseCoords(event);
			dragObject.style.top      = (mousePos.y - mouseOffset.y)+'px';
			dragObject.style.left     = (mousePos.x - mouseOffset.x)+'px';
			//return false;
		}
	});
	Event.observe(document,'mouseup',function(event){
		dragObject  = null;
		document.body.style.cursor = '';
	});
});



/**************************************************************/
function createMultiOptForm(optObj){
	// extended select multiple checkboxes
	optObj = optObj || {};

	var f = createForm();
	f.footer.innerHTML = '<button>Save</button>';
	Event.observe(f.footer.getElementsByTagName('button')[0],'click',function(){this.onEnterKey()}.bind(f));
	
	Event.observe(f.formBody,'click',function(e){
		var t = $(e.srcElement || e.target);
		if (t.tagName == 'DIV' && t.firstChild.click)
			t.firstChild.click();
		if (t.tagName == 'DIV' || t.tagName == 'INPUT')
			setTimeout(this.refreshSelColor,10);
	}.bindAsEventListener(f))

	f.refreshSelColor = function(){
		var divs = $A(this.formBody.getElementsByTagName('div'));
		for (var i = 0;i<divs.length;i++){
			if (divs[i].firstChild.checked)
				$(divs[i]).addClassName('sel');
			else
				$(divs[i]).removeClassName('sel');
		}
		return this;
	}.bind(f);
	
	return f;
}
// user notifications will continue to on each page load until the user checks the "do not show this message again" checkbox 
// all parms are passed in the optObj and should include at least innerHTML, title, and pid.
// the user pid will be created once "do not show this message again" is checked and the submit button is clicked
// each program must check the user preference for the user/pid combination to determine whether to call this function.
function createUserNotification(optObj){
	optObj = optObj || {};
	var form = createForm(optObj);
	form.style.zIndex = 1000;
	
	var b = form.getElementsByTagName('button')[0];
	var f = b.parentNode;
	f.style.textAlign = 'left';
	b.innerHTML = 'ok';
	b.style.position = 'absolute';
	b.style.right = '6px';
	var span = document.createElement('span');
	span.innerHTML = '<input type="checkbox" id="doNotShow"><label for="doNotShow">Do not show this message again</label>'; //
	var footer = form.select('.formFooter')[0];
	footer.insertBefore(span,footer.firstChild);
	form.center().show();

	form.onEnterKey = function(){
		if(form.getElementsByTagName('input')[0].checked){
			new Ajax.Request('/wwwroot/remaint/ajax/upduserprefs.cfm',{
				parameters:{user_id:cfo_user_id,pidsOn:'478',pidsOff:''},
				onComplete: function(t){
					try{eval(t.responseText)}
					catch(err){
						alert('error');
						document.write(t.responseText);
					}
				}
			});
		}
		form.close();
	};
	return form;
}
//creates a customizable form that has an onEnter function
function createForm(optObj){
	optObj = optObj || {};
	if (optObj.hideOnBlur == 'undefined') optObj.hideOnBlur = false;
	
	var box = createBox(optObj);
	box.form = box.appendChild($(document.createElement('form')));
	box.form.onsubmit = function(){return false;};
	box.hdr = box.form.appendChild($(document.createElement('div')));
	box.hdr.className = 'formHdr';
	
	if (!optObj.disableDragDrop){
		Event.observe(box.hdr,'mousedown',function(ev){
			var e = ev || event;
			var t = $(e.srcElement || e.target);
			if (t.hasClassName('fLink') || t.tagName=='IMG')
				return false;
			
			dragObject = box.parentNode;
			mouseOffset = CSI.getMouseOffset(box.parentNode, e);
			document.body.style.cursor = 'move'
		});
	}
	box.titleSpan = box.hdr.appendChild($(document.createElement('span')));
	box.titleSpan.className = 'title';
	box.rightMargin = 4;
	if (!optObj.insert && !optObj.disableClose){
		var i = $(document.createElement('img'));
		i.className='icon';
		i.style.right = box.rightMargin+'px';
		i.src = '/wwwroot/lib/csitools/2.0/close_small.gif';
		i.title = "Close";
		box.hdr.appendChild(i);
		box.rightMargin += (i.offsetWidth+6);
		Event.observe(i,'click',function(){this.close()}.bind(box));
	};

	box.addClassName('jsForm');
	box.formBody = box.form.appendChild($(document.createElement('div')));
	box.formBody.className = 'formBody';
	if (box.fullScreen){
		optObj.noFooter = true;

		setTimeout(function(){
			getScroll();
			box.formBody.setStyle({
				height:(windowHeight-(box.hdr.offsetHeight+2))+'px'
				,overflowY:'auto'
			})
		},150)
		box.setStyle({
			 width:windowWidth-2+'px'
		});
	}
	// keepOpen  [ checked | unchecked ]
	Object.extend(box,formMethods);
	
	if (optObj.formMethods)
		Object.extend(box,optObj.formMethods);
	
	if (optObj.title){
		box.setTitle(optObj.title);
	}
	if (!optObj.noFooter){
		box.footer = box.appendChild($(document.createElement('div')));
		if (optObj.keepOpen){
			var div = box.footer.appendChild($(document.createElement('div')));
			div.innerHTML = '<input type="checkbox" class="keepOpen" onclick="CSI.updPrefs(2,this.checked);"><span onclick="this.previousSibling.click();" style="cursor:pointer">Keep this form Open</span>';
			div.style.lineHeight = '1px'
			div.style.cssFloat = div.style.styleFloat = 'left';
			var k = box.keepOpenCkBx = div.getElementsByClassName('keepOpen')[0];
			k.setStyle({position:'relative',top:'3px'});
			if (optObj.keepOpen == 'checked'){
				box.keepOpenCkBx.checked=true;
			}
		}
		box.footer.className = 'formFooter';
		box.button = box.footer.appendChild(document.createElement('button'));
		box.button.innerHTML = 'Save';
		Event.observe(box.button,'click',function(ev){box.onEnterKey(ev)}.bindAsEventListener(box));
	}
										  
	var boxCloseMethod = box.close;


	box.close = function(){
		if (this.pushed){
			popForm(true)
		}
		boxCloseMethod.call(box);
	}

	box.__insert = box.insert;
	
	Event.observe(box,'keydown',box.handleKeys.bindAsEventListener(box));
	if (optObj.innerHTML){
		box.formBody.innerHTML = optObj.innerHTML;
		box.finish();
	}
	box.hideOnBlur = optObj.hideOnBlur;
	return box;
}



//chkDiv
CSSRule ('.chkDivChecked',{backgroundColor:'#ccc'});
CSSRule ('.chkDiv',{marginRight:'2px'});

formMethods = {
	updateValues : function(updateObj){
		var o = updateObj;
        for (var i in o){
            if (o.hasOwnProperty(i)){
                if (this.form[i]){
                    if (this.form[i].type=='checkbox'){
						//alert(i);
						if(this.form[i].parentNode.check) 
							this.form[i].parentNode.check(!!o[i]);
						else
							this.form[i].checked = !!o[i];
                    }
                    else 
                        this.form[i].value = o[i];
                }
            }
        }
		return this;
	}
	,getValues : function(){
		// returns a hash object with name/value pairs.  includes checkboxes that are not checked (value = '')
		var vObj = {};
		var a = this.form.getInputs('checkbox');
		for (var i=0; i<a.length; i++){
			vObj[a[i].name] = a[i].getAttribute('offValue') || "";
			//if (a[i].name == 'headHeadlineTextDecoration')
				//alert('xx:'+a[i].getAttribute('offValue'));
			//alert(a[i].name+':'+a[i].getAttribute('offValue'));
		}
		Object.extend(vObj,this.form.serialize(getHash=true));
		return vObj;
	}
	,saveValues : function(){
		this.savedValues = this.getValues();
	}
	,getChanged : function() {
		// returns null if nothing changed otherwise an object with the name of each changed item and a 2 item array of values {name:[oldval,newval],...}
		var s = this.savedValues || {};
		var c = this.getValues();
		var o ={};
		var changed = false;
		for (var i in s){
			if (s.hasOwnProperty(i)){
				if (s[i] != c[i]){
					o[i] = [s[i],c[i]];
					changed = true;
				}
			}
		}
		return changed ? o : null;
	}
	,done : function (){
		if (this.keepOpenCkBx){
			if (this.keepOpenCkBx.parentNode.style.visibility == 'hidden' || !this.keepOpenCkBx.checked ){
				this.close();
			} else {
				this.resetVals().focus();
			}
		} else {
			this.close();
		}
		return this;
	}
	//sets the title of the form, uses a div on the top of the form
	,setTitle : function(str,styleObj) {
		menuMethods.setTitle.call(this,str,styleObj)
		return this;
		//this.titleSpan.innerHTML = str;
	}
	//adds a button to the footer
	,addButton : function(obj){
		var str = obj.str || '';
		var fx = obj.fx || function(){};
		var b = this.footer.insertBefore(document.createElement('button'),this.footer.getElementsByTagName('button')[0]);
		b.innerHTML = str;
		Event.observe(b,'click',fx);
	}
	//resets the value of any item on the form, or all of them
	,resetVals : function(){
		var defaultVal, prompt, ai;
		if (!this.elms)
			this.elms = this.form.getElements();
		//alert(this.elms.length+':'+this.form.getElements().length);
		var a = this.elms;
		for (var i=0;i<a.length;i++){
			ai = a[i];
			//alert(ai.name+':'+ai.value+':'+ai.checked+':'+ai.getAttribute('defaultVal'));
			if (ai.autoSuggest)
				ai.searchResults = undefined;
				
			defaultVal =  ai.getAttribute('defaultVal');
			if (ai.type == 'checkbox'){
				//ai.checked = (defaultVal == 'checked') ? true : false;
				//alert(a[i].name+':'+defaultVal);
				
				if(ai.parentNode.hasClassName('chkDiv'))  // if it's a chkDiv,
					ai.parentNode.check(!!defaultVal)  //  use the method to turn if on/off
				else
					ai.checked = !!defaultVal ;
			}
			else {
				ai.style.color = '';
				if (defaultVal)
					ai.value = defaultVal;
				else {
					prompt = ai.getAttribute('prompt');
					if (prompt){
						ai.value=prompt;
						ai.style.color = '#999';
					}
					else
						ai.value = '';
				}
			}
		}
		return this;
	}
	//shows box and puts shadow over body, body is not clickable
	,push	:	function(){
		pushForm(this.parentNode,{opacity:.25})
		this.pushed = true;
		//this.formBody.style.width = (this.offsetWidth+2)+'px';
		if (this.fullScreen){
			this.parentNode.style.top = this.parentNode.style.left = '0px';
		}
		if (this.keepOpenCkBx) {
			this.keepOpenCkBx.checked = (window.aids && aids.indexOf(2) > -1) ? true : false;
		}
		if (this.resultsDiv){
			this.resultsDiv.parentNode.style.zIndex = parseInt(this.parentNode.style.zIndex)+2;
		}
		return this;
	}
	
	
	,finish : function(){
		this.elms = this.form.getElements();
		var myElms = $A(this.elms)
		myElms.push(this.getElementsByTagName('button')[0]);
		
		this.dates = [];
		var popupCalendar = false, prompt;
			
		if (this.form.select('.popupDate').length > 0)
			popupCalendar = true;
		
		for (var i=0;i<myElms.length;i++){
			var elm = $(myElms[i]);
			if (elm.autoSuggest){
				elm.autoSuggest.minSearchChars = elm.autoSuggest.minSearchChars || 
					((typeof(elm.autoSuggest.searchProvider) == 'string') ? 2 : 1);
				Event.observe(elm,'blur',function(){
					this.resultsDiv.close();
				}.bind(this));
				Event.observe(elm,'focus',function(elm){
					if (elm.searchResults)
						this.processMatches(elm);
				}.bind(this,elm));
				// add a resultsDiv
				if (!this.resultsDiv){
					this.resultsDiv = createBox({shadowWidth:3,shadowOpacity:50});
					this.resultsDiv.addClassName('resultsDiv');
					this.resultsDiv.parentForm = this;

					var close = this.close;
					this.close = function(){
						if (this.http && this.http.transport.readyState != 4)
							this.http.transport.abort();
						this.resultsDiv.removeHighlight();
						this.resultsDiv.close();
						close.call(this);
					}
					
					
					Object.extend(this.resultsDiv,resultsDivMethods);
					var cachedShowMethod = this.resultsDiv.show;
					
					this.resultsDiv.show = function(){
						
						this.style.overflow = this.style.height = this.style.width = '' ;
						var elm = this;
						var top = 0;
						getScroll();
						while (elm && elm != 'BODY' && elm != 'HTML'){
							top += elm.offsetTop;
							elm = elm.offsetParent;
						}
						var distanceFromTop = top - scrollTop;
						var distanceFromBottom = windowHeight - distanceFromTop;
						if (this.offsetHeight > distanceFromBottom){
							this.style.height = (distanceFromBottom-17)+'px';
							this.style.width = (this.offsetWidth + 13)+'px'
							this.style.overflow = 'auto';
							this.scrollTop = 0;
						}

						return cachedShowMethod.call(this);
					}.bind(this.resultsDiv);

					Object.extend(this,searchMethods);

					this.resultsDiv.moBound = this.resultsDiv.mouseover.bind(this.resultsDiv);
					Event.observe(this.resultsDiv,'mouseover',this.resultsDiv.moBound)
				}
			}

			if (elm.hasClassName('popupDate') || elm.getAttribute('popupDate')){
				this.dates.push(elm);
				Event.observe(elm,'focus',showCalendarControl.bind(this,elm));
				Event.observe(elm,'click',function(e){showCalendarControl(this);Event.stop(e)}.bindAsEventListener(elm));
				Event.observe(elm,'blur',validateDate.bind(this,elm));
				Event.observe(elm,'change',function(){this.validate='wait'}.bind(elm));
			}
			else {
				if (popupCalendar)
					Event.observe(elm,'focus',hideCalendarControl.bind(this,elm));
			}
			if (prompt = elm.getAttribute('prompt')){
				Event.observe(elm,'blur',function(){
					var prompt = this.getAttribute('prompt');
					if (trim(this.value) == '')
						this.value = prompt;
						
					this.style.color = (this.value==prompt) ? '#999' : '';
				}.bind(elm));
				Event.observe(elm,'focus',function(){
					var prompt = this.getAttribute('prompt');
					if (trim(this.value) == prompt){
						var oThis = this
						setTimeout(function(){oThis.select()},150);
					}
				}.bind(elm));
				Event.observe(elm,'keyup',function(){
					var prompt = this.getAttribute('prompt');
					if (trim(this.value) == prompt)
						this.style.color = '#999'
					else
						this.style.color = '';
				}.bind(elm));
				if (elm.value == ''){
					elm.value = prompt;
					elm.style.color = '#999';
				}
			}
			if (elm.getAttribute('date'))
				Event.observe(elm,'blur',validateDate.bind(this,elm));
		}

		var a = this.form.select('.chkDiv');
		var cb, ts;
		for (var i=0;i<a.length;i++){
			cb = document.createElement('input');
			cb.type = 'checkbox';
			
			//chkDiv
			cb.setAttribute('defaultVal',a[i].getAttribute('defaultVal'));
			cb.setAttribute('value',a[i].getAttribute('value'));
			//cb.setAttribute('name',a[i].getAttribute('name'));
			cb.name = a[i].getAttribute('name');
			cb.setAttribute('offValue',a[i].getAttribute('offValue'));
			
			ts = document.createElement('span');
			ts.innerHTML = a[i].getAttribute('label');
			Object.extend(a[i].style,{padding:'0px 4px 2px 1px', cursor:'pointer',  display:'inline-block'});//border:'1px solid #999',
			a[i].check = function(checked){ // if no parm is passed will return current setting.  pass true to turn on or false to turn off.
				if (checked == undefined){
					checked = this.getAttribute('checked');
					return (checked=='false') ? false : checked;
				}
				return this.setClass(checked);
			};
			a[i].setClass = function(checked){
				this.setAttribute('checked',checked)
				this.firstChild.checked = checked;
				(checked) ? this.addClassName('chkDivChecked') : this.removeClassName('chkDivChecked');
				return checked;
			};
			//alert(a[i].parentNode.innerHTML);
			cb.getValue = function(){
				return this.checked ? this.value : this.getAttribute('offValue');
			};
			Event.observe(a[i],'click',function(){
				var checked = this.getAttribute('checked');
				checked = (checked=='false') ? true : !checked;
				this.setClass(checked);
			}.bind(a[i]));
			a[i].appendChild(cb);
			a[i].appendChild(ts);
			//alert(a[i].parentNode.innerHTML);
		}
		this.elms = this.form.getElements();
		return this;
	}

	,insert	:	function(elm){
		this.getElementsByClassName('closeImg')[0].style.display='none';
		this.close = function(){return}
		this.__insert(elm);
	}
	//what the box will do when the default button is pressed, or the enter key is pressed
	,onEnterKey		:	function(){ alert('Error!\nMissing onEnterKey callback function.');}
	
	,focus			:	function(){
		var tries = 0;
		var oThis = this;
		if (!this.elms)
			this.elms = this.form.getElements();
		var fx = function(){
			if (!oThis.elms.length){
				return;
			}
			//try {oThis.elms[0].focus()}
			try {oThis.form.focusFirstElement()}
			catch (err) {
				if (tries++ < 5)
					setTimeout(fx,50)
			};
		}
		setTimeout(fx,50);
		return this;
	}
	
	,onkeypress		:	function(e){
		var vChars;
		var ev = (e)?e:event;
		var t = $(ev.srcElement || ev.target);
		var k = ev.keyCode || ev.charCode;
		if (k==9)
			return;
			
		if (vChars = t.getAttribute('vChars'))
			vChars = vChars.split('');
		else
			return k!=13 || t.tagName == 'TEXTAREA';
		if (vChars.indexOf(String.fromCharCode(k))==-1)
			return false
	}
	,reset	: function(){this.form.reset();return this}
	,cursorPos : function (elm){
		
		var i=elm.value.length+1;
		if (elm.createTextRange){
			theCaret = document.selection.createRange().duplicate();
			elm.selectedLength = theCaret.text.length
			while ( theCaret.parentElement() == elm	&& theCaret.move("character",1)==1 ) 
				--i;
		}
		return  i-1
	}
	
	,handleKeys 	:	function(e){
		var t = $(e.srcElement || e.target);
		var k = e.keyCode;
		if (k==13){
			if (t.tagName === 'TEXTAREA')
				return;
			this.onEnterKey(e);
			Event.stop(e);
			return;
		}
		
		if(e.ctrlKey && k != 17)
			if (k == 88 || k == 86 || k==67)
				return;
		
		if (k!=9){
			var digits = t.getAttribute('digits');
			if (digits){
				var a = digits.split('.')
				digits = a[0];
				var decimal = (a.length>1) ? a[1] : 0;
			}
		}
		if (!digits && k!=9)
			return;
			
		if (k==39 || k==37 || k==46 || k==8 || k==35 || k==36) //allowed keys
			return;

		t.cursorPos = this.cursorPos(t);
		
		var ta = t.value.split('');
		var d=null;
		
		var a = t.value.split('.')
		
		for (var i=0;i<ta.length;i++){
			if (ta[i]=='.'){
				d=i;
				break;
			}
		}
		if (k!=9){
			if (digits && (a.length==1 || d >= t.cursorPos) && a[0].replace(/,/g,  '').length >= digits && k!=190 && !t.selectedLength){
				Event.stop(e)
				return
			}
			if (a.length > 1 && decimal && ((d < t.cursorPos && a[1].replace(/,/g,  '').length >= decimal) || k==190)){
				Event.stop(e)
				return
			}
		
			if (!(k >= 48 && k<=57) && !(k >= 96 && k<=105))
				if (!decimal || k!=190){
					Event.stop(e)
					return
				}
		}
		if(k==9){
			var myElms = $A(this.elms)
			var buttons = this.getElementsByTagName('button');
			for (var i =0;i<buttons.length;i++)
				myElms.push(buttons[i]);
				
			if(t==myElms[0] && e.shiftKey)
				var toElm = myElms[myElms.length-1]
			else if (t==myElms[myElms.length-1] && !e.shiftKey)
				var toElm = myElms[0]

			if (toElm){
				CSI.clearSelection();
				toElm.focus();
				if (toElm.select)
					toElm.select();
				Event.stop(e);
			}
		}
	}
}
function createSearchForm(optObj){
	optObj = optObj || {}
	f = createForm(optObj);
	f.formBody.innerHTML = '<span style="display:inline;overflow:auto"><input type=text></span>'
	f.searchInput = f.formBody.getElementsByTagName('input')[0];
	var rsw = optObj.resultsShadowWidth==undefined ? 3 : optObj.resultsShadowWidth;
	var rso = optObj.resultsShadowOpacity==undefined ? 50 : optObj.resultsShadowOpacity;
	f.resultsDiv = createBox({shadowWidth:rsw,shadowOpacity:rso});
	f.resultsDiv.addClassName(optObj.resultsClassName || 'resultsDiv');
	f.resultsDiv.innerHTML = 'aaa';
	f.titleSpan.innerHTML = optObj.Title || 'Search';
	f.resultsDiv.position(f.searchInput).adjLeft(1).adjTop(1);
	f.resultsDiv.parentForm = f;
	f._sf_positionShadow = f.positionShadow;
	f._sf_close = f.close;
	f.resultsDiv._rd_show = f.resultsDiv.show;
	Object.extend(f.resultsDiv,resultsDivMethods);
	Object.extend(f,searchMethods);
	f.resultsDiv.moBound = f.resultsDiv.mouseover.bind(f.resultsDiv);
	Event.observe(f.resultsDiv,'mouseover',f.resultsDiv.moBound)
	
	Event.observe(f.resultsDiv,'click',f.resultsDiv.on_click.bindAsEventListener(f.resultsDiv))

	Event.observe(f.searchInput,'click',function(){
		if (this.searchResults && this.searchResults.length > 0){
			//$('ta').value += 'settimeout;';
			setTimeout(this.resultsDiv.show.bind(this.resultsDiv),25);
		}
	}.bind(f));
	return f;
}





searchMethods = {
	onclick : function(ev){
		e = ev || event;
		t = $(e.srcElement || e.target);
		if (t.autoSuggest && t.searchResults)
			this.processMatches(t);
	}

	,onkeydown: function(ev){
		var e = ev || event;
		if (e.keyCode == 38){	// up arrow
			if (this.resultsDiv.highlighted)
				this.move($(this.resultsDiv.highlighted.previousSibling))
			Event.stop(e);
		}else if (e.keyCode == 40){ 	// down arrow
			if (this.resultsDiv.highlighted)
				this.move($(this.resultsDiv.highlighted.nextSibling))
			Event.stop(e);
		}else if (e.keyCode == 27) {   // esc
			this.resultsDiv.close();
			this.resultsDiv.removeHighlight();
			Event.stop(e);
		}
	}
	,getSearchInput : function(e){
		var t = $(e.srcElement || e.target);
		if (!t.autoSuggest)
			return null;
		return t;
	}
	,onkeyup	: function(ev){
		e = ev || event;
		var searchInput = this.getSearchInput(e);
		if (!searchInput)
			return;
			
		if (searchInput.savedValue && trim(searchInput.savedValue) == trim(searchInput.value))
			return;
		searchInput.savedValue = searchInput.value
		if (searchInput.timeoutId){
			clearTimeout(searchInput.timeoutId);
			searchInput.timeoutId = null;
		}
		var oThis = this;
		if (e.keyCode == 8 || e.keyCode == 32 || (e.keyCode >= 46 && e.keyCode <= 111) || e.keyCode >123){
			if (this.resultsDiv.hasClassName('msg'))
				this.resultsDiv.close();
				
			this.resultsDiv.removeHighlight();
			searchInput.searchResults = null;
			if (searchInput.value.strip().length >= searchInput.autoSuggest.minSearchChars){
				if (typeof(searchInput.autoSuggest.searchProvider) == 'function'){
					searchInput.searchResults = searchInput.autoSuggest.searchProvider();
					this.processMatches(searchInput);
				}
				else if (typeof(searchInput.autoSuggest.searchProvider) == 'string')
					this.timeoutId = setTimeout(function(){
						oThis.search(searchInput);},225);

				if (this.http){
					if (this.http.transport.readyState != 4)
						this.http.transport.abort();
					this.http.transport.readyState == 5;
				}
			}
			else {
				this.resultsDiv.close();
				this.searchResults = null;
			}
		}
					
	}
	,search	: function(searchInput){
		if (this.http){
			this.http.transport.abort();
		}
		var parms = {data:searchInput.value};
		if (this.parameters)
			Object.extend(parms,this.parameters);
			
		this.http = new Ajax.Request(searchInput.autoSuggest.searchProvider+'?data='+this.searchInput.value,{
			parameters:parms
			,method:'post'
			,onSuccess:function(t){eval(t.responseText)}.bind(this)
		})
		this.timeoutId = null;
	}
	,noMatches:function(){
		var rd = this.resultsDiv;
		rd.innerHTML = 'No Matches';
		rd.removeHighlight();
		rd.addClassName('msg').show()
	}
	,highlight : function(i){
		var trs = this.resultsDiv.getElementsByTagName('tr')
		//if (!trs || !trs.length)
		//	return;
		this.resultsDiv.removeHighlight();
		$(trs[i]).addClassName('highlight');
		this.resultsDiv.highlighted = trs[i];
	}
	,move : function(elm){
		if (elm){
			var rd = this.resultsDiv;
			var h = this.resultsDiv.highlighted;
			if (h) 
				h.removeClassName('highlight')
			elm.addClassName('highlight')
			rd.highlighted = elm;
			var table = rd.firstChild;
			if (table.offsetHeight > rd.offsetHeight){
				if (elm.offsetTop+elm.offsetHeight > rd.offsetHeight+rd.scrollTop){
					Event.stopObserving(rd,'mouseover',rd.moBound);
					rd.scrollTop += elm.offsetHeight;
					rd.timeoutId = setTimeout(function(){Event.observe(rd,'mouseover',rd.moBound)},25)
				}
				else
				if (elm.offsetTop < rd.scrollTop){
					Event.stopObserving(this.resultsDiv,'mouseover',this.resultsDiv.moBound)
					rd.scrollTop -= elm.offsetHeight;
					rd.timeoutId = setTimeout(function(){Event.observe(rd,'mouseover',rd.moBound)},25)
				}
			}
		}
	}
	,onEnterKey : function(ev){
		e = ev || event;
		var searchInput = this.getSearchInput(e);
		if (!searchInput)
			return;

		var tries = 0;
		var oThis = this;
		var rd = this.resultsDiv;
		
		if (!rd.highlighted)
			return;
			
		// waitForAjax is only needed if search Provider is an ajax program.  this handles the situation where the user hit 
		// enter before the ajax program displayed.  wait for the response, then select the first result from searchResults;
		if (typeof(searchInput.autoSuggest.searchProvider)=='string'){
			var waitForAjax = function(){
				if (tries++ > 100){
					alert('timed out');
					return;
				}
				if (!oThis.timeoutId && !oThis.http)
					return;
			
				if (oThis.timeoutId || oThis.http.transport.readyState != 4 || oThis.resultsDiv.style.visibility=='hidden'){   // pending Ajax request
					setTimeout(fx,50)
					return;
				}
	
				if ((searchInput.value.length < searchInput.autoSuggest.minSearchChars)
				&& (rd.parentNode.visibility == 'hidden' || rd.hasClassName('msg'))){
					alert('Please enter at least \n'+searchInput.autoSuggest.minSearchChars+' characters to search.')
					return;
				}
				
				if (rd.hasClassName('msg')){
					return;
				}
				
				if (searchInput.autoSuggest.onSelect && rd.highlighted){
					searchInput.autoSuggest.onSelect.call(searchInput,e,rd.highlighted.getAttribute('i'));
					window.clearTimeout(rd.showTimeout)
					setTimeout(function(){rd.close()},25);
				}
			};
			waitForAjax();
			return;
		}
		searchInput.autoSuggest.onSelect.call(searchInput,e,rd.highlighted.getAttribute('i'))
		rd.close();
	}
	,ondblclick : function(){
		if (this.searchResults){
			this.resultsDiv.show();
		}
	}
	,createCells : function(i){  // this function should normally be overwritten
		return '<td>tim is great</td>';
	}
	,processMatches : function(searchInput){
		var sr = searchInput.searchResults;
		var rd = this.resultsDiv;
		if (!sr || !sr.length){
			if (searchInput.autoSuggest.onNoResults)
				searchInput.autoSuggest.onNoResults.call(searchInput);
			else
				rd.close();
			return;
		}
				
		rd.removeClassName('msg')
		var a = ['<table cellspacing=0 cellpadding=0>'];
		for (var i = 0;i<sr.length;i++){
			a.push('<tr i="'+i+'"')
			if (!(i%2))
				a.push(' class="odd"');
			a.push('>'+searchInput.autoSuggest.resultsFilter(sr[i])+'</tr>')
		}
		a.push('</table>');
		rd.innerHTML = a.join('');
		rd.style.width = '';
		var w = rd.offsetWidth;
		var sIw = searchInput.offsetWidth;
		if (w < sIw)
			$(rd.getElementsByTagName('table')[0]).setStyle({width:(sIw-5)+'px'})
		
		rd.onSelect = searchInput.autoSuggest.onSelect.bind(searchInput) || function(){};
		rd.position(searchInput).show();
		this.highlight(0);
	}
}
resultsDivMethods = {
	mouseover : function(ev){
		var e = ev || event;
		t = $(e.srcElement || e.target);
		if (t.tagName == 'TD'){
			var tr = t.parentNode;
			if (tr == this.highlighted)
				return;
			if (this.highlighted)
				this.highlighted.removeClassName('highlight');
			$(tr).addClassName('highlight');
			this.highlighted = tr;
		}
	}
	,removeHighlight : function(){
		if (this.highlighted){
			this.highlighted.removeClassName('highlight');
			this.highlighted = null;
		}
	}
	,onclick : function(e){
		var ev = e || event;
		var t = $(ev.srcElement || ev.target);
		if (this.onSelect && this.highlighted){
			this.onSelect(e,this.highlighted.getAttribute('i'));
		}
	}
}
/*
							End of jsform.js
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							Start of pushform.js
*/
pushformVPath = "/wwwroot/lib/csitools/2.0/";
var d = new Date().getTime();
document.write('<iframe name="timiscool" id="testFrame" style="display:none" src="'+pushformVPath+'pushform.html?'+d+'"></iframe>')
//

overlayArray=[];

Event.observe(window,'load',function(){
	Event.observe(document,'keyup',function(e){
		if (e.keyCode == 27){
			if(overlayArray.currentPage >= 0){
				history.go(-1);
				insertDivReg();// calling insert DivReg with no div parameter, will result in all divs being flushed;
			}
		}
	}.bindAsEventListener(this))
})

initScript = '<script>alert(37);par=window.parent;'+
	'if(par.overlay)'+
	'	par.cleanupOverlay(-1);'+
	'if (par.overlayArray && par.overlayArray.reInit){'+
	'	par.overlayArray.reInit()'+
	'}</script>'
	
overlayArray.truncate = function(index){
	for (var i=index;i<overlayArray.length;i++)
		overlayArray.close(i)
}


function pushForm(div, optionsObj){
	optionsObj = optionsObj || {};
	var last=prev=0; 

	truncateOverlayArray();

	getScroll();
	if (window.pageYOffset)	{
		  var scrollTop = window.pageYOffset
		  var scrollLeft = window.pageXOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)	{
		var scrollTop = document.documentElement.scrollTop
		var scrollLeft = document.documentElement.scrollLeft
	}
	else if (document.body){
		  var scrollTop = document.body.scrollTop
		  var scrollLeft = document.body.scrollLeft
	}
	
	if (window.innerHeight){
		var windowHeight = window.innerHeight
		var windowWidth = window.innerWidth
	}
	else if (document.documentElement && document.documentElement.clientHeight)	{
		var windowHeight = document.documentElement.clientHeight
		var windowWidth = document.documentElement.clientWidth
	}
	else if (document.body)	{
		var windowHeight = document.body.clientHeight;
		var windowWidth = document.body.clientWidth;
	}
	if (overlayArray.length==0)
		var currentZ = 0;
	else {
		var x = overlayArray.length-1;
		while (overlayArray[x] && !overlayArray[x].style && x > 0)
			x--;
		if (overlayArray[x] && overlayArray[x].style)
			var currentZ = parseInt(overlayArray[x].style.zIndex)
		else
			var currentZ = 0;
	}
	
	if (!window.overlay){
		overlay = document.createElement('div');
		overlay.id = 'overlay';
		overlay.onclick='event.cancelBubble=true';
		overlay.style.position='absolute';
		overlay.style.top='0';
		overlay.style.left='0';
		overlay.style.display='none';
		overlay.style.opacity='.5';
		overlay.style.filter='Alpha(Opacity=50)';
		overlay.style.backgroundColor='black';
		document.body.appendChild(overlay); 
	}
	if (optionsObj.opacity){
		overlay.style.opacity=optionsObj.opacity;
		overlay.style.filter='Alpha(Opacity='+optionsObj.opacity*100+')';
	}
	if (optionsObj.color){
		overlay.style.backgroundColor=optionsObj.color;
	}
	overlay.style.height = Math.max(windowHeight, document.body.scrollHeight)+'px';
	overlay.style.width = Math.max(windowWidth, document.body.scrollWidth)+'px';
	
	last = overlayArray.length
	overlayArray[last]= div;
	
	div.screenTop = div.saveScreenTop = scrollTop;

	overlayArray.currentPage = last;
	
	div.style.zIndex = currentZ+20;
	
	var divTop = Math.max(scrollTop, Math.round(scrollTop+((windowHeight-div.clientHeight)/2)))
	var divLeft = Math.round(scrollLeft+((windowWidth-div.clientWidth)/2))
	
	div.style.top = Math.max(divTop,0)+'px'
	div.style.left = Math.max(divLeft,0)+'px'

	var newZ = currentZ+10;
	//div.boundHandler = lockWindow.bindAsEventListener(div);
	//writeScript(initScript)
	writeScript(createDivJs(last,newZ));
}

CSI.fixRefresh = function(idx){
	if (!overlayArray.reachedStart){
		overlayArray.close(idx);
		history.back();
	}
}
function createDivJs(x,newZ){
	var a=['<script>;'
	,'	var par=window.parent;'
	,'	var fe, back;'
	,'	var me = '+x+';'
	,'  if (me < par.overlayArray.currentPage) {back = true; };'
	,'	if (par.userClickedRefresh){'
	,'		par.CSI.fixRefresh(me);'
	,'	}else {'
	,'		if(par.overlayArray[me]=="end"){	'
	,'			history.back();	'
	,'		}else if(par.overlayArray[me]=="closed"){	'
	,'			if (back)	{ 	'
	,'				history.back();} '
	,'			else {	'
	,'				history.forward(); }'
	,'		}else if (!par.overlayArray[me]){		'
	,'			par.overlayArray.close(me);	'
	//,'			//par.userClickedRefresh = true;	'
	,'			history.back();	'
	,'		}else{			'
	,'			par.overlay.style.display="";'
	,'			par.overlay.style.zIndex='+newZ+'; '
	,'			par.overlayArray[me].style.visibility="visible";'
	,'			if(par.overlayArray[me].firstChild.focus) par.overlayArray[me].firstChild.focus();'
	,'			par.cleanupOverlay(me);'
	,'		}	'
	,'	}'
	,'</script>'];
	
	return a.join('\n');
}
function createFxJs(x){
	var a=['<script>'
	,'	par=window.parent;'
	,'	var me = '+x+';'
	,'	par.cleanupOverlay(me);'
	,'	if (par.overlayArray.length-1 > me && par.overlayArray[me+1].style && par.overlay.style.display==""){ '
	,'		par.overlay.style.display="none";'
	,'		par.overlayArray[me+1].style.visibility="hidden";'
	,'	}else if (par.overlayArray[me] == "closed"){	'
	,'		par.overlayArray.close(me);	'
	,'		history.go(-1);	'
	,'	}else if (par.overlayArray[me] == "closed"){	'
	,'		par.overlayArray.close(me);	'
	,'		history.forward();	'
	,'	}else if (par.overlayArray.length-1 >= me){ '
	,'		par.overlayArray[me]();'
	,'	};	'
	,'</script>']
	return a.join('');
}

function truncateOverlayArray(){
	if (window.overlayArray && overlayArray.currentPage < overlayArray.length-1){
		overlayArray.splice(overlayArray.currentPage+1,999)
	}
}




function pushF(fx){
	truncateOverlayArray();
	var x = overlayArray.length;
	overlayArray[x]= fx;
	overlayArray.currentPage = x;
	writeScript(createFxJs(x))
}

function writeScript(historyScript){
	if (!window.sessionFrame){
		sessionFrame = $('testFrame');
	}	
	
	var doc = sessionFrame.contentWindow.document;
	if (sessionFrame.contentDocument){
		sessionFrame.src= pushformVPath+'echo.cfm?data='+historyScript;
	}
	else {
		doc.open();
		doc.write(historyScript)
		doc.close();
	}
}

function popForm(destroy){
	if (destroy){
		overlayArray.close(overlayArray.currentPage);
	}
	history.back();
}

overlayArray.close = function(i){
	turnItOff(i);
	this[i] = 'closed';
}


function turnItOff(ixx){
	var item = overlayArray[ixx];
	
	if (!item)
		return;
	if (item.saveScreenTop)
		scroll(0,item.saveScreenTop);
		
	if (item.style)
		item.style.visibility="hidden";

}

function cleanupOverlay(current){
	overlayArray.currentPage = current;
	if (current == -1){
		turnItOff(0);
		return;
	} 
	
	for (var i = 0;i<overlayArray.length;i++){
		//Event.stopObserving(document.body,'scroll',overlayArray[i].boundHandler)
		//Event.stopObserving(window,'scroll',overlayArray[i].boundHandler)
		
		if (i>current){
			if (overlayArray[i].style){
				overlayArray[i].style.visibility="hidden";
			}
		}
		else if (i==current){
			if (i+1 < overlayArray.length && overlayArray[i+1].saveScreenTop)
				scroll(0,overlayArray[i+1].saveScreenTop)
			//if (window.parent.isFunction(overlayArray[i].boundHandler)){
			//	Event.observe(document.body,'scroll',overlayArray[i].boundHandler)
			//	Event.observe(window,'scroll',overlayArray[i].boundHandler)
			//}
		}
	}
}

/*
function lockWindow(div){
	if (window.pageYOffset)	{
		  var scrollTop = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)	{
		var scrollTop = document.documentElement.scrollTop
	}
	else if (document.body)	{
		  var scrollTop = document.body.scrollTop
	}
	
	if (window.innerHeight)	{
		var clientHeight = window.innerHeight-16
	}
	else if (document.documentElement && document.documentElement.clientHeight)	{
		var clientHeight = document.documentElement.clientHeight
	}
	else if (document.body)	{
		var clientHeight = document.body.clientHeight
	}
	
	
	if (clientHeight >= this.offsetHeight){
		if (scrollTop < this.screenTop){
			if (this.offsetTop+this.offsetHeight > scrollTop+clientHeight){
				scroll(0,this.offsetTop+this.offsetHeight-clientHeight)
				this.screenTop = this.offsetTop+this.offsetHeight-clientHeight
			}
		}
		if (scrollTop > this.screenTop){
			if (scrollTop > this.offsetTop){
				scroll(0,this.offsetTop)
				this.screenTop = this.offsetTop
			}
		}
	}
	else {
		if (scrollTop < this.screenTop){
			if (this.offsetTop > scrollTop){
				scroll(0,this.offsetTop)
				this.screenTop = this.offsetTop
			}
		}
		if (scrollTop > this.screenTop){
			if (this.offsetTop+this.offsetHeight < scrollTop+clientHeight){
				scroll(0,this.offsetTop+this.offsetHeight-clientHeight)
				this.screenTop = this.offsetTop+this.offsetHeight-clientHeight
			}
		}
	}
}
*/



/*
							End of pushform.js
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							Start of Calendar Control.js
*/
CSSRule('#CalendarControlIFrame', {display:'none',left: '0px', position: 'absolute',top: '0px', height: '250px',width: '250px',zIindex: 99});
CSSRule('#CalendarControl',{position:'absolute',backgroundColor:'#FFF',margin:0,padding:0,display:'none',zIndex: 100});
CSSRule('#CalendarControl table',{fontFamily:'arial, verdana, helvetica, sans-serif',fontSize:'8pt',borderLeft:'1px solid #336',borderRight:'1px solid #336'});
CSSRule('#CalendarControl th',{fontWeight:'normal'});
CSSRule('#CalendarControl th a',{fontWeight:'normal',textDecoration:'none',color:'#FFF',padding:'1px'});
CSSRule('#CalendarControl td',{textAlign:'center'});
CSSRule('#CalendarControl .header',{backgroundColor:'#336'});
CSSRule('#CalendarControl .weekday',{backgroundColor:'#DDD',color:'#000'});
CSSRule('#CalendarControl .weekend',{backgroundColor:'#FFC',color:'#000'});
CSSRule('#CalendarControl .current',{border:'1px solid #339',backgroundColor:'#336',color:'#FFF'});

var tObj = {display:'block',textDecoration:'none',border:'1px solid #FFF',width:'2em'}
CSSRule('#CalendarControl .current',tObj);
CSSRule('#CalendarControl .weekday',tObj);
CSSRule('#CalendarControl .weekend',tObj);

tObj = {border:'1px solid #999',backgroundColor:'#336',color:'#fff'};
CSSRule('#CalendarControl .weekday:hover',tObj);
CSSRule('#CalendarControl .weekend:hover',tObj);
CSSRule('#CalendarControl .current:hover',tObj);

CSSRule('#CalendarControl .previous', {textAlign:'left',padding:'1px 3px 1px 3px',fontSize:'1.4em'});
CSSRule('#CalendarControl .next',{textAlign:'right',padding:'1px 3px 1px 3px',fontSize:'1.4em'});

tObj = {color:'#fff',textDecoration:'none',fontWeight:'bold'};

CSSRule('#CalendarControl .previous a',tObj);
CSSRule('#CalendarControl .next a',tObj);

CSSRule('#CalendarControl .title', {textAlign: 'center',fontWeight: 'bold',color: '#FFF'});

CSSRule('#CalendarControl .empty',{backgroundColor: '#CCC',border: '1px solid #FFF'});

//document.write('<style>@import "/lib/csitools/2.0/calendarcontrol.css";</style>');

function positionInfo(object) {
  var p_elm = object;

  this.getElementLeft = getElementLeft;
  function getElementLeft() {
    var x = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      x+= elm.offsetLeft;
      elm = elm.offsetParent;
    }
    return parseInt(x);
  }

  this.getElementWidth = getElementWidth;
  function getElementWidth(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetWidth);
  }

  this.getElementRight = getElementRight;
  function getElementRight(){
    return getElementLeft(p_elm) + getElementWidth(p_elm);
  }

  this.getElementTop = getElementTop;
  function getElementTop() {
    var y = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      y+= elm.offsetTop;
      elm = elm.offsetParent;
    }

	if ((y - document.body.scrollTop) > (document.body.clientHeight/2))
		y = y - (calendar.clientHeight + getElementHeight());
	
    return parseInt(y);
  }

  this.getElementHeight = getElementHeight;
  function getElementHeight(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetHeight);
  }

  this.getElementBottom = getElementBottom;
  function getElementBottom(){
    return getElementTop(p_elm) + getElementHeight(p_elm);
  }
}


Event.observe(window,'load',function(){
	Event.observe(document.body,'click',function(event){
		var src = event.target || event.srcElement;
		while (src && src.id != 'CalendarControl'){
			src = src.parentNode;
		}
		if (!src || src.id != 'CalendarControl'){
			setTimeout(hideCalendarControl,1);
		}
	})
})

function CalendarControl() {

  var calendarId = 'CalendarControl';
  var currentYear = 0;
  var currentMonth = 0;
  var currentDay = 0;

  var selectedYear = 0;
  var selectedMonth = 0;
  var selectedDay = 0;

  var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
  var dateField = null;

  /*function getProperty(p_property){
    var p_elm = calendarId;
    var elm = null;

    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    if (elm != null){
      if(elm.style){
        elm = elm.style;
        if(elm[p_property]){
          return elm[p_property];
        } else {
          return null;
        }
      } else {
        return null;
      }
    }
  }*/

  function setElementProperty(p_property, p_value, p_elmId){
    var p_elm = p_elmId;
    var elm = null;

    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    if((elm != null) && (elm.style != null)){
      elm = elm.style;
      elm[ p_property ] = p_value;
    }
  }

  function setProperty(p_property, p_value) {
    setElementProperty(p_property, p_value, calendarId);
  }

  function getDaysInMonth(year, month) {
    return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
  }

  function getDayOfWeek(year, month, day) {
    var date = new Date(year,month-1,day)
    return date.getDay();
  }

  this.clearDate = clearDate;
  function clearDate() {
    dateField.value = '';
    hide();
  }

  this.setFocus = setFocus;
  function setFocus() {
    dateField.focus();
  }

  this.setDate = setDate;
  function setDate(year, month, day) {
    if (dateField) {
      if (month < 10) {month = "0" + month;}
      if (day < 10) {day = "0" + day;}

      var dateString = month+"/"+day+"/"+year;
      dateField.value = dateString;
      setTimeout(hide,25);
    }
    return;
  }

  this.changeMonth = changeMonth;
  function changeMonth(change) {
    currentMonth += change;
    currentDay = 0;
    if(currentMonth > 12) {
      currentMonth = 1;
      currentYear++;
    } else if(currentMonth < 1) {
      currentMonth = 12;
      currentYear--;
    }

    calendar = document.getElementById(calendarId);
    calendar.innerHTML = calendarDrawTable();
  }

  this.changeYear = changeYear;
  function changeYear(change) {
    currentYear += change;
    currentDay = 0;
    calendar = document.getElementById(calendarId);
    calendar.innerHTML = calendarDrawTable();
  }

  function getCurrentYear() {
    var year = new Date().getYear();
    if(year < 1900) year += 1900;
    return year;
  }

  function getCurrentMonth() {
    return new Date().getMonth() + 1;
  } 

  function getCurrentDay() {
    return new Date().getDate();
  }

  function calendarDrawTable() {
    var dayOfMonth = 1;
    var validDay = 0;
    var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
    var daysInMonth = getDaysInMonth(currentYear, currentMonth);
    var css_class = null; //CSS class for each day

    var table = "<table cellspacing='0' cellpadding='0' border='0'>";
    table = table + "<tr class='header'>";

    table += " <td colspan='2' class='previous'>"
	if (notbefore && currentMonth <= notbefore.getMonth()+1 && currentYear <= notbefore.getFullYear())
		table += "<a style='color:#999999'>&lt;</a>"
	else
		table += "<a href='javascript:changeCalendarControlMonth(-1);'>&lt;</a>" //href='javascript:changeCalendarControlMonth(-1)
		
	if (notbefore && (((currentYear - 1) < notbefore.getFullYear()) || ((currentYear - 1) == notbefore.getFullYear() && currentMonth < notbefore.getMonth()+1)))
		table += "<a  style='color:#999999'>&laquo;</a></td>";
	else
		table += "<a href='javascript:changeCalendarControlYear(-1);'>&laquo;</a></td>";

    table += "<td colspan='3' class='title'>" + months[currentMonth-1] + "<br>" + currentYear + "</td>";
	table += "<td colspan='2' class='next'>"
	
	if (notafter && (((currentYear + 1) > notafter.getFullYear()) || ((currentYear + 1) == notafter.getFullYear() && currentMonth > notafter.getMonth()+1)))
	    table = table + "<a style='color:#999999' >&raquo;</a>";
	else
	    table = table + "<a href='javascript:changeCalendarControlYear(1);'>&raquo;</a>";

	if (notafter && (currentMonth >= notafter.getMonth()+1 && currentYear >= notafter.getFullYear()))
		table = table + "  <a style='color:#999999' >&gt;</a></td>";
	else
		table = table + "  <a href='javascript:changeCalendarControlMonth(1);'>&gt;</a></td>";

    table = table + "</tr>";
    table = table + "<tr><th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th></tr>";

    for(var week=0; week < 6; week++) {
      table = table + "<tr>";
      for(var dayOfWeek=0; dayOfWeek < 7; dayOfWeek++) {
		if(week == 0 && startDayOfWeek == dayOfWeek) {
			validDay = 1;
		} else if (validDay == 1 && dayOfMonth > daysInMonth) {
			validDay = 0;
		}

		if(validDay) {
			if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
				css_class = 'current';
			} else if (dayOfWeek == 0 || dayOfWeek == 6) {
				css_class = 'weekend';
			} else {
				css_class = 'weekday';
			}
			if (notafter && ((currentYear == notafter.getFullYear() && currentMonth == notafter.getMonth()+1 && dayOfMonth > notafter.getDate()))
			|| (notbefore && (currentYear == notbefore.getFullYear() && currentMonth == notbefore.getMonth()+1 && dayOfMonth < notbefore.getDate())))
				table = table + "<td><a class='"+css_class+"' style='color:#999999' >"+dayOfMonth+"</a></td>";
			else
				table = table + "<td><a class='"+css_class+"' href=\"javascript:setCalendarControlDate("+currentYear+","+currentMonth+","+dayOfMonth+")\">"+dayOfMonth+"</a></td>";
			dayOfMonth++;
		} else {
			table = table + "<td class='empty'>&nbsp;</td>";
        }
      }
      table = table + "</tr>";
	}
	if (!dateRequired)
	    table = table + "<tr class='header'><th colspan='7' style='padding: 3px;'><a href='javascript:clearCalendarControl();'>Clear</a> | <a href='javascript:hideCalendarControl();'>Close</a></td></tr>";
	else
	    table = table + "<tr class='header'><th colspan='7' style='padding: 3px;'><a href='javascript:hideCalendarControl();'>Close</a></td></tr>";
    table = table + "</table>";

    return table;
  }

  this.show = show;
  function show(field) {
    can_hide = 0;
	dateRequired = !!eval(field.getAttribute('required'));  // convert the string "false" and null object to a boolean false
		
	initAfterBefore(field);

	if (dateField == field) {
		return;
	} 
	else {
		dateField = field;
	}

    if(dateField) {
      try {
        var dateString = new String(dateField.value);
        var dateParts = dateString.split("/");
        
        selectedMonth = parseInt(dateParts[0],10);
        selectedDay = parseInt(dateParts[1],10);
        selectedYear = parseInt(dateParts[2],10);
      } catch(e) {}
    }
	if (selectedYear < 80)
		selectedYear += 2000;
	else if (selectedYear < 100)
		selectedYear += 1900;
	else if (selectedYear < 2099 && selectedYear > 1899)
		;
	else 
		selectedYear = null;
		
    if (!(selectedYear && selectedMonth && selectedDay)) {
      selectedMonth = getCurrentMonth();
      selectedDay = getCurrentDay();
      selectedYear = getCurrentYear();
    }

    currentMonth = selectedMonth;
    currentDay = selectedDay;
    currentYear = selectedYear;

	if (notafter){
		if (currentYear > notafter.getFullYear() || (currentYear == notafter.getFullYear() && currentMonth > notafter.getMonth()+1) || (currentYear == notafter.getFullYear() && currentMonth == notafter.getMonth()+1 && currentDay > notafter.getDate())){
		    currentMonth = notafter.getMonth()+1;
		    currentDay = notafter.getDate();
		    currentYear = notafter.getFullYear();
		}
		if (selectedYear > notafter.getFullYear() || (selectedYear == notafter.getFullYear() && selectedMonth > notafter.getMonth()+1) || (selectedYear == notafter.getFullYear() && selectedMonth == notafter.getMonth()+1 && selectedDay > notafter.getDate())){
		    selectedMonth = notafter.getMonth()+1;
		    selectedDay = notafter.getDate();
		    selectedYear = notafter.getFullYear();
		}
	}
	
	if (notbefore){
		if (currentYear < notbefore.getFullYear() || (currentYear == notbefore.getFullYear() && currentMonth < notbefore.getMonth()+1) || (currentYear == notbefore.getFullYear() && currentMonth == notbefore.getMonth()+1 && currentDay < notbefore.getDate())){
		    currentMonth = notbefore.getMonth()+1;
		    currentDay = notbefore.getDate();
		    currentYear = notbefore.getFullYear();
		}
		if (selectedYear < notbefore.getFullYear() || (selectedYear == notbefore.getFullYear() && selectedMonth < notbefore.getMonth()+1) || (selectedYear == notbefore.getFullYear() && selectedMonth == notbefore.getMonth()+1 && selectedDay < notbefore.getDate())){
		    selectedMonth = notbefore.getMonth()+1;
		    selectedDay = notbefore.getDate();
		    selectedYear = notbefore.getFullYear();
		}
	}
	

    if(document.getElementById){
		if (!(calendar = $(calendarId))){
			// create the iframe and div for the calendar only when needed.
			var iFrame = document.createElement('iframe');
			iFrame.id = 'CalendarControlIFrame';
			iFrame.frameBorder='1';
			iFrame.scrolling = 'no';
			document.body.appendChild(iFrame);
			
			calendar = document.createElement('div');
			calendar.id = 'CalendarControl';
			calendar.onClick = 'event.cancelBubble=true';
			document.body.appendChild(calendar);
		}
		calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
		setProperty('display', 'block');
		
		if (dateField.calendarPositionParent)
			var fieldPos = new positionInfo(dateField.parentNode);
		else
			var fieldPos = new positionInfo(dateField);
			
		var calendarPos = new positionInfo(calendarId);
		
		var x = fieldPos.getElementLeft();
		var y = fieldPos.getElementBottom();
		
		setProperty('left', x + "px");
		setProperty('top', y + "px");
 
      if (document.all) {
        setElementProperty('display', 'block', 'CalendarControlIFrame');
        setElementProperty('left', x + "px", 'CalendarControlIFrame');
        setElementProperty('top', y + "px", 'CalendarControlIFrame');
        setElementProperty('width', calendarPos.getElementWidth() + "px", 'CalendarControlIFrame');
        setElementProperty('height', calendarPos.getElementHeight() + "px", 'CalendarControlIFrame');
      }
    }
  }

  this.hide = hide;
  function hide() {
    if(dateField) {
      setProperty('display', 'none');
      setElementProperty('display', 'none', 'CalendarControlIFrame');
      dateField = null;
    }
  }

  this.visible = visible;
  function visible() {
    return dateField
  }

  this.can_hide = can_hide;
  var can_hide = 0;
}
var calendarControl = new CalendarControl();

function initAfterBefore(field){
	notafter = new Date();
	notbefore = new Date();

	notafter.setFullYear(2079,11,31)
	notafter.setHours(23,59,59,999)

	notbefore.setFullYear(1900,0,1)
	notbefore.setHours(0,0,0,0)

	if (field.notafter = field.getAttribute('notafter')){
		if (document.getElementById(field.notafter)){
			var myObj = document.getElementById(field.notafter)
			var dateString = trim(myObj.value)
			if (dateString == '' && (myObj.notafter=myObj.getAttribute('notafter')))
				if (!document.getElementById(myObj.notafter))
					dateString = myObj.notafter
		}
		else
			var dateString = field.notafter;
		if (dateString > ' '){
	        var dateParts = dateString.split("/");
			myYear = parseInt(dateParts[2],10);
			if (myYear < 80)
				myYear += 2000;
			else if (myYear < 100)
				myYear += 1900;
			notafter.setFullYear(myYear,parseInt(dateParts[0]-1,10),parseInt(dateParts[1],10))
		}
	}
	
	if (field.notbefore = field.getAttribute('notbefore')){
		if (document.getElementById(field.notbefore))
			var dateString = document.getElementById(field.notbefore).value
		else
			var dateString = field.notbefore;
		if (dateString > ' '){
	        var dateParts = dateString.split("/");
			myYear = parseInt(dateParts[2],10);
			if (myYear < 80)
				myYear += 2000;
			else if (myYear < 100)
				myYear += 1900;
			notbefore.setFullYear(myYear,parseInt(dateParts[0]-1,10),parseInt(dateParts[1],10))
		}
	}
}

function showCalendarControl(textField) {
	calendarControl.show(textField);
}

function clearCalendarControl() {
	var myobj = calendarControl.visible();
	calendarControl.clearDate();
	myobj.focus();
	if (myObj.fireEvent)
		myobj.fireEvent("onchange");
}

function hideCalendarControl() {
  if (calendarControl.visible()) {
    calendarControl.hide();
  }
}
function cancelTimeOuts() {
	if (window.myVtimeoutholder) {
		window.clearTimeout(myVtimeoutholder)
	}
}

function setCalendarControlDate(year, month, day) {
	//window.cancelBubble = true;
	var mystring = year + '';
	//year = mystring.substr(2,2)
	var myobj = calendarControl.visible();
	myobj.focus();
	calendarControl.setDate(year, month, day);
	if (myobj.fireEvent)
		myobj.fireEvent("onchange");
}

function changeCalendarControlYear(change) {
	if (window.myVtimeoutholder)
		window.clearTimeout(myVtimeoutholder)
	calendarControl.changeYear(change);
	calendarControl.setFocus();
}


function changeCalendarControlMonth(change) {
	if (window.myVtimeoutholder)
		window.clearTimeout(myVtimeoutholder)
	calendarControl.changeMonth(change);
	calendarControl.setFocus();
}

function parseDate(dateString){
	var myDate = new Date();
    var dateParts = dateString.split("/");
	var myYear = parseInt(dateParts[2],10);
	if (myYear < 80)
		myYear += 2000;
	else if (myYear < 100)
		myYear += 1900;
	myDate.setFullYear(myYear,parseInt(dateParts[0]-1,10),parseInt(dateParts[1],10))
	return(myDate);
	
}
function validateDate(fld) {
	if (window.myVtimeoutholder)
		window.clearTimeout(myVtimeoutholder)
	
	if (validateDate.arguments.length > 0){
		gfld = fld;
		myVtimeoutholder = setTimeout("validateDate()",300);
		return;
	}

	if (gfld.style.visibility == 'hidden' || gfld.parentNode.style.visibility == 'hidden'  )
	 	return;
		
	var fld = gfld;

	var prompt = fld.getAttribute('prompt');
	if (prompt && fld.value == prompt)
		var testValue = '';
	else
		var testValue = fld.value;
		


	initAfterBefore(fld);
	
	fld.style.backgroundColor = '';
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    var errorMessage = 'Please enter valid date as month, day, and two digit year.\nFormat is mm/dd/yy.\nOr select a valid date from the Calendar.';



	var required = !!eval(fld.getAttribute('required'));  // convert the string "false" and null object to a boolean false
	//Dec2010 Tim O'Brien  above line replaces following:
	//var required = false;
	//if (fld.required)
	//	required = true;

	var t = $(fld);
	while (t.getStyle && t.getStyle('visibility')==='inherit'){
		t = $(t.parentNode);
	}
	
	if (t.getStyle && t.getStyle('visibility')!= 'visible')
		return true;

	if (!required && trim(testValue) == ''){
		fld.validate = 'passed';
		return true;
	}

    if (testValue.match(RegExPattern)){
		var secondaryError = false;
		testValue = testValue.replace(/\-/g,"/")
		testValue = testValue.replace(/\./g,"/")
		if (notbefore){
			if (parseDate(testValue) < notbefore){
				errorMessage = 'Date out of Range.\nMust be after '+notbefore
				secondaryError = true;
			}
		}
		if (notafter){
			if (parseDate(testValue) > notafter){
				errorMessage = 'Date out of Range.\nMust be before '+notafter
				secondaryError = true;
			}
		}
		if (!secondaryError){
			fld.validate = 'passed';
	        return true; 
		}
	}
	if (window.submitAction) {
		window.clearTimeout(submitAction)
	}
	if (trim(testValue) == ''){
		errorMessage = 'Date is required.\n' + errorMessage;
	}
	else
		errorMessage = 'Date Formatting error.\n' + errorMessage;
		
	
	fld.style.backgroundColor = "#DE6C74";
	alert(errorMessage);
	fld.validate = 'failed';
	//setTimeout("gfld.focus()",3);
	if (window.myVtimeoutholder)
		window.clearTimeout(myVtimeoutholder)
	return(false)
}
function tabKey(event){
	if (event.keyCode == 9)
		hideCalendarControl();
}


function createSelect(optObj){
	var options = optObj.options;
	CSSRule('.jsSelect', {backgroundColor:'white', paddingLeft:'3px', border:'1px solid #000', position:'relative', backgroundPosition: 'right center', backgroundRepeat:'no-repeat', backgroundImage: 'url(down-arrow.gif)'});
	CSSRule('.jsSelectPullDown', {backgroundColor:'white', borderStyle:'solid', borderColor: '#999', borderLeftWidth:'3px',  borderWidth:'1px', cursor:'pointer', position:'absolute'}); //, borderWidth:'0px 1px 1px 1px', borderStyle:'solid'
	CSSRule('.jsSelectOption',{paddingLeft:'3px', cursor:'pointer'});
	CSSRule('.test', {position: 'absolute', height:'auto', width:'auto', visibility:'hidden'});  //
	CSSRule('.coverDiv', {position:'absolute', top:'0px', left: '0px', height:'25px', cursor:'pointer'});
	var hoverStyle = {backgroundColor:'red'}
	if (optObj.optionHoverStyle){
		Object.extend(hoverStyle,optObj.optionHoverStyle);
	}
	CSSRule('.jsSelectHover',hoverStyle);
	
	
	var maxWidth = 0;
	var selected;
	var initialize = true;
	
	var name= optObj.name || optObj.id;
	var id = optObj.id || optObj.name;
	
	var test, test2, test3, testItems;
	testItems = document.getElementsByClassName('test');
	if (!testItems.length){ 
		test = $(document.createElement('div'));
		test2 = $(document.createElement('div'));
		test3 = $(document.createElement('div'));
		test.className = 'jsSelect test';
		test2.className = 'jsSelectOption test';
		test3.className = 'jsSelectPullDown test';
		document.body.appendChild(test);
		document.body.appendChild(test2);
		document.body.appendChild(test3);
	}
	else {       // if creating a second pulldown,  use the same test elements already created.
		test = testItems[0];  // the select div
		test2 = testItems[1];  // option div
		test3 = testItems[2];	// pulldown div (holds all the options);
	}
	
	var div = document.createElement('div');
	
	var select = $(document.createElement('div'));
	select.className = 'jsSelect';
	if (optObj.selectStyle){
		Object.extend(select.style,optObj.selectStyle);
		Object.extend(test.style,optObj.selectStyle);
	}
	var paddingLeft = parseInt(test.getStyle('paddingLeft'));
	select.appendChild(document.createElement('span'));
	select.name = name;
	Event.observe(select,'mousedown',function(event){
		pullDown.toggle();
		Event.stop(event);
	});
	Event.observe(select,'mouseover',function(event){
		document.body.style.cursor = 'pointer';
	});
	Event.observe(select,'mouseout',function(event){
		document.body.style.cursor = '';
	});
	Event.observe(select,'mousemove',CSI.clearSelection);
	select.set = function(obj){
		var val = obj.value || obj.text;
		if (input.value == val){
			return;
		}
		this.firstChild.innerHTML = obj.text;
		input.value = val;
		if (!initialize){
			if (div.fx){
				div.fx(input);
			}
			fireEvent(input,'change');
		}
		initialize = false;
	}
	var coverDiv = document.createElement('div');
	coverDiv.className='coverDiv';
	select.appendChild(coverDiv);
	div.appendChild(select);
	
	var pullDown = $(document.createElement('div'));
	pullDown.className = 'jsSelectPullDown';
	if (optObj.pullDownStyle){
		Object.extend(pullDown.style,optObj.pullDownStyle);
		Object.extend(test3.style,optObj.pullDownStyle);
	}
	pullDown.style.borderTopWidth = '0px';
	pullDown.toggle();
	Event.observe(document,'mousedown',function(){
		this.hide();
	}.bind(pullDown));
	div.appendChild(pullDown);
	Event.observe(pullDown,'mousemove',CSI.clearSelection);
	
	var input = document.createElement('input');
	input.type = 'hidden';
	input.id = id;
	input.name = name;
	
	for (var i=0;i<options.length;i++){
		pullDown.appendChild(createOption(options[i]));
	}
	if (!selected){
		select.set(options[0]);
	}
	// these calculations are necessary in case the css border width(s) are changed.
	// this will allow the right and left borders to be set 

	var borderAdj = (parseInt(test3.getStyle('borderLeftWidth'))+parseInt(test3.getStyle('borderRightWidth')))
					-(parseInt(test.getStyle('borderLeftWidth'))+parseInt(test.getStyle('borderRightWidth')));

	coverDiv.style.width = pullDown.style.width = 	(maxWidth+(Math.max(borderAdj*-1,0)))+'px';
	select.style.width = (maxWidth-paddingLeft+(Math.max(borderAdj,0)))+'px';
	coverDiv.style.height = test.getHeight()+'px';
	
	div.appendChild(input);
	
	return div;
	
	function createOption(obj){
		test2.innerHTML = test.innerHTML = obj.text;
		maxWidth = Math.max(maxWidth, Math.max(test.getWidth()+15,test2.getWidth()));
		
		var o = document.createElement('div');
		o.className = 'jsSelectOption';
		if (optObj.optionStyle){
			Object.extend(o.style,optObj.optionStyle);
			Object.extend(test2.style,optObj.optionStyle);
		}
		o.innerHTML = obj.text;
		if (obj.selected && !selected){
			select.set(obj);
			selected= true;
		}
		Event.observe(o,'mouseup',function(){
			select.set(obj);
			pullDown.hide();
		});
		Event.observe(o,'mousedown',function(event){
			Event.stop(event);
		});
		Event.observe(o,'mouseover',function(event){
			o.addClassName('jsSelectHover');
		});
		Event.observe(o,'mouseout',function(event){
			o.removeClassName('jsSelectHover');
		});
		return o;
	}
}
function fireEvent(element,event){
    if (document.createEventObject){  //  IE
		var evt = document.createEventObject();
		return element.fireEvent('on'+event,evt)
    }
    else{	// all others
		var evt = document.createEvent("HTMLEvents");
		evt.initEvent(event, true, true ); // event type,bubbling,cancelable
		return !element.dispatchEvent(evt);
    }
}
function testPhone(phoneNum){
	var exp = new RegExp(/^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x|x| ext)\d{1,5}){0,1}$/);
	if (phoneNum.match(exp)) {
   		return true;
 	} else {
 		return false;
 	}
}
//document.write("<iframe id='CalendarControlIFrame' src='' frameBorder='1' scrolling='no'></iframe>");
//document.write("<div id='CalendarControl' onclick='event.cancelBubble=true' ></div>");

//abort cancels the response of an ajax in FF, Chrome, and others. In IE it atually stops the server side operations.
Ajax.Request.prototype.abort = function() {
    this.transport.onreadystatechange = Prototype.emptyFunction;
    this.transport.abort();
    Ajax.activeRequestCount--;
	
};
//cancel response just cancels the onSuccess, onFailure, etc. functions of an ajax request.
Ajax.Request.prototype.cancelResponse = function() {
    this.transport.onreadystatechange = Prototype.emptyFunction;
};
