function Faq(form_name, area_id)
{	this.form_name = form_name;
	this.area_id = area_id;
	this.construct = function ()
	{		this.form_obj = document.forms[this.form_name];
		this.area = document.getElementById(this.area_id);
		this.areaHTML = (this.area.innerHTML + '');
		this.clear_area = document.getElementById(this.area_id+'2');
		this.clear_areaHTML = (this.clear_area.innerHTML + '');
		this.default_question = this.form_obj['faq[default_question]'].value;
		this.default_name = this.form_obj['faq[default_name]'].value;
		this.default_email = this.form_obj['faq[default_email]'].value;
		this.form_obj['faq[question]'].value = this.default_question;
		this.form_obj['faq[question]'].onfocus = function()
		{
			if(Faq.form_obj['faq[question]'].value == Faq.default_question)
			{
				Faq.form_obj['faq[question]'].value = '';
				Faq.form_obj['faq[question]'].style.color = '#000000';
			}
		}

		this.form_obj['faq[question]'].onblur = function()
		{
			if(Faq.form_obj['faq[question]'].value == '')
			{
				Faq.form_obj['faq[question]'].style.color = '#BBBBBB';
				Faq.form_obj['faq[question]'].value = Faq.default_question;
			}
		}
	// -----------------------------------------------
		this.form_obj['faq[name]'].value = this.default_name;
		this.form_obj['faq[name]'].onfocus = function()
		{
			if(Faq.form_obj['faq[name]'].value == Faq.default_name)
			{
				Faq.form_obj['faq[name]'].value = '';
				Faq.form_obj['faq[name]'].style.color = '#000000';
			}
		}

		this.form_obj['faq[name]'].onblur = function()
		{
			if(Faq.form_obj['faq[name]'].value == '')
			{
				Faq.form_obj['faq[name]'].style.color = '#BBBBBB';
				Faq.form_obj['faq[name]'].value = Faq.default_name;
			}
		}
	// -----------------------------------------------
		this.form_obj['faq[email]'].value = this.default_email;
		this.form_obj['faq[email]'].onfocus = function()
		{
			if(Faq.form_obj['faq[email]'].value == Faq.default_email)
			{
				Faq.form_obj['faq[email]'].value = '';
				Faq.form_obj['faq[email]'].style.color = '#000000';
			}
		}

		this.form_obj['faq[email]'].onblur = function()
		{
			if(Faq.form_obj['faq[email]'].value == '')
			{
				Faq.form_obj['faq[email]'].style.color = '#BBBBBB';
				Faq.form_obj['faq[email]'].value = Faq.default_email;
			}
		}
	}

	this.construct();
	this.send = function(but)
	{		but.disabled = true;		var tmp = this.check();
		if(tmp != 4)
		{			alert(error_message[tmp]);
			this.form_obj[error_field[tmp]].focus();
			but.disabled = false;
			return false;
		}	    var req = new JsHttpRequest();
	    req.onreadystatechange = function()
	    {
	        if (req.readyState == 4)
	        {	        	Faq.result(req.responseText, req.responseJS['is_spam'], but);
	        }
	    }

        var arr = Array();
        arr['lang'] = this.special_chars(this.form_obj['faq[lang]'].value);
	    arr['name'] = this.special_chars(this.form_obj['faq[name]'].value);
	    arr['email'] = this.special_chars(this.form_obj['faq[email]'].value);
	    arr['question'] = this.special_chars(this.form_obj['faq[question]'].value);

	    req.open(null, '/www/a2.php', true);
	    req.send(arr);
	}
	this.check = function()
	{		if(this.form_obj['faq[question]'].value == this.default_question || this.form_obj['faq[question]'] == '') return 1;
		if(this.form_obj['faq[question]'].value.length < 5) return 1;
		if(this.form_obj['faq[name]'].value == this.default_name || this.form_obj['faq[name]'] == '') return 2;
		if(this.form_obj['faq[name]'].value.length < 2) return 2;
		if(this.form_obj['faq[email]'].value == this.default_email || this.form_obj['faq[email]'] == '') return 3;
		if(this.form_obj['faq[email]'].value.length < 7) return 3;
		if(!/^[a-z0-9][a-z0-9\.\-_]*\@[a-z0-9][a-z0-9\.\-_]*[a-z0-9]\.[a-z]{2,4}$/.test(this.form_obj['faq[email]'].value)) return 3;
		return 4;
	}
	this.result = function(text, flood, but)
	{		if(flood)
		{			alert(text);
			but.disabled = false;
			return false;		}
		this.area.innerHTML = text + '<br><br><center><a onclick="Faq.again();" alt="refresh" title="refresh" style="cursor: pointer; cursor: hand;">Задать еще вопрос</a></center>';
		this.clear_area.innerHTML = '';
	}
	this.special_chars = function(txt)
	{		var new_txt = '';		var chrs = Array(1240, 1241, 1186, 1187, 1170, 1171, 1198, 1199, 1200, 1201, 1178, 1179, 1256, 1257, 1210, 1211);
		for(var i = 0, to = txt.length; i < to; i++)
		{			tmp_chrcode = txt.charCodeAt(i);
			repl = false;
			for(var a = 0; a < 16; a++)
			{				if(chrs[a] == tmp_chrcode) repl = true;			}
			if(repl) new_txt += '&#' + tmp_chrcode + ';';
			else new_txt += txt.charAt(i);		}
		return new_txt;	}
	this.again = function()
	{		if(this.area.innerHTML != this.areaHTML)
		{			this.area.innerHTML = this.areaHTML;
			this.clear_area.innerHTML = this.clear_areaHTML;
			this.construct();
			return true;
		}	}
}
