//constants
	var CR = "\n";
	var LF = "\r";
	var TAB = "\t";
	var BR = "<br />" + CR;

//	COMMON FUNCTIONS SHORTENED
//	(most functions are named the same as the asp versions)
//-----------------------------------------------------------------------------------

	function dw(str) { document.write(str); }	
	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 =
				thisStr[1] = thisStr[1].replace(/\+/gi, ' '); //unescape doesn't recognize the + sign as a space
				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 );
								}
//-------------------------------------------------------------------------------
								
	function benchmark(startDate) {
		//returns seconds elapsed from date 1 to date 2
		var endDate = new Date().getTime();
		return (endDate - d1.getTime()) * .001;
	}

//-------------------------------------------------------------------------------
	function objXMLHTTP() {
		var xmlhttp=false;
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		  xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
	}
	
//	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);
	}

// DISABLE RIGHT (CTRL) CLICK---------------------------------------------
	function clickIE4(){
		if (event.button==2){
			return false;
		}
	};
	
	function clickNS4(e){
		if (document.layers||document.getElementById&&!document.all){
			if (e.which==2||e.which==3){
				return false;
			}
		}
	};
	
	function disableRightClick() {
		if (document.layers){
			document.captureEvents(Event.MOUSEDOWN);
			document.onmousedown=clickNS4;
		} else if (document.all&&!document.getElementById){
			document.onmousedown=clickIE4;
		}
		
		document.oncontextmenu = new Function("return 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, useLeadingZero, useParens, useCommas) {
		/**********************************************************************
		num - the number to format
		decimalNum - the number of decimal places to format the number to
		useLeadingZero - true / false - display a leading zero for numbers between -1 and 1
		useParens - true / false - use parenthesis around negative numbers
		useCommas - put commas as number separators.
 		**********************************************************************/
 		num = num.replace(/,|(|)|\s/gi, ""); //strip formatting characters
 		num = (isNaN(num) || isNothing(num) ? 0 : num-0);
		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 = tmpNum.toFixed(decimalNum);		
		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 put in the commas
		if (useCommas && (num >= 1000 || num <= -1000)) {
			var iStart = tmpNumStr.indexOf(".");
			if (iStart < 0)
				iStart = tmpNumStr.length;
	
			iStart -= 3;
			var iEnd = (num < 0 ? 2 : 1);
			while (iStart >= iEnd) {
				tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart)
				iStart -= 3;
			}
		}
		// See if we need to strip out the leading zero or not.
		if (!useLeadingZero && num < 1 && num > -1 && tmpNumStr.indexOf(".") != -1) {
			if (num >= 0) {
				tmpNumStr = tmpNumStr.substring(1);
			} else {
				tmpNumStr = "-" + tmpNumStr.substring(2);
			}
		}
		// See if we need to use parenthesis
		if (useParens && num < 0) {
			tmpNumStr = "(" + tmpNumStr.substring(1) + ")";
		}
	
		return tmpNumStr;
	};



// 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;
	
	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 s = this + "";
		var a = [];
			while(num > 0) {
				a.push(s);
			}
		return a.join('');
	}

