 // --------------------------------------------------------------
 // --- 	BROWSER VARIABLES
 // ---------------------------------------------------------------

isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

 // --------------------------------------------------------------
 // --- 	Interface of old select functions to new.
 // ---------------------------------------------------------------
		function switchListItem(f1,f2,sort) {

		fld1 = eval('document.forms[0].' + f1);
		fld2 = eval('document.forms[0].' + f2);
		moveSelectedOptions(fld1,fld2,sort);
		}

 

// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//	This is a general function used by the select functions below, to
//	avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}

// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//	This function selects all options that match the regular expression
//	passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//	This function selects all options that match the regular expression
//	passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//	This function Unselects all options that match the regular expression
//	passed in.
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}

// -------------------------------------------------------------------
// sortSelect(select_object)
//	 Pass this function a SELECT object and the options will be sorted
//	 by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
	var o = new Array();
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	o = o.sort(
		function(a,b) {
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			}
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}
	
	function sortSelectWithCase(obj) {
	
        var o = new Array();
        for (var i=0; i<obj.options.length; i++) {
                o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
                }
        o = o.sort(
                function(a,b) {
                        if ((a.text.toUpperCase()+"") < (b.text.toUpperCase()+"")) { return -1; }
                        if ((a.text.toUpperCase()+"") > (b.text.toUpperCase()+"")) { return 1; }
                        return 0;
                        }
                );

        for (var i=0; i<o.length; i++) {
                obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
                }
        }
	
	

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//	This function takes a select box and selects all options (in a
//	multiple select object). This is used when passing values between
//	two select boxes. Select all options in the right box before
//	submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
	
	
// -------------------------------------------------------------------
// deselectAllOptions(select_object)
//	This function takes a select box and de-selects all options 
// -------------------------------------------------------------------	
function deselectAllOptions(obj) {
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = false;
		}
	}	

// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//	This function moves options between select boxes. Works best with
//	multi-select boxes to create the common Windows control effect.
//	Passes all selected values from the first object to the second
//	object and re-sorts each box.
//	If a third argument of 'false' is passed, then the lists are not
//	sorted after the move.
//	If a fourth string argument is passed, this will function as a
//	Regular Expression to match against the TEXT or the options. If
//	the text of an option matches the pattern, it will NOT be moved.
//	It will be treated as an unmoveable option.
//	You can also put this into the <SELECT> object as follows:
//		onDblClick="moveSelectedOptions(this,this.form.target)
//	This way, when the user double-clicks on a value in one box, it
//	will be transferred to the other (in browsers that support the
//	onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to,sort,leave) {
	// Unselect matching options, if required
			//	if (arguments.length>3) {
	//		var regex = arguments[3];
		//		if (regex != "") {
			//			unSelectMatchingOptions(from,regex);
				//		}
				 // }



	// Check if to field has only the 'NO SELECTIONS' if so remove it first.
	if (to.options.length == 1 && to.options[0].value == "NO SELECTIONS")  {
		 to.options[0] = null;
	}

	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
			if (o.selected) {
				 // check for empty value
				 if(o.value != 'NO SELECTIONS') {
				to.options[to.options.length] = new Option( o.text, o.value, false, false);
				 }
		 }

		 }

	// Delete them from original
	if(arguments[3]!=true)
	{
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
				// check for empty value
		 //  if(o.value != 'NO SELECTIONS') {
			from.options[i] = null;
			 // }
				}
		}
	}

	// Check for empty from field and if so replace with "NO SELECTIONS"
	if(from.options.length == 0) {
		from.options[from.options.length] = new Option( "NO SELECTIONS", "NO SELECTIONS", false, false);
	}
	// Check for empty to field and if so replace with "NO SELECTIONS"
	if(to.options.length == 0) {
		to.options[to.options.length] = new Option( "NO SELECTIONS", "NO SELECTIONS", false, false);
	}



	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = 0; 	// rjs switched from -1
	to.selectedIndex = 0; // rjs switched from -1

 }

 // -------------------------------------------------------------------
 // removeSelected Option
 // -------------------------------------------------------------------
 function removeSelectedOption(obj) {

	for (var i=0; i<obj.options.length; i++) {
		var o = obj.options[i];
			if (o.selected) {
				 // check for empty value
				 obj.options[0] = null;
				 }
		 }
 }


// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//	This function copies options between select boxes instead of
//	moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	for (var i=0; i<to.options.length; i++) {
		options[to.options[i].text] = true;
		}
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.text] == null || options[o.text] == "undefined") {
				to.options[to.options.length] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//	Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//	Copy all options from one select box to another, instead of
//	removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//	Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}

// -------------------------------------------------------------------
// moveOptionUp(select_object)
//	Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	// If > 1 option selected, do nothing
	var selectedCount=0;
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			selectedCount++;
			}
		}
	if (selectedCount > 1) {
		return;
		}
	// If this is the first item in the list, do nothing
	var i = obj.selectedIndex;
	if (i == 0) {
		return;
		}
	swapOptions(obj,i,i-1);
	obj.options[i-1].selected = true;
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//	Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	// If > 1 option selected, do nothing
	var selectedCount=0;
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			selectedCount++;
			}
		}
	if (selectedCount > 1) {
		return;
		}
	// If this is the last item in the list, do nothing
	var i = obj.selectedIndex;
	if (i == (obj.options.length-1)) {
		return;
		}
	swapOptions(obj,i,i+1);
	obj.options[i+1].selected = true;
	}




