var nsForm = nsBase.extend({

	initialize: function(options)

	{

		this.parent(options);



	},

	initForm : function()

	{

		var felm = $(this.options.formId);

		if (!felm)

		{

			dbug.log("Html form id='%s' не найдена.", this.options.formId);

			return;

		}



		felm.onsubmit = function () {return false;}

		felm.addEvent('submit', function(event) {

			this.onsubmitEvent(event);

		}.bindWithEvent(this));

	},



	show : function () {



		var options = Object.extend({}, this.options['show']);



		var completeFunc = options.onComplete?options.onComplete:0;

		options.onComplete = function (evt)

		{			

			this.initForm();

			if ($type(completeFunc) == 'function')

				completeFunc(evt);

		}.bind(this);



		this.request(options);

	},

	onsubmitEvent : function(evt) {

		this.send(evt.target);

	},

	send : function (frm) 

	{



		var options = Object.extend({}, this.options['send']);



		var completeFunc = options.onComplete?options.onComplete:0;

		options.onComplete = function (xml_result)

		{

			this.sendComplete(xml_result);

			if ($type(completeFunc) == 'function')

				completeFunc(xml_result);

		}.bind(this);

        

		if (!frm)

			frm = $(options.frmId);



		this.submit(frm, options);



		if(this.options.error.update)

			$(this.options.error.update).setHTML('');

	},

	sendComplete : function (text) {

		if (text.test(/<result>1<\/result>/i))

			this.msg(text,'msg');

		else

			this.msg(text,'error');

	},

	msg : function (text, name) {

		var options = Object.extend({}, this.options[name]);

		Object.extend(options.data || {}, { reqXML : text});

		this.request(options);

	}



});



var nsFormExt = nsForm.extend({

	sendComplete : function (text) {

		var content = text.match(/<content[^>]*>((\n|\r|\t|.)*?)<\/content>/i);

		content = $type(content) =='array' ? content[1] || "" : "";



		if (text.test(/<result>1<\/result>/i))

			this.msg(content,'msg');

		else

			this.msg(content,'error');

	},



	msg : function (content, name) {

		var options = this.options[name];

		var elm = $(options.update);

		if ($type(elm) == 'element')

			elm.setHTML(content);

		var completeFunc = options.onComplete ? options.onComplete : 0;

		if ($type(completeFunc) == 'function')

			completeFunc(content);



	}

});

function ShowWindows (vForm, vUrl) {
myWindow=window.open('about:blank','Win1','left=0,top=0,width=400,height=250,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=yes,location=no')
	myWindow.focus();

	document.forms[vForm].action = vUrl;
	document.forms[vForm].target = 'Win1';
	document.forms[vForm].submit();
}