

//	COMMON FUNCTIONS SHORTENED
//	(most functions are named the same as the asp versions)
//------------------------------------------------------------------------------------------------------------------------------------------------------------

	function dw(str) { document.write(str); }
	function rw(str) { document.write(str); } // the asp version
	
	function rr(url) { window.location.href=url; }
	function go(url) { window.location.href=url; }
	
	function rq(varName) {
		var qs = window.location.search;
		var rexp = new RegExp("("+varName+"=)","i");
		if ( varName == 0 ) { return qs; } // returns entire query string starting with ?
		else if ( qs.search(rexp) == -1 ) { return false; } // can't find this variable name in query string
		else {
			rexp.compile("([\?|&]"+varName+"=)([^&]*)","gi");
			var arVal = qs.match(rexp); // returns an array of matching name=value pairs, i.e. ["test=1","test=2","test=3"]
			var thisStr = "";
			for (i in arVal) { // loop through previous compiled array
				thisStr = arVal[i].split("="); // split each name=value pair at =
				arVal[i] = unescape(thisStr[1]); // reassign only the value to this spot in array
			}
			return arVal;
		}
	}

	function getRandomNum(lbound, ubound) {
		return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
	}
	

//------------------------------------------------------------------------------------------------------------------------------------------------------------



//	VARIABLES TO USE WITH DHTML OBJECTS
//------------------------------------------------------------------------------------------------------------------------------------------------------------
	var isDOM = (document.getElementById ? true : false); 
	var isIE4 = ((document.all && !isDOM) ? true : false);
	var isNS4 = (document.layers ? true : false);

	function getRef(id) {
		if (isDOM) return document.getElementById(id);
		if (isIE4) return document.all[id];
		if (isNS4) return document.layers[id];
	}
	function getSty(id) {
		return (isNS4 ? getRef(id) : getRef(id).style);
	}

// STRING PROTOTYPE FUNCTIONS------------------------------------------------------------------------------------------------------------------------------------------------------------
	function strltrim() {
	return this.replace(/^\s+/,'');
	}
	function strrtrim() {
	return this.replace(/\s+$/,'');
	}
	function strtrim() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
	}
	
	String.prototype.ltrim = strltrim;
	String.prototype.rtrim = strrtrim;
	String.prototype.trim = strtrim;
	
	/**** the above functions used like their VBScript counterparts ****/
	function lTrim(str) {
	return str.replace(/^\s+/,'');
	}
	function rTrim(str) {
	return str.replace(/\s+$/,'');
	}
	function trim(str) {
	return str.replace(/^\s+/,'').replace(/\s+$/,'');
	}	

