// Global for brower version branching.
var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4))
var undefined;

// One object tracks the current modal dialog opened from this window.
var dialogWin    = new Object()
//var sClsBtn      = '<INPUT TYPE="button" id="btnCls" name="btnCls" VALUE="Close"  class="cRegButtons" onClick="parent.jsCloseCancel()">&nbsp;';
//var sPrtBtn      = '<INPUT TYPE="button" id="btnPrint" name="btnPrint" VALUE="Print" class="cRegButtons" onClick="parent.dlogBody.focus();parent.dlogBody.print()" >&nbsp;';
//var sOKBtn       = '<INPUT TYPE="button" id="btnOK"  name="btnOK"  VALUE="&nbsp;&nbsp;OK&nbsp;&nbsp;" class="cRegButtons" onClick="top.dlogBody.jsCloseMe()" >&nbsp;';  //parent.jsCloseOK()
var sClsBtn      = '<a href="javascript:parent.jsCloseCancel();" title="Close"><img src="images/button_close.gif" alt="Close" border="0"></a>&nbsp;';
var sPrntBtn     = '<a href="javascript:parent.dlogBody.focus();javascript:parent.dlogBody.print();" title="Print"><img src="images/button_print.gif" alt="Print" border="0"></a>&nbsp;';
var sOKBtn       = '<input type="button" id="btnOK"  name="btnOK"  VALUE="&nbsp;&nbsp;OK&nbsp;&nbsp;" class="cRegButtons" onClick="top.dlogBody.jsCloseMe()" >&nbsp;';  //parent.jsCloseOK()
var sSubBtn      = '<INPUT TYPE="button" id="btnSub" name="btnSub" VALUE="Submit" class="cRegButtons" onClick="top.dlogBody.jsCloseMe()" >&nbsp;';  //parent.jsCloseOK()
var sSavBtn      = '<INPUT TYPE="button" id="btnSav" name="btnSav" VALUE="Save"   class="cRegButtons" onClick="top.dlogBody.jsCloseMe()" >&nbsp;';  //parent.jsCloseOK()
var sNoBtn       = '<INPUT TYPE="button" id="btnNo"  name="btnNo"  VALUE="No"  class="cRegButtons" onClick="parent.jsCloseCancel()">&nbsp;';
var sYesBtn      = '<INPUT TYPE="button" id="btnYes" name="btnYes" VALUE="Yes" class="cRegButtons" onClick="top.dlogBody.jsCloseMe()" >&nbsp;';
var sDefArgs     = jsSetParamStr("OpenStr", "?", sKeySep, sValSep);
sDefArgs        += jsSetParamStr("PairSep", "=", sKeySep, sValSep);
sDefArgs        += jsSetParamStr("GroupSep", "&", sKeySep, sValSep);
var sDefAttrs    = ",resizable=yes";

//Generic dialog window opener
function jsOpenDialogWin(sContentURL, sWinTitle, oRetFunc, sBtnHTML, nWidth, nHeight, sScreenLoc, sWinAttrs, oDefFunc)
{
	var sURL        = "dialogFS.aspx";
	if (sWinTitle  != undefined) sURL      += "?windowname=" + sWinTitle;
	if (nWidth     == undefined) nWidth     = 550;
	if (nHeight    == undefined) nHeight    = 250;
	if (oRetFunc   == undefined) oRetFunc   = jsReturnDialog;
	if (sScreenLoc == undefined) sScreenLoc = "center";
	if (sWinAttrs  == undefined) sAttrs     = ""; //" resizable";
	sContentHTML    = "";
	var sButtonHTML = "";
	sButtonHTML    += '<SPAN style="width:100%;" class="cDataEntryR" >';
	if (sBtnHTML   == undefined) {
		sButtonHTML  += '<INPUT TYPE="button" id="btnOK"  name="btnOK"  class="cRegButtons" VALUE="&nbsp;&nbsp;OK&nbsp;&nbsp;" onClick="top.dlogBody.jsCloseMe()" >&nbsp;';  //parent.jsCloseOK()
		sButtonHTML  += '<INPUT TYPE="button" id="btnCls" name="btnCls" class="cRegButtons" VALUE="Close" onClick="parent.jsCloseCancel()">&nbsp;';
	} else {
		sButtonHTML  += sBtnHTML;
	}
	sButtonHTML    += '</SPAN>';
	var sArgs       = jsSetParamStr("OpenStr", "?", sKeySep, sValSep);
	sArgs          += jsSetParamStr("PairSep", "=", sKeySep, sValSep);
	sArgs          += jsSetParamStr("GroupSep", "&", sKeySep, sValSep);
	jsOpenDialog(sURL,nWidth,nHeight,oRetFunc,sContentHTML,sContentURL,sButtonHTML,sArgs,sScreenLoc,sWinAttrs,oDefFunc);
} //jsOpenDialogWin

