   var n4 = ( document.layers ) ? true : false
   var i4 = ( document.all ) ? true : false
   var n6 = ( document.getElementById && !i4 ) ? true : false
   var op = ( navigator.appName.indexOf( "Opera" ) != -1 ) ? true : false
   var wnd
   fldobj = ''
   var clicked = new Array()

function ao1(obj){obj.style.backgroundColor='#FFFFFF'}
function ao2(obj){obj.style.backgroundColor='#F3F2F0'}
function ao0(obj){obj.style.backgroundColor=''}

function nao0(obj,nr){if(clicked[nr]){obj.style.backgroundColor='#FFFF00'}else{obj.style.backgroundColor=''}}
function nac0(obj,nr){if(clicked[nr]){clicked[nr]=false}else{clicked[nr]=true;obj.style.backgroundColor='#66DD00'}}

function myscroll(){

   obj = getO( 'form_error_div' )
   x = getT( obj )
   window.scrollTo( 0, x-20 )
   alert( 'Popraw pola zaznaczone na czerwono\n(opis błędu w "dymku" pod nazwą pola)' )
}

function myscrollend(){
   window.scrollTo( 0, 1000000 )
   alert( 'Popraw pola zaznaczone na czerwono\n(opis błędu w "dymku" pod nazwą pola)' )
}

function zapisz( btn, p ){
   form = btn.form

   btn.style.cursor = 'wait'
   if( btn.value == 'czekaj...' ){
      alert( 'Trwa zapisywanie danych...' )
      return false
   }
   else {
      btn.disabled = true
      btn.value    = 'czekaj...'
      if( p ){
         form.target = '_self'
//         if( top != self ) top.cms_preview( 0 )
      }
      form.submit()
      return false
   }
}

function preview0( act ){
   top.cms_preview( 1 )
   top.pview.document.location.href = act
}

function preview( obj, act ){
   form = obj.form
   form.target = 'pview'
   form.action.value = act
   form.submit()
}

function preview2( obj, act ){
   top.cms_preview( 1 )
   doc = top.pview.document
   doc.open()
   doc.write( '<HTML><HEAD><LINK REL="stylesheet" TYPE="text/css" HREF="/!cms/admin/admin/styles.css"></HEAD><BODY scroll="no"><TABLE height=100% width=100% cellpadding=10 cellspacing=0><TR><TD align=center valign=middle width=100%><IFRAME name=pviewiframe id=pviewiframe width=100% height=100% src=""></IFRAME></TD></TR></TABLE></BODY></HTML>' )
   doc.close()

   form = obj.form
   form.target = 'pviewiframe'
   form.action.value = act
   form.submit()
}

function check_vote( btn, txt ){
   form = btn.form

   if( btn.value != 'czekaj...' ){
      for( i=0; i<form.elements.length; i++ ){
         el = form.elements[i]
         if(( el.name == 'pts' || el.name.substr( 0, 4 ) == 'vote' ) && el.checked ){
            btn.disabled     = true
            btn.style.cursor = 'wait'
            btn.value        = 'czekaj...'
            form.submit()
            return false
         }
      }
   }
   else {
      alert( 'Trwa zapisywanie danych...' )
      return flase
   }
   if( !txt ){ txt = 'Zaznacz liczbę punktów...' }
   alert( txt )
   return false
}

function galeria( xtitle, xjpg, xcopy ){

   if( !wnd || wnd.closed ) wnd = window.open( '', '', 'toolbar=no,menubar=yes,scrollbars=yes,resizable=yes' )
   with( wnd.document ){
      open()
      write( '<HTML><HEAD><META http-equiv="content-type" content="text/html; charset=iso-8859-2"><TITLE>' + xtitle + '</TITLE></HEAD><BODY bgcolor="#000000" onload="focus()" style="margin:0px"><CENTER>' )
      write( '<img src="' + xjpg + '">' )
      if( xcopy ) write( '<P style="margin-top:5px; color:#999999; font-family:verdana; font-size:10px">Copyright &copy; by '+ xcopy +'<BR>&nbsp;' )
      write( '</CENTER></BODY></HTML>' )
      close()
   }
   wnd.focus()
}

function blank2(){
   if( top != self ) top.blank( 2 )
}

