// + IE mod + ==================================================================
var testArr = new Array();
if( ! testArr.push ){
 Array.prototype.push = function( v ){
  this[ this.length ] = v;
 }
}
if( ! testArr.pop ){
 Array.prototype.pop = function(){
  delete this[ this.length - 1 ];
 }
}
delete testArr;
// - IE mod - ==================================================================

// + misc + ====================================================================
function doNothing(){}
try{ console.info( '' ); }catch(e){} // firebug is broken. without this console is undefined
// = + = http://developer.mozilla.org/en/docs/JavaScript =======================
if( ! Array.prototype.forEach ){
 Array.prototype.forEach = function( fun /*, thisp */ ){
  var len = this.length;
  if( typeof fun != 'function' ) throw new TypeError();
  var thisp = arguments[1];
  for( var nr = 0; nr < len; ++nr ){
   if( nr in this ){
    fun.call( thisp, this[ nr ], nr, this );
   }
  }
 };
}
if( ! Array.prototype.indexOf ){
 Array.prototype.indexOf = function( elt /*, from*/ ){
  var len = this.length, from = Number( arguments[ 1 ] ) || 0;
  from = ( from < 0 )? Math.ceil( from ): Math.floor( from );
  if( from < 0 )from += len;
  for( ; from < len; ++from ){
   if( from in this && this[ from ] === elt ) return from;
  }
  return -1;
 };
}
if( ! Array.prototype.filter ){
 Array.prototype.filter = function( fun /*, thisp*/ ){
  if( typeof fun != "function" ) throw new TypeError();
  var res = new Array(), thisp = arguments[ 1 ], len = this.length;
  for( var nr = 0; nr < len; ++nr ){
   if( nr in this ){
    var val = this[ nr ]; // in case fun mutates this
    if( fun.call( thisp, val, nr, this ) ) res.push( val );
   }
  }
  return res;
 };
}
if( ! Array.prototype.map ){
 Array.prototype.map = function( fun /*, thisp*/ ){
  var len = this.length;
  if( typeof fun != "function" ) throw new TypeError();
  var res = new Array( len );
  var thisp = arguments[ 1 ];
  for( var i = 0; i < len; i++ ){
   if( i in this ) res[ i ] = fun.call( thisp, this[ i ], i, this );
  }
  return res;
 };
}
// = - = http://developer.mozilla.org/en/docs/JavaScript =======================

// - misc - ====================================================================

// + sdxml mod + ===============================================================
String.prototype.clone = function(){
 return this;
}
String.prototype.toSdxml = function( key ){
 return '<s' + ( ( typeof key == 'undefined' || key == '' )? '': ' k="' + key.toXml() + '"' ) + '>' + this.toXml() + '</s>';
}
String.prototype.toXml = function(){
 return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');
}
String.prototype.toUrl = function(){
 return this.replace(/%/g,'%25').replace(/\+/g,'%2B').replace(/&/g,'%26');
}
String.prototype.fac = function(){
 return 's';
}

Number.prototype.clone = function(){
 return this;
}
Number.prototype.toSdxml = function( key ){
 return '<n' + ( ( typeof key == 'undefined' || key == '' )? '': ' k="' + key.toXml() + '"' ) + '>' + this + '</n>';
}
Number.prototype.fac = function(){
 return 's';
}

Boolean.prototype.toSdxml = function( key ){
 return '<n' + ( ( typeof key == 'undefined' || key == '' )? '': ' k="' + key.toXml() + '"' ) + '>' + ( this? '1': '0' ) + '</n>';
}
Boolean.prototype.fac = function(){
 return 's';
}
// - sdxml mod - ===============================================================

