// VE WEB LIBRARY -- COPYRIGHT 1999-2002 INTELLIUN CORPORATION. ALL RIGHTS RESERVED.


function includeJS( file ) 
  {
  document.write('<script type="text/javascript" src="' + file + '" ></script>');
  }

includeJS('/ve/res/js/spiked_lib.js');
includeJS('/ve/res/js/mousemover.js');
includeJS('/ve/res/js/popupdiv.js');

function includeCSS( file ) 
  {
  document.write('<link type="text/css" rel="stylesheet" href="' + file + '" />');
  }

////////////////////////////
// MULTI_BROWSER SUPPORT  //
////////////////////////////

function Browser() 
  {
  if( document.layers )
    this.isNS4 = true;
  
  if( navigator.userAgent.indexOf( "Gecko" ) != -1 )
    this.isNS6 = true;
  
  if( navigator.appVersion.indexOf( "Mac" ) != -1 )
    this.isMac = true;
  
  if( navigator.appVersion.indexOf( "MSIE 4.5" ) != -1 )
    this.isMac45 = true;
  
  if( this.isNS6 || this.isNS4 )
    this.isMac = false;
  
  if( navigator.userAgent.indexOf( "Opera" ) != -1 )
    this.isOpera = true;
  
  if( parseInt( navigator.productSub ) >= 20010726 )
    this.isNS61 = true;
  
  if( !document.getElementById && document.all )
    this.isIE4 = true;
  
  if( document.getElementById && document.all )
    this.isIE5 = true;
    
  if( navigator.userAgent.indexOf( "MSIE 5.5") >= 0 || navigator.userAgent.indexOf( "MSIE 6" ) >= 0 )
    {
    this.isIE55 = true;  
    this.IE6 = true;
    }
  
  //if( document.getElementById )
    this.gebi = true;
  
  if( navigator.userAgent.indexOf( "Konqueror" ) != -1 )
    this.isKonq = true;
    
  if( document.all )
    this.isIE = true;  
  }

var browser = new Browser();

function getBrowser()
  {
  return window.navigator.appName;
  }

function getTag( id )
  {
  if( document.getElementById )
    return document.getElementById( id );
  else if( document.all )
    return document.all[ id ];
  else
    return null;
  }

////////////////////////////
// BASE64 ENCODER/DECODER //
////////////////////////////

var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

function base64Decode( encStr )
  {
  var bits, decOut = '', i = 0;

  for( ; i < encStr.length; i += 4 )
    {
    bits = ( base64s.indexOf( encStr.charAt( i ) )     & 0xff ) <<18 |
           ( base64s.indexOf( encStr.charAt( i + 1 ) ) & 0xff ) <<12 |
           ( base64s.indexOf( encStr.charAt( i + 2 ) ) & 0xff ) << 6 |
           ( base64s.indexOf( encStr.charAt( i + 3 ) ) & 0xff );

    decOut += String.fromCharCode( ( bits & 0xff0000 ) >> 16, ( bits & 0xff00 ) >> 8, bits & 0xff );
    }

  if( encStr.charCodeAt( i - 2 ) == 61 )
    return decOut.substring( 0, decOut.length - 2 );
  else if( encStr.charCodeAt( i - 1 ) == 61 )
    return decOut.substring( 0, decOut.length - 1 );
  else
    return decOut;
  }

function base64Encode( decStr )
  {
  var bits, dual, i = 0, encOut = '';

  while( decStr.length >= i + 3 )
    {
    bits = ( decStr.charCodeAt( i++ ) & 0xff ) << 16 |
           ( decStr.charCodeAt( i++ ) & 0xff ) << 8  |
           ( decStr.charCodeAt( i++ ) & 0xff );

    encOut += base64s.charAt( ( bits & 0x00fc0000 ) >> 18 ) +
              base64s.charAt( ( bits & 0x0003f000 ) >> 12 ) +
              base64s.charAt( ( bits & 0x00000fc0 ) >> 6 )  +
              base64s.charAt( ( bits & 0x0000003f ) );
    }

  if( decStr.length - i > 0 && decStr.length - i < 3 )
    {
    dual = Boolean( decStr.length - i - 1 );
    bits = ( ( decStr.charCodeAt( i++ ) & 0xff ) << 16) | ( dual ? ( decStr.charCodeAt( i ) & 0xff ) << 8 : 0 );

    encOut += base64s.charAt( ( bits & 0x00fc0000 ) >> 18 ) +
              base64s.charAt( ( bits & 0x0003f000 ) >> 12 ) +
              ( dual ? base64s.charAt( ( bits & 0x00000fc0 ) >> 6 ) : '=' ) + '=';
    }

  return encOut;
  }

/////////////////////
// TOPIC FRAMEWORK //
/////////////////////

var TOPIC_ONLOAD          = "on_load";
var TOPIC_ONUNLOAD        = "on_unload";
var TOPIC_WINDOW_RESIZE   = "window_resize";
var TOPIC_PRESUBMIT       = "pre_submit";
var TOPIC_PRELOADIMAGES   = "preload images";
var TOPIC_SELECTION       = "selection";
var TOPIC_NEW_ROW 	  = "new_row";
var TOPIC_BEFORE_ADD	  = "before_add";
var TOPIC_REFRESH         = "ve_refresh_node";
var TOPIC_MOUSE_CLICKED   = "mouseclick";
var TOPIC_MOUSE_MOVED     = "mousemove";
var TOPIC_KEY_DOWN        = "keydown";
var TOPIC_ANYCHANGE       = "global_any_change";

var Topics                = !Topics ? new Array() : Topics;
var ve_pageHasChanges     = false;

var EXCEPTION_INFO        = 0;
var EXCEPTION_DEBUG       = 1;
var EXCEPTION_HIGH        = 2;
var EXCEPTION_CRITICAL    = 3;
var EXCEPTION_FATAL       = 4;

function Topic( name )
  {
  this.name = name;
  this.dependents = new Array();

  this.addDependent = function( dependent )
    {
    this.dependents[ this.dependents.length ] = dependent;
    }

  this.notify = function( id, param )
    {
//alert( "Notifying Topic ---> " + this.name + ", dl=" + this.dependents.length );
    ve_pageHasChanges = true;

    if( this.syncAll )
      this.syncAll( id, param );

    for( var i = 0; i < this.dependents.length; i++ )
      {
      try
        {
        this.dependents[ i ].update( id, param );
        }
      catch( e )
        {
//alert( "this = " + this.name + ",dependent " + this.dependents[ i ].name + ", func=" + this.dependents[ i ].update );
        if( e.description || e.desc )
          {
          if( e.severity >= EXCEPTION_CRITICAL )
            throw e;
          else    
            alert( e.description ); 
          }
        else
          throw e;
        }  
      }

    if( this.updateOnSet )
      this.updateOnSet( id, param );

    if( this.name != TOPIC_ANYCHANGE )
      getTopic( TOPIC_ANYCHANGE ).notify( id, param );
    }

  this.update = function( id, param )
    {
    if( this.updateValue )
      this.updateValue( id, param );

    if( this.updateDomain )
      this.updateDomain( id, param );

    if( this.updateApplicable )
      this.updateApplicable( id, param );

    if( this.updateReadOnly )
      this.updateReadOnly( id, param );
    }

  this.addListener = function( expression )
    {
    var dependent = new Object();
    dependent.expression = expression;

    dependent.update = function( id, param )
      {
//alert( "Evaluating ---> " + this.expression );
      eval( this.expression );
      }

    this.dependents[ this.dependents.length ] = dependent;
    }
  }

function getTopic( name )
  {
  var topic = Topics[ name ];

  if( topic == null )
    {
    topic = new Topic( name );
    Topics[ name ] = topic;
    }

  return topic;
  }

function addDependent( topic, dependent )
  {
  getTopic( topic ).addDependent( getTopic( dependent ) );
  }

function ve_notify( topicExpr, id, param )
  {
  var topic = getTopic( topicExpr );

  if( topic != null )
    topic.notify( id, param );
  }
  
function ve_execute_onload( tid, expr )
  {
  getTopic( TOPIC_ONLOAD ).addListener( expr );
  getTopic( TOPIC_ONLOAD + tid ).addListener( expr );
  }
    
///////////////////////////////
// Required Field Validation //
///////////////////////////////

var ve_requiredFields = new Array();

function ve_addRequiredField( id, name )
  {
  ve_requiredFields[ ve_requiredFields.length ] = new RequiredField( id, name );	
  }

function RequiredField( id, name )
  {
  this.id = id;
  this.name = name;	
  }

function ve_validateRequiredFields()
  {
  for( var i = 0 ; i < ve_requiredFields.length ; i++ )
    {
    var isTagOK = true;
    var aField = ve_requiredFields[i];
    var fieldTag = getTag( aField.id );

    if( !fieldTag )
      continue;

    try
      {
      if( fieldTag.getAttribute( 'getRequireValidationExpr' ) )
        isTagOK = eval( fieldTag.getAttribute( 'getRequireValidationExpr' ) );
      else if( fieldTag.type == "radio" || fieldTag.type == "checkbox" ) //|| fieldTag.type == "hidden" )
        continue;
      }
    catch( e )
      {
      }
      
    if( !isTagOK || !fieldTag.value || fieldTag.value == String.fromCharCode( 13 ) )
      {
      alert( "'" + aField.name + "' is a required field." );
      
      try
        {
        fieldTag.scrollToView();
        fieldTag.focus();
        }
      catch( e )
        {
        var el = fieldTag;
        var containerEl = null;
        var displayFieldFunc = null;
        
        //alert( 'Checking for display functions...' );
        
        while( displayFieldFunc == null && el != null )
          {
          displayFieldFunc = el.getAttribute( 've_displayFieldFunc' );  
          
          if( displayFieldFunc == null )
            el = el.parentElement;  
          }  

        if( displayFieldFunc != null )
          {
          //alert( "Evaluating...." + displayFieldFunc + "( el, fieldTag );" );
          eval( displayFieldFunc + "( el, fieldTag );" );  
          }
        }
      
      return false;  
      }	
    } 

  return true;	
  }

//////////////////
// LOCALIZATION //
//////////////////

var VELOCALE_DECIMALSEPARATOR  = '.';
var VELOCALE_CURRENCYSYMBOL    = '$';
var VELOCALE_PERCENT           = '%';
var VELOCALE_GROUPINGSEPARATOR = ',';

////////////////
// TAG ACCESS //
////////////////

//function ve_getTag( firingId, relatedId )
//  {
//  var fi = firingId.indexOf( "__" );
//  var fp = firingId.substring( 0, fi );
//  var tag = fp.indexOf( "a" ) != -1 ? fp + relatedId.substring( relatedId.indexOf( "__" ) ) : relatedId;
//  return getTag( tag );
//  }

function ve_getTag( firingId, relatedId )
  {
  var fi = firingId.indexOf( "__" );
  var fp = firingId.substring( 0, fi );
  var fa = fp.indexOf( "a" );
  var tag;

  if( fa != -1 )
    {
    var ri = relatedId.indexOf( "__" );
    var rp = relatedId.substring( 0, ri );
    var ra = rp.indexOf( "a" );

    if( ra != -1 )
      rp = rp.substring( 0, ra );

    tag = rp + fp.substring( fa ) + relatedId.substring( ri );
    }
  else
    {
    var ri = relatedId.indexOf( "__" );
    tag = firingId.substring( 0, fi ) + relatedId.substring( ri );
    }

  return getTag( tag );
  }

function ve_getElementValue( tagId, element, attribute )
  {
//alert( "Tag ID = " + tagId );
  var tag = getTag( tagId );
//alert( "Tag = " + tag );

  if( tag && tag.getElementValue )
    {
    var value = tag.getElementValue( element, attribute );
//    alert( "Key = " + attribute + ", " + value );
    return value;
    }
    
  return null;
  }

function ve_calcIntegerValue( value )
  {
  return value ? parseInt( value ) : 0;
  }

function ve_calcLongValue( value )
  {
  return value ? parseInt( value ) : 0;
  }

function ve_calcShortValue( value )
  {
  return value ? parseInt( value ) : 0;
  }

function ve_calcByteValue( value )
  {
  return value ? parseInt( value ) : 0;
  }

function ve_calcFloatValue( value )
  {
  return value ? parseFloat( ve_removeCurrency( value ) ) : 0;
  }

function ve_calcDoubleValue( value )
  {
  return value ? parseFloat( ve_removeCurrency( value ) ) : 0;
  }

