/**
 * In The Name of Allah, The Most Gracious, The Most Merciful
 * Optimization Tag: optimized to here
 */
var FileEquivalentsForAnObject = new Array(),
	DragableLayers = new Array();

//------------------------------------------
function FormLoading(v) {
	var SSD, Table, Save, f//, Scripts,

	!v && SetScreen();

	if (typeof (SSD = GBCG('SetSelectedData', 'function')) == 'function'){
		SSD();
	}
	if ((Table = $("tblTable")) && Table.dir) {
		if (Table.dir == "rtl") {
			SetDirection("rtl");
			if (document.title == "") {
				document.title = "سيستم مديريت محتواي پروانه";
			}
		}
		else if (Table.dir == "ltr")
		{
			SetDirection("ltr");
			if (document.title == "") {
				document.title = "Butterfly CMS";
			}
		}
	}
	if (Save = $("btnSave")) {
		if (Save.onclick == null) {
			Save.onclick = FormSubmit;
		}
	}

	if (typeof (f = GBCG('FormLoading_', 'function')) == 'function' && f !== $empty) {
		f();
	}
}
//------------------------------------------
function FormSubmit(FormID, Options) {
	var Form, $Form, A;
	Options = Options || {};

	Form = document.GetInfo ? document.GetInfo() : (A = GBCG('GetInfo', 'function'))();

	if (typeof Form == 'string' && Form == 'unsavedtableexist') {
		alert(W_WARNING_SAVE_ROW);
		return false;
	}
	if (!Form) {
		Form = FormID || document.forms[0]; // Form = FormID ? FormID : document.forms[0];
	}

	if (FormValidate(Form)) {
		$Form = $(Options.form = Form.id);
		if (Options.Group) {
			$Form.action = PrepareUrl({'Address': $Form.action, 'Options': {'Parameters': [{'Parameter': 'Group','Value': Options.Group}]}});
		}
		FormSubmit2(Options);
	}
}

function FormSubmit2(oOptions) {
	oOptions = oOptions || {};
	if (!oOptions.form)
		return false;

	var oForm = $(oOptions.form);
	oForm.action += oOptions.SubmitMode ? '&Mode=' + oOptions.SubmitMode : '';

	if(fE = $('_systemRequestType') || $('_systemRequestionType')) {
		switch(fE.value) {
			case 'AJAX':
				var fE = oForm.getElementById('_systemResponseType');
				if(fE) {
					FreezeFrame(GetWaitingFor());
//					FreezeFrame();
					switch(oOptions.responseType || fE.value) {
						case 'JSON':
							AfterSave = typeof AfterSave != 'undefined' ? AfterSave : function () {};
							new Request.JSON({url: oForm.action, method: oForm.method, 'onSuccess': oOptions.AfterSuccessSubmitHandler || AfterSave}).send(oForm);
							break;
						case 'HTML':
							new Request.HTML({url: oForm.action, method: oForm.method, 'onComplete': oOptions.AfterSuccessSubmitHandler || PageLoader, evalScripts: false}).send(oForm);
							break;
						default:
							alert('Your Request For Undefined Response Handler Can\'t be done!');
					}
				}
				break;
			case 'NORMAL':
			case 'RESPONSE_BACK':
				oForm.submit();
				break;
		}
	} else {
		oForm.submit();
	}
}

function AfterSave(JSONObject, JSONText) {
/*
	if (JSONObject.Messages) {
		var MessagesHolder = $('MessageHolder');
		MessagesHolder.innerHTML = '';
		var Messages = JSONObject.Messages;
		for(var i = 0; i < Messages.length; i++) {
			if (MessagesHolder) {
				MessagesHolder.innerHTML += '<p>' + Messages[i] + '</p>';
			} else {
				alert(Messages[i]);
			}
		}
	}
*/
	alert(JSONObject.FinalMessage);
	if (JSONObject.Status == 'true') {
		//$(window.document.getElementsByTagName('body')[0]).get('load', {url: JSONObject.ReferTo, method: 'get', evalScripts: true}).send();
		new Request.HTML({url: JSONObject.ReferTo, method: 'get', 'onSuccess': PageLoader, evalScripts: false}).send();
		return;
	}
	DefrostFrame();
}

function AddToListFromList(L1, L2)/*Lists*/
{
	L1 = $(L1); L2 = $(L2);

	for (var i = 0; i < L1.length; i++) {
		if (L1[i].selected) {
			var mView = L1[i].text, mValue = L1[i].value;
			//------------------------------------------
			if (!IsInList(mValue, L2)) {
				(L2.options[L2.options.length] = new Option(mView, mValue)).title = mView;
			} else {
				alert(mView + ' ' + W_WARNING_SELECTED);
			}
			//------------------------------------------
		}
	}
}
//------------------------------------------
function addToList(mView, mValue, L/*List*/)
{
	L = $(L);

	if (!IsInList(mValue, L)) {
		var i;
		(L.options[i = L.options.length] = new Option(mView, mValue)).title = mView;
		return L.options[i];
//		L.options[n].title = mView;
	} else {
		alert(mView + ' ' + W_WARNING_SELECTED);
		return false;
	}
}
//------------------------------------------
function ReturnToList(L2, L1)/*Lists*/ {
	L1 = $(L1);
	L2 = $(L2);

	for (var i = 0; i < L2.length; i++) {
		if (L2[i].selected) {
			for (var j = 0; j < L1.length; j++) {
				if (L1[j].value == L2[i].value) {
					$(L1[j]).setStyle('color', '#000000');
				}
			}
		}
	}
	//----------------------
	DeleteFromList(L2);
}
//------------------------------------------
function DeleteFromList(L) { //List
	L = $(L);

	for (var i = 0; i < L.length; ) {
		if (L[i++].selected) {
			L.removeChild(L[--i]);
		}
	}
}
//------------------------------------------
function RemoveFromList(L) { //List
	L = $(L);

	for (var i = -1; i < L.length - 1; $(L[++i]).selected && ($(L[i]).setStyle('color', '#BBBBBB').selected = false));
}
//------------------------------------------
function deactiveAnElementFromList(mValue, L) {
	L = $(L);
	var Index;
	if (Index = IsInList(mValue, L)) {
		$(L[Index - 1]).setStyle('color', '#BBBBBB').selected = false;
	}
}
//------------------------------------------
function SelectAllList(L) {
	L = $(L);

	for (var i = 0; i < L.length; $(L[i++]).selected = true);
}
//------------------------------------------
function DeselectAllList(L) {
	L = $(L);

	for (var i = 0; i < L.length; $(L[i++]).selected = false);
}
//------------------------------------------
function MoveToList(L1, L2) {
	AddToListFromList(L1, L2);
	DeleteFromList(L1);
}
//------------------------------------------
function CopyToList(L1, L2) {
	AddToListFromList(L1, L2);
	RemoveFromList(L1);
}
//------------------------------------------
function IsInList(mValue, L) {
	L = $(L);

	for(var i = 0; i < L.length;) {
		if (mValue == L[i++].value) {
			return i;
		}
	}
	return false;
}
//------------------------------------------
function IsInTable(mValue, T) {
	T = $(T);

	for (var i = 0; i < T.rows.length;) {
		if (mValue == T.rows[i++].id) {
			return true;
		}
	}
	return false;
}
//------------------------------------------
function EmptyTable(T, TT) {//TableType
	T = $(T);
	switch(trim(TT).toLowerCase()) {
		case 'dynamic':
			for (var i = T.rows.length - 1; i > 0; T.deleteRow(i--)) {
				T.deleteRow(i);
			}
			return true;
		case 'static':
			alert(W_THIS_FUNCTION_IS_NOT_AVAILABLE);
			return true;
	}
	return false;
}
//------------------------------------------
function AddToTable(L, T) {
	L = $(L);
	T = $(T);

	for (var i = 0, oTR, oTD, mValue, mView; i < L.length; i++) {
		if (L[i].selected) {
			mValue = L[i].value;
			mView = L[i].text;
			//------------------------------------------
			if (!IsInTable(mValue, T)) {
				(oTR = $(T.insertRow(-1)).addClass("TableListClass").setStyle("height", "20")).id = mValue;
				oTD = new Element("td", {"class": "TableListClass"}).inject(oTR);
				new Element("input", {type: "checkbox"}).inject(oTD);

				new Element("td", {"class": "TableListClass"}).inject(oTR).innerHTML = T.rows.length - 1;

				if (T.rows[0].cells.length == 4) {
					new Element("td", {"class": "TableListClass"}).inject(oTR).innerHTML = getParent("cmb" + L.id.substr(3), mValue);
				}

				new Element("td", {"class": "TableListClass"}).inject(oTR).innerHTML = mView;
			} else {
				alert(mView + W_WARNING_SELECTED);
			}
			//------------------------------------------
		}
	}
	//-----------------------
	RemoveFromList(L);
}
//------------------------------------------
function DeleteFromTable(T) {
	T = $(T);

	for (var i = 0; i < T.rows.length; ) {
		if ($(T.rows[i++].cells[0]).getFirst().checked) {
			T.deleteRow(--i);
		}
	}
}
//------------------------------------------
function SelectAllTable(T) {
	T = $(T);

	for (var i = 0; i < T.rows.length; $(T.rows[i++].cells[0]).getFirst().checked = true);
	return true;
}
//------------------------------------------
function DeselectAllTable(T)
{
	T = $(T);

	for (var i = 0; i < T.rows.length; $(T.rows[i++].cells[0]).getFirst().checked = false);
	return true;
}
//------------------------------------------
function Select_Deselect(T, Evt)
{
	T = $(T);

	if (new Event(Evt).target.checked) {
		SelectAllTable(T);
	} else {
		DeselectAllTable(T);
	}
	return true;
}
//------------------------------------------
function DataSetting(C, L) {// Combo, List
	C = $(C);
	L = $(L);

	for (var i = 0; i < L.length; L.removeChild(L[i]));
	//------------------------------------------
	var DataArray = GBCG("DataArray_" + C.id, 'var');
	for (var i = 0, D, mView; i < DataArray.length; ) {
		D = DataArray[i++];
		if (D.Parent == C.value) {
			//------------------------------------------
			(L.options[L.options.length] = new Option(mView = D.View, D.Value)).title = mView;
			//------------------------------------------
		}
	}
	return true;
}
//------------------------------------------
function DataSetting_DL_MS_MP(C, L) {
	DataSetting($(C), $(L));
	return true;
}
//------------------------------------------
function DataSetting3(C, L1, L2) {
	DataSetting($(C), $(L1));
	SelectAllList(L2 = $(L2));
	DeleteFromList(L2);
	return true;
}
//------------------------------------------
function IsSavedTable(T) {
	T = $(typeof T == 'string' && T.substr(0,3) != 'tbl' ? 'tbl' + T : T);

	for (var i = 0; i < T.rows.length; i++)
		if (T.rows[i].mode == "NEW" || T.rows[i].mode == "EDIT")
			return false;

	return true;
}
//------------------------------------------
function AddTableRow(TableID)
{
	var Table, TRow, oTR, oTD, tr, Fields, TableObject, ele,
	Data_, Error = false, NonEditableContent;

	TableObject = GetTableSpec(TableID = $(TableID));

	if (IsSavedTable(TableID)) {
		//------------------------------------------
		Fields = GBCG('Fields_' + TableID.id, 'var');

		oTR = $(TableID.insertRow(TableObject.StartRowAt)).addClass("TableClass");
		oTR.mode = 'NEW';
		TR = oTR;
		if (TableObject.RowsCheckable) {
			oTD = new Element("td", {"class": "TableClass"});
			new Element("img", {src: "../images/icon-delete.gif", title: W_DELETE}).setStyle('cursor', 'pointer').addEvent('click', DeleteTableRow).inject(oTD);
			oTD.inject(oTR);
		}

		if (TableObject.Arrangable)
		{
			oTD = new Element("td", {"class": "TableClass"});
			new Element("img", {src: "../images/up.gif", title: W_UP, direction: -1, id: 1}).setStyle('cursor', 'pointer').addEvent('click', MoveTableRow).inject(oTD);
			new Element("br").inject(oTD)
			new Element("img", {src: "../images/dn.gif", title: W_DOWN, direction: +1}).setStyle('cursor', 'pointer').addEvent('click', MoveTableRow).inject(oTD);
			oTD.inject(oTR);
		}

		if (TableObject.RowsEditable) {
			oTD = new Element("td", {"class": "TableClass"});
			new Element("input", {type: "Button", value: W_SAVE, "class": "ButtonClass"}).addEvent('click', SaveTableRow).inject(oTD);
			oTD.inject(oTR);
		}
		//------------------------------------------
		for (var i = 0; i < Fields.length; i++) {
			oTD = new Element("td", {"class": "TableClass"});

			if (!Fields[i] || !Fields[i].Type || Fields[i].Type != 'NonEditableContent')
			{
				var Data = Fields[i].Data.concat(), ii;
				if (Data) {
					if (Fields[i].Type == 'USE_ONCE')
					{
						
						for(tr = 0; tr<TableID.rows.length;tr++)
						{
							TRow = TableID.rows[tr];

							if (TRow.rowIndex == TR.rowIndex)
								continue;

							if ((!TRow.EditableRow && tr > 0) || TRow.EditableRow == 'true')
								for(ii = 0; ii < Data.length; ii++)
									if (Data[ii] && TRow.cells[i + TableObject.StartContentDataAt].id == Data[ii].Value)
										delete Data[ii];
						}
					}
					if (typeof Data == 'object')
					{
						Data_ = new Array();
						for(ii = 0; ii < Data.length; ii++)
							if (Data[ii])
								Data_[Data_.length] = Data[ii];

						Data = Data_;
					}
				}
				NonEditableContent = Fields[i].Type == 'NonEditableContent';
	
				if(Fields[i].Content)
					oTD.set('html', TD.Content = Fields[i].Content).set('id', '');
				else if (Data) {
					ele = new Element("select", {"class": "TableClass"});
					for (var j = 0; j < Data.length; j++) {
						ele.options[j] = $(new Option(View = Data[j].View, Data[j].Value)).set('title', View);
						if (NonEditableContent)
							ele.options[j].set('readOnly', NonEditableContent)
					}

					if (Data.length == 1 && Data[0].View == "") {
						oTD.setStyle('width', "0%");
						ele.set("class", "").setStyles({
							width: 0,
							visibility: 'hidden'
						});
					} else if (Data.length == 0) 
						Error = true;

				} else if (Fields[i].Type == 'DATE') {
					oTD.setStyle('direction', "ltr");
					ele = new Element("input", {type: "text", "class": "TableClass"}).setStyle('direction', 'ltr').addEvent('focus', DoOnDateEnter);
					if (NonEditableContent)
						ele.set('readOnly', NonEditableContent)
				} else {
					ele = new Element("input", {type: "text", "class": "TableClass"});
					if (NonEditableContent)
						ele.set('readOnly', NonEditableContent)
				}

				if (ele)
					oTD.grab(ele);
			}
			TR.grab(oTD);
		}
		//------------------------------------------
		if (Error) {
			TableID.deleteRow(TR.rowIndex);
			alert(W_NO_ENOUGH_INFORMATION_FOR_SHOWING_ROW);
		}
	}
	else alert(W_WARNING_SAVE_ROW);
}