// + l + =======================================================================
// deprecated
function l( arr ){
 if( typeof arr == 'undefined' ) arr = new Array()
 this.fromArray( arr );
}
l.prototype = {
   len: 0
 , add: function( d ){
    this._[ this.len ] = d;
    ++this.len;
   }
 , adds: function( d ){
    if( this.rms( d ) ){
     this._[ this.len - 1 ] = d;
    }else{
     this._[ this.len ] = d;
     ++this.len;
    }
   }
 , rmNr: function( nr ){
    if( this.len < 1 ) return false;
    var maxNr = this.len - 1;
    for( var it = nr; it < maxNr; ++ it ) this._[ it ] = this._[ it + 1 ];
    --this.len;
    delete this._[ this.len ];
   }
 , rm: function( d ){
    var found = false;
    for( var it = 0; it < this.len; it++ ) if( this._[ it ] === d ){
     this.rmNr( it );
     --it;
     found = true;
    }
    return found;
   }
 , rms: function( d ){
    var found = false;
    for( var it = 0; it < this.len; it++ ) if( this._[ it ] == d ){
     this.rmNr( it );
     --it;
     found = true;
    }
    return found;
   }
 , nr: function( p ){
    return this._.indexOf( p );
   }
 , toArray: function(){
    return this._;
   }
 , fromArray: function( arr ){
    this._ = arr;
    this.pointer = 0;
    this.len = arr.length;
   }
 , fromL: function( lOb ){
    this.fromArray( lOb.toArray() );
   }
 , cnt: function(){
    return this.len;
   }
 , rewind: function(){
    this.pointer = 0;
   }
 , next: function(){
    if( this.pointer >= this.cnt() ){
     this.pointer = 0;
     return false;
    }
    return this._[ this.pointer++ ];
   }
 , sort: function( f ){
    this._.sort( f );
   }
 , clone: function(){
    var ar = this._;
    var nl = new l();
    var len = ar.length;
    for( nr = 0; nr < len; ++nr ){
     nl.add( ar[ nr ].clone() );
    }
    return nl;
   }
 , toSdxml: function( key ){
    var sdxml = '<l' + ( ( typeof key == 'undefined' || key == '' )? '': ' k="' + key.toXml() + '"' ) + '>';
    var key = '';
    for( var it = 0; it < this.len; it++ ){
     sdxml += this._[ it ].toSdxml( key );
    }
    sdxml += '</l>';
    return sdxml;
   }
 , fac: function(){
    return 'l';
   }
}
// - l - =======================================================================

// + i + =======================================================================
// deprecated
function i( ob ){
 if( typeof ob == 'undefined' ) ob = new Object();
 this.fromObject( ob );
}
i.prototype = {
   v: function( key, d ){
    if( typeof d != 'undefined' ) this._[ key ] = d;
    if( d === null ) delete this._[ key ];
    if( typeof this._[ key ] == 'undefined' ) return null;
    return this._[ key ];
   }
 , toObject: function(){
    return this._;
   }
 , fromObject: function( obj ){
    this._ = obj;
    this.pointer = 0;
   }
 , keys: function(){
    var ob = this._, key, list = new l;
    for( key in ob ){
     list.add( key );
    }
    return list;
   }
 , fromI: function( iOb ){
    this.fromObject( iOb.toObject() );
   }
 , clone: function(){
    var ob = this._;
    var ni = new i();
    for( key in ob ){
     ni.v( key, ob[ key ].clone() );
    }
    return ni;
   }
 , toSdxml: function( key ){
    var key = '', sdxml = '<i' + ( ( typeof key == 'undefined' || key == '' )? '': ' k="' + key.toXml() + '"' ) + '>';
    for( key in this._ ){
     sdxml += this._[ key ].toSdxml( key );
    }
    sdxml += '</i>';
    return sdxml;
   }
 , fac: function(){
    return 'i';
   }
}
// - i - =======================================================================
function mks( v ){
 if( v !== null && typeof v != 'undefined' ){
  if( typeof v == 'object' ){
   if( v.fac && ( v.fac == 'i' || v.fac == 'l' || v.fac == 's' ) ){
    return v;
   }
   if( v[ 0 ] ){
    var len = v.length, r = new l;
    for( var k = 0; k < len; ++k ){
     r.add( sys( v[ k ] ) );
    }
    return r;
   }
   var r = new i;
   for( var k in v ){
    r.v( k, v[ k ] );
   }
   return r;
  }
  if( typeof v == 'array' ){
   var len = v.length, r = new l;
   for( var k = 0; k < len; ++k ){
    r.add( sys( v[ k ] ) );
   }
   return r;
  }
  return v;
 }
 return '';
}

