function string_trim()
	{
	var nasty=new String(this.toString());
	//debug(nasty.substring(0,1).length);
	//debug("X"+nasty.substring(0,1)+"X");
	while (nasty.substring(0,1)==" ")
		{
		nasty=nasty.substring(1,nasty.length);
		};
	while (nasty.substring(nasty.length-1,nasty.length)==" ")
		{
		nasty=nasty.substring(0,nasty.length-1);
		};
	return nasty;
	}

function date_add(strCode)
	{
	var NewDate; var nNum; var strUnit;
	//debug(strCode);
	var strAdditional=new String();
	strAdditional=strAdditional.concat(strCode);
	strAdditional=strAdditional.trim();
	var spaceAt=strAdditional.indexOf(" ");
	if ((spaceAt>-1) && (spaceAt<4))
		{
		nNum=parseInt(strAdditional);
		strUnit=strAdditional.substring((spaceAt+1), strAdditional.length).trim();
		}
	else
		{
		nNum=1;
		strUnit=strAdditional.trim();
		};
	
	switch (strUnit.toLowerCase().valueOf()) 
		{
		case 'day':
		case 'days':
		case 'd':
			NewDate=new Date(this.getTime()+((1000*60*60*24*1)*nNum));
			break;
		case 'week':
		case 'weeks':
		case 'w':
			NewDate=new Date(this.getTime()+((1000*60*60*24*7)*nNum));
			break;
		case 'month':
		case 'months':
		case 'm':
			month=(this.getMonth()+nNum);
			year=this.getFullYear().valueOf();
			day=this.getDate().valueOf();
			while (month>11)
				{
				month+=(-12);
				year++;
				};
			day=Math.min(day, this.daysInMonth(month));
			NewDate=new Date(year, month, day);
			break;
		case 'year':
		case 'years':
		case 'y':
			month=this.getMonth();
			year=this.getFullYear()+nNum;
			day=Math.min(this.getDate(), this.daysInMonth(month));
			NewDate=new Date(year, month, day);
			break;
		case 'perpetual':
			month=this.getMonth();
			year=this.getFullYear()+50;
			day=Math.min(this.getDate(), this.daysInMonth(month));
			NewDate=new Date(year, month, day);
			break;
		default :
			NewDate=this;
			break;
		}
	return NewDate;
	}
	
function date_daysInMonth(month) {return new Array(31,28,31,30,31,30,31,31,30,31,30,31)[month];}

function date_getShort()
	{
	if (this.getFullYear()<1940) {this.setFullYear(this.add('100 years').getFullYear())};
	var s="";
	s += (this.getMonth() + 1) + "/";
	s += this.getDate() + "/";
   	s += this.getFullYear();                         
	return s;
	}

function form_validate()
	{
	var isValid=true;
	var thisObject;
	var formElements;
	var errorBullet=((this.errorBullet) ? (this.errorBullet) : '')
	var errorMessage=((this.invalidMessage) ? (this.invalidMessage) : 'Please correct the following errors:\n\n')
	formElements = ( (document.all) ? (this.all) : (this.elements) )
	for (var intCounter = 0; intCounter < (formElements.length); intCounter++)
		{
		thisObject=formElements[intCounter];
		if ((thisObject.validPattern) && (!thisObject.validPattern.test(thisObject.value))) {
			isValid=false;
			errorMessage+= ((thisObject.validErrorMessage) ? (errorBullet+thisObject.validErrorMessage+'\n') : (errorBullet+'These was a problem with the entry in the field \''+thisObject.name+'\'\n'));
			};
		if ((thisObject.validate) && (!thisObject.validate())) {
			isValid=false;
			errorMessage += ((thisObject.validErrorMessage) ? (errorBullet+thisObject.validErrorMessage+'\n') : (errorBullet+'These was a problem with the entry in the field \''+thisObject.name+'\'\n'));
			};
		};
	if (!isValid) {
		alert(errorMessage)
		};
	return isValid;
	}

function select_atLeastOne()
	{
	return !(this.selectedIndex==-1);
	}