// Start Generic Utility functions

function isNumeric(val)
{
	var neg = false;
  var dp = false;
	var onedigit = false;
	for (var i=0; i < val.length; i++) {
		if (!isDigit(val.charAt(i))) {


			if (i==0 && val.charAt(i) == '-') {

					//ok, allow negatives
					neg = true;
					continue;

			} else	if (val.charAt(i) == '.') {
				if (dp == true) { return false; } // already saw a decimal point
				else { dp = true; }
				}
			else {
				return false;
				}
			} else
			  onedigit = true;
		}
  // returns false (0) if invalid, true (1?) if positive and -1 (which is also interpereted as true) if negative
	return (neg == true ? (onedigit == true ? -1 : false) : onedigit);
	}

function isDigit(num) {
	var string="1234567890";
	if (string.indexOf(num) != -1) {
		return true;
		}
	return false;
	}


function roundToX(num,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 0 : X);
amount = Math.round(num*Math.pow(10,X))/Math.pow(10,X);
amount -= 0;
// .99 cent format courtsey of Martin Webb
return (amount == Math.floor(amount)) ? amount : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}


function round(num) {
amount = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
amount -= 0;
// .99 cent format courtsey of Martin Webb
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '' + num + '.' + cents);
}


/*	-------------------------------------------------------------
		moveUp	: moves selected value in select field up in order
		-------------------------------------------------------------
*/

function moveUp(fld) {

			 //check selected
			 if(fld.selectedIndex == -1) { return; }

			 //check for first
			 selectedIndex = fld.selectedIndex;
			 if (selectedIndex==0) { return; }

			 //move it up
			 previndex = selectedIndex - 1;
			 selValue = fld.options[selectedIndex].value;
			 selText = fld.options[selectedIndex].text;
			 prevValue = fld.options[previndex].value;
			 prevText = fld.options[previndex].text;
			 fld.options[previndex].value=selValue;
			 fld.options[previndex].text=selText;
			 fld.options[selectedIndex].value=prevValue;
			 fld.options[selectedIndex].text=prevText;
			 fld.selectedIndex = previndex;

}


/*	-------------------------------------------------------------
		moveDown	: moves selected value in select field down in order
		-------------------------------------------------------------
*/

function moveDown(fld) {


			 //check selected
			 if(fld.selectedIndex == -1) { return; }

			 //check for last
			 selectedIndex = fld.selectedIndex;
			 currlength = fld.length;
			 if (selectedIndex==currlength-1) {return; }

			 //move it down
			 nextindex = selectedIndex + 1;
			 selValue = fld.options[selectedIndex].value;
			 selText = fld.options[selectedIndex].text;
			 nextValue = fld.options[nextindex].value;
			 nextText = dfld.options[nextindex].text;
			 fldoptions[nextindex].value=selValue;
			 fld.options[nextindex].text=selText;
			 fld.options[selectedIndex].value=nextValue;
			 fld.options[selectedIndex].text=nextText;
			 fld.selectedIndex = nextindex;

}

/*	-------------------------------------------------------------
		Start Date Functions
	-------------------------------------------------------------
*/


/*	Get a new Date	*/
function newDate(inDate) {
	calDate = new Date (inDate);
	if ( isNaN(calDate) && inDate.length > 0) {
		x = inDate.indexOf('-');
		len = inDate.length;
		month = inDate.substring(0,x);
		day = inDate.substring(x+1,len);
		x = day.indexOf('-');
		len = day.length;
		year = day.substring(x+1,len);
		day = day.substring(0,x);

		if (day.length > 0 && month.length > 0 && year.length > 0){
			inDate = month + ' ' + day + ', ' + year;
			inDate = new Date(inDate);
			return inDate;
		}
	}
	return calDate;
}



// Calculate the number of days in the current month
function daysInMonth(inputDate) {
			var tempDate = new Date( inputDate.toGMTString() ) ;
			tempDate.setDate(28);
			while ( inputDate.getMonth() == tempDate.getMonth() ) { tempDate = adjustDay(tempDate, 1); }
			tempDate = adjustDay(tempDate, -1);
			return tempDate.getDate();
}

// Adjust the input date by n days (n can be positive or negative)
function adjustDay(inputDate, n) {

	if (n==0) { return inputDate; }
	var oneDay = 60 * 1000 * 60 * 24;
	var dateInMs = inputDate.getTime();
	if (n>0) {		 // positive adjustment; add the right number of times
	for (var i=0; i<n; i++) { dateInMs += oneDay; }
	} else {		 // negative adjustment; subtract the right number of times
	n = Math.abs(n) ;	// convert to positive value
	for (var i=0; i<n; i++) { dateInMs -= oneDay; }
	}
	inputDate.setTime(dateInMs) ;
	return inputDate;
}