function jsReturnDialog() {
	var sRetVal  = dialogWin.returnedValue.substr(1);
	var sReturn  = "";
	var sTmpInr  = String.fromCharCode(61); //special separator used by modaldialog window instead of sKeySep
	var sTmpOutr = String.fromCharCode(38); //special separator used by modaldialog window instead of sValSep
	if(sRetVal!=null && sRetVal != ""){
	}
} //jsReturnDialog

function jsRetNoRefresh() {
} //jsRetNoRefresh

function jsRetRefresh() {
	window.setTimeout("jsSubmit()", 1000);  //delay calling (commonfunction.js)jsSubmit() for 1 second
}// jsRetRefresh


// Generate a modal dialog.
// Parameters:
//    url -- URL of the page/frameset to be loaded into dialog
//    width -- pixel width of the dialog window
//    height -- pixel height of the dialog window
//    returnFunc -- reference to the function (on this page)
//                  that is to act on the data returned from the dialog
//    contentHTML -- [optional] content for dialog window
//    contentURL  -- [optional] URL for content section of dialog window
//    buttonHTML  -- [optional] HTML for dialog window buttons
//    args -- [optional] any data you need to pass to the dialog
//    screenLoc -- [optional] position on screen for window
//    sWinAttrs -- [optional] Screen attributes other than position, height, & width
//    defaultFunc - [optional] reference to function with default behavior
function jsOpenDialog(url, width, height, returnFunc, contentHTML, contentURL, buttonHTML, args, screenLoc, sWinAttrs, defaultFunc) {
  if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {
    // Initialize properties of the modal dialog object.
    dialogWin.returnFunc    = returnFunc
    dialogWin.defaultFunc   = defaultFunc
    dialogWin.returnedValue = ""
    dialogWin.contentHTML   = contentHTML
    dialogWin.contentURL    = contentURL
    dialogWin.buttonHTML    = buttonHTML
    dialogWin.args          = args
    dialogWin.url           = url
    dialogWin.width         = width
    dialogWin.height        = height
    dialogWin.name          = (new Date()).getSeconds().toString(); //create unique name

    if (screenLoc == "" || screenLoc == undefined) screenLoc = "center";
    screenLoc = screenLoc.toLowerCase();
    switch (screenLoc) {
			case "ul":
				dialogWin.left = 5;
				dialogWin.top  = 5;
			break;
			case "um":
			  dialogWin.left = Nav4? window.screenX + ((window.outerWidth - dialogWin.width) / 2): ((screen.width - dialogWin.width) / 2);
			  dialogWin.top  = 5;
			break;
			case "ur":
				dialogWin.left = Nav4? window.screenX + (window.outerWidth - dialogWin.width) : (screen.width - dialogWin.width);
				dialogWin.left -= 9;
				dialogWin.top  = 5;
			break;
			case "cl":
				dialogWin.left = 5;
				dialogWin.top  = Nav4? window.screenY + ((window.outerHeight - dialogWin.height) / 2): ((screen.height - dialogWin.height) / 2);
			break;
			case "cr":
				dialogWin.left = Nav4? window.screenX + (window.outerWidth - dialogWin.width) : (screen.width - dialogWin.width);
				dialogWin.left -= 10;
				dialogWin.top  = Nav4? window.screenY + ((window.outerHeight - dialogWin.height) / 2): ((screen.height - dialogWin.height) / 2);
			break;
			case "ll":
				dialogWin.left  = 5;
				dialogWin.top   = Nav4? window.screenY + (window.outerHeight - dialogWin.height) : (screen.height - dialogWin.height);
				dialogWin.top  -= 56;
			break;
			case "lm":
				dialogWin.left = Nav4? dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2): ((screen.width - dialogWin.width) / 2);
				dialogWin.top  = Nav4? window.screenY + (window.outerHeight - dialogWin.height) : (screen.height - dialogWin.height);
				dialogWin.top  -= 56;
			break;
			case "lr":
				dialogWin.left = Nav4? window.screenX + (window.outerWidth - dialogWin.width) : (screen.width - dialogWin.width);
				dialogWin.left -= 9;
				dialogWin.top  = Nav4? window.screenY + (window.outerHeight - dialogWin.height) : (screen.height - dialogWin.height);
				dialogWin.top  -= 56;
			break;
			default: //case "center":
				dialogWin.left = Nav4? dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2): ((screen.width - dialogWin.width) / 2);
				dialogWin.top  = Nav4? window.screenY + ((window.outerHeight - dialogWin.height) / 2): ((screen.height - dialogWin.height) / 2);
				dialogWin.top  -= 50;
			break;
    } //switch
    dialogWin.left = parseInt(dialogWin.left);
    dialogWin.top  = parseInt(dialogWin.top);
    // Assemble window attributes and position the dialog.
    var lLbl = (Nav4)? "screenX=":  "left=";
    var tLbl = (Nav4)? ",screenY=": ",top=";
    dialogWin.attr = lLbl + dialogWin.left + tLbl + dialogWin.top + ",width=" + dialogWin.width + ",height="  + dialogWin.height;
    if (sWinAttrs != undefined && sWinAttrs != "") {
			if (sWinAttrs.substr(0,1) != ',') dialogWin.attr += ',';
			dialogWin.attr += sWinAttrs;
    } else {
			dialogWin.attr += ",resizable=no";
    }
    // Generate the dialog and make sure it has focus.
    dialogWin.win=window.open(dialogWin.url, dialogWin.name, dialogWin.attr)
    dialogWin.win.focus()
  } else {
    dialogWin.win.focus()
  }
	//Hide the busyBox if necessary
	if (busyBox != null) { window.setTimeout(function(){busyBox.Hide()}, 500); }
}

