// Cheap browser sniffing.
var ua = navigator.userAgent.toLowerCase();
var ns4 = (document.layers)?true:false;
var opera = (ua.indexOf("opera") != -1);
var ie4 = (document.all && !document.getElementById);
var dom = (!ie4 && !opera && document.getElementById);
var gecko = (ua.indexOf("gecko") != -1);
var safari = (ua.indexOf("safari") != -1);
// Default JavaScript library.
function JT_formEnterButton(f,e,bn)
{
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13 && f != null){
	if (window.event) window.event.keyCode = 0;
	var theButton = eval("f." + bn);
	if (theButton != null)
	    theButton.click();
	return false;
    }else{
	return true;
    }
}
function JT_print(url)
{
    if ((typeof sg_printURL == "string")){
	if (sg_printURL.length > 0){
	    JT_openWindow(sg_printURL, 'print');
	}else{
	    alert('This page is not available in a printer friendly version.');
	}
	return;
    }
    if (url == null || url.length == 0) url = location.href;
    if (url != null && url.length > 0){
	var pattern = 'home.do';
	var pos = url.indexOf(pattern);
	if (pos < 0) pattern = 'access.do'
	pos = url.indexOf(pattern);
	if (pos < 0) pattern = 'pick.do'
	pos = url.indexOf(pattern);
	if (pos < 0) pattern = 'print.do'
	pos = url.indexOf(pattern);
	var newUrl = "";
	if (pos >= 0){
	    newUrl = url.substring(0,pos) + "access.do" + url.substr(pos+pattern.length);
	    JT_openWindow(newUrl, 'print');
	    return;
	}
    }
    alert('This page is not available in a printer friendly version.');
}
function JT_preloadImage()
{
    if (document.images) {
	for(var i = 0; i < arguments.length; i++){
	    theImage = new Image();
	    theImage.src = arguments[i];
	}
    }
}
function JT_alert(prompt)
{
    if (prompt == "") prompt = "Be Alert! The world needs more lerts.";
    alert(prompt);
}
function JT_confirm(prompt)
{
    if (prompt == "") prompt = "Are you sure you wish to do this?";
    if (confirm(prompt))
	return true;
    else
	return false;
}
function JT_return()
{
    return true;
}
function JT_confirmURL(prompt, URL)
{
    if (prompt == "") prompt = "Are you sure you wish to do this?";
    if (confirm(prompt))
	document.location.replace(URL);
}
function JT_changeImage(id, url)
{
    if (document.images) {
	theImage = document.images[id];
	if (theImage) theImage.src = url;
    }
}
function JT_changeLayer(thelayer, s)
{
    if (thelayer == null || s == null) return;
    JT_hideLayer(thelayer);
    JT_setLayerContents(thelayer, s)
    JT_showLayer(thelayer);
}
function JT_userPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "user", JT_getValue(formName, inputName));
}
function JT_printPick(s)
{
    var pageUrl = s;
    if (s == null || s.length == 0) pageUrl = location.href;

    if (pageUrl != null && pageUrl.length > 0){
	if (pageUrl.indexOf('print.do') > 0 || pageUrl.indexOf('mail.do') > 0){
	    window.print();
	    return;
	}
	var pos = pageUrl.indexOf('home.do');
	var part2 = "";
	if (pos >= 0){
	    part2 = "" + pageUrl.substr(pos+7);
	    pageUrl = pageUrl.substring(0,pos) + "print.do";
	}else if (pageUrl.indexOf('index.jsp') > 0){
	    pos = pageUrl.indexOf('index.jsp');
	    part2 = "" + pageUrl.substr(pos+9);
	    pageUrl = pageUrl.substring(0,pos) + "print.do";
	}else if (pageUrl.indexOf('access.do') > 0){
	    pos = pageUrl.indexOf('access.do');
	    part2 = pageUrl.substr(pos+9);
	    pageUrl = pageUrl.substring(0,pos) + "print.do";
	}else{
	    pageUrl = '';
	}
	if (part2.length > 0){
	    if (part2.indexOf('cmd=button') < 0) pageUrl = pageUrl + part2;
	}
    }
    if (pageUrl.length > 0 ) {
	JT_openWindow(pageUrl, 'printPage');
       //var theValue = JT_urlEscape(pageUrl);
	//url = "pick.do?state=print&formName=&inputName=&value=" + theValue ;
	//var w = window.open(url, "printpicker", "width=530,height=420,scrollbars,resizable");
    }else{
	alert('This page is not available in a printer friendly version.');
    }
}
function JT_mailPick(s)
{
    if (s == null || s.length == 0 && (typeof sg_mailURL == "string")){
	if (sg_mailURL.length > 0){
	    s = sg_mailURL;
	}
    }
    var pageUrl = s;
    if (s == null || s.length == 0) pageUrl = location.href;

    if (pageUrl != null && pageUrl.length > 0){
	var newUrl = "";
	var pos = pageUrl.indexOf('home.do');
	var part2 = "";
	if (pos >= 0){
	    part2 =  pageUrl.substr(pos+7);
	    pageUrl = pageUrl.substring(0,pos) + "mail.do";

	}else if (pageUrl.indexOf('index.jsp') > 0){
	    pos = pageUrl.indexOf('index.jsp');
	    part2 = pageUrl.substr(pos+9);
	    pageUrl = pageUrl.substring(0,pos) + "mail.do";

	}else if (pageUrl.indexOf('print.do') >= 0){
	    pos = pageUrl.indexOf('print.do');
	    part2 = pageUrl.substr(pos+8);
	    pageUrl = pageUrl.substring(0,pos) + "mail.do";
	}else if (pageUrl.indexOf('access.do') >= 0){
	    pos = pageUrl.indexOf('access.do');
	    part2 = pageUrl.substr(pos+9);
	    pageUrl = pageUrl.substring(0,pos) + "mail.do";
	}else if (pageUrl.indexOf('mail.do') >= 0){
	    // Leave well enough alone.
	}else{
	    pageUrl = '';
	}
	if (part2.length > 0){
	    if (part2.indexOf('cmd=button') < 0) pageUrl = pageUrl + part2;
	}
    }
    if (pageUrl.length > 0 ) {
       var theValue = JT_urlEscape(pageUrl);
	url = "pick.do?state=mail&formName=&inputName=&value=" + theValue ;
	var w = window.open(url, "mailpicker", "width=620,height=520,scrollbars,resizable");
	return;
    }
    alert('This page may not be mailed.');
}
function JT_colorPick(formName, inputName)
{
   var theValue = JT_getValue(formName, inputName);
    url = "pick.do?state=color&formName=" + formName + "&inputName=" + inputName + "&value=" + JT_urlEscape(theValue) ;
    var w = window.open(url, "colorpicker", "width=530,height=420,scrollbars,resizable");
}
function JT_hebrewPick(formName, inputName)
{
   if (ns4) { alert("You browser does not support Hebrew"); return;}
   var theValue = JT_unicodeEscape(JT_getValue(formName, inputName));
    url = "pick.do?state=hebrew&formName=" + formName + "&inputName=" + inputName + "&value=" + JT_urlEscape(theValue) ;
    var w = window.open(url, "hebrewpicker", "width=620,height=420,scrollbars,resizable");
}
function JT_cssSysPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "appFile", JT_getValue(formName,inputName), "text/css");
}
function JT_sitePick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteFile", JT_getValue(formName,inputName), "");
}
function JT_dwtPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteFile", JT_getValue(formName,inputName), "dwt");
}
function JT_cssPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteFile", JT_getValue(formName,inputName), "text/css");
}
function JT_htmlPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteFile", JT_getValue(formName,inputName), "text/html");
}
function JT_jsPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteFile", JT_getValue(formName,inputName), "text/javascript");
}
function JT_swfPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteFile", JT_getValue(formName,inputName), "application/x-shockwave-flash");
}
function JT_jsSysPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "appFile", JT_getValue(formName,inputName), "text/javascript");
}
function JT_layoutPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteLayout", JT_getValue(formName,inputName), "image");
}
function JT_addressPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "address", JT_getValue(formName,inputName), "");
}
function JT_imagePick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteImage", JT_getValue(formName,inputName), "images");
}
function JT_appImagePick(formName, inputName)
{
    JT_openPicker(formName,inputName, "appImage", JT_getValue(formName,inputName), "images");
}
function JT_cimagePick(formName, inputName, cid)
{
    var theState = "contentImage";
    var cidArg = "";
    if (cid  != null && cid > 0)
	cidArg = "&cid=" + cid;
    var theValue = JT_getValue(formName,inputName);
    var theMT = "images";
    var url = "pick.do?state=" + theState + cidArg + "&formName=" + formName + "&inputName=" + inputName + "&value=" + JT_urlEscape(theValue) + "&mt=" + theMT;
    var w = window.open(url, theState + "picker", "width=620,height=400,scrollbars,resizable");
}
function JT_contentPick(formName, inputName)
{
    JT_openPicker(formName,inputName, "siteContent", JT_getValue(formName,inputName), "content");
}
function JT_pickFile(fileName)
{
    document.selectForm.selection.value = fileName;
}
function JT_donePicking()
{
    var selectedValue = document.selectForm.selection.value;
    var formName = document.selectForm.formName.value;
    var inputName = document.selectForm.inputName.value;
    JT_setValueInOpener(formName, inputName, selectedValue);
    window.returnValue = selectedValue;
    window.close();
    return false;
}
function JT_openWindow(url, name, height, width)
{
    var argString = "scrollbars,resizable";
    if (width > 0)
	argString = argString + ",width=" + width;
    if (height > 0)
	argString = argString + ",height=" + height;
    var w = window.open(url, name, argString);
}
var JT_unsafeURLChars = "\"<>%\\^[]`+$,;/?:@=&#";
var JT_hexArray = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
function JT_hex(x)
{
    var hexString = "";
    while(x >= 16){
	temp = x % 16;
	x = Math.floor(x/16);
	hexString = JT_hexArray[temp] + hexString;
    }
    hexString = JT_hexArray[x] + hexString;
    return hexString;
}
function JT_urlEscape(s)
{
    if (s == null) return "";
    var l = s.length;
    var newS = "";
    for (i = 0; i < l; i++){
	var ch = s.charAt(i);
	var chCode = s.charCodeAt(i);
	if (chCode > 32 && chCode < 132 && JT_unsafeURLChars.indexOf(ch) < 0){
	    newS += ch;
	}else{
	    newS = newS + "%" + JT_hex(chCode);
	}
    }
    return newS;
}
function JT_unicodeEscape(s){
    if (s == null) return "";
    var newS = "";
    var l = s.length;
    for(i = 0; i < l; i++){
	var ch = s.charAt(i);
	var chCode = s.charCodeAt(i);
	if (chCode > 255){
	    newS += "&#";
	    newS += "" + chCode;
	    newS += ";";
	}else if (chCode > 127){
	    newS += "&#";
	    newS += "" + chCode;
	    newS += ";";
	}else{
	    newS += ch;
	}
    }
    return newS;
}
function JT_openPicker(formName, inputName, type, theValue,  mimeType)
{
    url = "pick.do?state=" + type + "&formName=" + formName + "&inputName=" + inputName + "&value=" + JT_urlEscape(theValue) + "&mt=" + mimeType;
    var w = window.open(url, type + "picker", "width=620,height=400,scrollbars,resizable");
}
function JT_setValueInOpener(formName, inputName, theValue)
{
   if (formName && inputName){
       var theForm = window.opener.document.forms[formName];
       if (theForm) {
	   var theInput = theForm[inputName];
	   if (theInput){
	       theInput.value = theValue;
	   } 
       }
   }
}
function JT_getValue(formName, inputName)
{
   var theValue = "";
   var theForm = document.forms[formName];
   if (theForm) {
       var theInput = theForm[inputName];
       if (theInput){
	   theValue = theInput.value;
       } 
   }
   return theValue;
}
function JT_onLoad()
{
    if (typeof JT_pageInit == "function" ) JT_pageInit();
    if (typeof jsrsOnLoad == "function" ) jsrsOnLoad();
    if (typeof JT_imageLoad == "function" ) JT_imageLoad();
}
function JT_autoPrint()
{
    var pageUrl = location.href;
    if (pageUrl != null && pageUrl.length > 0){
	if (pageUrl.indexOf('print.do') > 0){
	    if (window.print) window.print();
	}
    }
}
////////////////////////////////////////////////////////////////////////////////
//
//  jsrsClient.js - javascript remote scripting client include
//  
//  Author:  Brent Ashley [jsrs@megahuge.com]
//          Adapted by Vincent

