/*
  (C) by KSI media sp. z o.o. ( www.ksimedia.pl )  
  Description : ExtComponents class.
  Author      : MS
  Create date : 2010-09-14
  Comment     :
*/

function classExtComponents ()
{
  
  this.updateFunctions = new Array() ;
  
  //
  // funkcje związane z obsługą "wartości podstawowych"
  //
  this.setValue = function ( name, value, sort )
  {
    var tmp ;
    try
    {
      if ( value == '' )
      {
        document.getElementById ( 'vis_'+name ).style.color = '#888888' ;
      }
      else
      {
        document.getElementById ( 'vis_'+name ).style.color = '#222222' ;
      }
    }
    catch(err){}
    
    tmp = value.split ( ';' ) ;
    
    if ( sort == undefined )
    {
      sort = false ;
    }
    if ( sort )
    {
      tmp.sort();
    }
    StringUtils.arrayDeleteItem ( '', tmp ) ;
    document.getElementById ( name ).value = StringUtils.arrayToString ( tmp ) ;
    this.updateValue( name ) ;
    return true ;
  }

  this.getValue = function ( name )
  {
    var tmp ;
    tmp = document.getElementById ( name ).value ;
    return tmp ;
  }
  
  this.getValueArray = function ( name )
  {
    var tmp ;
    tmp = document.getElementById ( name ).value ;
    return tmp.split( ';' ) ;
  }

  //
  // funkcje związane z obsługą "multi wartości"
  //
  this.addMultiValue = function ( name, value, sort )
  {
    var tmp ;
    var oval ;
    if ( sort == undefined )
    {
      sort = false ;
    }

    oval = this.getValue( name ) ;
    tmp = oval.split ( ';' ) ;
    if ( StringUtils.inArray ( value, tmp ) < 0 )
    {
      tmp.push ( value ) ;      
      this.setValue ( name, StringUtils.arrayToString ( tmp ), sort ) ;
    }
    else
    {
      return false ;
    }
  }

  this.deleteMultiValue = function ( name, value )
  {
    var tmp ;
    var oval ;
    oval = this.getValue( name ) ;
    tmp = oval.split ( ';' ) ;
    if ( StringUtils.inArray ( value, tmp ) >= 0 )
    {
      StringUtils.arrayDeleteItem ( value, tmp ) ;
      this.setValue ( name, StringUtils.arrayToString ( tmp ) ) ;
    }
    else
    {
      return false ;
    }
  }
  
  this.isMultiValue = function ( name, value )
  {
    var tmp ;
    var oval ;
    oval = this.getValue( name ) ;
    tmp = oval.split ( ';' ) ;
    if ( StringUtils.inArray ( value, tmp ) >= 0 )
    {
      return true ;
    }
    else
    {
      return false ;
    }
  }
  //
  // Updating visual components
  //
  this.updateValue = function ( name )
  {
    // aktualizuje elementy wizualne komponentu
    var fn ;
    if ( this.updateFunctions [ name ] != undefined )
    {
      fn = this.updateFunctions [ name ] + "('" + name + "')" ;
      try
      {
        eval ( fn ) ;
      }
      catch ( err ){}
    }
  }
}

ExtComponents = new classExtComponents ;