// Event handler to inhibit Navigator form element
// and IE link activity when dialog window is active.
function deadend() {
  if (dialogWin.win && !dialogWin.win.closed) {
    dialogWin.win.focus()
    return false
  }
}

// Since links in IE4 cannot be disabled, preserve
// IE link onclick event handlers while they're "disabled."
// Restore when re-enabling the main window.
var IELinkClicks

// Disable form elements and links in all frames for IE.
function disableForms() {
  IELinkClicks = new Array()
  for (var h = 0; h < frames.length; h++) {
    for (var i = 0; i < frames[h].document.forms.length; i++) {
      for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
        frames[h].document.forms[i].elements[j].disabled = true
      }
    }
    IELinkClicks[h] = new Array()
    for (i = 0; i < frames[h].document.links.length; i++) {
      IELinkClicks[h][i] = frames[h].document.links[i].onclick
      frames[h].document.links[i].onclick = deadend
    }
  }
}

// Restore IE form elements and links to normal behavior.
function enableForms() {
  for (var h = 0; h < frames.length; h++) {
    for (var i = 0; i < frames[h].document.forms.length; i++) {
      for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
        frames[h].document.forms[i].elements[j].disabled = false
      }
    }
    for (i = 0; i < frames[h].document.links.length; i++) {
      frames[h].document.links[i].onclick = IELinkClicks[h][i]
    }
  }
}

