function FormRegistrationClass(
  firstNameElementId,
  lastNameElementId,
  addressElementId,
  cityElementId,
  postalCodeElementId,
  provinceElementId,
  countryElementId,
  telephoneElementId,
  emailElementId,
  userNameElementId,
  passwordElementId,
  confirmPasswordElementId,
  captchaTextElementId,
  captchaImageElementId,
  checkFieldMessageElementId,
  formElementId,
  sendButtonElementId,
  loaderElementId) 
{
  var _formRegistration = this;
  
  var normalColor = '#FFFFFF';
  var wrongColor = '#ecd172';
  var errorColor = '#ffacac';
  var emailRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  
  this.firstNameElementId = firstNameElementId;
  this.lastNameElementId = lastNameElementId;
  this.addressElementId = addressElementId;
  this.cityElementId = cityElementId;
  this.postalCodeElementId = postalCodeElementId;
  this.provinceElementId = provinceElementId;
  this.countryElementId = countryElementId;
  this.telephoneElementId = telephoneElementId;
  this.emailElementId = emailElementId;
  this.userNameElementId = userNameElementId;
  this.passwordElementId = passwordElementId;
  this.confirmPasswordElementId = confirmPasswordElementId;
  this.captchaTextElementId = captchaTextElementId;
  this.captchaImageElementId = captchaImageElementId;
  this.checkFieldMessageElementId = checkFieldMessageElementId;
  this.formElementId = formElementId;
  this.sendButtonElementId = sendButtonElementId;
  this.loaderElementId = loaderElementId;
  
  this.checkNotEmptyInputField = function (inputElementId)
  {
	var check = false;  
	var inputElement = document.getElementById(inputElementId); 
	if (inputElement != null)
	{
	  if (inputElement.value != '')
	  {
		check = true;
		inputElement.style.backgroundColor = normalColor;	
	  }	  
	  else
	  {
	    check = false;
	    inputElement.style.backgroundColor = errorColor;
	  }		  
	}
	return check;	
  }
  
  this.checkMinLengthInputField = function (inputElementId, length)
  {
	var check = false;  
	var inputElement = document.getElementById(inputElementId); 
	if (inputElement != null)
	{
	  if (inputElement.value != '')
	  {
		if (inputElement.value.length >=8)
		{	
		  check = true;
		  inputElement.style.backgroundColor = normalColor;
		}
		else
		{
		  check = false;
		  inputElement.style.backgroundColor = wrongColor;	
		}	
	  }	  
	  else
	  {
	    check = false;
	    inputElement.style.backgroundColor = errorColor;
	  }		  
	}
	return check;	
  }
  
  this.checkEqualInputFields = function (inputElementId1, inputElementId2)
  {
	var check = false;  
	var inputElement1 = document.getElementById(inputElementId1); 
	var inputElement2 = document.getElementById(inputElementId2);
	
	if ((inputElement1 != null) && (inputElement2 != null))
	{
	  if (inputElement1.value == inputElement2.value)
	  {
		check = true;
		inputElement1.style.backgroundColor = normalColor;
		inputElement2.style.backgroundColor = normalColor;		
	  }	  
	  else
	  {
	    check = false;
	    inputElement1.style.backgroundColor = wrongColor;
		inputElement2.style.backgroundColor = wrongColor;
	  }		  
	}
	return check;	
  }
  
  this.checkEMailInputField = function (inputElementId)
  {
	var check = false;  
	var inputElement = document.getElementById(inputElementId); 
	if (inputElement != null)
	{
	  if (inputElement.value != '')
	  {
		if (emailRegExp.test(inputElement.value))
		{		
		  check = true;
		  inputElement.style.backgroundColor = normalColor;
		}
		else
		{
		  check = false;
		  inputElement.style.backgroundColor = wrongColor;	
		}	
	  }	  
	  else
	  {
	    check = false;
	    inputElement.style.backgroundColor = errorColor;
	  }		  
	}
	return check;	
  }
  
  this.dataUserInputValidate = function ()
  {
	var isValid = true;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.firstNameElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.lastNameElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.addressElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.cityElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.postalCodeElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.provinceElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.countryElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.telephoneElementId) && isValid;
	isValid = _formRegistration.checkEMailInputField(_formRegistration.emailElementId) && isValid;
	return isValid;
  }
  
  this.dataLoginInputValidate = function ()
  {
	var isValid = true;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.userNameElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.passwordElementId) && isValid;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.confirmPasswordElementId) && isValid;
	if (isValid)
	{
	  isValid = _formRegistration.checkMinLengthInputField(_formRegistration.userNameElementId, 8) && isValid;
	  isValid = _formRegistration.checkMinLengthInputField(_formRegistration.passwordElementId, 8) && isValid;
	}
	if (isValid)
	{
	  isValid = _formRegistration.checkEqualInputFields(_formRegistration.passwordElementId, _formRegistration.confirmPasswordElementId) && isValid;
	}	
	return isValid;
  }	
  
  this.dataCaptchaInputValidate = function ()
  {
	var isValid = true;
	isValid = _formRegistration.checkNotEmptyInputField(_formRegistration.captchaTextElementId) && isValid;
	return isValid;
  }
  
  this.dataInputValidate = function ()
  {
	var isValid = true;  
	isValid = _formRegistration.dataUserInputValidate() && isValid;	
	isValid = _formRegistration.dataLoginInputValidate() && isValid;
	isValid = _formRegistration.dataCaptchaInputValidate() && isValid;
	return isValid;
  }
  
  this.captchaValidate = function ()
  {
	var captchaTextElement = document.getElementById(_formRegistration.captchaTextElementId);  
    new Ajax.Request(
      UIObj.absRoot + '/' + 'ValidateCaptcha.svt' + UIObj.addJSessionId(), 
      { 
        method: 'post',
        parameters: 
        {
          captcha: captchaTextElement.value          
        },  
        onFailure: UIObj.failureAjaxUpdater,
        onComplete: _formRegistration.xmlCaptchaProcess,             
        evalScripts: true
      }
    );   
  }

  this.captchaImageUpdate = function ()
  {
	var captchaImageElement = document.getElementById(_formRegistration.captchaImageElementId);
	captchaImageElement.src = UIObj.absRoot + '/MakeCaptchaImage.svt' + UIObj.addJSessionId() + "?" + new Date();	    
  }

  this.xmlCaptchaProcess = function (request)
  {  
    var xmlResponse = request.responseXML;
    var validateNode = xmlResponse.getElementsByTagName('validate');
    var isValid = (validateNode[0].firstChild.nodeValue == 1);
    
    var checkFieldMessageElement = document.getElementById(_formRegistration.checkFieldMessageElementId);
    
    if (!isValid)
    {
      var captchaTextElement = document.getElementById(_formRegistration.captchaTextElementId);  
      captchaTextElement.style.backgroundColor = wrongColor;      
      checkFieldMessageElement.style.visibility = 'visible';
      _formRegistration.captchaImageUpdate();    
    }
    else
    {       	    	
      var loaderElement = document.getElementById(_formRegistration.loaderElementId);
      var sendButtonElement = document.getElementById(_formRegistration.sendButtonElementId);
      var formElement = document.getElementById(_formRegistration.formElementId);
      checkFieldMessageElement.style.visibility = 'hidden';
      sendButtonElement.disabled='disabled';
      loaderElement.style.display = 'inline';
      formElement.submit();
    }	
  }
  
  this.send = function ()
  {
	var checkFieldMessageElement = document.getElementById(_formRegistration.checkFieldMessageElementId);
	var isValid = _formRegistration.dataInputValidate();
	if (isValid)
	{
	  checkFieldMessageElement.style.visibility = 'hidden';
	  _formRegistration.captchaValidate();
	}
	else
	{
	  checkFieldMessageElement.style.visibility = 'visible';
	}	
  }	
  
  this.reset = function ()
  {
	var formElement = document.getElementById(_formRegistration.formElementId);	  
	formElement.reset();
  }
}