function select_validateSELLINE()
	{
	var out=true;
	this.realValue=valuableObject_realValue;
	if ((this.stageIndex<this.form.submittedItem.stageIndex) && (this.realValue()!==this.originalValue))
		{
		if (this.selectedIndex==-1)
			{
			this.validErrorMessage='You made no selection ' + ((this.caption) ? (this.caption) : 'at an earlier stage.') ;
			}
		else
			{
			this.validErrorMessage='You changed ' + ((this.caption) ? 'the value you previously selected for ' + (this.caption) : 'a value you had previously selected.') ;
			//this.validErrorMessage+=this.name+'\n';
			//this.validErrorMessage+=this.stageIndex+'\n';
			//this.validErrorMessage+=this.form.submittedItem.stageIndex+'\n';
			
			}
		out=false;

		//debug(this.value+'!=='+this.originalValue);
		//this.value=this.originalValue;
		};
	if ((this.stageIndex==this.form.submittedItem.stageIndex) && (this.selectedIndex==-1))
		{
		this.validErrorMessage='You must select at least one value' + ((this.caption) ? ' for ' + (this.caption) : '')+'.' ;
		out=false;
		};
	if ((this.stageIndex<=this.form.submittedItem.stageIndex) && (this.realValue() == '{DISABLED}')) {
		this.validErrorMessage='Your selection has been disabled.\n\nItems in red are disabled.\nPlease make another selection.';
		this.value=this.originalValue;
		out=false;
		};
	if ((this.stageIndex<=this.form.submittedItem.stageIndex) && (this.realValue() == '{CAPTION}')) {
		this.validErrorMessage='The option you selected is for display purposes only.';
		this.value=this.originalValue;
		out=false;
		};
	return out;
	}

function valuableObject_realValue()
	{
	var out;
	if (this.value)	{
		out = this.value;
		}
	else {
		if ((this.options) && (this.selectedIndex!==-1)) {
			out = this.options[this.selectedIndex].value;
			}
		else
			{
			out = '';
			}
		};
	return out;
	}


String.prototype.trim		=string_trim;
Date.prototype.add			=date_add;
Date.prototype.getShort		=date_getShort;
Date.prototype.daysInMonth	=date_daysInMonth;
//

//function getRandomUserName()
//	var out;
//	for (var i=1;i<=9;i++) {
//		out+=chr(randy(65,90));
//	}
//end function
//
//function randy(nMin, nMax)
//	dim nOut
//	nOut = cint(rnd()*(nmax-nmin))+nMin
//	randy=nOut
//end function


// Generic window opening functions
function openWindow(sHREF, windname, nTop, nLeft, nHeight, nWidth, sToolbar, sMenubar, sLocation, sResizable, sScrollbars)
	{
	var sParamString='top=' + nTop + ',left=' + nLeft + ',' + newWindSizeString(nHeight, nWidth) + ',toolbar='+sToolbar+',menubar='+sMenubar+',location='+sLocation+',resizable='+sResizable+',scrollbars='+sScrollbars
	var newWindow=window.open(sHREF,windname, sParamString);
	newWindow.focus();
	return newWindow;
	}

function newWindSizeString(nHeight, nWidth)
	{
	var out;
	if (document.all) {
		out='height=' + nHeight + ',width=' + nWidth		}
	else {
		out='outerHeight=' + (nHeight + 39) + ',outerWidth=' + (nWidth + 20)		};
	return out;
	}

function openInfoWindow(sHREF, nTop, nLeft, nHeight, nWidth, sResize, sName) 		{return openWindow(sHREF, sName, nTop, nLeft, nHeight, nWidth, 'no','no','no',sResize,'no');}
function openInfoWindowScroll(sHREF, nTop, nLeft, nHeight, nWidth, sResize, sName)	{return openWindow(sHREF, sName, nTop, nLeft, nHeight, nWidth, 'no','no','no',sResize,'yes');}
function openApplicationWindow(sHREF, nTop, nLeft, nHeight, nWidth, sName) 			{openWindow(sHREF, sName, nTop, nLeft, nHeight, nWidth, 'no','no','no','yes','yes');}

// Static window opening functions:
function openDisabledWindow() 				{openInfoWindow('/public/Public_Disabled.asp',30,30,466,300,'yes', 'disabled')}
function openAboutWindow() 					{openInfoWindow('/public/Public_AboutUs.asp',40,40,475,400,'yes', 'popup')}
function openPrivacyPolicyWindow() 			{openInfoWindowScroll('/public/Public_PrivacyPolicy.asp', 40, 40, 400, 400,'yes', 'popup')}
function openAcceptableUsePolicyWindow() 	{openInfoWindowScroll('/public/Public_AcceptableUsePolicy.asp', 40, 40, 500, 400,'true', 'popup')}
function openFAQsWindow() 					{openInfoWindowScroll('/public/Public_FAQs.asp', 40, 40, 600, 600,'yes', 'popup')}
function openLinksWindow() 					{openInfoWindowScroll('/public/Public_Links.asp', 40, 40, 600, 600,'yes', 'popup')}
function openOtherRegionsWindow() 			{openInfoWindowScroll('/public/Public_OtherRegions.asp', 40, 40, 250, 440,'yes','popup')}
function openDedicationWindow() 			{openInfoWindowScroll('/public/Public_Dedication.asp', 40, 40, 320, 280,'yes','popup')}
function openAboutUsWindow() 				{openInfoWindowScroll('/public/Public_AboutUs.asp', 40, 40, 600, 380,'yes','popup')}
function openSuggestWindow() 				{openApplicationWindow('security/Module_Admin_IssueNew.asp?MODE=NEW',40,40,425,500)}
function openLogoutWindow() 				{openApplicationWindow('Module_Logout.asp', 40, 40, 425, 575)}

