/*
Page:  Scripts.js
Created By:  Todd Pires
Created On:  12/06/2004
*/

function AllTrim(pSTRING)
{

while (pSTRING.substring(0, 1) == ' ')
	{
	pSTRING = pSTRING.substring(1, pSTRING.length);
	}
	
while (pSTRING.substring(pSTRING.length - 1, pSTRING.length) == ' ')
	{
	pSTRING = pSTRING.substring(0, pSTRING.length - 1);
	}
	
return pSTRING;
}

function CalcDurationAndDates(pDURATIONTYPEID, pDURATIONNUMBERID, pDATEID1, pDATEID2, pDATEMASK)
{
var aDate, aDuration;
var cDate, cDate1, cDate2, cDate3, cType;
var nDuration, nFactor, nIncr, nMonth, nSign, nTimeVal, nYear;
var nGoOn = 0;
var oDate1 = document.getElementById(pDATEID1);
var oDate2 = document.getElementById(pDATEID2);
var oDurationNumber = document.getElementById(pDURATIONNUMBERID);
var oDurationType = document.getElementById(pDURATIONTYPEID);
var oTgt;
var oType = new Object();
	oType[0] = "";
	oType[1] = "d"; 
	oType[2] = "w"; 
	oType[3] = "m";

// We need params 0 and any 2 of params 1 - 3 to complete this calculation
cType = oType[oDurationType.value];
nDuration = isNaN(parseFloat(oDurationNumber.value)) ? 0 : parseFloat(oDurationNumber.value);
nGoOn += nDuration > 0 ? 1 : 0; // check the duration number
nGoOn += !IsEmpty(oDate1) > 0 ? 1 : 0; // check the start date
nGoOn += !IsEmpty(oDate2) > 0 ? 1 : 0; // check the end date

if (!IsEmpty(cType) && nGoOn > 1)
	{
	// figure out where to put the result
	oTgt = nDuration == 0 ? oDurationNumber : oDate2;
	oTgt = IsEmpty(oDate1) ? oDate1 : oTgt;

	cDate1 = IsEmpty(oDate1) ? "" : ConvertDateFormat(oDate1, pDATEMASK, "M/d/yyyy");
	cDate2 = IsEmpty(oDate2) ? "" : ConvertDateFormat(oDate2, pDATEMASK, "M/d/yyyy");

	if (cType == "m")
		{
		if (oTgt.id == pDURATIONNUMBERID)
			{
			nDuration = Math.abs(DateDiff(oDate1, oDate2, pDATEMASK, pDATEMASK, "w"))
			oTgt.value = Math.round(nDuration / 4.35); // 4.35 is the avg number of weeks in a month
			}
		else
			{
			cDate = oTgt.id == pDATEID1 ? cDate2 : cDate1;
			aDate = cDate.split("/");
			aDuration = (nDuration / 12).toString().split(".");
			nSign = oTgt.id == pDATEID1 ? 1 : -1;
			nMonth = parseFloat(aDate[0]) - ((nDuration % 12) * nSign);
			nYear = parseFloat(aDate[2]) - (parseFloat(aDuration[0]) * nSign);
			if (nMonth > 12)
				{
				nMonth -= 12;
				nYear++;
				}
			else if (nMonth < 1)
				{
				nMonth += 12;
				nYear--;
				}
			//endif
			cDate3 = nMonth + "/" + aDate[1] + "/" + nYear;
			oTgt.value = ConvertDateFormat(cDate3, "M/d/yyyy", pDATEMASK);
			}
		//endif
		}
	else
		{
		nFactor = cType == "w" ? 7 : 1;
		nDuration = nDuration * nFactor;
		if (oTgt.id == pDURATIONNUMBERID)
			{
			oTgt.value = Math.round(Math.abs(DateDiff(oDate1, oDate2, pDATEMASK, pDATEMASK, cType)));
			}
		else
			{
			cDate = oTgt.id == pDATEID1 ? cDate2 : cDate1;
			nSign = oTgt.id == pDATEID1 ? 1 : -1;
			nTimeVal = Date.parse(cDate) - ((nDuration * 86400000) * nSign);
			dDate = new Date(nTimeVal);
			cDate3 = (dDate.getMonth() + 1) + "/";
			cDate3 += dDate.getDate() + "/";
			cDate3 += dDate.getYear();
			oTgt.value = ConvertDateFormat(cDate3, "M/d/yyyy", pDATEMASK);
			}
		//endif
		}
	//endif
	}
//endif

return
}

function CallCalendar(pDATEOBJID, pDATEMASK, pDEBUG)
{
var cStr;
var cUrl = "szMode=d"; // Set the flag to call the date (d) section of the calendar
var oCalendar, oObj;
var nDebug = arguments.length == 3 ? pDEBUG : 0;

cStr = "szDebug=" + nDebug;
cUrl = ListAppend(cUrl, cStr, "&"); // Set the debug flag
cStr = "szIsInPopUp=1";
cUrl = ListAppend(cUrl, cStr, "&"); // Set the popup flag

if (!IsEmpty(pDATEOBJID))
	{
	oObj = document.getElementById(pDATEOBJID);
	if (!IsEmpty(oObj))
		{
		cStr = "szDate=" + ConvertDateFormat(oObj, pDATEMASK, "yyyyMMdd");
		cUrl = ListAppend(cUrl, cStr, "&"); // Set the initial calendar date in yyyyMMdd format
		}
	//endif
	}
//endif

cUrl = ListAppend("/Calendar/Calendar.cfm", cUrl, "?");

if (nDebug == 0)
	{
	oCalendar = window.showModalDialog(cUrl, "", "dialogHeight:350px; dialogWidth:250px; edge:raised; center:yes; help:no; status:no; resizable:no; scroll:no;");
	if (oCalendar.Selected)
		{
		if (!IsEmpty(pDATEOBJID))
			{
			oObj = document.getElementById(pDATEOBJID);
			oObj.value = oCalendar.LocaleDate;
			oObj.fireEvent('onChange');
			}
		//endif
		}
	//endif
	}
else
	{
	window.open(cUrl);
	}
//endif	

return
}

