var dccServiceName = 'basedata';
var dccNotice = false; 				// No copyright/logo by default - if set then also set next...
var dccNoticePage = "";
var dccHBar = false; 				// Horizonal toolbar
var dccLegend = false; //= parent.dccLegend;		// Legend below layers list
var dccGrid = false; 				// Should probably check the map service for grid layers
var dccLegendOnly = false;
var dccRadioLayers; 					// Show only one of these at a time
var dccGroupLayers; 					// Group these together - work in progress as of 6Dec05
var dccLayerOptions;
var dccGroupName;
var dccAlwaysVisible; 				// An array of layers that must always be visible
var dccCentreX;
var dccCentreY;
var dccPostcode;

//--------------------------------------------------------------------------------------------
// Set to true so 'active' selector disappears.  This is for use when there only one layer
// should be visible at a time.  It should also force other layers invisible.
// Note that the mapservice should have only one visible layer defined.
//--------------------------------------------------------------------------------------------
var dccVisibleIsActive = false;
var dccMinScale = 20;
var dccMaxScale = 2000000;
var dccTitle = "Devon County Council - GIS";
var dccTextFrame = "text.htm";
var dccActiveLayerID = "";
var dccParams = parent.document.location.search;
var dccNewLayer = "";
var dccShowThemeSelector = false; 	// Pull down theme layer
var astrSplit = document.URL.split("/");
var dccSiteName = astrSplit[3];
var dccLayerIDs = null; 	// Initially for LMA codes - only show layers with these IDs (array of strings, aimsMap.js)

//*** Print parameters ***
var dccForceScale = false; 		// Allows user to set the print scale
var dccForcedScale = "1500"; 	// ... the setting... e.g. 10000 for 1:10000
var dccPrintScalar = "lowest"; 	// Image quality
var dccPrintTicks = false;
var dccPrintScale = true; 	// Show scale on map when true
var dccPrintFormat = "portrait";
var dccPrintSize = "A4";
var dccPrintLegend = true;
var dccPrintParms = new Array();

