var xMailSender = function ()
{
	//	PUBLIC VAR
	//	vName			- Control Name
	//	vDataUrl		- select data URL
	//	vError			- Last Error
	//	vControlClassName	- Control Style Class Name

	//	vId				- Control container
	//	vIdElement		- Control container Element
	//	vControlId		- Control ID
	//	vControlElement	- Control Element
	//	vControlLocked	- Control is locked

	this.vPostData		= [];

	this.tLoading = 'Loading data...';
	this.vControlClassName = 'xmails_';
	this.vShowLoading = false;
	this.vTextPrefix = '';
	this.vTextSuffix = '';
	this.vEmptyId = 0;
	this.vBoxWidth = 400;
	this.vBoxHeight = 300;
	this.vClosePic = '/images/closeb.gif';

	this.tUserTo = 'Mail to:';
	this.tTitle = 'Create New Mail';
	this.tSubject = 'Subject:';
	this.tSend = 'Send';
	this.tBody = '';

	this.vControlLoadingElement = null;
}

xMailSender.prototype = new xAjax;

xMailSender.prototype.fError = function ()
{
	alert('Class xText Error: ' + this.vError);
}

xMailSender.prototype.fInit = function ()
{
	if (!this.vDataUrl)
	{
		this.vError = 'vDataUrl is empty!';
		this.fError();
		return;
	}
}

xMailSender.prototype.fLockControl = function ()
{
	this.vControlLocked = true;
}

xMailSender.prototype.fCleanContent = function ()
{
	if (this.vControlElement)
	{
		this.vControlElement.parentNode.removeChild(this.vControlElement);
		this.vControlElement = null;
	}

	if (this.vControlLoadingElement)
	{
		this.vControlLoadingElement.parentNode.removeChild(this.vControlLoadingElement);
		this.vControlLoadingElement = null;
	}
}

xMailSender.prototype.fShow = function ()
{
	this.onShow();

	this.disabled = false;
	this.vControlLocked = false;
	this.fCleanContent();

	var tTable, tTBoby, tTr, tTd, tText, tInput, tTextArea, tDiv, tImg;

	var p = this;

	tTable = $$('TABLE');
	tTable.className = this.vControlClassName + 'tab';
	tTable.style.position = 'absolute';
	tTable.style.width = this.vBoxWidth + 'px';
	tTable.style.heigth = this.vBoxHeight + 'px';
	tTable.style.top = parseInt(document.body.clientHeight / 2 - this.vBoxHeight/2 + document.body.scrollTop) + 'px';
	tTable.style.left = parseInt(document.body.clientWidth / 2 - this.vBoxWidth/2 + document.body.scrollLeft) + 'px';
	tTBoby = $$('TBODY');

	tTr = $$('TR');
	tTd = $$('TD');
	tTd.className = this.vControlClassName + 'td_title';
	tTd.colSpan = 2;
	tDiv = $$('DIV');
	tDiv.className = this.vControlClassName + 'title';
	tText = document.createTextNode(this.tTitle);
	tDiv.appendChild(tText);
	tTd.appendChild(tDiv);
	tDiv = $$('DIV');
	tDiv.className = this.vControlClassName + 'closeb';
	tImg = $$('IMG');
	tImg.src = this.vClosePic;
	tImg.onclick = function ()
	{
		p.fCleanContent();
	}
	tDiv.appendChild(tImg);
	tTd.appendChild(tDiv);
	tTr.appendChild(tTd);
	tTBoby.appendChild(tTr);

	tTr = $$('TR');
	tTd = $$('TD');
	tTd.className = this.vControlClassName + 'td_text';
	tText = document.createTextNode(this.tUserTo);
	tTd.appendChild(tText);
	tTr.appendChild(tTd);
	tTd = $$('TD');
	tTd.className = this.vControlClassName + 'td_input';
	tInput = $$('INPUT');
	tInput.className = this.vControlClassName + 'input';
	if (this.vUserTo)
		tInput.value = this.vUserTo;
	if (this.vNoEditUserTo)
		tInput.disabled = true;
	else
	{
		this.oHelper = new xHelper;
		this.oHelper.vElementId = tInput;
		this.oHelper.vDataUrl = '/dynamic/user/user/helper_user_list.ajax';
		this.oHelper.fInit();
	}
	
	this.oUserTo = tInput;
	tTd.appendChild(tInput);
	tTr.appendChild(tTd);
	tTBoby.appendChild(tTr);

	tTr = $$('TR');
	tTd = $$('TD');
	tTd.className = this.vControlClassName + 'td_text';
	tText = document.createTextNode(this.tSubject);
	tTd.appendChild(tText);
	tTr.appendChild(tTd);
	tTd = $$('TD');
	tTd.className = this.vControlClassName + 'td_input';
	tInput = $$('INPUT');
	this.oSubject = tInput;
	tInput.className = this.vControlClassName + 'input';
	tTd.appendChild(tInput);
	tTr.appendChild(tTd);
	tTBoby.appendChild(tTr);

	if (this.tBody)
	{
		tTr = $$('TR');
		tTd = $$('TD');
		tTd.className = this.vControlClassName + 'td_text';
		tTd.colSpan = 2;
		tText = document.createTextNode(this.tBody);
		tTd.appendChild(tText);
		tTr.appendChild(tTd);
		tTBoby.appendChild(tTr);
	}

	tTr = $$('TR');
	tTd = $$('TD');
	tTd.colSpan = 2;
	tTd.className = this.vControlClassName + 'td_input';
	tTextArea = $$('TEXTAREA');
	this.oBody = tTextArea;
	tTextArea.className = this.vControlClassName + 'body';
	tTd.appendChild(tTextArea);
	tTr.appendChild(tTd);
	tTBoby.appendChild(tTr);

	tTr = $$('TR');
	tTd = $$('TD');
	tTd.colSpan = 2;
	tTd.className = this.vControlClassName + 'td_control';
	tInput = $$('INPUT');
	tInput.type = "button";
	tInput.className = 'button';
	tInput.value = this.tSend;
	this.oSend = tInput;
	tInput.onclick = function ()
	{
		if (p.oUserTo.value == '')
		{
			alert('You need fill field `Mail To`!');
		}
		else
		{
			p.vPostData['to'] = p.oUserTo.value;
			p.vPostData['subj'] = p.oSubject.value;
			p.vPostData['body'] = p.oBody.value;
			p.AJAXPostData(p.vDataUrl, p.vPostData);
			this.disabled = true;
		}
	}
	tTd.appendChild(tInput);
	tTr.appendChild(tTd);
	tTBoby.appendChild(tTr);

	tTable.appendChild(tTBoby);

	document.body.appendChild(tTable);
	this.vControlElement = tTable;

	this.onShowEnd();
}

xMailSender.prototype.aOnExec = function()
{
	if (arguments[0] == 'error')
	{
		alert(this.vError);
		this.oSend.disabled = false;
	}
	else
		this.fCleanContent();
}

xMailSender.prototype.onShow = function()
{
	//
}

xMailSender.prototype.onShowEnd = function()
{
	//
}
