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

addLoadEvent(loadEvents);

function loadEvents() {

  if( input_login = document.getElementById('login2') ) {
    input_login.onfocus = function() {
      if( this.value == 'login' ) {
        this.value = '';
        document.getElementById('password2').value = '';
      } else {
        this.select();
      }
    }

    input_login.onblur = function() {
      if( this.value == '' ) {
        this.value = 'login';
        document.getElementById('password2').value = '....';
      }
    }

  }

  if( input_pwd = document.getElementById('password2') ) {
    input_pwd.onfocus = function() {
      if( this.value == '....' ) {
        this.value = '';
      } else {
        this.select();
      }
    }

    input_pwd.onblur = function() {
      if( this.value == '' ) {
        this.value = 'login';
        document.getElementById('password2').value = '....';
      }
    }

  }

  if( register_pwd = document.getElementById('password') )
    register_pwd.setAttribute( "autocomplete", "off" );

  if( register_login = document.getElementById('login') )
    register_login.setAttribute( "autocomplete", "off" );

}

function show_forget_pwd_form()
{
  remove_all_children('forget_pwd');

  var p_forget_pwd = document.getElementById('forget_pwd');

  var m_text = document.createElement('span');
  m_text.setAttribute('style', 'font-size: 8pt;margin: 0 3px 0 0;');
  var var_text = document.createTextNode('Entrer votre email');

  var msg_p = document.createElement('p');
  msg_p.setAttribute('id', 'error_msg');
  msg_p.setAttribute('class', 'red');
  msg_p.setAttribute('className', 'red');

  var input_text = document.createElement('input');
  input_text.setAttribute('type', 'text');
  input_text.setAttribute('size', '15');
  input_text.setAttribute('id', 'email_forget_pwd');
  input_text.setAttribute('class', 'inputtext');
  input_text.setAttribute('className', 'inputtext');
  input_text.setAttribute('style', 'margin: 4px 0 0 0;');

  var input_button = document.createElement('a');
  input_button.setAttribute('href', 'javascript:void(0)');
  input_button.setAttribute('class', 'small_submit');
  input_button.setAttribute('className', 'small_submit');

  var var_ok = document.createTextNode('ok');

  var input_span1 = document.createElement('span');
  var input_span2 = document.createElement('span');
  var input_span3 = document.createElement('span');

  if( document.all )
    input_button.attachEvent( "onclick", send_pwd_mail );
  else
    input_button.addEventListener( "click", send_pwd_mail, true );

  m_text.appendChild(var_text);
  input_span3.appendChild(var_ok);
  input_span2.appendChild(input_span3);
  input_span1.appendChild(input_span2);
  input_button.appendChild(input_span1);

  p_forget_pwd.appendChild(m_text);
  p_forget_pwd.appendChild(input_text);
  p_forget_pwd.appendChild(input_button);
  p_forget_pwd.appendChild( msg_p );

  return false;
}

function send_pwd_mail( event )
{
  var msg_p = document.getElementById('error_msg');
  var email = document.getElementById('email_forget_pwd').value;

  if( email == '' ) {
    var msg = document.createTextNode('Veuiller entrer une adresse email.');
  } else {
    var is_mail_sent = ajax_get_synchro_request('http://www.ranks.fr/fr/ajax_request.php?send_password='+email);
    if( is_mail_sent == 'true') {
      remove_all_children('forget_pwd');

      var msg_p_ = document.createElement('p');
      msg_p_.setAttribute('id', 'error_msg');
      msg_p_.setAttribute('class', 'red');
      msg_p_.setAttribute('className', 'red');
      document.getElementById('forget_pwd').appendChild( msg_p_ );
      msg_p = document.getElementById('error_msg');

      var msg = document.createTextNode('Email envoyé');
    } else {
      var msg = document.createTextNode('Aucun compte avec cet email. Contactez-nous en cas de problème');
    }
  }
  remove_all_children('error_msg');
  msg_p.appendChild( msg );
}

function remove_all_children( element_id ) {
  if( cell = document.getElementById( element_id ) ) {
    if( cell.hasChildNodes() )
    {
      while( cell.childNodes.length >= 1 )
      {
        cell.removeChild( cell.firstChild );
      }
    }
  }
}

function submitlogin() {
  var login_value = document.getElementById('login2').value;
  var pwd_value = document.getElementById('password2').value;

  if( login_value != '' && login_value != 'login' && pwd_value != '' && pwd_value != '....' ) {
    return true;
  }

  return false;
}

function popup_chat() {
  window.open('http://www.google.com/talk/service/badge/Start?tk=z01q6amlq3cdbj1alupalh8ktucoorj4e0dl9rs0dllo19s0qk6n1ftcv0bp8jgi4al207e59jqi4ans4lg0rf7o3k793baoc917fo1b9pid6460fr5ueo4is0j6h9012otjabraue4a6c6pq5n7dhc10ndbprt2gpt0on7p2i948c0d2tfbivtb1vqg9h8cdss',
              '_blank',
              'toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=400, height=310');
}

