/**
 * Copyright 2008 ERDAS, Inc. This document contains unpublished source code of
 * ERDAS, Inc. This notice does not indicate any intention to publish the source
 * code contained herein.
 *
 * /ecwplugins/lib/Scripts/NCSConstants.js
 * Define common constants
 */

// Setup custom EPSG-GDT mappings
// format:
//    EPSG,PROJECTION,DATUM,COMMENTS:EPSG,PROJECTION,DATUM,COMMENTS:...
// The "COMMENTS" are optional
var IWS_CUSTOM_EPSG_GDT_MAPPINGS = "";//"4326,GEODETIC,WGS84:32767,GK3GERM,DHDN,DHDN_Gauss-Kruger_zone_3";

// Setup/update Datum Replacement entries. 
// format:
//    CoordSysEpsdCode1,DatumToBeUsed1,notes1|CoordSysEpsdCode2,DatumToBeUsed2,notes2|....
// Note:
// 1. Each entry must have 3 items separated by a coma;
// 2. The separators between entries is "|" and "," between items in each entry;
// 3. this provide method to overwrite existing datum replacements in EprjDatumChanges.xml;
// 4. The following sample string shows the format only.
var IWS_EXTRA_DATUM_SHIFTS_ENTRIES = ""; //"EPSG:20356,AGD84 (NTv2),Replacing default Australian Geodetic 1984 with AGD84 (NTv2).|EPSG:23029,European 1950 (Spain Iberian Peninsula) (NTv2),";

// Setup/update coordinate system based datum shifts.
// Format:
//    "CoordSysEpsdCode1,CoordSysEpsdCode2,datum1,datum2,notes|CoordSysEpsdCode1,CoordSysEpsdCode2,datum1,datum2,notes"
// 1. Each entry must have 5 items separated by a comma.;
// 2. If there is no change to a datum, have a space in between two commas
// 2. The separators between entries is "|" and "," between items in each entry;
// 3. this provide method to overwrite existing datum shifts in EprjDatumChanges.xml;
// 4. The following sample string shows the format only.
var IWS_EXTRA_COORDSYS_DATUM_SHIFTS_ENTRIES = ""; //"EPSG:20356,EPSG:28356, ,AGD84 (NTv2),comment|EPSG:23029,EPSG:25829,European 1950 (Spain Iberian Peninsula) (NTv2),,comment";


// When IWS_LIMIT_TO_ENVELOPE is true, the program uses envelopes of source, target and datum shifts involved to limit the extents on the target
// coordinate system. The result will generally be to limit that content but with better accuracy. Whereas when it is false, the program will try to reproject
// any system to any others without guarantee the correctness and accuracy.
var IWS_LIMIT_TO_ENVELOPE = true;

//
// Constants
//
var IMAGE_WEB_SERVER_VERSION	   = "11,0,2,33"
var IMAGE_WEB_SERVER_VERSION_DOT   = "11.0.2.33"

var IMAGE_WEB_SERVER_RELEASE       = "2011"
var ECW_NETSCAPE_MIME_TYPE		   = "application/x-ImageWebServer2-ecw"
var ECW_NETSCAPE_TOOLBAR_MIME_TYPE = "application/x-ImageWebServer-toolbar"
var ECW_NETSCAPE_PROGBAR_MIME_TYPE = "application/x-ImageWebServer-progressbar"
var ECW_NETSCAPE_REG_NAME		   = "plugins/IWS/ImageViewer"
var ECW_NETSCAPE_PLUGINS_PAGE	   = "/ecwplugins/DownloadPlugin.htm"

var ECW_ACTIVEX_NAME			   = "NCSViewManager.NCSLayeredView.1"
var ECW_ACTIVEX_CODEBASE		   = "/ecwplugins/DownloadPlugin.htm"
var ECW_ACTIVEX_NCSVIEW_CLASSID    = "clsid:D147430C-86CD-4E6F-A807-93FBC496D201"
var ECW_ACTIVEX_NCSTOOLBAR_CLASSID = "clsid:79E46020-ED4B-447A-B191-AD2A63AF51A1"
var ECW_ACTIVEX_NCSPROGBAR_CLASSID = "clsid:584719E2-015C-438F-A012-0085270F8E63"
											
var ECW_JAVA_VIEWJARFILE		   = "JNCSViewS.jar,JNCSGDT.jar"
var ECW_JAVA_GUIJARFILE 		   = "JNCSGui.jar"
var ECW_JAVA_JARCODEBASE		   = "/ecwplugins"
var ECW_JAVA_APPLETCLASS		   = "com.ermapper.view.JNCSViewApplet.class"
var ECW_JAVA_TOOLBARCLASS		   = "com.ermapper.gui.JNCSToolbarApplet.class"
var ECW_JAVA_PROGBARCLASS		   = "com.ermapper.gui.JNCSProgressbarApplet.class"
var ECW_JAVA_VM_CLASSID			   = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
var ECW_JAVA_VM_APPLET_TYPE		   = "application/x-java-applet;version=1.4"
var ECW_JAVA_VM_IE_CODEBASE		   = "http://java.sun.com/update/1.6.0/jinstall-6u1-windows-i586-jc.cab#Version=6,0,010,6"
var ECW_JAVA_VM_NS_CODEBASE		   = "http://java.sun.com/products/plugin/index.html#download"