function ve_calcCurrencyValue( value )
  {
  return ve_calcDoubleValue( value );
  }
  
function ve_calcStringValue( value )
  {
  return value;
  }

function ve_calcDateValue( value )
  {
  if( value == null || value == "" )
    return null;
  else if( /^\d+$/.test( value ) )
    return new Date( parseInt( value ) );
  else if( /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/.test( value ) )
    {
    var date = value.split( RegExp.$1 );
    var year = date[ 2 ];
    
    if( year.length == 2 )
      {
      if( year.charAt( 0 ) == '0' )
        year = year.substring( 1 );
      
      year = parseInt( year );
    
      if( year < 100 )
        year += year < 70 ? 2000 : 1900;
      }

    return new Date( year, date[ 0 ] - 1, date[ 1 ] );
    }
  else
    return null;
  }

function ve_calcTimestampValue( value )
  {
  if( value == null || value == "" )
    return null;
  else if( /^\d+$/.test( value ) )
    return new Date( parseInt( value ) );
  else if( /^(\d{1,2})(\-|\/|\.)(\d{1,2})\2(\d{2})(\D+.*)$/.test( value ) )
    {
    var date = value.split( RegExp.$1 );
    var year = RegExp.$4;
    
    if( year.length > 0 && year.charAt( 0 ) == '0' )
      year = year.substring( 1 );
      
    year = parseInt( year );
    year += year < 70 ? 2000 : 1900;
    value = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$2 + year + RegExp.$5;  
    }

  return new Date( value );
  }

function ve_getIntegerValue( id, topic )
  {
  var tag = ve_getTag( id, topic );
  var value = tag ? ( tag.value == undefined ? tag.innerHTML : tag.value ): null;
  
  if( value && value.constructor == String )
    value = ve_removeCurrency( value );

  return value ? parseInt( value ) : 0;
  }

function ve_getLongValue( id, topic )
  {
  return ve_getIntegerValue( id, topic );
  }

function ve_getShortValue( id, topic )
  {
  var tag = ve_getTag( id, topic );
  var value = tag ? ( tag.value == undefined ? tag.innerHTML : tag.value ): null;
  
  return value ? parseInt( value ) : 0;
  }

function ve_getByteValue( id, topic )
  {
  var tag = ve_getTag( id, topic );
  var value = tag ? ( tag.value == undefined ? tag.innerHTML : tag.value ): null;
  
  return value ? parseInt( value ) : 0;
  }

function ve_getFloatValue( id, topic )
  {
  var tag = ve_getTag( id, topic );
  var value = tag ? ( tag.value == undefined ? tag.innerHTML : tag.value ): null;

  if( value && value.constructor == String )
    value = ve_removeCurrency( value );

  return value ? parseFloat( value ) : 0;
  }

function ve_getDoubleValue( id, topic )
  {
  var tag = ve_getTag( id, topic );
  var value = tag ? ( tag.value == undefined ? tag.innerHTML : tag.value ) : null;

  if( value && value.constructor == String )
    value = ve_removeCurrency( value );

  return value ? parseFloat( value ) : 0;
  }

function ve_getStringValue( id, topic )
  {
  var tag = ve_getTag( id, topic );
  var value = tag ? ( tag.value == undefined ? tag.innerHTML : tag.value ) : null;
  
  if( !value )
    value = "";
    
  return value;
  }

function ve_getDateValue( id, topic )
  {
  var tag = ve_getTag( id, topic );
  var value = tag ? ( tag.value == undefined ? tag.innerHTML : tag.value ) : null;
  
  if( !value )
    value = "";
    
  return value;
  }

function ve_getBooleanValue( id, topic )
  {
  var tag = ve_getTag( id, topic );
  // this doesn't work when tag is radio button (or array of)--ij
  return tag && ( tag.value == true || tag.value == "true" );
  }

function ve_setValue( id, topic, value, veformat )
  {
  var tag = ve_getTag( id, topic );
  var setter;
  
  if( tag )
    if( ( setter = tag.getAttribute( "veSetValue" ) ) != null )
      {
      var formattedValue = veformat ? ve_formatValue( value, veformat ) : value;
      eval( setter );
      }
    else
      tag.value = veformat ? ve_formatValue( value, veformat ) : value;
  }

function ve_setApplicable( id, topic, value )
  {
  var tag = ve_getTag( id, topic );
  
  if( tag == null )
    tag = getTag( topic );
    
  //if( tag )
  //  tag.disabled = !value;
  //else
    ve_refresh();
  }

function ve_setReadOnly( id, topic, value )
  {
  var tag = ve_getTag( id, topic );
  
  if( tag == null )
    tag = getTag( topic );
    
  if( tag )
    tag.readOnly = value;
  }

function ve_setDomain( id, topic, array )
  {
  var tag = ve_getTag( id, topic );

  if( tag && tag.options )
    {
    tag.options.length = array.length;

    for( var i = 0; i < array.length; i++ )
      tag.options[ i ] = new Option( array[ i ], array[ i ], false, false );
    }
  }

function ve_getOID( id )
  {
  var index = id.indexOf( "__" );
  var tag = getTag( index == -1 ? id : id.substring( 0, index ) );
  return tag == null ? null : tag.value;
  }

function ve_invoke( id, name )
  {
  var oid = ve_getOID( id );
  var params = new Array();

  for( i = 1; i < arguments.length; i++ )
    params[ i - 1 ] = arguments[ i ];

  return veopsupport_invoke( oid, "", name, params );
  }

var TOIDsByOIDs;
var lastTOID;

function ve_createInput( id, value )
  {
  var element = null;
  var tag = value && value.constructor == String && value.indexOf( "\n" ) != -1 ? "TEXTAREA" : "INPUT";

  if( document.all )
    {
    element = document.createElement( "<" + tag + ">" );
    element.id = id;
    element.name = id;
    element.value = value;

    if( tag == "INPUT" )
      element.type = "hidden";
    }
  else
    {  
    element = document.createElement( tag );
    element.setAttribute( "id", id );
    element.setAttribute( "name", id );
    element.setAttribute( "value" ,value );

    if( tag == "INPUT" )
      element.setAttribute( "type", "hidden" );
    }

  return element;
  }

function ve_createElement( tag )
  {
  var element = null;
  
  if( document.all )
    element = document.createElement( "<" + tag + ">" );
  else
    element = document.createElement( tag );

  return element;
  }

function ve_copyElement( source )
  {
  var element = ve_createElement( source.tagName );
  var children = source.children;
  element.mergeAttributes( source );

  for( var i = 0; i < children.length; i++ )
    element.appendChild( ve_copyElement( children[ i ] ) );

  return element;
  }

function ve_acquireTOID( oid, justGet, all )
  {
  if( !TOIDsByOIDs )
    {
    TOIDsByOIDs = new Array();
    var elements = document.forms[ 0 ].all;
    var elemTypes = new Array();
    lastTOID = 500;

    for( var i = elements.length - 1; i >= 0; i-- )
      {
      var toid = elements[ i ].name;
      var sIndex;
      var eType;

      if( toid && toid.indexOf( "_v" ) == 0 )
        if( ( sIndex = toid.indexOf( "__" ) ) == -1 )
          {
          var existing = TOIDsByOIDs[ elements[ i ].value ];

          //if( !existing || elemTypes[ toid ] )
          //  TOIDsByOIDs[ elements[ i ].value ] = toid;

          if( !existing )
            TOIDsByOIDs[ elements[ i ].value ] = new Array();

          TOIDsByOIDs[ elements[ i ].value ].push( toid );
          var index = parseInt( toid.substring( 2 ) );

          if( index > lastTOID )
            lastTOID = index;
          }
        else if( ( eType = elements[ i ].type ) != "button" )
          {
          var prefix = toid.substring( 0, sIndex );

          if( elemTypes[ prefix ] == null )
            elemTypes[ prefix ] = eType;
          }
      }
    }

  var toid = TOIDsByOIDs[ oid ];

  if( !toid && !justGet )
    {
    var old = lastTOID;

    toid = "_v" + (++lastTOID);
    ve_appendChildToForm( document.forms[ 0 ], toid, oid );
    toid = TOIDsByOIDs[ oid ] = new Array( toid );
    }

  return toid && !all ? toid[ 0 ] : toid;
  }

function ve_setValueByOid( oid, member, value )
  {
  var toid = ve_acquireTOID( oid );
  var tid = toid + "__" + member;
  var tag = getTag( tid );

  ve_pageHasChanges = true;

  if( !tag )
    ve_appendChildToForm( document.forms[ 0 ], tid, value );
  else
    tag.value = value;
  }

function ve_appendChildToForm( form, tid, value )
  {
  var el = ve_createInput( tid, value );  
  form.appendChild( el );
  return el;
  }
  
function ve_newForm( keepRaw )
  {
  var formTag = browser.isIE ? "<FORM>" : "FORM";
  var form = document.createElement( formTag );
  var copy = new Array( "vhtml", "veportal" );
  //var mainForm = document.form[ 0 ];

  if( !keepRaw )
    for( var i = 0; i < copy.length; i++ )
      ve_appendChildToForm( form, copy[ i ], getTag( copy[ i ] ).value );

  return form;
  }

function ve_refreshFields( fields )
  {
  var form = ve_newForm();

  if( fields )
    for( var i = 0; i < fields.length; i++ )
      {
      var tag = getTag( fields[ i ] );

      if( tag )
        ve_appendChildToForm( form, fields[ i ], tag.value );
      }

  form.action = ve_getUrlPrefix(false, true) + ACTION_NOOP + ".v";
  form.target = "ve_backgroundPostFrame";
  form.method = "POST";
  var docBody = document.getElementsByTagName( "body" )[ 0 ];
  docBody.appendChild( form );
  form.submit();
  docBody.removeChild( form );

  //we need to block until server responds f( ve_backgroundPostFrame.document && isDocumentReady( ve_backgroundPostFrame.document ) )
  }

function ve_execProcessInNewWindow( url, oid, execParms )
  {
  var prSignature = "Request/execute.v?o=" + oid;
  var pr = url.indexOf( prSignature );
  var k = url.lastIndexOf( "/", pr );
  var moreParams = url.substring( pr + prSignature.length + 1 );
  url = url.substring( 0, k + 1 ) + url.substring( k + 1, k + 2 ).toLowerCase() + url.substring( k + 2, pr ) + ".v" + moreParams;
  var sep = moreParams ? "&" : "?";
  var elements = document.forms[ 0 ].elements;
  var prefixes = ve_acquireTOID( oid, true, true );

  for( var j = 0; j < prefixes.length; j++ )
    {
    var prefix = prefixes[ j ] + "__";

    for( var i = 0; i < elements.length; i++ )
      {
      if( elements[ i ].name && elements[ i ].name.indexOf( prefix ) == 0 )
        {
        var value;

        if( elements[ i ].tagName.toLowerCase() == "input" )
          {
          var type = elements[ i ].type;

          if( type )
            type = type.toLowerCase();

          if( type == "radio" )
            value =  elements[ i ].checked ? elements[ i ].value : null;
          else if( !( value = elements[ i ].value ) )
            value = '';
          }
        else if( elements[ i ].tagName == "SELECT" )
          value = elements[ i ].value == String.fromCharCode( 13 ) ? null : elements[ i ].value;
       
        if( value )
          {
          url += sep + elements[ i ].name.substring( prefix.length ) + "=" + escape( value );
          sep = "&";
          }
        }
      }
    }

  if( execParms )
    url += sep + execParms;
    
  window.open( url, "_blank", "location=yes,menubar=yes,toolbar=yes,resizable=yes,scrollbars=yes" );
  }

