/******************************************************************************
    Corda Embedder for JavaScript
    CORDA Technologies
    Version 6.0 - Dec 2003
******************************************************************************/

// * definitions

var SVG = "SVG";
var FLASH = "FLASH";
var GIF = "GIF";
var PDF = "PDF";
var PDFCF = "PDF_CF";
var EPS = "EPS";
var WBMP = "WBMP";
var PNG = "PNG"
var TIFF = "TIFF";
var JPEG = "JPEG"
var JPG = JPEG;
var svg = SVG;
var flash = FLASH;
var gif = GIF;
var pdf = PDF;
var eps = EPS;
var wbmp = WBMP;
var png = PNG;
var tiff = TIFF;
var jpeg = JPEG;
var jpg = JPEG;
var LOOSE = "LOOSE";
var loose = LOOSE;
var STRICT = "STRICT";
var strict = STRICT;

var AllowPrinting = 2052;
var AllowModifyContents = 8;
var AllowCopy = 16;
var AllowModifyAnnotations = 32;
var AllowFillIn = 256;
var AllowScreenReaders = 512;
var AllowAssembly = 1024;
var AllowDegradedPrinting = 4;

var AllowView = 0;
var AllowAll = 3900;
var AllowDefaults = 2580;

var CordaMapNumber = 0;				   // specifies unique map number for image maps
var cordaServerAddress = "http://corda.foundationcenter.org:443"


// ************  CordaEmbedder DECLARATION AND CONSTRUCTOR *********************


