

//	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
				arVal[i] = new String(arVal[i]);
				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;
		}
	}
	
	//this function checks for null, undefined, or zero length string value
	function isNothing(v)		{ 
									v = new String(v);
									return ( v == 'undefined' || v == 'null' || v.length == 0 ? true : false );
								}

// MISC NUMBER FUNCTIONS----------------------------------------------------------------------------------------------------------------------------------

	function getRandomNum(lbound, ubound) {
		return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
	}
	
	//------------------------------------------------------------------------------------------------
	function round_decimals(original_number, decimals) {
	    var result1 = original_number * Math.pow(10, decimals)
	    var result2 = Math.round(result1)
	    var result3 = result2 / Math.pow(10, decimals)
	    return result3;
	}


	//------------------------------------------------------------------------------------------------
	function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas) {
		/**********************************************************************
		num - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 		**********************************************************************/
 		
        if ( isNaN(parseInt(num)) ) { return "NaN" };

		var tmpNum = num;
		var iSign = ( num < 0 ? -1 : 1 );		// Get sign of number
		
		// Adjust number so only the specified number of numbers after
		// the decimal point are shown.
		tmpNum *= Math.pow(10,decimalNum);
		tmpNum = Math.round(Math.abs(tmpNum))
		tmpNum /= Math.pow(10,decimalNum);
		tmpNum *= iSign;					// Readjust for sign
		
		
		// Create a string object to do our formatting on
		var tmpNumStr = new String(tmpNum);
		
		// Add zeros after decimal
		var tmpNumDec = tmpNumStr;
		if (tmpNumDec.indexOf(".") == -1 && decimalNum > 0) {
			tmpNumStr += "." + "0".repeat(decimalNum);
		} else if(decimalNum > 0) {
			tmpNumDec = tmpNumDec.substring(tmpNumDec.indexOf(".") + 1, tmpNumDec.length);
			tmpNumDec = (tmpNumDec.length < decimalNum ? "0".repeat(decimalNum - tmpNumDec.length) : "");
			tmpNumStr += tmpNumDec;
		}
			
		// See if we need to strip out the leading zero or not.
		if (!bolLeadingZero && num < 1 && num > -1 && tmpNumStr.indexOf(".") != -1)
			if (num >= 0)
				tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
			else
				tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
			
		// See if we need to put in the commas
		if (bolCommas && (num >= 1000 || num <= -1000)) {
			var iStart = tmpNumStr.indexOf(".");
			if (iStart < 0)
				iStart = tmpNumStr.length;
	
			iStart -= 3;
			while (iStart >= 1) {
				tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
				iStart -= 3;
			}		
		}
	
		// See if we need to use parenthesis
		if (bolParens && num < 0)
			tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";
	
		return tmpNumStr;		// Return our formatted string!
	} /** end function FormatNumber **/
	

	//------------------------------------------------------------------------------------------------
	function FormatCurrency(num,decimalNum,bolLeadingZero,bolParens,bolCommas) {
		/**********************************************************************
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.											
		**********************************************************************/
		var tmpStr = new String(FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas));
	
		if (tmpStr.indexOf("(") != -1 || tmpStr.indexOf("-") != -1) {
			// We know we have a negative number, so place '$' inside of '(' / after '-'
			if (tmpStr.charAt(0) == "(")
				tmpStr = "($"  + tmpStr.substring(1,tmpStr.length);
			else if (tmpStr.charAt(0) == "-")
				tmpStr = "-$" + tmpStr.substring(1,tmpStr.length);
				
			return tmpStr;
		}
		else
			return "$" + tmpStr;		// Return formatted string!
	} /** end function FormatCurrency **/

//	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+$/,'');
	}
	
	//a little update to the link method
	String.prototype.link = function(strHref, strTitle, strClass, strStyle) {
		var strLink = '<a href="' + strHref + '" ';
		strLink += (!isNothing(strTitle) ? 'title="' + strTitle + '" ' : '');
		strLink += (!isNothing(strClass) ? 'class="' + strClass + '" ' : '');
		strLink += (!isNothing(strStyle) ? 'style="' + strStyle + '" ' : '');
		strLink += '>' + this + '</a>';
		return strLink;
	}
	
	String.prototype.repeat = function(num) {
		var tmpstr = this;
		var newstr = ""
			for(var i = 1; i <= num; i++) {
				newstr += tmpstr;
			}
		return newstr;
	}