function DoOnDateChange(Evt) {
	//optimized to here
	var Evt = new Event(Evt);
	var CE = Evt.target;
	var currentText = CE.value;
	var newText = '';

	var code = Evt.code;
	currentText = currentText.clear();
	var DateForm = /^[1-9*]{1}[0-9*]{3}\/(([0]{1}[1-9*]{1})|([1*]{1}[0-2*]{1}))\/(([0-2*]{1}[0-9*]{1})|([3]{1}[0-1*]{1}))$/ ;
	if (code == 9) {
		return true;
	}
	Evt.preventDefault();
//	Evt.returnValue = false;
	if (DateForm.test(currentText))
	{
		if (code == 8)
		{
			// Backspace
			AsterikPosition = -1;
			if (AsterikPosition = currentText.indexOf('*'))
			{
				if (AsterikPosition== -1)
				{
					AsterikPosition = currentText.length;
				}
				AsterikPosition--;
				if (AsterikPosition == 4 || AsterikPosition == 7)
				{
					AsterikPosition--;
				}
				newText = currentText.replaceCharAt(AsterikPosition , '*')
			}
		}
		else
		{
			if (code < 106 && code > 95)
			{
				code -= 96;
			}
			else if (code < 58 && code > 47)
			{
				code -= 48;
			}
			else
			{
				return false;
			}
			if (!(code > 9 || code < 0))
			{
				// For Checking The Validation of Characters is Not Out Numeric Range!
				newText = currentText.replace(/\*/ , String.fromCharCode(code + 48))
			}
			else
			{
				
			}
		}
		if (!DateForm.test(newText))
		{
			newText = currentText;
		}
		CE.value = newText;
		return false;
	}
	else
	{
		if (confirm(W_DATE_FORMAT_IS_INCORRECT + ', ' + W_DO_YOU_WANT_CORRECT_THAT))
		{
			CE.value = '****/**/**';
		}
	}
	return false;
}

function DoOnDateEnter(Evt)
{
	var CE = (new Event(Evt)).target;
	
	CE.removeEvent('keydown', DoOnDateChange);
	CE.addEvent('keydown', DoOnDateChange);

	CE.removeEvent('blur', DoOnDateExit); 
	CE.addEvent('blur', DoOnDateExit); 
	
	var DateDefaultValue = '****/**/**';

	CE.value = CE.value.clear();
	var DateForm = /^[1-9]{1}[0-9]{3}\/(([0]{1}[1-9]{1})|([1]{1}[0-2]{1}))\/(([0-2]{1}[0-9]{1})|([3]{1}[0-1]{1}))$/ ;
	if (!DateForm.test(CE.value))
	{
		CE.value = DateDefaultValue;
	}

	return true;
}

function DoOnDateExit(Evt)
{
	var CE = (new Event(Evt)).target;
	CE.value = CE.value.clear();

	var DateForm = /^[1-9]{1}[0-9]{3}\/(([0]{1}[1-9]{1})|([1]{1}[0-2]{1}))\/(([0-2]{1}[0-9]{1})|([3]{1}[0-1]{1}))$/ ;
	if (!DateForm.test(CE.value))
	{
		CE.value = '';
	}

	return true;
}