function CallTimer(pTIMEOBJID, pTIMEMASK, pMARKTGTAM, pMARKTGTPM, pDEBUG)
{
var cStr;
var cUrl = "szMode=t"; // Set the flag to call the time (t) section of the calendar
var lIsAm = false;
var nDebug = pDEBUG ? pDEBUG : 0;
var oCalendar, oObj;

cStr = "szDebug=" + nDebug;
cUrl = ListAppend(cUrl, cStr, "&"); // Set the debug flag
cStr = "szIsInPopUp=1";
cUrl = ListAppend(cUrl, cStr, "&"); // Set the popup flag

if (!IsEmpty(pTIMEOBJID))
	{
	oObj = document.getElementById(pTIMEOBJID);
	if (!IsEmpty(oObj))
		{
		if (pTIMEMASK.indexOf("h") > -1)
			{
			lIsAm = oObj.value.indexOf(pMARKTGTAM) > -1;
			}
		//endif
		cStr = ConvertTimeFormat(oObj, pTIMEMASK, "HHmm", lIsAm, pMARKTGTAM, pMARKTGTPM);
		cStr = "szTime=" + cStr;
		cUrl = ListAppend(cUrl, cStr, "&"); // Set the initial calendar time in HHmm format
		}
	//endif
	}
//endif

cUrl = ListAppend("/Calendar/Calendar.cfm", cUrl, "?");

if (nDebug == 0)
	{
	oCalendar = window.showModalDialog(cUrl, "", "dialogHeight:350px; dialogWidth:250px; edge:raised; center:yes; help:no; status:no; resizable:no; scroll:no");
	if (oCalendar.Selected)
		{
		if (!IsEmpty(pTIMEOBJID))
			{
			oObj = document.getElementById(pTIMEOBJID);
			oObj.value = oCalendar.LocaleTime;
			}
		//endif
		}
	//endif
	}
else
	{
	window.open(cUrl);
	}
//endif	

return
}

function CenterDialogBox(pBOXHEIGHT, pBOXWIDTH)
{
var nTop = (screen.availHeight - pBOXHEIGHT) / 2;
var nLeft = (screen.availWidth - pBOXWIDTH) / 2;

window.dialogLeft = nLeft + "px";
window.dialogTop = nTop + "px";

return
}

function CheckDate(pDATE, pMASK, pALERT) 
{
// Returns a boolean indicating if the date passed is a valid gregorian date
var cDataString, cMaskString, cStr; // string variables
var cDateString = typeof(pDATE) == "string" ? AllTrim(pDATE) : AllTrim(pDATE.value); // string to hold the data to convert
var eDigits = /[\D]/; // reg ex to test for only digits
var eMask = /[dmy]/gi;
var lRetVal; //return value of the function
var nDay, nDaysInMonth, nMonth, nYear; // date part variables
var nI, nIStop; // loop varaibles
var oPartsSrc = GetMaskParts(cDateString, pMASK.toLowerCase(), "d,m,y"); // get the object for the date & source mask

cDataString = cDateString;
cMaskString = pMASK.replace(eMask, "");
nIStop = cMaskString.length;

for (nI = 0; nI < nIStop; nI++)
	{
	cStr = cMaskString.substr(nI, 1);
	cDataString = cDataString.replace(cStr, "");
	}
//endif

lRetVal = !eDigits.test(cDataString);
if (lRetVal) // We have a 3 numeric date parts
	{
	lRetVal = AllTrim(oPartsSrc["y"]["Data"]).length == 4; // Check for 4 character long year
	if (lRetVal) // We have a 4 character long year (must be 4 characters to check for leap years, even if it is year 0001)
		{
		nYear = parseFloat(oPartsSrc["y"]["Data"]); // Convert the year date part to a number
		lRetVal = nYear > 0; // Check that the year is > 0
		if (lRetVal) // We have a valid number for the year
			{
			nMonth = parseFloat(oPartsSrc["m"]["Data"]); // Convert the month date part to a number
			lRetVal = 1 <= nMonth && nMonth <= 12; // Check that we have a valid number for the month
			if (lRetVal) // We have a valid number for the month
				{
				nDaysInMonth = DaysInMonth(nMonth - 1, nYear); // The DaysInMonth() function takes a js month number as the 1st param, so subtract 1 from the month number passed
				nDay = parseFloat(oPartsSrc["d"]["Data"]); // Convert the day date part to a number
				lRetVal = 1 <= nDay && nDay <= nDaysInMonth; // Check that we have a valid number for the day
				}
			//endif
			}
		//endif
		}
	//endif
	}
//endif

if (!lRetVal && pALERT && typeof(pDATE) != "string" && !IsEmpty(pDATE))
	{
	cMsgTxt = objMsgs["dateInFollowingFormat"] + "  " + pMASK;
  alert(cMsgTxt);
 	pDATE.value = "";
  pDATE.focus();
	}
//endif
	
return lRetVal;
}

function ClearFields(pFIELDLIST)
{
var aFields = pFIELDLIST.split(",");
var nI;
var nIStop = aFields.length;
var oObj;

for (nI = 0; nI < nIStop; nI++)
	{
	oObj = document.getElementById(aFields[nI]);
	oObj.value = "";
	}
//next

return
}

function ClickIt(pOBJ)
{
var oObj;

if (typeof(pPARAM) == "string")
	{
	oObj = document.getElementById(pOBJ);
	}
else
	{
	oObj = pOBJ;
	}
//endif

if (!oObj.disabled)
	{
	oObj.focus();
	oObj.click();
	}
//endif

return
}

function ConvertDateFormat(pDATE, pMASKSRC, pMASKTGT)
{
// Returns a date string converted from one mask to another 
var cRetVal = typeof(pDATE) == "string" ? AllTrim(pDATE) : AllTrim(pDATE.value); // string to hold the data to convert
var nI, nIStop; // loop variables
var oPartsSrc, oPartsTgt; // Objects to hold information about the time & mask

if (pMASKSRC != pMASKTGT)
	{
	oPartsSrc = GetMaskParts(cRetVal, pMASKSRC.toLowerCase(), "d,m,y"); // get the object for the date & source mask
	oPartsTgt = GetMaskParts("", pMASKTGT.toLowerCase(), "d,m,y"); // get the object for the target mask

	aMaskDesignators = oPartsTgt["Designators"].split(","); // convert the target mask designators string into an array
	cRetVal = pMASKTGT.toLowerCase(); // set the return string to the target mask
	nIStop = aMaskDesignators.length; // set the end loop value

	for (nI = 0; nI < nIStop; nI++)
		{
		// pad the data value from the source date to the length of the corresponding mask part of the target mask
		cStr = AllTrim(oPartsSrc[aMaskDesignators[nI]]["Data"]);
		if (cStr.length < oPartsTgt[aMaskDesignators[nI]]["Part"].length)
			{
			cStr = PadLeft(cStr, "0", oPartsTgt[aMaskDesignators[nI]]["Part"].length);
			}
		//endif
		cRetVal = cRetVal.replace(oPartsTgt[aMaskDesignators[nI]]["Part"], cStr); // replace each mask part of the target mask with the corresponding data value from the source date
		}
	//next
		
	}
//endif

return cRetVal;
}