// DATE FUNCTIONS----------------------------------------------------------------------------------------------------------------------------------
	function secToMill(n) { return new Number(n * 1000);  }
	function minToMill(n) { return new Number(secToMill(n * 60)); }
	function hourToMill(n) { return new Number(secToMill(minToMill(n * 60))); }
	function dayToMill(n) { return new Number(secToMill(minToMill(hourToMill(n * 24)))); }
	
	//------------------------------------------------------------------------------------------------
	function isValidDate(dateStr, format) {
	   if (format+'' == 'undefined') { format = "MDY"; }
	   format = format.toUpperCase();
	   if (format.length != 3) { format = "MDY"; }
	   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
	   if (format.substring(0, 1) == "Y") { // If the year is first
	      var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
	      var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
	   } else if (format.substring(1, 2) == "Y") { // If the year is second
	      var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
	      var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
	   } else { // The year must be third
	      var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
	      var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	   }
	   // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
	   if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
	   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
	   // Check to see if the 3 parts end up making a valid date
	   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
	   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
	   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
	   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
	   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
	   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
	   if (parseFloat(dd) != dt.getDate()) { return false; }
	   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
	   return true;
	}

	//------------------------------------------------------------------------------------------------
	function FormatDateTime(datetime, FormatType, abbr) {
		//**********************************************************************
		//	FormatType takes the following values
		//	1 - General Date = Friday, October 30, 1998
		//	2 - Typical Date = 10/30/1998
		//	2.5 - Typical Date = 10/30/98 (short yr)
		//	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 dayName = myDate.getDayName(abbr);
		
		var monthName = myDate.getMonthName(abbr);
		
		var dayNum = myDate.getDate();
			dayNum = (dayNum.length == 1 ? "0" + dayNum : dayNum + "");

		var Year = new String(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 + " " + dayNum + ", " + Year;
				break;
			case 2 :
				strDate = (myDate.getMonth() + 1) + "/" + dayNum + "/" + Year;
				break;
			case 2.5 :
				strDate = (myDate.getMonth() + 1) + "/" + dayNum + "/" + Year.substring(2, 4);
				break;
			case 3 :
				var AMPM = ( Hour >= 12 ? "PM" : "AM" );
				switch(AMPM) {
					case "PM" :
						strDate = Hour - 12;
						strDate = (strDate == 0 ? 12 : strDate);
						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;
	} //end FormatDateTime
	
	
	//------------------------------------------------------------------------------------------------
	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];
	}
	
	// ----------------------------------------------------------------------------------------------------------------------------------
	/**** Day object *****************************/
	function Day() {}
	Day.prototype.name = function(weekday) {
		var ar = new Array(7);
		ar[0] = "Sunday";		ar[1] = "Monday";		ar[2] = "Tuesday";
		ar[3] = "Wednesday";	ar[4] = "Thursday";		ar[5] = "Friday";
		ar[6] = "Saturday";		return ar[weekday];
	}
	Day.prototype.nameAbbr = function(weekday) {
		var ar = new Array(7);
		ar[0] = "Sun";		ar[1] = "Mon";		ar[2] = "Tue";
		ar[3] = "Wed";		ar[4] = "Thu";		ar[5] = "Fri";
		ar[6] = "Sat";		return ar[weekday];	
	}
	
	/**** Date object prototypes *****************************/
	Date.prototype.getMonthName = function(isAbbr) {
		var oMonth = new Month();
			return ( !isAbbr ? oMonth.name(this.getMonth()) : oMonth.nameAbbr(this.getMonth()) );
	}
	Date.prototype.getDayName = function(isAbbr) {
		var oDay = new Day();
			return ( !isAbbr ? oDay.name(this.getDay()) : oDay.nameAbbr(this.getDay()) );
	}
	Date.prototype.toSQLstring = function(useSeconds) {
		var dStr = (this.getMonth()+1) + "/" + this.getDate() + "/" + this.getFullYear();
		var hStr = this.getHours();
		var mStr = new String(this.getMinutes());
			mStr = (mStr.length == 1 ? "0" + mStr : mStr);
		var secStr = ( useSeconds+"" == "undefined" || useSeconds == false ? "" : ":" + this.getSeconds() );
			setStr = (secStr.length == 2 ? "0" + secStr : secStr);
		return dStr + " " + hStr + ":" + mStr  + secStr;
	}


//	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;
		
	}

//------------------------------------------------------------------------------------------------------------------------------------------------------------



//	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;
	}

	var checkToggle = false;
	/**** SELECTS ALL CHECK BOXES ****/
	function checkAll(formName,itemName) {
		if (checkToggle == true) {
			checkNone(formName,itemName);
			checkToggle = false;
		}
		else {
			var thisItem = eval("document.forms." + formName + "." + itemName);
			checkToggle = true;
			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;
			}
		}
	}
	
	//return select index for an array of Radios or Checkboxes
	function getSelectedIndex(formItem) {
		for(var i = 0; i <= formItem.length - 1; i++) {
			if(formItem[i].checked == true) {
				return i;
			}
		}
		return -1;
	}
//------------------------------------------------------------------------------------------------------------------------------------------------------------



// WINDOW & SCREEN FUNCTIONS
//------------------------------------------------------------------------------------------------------------------------------------------------------------
	function refresh() {
		window.location.href = window.location.href;
	};
	
	function popup(url, xWidth, yHeight, x, y, statusB) {
		var statbar = (isNothing(statusB) == true ? true : statusB); //statusB is a boolean value, optional, default true
			statbar = (statbar == false ? 'no' : 'yes');
		var attr = "width="+xWidth+",height="+yHeight+",toolbar=no,status="+statbar+",scrollbars";
		x = x - 0; y = y - 0; //convert to number
		if (x == -1 && y == -1) { attr += ",left=" + halfx(xWidth) + ",top=" + halfy(yHeight); }
		else if ( x == -1 ) { attr += ",left=" + halfx(xWidth) + ",top=" + y; }
		else if ( y == -1 ) { attr += ",left=" + x + ",top=" + halfy(yHeight); }
		else { attr += ",left=" + x + ",top=" + y; }
		thisWin = window.open(url,"popup",attr);
		thisWin.focus();
	};
	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) );
	}
//------------------------------------------------------------------------------------------------------------------------------------------------------------


