function preLoad( img_url ) {
    var img_pre = new Image();
    img_pre.src = img_url;
    return img_pre;
}

function toggleRegForm() {
    if ( $('regForm').visible() ) {
        new Effect.Fade('regForm', { duration: 0.5, queue: {position: 'end', scope: 'regForm'}});

        $('regFormSpacer').morph('height: 0px', {duration: 0.5, queue: {position: 'end', scope: 'regForm'},
            afterFinish: function(obj) {
                $('regErrorN1').hide();
                $('regErrorN2').hide();
                $('regErrorN3').hide();
                $('regErrorE1').hide();
                $('regErrorE2').hide();
                $('regErrorE3').hide();
                $('regFormErrors').style.height = '0px';
            }
         });

    } else {
        $('regErrorN1').hide();
        $('regErrorN2').hide();
        $('regErrorN3').hide();
        $('regErrorE1').hide();
        $('regErrorE2').hide();
        $('regErrorE3').hide();
        $('regFormErrors').style.height = '0px';

        new Effect.Fade('regFormOK', { duration: 0.5, queue: {position: 'end', scope: 'regForm'}});
        $('regFormSpacer').morph('height: 80px', {duration: 0.5, queue: {position: 'end', scope: 'regForm'}});
        new Effect.Appear('regForm', { duration: 0.5, queue: {position: 'end', scope: 'regForm'}});
    }
}



function doReg() {
    new Ajax.Request('?base=forumRPC&action=registration', {
      method: 'post',
      parameters: { email: $('regEmail').value, nick: $('regNick').value },
      onSuccess: function(transport) {

          if ( transport.responseText.include('OK') ) {
              new Effect.Fade('regForm', { duration: 0.5, queue: {position: 'end', scope: 'regForm'}});
              $('regFormSpacer').morph('height: 80px', {duration: 0.5, queue: {position: 'end', scope: 'regForm'}});
              new Effect.Appear('regFormOK', { duration: 0.5, queue: {position: 'end', scope: 'regForm'}});
              return false;
          }


          var errorsHeight = 0;

          var oldErrors = {
          N1: ($('regErrorN1').style.display !== 'none'),
          N2: ($('regErrorN2').style.display !== 'none'),
          N3: ($('regErrorN3').style.display !== 'none'),
          E1: ($('regErrorE1').style.display !== 'none'),
          E2: ($('regErrorE2').style.display !== 'none'),
          E3: ($('regErrorE3').style.display !== 'none')
          };

          var newErrors = {
              N1: false, N2: false, N3: false, E1: false, E2: false, E3: false
          }
            
        for ( i in oldErrors ) {
          newErrors[i] = transport.responseText.include(i);
          if ( newErrors[i] && !oldErrors[i] ) {
              errorsHeight += 15;
          } else if ( !newErrors[i] && oldErrors[[i]] ) {
              errorsHeight -= 15;
          }

        }

        for ( i in oldErrors ) {
          if ( !newErrors[i] && oldErrors[[i]] ) {
              Effect.Fade('regError'+i, { duration: 0.3, queue: {position: 'end', scope: 'regErrors'}});
          }
        }
        
        if ( errorsHeight > 0 )
              resizeDiv( 'regFormErrors', errorsHeight, 'regErrors' );

        for ( i in oldErrors ) {
          if ( newErrors[i] && !oldErrors[i] ) {
              Effect.Appear('regError'+i, { duration: 0.3, queue: {position: 'end', scope: 'regErrors'}});
          }
        }

        if ( errorsHeight < 0 )
              resizeDiv( 'regFormErrors', errorsHeight, 'regErrors' );
        
      }
    });

}


//FÓRUM - JELSZÓ EMLÉKEZTETŐ


function toggleRemindForm() {
    if ( $('remindForm').visible() ) {
      new Effect.Fade('remindForm', { duration: 0.5, queue: {position: 'end', scope: 'remindForm'}});
      $('remindFormSpacer').morph('height: 0px', {duration: 0.5, queue: {position: 'end', scope: 'remindForm'}});

        $('remindFormSpacer').morph('height: 0px', {duration: 0.5, queue: {position: 'end', scope: 'remindForm'},
            afterFinish: function(obj) {
                $('remindErrorE1').hide();
                $('remindErrorE2').hide();
                $('remindErrorE3').hide();
                $('remindFormErrors').style.height = '0px';
            }
         });

    } else {

      $('remindErrorE1').hide();
      $('remindErrorE2').hide();
      $('remindErrorE3').hide();
      $('remindFormErrors').style.height = '0px';

      new Effect.Fade('remindFormOK', { duration: 0.5, queue: {position: 'end', scope: 'remindForm'}});
      $('remindFormSpacer').morph('height: 75px', {duration: 0.5, queue: {position: 'end', scope: 'remindForm'}});
      new Effect.Appear('remindForm', { duration: 0.5, queue: {position: 'end', scope: 'remindForm'}});
    }
}


function doRemind() {
    new Ajax.Request('?base=forumRPC&action=remind', {
      method: 'post',
      parameters: { email: $('remindEmail').value },
      onSuccess: function(transport) {

          if ( transport.responseText.include('OK') ) {
              new Effect.Fade('remindForm', { duration: 0.5, queue: {position: 'end', scope: 'remindForm'}});
              $('remindFormSpacer').morph('height: 60px', {duration: 0.5, queue: {position: 'end', scope: 'remindForm'}});
              new Effect.Appear('remindFormOK', { duration: 0.5, queue: {position: 'end', scope: 'remindForm'}});
              return false;
          }


          var errorsHeight = 0;

          //Régi hibák elrejtése
          var oldErrors = {
          E1: ($('remindErrorE1').style.display !== 'none'),
          E2: ($('remindErrorE2').style.display !== 'none'),
          E3: ($('remindErrorE3').style.display !== 'none')
          };

          var newErrors = {
              E1: false, E2: false, E3: false
          }
            
        for ( i in oldErrors ) {
          newErrors[i] = transport.responseText.include(i);
          if ( newErrors[i] && !oldErrors[i] ) {
              errorsHeight += 15;
          } else if ( !newErrors[i] && oldErrors[[i]] ) {
              errorsHeight -= 15;
          }

        }

        for ( i in oldErrors ) {
          if ( !newErrors[i] && oldErrors[[i]] ) {
              Effect.Fade('remindError'+i, { duration: 0.3, queue: {position: 'end', scope: 'remindErrors'}});
          }
        }
        
        if ( errorsHeight > 0 )
              resizeDiv( 'remindFormErrors', errorsHeight, 'remindErrors' );

        for ( i in oldErrors ) {
          if ( newErrors[i] && !oldErrors[i] ) {
              Effect.Appear('remindError'+i, { duration: 0.3, queue: {position: 'end', scope: 'remindErrors'}});
          }
        }

        if ( errorsHeight < 0 )
              resizeDiv( 'remindFormErrors', errorsHeight, 'remindErrors' );
        
      }
    });

}


//betöltődéskor végrehajtandó műveletek
/*
Event.observe(window, 'load',
  function() { 
    var h1 = $$('h1 span:first-'); 

    for (var i = 0; i < h1.length; i++) { 
        h1[i].style.color="red";
    }
}
);*/
