//*********************************************************************************
// CMS Symp 3.0
// JavaScript класс для отправки данных формы
//*********************************************************************************
function sendForm_symp () {
        //public attributes
        this.sever_file_name = "";              //Имя серверного скрипта;
        this.form_tag = "";                     //id Имя формы для отправки;
        this.accept_tag = "";                   //id элемента, в случаи удачной операции;
        this.error_tag = "";                    //id элемента, в случаи удачной операции;
        this.type_res = "str";
        this.isFeed = 'no';

        //private method
        this.send = function() {                        //отрпавка данных на сервер
                //Найдем все элементы формы
                try{
                var ind = document.getElementById('pwlocaltext').innerHTML;
                }catch(e){}
                $("form#"+this.form_tag+" input[type = 'text']").css("background-color", "#ffffff");
                $("form#"+this.form_tag+" input[type = 'password']").css("background-color", "#ffffff");
                $("form#"+this.form_tag+" input[type = 'file']").css("background-color", "#ffffff");
                $("form#"+this.form_tag+" textarea").css("background-color", "#ffffff");
                $("label[type='result_field']").text("");
                this.param = $("form#"+this.form_tag).serialize();

                if(this.isFeed=='yes'){
                        $("#"+this.error_tag).html(document.getElementById('pwlocaltext').innerHTML);
                }else{
                        $("#"+this.error_tag).html("<img src=\"/resources/images/indicator.gif\">");
                }
                
                $.post(this.sever_file_name, this.param, this.response);
        }

        this.response = function(xml) {                 //получаем результат
                var accept = $("accept", xml).text();
                var obj_parent = this.success.parent;
                if (accept == 0) {
                        $("#"+obj_parent.error_tag).text($("glob_message", xml).text());
                        $("filed", xml).each(
                                function() {
                                        $("#result_"+$(this).attr("name")).text($(this).text());
                                        $("input[name = '"+$(this).attr("name")+"']").css("background-color", "#c9d9e9");

                                        // Little hack.
                                        if ($(this).attr('name') == 'vacform_resume_name') {
                                                $("input[name = 'vacform_resume']").css('background-color', '#c9d9e9');
                                        }
                                }
                        )
                } else if (accept == 1) {
                        //$("#"+obj_parent.accept_tag).text($("glob_message", xml).text());
                        if (obj_parent.type_res == "obj") {
                                obj_parent.add_accept_function_obj(xml);
                        } else {
                                obj_parent.add_accept_function($("glob_message", xml).text());
                        }
                }
        }
        this.response.parent = this; //Позволит обращаться к предку класса

        this.add_accept_function = function(accept_text) {              //Стандартная функция вывода результатов
                $("#"+this.response.parent.accept_tag).text(accept_text);
        }

        this.add_accept_function_obj = function(xml) {          //Стандартная функция вывода результатов
        }

}

function sendForm2_symp () {
        //public attributes
        this.sever_file_name = "";              //Имя серверного скрипта;
        this.form_tag = "";                     //id Имя формы для отправки;
        this.accept_tag = "";                   //id элемента, в случаи удачной операции;
        this.error_tag = "";                    //id элемента, в случаи удачной операции;
        this.type_res = "str";
        this.isFeed = 'no';

        //private method
        this.send = function() {                        //отрпавка данных на сервер
                //Найдем все элементы формы
                try{
                var ind = document.getElementById('pwlocaltext').innerHTML;
                }catch(e){}
                $("form#"+this.form_tag+" .ask_field").removeClass('red');
                $("label[type='result_field']").text("");
                $("#ask_code_field_more").hide();
                this.param = $("form#"+this.form_tag).serialize();
                if(this.isFeed=='yes'){
                        $("#"+this.error_tag).html(document.getElementById('pwlocaltext').innerHTML);
                }else{
                        $("#"+this.error_tag).html("<img src=\"/resources/images/indicator.gif\">");
                }
                
                $.post(this.sever_file_name, this.param, this.response);
        }

        this.response = function(xml) {                 //получаем результат
                var accept = $("accept", xml).text();
                var obj_parent = this.success.parent;
                if (accept == 0) {
                        $("#"+obj_parent.error_tag).text($("glob_message", xml).text());
                        $("filed", xml).each(
                                function() {
                                        $("#result_"+$(this).attr("name")).text($(this).text());
                                        $("#"+$(this).attr("name")+"_field").addClass('red');
                                        
                                        // Little hack.
                                        if ($(this).attr('name') == 'ask_code') {
                                                $("#ask_code_field_more").show();
                                        }
                                }
                        )
                } else if (accept == 1) {
                        //$("#"+obj_parent.accept_tag).text($("glob_message", xml).text());
                        if (obj_parent.type_res == "obj") {
                                obj_parent.add_accept_function_obj(xml);
                        } else {
                                obj_parent.add_accept_function($("glob_message", xml).text());
                        }
                }
        }
        this.response.parent = this; //Позволит обращаться к предку класса

        this.add_accept_function = function(accept_text) {              //Стандартная функция вывода результатов
                $("#"+this.response.parent.accept_tag).text(accept_text);
        }

        this.add_accept_function_obj = function(xml) {          //Стандартная функция вывода результатов
        }

}