// Grab all Navigator events that might get through to form
// elements while dialog is open. For IE, disable form elements.
function blockEvents() {
  if (Nav4) {
    window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
    window.onclick = deadend
  } else {
    disableForms()
  }
  window.onfocus = checkModal
}
// As dialog closes, restore the main window's original
// event mechanisms.
function unblockEvents() {
  if (Nav4) {
    window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
    window.onclick = null
    window.onfocus = null
  } else {
    enableForms()
  }
}

// Invoked by onFocus event handler of EVERY frame,
// return focus to dialog window if it's open.
function checkModal() {
  if (dialogWin.win && !dialogWin.win.closed) {
    dialogWin.win.focus()
  }
}
//-----dialog content functions

// Generic function converts form element name-value pairs
// into a URL search string.
function jsParseReturn(form) {
  var sRetOpenStr;
  var sPairSep;
  var sGroupSep;

  if (top.opener && !top.opener.closed) {
    var sArgs       = top.opener.dialogWin.args;
    if ( sArgs == undefined ) {
      sArgs = "";
    }
    var sRetOpenStr = jsGetParamStr("OpenStr", sArgs, sKeySep, sValSep);
    var sPairSep    = jsGetParamStr("PairSep", sArgs, sKeySep, sValSep);
    var sGroupSep   = jsGetParamStr("GroupSep", sArgs, sKeySep, sValSep);

  }
  if (sRetOpenStr == "" || sRetOpenStr == undefined) sRetOpenStr = "?";
  if (sPairSep    == "" || sPairSep    == undefined) sPairSep    = "=";
  if (sGroupSep   == "" || sGroupSep   == undefined) sGroupSep   = "&";
  var sReturn = sRetOpenStr;
  var onePair;
  // Harvest values for each type of form element
  for (var i = 0; i < form.elements.length; i++) {
    if (sReturn != sRetOpenStr) sReturn += sGroupSep;
		if (form.elements[i].type == "text") {
      onePair  = escape(form.elements[i].name) + sPairSep;
      onePair += escape(form.elements[i].value);
    } else if (form.elements[i].type == "hidden" &&
			form.elements[i].name.substr(0,2) != "__")
    { //06/13/02 new option
      onePair  = escape(form.elements[i].name) + sPairSep;
	    onePair += escape(form.elements[i].value);
    } else if (form.elements[i].type.indexOf("select") != -1) {
			if (form.elements[i].selectedIndex > -1) {
				onePair  = escape(form.elements[i].name) + sPairSep;
				onePair += escape(form.elements[i].options[form.elements[i].selectedIndex].value);
			}
    } else if (form.elements[i].type == "radio") {
      onePair  = escape(form.elements[i].name) + sPairSep;
      onePair += escape(form.elements[i].checked);
    } else if (form.elements[i].type == "checkbox") {
      onePair  = escape(form.elements[i].name) + sPairSep;
      onePair += escape(form.elements[i].checked);
    } else continue
    sReturn += onePair; // + "&";
  }
  return sReturn
}  //jsParseReturn

function jsGetContent() {
  var sContent = "";
  if (top.opener && !top.opener.closed) {
    sContent = top.opener.dialogWin.contentHTML;
  }
  if (sContent == "") {
    sContent = "Sorry, browser passed no data to dialog window.";
  }
  return sContent;
} //jsGetContent

// Send gathered data to the dialog window object's returnedValue property
function jsTransferData() {
  if (top.opener && !top.opener.closed) {
    top.opener.dialogWin.returnedValue = jsParseReturn(document.dialogForm);
  }
} //jsTransferData

//-----frameset functions
function jsCloseWin() {
//  if ( typeof opener.dialogWin.defaultFunc != undefined) {
  //   opener.dialogWin.defaultFunc();
//   }
  top.window.close();
} //jsCloseWin()

// Handle click of OK button
function jsCloseOK() {
  if (top.opener && !top.opener.closed) {
    top.dlogBody.jsTransferData();
    if ( typeof top.opener.dialogWin.returnFunc != undefined) {
      top.opener.dialogWin.returnFunc();
    }
  } else {
    window.alert("You have closed the main window.\n\nNo action will be taken on the choices in this dialog box.");
  }
  jsCloseWin();
  return false;
} //jsCloseOK