function edit( url, obj ){
   if( top == self ){ alert( 'W "nowym" okienku edycja nie jest możliwa.' )}
   else {
      strAttr = "status:no;dialogWidth:640px;dialogHeight:400px;help:no;scroll:no";
      html = showModalDialog( url, obj, strAttr );
   }
}

function edit_end(){
   alert( 'ok' )
}

function save( obj, act ){
   form = obj.form
   if( obj.value != 'czekaj...' ){
      if( top == self ){ alert( 'W "nowym" okienku zapis nie jest możliwy.' )}
      else {
         obj.value = 'czekaj...'
         form.target       = '_self'
         form.action.value = act
         form.submit()
      }
   }
}

var forum_button_clicked = false
//---------------------------------------------------------------
function post_del( url ){

   if( forum_button_clicked ){
      alert( 'Chwileczkę...' )
      return
   }

   if( confirm( 'Potwierdź, że zgłaszasz ten post do usunięcia.' )){
      forum_button_clicked = true
      url = '/!cms/rjs_forum_post.php?del-' + url
      httpGET( url, post_del_response )
   }

}
function post_del_response( err, txt ){
   forum_button_clicked = false
   alert( err )
}

function post_edit( url ){

   form = document.forms['editpost']
   form.txt.value = ''
   form.par.value = url
   if( form.usun ) form.usun.disabled = true
   if( form.save ) form.save.disabled = true
   obj = getO( 'post_edit_div' )
   obj.parentNode.removeChild( obj )
   document.body.appendChild( obj )
   setPosCenter( obj )
   url = '/!cms/rjs_forum_post.php?edit-' + url
   httpGET( url, post_edit_response )
}
function post_edit_response( err, txt ){

   objcheck = form['fld_checkbox_txt']
   if( err ){
      objcheck.disabled = true
      alert( err )
   }
   else {
      form = document.forms['editpost']
      form.txt.value = txt
      if( form.usun ) form.usun.disabled = false
      if( form.save ) form.save.disabled = false
      objcheck.disabled  = false
      objcheck.checked   = ( form.txt.wrap == 'soft' ) ? true : false
   }

}

function post_edit_del( url ){
   if( confirm( 'Are you sure na pewno?' )){
      url = '/!cms/rjs_forum_post.php?edit_del-' + url
      httpGET( url, post_edit_del_response )
      if( form.usun ) form.usun.disabled = true
      if( form.save ) form.save.disabled = true
   }
}
function post_edit_del_response( err, txt ){

   if( err == 'ok' ){ 
      post_edit_close()
      alert( 'Post został usunięty' )

      if( txt.length > 3 ){ document.location.href = txt }
      else                { history.go( 0 )}
   }
   else if( err != 'notlast' ){ 
      alert( err )
   }
   else if ( confirm( 'Możesz usuwać tylko swój ostatni post w danym temacie.\nCzy chcesz zgłosić ten post do usunięcia?' )){
      post_del( txt )
   }
   if( form.usun ) form.usun.disabled = false
   if( form.save ) form.save.disabled = false
}

function post_edit_save( form ){

   if( form.usun ) form.usun.disabled = true
   if( form.save ) form.save.disabled = true
   par    = form.par.value
   txt    = form.txt.value
   params = 'par=edit_save-' + par + '&txt=' + encodeURIComponent( txt )

   url = '/!cms/rjs_forum_post.php'
   httpPOST( url, post_edit_save_response, params )

}
function post_edit_save_response( err, txt ){

   form = document.forms['editpost']
   if( form.usun ) form.usun.disabled = false
   if( form.save ) form.save.disabled = false

   if( err ){
      form.txt.value = txt
      alert( err )
   }
   else { history.go( 0 )}

}

function post_cite( url ) {

//alert( url )
//return

   url = '/!cms/rjs_forum_post.php?cite-' + url
   httpGET( url, post_cite_response )
}
function post_cite_response( err, txt ){

   if( err ){
      alert( err )
   }
   else {
      form = document.forms['post']
      mT   = getT( form )
      window.scrollTo( 0, mT )
      if( form.txt.value ) txt = '\n\n' + txt
      form.txt.value += txt
   }

}