// Adjust the input date by n months (n can be positive or negative)
function adjustMonth(inputDate, n) {

	if (n==0) { return inputDate; }
	var currDayNum = inputDate.getDate();
	inputDate.setDate(1);
	var newMonthNum = inputDate.getMonth() + n;
	if ( inputDate.getFullYear() ) {	 // Full 4-digit year, if the browser supports it
	var newYearNum = inputDate.getFullYear();
	} else {			// For browsers that do have the getFullYear function defined
	var newYearNum = inputDate.getYear();
	}
	if (newYearNum <= 999) { newYearNum += 1900; }	 // fix for Netscape date handling
	while (newMonthNum < 0) {	// adjust years until month is valid
	newYearNum--; // decrease year, increase month by 12
	newMonthNum += 12;
	}
	while (newMonthNum > 11) {	 // adjust years until month is valid
	newYearNum++;  // increase year, decrease month by 12
	newMonthNum -= 12;
	}
	inputDate.setYear(newYearNum);
	inputDate.setMonth(newMonthNum);
	if ( currDayNum > daysInMonth(inputDate) ) {
	inputDate.setDate(daysInMonth(inputDate));
	} else {
	inputDate.setDate(currDayNum);
	}
	return inputDate;
}

/* format to MM/DD/YYYY */
function formatUSDate(d) {
	var mpad = '';
	var dpad = '';
	if (d.getMonth() < 9) {mpad='0';}
	if (d.getDate() < 9) {dpad='0';}
	fdate = mpad + (d.getMonth()+1) + '/' + dpad + d.getDate() + '/' + d.getFullYear();
	return fdate;
}



/* return difference in 2 dates */
function dateDiff(startDate,endDate) {

	objStart = newDate(startDate);
	objEnd = newDate(endDate);
	diff = (objStart.getTime()) - (objEnd.getTime());
	diff = diff/86400000;
	diff = parseInt(diff);
	return diff;
}

/* increase a  date */
function dateAdd(offset, currDate) {
	curDate = newDate(currDate);
	offset = parseInt(offset) + parseInt(curDate.getDate());
	if (curDate.getYear() > 99 && curDate.getYear() < 1000){
		curDate = new Date(parseInt(curDate.getYear()) + 1900, curDate.getMonth(), offset);
	}
	else{
		curDate = new Date(curDate.getYear(), curDate.getMonth(), offset);
	}
	return curDate;
}









function checkdate(objName) {

var datefield = objName;
if (chkdate(objName) == false) {
return false;
}
else {
return true;
	 }
}
function chkdate(objName) {



var strDatestyle = "US"; //United States date style
//var strDatestyle = "EU";	//European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "01";
strMonthArray[1] = "02";
strMonthArray[2] = "03";
strMonthArray[3] = "04";
strMonthArray[4] = "05";
strMonthArray[5] = "06";
strMonthArray[6] = "07";
strMonthArray[7] = "08";
strMonthArray[8] = "09";
strMonthArray[9] = "10";
strMonthArray[10] = "11";
strMonthArray[11] = "12";
strDate = datefield.value;
 if (strDate.length < 1) {
return true;
}




for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++)
{
	if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
	{
	 strDateArray = strDate.split(strSeparatorArray[intElementNr]);
	 if (strDateArray.length != 3)
	 {
	 err = 1;
	 return false;
		}
		else
		{
		strDay = strDateArray[0];
		strMonth = strDateArray[1];
		strYear = strDateArray[2];
		}
		booFound = true;
	}
}

if (booFound == false)
{
 if (strDate.length>5)
 {
 strDay = strDate.substr(0, 2);
 strMonth = strDate.substr(2, 2);
 strYear = strDate.substr(4);
 }
 else return false;
}

intYear = parseInt(strYear, 10);

if (strYear.length == 2)
 {
 if(intYear < 30)
	 strYear = '20' + strYear;
 else
	 strYear = '19' + strYear;
 } else if(strYear.length == 1) {
 strYear = '200' + strYear;
 }
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
	 }
}
if (isNaN(intMonth)) {
err = 3;
return false;
	 }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {

if(intday < 10)
{ intdaystr = "0" + String(intday); }
else
 { intdaystr = String(intday); }
datefield.value = strMonthArray[intMonth-1] + "/" + intdaystr + "/" + strYear;
}
else {
datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}
function doDateCheck(from, to) {
if (Date.parse(from.value) <= Date.parse(to.value)) {
alert("The dates are valid.");
}
else {
if (from.value == "" || to.value == "")
alert("Both dates must be entered.");
else
alert("To date must occur after the from date.");
	 }
}


//-------------------------------------------
// END DATE VALIDATION
//-------------------------------------------



// ============================================
// DATE PICKER
// ============================================
var weekend = [0,6];
var weekendColor = "#C6D0DC";
var fontface = "Verdana";
var fontsize = 2;
// gets initialized in show_calendar
var gDate;