function CordaEmbedder() {

  // Standard Embedder atrributes
  this.appearanceFile = "";
  this.imageTemplate = "";
  this.bgColor = "";
  this.externalServerAddress = cordaServerAddress;
  this.extraHTMLAttributes = "";
  this.extraCTSCommands = "";
  this.extraPCSCommands = "";
  this.fallback = LOOSE;
  this.height = -1;
  this.htmlHeight = "";
  this.htmlWidth = "";
  this.imageType = "";
  this.outputType = "";
  this.defaultImageType = "FLASH";
  this.language = "EN";
  this.pcScript = "";
  this.returnDescriptiveLink = false;
  this.svgTemplate = "";
  this.useCache = true;
  this.width = -1;

  // Nonstandard Embedder Attributes
  this.border = 0;
  this.description = "";
  this.dLinkTitle = "Description of Chart";
  this.dLinkText = "d";
  this.dLinkNewWindow = false;
  this.linkDescriptionPrefix = "Graph: ";
  this.linkDescription = "";
  this.linkNewWindow = false;
  this.message = "";
  this.paramDelimiter = ",";
  this.seriesDelimiter = ";";
  this.title = "";
  this.controlBarHTML = "&controlbar;";

  // private attributes - Do not set these externally
  this.CordaEmbedderVersion = "7.0";
  this.serverCommands = "";
  this.varAddPCXML = "";
  this.varAddITXML = "";
  this.varloadCommandFile = "";
  this.varloadData = "";
  this.varloadImage = "";
  this.varloadPCXML = "";
  this.varloadITXML = "";
  this.returnMap = false;
  this.varParamTags = "";
  this.outputName = "";

  //Highwire stuff
  this.varloadDoc = "";
  this.varappendDoc = "";
  this.varappendPDF = "";
  this.varPromptToSave = "";
  this.varLinkBehavior = "";
  this.docOrientation = "";
  this.docPageSize = "";
  this.docPageMargins = "";
  this.pdfLock = -1;
  this.userPasswd = "";
  this.ownerPasswd = "";
  this.pdfHighEnc = false;
  this.loadDoc = loadDoc;
  this.setPageSize = setPageSize;
  this.setPageMargins = setPageMargins;
  this.setOrientation = setOrientation;
  this.promptToSave = promptToSave;
  this.lockPDF = lockPDF;
  this.setLinkBehavior = setLinkBehavior;

  // Standard Embedder Methods
  this.addObjectParamTag = addObjectParamTag;
  this.addPCXML = addPCXML;
  this.addITXML = addITXML;
  this.getEmbeddingHTML = getEmbeddingHTML;
  this.getCordaEmbedderVersion = getCordaEmbedderVersion;
  this.loadCommandFile = loadCommandFile;
  this.loadData = loadData;
  this.loadMapData = loadMapData;
  this.loadPCXML = loadPCXML;
  this.loadITXML = loadITXML;
  this.loadFromCordaServer = loadServerSideImage;
  this.loadServerSideImage = loadServerSideImage;
  this.resetPCXML = resetPCXML;
  this.saveToAppServer = saveToAppServer;
  this.saveImageToImageServer = saveToAppServer; 
  this.saveToCordaServer = saveToCordaServer;
  this.saveImageToCordaServer = saveToCordaServer;
  this.setOutputName = setOutputName;
  this.setSVGTemplate = setSVGTemplate;

  // Nonstandard Embedder methods
  this.writeDLink = writeDLink;
  this.writeEmbeddingHTML = writeEmbeddingHTML;
  this.writeEPSObject = writeEPSObject;
  this.writeTIFFObject = writeTIFFObject;
  this.writeFLASHObject = writeFLASHObject;
  this.writeGIFImage = writeGIFImage;
  this.writePDFObject = writePDFObject;
  this.writePNGImage = writePNGImage;
  this.writeJPEGImage = writeJPEGImage;
  this.writeImageLink = writeImageLink;
  this.writeImageLinks = writeImageLinks;
  this.writeSVGObject = writeSVGObject;
  this.writeWBMPImage = writeWBMPImage;
  
  // Unsupported Embedder Methods -- use server-side embedders instead
  this.addHTMLTable = addHTMLTable;
  this.saveImageToAppServer = saveImageToAppServer;
  this.setData = setData;
  this.setDBQuery = setDBQuery;
  this.setMapDBQuery = setMapDBQuery;
  this.setTypedDBQuery = setTypedDBQuery;
  this.setResultSet = setResultSet;
  this.setMapResultSet = setMapResultSet;
  this.setTypedResultSet = setTypedResultSet;
  this.setDoc = setDoc;
  this.getBytes = getBytes;

  // getting Blocks  
  this.getDLink = getDLink;
  this.getImageTag = getImageTag;
  this.getImageMap = getImageMap;
  this.getSVGObject = getSVGObject;
  this.getFLASHObject = getFLASHObject;
  this.getPDFObject = getPDFObject;
  this.getAttList = getAttList;
  this.getImageLink = getImageLink;
  this.getHTTPRequest = getHTTPRequest;
  this.getHTTPRequestInternal = getHTTPRequestInternal;
  this.getPCScript = getPCScript;
  this.getServerCommandString = getServerCommandString;
  this.getTextDescriptionURL = getTextDescriptionURL;
  this.getControlBar = getControlBar;
  this.getImageType = getImageType;
}



// ************  META METHODS **********************************

function getCordaEmbedderVersion() {
   return this.CordaEmbedderVersion;
}

// ************  SERVER-SIDE IMAGE METHODS **********************************

function loadServerSideImage(file) {
   this.varloadImage += "@_LOAD" + file;
}

function saveToCordaServer(file) {
   notSupported("saveToCordaServer");
}

// ************  DATA LOADING METHODS **********************************

function loadData(object,source,method,table,encoding) {
   this.varloadData += object + ".LoadFile(" + source;
   this.varloadData += "," + method;
   this.varloadData += "," + table;
   if (encoding!=null) { this.varloadData += "," + encoding; } 
   this.varloadData += ")";
}

function loadMapData(object,layer,source,table,encoding) {
   this.varloadData += object + ".LoadMapFile(" + layer;
   this.varloadData += "," + source;
   this.varloadData += "," + table;
   if (encoding!=null) { this.varloadData += "," + encoding; }
   this.varloadData += ")";
}

function loadCommandFile(file, encoding) {
   if (encoding != null)
   {
	   this.varloadCommandFile += "@_ENCLOADREQUEST" + encoding + "," + file;
   }
   else
   {
	   this.varloadCommandFile += "@_LOADREQUEST" + file;
   }
}

function loadPCXML(file) {
   this.varloadPCXML += "<PCDELIM>" + file + "</PCDELIM>";
}

