// Copyright 2006 Adobe Macromedia Software LLC and its licensors. All rights reserved.

var HELP_DOC = MM.HELP_cmdSpryDesignTimeFeed;

var _dataSetName = null;
var _designTimeFeed = null;
var _dynamicFeed = null;

//*************************API**************************

//--------------------------------------------------------------------
// FUNCTION:
//   commandButtons
//
// DESCRIPTION:
//   Returns the array of buttons that should be displayed on the
//   right hand side of the dialog.  The array is comprised
//   of name, handler function name pairs.
//
// ARGUMENTS:
//   none
//
// RETURNS:
//   array of strings - name, handler function name pairs
//--------------------------------------------------------------------

function commandButtons()
{                          
   return new Array( MM.BTN_OK,     "okClicked()",
                     MM.BTN_Cancel, "window.close()",
                     MM.BTN_Help,   "displayHelp()");

}

//--------------------------------------------------------------------
// FUNCTION:
//   okClicked
//
// DESCRIPTION:
//   Sets the return value to the selected DSN and closes the window.
//
// ARGUMENTS:
//   none
//
// RETURNS:
//   nothing
//--------------------------------------------------------------------

function okClicked()
{
  var retVal = new Array();
  var designTimeSchemaURI = _designTimeFeed.value;
  if (designTimeSchemaURI && designTimeSchemaURI.length)
  {
	ajaxUtils.setDesignTimeSchemaURI(_dataSetName,designTimeSchemaURI);
	//set the return value
    dwscripts.setCommandReturnValue("true");
  }
  else
  {
	//remove the design time schema uri
	ajaxUtils.removeDesignTimeSchemaURI(_dataSetName);
	//set the return value
    dwscripts.setCommandReturnValue("true");
  }
  window.close();
}

//--------------------------------------------------------------------
// FUNCTION:
//   cancelClicked
//
// DESCRIPTION:
//   Closes the window and returns nothing
//
// ARGUMENTS:
//   none
//
// RETURNS:
//   nothing
//--------------------------------------------------------------------

function cancelClicked()
{
  dwscripts.setCommandReturnValue("");
  window.close();
}


//--------------------------------------------------------------------
// FUNCTION:
//   browseForXMLFile
//
// DESCRIPTION:
//   browse for the xml file
//
// ARGUMENTS:
//	 none
//
// RETURNS:
//   nothing
//--------------------------------------------------------------------
function browseForDesignTimeFile()
{
	var LABEL_XMLFILTER = "XML (*.xml)|*.xml|XML|";
    var theXMLFilter	= new Array(LABEL_XMLFILTER);
	var fileName = dw.browseForFileURL("select",dw.loadString("XMLXSL_SB/SelectXML"),false,false,theXMLFilter);
	if (fileName) 
	{
		_designTimeFeed.value = fileName;
	}
}



//--------------------------------------------------------------------
// FUNCTION:
//   initializeUI
//
// DESCRIPTION:
//   This function is called in the onLoad event.  It is responsible
//   for initializing the UI.  If we are inserting a recordset, this
//   is a matter of populating the connection drop down.
//
//   If we are modifying a recordset, this is a matter of inspecting
//   the recordset tag and setting all the form elements.
//
// ARGUMENTS:
//   none
//
// RETURNS:
//   nothing
//--------------------------------------------------------------------
function initializeUI()
{
  _designTimeFeed = dwscripts.findDOMObject("designTimeFeed"); 
  _dynamicFeed    = dwscripts.findDOMObject("dynamicFeed"); 
  var cmdArgs = dwscripts.getCommandArguments();
  if (cmdArgs && cmdArgs.length)
  {
	//get the xml source and xpath reference
	_dataSetName = cmdArgs[0];
	var dynamicFeedSrc = "(" + cmdArgs[1] + ")";
	_dynamicFeed.innerHTML = dynamicFeedSrc;		
	//set the design Time Src using the design notes API
	var designTimeSrc = ajaxUtils.getDesignTimeSchemaURI(_dataSetName);
	_designTimeFeed.value = designTimeSrc;

  }
}

//--------------------------------------------------------------------
// FUNCTION:
//   setAppServer
//
// DESCRIPTION:
//	  launches the app server section of site definition dialog
//
//
// ARGUMENTS:
//   none
//
// RETURNS:
//   nothing
//--------------------------------------------------------------------
function setAppServer()
{
	site.showTestingServerSettings();
}




//--------------------------------------------------------------------
// FUNCTION:
//   displayHelp
//
// DESCRIPTION:
//   Displays the built-in Dreamweaver help.
//
// ARGUMENTS:
//   none
//
// RETURNS:
//   nothing
//--------------------------------------------------------------------
function displayHelp()
{
  // Replace the following call if you are modifying this file for your own use.
	dwscripts.displayDWHelp(HELP_DOC);
}