var ggWinCal;
//isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
//isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCal;
	else
		this.gWinCal = p_WinCal;

	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = Calendar.get_month(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}

	this.gYear = p_year;
	this.gFormat = p_format;
	this.gBGColor = "white";
	this.gFGColor = "black";
	this.gTextColor = "black";
	this.gHeaderColor = "black";
	this.gReturnItem = p_item;
}

Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
	return Calendar.Months[monthNo];
}

function Calendar_get_daysofmonth(monthNo, p_year) {
	/*
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for...
	2.Years also evenly divisible by 100 are not leap years, except for...
	3.Years also evenly divisible by 400 are leap years.
	*/
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return Calendar.DOMonth[monthNo];

		return Calendar.lDOMonth[monthNo];
	} else
		return Calendar.DOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/*
	Will return an 1-D array with 1st element being the calculated month
	and second being the calculated year
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();

	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}

	return ret_arr;
}

function Calendar_print() {
	ggWinCal.print();
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/*
	Will return an 1-D array with 1st element being the calculated month
	and second being the calculated year
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();

	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}

	return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";

	// Begin Table Drawing code here..
	//vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";
	vCode = vCode + "<TABLE BORDER=1>";

	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode = vCode + vHeader_Code + vData_Code;

	vCode = vCode + "</TABLE>";

	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";

	this.gWinCal.document.open();

	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar </title>");
	this.wwrite("</head>");
	this.wwrite("<body class=tab1 ");

	//mes edit to include css
	this.wwrite("<!-#include file='default.css' ->");

	this.wwriteA("<center><FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwriteA(this.gMonthName + " " + this.gYear);
	this.wwriteA("</B></FONT></center>");

	// Show navigation buttons
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];

	this.wwrite("<center><table border=0><tr><td align=center valign=center>");
	this.wwrite("<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem.split("'").join("\\'") + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><img src='images/leftAll.gif' alt=\"Go To Previous Year\" border=0></A></TD><TD ALIGN=center valign=center>");
	this.wwrite("<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem.split("'").join("\\'") + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><img src='images/leftOne.gif' alt=\"Go To Previous Month\" border=0></A></TD><TD ALIGN=center>");
			 // this.wwrite("<A HREF=\"javascript:window.print();\"><img src='images/print.gif' border=0></A></TD><TD ALIGN=center valign=center>");
	this.wwrite("<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem.split("'").join("\\'") + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><img src='images/rightOne.gif' alt=\"Go To Next Month\" border=0></A></TD><TD ALIGN=center valign=center>");
	this.wwrite("<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem.split("'").join("\\'") + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><img src='images/rightAll.gif' alt=\"Go To Next Year\" border=0></A></td></tr></table></center><br>");

	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);

	this.wwrite("</body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.showY = function() {
	var vCode = "";
	var i;
	var vr, vc, vx, vy; // Row, Column, X-coord, Y-coord
	var vxf = 285;			// X-Factor
	var vyf = 200;			// Y-Factor
	var vxm = 10; // X-margin
	var vym;				// Y-margin
	if (isIE) vym = 75;
	else if (isNav) vym = 25;

	this.gWinCal.document.open();

	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("<style type='text/css'>\n<!--");
	for (i=0; i<12; i++) {
		vc = i % 3;
		if (i>=0 && i<= 2)	vr = 0;
		if (i>=3 && i<= 5)	vr = 1;
		if (i>=6 && i<= 8)	vr = 2;
		if (i>=9 && i<= 11) vr = 3;

		vx = parseInt(vxf * vc) + vxm;
		vy = parseInt(vyf * vr) + vym;

		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
	}
	this.wwrite("-->\n</style>");
	this.wwrite("</head>");

	this.wwrite("<body " +
		"link=\"" + this.gLinkColor + "\" " +
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwrite("Year : " + this.gYear);
	this.wwrite("</B><BR>");

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;

	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem.split("'").join("\\'") + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" alt='Prev Year'><font size=1 color=black face=arial><</font><\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem.split("'").join("\\'") + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for each month..
	var j;
	for (i=11; i>=0; i--) {
		if (isIE)
			this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
		else if (isNav)
			this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

		this.gMonth = i;
		this.gMonthName = Calendar.get_month(this.gMonth);
		vCode = this.getMonthlyCalendarCode();
		this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
		this.wwrite(vCode);

		if (isIE)
			this.wwrite("</DIV>");
		else if (isNav)
			this.wwrite("</LAYER>");
	}

	this.wwrite("</font><BR></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
	this.gWinCal.document.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";

	vCode = vCode + "<TR>";
	vCode = vCode + "<TD class=tr1 WIDTH='14%'><SMALL><b>Sun</b></SMALL></TD>";
	vCode = vCode + "<TD class=tr1 WIDTH='14%'><SMALL><b>Mon</b></SMALL></TD>";
	vCode = vCode + "<TD class=tr1 WIDTH='14%'><SMALL><b>Tue</b></SMALL></TD>";
	vCode = vCode + "<TD class=th1 WIDTH='14%'><SMALL><b>Wed</b></SMALL></TD>";
	vCode = vCode + "<TD class=tr1 WIDTH='14%'><SMALL><b>Thu</b></SMALL></TD>";
	vCode = vCode + "<TD class=tr1 WIDTH='14%'><SMALL><b>Fri</b></SMALL></TD>";
	vCode = vCode + "<TD class=tr1 WIDTH='16%'><SMALL><b>Sat</b></SMALL></TD>";
	vCode = vCode + "</TR>";

	return vCode;
}

Calendar.prototype.cal_data = function() {
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);

	var vFirstDay=vDate.getDay();
	var vDay=1;
	var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
	var vOnLastDay=0;
	var vCode = "";

	/*
	Get day for the 1st of the requested month/year..
	Place as many blank cells before the 1st day of the month as necessary.
	*/

	vCode = vCode + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
			"<A HREF='#' " +
				"onClick=\"self.opener.fieldsHaveChanged=true; self.opener.document." + this.gReturnItem + ".value='" +
				this.format_data(vDay) +
				"'; window.close();\"><font color='#000000'>" +
				this.format_day(vDay) +
			"</font></A>" +
			"</FONT></TD>";
		vDay=vDay + 1;
	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

		for (j=0; j<7; j++) {
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
				"<A HREF='#' " +
					"onClick=\"self.opener.fieldsHaveChanged=true; self.opener.document." + this.gReturnItem + ".value='" +
					this.format_data(vDay) +
					"'; window.close();\"><font color='#000000'>" +
				this.format_day(vDay) +
				"</font></A>" +
				"</FONT></TD>";
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 6)
			vCode = vCode + "</TR>";
		if (vOnLastDay == 1)
			break;
	}

	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
		else
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
	}

	return vCode;
}