function post_edit_close(){
   obj = getO( 'post_edit_div' )
   setPos( obj, 0, -1000 )
   showElems( 'visible' )
}


//---------------------------------------------------------------
function storeCaret( obj ) {
   if ( obj.createTextRange ){
      obj.caretPos = document.selection.createRange().duplicate()
      top.copycont = obj
   }
}

function insertAtCaret( obj, text ) {

   if ( obj.createTextRange && obj.caretPos ){
      var caretPos = obj.caretPos
      caretPos.text = caretPos.text.charAt( caretPos.text.length - 1 ) == ' ' ? text + ' ' : text
   }
   else {
      obj.value += text
   }
}

//---------------------------------------------------------------
function label_show( obj, id, form, inline ){

   obj2   = document.forms[form][id]
   fldobj = 'fld_check_' + id
   fldobj = getO( fldobj )

   t = getT( obj ) + getH( obj )

   if( inline ){ l = getL( obj ) - 42; t += 1 }
   else        { l = getL( obj ) + getW( obj ) - 36 }
   setPos( fldobj, t, l )

   objcheck = document.forms[form]['fld_checkbox_' + id]
   objcheck.checked = ( obj2.wrap == 'soft' ) ? true : false
   obj.onmouseover  = ''

}
function label_wrap( form, id ){

   obj2 = document.forms[form][id]
   if( obj2.wrap == 'soft' ){
      obj2.wrap = 'off'
      obj2.rows--
   }
   else {
      obj2.wrap = 'soft'
      obj2.rows++
   }
}

//---------------------------------------------------------------
function getO( e, doc ){
   if( !doc ){ doc = document }
   if( i4 ){ return doc.all[e] }
   if( n4 ){ return doc.layers[e] }
   if( n6 ){ return doc.getElementById( e )}
}

function setPos( e, t, l ){
   if( e ){
      if     ( i4 ){ e.style.top  = t;   e.style.left = l }
      else if( n4 ){ e.moveTo( l, t )}
      else if( n6 ){ e.style.top  = t + 'px'; e.style.left = l + 'px' }
   }
}

function newO( name, pT, pL, txt ){
   if( i4 ){
      div = document.body
      txt = '<DIV id="' + name + '" name="' + name + '" style="visibility:visible; position:absolute; top:'+pT+'; left:'+pL +'">' + txt + '</DIV> \n'
      div.insertAdjacentHTML( "BeforeEnd", txt )
      obj = document.all( name )
   }
   return obj
}

function getT( e ){
   var curtop = 0;
   if ( e.offsetParent ){
      while( e.offsetParent ){
         curtop += e.offsetTop
         e = e.offsetParent;
      }
   }
   else if ( e.y ) curtop += e.y
   return curtop
}

function getL( e ){
   var curtop = 0;
   if( e.offsetParent ){
      while( e.offsetParent ){
         curtop += e.offsetLeft
         e = e.offsetParent;
      }
   }
   else if ( e.x ) curtop += e.x;
   return curtop;
}

function getW( e ){
   result = 0
   if      ( e.offsetWidth ) result = e.offsetWidth
   else if ( e.clip && e.clip.width ) result = e.clip.width
   else if ( e.style && e.style.pixelWidth ) result = e.style.pixelWidth
   return parseInt( result )
}
function getH( e ) {
   result = 0
   if      ( e.offsetHeight ) result = e.offsetHeight
   else if ( e.clip && e.clip.height ) result = e.clip.height
   else if ( e.style && e.style.pixelHeight ) result = e.style.pixelHeight
   return parseInt( result )
}

function getST(){
   x = 0;
   if      ( self.pageYOffset ) x = self.pageYOffset
   else if ( document.documentElement && document.documentElement.scrollTop ) x = document.documentElement.scrollTop
   else if ( document.body ) x = document.body.scrollTop
   return parseInt( x )
}
function getSL(){
   x = 0;
   if      ( self.pageXOffset ) x = self.pageXOffset
   else if ( document.documentElement && document.documentElement.scrollLeft ) x = document.documentElement.scrollLeft
   else if ( document.body ) x = document.body.scrollLeft
   return parseInt( x )
}