// 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) {
		// Checks for the following valid date formats:
		// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
		// Also separates date into month, day, and year variables
		
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
		
		// To require a 4 digit year entry, use this line instead:
		// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
		
		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
			return false;
		}
		month = matchArray[1]; // parse date into variables
		day = matchArray[3];
		year = matchArray[4];
		if (month < 1 || month > 12) { // check month range
			return false;
		}
		if (day < 1 || day > 31) {
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			return false;
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				return false;
		   	}
		}
		return true;  // date is valid
	};
	//------------------------------------------------------------------------------------------------
	Date.prototype.format = function(useFullYear, useTime, useMilitaryTime) {	
		var strdate = this.getFullYear() + '';
		if(!useFullYear) { strdate = strdate.substr(2,2); }
		var m = this.getMonth()+1;
		var d = this.getDate() + '';
			d = (d.length == 1 ? "0" : "") + d;
			strdate = m + "/" + d + "/" + strdate;
		if(useTime) {
			strdate += this.formatTime(useMilitaryTime);
		}
		return strdate;
	};
	Date.prototype.formatTime = function(useMilitaryTime) {
		var strdate = "";
		var mm = this.getMinutes() + '';
			mm = (mm.length == 1 ? "0" : "") + mm;
		var h = this.getHours() + '';
		switch(useMilitaryTime) {
			case true :
				strdate += " " + (h.length == 1 ? "0" : "") + h + ":" + mm;
				break;
			default :
				var ampm = " AM";
				if(h >= 12) {
					h = h - 12;
					ampm = " PM"
				}
				strdate += " " + (h.length == 1 ? "0" : "") + h + ":" + mm + ampm;
				break;
		}
		return strdate;
	};
	
	//------------------------------------------------------------------------------------------------
	function dateAdd(start, interval, number) {
		//start = valid date
		//interval accepts: d (day), h (hour), m (minutes), s (seconds)
	    // get the milliseconds for this Date object. 
	    var buffer = Date.parse(start) ;
		
	    // check that the start parameter is a valid Date. 
	    if (isNaN(buffer)) { return null; }
	
	    // check that the number parameter is numeric. 
	    if (isNaN(number))	{ return null; }
	
	    // what kind of add to do? 
	    switch (interval) {
	        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:	
	        	return null;
	    }
	    return new Date(buffer + number);
	};

	//-------------------------------------------------------------------------
	function dateDiff(start, end, interval, rounding) {
	
	    var iOut = 0;
	
	    var bufferA = Date.parse(start) ;
	    var bufferB = Date.parse(end) ;
	    	
	    // check that the start parameter is a valid Date. 
	    if ( isNaN (bufferA) || isNaN (bufferB) ) { return null; }
			    
	    var number = bufferB-bufferA ;
	    
	    // what kind of add to do? 
	    switch (interval)
	    {
	        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:	
	        	return null;
	    }
	    
	    return iOut ;
	};
	// ----------------------------------------------------------------------
	
	