// callback pool needs global scope
var jsrsContextPoolSize = 0;
var jsrsContextMaxPool = 10;
var jsrsContextPool = new Array();
var jsrsBrowser = jsrsBrowserSniff();
var jsrsPOST = true;

// constructor for context object
function jsrsContextObj( contextID ){
  
  // properties
  this.id = contextID;
  this.busy = true;
  this.callback = null;
  this.container = contextCreateContainer( contextID );
  
  // methods
  this.GET = contextGET;
  this.POST = contextPOST;
  this.getPayload = contextGetPayload;
  this.setVisibility = contextSetVisibility;

  return this;
}
//  method functions are not privately scoped 
//  because Netscape's debugger chokes on private functions
function contextCreateContainer( containerName ){
  // creates hidden container to receive server data 
  var container = null;
  switch( jsrsBrowser ) {
    case 'NS':
      container = new Layer(1500);
      container.name = containerName;
      container.visibility = 'hidden';
      container.clip.width = 100;
      container.clip.height = 100;
      break;
    
    case 'IE':
      document.body.insertAdjacentHTML( "afterBegin", '<span id="SPAN' + containerName + '"></span>' );
      var span = document.all( "SPAN" + containerName );
      var html = '<iframe name="' + containerName + '" src=""></iframe>';
      span.innerHTML = html;
      span.style.display = 'none';
      container = window.frames[ containerName ];
      break;
      
    case 'MOZ':  
      var span = document.createElement('SPAN');
      span.id = "SPAN" + containerName;
      document.body.appendChild( span );
      var iframe = document.createElement('IFRAME');
      iframe.name = containerName;
      span.appendChild( iframe );
      container = iframe;
      break;
  }
  return container;
}