function setPosCenter( obj ){
   hideElems()

   a  = getPS()
   wT = getST()
   wT = Math.max( wT, wT     + parseInt(( a[3] - getH( obj ) )/2 ))
   wL = Math.max( 0, getSL() + parseInt(( a[2] - getW( obj ) )/2 ))
   setPos( obj, wT, wL )

//   obj.style.left = "50%"
//   obj.style.top  = "50%"
//   wT = getST() + getT( obj ) - parseInt( getH( obj )/2 )
//   wL = getSL() + getL( obj ) - parseInt( getW( obj )/2 )
//   if( wT < 0 ) wT = 0
//   if( wL < 0 ) wL = 0
//   setPos( obj, wT, wL )
}

function load_event( func ) {
   var oldonload = window.onload;
   if( typeof window.onload != 'function' ) window.onload = func
   else window.onload = function(){ oldonload(); func()}
}

//---------------------------------------------------------------
var backupElems = []
function hideElems(){
// badElems = [ "SELECT", "IFRAME", "APPLET", "EMBED", "OBJECT" ];
   badElems = [ "APPLET", "EMBED", "OBJECT" ];
//return
   if( document.all && ( window.navigator.userAgent.indexOf( "Opera" ) == -1 )){ 
      for( i=0; i < badElems.length; i++){
         backupElems[i] = document.getElementsByTagName ? document.getElementsByTagName( badElems[i] ) : document.all ? document.all.tags( badElems[i] ) : ""
      }
      showElems( 'hidden' )
   }
}   
function showElems( vis ){
   if( backupElems && ( backupElems.length > 0 )) {
      for( i=0; i < backupElems.length; i++) {
         if( backupElems[i].length > 0 ) for( j=0; j < backupElems[i].length;j++ ) if( backupElems[i][j].style ) backupElems[i][j].style.visibility=vis
      } 
   } 
}
var httpOBJ = undefined
//---------------------------------------------------------------
function makeHTTP(){

   if( window.XMLHttpRequest ){
      httpOBJ = new XMLHttpRequest()
      if( httpOBJ.overrideMimeType ) httpOBJ.overrideMimeType('text/html')
   }
   else if( window.ActiveXObject ){
      try {
         httpOBJ = new ActiveXObject( "Msxml2.XMLHTTP" );
      } catch( e ) {
         try {
            httpOBJ = new ActiveXObject( "Microsoft.XMLHTTP" );
         } catch ( e ) {}
      }
   }
   if( !httpOBJ ){
      alert( "Brak polaczenia http" )
   }
   return httpOBJ
}

function abortHTTP(){
	if( httpOBJ ){
      if( httpOBJ.readyState != 4 && httpOBJ.readyState != 0 ){ httpOBJ.abort() }
      httpOBJ = undefined
   }
}

function httpGET( url, func ){
   obj = makeHTTP()
   obj.onreadystatechange = function(){
      if( obj.readyState == 4 && obj.status == 200 ){
         pos  = obj.responseText.indexOf( ':' )
         mess = obj.responseText.substr( 0, pos )
         txt  = obj.responseText.substr( pos+1 )
         func( mess, txt )
      }
   }
   obj.open( 'GET', url, true );
   obj.send( null );
}
function httpPOST( url, func, params ){
   obj = makeHTTP()
   obj.onreadystatechange = function(){
      if( obj.readyState == 4 && obj.status == 200 ){
         pos  = obj.responseText.indexOf( ':' )
         mess = obj.responseText.substr( 0, pos )
         txt  = obj.responseText.substr( pos+1 )
         func( mess, txt )
      }
   }
   obj.open( 'POST', url, true );
   obj.setRequestHeader( "Content-type", "application/x-www-form-urlencoded; charset=iso-8859-2");
   obj.setRequestHeader( "Content-length", params.length );
   obj.setRequestHeader( "Connection", "close" );
   obj.send( params );
}