function ve_postInNewWindow( url, auxFields, execParms )
  {
  var elements = document.forms[ 0 ].elements;
  var form = document.createElement( browser.isIE ? "<FORM>" : "FORM" );
  var docBody = document.getElementsByTagName( "body" )[ 0 ];
  docBody.appendChild( form );

  for( var i = 0; i < elements.length; i++ )
    {
    if( elements[ i ].name && elements[ i ].name != "veWhereAmI" )
      {
      var value;

      if( elements[ i ].tagName.toLowerCase() == "input" )
        {
        var type = elements[ i ].type;

        if( type )
          type = type.toLowerCase();

        if( type == "radio" )
          value =  elements[ i ].checked ? elements[ i ].value : null;
        else if( !( value = elements[ i ].value ) )
          value = '';
        }
      else if( elements[ i ].tagName == "SELECT" )
        value = elements[ i ].value;
      else if( elements[ i ].tagName == "TEXTAREA" )
        value = elements[ i ].value;
       
      if( value || value == '' )
        ve_appendChildToForm( form, elements[ i ].name, value );
      }
    }

  if( auxFields )
    for( var i = 0; i < auxFields.length; i++ )
      {
      var field = getTag( auxFields[ i ] );
      
      if( field )
        ve_appendChildToForm( form, auxFields[ i ], field.value );
      }
    
  if( execParms )
    {
    var pairs = execParms.split( "&" );
    
    for( var i = 0; i < pairs.length; i++ )
      {
      var keyValue = pairs[ i ].split( "=" );
      
      if( keyValue.length == 2 )
        ve_appendChildToForm( form, keyValue[ 0 ], keyValue[ 1 ] );
      }
    }   
  
  form.action = url;
  form.target = "_blank";
  form.method = "POST";
  form.submit();
  docBody.removeChild( form );
  }

////////////////
// EXCEPTIONS //
////////////////

function RequiredFieldException( name, displayName )
  {
  this.name = name;
  this.displayName = displayName;
  this.desc = displayName + " is a required field."
  }

function SelectionRequiredException()
  {
  this.desc = "Please select an item to continue."
  }

//////////////////////////
// SERVER COMMUNICATION //
//////////////////////////

var ACTION_NOOP        = 've/core/ClientInteraction/save';
var ACTION_FETCH       = 've/core/Object/fetch';
var ACTION_PERSONALIZE = 've/tools/personalization/personalize';
var ACTION_SUBMIT      = 'submit';
var ACTION_CANCEL      = 'cancel';
var ACTION_GOTO        = 'goto';
var ACTION_ADD         = 've/core/Object/add';
var ACTION_REMOVE      = 've/core/Object/remove';
var PORTAL_VHTML_ID    = 'veportal';
var INPUT_WHEREAMI     = 'veWhereAmI';

var ACTION_PROCESSREQUEST_EXECUTE      = 've/meta/ProcessRequest/execute';

var isInEditMode = false;
var currentChildOid = null;
var isSubmitting = false;
var ve_target;
var ve_cid;
var ve_execDefaultParams = null;

function ve_getUrlPrefix( isSecure, includePortal, portalName )
  {
  var levels = ve_target.split( '/' ).length;
  var prefix = "";

  var location = window.location;
  var protocol = location.protocol;

//  if( ( isSecure == null || isSecure == "false" ) && protocol.toLowerCase() == "https:" )
//    protocol = "http:" ;
//  else if( isSecure == "true" )  
//    protocol = "https:";

  var surl = location.href;
  var isDefaultPortal = surl.indexOf( "/" + ve_portal_name + ( ve_target && ve_target != ve_portal_name ? "/" : "" ) ) == -1;
  
  if( ( index = surl.indexOf( "?" ) ) > -1 )
    surl = surl.substring( 0, index );

  index = -1;  
  for( var i = 0 ; i < levels ; i++ )
    {
    if( ( index = surl.lastIndexOf( "/" ) ) > -1 )
      {
      //if( surl.charAt( index + 1 ) != "~" )
        surl = surl.substring( 0, index );
      }
    }

//  if( surl.indexOf( "http://" ) > -1 )
//    prefix = protocol + surl.substring( 5 );
//  else if( surl.indexOf( "https://" ) > -1 )
//    prefix = protocol + surl.substring( 6 );
  prefix = surl;
    
  // Include the portal name always  
  //if( includePortal && ve_portal_name && ( ve_portal_name.indexOf( "ve/tools/personalization" ) == -1 ) )
  //if( ve_portal_name && ( prefix.indexOf( ve_portal_name ) == -1 ) && ( ve_portal_name.indexOf( "ve/tools/personalization" ) == -1 ) )
  if( ve_portal_name && !isDefaultPortal && ( ve_portal_name.indexOf( "ve/tools/personalization" ) == -1 ) )
    {
    prefix += "/" + ( portalName != null && portalName != '' ? portalName : ve_portal_name );
    }

  return prefix + "/";
  //return prefix + ( ve_portal_name ? ( "/" + ve_portal_name ) : "" ) + "/";
  }

function ve_getSecureUrl( link )
  {
  var index = -1;
  var surl = null;
  
  var prefix = ve_getUrlPrefix();
  var levels = prefix.split( '..' ).length;
  
  surl = location.href;
  for( var i = 1 ; i < levels ; i++ )
    {
    if( ( index = surl.lastIndexOf( "/" ) ) > -1 )
      surl = surl.substring( 0, index );
    }
      
  if( surl.indexOf( "http://" ) == 0 )
    surl = "https" + surl.substring( 4 );    
  
  return surl + "/" + link;
  }

function ve_formatUrl( link, isSecure )
  {
  var index = -1;
  var surl = null;
  
  if( link.indexOf( "." ) == -1 )
    {
    surl = location.href;
    
    //if( ( index = surl.lastIndexOf( "~" ) ) > -1 )
    //  {
    //  index = surl.indexOf( "/", index );
      
    //  var remaining = surl.substring( index + 1, surl.length );
    //  surl = surl.substring( 0, index );
    // }
    
    surl = location.href;

    if( ( index = surl.indexOf( "?" ) ) > -1 )
      surl = surl.substring( 0, index );
  
    var levels = ve_target.split( '/' ).length;
    index = -1;  

    for( var i = 0 ; i <= levels ; i++ )
      {
      if( ( index = surl.lastIndexOf( "/" ) ) > -1 )
        {
        if( surl.charAt( index + 1 ) != "~" )
          surl = surl.substring( 0, index );
        }
      }

    var portalName = null;
    var portalTag = getTag( PORTAL_VHTML_ID );
    if( portalTag && portalTag.fullName )
      portalName = portalTag.fullName;
    
    if( portalName && portalName != '' )
      surl = surl + "/" + portalName;
      
    if( isSecure && surl.indexOf( "http://" ) == 0 )
      surl = "https" + surl.substring( 4 );    
    else if( ( isSecure == false || isSecure == null ) && surl.indexOf( "https://" ) == 0 )
      surl = "http" + surl.substring( 5 );    
  
    return link != null && link != '' ? surl + "/" + link : surl;
    }
  else
    {
    if( link.indexOf( "://" ) > -1 )
      return link;
      
    if( isSecure )
      return "https://" + location.host + "/" + link;
    else  
      return "http://" + location.host + "/" + link;
    }  
  }
  
function ve_submit( action )
  {
  if( !isSubmitting )
    {
    try
      {
      isSubmitting = true;
      getTopic( TOPIC_PRESUBMIT ).notify( null, action );
      document.forms[ 0 ].submit();
      }
    catch( ex )
      {
      isSubmitting = false;
      throw ex;
      }
    }
  }

function ve_submitForm( parms , background, listener )
  {
  try
    {
    if( ve_validateRequiredFields() )
      {
      var isSecure = "false";
      var secureTag = getTag( "secure" );
      
      if( secureTag != null )
        isSecure = secureTag.value;
        
      var url = ve_getUrlPrefix( isSecure, true ) + ACTION_SUBMIT + ".v?c=" + ve_cid;
  
      if( parms )
  	    url += "&" + parms;
        
      document.forms[ 0 ].action = url;
        
      if( background )
        {
        document.forms[ 0 ].target = "ve_backgroundPostFrame";
      
        if( listener != null )
          getTopic( "ve_background_post_poll" ).addListener( listener );
          
        ve_backgroundPostPoll.interval = window.setInterval( "ve_backgroundPostPoll()", 200 )
        }
  
      ve_submit();
      }
    }
  catch( e )
    {
    if( e.description )  
      alert( e.description );
      
    if( e.desc )
      {
      alert( "submit error2=" + e.desc );

      if( e.name && e.name != "" )
        {
        var element = getTag( e.name );

        if( element )
          element.focus();
        }
      }
    }
  }

function ve_submitForm_Original( parms , background, listener, event )
  {
  try
    {
    if( !ve_validateRequiredFields() )
      {
      window.event.returnValue = false;	
      window.event.cancelBubble = true;
      return false;
      }
    
    var isSecure = "false";
    var secureTag = getTag( "secure" );
    
    if( secureTag != null )
      isSecure = secureTag.value;
      
    var url = ve_getUrlPrefix( isSecure, true ) + ACTION_SUBMIT + ".v?c=" + ve_cid;

    if( parms )
	    url += "&" + parms;
      
    document.forms[ 0 ].action = url;
      
    if( background )
      {
      document.forms[ 0 ].target = "ve_backgroundPostFrame";
    
      if( listener != null )
        getTopic( "ve_background_post_poll" ).addListener( listener );
        
      ve_backgroundPostPoll.interval = window.setInterval( "ve_backgroundPostPoll()", 200 )
      }

    ve_submit();
    }
  catch( e )
    {
    if( e.description )  
      alert( e.description );
      
    if( e.desc )
      {
      alert( "submit error2=" + e.desc );

      if( e.name && e.name != "" )
        {
        var element = getTag( e.name );

        if( element )
          element.focus();
        }
      }
    }
  }

function ve_cancelForm()
  {
  var elements = document.forms[ 0 ].elements;

  for( var i = elements.length - 1; i >= 0; i-- )
    {
    var toid = elements[ i ].name;

    if( toid && toid.indexOf( "_v" ) == 0 && toid.indexOf( "__" ) == -1 )
      elements[ i ].name = "";
    }

  ve_exec( null, ACTION_CANCEL, null, "c=" + ve_cid );
  }

function ve_submitProcessRequest( oid, action, parms , background, listener )
  {
  try
    {
    if( ve_validateRequiredFields() )
      {
      action = !action ? ACTION_PROCESSREQUEST_EXECUTE : action;  
      //alert( action );
      ve_exec( oid, action );
      }
    }
  catch( e )
    {
    if( e.description )  
      alert( e.description );
      
    if( e.desc )
      {
      alert( "submit error2=" + e.desc );

      if( e.name && e.name != "" )
        {
        var element = getTag( e.name );

        if( element )
          element.focus();
        }
      }
    }
  }

function load( url, id, func )
  {
  if( document.layers )
    document.layers[ id ].load( url, 0 );
  else if( window.frames.length > -1 )
    window.frames[ id ].location.replace( url );

  load.args = arguments;
  load.timer = window.setInterval( "loadComplete()", 200 );
  }

function loadComplete()
  {
  try
    {
    if( window.frames[ load.args[ 1 ] ].document.readyState == "complete" )
      {
      window.clearInterval( load.timer );
      eval( load.args[ 2 ] );
      }
    }
  catch( e )
    {
    window.clearInterval( load.timer );
    alert( "got an exception " + e );
    window.setTimeout( load.args[ 2 ], 1000 );
    }
  }

function ve_load( url )
  {
  ve_load.isLoading = true;
  ve_load.frame = window.frames[ 'veHiddenFrame' ];

  if( !ve_load.frame )
    return;

  ve_load.frame.location.href = url; 
  window.setInterval( "ve_loadComplete()", 200 );
  }

function ve_loadComplete()
  {
  }

function ve_modeexec( oid, action, params, mode, isSecure, listener )
  {
  if( mode == 'Dialog' )
    ve_dialogexec( oid, action, params, isSecure );
  else if( mode == "New Window" )  
    ve_exec( oid, action, null, params, true, isSecure );
  //else if( mode == "Double Buffered" )
  //  ve_execDoubleBuffered( oid, action, params, isSecure );  
  else if( mode == "Background" )
    ve_execBackground( oid, action, params, isSecure, listener );  
  else  
    ve_exec( oid, action, null, params, false, isSecure );
	}

function ve_execBackground( oid, action, params, isSecure, listener )
  {
  var surl = "";
  
  if( action == "ve/core/Globals/submit" )
    {
    surl = ve_getUrlPrefix( isSecure, true ) + ACTION_SUBMIT + ".v?c=" + ve_cid;

    if( params )
      surl += surl.indexOf( "?" ) == -1 ? ( "?" + params ) : ( "&" + params );
    }
  else
    {  
    surl = ve_getUrlPrefix( isSecure, true ) + action + ".v";
  
    if( oid )
      surl += "?o=" + oid;
  
    if( params )
      surl += surl.indexOf( "?" ) == -1 ? ( "?" + params ) : ( "&" + params );
  
    //if( ve_cid )
    //  surl += surl.indexOf( "?" ) == -1 ? ( "?c=" + ve_cid ) : ( "&c=" + ve_cid );
    }

  var form = document.forms[0];
	form.action = surl;
	form.target = "ve_backgroundPostFrame";

  if( listener != null )
    getTopic( "ve_background_post_poll" ).addListener( listener );

//alert( "URL = " + surl );

  ve_progressbar_start();
  form.submit();
	ve_backgroundPostPoll.interval = window.setInterval( "ve_backgroundPostPoll()", 100 )
  }