// Context-sensitive window opening functions
function openHelpWindow(programArea, programSubArea)	{if (programArea.constructor.toString().indexOf('String')>0) {openInfoWindowScroll('fHelp/helpitem.asp?PROGRAMAREA='+programArea+'&PROGRAMSUBAREA='+programSubArea,30,30,600,400,'yes','popup')} else {openInfoWindowScroll('fHelp/helpitem.asp?HELPID='+programArea,30,30,600,400,'yes','popup')}	}
function openExportWindow(nQueryID, sType) 			{openApplicationWindow('Module_Export.asp?QUERYID=' + nQueryID + '&type=' + sType, 40, 40, 425, 575)}
function openChartWindow(nQueryID) 						{openApplicationWindow('/fChart/getChart.asp?QUERYID=' + nQueryID, 40, 40, 425, 575)}
function openDataWindow(nQueryID, sType)				{openApplicationWindow('Module_DisplayData.asp?QUERYID=' + nQueryID + '&type=' + sType, 40, 40, 300, 325);}	
function openDataInfo(sOwnerTable, sID)								{openApplicationWindow('fDataInfo/datainfoitem.asp?OWNERTABLE=' + sOwnerTable + '&ID='+sID, 40, 40, 425, 575, 'datainfo')}


/*function openDataSearch(sSearchType, sValues)			{
		if ((!sSearchType) || (sSearchType=='DEFAULT')) {
			openInfoWindowScroll('fDataSearch/datasearch.asp?SEARCHTYPE=DEFAULT', 40, 40, 500, 425, 'datasearch');
			}
		else {
			if (!sValues)	{
				openInfoWindowScroll('fDataSearch/datasearch.asp?SEARCHTYPE='+sSearchType, 40, 40, 500, 425, 'datasearch');
				}
			else {
				openInfoWindowScroll('fDataSearch/datasearch.asp?SEARCHTYPE='+sSearchType+'&IDS='+sValues, 40, 40, 500, 425, 'datasearch');			
				}
			}
		}
*/
function openDataSearch(sSearchType, sValues)			{
		if (!sSearchType) {sSearchType=='DEFAULT'};
		var sLocation='/fDataSearch/datasearch_AreaProfile.asp?SEARCHTYPE='+sSearchType;
		if (sValues)	{sLocation+='&IDS='+sValues;}
		top.Main.location=sLocation;
		}

// Location and context setting functions

function GoToPage(PageName) {top.Main.location = PageName;}

function changeSideBar(sProgramArea, sProgramSubArea)
	{
		if (top.SideBar)
			{
			if (top.SideBar.currentArea)
				{
				top.SideBar.changedMain(sProgramArea,sProgramSubArea)
				}
			else 
				{
				top.refreshSideBar();
				//top.SideBar.location = 'Main_Sidebar.asp'
				};
			};
	}


// Browser-independent functions that return a reference to an obj/form		

function obj(ItemName)
	{
	if (document.all)
		{
		return document.all(ItemName)
		}
	else
		{
		for (i=0;i<=(document.forms.length-1);i++)
			{
				if (eval('document.forms[' + i + '].' + ItemName))
					{
						return eval('document.forms[' + i + '].' + ItemName);
					};
			};
		};
	}
	
function form(ItemName)
	{
	if (document.all)
		{
		return document.forms(ItemName)
		}
	else
		{
		for (i=0;i<=(document.forms.length-1);i++)
			{
			if (document.forms[i].name == ItemName)
				{
					return document.forms[i];
				}
			};
		};
	}


function getItemRef(ItemName, ItemForm) { return objInForm(ItemName, form(ItemForm));}
function objInForm(sItemName, oForm)
	{
	var item;
	if (document.all)
		{ item = oForm(sItemName) }
	else
		{ item = eval('document.' + oForm.name + '.' + sItemName) };
	return item;
	}