function ConvertTimeFormat(pTIME, pMASKSRC, pMASKTGT, pISAM, pMARKTGTAM, pMARKTGTPM)
{
// Returns a time string converted from one mask to another 
var cRetVal = typeof(pTIME) == "string" ? AllTrim(pTIME) : AllTrim(pTIME.value); // string to hold the data to convert
var nI, nIStop; // loop variables
var nOffSet = 0; // time conversion variable
var lSrcIs24Hr = pMASKSRC.indexOf("H") > -1; // flag to indicate if the src mask is 24 hr time
var lTgtIs24Hr = pMASKTGT.indexOf("H") > -1; // flag to indicate if the tgt mask is 24 hr time
var oPartsSrc, oPartsTgt; // Objects to hold information about the time & mask

if (pMASKSRC != pMASKTGT)
	{
	oPartsSrc = GetMaskParts(cRetVal, pMASKSRC.toLowerCase(), "h,m,a"); // get the object for the time & source mask
	oPartsTgt = GetMaskParts("", pMASKTGT.toLowerCase(), "h,m,a"); // get the object for the target mask

	if (lSrcIs24Hr != lTgtIs24Hr) // need to convert from 12 hr time to 24 hr time or 24 hr time to 12 hr time
		{
		if (lSrcIs24Hr) // need to convert from 24 hr time to 12 hr time
			{
			nOffSet = parseFloat(oPartsSrc["h"]["Data"]) == 0 ? 12 : nOffSet; // if the hour is 0, set the hour to 12 am
			nOffSet = parseFloat(oPartsSrc["h"]["Data"]) > 12 ? -12 : nOffSet; // if the hours are > 12 set the hours to pm
			}
		else // need to convert from 12 hr time to 24 hr time
			{
			nOffSet = parseFloat(oPartsSrc["h"]["Data"]) == 12 && cRetVal.indexOf(pMARKTGTAM) > -1 ? -12 : nOffSet; // if the hour is 12 pm
			nOffSet = parseFloat(oPartsSrc["h"]["Data"]) < 12 && cRetVal.indexOf(pMARKTGTPM) > -1 ? 12 : nOffSet; // if the hours are < 12 but it is pm
			}
		//endif
		oPartsSrc["h"]["Data"] = (parseFloat(oPartsSrc["h"]["Data"]) + nOffSet).toString();
		}
	//endif
	aMaskDesignators = oPartsTgt["Designators"].split(","); // convert the target mask designators string into an array
	cRetVal = pMASKTGT.toLowerCase(); // set the return string to the target mask
	nIStop = aMaskDesignators.length; // set the end loop value
	
	for (nI = 0; nI < nIStop; nI++)
		{
		if (aMaskDesignators[nI] == "a")
			{
			if (!lTgtIs24Hr)
				{
				cStr = pISAM ? pMARKTGTAM : pMARKTGTPM;
				}
			//endif
			} 
		else
			{
			// pad the data value from the source date to the length of the corresponding mask part of the target mask
			cStr = AllTrim(oPartsSrc[aMaskDesignators[nI]]["Data"]);
			if (cStr.length < oPartsTgt[aMaskDesignators[nI]]["Part"].length)
				{
				cStr = PadLeft(cStr, "0", oPartsTgt[aMaskDesignators[nI]]["Part"].length);
				}
			//endif
			}
		//endif
		cRetVal = cRetVal.replace(oPartsTgt[aMaskDesignators[nI]]["Part"], cStr); // replace each mask part of the target mask with the corresponding data value from the source time
		}
	//next

	}
//endif

return cRetVal;
}

function DateDiff(pDATE1, pDATE2, pDATEMASK1, pDATEMASK2, pDATEPART)
{
// Returns the difference between two dates
var cDateString1 = typeof(pDATE1) == "string" ? AllTrim(pDATE1) : AllTrim(pDATE1.value); // String to hold the date to compare
var cDateString2 = typeof(pDATE2) == "string" ? AllTrim(pDATE2) : AllTrim(pDATE2.value); // String to hold the date to compare
var nRetVal;

cDatePart = arguments.length == 5 ? pDATEPART.toLowerCase() : "d";
cDateString1 = ConvertDateFormat(cDateString1, pDATEMASK1, "MM/dd/yyyy");
cDateString2 = ConvertDateFormat(cDateString2, pDATEMASK2, "MM/dd/yyyy");
nRetVal = Date.parse(cDateString1) - Date.parse(cDateString2);  // return milli-seconds

switch (cDatePart)
	{
	
	case "s": // return seconds
		nRetVal = nRetVal / 1000;
		break;
	//endcase
	
	case "m": // return minutes
		nRetVal = nRetVal / 60000;
		break;
	//endcase

	case "h": // return hours
		nRetVal = nRetVal / 3600000;
		break;
	//endcase

	case "d": // return days
		nRetVal = nRetVal / 86400000;
		break;
	//endcase

	case "w": // return weeks
		nRetVal = nRetVal / 604800000;
		break;
	//endcase

	}
//endswitch

return nRetVal;
}

function DaysInMonth(pMONTH, pYEAR)
{
var aDaysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var nRetVal = pMONTH == 1 && IsLeapYear(pYEAR) ? 1 : 0;

nRetVal += aDaysInMonth[pMONTH];

return nRetVal;
}

function DisableObjectsById(pOBJECTIDLIST)
{
var aObjectId = pOBJECTIDLIST.split(",");
var nI;
var nIStop = aObjectId.length;

for (nI = 0; nI < nIStop; nI++)
	{
	document.getElementById(aObjectId[nI]).disabled = true;
	}
//next

return
}

function DragStart(pSRC)
{
oDragItem.Src = pSRC;
oDragItem.MousePosX = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; // get the cursor position with respect to the page
oDragItem.MousePosY = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; // get the cursor position with respect to the page
oDragItem.SrcPosX = parseFloat(pSRC.style.left); // get the starting position of the source element
oDragItem.SrcPosY = parseFloat(pSRC.style.top); // get the starting position of the source element

document.attachEvent("onmousemove", DragMove); // attach the onmousemove event to the document
document.attachEvent("onmouseup", DragStop); // attach the onmouseup event to the document

return
}