//------------------------------------------
function SaveTableRow(Evt, Row)  //cross - browser
{
	var Fields, Table, TBody, TR, TD, Cell, TableObject,
	c, ValidationStatus,
	IsEmpty = false, Warning = "", NotValid = "", NotValidWithAlert = "", NotValidForForce = "", NotValidForForceWithAlert = "";

	if (typeof Evt == 'undefined' && Evt == null && typeof Row == 'object')
	{
		TR = Row;
	}
	else
	{
		var Evt = new Event(Evt);
		var fE = Evt.target;

		TD = fE.parentNode;
		TR = TD.parentNode;
	}

	TBody = TR.parentNode;

	if(TBody.tagName.toLowerCase() == "table")
	{
		Table = TBody;
	}
	else
	{
		Table = TBody.parentNode;
	}
	TableObject = GetTableSpec(Table);
	
	c = TableObject.StartContentDataAt;

	Fields = GBCG("Fields_" + Table.id, 'var');

	//------------------------------------------
	for (var i = 0, CellFirstChild, CellInnerHtml, CFCT, si; i < TR.cells.length; i++)
	{
		Cell = $(TR.cells[i]);

		if ((!Cell.NotEditable || trim(Cell.NotEditable.toLowerCase()) != 'noteditable') && (!Fields[i - c] || !Fields[i - c].Type || Fields[i - c].Type != 'NonEditableContent'))
		{
			CellFirstChild = Cell.getFirst();
			if (CellFirstChild)
			{
				CFCT = CellFirstChild.tagName;
				ActAs = '';
				if ($defined(Fields[i - c]))
				{
					if ($defined(Fields[i - c].Interface))
					{
						ActAs = Fields[i - c].Interface;
					}
					else
					{
						if (CellFirstChild.tagName == "SELECT")
						{
							ActAs = 'ComboBox';
						}
						else if (CellFirstChild.tagName == "INPUT")
						{
							ActAs = 'TextEditor';
						}
					}
					if (Fields[i - c].Content)
					{
						ActAs = 'Custom';
						//Cell.innerHTML = Cell.View || '';
					}
				}
				else
				{
					if (Cell.getFirst().type == "button")
					{
						ActAs = 'SaveButton';
					}
					else if (CellFirstChild.type != "checkbox" && i == 0)
					{
						ActAs = 'DeleteImg';
					}
				}

				switch(ActAs)
				{
					case 'Custom':
						Cell.innerHTML = Cell.View || '';
						break;
					case 'ComboBox':
						if (CFCT == "SELECT" && (si = CellFirstChild.selectedIndex) > -1)
						{
							Cell.id = CellFirstChild.options[si].value;
							Cell.set('html', CellFirstChild.options[si].text);
						}
						break;
					case 'TextEditor':
					case 'DateEditor':
						if (CFCT == "INPUT")
						{
							CellInnerHtml = Cell.get('html');
							Cell.set('html', CellInnerHtml = trim(CellFirstChild.value));

							if ((ValidationStatus = Validate(CellInnerHtml, Fields[i - c].Type, Fields[i - c].Force)) > 0)
							{
							}
							else
							{
								if (ValidationStatus === -2)
								{
									if (Fields[i - c].ForceAlert && Fields[i - c].ForceAlert != '')
									{
										NotValidForForceWithAlert += Fields[i - c].ForceAlert + '\n';
									}
									else
									{
										NotValidForForce += (i - c + 1) + " و ";
									}
								}
								else if (ValidationStatus === -1)
								{
									if (Fields[i - c].ValidationAlert && Fields[i - c].ValidationAlert != '')
									{
										NotValidWithAlert += Fields[i - c].ValidationAlert + '\n';
									}
									else
									{
										NotValid += (i - c + 1) + " و ";
									}
								}
							}
						}
						break;
					case 'SaveButton':
						CellFirstChild.value = W_EDIT;
						$(CellFirstChild).removeEvents().addEvent('click', EditTableRow)
						break;
					case 'DeleteImg':
						Cell.removeChild(CellFirstChild);
						var fE = new Element("input");
						fE.type = "checkbox";
						Cell.grab(fE);
						break;
				}
			}
		}
	}
	//------------------------------------------
	if (TR.mode == "NEW" || TR.mode == "EDIT")
	{
		TR.mode = "SAVED";
	}
	TR.className = "TableClass";
	//------------------------------------------
	if (IsEmpty)
	{
		alert(W_WARNING_NO_DATA);
		var TRF = $(TR.cells[0]).getFirst();
		TRF.checked = true;
		DeleteFromTable(Table);
	}
	if (NotValidForForce != "" || NotValidForForceWithAlert != "")
	{
		Warning = NotValidForForceWithAlert;
		if (!(NotValidForForce = NotValidForForce.substr(0, NotValidForForce.length - 3)))
		{
			Warning = Warning.substr(0, Warning.length - 1);
		}
		else
		{
			Warning += W_WARNING_NOT_VALID_FOR_FORCE_1 + ' ' + NotValidForForce + ' ' + W_WARNING_NOT_VALID_FOR_FORCE_2;
		}
	}
	if (NotValid != "" || NotValidWithAlert != "")
	{
		Warning = NotValidWithAlert;
		if (!(NotValid = NotValid.substr(0, NotValid.length - 3)))
		{
			Warning = Warning.substr(0, Warning.length - 1);
		}
		else
		{
			Warning += W_WARNING_NOT_VALID_1 + ' ' + NotValid + ' ' + W_WARNING_NOT_VALID_2;
		}
	}
	if (Warning)
	{
		alert(Warning);
		EditTableRow(null, TR)
	}
	//------------------------------------------
}
//------------------------------------------
function EditTableRow(Evt, Row)  //cross - browser
{
	var Fields, Table, TBody, TR, TRow, TD, Cell, TableObject,
	tr, c, ValidationStatus, NoEditableContent, Data_, View, Value, j;

	if (typeof Evt != 'undefined' && Evt == null && typeof Row == 'object')
	{
		TR = Row;
	}
	else
	{
		var Evt = new Event(Evt);
		var fE = Evt.target;
		TD = fE.parentNode;
		TR = TD.parentNode;
	}

	TBody = TR.parentNode;

	if(TBody.tagName.toLowerCase() == "table")
	{
		Table = TBody;
	}
	else
	{
		Table = TBody.parentNode;
	}

	TableObject = GetTableSpec(Table);

	var c = TableObject.StartContentDataAt, ActAs;

	Fields = GBCG("Fields_" + Table.id, 'var');

	if (IsSavedTable(Table))
	{
		for (var i = 0, fE; i < TR.cells.length; i++)
		{
			if(!Fields[i - c] || !Fields[i - c].Type || Fields[i - c].Type != 'NonEditableContent')
			{
				NonEditableContent = false;
				Cell = $(TR.cells[i]);
				if ($defined(Fields[i - c]) && $defined(Fields[i - c].Interface))
				{
					ActAs = Fields[i - c].Interface;
				}
				else
				{
					ActAs = '';
					if (!Cell.getFirst())
					{
						if (Fields[i - c].Content)
						{
							ActAs = 'Custom';
						}
						else if (!Cell.id)
						{
							if (Fields[i - c].Type == 'DATE')
							{
								ActAs = 'DateEditor';
							}
							else
							{
								ActAs = 'TextEditor';
							}
						}
						else
						{
							if (Cell.get('html') != "")
							{
								ActAs = 'ComboBox';
							}
							else
							{
								ActAs = 'NonEditable';
							}
						}
					}
					else if (!Cell.getFirst().tagName)
					{
						if (Cell.id)
						{
							ActAs = 'ComboBox';
						}
						else if (Fields[i - c].Type == 'DATE')
						{
							ActAs = 'DateEditor';
						}
						else
						{
							ActAs = 'TextEditor';
						}
					}
					else if (Cell.getFirst().type == "button")
					{
						ActAs = 'EditButton';
					}
				}

				if ($defined(Fields[i - c])) {

					if ((ActAs == 'ComboBox') || ActAs == 'Custom')
					{
						var Data = Fields[i - c].Data.concat(), ii;
						if (Fields[i - c].Type == 'USE_ONCE')
						{
							for(tr = 0; tr<Table.rows.length;tr++)
							{
								TRow = Table.rows[tr];
								if (TRow.rowIndex == TR.rowIndex)
								{
									continue;
								}
								if ((!TRow.EditableRow && tr > 0) || TRow.EditableRow == 'true')
								{
									for(ii = 0; ii < Data.length; ii++)
									{
										if (Data[ii] && TRow.cells[i].id == Data[ii].Value)
										{
											delete Data[ii];
										}
									}
								}
							}
						}
						if (typeof Data == 'object')
						{
							Data_ = new Array();
							for(ii = 0; ii < Data.length; ii++)
							{
								if (Data[ii])
								{
									Data_[Data_.length] = Data[ii];
								}
							}
							Data = Data_;
						}
					}
				}
				if ((!Cell.NotEditable || trim(Cell.NotEditable.toLowerCase()) != 'noteditable') && (!Cell.NonEditable || trim(Cell.NonEditable.toLowerCase()) != 'noneditable'))
				{
					fE = '';
					if (ActAs == 'Custom'/*Fields[i - c].Content*/)
					{
						Cell.View = Cell.View || Cell.innerHTML || '';
						Cell.innerHTML = Cell.View + (Cell.Content = Fields[i - c].Content);
					}
					else if (ActAs == 'DateEditor'/*!Cell.id*/)
					{
						Cell.dir = 'ltr';
						fE = new Element("input");
						fE.type = "text";
						fE.onfocus = DoOnDateEnter;
						fE.addClass("TableClass");
						fE.dir = "ltr";
						fE.readOnly = NonEditableContent;

						var InnerHTML = Cell.get('html');
						fE.value = InnerHTML;

						Cell.set('html', "");
						Cell.grab(fE);
					}
					else if (ActAs == 'TextEditor'/*!Cell.id*/)
					{
						fE = new Element("input");
						fE.type = "text";
						fE.className = "TableClass";
						fE.readOnly = NonEditableContent;
						var InnerHTML = Cell.get('html');
						fE.value = InnerHTML;
						Cell.set('html', "");
						Cell.grab(fE);
					}
					else if (ActAs == 'ComboBox'/*!Cell.id*/)
					{
						fE = new Element("select");
						fE.className = "TableClass";
						for (j = 0; j < Data.length; j++)	// !!! ???
						{
							View = Data[j].View;
							Value = Data[j].Value;
							fE.options[j] = new Option(View, Value);
							fE.options[j].title = View;
						}
						fE.readOnly = NonEditableContent;
						fE.value = Cell.id;
						Cell.set('html', "");
						Cell.grab(fE);
					}
 					else if (ActAs == 'EditButton'/*!Cell.id*/)
					{
						var FirstChild = Cell.getFirst();
						FirstChild.value = W_SAVE;
						$(FirstChild).onclick = '';
						$(FirstChild).removeEvents().addEvent('click', SaveTableRow);
					}
					if (fE && Fields[i - c].Listeners && Fields[i - c].Listeners.length)
					{
						for (j = 0; j < Fields[i - c].Listeners.length; j++)	// !!! ???
						{
							fE.addEvent(Fields[i - c].Listeners[j].Event, Fields[i - c].Listeners[j].Listener);
						}
					}
				}
			}
		}
		//------------------------------------------
		if (!TR.mode)
			TR.mode = 'EDIT';
		if (TR.mode == "SAVED")
		{
			TR.mode = "EDIT";
		}

		TR.className = "TableClass";
		//------------------------------------------
	}
	else
	{
		alert(W_WARNING_SAVE_ROW);
	}
}
//------------------------------------------
function AddSaveTableRow(Evt)
{
	var Evt = new Event(Evt);
	var fE = Evt.target, Table, TBody, TR, TD, Fields, TableObject,
	ValidationStaus, IsEmpty = false, tmp_,
	Warning = "", NotValid = "", NotValidWithAlert = "", NotValidForForce = "", NotValidForForceWithAlert = "";

	TD = fE.parentNode;
	TRow = TD.parentNode;

	TBody = TRow.parentNode;

	if(TBody.tagName.toLowerCase() == "table")
	{
		Table = TBody;
	}
	else
	{
		Table = TBody.parentNode;
	}

	TableObject = GetTableSpec(Table);

	Fields = GBCG("Fields_" + Table.id, 'var');

	if (IsSavedTable(Table))
	{
		//------------------------------------------
		TR = $(Table.insertRow(-1));
		TR.className = "TableClass";
		TR.mode = "SAVED";

		if (TableObject.RowsCheckable)
		{	
			TD = new Element('td');
			TD.className = "TableClass";
				var fE = new Element("input");
				fE.type = "checkbox";
			TD.grab(fE);
			TR.grab(TD);
		}

		if (TableObject.Arrangable)
		{
			TD = new Element("td");
			TD.className = "TableClass";
				var fE = new Element("img");
				fE.src = "../images/up.gif";
				fE.title = W_UP;
				fE.direction = -1;
				fE.onclick = MoveTableRow;
				fE.style.cursor = "pointer";
				fE.id = "1";
			TD.grab(fE);
			new Element("br").inject(TD);
			new Element("br").inject(TD)

			var fE = new Element("img");
				fE.src = "../images/dn.gif";
				fE.title = W_DOWN;
				fE.direction = +1;
				fE.onclick = MoveTableRow;
				fE.style.cursor = "pointer";
			TD.grab(fE);
			TR.grab(TD);
		}

		if (TableObject.RowsEditable)
		{
			TD = new Element('td');
			TD.className = "TableClass";
				var fE = new Element("input");
				fE.type = "button";
				fE.value = W_EDIT;
				fE.className = "ButtonClass";
				$(fE).addEvent('click', EditTableRow)
			TD.grab(fE);
			TR.grab(TD);
		}

		//TD.innerHTML = TableID.rows.length - 1;

		//------------------------------------------
		for (var i = 0, CountedFields = 0, t; i < TRow.cells.length;i++, CountedFields++)
		{
			if ($(TRow.cells[i]).getFirst().tagName)
			{
				if ((t = $(TRow.cells[i]).getFirst().tagName) == "SELECT")
				{
					TD = new Element('td');
					TD.className = "TableClass";
					si = $(TRow.cells[i]).getFirst().selectedIndex;
					TD.id = $(TRow.cells[i]).getFirst().options[si].value;
					TD.set('html', $(TRow.cells[i]).getFirst().options[si].text);
					TR.grab(TD);
				}
				else if (t == "INPUT")
				{
					if ($(TRow.cells[i]).getFirst().type == "text")
					{
						TD = new Element('td');
						TD.className = "TableClass";
						TD.set('html', trim($(TRow.cells[i]).getFirst().value));
						$(TRow.cells[i]).getFirst().value = "";
						if ((tmp_ = TD.get('html')) == "")
						{
						}
						else if ((ValidationStatus = Validate(tmp_, Fields[CountedFields].Type, Fields[CountedFields].Force)) > 0)	// !!! ???
						{
							//IsEmpty = false;
						}
						else
						{
							//IsEmpty = false;
							//NotValid += Table.rows[1].cells[i].innerHTML + " و ";
							if (ValidationStatus === -2)
							{
								if (Fields[CountedFields].ForceAlert && Fields[CountedFields].ForceAlert != '')
								{
									NotValidForForceWithAlert += Fields[CountedFields].ForceAlert + '\n';
								}
								else
								{
									NotValidForForce += i + " و ";
								}
							}
							else if (ValidationStatus === -1)
							{
								if (Fields[CountedFields].ValidationAlert && Fields[CountedFields].ValidationAlert != '')
								{
									NotValidWithAlert += Fields[CountedFields].ValidationAlert + '\n';
								}
								else
								{
									NotValid += i + " و ";
								}
							}
							
						}
						TR.grab(TD);
					}
					else if ((t = $(TRow.cells[i]).getFirst().type) == 'button' || t == 'checkbox')
					{
						CountedFields--;
					}
				}
				else
				{
					TD = new Element('td');
					if (TRow.cells[i].id)
					{
						TD.id = TRows.cells[i].id;
					}
					TD.className = "TableClass";

					TD.set('html', $(TRow.cells[i]).get('html'));
					TR.grab(TD);
				}
			}
		}
		//------------------------------------------
		if (IsEmpty)
		{
			alert(W_WARNING_NO_DATA);
			$(TR.cells[0]).getFirst().checked = true;
			DeleteFromTable(Table);
		}

		if (NotValidForForce != "" || NotValidForForceWithAlert != "")
		{
			Warning = NotValidForForceWithAlert;
			if (!(NotValidForForce = NotValidForForce.substr(0, NotValidForForce.length - 3)))
			{
				Warning = Warning.substr(0, Warning.length - 1);
			}
			else
			{
				Warning += W_WARNING_NOT_VALID_FOR_FORCE_1 + ' ' + NotValidForForce + ' ' + W_WARNING_NOT_VALID_FOR_FORCE_2;
			}
		}
		if (NotValid != "" || NotValidWithAlert != "")
		{
			Warning = NotValidWithAlert;
			if (!(NotValid = NotValid.substr(0, NotValid.length - 3)))
			{
				Warning = Warning.substr(0, Warning.length - 1);
			}
			else
			{
				Warning += W_WARNING_NOT_VALID_1 + ' ' + NotValid + ' ' + W_WARNING_NOT_VALID_2;
			}
		}
		if (Warning)
		{
			alert(Warning);
			EditTableRow(null, TR)
		}
		//------------------------------------------
	}
	else
	{
		alert(W_WARNING_SAVE_ROW);
	}
}
//------------------------------------------
function DeleteTableRow(Evt)
{
	var fE = new Event(Evt).target;

	TR = fE.parentNode.parentNode;
	TBody = TR.parentNode;

	if(TBody.tagName.toLowerCase() == "table")
		Table = TBody;
	else
		Table = TBody.parentNode;

	Table.deleteRow(TR.rowIndex);
}
//------------------------------------------
function SetSelectedDataArray(Name, ShouldBeSpecifiedArray) {
	var SDA;
	if ((typeof ShouldBeSpecifiedArray) == 'undefined')
		ShouldBeSpecifiedArray = false;

	if (!(SDA = GBCG("SelectedDataArray_" + (typeof Name == 'string' ? Name : $(Name).id), 'var')))
		if (!ShouldBeSpecifiedArray)
			SDA = GBCG("SelectedDataArray_OSRelation", 'var');

	return SDA;
}
//------------------------------------------
function SetSelectedData_Radio_Check(Name)
{
	SelectedDataArray = SetSelectedDataArray(Name);

	if (SelectedDataArray.length && typeof SelectedDataArray[0] == 'object') {
		var EDataArray = GBCG("DataArray_" + Name, 'var');
		for (var i = 0; fE = $(Name + i); i++) {
			if (!$defined(EDataArray[i].Role))
				EDataArray[i].Role = 0;
			for (var j = 0; j < SelectedDataArray.length; j++)
				if (EDataArray[i].Role == SelectedDataArray[j].Role && EDataArray[i].Value == SelectedDataArray[j].Subject) {
					fE.checked = true;
					break;
				}
		}
	} else for (var i = 0; fE = $(Name + i); i++)
		for (var j = 0; j < SelectedDataArray.length; j++)
			if (fE.value == SelectedDataArray[j]) {
				fE.checked = true;
				break;
			}
}
//------------------------------------------
function SetSelectedData_List(Name, DataContainerEle)
{
	var SelectedDataArray = SetSelectedDataArray(Name), fE = $(Name);

	if (SelectedDataArray.length && typeof SelectedDataArray[0] == 'object') {
		var EDataArray = GBCG("DataArray_" + $(DataContainerEle || Name).id, 'var');
		for (var i = 0; i < EDataArray.length; i++) {
			if (!$defined(EDataArray[i].Role))
				EDataArray[i].Role = 0;

			for (var j = 0; j < SelectedDataArray.length; j++)
				if (EDataArray[i].Role == SelectedDataArray[j].Role && EDataArray[i].Value == SelectedDataArray[j].Subject) {
					for (var k = 0; k < fE.length; k++)
						if (fE[k].value == EDataArray[i].Value) {
							fE[k].selected = true;
							break;
						}
					break;
				}
		}
	} else for (var i = 0; i < fE.length; i++)
		for (var j = 0; j < SelectedDataArray.length; j++)
			if (fE[i].value == SelectedDataArray[j]) {
				fE[i].selected = true;
				break;
			}
}