function ve_backgroundPostPoll()
	{
	if( ve_backgroundPostFrame.document && isDocumentReady( ve_backgroundPostFrame.document ) )
		{
		window.clearInterval( ve_backgroundPostPoll.interval );
    ve_progressbar_stop();
  	document.forms[0].target = "";
    getTopic( "ve_background_post_poll" ).notify();
    return true;
		}

	return false;
	}

function ve_execDoubleBuffered( oid, action, params, isSecure )
  {
  var surl = "";
  
  if( action == "ve/core/Globals/submit" )
    {
    surl = ve_getUrlPrefix( isSecure, true ) + ACTION_SUBMIT + ".v?c=" + ve_cid;

    if( params )
      surl += surl.indexOf( "?" ) == -1 ? ( "?" + params ) : ( "&" + params );
    }
  else
    {  
    surl = ve_getUrlPrefix( isSecure, true ) + action + ".v";
  
    if( oid )
      surl += "?o=" + oid;
  
    if( params )
      surl += surl.indexOf( "?" ) == -1 ? ( "?" + params ) : ( "&" + params );
  
    //if( ve_cid )
    //  surl += surl.indexOf( "?" ) == -1 ? ( "?c=" + ve_cid ) : ( "&c=" + ve_cid );
    }

  ve_setFocusElement();
  ve_setPageId();

  var form = document.forms[0];
	form.action = surl;
	form.target = "ve_backgroundPostFrame";

//alert( "URL = " + surl );

  ve_progressbar_start();
  form.submit();
	ve_backgroundPostPoll.interval = window.setInterval( "ve_doubleBufferedPostPoll()", 100 )
  }
  
function ve_doubleBufferedPostPoll()
	{
	if( ve_backgroundPostFrame.document && isDocumentReady( ve_backgroundPostFrame.document ) )
		{
		var oldFrame = getTag( "ve_backgroundPostFrame_old" );

		var oldScrollDiv = getTag( "ve_scroll_div" );
    if( oldScrollDiv )
      {
      oldScrollDiv.style.overflowX = "visible";
      oldScrollDiv.style.overflowY = "visible";
      oldScrollDiv.id = "";
      }
      
    var scrollDivText = "<div id='ve_scroll_div' style='height:100%;width:100%;overflow-x:auto;overflow-y:scroll;display:inline'></div>";
    var scrollDiv = document.createElement( scrollDivText );
    ve_backgroundPostFrame.document.body.applyElement( scrollDiv, 'inside' );
    document.body.scroll = "no";
        
		window.clearInterval( ve_backgroundPostPoll.interval );
    ve_progressbar_stop();
  	document.forms[0].target = "";

    getTag( "ve_page_div" ).style.display = "none";
    getTag( "ve_page_div" ).innerHTML = "";
    getTag( "ve_background_post_div" ).style.display = "inline";
    
    ve_backgroundPostFrame.scrolling = "no";
    ve_backgroundPostFrame.id = "ve_backgroundPostFrame_old";
    ve_backgroundPostFrame.name = "ve_backgroundPostFrame_old";
    return true;
		}

	return false;
	}
	
function isDocumentReady( doc )
  {
  if( doc && ( doc.readyState == "4" || doc.readyState == "complete" ) )
    return true;

  return false;
  }	

function ve_exec( oid, action, member, params, newWindow, isSecure, mode, listener, confirmMsg, execParms )
  {
  if( confirmMsg != null && confirmMsg != '' && confirmMsg != 'null' )
    {
    if( !confirm( confirmMsg ) )
      return false;
    }
  
  if( mode == 'Dialog' )
    {
    if( execParms != null )
      {
      // Sample : title="Test"&executeOnOk=null&closeOnOk=true&height="300"&width="250"&isModal=false&autoSize=false	
      var eparmValues = execParms != null && execParms != "" ? execParms.split( "&" ) : {};	
      var map = new Array();

      for( var i = 0 ; i < eparmValues.length ; i++ )
        {
        var value = eparmValues[i];
	
	  if( value.indexOf( "=" ) > -1 )
          {
	    var keyvalue = value.split( "=" );
          var key = keyvalue[0];
	    var val = keyvalue[1];
          map[key] = val; 
	    }
        }
      
      var title = map[ "title" ];	
      var executeOnOk =  map["executeOnOk"] == null ? listener : map["executeOnOk"];
      var closeOnOk = map["closeOnOk"] == null ? true : map["closeOnOk"];
      var height = map["height"];
      var width = map["width"];
      var isModal = map["isModal"] == null ? true : map["isModal"];
      var autoSize = map["autoSize"] == null ? true : map["autoSize"];
      var view = map["view"];
	
	    if( view )
	      {
	      if( params )
	        params += "&view=" + view;
	      else
	        params = "view=" + view;
	      }
	
      //function ve_dialogexec( oid, action, member, params, title, executeOnOk, closeOnOk, height, width, isModal, isSecure, autoSize )
      return ve_dialogexec( oid, action, member, params, title, executeOnOk, closeOnOk, height, width, isModal, isSecure, autoSize );
      }
    else
      {
      //function ve_dialogexec( oid, action, member, params, title, executeOnOk, closeOnOk, height, width, isModal, isSecure, autoSize )
      return ve_dialogexec( oid, action, member, params, "", listener, true, null, null, true, isSecure, true );
      }
    }
  else if( mode == "Background" )
    return ve_execBackground( oid, action, params, isSecure, listener );  

  if( mode == "New Window" )  
    newWindow = true;
  
  var veop;

  if( action == "ve/core/Globals/submit" )
    {
    ve_submitForm();
    return;
    }
  else if( ( veop = veopsupport_getOperation( oid, action ) ) != null )
    return veop.execute();
    
  //var surl = ve_getUrlPrefix( isSecure ) + action + ".v";
  var surl = null;

  if( action == ACTION_CANCEL )
    surl = ve_getUrlPrefix( isSecure, false ) + action + ".v";
  else
    surl = ve_getUrlPrefix( isSecure, true ) + action + ".v";

  if( oid )
    surl += "?o=" + oid;

  if( member )
    surl += surl.indexOf( "?" ) == -1 ? ( "?m=" + member ) : ( "&m=" + member );

  if( params )
    surl += surl.indexOf( "?" ) == -1 ? ( "?" + params ) : ( "&" + params );

  //if( ve_cid )
  //  surl += surl.indexOf( "?" ) == -1 ? ( "?c=" + ve_cid ) : ( "&c=" + ve_cid );

  if( ve_execDefaultParams )
    surl += ( surl.indexOf( "?" ) == -1 ? "?" : "&" ) + ve_execDefaultParams;
 
  if( newWindow )
    {
    if( oid && action && action.indexOf( "Request/execute" ) == action.length - 15 )
      ve_execProcessInNewWindow( surl, oid, execParms );
    else
      ve_postInNewWindow( surl, null, execParms );
      
    //window.open( surl, "_blank", "directories=no,location=no,menubar=no,toolbar=no,resizable=yes" );
    }
  else
    {
    ve_setFocusElement();
    ve_setPageId();

    document.forms[ 0 ].target = newWindow ? "_blank" : "";
    document.forms[ 0 ].action = surl;
    ve_submit( action );
    }
  }

function ve_save( oid )
  {
  var url = ve_getUrlPrefix( false, true ) + ACTION_NOOP + ".v?o=" + oid;

  //if( ve_cid )
  //  url += "&c=" + ve_cid;

  document.forms[ 0 ].action = url;
  ve_submit( ACTION_NOOP );
  }

function ve_personalize()
  {
  var url = ve_getUrlPrefix( false, false ) + ACTION_PERSONALIZE + ".v";

  var wmiOid = ve_getWhereAmI();
  
	if( wmiOid )
		url += "?veWhereAmI=ve_oid:wai:" + wmiOid + "&wmi=ve_oid:wai:" + wmiOid;

  var view = getTag( "view" );
  if( view && view.value )
		url += "&view=" + view.value;

//alert( "Personalization URL ----> " + url );

  window.location.replace( url );
  }
  
function ve_refresh( background, params, listener )
  {
  var url = ve_getUrlPrefix(false, true) + ACTION_NOOP + ".v";

  if( params != null )
    url = url.indexOf( "?" ) > -1 ? ( url + "&" + params ) : ( url + "?" + params );

  if( background )
    {
    //ve_progressbar_start();

    document.forms[ 0 ].target = "ve_backgroundPostFrame";
    ve_backgroundPostPoll.interval = window.setInterval( "ve_backgroundPostPoll()", 100 )
    
    if( listener != null )
      getTopic( "ve_background_post_poll" ).addListener( listener );
    }
  else
    {
    ve_setFocusElement();
    ve_setPageId();
    }

  document.forms[ 0 ].action = url;
  ve_submit( ACTION_NOOP );
  }

function ve_fetch( oid, member, params )
  {
  if( !document.all )
    {
    if( member != undefined && member != null )
      window.setTimeout( "ve_exec( " + oid + ", ACTION_FETCH, '" + member + "', " + ( params ? "'" + params + "'" : "null" ) + ", false, false )", 500 );
    else  
      window.setTimeout( "ve_exec( " + oid + ", ACTION_FETCH, null, " + ( params ? "'" + params + "'" : "null" ) + ", false, false )", 500 );
      
    return;
    }
      
  ve_exec( oid, ACTION_FETCH, member, params, false, false );
  }

function ve_navigate( link, isSecure, parms, resource )
  {
  if( isInEditMode )
    {
    //ve_exec( null, resource );
    }
  else
    {    
    if( link.length > 0 && link.indexOf( "." ) == -1 && link.substring( 0, 1 ) == "/" )
      link = link.substring( 1 );
  
    var surl = ve_getUrlPrefix( isSecure, true ) + link;

    if( parms )
      surl = surl + "?" + parms;
        
    window.location.href = surl;
    }
  }

function ve_launch( target, parms, isSecure )
  {
  if( target.length > 0 && target.indexOf( "." ) == -1 )
    target = target + ".v";
  
  var surl = ve_getUrlPrefix( isSecure, true ) + target;

  if( parms )
    surl = surl + ( target.indexOf( "?" ) == -1 ? "?" : "&" ) + parms;
        
  window.location.href = surl;
  }

///////////////
// SMART GUI //
///////////////

function validateRequired( name, displayName )
  {
  var element = getTag( name );

  if( element )
    {
    var value = element.value;

    if( value == null || value == "" )
      throw new RequiredFieldException( name, displayName );
    }
  }

///////////////////////
// PAGE HOUSEKEEPING //
///////////////////////

function newImage( arg )
  {
  if( document.images )
    {
    var im = new Image();
    im.src = arg;
    return im;
    }
  else
    return null;
  }

function preloadImages()
  {
  if( document.images )
    {
    newImage( "/ve/res/images/shim.gif" );
    getTopic( TOPIC_PRELOADIMAGES ).notify();
    }
  }

function runOnLoad()
  {
  preloadImages();
  getTopic( TOPIC_ONLOAD ).notify();
  
  window.setTimeout( 'setFocusOnLoad()', 100 );

  // TODO : A complete hack to get the page div working in Netscape......
  if( !document.all && document.getElementById( "ve_page_div" ) )
    {
    document.getElementById( "ve_page_div" ).style.width = "98%";
    document.getElementById( "ve_page_div" ).style.height = "98%";
    }
  }

function runOnUnload()
  {
  getTopic( TOPIC_ONUNLOAD ).notify();
  ve_page_cleanup();
  }

function runOnWindowResize()
  {
  getTopic( TOPIC_WINDOW_RESIZE ).notify();
  }
  
function ve_page_cleanup()
  {
  VEDialog_closeDialogWindows();
  }

