/**
 * Copyright 2002 Earth Resource Mapping Pty Ltd. This document contains unpublished source code of
 * Earth Resource Mapping Pty Ltd. This notice does not indicate any intention to publish the source
 * code contained herein.
 * 
 * /ecwplugins/lib/Scripts/NCSCreateView.js
 *
 */

function NeedFunction(Functions, nFunction) {
	for (var i = 3; i < Functions.length; i++) {
	  if((typeof(Functions[i]) == "number") && (Functions[i] == nFunction)) {
		return(true);
	  }
	}
	return(false);
}

function GetFunctionParameter(Functions, nFunction) {
	for (var i = 3; i < Functions.length; i++) {
	  if((typeof(Functions[i]) == "number") && (Functions[i] == nFunction) &&
		 (i < Functions.length - 1) && (typeof(Functions[i + 1]) == "string")) {
		return(Functions[i + 1]);
	  } 
	}
	return("");
}

function WriteFunctionParameter(paramNameArray, eFunction, Functions, bParamTags) {
	if(NeedFunction(Functions, eFunction)) {
		sParam = GetFunctionParameter(Functions, eFunction);

		if(bParamTags) {
			document.write("		<param ");
		} else {
			document.write("	");
		}	
		
		if(bParamTags) {
			if(sParam != "") {
				document.write("name=\"" + paramNameArray[eFunction] + "\" value=\"" + sParam + "\"");
			}
		} else {
			if(sParam != "") {
				document.write(paramNameArray[eFunction] + "=\"" + sParam + "\"");
			}
		}
		
		if(bParamTags) {
			document.writeln(">");
		} else {
			document.writeln("");
		}
	}
}

function NCSCreateView() {

	var bIsIEActiveX = false;
	var bNativePlugin = (ECWCheck() == 5) ? false : true;
	
	sName = "ECWView1";
	sWidth = "100%";
	sHeight = "100%";
	
	// if using Java
	if ((bNativePlugin == false) && (navigator.userAgent.indexOf('Netscape'))) {
		sHeight = "99%";
	}
	
	if(NCSCreateView.arguments.length >= 1) {
		sName = NCSCreateView.arguments[0];

		if(NCSCreateView.arguments.length >= 2) {
			sWidth = NCSCreateView.arguments[1];

			if(NCSCreateView.arguments.length >= 3) {
				sHeight = NCSCreateView.arguments[2];
			}
		}
	}
	
	if(bNativePlugin) {
		if(navigator.userAgent.indexOf('MSIE') != -1) {
			// IE, output ActiveX OBJECT tag
			bIsIEActiveX = true;
			document.writeln("	  <OBJECT id=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\" ");
			document.writeln("	  classid=\"" + ECW_ACTIVEX_NCSVIEW_CLASSID + "\" codebase=\"" + ECW_ACTIVEX_CODEBASE + "\""); 
			
		} else {
			// EMBED tag for native Netscape plugin
			document.writeln("	  <EMBED name=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\"");
			document.writeln("	  type=\"" + ECW_NETSCAPE_MIME_TYPE + "\" pluginspage=\"" + ECW_NETSCAPE_PLUGINS_PAGE + "\"");
		}
	} else {
		// Java APPLET tag
		document.writeln("	<APPLET name=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\" hspace=\"0\" vspace=\"0\"");
		document.writeln("	code=\"" + ECW_JAVA_APPLETCLASS + "\" ARCHIVE=\"" + ECW_JAVA_VIEWJARFILE + "\" CODEBASE=\"" + ECW_JAVA_JARCODEBASE + "\" MAYSCRIPT=\"true\" ");
	}
  
	if(NeedFunction(NCSCreateView.arguments, PARAM_VIEW_STYLE)) {
		var sParam = GetFunctionParameter(NCSCreateView.arguments, PARAM_VIEW_STYLE);
		document.write("\n	  style=\"" + sParam + "\"");
	}
	
	// Close the OBJECT tag for IE and APPLET tag for Java
	if(bIsIEActiveX || !bNativePlugin) {
		document.writeln(">");
	}
	
	// Write out param tags for IE and JAVA, but inline params for Netscape
	WriteFunctionParameter(NCSViewParamNames, PARAM_VIEW_ONMOUSEDOWN,		NCSCreateView.arguments, bIsIEActiveX ||!bNativePlugin);
	WriteFunctionParameter(NCSViewParamNames, PARAM_VIEW_ONMOUSEMOVE,		NCSCreateView.arguments, bIsIEActiveX ||!bNativePlugin);
	WriteFunctionParameter(NCSViewParamNames, PARAM_VIEW_ONMOUSEUP, 		NCSCreateView.arguments, bIsIEActiveX ||!bNativePlugin);
	WriteFunctionParameter(NCSViewParamNames, PARAM_VIEW_ONEXTENTCHANGE,	NCSCreateView.arguments, bIsIEActiveX ||!bNativePlugin);
	WriteFunctionParameter(NCSViewParamNames, PARAM_VIEW_ONPERCENTCOMPLETE, NCSCreateView.arguments, bIsIEActiveX ||!bNativePlugin);
	WriteFunctionParameter(NCSViewParamNames, PARAM_VIEW_ONLAYERRESPONSE,	NCSCreateView.arguments, bIsIEActiveX ||!bNativePlugin);
	WriteFunctionParameter(NCSViewParamNames, PARAM_VIEW_ONLOAD,			NCSCreateView.arguments, bIsIEActiveX ||!bNativePlugin);
	WriteFunctionParameter(NCSViewParamNames, PARAM_VIEW_BGCOLOR,			NCSCreateView.arguments, bIsIEActiveX ||!bNativePlugin);

	if(bIsIEActiveX) {
		document.writeln("	  </OBJECT>");
	} else {
		if(bNativePlugin) {
			document.writeln(">");
		} else {
			document.writeln("</APPLET>");
		}
	}
}