var strArray = dccParams.substr(1).split('&'); // Extract the URL parms - skipping the '?' on the start
for (var ix = 0; ix < strArray.length; ix++) {
    var strFix = strArray[ix]; // ToDo: Rework...	
    strArray[ix] = strArray[ix].toLowerCase();
    if (strArray[ix].substr(0, 11) == "dccservice=") {
        dccServiceName = strArray[ix].substr(11);
    } else if (strArray[ix].substr(0, 12) == "activelayer=") {
        dccActiveLayerID = strArray[ix].substr(12);
    } else if (strArray[ix].substr(0, 9) == "addlayer=") {
        dccNewLayer = strArray[ix].substr(9);
    } else if (strArray[ix].substr(0, 6) == "title=") {
        // Title override like this will only work if site title isn't specified below...
        dccTitle = unescape(strFix.substr(6));
    }
}
// dccHBar == false: standard ArcIMS layout, == true: horizontal bar and legend/layer on left
// dccLegend == false: standard ArcIMS layout, == true: legend is shown below the layer list
//			layer/legend selector should disappear and legend shown at startup
if (dccServiceName == "terrier") {
    //alert("Service change");
    //dccServiceName = "basedata";
}
switch (dccServiceName) {
    case 'llmf':
        dccGrid = false;
        dccTitle = "Themes of the Culm";
        dccShowThemeSelector = false;
        dccActiveLayerID = "9";
        break;

    case 'basedata':
    case 'basetest':
        dccGrid = true;
        dccActiveLayerID = "NatParks";
        dccShowThemeSelector = true;
        break;

    case 'childrenstrust':
        dccGrid = true;
        dccActiveLayerID = "AXS Networks";
        dccShowThemeSelector = true;
        dccTitle = "Children's Trust";
        dccMinScale = 5000;
        break;

    case 'datawright':
        dccGrid = true;
        dccActiveLayerID = "Sites";
        dccShowThemeSelector = false;
        break;
    case 'devonadmin':
        dccActiveLayerID = "District";
        dccTitle = "Administrative Areas of Devon";
        dccMinScale = 3000;
        dccShowThemeSelector = true;
        dccRadioLayers = new Array(0, 1, 2, 3, 4, 5);
        break;
    case 'election2005':
        dccGrid = true;
        dccActiveLayerID = "NewElectoralDiv";
        dccTitle = "Electoral Divisions 2005";
        dccMinScale = 5000;
        break;
    case 'environ':
        dccGrid = true;
        dccActiveLayerID = "Accidents3";
        dccShowThemeSelector = true;
        dccTitle = "Environment Dept.: Accidents & Bridges";
        dccPrintLegend = false;
        break;
    case 'hlc':
        dccGrid = true;
        dccActiveLayerID = "Modern HLC";
        dccShowThemeSelector = true;
        dccTitle = "Historic Landscape Characterisation";
        dccPrintLegend = false;
        dccMinScale = 5000;
        dccMaxScale = 200000;
        dccNotice = true; // This gets the DCC logo frame + the following ...
        dccNoticePage = "noticeHLC.htm";
        dccRadioLayers = new Array(2, 3, 4, 5, 6);
        dccTextFrame = "textHLC.htm";
        break;
    case 'her':
        dccGrid = true;
        dccActiveLayerID = "HERMonuments";
        dccShowThemeSelector = false;
        dccTitle = "Devon County Council Historic Environment Record";
        dccPrintLegend = false;
        dccMinScale = 2500;
        //dccMaxScale = 200000;
        dccNotice = true; // This gets the DCC logo frame + the following ...
        dccNoticePage = "noticeHER.htm";
        //dccRadioLayers = new Array(2,3,4);
        dccTextFrame = "textHER.htm";

        dccGroupName = "Group";
        // Selection groups group multiple layers as a single theme
        //                             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
        dccSelectionGroups = new Array(0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        dccSelectionGroupNames = new Array("Background", "HER Monuments", "HER Events", "Scheduled Monuments", "Listed Buildings", "Parks & Gardens", "Protected Wrecks", "World Heritage Sites");
        //                             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
        dccRadioGroups = new Array(0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        break;
    case 'historic':
        dccTitle = "Devon County Council - Historic Maps";
        dccGrid = true;
        dccActiveLayerID = "NatParks";
        dccShowThemeSelector = true;
        break;

    case 'greeninfra':
        dccGrid = true;
        dccShowThemeSelector = true;
        dccTitle = "Green Infrastructure in Devon";
        dccMinScale = 2500;
        dccTextFrame = "textGreenInfra.htm"
        break;

    case 'footpath':
    case 'footpathgradient':
    case 'footpathnew':
        dccGrid = true;
        dccActiveLayerID = "ProwLines";
        dccShowThemeSelector = true;
        dccTitle = "Where you can walk, ride and cycle in Devon";
        dccMinScale = 1000;
        dccNotice = true;
        //dccRadioLayers = new Array(5,6,7,8,9,10);
        dccNoticePage = "noticePROW.htm";
        dccGroupName = "Show stiles, gates and bridges";
        dccTextFrame = "textPROW.htm"

        //                             0   1   2   3   4   5   6   7   8   9   0   1   2   3   4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
        dccLayerOptions = new Array(0, 0, 'a', 'a', 'a', 1, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        //                             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
        dccRadioGroups = new Array(0, 0, 0, 0, 0, 1, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

        // Selection groups group multiple layers as a single theme, e.g. styles+gates+bridges layers are group 1 with title 'PROW Furniture'
        //                             0  1  2  3  4  5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
        dccSelectionGroups = new Array(0, 0, 1, 1, 1, 2, 0, 2, 2, 2, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        dccSelectionGroupNames = new Array("Background", "PROW Furniture", "DEFRA Stewardship Sites", "Access Land & Dartmoor Commons", "Cycleways");
        break;

    case 'prowsection31':
        dccGrid = true;
        dccActiveLayerID = "section31";
        dccShowThemeSelector = true;
        dccTitle = "Highways Act 1980 Section 31(6) Deposits";
        dccMinScale = 1000;
        dccNotice = true;
        //dccRadioLayers = new Array(5,6,7,8,9,10);
        dccNoticePage = "noticePROW.htm";
        dccGroupName = "Show stiles, gates and bridges";
        dccTextFrame = "textPROW.htm"

        //                          0  1   2   3   4   5   6   7   8   9   0   1   2   3   4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
        dccLayerOptions = new Array(0, 0, 'a', 'a', 'a', 1, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        //                         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
        dccRadioGroups = new Array(0, 0, 0, 0, 0, 1, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

        // Selection groups group multiple layers as a single theme, e.g. styles+gates+bridges layers are group 1 with title 'PROW Furniture'
        //                             0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8 9 0 1 2 3 4 5 6 7 8
        dccSelectionGroups = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        dccSelectionGroupNames = new Array("Background");
        break;
        
    case 'prows14':
        dccGrid = true;
        dccActiveLayerID = "Prows14";
        dccShowThemeSelector = true;
        dccTitle = "Rights of Way - Schedule 14 Applications";
        dccMinScale = 5000;
        dccNotice = true;
        dccRadioLayers = new Array(2, 99); // A single-value array will be converted to a scalar so use 99 as a dummy entry
        dccNoticePage = "noticePROW.htm";
        dccTextFrame = "textPROWS14.htm"
        //dccGroupLayers = new Array(2);
        //dccGroupName = "Applications";
        break;

    case 'paiinfo':
        dccGrid = true;
        dccActiveLayerID = "grid1kmover";
        dccShowThemeSelector = true;
        dccTitle = "OS Positional Accuracy Improvement";
        break;
    //case 'footpath': 
    case 'footpathaerial':
        dccGrid = true;
        dccActiveLayerID = "ProwLines";
        dccNotice = true;
        dccNoticePage = "noticePROW.htm";
        dccTitle = "Where you can walk or ride in Devon";
        dccMinScale = 5000;
        //dccLegend = true;
        dccLegendOnly = true;
        dccShowThemeSelector = true;
        break;
    case 'primarycaretrust':
    case 'pcttemp':
        dccTitle = "DCC and Health Authority Property Locations-Demo";
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        dccActiveLayerID = "PCTSite";
        dccAlwaysVisible = new Array(10, 99);
        //dccRadioLayers = new Array(4,5,6,7,8,9,10,11,12,13);
        //dccGroupLayers = new Array(2,3);
        //dccGroupName = "PCT Sites and Properties";
        break;
    case 'rick':
        //dccNotice = true;
        //dccNoticePage = "noticePROW.htm";
        dccGrid = true;
        dccLegend = false;
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        dccPrintScalar = "best";
        break;

    case 'floodplain':
        /*		dccLegend = true;		dccTitle = "Floodplains";
        dccShowThemeSelector = true;		break;*/
    case 'floodzone':
    case 'floodmap':
        dccTitle = "Environment Agency Flood Map (DCC use only)";
        dccShowThemeSelector = true;
        dccGrid = true;
        break;
    case 'depriv':
        dccTitle = "Deprivation by area";
        dccMinScale = 5000;
        dccLegend = true;
        dccVisibleIsActive = true;
        dccShowThemeSelector = true;
        break;

    case 'schoolsplusone': 		// Note the axl file for this is school_designation_plusone.axl
        dccTitle = "School Designated Area Maps (2012-13)";
        dccActiveLayerID = "PSDesig";
        dccTextFrame = "text_schools.htm";
        dccGrid = false;
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        break;

    case 'schools': 		// Note the axl file for this is school_designation.axl
    case 'schoolsdetail':   // Note the axl file for this is schools_internal.axl
        dccTitle = "School Designated Area Maps (2011-12)";
        dccActiveLayerID = "PSDesig";
        //dccLegend = true;
        dccTextFrame = "text_schools.htm";
        dccGrid = false;
        //dccLegendOnly = true;
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        break;

    case 'schoolswalking':
        //dccActiveLayerID = "unsafe";
        dccActiveLayerID = "PSDesig";
        dccTitle = "CYPS - School Walked Routes";
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        dccPrintScalar = "best";
        break;

    case 'instow':
        dccActiveLayerID = "bomb";
        dccShowThemeSelector = true;
        break;
        
    case 'terrier':
        dccTitle = "Property Terrier";
        dccShowThemeSelector = true;
        dccPrintScalar = "best";
        dccActiveLayerID = "TParish";
        break;

    case 'watchdog':
        dccGrid = true;
        dccActiveLayerID = "Watchdog";
        dccShowThemeSelector = true;
        break;
    case 'capital':
        dccTitle = "Capital Program"
        dccActiveLayerID = "CAP1";
        dccShowThemeSelector = true;
        //dccLegend = true;
        dccShowThemeSelector = true;
        dccPrintScalar = "best";
        break;
    case 'capitalreceipts':
        dccTitle = "Predicted Capital Receipts for the next 5 years"
        dccActiveLayerID = "1";
        //dccLegend = true;
        dccShowThemeSelector = true;
        dccPrintScalar = "best";
        break;
    case 'exeterhighways':
        dccGrid = true;
        dccActiveLayerID = "ECC_Land_region";
        dccShowThemeSelector = true;
        dccTitle = "Exeter Highway Records"
        break;
    case 'internetproperty':
        dccTitle = "Devon County Property Estate"
        dccActiveLayerID = "1";
        dccLegend = true;
        dccLegendOnly = true;
        break;
    case 'pupils':
        dccTitle = "Pupil Postcodes";
        dccActiveLayerID = "PupPost";
        dccShowThemeSelector = true;
        break;
    case 'property':
        dccActiveLayerID = "1";
        dccTitle = "Buildings Information";
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        dccPrintScalar = "best";
        break;
    case 'propertycc':
        dccActiveLayerID = "vwcalling";
        dccTitle = "Property Maintenance Contracts";
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        dccPrintScalar = "best";
        dccMinScale = 500;
        break;
    case 'roadsafety':
        dccActiveLayerID = "RoadSafety";
        dccTitle = "School Travel Plan Maps";
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        dccPrintScalar = "best";
        dccMinScale = 500;
        break;
    case 'mobilelibraries':
        dccActiveLayerID = "MobLib";
        dccTitle = "Mobile Libraries";
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        dccPrintScalar = "best";
        break;
    case 'trams':
    case 'tramsmap':
    case 'tramstest':
        dccActiveLayerID = "pups";
        dccTitle = "Transport Management System Mapping";
        dccShowThemeSelector = true;
        dccPrintLegend = false;
        dccPrintScalar = "best";
        break;
    default:
        dccTitle = "Devon County Council GIS";
        dccActiveLayerID = "NatParks";
        break;
}

// **** Overrides for all services *****
if (!parent.dccInternal) {
    switch (dccServiceName) {
        case "footpath": 		// Has group layers
        case "hlc": 				// Has group layers
        case "primarycaretrust": // Has must-be-visible layer(s)
        case "greeninfra":           // Has TOC.htm code to enforce PRoW visible
        case "roadsafety": 		// Temporary allow
            break; // Allow these services to show a layer selector
        default:
            dccLegendOnly = true;
            break;
    }
    dccShowThemeSelector = false;
}

if (parent.dccProtected) {
    dccShowThemeSelector = false;
}

// -----------------------------
function openDCCAttributePage() {
    var docObject = parent.MapFrame;
    var docName = "parent.MapFrame";
    if (!useTextFrame) docName = "opener.parent.MapFrame";
    var Win1;
    setLayerFields(ActiveLayerIndex);
    var str = '<html><meta http-equiv="Content-Type" content="text/html; charset=' + docObject.charSet + '">';
    str += '<head>';
    str += '<link rel="stylesheet" href="/dcc.css" type="text/css" media="screen">';
    str += '<title>' + docObject.titleList[7] + '</title>';
    str += '</head>';

    dccAttributeWin = open("", "SearchResults", "width=600,height=460,scrollbars=yes,resizable=yes");
    dccAttributeWin.document.open();
    dccAttributeWin.document.writeln(str);
}

function closeDCCAttributePage() {
    dccAttributeWin.document.writeln("</body></html>");
    dccAttributeWin.document.close();
}