function contextPOST( rsPage, func, parms ){

  var d = new Date();
  var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
  var doc = (jsrsBrowser == "IE" ) ? this.container.document : this.container.contentDocument;
  doc.open();
  doc.write('<html><body>');
  doc.write('<form name="jsrsForm" method="post" target="" ');
  doc.write(' action="' + rsPage + '?U=' + unique + '">');
  doc.write('<input type="hidden" name="C" value="' + this.id + '">');

  // func and parms are optional
  if (func != null){
  doc.write('<input type="hidden" name="F" value="' + func + '">');

    if (parms != null){
      if (typeof(parms) == "string"){
        // single parameter
        doc.write( '<input type="hidden" name="P0" '
                 + 'value="[' + jsrsEscapeQQ(parms) + ']">');
      } else {
        // assume parms is array of strings
        for( var i=0; i < parms.length; i++ ){
          doc.write( '<input type="hidden" name="P' + i + '" '
                   + 'value="[' + jsrsEscapeQQ(parms[i]) + ']">');
        }
      } // parm type
    } // parms
  } // func

  doc.write('</form></body></html>');
  doc.close();
  doc.forms['jsrsForm'].submit();
}

function contextGET( rsPage, func, parms ){

  // build URL to call
  var URL = rsPage;

  // always send context
  URL += "?C=" + this.id;

  // func and parms are optional
  if (func != null){
    URL += "&F=" + escape(func);

    if (parms != null){
      if (typeof(parms) == "string"){
        // single parameter
        URL += "&P0=[" + escape(parms+'') + "]";
      } else {
        // assume parms is array of strings
        for( var i=0; i < parms.length; i++ ){
          URL += "&P" + i + "=[" + escape(parms[i]+'') + "]";
        }
      } // parm type
    } // parms
  } // func

  // unique string to defeat cache
  var d = new Date();
  URL += "&U=" + d.getTime();
 
  // make the call
  switch( jsrsBrowser ) {
    case 'NS':
      this.container.src = URL;
      break;
    case 'IE':
      this.container.document.location.replace(URL);
      break;
    case 'MOZ':
      this.container.src = '';
      this.container.src = URL; 
      break;
  }  
  
}

