////////////////////////////////
// Sélection d'une resource CMS.
////////////////////////////////
function SelectResource(resultId, types)
{
	if(resultId == null)
		return;
	if(types == null)
		types = "";
	var path = "/McmsAgridyne/Pages/ResourceGalleryResourceSelection.aspx";
	var resultIdObj = document.getElementById(resultId);
	path += "?types=" + types;
	path += "&onlyGallery=false";
	
	var currCursor = document.body.style.cursor;
	document.body.style.cursor = "wait";
	var result = window.showModalDialog(path, null, "dialogHeight: 590px; dialogWidth: 795px; edge: Raised; resizable: Yes; status: No;");
	document.body.style.cursor = currCursor;
	
	if(result != null)
		resultIdObj.value = result;	
	else
		resultIdObj.value = "";	
}

//////////////////////////////
// Sélection d'un posting CMS.
//////////////////////////////
function SelectPosting(resultId, templates, currentChannelGuid)
{
	if(resultId == null)
		return;
	if(templates == null)
		templates = "";
	if(currentChannelGuid == null)
		currentChannelGuid = "";
	var path = "/McmsAgridyne/Pages/ChannelPostingSelection.aspx";
	var resultIdObj = document.getElementById(resultId);
	path += "?onlyChannel=false";
	path += "&templates=" + templates;
	path += "&cmsCurrentChannel=" + currentChannelGuid;
	path += "&bothChannelsPostings=false";
	

	var currCursor = document.body.style.cursor;
	document.body.style.cursor = "wait";
	var result = window.showModalDialog(path, null, "dialogHeight: 595px; dialogWidth: 500px; edge: Raised; center: Yes; resizable: Yes; status: No;");
	document.body.style.cursor = currCursor;

	if(result != null)
		resultIdObj.value = result;
	else
		resultIdObj.value = "";
}


//////////////////////////////
// Sélection d'un channel CMS.
//////////////////////////////
function SelectChannel(resultId, currentChannelGuid, showMaxLink, maxLinks)
{
	if(resultId == null)
		return;
	if(currentChannelGuid == null)
		currentChannelGuid = "";
	if(showMaxLink == null)
		showMaxLink = "false";
	if(maxLinks == null)
		maxLinks = "";

	var path = "/McmsAgridyne/Pages/ChannelPostingSelection.aspx";
	var resultIdObj = document.getElementById(resultId);
	path += "?onlyChannel=true";
	path += "&showMaxLink=" + showMaxLink;
	path += "&cmsCurrentChannel=" + currentChannelGuid;
	path += "&bothChannelsPostings=false";	
	if(maxLinks != "")
		path += "&maxLinks=" + maxLinks;	

	var currCursor = document.body.style.cursor;
	document.body.style.cursor = "wait";
	var result = window.showModalDialog(path, null, "dialogHeight: 595px; dialogWidth: 500px; edge: Raised; center: Yes; resizable: Yes; status: No;");
	document.body.style.cursor = currCursor;

	if(result != null)
		resultIdObj.value = result;
	else
		resultIdObj.value = "";			
}

//////////////////////////////////////////////
// Sélection d'un channel ou d'un posting CMS.
//////////////////////////////////////////////
function SelectChannelOrPosting(resultId, currentChannelGuid, showMaxLink, maxLinks)
{
	if(resultId == null)
		return;
	if(currentChannelGuid == null)
		currentChannelGuid = "";
	if(showMaxLink == null)
		showMaxLink = "false";
	if(maxLinks == null)
		maxLinks = "";

	var path = "/McmsAgridyne/Pages/ChannelPostingSelection.aspx";
	var resultIdObj = document.getElementById(resultId);
	path += "?onlyChannel=true";
	path += "&showMaxLink=" + showMaxLink;
	path += "&cmsCurrentChannel=" + currentChannelGuid;
	path += "&bothChannelsPostings=true";	
	if(maxLinks != "")
		path += "&maxLinks=" + maxLinks;	

	var currCursor = document.body.style.cursor;
	document.body.style.cursor = "wait";
	var result = window.showModalDialog(path, null, "dialogHeight: 595px; dialogWidth: 500px; edge: Raised; center: Yes; resizable: Yes; status: No;");
	document.body.style.cursor = currCursor;

	if(result != null)
		resultIdObj.value = result;
	else
		resultIdObj.value = "";			
}


/////////////////////////////////////////////////////
// Gestion des mini modules : sélection d'un channel.
/////////////////////////////////////////////////////
function SelectChannelSpecificParam(resultId)
{
	if(resultId == null)
		return;

	var path = "/McmsAgridyne/Pages/ChannelTreeViewSpecificParams.aspx";
	var resultIdObj = document.getElementById(resultId);

	var currCursor = document.body.style.cursor;
	document.body.style.cursor = "wait";
	var result = window.showModalDialog(path, null, "dialogHeight: 540px; dialogWidth: 650px; edge: Raised; center: Yes; resizable: Yes; status: No;");
	document.body.style.cursor = currCursor;

	if(result != null)
		resultIdObj.value = result;
	else
		resultIdObj.value = "";			
}

/////////////////////////////////////////////
// Demande de confirmation avant suppression.
/////////////////////////////////////////////
function ConfirmDelete(resultId)
{
	if(resultId == null)
		return;
	var resultIdObj = document.getElementById(resultId);
	if(confirm("Confirmez-vous la suppression ?"))
		resultIdObj.value = "true";
	else
		resultIdObj.value = "";
}

/////////////////////////
// Prompt d'une variable.
/////////////////////////
function PromptVariable(promptQuestion, resultId, defaultValue)
{
	if(resultId == null)
		return;
	var resultIdObj = document.getElementById(resultId);
	var answer = prompt(promptQuestion, defaultValue);
	if(answer != null)
		resultIdObj.value = answer;
	else
		resultIdObj.value = "";
}

///////////////////////////
// Fermeture d'une fenêtre.
///////////////////////////
function Close()
{
	window.close();
}


///////////////////////////////
// Handles the enter key press. 
///////////////////////////////
function HandleKeyPress()
{
    // If enter key is pressed then ignore it
    if(window.event.keyCode == 13)
		window.event.keyCode = 0;
}