function SetSelectedData_TwoList(ListID1,ListID2) {
	SetSelectedData_List(ListID1 = $(ListID1));
	CopyToList(ListID1, $(ListID2));
}

function SetSelectedData_TableList(Name) {
	SetSelectedData_List(Name);
	AddToTable(Name, "tbl" + $(Name).id.substr(3));
}

function SetSelectedData_DL(ComboID, ListID)
{
	ComboID = $(ComboID);
	ListID = $(ListID);

	var DataArray = GBCG("DataArray_" + ComboID.id, 'var'),
	SelectedDataArray = SetSelectedDataArray(ListID),
	SelectedDataParent = "", i;

	if (SelectedDataArray.length && typeof SelectedDataArray[0] == 'object') {
		for (var i = 0; i < DataArray.length; i++) {
			if (!$defined(DataArray[i].Role))
				DataArray[i].Role = 0;

			for (var j = 0; j < SelectedDataArray.length; j++)
				if (DataArray[i].Role == SelectedDataArray[j].Role && DataArray[i].Value == SelectedDataArray[j].Subject) {
					var Parent = DataArray[i].Parent;
					if (typeof Parent == 'string')
						Parent = trim(Parent);

					if (DataArray[i].Parent !== 0 && DataArray[i].Parent !== '0')
						SelectedDataParent = DataArray[i].Parent;
				}
		}
	} else for (var i = 0; i < DataArray.length; i++) {
		for (var j = 0; j < SelectedDataArray.length; j++)
			if (DataArray[i].Value == SelectedDataArray[j]) {
				var Parent = DataArray[i].Parent;
				if (typeof Parent == 'string')
					Parent = trim(Parent);

				if (DataArray[i].Parent !== 0 && DataArray[i].Parent !== '0')
					SelectedDataParent = DataArray[i].Parent;
			}
	}
	//----------------------------------------------
	for (i = 0; i < ComboID.length; i++)
	{
		if (ComboID[i].value == SelectedDataParent) {
			ComboID[i].selected = true;
			break;
		}
	}
	//----------------------------------------------
	DataSetting(ComboID, ListID);
	SetSelectedData_List(ListID, ComboID);
}
//------------------------------------------
function SetSelectedData_DL_MS_SP_2List(ComboID, ListID1, ListID2)
{
	ComboID = $(ComboID);
	ListID1 = $(ListID1);
	ListID2 = $(ListID2);

	SetSelectedData_DL(ComboID.id, ListID1.id);
	CopyToList(ListID1, ListID2);
}
//------------------------------------------
function SetSelectedData_DL_MS_MP_2List(ComboID, ListID1, ListID2)
{
	ComboID = $(ComboID);
	ListID1 = $(ListID1);
	ListID2 = $(ListID2);

	SetSelectedData_DL(ComboID.id, ListID1.id);

	var DataArray = GBCG("DataArray_" + ComboID.id, 'var'),
	SelectedDataArray = SetSelectedDataArray(ListID1.id),
	view, value, parentValue, parentView;

	if (SelectedDataArray.length && typeof SelectedDataArray[0] == 'object')
		for (var i = 0, value, view, role, parentValue, parentView; i < DataArray.length; i++) {
			value = DataArray[i].Value;
			view = DataArray[i].View;
			role = $defined(DataArray[i].Role) ? DataArray[i].Role : 0;

			parentValue = DataArray[i].Parent;
			parentView = getView(ComboID.id, parentValue);
			for (var j = 0; j < SelectedDataArray.length; j++)
				if (role == SelectedDataArray[j].Role && value == SelectedDataArray[j].Subject)
					addToList(parentView + ' - ' + view, value, ListID2);
		}
	else for (var i = 0; i < DataArray.length; i++) {
		value = DataArray[i].Value;
		view = DataArray[i].View;
		parentValue = DataArray[i].Parent;
		parentView = getView(ComboID.id, parentValue);
		for (var j = 0; j < SelectedDataArray.length; j++) {
			if (value == SelectedDataArray[j]) {
				addToList(parentView + ' - ' + view, value, ListID2);
//				deactiveAnElementFromList(value, ListID1);
			}
		}
	}
}
//------------------------------------------
function SetSelectedData_DL_MS_TableList(ComboID, ListID, TableID)
{
	ComboID = $(ComboID);
	ListID = $(ListID);
	TableID = $(TableID);

	var DataArray = GBCG("DataArray_" + ComboID.id, 'var'),
	SelectedDataArray = SetSelectedDataArray(ListID.id),
	TR, TD, View, Value, Parent;

	if (SelectedDataArray.length && typeof SelectedDataArray[0] == 'object')
		for (var i = 0, Value, View, role, Parent; i < DataArray.length; i++) {
			Value = DataArray[i].Value;
			View = DataArray[i].View;
			role = $defined(DataArray[i].Role) ? DataArray[i].Role : 0;
			Parent = DataArray[i].Parent;
			for (var j = 0; j < SelectedDataArray.length; j++)
				if (role == SelectedDataArray[j].Role && Value == SelectedDataArray[j].Subject)
					AddTableListRow(TableID, View, Value, getView(ComboID.id, Parent))
		}
	else for (var i = 0; i < DataArray.length; i++) {
		Value = DataArray[i].Value;
		View = DataArray[i].View;
		Parent = DataArray[i].Parent;
		for (var j = 0; j < SelectedDataArray.length; j++)
			if (Value == SelectedDataArray[j])
				AddTableListRow(TableID, View, Value, getView(ComboID.id, Parent))
	}
}