// DATE FUNCTIONS----------------------------------------------------------------------------------------------------------------------------------

	function FormatDateTime(datetime, FormatType, abbr) {
	//**********************************************************************
	//	FormatType takes the following values
	//	1 - General Date = Friday, October 30, 1998
	//	2 - Typical Date = 10/30/98
	//	3 - Standard Time = 6:31 PM
	//	4 - Military Time = 18:31
	//	
	//	abbr (optional, default false) is boolean, 
	//	determines whether days and months are abbreviated
	//**********************************************************************

		var strDate = new String(datetime);
		var abbr = Boolean(abbr);
	
		if (strDate.toUpperCase() == "NOW") {
			var myDate = new Date();
			strDate = String(myDate);
		} else {
			var myDate = new Date(datetime);
			strDate = String(myDate);
		}
	
		// Get the date variable parts
		var Day = myDate.getDay();
		var dayName;
		switch (Day) {
			case 0 : dayName = (!abbr ? "Sunday" : "Sun"); break;
			case 1 : dayName = (!abbr ? "Monday" : "Mon"); break;
			case 2 : dayName = (!abbr ? "Tuesday" : "Tue"); break;
			case 3 : dayName = (!abbr ? "Wednesday" : "Wed"); break;
			case 4 : dayName = (!abbr ? "Thursday" : "Thur"); break;
			case 5 : dayName = (!abbr ? "Friday" : "Fri"); break;
			case 6 : dayName = (!abbr ? "Saturday" : "Sat");
		}

		var thisMonth = myDate.getMonth() + 1;
		var monthName;
		switch (thisMonth) {
			case 1 : monthName = (!abbr ? "January" : "Jan"); break;
			case 2 : monthName = (!abbr ? "February" : "Feb"); break;
			case 3 : monthName = (!abbr ? "March" : "Mar"); break;
			case 4 : monthName = (!abbr ? "April" : "Apr"); break;
			case 5 : monthName = (!abbr ? "May" : "May"); break;
			case 6 : monthName = (!abbr ? "June" : "Jun"); break;
			case 7 : monthName = (!abbr ? "July" : "Jul"); break;
			case 8 : monthName = (!abbr ? "August" : "Aug"); break;
			case 9 : monthName = (!abbr ? "September" : "Sep"); break;
			case 10 : monthName = (!abbr ? "October" : "Oct"); break;
			case 11 : monthName = (!abbr ? "November" : "Nov"); break;
			case 12 : monthName = (!abbr ? "December" : "Dec");
		}
		
		var monthDay = myDate.getDate();
			monthDay = (monthDay.length == 1 ? '0' + monthDay : monthDay+'');
		
		var Year = myDate.getFullYear();	
		var Hour = myDate.getHours();
		var Min = myDate.getMinutes() + '';
			Min = (Min.length == 1 ? '0' + Min : Min);
		
			
		// Format Type decision time!
		switch (FormatType) {
			case 1 :
				strDate = dayName + ", " + monthName + " " + monthDay + ", " + Year;
				break;
			case 2 :
				strDate = thisMonth + "/" + monthDay + "/" + Year;
				break;
			case 3 :
				var AMPM = ( Hour >= 11 ? 'PM' : 'AM' );
				switch(AMPM) {
					case 'PM' :
						strDate = Hour - 12;
						break; 
					default :
						Hour = (Hour == 0 ? '12' : Hour+'');
						strDate = Hour + '';
				}
				strDate += ':' + Min + ' ' + AMPM;
				break;
			case 4 :
				Hour = Hour + '';
				Hour = (Hour.length == 1 ? '0' + Hour : Hour);
				strDate = Hour + ':' + Min;
		}
	
		return strDate;
	}
	
	// ----------------------------------------------------------------------------------------------------------------------------------
	
	function dateAdd( start, interval, number ) {
		
	    // Create 3 error messages, 1 for each argument. 
	    var startMsg = "Sorry the start parameter of the dateAdd function\n"
	        startMsg += "must be a valid date format.\n\n"
	        startMsg += "Please try again." ;
			
	    var intervalMsg = "Sorry the dateAdd function only accepts\n"
	        intervalMsg += "d, h, m OR s intervals.\n\n"
	        intervalMsg += "Please try again." ;
	
	    var numberMsg = "Sorry the number parameter of the dateAdd function\n"
	        numberMsg += "must be numeric.\n\n"
	        numberMsg += "Please try again." ;
			
	    // get the milliseconds for this Date object. 
	    var buffer = Date.parse( start ) ;
		
	    // check that the start parameter is a valid Date. 
	    if ( isNaN (buffer) ) {
	        alert( startMsg ) ;
	        return null ;
	    }
		
	    // check that an interval parameter was not numeric. 
	    if ( interval.charAt == 'undefined' ) {
	        // the user specified an incorrect interval, handle the error. 
	        alert( intervalMsg ) ;
	        return null ;
	    }
	
	    // check that the number parameter is numeric. 
	    if ( isNaN ( number ) )	{
	        alert( numberMsg ) ;
	        return null ;
	    }
	
	    // so far, so good...
	    //
	    // what kind of add to do? 
	    switch (interval.charAt(0))
	    {
	        case 'd': case 'D': 
	            number *= 24 ; // days to hours
	            // fall through! 
	        case 'h': case 'H':
	            number *= 60 ; // hours to minutes
	            // fall through! 
	        case 'm': case 'M':
	            number *= 60 ; // minutes to seconds
	            // fall through! 
	        case 's': case 'S':
	            number *= 1000 ; // seconds to milliseconds
	            break ;
	        default:
	        // If we get to here then the interval parameter
	        // didn't meet the d,h,m,s criteria.  Handle
	        // the error. 		
	        alert(intervalMsg) ;
	        return null ;
	    }
	    return new Date( buffer + number ) ;
	}