function ve_update_selected( topic, oids, selectedName )
  { 
  var selected = getTag( selectedName ? selectedName : "ve_selected" );

  if( !selected )
    return;

  var byTopic = selected.byTopic;

  if( !byTopic )
    selected.byTopic = byTopic = new Object();

  byTopic[ topic ] = oids;
  var all = new Array();

  for( var aTopic in byTopic )
    {
    var topicOids = byTopic[ aTopic ];

    if( topicOids && topicOids != "" )
      all[ all.length ] = topicOids;
    }

  selected.value = all.length == 1 ? all[ 0 ] : all.join( ',' );
  }

/////////////////////////////
// DIALOG ENVELOPE METHODS //
/////////////////////////////

var ENVELOP_STATUS_OK = "envelop_ok";
var ENVELOP_STATUS_CANCEL = "envelop_cancel";
var DIALOG_WINDOW;
var DIALOG_TITLE;
var DIALOG_EXECUTE_ONOK;
var NS = window.captureEvents;
var ve_dialogWindowIndex = 0;
var ve_dialogWindowObjects = new Array();

function VEDialog_getDialogWindow( name ) 
  {
  var dialogObject = null;
  
  for( var i = 0; i < ve_dialogWindowObjects.length; i++ ) 
    {
    if( ve_dialogWindowObjects[i] != null ) 
      {
      var d = ve_dialogWindowObjects[i];
      
      if( d.getName() == name )
        {
        dialogObject = d;
        break;
        }
      }
    }
    
  return dialogObject;  
  }
  
function VEDialog_closeDialogWindows() 
  {
  for( var i = 0; i < ve_dialogWindowObjects.length; i++ ) 
    {
    if( ve_dialogWindowObjects[i] != null ) 
      {
      var d = ve_dialogWindowObjects[i];
      d.hide();
      }
    }
  }
  
function VEDialog_onPostComplete( name )
  {
  var dialog = VEDialog_getDialogWindow( name );
  dialog.onPostComplete();
  }

VEDialog.popupWindow = null;

function VEDialog( oid, action, member, params, title, executeOnOk, closeOnOk, height, width, isModal, isSecure, autoSize, portalName )
  {
  if( !window.ve_dialogWindowIndex ) 
    window.ve_dialogWindowIndex = 0;
    
  if( !window.ve_dialogWindowObjects )
    window.ve_dialogWindowObjects = new Array();

  this.index = ve_dialogWindowIndex++;
  this.name = "ve_dialog_window_" + this.index;
  ve_dialogWindowObjects[ this.index ] = this;

  this.popupWindow = null;
  this.url = null;
  this.returnValue = null;
  
  this.autoSize = autoSize == 'undefined' ? false : autoSize;
  this.oid = oid;
  this.action = action;
  this.member = member;
  this.params = params;
  this.usePost = params && params.constructor != String;
  this.title = title;
  this.executeOnOk = executeOnOk;
  this.closeOnOk = closeOnOk;
  this.width = width != null && width != "" ? width : 400;
  this.height = height != null && height != "" ? height : 600;
  this.isModal = isModal;
  this.isSecure = isSecure;
  this.offsetX = 0;
  this.offsetY = 0;
  this.x = 0;
  this.y = 0;
  this.thisWindow = window;
  this.portalName = portalName;
  
  // Method mappings
  
  this.refresh = function()
    {
    if( this.popupWindow != null && !this.popupWindow.closed ) 
      this.popupWindow.location.replace( this.url );
    };
  
  this.show = function()
    {
    if( this.popupWindow == null || this.popupWindow.closed ) 
      {
      var xMax = 640, yMax = 480;

      this.x = 300;
      this.y = 300;
      
      if( document.all ) 
        {
        this.x = this.autoSize ? (screen.width - 100)/2 : (screen.width - this.width)/2;
        this.y = this.autoSize ? (screen.height - 100)/2 : (screen.height - this.height)/2; 
        }
      else
        { 
        this.x = this.autoSize ? (screen.availWidth - 100) / 2 : (screen.availWidth - this.width) / 2;
        this.y = this.autoSize ? (screen.availHeight - 100) / 2 : (screen.availHeight - this.height) / 2;
        } 

      this.url  = ve_getUrlPrefix( isSecure, true, portalName ) + this.action + ".v";

      if( this.oid )
        this.url += "?o=" + this.oid;

      var isFirst = this.url.indexOf( "?" ) == -1;
      if( this.member )
        this.url += isFirst ? ( "?m=" + this.member ) : ( "&m=" + this.member );

      isFirst = this.url.indexOf( "?" ) == -1;
      if( this.params && !this.usePost )
        this.url += isFirst ? ( "?" + this.params ) : ( "&" + this.params );

      isFirst = this.url.indexOf( "?" ) == -1;
      
      if( this.params && !this.usePost && this.params.indexOf( "view=" ) > -1 )
        this.url += ( isFirst ? "?" : "&" ) + "vetemplateId=Dialog";
      else  
        this.url += ( isFirst ? "?" : "&" ) + "vetemplateId=Dialog&view=Dialog";

      var wai = ve_getWhereAmI();
      
      if( wai )
        this.url += "&veWhereAmI=:" + wai;
        
      var features = null;
      
      if( this.width > 0 && this.height > 0 && ( !this.autoSize || this.autoSize == false || this.autoSize == "false" ) )
	      {
        features = "resizable=yes,minimize=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,alwaysRaised,dependent,titlebar=no,width=" + this.width + ",height=" + this.height + ",screenX=" + this.x + ",left=" + this.x + ",screenY=" + this.y + ",top=" + this.y + "";
	      }
      else
        {
        features = "resizable=yes,minimize=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,alwaysRaised,dependent,titlebar=no,width=100,height=100,screenX=" + this.x + ",left=" + this.x + ",screenY=" + this.y + ",top=" + this.y + "";
	      }

      if( this.usePost )
        {
        this.popupWindow = window.open( "about:blank", this.name, features );
        var form = ve_newForm( true );

        for( var key in this.params )
          {
          var value = this.params[ key ];
        
          if( value && value.constructor == String && value.indexOf( "ve_oid:" ) == 0 )
            this.url += "&" + key + "=" + value;
          else
            ve_appendChildToForm( form, key, value );
          }

        form.action = this.url;
        form.target = this.name;
        form.method = "POST";
        var docBody = document.getElementsByTagName( "body" )[ 0 ];
        docBody.appendChild( form );
        form.submit();
        docBody.removeChild( form );
        }
      else
        this.popupWindow = window.open( this.url, this.name, features );

	//if( autoSize )
	//  {
	//  this.popupWindow.sizeToContent();
	//  this.popupWindow.sizeToContent();	

	//  for reasons beyond understanding, only if we call it twice we get the correct size.
	//  }

      if( this.isModal )
        {
        VEDialog.popupWindow = this.popupWindow;
        this.captureWindow( window );
        for( var i = 0; i < window.frames.length; this.captureWindow( window.frames[ i++ ] ) );
        }
      }
    else
      {
      this.popWindow.location.replace( this.url );
      }

    this.popupWindow.focus();
    };

  this.hide = function()
    {
    if( this.popupWindow && !this.popupWindow.closed ) 
      {
      this.popupWindow.close();
      this.popupWindow = null;
      
      if( this.isModal )
        {
        VEDialog.popupWindow = null;

  	    this.releaseWindow( window );
  	    for( var i = 0; i < window.frames.length; this.releaseWindow( window.frames[ i++ ] ) );
  	    }
      }
    };

  this.autoHide = function()
    {
    this.hide();
    
    if( !this.closeOnOk && this.executeOnOk )
      {
      eval( this.executeOnOk );
      return;
      }
      
    setTimeout( "ve_refresh()", 10 );
    };
    
  this.getWidth = function()
    {
    return this.width;
    };

  this.getHeight = function()
    {
    return this.height;
    };

  this.getTitle = function()
    {
    return this.title;
    }; 

  this.getName = function()
    {
    return this.name;
    }; 

  this.setSize = function( width, height )  
    {
    this.width = width;
    this.height = height;
    };

  this.onPostComplete = function() 
    {
    this.returnValue = ENVELOP_STATUS_OK;
    //alert( "Dialog post complete..." );          

    if( this.closeOnOk )
      {
      //alert( "Closing on OK..." );
      this.hide();

      if( this.executeOnOk )
        eval( this.executeOnOk );
      }
    else
      {
      //alert( "Setting opener..." );
      //this.popupWindow.opener = window;
      }  
    };

  this.onOk_Old = function( isSubmit )
    {
    if( this.isModal )
      {
      if( isSubmit )
        {
        //alert( "Modal Submit" );
        //this.popupWindow.ve_submitForm( "vetemplateId=Dialog&view=Dialog", true, "opener.VEDialog_onPostComplete( '" + this.name + "' )" );
        this.popupWindow.ve_submitForm( "vetemplateId=Dialog&view=Dialog" );
        }
      else  
        {
        //alert( "Modal Refresh" );
        this.popupWindow.ve_refresh( true, null, "opener.VEDialog_onPostComplete( '" + this.name + "' )" );
        }
      }
    else
      {
      this.returnValue = ENVELOP_STATUS_OK;

      if( this.popupWindow && !this.popupWindow.closed ) 
        {
        if( this.closeOnOk )
          {
          //alert( "Non-modal close on ok..." );
          this.popupWindow.ve_submitForm( "vetemplateId=Dialog&view=Dialog", true, "opener.VEDialog_onPostComplete( '" + this.name + "' )" );
          }
        else  
          {
          //alert( "Non-modal Submit" );
          this.popupWindow.ve_submitForm( "vetemplateId=Dialog&view=Dialog" );
          }
        }
      }
    };

  this.onOk = function( isSubmit )
    {
    this.returnValue = ENVELOP_STATUS_OK;

    if( isSubmit )
      {
      if( this.closeOnOk )
        this.popupWindow.ve_submitForm( "vetemplateId=Dialog&view=Dialog", true, "opener.VEDialog_onPostComplete( '" + this.name + "' )" );
      else
        this.popupWindow.ve_submitForm( "vetemplateId=Dialog&view=Dialog" );
      }
    else  
      {
      if( this.closeOnOk )
        this.popupWindow.ve_refresh( true, null, "opener.VEDialog_onPostComplete( '" + this.name + "' )" );
      else
        this.popupWindow.ve_refresh( true );
      }
    };

  this.processRequestOnOk = function( oid, action )
    {
    this.returnValue = ENVELOP_STATUS_OK;

    //alert( "VEDialog.executeOnOk::OID = " + oid );

    if( this.closeOnOk )
      this.popupWindow.ve_submitProcessRequest( oid, action, "vetemplateId=Dialog&view=Dialog", true, "opener.VEDialog_onPostComplete( '" + this.name + "' )" );
    else
      this.popupWindow.ve_submitProcessRequest( oid, action, "vetemplateId=Dialog&view=Dialog" );
    };

  this.onCancel = function()
    {
    this.returnValue = ENVELOP_STATUS_CANCEL;
    this.hide();
    };

  this.onHelp = function()
    {
    };
  
  this.captureWindow = function( w ) 
    {
    if( document.all )
      {
  	  w.attachEvent( "onclick", VEDialog.handleParentEvent );
  	  w.attachEvent( "onmouseover", VEDialog.handleParentEvent );
  	  w.attachEvent( "onmousedown", VEDialog.handleParentEvent );
  	  w.attachEvent( "onfocus", VEDialog.handleParentEvent );
  	  w.document.body.attachEvent( "onmouseover", VEDialog.handleParentEvent );
  	  w.document.body.attachEvent( "onmousedown", VEDialog.handleParentEvent );
      }
    else
      {
  	  w.addEventListener( "click", VEDialog.handleParentEvent, true );
  	  w.addEventListener( "mouseover", VEDialog.handleParentEvent, true );
  	  w.addEventListener( "mousedown", VEDialog.handleParentEvent, true );
  	  w.addEventListener( "focus", VEDialog.handleParentEvent, true );
  	  w.document.body.addEventListener( "mouseover", VEDialog.handleParentEvent, true );
  	  w.document.body.addEventListener( "mousedown", VEDialog.handleParentEvent, true );
  	  }
    };
	    
  this.releaseWindow = function( w ) 
    {
    if( document.all )
      {
  	  w.detachEvent( "onfocus", VEDialog.handleParentEvent );
  	  w.detachEvent( "onmousedown", VEDialog.handleParentEvent );
  	  w.detachEvent( "onmouseover", VEDialog.handleParentEvent );
  	  w.detachEvent( "onclick", VEDialog.handleParentEvent );
  	  w.document.body.detachEvent( "onmouseover", VEDialog.handleParentEvent );
  	  w.document.body.detachEvent( "onmousedown", VEDialog.handleParentEvent );
      }
    else
      {
  	  w.removeEventListener( "focus", VEDialog.handleParentEvent, true );
  	  w.removeEventListener( "mousedown", VEDialog.handleParentEvent, true );
  	  w.removeEventListener( "mouseover", VEDialog.handleParentEvent, true );
  	  w.removeEventListener( "click", VEDialog.handleParentEvent, true );
  	  w.document.body.removeEventListener( "onmouseover", VEDialog.handleParentEvent, true );
  	  w.document.body.removeEventListener( "onmousedown", VEDialog.handleParentEvent, true );
  	  }
    };
  }
    