Calendar.prototype.format_day = function(vday) {

	var vNowDay = gDate.getDate();
	var vNowMonth = gDate.getMonth();
	var vNowYear = gDate.getFullYear();

	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		return ("<FONT COLOR=\"ORANGE\"><B>" + vday + "</B></FONT>");
	else
		return (vday);
}

Calendar.prototype.write_weekend_string = function(vday) {
	var i;

	// Return special formatting for the weekend day.
	for (i=0; i<weekend.length; i++) {
		if (vday == weekend[i])
			return (" BGCOLOR=\"" + weekendColor + "\"");
	}

	return "";
}

Calendar.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
	var vY4 = new String(this.gYear);
	var vY2 = new String(this.gYear.substr(2,2));
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

	switch (this.gFormat) {
		case "MM\/DD\/YYYY" :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
			break;
		case "MM\/DD\/YY" :
			vData = vMonth + "\/" + vDD + "\/" + vY2;
			break;
		case "MM-DD-YYYY" :
			vData = vMonth + "-" + vDD + "-" + vY4;
			break;
		case "MM-DD-YY" :
			vData = vMonth + "-" + vDD + "-" + vY2;
			break;

		case "DD\/MON\/YYYY" :
			vData = vDD + "\/" + vMon + "\/" + vY4;
			break;
		case "DD\/MON\/YY" :
			vData = vDD + "\/" + vMon + "\/" + vY2;
			break;
		case "DD-MON-YYYY" :
			vData = vDD + "-" + vMon + "-" + vY4;
			break;
		case "DD-MON-YY" :
			vData = vDD + "-" + vMon + "-" + vY2;
			break;

		case "DD\/MONTH\/YYYY" :
			vData = vDD + "\/" + vFMon + "\/" + vY4;
			break;
		case "DD\/MONTH\/YY" :
			vData = vDD + "\/" + vFMon + "\/" + vY2;
			break;
		case "DD-MONTH-YYYY" :
			vData = vDD + "-" + vFMon + "-" + vY4;
			break;
		case "DD-MONTH-YY" :
			vData = vDD + "-" + vFMon + "-" + vY2;
			break;

		case "DD\/MM\/YYYY" :
			vData = vDD + "\/" + vMonth + "\/" + vY4;
			break;
		case "DD\/MM\/YY" :
			vData = vDD + "\/" + vMonth + "\/" + vY2;
			break;
		case "DD-MM-YYYY" :
			vData = vDD + "-" + vMonth + "-" + vY4;
			break;
		case "DD-MM-YY" :
			vData = vDD + "-" + vMonth + "-" + vY2;
			break;

		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	}

	return vData;
}

function Build(p_item, p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	// Choose appropriate show function
	if (gCal.gYearly) gCal.showY();
	else	gCal.show();
}