// ----------------------------------------------------------------------------------------------------------------------------------
	function dateDiff( start, end, interval, rounding ) {
	
	    var iOut = 0;
	    
	    // Create 2 error messages, 1 for each argument. 
	    var startMsg = "Check the Start Date and End Date\n"
	        startMsg += "must be a valid date format.\n\n"
	        startMsg += "Please try again." ;
			
	    var intervalMsg = "Sorry the dateAdd function only accepts\n"
	        intervalMsg += "d, h, m OR s intervals.\n\n"
	        intervalMsg += "Please try again." ;
	
	    var bufferA = Date.parse( start ) ;
	    var bufferB = Date.parse( end ) ;
	    	
	    // check that the start parameter is a valid Date. 
	    if ( isNaN (bufferA) || isNaN (bufferB) ) {
	        alert( startMsg ) ;
	        return null ;
	    }
		
	    // check that an interval parameter was not numeric. 
	    if ( interval.charAt == 'undefined' ) {
	        // the user specified an incorrect interval, handle the error. 
	        alert( intervalMsg ) ;
	        return null ;
	    }
	    
	    var number = bufferB-bufferA ;
	    
	    // what kind of add to do? 
	    switch (interval.charAt(0))
	    {
	        case 'd': case 'D': 
	            iOut = parseInt(number / 86400000) ;
	            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
	            break ;
	        case 'h': case 'H':
	            iOut = parseInt(number / 3600000 ) ;
	            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
	            break ;
	        case 'm': case 'M':
	            iOut = parseInt(number / 60000 ) ;
	            if(rounding) iOut += parseInt((number % 60000)/30001) ;
	            break ;
	        case 's': case 'S':
	            iOut = parseInt(number / 1000 ) ;
	            if(rounding) iOut += parseInt((number % 1000)/501) ;
	            break ;
	        default:
	        // If we get to here then the interval parameter
	        // didn't meet the d,h,m,s criteria.  Handle
	        // the error. 		
	        alert(intervalMsg);
	        return null ;
	    }
	    
	    return iOut ;
	} //end function dateDiff
	// ----------------------------------------------------------------------------------------------------------------------------------
	
	
// MONTH OBJECT----------------------------------------------------------------------------------------------------------------------------------
	function leapYear(year) {
	  if (year % 4 == 0) {// basic rule
	    return true; // is leap year
	  }
	  /* else */ // else not needed when statement is "return"
	  return false; // is not leap year
	}

	/**** month object ****/
	function Month() {	}
	Month.prototype.getDays = function (month, year) {
		 // create array to hold number of days in each month
		 var ar = new Array(12);
		 ar[0] = 31; // January
		 ar[1] = (leapYear(year)) ? 29 : 28; // February
		 ar[2] = 31; // March
		 ar[3] = 30; // April
		 ar[4] = 31; // May
		 ar[5] = 30; // June
		 ar[6] = 31; // July
		 ar[7] = 31; // August
		 ar[8] = 30; // September
		 ar[9] = 31; // October
		 ar[10] = 30; // November
		 ar[11] = 31; // December
		 return ar[month];
	}
	
	Month.prototype.name = function(month) {
		var ar = new Array(12);
		ar[0] = "January";
		ar[1] = "February";
		ar[2] = "March";
		ar[3] = "April";
		ar[4] = "May";
		ar[5] = "June";
		ar[6] = "July";
		ar[7] = "August";
		ar[8] = "September";
		ar[9] = "October";
		ar[10] = "November";
		ar[11] = "December";
		return ar[month];
	}
	
	Month.prototype.nameAbbr = function(month) {
		var ar = new Array(12);
		ar[0] = "Jan";
		ar[1] = "Feb";
		ar[2] = "Mar";
		ar[3] = "Apr";
		ar[4] = "May";
		ar[5] = "Jun";
		ar[6] = "Jul";
		ar[7] = "Aug";
		ar[8] = "Sep";
		ar[9] = "Oct";
		ar[10] = "Nov";
		ar[11] = "Dec";
		return ar[month];
	}