function DragMove()
{
var nMousePosX = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; // get the cursor position with respect to the page
var nMousePosY = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; // get the cursor position with respect to the page

oDragItem.Src.style.left = (oDragItem.SrcPosX + nMousePosX - oDragItem.MousePosX) + "px"; // move the object by the same amount the cursor moved
oDragItem.Src.style.top = (oDragItem.SrcPosY + nMousePosY - oDragItem.MousePosY) + "px"; // move the object by the same amount the cursor moved

return
}

function DragStop()
{
document.detachEvent("onmousemove", DragMove); // detach the onmousemove event from the document
document.detachEvent("onmouseup", DragStop); // detach the onmouseup event from the document

oDragItem = new Object(); // reset oDragItem

return
}

function FixDate(pDATE, pDATEMASK)
{
//DEPRECATED!!!!  DO NOT USE - tpires - 04/21/2005
var aDateParts; // Array to hold the date string date parts
var cDateString = ""; // String to hold the properly formatted date
var cDelimiter = ""; // String to hold the delimiter of the date mask
var cDateMask = !pDATEMASK ? "MM/dd/yyyy" : pDATEMASK; // String to hold the date mask
var cMsgTxt = ""; // String to hold the invalid date message
var lGoodDate = true; // Set this to true to accept blanks

if (!IsEmpty(pDATE)) 
	{
	cDateString = AllTrim(pDATE.value); // Get the date passed as a string
	cDelimiter = GetMaskDelimiter(cDateMask); // Determine the delimiter used by the date mask
	aDateParts = cDateString.split(cDelimiter); // Create an array holding the parts of the date passed in

	if (aDateParts.length == 1 && cDateString.length == 8) // no delimiter
		{
	  cDateString = cDateString.substring(0,2) + cDelimiter + cDateString.substring(2,4) + cDelimiter + cDateString.substring(4,8);
		lGoodDate = CheckDate(cDateString, cDateMask);
  	}
	else if (aDateParts.length == 3) // 3 part date with a delimiter
		{
	  cDateString = PadLeft(aDateParts[0], "0", 2) + cDelimiter + PadLeft(aDateParts[1], "0", 2) + cDelimiter + aDateParts[2];
		lGoodDate = CheckDate(cDateString, cDateMask);
		}
	else
		{
		lGoodDate = false;
		}
	//endif

	if (!lGoodDate) 
		{
		cMsgTxt = objMsgs["dateInFollowingFormat"] + cDateMask;
	  alert(cMsgTxt);
	 	pDATE.value = "";
	  pDATE.focus();
  	} 
	else
		{
	 	pDATE.value = cDateString;
		}
	//endif
	}
//endif

return lGoodDate;
}

function GetMaskParts(pDATA, pMASK, pMASKPARTS)
{
var aDataParts = new Array(); // an array to hold the data parts
var aDesignators; // an array to hold the designators found in the mask
var aMaskParts = pMASKPARTS.split(","); // an array of all the possible designators of the data mask
var cDataPart, cMaskPart, cStr; // string variables
var cDataString = typeof(pDATA) == "string" ? AllTrim(pDATA) : AllTrim(pDATA.value); // String to hold the date being parsed
var eDigits = /[0-9]/; // reg ex to test for only digits
var nI, nJStop;  // counter & loop variables
var nIStop = aMaskParts.length; // loop variable
var nJ = 0; // counter variable
var oMaskParts = new Object(); // object to hold the data part value, mask part order & mask part value by mask part designator

// initialize oMaskParts 
for (nI = 0; nI < nIStop; nI++)
	{
	oMaskParts[aMaskParts[nI]] = new Object();
	oMaskParts[aMaskParts[nI]]["Data"] = "";
	oMaskParts[aMaskParts[nI]]["Order"] = -1;
	oMaskParts[aMaskParts[nI]]["Part"] = "";
	}
//next

oMaskParts["Designators"] = "";

nIStop = pMASK.length;
nJ = 0;

// populate oMaskParts
for (nI = 0; nI < nIStop; nI++)
	{
	cMaskPart = pMASK.substr(nI, 1); // get a single character of the data mask
	if (pMASKPARTS.indexOf(cMaskPart) > -1) // if the current character of the mask is a mask designator
		{
		if (oMaskParts["Designators"].indexOf(cMaskPart) == -1)
			{
			oMaskParts["Designators"] = ListAppend(oMaskParts["Designators"], cMaskPart, ","); // append the designator to the list of parts in the mask
			}
		//endif
		oMaskParts[cMaskPart]["Part"] += cMaskPart; // add the mask part character to the object
		oMaskParts[cMaskPart]["Order"] = oMaskParts[cMaskPart]["Order"] == -1 ? nJ++ : oMaskParts[cMaskPart]["Order"]; // set the mask order
		}
	//endif
	}
//next

cDataPart = "";
nIStop = cDataString.length;

// get the numeric parts of the data element and put them in aDataParts
for (nI = 0; nI < nIStop; nI++)
	{
	cStr = pDATA.substr(nI, 1); // a string to hold a single character of the data
	if (eDigits.test(cStr)) // if the current character of the data is a digit
		{
		cDataPart += cStr;
		}
	else if (cDataPart.length > 0)
		{
		aDataParts.push(cDataPart);
		cDataPart = "";		
		}
	//endif
	}
//next

if (cDataPart.length > 0) // if the terminal character of pDATA was data and not a delimiter
	{
	aDataParts.push(cDataPart);
	}
//endif

aDesignators = oMaskParts["Designators"].split(",");
nIStop = aDesignators.length;
nJStop = aDataParts.length;

// populate oMaskParts
for (nI = 0; nI < nIStop; nI++)
	{
	if (nI < nJStop)
		{
		oMaskParts[aDesignators[nI]]["Data"] = aDataParts[oMaskParts[aDesignators[nI]]["Order"]];
		}
	//endif
//alert('oMaskParts["Designators"] = ' + oMaskParts["Designators"]);
//alert('aDesignators[' + nI + '] = ' + aDesignators[nI] + '  nIStop = ' + nIStop);
//alert('oMaskParts[aDesignators[' + nI + ']]["Part"] = ' + oMaskParts[aDesignators[nI]]["Part"]);
//alert('oMaskParts[aDesignators[' + nI + ']]["Data"] = ' + oMaskParts[aDesignators[nI]]["Data"]);
//alert('oMaskParts[aDesignators[' + nI + ']]["Order"] = ' + oMaskParts[aDesignators[nI]]["Order"]);
	}
//next

return oMaskParts;
}

