 /**
 * Web in de Wijk
 *
 * (C) 2006, Q42 Internet BV - http://q42.nl
 */

proxies.Validation.ValidateUserRegistration.func = function(soapResult)
{
    inputEl = document.getElementById("gebruikersnaam");

    if (soapResult != "")
    {
      document.getElementById("username-error").innerHTML = soapResult;
      Spif.ClassNameAbstraction.add(inputEl, "error");
    }
    else
    {
      document.getElementById("username-error").innerHTML = "<img src='/_img/oke.gif' alt='oke'/>";
      Spif.ClassNameAbstraction.remove(inputEl, "error");
    }
}

proxies.Validation.ValidateEmailRegistration.func = function(soapResult)
{
    inputEl = document.getElementById("email");
    
    if (soapResult != "")
    {
      document.getElementById("email-error").innerHTML = soapResult;
      Spif.ClassNameAbstraction.add(inputEl, "error");
    }
    else
    {
      document.getElementById("email-error").innerHTML = "<img src='/_img/oke.gif' alt='oke'/>";
      Spif.ClassNameAbstraction.remove(inputEl, "error");
    }
}

proxies.Validation.ValidatePasswordRegistration.func = function(soapResult)
{
    inputEl = document.getElementById("wachtwoord");

    if (soapResult != "")
    {
      document.getElementById("wachtwoord-error").innerHTML = soapResult;
      Spif.ClassNameAbstraction.add(inputEl, "error");
    }
    else
    {
      document.getElementById("wachtwoord-error").innerHTML = "<img src='/_img/oke.gif' alt='oke'/>";
      Spif.ClassNameAbstraction.remove(inputEl, "error");
    }
}

function UserRegistration()
{}
UserRegistration.prototype =
{
  timer:null,
  func:null,
  inputEl:null,

  checkUserName : function (el)
  {
    var value = el.value;
    if (value != "")
      document.getElementById("username-error").innerHTML = "<img src='/_img/q42loading_bloem.gif' class='waiting' alt='waiting' />";
    else
      document.getElementById("username-error").innerHTML = "";
      
    var newUserId = parseInt(document.getElementById("newUserId").value);
    if (typeof(newUserId) != "number" || isNaN(newUserId))   
      newUserId = -1;
      
    if (this.timer!=null)
    {
      clearTimeout(this.timer);
      this.timer=null;
      if (this.inputEl != el)
        setTimeout(this.func, 1);
      this.inputEl = el;
    }
    
    this.func = function() {proxies.Validation.ValidateUserRegistration(el.value, newUserId)}
    this.timer = setTimeout(this.func, 1500);
  },
  
  checkEmailadres : function (el)
  {
    var value = el.value;
    if (value != "")
      document.getElementById("email-error").innerHTML = "<img src='/_img/q42loading_bloem.gif' class='waiting' alt='waiting' />";
    else
      document.getElementById("email-error").innerHTML = "";
  
    var newUserId = parseInt(document.getElementById("newUserId").value);
    if (typeof(newUserId) != "number" || isNaN(newUserId))   
      newUserId = -1;
      
    if (this.timer!=null)
    { 
      clearTimeout(this.timer);
      this.timer=null;
      if (this.inputEl != el)
        setTimeout(this.func, 1);
      this.inputEl = el;
    }
    
    this.func = function() {proxies.Validation.ValidateEmailRegistration(el.value, newUserId)};  
    this.timer = setTimeout(this.func, 1500);
  
  },
  
  checkPassword : function (el)
  {
    var value = el.value;
    if (value != "")
      document.getElementById("wachtwoord-error").innerHTML = "<img src='/_img/q42loading_bloem.gif' class='waiting' alt='waiting' />";
    else
      document.getElementById("wachtwoord-error").innerHTML = "";
      
    if (this.timer!=null)
    { 
      clearTimeout(this.timer);
      this.timer=null;
      if (this.inputEl != el)
        setTimeout(this.func, 1);
      this.inputEl = el;
    }
      
    this.func = function() {proxies.Validation.ValidatePasswordRegistration(el.value)};  
    this.timer = setTimeout(this.func, 1500);
 

    var ww2 = document.getElementById("wachtwoord2");
    if (ww2)
      ww2.value = "";
  },
  
  checkPassword2 : function (el, afhankelijkheid)
  {
    if (el.value != document.getElementById(afhankelijkheid).value) 
    {
      document.getElementById("wachtwoord2-error").innerHTML = "De beide wachtwoorden zijn niet gelijk";
      Spif.ClassNameAbstraction.add(el, "error");
    }   
    else
    {
      document.getElementById("wachtwoord2-error").innerHTML = "<img src='/_img/oke.gif' alt='oke'/>";
      Spif.ClassNameAbstraction.remove(el, "error");
    }
  }
}

var userregistration = new UserRegistration();
