// ----------------------------------------------------------------------------
//
//	File: SelectionFrame.js
//
//	Description: For JavaScript support in the Selection (bottom) frame of the
//				Internal Links dialog.
//
// ----------------------------------------------------------------------------

// these have to match the definitions in InternalProgrammingConstants.inc
var IDS_FORM_OBJECT_URL = "NC_intxtObjectURL";
var IDS_FORM_OBJECT_EXISTING_URL = "NC_intxtObjectExistingURL";

var IDS_NO_SEL = "No Internal Link has been selected.";

var g_pChannelNameForm = null;
var g_bIsIEModal = false;

// ---- [Public] For handling Body onLoad event
function WBC_onLoadHandler( bIsIEModal )
{
	// cache whether the dialog is brought up by IE's showModalDialog or
	// just regular JavaScript window.open
	g_bIsIEModal = bIsIEModal;
	
	// set default return value of showModalDialog() case to be "Cancel"
	if (g_bIsIEModal)
	{
		window.top.returnValue = "Cancel";
	}
}

// ---- [Public] For external code to set the Link selection input field
function WBC_setLinkSelectionField( strURL )
{
	document.NC_ChannelNameForm[IDS_FORM_OBJECT_URL].value = strURL;
}

// ---- [Public] Responds to OK button event
function WBC_onOkayClicked()
{
	var strURL = document.NC_ChannelNameForm[IDS_FORM_OBJECT_URL].value;
	
	if ( strURL == "" )
	{
		alert(IDS_NO_SEL)
		return false;
	}
	else
	{
		// two ways to return URL value
		if (g_bIsIEModal)
		{
			window.top.returnValue = strURL;
		}
		else
		{
			// call SetHLink() function in opener window to set new HLink value
			var pFuncWin = WBC_getFuncWin("WBC_SetHLink", window.top.parent.opener);
			if (pFuncWin == null) {
				alert(IDS_FUNCTION_NOT_FOUND);
			} else {
				window.top.opener.WBC_SetHLink(strURL);
			}
		}
		window.top.close();
	}
}
	
// ---- [Public] Responds to Cancel button event
function WBC_onCancelClicked()
{
	// set Return value for IE window.showModalDialog() caller
	if (g_bIsIEModal)
	{
		window.top.returnValue = "Cancel";
	}

	window.top.close();
}


