function DisplayMessageBox(ModDisplay, Header, Mesaj, Timp)
{
	if (ModDisplay == 'open')
	{
		$('MessageBoxMesaj').style.display = 'block';
		$('spnMesajHeader').innerHTML = Header;
		$('spnMesajDeAfisat').innerHTML = Mesaj;
		setTimeout('DisplayMessageBox("close", "", 0)', Timp);
	}
	else if (ModDisplay == 'close')
	{
		$('MessageBoxMesaj').style.display = 'none';
	}
}

function Listeaza(ListObjId, ObjToBeListed, Type) // obiectul care se listeaza trebuie sa contina nume si id
{
	while ($(ListObjId).options.length > 0)
		$(ListObjId).options[0] = null;
	
	var j = 0;
	if (Type != 0)
	{
		var myNewOption = new Option('--', 0);
		$(ListObjId).options[0] = myNewOption;
		j = 1;
	}
	
	for (var i = 0; i < ObjToBeListed.length ; i++)
	{
		var myNewOption = new Option(ObjToBeListed[i].Nume, ObjToBeListed[i].Id);
		$(ListObjId).options[i + j] = myNewOption;
	}
	
	return true;
}

function trim(string_val)
{
	return string_val.replace(/^\s+|\s+$/g, "");
}

function ClearSelect(SelectObj)
{
	while ($(SelectObj).options.length > 0)
	{
		$(SelectObj).options[0] = null;
	}
}

/* Drag and Drop functions */
var DragAndDrop = 
{
	ElementToMoveId : '',
	BoxToMoveId : '',
	ElementToMovePosition : 0,
	
	ElementsToHide : [],
	
	Initialize : function(Elements)
	{
		var k = 0;
		Elements.each(function(Item)
		{
			if (($(Item.key)) && ($(Item.value)))
			{
				Event.observe(Item.key, 'mousedown', function() 
				{
					DragAndDrop.ElementToMoveId = Item.key;
					DragAndDrop.BoxToMoveId = Item.value;
					document.onmousemove = DragAndDrop.BoxRepositioning;
					document.onmouseup = DragAndDrop.EndDragDrop;
				});
				DragAndDrop.ElementsToHide[k] = Item.value;
				k++;
			}
		});
		if ($('dialog'))
		{
			Event.observe($('dialog'), 'mousedown', DragAndDrop.CloseAllWindows); 
		}
		document.onkeydown = DragAndDrop.OnKeyIsPressed;
	},
	
	EndDragDrop : function(event)
	{
		document.onmousemove = null;
		document.onmouseup = null;
		if ($('MovingDiv'))
		{
			$('MovingDiv').style.cursor = 'default';
			$(DragAndDrop.BoxToMoveId).style.left = $('MovingDiv').style.left;
			$(DragAndDrop.BoxToMoveId).style.top = $('MovingDiv').style.top;
			DragAndDrop.ElementToMovePosition = 0;
			document.body.removeChild($('MovingDiv'));
		}
	},
	
	BoxRepositioning : function(event)
	{
		selObj = window.getSelection();
		selObj.removeAllRanges();
		
		Pos = Position.cumulativeOffset($(DragAndDrop.ElementToMoveId));
		
		var DivObj = $(DragAndDrop.BoxToMoveId);
		if (!$('MovingDiv'))
		{
			var DivToMove = document.createElement('div');
			DivToMove.className = 'DragBox';
			DivToMove.setStyle({
	 					width: DivObj.getWidth() + 'px',
	 					height: DivObj.getHeight() + 'px',
						left: Pos[0] + 200 + 'px',
						top: Pos[1] + 'px',
						zIndex: '100'						
					});
			var newImage = document.createElement('img');
			newImage.src = "img/black.png";
			newImage.setStyle({width: '100%',height: '100%'});
			DivToMove.appendChild(newImage);
			DivToMove.id = 'MovingDiv';
			document.body.appendChild(DivToMove);
		}
		$('MovingDiv').style.cursor = 'move';
		if (DragAndDrop.ElementToMovePosition == 0)
		{
		 	DragAndDrop.ElementToMovePosition = event.clientX - Pos[0];
		}
		$('MovingDiv').style.left = (event.clientX - DragAndDrop.ElementToMovePosition) + 'px';
		$('MovingDiv').style.top = event.clientY - 10 +  'px';
	},
	
	OnKeyIsPressed : function(e)
	{
		if (e.keyCode == 27)
		{
			DragAndDrop.CloseAllWindows();
		}
	},
	
	CloseAllWindows : function()
	{
		DragAndDrop.ElementsToHide.each(function(s)
		{
			$(s).style.display = 'none';
		});
		
		if ($('dialog'))
		{
			$('dialog').style.display = 'none';
		}		
	}
}
/* Drag and Drop functions */

function OpenBox(BoxId)
{
	$('dialog').style.display = 'block';
	$(BoxId).style.display = 'block';
}

function CloseBox(BoxId)
{
	$('dialog').style.display = 'none';
	$(BoxId).style.display = 'none';
}

contor = 0;
function DisplayHeader(Tip)
{
	contor++;
	switch (Tip)
	{
		case 1:
		{
			Effect.multiple('text_header', Effect.Fade, {speed:0.05, afterFinishInternal:function(){}});
			setTimeout('DisplayHeader(2)', 2000);
			break;
		}
		case 2:
		{
			Effect.multiple('text_header', Effect.Appear, {speed:0.05, afterFinishInternal:function(){}});
			setTimeout('DisplayHeader(1)', 5000);
			break;
		}
	}	
}