//	COMMON FORM FUNCTIONS
//------------------------------------------------------------------------------------------------------------------------------------------------------------

	function returnFormRef(formRef) {
		if (isNaN(formRef)) { return eval("document.forms." + formRef); }
		else { return document.forms[formRef]; }
	}


	function focusInput(formRef,inputRef) {
		eval('document.forms['+formRef+'].'+inputRef+'.focus()');
	}
	
	function confirmAction(message) {
		if ( window.confirm(message) ) {

			return true;
		}
		else {
			return false;
			}
	}

	function encodeQuotes(formName,itemName) {
		var thisField = eval("document.forms." + formName + "." + itemName);
		var thisStr = thisField.value;
		var pattern1 = new RegExp("'","gi");
		var pattern2 = new RegExp("\"","gi");
		var pattern3 = new RegExp("<","gi");
		var pattern4 = new RegExp(">","gi");
		thisStr = thisStr.replace(pattern1,"&#146;");
		thisStr = thisStr.replace(pattern2,"&quot;");
		thisStr = thisStr.replace(pattern3,"&lt;");
		thisStr = thisStr.replace(pattern4,"&gt;");
		thisField.value = thisStr;
		
	}
	
	// must have 2 css classes named span.pseudo_button and span.pseudo_button_down
	function pseudoButton(lbl,url) {
		this.label = lbl;
		this.url = url;
	}
	pseudoButton.prototype.label;
	pseudoButton.prototype.url;
	pseudoButton.prototype.title;
	pseudoButton.prototype.inline = false; //false writes a <div>, true writes a <span>
	pseudoButton.prototype.title;
	pseudoButton.prototype.target;
	pseudoButton.prototype.imgSrc;
	pseudoButton.prototype.width = 'auto';
	pseudoButton.prototype.write = function() {
		var tag = (this.inline ? 'span' : 'div');
		var thisBut = '<' + tag + ' class="pseudo_button" style="width:' + this.width + '" ';
			thisBut += 'onmousedown="this.className=\'pseudo_button_down\';" ';
			thisBut += 'onmouseup="this.className=\'pseudo_button\';window.location.href=\'' + this.url + '\';">';
			thisBut += (this.imgSrc == undefined ? '' : '<img src="' + this.imgSrc + '" border="0" alt="" hspace="2" />');
			thisBut += '<a href="' + this.url + '" title="' + this.title + '" class="apseudo_button">';
			thisBut += this.label + '</a></' + tag + '>';
			
			document.write(thisBut);
	}

//------------------------------------------------------------------------------------------------------------------------------------------------------------



//	FUNCTION GROUP TO DEAL WITH MULTIPLE CHECK BOXES
//------------------------------------------------------------------------------------------------------------------------------------------------------------

	/**** RETURNS FALSE IF NO BOXES ARE CHECKED, TRUE OTHERWISE ****/
	function checkAny(formName, itemName) {
		var thisItem = eval("document.forms." + formName + "." + itemName);
		var checkedFlag = false;
		if( thisItem.length == "undefined" || isNaN(thisItem.length) && thisItem.checked ) {
			checkedFlag = true;
		}
		else {
			for(var i = 0; i <= thisItem.length-1; i++) {
				if( thisItem[i].checked == true ) {
					checkedFlag = true;
					break;
				}
			}
		}
		return checkedFlag;
	}

	/**** SELECTS ALL CHECK BOXES ****/
	function checkAll(formName,itemName) {
		var thisItem = eval("document.forms." + formName + "." + itemName);
	
		if( thisItem.length == "undefined" || isNaN(thisItem.length) && !thisItem.checked ) {
			thisItem.checked = true;
		}
		else {
			for(var i = 0; i <= thisItem.length-1; i++) {
				thisItem[i].checked = true;
			}
		}
	}

	/**** DESELECTS ALL DELETE CHECK BOXES ****/
	function checkNone(formName,itemName) {
		var thisItem = eval("document.forms." + formName + "." + itemName);
		if( thisItem.length == "undefined" || isNaN(thisItem.length) && thisItem.checked ) {
			thisItem.checked = false;
		}
		else {
			for(var i = 0; i <= thisItem.length-1; i++) {
				thisItem[i].checked = false;
			}
		}
	}
