// Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.

//---------------   GLOBAL VARIABLES   ---------------

var helpDoc = MM.HELP_objInsertEntity;

//---------------     API FUNCTIONS    ---------------

function isDOMRequired() { 
	// Return false, indicating that this object is available in code view.
	return false;
}

function commandButtons(){
/*  return new Array(MM.BTN_OK,    'insertChars()',
                   MM.BTN_Cancel,'cleanupUI()',
                   MM.BTN_Help,  'displayHelp()');
*/

// for CT. puts the buttons on the bottom of the dialog rather than
// on the side. -- jcheng bug# 174227

	return new Array( "PutButtonsOnBottom", 
					  "OkButton", MM.BTN_OK, "insertChars()",
				      "CancelButton", MM.BTN_Cancel, "cleanupUI()",
					  "PutButtonOnLeft", MM.BTN_Help,    "displayHelp()");

}


function canAcceptCommand() {
  return true;
}


//---------------    LOCAL FUNCTIONS   ---------------

// function: initUI
// description: initialize UI and other associated preferences
function initUI() {  
}

// function: cleanupUI
// description: 
function cleanupUI() {
  // Exit
  document.entityForm.Insert.childNodes[1].value = '';
  window.close();
}

// function: insertChars
// description: Insert selected character and cleanupUI
// As an Object this command uses the return value in Object tag to insert characters.
function insertChars(curChar) {

  //as a security precaution: if chars looks like code (has < or >), replace <> with entities.
  var val = document.entityForm.Insert.childNodes[1].value;
  if (val && (val.indexOf("<") != -1 || val.indexOf(">") != -1))
  {
    val = val.replace(/</g,"&lt;");
    val = val.replace(/>/g,"&gt;");
    document.entityForm.Insert.childNodes[1].value = val;
  }

  window.close();
}

// function: objectTag
// description: Return inserted value for an Object
function objectTag() {
  // Return the html tag that should be inserted
  return document.entityForm.Insert.childNodes[1].value;
}

//--- Interface Support Functions

// Handles selection and display of choosen character in the form field.
function setChar(curChar) {
  // Add the character to the insertion field.
  document.entityForm.Insert.childNodes[1].value = '&' + curChar + ';';
}