function NCSCreateToolbar() {

	var bIsIEActiveX = false;
	var bNativePlugin = (ECWCheck() == 5) ? false : true;

	sName	= "ECWToolbar1";
	sWidth	= "178px";
	sHeight = "30px";

	if(NCSCreateToolbar.arguments.length >= 1) {
		sName = NCSCreateToolbar.arguments[0];
	}
	if(NCSCreateToolbar.arguments.length >= 2) {
		sWidth = NCSCreateToolbar.arguments[1];
	}
	if(NCSCreateToolbar.arguments.length >= 3) {
		sHeight = NCSCreateToolbar.arguments[2];
	}

	if(bNativePlugin) {
		if(navigator.userAgent.indexOf('MSIE') != -1) {
			// IE, output ActiveX OBJECT tag
			document.writeln("	  <OBJECT id=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\"");
			document.writeln("	  classid=\"" + ECW_ACTIVEX_NCSTOOLBAR_CLASSID + "\" codebase=\"" + ECW_ACTIVEX_CODEBASE + "\"");
			bIsIEActiveX = true;
		} else {
			// EMBED tag for native Netscape plugin
			document.writeln("	  <EMBED name=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\"");
			document.writeln("	  type=\"" + ECW_NETSCAPE_TOOLBAR_MIME_TYPE + "\" pluginspage=\"" + ECW_NETSCAPE_PLUGINS_PAGE + "\"");
		}
	} else {
		// Java APPLET tag
		document.writeln("	<APPLET name=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\" hspace=\"0\" vspace=\"0\" cellspacing=2 bgcolor='#ffffff'");
		document.writeln("	code=\"" + ECW_JAVA_TOOLBARCLASS + "\" ARCHIVE=\"" + ECW_JAVA_GUIJARFILE + "\" CODEBASE=\"" + ECW_JAVA_JARCODEBASE + "\" MAYSCRIPT=\"true\">");
	}

	if(NeedFunction(NCSCreateToolbar.arguments, PARAM_TOOLBAR_STYLE)) {
		var sParam = GetFunctionParameter(NCSCreateToolbar.arguments, PARAM_TOOLBAR_STYLE);
		document.write("\n	  style=\"" + sParam + "\"");
	}

	if(bIsIEActiveX) {
		document.writeln(">");
	} else {
		document.writeln("");
	}

	WriteFunctionParameter(NCSToolbarParamNames, PARAM_TOOLBAR_ONHELP,				NCSCreateToolbar.arguments, bIsIEActiveX || !bNativePlugin);
	WriteFunctionParameter(NCSToolbarParamNames, PARAM_TOOLBAR_ONPOINTERMODECHANGE, NCSCreateToolbar.arguments, bIsIEActiveX || !bNativePlugin);
	WriteFunctionParameter(NCSToolbarParamNames, PARAM_TOOLBAR_ONSETEXTENTSALL, 	NCSCreateToolbar.arguments, bIsIEActiveX || !bNativePlugin);
	WriteFunctionParameter(NCSToolbarParamNames, PARAM_TOOLBAR_CELLSPACING,		    NCSCreateToolbar.arguments, bIsIEActiveX || !bNativePlugin);
	WriteFunctionParameter(NCSToolbarParamNames, PARAM_TOOLBAR_BGCOLOR,			    NCSCreateToolbar.arguments, bIsIEActiveX || !bNativePlugin);
	WriteFunctionParameter(NCSToolbarParamNames, PARAM_TOOLBAR_LAYERED,			    NCSCreateToolbar.arguments, bIsIEActiveX || !bNativePlugin);

	if(bIsIEActiveX) {
		document.writeln("	  </OBJECT>");
	} else {
		if(bNativePlugin) {
			document.writeln(">");
		} else {
			document.writeln("</APPLET>");
		}
	}
}