function getPS(){

   if( window.innerHeight && window.scrollMaxY ){   
      xScroll = document.body.scrollWidth
      yScroll = window.innerHeight + window.scrollMaxY
   }
   else if( document.body.scrollHeight > document.body.offsetHeight ){
      xScroll = document.body.scrollWidth
      yScroll = document.body.scrollHeight
   }
   else {
      xScroll = document.body.offsetWidth
      yScroll = document.body.offsetHeight
   }
   
   if( self.innerHeight ){
      windowWidth  = self.innerWidth
      windowHeight = self.innerHeight
   }
   else if( document.documentElement && document.documentElement.clientHeight ){
      windowWidth  = document.documentElement.clientWidth
      windowHeight = document.documentElement.clientHeight
   }
   else {
      windowWidth  = document.body.clientWidth
      windowHeight = document.body.clientHeight
   }   

   if( yScroll < windowHeight ){ pageHeight = windowHeight } else { pageHeight = yScroll }
   if( xScroll < windowWidth  ){ pageWidth  = windowWidth  } else { pageWidth  = xScroll }

   return new Array( pageWidth, pageHeight, windowWidth, windowHeight ) 
}

function galleryShow( nr, copyright ){

   a = getPS()

   this.border    = 1
   this.opacity   = 0.55
   this.nr        = nr
   this.copyright = copyright ? 'Copyright &copy by ' + copyright : ''
   this.images    = new Array()

   for( i=2; i<arguments.length; i++ ){
      this.images[i-1] = arguments[i] 
   }

   hideElems()
//   this.W = Math.min( 800 + 2*this.border, parseInt( 0.9  * a[2] ))
//   this.H = Math.min( 600 + 2*this.border, parseInt( 0.95 * a[3] ))
   this.W = Math.min( 802+2*this.border, parseInt( 0.9  * a[2] ))
   this.H = Math.min( 602+2*this.border, parseInt( 0.95 * a[3] ))

this.H = 602+2*this.border

   this.T = Math.max( 0, getST() + parseInt(( a[3] - this.H )/2 - this.border ))
   this.L = Math.max( 0, getSL() + parseInt(( a[2] - this.W )/2 - this.border ))

   txt  = "<div id='galleryINNER' style='position:absolute; z-index: 1002; display:block; left:" + this.L + "px; top:" + this.T + "px; width:" + this.W + "px; height:" + this.H + "px; border: solid " + this.border + "px #000000; background-color:#000000; overflow:auto; text-align:center' title=''>"
   txt += "<img id='galleryIMG' src='/images/gallery_pixel.gif' style='display:block'>"
   txt += "</div>"
   this.newdiv( 'galleryDIV', txt )

   txt = "<img src='/images/gallery_pixel.gif' style='display:block; top:0; left:0; width:" + a[0] + "px; height:" + a[1] + "px; z-index: 1001; filter: alpha(opacity=" + parseInt( this.opacity*100 ) + "); position: absolute; background-color: #000000; -moz-opacity:"+this.opacity+"; opacity:"+this.opacity+"; cursor:hand' title='zamknij galerię'/>"
   this.newdiv( 'galleryFADE', txt )

   t = parseInt( this.T + ( this.H-16 )/2 )
   l = parseInt( this.L + ( this.W-16 )/2 )
   txt = "<img src='/images/gallery_loading.gif' style='top:" + t + "px; left:" + l + "px; z-index: 1003; position:absolute' />"
   this.newdiv( 'galleryLOADING', txt )
   this.newdiv( 'galleryNAVI', '' )

   this.div     = getO( 'galleryDIV'  )
   this.fade    = getO( 'galleryFADE' )
   this.img     = getO( 'galleryIMG'  )
   this.loading = getO( 'galleryLOADING' )
   this.navi    = getO( 'galleryNAVI' )
   this.inner   = getO( 'galleryINNER' )

   xxx = this
   this.fade.onclick = function(){ xxx.hide(); return false; }
   this.load( nr )

}