function show_calendar(fld) {
	/*
		p_month : 0-11 for Jan-Dec; 12 for All Months.
		p_year	: 4-digit year
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
		p_item	: Return Item.
	*/



	p_item = arguments[0];

	var dateitem = eval("this.document." + p_item);


	if(checkdate(dateitem) && dateitem.value != "")
		gDate = new Date(dateitem.value);
	else
		gDate = new Date();

	if (arguments[1] == null)
		p_month = new String(gDate.getMonth());
	else
		p_month = arguments[1];
	if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gDate.getFullYear().toString());
	else
		p_year = arguments[2];
	if (arguments[3] == null)
		p_format = "MM/DD/YYYY";
	else
		p_format = arguments[3];

	vWinCal = window.open("", "Calendar",
		"width=250,height=250,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;

	if(opener) {
		if(opener.addChild) {
		      //  addChild(vWinCal);
		}
	}

	if(top){

		if(top.opener) {
			if(top.opener.addChild)
				top.opener.addChild(vWinCal);
			else if(top.opener.top) {
				if(top.opener.top.addChild)
					top.opener.top.addChild(vWinCal);
			}
		} else if(top.addChild)
			top.addChild(vWinCal);
	}

	ggWinCal = vWinCal;

	Build(p_item, p_month, p_year, p_format);
}
/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
	// Load the defaults..
	if (p_year == null || p_year == "")
		p_year = new String(gDate.getFullYear().toString());
	if (p_format == null || p_format == "")
		p_format = "MM/DD/YYYY";

	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
	vWinCal.opener = self;

	if(opener) {
		if(opener.addChild)
			addChild(vWinCal);
	}
	if(top){
		if(top.opener) {
			if(top.opener.addChild)
				top.opener.addChild(vWinCal);
			else if(top.opener.top) {
				if(top.opener.top.addChild)
					top.opener.top.addChild(vWinCal);
			}
		} else if(top.addChild)
			top.addChild(vWinCal);
	}

	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}
// ==================END DATE PICKER =======================


// =========================================================
//				 FIELD MASKS
// =========================================================
	 // phone number
			function phoneMask(fld)
			{
	origValue = fld.value;
	var tmpValue = '';
	var newValue = '';
	for(var i = 0; i < fld.value.length; i++)
	 {
		if(isDigit(fld.value.charAt(i)))
		 {
			 tmpValue += fld.value.charAt(i);
		 }
	 }
			 if(tmpValue.length < 7)
	{
	 return;
	}
			 // format it it like a standard local number
			 if(tmpValue.length == 7)
			 {
	for(var n = 0; n<tmpValue.length; n++)
	 {
		 if(n == 3)
			{
			 newValue += '-' + tmpValue.charAt(n);
			}
		 else
			{
			 newValue += tmpValue.charAt(n);
			}
	 }
	 fld.value = newValue;
			 }
			 // format it with area code in parens
			 if(tmpValue.length == 10)
	{
	 newValue = '(';
	 for(var n = 0; n<tmpValue.length; n++)
	 {
		 if(n == 3)
			{
			 newValue += ') ' + tmpValue.charAt(n);
			}
		 else if(n == 6)
			{
			 newValue += '-' + tmpValue.charAt(n);
			}
		 else
			{
			 newValue += tmpValue.charAt(n);
			}
	 }
	 fld.value = newValue;
	}
			}
// ----- end phone number --------

// ------- zip code --------------
 function zipMask(fld)
	 {
		 origValue = fld.value;
		 var tmpValue = '';
		 var newValue = '';
		 for(var i = 0; i < fld.value.length; i++)
			 {
	 if(isDigit(fld.value.charAt(i)))
	 {
		tmpValue += fld.value.charAt(i);
	 }
			 }
		 // 5-digit US zip
		 if(tmpValue.length == 5)
			{

	 fld.value = tmpValue;
			}
		// US w/ extension
		if(tmpValue.length == 9)
			{
	for(var n = 0; n<tmpValue.length; n++)
	 {
		 if(n == 5)
			{
			 newValue += '-' + tmpValue.charAt(n);
			}
		 else
			{
			 newValue += tmpValue.charAt(n);
			}
	 }
	fld.value = newValue;
			}

	 }
// ------- end zip code ----------


// ------- ProperCase FieldMask ---------------

function pcaseMask(fld){
STRING = fld.value;
var strReturn_Value = "";
var iTemp = STRING.length;
if(iTemp==0){
return"";
}
var UcaseNext = false;
strReturn_Value += STRING.charAt(0).toUpperCase();
for(var iCounter=1;iCounter < iTemp;iCounter++){
if(UcaseNext == true){
strReturn_Value += STRING.charAt(iCounter).toUpperCase();
}
else{
strReturn_Value += STRING.charAt(iCounter).toLowerCase();
}
var iChar = STRING.charCodeAt(iCounter);
if(iChar == 32 || iChar == 45 || iChar == 46){
UcaseNext = true;
}
else{
UcaseNext = false
}
if(iChar == 99 || iChar == 67){
if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109){
UcaseNext = true;
}
}


} //End For

//return strReturn_Value;
fld.value = strReturn_Value;
} //End Function



// --------- end ProperCase --------------------


function validateInput(field, bad_chars, remove_bad, field_name) {
  var valid = true;

  if(field == null) {
    alert('The field you passed to validateInput is null!');
    return false;
  }

  if(field.value == null)
    return false;

  if(bad_chars == null)
    bad_chars = '"\'(){}[]\\';


  // Spin through the bad character to check for each
  for(c = 0; c < bad_chars.length; c++) {
    strs = field.value.split(bad_chars.charAt(c));
    if(strs.length > 1) {
      // Uh oh, the bad char is in the string
      valid = false;

      if(remove_bad) {
	// Remove bad chars
	field.value = strs.join('');
      }
    }
  }

  if(!valid && field_name != null) {
    alert("The " + field_name + " cannnot contain the following character(s): " + bad_chars);
    field.focus();
    field.select();
  }

  return valid;
}

