var MAG = Object.extend({}, MAG || {});
MAG.MailSend = Class.create();
MAG.MailSend.prototype = {

	is_loading: false,

	initialize: function(options)
	{
		Element.addMethods({
			clearAndFocus: function(element) {
			    if (!(element = $(element))) return;
			    element.value = '';
			    element.focus();
			    return element;
			}
		});

		MAG.MagMailSend = this;
		this.options = {
			ajax_url: self.location.toString(),
			form: $('offer_email'),
			img_code: $$('#offer_email img').first(),
			flash_container: $('flash_message_email')
		};
		Object.extend(this.options, options || {});
		if(!this.options.form) {
			return;
		}

		this.attach_event();

		return true;
	},

	attach_event: function() {
		this.options.form.observe('submit', this.form_submit.bind(this));
	},

	form_submit: function(e)
	{
		Event.stop(e);
		if(this.is_loading) return;
		this.is_loading = true;
		MAG.MagAjax.make_response(this.options.ajax_url, this.options.form.serialize(), 'post', this.dummy.bind(this));
	},

	dummy: function(req) {eval(req.responseText);this.is_loading=false;}
};

document.observe('dom:loaded', function(){new MAG.MailSend;});

function updateQuestion(txt, in_value)
{
	$('idquestion').update(txt+"\n");
	
	$('client_search').remove();
	
	input = new Element('input',{name: "client_search", value: in_value, id: "client_search"});
	input.style.display = 'none';	
	//$('client_search').value = in_value;
	//alert($F('client_search'));
	
	$('offer_email').insert(input);
	Element.scrollTo($('offer_email'));
}