galleryShow.prototype.load = function( nr ){

   if( typeof( this.images[nr] ) != 'object' ){
      this.loading.style.display = 'inline'
      tmp = new Image()
      tmp.src = this.images[nr]
      this.images[nr] = tmp
   }
   this.preload( nr )

   xxx = this
   txt = ''
   for( i=1; i<this.images.length; i++ ){
      if( i == nr ){ xcolor = '#FFFFFF' ; xborder = 'border:1px solid #EEEEEE; margin-right:6px' }
      else         { xcolor = '#555555' ; xborder = 'margin-left:1px; margin-right:7px' }
      txt += "<A HREF='#' onclick='xxx.load( "+i+" ); return false' style='font-size:14px; font-family:\"courier new\"; text-decoration:none; color:" + xcolor + "; background-color:#222222; line-height:24px; " + xborder + "'><B>&nbsp;" + i + "&nbsp;</B></A>";
   }

   t = parseInt( this.T + this.H - 55 )
   l = parseInt( this.L + this.border + 6 )

   nrprew = Math.max( nr-1, 1 )
   nrnext = Math.min( nr+1, this.images.length-1 )
//   txt    = "<A HREF='#' onclick='xxx.load( " + nrprew + " ); return false' style='font-size:14px; font-family:webdings; text-decoration:none; color:#333333; line-height:18px; text-align:center; margin-right:6px; margin-left:6px'><B>&nbsp;3&nbsp;</B></A>" + txt
//   txt   += "<A HREF='#' onclick='xxx.load( " + nrnext + " ); return false' style='font-size:14px; font-family:webdings; text-decoration:none; color:#333333; line-height:18px; text-align:center; margin-right:6px'><B>&nbsp;4&nbsp;</B></A>"

//   txt    = "<A HREF='#' onclick='xxx.load( " + nrprew + " ); return false'><img src='/images/gallery_prev.gif' width=26 height=18 border=0 /></A>" + txt
//   txt   += "<A HREF='#' onclick='xxx.load( " + nrnext + " ); return false'><img src='/images/gallery_next.gif' width=26 height=18 border=0 /></A>"

   btn_prev  = "<A HREF='#' onclick='xxx.load( " + nrprew + " ); return false'><img src='/images/gallery_prev.gif'  width=26 height=18 border=0 /></A>"
   btn_next  = "<A HREF='#' onclick='xxx.load( " + nrnext + " ); return false'><img src='/images/gallery_next.gif'  width=26 height=18 border=0 /></A>"
   btn_close = "<A HREF='#' onclick='xxx.hide(); return false'><img src='/images/gallery_close.gif' width=26 height=18 border=0 alt='zamknij galerię' /></A>"

   txt    = "<TABLE cellpadding=0 cellspacing=0 border=0 width=" + ( this.W-40 ) + " style='top:" + t + "px; left:" + l + "px; z-index: 1004; position:absolute'><TR><TD style='border:1px solid #666666; background-color:#999999'><table border=0 cellpadding=0 cellspacing=0 border=0><tr><td>&nbsp;</td><td>"+btn_prev+"</td><td>&nbsp;</td><td>" + txt + "</td><td>"+btn_next+"</td><td>"+btn_close+"</td><td>&nbsp;</td></tr></table></TD><TD style='color:#333333; font-family:tahoma; font-size:10px' align=right width=90%>" + this.copyright + "</TD></TR></TABLE>"
//   txt    = "<TABLE cellpadding=0 cellspacing=0 border=0 width=" + ( this.W-40 ) + " style='top:" + t + "px; left:" + l + "px; z-index: 1004; position:absolute'><TR><TD style='border:1px solid #666666; background-color:#999999'>" + txt + "</TD><TD style='color:#333333; font-family:tahoma; font-size:10px' align=right width=90%>" + this.copyright + "</TD></TR></TABLE>"
   this.navi.innerHTML = txt
}

galleryShow.prototype.preload = function( nr ){

   if( this.images[nr].complete ) {
      this.img.src = this.images[nr].src
      this.loading.style.display = 'none'
      this.center( this.images[nr] )
      this.inner.scrollTop  = 0
      this.inner.scrollLeft = 0
   }
   else {
      xxx = this
      window.setTimeout( 'xxx.preload(' + nr + ')', 250 );
   }
}

galleryShow.prototype.center = function( img ){
   this.img.style.marginTop = Math.max( 0, parseInt(( this.H - img.height )/2 )) + 'px'
}

galleryShow.prototype.newdiv = function( id, txt ){
   obj = document.createElement( 'div' );
   obj.id = id
   obj.innerHTML = txt
   document.body.insertBefore( obj, document.body.firstChild )
}

galleryShow.prototype.hide = function(){
   document.body.removeChild( this.fade );
   document.body.removeChild( this.div  );
   document.body.removeChild( this.navi );
   document.body.removeChild( this.loading );
   showElems( 'visible' )
}