// =========================================================
//     TAB SAVING
// =========================================================
var fieldsHaveChanged = false;

// =========================================================
//     UNIVERSAL FORM FIXES
// =========================================================

// this function does the following things to fields in a form:
//	- fixes inputs by added onKeyPress event handler to avoid beeps
//	- sets onChange to set a flag for tab saving
//var changeFunctions = new Array();

function fixForm()
{
  frm = document.forms[0];

  if(frm)
  {
    for(i = 0; i < frm.length; i++) {
      elt = frm.elements[i];
      if(elt.tagName == "INPUT" && elt.type != "hidden") {
	if(elt.onkeypress == null)
	      elt.onkeypress = handleEnter;
      }

      //alert(elt.tagName + '\n' + elt.type);
      if(elt.type != "hidden" && window.saveme) {
	if(elt.onchange == null)
	  elt.onchange = new Function("fieldsHaveChanged = true;");
	if(elt.onblur == null)
	  elt.onblur = new Function("fieldsHaveChanged = true;");
	//else
	//  alert("An onChange handler has been detected: " + fld.name + "\n\n" + fld.onchange);
      }
    }
  }
}

// this is very tricky but should work universally
setTimeout("fixForm()", 1500);

// =========================================================
//     QUICK KEYS - CAPTURE THE ENTER KEY
// =========================================================

      if(navigator.appName == "Netscape") {
	document.captureEvents(Event.KEYPRESS);
      }

      function qk(keyp)
      {
	if(getKeyCode() == 13)
	  {
	    if(event.srcElement.type != 'textarea' && event.srcElement.tagName != "A")
	    {
	      event.returnValue = false;
	      event.cancelBubble = true;
	      if(window.saveme) {
		var doSave = true;

		if(layerExists) {
		  if(layerExists("SaveButton")) {
		    if(isHidden("SaveButton"))
		      doSave = false;
		  }
		}

		if(doSave)
		  saveme();
	      }
	    }
	  }
      }

      function getKeyCode()
      {
	      return (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
      }

      // this handles enter keypressed on inputs to avoid beep
      function handleEnter()
      {
	      return (getKeyCode() != 13);
      }

      document.onkeypress = qk;

// =========================================================
//     OPEN URL WITH OFFSET
// =========================================================

function openUrl(wUrl, FromTop, FromLeft, size, isModal) {  
  if(FromTop) {
    if(isNumeric(FromTop)) {
      FromTop = FromTop;
    }
  } else {
    FromTop=5;
  }  
  if(FromLeft) {
    if(isNumeric(FromLeft)) {
      FromLeft = FromLeft;
    }
  } else {
    FromLeft=5;
  }
              
  
  
  
  var userscreenwidth= screen.width - 150
  var userscreenheight = screen.height - 150
  var scrolling = "yes";
  wHeight=userscreenheight;
  wWidth=userscreenwidth;
  
  if (size) {
    if (size=="small") {
    // Calc this a a percent of users screen resolution (40%)
      wHeight = (Math.round(userscreenheight * .5)); 
      wWidth = (Math.round(userscreenwidth * .5)); 
     //wHeight="200";
     //wWidth="450";
    } else if (size=="medium"){
    // Calc this a a percent of users screen resolution (60%)
      wHeight = (Math.round(userscreenheight * .75)); 
      wWidth = (Math.round(userscreenwidth * .75)); 
    // wHeight="450";
    // wWidth="650";
    } else {
     //large
     scrolling = "yes";
    }
  }
  
  var now = new Date();
  timestamper = now.getTime();
  wName='appWin'+timestamper;
  if (isModal == 1 && isIE) {
    window.showModalDialog(wUrl,wName,"dialogHeight: "+wHeight+"px; dialogWidth: "+wWidth+"px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
  } else {
    window.open(wUrl,''+wName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scrolling+",resizable=yes,width="+wWidth+",height="+wHeight+",screenX=0,screenY=0, left=" + FromLeft +", top=" + FromTop);
    if(top.addChild) { top.addChild(wName); }
  }
}



// =========================================================
//     CLOSE POP-UP WINDOW, REFOCUS ON OPENER
// =========================================================

function closePopUp(reloadOpt) {

  if (reloadOpt != null && reloadOpt==1) {
    if(top.opener) {
      top.opener.focus();
      var locchk = String(top.opener.location);
      if ( locchk.indexOf('allmenu') > 0) {
	//do not fresh the menu.., refresh main..
      } else {
	top.opener.location.reload(true);
      }
      parent.window.close();
    }  else {
      parent.window.close();
   }
  } else {
    if(opener) {
      opener.focus();
      parent.window.close();
    }  else {
      parent.window.close();
   }

  }
}

// =========================================================
//     OPEN GENERIC ENTITY FROM PORTAL WINDOW
// =========================================================


function openentity(id, tableName, masterKeyName, popUp, subareaTableName, subareaTableId,frmutl,id2,yPos) {
  //alert(tableName);
  // alert(frmutl);
  if (subareaTableName == null) { subareaTableName =  tableName; }
  if (subareaTableId == null || subareaTableId == 'undefined' || subareaTableId == 0 || subareaTableId == '0') { subareaTableId =  ''; }
  if(id == null || id == 'undefined' || id == 0 || id == '0') {id = ""; }
  if(id2 == null || id2 == 'undefined' || id2 == 0 || id2 == '0') {id2 = ""; }
  if(frmutl == null || frmutl == 'undefined' ) 
    {frmutl = "1"; } 
  else if(frmutl == 0 || frmutl == '0') 
    { frmutl = "0";  } 
  else {frmutl = "1"; }
  if (yPos==null ||yPos == 'undefined') { yPos = 0; } 
 // alert(frmutl);
  
  url = "SRIentityGroup.jsp?id=" + id + "&id2=" + subareaTableId + "&tableName=" + subareaTableName + "&masterTableName=" + tableName +  "&masterKeyName=" + masterKeyName+"&subNav=1&subareatableId=" + subareaTableId + "&formutil=" + frmutl + "&yPos="+yPos;
   //alert(url);
   winname = "entityGroup" + id + "";
   if (popUp == 1) {

    var userscreenwidth= screen.width - 25
    var userscreenheight = screen.height - 100

    eval("winname = window.open(url, winname ,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=yes,width=" + userscreenwidth + ",height=" + userscreenheight  + " screenX=5,screenY=5,top=5,left=5')");
    if(top.addChild) { top.addChild(winname); }
   } else if (popUp == 2) {
      this.location = url;
   } else if (popUp == 3) {
      parent.main.location = url;
   } else {
      parent.location = url;
   }
}



function openentityInt(id, tableName, masterKeyName) {
   top.openentity(id, tableName, masterKeyName);
}

// =========================================================
//     FOCUSES ON FIRST NON-HIDDEN CONTROL IN FORM
// =========================================================

function focusOnFirstControl(frm)
{
  if(document.forms[0]) {
    elts = document.forms[0].elements;

    if(elts) {
      for(i = 0; i < elts.length; i++) {
	if(elts[i].type != "hidden" && elts[i].type != "button" && elts[i].type.indexOf("select") == -1 ) {
	  elts[i].focus();
	  //if(elts[i].select)
	  //  elts[i].select();
	  return;
	}
      }
    }
  }
}

// =========================================================
//     STATUS BAR
// =========================================================

function statOn(str) {
  window.status = str;
  return true;
}

function statOff() {
  window.status = "";
  return true;
}


// =========================================================
//     COOKIES
// =========================================================

function setCookie(name, value, expires) {
 var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "");
  document.cookie = curCookie;
}



function getCookie(name) {

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// =========================================================
//     TEXTAREA REPLACE CARRAIGE RETURN WITH PASSED VALUE
// =========================================================

function replaceTextAreaCR(textarea,replaceWith){

//1. encode textarea string's carriage returns
textarea.value = escape(textarea.value)

//2. replace
	for(i=0; i<textarea.value.length; i++){

		if(textarea.value.indexOf("%0D%0A") > -1){ ///Windows encodes returns as \r\n hex
		  textarea.value=textarea.value.replace("%0D%0A",replaceWith)
		}
		else if(textarea.value.indexOf("%0A") > -1){ // Unix encodes returns as \n hex
		  textarea.value=textarea.value.replace("%0A",replaceWith)
		}
		else if(textarea.value.indexOf("%0D") > -1){ // Macintosh encodes returns as \r hex
		  textarea.value=textarea.value.replace("%0D",replaceWith)
		}
		
	}
//3. unescape all other encoded characters
textarea.value=unescape(textarea.value)
}

// =========================================================
//     FIX SPECIAL CHARS IN URLS, ETC....
// =========================================================

function encodeMyHtml(fldvaue) {
  encodedHtml = escape(fldvaue);
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     encodedHtml = encodedHtml.replace(/#/g,"%23");
     encodedHtml = encodedHtml.replace(/%/g,"%25");
     encodedHtml = encodedHtml.replace(/ /g,"%20");
     encodedHtml = encodedHtml.replace(/!/g,"%21");
  return encodedHtml;
}


// =========================================================
//     TRIM LEADING AND TRAILING
// =========================================================



function trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}


// =========================================================
//     Functions Used for Multi Option widget with OTHER
// =========================================================
 function chkOtherIMG(img) {
       f = document.forms[0];
       var fldid = img.id.split("CHKIMG").join("TEXT");
       var fld = f.elements(fldid);
       if(img.src.indexOf('chkOff.gif') > 0) {
         img.src = 'images/graychkOn.gif';
         fld.select();
       } else {
         img.src = 'images/graychkOff.gif'
         fld.value='';
       }
     }

    function chkOtherTXT(fld) {
       f = document.forms[0];
       var imgid = fld.id.split("TEXT").join("CHKIMG");
       var img = document.getElementById(imgid);
       if(fld.value == '') {
         img.src = 'images/graychkOff.gif';
       } else {
         img.src = 'images/graychkOn.gif';
       }
     }