function loadITXML(file) {
   this.varloadITXML += "<PCDELIM>" + file + "</PCDELIM>";
}

// ************ ADD PCXML *******************************************************

function addPCXML(pcxml) {
	this.varAddPCXML += "Main.addPCXML(" + pcxml;
	this.varAddPCXML += ")" ;
}
function addITXML(itxml) {
	this.varAddITXML += "Main.addITXML(" + itxml;
	this.varAddITXML += ")" ;
}

function resetPCXML() {
	this.varAddPCXML = "";
	this.varloadPCXML = "";
	this.varAddITXML = "";
	this.varloadITXML = "";
}

// ************ ADD PARAM TAG TO IMAGES EMBEDDED INSIDE AN OBJECT ***************

function addObjectParamTag(name, value) {
   this.varParamTags += "<param name='" + name + "' value='" + value + "' />";
}


// ************ HIGHWIRE METHODS ***************
function loadDoc(docname) {
	this.varloadDoc = docname;
}

function appendDoc(docname, pdf) {
	this.varappendDoc = docname;
	if (pdf != null)
	{
		this.varappendPDF = pdf;
	}
}

function setPageSize(size) {
	this.docPageSize = size;
}

function setPageMargins(size) {
	this.docPageMargins = size;
}

function setOrientation(size) {
	this.docOrientation = size;
}

function lockPDF(upw,opw,opts,enc) {
	if (opts == null) this.pdfLock = AllowDefaults;
	else this.pdfLock = opts;
	if (upw != null) this.userPasswd = upw;
	if (opw != null) this.ownerPasswd = opw;
	if (enc) this.pdfHighEnc = true;
}

function promptToSave(name) {
	this.varPromptToSave = "@_SI";
	if (name != null) this.varPromptToSave += name;
	else this.varPromptToSave += this.outputName;
}

function setLinkBehavior(behave) {
	this.varLinkBehavior = "@_DOC_LINKBEHAVIOR" + behave;
}

function setOutputName(name) {
	this.outputName = name;
	if (name.search(".") == -1) { this.outputName += "." + getImageType().toLowerCase(); }
}

function setSVGTemplate(template) {
	this.svgTemplate = template;
}

// ************ GETS THE OUTPUT TYPE (to compensate for 5.0) ***************

function getImageType() {
   var ret = "";
   if (this.outputType != "") { ret = this.outputType; }
   else if (this.imageType != "") { ret = this.imageType; }
   else if (this.varloadDoc != "") { ret = PDF; }
   else if (this.varappendDoc != "") { ret = PDF; }
   else ret = this.defaultImageType;
   return ret.toUpperCase();
}

// ************  GENERATE THE EMBEDDING HTML **********************************

function writeEmbeddingHTML() {
  document.writeln(this.getEmbeddingHTML());
}

function getEmbeddingHTML() {
  var ret = "";
  this.imageType = this.getImageType();

  // Highwire
  if (this.varloadDoc != "" || this.varappendDoc != "") {
	ret += '<a href="' + this.getHTTPRequest() + '"><img border="0" alt="Generate PDF" src="' + this.externalServerAddress + '/?highwire_icon"/></a>';
  }
  // else PopChart/OptiMap
  else {
	  this.fallback = this.fallback.toUpperCase();

	  // Don't show if EPS or TIFF
	  var show = !(this.imageType == "EPS") && !(this.imageType=="TIFF") && !(this.imageType=="URL");
	
	  if (this.imageType=="URL") {
		ret = this.getHTTPRequest();
	  }
	  else {
		  if (show) {  
		    if ((this.imageType == "PDF") || (this.imageType == "PDF_CF")) ret += this.getPDFObject();
		    else if ((this.imageType == "EPS") || (this.imageType == "EPS_CF")) ret += this.getEPSObject();
		    else if (this.imageType == "WBMP") ret += this.getImageTag("WBMP");
		    else if (this.imageType == "JPEG") ret += this.getImageTag("JPEG");
		    else if (this.imageType == "GIF") ret += this.getImageTag("GIF");
		    else if (this.imageType == "PNG") ret += this.getImageTag("PNG");
		    else if ((this.fallback == "STRICT") || (this.fallback == "LOOSE"))  {
		      if ((this.imageType != "FLASH") && (this.imageType != "PNG") && (hasSVGSupport)) ret += this.getSVGObject();
		      else if ((hasFlash || hasFlash3up) && (this.imageType != "PNG")) ret += this.getFLASHObject();
		      else ret += this.getImageTag("JPEG");
		    }
		    else {
		      if (this.imageType == "SVG") ret += this.getSVGObject();
		      else if (this.imageType == "FLASH") ret += this.getFLASHObject();
		      else if (this.imageType == "PNG") ret += this.getImageTag("PNG");
		      else ret += this.getImageTag("JPEG");
		    }
		    // show descriptive text
		    if (this.returnDescriptiveLink) ret += this.getDLink();
		    // show image map
		    if (this.returnMap) {
				ret += this.getImageMap();
				this.returnMap = false;
				CordaMapNumber++;
		    }
		  }
		  // just create a link.
		  else {
		     ret += this.getImageLink();
		  }
  	  }
  }
  return ret;
}