// Pointer Modes
var PM_ROAM    = 0;
var PM_ZOOM    = 1; 
var PM_POINTER = 2;
var PM_ZOOMBOX = 3;

// Geolink Modes
var GM_NONE    = 0;
var GM_WINDOW  = 1;
var GM_SCREEN  = 2;

// Mouse event callback masks
var MVK_CONTROL = 8;
var MVK_LBUTTON = 1;
var MVK_MBUTTON = 16;
var MVK_RBUTTON = 2;
var MVK_SHIFT = 4;

// Function parameter definitions for the ECWView ActiveX/Netscape/applet
var PARAM_VIEW_NONE 				  = 0;
var PARAM_VIEW_STYLE				  = 1;
var PARAM_VIEW_ONMOUSEDOWN			  = 2;
var PARAM_VIEW_ONMOUSEMOVE			  = 3;
var PARAM_VIEW_ONMOUSEUP			  = 4;
var PARAM_VIEW_ONEXTENTCHANGE		  = 5;
var PARAM_VIEW_ONPERCENTCOMPLETE	  = 6;
var PARAM_VIEW_ONPOINTERMODECHANGE	  = 7;
var PARAM_VIEW_ONLAYERRESPONSE		  = 8;
var PARAM_VIEW_ONLOAD				  = 9;
var PARAM_VIEW_BGCOLOR				  = 10;
var PARAM_VIEW_ONDRAWBEGIN			  = 11;
var PARAM_VIEW_ONDRAWEND			  = 12;
var PARAM_VIEW_WINDOWLESS			  = 13;
var PARAM_VIEW_ONERROR				  = 14;
var PARAM_VIEW_ONGEOLINKMODECHANGE	  = 15;
var NCSViewParamNames = new Array("", "", "onMouseDown", "onMouseMove", "onMouseUp", "onExtentChange", "onPercentComplete", "onPointerModeChange", "onLayerResponse", "onLoad", "bgcolor", "onDrawBegin", "onDrawEnd", "windowless", "onError", "onGeolinkModeChange");

// Error codes
var ERROR_CONNECTION_LOST             = 75;
var ERROR_ECWP_POLLING                = 114;
var ERROR_SET_EXTENTS_ERROR           = 92;
var ERROR_INCOMPATIBLE_COORDINATE_SYSTEMS = 67;
var ERROR_SUCCESS                     = 0;

// Function parameter definitions for the ECWToolbar ActiveX/Netscape/applet
var PARAM_TOOLBAR_NONE				  = 0;
var PARAM_TOOLBAR_STYLE 			  = 1;
var PARAM_TOOLBAR_ONPOINTERMODECHANGE = 2;
var PARAM_TOOLBAR_ONSETEXTENTSALL	  = 3;
var PARAM_TOOLBAR_ONHELP			  = 4;
var PARAM_TOOLBAR_CELLSPACING		  = 5;
var PARAM_TOOLBAR_BGCOLOR			  = 6;
var PARAM_TOOLBAR_LAYERED			  = 7;
var NCSToolbarParamNames = new Array("", "", "onPointerModeChange", "onSetExtentsAll", "onHelp", "cellSpacing", "bgcolor", "layeredToolbar");

// Function parameter definitions for the ECWPROGBAR ActiveX/Netscape/applet
var PARAM_PROGBAR_NONE				  = 0;
var PARAM_PROGBAR_STYLE 			  = 1;
var PARAM_PROGBAR_BGCOLOR			  = 2;
var PARAM_PROGBAR_FGCOLOR			  = 3;
var PARAM_PROGBAR_SOLID 			  = 4;
var NCSProgbarParamNames = new Array("", "", "bgcolor", "fgcolor", "solid");

//Copyright notice
function WriteCopyright() {
	document.writeln("©1999-2011 <A href='http://www.erdas.com' target=_blank>ERDAS, Inc.</A>");
}

// Set a cookie in the browser
function setCookie(name, value) {
	setCookieIntern(name, value, null, null, null, null);
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments

function setCookieIntern(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//
// Check if coolies are enabled
//
function cookiesEnabled( ) {
	var oldCookie = document.cookie;
	var bIsEnabled = true;
    document.cookie = "test=cookiesEnabled";
    var pos = document.cookie.indexOf( "test=" );
    if( pos == -1 ) {
        bIsEnabled = false;
    }
    document.cookie = oldCookie;
    return bIsEnabled;
}

// This object is used as a color list
function NCSColorList() {
}