function AddTableListRow(Tbl, View, Value, ParentView) {
	TR = $(Tbl.insertRow(-1));
	TR.className = "TableListClass";
	TR.id = Value;

	TD = new Element('td');
	TD.className = "TableListClass";
		var fE = new Element("input");
		fE.type = "checkbox";
	TD.grab(fE);
	TR.grab(TD);

	TD = new Element('td');
	TD.className = "TableListClass";
	TD.set('html', Tbl.rows.length - 1);
	TR.grab(TD);

	TD = new Element('td');
	TD.className = "TableListClass";
	TD.set('html', ParentView);
	TR.grab(TD);

	TD = new Element('td');
	TD.className = "TableListClass";
	TD.set('html', View);
	TR.grab(TD);	
}
//------------------------------------------
function SetSelectedData_ML_MS_Tree_List(TreeID, ListID)
{
	var List = $(ListID), Tree = $(TreeID), SelectedDataArray;

	if(SelectedDataArray = SetSelectedDataArray(TreeID, true))
	{
		
	}
}
//------------------------------------------
function CopyFromTreeToList(TreeID, oList) {
	var oTree = $(TreeID), oSelectedItem = {}, oNode;
	oList = $(oList);

	if (oTree && oTree.get('TreeType') == 'mif') {
		if ((oNode = oTree.TreeHandler.getSelected()) && (oNode.data.cms_uid - 0) != 0)
			oSelectedItem = {UID: oNode.data.cms_uid, Text: oNode.name};
	} else {
		try {
			var _tree = GBCG('tree_' + TreeID, 'var');
			if (oSelectedItem.UID = _tree.getSelectedItemId()) {
				oSelectedItem.Text = _tree.getItemText(oSelectedItem.UID);
			} else return true;
		} catch (Err) {return false}; //alert('An error accurred when is going to copy an item from tree to list');
	}
	
	if (oSelectedItem != {} && oSelectedItem.UID) {
		if (!IsInList(oSelectedItem.UID, oList)) {
			var _n = oList.options.length;
			oList.options[_n] = new Option(oSelectedItem.Text, oSelectedItem.UID);
			oList.options[_n].title = oSelectedItem.Text;
		} else alert(oSelectedItem.Text + ' ' + W_WARNING_SELECTED);
	}
}
//------------------------------------------
function ReturnFromListToTree(ListID, TreeID)
{
	List = $(ListID);
//	TreeID = $(TreeID);
	DeleteFromList(List);
}
//------------------------------------------
function getView(ArrayID, Value)
{
	var DataArray = GBCG("DataArray_" + ArrayID, 'var');
	for (var i = 0; i < DataArray.length; i++)
		if (DataArray[i].Value == Value)
			return DataArray[i].View;
}
//------------------------------------------
function getParent(ArrayID, Child)
{
	var DataArray = GBCG("DataArray_" + ArrayID, 'var'), Parent;
	for (var i = 0; i < DataArray.length; i++)
	{
		if (DataArray[i].Value == Child)
		{
			Parent = DataArray[i].Parent;
			break;
		}
	}
	return getView(ArrayID, Parent);
}
//------------------------------------------
function SetHiddenValue(Name, hiddenValue) {
	$("hid" + Name).value = hiddenValue;
}
//------------------------------------------
function GetCheckInfo(Name)
{
	hiddenValue = "";
	var i = 0;
	var k = 0;
	while (fE = $("chk" + Name + i)) {
		i++;
		if(fE.checked)
		{
			if(k > 0)
				hiddenValue += "*";

			hiddenValue += fE.value;
			k++;
		}
	}
	SetHiddenValue(Name, hiddenValue);
}
//------------------------------------------
function GetListInfo(Name)
{
	var fnclvListID;
	DeselectAllList($((fnclvListID = "lst" + Name) + "[1]") || $(fnclvListID + "_1"));
	//---------------------------------------
	SelectAllList($(fnclvListID + "[2]") || $(fnclvListID + "_2"));
}
//------------------------------------------
function GetListInfo2(ListID)
{
	List = $(ListID);
	SelectAllList(List);
}
//------------------------------------------
function GetTableListInfo(Name)
{
	ListID = "lst" + Name;
	ListID = $(ListID);
	DeselectAllList(ListID);
	//---------------------------------------
	TableID = "tbl" + Name;
	TableID = $(TableID);
	hiddenValue = "";
	var n = 0;
	for (var i = 1; i < TableID.rows.length; i++)
	{
		if (n > 0)
		{
			hiddenValue += "*";
		}
		Row = TableID.rows[i];
		hiddenValue += Row.id;
		n++;
	}
	SetHiddenValue(Name, hiddenValue);
}
//------------------------------------------
function GetTableInfo(Name)
{
	TableID = "tbl" + Name;
	TableID = $(TableID);

	for(var tr = 0; i<TableID.rows.length;TableID.rows[tr++].EditableRow = TableID.RowsEditable);

	TableObject = GetTableSpec(TableID);
	var c = TableObject.StartContentDataAt, ActAs, Fields = GBCG("Fields_" + TableID.id, 'var');;

	TableType = false;
	hiddenValueNew = "";
	hiddenValueOld = "";
	for (var i = 0; i < TableID.rows.length; i++)
	{
		Row = TableID.rows[i];
		if (Row.EditableRow && Row.EditableRow == 'false')
		{
			continue;
		}
		if (Row.mode == "SAVED" && (!Row.id || Row.id == ""))
		{
			for (var j = 0; j < Row.cells.length; j++)
			{
				ActAs = '';
				Cell = $(Row.cells[j]);
				if ($defined(Fields[j - c]) && $defined(Fields[j - c].Interface))
				{
					ActAs = Fields[j - c].Interface;
				}
				else
				{
					if (Cell.getFirst() && Cell.getFirst().tagName)
					{
						switch (Cell.getFirst().type || Cell.getFirst().tagName.toLowerCase())
						{
							case "button":
								ActAs = 'ActionButton';
								break;
							case "checkbox":
								if (j == 0)
								{
									ActAs = 'CheckBox';
								}
								break;
							case "img":
								if (j == 0)
								{
									ActAs = 'DeleteImg';
								}
								if (j == TableObject.ArrangementPosition)
								{
									ActAs = 'ArrangeElement';
								}
								break;
						}
					}
					else if (Cell.id || Fields[j - c].Content)
					{
						ActAs = 'Custom';
					}
					else
					{
						ActAs = 'TextEditor';
					}
				}
				switch (ActAs)
				{
					case 'ComboBox':
					case 'Custom':
						hiddenValueNew += Cell.id;
						break;
					case 'DateEditor':
					case 'TextEditor':
						hiddenValueNew += Cell.get('html');
						break;
					case 'ActionButton':
					case 'CheckBox':
					case 'DeleteImg':
					case 'ArrangeElement':
						continue;
					default:
						if (Cell.id)
						{
							hiddenValueNew += Cell.id;
						}
						else
						{
							hiddenValueNew += Cell.innerHTML;
						}
				}
				hiddenValueNew += "*";
			}
			hiddenValueNew = hiddenValueNew.substr(0, hiddenValueNew.length - 1);
			hiddenValueNew += "||";
		}
		else if ((Row.mode && Row.mode == "SAVED" && Row.id != "") || (!Row.mode && Row.id != "NEW" && Row.id != "EDIT" && Row.id != ""))
		{
			hiddenValueOld += Row.id + "*";
			for (var j = 0; j < Row.cells.length; j++)
			{
				ActAs = '';
				Cell = $(Row.cells[j]);
				if ($defined(Fields[j - c]) && $defined(Fields[j - c].Interface))
				{
					ActAs = Fields[j - c].Interface;
				}
				else
				{
					if (Cell.getFirst() && Cell.getFirst().tagName)
					{
						switch (Cell.getFirst().type || Cell.getFirst().tagName.toLowerCase())
						{
							case "button":
								ActAs = 'ActionButton';
								break;
							case "checkbox":
								if (j == 0)
								{
									ActAs = 'CheckBox';
								}
								break;
							case "checkbox":
								if (j == 0)
								{
									ActAs = 'DeleteImg';
								}
								break;
							case "img":
								if (j == TableObject.ArrangementPosition)
								{
									ActAs = 'ArrangeElement';
								}
								break;
						}
					}
					else if (Cell.id || ($defined(Fields[j - c]) && Fields[j - c].Content))
					{
						ActAs = 'Custom';
					}
					else
					{
						ActAs = 'TextEditor';
					}
				}
				switch (ActAs)
				{
					case 'ComboBox':
					case 'Custom':
						hiddenValueOld += Cell.id;
						break;
					case 'DateEditor':
					case 'TextEditor':
						hiddenValueOld += Cell.get('html');
						break;
					case 'ActionButton':
					case 'CheckBox':
					case 'DeleteImg':
					case 'ArrangeElement':
						continue;
					default:
						if (Cell.id)
						{
							hiddenValueOld += Cell.id;
						}
						else
						{
							var CellInnerHTML = Cell.get('html');
							hiddenValueOld += CellInnerHTML;
						}
				}
				hiddenValueOld += "*";
			}
			hiddenValueOld = hiddenValueOld.substr(0, hiddenValueOld.length-1);
			hiddenValueOld += "||";
		}
		else
		{
			switch(TableType || ((TableType = GetTableType(TableID)) ? TableType : TableType)) {
				case 'DYNAMIC':
				case 'SIMPLECROSS':
					UnrecognizableStatus = i > 0 ? true : false;
				break;
				case 'STATIC':
					UnrecognizableStatus = i > 1 ? true : false;
				break;
				case false:
					UnrecognizableStatus = i > 0 ? true : false;
				break;
			}
			if (UnrecognizableStatus)
				alert(W_UNKNOWN_ERROR + ' (' + i + ')');
		}
	}
	hiddenValueNew = hiddenValueNew.substr(0, hiddenValueNew.length-2);
	hiddenValueOld = hiddenValueOld.substr(0, hiddenValueOld.length-2);
	hiddenValue = hiddenValueNew + "###" + hiddenValueOld;
	SetHiddenValue(Name, hiddenValue);
}
//------------------------------------------
function DeleteFromTable_(TableID)
{
	TableID = $(TableID);

	hiddenValue = "";
	var n = 0;
	for (var i = 0; i < TableID.rows.length; i++)
	{
		Row = TableID.rows[i];
		//Cell = Row.cells[0];
		if ($(Row.cells[0]).getFirst())
		{
			if ($(Row.cells[0]).getFirst().checked)
			{
				if (n > 0)
				{
					hiddenValue += "*";
				}
				hiddenValue += Row.id;
				n++;
			}
		}
	}
	if (n > 0)
	{
		Name = TableID.id;
		Name = Name.substr(3);
		SetHiddenValue(Name, hiddenValue);
		if (confirm(W_WARNING_CONFIRM))
		{
			document.forms[0].action = "save.php?Mode=DELETE";
			FormSubmit2({form: document.forms[0], responseType: 'HTML'});
		}
	}
	else
	{
		alert(W_WARNING_NO_SELECTED);
	}
}
//------------------------------------------
function Arrange(Evt, TableID)
{
	TableID = $(TableID);

	hiddenValue = "";
	var n = 0;
	for (var i = 0; i < TableID.rows.length; i++) {
		Row = TableID.rows[i];
		if ($(Row.cells[0]).getFirst())
		{
			if (n > 0)
			{
				hiddenValue += "*";
			}
			hiddenValue += Row.id;
			n++;
		}
	}
	if (n > 0)
	{
		Name = TableID.id;
		Name = Name.substr(3);
		SetHiddenValue(Name, hiddenValue);
		if (confirm(W_WARNING_CONFIRM))
		{
			document.forms[0].action = "save.php?Mode=ARRANGE";
			FormSubmit2({form: document.forms[0], responseType: 'HTML'});
		}
	}
	else
	{
		alert(W_WARNING_NO_SELECTED);
	}
}
//------------------------------------------
function GetListSelectedItemsWithASeperator(Evt, TableID, Seperator, All)
{
	TableID = $(TableID);

	hiddenValue = "";
	var n = 0;
	for (var i = 0; i < TableID.rows.length; i++)
	{
		Row = TableID.rows[i];
		if ($(Row.cells[0]).getFirst())
		{
			if ($(Row.cells[0]).getFirst().checked || (typeof All != 'undefined' && All))
			{
				if (n > 0)
				{
					hiddenValue += Seperator;
				}
				hiddenValue += Row.id;
				n++;
			}
		}
	}
	return hiddenValue;
}
//------------------------------------------
function Set(TableID, Subject, Role, InModuleUniqueSubject)
{
	TableID = $(TableID);

	hiddenValue = "";
	for (var i = 0, n = 0; i < TableID.rows.length; i++) {
		Row = TableID.rows[i];
		if ($(Row.cells[0]).getFirst())
			if ((Row.cells[0]).getFirst().checked || Subject == 0) {
				if (n++ > 0) hiddenValue += "*";

				hiddenValue += Row.id;
			}
	}

	if (hiddenValue) {
		SetHiddenValue(TableID.id.substr(3), hiddenValue);
		if (confirm(W_WARNING_CONFIRM)) {
			document.forms[0].action = "save.php?Mode=SET&Subject=" + Subject + (Role ? '&Role=' + Role : '') + (InModuleUniqueSubject ? '&InModuleUniqueSubject=true' : '');
			FormSubmit2({form: document.forms[0], responseType: 'HTML'});
		}
	} else
		alert(W_WARNING_NO_SELECTED);
}

