﻿//////////////////////////////////////////////////////////////////
//    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	  arrivo scheduling assistant v8.0
//    Mark W. Robbins, Robbins Systems
//    Copyright 2009 by Robbins Systems LLC
//    All Rights Reserved
//    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//////////////////////////////////////////////////////////////////
var objHelpWnd=null;
var pageTopic = "";
var rootPath = "";
var browserName = "";
var dirty = false;
//~~~~Style Constants~~~~~~~~~~~
var defBorderDark	= "#7f7f7f";
var defBorderLight	= "#b0b0b0";
var gradientStart	= "#fff5cc";
var gradientEnd		= "#ffdb75";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function window_OnHelp()
{
	try
	{
		if (browserName == "ie")
		{
			event.returnValue = false;
			event.cancelBubble = true;
		}
    }
    catch(ex){ }
    OpenHelp(pageTopic);
}
function OpenHelp(sTopic)
{
	try	
	{
		if(objHelpWnd!=null)
			objHelpWnd.close;
		objHelpWnd=null;
	}
	catch(ex){ }
	var h=650;
	var w=850;
	if(screen.height<=600)
	{
		h=300;
		w=500;
	}
	else if(screen.height<=640)
	{
		h=480;
		w=700;
	}
	var t=10;
	var l  = (screen.width - (w+20));
	var strURL = "";
	var ary;
	if(sTopic.length<=0)
		strURL = rootPath + "/help/default.aspx";
	else
	{
		// If InStr(1, sTopic, "#", vbTextCompare)>0 Then
		if(sTopic.indexOf("#", 1)>0)
		{
			ary = sTopic.split("#");
			strURL = rootPath + "/help/default.aspx?theURL=html/" & ary[0] & ".htm&Ref=" & ary[1];
		}
		else
			strURL = rootPath + "/help/default.aspx?theURL=html/" + sTopic + ".htm";
	}
	strOptions = "height=" + h + ",width=" + w + ",top=" + t + ",left=" + l + ",scrollbars=yes,status=yes,resizable=yes,toolbar=no,menubar=no,location=no";
	objHelpWnd = window.open(strURL, "objHelpWnd", strOptions);
}
function getTimeSpan(startDateTime, endDateTime)
{
	var sRetVal = "";
	var dStart = new Date(startDateTime);
	var dEnd = new Date(endDateTime);
	if(dStart > dEnd)
	{
		sRetVal = null;
	}
	else
	{
		var msElapsed = (dEnd.getTime() - dStart.getTime());
		var one_hour = 1000*60*60;
		var one_minute = 1000*60;
		
		var hrElapsed = Math.floor( msElapsed / one_hour );
		var mnElapsed = Math.floor((msElapsed - (hrElapsed * one_hour)) / one_minute);
	
		sRetVal = hrElapsed + ":" + mnElapsed;
	}
	return sRetVal;
}
function BtnHilite(oCtl)
{
	if(oCtl.disabled)
		return;
	try
	{
			if (browserName == "ie")
			{
				oCtl.runtimeStyle.borderRightColor = defBorderDark;
				oCtl.runtimeStyle.borderBottomColor = defBorderDark;
				oCtl.runtimeStyle.borderLeftColor = defBorderLight;
				oCtl.runtimeStyle.borderTopColor = defBorderLight;
				var filterStr = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='" + gradientStart + "', EndColorStr='" + gradientEnd + "', enabled=true)";
				oCtl.runtimeStyle.filter = filterStr
			}
	}
	catch (ex) { }
}
function BtnRestore(oCtl)
{
	try
	{
		if (browserName == "ie")
			oCtl.runtimeStyle.cssText = "";
	}
	catch (ex) { }
}
function handlePostBack(ctl)
{
	__doPostBack(ctl.id, "");
}
function setVisibility(ctlID, bVisible)
{
	if(ElementExists(ctlID))
	{
		if(bVisible)
			document.getElementById(ctlID).style.display = "block";
		else
			document.getElementById(ctlID).style.display = "none";
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// BEGIN Change Event Handling Routines
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function clean()
{
	dirty = false;
}
function safeEncode(txtCtl)
{
	var sVal = txtCtl.value;
	txtCtl.value = sVal.replace(/</g, "").replace(/>/g, "");
}
function strictEncode(txtCtl)
{
	var sVal = txtCtl.value;
	sVal = sVal.replace(/</g, "").replace(/>/g, "");
	sVal = sVal.replace("?", "").replace(/>/g, "");
	sVal = sVal.replace("#", "").replace(/>/g, "");
	sVal = sVal.replace("&", "").replace(/>/g, "");
	txtCtl.value = sVal
}
function htmEncode(txtCtl)
{
	var sVal = txtCtl.value;
	txtCtl.value = sVal.replace(/</g, '{').replace(/>/g, '}');
}
function formatCurrencyTextbox(ctrl)
{
	ctrl.value = FormatAsCurrency(ctrl.value);
}
function formatIntegerTextbox(ctrl)
{
	ctrl.value = FormatAsInteger(ctrl.value);
}
function NumsOnly()
{
	// enforces numeric-only input in textboxes.
	var iKeyCode = event.keyCode;
	if ((iKeyCode >= 48 && iKeyCode <= 57) || (iKeyCode == 189))
	{
		// Keyboard Number keys allowed, but not if Shift is pressed
		if (window.event.shiftKey)
			window.event.returnValue = false;
		else
			return;
	}
	else if ((iKeyCode >= 96 && iKeyCode <= 105) || (iKeyCode == 109))
	{
		// Numeric keypad keys... allowed
		return;
	}
	else
	{
		// 37, 38, 39, 40
		switch (iKeyCode)
		{
			case 9:
			case 16:
			case 17:
			case 18:
			case 8:
			case 46:
			case 110:
			case 190:
			case 36:
			case 35:
				// tab, shift, ctrl, alt, backspc, del, del (keypad), home, end
				return;
				break;
			case 37:
			case 38:
			case 39:
			case 40:
				// cursor keys: left, up, right, down
				return;
				break;
			default:
				// no others are allowed.
				// Note that we allow the event to bubble
				// up to the document level for additional 
				// keystroke handling.
				window.event.returnValue = false;
				return;
		}
	}
}
function SetButton(obj, bDisabled)
{
	// Enables or Disables a BUTTON element
	// and changes the button's Image as appropriate.
	try
	{
		if (bDisabled == true) BtnRestore(obj);
		obj.disabled = bDisabled;
		if (obj.children.length > 0)
		{
			var srcStr = obj.firstChild.src;
			if (bDisabled == true)
			{
				// Disable the button
				if (srcStr.indexOf("_disabled.gif") < 0)
				{
					srcStr = srcStr.replace(".gif", "_disabled.gif");
					obj.firstChild.src = srcStr;
				}
			}
			else
			{
				// Activate the button
				if (srcStr.indexOf("_disabled.gif") > 0)
				{
					srcStr = srcStr.replace("_disabled.gif", ".gif");
					obj.firstChild.src = srcStr;
				}
			}
		}
	}
	catch (e) { }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// END Change Event Handling Routines
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// BEGIN General Utility Routines
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function PadNr(iNum, iLen)
{
	// Pads the numeric string with zeros to the specified length
	var sNum = MakeString(iNum);
	var iSpc = (MakeLong(iLen) - sNum.length);
	if(iSpc > 0)
	{
		for(indx=0; indx<iSpc; indx++)
		{
			sNum = ("0" + sNum);
		}
	}
	return sNum;
}
function trim(strVal)
{
	// trims leading and trailing whitespace
	var retVal = "";
	try
	{
		retVal = strVal.toString().replace(/(^\s*)|(\s*$)/g, "");
	}
	catch(ex) 
	{
		retVal = "";
	}
	return retVal;
}
function StripChars(strVal)
{
	var retVal = "";
	var schar = "";
	tmpVal = trim(strVal);
	for(indx=0; indx<tmpVal.length; indx++)
	{
		schar = tmpVal.substr(indx, 1);
		switch(schar)
		{
			case ".":
			case "-":
			case "0":
			case "1":
			case "2":
			case "3":
			case "4":
			case "5":
			case "6":
			case "7":
			case "8":
			case "9":
				retVal += schar;
				break;
			default:
				break;
		}
	}
	return(retVal);
}
function MakeLong(iVal)
{
	var iRetVal=0;
	try {
		if (!isNaN(parseInt(iVal)))
		{
			iRetVal = parseInt(iVal);
		}
	}
	catch(e) {
		iRetVal=0;
	}
	return iRetVal;
}
function FormatAsInteger(iVal)
{
	var iRetVal = 0;
	try
	{
		if (!isNaN(parseInt(iVal)))
		{
			iRetVal = parseInt(iVal);
		}
	}
	catch(e) {
		iRetVal = 0;
	}
	return iRetVal;
}
function FormatAsCurrency(iVal)
{
	var sRetVal="0.00";
	try {
		var sValue = "0";
		var sDecimal = "00";
		var ary = MakeString(iVal).split(".")
		if (ary.length > 0)
		{
			if (!isNaN(parseInt(ary[0])))
			{
				sValue = parseInt(ary[0]).toString();
			}
			
			if (ary.length > 1)
			{
				if (!isNaN(parseInt(ary[1])))
				{
					// if value is 1 char, pad it with a trailing zero,
					// if value is longer than 1 char, take only the first two chars,
					// otherwise the value is 2 chars long, and we take it as-is.
					sDecimal = ary[1];
					if (sDecimal.length == 1)
						sDecimal = sDecimal + "0";
					else if (sDecimal.length > 2)
						sDecimal = sDecimal.substr(0, 2);
				}
			}
		}
		sRetVal = sValue + "." + sDecimal;
	}
	catch(e) {
		sRetVal="0.00";
	}
	return sRetVal;
}
function MakeString(strInput)
{
	var sRetVal="";
	try {
		sRetVal = strInput.toString();
		}
	catch(e) {
		sRetVal="";
	}
	return sRetVal;
}
function BooleanAsInt(iVal)
{
    var retVal = 0;
    if (MakeBoolean(iVal))
        retVal = 1;
    return retVal;
}
function MakeBoolean(iVal)
{
	var bRetVal=false;
	try {
		var sTmp = MakeString(iVal).toLowerCase();
		if (sTmp.length > 0)
		{
			if (!isNaN(parseInt(sTmp)))
			{
				if (parseInt(sTmp)!=0)
					bRetVal=true;
			}
			else
			{
				if ((sTmp=="true") || (sTmp=="y") || (sTmp=="yes"))
					bRetVal=true;
			}
		}
	}
	catch(e) {
		bRetVal=false;
	}
	return bRetVal;
}
function IsDisabled(ctl)
{
	var bRetVal = false;
	try
	{
		bRetVal = ctl.disabled;
	}
	catch (ex) { }
	return bRetVal;
}
function ElementExists(elementID)
{
	var bRetVal=false;
	var sTag="";
	try {
		sTag = document.getElementById(elementID).tagName
		if (sTag.length > 0)
			bRetVal=true;
	}
	catch(e) {
		bRetVal=false;
	}
	return bRetVal;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// END General Utility Routines
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// BEGIN Element Positioning Routines
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function PopupCoords(left, top)
{
	this.left = left;
	this.top = top;
}
function CalcPopupCoords(el, objPopupCoords)
{
	var iDiff=0;
	GetLeftTop(el, objPopupCoords);
	iDiff = (window.event.clientX - objPopupCoords.left);
	objPopupCoords.left = (window.event.screenX - iDiff) - document.body.scrollLeft;
	iDiff = (window.event.clientY - objPopupCoords.top);
	objPopupCoords.top  = ((window.event.screenY - iDiff) + el.offsetHeight) - document.body.scrollTop;
}
function CalcPopupCoords_ScollPanel(objScrollPanel, el, objPopupCoords)
{
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Calculates the coordinates necessary 
	// to left-align a popup with the element
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	GetLeftTop(el, objPopupCoords);
	var iDiff = (window.event.clientX - objPopupCoords.left);
	objPopupCoords.left = (window.event.screenX - iDiff) - document.body.scrollLeft;
	iDiff = (window.event.clientY - objPopupCoords.top);
	objPopupCoords.top  = (((window.event.screenY - iDiff) + el.offsetHeight) - document.body.scrollTop) - objScrollPanel.scrollTop;
}
function GetLeftTop(AnObject, objPopupCoords)
{
	try {
		var oParent=null;
		objPopupCoords.left = AnObject.offsetLeft;
		objPopupCoords.top = AnObject.offsetTop;
		oParent = AnObject.offsetParent;
		while (oParent!=null)
		{
			objPopupCoords.left += oParent.offsetLeft;
			objPopupCoords.top += oParent.offsetTop;
			oParent = oParent.offsetParent;
		}
	}
	catch(e) {
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// END Element Positioning Routines
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// BEGIN Combobox Handling Routines
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function SetComboIndex(id, cboCtl)
{
	var opt;
	try {
		var val = MakeString(id).toLowerCase();
		for (indx=0; indx<cboCtl.options.length; indx++)
		{
			opt = cboCtl.options[indx];
			if (MakeString(opt.value).toLowerCase() == val)
			{
				opt.Selected = true;
				break;
			}
		}
	}
	catch(e) {
	}
}

function ClearAllOptions(ctl)
{
	var bRetVal=false;
	var el;
	try {
		for (indx=0; indx<ctl.options.length; indx++)
		{
			ctl.Remove(0);
		}
		bRetVal = (ctl.options.length=0) ? true : false;
	}
	catch(e) {
		bRetVal=false;
	}
	return bRetVal;
}
function AddOption(sTxt, sVal, ctl)
{
	try {
		var el = document.createElement("option");
		el.innerText = sTxt;
		el.value = sVal;
		ctl.appendChild(el);
		return el;
	}
	catch(e) {
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// BEGIN Combobox Handling Routines
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

