window.addEvent('domready', function()
{
	dbug.enable();
	nsPrgsBar.enable(Config.prgsBar);//disable();
	if (typeof ns == "undefined" )
		ns = new nsBase(Config.nsSys);


	if ($('frm_order'))
		new TourOrderForm(Config.OrderTour).initForm();

	if ($('frm_response'))
		new nsForm(Config.Response).initForm();

	if ($('frm_subscribe'))
		new nsForm(Config.Subscribe).initForm();

	if ($('frm_faq'))
		new nsFormExt(Config.Faq).initForm();
	
	if ($('frm_feedback'))
		new nsFormExt(Config.Feedback).initForm();


	initConsultantForm();
});


var initConsultantForm = function(){
	var frm = $('consultform');
	if (!frm)
		return;

	var options = {
		callback: initConsultantForm
	};
	
	initAxForm(frm, options);
}


function initAxForm(frm, options) {
	options = $extend({
		msg : "Отправка данных...",
		output : true,  // true| false is need output result
		params : {},
		callback : '',
		fireEvent: false,
		eventType : 'submit'
	}, options);


	// clear form submit property
	frm.onsubmit = function () {return false;}
	frm.submit = function () {return false;}

	// get result objects
	var resto = frm.getProperty('resto');
	if (!resto) return;
	var output = Json.evaluate(resto);

	frm.addEvent(options.eventType, function() {
		var request = {
			method : 'post',
			prgsMsg : options.msg,
			data : options.params,
			onComplete: function(text) {

				if (options.output)
					$(output.obj).setHTML(text);
/*
don't erase!!!
			        if (options.output) {
//					var tmp = text.match(/<content[^>]*>((\n|\r|\t|.)*?)<\/content>/i);
//					text = $type(tmp) =='array' ? tmp[1] || "" : "";

					if (!text.test(/<result>1<\/result>/i)) {
						if (outputElms.err)
							$(outputElms.err).setHTML(text);
						else
							alert(text);

					} else 
						$(outputElms.obj).setHTML(text);
				}
*/
				if ($type(options.callback) == 'function')
					options.callback(request.data, text);
			}
		}

		ns.submit(frm, request);
	});

	if (options.fireEvent)
		frm.fireEvent(options.eventType);
}