function GetParent(pOBJ, pPARENTTAGNAME)
{
var oParent = pOBJ;

while (oParent.tagName.toLowerCase() != pPARENTTAGNAME.toLowerCase())
	{
	oParent = oParent.parentElement;
	}
//endwhile

return oParent;
}

function GetXmlHttpRequestPipe(pipeName)
{
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
	pipeName = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		pipeName = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		pipeName = false;
	}
}
@end @*/

if (typeof XMLHttpRequest!='undefined') 
	{
	pipeName = new XMLHttpRequest();
	}
//endif

return pipeName;
}

function GetXmlHttpRequest(pURL)
{
var cRetVal = "";
var oPipe = GetXmlHttpRequestPipe('oPipe');

oPipe.open('GET', pURL, false);
oPipe.onreadystatechange = function()
	{
	if (oPipe.readyState==4)
		{
		cRetVal = oPipe.responseText;
		}
	//endif
	}
oPipe.send(null);

return cRetVal;
}

function IsEmpty(pPARAM)
{
var cObjType;
var lRetVal = true;
var nI, nIStop;

if (typeof(pPARAM) != "object")
	{
	lRetVal = AllTrim(pPARAM.toString()).length == 0;
	}
else
	{
	cObjType = pPARAM.tagName ? pPARAM.tagName.toLowerCase() : "radio"; // the tagName of a radio button is null in i.e.
	cObjType = cObjType == "input" && pPARAM.type.toLowerCase() == "checkbox" ? "checkbox" : cObjType;
	
	switch (cObjType)
		{
	
		case "checkbox": // Checkbox
		lRetVal = !pPARAM.checked;
			break;
		//endcase

		case "input": // File, Hidden, Password, Text
			lRetVal = AllTrim(pPARAM.value).length == 0;
			break;
		//endcase
		
		case "radio": // Radio
			nIStop = pPARAM.length;
			
			for (nI = 0; nI < nIStop; nI++)
				{
				lRetVal = !pPARAM[nI].checked;
				if (!lRetVal)
					{
					break;
		}
	//endif
	}
			//next

			break;
		//endcase
	
		case "select": // Select, Select-multiple
			lRetVal = pPARAM.selectedIndex < 0 || AllTrim(pPARAM[pPARAM.selectedIndex].value).length == 0;
			break;
		//endcase
	
		case "textarea": // Textarea
			lRetVal = AllTrim(pPARAM.value).length == 0;
			break;
		//endcase
	
		}
	//endswitch
		
	}
//endif

return lRetVal;
}

function IsLeapYear(pYEAR)
{
var lRetVal;

lRetVal = (pYEAR % 4) == 0 && ((pYEAR % 100) != 0 || (pYEAR % 400) == 0);

return lRetVal;
}

function ListAppend(pLIST, pITEM, pDELIMITER)
{
var cDelimiter = arguments.length == 3 ? pDELIMITER : ","; // Default the delimiter to a comma
pLIST += pLIST != "" ? cDelimiter : ""; // If the list is not empty, append the delimter
pLIST += pITEM; // Append the item to the list
	
return pLIST;
}

function NumberFormat(pNUM, pDECS)
{
var nPos;
var nPower = Math.pow(10, pDECS); // compute the power of ten to raise the number to
var nRetVal = pNUM = Math.round(parseFloat(pNUM) * nPower) / nPower; // raise the number, round it to the nearest integer, then divide it back to get the desired number of decimals
var	cRetVal = nRetVal.toString(); // convert the number to a string to manipulate the format

nPos = cRetVal.indexOf(".");
if (nPos == 0)
	{
	cRetVal = "0" + cRetVal; // add a leading 0 if the number is less than 0.
	}
else if (nPos == -1)
	{
	cRetVal += "."; // add a trailing decimal point if the number is an integer.
	}
//endif

nPos = cRetVal.indexOf(".") + 1;

while (nPos > (cRetVal.length - pDECS))
	{
	cRetVal += "0";
  }
//endwhile

return cRetVal;
}

function PadLeft(pPADVAL, pPADCHR, pPADLEN)
// Pads left any string with a substring
// pPADVAL: string
// pPADCHR: substring
// pPADLEN: number of copies of the substring
// Returns the new left-padded string
{
var cRetVal = "";
var nI;

for (nI = 0; nI < pPADLEN; nI++)
	{
	cRetVal += pPADCHR;
	}
//next

cRetVal += pPADVAL;
nI = cRetVal.length - pPADLEN;
cRetVal = cRetVal.substr(nI);

return cRetVal;
}

function PopulateSelectBox(pTGTID, pARRAY, pTOPVALUE, pTOPTEXT, pVALUE)
{
var nI;
var nIStop = pARRAY.length;
var oOpt;
var oTgt = document.getElementById(pTGTID);

oTgt.options.length = 0;
if (pTOPVALUE || pTOPTEXT)
	{
	oOpt = new Option
	oOpt.text = pTOPTEXT;
	oOpt.value = pTOPVALUE;
	oTgt.add(oOpt);
	if (pVALUE)
		{
		oOpt.selected = pVALUE == pTOPVALUE;
		}
	//endif
	}
//endif

for (nI = 0; nI < nIStop; nI++)
	{
	oOpt = new Option
	oOpt.text = pARRAY[nI][1];
	oOpt.value = pARRAY[nI][0];
	oTgt.add(oOpt);
	if (pVALUE)
		{
		oOpt.selected = pVALUE == pARRAY[nI][0];
		}
	//endif
	}
//next

return
}