VEDialog.handleParentEvent = function( evt ) 
  {
  if( VEDialog.popupWindow && !VEDialog.popupWindow.closed ) 
	  {
		VEDialog.popupWindow.focus();
		
		if( document.all )
		  {
		  evt.cancelBubble = true;
		  evt.returnValue = false;
		  }
		else
		  {
		  evt.preventDefault();
		  evt.stopPropagation();
		  }
	  }
  }

function ve_dialogexec( oid, action, member, params, title, executeOnOk, closeOnOk, height, width, isModal, isSecure, autoSize )
  {
  var dialog = new VEDialog( oid, action, member, params, title, executeOnOk, closeOnOk, height, width, isModal, isSecure, autoSize, ve_portal_name );
  dialog.show();
  }

//////////////////////////////////////
// END MODEL DIALOG ENVELOP METHODS //
//////////////////////////////////////

////////////////////////////////
// SUPPORT & UTILITY METHODS ///
////////////////////////////////

function ve_isSamePage()
  {
  var prevPageTag = getTag( 'vePageId' );
  var prevPageId = prevPageTag != null ? prevPageTag.value : null;
  
  return ve_pageId != null && prevPageId != null && ve_pageId == prevPageId;
  }

function ve_setPageId()
  {
  var prevPageTag = getTag( 'vePageId' );
  if( prevPageTag )
	  prevPageTag.value = ve_pageId;  
  }

function ve_setFocusElement()
  {
	// Set the focus tag to current active element if not set yet.
  var focusTag = getTag( "ve_current_focus" );
  
  if( focusTag && !focusTag.value )
    {
    var activeEl = document.activeElement;

    if( activeEl && activeEl.tagName.toLowerCase() != "button" )
      focusTag.value = activeEl.id;
    }
  }
  
function ve_checkApplet( appletName, handler )
  {
  var browser = getBrowser();

  if( browser.indexOf( "Microsoft" ) > -1 )
    {
    var applet = eval( "document." + appletName );
    
    if( document && applet && applet.readyState == "4" )
      handler();
    else
		  setTimeout( ve_checkApplet, 100, appletName, handler );
    }
  else
    {
    if( document && document.applets[ appletName ] && document.applets[ appletName ].isActive() )
      handler();
    else
		  setTimeout( ve_checkApplet, 100, appletName, handler );
    }
  }  

////////////////////////////////////////////////////////////////
// Private Functions related to managing focus within the form//
////////////////////////////////////////////////////////////////

var ve_focusFirst = null;
var ve_focusIndex = -1;
var ve_focusCurrent = null;

function setFocusOnLoad()
  {
  try
    {	
    // Calculate generateTabEvent value
    var generateTabTag = document.getElementById( "ve_generate_tabevent" );	
    var generateTabEvent = generateTabTag && generateTabTag.value != null &&  generateTabTag.value != "" ? generateTabTag.value : "false";
  	
    // Set the focus to the previously active element	in the form
    var focusIdTag = document.getElementById( "ve_current_focus" );	
    var focusElementId = focusIdTag ? focusIdTag.value : null;
       
    if( focusIdTag )
      focusIdTag.value = "";

    if( ve_isSamePage() && focusElementId )
      {
      var focusElement = getTag( focusElementId );	

      if( focusElement )
        {
        if( focusElement.rows )
          {
          var row = focusElement.rows.length > 0 ? focusElement.rows[ focusElement.rows.length - 1 ] : null;

          if( row && row.cells )
            {
            for( var i = 0 ; i < row.cells.length ; i++ )
              {	
              var cell = row.cells[ i ];

              if( cell && ve_setFocusInCell( cell ) )
  	          return;
	        }
            }
          }
        else
          {  
          focusElement.focus();
			    
          if( generateTabEvent == "true" )
            {
            if( generateTabTag )	
              generateTabTag.value = "false";
						
            ve_shiftFocus( focusElement );	      	
            }
			    
            return;
	    }
        }
      }
	    
    // Otherwise, set the focus to the very first focusable element in the form  
    var form = document.forms[0];
	
    for( var i = 0 ; i < form.elements.length ; i++ )
      {
      var element = form.elements[i];
	
      if( isFocusable( element ) )
        {
        element.select();
        element.focus();
        ve_focusCurrent = element;
        ve_focusFirst = element;
        ve_focusIndex = i;
        return;
        }
  	}
    }
  catch( e )
    {
    //Ignore	
    }	
  }
	
function ve_shiftFocus( element )
  {
  try
	  {	
	  var candidate = null;
		var form = element.form;
	  
	  var j = 0;
	  for( j = 0 ; j <= form.elements.length ; j++ )
	    {
	    if( element == form.elements[j] ) 
	      break;
	    }
	   
	  if( j < form.elements.length )
		  {
		  for( var i = j + 1 ; i < form.elements.length ; i++ )
		    {
		    element = form.elements[i];
		
		    if( isFocusable( element ) )
		      {
		      ve_focusIndex = i;
		      candidate = element;	
		      break;
		      }
		  	}
	  	}

	  if( candidate != null )
	  	{
	  	candidate.select();	
	    candidate.focus();    
	    }
	  else
	    {
	    ve_focusIndex = 0;
	    ve_focusFirst.select();  
	    ve_focusFirst.focus();  
	    }
  	}
  catch( e )
    {
    //Ignore	
  	}	
	}

function isFocusable( element )
  {
  if( element && element.name != null && element.type != 'hidden' && element.type != 'button' && element.type != 'image' && element.tabIndex != -1 )
    {
  	if( element.readOnly && element.readOnly == true )
  	  return false;
  	  
  	return true;  
    }
  
  return false;
	}

function ve_setFocusInCell( cell )
  {
  var children = cell.children;
  if( children && children.length > 0 )
    {
    for( var i = 0 ; i < children.length ; i++ )
      {	
      var candidate = children[i];
      if( isFocusable( candidate ) )
        {
        candidate.focus();
        
        try
          {
          candidate.select();
          }
        catch( e )
          {
          }
        
        return true;
        }
      }
    }  

  children = cell.getElementsByTagName( "input" );
  if( children && children.length > 0 )
    {
    for( var i = 0 ; i < children.length ; i++ )
      {	
      var candidate = children[i];
      if( isFocusable( candidate ) )
        {
        candidate.focus();
        
        try
          {
          candidate.select();
          }
        catch( e )
          {
          }
        
        return true;
        }
      }
    }  

  children = cell.getElementsByTagName( "select" );
  if( children && children.length > 0 )
    {
    for( var i = 0 ; i < children.length ; i++ )
      {	
      var candidate = children[i];
      if( isFocusable( candidate ) )
        {
        candidate.focus();
        
        try
          {
          candidate.select();
          }
        catch( e )
          {
          }
        
        return true;
        }
      }
    }  
   
  return false;  
  }

function ve_onFocus( eventObj, element )
  {
  var i = 0;
  
  for( i = 0 ; i <= element.form.elements.length ; i++ )
    if( element == element.form.elements[i] ) 
      break;
      
  ve_elementIndex = i;
	ve_focusElement = element;

	return true;
  }


/////////////////////////////////////	
//Key manipulation Functions	///////
/////////////////////////////////////

function ve_onKeyDown( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if (document.all) 
		keyCode=eventObj.keyCode;
	else
		keyCode=eventObj.which;

	//if( keyCode == 13 )
	//  eventObj.keyCode = 9;

	return true;
  }

function ve_keyCheck( eventObj, keyCode, element )
  {
//	if( element != null && keyCode != 9 )
//		{
//		if( element.maxLength && element.value.length + 1 == element.maxLength )
//		  {
//		  element.value = element.value + String.fromCharCode( keyCode );
//		  ve_shiftFocus( element );
//			eventObj.returnValue = false;
//			return false;
//			}
//		}

	return true;
  }

function isGlobal( keyCode )
  {
//  return false; //keyCode >= 35 && keyCode <= 40;	
  return ( keyCode >= 63232 && keyCode <= 63235 ) || keyCode == 63272 || keyCode == 0 || keyCode == 8 || keyCode == 9;
  }

/////////////////////////////////////	
//Input validation Functions	///////
/////////////////////////////////////

function ve_fieldChanged( element, topic, pattern, message )
  {
  if( pattern && element.value && new RegExp( pattern ).test( element.value ) == false )
    {
    alert( message ? message : "Invalid format" );
    setTimeout( function() { element.select(); element.focus(); }, 1 );
    return false;
    }

  element.name = element.id;
  getTopic( topic ).notify( element.id );
  }

function ve_validateInputForFloat( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all )
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;

	if( isGlobal( keyCode ) )
	  return true;
	  
	var str = element.value;
  var dec = VELOCALE_DECIMALSEPARATOR.charCodeAt( 0 );
  
	if( keyCode == dec )
		return str.indexOf( VELOCALE_DECIMALSEPARATOR ) < 0;
  else if( keyCode == 45 ) // -
    {
    if( str.length == 0 || ( browser.isIE && document.selection.type.toLowerCase() != 'none' ) )
      return true;      
    else if( str.indexOf( '-' ) == -1 )
      if( browser.isIE )
        {
        var range = element.createTextRange();   
        range.move( "character", 0 );   
        range.select();   
        return true;
        }
      else
        element.value = '-' + str;
      
    return false;
    }

  // Allow only integers and decimal points
	if( keyCode < 48 || keyCode > 57 ) 
		return false;

	return ve_keyCheck( eventObj, keyCode, element );
  }

function ve_validateInputForDouble( eventObj, element )
  {
	return ve_validateInputForFloat( eventObj, element );
  }

function ve_validateInputForInteger( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all ) 
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;

	if( isGlobal( keyCode ) )
	  return true;
  else if( keyCode == 45 ) // -
    {
    var str = element.value;
    
    if( str.length == 0 )
      return true;      
    else if( str.indexOf( '-' ) == -1 )
      element.value = '-' + str;
      
    return false;
    }

  // Allow only integers
	if( keyCode < 48 || keyCode > 57 ) 
		return false;

	return ve_keyCheck( eventObj, keyCode, element );
  }

function ve_validateInputForShort( eventObj, element )
  {
	return ve_validateInputForInteger( eventObj, element );
  }

function ve_validateInputForString( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all ) 
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;

	if( isGlobal( keyCode ) )
	  return true;

  if( element && element.vepattern && element.vepattern.length > 1 )
    {
    var pattern = element.vepattern;

    if( pattern.charAt( pattern.length - 1 ) == '*' )
      if( keyCode >= 65 && keyCode <= 122 )
        {
        var upper = pattern.indexOf( "\\p{Upper}" );
        var lower = pattern.indexOf( "\\p{Lower}" );

        if( upper != -1 && lower == -1 && keyCode >= 97 && keyCode <= 122 )
          event.keyCode = keyCode - 32;
        else if( upper == -1 && lower != -1 && keyCode >= 65 && keyCode <= 90 )
          event.keyCode = keyCode + 32;

        //var str = String.fromCharCode( event.keyCode );
        }
      else if( keyCode == 32 )
        return pattern.indexOf( "\\s" ) != -1 || pattern.indexOf( "\\p{Space}" ) != -1 || pattern.indexOf( "\\p{Blank}" ) != -1;
    }

  return ve_keyCheck( eventObj, keyCode, element );
  }

function ve_validateInputForLong( eventObj, element )
  {
  return ve_validateInputForInteger( eventObj, element );
  }
	
function ve_validateInputForByte( eventObj, element )
  {
	return ve_validateInputForInteger( eventObj, element );
  }

function ve_validateInputForCharacter( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all ) 
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;

	if( isGlobal( keyCode ) )
	  return true;

	return ve_keyCheck( eventObj, keyCode, element );
  }
	