// Misc
function toggleDisplays(arrFormNames)
	{
	var formie;
		//alert('hi');
		//alert(arrFormNames.sort);
	if (arrFormNames.sort)
		{
		for (var i=0;i<arrFormNames.length;i++)
			{
			formie=form(arrFormNames[i]);
			//alert(i+' '+arrFormNames[i]);
			//alert(formie.style.display);
			alert(document.layers.length);
			if (formie.style.display=='none')
				{
				formie.style.display='block' 
				}
			else
				{
				formie.style.display='none' 
				};
			}
		}
	else
		{
		formie=form(arrFormNames);
		if (formie.style.display=='none')
			{
			formie.style.display='block' 
			}
		else
			{
			formie.style.display='none' 
			};
		}
	}


function printSelf() {self.print();}

function newSearch()
	{
	var sDocName = document.location.pathname;
	var q;
	if (document.all)
		{
		q = new RegExp('?'.toString);
		}
		else
		{
		q = new RegExp('?');
		};
	if (sDocName.search(q) > -1)
		{
		sDocName = sDocName.substring(0, sDocName.search(q));
		};
	document.location = sDocName;
	}


// Form + input interaction routines	
function selectAll(item)
	{
	for (var intCounter = 0; intCounter < (item.options.length); intCounter++)
		{
		item.options[intCounter].selected=true
		};
	}

function submitMultiSelect(item)
	{
	if (item.selectedIndex>-1)
		{
		submitForm(item)
		}
	else
		{
		if (item.noneSelectedErrMsg)
			{
			alert(item.noneSelectedErrMsg)
			}
		else
			{
			alert('Please select at least one item from the list')
			}
		};
	}
	
/*
function submitForm(item)
	{
	if ((!item.form) && (item.length))
		{
		item=item[0]
		}
	var oform=item.form;
	oform.submittedItem=item;
	oform.validate=form_validate;

	if (oform.validate()) {
		var sDocName = document.location.pathname;
		var q=sDocName.indexOf('?');
		
		//	alert(q);
		if (q>-1) {sDocName=sDocName.substring(0, q)}
		if (window.event && window.event.name)
			{
			var sEventName = window.event.type;
			};
		
		var sSourceName = item.name;
		var sAdditionalParams=getAdditionalParams();
		var sFormName = oform.name;
		//debugger;
		//		alert(sAdditionalParams);
		oform.method = 'POST';
		oform.action = sDocName + '?EVENTSOURCE=' + sSourceName + '&FORM=' + sFormName + sAdditionalParams;
		//alert(oform.action);
		oform.submit();
		}
	}
*/

function submitForm(item, formname, clickData)
	{
	if (formname) {
		//we are just submitting a string in item
		
		var oform=form(formname);
		oform.sourceName=item;
	}
	else {
		if ((!item.form) && (item.length))
			{
			item=item[0];
			}
		var oform=item.form;
		oform.submittedItem=item;
		oform.sourceName=item.name;
	}
	
	oform.validate=form_validate;		
	if (oform.validate()) {
		var sDocName = document.location.pathname;
		var q=sDocName.indexOf('?');
		
		//	alert(q);
		if (q>-1) {sDocName=sDocName.substring(0, q)}
		if (window.event && window.event.name)
			{
			var sEventName = window.event.type;
			};
		
		var sSourceName = oform.sourceName;
		var sAdditionalParams=getAdditionalParams();
		var sFormName = oform.name;
		//debugger;
		//		alert(sAdditionalParams);
		oform.method = 'POST';
		oform.action = sDocName + '?EVENTSOURCE=' + sSourceName + '&FORM=' + sFormName + ( (clickData) ? '&EVENTDATA='+clickData : '' ) + sAdditionalParams;
		//alert(oform.action);
		oform.submit();
		}
	}	


var qStringParams = new Array;
	
function getAdditionalParams()
	{
	var result='';
	for (var i=0;i<qStringParams.length;i++)
		{  
		result+='&'+qStringParams[i].name+'='+qStringParams[i].value
		}		
	if (window.submissionInfo)
		{
		var si = new submissionInfo;
		result+=si.additionalParams;
		}
	return result;
	}


function qStringParam(sQStringVarName, sQStringVarValue)
	{
	this.name=sQStringVarName;
	this.value=sQStringVarValue;
	}

function addQStringParam(sQStringVarName, sQStringVarValue)
	{
	qStringParams[qStringParams.length]= new qStringParam(sQStringVarName, sQStringVarValue)
	}