function PopulateSubordinateSelectBox(pTGTID, pOBJECTNAME, pSRCID, pTOPVALUE, pTOPTEXT, pVALUE)
{
var aArray = new Array();
var lGoOn;
var nI, nIStop, nJ, nJStop;
var oObj = eval(pOBJECTNAME);
var oSrc = document.getElementById(pSRCID);

if (oSrc.multiple) // if we are dealing with a multiple select, we want ALL the associated values from the source
	{
	lGoOn = oSrc.options[0].selected && (oSrc.options[0].value.toUpperCase() == "ALL" ||oSrc.options[0].text.toUpperCase() == '- ALL -') ;
	nIStop = oSrc.options.length;
	
	for (nI = 0; nI < nIStop; nI++)
		{
		if (lGoOn || oSrc.options[nI].selected) // if a source element is selected
			{
			if (oObj.hasOwnProperty(oSrc.options[nI].value)) // if it has subordiate elements
				{
				nJStop = oObj[oSrc.options[nI].value].length;
				
				for (nJ = 0; nJ < nJStop; nJ++)
					{
					aArray.push(oObj[oSrc.options[nI].value][nJ]); // add the subordinate elements to the array
					}
				//next

				}
			//endif
			}
		//endif
		}
	//next

	nIStop = aArray.length;

	for (nJ = 0; nJ < 2; nJ++)
		{

		for (nI = 0; nI < nIStop; nI++)
			{
			aArray[nI].reverse(); // reverse each sub-array so we can sort the array by text not value and then reverse it again to set it back
			}
		//next
		
		if (nJ == 0)
			{
			aArray.sort(); // sort the array
			}
		//endif
		}
	//next
	
	}
else
	{
	if (oObj.hasOwnProperty(oSrc.value))
		{
		aArray = oObj[oSrc.value];
		}
	//endif
	}
//endif

PopulateSelectBox(pTGTID, aArray, pTOPVALUE, pTOPTEXT, pVALUE);

return
}

function Right(pSTR, pLEN)
{
var cRetVal = "";
var cStr = pSTR.toString();
var nLen = cStr.length;

if (pLEN > 0)
	{
	cRetVal = pLEN > nLen ? cStr : cStr.substring(nLen, nLen - pLEN);
	}
//endif

return cRetVal;
}

function SetGrayBar(pTABLE, pCLASS1, pCLASS2)
{
var nI;
var nIStop = pTABLE.rows.length;
var nJ = 0;
var oRow;

for (nI = 0; nI < nIStop; nI++)
	{
	oRow = pTABLE.rows[nI];
	if (oRow.style.display == "" && oRow.cells[0].innerHTML != "&nbsp;" && oRow.cells[0].innerHTML != "")
		{
		nJ++;
		oRow.className = nJ % 2 == 0 ? pCLASS2 : pCLASS1;
		}
	//endif
	}
//next

return
}

function SetLookupRowBGColor(pOBJ)
{
var cEventType = event.type.toLowerCase();
var nI;
var nIStop = pOBJ.cells.length;

pOBJ.style.backgroundColor = cEventType == "mouseover" ? "#FF6633" : "#FFFFFF";

for (nI = 0; nI < nIStop; nI++)
	{
	pOBJ.cells[nI].style.color = cEventType == "mouseover" ? "#FFFFFF" : "#000000";
	}
//next

return
}

function ShowDialogBox(pLOOKUPID, pAPARAMS, pDEBUG)
{
var cFeatures = "";
var cStr;
var cUrl = "/Lookups/Lookup.cfm";
var nDebug = pDEBUG ? pDEBUG : 0;
var nI;
var nIStop = pAPARAMS.length;
var xWinVal;

cUrl += "?pLookupId=" + pLOOKUPID;
cUrl += "&szDebug=" + nDebug;

for (nI = 0; nI < nIStop; nI++)
	{
	cStr = "p" + PadLeft(nI + 1, "0", 2) + "=" + pAPARAMS[nI];
	cUrl = ListAppend(cUrl, cStr, "&");
	}
//next

if (nDebug == 0)
	{
	xWinVal = window.showModalDialog(cUrl, "SELookUps", "dialogHeight:600px; dialogWidth:600px; edge:Raised; center:Yes; help:No; status:No; resizable:No; scroll:No");
	}
else
	{
	window.open(cUrl, "", "dialogHeight:600px; dialogWidth:600px; edge:Raised; center:Yes; help:No; resizable:No; scroll:Yes; status:No;");
	}
//endif

return xWinVal;
}

function ToggleCheck(pOBJID, pMODE)
{
var nI, nIStop;
var oObj = document.getElementsByName(pOBJID);

nIStop = oObj.length;
	
for (nI = 0; nI < nIStop; nI++)
	{
	if (!oObj[nI].disabled)
		{
		if (pMODE == "All")
			{
			oObj[nI].checked = true;
			}
		else if (pMODE == "None")
			{
			oObj[nI].checked = false;
			}
		else if (pMODE == "Toggle")
			{
			oObj[nI].checked = !oObj[nI].checked;
			}
		//endif
		}
	//endif
	}
//next
	
return
}

function ToggleCheck(pOBJID, pMODE)
{
var nI, nIStop;
var oObj = document.getElementsByName(pOBJID);

nIStop = oObj.length;

for (nI = 0; nI < nIStop; nI++)
	{
	if (!oObj[nI].disabled)
		{
		if (pMODE == "All")
			{
			oObj[nI].checked = true;
			}
		else if (pMODE == "None")
			{
			oObj[nI].checked = false;
			}
		else if (pMODE == "Toggle")
			{
			oObj[nI].checked = !oObj[nI].checked;
			}
		//endif
		}
	//endif
	}
//next
	
return
}