function SetForStaticTables(TableID, Subject)
{
	TableID = $(TableID);

	hiddenValue = "";
	var n = 0;
	for (var i = 2; i < TableID.rows.length; i++) {
		Row = TableID.rows[i];
		if ($(Row.cells[0]).getFirst()) {
			if ($(Row.cells[0]).getFirst().checked || Subject == 0) {
				if (n++ > 0) hiddenValue += "*";

				hiddenValue += Row.id;
			}
		}
	}
	if (hiddenValue) {
		SetHiddenValue(TableID.id.substr(3), hiddenValue);
		if (confirm(W_WARNING_CONFIRM)) {
			document.forms[0].action = "save.php?Mode=SET&Subject=" + Subject;
			FormSubmit2({form: document.forms[0], responseType: 'HTML'});
		}
	} else {
		alert(W_WARNING_NO_SELECTED);
	}
}
//------------------------------------------
function SetDirection(dir)
{
	//document.body.dir = dir;
	var FormElementsArray = GBCG('FormElementsArray', 'var');
	if (FormElementsArray)
	{
		for (var i = 0; i < FormElementsArray.length; i++)
		{
			ID = FormElementsArray[i].ID;
			Type = FormElementsArray[i].Type;
			if (Type)
			{
				if (fE = $(ID))
				{
					if (Type == "Fa_STRING" || Type == "STRING" || Type == "NAME")
					{
						fE.dir = dir;
					}
					else if (Type != "TABLE" && Type != "TABLE_LIST" && Type != "RADIO" && Type != "CHECKBOX" && Type != "LIST")
					{
						fE.dir = "ltr";
					}
				}
			}
		}
	}
}
//------------------------------------------
function FormValidate(FormID)
{
	FormID = $(FormID);
	var FEA, FormElementsArray;
	if (FormID) {
		if (!(FEA = GBCG("FormElementsArray_" + FormID.id, 'var')))
			FEA = GBCG("FormElementsArray", 'var');

		FormElementsArray = FEA;
	}
	//----------------------
	var Name, ID, Type, Force,
	ForceAlert, ValidationAlert, Value, Warning, WarningAlert, TableType, Empty;
	//----------------------
	for (var i = 0; i < FormElementsArray.length; i++)
	{
		if (FormElementsArray[i])
		{
			Name = FormElementsArray[i].Name;
			ID = FormElementsArray[i].ID;
			Type = FormElementsArray[i].Type;
			Force = FormElementsArray[i].Force;
			if (Type === 'NonEditableContent')
			{
				continue;
			}
			if (typeof FormElementsArray[i].ForceAlert != 'undefined')
			{
				ForceAlert = FormElementsArray[i].ForceAlert;
			}
			else
			{
				ForceAlert = '';
			}
			if (typeof FormElementsArray[i].ValidationAlert != 'undefined')
			{
				ValidationAlert = FormElementsArray[i].ValidationAlert;
			}
			else
			{
				ValidationAlert = '';
			}

			if (Type) {
				Value = (fE = $(ID)) ? fE.value : false;

				WarningEmpty = W_WARNING_ENTER_1 + ' ' + Name + ' ' + W_WARNING_ENTER_2;
				Warning = W_WARNING_NOT_VALID_1 + ' ' + Name + ' ' + W_WARNING_NOT_VALID_2;

				switch (Type) {
					case "TABLE":
					if (!(TableType = GetTableType(fE)) && Force)
					{
						alert(false);
						return false;
					}

					switch(TableType) {
						case 'DYNAMIC':
						case 'SIMPLECROSS':
							Empty = fE.rows.length > 1 ? false : true;
						break;
						case 'STATIC':
							Empty = fE.rows.length > 2 ? false : true;
						break;
					}

					if (Force && Empty)
					{
						alert(WarningEmpty);
						fE.focus();
						return false;
					}

					break;
					case "TABLE_LIST":
					if (Force)
					{
						if (fE.rows.length < 2) {
							alert(WarningEmpty);
							fE.focus();
							return false;
						}
					}
					break;
					case "RADIO":
					case "CHECKBOX":
					if (Force)
					{
						k = 0;
						j = 0;
						while (fE = $(ID + j))
						{
							j++;
							if(fE.checked)
							{
								k++;
							}
						}
						if (k == 0)
						{
							alert(WarningEmpty);
							if (fE)
							{
								fE.focus();
							}
							return false;
						}
					}
					break;
				 	case 'LIST':
					if (Force) {
						if ((typeof IS_NOT_SELECTED != 'undefined') && trim(Value) - 0 == IS_NOT_SELECTED) {
							alert(WarningEmpty);
							return false;
						} else if (!Value) {
							alert(WarningEmpty);
							return false;
						}
					}
					break;
					case 'AJAX_TEXT_FLOAT_LIST_SEARCH':
					if (Force) {
						if (!$(ID).value) {
							alert(WarningEmpty);
							return false;
						}
					}
					break;
					case 'AJAX_TEXT_FLOAT_LIST_SUPPLEMENTARY':
					if (Force) {
						if (!trim($('txt' + ID.substr(3)).value) && !($(ID).value - 0)) {
							alert(WarningEmpty);
							return false;
						}
					}
					break;
					case "PASSWORD":
					Confirm = $(ID + "Confirm")
					if (Value === Confirm.value) {
						if (!(!Force && Value == '')) {
							if (Validate(Value, Type, Force) < 0) {
								alert(Warning);
								fE.focus();
								return false;
							} else
								Confirm.value = fE.value = MD5(Value);
						}
					} else {
						Confirm.value = fE.value = "";
						alert(W_WARNING_PASSWORD_CONFIRM);
						fE.focus();
						return false;
					}
					default:
					if(Validate(Value, Type, Force) < 0) {
						alert(Warning);
						fE.focus();
						return false;
					}
				}
			}
		}
	}
	//----------------------
	return true;
}
//------------------------------------------
function Add(Name) {
	GoTo("index.php?Page=" + Name + "&Mode=NEW");
}
//------------------------------------------
function Edit(Name, Evt) {
	var TR = new Event(Evt).target.parentNode.parentNode;
	GoTo("index.php?Page=" + Name + "&Mode=EDIT&UID=" + TR.id);
}
//------------------------------------------
function Edit_InOtherLanguage(Name, Evt) {
	var fE = new Event(Evt).target, TD = fE.parentNode, TR = TD.parentNode, sUrl;

	if (fE.id == "")
		sUrl = "index.php?Page=" + Name + "&Mode=NEW&ID=" + $(TR).get('categoryid') + "&Language=" + TD.id;
	else
		sUrl = "index.php?Page=" + Name + "&Mode=EDIT&UID=" + fE.id + "&Language=" + TD.id;

	GoTo(sUrl);
}
//------------------------------------------
function MoveTableRow(Direction, Evt)
{
	if(typeof Evt == 'undefined')
	{
		if (typeof Direction != 'number')
		{
			if (typeof Direction != 'undefined')
			{
				Evt = Direction;
				Direction = null;
			}
			else
			{
				Evt = null;
			}
		}
		else
		{
			Evt = null;
		}
	}

	if (Evt == null)
	{
		var Evt = new Event(event);
	}
	else
	{
		var Evt = new Event(Evt);
	}

	var fE = Evt.target;

	if (typeof Direction == 'undefined' || Direction == null) {
		Direction = $(fE).get('direction') - 0;
	}


	TD = fE.parentNode;
	TR = TD.parentNode;
	TBody = TR.parentNode;

	if(TBody.tagName.toLowerCase() == "table")
	{
		Table = TBody;
	}
	else
	{
		Table = TBody.parentNode;
	}

	if ((NewTR = Table.rows[TR.rowIndex + Direction - 0]) && (TR.rowIndex + Direction) > 0)
	{
		swapNodes(TR, NewTR);
	}
}
//------------------------------------------
function FormInfo()
{
	string = "  :  ( tagName ) ( type ) ( name ) ( id ) ( className ) \n";
	for (i = 0; i < document.forms[0].elements.length; i++)
	{
		string += i + " : ";
		string += " ( " + document.forms[0].elements[i].tagName + " ) ";
		string += " ( " + document.forms[0].elements[i].type + " ) ";
		string += " ( " + document.forms[0].elements[i].name + " ) ";
		string += " ( " + document.forms[0].elements[i].id + " ) ";
		string += " ( " + document.forms[0].elements[i].className + " ) ";
		string += "\n";
	}
	//alert(string);
	w = window.open();
	w.document.write("<pre>" + string + "</pre>");
}
//------------------------------------------
function FormInfoTable()
{
	W = window.open();
	Table = W.document.createElement("table");
	Table.align = "center";
	Table.border = "1";
	Table.borderColor = "#990000";
	TR = Table.insertRow(-1);
	TD = TR.insertCell();
	xInnerHtml(TD, "&nbsp;");
	TD = TR.insertCell();
	xInnerHtml(TD, "tagName");
	TD = TR.insertCell();
	xInnerHtml(TD, "type");
	TD = TR.insertCell();
	xInnerHtml(TD, "name");
	TD = TR.insertCell();
	xInnerHtml(TD, "id");
	TD = TR.insertCell();
	xInnerHtml(TD, "className");
	for (i = 0; i < document.forms[0].elements.length; i++)
	{
		TR = Table.insertRow(-1);
		TD = TR.insertCell();
		xInnerHtml(TD, i);
		TD = TR.insertCell();
		xInnerHtml(TD, document.forms[0].elements[i].tagName);
		TD = TR.insertCell();
		xInnerHtml(TD, document.forms[0].elements[i].type);
		TD = TR.insertCell();
		xInnerHtml(TD, document.forms[0].elements[i].name);
		TD = TR.insertCell();
		xInnerHtml(TD, document.forms[0].elements[i].id);
		TD = TR.insertCell();
		xInnerHtml(TD, document.forms[0].elements[i].className);
	}
	W.document.body.appendChild(Table);
}
//------------------------------------------
function ShowHide(fE)
{
//	if (fE.currentStyle.visibility == "hidden")
	if (fE.getStyle('visibility') == "hidden")
	{
		fE.setStyle('visibility', 'visible')
	}
//	else if (fE.currentStyle.visibility == "visible")
	else if (fE.getStyle('visibility') == "visible")
	{
		fE.setStyle('visibility', 'hidden')
	}
}