// ************  GENERATE A LINK TO AN IMAGE ********************************

function writeImageLink() {
     document.writeln(this.getImageLink());
}

function getImageLink() {
     this.imageType = this.getImageType();
     var ret="";
     if ((this.linkNewWindow) && (this.imageType!="EPS") && (this.imageType!="TIFF")) {
	       ret += "<a href=\"" + this.getHTTPRequest() + "\" ";
	       ret += "target=\"CordaWindow\" onclick=\"openWindow('about:blank','CordaWindow','toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,dependent=yes,alwaysRaised=yes";
         tWidth = this.width;
         tHeight = this.height;
         if ((this.imageType == "GIF") || (this.imageType == "PNG") || (this.imageType == "JPEG")) { tWidth += 25; tHeight +=25; }
         if ((this.imageType == "PDF") || (this.imageType == "PDF_CF")) { tWidth = tWidth*1.1; tHeight = tHeight*1.25; }
         if (this.width != -1) ret +=",width=" + tWidth;
         if (this.height != -1) ret +=",height=" + tHeight;
	       ret += "');"
     } 
     else {
             ret += '<a href="' + this.getHTTPRequest();
     }
     var desc;
     if (this.linkDescription != "") desc = this.linkDescription;
     else desc = this.linkDescriptionPrefix + this.title;
     ret += '" title="' + desc + '">' + desc;
     if (this.imageType != "") ret += ' ('+this.imageType+')';
     ret += '</a> ';
     if (this.returnDescriptiveLink) ret += this.getDLink();
     return ret;
}

