var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 	try {
 		 xmlhttp = new XMLHttpRequest();
 	} catch (e) {
 		 xmlhttp=false;
 	}
}

/*@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.
if (!xmlhttp){
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
}
@end @*/

if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


var please_wait = "Please wait...";

function open_url(url, targetId) {
  if(!xmlhttp) {
    return false;
  }
    var e=document.getElementById(targetId);if(!e)return false;
    if(please_wait)e.innerHTML = please_wait;
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange = function() { response(url, e); }
    try{
      xmlhttp.send(null);
    }catch(l){
    while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
    e.appendChild(document.createTextNode("request failed"));
  }
}

function response(url, e) {
  if(xmlhttp.readyState != 4)return;
    var tmp= (xmlhttp.status == 200 || xmlhttp.status == 0) ? xmlhttp.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the following error code: " + xmlhttp.status+" "+xmlhttp.statusText;
    var d=document.createElement("div");
    d.innerHTML=tmp;
    setTimeout(function(){
      while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
      e.appendChild(d);
    },10)
}

function atoi( str ) {
  if( str == null ) {// || (/^.*\D/).test(str) ) {
    return 0;
  }
  var num=parseInt( str, 10 );
  if( num == null || isNaN(num) ) {
    return 0;
  }
  return num;
}

function STR( value ) {
  if( value && value != 'undefined' ) {
    return ''+value;
  }
  return '';
}

function tfnum( bool ) {
  return bool?1:0;
}

var UA={};

function addSelect( select, option, idx ) {
  if( idx == null ) {
    idx=0;
  }
  var before=document.all?idx:select.options[idx];
  select.add( option, before );
}

if( navigator.userAgent.indexOf("MSIE 5.5") != -1 ) {
  UA.bugMode=true;
}
else {
  UA.bugMode=false;
}

// fix the probem related to old IE browser that does not support getElementById
var IE_all_cache = new Object();
function IE_getElementById(id) {
  if (IE_all_cache[id] == null) {
    IE_all_cache[id] = document.all[id];
  }
  return IE_all_cache[id];
}

if (document.all) {
  if (!document.getElementById) {
    document.getElementById = IE_getElementById;
  }
}

// Fixes some of the nonconformance problems inherent in IE versions lower than 5.5.

Array.prototype.push=function( item ) {
  this[this.length]=item;
}

