function parse_form(formId, handler, lang){

  // ==============   dictionary  ================
  function get_dictionary(lang){
    var dictionary = new Array();
    
    switch(lang){
    
      case '':
        dictionary['empty_field'] = 'Необходимо заполнить поле: "[title]"';
        dictionary['wrong_format'] = 'Некорректно заполнено поле: "[title]"';
        dictionary['captcha_error'] = 'Неверно введен код. Сообщение не будет добавленно';        
        break;
        
      case 'russian':
        dictionary['empty_field'] = 'Необходимо заполнить поле: "[title]"';
        dictionary['wrong_format'] = 'Некорректно заполнено поле: "[title]"';
        dictionary['captcha_error'] = 'Неверно введен код. Сообщение не будет добавленно';        
        break;
        
      case 'english':
        dictionary['empty_field'] = 'Please make sure the "[title]" field was properly completed.';
        dictionary['wrong_format'] = 'Please make sure the "[title]" field was properly completed.';
        dictionary['captcha_error'] = 'Wrong code. Message was not added';        
        break;
                        
    } // switch
    return dictionary;
  } // function


  // ============= validator/sender ============== 
  
  var form = document.getElementById(formId);
  var r;
  var req;
  var reg_title = /\[title\]/i;
  var dictionary = get_dictionary(lang);

  // form validation
  
  for(r=0;r<form.elements.length;r++){

    if(form.elements[r].tagName=='FIELDSET') continue;
    name = form.elements[r].name;
    req  = false;
    if((name!='undefined') && (name)){
        if(name.substr(0, 1)=='_') {
          name  = name.substr(1);
          req  = true;
        } // if required
    } // if defined
    else { name = 'null' }

      if ($('#agreed').size()) {
          if (!$('#agreed').is(':checked')) {

              alert ("Вы должны принять соглашение на обработку персональных данных");
              form.elements[r].focus();
              return;
          }
      }

    if(req && (!form.elements[r].value)) {
      alert (dictionary['empty_field'].replace(reg_title, form.elements[r].title));
      
      form.elements[r].focus();
      return;
    }

    if(name == "email") // email check
        {
            mailString = form.elements[r].value; 
            re = /([\.\-_@][\.\-_@])|(^[\.])|(^[\-])|(^[\@])/;
            result = re.test(mailString);
            if(!result)     
            {
                re = /^[\w\-\.]+@[\w\-\.]+\.[a-zA-Z]{2,4}$/;
                result = re.test(mailString);
                
                if(!result){ 
                  alert (dictionary['wrong_format'].replace(reg_title, form.elements[r].title));
                  form.elements[r].focus();
                  return;
                }
                   
            } // if 
            else {
             alert (dictionary['wrong_format'].replace(reg_title, form.elements[r].title));
             form.elements[r].focus();
             return;
             } // else 
        } // if email
    
    
  } // for
  
  // form sending
  var ajaxposter = new sack();
  
  ajaxposter.method = 'POST';
  ajaxposter.requestFile = '/ajax/ajax.php';
  
  for(r=0;r<form.elements.length;r++){
    if(form.elements[r].tagName=='FIELDSET') continue;
      
    name = form.elements[r].name;
    if((name!='undefined') && (name)){
        if(name.substr(0, 1)=='_') name  = name.substr(1);
    }
    else { name = 'null' }
    
    //////////////////////////////////////////////////////////////        
    switch(form.elements[r].tagName){
    
    case "INPUT":
              
              switch(form.elements[r].type){
                          
              case "checkbox":
                    ajaxposter.setVar(name, form.elements[r].checked);      
                    break;

              case "radio":
                    if(form.elements[r].checked)
                    ajaxposter.setVar(name, form.elements[r].value);
                    break;
                    
              default:
                    ajaxposter.setVar(name, form.elements[r].value);      
                    break;
              
              } // switch type 
              break;
    
    case "TEXTAREA":
              ajaxposter.setVar(name, form.elements[r].value);
              break;

    case "SELECT":
              ajaxposter.setVar(name, form.elements[r].options[form.elements[r].selectedIndex].text);
              ajaxposter.setVar(name+'_value', form.elements[r].options[form.elements[r].selectedIndex].value);
              break;
    } // switch tagname
  } // for

  switch(typeof(handler)){
    case 'string':
          ajaxposter.onCompletion = function(){
            if(this.response == 'captcha_error'){
              alert (dictionary['captcha_error']);
            }
            else {
              document.getElementById(handler).innerHTML=this.response;
            }
          } // function  
          break;
  
    case 'function':
          ajaxposter.onCompletion = handler;
          break;
            
  } // switch
  


  
  ajaxposter.runAJAX();         
  
} // function
