﻿// EMR Resources JScript File

// define fixed resource names, layer names and other values for use by javascript code
var EMR_ACTIVE_LAYER_LABEL = 'Active Layer:';
var EMR_THEMATIC_RESOURCE_NAME = 'Thematic Maps';
var EMR_ENTITY_IDS_RESOURCE_NAME = 'Water Quality';
var EMR_GRAPHIC_RESOURCE_NAME = 'USGS Water Monitoring Stations';
var EMR_GRAPHIC_LAYER_NAMES = ['USGS Surface Water Monitoring Stations', 'USGS Ground Water Monitoring Stations'];
var EMR_GRAPHIC_LAYER_REPORT_ID = 'USGS_1';
var EMR_GRAPHIC_LAYER_REPORT_FILE = 'usgs.xml';
var EMR_GRAPHIC_LAYER_SYMBOL_SURFACE_WATER = 'usgs_surface_water.GIF';
var EMR_GRAPHIC_LAYER_SYMBOL_GROUND_WATER = 'usgs_ground_water.GIF';
var EMR_GRAPHIC_LAYER_MAX_SCALE_DEGREE_MEASURE = 0.4;
var EMR_RESOURCE_NAMES_EXCLUDE_ACTIVATING_LAYERS = "Base Imagery, USA, OverviewMapService, National Wetlands Inventory (NWI)";

// timeouts
var PAGE_LOADING_TIMEOUT = 30000;
var ERROR_MESSAGE_TIMEOUT = 30000;
var timeoutTOCRefresh = 30000; // time in ms to wait before refreshing the TOC
var QUERY_RESULT_TIMEOUT = 120000;

// capture the application's URL
var EMR_URL = document.location.href;
// build the correct URL for the root app
if (document.location.search)
    EMR_URL = EMR_URL.substring(0, EMR_URL.indexOf('?'));
if (EMR_URL.indexOf('.aspx'))
    EMR_URL = EMR_URL.substring(0, EMR_URL.lastIndexOf('/'));

// utility functions
function $(id) {
    return document.getElementById(id);
}
function getRequestParameter(parameterName) {
    var requestString = document.location.search;
    parameterName += "=";
    var value = "";
    if (requestString.length > 0) {
        begin = requestString.indexOf(parameterName);
        if (begin != -1) {
            begin += parameterName.length;
            end = requestString.indexOf("&", begin);
            if (end == -1) {
                end = requestString.length;
            }
            value = unescape(requestString.substring(begin, end));
        }
    }
    return value;
}

// initialize error and message object holders
var EMR_ERRORS = new Object();
var EMR_TEXT = new Object();

// define patterns for input validation
var reZipcode = /^[0-9]{5}$/;
var reWatershedHUC4 = /^[0-9]{4}$/;
var reWatershedHUC8 = /^[0-9]{8}$/;
var reLatLng = /^-?[0-9].*\.?[0-9]*$/;
var reWholeNumber = /^[0-9].*$/;
var reDouble = /^[0-9].*\.?[0-9]*$/;
var reCountycode = /^[0-9]{3}$/;
var reStatecode = /^[A-Z]{2}$/;

// define error object codes and text
EMR_ERRORS.e1001 = "Watershed must be an 8-digit number";
EMR_ERRORS.e1002 = "Zipcode must be a 5-digit number";
EMR_ERRORS.e1003 = "The Program Web Service could not be found. Please contact the System Administrator.";
EMR_ERRORS.e1004 = "The Feature Layer ID is invalid.";
EMR_ERRORS.e1005 = "Unable to Zoom to Geographic Area.";
EMR_ERRORS.e1006 = "The Entity ID is invalid.";
EMR_ERRORS.e1007 = "Map coordinates must be valid latitude/longitude numbers.";
EMR_ERRORS.e1008 = "Too many features returned to display ";
EMR_ERRORS.e1009 = "No Metadata is available for this Layer.";
EMR_ERRORS.e1010 = " layer. You must zoom in further (at least to a zipcode) to view this layer.";
EMR_ERRORS.e1011 = "Map scale radius must be a valid number.";
EMR_ERRORS.e1012 = "Your long-running request has timed out. Please wait a while longer or try your request again.";
EMR_ERRORS.e1013 = "External web service is not responding. Query timed out.";
EMR_ERRORS.e1014 = "Long/Lat must be in decimal degrees";
EMR_ERRORS.e1015 = "County is required";
EMR_ERRORS.e1016 = "State is required";

// define message object codes and text
EMR_TEXT.t1001 = 'Are you sure you want to reload EnviroMapper?';
EMR_TEXT.t1002 = 'Collapse Panels to Enlarge Map';
EMR_TEXT.t1003 = 'Expand Panels';
EMR_TEXT.t1004 = 'Getting Information...';
EMR_TEXT.t1005 = 'It appears that your browser window was resized. It is recommended that you reload EnviroMapper.\n\nDo you wish to reload EnviroMapper?';
EMR_TEXT.t1006 = 'Session has timed out from extended inactivity. You must reload EnviroMapper to establish a new session.\n\nDo you wish to reload EnviroMapper?';
EMR_TEXT.t1007 = 'Loading results from external web service ...';
EMR_TEXT.t1008 = 'Loading results ...';
EMR_TEXT.t1009 = 'Loading results ...';