// + z + =======================================================================
function iter( v ){
 this._l = v;
 this._lc = 0;
}
iter.prototype = {
   iter: function(){
    return new iter( this._l );
   }
 , next: function(){
    var r;
    if( r = this._l[ this._lc++ ] ){
     return r;
    }
    this._lc = 0;
    return null;
   }
}
function z( v, i, l ){
 this._v = null;
 this._l = [];
 this._i = {};
 this._k = [];
 this._v = [];
 this._lc = 0;
 this._ll = 0;
 if( typeof v != 'undefined' ){
  this.val( v );
 }
 if( typeof i != 'undefined' ){
  for( var k in i ){
   this.set( k, i[ k ] );
  }
 }
 if( typeof l != 'undefined' ){
  var len = l.length;
  for( var nr = 0; nr < len; ++nr ){
   this.add( l[ nr ] );
  }
 }
}
z.prototype = {
// + simple
   val: function( v ){
    this._v = v;
   }
 , str: function(){
    if( this._v === null ){ return ''; }
    return '' + this._v;
   }
 , num: function(){
    return Number( this._v );
   }
 , pnt: function(){
    return this._v;
   }
// - simple
// + key index
 , set: function( k, v ){
    if( typeof k == 'string' ){
     return this._i[ k ] = v;
    }else{
     this._k[ this._ll ] = k;
     return this._v[ this._ll++ ] = v;
    }
   }
 , get: function( k ){
    var r;
    if( typeof k == 'string' ){
     r = this._i[ k ];
    }else{
     r = this._v[ this._k.indexOf( k ) ];
    }
    if( typeof r == 'undefined' ){
     return this.set( k, new z );
    }
    return r;
   }
 , v: function( k, v ){ // deprecated, use set and get
    if( typeof v != 'undefined' ) return this.set( k, v );
    return this.get( k );
   }
 , keys: function(){
    var r = new z, k, v;
    for( k in this._i ){
     v = new z;
     v.val( k );
     r.add( v );
    }
    //this._k.forEach( function(){ var v = new z; v.val( k ); r.add( v ); } );
    return r;
   }
// - key index
// + list
 , add: function( v ){
    this._l[ this._lc++ ] = v;
   }
 , iter: function(){
    return new iter( this._l );
   }
 , arr: function(){
    return this._l;
   }
// - list
// + export
 , toSdxml: function( k ){
    var r = '<z' + ( ( typeof k == 'undefined' || k == '' )? '': ' k="' + k.toXml() + '"' ) + ( ( this._v === null || typeof this._v == 'undefined' )? '': ' v="' + this.str().toXml() + '"' ) + '>';
    for( k in this._i ){
     r += this._i[ k ].toSdxml( k );
    }
    for( var k = 0; k < this._lc; ++k ){
     r += this._l[ k ].toSdxml();
    }
    r += '</z>';
    return r;
   }
// - export
 , fac: function(){
    return 'z';
   }
}
z.prototype.toString = z.prototype.str;

function sys( v ){
 var r = new z;
 if( v !== null ){
  if( typeof v == 'object' ){
   if( v.fac && v.fac == 'z' ){
    return v;
   }
   if( v[ 0 ] ){
    var len = v.length;
    for( var k = 0; k < len; ++k ){
     r.add( sys( v[ k ] ) );
    }
    return r;
   }
   for( var k in v ){
    r.v( k, v[ k ] );
   }
   return r;
  }
  if( typeof v == 'array' ){
   var len = v.length;
   for( var k = 0; k < len; ++k ){
    r.add( sys( v[ k ] ) );
   }
   return r;
  }
  r.val( v );
  return r;
 }
 return r;
}
// - z - =======================================================================