function contextGetPayload(){
  switch( jsrsBrowser ) {
    case 'NS':
      return this.container.document.forms['jsrs_Form'].elements['jsrs_Payload'].value;
    case 'IE':
      return this.container.document.forms['jsrs_Form']['jsrs_Payload'].value;
    case 'MOZ':
      return window.frames[this.container.name].document.forms['jsrs_Form']['jsrs_Payload'].value; 
  }  
}

function contextSetVisibility( vis ){
  switch( jsrsBrowser ) {
    case 'NS':
      this.container.visibility = (vis)? 'show' : 'hidden';
      break;
    case 'IE':
      document.all("SPAN" + this.id ).style.display = (vis)? '' : 'none';
      break;
    case 'MOZ':
      document.getElementById("SPAN" + this.id).style.visibility = (vis)? '' : 'hidden';
      this.container.width = (vis)? 250 : 0;
      this.container.height = (vis)? 100 : 0;
      break;
  }  
}

// end of context constructor

function jsrsGetContextID(){
  var contextObj;
  for (var i = 1; i <= jsrsContextPoolSize; i++){
    contextObj = jsrsContextPool[ 'jsrs' + i ];
    if ( !contextObj.busy ){
      contextObj.busy = true;      
      return contextObj.id;
    }
  }
  // if we got here, there are no existing free contexts
  if ( jsrsContextPoolSize <= jsrsContextMaxPool ){
    // create new context
    var newId = (jsrsContextPoolSize + 1);
    var contextID = "jsrs" + newId;
    var newContext = new jsrsContextObj(contextID);
    jsrsContextPool[ contextID ] = newContext;
    jsrsContextPoolSize++;
    return contextID;
  } else {
    alert( "jsrs Error:  context pool full" );
    return null;
  }
}

function jsrsExecute( rspage, callback, func, parms, visibility ){
  // call a server routine from client code
  //
  // rspage      - href to asp file
  // callback    - function to call on return 
  //               or null if no return needed
  //               (passes returned string to callback)
  // func        - sub or function name  to call
  // parm        - string parameter to function
  //               or array of string parameters if more than one
  // visibility  - optional boolean to make container visible for debugging
  
  // get context
  var contextObj = jsrsContextPool[ jsrsGetContextID() ];
  contextObj.callback = callback;

  var vis = (visibility == null)? false : visibility;
  contextObj.setVisibility( vis );


  if ( jsrsPOST && ((jsrsBrowser == 'IE') || (jsrsBrowser == 'MOZ'))){
    contextObj.POST( rspage, func, parms );
  } else {
    contextObj.GET( rspage, func, parms );
  }  
  
  return contextObj.id;
}

function jsrsLoaded( contextID ){
  // get context object and invoke callback
  var contextObj = jsrsContextPool[ contextID ];
  if( contextObj.callback != null){
    contextObj.callback( jsrsUnescape( contextObj.getPayload() ), contextID );
  }
  // clean up and return context to pool
  contextObj.callback = null;
  contextObj.busy = false;
}

function jsrsError( contextID, str ){
  alert( unescape(str) );
  jsrsContextPool[ contextID ].busy = false
}

function jsrsEscapeQQ( thing ){
  return thing.replace(/'"'/g, '\\"');
}