function ve_validateInputForColor( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all ) 
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;

	if( isGlobal( keyCode ) )
	  return true;

  // Allow numeric characters
  if( keyCode >= 48 && keyCode <= 57 )
		return ve_keyCheck( eventObj, keyCode, element );

	// Allow all lowercase & uppercase letters
	if( ( keyCode >= 65 && keyCode <= 90 ) || ( keyCode >= 97 && keyCode <= 122 ) )
		return ve_keyCheck( eventObj, keyCode, element );	

	return false;
  }
	
function ve_validateInputForDate( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all ) 
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;
		
	if( isGlobal( keyCode ) )
	  return true;

  // Allow "/" or "." or "-" characters
	if( keyCode >= 45 && keyCode <= 47 )
		return ve_keyCheck( eventObj, keyCode, element );	

  // Allow numeric characters
  if( keyCode >= 48 && keyCode <= 57 )
		return ve_keyCheck( eventObj, keyCode, element );

	return false;
  }
	
function ve_validateInputForTimestamp( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all ) 
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;
		
	if( isGlobal( keyCode ) )
	  return true;

  // Allow " ", "/" or ":" characters
	if( keyCode == 32 || keyCode == 47 || keyCode == 58 )
		return ve_keyCheck( eventObj, keyCode, element );	

  // Allow numeric characters
  if( keyCode >= 48 && keyCode <= 57 )
		return ve_keyCheck( eventObj, keyCode, element );

  // Allow A,P and M characters
  if( keyCode == 65 || keyCode == 77 || keyCode == 80 )
		return ve_keyCheck( eventObj, keyCode, element );

  // Allow a,p and m characters
  if( keyCode == 97 || keyCode == 109 || keyCode == 112 )
    {
    eventObj.keyCode = keyCode - 32;
    return ve_keyCheck( eventObj, keyCode, element );
    }

  return false;
  }

function ve_validateInputForTime( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all ) 
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;
		
	if( isGlobal( keyCode ) )
	  return true;

  // Allow " " or ":" characters
	if( keyCode == 32 || keyCode == 58 )
		return ve_keyCheck( eventObj, keyCode, element );	

  // Allow numeric characters
  if( keyCode >= 48 && keyCode <= 57 )
		return ve_keyCheck( eventObj, keyCode, element );

  // Allow A,P and M characters
  if( keyCode == 65 || keyCode == 77 || keyCode == 80 )
		return ve_keyCheck( eventObj, keyCode, element );

  // Allow a,p and m characters
  if( keyCode == 97 || keyCode == 109 || keyCode == 112 )
    {
    eventObj.keyCode = keyCode - 32;
    return ve_keyCheck( eventObj, keyCode, element );
    }

	return false;
  }

function ve_validateInputForPassword( eventObj, element )
  {
	var keyCode = null;

	// Check For Browser Type
	if( document.all ) 
		keyCode = eventObj.keyCode;
	else
		keyCode = eventObj.which;
		
	if( isGlobal( keyCode ) )
	  return true;

  // Allow special characters and numeric characters
  if( keyCode >= 33 && keyCode <= 57 )
		return ve_keyCheck( eventObj, keyCode, element );

	// Allow all lowercase & uppercase letters
	if( ( keyCode >= 65 && keyCode <= 90 ) || ( keyCode >= 97 && keyCode <= 122 ) )
		return ve_keyCheck( eventObj, keyCode, element );	

	return false;
  }
	
// FORMATTING METHODS
	
function ve_validateValue( strValue, strMatchPattern ) 
  {
  /************************************************
  DESCRIPTION: Validates that a string a matches
    a valid regular expression value.
      
  PARAMETERS:
     strValue - String to be tested for validity
     strMatchPattern - String containing a valid
        regular expression match pattern.
        
  RETURNS:
     True if valid, otherwise false.
  *************************************************/
  var objRegExp = new RegExp( strMatchPattern);
   
  //check if string matches pattern
  return objRegExp.test(strValue);
  }


function ve_rightTrim( strValue ) 
  {
  /************************************************
  DESCRIPTION: Trims trailing whitespace chars.
      
  PARAMETERS:
     strValue - String to be trimmed.  
        
  RETURNS:
     Source string with right whitespaces removed.
  *************************************************/
  var objRegExp = /^([\w\W]*)(\b\s*)$/;
   
  if(objRegExp.test(strValue)) 
    {
    //remove trailing a whitespace characters
    strValue = strValue.replace(objRegExp, '$1');
    }

  return strValue;
  }

function ve_leftTrim( strValue ) 
  {
  /************************************************
  DESCRIPTION: Trims leading whitespace chars.
      
  PARAMETERS:
     strValue - String to be trimmed
     
  RETURNS:
     Source string with left whitespaces removed.
  *************************************************/
  var objRegExp = /^(\s*)(\b[\w\W]*)$/;
   
  if(objRegExp.test(strValue)) 
    {
    //remove leading a whitespace characters
    strValue = strValue.replace(objRegExp, '$2');
    }

  return strValue;
  }

function ve_trimAll( strValue ) 
  {
  /************************************************
  DESCRIPTION: Removes leading and trailing spaces.
  
  PARAMETERS: Source string from which spaces will
    be removed;
  
  RETURNS: Source string with whitespaces removed.
  *************************************************/ 

  var objRegExp = /^(\s*)$/;
  
  //check for all spaces
  if(objRegExp.test(strValue)) 
    {
    strValue = strValue.replace(objRegExp, '');
    if( strValue.length == 0)
      return strValue;
    }
  
  //check for leading & trailing spaces
  objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
    if(objRegExp.test(strValue)) 
    {
    //remove leading and trailing whitespace characters
    strValue = strValue.replace(objRegExp, '$2');
    }

  return strValue;
  }

function ve_formatValue( value, veformat )
  {
  var perIndex;
  
  if( value == null || !veformat || veformat.substring( 0 , 3 ) != "ve:" )
    return value;
  else if( typeof( value ) == "string" )
    if( ( perIndex = value.indexOf( "%" ) ) != -1 )
      value = value.substring( 0, perIndex ) / 100;
    else
      value = ve_removeCurrency( value );
    
  var tokens = veformat.substring( 3 ).split( ',' );
  
  if( "#0$%".indexOf( tokens[ 0 ] ) != -1 )
    {
    var decimalNum = 0;
    var bolLeadingZero = true;
    
    if( tokens.length > 2 && tokens[ 2 ] )
      {
      var len = tokens[ 2 ].split( '.' );
      decimalNum = len.length > 1 ? parseInt( len[ 1 ] ) : parseInt( len[ 0 ] );
      bolLeadingZero = len.length == 1 || parseInt( len[ 0 ] ) > 0;
      }
    
    if( tokens[ 0 ] == '%' )
      value *= 100;

    var formattedValue = ve_formatNumber( value, decimalNum, bolLeadingZero, false, tokens.length < 1 || tokens[ 1 ] != 'false', tokens[ 0 ] == '$' );
    
    if( tokens[ 0 ] == '%' )
      if( ( value >= 0 && ( tokens.length <= 4 || !tokens[ 4 ] ) ) || ( value < 0 && ( tokens.length <= 6 || !tokens[ 6 ] ) ) )
        formattedValue += VELOCALE_PERCENT;
      
    if( value >= 0 )
      {
      if( tokens.length > 3 && tokens[ 3 ] )
        formattedValue = tokens[ 3 ] + formattedValue;
        
      if( tokens.length > 4 && tokens[ 4 ] )
        formattedValue = formattedValue + tokens[ 4 ];
      }
    else
      {
      if( tokens.length > 5 && tokens[ 5 ] )
        formattedValue = tokens[ 5 ] + ( formattedValue.length > 0 && formattedValue.charAt( 0 ) == '-' ? formattedValue.substring( 1 ) : formattedValue );
        
      if( tokens.length > 6 && tokens[ 6 ] )
        formattedValue = formattedValue + tokens[ 6 ];
      }
      
    return formattedValue; 
    }
  else
    return ve_formatDate( tokens[ 0 ], tokens.length > 1 ? tokens[ 1 ] : null );
  }

function ve_formatDate( value, dateFormat, timeFormat )
  {
  return value;
  }

function ve_removeCurrency( strValue ) 
  {
  /************************************************
  DESCRIPTION: Removes currency formatting from 
    source string.
    
  PARAMETERS: 
    strValue - Source string from which currency formatting
       will be removed;
  
  RETURNS: Source string with commas removed.
  *************************************************/
  var objRegExp = /\(/;
  var strMinus = '';
  var dec = VELOCALE_DECIMALSEPARATOR;
  
  //check if negative
  if(objRegExp.test(strValue))
    strMinus = '-';
    
  objRegExp = new RegExp( "[^\\d\\" + dec + "-]", "g" );
  strValue = strValue.replace( objRegExp, '' );
  
  if( dec != '.' )
    strValue = strValue.replace( dec, '.' );

  return strMinus + strValue;
  }

function ve_addCurrency( strValue, useParant ) 
  {
  if( useParant && strValue.length > 0 && strValue.charAt( 0 ) == '-' )
    strValue = '(' + VELOCALE_CURRENCYSYMBOL + strValue + ')';
  else 
    strValue = VELOCALE_CURRENCYSYMBOL + strValue;

  return strValue;
  }
   
function ve_addCurrency2( strValue ) 
  {
  /************************************************
  DESCRIPTION: Formats a number as currency.
  
  PARAMETERS: 
    strValue - Source string to be formatted
  
  REMARKS: Assumes number passed is a valid 
    numeric value in the rounded to 2 decimal 
    places.  If not, returns original value.
  *************************************************/
  var objRegExp = /-?[0-9]+\.[0-9]{2}$/;
  
  if( objRegExp.test( strValue ) ) 
    {
    objRegExp.compile( '^-' );
    strValue = addCommas( strValue );
    if( objRegExp.test( strValue ) )
      {
      strValue = '($' + strValue.replace(objRegExp,'') + ')';
      }
    else 
      {
      strValue = '$' + strValue;
      }

    return  strValue;
    }
  else
    return strValue;
  }

function ve_removeCommas( strValue ) 
  {
  /************************************************
  DESCRIPTION: Removes commas from source string.
  
  PARAMETERS: 
    strValue - Source string from which commas will 
      be removed;
  
  RETURNS: Source string with commas removed.
  *************************************************/
  var objRegExp = /,/g; //search for commas globally
 
  //replace all matches with empty strings
  return strValue.replace(objRegExp,'');
  }

function ve_addCommas( strValue ) 
  {
  var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})'); 
  var decSep = strValue.indexOf( VELOCALE_DECIMALSEPARATOR );
  var suffix = null;
  
  if( decSep != -1 )
    {
    suffix = strValue.substring( decSep ); 
    strValue = strValue.substring( 0, decSep );
    }

  while( objRegExp.test( strValue ) ) 
    {
    //replace original string with first group match, 
    //a comma, then second group match
    strValue = strValue.replace( objRegExp, '$1' + VELOCALE_GROUPINGSEPARATOR + '$2' );
    }

  if( suffix )
    strValue += suffix;
    
  return strValue;
  }

function ve_removeCharacters( strValue, strMatchPattern ) 
  {
  /************************************************
  DESCRIPTION: Removes characters from a source string
    based upon matches of the supplied pattern.
  
  PARAMETERS: 
    strValue - source string containing number.
    
  RETURNS: String modified with characters
    matching search pattern removed
    
  USAGE:  strNoSpaces = removeCharacters( ' sfdf  dfd', '\s*')
  *************************************************/
  var objRegExp =  new RegExp( strMatchPattern, 'gi' );
   
  //replace passed pattern matches with blanks
  return strValue.replace(objRegExp,'');
  }