function addOptions(ChildSelect, intListCount, arrChildValues, arrChildText)
	{
	ChildSelect.length = 0;
	for (var intCounter = 0; intCounter < (intListCount); intCounter++)
	{
		var xOption;
	    if (document.all)
	    {
	        xOption = document.createElement('OPTION');
	        xOption.value = arChildValues[intCounter];
	        xOption.text = arChildText[intCounter];
	        if (arChildValues[intCounter] == '{DISABLED}') {xOption.className = 'Disabled'};
	        if (arChildValues[intCounter] == '{CAPTION}') {xOption.className = 'Caption'};
	        ChildSelect.options.add(xOption);
	    }
	    else
	    {
			var sText = arChildText[intCounter];
			var sValue = arChildValues[intCounter];
	        xOption = new Option(sText, sValue, false, false);
			if (sValue == '{DISABLED}') {xOption.className = 'Disabled'};
			if (sValue == '{CAPTION}')
				{
				xOption.className = 'Caption';
				xOption.text = '---- ' + sText + ' ----';
				};
	        ChildSelect.options[ChildSelect.length] = xOption;
	    }
	};
	ChildSelect.selectedIndex = -1;
	ChildSelect.size = 15;
	}
	



function submitOnConfirmDelete(objSubmittor, sPrompt)
	{
	var msg=(sPrompt ? sPrompt : 'Are you sure you want to delete this item?');
	//if (sPrompt) {msg=sPrompt} else {msg='Are you sure you want to delete this item?'}
		
	if (window.confirm(msg)) 
		{
		submitForm(objSubmittor);
		};
	}

function submitFormOnCode(obj, evt, keyNum) {
	{
	if (keyWas(keyNum, evt))
		{
		submitForm(obj);
		return false;
		}
	else
		{
		return true;
		}
	}
}
function submitFormOnEnter(obj, evt) {return submitFormOnCode(obj, evt, 13)}

// Deprecated form validation routines
var validCriteria = new Array;

function validCriterion(sFormName, sInputName, regexpPattern, sErrMsg)
	{
	this.FormName=sFormName
	this.InputName=sInputName
	this.RX=regexpPattern
	this.ErrMsg=sErrMsg
	}

function addCriterion(sFormName, sInputName, regexpPattern, sErrMsg)
	{
	validCriteria[validCriteria.length]= new validCriterion(sFormName, sInputName, regexpPattern, sErrMsg)
	}




// Key-pressed tests
function keyPressedCode(evt)
	{
	return ((document.all) ? window.event.keyCode : evt.which )
	};


function keyWas(keyNum, evt) {return (keyPressedCode(evt)==keyNum);	}
function keyWasEnter(evt) 	{return (keyWas(13, evt));};
	
function processTab(evt) {
	if (document.all && keyWas(9, evt)) 
		{
		var s = document.selection;
		var tr = s.createRange();
		if ( tr !== null ) 
			{
			tr.text = "\t";
			}
		return false;
		}
	else
		{
		return true;
		}
}


// Programming/Debugging utilities
function pageReport() 
	{	if (pageInfo)
		{
		var pi = new pageInfo;
		var output = 'Timer: ' + pi.TimerReport + '\nQueryString: ' + pi.QueryString + '\nForm: ' + pi.Form + '\nCookies: ' + pi.Cookies;
		debug(output);
		};
	}

function debug(obj) {if (document.location.host=='localhost') {alert(obj);};}

// Table manipulation routines
function sortRowsOwner(sSectionName, colIndex)
	{
	document.body.style.cursor='wait';
	var biddy=document.all(sSectionName);
	biddy.style.display='none';
	var arr=new Array();
	for (var i=0;i<biddy.rows.length;i++)
		{
		arr[arr.length]=(new sortableRow(i, biddy.rows(i), colIndex));
		}

	arr2=arr.sort(sortEm);
	for (i=0;i<arr2.length;i++)
		{
		addRow(biddy, arr2[i].row);
		}

	for (i=0;i<arr2.length;i++)
		{
		biddy.deleteRow(0)
		}
	biddy.style.display='block';
	document.body.style.cursor='default';
	}

function sortableRow(rowIndex, otr, sortOnCellIndex)
	{
	this.row=otr;
	this.origIndex=rowIndex;
	this.valueOf=otr.cells(sortOnCellIndex).innerText.toUpperCase();
	}

function sortEm(obj1, obj2)
	{
	if (obj1.valueOf<obj2.valueOf) {return -1;};
	if (obj1.valueOf>obj2.valueOf) {return 1;};
	return 0;
	}

function addRow(otable, otr)
	{
	newtr=otable.insertRow();
	for (var i=0;i<otr.cells.length;i++)
		{
		newcell=newtr.insertCell();
		newcell.innerHTML=otr.cells(i).innerHTML;
		newcell.setAttribute('className', otr.cells(i).getAttribute('className'));
		}
	}