function TransferListItem(pSRCID, pTGTID, pTRANSTYPE, pSELECTALL, pCOLOR)
{
/*  
	pSRCID (the "Source" list or text box) is the id of the text or list box containing the data 
		element(s) to be copied / moved.  This parameter can not be left blank.
	pTGTID (the "Target" list box) is the id of the listbox to which the data element(s) 
		of pSRCID will be copied / moved.  If this parameter is left blank and the value of the pTRANSTYPE 
		parameter is set to "Move", the data element(s) of pSRCID will simply be removed from pSRCID.  If this 
		parameter is left blank and the value of the pTRANSTYPE parameter is not set to "Move", the 
		function does nothing.
	pTRANSTYPE is a string literal that indicates whether or not the data element(s) of pSRCID will be 
		removed from pSRCID after they are added to pTGTID.  A value of "Move" for pTRANSTYPE will remove the 
		selected data element(s) from pSRCID, any other value (including a blank) will leave them in place.
	pSELECTALL is a string literal ("Y" or "N") that indicates whether or not ALL of the data element(s)
		of pSRCID will be added to pTGTID (if pSRCID.multiple is true).  A value of "Y" for pSELECTALL will add 
		all of the data element(s).  Any other value (including a blank) will be ignored.
	pCOLOR is a string literal that indicates what the style.color attribute of the option to be added 
		will be set to.
/*                                                                                                                                                                                                                                                          WARNING !!!!!
/*  Initial variable declarations */
var aDel = new Array(); // array to hold the elements to be deleted from the source listbox. 
var aRetVal = new Array(); // array to hold the data to be returned from this function 
var aTemp;
var aId = new Array(); // array to hold the id data from the selected elements in the source listbox. 
var aTxt = new Array(); // array to hold the text data from the selected elements in the source listbox. 
var aVal = new Array(); // array to hold the value data from the selected elements in the source listbox. 
var cMsgTxt = "";
var cSrcType;
var lAdded;
var lCopyAll = pSELECTALL && pSELECTALL.toUpperCase() == "Y";
var oOpt, oSrc, oTgt;
var nI, nIStop, nJ, nJStop;

/* Create a reference to the source object. */
oSrc = document.getElementById(pSRCID);
cSrcType = oSrc.type.toLowerCase();
cSrcType = cSrcType.indexOf("select") > -1 ? cSrcType : "text";
if (cSrcType == "text")
	{
	cMsgTxt = IsEmpty(oSrc) ? objMsgs["sourceTextBoxIsEmpty"] : "";
	}
else if (!lCopyAll)
	{
	cMsgTxt = oSrc.selectedIndex == -1 ? objMsgs["mustSelectItemFromList"] : "";
	}
//endif
if (cMsgTxt != "")
	{
	/* If there are no elements selected in the source listbox / the source textbox is empty. */
	alert(cMsgTxt);
	}
else
	{
	if (cSrcType == "text")
		{
		aId.push("");
		aTxt.push(oSrc.value);
		aVal.push(oSrc.value);
		if (pTRANSTYPE == "Move")
			{
			/* We want to remove the text from the source textbox. */
			oSrc.value = "";
			}
		//endif
		}
	else
		{
		if (lCopyAll || oSrc.multiple)
			{
			/* The source list box was a multiple select listbox or we want all of the items in the listbox. */
			nIStop = oSrc.options.length;

			for (nI = 0; nI < nIStop; nI++)
				{
				/* 
				Loop through the source list box, get the option value and option text of each 
				of the selected items and add it to the text and value arrays. 
				*/
				if (lCopyAll || oSrc.options[nI].selected)
					{
					aId.push(oSrc.options[nI].id);
					aTxt.push(oSrc.options[nI].text);
					aVal.push(oSrc.options[nI].value);

					if (pTRANSTYPE == "Move")
						{
						/* 
						We want to remove the selected item from the source listbox so add the index to remove to an array. 
						*/
						aDel.push(nI);
						}
					//endif
					}
				//endif
				}
			//next

			nIStop = aDel.length - 1;

			for (nI = nIStop; nI >= 0; nI--)
				{
				/* 
				Remove the selected item from the source listbox. Start from the bottom of the array 
				so we delete listbox options from the bottom up - that way and don't get any out of 
				bound errors
				*/
				oSrc.remove(aDel[nI]);
				}
			//next
			}
		else
			{
			/* 
			Get the option value and option text of the selected item and add it to the text and 
			value arrays. 
			*/
			nI = oSrc.selectedIndex;
			aId.push(oSrc.options[nI].id);
			aTxt.push(oSrc.options[nI].text);
			aVal.push(oSrc.options[nI].value);

			if (pTRANSTYPE == "Move")
				{
				/* We want to remove the selected item from the source listbox. */
				oSrc.remove(nI);
				}
			//endif
			}
		//endif
		}           
	//endif
	if (pTGTID != "")
		{
		/* 
		A target list box has been designated to receive the selected element(s) from the source listbox. 
		*/
		/* Create a reference to the target listbox object. */
		oTgt = document.getElementById(pTGTID);
		nIStop = aVal.length;

		for (nI = 0; nI < nIStop; nI++)
			{
			/* Loop through the element(s) to be added. */
			lAdded = false;
			nJStop = oTgt.options.length;
			oOpt = new Option;
			if (pCOLOR != null)
				{
				oOpt.style.color = pCOLOR;
				}
			//endif
			oOpt.id = aId[nI];
			oOpt.text = aTxt[nI];
			oOpt.value = aVal[nI];

			for (nJ = 0; nJ < nJStop; nJ++)
				{
				/* 
				Loop through the target listbox to insert the element(s) to be added in alphabetical 
				order by text value. 
				*/
				if (oOpt.text.toUpperCase() <= oTgt.options[nJ].text.toUpperCase())
					{
					oTgt.add(oOpt, nJ);
					lAdded = true;
					break; /* Exit the loop after adding the element for better performance. */
					}
				//endif                           
				}
			//next
			
			if (!lAdded)
				{
				/* 
				If we haven't added the element yet because it is alpabetically last on the target list, 
				add it now. 
				*/
				oTgt.add(oOpt);
				}
			//endif
			}
		//next

		}
	//endif
	}
//endif

nIStop = aVal.length;

for (nI = 0; nI < nIStop; nI++)
	{
	aTemp = new Array(aVal[nI], aTxt[nI]);
	aRetVal.push(aTemp);
	}
//next

return aRetVal;
}