function ve_formatNumber( num, decimalNum, bolLeadingZero, bolParens, addCommas, addCurrency )
   {
   var tmpNum = num;

   tmpNum *= Math.pow( 10, decimalNum );
   tmpNum = Math.round( tmpNum );

   if( tmpNum == 0 )
     for( var i = 0; i < decimalNum ; i++ )
       tmpNum += "0";
  
   var tmpStr = "" + tmpNum;
   var periodPos = tmpStr.length - decimalNum;
   var prefix;
   
   if( periodPos == 0 && num >= 0 )
     prefix = "0";
   else if( periodPos == 1 && num < 0 )
     prefix = "-0";
   else if( decimalNum > 0 )
     prefix = tmpStr.substring( 0, periodPos );
     
   while( periodPos < 0 )
  	 {
  	 tmpStr = "0" + tmpStr;
     periodPos++;
  	 }

   if( decimalNum > 0 )
     tmpStr = prefix + VELOCALE_DECIMALSEPARATOR + tmpStr.substring( periodPos );
   
   // See if we need to hack off a leading zero or not
   if( !bolLeadingZero && num < 1 && num > -1 && num !=0 )
     if (num > 0)
       tmpStr = tmpStr.substring( 1, tmpStr.length );
     else
       // Take out the minus sign out (start at 2)
       tmpStr = "-" + tmpStr.substring( 2, tmpStr.length );                        

   // See if we need to put parenthesis around the number
   if( bolParens && num < 0 && !addCurrency )
     tmpStr = "(" + tmpStr.substring( 1, tmpStr.length ) + ")";

   if( addCommas )
     tmpStr = ve_addCommas( tmpStr );
     
   if( addCurrency )
     tmpStr = ve_addCurrency( tmpStr, bolParens );
     
   return tmpStr;
   }
   
// PROGRESS BAR UTILITIES

var progressEnd = 9;		// set to number of progress <span>'s.
var progressColor = '#000099';	// set to progress bar color
var progressInterval = 200;	// set to time between updates (milli-seconds)

//var progressAt = progressEnd;
var progressAt = 0;
var progressTimer;

function ve_progressbar_start()
  {
  var progressBar = getTag( "ve_progress_bar" );
  
  if( !progressBar )
    {
    var tag = document.createElement( "<div id='ve_progress_bar' style='visibility:hidden;width:200px;height:60px;position:absolute;border:3px ridge silver;background-color:#EEEEEE'></div>" );
  
    tag.innerHTML = "<table align='center'><tr><td align='center' valign='middle' style='font-size:10pt;font-family:Tahoma Verdana Helvetica'><p><b>Please wait...</b></p></td></tr><tr><td>&nbsp;</td></tr><tr><td><div style='width:100px;font-size:8pt;padding:2px;border:solid black 1px;height:20px'><span id='progress1' style='width:10px'>   </span><span id='progress2' style='width:10px'>   </span><span id='progress3' style='width:10px'>   </span><span id='progress4' style='width:10px'>   </span><span id='progress5' style='width:10px'>   </span><span id='progress6' style='width:10px'>   </span><span id='progress7' style='width:10px'>   </span><span id='progress8' style='width:10px'>   </span><span id='progress9' style='width:10px'>   </span></div></td></tr></table>";
  
	  document.body.insertAdjacentElement( "BeforeEnd", tag );
    }
  
  progressBar = getTag( "ve_progress_bar" );
  centerThis( progressBar, 200, 60, "screen" );
  progressBar.style.visibility = "visible";
  
  ve_progressbar_update();		// start progress bar
  }
  
function ve_progressbar_clear() 
  {
	for( var i = 1; i <= progressEnd ; i++ ) 
	  document.getElementById( 'progress' + i ).style.backgroundColor = 'transparent';
	  
	progressAt = 0;
  }

function ve_progressbar_update()
  {
	progressAt++;
	
	if( progressAt > progressEnd ) 
	  ve_progressbar_clear();
	else 
	  {
	  var tag = document.getElementById( 'progress' + progressAt );
	  if( tag )
	    tag.style.backgroundColor = progressColor;
	  }
	  
	progressTimer = setTimeout( 've_progressbar_update()', progressInterval );
  }
  
function ve_progressbar_stop()
  {
  if( progressTimer != null )
	  clearTimeout( progressTimer );

  var progressBar = getTag( "ve_progress_bar" );

  if( progressBar && progressBar.style.visibility == "visible" )
    {
    ve_progressbar_clear();
    progressAt = 0;
    progressBar.style.visibility = "hidden";
    }
  }
  
function centerThis( tag, w, h, rel )
    {
    if ( document.all )
    	{
    	xMax = rel == "screen" ? screen.width : document.body.clientWidth;
    	yMax = rel == "screen" ? screen.height : document.body.clientHeight;
    	}
    else if( document.layers )
    	{
    	xMax = rel == "screen" ? window.outerWidth : window.innerWidth;
    	yMax = rel == "screen" ? window.outerHeight : window.innerHeight;
    	}
    else
    	{
    	xMax = 640;
    	yMax = 480;
    	}
    
    xOffset = (xMax - w)/2;
    yOffset = (yMax - h)/2;
    
    tag.style.left = xOffset;
    tag.style.top = yOffset;
    }     
    
///////////////////////////////	
// SUPPORT FOR VE OPERATIONS //
///////////////////////////////

function veopsupport_get( tid, name, type )
  {
  var tname = tid + "__" + name;

  if( type == null )
    {
    var tag = ve_getTag( tname, tname );
    return tag == null ? null : tag.value;
    }
  else
    return eval( "ve_get" + type + "Value( '" + tname + "', '" + tname + "' )" );
  }

function veopsupport_set( tid, name, value )
  {
  var tname = tid + "__" + name;
  //ve_setValue( tname, tname, value );
  var tag = ve_getTag( tname, tname );

  if( tag )
    {
    tag.value = value;
    tag.onchange();
    }
  }

function veopsupport_invoke( oid, fullName, name, params )
  {
  if( name.indexOf( '/' ) == -1 )
    {
    var i = fullName.lastIndexOf( '/' );
    
    if( i != -1 )
      name = fullName.substring( 0, i + 1 ) + name;
    }

  var op = veopsupport_getOperation( oid, name );

  if( op == null )
    return ve_exec( oid, name );

  if( params.length == 1 )
    return op.execute();
  else
    {
    var call = "op.execute( params[ 1 ]" ;

    for( var i = 2; i < params.length; i++ )
      call += ", params[ " + i + " ]";

    return eval( call + " )" );
    }
  }

function veopsupport_getOperation( oid, fullName )
  {
  var name = fullName;

  while( name.indexOf( '/' ) >= 0 )
    name = name.replace( '/', '_' );

  name = "veop_" + name;

  try
    {
    if( eval( "window." + name + " != null" ) )
      return eval( "new " + name + "( '" + oid + "', '" + fullName + "' )" );
    }
  catch( e )
    {
    }
   
  return null; 
  }

function veopsupport_getTid( oid )
  {
  return ve_acquireTOID( oid, true );
  }
    
function ve_getWhereAmI()
  {
  var whereAmI = getTag( "veWhereAmI" );  
  var value = whereAmI ? whereAmI.value : null;
  
  if( value )
    value = value.substring( 0, value.indexOf( '-' ) );
    
  return value;  
  }
  
function positionIt() 
  {
	if( document.getElementById ) 
	  {
		// Get a reference to divTest and measure its width and height.
		var div = document.getElementById( "centerit" );
		var divWidth = div.offsetWidth ? div.offsetWidth : div.style.width ? parseInt( div.style.width ) : 0;
		var divHeight = div.offsetHeight ? div.offsetHeight :  div.style.height ? parseInt( div.style.height ) : 0;
		
		// Calculating setX and setX so the div will be centered in the viewport.
		var setX = ( getViewportWidth() - divWidth ) / 2;
		var setY = ( getViewportHeight() - divHeight ) / 2;
		
		// If setX or setY have become smaller than 0, make them 0.
		if( setX < 0 ) setX = 0;
		if( setY < 0 ) setY = 0;
		
		// Position the div in the center of the page and make it visible.
		div.style.left = setX + "px";
		div.style.top = setY + "px";
		div.style.visibility = "visible";
	  }
  };

function getViewportWidth() 
  {
	var width = 0;
	
	if( document.documentElement && document.documentElement.clientWidth ) 
	  {
		width = document.documentElement.clientWidth;
	  }
	else if( document.body && document.body.clientWidth ) 
	  {
		width = document.body.clientWidth;
	  }
	else if( window.innerWidth ) 
	  {
		width = window.innerWidth - 18;
	  }
	  
	return width;
  };

function getViewportHeight()
  {
	var height = 0;
	
	if( document.documentElement && document.documentElement.clientHeight ) 
	  {
		height = document.documentElement.clientHeight;
	  }
	else if( document.body && document.body.clientHeight ) 
	  {
		height = document.body.clientHeight;
	  }
	else if( window.innerHeight ) 
	  {
		height = window.innerHeight - 18;
	  }
	
	return height;
  };  
  
//////////////////////////
// HTTPREQUEST SUPPORT  //
//////////////////////////


function HTTPRequest()
  {
  this.r = browser.isIE ? new ActiveXObject( "Microsoft.XMLHTTP" ) : new XMLHttpRequest();

  this.open = function( method, url, asyncFlag, userName, password )
    {
    if( browser.isIE )
      this.r.onreadystatechange = this.onReady;
    else
      {
      this.r.onload = this.onReady;
      this.r.onreadystatechange = this.onReady;
      }
      
    return this.r.open( method, url, asyncFlag, userName, password );
    };

  this.skipCache = function()
    {
    this.r.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
    };
      
  this.send = function( content )
    {
    this.r.send( content );
    };
  
  this.abort = function()
    {
    this.r.abort();
    };
    
  this.setRequestHeader = function( label, value )
    {
    this.r.setRequestHeader( label, value );
    };
  
  this.getResponseHeader = function( label )  
    {
    return this.r.getResponseHeader( label );  
    };
  
  this.getAllResponseHeaders = function()
    {
    return this.r.getAllResponseHeaders();
    };
  
  this.addListener = function( l )
    {
    if( !this.listeners )
      this.listeners = new Array();
      
    this.listeners[ this.listeners.length ] = l.constructor == String ? new Function( "request", l ) : l;
    };

  this.readyState = function() { return this.r.readyState; };
  
  this.responseText = function() { return this.r.responseText; };
  
  this.responseXML = function() { return this.r.responseXML; };
  
  this.status = function() { return this.r.status; };
  
  this.statusText = function() { return this.r.statusText; };
  
  this.responseObject = function() 
    {    
    if( !this.rObject )
      {
      var text = this.r.responseText;
      this.rObject = text ? eval( 'ignore = ' + text ) : null;
      this.rObject = this.rObject ? this.resolveRefs( this.rObject, new Object() ) : null;
      }

    return this.rObject;
    };
    
  this.onReady = function()
    {
    var request = arguments.callee.request;
    var state = request.readyState();
  
    if( state == 4 )
      if( request.listeners )
        for( var i = 0; i < request.listeners.length; i++ )
          request.listeners[ i ]( request );
    else  
      if( request.listeners )
        for( var i = 0; i < request.listeners.length; i++ )
          if( request.listeners[ i ].arity > 1 )
            request.listeners[ i ]( request, state );
    };
  
  this.onReady.request = this;
  
  this.resolveRefs = function( object, map )
    {
    var candidate;

    if( object.constructor == Array )
      for( var i = 0; i < object.length; i++ )
        object[ i ] = this.resolveRefs( object[ i ], map );
    else if( object.__objectref && ( candidate = map[ object.__objectref ] ) != null )
      return candidate;
    else if( object.__oid )
      {
      map[ object.__oid ] = object;
      for( var member in object )
        if( ( candidate = object[ member ] ) != null && ( candidate.constructor == Object || candidate.constructor == Array ) )
          object[ member ] = this.resolveRefs( candidate, map );
      }

    return object;
    }
  }

function ve_DownloadMonitor( url )
  {
  this.url = url;
  this.isDone = false;
  this.listeners = new Array();
  this.request = new HTTPRequest();
  this.request.monitor = this;

  this.download = function()
    {
    this.isDone = false;
    this.request.addListener( this.markDone );
    this.request.open( "GET", this.url );
    this.request.send( "" );
    }

  this.markDone = function( r )
    {
    r.monitor.rawData = r.responseText();
    r.monitor.result = r.responseObject();
    r.monitor.isDone = true;

    for( var i = 0; i < r.monitor.listeners.length; i++ )
      r.monitor.listeners[ i ].dataReady( r.monitor );
    }

  this.addListener = function( listener )
    {
    if( this.isDone )
      listener.dataReady( this );
    else
      this.listeners[ this.listeners.length ] = listener;
    }
  }

function ve_runBackground( oid, action, params )
  {
  if( params )
    params = "?" + params + "&device=js";
  else
    params = "?device=js";

  if( oid )
    params += "&o=" + oid;

  var monitor = new ve_DownloadMonitor( ve_getUrlPrefix() + action + ".v" + params );
  monitor.download();
  return monitor;
  }