String.prototype.splitCSV=function() {
  var ret=[], split=this.split( ',' ), idx=0;
  while( idx < split.length ) {
    if( split[idx].match(/\"/g) && split[idx].match(/\"/g).length == 1 ) {
      ret.push( '' );
      do {
        ret[ret.length-1]+=split[idx++]+',';
      } while( idx < split.length && (!split[idx].match(/\"/g) || split[idx].match(/\"/g).length == 1) );
      ret[ret.length-1]=ret[ret.length-1].replace( /,$/, '' );
    }
    else if( split[idx].match(/'/g) && split[idx].match(/'/g).length == 1 ) {
      ret.push( '' );
      do {
        ret[ret.length-1]+=split[idx++]+',';
      } while( idx < split.length && (!split[idx].match(/'/g) || split[idx].match(/'/g).length == 1) );
      ret[ret.length-1]=ret[ret.length-1].replace( /,$/, '' );
    }
    else {
      ret.push( split[idx++] );
    }
  }
  // Remove leading and trailing single or double quotes from all array elements before returning
  ret.transform( function(value) {return value.replace(/(^['"])|(['"]$)/g,'');} );
  return ret;
}

Array.prototype.toCSV=function( which ) {
  var array=this.copy();
  if( which==null ) {
    array.transform( function(value) {return "\""+value+"\"";} );
  }
  return array.join( ',' );
}

var arraySortDescending=false;
var arraySortFields=[];
var arraySortByCase=false;

var compareIsLess=-1, compareIsMore=1, compareIsEqual=0;
function compareObjsByField( item1, item2, field ) {
  if( !arraySortByCase && item1[field] && item2[field] ) {
    if(  !item1[field].toString().isAllDigits() && !item2[field].toString().isAllDigits() ) {
      var field1=item1[field].toString();
      var field2=item2[field].toString();
      if( field1.toLowerCase() < field2.toLowerCase() ) {
        return compareIsLess;
      }
      return (field1 == field2 ? compareIsEqual : compareIsMore);
    }
    var field1=item1[field], field2=item2[field];
    if( field1 < field2 ) {
      return compareIsLess;
    }
    return (field1 == field2 ? compareIsEqual : compareIsMore);
  }
  if( item1[field] < item2[field] ) {
    return compareIsLess;
  }
  return (item1[field] == item2[field] ? compareIsEqual : compareIsMore);
}

function arraySortByFunc( item1, item2 ) {
  var result=0;
  for( var idx=0; idx < arraySortFields.length; idx++ ) {
    if( (result=compareObjsByField(item1,item2,arraySortFields[idx])) != compareIsEqual ) {
      return (arraySortDescending?-1:1)*result;
    }
  }
  return compareIsEqual;
}

Array.prototype.sortby=function( field, order ) {
  arraySortDescending= order!=null && order;
  arraySortFields=[ field ];
  this.sort( arraySortByFunc );
}

Array.prototype.sortbyMulti=function( fieldsAry, order ) {
  arraySortDescending= order!=null && order;
  arraySortFields=fieldsAry;
  this.sort( arraySortByFunc );
}

Array.prototype.find=function( item ) {
  for( var idx=0; idx < this.length; idx++ ) {
    if( item == this[idx] ) {
      return idx;
    }
  }
  return -1;
}

Array.prototype.get=function( item ) {
  idx=this.find( item );
  return idx >= 0 ? this[idx] : null;
}

Array.prototype.findByField=function( item, field ) {
  for( var idx=0; idx < this.length; idx++ ) {
    if( item == this[idx][field] ) {
      return idx;
    }
  }
  return -1;
}

Array.prototype.getByField=function( item, field ) {
  idx=this.findByField( item, field );
  return idx >= 0 ? this[idx] : null;
}

Array.prototype.convertToObject=function( field ) { // Convert an array into an indexable object based on 'field' property of its elements
  var obj={};
  for( var idx=0; idx < this.length; idx++ ) {
    obj[this[idx].field]=this[idx];
  }
  return obj;
}

Array.prototype.pushUnique=function( item ) {
  if( this.find(item) < 0 ) {
    this.push( item );
  }
}

Array.prototype.pushUniqueByField=function( item, field ) {
  if( this.findByField(item[field],field) < 0 ) {
    this.push( item );
  }
}

Array.prototype.remove=function( item ) {
  for( var idx=0; idx < this.length; idx++ ) {
    if( item == this[idx] ) {
      this.splice( idx--, 1 );
    }
  }
}

Array.prototype.insert=function( item, index ) {
  if( index >= this.length ) {
    this.push( item );
    return;
  }
  var previous=null;
  for( var idx=this.length ; idx > index ; idx-- ) {
    this[idx]=this[idx-1];
  }
  this[index]=item;
}

Array.prototype.removeByField=function( item, field ) {
  for( var idx=0; idx < this.length; idx++ ) {
    if( item == this[idx][field] ) {
      this.splice( idx--, 1 );
    }
  }
}


function copyArray( rhs, func ) { // func is an optional parameter specifying a condition elements must satisfy to be copied
  var a=[];
  for( var idx=0; idx < rhs.length; idx++ ) {
    if( func == null || typeof func != 'function' || func(rhs[idx]) ) {
      a.push( rhs[idx] );
    }
  }
  return a;
}

Array.prototype.transform=function( f ) {
  if( typeof f != 'function' ) {
    reportScriptError( 'transform(): Argument is not a function (f='+f+')' );
    return;
  }
  for( var idx=0; idx < this.length; idx++ ) {
    this[idx]=f( this[idx] );
  }
}

Array.prototype.spliceByValue=function( v ) {
  var idx=this.find( v );
  if( idx != -1 ) {
    this.splice( idx, 1 );
  }
}

Array.prototype.spliceByField=function( v, field ) {
  var idx=this.findByField( v, field );
  if( idx != -1 ) {
    this.splice( idx, 1 );
  }
}

function stringize( v ) {
  return ''+v;
}

// Provide for copying of objects

//Object.prototype.copy=function() {
//  return this;  // Use default reference/value semantics
//}

//Object.prototype.deepCopy=function() {
//  return this.copy( true );
//}

Array.prototype.copy=function( deep ) { // Deep attempts to populate the copied array with copied values rather than references.
  if( !deep ) {
    return this.concat();
  }
  var c=[];
  for( var idx=0; idx < this.length; idx++ ) {
    c.push( this[idx].copy(true) );
  }
  return c;
}

Date.prototype.copy=function() {
  var d=new Date();
  d.setTime( this.getTime() );
  return d;
}

function isClosed( win ) {
    try {
      return( win.closed );
    }
    catch (ex) {
      return( true );
    }
}

// Taken from http://www.crockford.com/javascript

Function.prototype.method=function( name, func ) {
  this.prototype[name]=func;
  return this;
};

function isAlien( a ) {
  return isObject( a ) && typeof a.constructor != 'function';
}

function isArray( a ) {
  return isObject( a ) && a.constructor == Array;
}

function isBoolean( a ) {
  return typeof a == 'boolean';
}

function isEmpty( o ) {
  var i, v;
  if( isObject(o) ) {
    for( i in o ) {
      v=o[i];
      if( isUndefined(v) && isFunction(v) ) {
        return false;
      }
    }
  }
  return true;
}

function isFunction( a ) {
    return typeof a == 'function';
}

function isNull( a ) {
    return typeof a == 'object' && !a;
}

function isNumber( a ) {
    return typeof a == 'number' && isFinite(a);
}

function isObject( a ) {
    return (a && typeof a == 'object') || isFunction( a );
}

function isString( a ) {
    return typeof a == 'string';
}

function isUndefined( a ) {
    return typeof a == 'undefined';
}

Function.method( 'apply', function(o, a) {
  var r, x = '____apply';
  if( !isObject(o) ) {
    o={};
  }
  o[x] = this;
  switch ((a && a.length) || 0) {
  case 0:
    r = o[x]();
    break;
  case 1:
    r = o[x]( a[0] );
    break;
  case 2:
    r = o[x]( a[0], a[1] );
    break;
  case 3:
    r = o[x]( a[0], a[1], a[2] );
    break;
  case 4:
    r = o[x]( a[0], a[1], a[2], a[3] );
    break;
  case 5:
    r = o[x]( a[0], a[1], a[2], a[3], a[4] );
    break;
  case 6:
    r = o[x]( a[0], a[1], a[2], a[3], a[4], a[5] );
    break;
  default:
    alert( 'Too many arguments to apply.' );
  }
  try {
    delete o[x];
  }
  catch( ex ) {}
  return r;
});

if( !isFunction(Array.prototype.splice) ) {
  Array.prototype.splice=function( start, delCnt ) {
    var max=Math.max;
    var min=Math.min;
    var ret=[]; // The return value array
    var ele;  // element
    var ins=max(arguments.length - 2, 0);   // insert count
    var kdx=0;
    var len=this.length;
    var nlen;  // new length
    var delta;  // delta
    var shift;  // shift count
    if( start < 0 ) {
      start+=len;
    }
    start=max( min(start,len), 0 );  // start point
    delCnt=max( min(isNumber(delCnt)?delCnt:len,len-start), 0);    // delete count
    delta=ins-delCnt;
    nlen=len+delta;
    while( kdx < delCnt ) {
      ele=this[start+kdx];
      if( !isUndefined(ele) ) {
        ret[kdx]=ele;
      }
      kdx+=1;
    }
    shift=len-start-delCnt;
    if( delta < 0 ) {
      kdx=start+ins;
      while( shift ) {
        this[kdx]=this[kdx-delta];
        kdx+=1;
        shift-=1;
      }
      this.length = nlen;
    }
    else if( delta > 0 ) {
      kdx=1;
      while( shift ) {
        this[nlen-kdx]=this[len-kdx];
        kdx+=1;
        shift-=1;
      }
    }
    for( kdx=0; kdx < ins; ++kdx ) {
      this[start+kdx]=arguments[kdx+2];
    }
    return ret;
  }
}


//JavaScript Cookie Handling
function GetCookie( name ) {
  var arg = name + '=';
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while( i < clen ) {
     var j = i + alen;
     if( document.cookie.substring(i,j)  == arg ) {
       return GetCookieVal( j );
     }
     i = document.cookie.indexOf(" ", i) + 1;
     if ( i == 0 ) {
       break;
     }
  }
  return null;
}

function GetCookieVal( offset ) {
  var endstr = document.cookie.indexOf(';',offset);
  if( endstr == -1 ) {
    endstr = document.cookie.length;
  }
  return( unescape( document.cookie.substring(offset,endstr) )  );
}


var firstslash=location.href.indexOf('/')
//var firstbackslash=location.href.indexOf('\\')
var slash=location.pathname.lastIndexOf('/')
var backslash=location.pathname.lastIndexOf('\\')
if( slash < backslash ) {
  slash=backslash
}
//if( firstslash > firstbackslash ) {
//  firstslash=firstbackslash
//}

var prefix=location.href.substring(firstslash+2,location.href.indexOf('.'))
var filename=location.pathname.substring(slash+1,location.pathname.length)
var url="" + window.location;

function windowDimensions() {
  this.height;
  this.width;
}

function GetWindowDimensions( height, width ) {
   var myWidth = 0, myHeight = 0;
   var wD=new windowDimensions();
   if( typeof( window.innerWidth ) == 'number' ) {
      //Non-IE
      myWidth = window.innerWidth;
      myHeight = window.innerHeight;
   } else if( top.document.documentElement && ( top.document.documentElement.clientWidth || top.document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = top.document.documentElement.clientWidth;
      myHeight = top.document.documentElement.clientHeight;
   } else if( top.document.body && ( top.document.body.clientWidth || top.document.body.clientHeight ) ) {
      //IE 4 compatible
      myWidth = top.document.body.clientWidth;
      myHeight = top.document.body.clientHeight;
   }
   wD.height=myHeight;
   wD.width=myWidth;
   return(wD);
 }

function SetCookie( name, value ) {
  var expires=new Date();
  var thisYear=expires.getYear() + 1;
  expires.setYear( thisYear );
  document.cookie = name + '=' + escape(value)
    + '; expires=' + expires.toGMTString()
    + '; path=/'
    + '; domain=.flica.net'
}

function DeleteCookie( name ) {
  if( GetCookie(name) ) {
    document.cookie = name + '=' +
    '; path=/' +
    '; domain=.flica.net'
    '; expires=Thu, 01-Jan-70 00:00:01 GMT';
  }
}

function cookieGet( name ) {
  //alert( name );
  if (document.cookie) {
    index = document.cookie.indexOf(name);
    if (index != -1) {
      namestart = (document.cookie.indexOf("=", index) + 1);
      nameend = document.cookie.indexOf('cbEndCookie;', index);
      if (nameend == -1) {
        nameend = 0;
      }
      var getstr = document.cookie.substring(namestart, nameend);
      //alert( getstr );
      return getstr;
    }
  }
}

function cookieSet( name,  val ) {
  if (document.cookie != document.cookie) {
    index = document.cookie.indexOf(name);
  } else {
    index = -1;
  }
  if (index == -1) {
    document.cookie=name+"="+val+"cbEndCookie; expires=Monday, 04-Apr-2020 05:00:00 GMT"+ '; path=/'+ '; domain=.flica.net';
  }
}

function cookieDelete( name ) {
  if (document.cookie != document.cookie) {
    index = document.cookie.indexOf(name);
  } else {
    index = -1;
  }
  if (index == -1) {
    document.cookie=name+"=GONEcbEndCookie; expires=Monday, 19-Aug-1996 05:00:00 GMT"+ '; path=/'+ '; domain=.flica.net';
  }
  //document.location.href = document.location.href;
  //to reload without queryString parameters, use the line below instead
  //document.location = document.location.href.substring(0,document.location.href.indexOf("?"));
}

//End of Javascript Cookie Handling

var theMapOfAllElements={};

function getUniqueElement( id ) {
  var a=theMapOfAllElements[id];
  if( a != null ) {
    return a;
  }
  return( theMapOfAllElements[id]=document.getElementById(id) );
}
function removeUniqueElement( id ) {
  var a=theMapOfAllElements[id];
  if( a == null ) {
      return;
  }
  theMapOfAllElements[id]=null;
}
var theMapOfTheFrames={};

function getFrameWindow( name ) {
  var f=theMapOfTheFrames[name];
  if( f != null ) {
    return f;
  }
  var elem=document.getElementById( name );
  if( !elem ) {
    return null;
  }
  var cw=elem.contentWindow;
  if( cw ) {
    return( theMapOfTheFrames[name]=cw );
  }
  return( theMapOfTheFrames[name]=window[name] );
}

// End remedial script

Number.prototype.pad=function( places ) {
  if( places == null ) {
    places=2;
         }
  var str='';
  for( var idx=1; idx < places; idx++ ) {
    if( this < Math.pow(10,idx) ) {
      str+='0';
    }
  }
  return str+this;
}

String.prototype.isDigit=function() {
  return (/^\d$/).test( this );
}

String.prototype.isAlpha=function() {
  return (/^[a-zA-Z]$/).test( this );
}

String.prototype.isAllAlpha=function() {
  return (/^[a-zA-Z]+$/).test( this );
}

String.prototype.isAllAlNum=function() {
  return (/^\w+$/).test( this );
}

String.prototype.isAlNum=function() { // Accepts '_'
  return (/^\w+$/).test( this );
}

String.prototype.isSafe=function() {
  return this.isAlNum() || this == ' ' || this == ',';
}

String.prototype.isSpace=function() {
  return (/^\s$/).test( this );
}

String.prototype.isAllDigits=function() { // Accepts the empty string
  return (/^\d*$/).test( this );
}

String.prototype.isNumeric=function() { // Does not accept the empty string
  return (/^\d+$/).test( this );
}

String.prototype.trim=function() {
  var idx=this.search( /[ ]+$/ );
  if( idx != -1 ) {
    return this.substring( 0, idx );
  }
  return this;
}

// objects.js - Utility objects

function Pair( first, second )
{
  this.first=first;
  this.second=second;
}

var Months=[ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
var SMonths=[ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
var Days=[ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
var SDays=[ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ];
var ShortDays=SDays; // Unfortunately, some script redefines SDays, so we have to use this alternative to reduce the risk of script errors
var DayCount=[ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

function isLeapYear( year ) {
  if( year < 1900 ) {
    year+=1900;
  }
  return year%400 == 0 || year%4 == 0 && year%100 !=0;
}

function getFirstDay( month, year ) {
  return ( new Date(year,month,1) ).getDay();
}

var tfFullAbbreviated="FullAbbreviated";  // Fri Feb 04, 2005 12:00
var tfFullYYYYSpaces="FullYYYYSpaces";    // 2005 02 04 12:00
var tfYYYYMMDDHHMMSS="YYYYMMDDHHMMSS";    // 20050204120000
var tfCompact="YYYYMMDDHHMMSS";           // Same as above
var tfCompactFullTime="CompactFullTime";// February 04, 2005 12:30:00
var tfYYYYMMDD="YYYYMMDD";                // 20050204
var tfMonthDDYYYY="MonthDDYYYY";          // February 04, 2005
var tfMonDDYYYY="MonDDYYYY";              // Feb 04, 2005
var tfMM_DD_YY="MM_DD_YY";                // 04/02/05
var tfLastUpdated="LastUpdated";          // 04/02/2005 12:00:00
var tfMonYYYY="MonYYYY";                  // Feb2005
var tfMon_YYYY="Mon_YYYY";                // Feb 2005
var tfDDMon="DDMon";                      // 20FEB
var tfMM_DD_YYYY_HH_MM="LastUpdated2";    // 04/02/2005 12:00
var tfMM_DD_YY_HH_MM_SS="LastUpdated3";   // 04/02/2005 12:00:00
var tfYYYY_MM_DD_HH_MM='_YYYYMMDDHHMM';   // 2005 04 02 12:00
var tfHHMMnc='HHMMnc';                    // HHMM (24 hour, no colons)
var tfHHMM='HHMM';                        // HH:MM 24 hour

Number.prototype.isLeapYear=function() {
  if( this < 100 && this > 0 ) { // Assume 19XX
    return this%4 == 0;
  }
  else if( this >= 100 && this < 3000 ) {
    return this%400 == 0 || this%4 == 0 && this%100 !=0;
  }
  throw Error( 'Number.isLeapYear: Invalid value '+this );
}

Date.prototype.toString=function( format, gmt ) {
  if( gmt == null ) {
    gmt='';
  }
  else {
    gmt='UTC';
  }
  if( isUndefined(format) ) {
    format=tfFullAbbreviated;
  }
  var str='';
  if( format == tfFullAbbreviated ) {
    str=ShortDays[this['get'+gmt+'Day']()]+' '+SMonths[this['get'+gmt+'Month']()]+' ';
    str+=this['get'+gmt+'Date']().pad()+', '+this['get'+gmt+'FullYear']()+' '+this['get'+gmt+'Hours']().pad()+':'+this['get'+gmt+'Minutes']().pad();
  }
  else if( format == tfMonDDYYYY ) {
    str+=SMonths[this['get'+gmt+'Month']()]+' '+this['get'+gmt+'Date']().pad()+', '+this['get'+gmt+'FullYear']();
  }
  else if( format == tfFullYYYYSpaces ) {
    str+=this['get'+gmt+'FullYear']()+' '+this['get'+gmt+'Month']().pad()+' '+this['get'+gmt+'Date']().pad()+' '+this['get'+gmt+'Hours']().pad()+':'+this['get'+gmt+'Minutes']().pad();
  }
  else if( format == tfYYYYMMDDHHMMSS ) {
    str+=this['get'+gmt+'FullYear']()+(this['get'+gmt+'Month']()+1).pad()+this['get'+gmt+'Date']().pad()+this['get'+gmt+'Hours']().pad()+this['get'+gmt+'Minutes']().pad()+this['get'+gmt+'Seconds']().pad();
  }
  else if( format == tfYYYYMMDD ) {
    str+=this['get'+gmt+'FullYear']()+(this['get'+gmt+'Month']()+1).pad()+this['get'+gmt+'Date']().pad();
  }
  else if( format == tfMonthDDYYYY ) {
    str+=Months[this['get'+gmt+'Month']()]+' '+this['get'+gmt+'Date']().pad()+', '+this['get'+gmt+'FullYear']();
  }
  else if( format == tfCompactFullTime ) {
    str+=Months[this['get'+gmt+'Month']()]+' '+this['get'+gmt+'Date']().pad()+', '+this['get'+gmt+'FullYear']()+' '+this['get'+gmt+'Hours']().pad()+':'+this['get'+gmt+'Minutes']().pad()+':'+this['get'+gmt+'Seconds']().pad();
  }
  else if( format == tfMM_DD_YY ) {
    str+=(this['get'+gmt+'Month']()+1).pad()+'/'+this['get'+gmt+'Date']().pad()+'/'+(this['get'+gmt+'FullYear']()%100).pad();
  }
  else if( format == tfMonYYYY ) {
    str+=SMonths[this['get'+gmt+'Month']()]+this['get'+gmt+'FullYear']();
  }
  else if( format == tfMon_YYYY ) {
    str+=SMonths[this['get'+gmt+'Month']()]+' '+this['get'+gmt+'FullYear']();
  }
  else if( format == tfLastUpdated ) {
    str+=(this['get'+gmt+'Month']()+1).pad()+'/'+this['get'+gmt+'Date']().pad()+'/'+this['get'+gmt+'FullYear']()+' '+this['get'+gmt+'Hours']().pad()+':'+this['get'+gmt+'Minutes']().pad()+':'+this['get'+gmt+'Seconds']().pad();
  }
  else if( format == tfMM_DD_YYYY_HH_MM ) {
    str+=(this['get'+gmt+'Month']()+1).pad()+'/'+this['get'+gmt+'Date']().pad()+'/'+this['get'+gmt+'FullYear']()+'&nbsp;'+this['get'+gmt+'Hours']().pad()+':'+this['get'+gmt+'Minutes']().pad();
  }
  else if( format == tfMM_DD_YY_HH_MM_SS ) {
    str+=(this['get'+gmt+'Month']()+1).pad()+'/'+this['get'+gmt+'Date']().pad()+'/'+(this['get'+gmt+'FullYear']()%2000).pad()+'&nbsp;'+this['get'+gmt+'Hours']().pad()+':'+this['get'+gmt+'Minutes']().pad()+':'+this['get'+gmt+'Seconds']().pad();
  }
  else if( format == tfDDMon ) {
    str=this['get'+gmt+'Date']().pad()+SMonths[this['get'+gmt+'Month']()];
    str=str.toUpperCase();
  }
  else if( format == tfYYYY_MM_DD_HH_MM ) {
    str+=(this['get'+gmt+'FullYear']()).pad()+' '+(this['get'+gmt+'Month']()+1).pad()+' '+this['get'+gmt+'Date']().pad()+' '+this['get'+gmt+'Hours']().pad()+':'+this['get'+gmt+'Minutes']().pad()+':'+this['get'+gmt+'Seconds']().pad();
  }
  else if( format == tfHHMMnc ) {
    str+=this['get'+gmt+'Hours']().pad()+this['get'+gmt+'Minutes']().pad();
  }
  else if( format == tfHHMM ) {
    str+=this['get'+gmt+'Hours']().pad()+':'+this['get'+gmt+'Minutes']().pad();
  }
  return str;
}

Date.prototype.fromString=function( str, format, gmt ) {
  if( gmt == null ) {
    gmt='';
  }
  else {
    gmt='UTC';
  }
  // Check for errors
  if( isUndefined(format) ) {
    throw Error( 'Date.fromString: null format' );
//    format=tfFullAbbreviated;
  }
  try {
    /* NOTE NOTE NOTE!! The date MUST BE SET FIRST or else setMonth may fail if the date is currently above the max for the month */
    if( format == tfYYYYMMDDHHMMSS || format == tfCompact ) {
      this['set'+gmt+'Month']( 0 );
      this['set'+gmt+'Date']( eval(str.slice(6,8)) );
      this['set'+gmt+'Month']( eval(str.slice(4,6))-1 );
      this['set'+gmt+'FullYear']( eval(str.slice(0,4)) );
      this['set'+gmt+'Hours']( eval(str.slice(8,10)) );
      this['set'+gmt+'Minutes']( eval(str.slice(10,12)) );
      this['set'+gmt+'Seconds']( eval(str.slice(12,14)) );
      this['set'+gmt+'Milliseconds']( 0 );
    }
    else if( format == tfYYYYMMDD ) {
      this['set'+gmt+'Month']( 0 );
      this['set'+gmt+'Date']( eval(str.slice(6,8)) );
      this['set'+gmt+'Month']( eval(str.slice(4,6))-1 );
      this['set'+gmt+'FullYear']( eval(str.slice(0,4)) );
      this['set'+gmt+'Hours']( 0 );
      this['set'+gmt+'Minutes']( 0 );
      this['set'+gmt+'Seconds']( 0 );
      this['set'+gmt+'Milliseconds']( 0 );
    }
    else if( format == tfYYYY_MM_DD_HH_MM ) {
      this['set'+gmt+'Month']( 0 );
      this['set'+gmt+'Date']( eval(str.slice(8,10)) );
      this['set'+gmt+'Month']( eval(str.slice(5,7))-1 );
      this['set'+gmt+'FullYear']( eval(str.slice(0,4)) );
      this['set'+gmt+'Hours']( eval(str.slice(11,13)) );
      this['set'+gmt+'Minutes']( eval(str.slice(14,16)) );
      this['set'+gmt+'Seconds']( 0 );
      this['set'+gmt+'Milliseconds']( 0 );
    }
  }
  catch( ex ) {
    alert( 'Exception in Date.prototype.fromString: '+ex.message+' (format='+format+', str='+str+')' );
  }
  if( typeof(this.toElement) == 'function' ) {
    this.toElement();
  }
}

Date.prototype.addYears=function( years ) {
  this.setYear( this.getYear()+years );
  if( typeof(this.toElement) == 'function' ) {
    this.toElement();
  }
}

Date.prototype.addMonths=function( months ) {
  this.setMonth( this.getMonth()+months );
  if( typeof(this.toElement) == 'function' ) {
    this.toElement();
  }
}

var ThrowCautionToTheWinds; // For some GOD FORSAKEN STUPID LAME REASON, adding addDays to the prototype screws everything up.

if( ThrowCautionToTheWinds ) {
  Date.prototype.addDays=function( days ) {
    this.setDate( this.getDate()+days );
  }
  if( typeof(this.toElement) == 'function' ) {
    this.toElement();
  }
}

Date.prototype.addHours=function( hours ) {
  this.setHours( this.getHours()+hours );
  if( typeof(this.toElement) == 'function' ) {
    this.toElement();
  }
}

Date.prototype.addMinutes=function( minutes ) {
  this.setMinutes( this.getMinutes()+minutes );
  if( typeof(this.toElement) == 'function' ) {
    this.toElement();
  }
}

Date.prototype.addSeconds=function( seconds ) {
  this.setTime( this.getTime()+(seconds*1000) );
  if( typeof(this.toElement) == 'function' ) {
    this.toElement();
  }
}

Date.prototype.asDayMinutes=function() {
  return this.getHours()*60+this.getMinutes()
}

Date.prototype.set=function( rhs ) {
  this.setTime( rhs.getTime() );
  if( typeof(this.toElement) == 'function' ) {
    this.toElement();
  }
}

function transformDateFormat( s, oldF, newF ) {
  var d=new Date();
  d.fromString( s, oldF );
  return d.toString( newF );
}

function DateToStr( dt, format, gmt ) {
   return( dt.toString(format,gmt) );
}

function ExtractMonth( str ) {
   if( str.length > 6 )
    return( str.substring(4,6) );
   else if( str.length > 4 )
    return( str.substring(4) );
   else
    return( str );
}

// Legacy code, may thy name be cursed...

function DayRight( form )
{
  try {
    var mydate = new Date();
    if( parseInt(ExtractMonth(form.Month.options[form.Month.selectedIndex].value),10)  == 2) { // February
      form.Day.options.length = 28;
      var yr=mydate.getYear();
      if ( form.Month.selectedIndex < mydate.getMonth() ) {
        yr+=1;
      }
      if( yr.isLeapYear() ) {
        form.Day.options.length = 29;
        form.Day.options[28].text = form.Day.options[28].value = '29';
      }
    }
    else {
      form.Day.options.length=DayCount[form.Month.selectedIndex];
      for( var idx=28; idx < form.Day.options.length; idx++ ) {
        form.Day.options[idx].text=form.Day.options[28].value=''+(idx+1);
      }
    }
  }
  catch( ex ) {
    throw Error( ex.message+' in basicfunc.js/DayRight()' );
  }
}

function populateDaySelectElement( month, daySelectElement, year, notzerobased ) { // January=0
  if( notzerobased != null  && notzerobased ) {
    month=parseInt(ExtractMonth(''+month),10)-1;
  }
  if( month != 1 ) { // Not February
    daySelectElement.selectedIndex=Math.min( DayCount[month]-1, daySelectElement.selectedIndex );
    daySelectElement.length=DayCount[month];
    for( var idx=28; idx < daySelectElement.length; idx++ ) {
      daySelectElement[idx].text=daySelectElement[idx].value=''+(idx+1);
    }
  }
  else {
    var days=DaysInMonth( month+1, year!=null?year:new Date().getFullYear() )
    daySelectElement.selectedIndex=Math.min( days-1, daySelectElement.selectedIndex );
    daySelectElement.length=days;
  }
}

function initializeMonthSelectElement( elem, sIdx ) {
  if( isUndefined(sIdx) ) {
    sIdx=0;
  }
  if( elem.options.length == 0 ) {
    for( var idx=0; idx < 12; idx++ ) {
      var opt=document.createElement( 'option' );
      opt.text=SMonths[idx].toUpperCase();
      opt.value=idx.pad();
      addSelect( elem, opt, idx+1 );
    }
    elem.registerDaySelectElement=function( delem ) {
      this.dayElement=delem;
      this.onchange=function() {
        populateDaySelectElement( this.selectedIndex, this.dayElement );
      }
      populateDaySelectElement( sIdx, this.dayElement );
    }
  }
  elem.selectedIndex=sIdx;
}

function initializeMonthSelectElement2( elem, sIdx, start, end, today, StartFromToday ) {
  if( isUndefined(sIdx) ) {
    sIdx=0;
  }
  startmonth=parseInt(start.substring(4,6),10)-1;
  startyear=parseInt(start.substring(0,4),10);
  endmonth=parseInt(end.substring(4,6),10)-1;
  endyear=parseInt(end.substring(0,4),10);
  today=parseInt(today.substring(0,6),10);
  if( elem.options.length == 0 ) {
    if( startyear != endyear ) {
      for( var jdx=startyear; jdx <= endyear; jdx++ ) {
        for( var idx=0; idx < 12; idx++ ) {
          var thisval=parseInt(jdx+''+(idx+1).pad(),10)
          if(  (thisval < today) && StartFromToday ) {
            continue;
          }
          var opt=document.createElement( 'option' );
          opt.text=SMonths[idx].toUpperCase()+' '+jdx;
          opt.value=(idx.pad()+1)+jdx;
          opt.selected=today==thisval;
          addSelect( elem, opt, idx+1 );
        }
      }
    }
    else {
        for( var idx=startmonth; idx <= endmonth; idx++ ) {
          var thisval=parseInt(startyear+''+(idx+1).pad(),10)
          if( (thisval<today) && StartFromToday ) {
            continue;
          }
          var opt=document.createElement( 'option' );
          opt.text=SMonths[idx].toUpperCase()+' '+startyear;
          opt.value=(idx.pad()+1)+startyear;
          opt.selected=today==thisval;
          addSelect( elem, opt, idx+1 );
        }
    }
    elem.registerDaySelectElement=function( delem ) {
      this.dayElement=delem;
      this.onchange=function() {
        //populateDaySelectElement( this.value.substring(0,2)selectedIndex%12, this.dayElement );
        populateDaySelectElement( parseInt(this.value.substring(0,2),10)%12, this.dayElement );
      }
      populateDaySelectElement( sIdx%12, this.dayElement );
    }
  }
  //elem.selectedIndex=sIdx;
}


function initializeDaySelectElement( elem, sIdx ) {
  if( !elem.options.length ) {
    for( var idx=1; idx < 32; idx++ ) {
      var opt=document.createElement( 'option' );
      opt.text=opt.value=idx.pad();
      addSelect( elem, opt, idx+1 );
    }
  }
  if( isUndefined(sIdx) ) {
    sIdx=0;
  }
  elem.selectedIndex=sIdx;
}

function DaysInMonth( month, yr ) // January=1
{
  if( month != 2 ) { // Not February
    return DayCount[month-1];
  }
  return yr.isLeapYear() ? 29 : 28;
}

function splitOptions( strArray, fromUrl ) {
  var obj={};
  for( var idx=0; idx < strArray.length; idx++ ) {
    var opt=strArray[idx].split( '=' );
    if( opt.length < 2 ) {
      continue;
    }
    if( fromUrl == null ) {
      obj[opt[0]]=opt[1];
      continue;
    }
    opt[0]=opt[0].toLowerCase();
    switch( opt[1].slice(0,1) ) {
    case '_':
      obj[opt[0]]=new Number( atoi(opt[1].slice(1)) );
      break;
    case '~':
      switch( opt[1].slice(1) ) {
      case 'true': case '1': case 't':
        obj[opt[0]]=true;
        break;
      case 'false': case '0': case 'f': case '': case null:
        obj[opt[0]]=false;
        break;
      default:
        obj[opt[0]]=null;
      }
      break;
    default:
      obj[opt[0]]=opt[1];
    }
  }
  return obj;
}

function getOptions( str ) {
  try {
    return splitOptions( decodeURI(str).slice( 1 ).split('&'), true );
  }
  catch( ex ) { // IE 5, and possibly 5.5, cannot handle decodeURI
    return splitOptions( unescape(str).slice( 1 ).split('&'), true );
  }
}

var windowOptions=getOptions( window.location.search );

if( isUndefined(window['allElements']) ) {
  window['allElements']={};
}

function addElements() {
  for( var idx=0; idx < addElements.arguments.length; idx++ ) {
    allElements[addElements.arguments[idx]]='byId';
  }
}

function addNamedElements() {
  for( var idx=0; idx < addNamedElements.arguments.length; idx++ ) {
    allElements[addNamedElements.arguments[idx]]='byName';
  }
}

function initializeElements() {
  for( elem in allElements ) {
    try {
      if( typeof allElements[elem] == 'function' ) {
        continue;
      }
      if( allElements[elem] == 'byId' ) {
        window[elem]=document.getElementById( elem );
      }
      else if( allElements[elem] == 'byName' ) {
        window[elem+'s']=document.getElementsByName( elem );
      }
      else {
        alert( 'initializeElements failed: allElements['+elem+']='+allElements[elem] );
      }
    }
    catch( ex ) {}
  }
}

var toolbar=',toolbar=yes';
var status=',status=yes';
var uselocation=',location=yes';
var menubar=',menubar=yes';
var resizable=',resizable=yes';
var noscroll=',scrollbars=no';
var junkdate='junkdate';
var alwaysRaised='alwaysRaised=yes';
var popup, popupDocument;

if( popup == null ) {
  popup=function( width, height, url, wname ) {
    try {
      var count=0;
      var scrollspecified=false;
      count++;
      var opts='';
      count++;
      var left=( screen.width-width )/2;
      count++;
      var top=( screen.height-height )/2;
      count++;
      if( popup.arguments.length < 4 || wname == null ) {
        wname=''+(new Date()).valueOf();
      }
      count++;
      if( url.indexOf('?') == -1 ) {
        url+='?';
      }
      count++;
      for( var i=4; i < popup.arguments.length; i++ ) {
        count+=10;
        if( popup.arguments[i] == noscroll ) {
          scrollspecified=true;
        }
        else if( popup.arguments[i] == junkdate ) {
          url+='&junkdate='+(new Date()).valueOf();
          continue;
        }
        if( !popup.arguments[i] ) {
          continue;
        }
        opts+=popup.arguments[i];
      }
      count++;
      if( !scrollspecified ) {
        opts+=',scrollbars=yes';
      }
      count++;
      try {
        var pWin=open( url, wname, 'width='+width+',height='+height+',left='+left+',top='+top+opts );
        count++;
      }
      catch( ex ) {
        alert( 'A FLiCA window has been blocked.\nPlease verify the settings on all programs that may be blocking the popup.' );
        return null;
        //reportScriptError( 'open() failed, nothing popped up: url='+url+', msg='+ex.message, true );
        //return;
      }
      if( pWin != null ) {
        try {
          pWin.focus();
          if( pWin.screenX != null ) {
            pWin.screenX=left;
            pWin.screenY=top;
          }
        }
        catch( ex ) {}
        return pWin;
      }
      alert( 'A FLiCA window has been blocked.\nPlease verify the settings on all programs that may be blocking the popup.' );
      return null;
    }
    catch( ex ) {
      throw Error( ex.message+' in popup.js/popup(), count='+count );
    }
  }
}

function popupWebHelp( file ) {
  window.open( 580, 400, '/rbc/webhelp_popup.cgi?MyURL='+file, resizable );
}

var dtStrict="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"
var dtTransitional="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html40/loose.dtd\">"

if( popupDocument == null ) {
  popupDocument=function( win, title, style, dt ) {
    try{
      if( !win ) {
        return;
      }
      var doc=win.document;
      if( title == null ) {
        title='FLiCA.Net';
      }
      if( dt != null ) {
        doc.writeln( dt );
      }
      if( style == null ) {
        style='';
      }
      doc.writeln( "<html>" );
      doc.writeln( "  <head id=\"theHead\">" );
      doc.writeln( "    <title>"+title+"</title>" );
      doc.writeln( "    <meta http-equiv=\"Pragma\" name=\"Pragma\" content=\"no-cache\">" );
      doc.writeln( "    <meta http-equiv=\"Cache-Control\" meta.content=\"no-cache\">" );
      doc.writeln( "    <meta name=\"robots\" content=\"noindex\">" );
      doc.writeln( "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" );
      doc.writeln( "    <style type=\"text/css\">\n"+style+"</style>" );
      doc.writeln( "  </head>" );
      doc.writeln( "  <body id=\"theBody\">" );
      doc.writeln( "</body></html>" );
      doc.close();
      this.head=doc.getElementById( "theHead" );
      this.headScript=this.head.appendChild( doc.createElement("script") );
      this.body=doc.getElementById( "theBody" );
      this.createElement=doc.createElement;
    }
    catch( ex ) {
      throw Error( ex.message+' in popup.js/popupDocument()' );
    }
  }
}

var modalGearboxWindow;
var focuser;
var bGearBoxClosed=false;

function maintainFocus() {
  try {
    if( modalGearboxWindow.closed  && bGearBoxClosed ) {
      window.clearInterval( focuser );
      return;
    }
    if( !bGearBoxClosed ) {
      modalGearboxWindow.focus();
    }
  }
  catch( ex ) {}
}

function showModalGearbox( wd, hi, scrollable ) {
  if( wd == null ) {
    wd=360;
  }
  if( hi == null ) {
    hi=200;
  }
  if( scrollable == null ) {
    modalGearboxWindow=popup( wd, hi, '/public/timeticker.html', 'GearBox', noscroll, resizable );
  }
  else if(  scrollable ) {
    modalGearboxWindow=popup( wd, hi, '/public/timeticker.html', 'GearBox', resizable );
  }
  bGearBoxClosed=false;
  focuser=window.setInterval( "maintainFocus()", 250 );
}

function hideModalGearbox() {
  if( !bGearBoxClosed ) {
    if( modalGearboxWindow && modalGearboxWindow.open ) {
        if( modalGearboxWindow.location.href.indexOf( 'confirm' ) == -1 ) {
          modalGearboxWindow.close();
          bGearBoxClosed=true;
        }
    }
  }
}

function ChangeModalUrl( url ) {
  if( !bGearBoxClosed ) {
    if( modalGearboxWindow && modalGearboxWindow.open ) {
      modalGearboxWindow.location=url;
      window.clearInterval( focuser );
    }
  }
}


// Drag.js:
// Drag-and-drop code based on example found in Javascript: The Definitive Guide, by O'Reilly.

function beginDrag( element, event ) {
  var x=parseInt( element.style.left );
  var y=parseInt( element.style.top );
  var deltaX=event.clientX-x;
  var deltaY=event.clientY-y;
  if( document.addEventListener ) {
    document.addEventListener( 'mousemove', moveHandler, true );
    document.addEventListener( 'mouseup', upHandler, true );
  }
  else {
    document.attachEvent( 'onmousemove', moveHandler );
    document.attachEvent( 'onmouseup', upHandler );
  }
  if( event.stopPropagation ) {
    event.stopPropagation();
  }
  else {
    event.cancelBubble=true;
  }
  if( event.preventDefault ) {
    event.preventDefault();
  }
  else {
    event.returnValue=false;
  }

  function moveHandler( e ) {
    if( !e ) {
      e=window.event;
    }
    element.style.left=(e.clientX-deltaX)+'px';
    element.style.top=(e.clientY-deltaY)+'px';
    if( e.stopPropagation ) {
      e.stopPropagation();
    }
    else {
      e.cancelBubble=true;
    }
  }

  function upHandler( e ) {
    if( !e ) {
      e=window.event;
    }
    if( document.removeEventListener ) {
      document.removeEventListener( 'mouseup', upHandler, true );
      document.removeEventListener( 'mousemove', moveHandler, true );
    }
    else {
      document.detachEvent( 'onmouseup', upHandler );
      document.detachEvent( 'onmousemove', moveHandler );
    }
    if( e.stopPropagation ) {
      e.stopPropagation();
    }
    else {
      e.cancelBubble=true;
    }
  }
}

function filterKeys(        // A versatile key handler for onKeyPress events
  e,                          // event (for the benefit of NS-model browsers)
  keyFilter,                  // Can be a String function (such as isAlpha), a generic function that takes a single-character string
                                 // and returns a character or null (null prevents the keystroke from being registered), or a string
                                 // of characters to allow.
                                 // IMPORTANT NOTE!  NS/Mozilla browsers do NOT allow you to change the character code that is returned,
                                 // so such functionality will require considerable extra effort and is not implemented here.
  codes )                     // An optional array of character codes to allow (useful for allowing non-printable characters, such as CR)
{
  try {
    var code=window.event.keyCode;
  }
  catch( ex ) {
    code=e.which;
  }
  if( codes && codes.find(code) >= 0 || code == 8 ) { // Always allow backspace
    return true;
  }
  if( !keyFilter ) {
    try {
      window.event.returnValue=false;
    }
    catch( ex ) {}
    return false;
  }
  var theChar=String.fromCharCode( code );
  if( theChar[keyFilter] ) {
    if( theChar[keyFilter]() ) {
      return true;
    }
    try {
      window.event.returnValue=false;
    }
    catch( ex ) {}
    return false;
  }
  if( typeof keyFilter == 'function' ) {
    var ret=keyFilter( theChar );
    if( !ret ) {
      try {
        window.event.returnValue=false;
      }
      catch( ex ) {}
      return false;
    }
    var newcode=ret.charCodeAt( 0 );
    try {
      window.event.keyCode=newcode;
    }
    catch( ex ) {
      e.which=newcode;
    }
    return true;
  }
  if( keyFilter.indexOf(theChar) >= 0 ) {
    return true;
  }
  window.event.returnValue=false;
  return false;
}

function forceDigits() {
  if( window.event.keyCode < 48 && window.event.keyCode != 13 || window.event.keyCode > 57 ) { // 13 is Enter
    window.event.returnValue=false;
    return false;
  }
  return true;
}

function filterSQL(evt) {
  return filterKeys(evt,'_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$^&*()[]{}|~-!@.`')
}

function transformQuotes() {
  switch( window.event.keyCode ) {
  case 34: // Double quote
  case 39: // Single quote
    window.event.keyCode=96; // Back quote
    break;
  default:
  }
}

function captureQuotes() { // Rename me
  switch( window.event.keyCode ) {
  case 13:
    window.event.returnValue=false;
    return false;
  case 34: // Double quote
  case 39: // Single quote
    window.event.keyCode=96; // Back quote
    break;
  default:
  }
  return true;
}

function cookieEncode( str ) {
  if( !str ) {
    return '';
  }
  if( !str.replace ) { // Not a string
    return str;
  }
  return str.replace( / /g, '+' ).replace( /[;%'"]/g, escape );
}

function cookieDecode( str ) {
  return unescape( str ).replace( /\+/g, ' ' );
}

function niBoolOpt( str ) {
  if( !this[str] || this[str] == '0' || this[str] == 'f' || this[str] == 'F' || this[str] == 'false' ) {
    return false;
  }
  return true;
}

function NamedItemObject( str ) {
  this.fromString( str );
  this.boolOpt=niBoolOpt;
}

NamedItemObject.prototype.fromString=function( str ) {
  if( str != null ) {
    var array=str.split( ';' );
    for( var idx=0; idx < array.length; idx++ ) {
      var item=array[idx].split( '=' );
      if( item.length != 2 ) {
        continue;
      }
      this[item[0]]=cookieDecode( item[1] );
    }
  }
}

NamedItemObject.prototype.toString=function() {
  var str='';
  for( field in this ) {
    if( field == 'oldValues' || !this[field] || typeof this[field] == 'function' ) {
      continue;
    }
    str+=cookieEncode( field )+'='+cookieEncode( this[field] )+';';
  }
  return str;
}

function cookieHasChangedFunc() {
  for( field in this ) {
    if( field == 'oldValues' || typeof this[field] == 'function' ) {
      continue;
    }
    if( this[field] != this.oldValues[field] ) {
      return true;
    }
  }
  return false;
}

function cookieHasOptionChangedFunc( field ) {
  return this[field] != this.oldValues[field];
}

function Cookie( str ) {
  this.fromString( str );
  this.oldValues=new NamedItemObject( str );
  this.hasChanged=cookieHasChangedFunc;
  this.optionChanged=cookieHasOptionChangedFunc;
}

Cookie.prototype=new NamedItemObject( '' );
Cookie.prototype.constructor=Cookie;

var CheckedBT=false;//checked broswer type already
var IsIE4=false;
var IsIE5=false;
var IsIE6=false;
var IsNAV6=false;
var bar;//temporary, need to remove when references to 'bar' are changed in cgis (ask Desi)
var progressBarWin;
var progressBarOpenRequest=false;
var progressBarCloseRequest=false;

function openProbar( cap, pwidth, pheight, x, y ) {
  try {
    var mywidth=380;
    var myheight=100;
    myX=0;
    myY=0;
    if( arguments.length > 1 ) {
      mywidth=pwidth;
    }
    if( arguments.length > 2 ) {
      myheight=pheight;
    }
    if( arguments.length > 3 ) {
      myX=x;
      myY=y;
    }
    if( progressBarCloseRequest ) {
      progressBarOpenRequest=true;
      closeProbar();
      return;
    }
    if( IE5() && myX ) {
      //alert( 'x=' + myX + 'y=' + myY );
      progressBarWin=open( 'blank.html', 'ProgressBar', 'width='+mywidth+', height=100, left='+(myX-mywidth)/2+', top='+(myY-myheight)/2 );
    }
    else {
      progressBarWin=open( 'blank.html', 'ProgressBar', 'width='+mywidth+', height=100' );
    }
    if( NAV6() && myX ) {
      progressBarWin.screenX=myX;
      progressBarWin.screenY=myY;
    }
    bar=progressBarWin// temporary!!!
    var txt ='<html><head><title>FLiCA.Net</title></head>';
        txt+='<body bgcolor="silver"><center><b>' + cap + '</b></center><br>';
    if( myX != 0 ) {
      txt+='<center><img src="/images/progressbar.gif" height="10" width="'+(mywidth-20)+'"></center>';
    }
    else {
      if( IE6() || IE5() || IE4() || NAV6() ) {         // need to check IE6 first
        txt+='<div name="probar" id="probar"></div>'
      }
      else {
        txt+='<layer name="probar" id="probar" top="60" left="5" visibility="show" width=100% height=20></layer>';
      }
    }
    txt+='</body></html>'
    if( progressBarWin ) {
      try{
        progressBarWin.document.write( txt );
        progressBarWin.document.close();
        progressBarWin.focus();
      }
      catch( ex ) {}
    }
    else {
      alert( 'A popup window failed to open.  Please check the settings on any program that may be blocking the popup.' );
    }
    progressBarOpenRequest=true;
  }
  catch( ex ) {
    throw Error( ex.message+' in basicfunc.js/openProbar()' );
  }
}

function drawProbar( percent ) {
  try {
    if( progressBarOpenRequest && progressBarCloseRequest ) {
      closeProbar()
      return;
    }
    if( progressBarWin && !progressBarWin.closed ) {
      if( IE6() || NAV6() ) {
          progressBarWin.document.getElementById('probar').innerHTML='<img src="/images/onebluepixel.gif" height="10" width="' + percent*3 + '">';
      }
      else if( IE5() || IE4() ) {
        progressBarWin.document.all.probar.innerHTML='<img src="/images/onebluepixel.gif" height="10" width="' + percent*3 + '">';
      }
      else {//NS
        with( progressBarWin.document.probar.document ) {
          write( "<img src='/images/onebluepixel.gif' " + "height=10 width='" + percent*3 + "'>" );
          close();
        }
      }
      progressBarWin.focus();
    }
  }
  catch( ex ) {
    throw Error( ex.message+' in basicfunc.js/drawProbar()' );
  }
}

function closeProbar() {
  try {
    progressBarCloseRequest=true;
    if( !progressBarOpenRequest ) {
      return;
    }
    if( progressBarWin && !progressBarWin.closed ) {
      progressBarWin.close();
    }
    progressBarOpenRequest=false;
    progressBarCloseRequest=false;
  }
  catch( ex ) {
    throw Error( ex.message+' in basicfunc.js/closeProbar()' );
  }
}

function IE4() {
  if( IsIE4 ) {
    return true;
  }
  if( CheckedBT ) {
    return false;
  }
  if( BrowserType() == "IE" && BrowserVersion() >= 400 ) {
    IsIE4=true;
    CheckedBT=true
    return true;
  }
  else {
    return false;
  }
}

function IE5() {
  if( IsIE5 ) {
    return true;
  }
  if( CheckedBT ) {
    return false;
  }
  if( BrowserType() == "IE" && BrowserVersion() >= 500 ) {
    IsIE5=true;
    CheckedBT=true
    return true;
  }
  else {
    return false;
  }
}

function IE6() {
  if( IsIE6 ) {
    return true;
  }
  if( CheckedBT ) {
    return false;
  }
  if( BrowserType()=="IE" && BrowserVersion() >= 600 ) {
    IsIE6=true;
    CheckedBT=true
    return true;
  }
  else {
    return false;
  }
}

function NAV4() {
  if( BrowserType()=="NAV" && BrowserVersion()>=400 || BrowserType() == "FFX" ) {
    return true;
  }
  else {
    return false;
  }
}

function NAV6() {
  if( IsNAV6 ) {
    return true;
  }
  if( CheckedBT ) {
    return false;
  }
  if( BrowserType()=="NAV" && BrowserVersion()>=600 || BrowserType() == "FFX" ) {
    IsNAV6=true;
    CheckedBT=true
    return true;
  }
  else {
    return false;
  }
}

function BrowserType() {
  // Detect the Browser Type
  var type;

  if( navigator.userAgent.indexOf("MSIE") != -1 || navigator.userAgent.indexOf("Microsoft Internet Explorer") != -1 ) {
    return "IE";
  }
  else if( navigator.appName.indexOf('Netscape') != -1 ) {
    if( navigator.userAgent.indexOf("Firefox") != -1 ) {
      return "FFX";
    }
    return "NAV";
  }
  return "UNK";
}

function BrowserVersion() {
  var chr;
  var sidx=-1;
  var eidx;

  switch( BrowserType() ) {
  case 'IE':
    if( navigator.userAgent.indexOf("MSIE") != -1 ) {
      sidx=navigator.userAgent.indexOf("MSIE")+4;
      while( navigator.userAgent.charAt( sidx ) == " " ) {
        sidx++;
      }
      var str=navigator.userAgent;
    }
    break;
  case 'NAV':
    if( navigator.userAgent.indexOf("Netscape") != -1 ) {             // only will occur w/ Netscape 6.0 and up
      sidx=navigator.userAgent.indexOf("Netscape");
      if ( navigator.userAgent.indexOf("/") != -1 ) {                  // will be in form of:   Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
        while ( (navigator.userAgent.charAt( sidx )!="/") ) {
          sidx++;
        }
        sidx++;
      }
      var str=navigator.userAgent;
    }
    else if( navigator.appName.indexOf("Netscape") != -1 ) {      // will occur Netscape 4.x and Firefox
      sidx=0;
      while( !navigator.appVersion.charAt(sidx).isDigit() ) {
        sidx++;
      }
      var str=navigator.appVersion;
    }
    break;
  }
  if( sidx == -1 ) {
    return 1;
  }
  eidx=sidx;
  while( (/^[0-9.]$/).test(str.charAt(eidx)) ) {     // if it's a digit or a '.'
    eidx++;
  }
  chr=str.substring( sidx, eidx );  // Version # in X.XX/X.X/X form - convert to hundreds form
  var vr=chr.split( '.' );
  if( vr.length == 1 ) {
    return atoi( vr[0]+'00' );
  }
  else {
    return atoi( vr[0] )*100+atoi( vr[1] )*Math.pow( 10, 2-vr[1].length );
  }
}

// It'd be nice to phase out using this function and switching to the new one (in confirmbox.js)

function confirmBox( cap, ttl, lab1, lab2, myhi, mywd, caption, capcolor, noicon, punct ) {
  try {
    // no punct given defaults to question mark
    // punct=1 period
    // punct=2 exclamation
    var myUrl="/public/confirmbox.cgi?msg="+cap+"&title="+ttl+"&lbl1="+lab1+"&lbl2="+lab2
    var confirmval;
    var boxhi=140;
    var boxwd=380;
    if ( arguments.length >= 6 ) {
        boxhi=myhi;
        boxwd=mywd;
    }
    if ( arguments.length >= 7 ) {
      myUrl+="&Caption="+caption
    }
    if ( arguments.length >= 8 ) {
      myUrl+="&CapColor="+capcolor
    }
    if ( arguments.length >= 9 ) {
      myUrl+="&NoIcon="+noicon
    }
    if ( arguments.length >= 10 ) {
      myUrl+="&Punct="+punct
    }
    //alert(myUrl)
    var bYorN  = window.showModalDialog(  myUrl,confirmval,"DialogHeight:"+boxhi+"px; DialogWidth:"+boxwd+"px; status:no; help:no");
    return( bYorN );
  }
  catch( ex ) {
    if( String(ex.message).search('Access is denied') != -1 ) {
        alert( 'A popup window failed to open.  Please check the settings on any program that may be blocking the popup.' );
        return;
    }
    throw Error( ex.message+' in basicfunc.js/confirmBox()' );
  }
}

// 3 buttons popup
function confirmBox1( cap, ttl, lab1, lab2, lab3, myhi, mywd, caption, capcolor, noicon, punct ) {
  try {
    var confirmval;
    var boxhi=140;
    var boxwd=440;
    var myUrl="/public/confirmbox.cgi?msg="+cap+"&title="+ttl+"&lbl1="+lab1+"&lbl2="+lab2+"&lbl3="+lab3
    if ( arguments.length >= 6 ) {
        boxhi=myhi;
        boxwd=mywd;
    }
    if ( arguments.length >= 8 ) {
      myUrl+="&Caption="+caption

    }
    if ( arguments.length >= 9 ) {
      myUrl+="&CapColor="+capcolor

    }
    if( arguments.length >= 10 && noicon ) {
      myUrl+="&NoIcon="+noicon
    }
    if ( arguments.length == 11 ) {
      myUrl+="&Punct="+punct
    }
    //alert(myUrl)
    var bYorNorC  = window.showModalDialog( myUrl,confirmval,"DialogHeight:"+boxhi+"px; DialogWidth:"+boxwd+"px; status:yes; help:no; scroll: no;");
    return( bYorNorC );
  }
  catch( ex ) {
    if( String(ex.message).search('Access is denied') != -1 ) {
        alert( 'A popup window failed to open.  Please check the settings on any program that may be blocking the popup.' );
        return;
    }
    throw Error( ex.message+' in basicfunc.js/confirmBox1()' );
  }
}
// 4 button popup
function confirmBox2( cap, ttl, lab1, lab2, lab3, lab4, myhi, mywd, caption, capcolor, noicon, punct ) {
  try {
    var confirmval;
    var boxhi=140;
    var boxwd=440;
    var myUrl="/public/confirmbox.cgi?msg="+cap+"&title="+ttl+"&lbl1="+lab1+"&lbl2="+lab2+"&lbl3="+lab3+"&lbl4="+lab4
    if ( arguments.length >= 7 ) {
        boxhi=myhi;
        boxwd=mywd;
    }
    if ( arguments.length >= 9 ) {
      myUrl+="&Caption="+caption

    }
    if ( arguments.length >= 10 ) {
      myUrl+="&CapColor="+capcolor

    }
    if( arguments.length >= 11 && noicon ) {
      myUrl+="&NoIcon="+noicon
    }
    if ( arguments.length == 12 ) {
      myUrl+="&Punct="+punct
    }
    //alert(myUrl)
    var bYorNorC  = window.showModalDialog( myUrl,confirmval,"DialogHeight:"+boxhi+"px; DialogWidth:"+boxwd+"px; status:yes; help:no; scroll: no;");
    return( bYorNorC );
  }
  catch( ex ) {
    if( String(ex.message).search('Access is denied') != -1 ) {
        alert( 'A popup window failed to open.  Please check the settings on any program that may be blocking the popup.' );
        return;
    }
    throw Error( ex.message+' in basicfunc.js/confirmBox1()' );
  }
}

// any button popup (up to 5 for now because the CGI only supports for 5)
function confirmBoxN( cap, ttl, myhi, mywd, caption, capcolor, noicon, punct, lab1, lab2, lab3, lab4, lab5 ) {
  try {
    var confirmval;
    var boxhi=140;
    var boxwd=440;
    if( myhi ) {
        boxhi=myhi;
    }
    if( mywd ) {
        boxwd=mywd;
    }
    var myurl="/public/confirmbox.cgi?msg="+cap+"&title="+ttl;
    if( caption != '' ) {
      myurl+="&Caption="+caption;
    }
    if( capcolor != '' ) {
      myurl+="&CapColor="+capcolor;
    }
    if( noicon != '' ) {
      myurl+="&NoIcon="+noicon;
    }
    if( punct != '' ) {
      myurl+="&Punct="+punct;
    }
    if( arguments.length >= 9 && lab1 != '' ) {
      myurl+="&lbl1="+lab1;
    }
    if( arguments.length >= 10 && lab2 != '' ) {
      myurl+="&lbl2="+lab2;
    }
    if( arguments.length >= 11 && lab3 != '' ) {
      myurl+="&lbl3="+lab3;
    }
    if( arguments.length >= 12 && lab4 != '' ) {
      myurl+="&lbl4="+lab4;
    }
    if( arguments.length >= 13 && lab5 != '' ) {
      myurl+="&lbl5="+lab5;
    }
    //alert(myUrl)
    var bYorNorC  = window.showModalDialog( myurl,confirmval,"DialogHeight:"+boxhi+"px; DialogWidth:"+boxwd+"px; status:yes; help:no; scroll: no;");
    return( bYorNorC );
  }
  catch( ex ) {
    if( String(ex.message).search('Access is denied') != -1 ) {
        alert( 'A popup window failed to open.  Please check the settings on any program that may be blocking the popup.' );
        return;
    }
    throw Error( ex.message+' in basicfunc.js/confirmBox1()' );
  }
}

function leadingZeros( val, strlength ) {
  try {
    if ( val.length < strlength ) {
      for( var idx = val.length; idx < strlength; idx++ ) {
            val = '0' + val;
      }
    }
    return (val);
  }
  catch( ex ) {
    throw Error( ex.message+' in basicfunc.js/leadingZeros()' );
  }
}

function DayRight( form )
{
  try {
    var mydate = new Date();
    if(form.Month.options[form.Month.selectedIndex].value  == 2) { // February
      form.Day.options.length = 28;
      var yr=mydate.getYear();
      if ( parseInt(form.Month.options[form.Month.selectedIndex].value, 10) < (mydate.getMonth()+1) ) {
        yr+=1;
      }
      if( ((yr % 4) == 0) && ((yr % 100) != 0) ) {
        form.Day.options.length = 29;
        form.Day.options[28].text = form.Day.options[28].value = '29';
      }
    }
    else if( form.Month.options[form.Month.selectedIndex].value == 4 ||
            form.Month.options[form.Month.selectedIndex].value == 6 ||
            form.Month.options[form.Month.selectedIndex].value == 9 ||
            form.Month.options[form.Month.selectedIndex].value == 11)  { // 30 day month
      form.Day.options.length = 30;
      form.Day.options[28].text = form.Day.options[28].value = '29';
      form.Day.options[29].text = form.Day.options[29].value = '30';
    }
    else {
      form.Day.options.length = 31;
      form.Day.options[28].text = form.Day.options[28].value = '29';
      form.Day.options[29].text = form.Day.options[29].value = '30';
      form.Day.options[30].text = form.Day.options[30].value = '31';
    }
  }
  catch( ex ) {
    throw Error( ex.message+' in basicfunc.js/DayRight()' );
  }
}

// Legacy - use extensions.js versions

function IsEmpty( S ) {
  return( (S == null) || (S.length == 0) );
}                       // end IsEmpty

function IsDigit( C ) {
  try {
    return C.isDigit();
  }
  catch( ex ) {
    return false;
  }
}

function IsAlpha( C ) {
  try {
    return C.isAlpha();
  }
  catch( ex ) {
    return false;
  }
}

function IsAlphaNum( C ) {
  try {
    return C.isAlNum();
  }
  catch( ex ) {
    return false;
  }
}

function IsNumber( theVal ) {
  try {
    if( !theVal.isAllDigits() ) {
      alert( 'Please provide a number.' );
      return false;
    }
  }
  catch( ex ) {
    return false;
  }
  return true;
}

function IsSpace( C ) {
  try {
    return C.isSpace();
  }
  catch( ex ) {
    return false;
  }
}

//
//boolean Sameline(S1, S2)--See whether line S1 is the same as line S2 except
//                          that S2 may have append the position.
//
function Sameline(S1, S2) {
  if( S1.length == S2.length ) {
    if( S1 == S2 ) {
      return( true );
    }
    else {
      return( false );
		}
  }
  else if( S2.length > S1.length ) {
		var lenS1=S1.length;
    if( S1 == S2.substring(0,lenS1) ) {
      return( true );
    }
    else {
      return( false );
		}
  }
  else {
    return( false );
	}
}

//
// convertLine - convert a line to the format as shown in bid packages
//
function convertLine(line, resLo, resHi, relLo, relHi) {
  var linId;
  var iS=Trim2(String(line));
  if( AllDigits(iS, false) ) {
    var tempId= parseInt(iS,10);
    if ( arguments.length >= 5 && tempId>=resLo && tempId<=resHi) {
      linId='RES'+tempId;
    } else
    if ( arguments.length >= 5 && tempId>=relLo && tempId<=relHi) {
      linId='REL'+tempId;
    } else
    if( tempId < 10 ) {
      linId = "00"+String(tempId);
    }
    else if( tempId < 100 ) {
      linId = "0"+String(tempId);
    }
    else {
      linId=tempId;
    }
  }
  else {
    iS=iS.toUpperCase();
    if( iS.charAt(0) == 'L' ) {
      var tempId= parseInt(iS.substring(1), 10);
      if( tempId < 10 ) {
        linId = '00'+tempId;
      }
      else if( tempId < 100 ) {
        linId = '0'+tempId;
      }
      else {
        linId = tempId;
      }
    }
    else if( iS == 'R' ) {
      linId='RES';
    }
    else if( iS == 'F' ) {
      linId='REL';
    }
    else if( iS == 'A' ) {
      linId='ANY';
    }
    else if( iS == 'T' ) {
      linId='T0000';
    }
    else if( iS.substring(0,3) == 'RES' && iS.length > 3 ) {
      var tempId= parseInt(iS.substring(3), 10);
      linId='RES'+tempId;
    }
    else if( iS.substring(0,3) == 'REL' && iS.length > 3 ) {
      var tempId= parseInt(iS.substring(3), 10);
      linId='REL'+tempId;
    }
    else if( iS.charAt(0) == 'R' && !isNaN(parseInt(iS.substring(1))) ) {
      var tempId= parseInt(iS.substring(1), 10);
      linId='RES'+tempId;
    }
    else if( iS.charAt(0) == 'F' && !isNaN(parseInt(iS.substring(1))) ) {
      var tempId= parseInt(iS.substring(1), 10);
      linId='REL'+tempId;
    }
    else if( iS.charAt(0) == 'T' && !isNaN(parseInt(iS.substring(1))) ) {
      var tempId= parseInt(iS.substring(1), 10);
      if( tempId < 10 ) {
        linId='T'+'000'+tempId;
      }
      else if( tempId < 100 ) {
        linId='T'+'00'+tempId;
      }
      else {
        linId='T'+tempId;
      }
    } else if ( IsDigit(iS.charAt(0)) ) {
      var tempId= parseInt(iS,10);
      if( tempId < 10 ) {
        tempId="00"+tempId;
      }
      else if( tempId < 100 ) {
        tempId="0"+tempId;
      }
      linId = tempId + TrimDigit(iS);
    }
    else {
      linId=iS;
    }
  }
  return( linId );
}

function AllDigits( S, AllowEmpty ) {
//  return S.( (AllowEmpty==true)?isAllDigits:isNumeric )();
  if( AllowEmpty == true ) {
    return S.isAllDigits();
  }
  return S.isNumeric();
}                       // end AllDigits

function Skipndigits( s ) // skip non-numeric characters space
{
     var idx=0;
     var chr;

     if( s.length == 0 ) {
          return( s );
     }
     do {
          chr=s.charAt(idx);
          if( (chr >= '0' && chr <= '9')
           || !chr ) {
               break;
          }
          idx++;
     } while( idx < s.length );
     return( s.substring(idx) );
}                             // end skipndigits
//
// Assume the string consists of digital part and character part.
// This function is to strip the digital part and return the remaining
// string.
//
function TrimDigit(S) {
  for( var idx=0 ; idx < S.length ; idx++ ) {
    var C=S.charAt( idx );
    if( !IsDigit(C) ) {
        return( S.substring(idx) );
    }
  }
  return( S );
}

//
// String TrimPhone( N ) - strips valid phone delimiters from a
//    perspective phone number string
//
function TrimPhone( N ) {
  var idx;
  var Result="";

  for( idx=0 ; idx < N.length ; idx++ ) {
    var C=N.charAt( idx );

    if( PhoneNumberDelimiters.indexOf(C) == -1 ) {
        Result+=C;
    }
  }
  return( Result );
}                       // end TrimPhone


function IsEmail(email) {
      var ampersand = email.indexOf( '@' );
      var dot = email.lastIndexOf( '.' );
      if( ampersand < 1 || dot < 0 || dot >= (email.length-1) || ampersand > dot ) {
        alert("Your email address must be in the following format:\n\nname@domain\n\nFor example, 'john@myisp.com'.");
        return (false);
      }
      var hasspace = email.indexOf( ' ' );
      if( hasspace != -1 ) {
        alert("Invalid format. Your email address cannot have space in it.");
        return (false);
      }
      var hascomma = email.indexOf( ',' );
      if( hascomma != -1 ) {
        alert("Invalid format. Your email address cannot have comma in it.");
        return (false);
      }
      var hassemicolum = email.indexOf( ';' );
      if( hassemicolum != -1 ) {
        alert("Invalid format. Your email address cannot have semicolum in it.");
        return (false);
      }
      return (true);
}


function validEmailPassword( password, userid ) {
  var tmpStr=password;
  tmpStr=tmpStr.toUpperCase();
  if( password.length < 4 ) {
    return "Your new password is too short.";
  }
  else if( password.length > 20 ) {
    return "Your new password is too long.";
  }
  else if( tmpStr == userid ) {
    return "Your new password cannot be your User ID.";
  }
  else if( tmpStr == "PASSWORD" ) {
    return "Your new password cannot be 'password'.";
  }
  else if( tmpStr.isAllAlNum() && userid.indexOf(password) != -1 ) {
    return "Your new password cannot include your Employee ID number.";
  }
  else {
    for( var i=0; i< password.length; i++ ) {
      var chr=password.charAt(i);
      if( (chr == ' ') ||
          (chr == '<') ||
          (chr == '>') ||
          (chr == '"') ||
          (chr == "'") ) {
        return "Your new password contains one or more illegal characters.";
      }
    }
  }
  return "";
}


function CheckComments(cmt) {
        var lengthOfWord=0;
        for( var z=0; z < cmt.length; z++ ) {
          if( cmt.charAt(z) == '<' || cmt.charAt(z) == '>' || cmt.charAt(z) == '%' ) {
            alert("The comment field cannot contain the following invalid characters:  < > % ");
            return (false);
          }
          if( z > 1000 ) {
            alert("The comment field contains too many characters. The size limit is a total of 1000 characters.");
            return (false);
          }
          if( cmt.charAt(z)==" " || cmt.charAt(z)=="\n" ) {
            lengthOfWord=0;
          }
          else {
            lengthOfWord++;
          }
          if( lengthOfWord > 40 ) {
            alert("The comment field contains one or more words that are too long. The maximum length for a word is 40 characters.");
            return (false);
          }
        }
        return true;
}


//
// String Trim( S ) - Trim trailing whitespace from a string
//
function Trim( S ) {
  var idx;
  var Result=S;

  if( S.length == 0 ) {
    return( Result );
  }
  for( idx=S.length-1 ; idx > 0 ; idx-- ) {
    var C=S.charAt( idx );

    if( !IsSpace(C) ) {
        Result=S.substring( 0, idx+1 );
        break;
    }
  }
  return( Result );
}                       // end Trim


//
// String Trim2( S ) - Trim leading and trailing whitespace from a string
//
function Trim2( S ) {
  var idx;
  var Temp="";

  if( S.length == 0 ) {
    return( Temp );
  }
  if( !IsSpace(S.charAt(0)) ) {
    return( Trim(S) );
  }
  for( idx=0 ; idx < S.length ; idx++ ) {
    var C=S.charAt( idx );

    if( !IsSpace(C) ) {
        Temp=S.substring( idx, S.length );
        break;
    }
  }
  Temp=Trim(String(Temp));
  return( Temp );
}                       // end Trim2

//
// Input: MMYY, output: Month Year
//
function getMMYY( Str ) {
  if( Str.length != 4 || !Str.allDigits() ) {
    throw Error( 'getMMYY(): Invalid argument '+Str );
  }
  return SMonths[atoi(Str.substring(0-2))-1]+' '+(2000+atoi(Str.substring(2,4)));
}

function AtoI ( num, PB ) {
  var newNum = "";
  var i = 0;
  if( !PB ) {  //if it's a normal bid search
    while( num.charAt(i) == 0 ) {
      i++;
    }
    while( i < num.length ) {
      newNum += num.charAt(i);
      i++;
    }
  }
  else {  //if it's a regular bid search
    while( num.charAt(i) == 0 ) {
      i++;
    }
    while( i < num.length-1 ) {
      newNum += num.charAt(i);
      i++;
    }
    var lastChar = num.charAt(i).toUpperCase();
    newNum += lastChar;
  }
  return( newNum );
}

function _popup( url, name, height, width, scrollbars ) { // Don't use this function - popup.js has a much better version
	var popwin;
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=no";
	opts += ",height=" + height + ",width=" + width + ",scrollbars=" + scrollbars;
  popwin = window.open( "", name, opts );
	popwin.focus();
	popwin.location = url;
}

function ValidPairFormatUSA( pair, nowarning, alid  ) {
  // num - num - num - num - num
  if( !(/^\d{5}$/).test(pair) ) {
    if( !nowarning ) {
      if( arguments.length < 3 ) {
        alid=0;
      }
      var egText=ValidPairFormat_Example( alid );
      alert( 'Please enter a pairing number in a valid format.\nExample: '+egText+'.' );
    }
    return false;
  }
  return true;
}

function ValidPairFormatDAL( pair, version ) {
  // num - num - num - num
  if( !(/^\d{4}$/).test(pair) ) {
    if( version==null ) {
      alert( 'Please enter a pairing number in a valid format.\nExample: 3200.' );
    }
    return false;
  }
  return true;
}

function ValidPairFormat( pair, nowarning, alid ) {
  var num=Skipndigits(pair);
  // consider anything 5 characters or longer, beginning with a character, and with at least one digit to be a pairid (necessary for Virign (VRD))
  // VRD no longer will have a base code on front, but 5 characters or more with at least one digit is still an acceptable test.
  //if( /*isalpha(*name) &&*/ strlen(name) >= 5 && *skipndigits((PCHAR)name) != 0 ) {
  //     return( true );
  //}
  if( alid == 13 || alid == 1073 ) {
     if( pair.length >= 5 && num.length > 0  && (num=num.charAt(0)) >= '0' && num <= '9' ) {
       return true;
     }
  }
  // A1234, AB123, A1234B, AB123C
  // anything 5+ characters long with at least one digit as a pairid for CT airlines
  // alpha - alpha|num - alpha|num - alpha|num - alpha|num - alpha|null
  //if( !(/^[a-zA-Z][a-zA-Z0-9][a-zA-Z0-9]\d{2}[a-zA-Z]?$/).test(pair) ) {
  if( !(/^[a-zA-Z][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z]?$/).test(pair) || (num=num.charAt(0)) < '0' || num > '9' ) {
    if( !nowarning ) {
      if( arguments.length < 3 ) {
        alid=0;
      }
      var egText=ValidPairFormat_Example( alid );
      alert( 'Please enter a pairing number in a valid format.\nExample: '+egText+'.' );
    }
    return false;
  }
  return true;
}                             // end  ValidPairFormat

// There's really no call for this to be in script rather than C++, but I didn't write it, so here it stays.

function ValidPairFormat_Example( airline_id ) {
  // At some point we may need to provide different examples for different airlines
  // For now it will just go to the default case
  switch( airline_id ) {
    case 32:          // Delta airlines
    case 4:           // Test Airline 4
      return("1234");
    case 7:           // Test Airline 7
    case 1062:        // USAirways Airlines
      return ("46001");
    case 29:          // America West
      return "P1234, L1234";
    case 1:           // Frontier Test
    case 40:          // Frontier Airlines
      return "D1234, M1234";
    case 42:          // Midwest Express
    case 1018:        // Skyway airlines
      return "M1234";
    case 9:           // Test Airline 9
    case 45:          // AirTran
      return "A1234, M1234";
    case 2:           // ASA Test
    case 48:          // Atlantic Southeast Airlines
      return "A1234, D1234, I1234, S1234";
    case 1017:        // JetBlue Airways
      return "J1234, L1234, F1234, B1234";
    case 1007:        // Air Wisconsin Airlines
      return "A1234, O1234, D1234, I1234, P1234";
    case 1074:          // Flightline Air
      return "C1234, C123A, C1234A";
    case 69:          // Flightline Air
      return "A1234, D1234";
    case 1073:        // Virgin America
    case 13:          // Virgin America Test
      return "00219";
    case 3:           // AirWis Test
    case 5:           // Test Airline 5
    case 6:           // Test Airline 6
    case 8:           // Test Airline 8
    case 20:          // Flightline Express
    case 51:          // SkyWest Airlines
    case 55:          // Mesaba Airlines
    default:
      return "A1234, AB123, A1234B, AB123C";
  }
}      // end ValidPairFormat_Example


function ValidPairIdFormat_Example( airline_id ) {
  // At some point we may need to provide different examples for different airlines
  // For now it will just go to the default case
  switch( airline_id ) {
    case 32:          // Delta airlines
    case 4:           // Test Airline 4
      return("1234:DDMON or 1234:YYYYMMDD");
    case 1062:        // USAirways Airlines
      return ("46001:DDMON or 46001:YYYYMMDD");
    case 29:          // America West
      return "P1234:DDMON or P1234A:YYYYMMDD";
    case 1:           // Frontier Test
    case 40:          // Frontier Airlines
      return "D1234:DDMON or D1234A:YYYYMMDD";
    case 42:          // Midwest Express
    case 1018:        // Skyway airlines
      return "M1234:DDMON or M1234A:YYYYMMDD";
    case 9:           // Test Airline 9
    case 45:          // AirTran
    case 48:          // Atlantic Southeast Airlines
      return "A1234:DDMON or A1234A:YYYYMMDD";
    case 1017:        // JetBlue Airways
      return "J1234:DDMON or J1234A:YYYYMMDD";
    case 2:           // ASA Test
    case 3:           // AirWis Test
    case 5:           // Test Airline 5
    case 6:           // Test Airline 6
    case 7:           // Test Airline 7
    case 8:           // Test Airline 8
    case 20:          // Flightline Express
    case 69:          // Flightline Air
    case 1007:        // Air Wisconsin Airlines
    case 51:          // SkyWest Airlines
    case 55:          // Mesaba Airlines
    default:
      return "A1234:DDMON or 12345:YYYYMMDD";
  }
}      // end ValidPairFormat_Example



function makeTab( label, link, title ) {
  var txt='';
  disabledTab=false;
  if( !title ) {
    title=''
  } else if( title=='disabled') {
    disabledTab=true;
  }
  if( link && link != '' && link != ' ' && !disabledTab ) {
    txt =' <td nowrap="nowrap"><a href="' + link + '" title="' + title + '" alt="' + title + '">  ';
    txt+='   <img src="/images/tab_left_corner2.gif" border="0"></a></td>                         ';
    txt+=' <td nowrap="nowrap" background="/images/spacer2.gif">                                  ';
    txt+='   <a href="' + link + '" title="' + title + '" alt="' + title + '" class="XLINK">      ';
    txt+='     <b><font color="gray">&nbsp; ' + label + ' &nbsp;</font></b></a></td>                                      ';
    txt+=' <td nowrap="nowrap"><a href="' + link + '" title="' + title + '" alt="' + title + '">  ';
    txt+='   <img src="/images/tab_right_corner2.gif" border="0"></a></td>                        ';
  }
  else if( disabledTab ) {
    txt =' <td nowrap="nowrap">                                                                                 ';
    txt+='   <img src="/images/tab_left_corner2.gif" border="0"></td>  ';
    txt+=' <td nowrap="nowrap" background="/images/spacer2.gif">                                                 ';
    txt+='   <font color="gray"><b> &nbsp; ' + label + ' &nbsp; </b></font></td>   ';
    txt+=' <td nowrap="nowrap">                                                                                 ';
    txt+='   <img src="/images/tab_right_corner2.gif" border="0"></td> ';
  } else {
    txt =' <td nowrap="nowrap">                                                                                 ';
    txt+='   <img src="/images/tab_left_corner.gif" border="0" title="' + title + '" alt="' + title + '"></td>  ';
    txt+=' <td nowrap="nowrap" background="/images/spacer.gif">                                                 ';
    txt+='   <font title="' + title + '" alt="' + title + '"><b> &nbsp; ' + label + ' &nbsp; </b></font></td>   ';
    txt+=' <td nowrap="nowrap">                                                                                 ';
    txt+='   <img src="/images/tab_right_corner.gif" border="0" title="' + title + '" alt="' + title + '"></td> ';
  }
  return( txt );
}

function makeTab1( label, link, title ) {
  var txt="";
  disabledTab=false;
  if( !title ) {
    title=""
  } else if( title=="disabled") {
    disabledTab=true;
  }
  if( link && link != "" && link != " " && !disabledTab ) {
    //alert(link);
    txt =" <td nowrap=\"nowrap\"><a href=\"JavaScript:OpenPage('" + link + "')\" title=\"" + title + "\" alt=\"" + title + "\">  ";
    txt+="   <img src=\"/images/tab_left_corner2.gif\" border=\"0\"></a></td>                         ";
    txt+=" <td nowrap=\"nowrap\" background=\"/images/spacer2.gif\">                                  ";
    txt+="   <a href=\"JavaScript:OpenPage('" + link + "')\" title=\"" + title + "\" alt=\"" + title + "\" class=\"XLINK\">      ";
    txt+="     <b><font face=\"Arial\" color=\"black\" size=\"-1\">&nbsp; " + label + " &nbsp;</font></b></a></td>                                      ";
    txt+=" <td nowrap=\"nowrap\"><a href=\"JavaScript:OpenPage('" + link + "')\" title=\"" + title + "\" alt=\"" + title + "\">  ";
    txt+="   <img src=\"/images/tab_right_corner2.gif\" border=\"0\"></a></td>                        ";
  }
  else if( disabledTab ) {
    txt =' <td nowrap="nowrap">                                                                                 ';
    txt+='   <img src="/images/tab_left_corner2.gif" border="0"></td>  ';
    txt+=' <td nowrap="nowrap" background="/images/spacer2.gif">                                                 ';
    txt+='   <font face=\"Arial\" color="black" size=\"-1\"><b> &nbsp; ' + label + ' &nbsp; </b></font></td>   ';
    txt+=' <td nowrap="nowrap">                                                                                 ';
    txt+='   <img src="/images/tab_right_corner2.gif" border="0"></td> ';
  } else {
    txt =' <td nowrap="nowrap">                                                                                 ';
    txt+='   <img src="/images/tab_left_corner.gif" border="0" title="' + title + '" alt="' + title + '"></td>  ';
    txt+=' <td nowrap="nowrap" background="/images/spacer.gif">                                                 ';
    txt+='   <font face=\"Arial\" title="' + title + '" alt="' + title + '" size=\"-1\"><b> &nbsp; ' + label + ' &nbsp; </b></font></td>   ';
    txt+=' <td nowrap="nowrap">                                                                                 ';
    txt+='   <img src="/images/tab_right_corner.gif" border="0" title="' + title + '" alt="' + title + '"></td> ';
  }
  return( txt );
}

//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

var pColors=[];
pColors[ 0]={ hexcode:"00FF00", name:"lime" };
pColors[ 1]={ hexcode:"32CD32", name:"limegreen" };
pColors[ 2]={ hexcode:"008000", name:"green" };
pColors[ 3]={ hexcode:"008080", name:"teal" };
pColors[ 4]={ hexcode:"40E0D0", name:"turquoise" };
pColors[ 5]={ hexcode:"87CEEB", name:"skyblue" };
pColors[ 6]={ hexcode:"1E90FF", name:"dodgerblue" };
pColors[ 7]={ hexcode:"0000FF", name:"blue" };
pColors[ 8]={ hexcode:"00008B", name:"darkblue" };
pColors[ 9]={ hexcode:"800080", name:"purple" };
pColors[10]={ hexcode:"EE82EE", name:"violet" };
pColors[11]={ hexcode:"FFC0CB", name:"pink" };
pColors[12]={ hexcode:"FF1493", name:"deeppink" };
pColors[13]={ hexcode:"FF0000", name:"red" };
pColors[14]={ hexcode:"FF6347", name:"tomato" };
pColors[15]={ hexcode:"FFA500", name:"orange" };
pColors[16]={ hexcode:"FFFF00", name:"yellow" };
pColors[17]={ hexcode:"000000", name:"black" };
pColors[18]={ hexcode:"A52A2A", name:"brown" };
pColors[19]={ hexcode:"C0C0C0", name:"silver" };