// MONTH OBJECT-------------------------------------------------------------
	function leapYear(year) {
		if (year % 4 == 0) { return true; }
		return false;
	};

	/**** month object ****/
	function Month() {	} //months are 0 based
	Month.prototype.getDays = function (month, year) {
		 switch(month) {
		 	case 3: case 5: case 8: case 10 :
		 		return 30;
		 	case 0: case 2: case 4: case 6:
		 	case 7: case 9: case 11 :
		 		return 31;
		 	case 1 : return (leapYear(year) ? 29 : 28); //feb
		 	default : return 'isNaN';
		 }
	};
	
	Month.prototype.name = function(month) {
		switch(month) {
			case 0: return "January";
			case 1: return "February";
			case 2: return "March";
			case 3: return "April";
			case 4: return "May";
			case 5: return "June";
			case 6: return "July";
			case 7: return "August";
			case 8: return "September";
			case 9: return "October";
			case 10: return "November";
			case 11: return "December";
			default: return null;
		}
	};
	
	Month.prototype.nameAbbr = function(month) {
		return this.name(month).substring(0,3);
	};
	
	// --------------------------------------------------------------------------
	/**** Day object *****************************/
	function Day() {} //days are 0 based
	Day.prototype.name = function(weekday) {
		switch(weekday) {
			case 0: return "Sunday";
			case 1: return "Monday";
			case 2: return "Tuesday";
			case 3: return "Wednesday";
			case 4: return "Thursday";
			case 5: return "Friday";
			case 6: return "Saturday";
			default: return null;
		}
	}
	Day.prototype.nameAbbr = function(weekday) {
		return this.name(weekday).substring(0,3);	
	}
	
	/**** 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 hiliteInput(inputRef, color) {
		var clr = (!isNothing(color) ? color : "red");
		inputRef.style.borderColor = clr;
		inputRef.style.backgroundColor = "yellow";
		inputRef.style.color = "#b50000";
	};
	function clearHilite(inputRef) {
		inputRef.style.borderColor = '';
		inputRef.style.backgroundColor = '';
		inputRef.style.color = '';
	};
	function clearAllHilites(formRef) {
		for(var i = formRef.elements.length-1; i >= 0; i--) {
			formRef.elements[i].style.borderColor = '';
			formRef.elements[i].style.backgroundColor = '';
			formRef.elements[i].style.color = '';
		}
	};
	
	function validateField(strType, strVal) {
		switch(strType) {
			case 'phone_full' : //xxX-XXX-XXX-XXXX w/req country code digits
				var objRegExp  = /^\d{1,3}\-\d{3}\-\d{3}\-\d{4}$/;
				break;
			case 'phone_ac' :  //xxx-XXX-XXX-XXXX w/opt country code digits and req area code
				var objRegExp  = /^(\d{1,3}\-)?\d{3}\-\d{3}\-\d{4}$/;
				break;
			case 'phone_part' :  //xxx-XXX-XXXX w/opt area code
				var objRegExp  = /^(\d{3}\-)?\d{3}\-\d{4}$/;
				break;
			case 'email' :
				var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
				break;
			case 'state' :
				var objRegExp = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i; 
				break;
			case 'zip' :
				var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
				break;
			case 'ssn' :
				var objRegExp  = /^\d{3}\-\d{2}\-\d{4}$/;
				break;
		};
		
		return (strVal.search(objRegExp) > -1 ? true : false);
	
	};
	
	//this function should be called from the onkeyup event
	//will finish the date string with the current year after the second slash (/)
	function completeDate(dateStr) {
		var objRegExp1 = /^\d{1,2}\/\d{1,2}\/\d{1,}$/;
		var objRegExp2 = /^\d{1,2}\/\d{1,2}\/$/;
		if(dateStr.search(objRegExp1) > -1) {
			return dateStr;
		} else if(dateStr.search(objRegExp2) > -1) {
			var yr = new Date(); yr = yr.getFullYear();
			return dateStr + yr;
		}
		return dateStr;
	
	};
	function selectOption(inputRef, optValue, defaultSelected) {
		var i = inputRef.options.length-1;
		while(i >= 0) {
			if(inputRef[i].value == optValue) {
				inputRef.selectedIndex = i;
				inputRef.options[i].selected = true;
				if(defaultSelected) { inputRef.options[i].defaultSelected = true; }
				return true;
				break;
			}
			i--;
		}
		return false;
	};

//-----------------------------------------------------------------------------------------



//	FUNCTION GROUP TO DEAL WITH MULTIPLE CHECK BOXES
//----------------------------------------------------------------------------------------

	/**** RETURNS FALSE IF NO BOXES ARE CHECKED, TRUE OTHERWISE ****/
	function checkAny(checkBoxGroup) {
		if(checkBoxGroup === undefined) { return false; }
		var i = checkBoxGroup.length-1;
		while(i >= 0) {
			if(checkBoxGroup[i].checked == true) {
				return true;
			}
			i--;
		}
		return false;
	};

	var checkToggle = false; //persistant
	/**** SELECTS ALL CHECK BOXES ****/
	function checkAll(checkBoxGroup) {
		if(checkBoxGroup === undefined) { return false; }
		if (checkToggle == true) {
			checkNone(checkBoxGroup);
			checkToggle = false;
		} else {
			checkToggle = true;
			var i = checkBoxGroup.length-1;
			while(i >= 0) {
				checkBoxGroup[i].checked = true;
				i--;
			}
		}
	};
	/**** DESELECTS ALL CHECK BOXES ****/
	function checkNone(checkBoxGroup) {
		if(checkBoxGroup === undefined) { return false; }
		var i = checkBoxGroup.length-1;
		while(i >= 0) {
			checkBoxGroup[i].checked = false;
			i--;
		}
	};
	
	//return select index for an array of Radios (and checkboxes, but pretty useless)
	function getSelectedIndex(radioGroup) {
		var i = radioGroup.length-1;
		while(i >= 0) {
			if(radioGroup[i].checked == true) {
				return i;
			}
			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 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 halfx(winWidth) {
		return Math.ceil( (getScreenWidth() / 2) - (winWidth / 2) );
	};
	function halfy(winHeight) {
		return Math.ceil( (getScreenHeight() / 2) - (winHeight / 2) );
	};


//CUSTOM FUNCTIONS BELOW THIS LINE ------------------------------------------------------------------------------------------------------------------------------------------------------------