function AddFileForObjectEquivalents(Object, FileExt, EquivalentsLanguages) {
	if (EquivalentsLanguages == '') {
		alert(W_NO_EQUIVALENTS_AVAILABLE);
		return;
	}

	FileEquivalentsForAnObject = new Array();
	if(typeof EquivalentsLanguages == 'string')
		EquivalentsLanguages = EquivalentsLanguages.split(";");

	if (EquivalentsLanguages.length > 0) {
		var oLayer = new Element("div").setStyles({
			position: 'absolute',
			'background-color': '#CC9933',
			width: 300,
			'border-color': '#CC6600',
			'border-style': 'dotted',
			'border-width': 1
		}).makeDraggable();

		Table = new Element("table");
		Table.style.textAlign = "center";
		Table.style.borderWidth = "0px";

		for (i = 0; i < EquivalentsLanguages.length; i++) {
			EquivalentsLanguages[i] = EquivalentsLanguages[i].split(":");
	
			TR = $(Table.insertRow(-1));
			TD = new Element('td');
	
			var fE = new Element("input");
				fE.type = "checkbox";
				fE.value = EquivalentsLanguages[i][0];
				fE.title = EquivalentsLanguages[i][1];

			FileEquivalentsForAnObject[FileEquivalentsForAnObject.length] = fE;

			TD.grab(fE);
			TR.grab(TD);

			TD = new Element('td');
			Text = document.createTextNode(EquivalentsLanguages[i][1]);
			TD.grab(Text);
			TR.grab(TD);
		}

		TR = $(Table.insertRow(-1));
		TD = new Element('td');
		TD.colSpan = 2;

		fE = new Element("input");
		fE.type = "button";
		fE.uid = Object;
		fE.extension = FileExt;
		fE.className = 'buttonClass';
		fE.value = W_REGISTER;
		fE.title = W_REGISTER;
		fE.onclick = AddFileEquivalencyForObject;

		TD.grab(fE);
		TR.grab(TD);

		oLayer.grab(Table)
		$(document.body).grab(oLayer);

		var xpos1 = document.body.scrollLeft + Math.floor(document.body.clientWidth / 2) - Math.floor(25);
		var ypos1 = document.body.scrollTop + Math.floor(document.body.clientHeight / 2) - Math.floor(25);
		oLayer.setStyles({left: xpos1, top: ypos1});
	}
	else
		alert('No Equivalents Available!');
}