//------------------------------------------------------------------------------------------------------------------------------------------------------------



// WINDOW & SCREEN FUNCTIONS
//------------------------------------------------------------------------------------------------------------------------------------------------------------

	function popup(url,xWidth,yHeight,x,y) {
		var attr = "width="+xWidth+",height="+yHeight+",toolbar=no,statusbar=no,scrollbars=auto";
		thisWin = window.open(url,"popup",attr);
		x = x - 0; y = y - 0; //convert to number
		if (x == -1 && y == -1) { centerWin('thisWin',1,1); }
		else if ( x == -1 ) { centerWin('thisWin',1,0) }
		else if ( y == -1 ) { centerWin('thisWin',0,1) }
		else { moveWindow('thisWin',x,y); }
	}
	function getWinXpos(ref) {
		if ( ref == null ) { ref = 'window'; }
		if (window.left) { return eval(ref+'.left'); }
		else if (window.screenX) { return eval(ref+'.screenX'); }
		else { return 0 }
	}
	function getWinYpos(ref) {
		if ( ref == null ) { ref = 'window'; }
		if (window.top) { return eval(ref+'.top'); }
		else if (window.screenY) { return eval(ref+'.screenY'); }
		else { return 0 }
	}
	function getWinWidth(ref) {
		if ( ref == null ) { ref = 'window'; }
		if (window.outerWidth) { return eval(ref+'.outerWidth'); }
		else if (window.innerWidth) { return eval(ref+'.innerWidth'); }
		else if (window.width) { return eval(ref+'.width'); }
		else { return 0 }
	}
	function getWinHeight(ref) {
		if ( ref == null ) { ref = 'window'; }
		if (window.outerHeight) { return eval(ref+'.outerHeight'); }
		else if (window.innerHeight) { return eval(ref+'.innerHeight'); }
		else if (window.height) { return eval(ref+'.height'); }
		else { return 0 }
	}
	function setWinSize(x,y) {
		if (window.outerHeight) { window.outerHeight = y; window.outerWidth = x; }
		else if (window.innerHeight) { window.innerHeight = y; window.outerWidth = x; }
		else if (window.height) { window.height = y; window.width = x; }
		else {  }
	}
	function getScreenWidth() {
		if (screen.width) { return screen.width }
		else if (screen.availWidth) { return screen.availWidth }
		else { return 640 }
	}
	function getScreenHeight() {
		if (screen.height) { return screen.height }
		else if (screen.availHeight) { return screen.availHeight }
		else { return 480 }
	}
	function moveWindow(ref,x,y) {
			if (x == null || x == -1) { x = getWinXpos(ref); }
			if (y == null || y == -1) { y = getWinYPos(ref); }
			eval(ref+'.moveTo(x,y)');
			eval(ref+'.focus()');
	}
	function centerWin(ref,centerX,centerY) {
		// centerX and centerY are boolean values
		var halfx = -1 //default off for moveWindow
		var halfy = -1 //default off for moveWindow
		if (getWinWidth(ref) && centerX) {
			halfx = halfx(getWinWidth(ref));
		}
		if (getWinHeight() && centerY) {
			halfy = halfy(getWinHeight(ref));
			halfy -= 20; //visual balance to compensate for toolbar
		}
		window.moveTo(halfx,halfy);
		
	}
	function halfx(winWidth) {
		return Math.ceil( (getScreenWidth() / 2) - (winWidth / 2) );
	}
	function halfy(winHeight) {
		return Math.ceil( (getScreenHeight() / 2) - (winHeight / 2) );
	}
//------------------------------------------------------------------------------------------------------------------------------------------------------------