// Handle click of Cancel button
function jsCloseCancel() {
  jsCloseWin();
  return false;
} //jsCloseCancel
  function jsGetFrameContent(sButtonHeight) {
  var sReturn = "";
  if (sButtonHeight == undefined) {
		nButtonHeight = 35;
	} else {
		nButtonHeight = sButtonHeight - 0;
	}
  sReturn    += '<FRAMESET FRAMEBORDER=no FRAMESPACING=0 ROWS="*,' + nButtonHeight + '" BORDER=0 ';
  sReturn    += 'onLoad="if (opener) opener.blockEvents()" onUnload="if (opener) opener.unblockEvents()">';
  sReturn    += '<FRAME NAME="dlogBody" ID="dlogBody"    SRC="';
  var sURL    = "";
  if (top.opener && !top.opener.closed)  sURL = top.opener.dialogWin.contentURL;
  if (sURL   == "" || sURL == undefined) sURL = "dialogContent.aspx";
  sReturn    +=  sURL + '" FRAMEBORDER=no>';
  sReturn    += '<FRAME NAME="dlogButtons" ID="dlogButtons" SRC="dialogButtons.aspx" FRAMEBORDER=no SCROLLING=no>';
  sReturn    += '</FRAMESET>';
  return sReturn;
} //jsGetFrameContent

/**
  * jsGetButtons returns an HTML string to make the button bar
  *
  * <br><br>
  * @author Robert E. Hoch <br>
  * @version January 26, 2002 <br>
  * @param   none<br>
  * @return  <B>sReturn</B> <I>String</I> HTML String to make the buttons for dialog window.<br>
  */
function jsGetButtons( ) {
  var sReturn = "";
  if (top.opener && !top.opener.closed) sReturn = top.opener.dialogWin.buttonHTML;
  if ( sReturn == "" || sReturn == undefined) {
		//default buttons
		sReturn  = '<SPAN style="width:100%; text-align:right; vertical-align:center;" >';
    sReturn += '<INPUT TYPE="button" VALUE="Cancel" onClick="parent.jsCloseCancel()">';
    sReturn += '&nbsp;';
    sReturn += '<INPUT TYPE="button" VALUE="&nbsp;&nbsp;OK&nbsp;&nbsp;" onClick="parent.jsCloseOK()">';
    sReturn += '&nbsp;';
    sReturn += '</SPAN>';
  }
  return sReturn;
}  // jsGetButtons

function jsSubmit(oForm) {
 if (typeof oForm == "object") {
		//jsSubmitForm(oForm);
		oForm.submit();
	} else {
		document.forms[0].submit();
	}
} //jsSubmit

function jsCloseMe() {
	parent.jsCloseOK();
 // jsSubmitWindow("Save");
 
}

function jsCloseDelete() {
  jsSubmitWindow("Delete");
} //jsCloseDelete

function jsSubmitWindow(sMode, nFormNum) {
	var oMode = jsGetObjectRef("hidPageMode");
	if (typeof oMode == "object") {
		oMode.value = sMode;
		var bOK = true;
		if (sMode.toLowerCase() == "delete"  || sMode.toLowerCase() == "inactivate") {
			bOK = window.confirm("Are you sure you want to delete this record?");
		} else if (sMode.toLowerCase() == "save") {
			bOK = jsValidate();
		}
		if (bOK) {
			var oForm = document.dialogForm;
			jsSubmit(oForm);
		}
	}
} //jsSubmitPopup
function jsValidate() {
	//shell function; return true if page validates; can be overwritten at the page level.
	return true;
}

function jsPopBodyLoad() {
	var oMode = jsGetObjectRef("hidPageMode");
	if (typeof oMode == "object") {
		if (oMode.value == "Close") { //jsCloseMe();
			parent.jsCloseOK();
		}
	}
} //jsBodyLoad
function jsStatusChanged() {
	jsSubmitWindow("save", 0);
} //jsStatusChanged