function AddFileEquivalencyForObject(Evt)
{
	Evt = new Event(Evt);
	var fE = Evt.target;

	Languages = '';
	for (i = 0; i < FileEquivalentsForAnObject.length; i++)
	{
		//alert(fE.uid + ' : ' + FileEquivalentsForAnObject[i].value + ' : ' + FileEquivalentsForAnObject[i].checked)
		if (FileEquivalentsForAnObject[i].checked)
		{
			if (Languages.length)
			{
				Languages += ';';
			}
			Languages += FileEquivalentsForAnObject[i].value;
		}
	}

	if (Languages.length)
	{
		GoTo('addfileforequivalentsofobject.php?Object=' + fE.uid + '&Remote&Extension=' + fE.extension + '&Languages=' + Languages + '&redirect=' + escape(document.URL));
	}
	else
	{
		alert('No Equivalents Available');
	}
}

function GetTableType(Table)
{
	Table = $(Table);
	if (typeof Table.type != 'undefined')
	{
		TableType = Table.type;
	}
	else if (typeof Table.className != 'undefined')
	{
		TableType = Table.className.substr(0, Table.className.length - 5);
	}
	else
	{
		return false;
	}
	return TableType;
}
function GetTableSpecs(Table, Attribute, CaseSensitive)
{
	Table = $(Table);

	CaseSensitive = !!CaseSensitive;

	var TA, lclvarAttributes = (TA = GetElementAttributes(Table)).Attributes ? TA.split(',') : new Array();

	if (Attribute)
	{
		var tmpAttribute, i = 0;
		if (lclvarAttributes.length){
			for(; i < lclvarAttributes.length; i++)
			{
				if (!CaseSensitive)
				{
					if (lclvarAttributes[i].indexOf(':') > 0)
					{
						lclvarAttributes[i] = lclvarAttributes[i].split(':');
						lclvarAttributes[i].Attribute = lclvarAttributes[i][0];
						lclvarAttributes[i].Value = lclvarAttributes[i][1];
					}
					else
					{
						tmpAttribute = lclvarAttributes[i];
						lclvarAttributes[i] = new Array();
						lclvarAttributes[i].Attribute = tmpAttribute;
						lclvarAttributes[i].Value = lclvarAttributes[i].Attribute;
					}

					if (typeof lclvarAttributes[i].Attribute == 'string' && typeof Attribute == 'string')
					{
						lclvarAttributes[i].Attribute = lclvarAttributes[i].Attribute.toLowerCase();
						Attribute = Attribute.toLowerCase();
					}
				}
				if (lclvarAttributes[i].Attribute == Attribute)
				{
					return lclvarAttributes[i].Value;
				}
			}
		}
		return false;
	}
//	else
//	{
//		return Attributes;
//	}
	return false;
}

function GetTableSpec(Table)
{
	var TableObject = new Object;
	TableObject.StartContentDataAt = 0;
	TableObject.ArrangementPosition = -1;

	var TableType = GetTableType(Table);

	if ((A = GetTableSpecs(Table, 'StartRowAt')) !== false)
	{
		if (Validate(A, 'NUMBER', true) === true)
		{
			TableObject.StartRowAt = A;
		}
		else
		{
			TableObject.StartRowAt = 0;
		}
	}
	else
	{
		if ($(Table.rows[0]).hasClass('HeaderTableClass'))
		{
			TableObject.StartRowAt = 1;
		}
		else
		{
			TableObject.StartRowAt = 0;
		}

		for (var i = TableObject.StartRowAt; i < Table.rows.length; i++)
		{
			if (!Table.rows[i].EditableRow || Table.rows[i].EditableRow == 'true')
			{
				break;
			}
			TableObject.StartRowAt++;
		}
	}

	if (GetTableSpecs(Table, 'RowsNotCheckable') || GetTableSpecs(Table, 'NoRowCheckable') || TableType == 'SIMPLECROSS')
	{
		TableObject.RowsCheckable = false;
	}
	else
	{
		TableObject.RowsCheckable = true;
		TableObject.StartContentDataAt++;
	}

	if (GetTableSpecs(Table, 'RowsNotEditable') || GetTableSpecs(Table, 'NoRowEditable'))
	{
		TableObject.RowsEditable = false;
	}
	else
	{
		TableObject.RowsEditable = true;
		TableObject.StartContentDataAt++;
	}

	if (GetTableSpecs(Table, 'NonArrangementic') || (TableObject.RowsEditable + TableObject.RowsCheckable + 1 > Table.rows[0].cells[0].colSpan) || TableType == 'SIMPLECROSS')
	{
		TableObject.Arrangable = false;
	}
	else
	{
		TableObject.Arrangable = true;
		TableObject.ArrangementPosition = TableObject.RowsCheckable + 0;
		TableObject.StartContentDataAt++;
	}

	return TableObject;
}
/*
function SetCellValue(Options){
	if (Options.id){
		this.id = Options.id;
	} 
	if (Options.innerHTML){
		this.innerHTML = Options.innerHTML;
	} 
}
*/
function TableLayerLoader(ID, Type, Object) {
	Object = $(Object);
	FreezeFrame();
	switch(Type.toLowerCase()){
		case 'element':
			var lElement = $(ID);
			if (lElement){
//				lElement = lElement.clone(true, true);
//				lElement.id = 'cloned_' + lElement.id;
//				var lLayer = new Element('div', {'styles': {'position': 'absolute', 'z-Index': FreezerRoof + 1, 'cursor': 'pointer'}}),
//				lElement.setStyles(lElement.getCoordinates())
				lElement.setStyles({/*'left': 100, 'top': 100*/})
				.setStyles({'position': 'absolute', 'z-Index': FreezerRoof + 1, 'cursor': 'pointer'});
				if (!DragableLayers[lElement.id]){
					DragableLayers[lElement.id] = {
						'onStart': function(el) {
							el.setStyle('opacity', 0.5);
						},
						'onDrag': function(el) {
							var epl, ew, wsl, wsr, ept, eh, wst, wsb;
							if ((epl = parseInt(el.getStyle('left'))) < (wsl = parseInt(window.getScrollLeft())))
								el.setStyle('left', wsl);

							if ((epl + (ew = parseInt(el.getStyle('width')))) > (wsr = wsl + parseInt(document.documentElement.clientWidth)))
								el.setStyle('left', wsr - ew);

							if ((ept = parseInt(el.getStyle('top'))) < (wst = parseInt(window.getScrollTop())))
								el.setStyle('top', wst);

							if ((ept + (eh = parseInt(el.getStyle('height')))) > (wsb = wst + parseInt(document.documentElement.clientHeight)))
								el.setStyle('top', wsb - eh);

							window.status = "el.({left: " + epl + ", top: " + epl + ", width: " + ew + ", height: " + eh + "}) + d.({top: " + wst + ", left: " + wsl + ", right: " + wsr + ", bottom: " + wsb + "})";
						},
						'onComplete': function(el) {
							el.setStyle('opacity', 1);
						}
					}
					var h;
					if (h = $(ID + '_Handle')){
						DragableLayers[lElement.id].handle = h;
						DragableLayers[lElement.id].modifiers = {'x': 'left', 'y': 'top'}; 
					}
					//alert(DragableLayers[lElement.id].onStart + ' ' + DragableLayers[lElement.id].onComplete);
					DragableLayers[lElement.id] = new Drag(lElement, DragableLayers[lElement.id]);
				}
				lElement.fireEvent('call', {Value: Object.id, Caller: Object});

//				lLayer.adopt(lElement);
//				Object.adopt(lLayer);
				lElement.setStyle('visibility', 'visible');
				CenteralizeLayer(lElement);
//				lElement.scrollIntoView(true);
			}
			break;
	}
}

function GetElementForm(Ele) {
	return $(Ele).getParent('form');
}


function GetElementInfo(Ele, Frm) {
	Ele = $(Ele);
	if (!Frm)
		Frm = GetElementForm(Ele);

	var FrmElements = GBCG("FormElementsArray_" + Frm.id, 'var')

	for (var i = 0; i < FrmElements.length; i++)
		if (FrmElements[i].ID == Ele.id)
			return FrmElements[i];

	return;
}

window.addEvent("load", function(){
	$$('.EditTableRowButtonClass').each(function(elem){
		elem.addEvent('click', EditTableRow);
	})
});