//***************************************************************************************
// This file contains all the javascript that is used to manage modules by template pages
//***************************************************************************************

//***************************************************************************************
//***************************************************************************************
// This section contains the AJax funtions..
//
// The move up and down options as well as the delete option use AJax to request the 
// change once the server has made the change the page is reloaded to reflect the change.
//***************************************************************************************
//***************************************************************************************
var RequestObj = null;

//_______________________________________________________________________________________
// Process the response from the Server page that handels the Ajax request. If the 
// request was successful then the page is reloaded.
function processAjaxResponse()
{
	if (ajaxIsRequestGood(RequestObj))
	{
		var response = 	RequestObj.responseText;
		
		switch (response)
		{
			case "ReloadPage":
				window.location = window.location;
			break;
		}
	}
}

//_______________________________________________________________________________________
// Requests the module to be moved either up or down
function sendMoveModuleRequest(Direction,PageID,ModuleID)
{
	// Send ajax request to move HTML Control
	RequestObj = ajaxInitializeRequestObject();
	RequestObj.onreadystatechange = processAjaxResponse;
	
	RequestObj.open("GET","/Admin/Modules/ManageModules.aspx?Action=Move"
															+ "&Direction=" + Direction
															+ "&PageID=" + PageID 
															+ "&PageModuleID=" + ModuleID 
															+ "&TS=" + new Date() ,true);
	RequestObj.send(null);
}

//_______________________________________________________________________________________
// Confirms that the user wants to delete the conrol if they do sends Delete Request.
function sendDeleteModuleRequest(PageID,ModuleID)
{
	if (window.confirm('Are you sure you want to delete this module ?'))
	{
		// Send ajax request to Delete HTML Control
		RequestObj = ajaxInitializeRequestObject();
		RequestObj.onreadystatechange = processAjaxResponse;
		
		RequestObj.open("GET","/Admin/Modules/ManageModules.aspx?Action=Delete"
																+ "&PageID=" + PageID 
																+ "&PageModuleID=" + ModuleID 
																+ "&TS=" + new Date() ,true);
		RequestObj.send(null);
	}
}

//_______________________________________________________________________________________
// Calls the show popup and is used to change the users Edit Rights for the control.
function showSecurityRights(PageID,PageModuleID)
{
	showPopup('250px','150px',"/Admin/Modules/ManageModule_IFrame.aspx?Action=Security&PageModuleID=" + PageModuleID + "&PageID=" + PageID);
}

//_______________________________________________________________________________________
// Calls the show popup and is used to change the users View Rights for the control.
function showSecurityViewRights(PageID,PageModuleID)
{
	showPopup('250px','150px',"/Admin/Modules/ManageModule_IFrame.aspx?Action=securityview&PageModuleID=" + PageModuleID + "&PageID=" + PageID);
}

//_______________________________________________________________________________________
// Calls the move page that allows the user to move a module to another page.
function showMove(PageID,PageModuleID)
{
	showPopup('350px','115px',"/Admin/Modules/ManageModule_IFrame.aspx?Action=Move&PageModuleID=" + PageModuleID + "&PageID=" + PageID);
}

//_______________________________________________________________________________________
// Allows the user to add a new or existing module to the page.
// This funtion is called from a link buttion that is added by the Default.aspx page.
function showAddModule(PageID,ContentSectionID)
{
	showPopup('500px','160px',"/Admin/Modules/ManageModule_IFrame.aspx?Action=Add&ContentSectionID=" + ContentSectionID + "&PageID=" + PageID);
}

//_______________________________________________________________________________________
// Allows the user to Edit the module details badly named should be somthing like 
// Edit module details as there can be confustion with the Module content edit option.
function showEditModule(PageID,PageModuleID)
{
	showPopup('275px','120px',"/Admin/Modules/ManageModule_IFrame.aspx?Action=Edit&PageModuleID=" + PageModuleID + "&PageID=" + PageID);
}