function jsrsUnescape( str ){
  // payload has slashes escaped with whacks
  return str.replace( /\\\//g, "/" );
}

function jsrsBrowserSniff(){
  if (document.layers) return "NS";
  if (document.all) return "IE";
  if (document.getElementById) return "MOZ";
  return "OTHER";
}

/////////////////////////////////////////////////
//
// user functions

function jsrsArrayFromString( s, delim ){
  // rebuild an array returned from server as string
  // optional delimiter defaults to ~
  var d = (delim == null)? '~' : delim;
  return s.split(d);
}

function jsrsDebugInfo(){
  // use for debugging by attaching to f1 (works with IE)
  // with onHelp = "return jsrsDebugInfo();" in the body tag
  var doc = window.open().document;
  doc.open;
  doc.write( 'Pool Size: ' + jsrsContextPoolSize + '<br><font face="arial" size="2"><b>' );
  for( var i in jsrsContextPool ){
    var contextObj = jsrsContextPool[i];
    doc.write( '<hr>' + contextObj.id + ' : ' + (contextObj.busy ? 'busy' : 'available') + '<br>');
    doc.write( contextObj.container.document.location.pathname + '<br>');
    doc.write( contextObj.container.document.location.search + '<br>');
    doc.write( '<table border="1"><tr><td>' + contextObj.container.document.body.innerHTML + '</td></tr></table>' );
  }
  doc.write('</table>');
  doc.close();
  return false;
}

/////////////////////////////////////////////////
//
// Support for dynamic inputs (especially select)
//
// 1. Input dependencies are registered.
// 2. 

// globals
//var curOption = new Array();
//var isLoaded = new Array();

var JT_dependency = new Array();
var JT_dependencyCount = 0;
var JT_handler = new Array();
var JT_handlerCount = 0;

// Register the dependency of one input on another.
function JT_addDependency(formName, triggerInput, dependentInput, dependentType, action)
{
    if (!action) action = "set";
    var obj = new Object();
    obj.formName = formName;
    obj.action = action;
    obj.trigger = triggerInput;
    obj.dependent = dependentInput;
    obj.dependentType = dependentType;
    JT_dependency[JT_dependencyCount++] = obj;
}
// Register the url that will handle the request.
function JT_registerHandler(formName, inputName, handler, funcName)
{
    var obj = new Object();
    obj.formName = formName;
    obj.inputName = inputName;
    obj.handler = handler;
    obj.funcName = funcName;
    JT_handler[JT_handlerCount++] = obj;
}
function JT_getHandler(formName, inputName)
{
    for(i = 0; i < JT_handlerCount; i++){
	var theHandler = JT_handler[i];
	if (theHandler.formName == formName &&
	    theHandler.inputName == inputName)
	    return theHandler.handler;
    }
    return "";
}
function JT_getFuncName(formName, inputName)
{
    for(i = 0; i < JT_handlerCount; i++){
	var theHandler = JT_handler[i];
	if (theHandler.formName == formName &&
	    theHandler.inputName == inputName)
	    return theHandler.funcName;
    }
    return "";
}
function JT_inputChange(o)
{
    if (arguments.length == 0)
	o = this;
    if (typeof o == "undefined"){ alert("undefined input change"); return;}
    var myName = o.name;
    var myFormName = o.form.name;
    var myValue = "";
    if (o.options){
	myValue = o.options[o.selectedIndex].value;
    }else{
	myValue = o.value;
    }
    // Update any dependent inputs.
    for(i =0; i < JT_dependencyCount; i++){
	var theEntry = JT_dependency[i];
	if (theEntry.formName == myFormName &&
	    theEntry.trigger == myName){
	    if (theEntry.action == "set" || theEntry.action.length == 0){
		JT_initInput(myFormName,
			     theEntry.dependent,
			     theEntry.dependentType,
			     myValue);
	    }else{
		JT_clearInput(myFormName,
			     theEntry.dependent,
			     theEntry.dependentType);
	    }

	}
    }
}
function JT_clearInput(formName, inputName, inputType)
{
    if (inputType == "select"){
	JT_clearSelect(formName, inputName);
    }else{
	document.forms[formName][inputName].value = "";
    }
}
function JT_initInput(formName, inputName, inputType, value, funcName)
{
    if (arguments.length < 5) funcName = "";
    window.status = "Loading dynamic options...";
    // Fetch handler for this input
    var handler = JT_getHandler(formName, inputName);
    if (funcName == "")
	funcName = JT_getFuncName(formName, inputName);
    if (handler.length > 0){
    	var params = new Array();
	params[0] = formName;
	params[1] = inputName;
	params[2] = inputType;
	params[3] = value;
	//alert("Calling remote script: formName =  " + formName);
	//alert("Calling remote script: " + handler + " func = " + funcName);
	var contextId = jsrsExecute( handler, JT_callback, funcName, params, "");
	//alert("Context id = " + contextId);
    }
}
// We expect back an array of values. The first three indicating
// input and the rest are real values.
function JT_callback(payload)
{
    if (payload == null) {alert("Failure loading options"); return;}
    if (payload.length < 3) {alert("Return value was too short"); return;}
    var params = payload.split('|');
    if (params.length < 4) {alert("Too few return values"); return;}
    var formName = params[0]; 
    var inputName = params[1];
    var inputType = params[2];
    if (inputType == "select"){
	JT_clearSelect(formName, inputName);
	var theSelect = document.forms[formName][inputName];
	theSelect.disabled = true;
	var numOptions = (params.length - 3)/2;
	j = 3;
	for(i = 0; i < numOptions; i++){
	    var theOption = params[j++];
	    var theValue = params[j++];
	    theSelect.options[i] = new Option(theOption, theValue);
	}
	theSelect.disabled = false;
	theSelect.onchange = JT_inputChange;
    }else{
	var theInput = document.forms[formName][inputName];
	theInput.value = params[3];
	theInput.onchange = JT_inputChange;
    }
}
function JT_clearSelect( formName, inputName ){
  var lst = document.forms[formName][inputName];
  lst.options.length = 0;
  lst.options[0] = new Option("Not Loaded", "");
  lst.onchange = null;
}
function JT_jsrsInit()
{
    jsrsContextPool = new Array();
    JT_dependency = new Array();
    JT_handler = new Array();
}
function fillList( listName, strOptions ){
  // fill any list with options
  emptyList( listName );
  
  // always insert selection prompt
  var lst = document.forms['QForm'][listName];
  lst.disabled = true;
  lst.options[0] = new Option('-- Please Select --', noValue);
  
  // options in form "value~displaytext|value~displaytext|..."
  var aOptionPairs = strOptions.split('|');
  for( var i = 0; i < aOptionPairs.length; i++ ){
    if (aOptionPairs[i].indexOf('~') != -1) {
      var aOptions = aOptionPairs[i].split('~');
      lst.options[i + 1] = new Option(aOptions[1], aOptions[0]);
    }  
  }
  // init to no value
  selectOption( listName, noValue );
  lst.onchange = eval( listName + "_onChange" );
  isLoaded[listName] = true;
  lst.disabled = false;
}
function emptyList( listName ){
  var lst = document.forms['QForm'][listName];
  lst.options.length = 0;
  lst.onchange = null;
  isLoaded[listName] = false;
  curOption[listName] = noValue;
}
function selectOption( listName, optionVal ){
  // set list selection to option based on value
  var lst = document.forms['QForm'][listName];
  for( var i = 0; i< lst.options.length; i++ ){
    if( lst.options[i].value == optionVal ){
      lst.selectedIndex = i;
      curOption[listName] = optionVal;
      return;
    }  
  }
}
function jsrsOnLoad()
{
    if (typeof jsrsPageInit == "function") jsrsPageInit();
}
////////////////////////////////////////////////////////////////////////////////
// Cascading menus [By Vincent]
var JT_arrow = "/appimages/arrow.gif";
var JT_menuTimers = new Array();
var JT_menuPath = new Array();
var JT_menuDelay = 500;
function JT_arrayFind(a, o)
{
    if (o){
	for(var i = 0; i < a.length; i++){
	    if (a[i] == o){
		return i;
	    }
	}
    }
    return -1;
}
function JT_removeLeaf(menu)
{
    var pos = JT_arrayFind(JT_menuPath, menu);
    if (pos >= 0){
	for(var i = pos; i < JT_menuPath.length; i++){
	    var layerName = JT_menuPath[i];
	    if (layerName) JT_hideLayer(layerName);
	    JT_menuPath[i] = null;
	}
    }
}
function JT_currentMenu(menu)
{
    var isCurrent = false;
    for(var i = 0; i < JT_menuPath.length; i++){
	var layerName = JT_menuPath[i];
	if (menu == layerName){
	    isCurrent = true;
	}else if (menu != null){
	    isCurrent = false;
	}
    }
    return isCurrent;
}
function JT_manageLayers(parent, menu)
{
    var parentPos = -1;
    if (parent != null) parentPos = JT_arrayFind(JT_menuPath, parent);
    if (parentPos >= 0){
	for(var i = parentPos+1; i < JT_menuPath.length; i++){
	    var layerName = JT_menuPath[i];
	    if (layerName){
		JT_closeMenu(layerName);
		JT_menuPath[i] = null;
	    }
	}
	if (menu) JT_menuPath[i+1] = menu;
    }else{
	for(var i = 0; i < JT_menuPath.length; i++){
	    var layerName = JT_menuPath[i];
	    if (layerName){
		JT_closeMenu(layerName);
		JT_menuPath[i] = null;
	    }
	}
	if (menu) JT_menuPath[0] = menu;
    }
    if (parent != null) JT_clearTimer(parent);
}
function JT_findObject(name){
    var o = null;
    if (ns4){
	o = document.layers[name];
	if (o == null) o = document.anchors[name];
	if (o == null) o = eval("document." + name);
	if (o != null && typeof o == "undefined") o = null;
    }else if (document.all && !document.getElementById){
	o = document.all[name];
    }else if (document.getElementById){
	o = document.getElementById(name);
	if (o == null) o = document.anchors[name];
    }
    return o;
}
function JT_getPosOfAnchorInLayer(layer, anchorName)
{
    var o = layer.document.anchors[anchorName];
    if (o == null) return null;
    var r = new Array();
    r[0] = o.x;
    r[1] = o.y;
    r[2] = null;
    r[3] = null;
    return r;
}
var ns4 = (document.layers)?true:false;
function JT_getObjectPos(name){
    var o = JT_findObject(name);
    var r = new Array();
    r[0] = r[1] = r[2] = r[3] = null;
    if (ns4){
	var shadowName = name + "shadow";
	var anchorName = name + "anchor";
	if (o == null){
	    o = document.anchors[anchorName];
	    if (o != null){
		r[0] = o.x;
		r[1] = o.y;
	    }
	}else{
	    r[0] = o.left; 
	    r[1] = o.top; 
	}
	if (o == null) return null;
	if (o.clip){
	    r[2] = o.clip.width;
	    r[3] = o.clip.height;
	}else{
	    o = JT_findObject(shadowName);
	    if (o != null && o.clip){
		r[2] = o.clip.width;
		r[3] = o.clip.height;
	    }
	}
	//alert("" + name + ":x=" + r[0] + ",y=" + r[1] + ",w=" + r[2] + "h="+r[3]);
    }else{ //Not NS4
	if (o == null){
	    var anchorName = name + "anchor";
	    o = JT_findObject(anchorName);
	}
	if (o == null) return null;
	r[2] = o.offsetWidth; 
	r[3] = o.offsetHeight;

	var trueOffsetLeft = 0;
	var trueOffsetTop = 0;
	while (o != null){
	    trueOffsetLeft += o.offsetLeft;
	    trueOffsetTop += o.offsetTop;
	    o = o.offsetParent;
	}
	r[0] = trueOffsetLeft;
	r[1] = trueOffsetTop; 
	//alert("" + name + ":x=" + r[0] + ",y=" + r[1] + ",w=" + r[2] + "h="+r[3]);
    }
    if (typeof r[0] == "undefined") r[0] = null;
    if (typeof r[1] == "undefined") r[1] = null;
    if (typeof r[2] == "undefined") r[2] = null;
    if (typeof r[3] == "undefined") r[3] = null;
    return r;
}
function JT_leafIn()
{
    JT_clearTimers();
}
function JT_leafOut()
{
    JT_startTimer();
}
function JT_menuIn(parentLayer, menuLayer, e, where, pos, row)
{
    JT_manageLayers(parentLayer, menuLayer);
    if (arguments.length > 0){
	var x = 0;
	var y = 0;
	JT_hideLayer(menuLayer);
	if (typeof event == "undefined"){
	    if (e != null){
		x = e.pageX; y = e.pageY;
	    }
	}else{
	    x = (event.x + document.body.scrollLeft);
	    y = (event.y + document.body.scrollTop);
	}
	if (pos != null){
	    var px = pos[0]; var py = pos[1]; var pw = pos[2]; var ph = pos[3];
	    var foundRow = false;
	    if (parentLayer != null && parentLayer.substring(0,4) == "menu" && row != null){
		var parentRow = parentLayer + "_" + row;
		var npos = JT_getObjectPos(parentRow);
		if (npos != null){
		    px = npos[0]; py = npos[1]; pw = npos[2]; ph = npos[3];
		    foundRow = true;
		}
	    }
	    if (where == "b"){
		if (py != null && ph != null){ y = py+ph;}else if (py != null){y = max(py+30,y);}
		if (px != null) x = px;
	    }else if (where == "r"){

		if (px != null && pw != null) x = px+pw;
		if ((foundRow || parentLayer == null) && py != null) y = py;
	    }else if (where == "c"){
		if (py != null && ph != null){ y = py+ph;}else if (py != null){y=max(py+30,y);}
		if (px != null && pw != null){
		    var centre = px + pw/2;
		    var mPos = JT_getObjectPos(menuLayer);
		    var mw = null;
		    if (mPos != null){
			mw = mPos[2];
			if (mw) x = centre - (mw/2);
		    }
		}
	    }else{
		if (px != null){
		    if (pw != null)
			x = px + pw;
		    else
			x = Math.max(x, px + 50);
		}
		if (py != null){
		    if (ph != null)
			y = Math.min(y+10, py + ph);
		}
	    }
	}else{
	    //alert('pos is null');
	    //alert('x='+x+',y='+y);
	}
	JT_moveLayer(menuLayer, x, y);
	JT_showLayer(menuLayer);
	JT_clearTimers();
    }
}
function JT_clearTimers()
{
    for(var i = 0; i < JT_menuPath.length; i++){
	var layerName = JT_menuPath[i];
	JT_clearTimer(layerName);
    }
}
function JT_clearTimer(layerName)
{
    var theTimer = JT_menuTimers[layerName];
    if (theTimer != null)
	clearTimeout(theTimer);
    JT_menuTimers[layerName] = null;
}
function JT_startTimer()
{
    // Start a timer on the current leaf
    var layerName = null;
    a = JT_menuPath;
    for(var i = 0; i < a.length; i++)
	if (a[i] != null) layerName = a[i];
    if (layerName){
	var theTimer = JT_menuTimers[layerName];
	if (theTimer != null){
	    clearTimeout(theTimer);
	    JT_menuTimers[layerName] = setTimeout("JT_closeMenu('"+layerName+"')", JT_menuDelay);
	}else{
	    JT_menuTimers[layerName] = setTimeout("JT_closeMenu('" + layerName +"')", JT_menuDelay);
	}
    }
}
function JT_menuOut(layerName)
{
    if (JT_currentMenu(layerName) == true) JT_startTimer();
}
function JT_closeMenu(layerName)
{
    JT_removeLeaf(layerName);
    JT_hideLayer(layerName);
    JT_clearTimer(layerName);
    JT_startTimer();
}
function JT_moveLayer(layerName, x, y)
{
    var theLayer = null;
    if (ns4){
	theLayer = document.layers[layerName];
	if (theLayer){
	    theLayer.top = y;
	    theLayer.left = x;
	}else{
	    //alert('could not find ' + layerName);
	}
    }else if (opera){
	theLayer = document.all[layerName];
	if (theLayer){
	    theLayer.style.pixelTop = y;
	    theLayer.style.pixelLeft = x;
	}
    }else if (ie4){
	theLayer = document.all[layerName];
	if (theLayer) {
	    theLayer.style.pixelTop = y;
	    theLayer.style.pixelLeft = x;
	}
    }else if (dom){
	theLayer = document.getElementById(layerName);
	if (theLayer){
	    theLayer.style.top = y+"px";
	    theLayer.style.left = x+"px";
	}
    }
}
function JT_setLayerContents(layerName, s)
{
    if (ns4){
	var theLayer = document.layers[layerName];
	if (theLayer != null){
	    theLayer.document.write(s);
	    theLayer.document.close();
	}
    }else{
	var theLayer = document.getElementById(layerName);
	if (theLayer != null){
	    document.getElementById(layerName).innerHTML =s ;
	}
    }
}
function JT_showLayer(layerName)
{
    if (ns4){
	theLayer = document.layers[layerName];
	if (theLayer){
	    //alert('Showing ' + layerName);
	    theLayer.visibility = 'show';
	}else{
	    //alert('Show: could not find ' + layerName);
	}
    }else if (opera || ie4){
	theLayer = document.all[layerName];
	if (theLayer) theLayer.style.visibility = 'visible';
    }else if (dom){
	theLayer = document.getElementById(layerName);
	if (theLayer) theLayer.style.visibility = 'visible';
    }
}
function JT_hideLayer(layerName)
{
    if (ns4){
	theLayer = document.layers[layerName];
	if (theLayer){
	    theLayer.visibility = 'hide';
	}else{
	    //alert('Hide: Could not find ' + layerName);
	}
    }else if (opera || ie4){
	theLayer = document.all[layerName];
	if (theLayer) theLayer.style.visibility = 'hidden';
    }else if (dom){
	theLayer = document.getElementById(layerName);
	if (theLayer) theLayer.style.visibility = 'hidden';
    }
}
function JT_showLayerAtPos(sourceLayer, targetLayer)
{
    var thePos = JT_getObjectPos(targetLayer);
    if (thePos != null){
	JT_moveLayer(sourceLayer, thePos[0], thePos[1]);
	JT_showLayer(sourceLayer);
    }else{
	alert('showLayer: no position');
    }
}
////////////////////////////////////////////////////////////////////////////////
function JT_objectDef(label, classid, codebase, pluginspace, type)
{
    this.label = label;
    this.classid = classid;
    this.codebase = codebase;
    this.pluginspace = pluginspace;
    this.type = type;
}
var JT_objectAttrs=",WIDTH,HEIGHT,ID,NAME,ALIGN,";
var JT_embedAttrs=",WIDTH,HEIGHT,ID,NAME,ALIGN,";
var JT_objectDefs = new Array(4);
JT_objectDefs[0] = new JT_objectDef("QT",
	"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B",
	"http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0",
      	"http://www.apple.com/quicktime/download/", "");
JT_objectDefs[1] = new JT_objectDef("RA",
	"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA",
	"",
	"",
	"audio/x-pn-realaudio-plugin" );
JT_objectDefs[2] = new JT_objectDef("WM", "clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6", "", "", "");
JT_objectDefs[3] = new JT_objectDef("SWF",
        "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
	"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0",
	"http://www.macromedia.com/go/getflashplayer",
	"application/x-shockwave-flash");
function JT_getObjectDef(label)
{
    for(i = 0; i < JT_objectDefs.length;i++)
	if (JT_objectDefs[i].label == label)
	    return JT_objectDefs[i];
    return null;
}
function JT_genAttrPair(name,value)
{
    if (value != "")
	return  " " + name + "=\"" + value + "\"";
    else
	return "";
}
function JT_genAttrFromArgs(name, theArgs, defaultValue)
{
    for(var i = 0; i < (theArgs.length)-1; i+= 2){
	var thisName = theArgs[i];
	var thisValue = theArgs[i+1];
	if (name == thisName){
	    return JT_genAttrPair(name, thisValue);
	}
    }
    return "";
}
function JT_genAttrsFromArgs(avoidList, theArgs)
{
    var attrs = "";
    for(var i = 0; i < (theArgs.length)-1; i+= 2){
	var thisName = theArgs[i];
	var thisValue = theArgs[i+1];
	var tmp = "," + thisName + ",";
	if (avoidList.indexOf(tmp) < 0){
	    var thisAttr = JT_genAttrPair(thisName, thisValue);
	    attrs += thisAttr;
	}
    }
    return attrs;
}
function JT_genParamsFromArgs(avoidList, theArgs)
{
    var params = "";
    for(var i = 0; i < (theArgs.length)-1; i+= 2){
	var thisName = theArgs[i];
	var thisValue = theArgs[i+1];
	var tmp = "," + thisName + ",";
	if (avoidList.indexOf(tmp) < 0){
	    var thisParam = "<" +
	                    "PARAM NAME=\"" +
			    thisName +
			    "\" VALUE=\"" +
			    thisValue +
			    "\">";
	    params += thisParam;
	}
    }
    return params;
}
function JT_objectHTML(label)
{
    var args = new Array();
    for(var i = 1; i < JT_objectHTML.arguments.length; i++){
	args[i-1] = JT_objectHTML.arguments[i];
    }
    var o = JT_getObjectDef(label);
    if (o == null){ alert('could not find ' + label);  return;}
    var objectTag = "";
    var paramTags = "";
    var embedTag = "";
    if (o.classid != ""){
	objectTag = "<" + "OBJECT "
	                + JT_genAttrPair("CLASSID",o.classid)
	                + JT_genAttrPair("CODEBASE", o.codebase)
			+ JT_genAttrFromArgs("WIDTH", args)
			+ JT_genAttrFromArgs("HEIGHT", args)
			+ JT_genAttrFromArgs("ID", args)
			+ JT_genAttrFromArgs("ALIGN", args)
			+ ">";
	paramTags = JT_genParamsFromArgs(JT_objectAttrs, args);
    }
    if (o.pluginspace != ""){
	embedTag = "<" + "EMBED " 
		       + JT_genAttrPair("PLUGINSPACE", o.pluginspace)
		       + JT_genAttrPair("TYPE", o.type)
		       + JT_genAttrFromArgs("WIDTH", args)
		       + JT_genAttrFromArgs("HEIGHT", args)
		       + JT_genAttrFromArgs("NAME", args)
		       + JT_genAttrFromArgs("ALIGN", args)
		       + JT_genAttrsFromArgs(JT_embedAttrs, args)
		       + ">";
    }
    document.writeln(objectTag);
    document.writeln(paramTags);
    document.writeln(embedTag);
    document.writeln('</EMBED>');
    document.writeln('</OBJECT>');
    document.writeln('');
}
/*if (typeof JT_pageInit == "function" ) JT_pageInit();*/