function ValidateEmailAddress(pFIELD, pMSG)
{
var aErrMsg = new Array();
var aMsgParts = new Array("", "", "", "");
var aParts1, aParts2;
var aPatterns = new Array();
var cAddress = typeof(pFIELD) == "string" ? AllTrim(pFIELD) : AllTrim(pFIELD.value);
var cMsg = !pMSG || pMSG == "" ? objMsgs["email"] : pMSG + " " + objMsgs["spaceEmail"];
var cRetVal = "";
var cStr = ""; 
var nI, nIStop, nJ, nJStop;

aPatterns.push("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\.-_?");
aPatterns.push("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\.-_?");
aPatterns.push("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\.-");
aPatterns.push("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");

aParts1 = cAddress.split("@");

cRetVal += aParts1.length < 2 ? cMsg + " " + objMsgs["addressMustContainATsymbol"] + "\n" : "";
cRetVal += aParts1.length > 2 ? cMsg + " " + objMsgs["addressOnlyContainOneATsymbol"] + "\n" : "";

if (cRetVal == "")
	{
	aMsgParts[0] = aParts1[0];
	aParts2 = aParts1[1].split(".");
	cRetVal += aParts2.length < 1 ? cMsg + " " + objMsgs["addressMustContainOnePERIOD"] + "\n" : "";
	}
//endif
if (cRetVal == "")
	{
	cRetVal += cAddress.indexOf(".@") > 0 ? cMsg + " " + objMsgs["addressNotHavePERIODrightBeforeATsymbol"] + "\n" : "";
	cRetVal += cAddress.indexOf("@.") > 0 ? cMsg + " " + objMsgs["addressNotHavePERIODrightAfterATsymbol"] + "\n" : "";
	cRetVal += cAddress.indexOf("..") > 0 ? cMsg  + " " + objMsgs["addressCannotContainPERIODrightAfterPERIOD"] + "\n" : "";
	}
//endif
if (cRetVal == "")
	{
	nIStop = aParts2.length - 1;
	
	for (nI = 0; nI <= nIStop; nI++)
		{
		if (nI == nIStop)
			{
			aMsgParts[3] = aParts2[nI];
			}
		else if (nI == nIStop - 1)
			{
			aMsgParts[2] = aParts2[nI];
			}
		else
			{
			aMsgParts[1] += aParts2[nI];
			}
		//endif
		}
	//next
	
	cRetVal += aMsgParts[3].length < 2 ? cMsg  + " " + objMsgs["addressContainTwoLetterAfterFinalPERIOD"] + "\n" : "";
	}
//endif

aErrMsg.push(" " + objMsgs["priorToATsymbol"] + "\n");
if (aMsgParts[1] == "")
	{
	aErrMsg.push("");
	aErrMsg.push(" " + objMsgs["betweenATandPERIOD"] + "\n");
	aErrMsg.push(" " + objMsgs["afterPERIOD"] + "\n");
	}
else
	{
	aErrMsg.push(" " + objMsgs["betweenATandSecondToLastPERIOD"] + "\n");
	aErrMsg.push(" " + objMsgs["betweenSecondToLastPERIODandLastPERIOD"] + "\n");
	aErrMsg.push(" " + objMsgs["afterLastPERIOD"] + "\n");
	}
//endif

if (cRetVal == "")
	{
	nIStop = aPatterns.length;
	
	for (nI = 0; nI < nIStop; nI++)
		{
		nJStop = aMsgParts[nI].length;
		
		for (nJ = 0; nJ < nJStop; nJ++)
			{
			cStr = aMsgParts[nI].substr(nJ, 1);
			if (aPatterns[nI].indexOf(cStr) == -1)
				{
				cStr = cStr == " " ? objMsgs["space"] : "'" + cStr + "'";
				cRetVal += cMsg + " " + objMsgs["addressMayNotContain"] + " " + cStr + aErrMsg[nI];
				}
			//endif						
			}
		//next

		}
	//next
	
	}
//endif

return cRetVal
}

function ValidateFormat (pFIELD, pMASK, pMSG) 
{

if (pFIELD.value.match(pMASK) == null) 
	{
	pMSG = objMsgs["enterDataInFollowingFormat"] + pMSG ;
	if (pFIELD.value != "")
		{
		alert(pMSG);
		pFIELD.value = "";
		pFIELD.focus();
		}
	//endif
	}
//endif

return
}

function ValidateNumber(pFIELD, pMINOPERATOR, pMIN, pMAXOPERATOR, pMAX) 
{
var cMsgTxt = "";
var cStr;
var lBadChars;
var nVal;

if (typeof(pFIELD) == "string")
	{
	cStr = AllTrim(pFIELD.replace(",", ""));
	nVal = parseFloat(cStr);
	cStr = cStr.replace(".", "");
	lBadChars = cStr.match(/\D/) != null;
	}
else
	{
	cStr = AllTrim(pFIELD.value.replace(",", ""));
	nVal = parseFloat(cStr);
	cStr = cStr.replace(".", "");
	lBadChars = cStr.match(/\D/) != null;
	}
//endif
if (isNaN(nVal) || lBadChars) // see if the field contains a valid number
	{
	cMsgTxt = "NAN"; // the field does not contain a valid number
	}
else 
	{
	if (!isNaN(pMIN)) // if the pMIN param is a valid number, check to see if the field value is less than pMIN
		{
		cMsgTxt += (pMINOPERATOR == "GTE" && nVal < pMIN) || (pMINOPERATOR == "GT" && nVal <= pMIN) ? "MIN" : ""; // the field value is less than pMIN
		}
	//endif
	if (!isNaN(pMAX)) // if the pMAX param is a valid number, check to see if the field value is greater than pMAX
		{
		cMsgTxt += (pMAXOPERATOR == "LTE" && nVal > pMAX) || (pMAXOPERATOR == "LT" && nVal >= pMAX) ? "MAX" : ""; // the field value is greater than pMAX
		}
	//endif
	}
//endif

return cMsgTxt;
}

function NewWindow(url,winname,w,h,winprop)
{
	// set width/height if blank or larger than screen size
	w = configureWidth(w);
	h = configureHeight(h);
	// center window
	l = (screen.availWidth) ? (screen.availWidth-w)/2 : 0;
	t = (screen.availHeight) ? (screen.availHeight-h)/2 : 0;
	
	if (winname.length > 0)
		varname = winname;
	else
		varname = "newwindow";
		
	if (winprop != null) winprop = "," + winprop;

	eval(varname+" = window.open('" + url + "', '" + winname + "', 'width=" + w + ", height=" + h + ", top=" + t + ", left=" + l + winprop + "');");
}

function configureWidth(w)
{
	var defaultWidth = 800;
	if (w.length == 0 || w < 0)	// if no width was supplied
	{
		if (screen.availWidth <= defaultWidth)	// if screen size if less than default width
			return screen.availWidth - 100;
		else
			return defaultWidth;
	}
	else if (w > screen.availWidth)	// if supplied width greater than screen size
		return screen.availWidth - 100;
	else
		return w;	// return supplied width
}

function configureHeight(h)
{
	var defaultHeight = 600;
	if (h.length == 0 || h < 0)	// if no height was supplied
	{
		if (screen.availHeight <= defaultHeight)	// if screen size if less than default width
			return screen.availHeight - 100;
		else
			return defaultHeight;
	}
	else if (h > screen.availHeight)	// if supplied width greater than screen size
		return screen.availHeight - 100;
	else
		return h;	// return supplied width
}


function SelectCboValue(pFIELD, pINDEX)
{
	var oCbo = typeof(pFIELD) == "string" ? document.getElementById(AllTrim(pFIELD)) : pFIELD;
	var aValues = pINDEX.split();
	var nI, nJ;
	oCbo.selectedIndex = -1;
	for (nI = 0;nI < oCbo.options.length; nI++)
	{
		for (nJ = 0; nJ < aValues.length; nJ++)
		{
			oCbo.options[nI].selected = oCbo.options[nI].value == aValues[nJ];
		}
	}
}