function NCSCreateProgressbar() {

	var bIsIEActiveX = false;
	var bNativePlugin = (ECWCheck() == 5) ? false : true;

	sName	= "ECWProgressbar1";
	sWidth	= "178px";
	sHeight = "30px";

	if(NCSCreateProgressbar.arguments.length >= 1) {
		sName = NCSCreateProgressbar.arguments[0];
	}
	if(NCSCreateProgressbar.arguments.length >= 2) {
		sWidth = NCSCreateProgressbar.arguments[1];
	}
	if(NCSCreateProgressbar.arguments.length >= 3) {
		sHeight = NCSCreateProgressbar.arguments[2];
	}

	if(bNativePlugin) {
		if(navigator.userAgent.indexOf('MSIE') != -1) {
			// IE, output ActiveX OBJECT tag
			document.writeln("	  <OBJECT id=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\"");
			document.writeln("	  classid=\"" + ECW_ACTIVEX_NCSPROGBAR_CLASSID + "\" codebase=\"" + ECW_ACTIVEX_CODEBASE + "\"");
			bIsIEActiveX = true;
		} else {
			// EMBED tag for native Netscape plugin
			document.writeln("	  <EMBED name=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\"");
			document.writeln("	  type=\"" + ECW_NETSCAPE_PROGBAR_MIME_TYPE + "\" pluginspage=\"" + ECW_NETSCAPE_PLUGINS_PAGE + "\"");
		}
	} else {
		// Java APPLET tag
		document.writeln("	<APPLET name=\"" + sName + "\" width=\"" + sWidth + "\" height=\"" + sHeight + "\" hspace=\"0\" vspace=\"0\" cellspacing=2 bgcolor='#ffffff'");
		document.writeln("	code=\"" + ECW_JAVA_PROGBARCLASS + "\" ARCHIVE=\"" + ECW_JAVA_GUIJARFILE + "\" CODEBASE=\"" + ECW_JAVA_JARCODEBASE + "\" MAYSCRIPT=\"true\">");
	}

	if(NeedFunction(NCSCreateProgressbar.arguments, PARAM_PROGBAR_STYLE)) {
		var sParam = GetFunctionParameter(NCSCreateProgressbar.arguments, PARAM_PROGBAR_STYLE);
		document.write("\n	  style=\"" + sParam + "\"");
	}

	if(bIsIEActiveX) {
		document.writeln(">");
	} else {
		document.writeln("");
	}

	WriteFunctionParameter(NCSProgbarParamNames, PARAM_PROGBAR_FGCOLOR, NCSCreateProgressbar.arguments, bIsIEActiveX || !bNativePlugin);
	WriteFunctionParameter(NCSProgbarParamNames, PARAM_PROGBAR_BGCOLOR, NCSCreateProgressbar.arguments, bIsIEActiveX || !bNativePlugin);
	WriteFunctionParameter(NCSProgbarParamNames, PARAM_PROGBAR_SOLID,   NCSCreateProgressbar.arguments, bIsIEActiveX || !bNativePlugin);

	if(bIsIEActiveX) {
		document.writeln("	  </OBJECT>");
	} else {
		if(bNativePlugin) {
			document.writeln(">");
		} else {
			document.writeln("</APPLET>");
		}
	}
}

