﻿Ext.MessageBox = Ext.apply(Ext.MessageBox, {
	error: function (title, msg, fn, scope) {this.show({
		title: title,
		msg: msg,
		fn: fn,
		scope: scope,
		buttons:this.OK,
		icon: this.ERROR
	})}		
});
Ext.TabsButton = Ext.extend(Ext.Button, {
	ctCls: 'x-btn-over',
	style: 'margin-right:5px'
});


var popin_win_width = 300;
var popin_win_height = 180;

Ext.Msg.Window = Ext.extend(Ext.Window, {
	closable: true,
	width: popin_win_width,
	//height: popin_win_height,
	//border:false,
	plain: true,
	bodyStyle: 'text-align:center',
	modal: true,
	//layout: 'border',
	initComponent:function() {
		Ext.apply(this, {
			items: [ new Ext.Msg.TextArea({}) ]
		});
		Ext.Msg.Window.superclass.initComponent.apply(this, arguments);
	}
});

Ext.Msg.TextArea = Ext.extend(Ext.form.TextField, {
	title: 'Ваше сообщение',
	name: 'textnote',
	type: 'textarea',
	allowBlank: false,
	//fieldLabel: 'Текст вашего сообщение',
	id: 'id_textnote',
	//emptyText  : 'Текст вашего сообщения',
	width: popin_win_width - 18,
	height: popin_win_height - 75
});

Ext.Msg.CancelButton = 
{
	text: 'Отмена',
	handler: function() {
		this.ownerCt.close();
		return false;
	}
}

Ext.Msg.SaveData = function(vars) {  //vars: owner, action, title, success, failure     globals: common_url, _messageid
	if (vars.owner)
		if (Ext.get('id_textnote') == undefined || Ext.get('id_textnote').getValue() == '') {
			Ext.MessageBox.error('Добавление сообщения', 'Сообщение пусто!');
			return false;
		}
	Ext.Ajax.request({
		method: 'GET',
		url: common_url + 'action.php',
		params: {
			action: vars.action,
			messageid: _messageid,
			textnote: Ext.get('id_textnote').getValue(),
			vendorid: Ext.get('id_vendorid').getValue()
		},
		waitMsg: 'Сохранение даных...',
		success: function(response, options) {
			if (vars.owner) Ext.MessageBox.alert(vars.title, vars.success);
			if (vars.owner) vars.owner.close();
			var autoRefresh; if (autoRefresh!=undefined) autoRefresh();
			return false;
		},
		failure: function(response, options) {
			Ext.MessageBox.error(vars.title, vars.failure + response.responseText);
			return;
		}
	})
}

/*Ext.MsgCheckEmpty = function() {
	if (Ext.get('id_textnote') == undefined || Ext.get('id_textnote').getValue() == '') {
		Ext.MessageBox.error('Добавление сообщения', 'Сообщение пусто!');
		return false;
	}
	return true;
}*/