function writeImageLinks(formatstring) {
   formatstring = formatstring.toUpperCase();

   var TimageType = this.imageType;
   var TreturnDescriptiveLink = this.returnDescriptiveLink;
   this.returnDescriptiveLink = false;
   // Cycle through images and output ones in list.
   if (formatstring.search("SVG") != -1) { this.imageType = "SVG"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>"); }
   if (formatstring.search("FLASH") != -1) { this.imageType = "FLASH"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("PDF") != -1) { this.imageType = "PDF"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("EPS") != -1) { this.imageType = "EPS"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("PDF_CF") != -1) { this.imageType = "PDF_CF"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("EPS_CF") != -1) { this.imageType = "EPS_CF"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("GIF") != -1) { this.imageType = "GIF"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("PNG") != -1) { this.imageType = "PNG"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("JPEG") != -1) { this.imageType = "JPEG"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("TIFF") != -1) { this.imageType = "TIFF"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   if (formatstring.search("WBMP") != -1) { this.imageType = "WBMP"; document.write("<li>"); this.writeImageLink(); document.writeln("</li>");}
   
   this.imageType = TimageType;
   
   // Now handle Text Description     
   this.returnDescriptiveLink = TreturnDescriptiveLink;
   if (this.returnDescriptiveLink) {
     var TdLinkText = this.dLinkText;
     this.dLinkText = "Text Description: ";
     if (this.linkDescription != "") this.dLinkText += this.linkDescription;
     else this.dLinkText += this.title;
     document.write("<li>");
     this.writeDLink();
     document.writeln("</li>");
     this.dLinkText = TdLinkText;
   }
}

// ************  WRITES HTML FOR EMBEDDING AN IMAGE ***********************

function getAttList() {
  var ret="";
  if (this.htmlWidth != "") ret += 'width="'+this.htmlWidth+'" ';
  else if (this.width != -1) ret += 'width="'+this.width+'" ';
  if (this.htmlHeight != "") ret += 'height="'+this.htmlHeight+'" ';
  else if (this.height != -1) ret += 'height="'+this.height+'" ';
  if (this.extraHTMLAttributes != "") ret += this.extraHTMLAttributes + ' ';
  return ret;
}

function writePDFObject() {
  document.writeln(this.getPDFObject());
}

function getPDFObject() {
  var ret = "";
  if (useVBMethod) {
     ret += '<object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" ';
     ret += this.getAttList();
  } else {
     ret += '<embed type="application/pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep.html" ';
     ret += this.getAttList();
  }
  ret += 'alt="'+this.title+'" longdesc="'+this.description+'" border="'+this.border+'" ';
  ret += this.getAttList();
  if (this.extraHTMLAttributes != "") ret += this.extraHTMLAttributes + ' ';
  var ttype = "PDF";
  if (this.imageType.toUppercase == "PDF_CF") { ttype = "PDF_CF"; }
  if (useVBMethod) {
     ret += '>' + this.varParamTags + '<param name="SRC" value="'+this.getHTTPRequestInternal() + '@_' + ttype + '"></object>';
  } else {
     ret += 'src="'+this.getHTTPRequestInternal()+'@_PDF">\n</embed>';
  }
  return ret;
}

function writeEPSObject() {
  document.writeln("<p>EPS Object Output not yet supported");
}

function writeTIFFObject() {
  document.writeln("<p>TIFF Object Output not yet supported");
}

function writeWBMPImage() {
  document.writeln(this.getImageTag("WBMP"));
}

function writeFLASHObject() {
  document.writeln(this.getFLASHObject());
}

function getFLASHObject() {
  var ret = "";
  if (useVBMethod && hasFlash4) {
     ret += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" ';
  } else {
     ret += '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ';
  }
  ret += 'alt="'+this.title+'" longdesc="'+this.description+'" border="'+this.border+'" ';
  ret += this.getAttList();
  if (useVBMethod && hasFlash4) {
     ret += '>' + this.varParamTags + '<param name="MOVIE" value="'+this.getHTTPRequestInternal()+'@_FLASH"></object>';
  } else {
     ret += 'src="'+this.getHTTPRequestInternal()+'@_FLASH">\n</embed>';
  }
  return ret;
}

function writeSVGObject() {
  document.writeln(this.getSVGObject());
}

function getSVGObject() {
  var ret = '<embed alt="'+this.title+'" longdesc="'+this.description+'" border="'+this.border+'" type="image/svg-xml" pluginspage="http://www.adobe.com/svg/viewer/install/main.html" ';
  ret += this.getAttList();
  ret += 'src="'+this.getHTTPRequestInternal()+'@_SVG">\n</embed>';
  return ret;
}

function writeGIFImage() {
  document.writeln(this.getImageTag("GIF"));
}

function writePNGImage() {
  document.writeln(this.getImageTag("PNG"));
}

function writeJPEGImage() {
  document.writeln(this.getImageTag("JPEG"));
}

function getImageTag(imageType) {
  var ret = '<img id="CordaMap' + CordaMapNumber + '" name="CordaMap' + CordaMapNumber + '" alt="'+this.title+'" longdesc="'+this.description+'" border="'+this.border+'" ';
  ret += this.getAttList();
  if (imageType != WBMP) {
        ret += ' usemap="#CordaMap' + CordaMapNumber + '" ';
	this.returnMap = true;
  }
  ret += 'src="'+this.getHTTPRequestInternal()+'@_'+imageType+'" />\n';
  return ret;
}

function getImageMap() {
	var ret = '<' + 'script language="JavaScript" src="' + this.getHTTPRequestInternal() + '@_IMAGEMAPCordaMap' + CordaMapNumber + '"></' + 'script>';
	return ret;
}

// ************  WRITES A LINK FOR A TEXT DESCRIPTION OF THE IMAGE ********

function writeDLink() {
     document.writeln(this.getDLink());
}

function getDLink() {
     var ret = "";
     ret += '<a href="' + this.getTextDescriptionURL();
     if (this.dLinkNewWindow) { 
             ret += '" target="TextDescription" onClick="openWindow(\'about:blank\',';
             ret += "'TextDescription','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,dependent=yes,alwaysRaised=yes,width=400,height=400')";
     }
     ret += '" title="' + this.dLinkTitle + '">' + this.dLinkText + '</a>';
     return ret;
}

function getTextDescriptionURL() {
     var url = this.getHTTPRequestInternal() + '@_TEXTDESCRIPTION' + this.language;
     return url;
}

// ************  BUILD AN HTTP REQUEST FOR AN IMAGE  *********************

function getHTTPRequest() {
  this.imageType = this.getImageType();
  var HTTPRequest = this.getHTTPRequestInternal();
  if (this.imageType != "") HTTPRequest += "@_" + this.imageType;
  return HTTPRequest;
}

function getHTTPRequestInternal() {  
  var HTTPRequest;
  HTTPRequest = this.externalServerAddress + "/" + this.outputName + "?" + this.getServerCommandString();
  return HTTPRequest;
}

function getPCScript() {

  var pcScript = "";
  pcScript += this.varAddPCXML;
  pcScript += this.varloadData;
  if (this.message != "") pcScript += "Main.Message(" + this.message + ")";
  if (this.paramDelimiter != ",") pcScript += "Main.ParamDelimiter(" + this.paramdelimiter + ")";
  if (this.seriesDelimiter != ";") pcScript += "Main.SeriesDelimiter(" + this.seriesdelimiter + ")";
  if (this.returnDescriptiveLink) {
    if (this.title != "") pcScript += "Main.Title(" + this.title + ")";
    if (this.description != "") pcScript += "Main.Description(" + this.description + ")";
  }
  pcScript += this.pcScript;
  return urlEncode(pcScript);

}

function getServerCommandString() {
  
  var commandString = this.serverCommands;

  if (!this.useCache) commandString += "@_DONTCACHE";
  commandString += this.varloadCommandFile;
  commandString += this.varloadImage;
  commandString += this.varPromptToSave;
  commandString += this.varLinkBehavior;
  if (this.extraCTSCommands != "") commandString += this.extraCTSCommands;
  
  //highwire
  if (this.varloadDoc != "" || this.varappendDoc != "") {
	  if (this.varappendDoc != "")
	  {
		  if (this.varappendPDF != "")
		  {
			  commandString += "@_DOC_LOAD_PDF" + this.varappendDoc;
		  }
		  else
		  {
			  commandString += "@_DOC_LOAD" + this.varappendDoc;
		  }
	  }
	  else
	  {
		 commandString += "@_DOC_LOAD" + this.varloadDoc;
	  }
	 // commandString += "@_DOC_LOAD" + this.varloadDoc;
	  if (this.pdfLock != -1) {
		  commandString += "@_LOCK" + this.pdfLock;
		  if (this.userPasswd != "") commandString += "@_UPW" + this.userPasswd;
		  if (this.ownerPasswd != "") commandString += "@_OPW" + this.ownerPasswd;
		  if (this.pdfHighEnc) commandString += "@_ECH";
	  }
	  if (this.docOrientation != "") commandString += "@_DOC_ORIENTATION" + this.docOrientation;
	  if (this.docPageMargins != "") commandString += "@_DOC_PAGEMARGINS" + this.docPageMargins;
	  if (this.docPageSize != "") commandString += "@_DOC_PAGESIZE" + this.docPageSize;
  }
  //optimap and popchart
  else {
	  var pcScript = this.getPCScript();
	  if (this.imageTemplate != "")
	  {
		  commandString += "@_FILE" + this.imageTemplate;
	  }
	  else if (this.appearanceFile != "")
	  {
		  commandString += "@_FILE" + this.appearanceFile;
	  }
	  if (this.varloadPCXML != "") commandString += "@_LOADPCXML" + this.varloadPCXML;
	  if (this.height != -1) commandString += "@_HEIGHT" + this.height;
	  if (this.svgTemplate != "") commandString += "@_USESVGTEMPLATE" + this.svgTemplate;
	  if (this.width != -1) commandString += "@_WIDTH" + this.width;
	  if (this.bgColor != "") commandString += "@_BGCOLOR" + this.bgColor;
	  if (pcScript != "") commandString += "@_PCSCRIPT" + pcScript;
  }
  if (this.outputName != "") commandString += "@_OUTPUTNAME/" + this.outputName;
	
  return commandString;
}

// ************ CONTROL BAR STUFF (not yet supported) **************************************

function getControlBar() {
  var controlBar = this.controlBarHTML;
  var ifwidth,ifheight,width,height,tmp_width,tmp_height;
  if (this.htmlWidth != "") {
	ifwidth=this.htmlWidth;
	width=ifwidth;
	tmp_width = this.width;
	this.width = -1;
  }
  else {
  	if (this.width != -1) width = this.width;
	else width = "540";
	ifwidth = width;
  }
  if (this.htmlHeight != "") {
	ifheight=this.htmlHeight;
	height=ifheight;
	tmp_height = this.height;
	this.height = -1;
  }
  else {
  	if (this.height != -1) height = this.height;
	else height = "540";
	ifheight = height;
  }
  
  var eHTMLString = "javascript:var controlbarfix=true;document.writeln('" + this.getEmbeddingHTML().replace(/\'/g,"\\\'").replace(/\"/g,"\\\'") + "');"
  if ((this.imageType != JPEG) && (this.imageType != PNG) && (this.imageType != GIF) && (this.imageType != "AUTO")) {
    eHTMLString += "document.close();";
  }
  controlBar = controlBar.replace(/&cacheID;@_EHTML/g, eHTMLString);
  controlBar = controlBar.replace(/&cacheID;/g, this.getHTTPRequest());
  controlBar = controlBar.replace(/&iframename;/g, 'CordaFrame' + CordaMapNumber);
  controlBar = controlBar.replace(/&width;/g, width);
  controlBar = controlBar.replace(/&height;/g, height);
  controlBar = controlBar.replace(/&ifwidth;/g, ifwidth);
  controlBar = controlBar.replace(/&ifheight;/g, ifheight);

  if (this.htmlWidth != "") this.width = tmp_width;
  if (this.htmlHeight != "") this.width = tmp_height;

  return controlBar;
}

// ************  URLENCODE FUNCTION ******************************************

function urlEncode(str)
{
	var ms = "%25#23 20+2B?3F<3C>3E{7B}7D[5B]5D|7C^5E~7E`60\"22"
	var msi = 0
	var i,c,rs,ts
	while (msi < ms.length)
	{
		c = ms.charAt(msi)
		rs = ms.substring(++msi, msi +2)
		msi += 2
		i = 0
		while (true)
		{
			i = str.indexOf(c, i)
			if (i == -1) break
			ts = str.substring(0, i)
			str = ts+"%"+rs+str.substring(++i, str.length)
		}
	}
	return str
}

// ********** Miscellanous Functions *****************************************

function openWindow(loc,title,args) {
	newwin = window.open(escapequotes(loc),title,args);
}

function escapequotes(str) {
	return str.replace(/'/gi,"\\'").replace(/"/gi,"\\\"");
}

// ********** Not Supported Functions ****************************************

function notSupported(method) {
	document.writeln("<p><b>Corda Embedder Error:</b>  The server could not generate your image as requested.");
	document.writeln("The <em>" + method + "()</em> method is not supported in the JavaScript version\r\n\r\n of the Corda Embedder.");
        document.writeln("  You should use a server-side version of the Corda Embedder (ASP, JSP, PHP, etc) to take advantage");
	document.writeln(" of this method.  Refer to <a href='http://www.corda.com/devzone/docs/5_0/docs/wwhelp/js/html/frames.htm?frame=/devzone/docs/5_0/docs/web_dev_guide/using_po.htm'>Chapter 2 of the <em>Web Development Guide</em></a> for more information.</p>");
}

function notSupportedHighwire(method) {
	document.writeln("<p><b>Corda Embedder Error:</b>  The server could not generate your document link as requested.");
	document.writeln("The <em>" + method + "()</em> method is not supported in the JavaScript version\r\n\r\n of the Corda Embedder.");
        document.writeln("  You should use a server-side version of the Corda Embedder (ASP, JSP, PHP, etc) to take advantage");
	document.writeln(" of this method.  Refer to <a href='http://www.corda.com/devzone/docs/5_0/docs/wwhelp/js/html/frames.htm?frame=/devzone/docs/5_0/docs/web_dev_guide/using_po.htm'>Chapter 2 of the <em>Web Development Guide</em></a> for more information.</p>");
}

function addHTMLTable() { notSupported("addHTMLTable"); }
function saveImageToAppServer() { notSupported("saveImageToAppServer"); }
function setData() { notSupported("setData"); }
function setDBQuery() {	notSupported("setDBQuery"); }
function setMapDBQuery() {	notSupported("setMapDBQuery"); }
function setTypedDBQuery() {	notSupported("setTypedDBQuery"); }
function setResultSet() { notSupported("setResultSet"); }
function setMapResultSet() { notSupported("setMapResultSet"); }
function setTypedResultSet() { notSupported("setTypedResultSet"); }
function setDoc() {	notSupportedHighwire("setDoc"); }
function getBytes() { notSupported("getBytes"); }
function saveToAppServer() {	notSupported("saveToAppServer"); }

function PopChartEmbedderNotSupported() {
	document.writeln("<p><b>Corda Embedder Error:</b>  The PopChartEmbedder class is no longer supported in CordaServer 6.0.");
	document.writeln("Please update your code to use the CordaEmbedder class.  Refer to your documentation for details.</p>");
}

// ****************** For backwards compatibility *******************

function PopChartEmbedder() {
	this.getEmbeddingHTML = PopChartEmbedderNotSupported;
}


// This code is used to detect the user's browser and the plug-ins that
// are available.  No matter how many Images you have in a page, it
// only needs to run once, so we run it automatically at the end of this
// file.

	var hasSVGSupport = false;
	var hasFlash3up = false;
	var hasFlash = false;
        var hasFlash4 = false;
	var useVBMethod = false;
	var flash_str = "Shockwave Flash";
	if (navigator.mimeTypes != null && navigator.mimeTypes.length > 0) {
		var numPlugins = navigator.plugins.length;
		for (var i = 0; i < numPlugins; i++) {
			var plugin = navigator.plugins[i];
			var numTypes = plugin.length;
			for (var j = 0; j < numTypes; j++) {
				var mimetype = plugin[j];
				if (mimetype) {
					var enabled = "No";
					var enabledPlugin = mimetype.enabledPlugin;
					if (enabledPlugin && (enabledPlugin.name == plugin.name)) enabled = "Yes";
					if (enabled == "Yes") {
						var svgPos = mimetype.type.indexOf("svg");
						if (svgPos != -1) {
							hasSVGSupport = true;
						}
					}
				}
			}
		}
		if (navigator.plugins[flash_str] != null) {
			var pos = navigator.plugins[flash_str].description.search(/\d/);
			var len = navigator.plugins[flash_str].description.length;
			var ver = parseFloat(navigator.plugins[flash_str].description.slice(pos,len));
			if(ver >= 3) {
				hasFlash3up = true;
			}
		}
	} else {
		useVBMethod = true;
	}

// Use VBScript if in MSIE
  
  if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
     document.writeln('    <script language="VBScript">');
     document.writeln('        <!--');
     document.writeln('	          On Error Resume Next');
     document.writeln('	              If useVBMethod = true Then');
     document.writeln('            		hasSVGSupport = IsObject(CreateObject("Adobe.SVGCtl"))');
     document.writeln('            		hasFlash = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash"))');
     document.writeln('               hasFlash4 = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))');
     document.writeln('           	End If');
     document.writeln('        //-->');
     document.writeln('    </script>');
  }