
function deleteLayer(iLayerId)
{
	if (confirm("Are you SURE you want to DELETE this Layer?") == false)
		return;
		
	$('Processing').show( );

	var sUrl    = "ajax/papers/delete-layer.php"; 
	var sParams = ("LayerId=" + iLayerId);
	
	new Ajax.Request(sUrl, { method:'post', parameters:sParams, onFailure:_showError, onSuccess:_deleteLayer });
}

function _deleteLayer(sResponse)
{
	if (sResponse.status == 200 && sResponse.statusText == "OK")
	{
		var sParams = sResponse.responseText.split('|-|');
		
		if (sParams[0] == "OK")
		{
			var iLayerId = sParams[1];
			
			$("Layer_" + iLayerId).innerHTML = sParams[2];
			$("Layer_" + iLayerId).setStyle( { borderColor:'#cccccc', marginBottom:'5px', height:'90px' } );
			
			setTimeout( 
				    function( ) 
				    { 
				    	new Effect.SlideUp("Layer_" + iLayerId);
				    	
				    	setTimeout( 
				    		    function ( ) 
				    		    { 
				    		    	$("Layer_" + iLayerId).remove( );
				    		    	
							var objList = $$(".layer");

							if (objList.length == 0)
								new Effect.Appear('NoRecord', { duration: 2.0 });
				    		    },
				    		    
				    		    1100
				    		  );
				    },
				    
				    2000
				  );
		}
			
		else
			_showError(sParams[1]);
			
		$('Processing').hide( );
	}
	
	else
		_showError( );
}

function changeBorderColor(iPageId, sColor)
{
	$('Processing').show( );

	var sUrl    = "ajax/papers/save-border-color.php"; 
	var sParams = ("PageId=" + iPageId + "&Color=" + sColor);
	
	new Ajax.Request(sUrl, { method:'post', parameters:sParams, onFailure:_showError, onSuccess:_changeBorderColor });
}

function _changeBorderColor(sResponse)
{
	if (sResponse.status == 200 && sResponse.statusText == "OK")
	{
		var sParams = sResponse.responseText.split('|-|');
		
		if (sParams[0] == "OK")		
		{
			var objList = $$(".border");

			if (objList.length > 0)
			{
				for (var i = 0; i < objList.length; i ++)
					objList[i].setStyle({   borderColor: sParams[1] }); 
			}
		}
			
		else
			_showError(sParams[1]);
			
		$('Processing').hide( );
	}
	
	else
		_showError( );
}

function showLinks(iBoxId)
{
	$('Links_' + iBoxId).show( );
}

function hideLinks(iBoxId)
{
	$('Links_' + iBoxId).hide( );
}

function deleteBox(iBoxId, iLayerId, sLayerBoxId)
{
	if (confirm('Are you SURE, You want to Delete this Box?') == false)
		return;

	$('Processing').show( );

	var sUrl    = "ajax/papers/delete-box.php"; 
	var sParams = ("BoxId=" + iBoxId + "&LayerId=" + iLayerId + "&LayerBoxId=" + sLayerBoxId);
	
	new Ajax.Request(sUrl, { method:'post', parameters:sParams, onFailure:_showError, onSuccess:_deleteBox });
}

function _deleteBox(sResponse)
{
	if (sResponse.status == 200 && sResponse.statusText == "OK")
	{
		var sParams = sResponse.responseText.split('|-|');
		
		if (sParams[0] == "OK")		
		{
			var sLayerBoxId = sParams[1];
			
			new Effect.Opacity($(sLayerBoxId), { from: 1.0, to: 0.0, duration: 2.0 });
			
			setTimeout( 
				    function ( )
				    { 
				    	$(sLayerBoxId).innerHTML = "";				    	
				    	$(sLayerBoxId).setStyle( { borderColor:'#ffffff', backgroundColor:'#ffffff', cursor:'default' } );
				    },
				    
				    2000
				  );
		}
			
		else
			_showError(sParams[1]);
			
		$('Processing').hide( );
	}
	
	else
		_showError( );
}

addLoadEvent(function( ) { $('TempOverlay').hide( ) });

setInterval( function( ) 
		 {
			var iScroll       = 0;
			var iWindowHeight = 0;
			var iPageHeight   = 0;

			if (window.innerHeight && window.scrollMaxY)
				iScroll = (window.innerHeight + window.scrollMaxY);

			else if (document.body.scrollHeight > document.body.offsetHeight)
				iScroll = document.body.scrollHeight;

			else
				iScroll = document.body.offsetHeight;


			if (self.innerHeight)
				iWindowHeight = self.innerHeight;

			else if (document.documentElement && document.documentElement.clientHeight)
				iWindowHeight = document.documentElement.clientHeight;

			else if (document.body)
				iWindowHeight = document.body.clientHeight;


			if (iScroll < iWindowHeight)
				iPageHeight = iWindowHeight;

			else
				iPageHeight = iScroll;


			if ($('TempOverlay'))
				$('TempOverlay').setStyle( { height:(iPageHeight + 'px'), opacity:0.30 } );
		 },
		
		 1000);
