/*
* **************************************************************************
lp.js
Interactive Local Plan
Braintree District Council
Ver 1.0
Lovell Johns Ltd.
11/05
****************************************************************************
*/

//*********************GLOBALS
// Insert output from 'js_navrray.txt' below		
//Set up the array for required info about each inset maps.
//Map name,origin X of overview inset frame,origin Y of overview inset frame,width of overview inset frame,blx of map grid,bly of map grid,trx of map grid,try of map grid,Grid Size,Grid Overlap,no. of rows,no. of cols
var theinsetsmaps = new Array (67)
var nofInsets = 67;
theinsetsmaps[0] = new Array("inset_03",574328,241839,743.172,574400,241800,575100,242700,300,100,4,3);
theinsetsmaps[1] = new Array("inset_04",581070,237400,400,581100,237400,581600,237900,300,100,2,2);
theinsetsmaps[2] = new Array("inset_05",579900,241295,900,579900,241500,580800,242000,300,100,2,4);
theinsetsmaps[3] = new Array("inset_06",578814,241837,885.875,578800,241900,579700,242600,300,100,3,4);
theinsetsmaps[4] = new Array("inset_07",581650,240200,500,581700,240200,582200,240700,300,100,2,2);
theinsetsmaps[5] = new Array("inset_09",580233,222500,737.344,580300,222500,581000,223400,300,100,4,3);
theinsetsmaps[6] = new Array("inset_12",583800,239833,900,583800,239900,584700,240800,300,100,4,4);
theinsetsmaps[7] = new Array("inset_13",584405,238646,887.578,584400,238600,585300,239700,300,100,5,4);
theinsetsmaps[8] = new Array("inset_15",577618,235006,1437.31,577600,235200,579100,236300,300,100,5,7);
theinsetsmaps[9] = new Array("inset_16",584128,221667,2143.09,584400,221600,586100,223900,300,100,11,8);
theinsetsmaps[10] = new Array("inset_17",584354,229940,1070.25,584300,230100,585600,231000,300,100,4,6);
theinsetsmaps[11] = new Array("inset_18",567992,236135,536.531,568000,236100,568700,236800,300,100,3,3);
theinsetsmaps[12] = new Array("inset_19",578905,220331,813.234,579000,220300,579700,221200,300,100,4,3);
theinsetsmaps[13] = new Array("inset_21",584158,226319,742.063,584100,226400,585000,227100,300,100,3,4);
theinsetsmaps[14] = new Array("inset_22",584556,228000,1889,584800,227900,586300,230000,300,100,10,7);
theinsetsmaps[15] = new Array("inset_23",586055,228000,1700,586100,227900,587800,229800,300,100,9,8);
theinsetsmaps[16] = new Array("inset_25",568138,232347,834.891,568100,232300,569000,233200,300,100,4,4);
theinsetsmaps[17] = new Array("inset_26",583252,244425,522.375,583200,244400,583900,244900,300,100,2,3);
theinsetsmaps[18] = new Array("inset_27",580740,237944,1055.52,581000,237900,581700,239000,300,100,5,3);
theinsetsmaps[19] = new Array("inset_28",577294,228840,1919.1,577200,229000,579300,230700,300,100,8,10);
theinsetsmaps[20] = new Array("inset_29",566763,229709,1641.86,567000,229700,568300,231400,300,100,8,6);
theinsetsmaps[21] = new Array("inset_30",580393,233776,1150.28,580500,233700,581400,235000,300,100,6,4);
theinsetsmaps[22] = new Array("inset_31",569595,225000,1100,569700,225000,570600,226100,300,100,5,4);
theinsetsmaps[23] = new Array("inset_32",575397,237500,1455.61,575600,237500,576700,239000,300,100,7,5);
theinsetsmaps[24] = new Array("inset_33",581881,227662,838.313,582000,227600,582700,228500,300,100,4,3);
theinsetsmaps[25] = new Array("inset_36",578400,210750,1900,578400,211000,580300,212500,300,100,7,9);
theinsetsmaps[26] = new Array("inset_37",564600,241159,882,564600,241300,565500,242000,300,100,3,4);
theinsetsmaps[27] = new Array("inset_39",588749,235432,524.125,588700,235400,589400,236100,300,100,3,3);
theinsetsmaps[28] = new Array("inset_40",582420,233648,1046.69,582400,233800,583500,234700,300,100,4,5);
theinsetsmaps[29] = new Array("inset_41",577512,239157,742.938,577600,239100,578300,240000,300,100,4,3);
theinsetsmaps[30] = new Array("inset_42",578600,238782,400,578600,238800,579100,239100,300,100,1,2);
theinsetsmaps[31] = new Array("inset_43",579500,210004,1051.81,579500,210100,580600,211000,300,100,4,5);
theinsetsmaps[32] = new Array("inset_45",584748,232874,1351.75,584700,233000,586200,234100,300,100,5,7);
theinsetsmaps[33] = new Array("inset_47",573242,240500,864.781,573300,240500,574200,241400,300,100,4,4);
theinsetsmaps[34] = new Array("inset_50",571739,228769,779.203,571700,228700,572600,229600,300,100,4,4);
theinsetsmaps[35] = new Array("inset_51",571978,227900,735,572100,227900,572600,228800,300,100,4,2);
theinsetsmaps[36] = new Array("inset_52",577107,233445,1755,577400,233400,578700,235300,300,100,9,6);
theinsetsmaps[37] = new Array("inset_53",580163,218917,1576.98,580100,219000,581800,220500,300,100,7,8);
theinsetsmaps[38] = new Array("inset_54",570400,238561,673,570400,238700,571100,239200,300,100,2,3);
theinsetsmaps[39] = new Array("inset_55",571915,238300,538.656,571900,238300,572600,239000,300,100,3,3);
theinsetsmaps[40] = new Array("inset_56",567300,240600,1100,567300,240600,568400,241700,300,100,5,5);
theinsetsmaps[41] = new Array("inset_57",579619,224521,745.484,579700,224500,580400,225400,300,100,4,3);
theinsetsmaps[42] = new Array("inset_58",569112,243475,972.905,569100,243600,570200,244500,300,100,4,5);
theinsetsmaps[43] = new Array("inset_60",575850,214148,1850.06,575800,214400,577700,215700,300,100,6,9);
theinsetsmaps[44] = new Array("inset_61",576078,239800,348.328,576000,239800,576500,240300,300,100,2,2);
theinsetsmaps[45] = new Array("inset_62",573500,236800,800,573600,236800,574300,237700,300,100,4,3);
theinsetsmaps[46] = new Array("inset_63",570428,229971,1972.19,570400,230200,572500,231700,300,100,7,10);
theinsetsmaps[47] = new Array("inset_64",578141,217900,800,578100,217900,579000,218800,300,100,4,4);
theinsetsmaps[48] = new Array("inset_65",582682,236100,834.922,582800,236100,583500,237000,300,100,4,3);
theinsetsmaps[49] = new Array("inset_14",589988,233400,800,590000,233400,590900,234300,300,100,4,4);
theinsetsmaps[50] = new Array("inset_24",586087,218900,1747.5,586300,218800,587600,220700,300,100,9,6);
theinsetsmaps[51] = new Array("inset_38",585247,217700,1911.81,585500,217700,587000,219800,300,100,10,7);
theinsetsmaps[52] = new Array("inset_34",580144,229000,3214.19,580000,228000,583250,232750,1000,250,6,4);
theinsetsmaps[53] = new Array("inset_01",572241,219879,7121.5,573000,219000,579250,227500,1000,250,11,8);
theinsetsmaps[54] = new Array("inset_02",579580,212400,5381.72,580000,212000,584750,218250,1000,250,8,6);
theinsetsmaps[55] = new Array("inset_35",580673,230000,1200,580700,230000,582000,231300,300,100,6,6);
theinsetsmaps[56] = new Array("inset_08",576195,219820,1126.07,576200,219800,577300,221100,300,100,6,5);
theinsetsmaps[57] = new Array("inset_10",575300,222509,1039.38,575300,222600,576400,223500,300,100,4,5);
theinsetsmaps[58] = new Array("inset_11",575517,223400,1043.95,575600,223400,576500,224500,300,100,5,4);
theinsetsmaps[59] = new Array("inset_20",577494,220278,1171.56,577600,220200,578500,221500,300,100,6,4);
theinsetsmaps[60] = new Array("inset_44",572900,224803,1097.13,572900,225000,574000,225700,300,100,3,5);
theinsetsmaps[61] = new Array("inset_46",572286,222200,1000,572300,222200,573200,223300,300,100,5,4);
theinsetsmaps[62] = new Array("inset_48",582565,217200,558.828,582500,217200,583200,217900,300,100,3,3);
theinsetsmaps[63] = new Array("inset_49",583484,216342,515.75,583400,216400,584100,216900,300,100,2,3);
theinsetsmaps[64] = new Array("inset_66",581263,213800,1695,581600,213800,582700,215500,300,100,8,5);
theinsetsmaps[65] = new Array("inset_59",567042,243371,1857.56,567000,243900,568900,244600,300,100,3,9);
theinsetsmaps[66] = new Array("proposals",556500,207000,41000,562000,207000,593000,248000,3000,1000,20,15);

// ^^^^Insert output from 'js_navarray.txt' above ^^^^^^^^^

//*********************BROWSER CHECKING
// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4, 
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//     is_sun, is_sun4, is_sun5, is_suni86
//     is_irix, is_irix5, is_irix6
//     is_hpux, is_hpux9, is_hpux10
//     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//     is_linux, is_sco, is_unixware, is_mpras, is_reliant
//     is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater") 
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1); 

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) is_js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (is_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 || 
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) || 
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||   
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || 
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || 
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);    
    var is_aix2  = (agt.indexOf("aix 2") !=-1);    
    var is_aix3  = (agt.indexOf("aix 3") !=-1);    
    var is_aix4  = (agt.indexOf("aix 4") !=-1);    
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1); 
    var is_mpras    = (agt.indexOf("ncr")!=-1); 
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || 
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || 
                 is_sco ||is_unixware || is_mpras || is_reliant || 
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

//***********END OF BROWSER CHECK

//*********Image click (Overview map page > main mappping) This functionality only works for IE and Opera
function gotoMainMap(e){

	//Get the current overview image.
	var cmdString = String(document.location.search);
	var theName = cmdString.substring(1,cmdString.length);		
		
	//Define the current overview.	
	for(i=0;i<nofInsets;i++){														
		if(theName.toUpperCase() == theinsetsmaps[i][0].toUpperCase()){
			var useIndex = i;
		}
	}
	
	var imageWidth = 400; 																		//Width of opening overview image in pixels
	var pixpermetre =  theinsetsmaps[useIndex][3] / imageWidth;
	var origTLY = theinsetsmaps[useIndex][2] + theinsetsmaps[useIndex][3];						//Make origin top left

	//Get user clicked location x,y (pixels).
	var theX = event.offsetX;			
	var theY =  event.offsetY;

	//Convert to real world metres.
	theX = Number(theX) * pixpermetre;	
	theY = Number(theY) * pixpermetre; 
	theX =  theinsetsmaps[useIndex][1] + theX;
	theY =  origTLY - theY;

	//Define if user has clicked in the map area
	var outSideX = "false";
	var outSideY = "false";
	
	if((theX >= theinsetsmaps[useIndex][6]) | (theX <= theinsetsmaps[useIndex][4])){
		outSideX = "true";		
	}
	if((theY >= theinsetsmaps[useIndex][7]) | (theY <= theinsetsmaps[useIndex][5])){
		outSideY = "true";
	}

	//Define the new map image to load in.
	if((outSideX == "true") | (outSideY == "true")){			
		//alert("outside the area")
	}
	else{
		var distx = theX - theinsetsmaps[useIndex][4];
		var disty = theY - theinsetsmaps[useIndex][5];
		
		var gridcnt = theinsetsmaps[useIndex][8];
  		var thecol = 1; 
		while (gridcnt < distx){
			thecol = thecol + 1;
			gridcnt = gridcnt + (theinsetsmaps[useIndex][8] - theinsetsmaps[useIndex][9]);
		}	
 
		var gridcnt = theinsetsmaps[useIndex][8];
  		var therow = 1;  
		while (gridcnt < disty){
			therow = therow + 1;
			gridcnt = gridcnt + (theinsetsmaps[useIndex][8] - theinsetsmaps[useIndex][9]);
		}			
		
		var theTileNo =  ((therow -1) * theinsetsmaps[useIndex][11]) + thecol;

		//Adjust the tile number to agree with the standard "###"
		if(theTileNo < 10){
			theTileNo = "00" + theTileNo;
		}
		else if(theTileNo < 100){
			theTileNo = "0" + theTileNo;
		}
		else{
			theTileNo = String(theTileNo);
		}

		var theNewHTML = "map_htm/" + theName + "/" + theName + "_" + theTileNo + ".htm";
		//Open the selected tile in same window
 		eval("parent.location='" + theNewHTML + "'");
	}
	
}


//*********Open the main mapping -centre image called from overview map page. This functionality only works for IE and Opera
//vvv Insert pre- generated code below (js_openmapatcentre.txt) vvv
function openMapAtCentre(theMap,source){
	var newMap;
	if(theMap.toLowerCase() == "ashen"){
	  newMap = "map_htm/inset_03/inset_03_008.htm";
	}
	else if(theMap.toLowerCase() == "audley end"){
	  newMap = "map_htm/inset_04/inset_04_001.htm";
	}
	else if(theMap.toLowerCase() == "belchamp otten"){
	  newMap = "map_htm/inset_05/inset_05_006.htm";
	}
	else if(theMap.toLowerCase() == "belchamp st paul"){
	  newMap = "map_htm/inset_06/inset_06_006.htm";
	}
	else if(theMap.toLowerCase() == "belchamp walter"){
	  newMap = "map_htm/inset_07/inset_07_003.htm";
	}
	else if(theMap.toLowerCase() == "bradwell"){
	  newMap = "map_htm/inset_09/inset_09_008.htm";
	}
	else if(theMap.toLowerCase() == "bulmer"){
	  newMap = "map_htm/inset_12/inset_12_007.htm";
	}
	else if(theMap.toLowerCase() == "bulmer tye"){
	  newMap = "map_htm/inset_13/inset_13_007.htm";
	}
	else if(theMap.toLowerCase() == "castle hedingham"){
	  newMap = "map_htm/inset_15/inset_15_018.htm";
	}
	else if(theMap.toLowerCase() == "coggeshall"){
	  newMap = "map_htm/inset_16/inset_16_044.htm";
	}
	else if(theMap.toLowerCase() == "colne engaine"){
	  newMap = "map_htm/inset_17/inset_17_003.htm";
	}
	else if(theMap.toLowerCase() == "cornish hall end"){
	  newMap = "map_htm/inset_18/inset_18_005.htm";
	}
	else if(theMap.toLowerCase() == "cressing"){
	  newMap = "map_htm/inset_19/inset_19_005.htm";
	}
	else if(theMap.toLowerCase() == "earls colne airfield"){
	  newMap = "map_htm/inset_21/inset_21_006.htm";
	}
	else if(theMap.toLowerCase() == "earls colne and white colne west"){
	  newMap = "map_htm/inset_22/inset_22_033.htm";
	}
	else if(theMap.toLowerCase() == "earls colne and white colne east"){
	  newMap = "map_htm/inset_23/inset_23_036.htm";
	}
	else if(theMap.toLowerCase() == "finchingfield"){
	  newMap = "map_htm/inset_25/inset_25_010.htm";
	}
	else if(theMap.toLowerCase() == "foxearth"){
	  newMap = "map_htm/inset_26/inset_26_005.htm";
	}
	else if(theMap.toLowerCase() == "gestingthorpe"){
	  newMap = "map_htm/inset_27/inset_27_010.htm";
	}
	else if(theMap.toLowerCase() == "gosfield"){
	  newMap = "map_htm/inset_28/inset_28_035.htm";
	}
	else if(theMap.toLowerCase() == "great bardfield"){
	  newMap = "map_htm/inset_29/inset_29_027.htm";
	}
	else if(theMap.toLowerCase() == "great maplestead"){
	  newMap = "map_htm/inset_30/inset_30_018.htm";
	}
	else if(theMap.toLowerCase() == "great saling"){
	  newMap = "map_htm/inset_31/inset_31_010.htm";
	}
	else if(theMap.toLowerCase() == "great yeldham"){
	  newMap = "map_htm/inset_32/inset_32_018.htm";
	}
	else if(theMap.toLowerCase() == "greenstead green"){
	  newMap = "map_htm/inset_33/inset_33_005.htm";
	}
	else if(theMap.toLowerCase() == "hatfield peverel"){
	  newMap = "map_htm/inset_36/inset_36_032.htm";
	}
	else if(theMap.toLowerCase() == "helions bumpstead"){
	  newMap = "map_htm/inset_37/inset_37_006.htm";
	}
	else if(theMap.toLowerCase() == "lamarsh"){
	  newMap = "map_htm/inset_39/inset_39_005.htm";
	}
	else if(theMap.toLowerCase() == "little maplestead"){
	  newMap = "map_htm/inset_40/inset_40_013.htm";
	}
	else if(theMap.toLowerCase() == "little yeldham"){
	  newMap = "map_htm/inset_41/inset_41_005.htm";
	}
	else if(theMap.toLowerCase() == "north end"){
	  newMap = "map_htm/inset_42/inset_42_001.htm";
	}
	else if(theMap.toLowerCase() == "nounsley"){
	  newMap = "map_htm/inset_43/inset_43_013.htm";
	}
	else if(theMap.toLowerCase() == "pebmarsh"){
	  newMap = "map_htm/inset_45/inset_45_018.htm";
	}
	else if(theMap.toLowerCase() == "ridgewell"){
	  newMap = "map_htm/inset_47/inset_47_006.htm";
	}
	else if(theMap.toLowerCase() == "shalford"){
	  newMap = "map_htm/inset_50/inset_50_010.htm";
	}
	else if(theMap.toLowerCase() == "shalford (church end)"){
	  newMap = "map_htm/inset_51/inset_51_004.htm";
	}
	else if(theMap.toLowerCase() == "sible hedingham"){
	  newMap = "map_htm/inset_52/inset_52_027.htm";
	}
	else if(theMap.toLowerCase() == "silver end"){
	  newMap = "map_htm/inset_53/inset_53_028.htm";
	}
	else if(theMap.toLowerCase() == "stambourne chapel end way"){
	  newMap = "map_htm/inset_54/inset_54_002.htm";
	}
	else if(theMap.toLowerCase() == "stambourne dyers end"){
	  newMap = "map_htm/inset_55/inset_55_005.htm";
	}
	else if(theMap.toLowerCase() == "steeple bumpstead"){
	  newMap = "map_htm/inset_56/inset_56_013.htm";
	}
	else if(theMap.toLowerCase() == "stisted"){
	  newMap = "map_htm/inset_57/inset_57_005.htm";
	}
	else if(theMap.toLowerCase() == "sturmer east"){
	  newMap = "map_htm/inset_58/inset_58_008.htm";
	}
	else if(theMap.toLowerCase() == "terling"){
	  newMap = "map_htm/inset_60/inset_60_025.htm";
	}
	else if(theMap.toLowerCase() == "tilbury juxta clare"){
	  newMap = "map_htm/inset_61/inset_61_001.htm";
	}
	else if(theMap.toLowerCase() == "toppesfield"){
	  newMap = "map_htm/inset_62/inset_62_008.htm";
	}
	else if(theMap.toLowerCase() == "wethersfield"){
	  newMap = "map_htm/inset_63/inset_63_035.htm";
	}
	else if(theMap.toLowerCase() == "white notley"){
	  newMap = "map_htm/inset_64/inset_64_007.htm";
	}
	else if(theMap.toLowerCase() == "wickham st paul"){
	  newMap = "map_htm/inset_65/inset_65_005.htm";
	}
	else if(theMap.toLowerCase() == "bures hamlet"){
	  newMap = "map_htm/inset_14/inset_14_010.htm";
	}
	else if(theMap.toLowerCase() == "feering"){
	  newMap = "map_htm/inset_24/inset_24_027.htm";
	}
	else if(theMap.toLowerCase() == "kelvedon"){
	  newMap = "map_htm/inset_38/inset_38_046.htm";
	}
	else if(theMap.toLowerCase() == "halstead town"){
	  newMap = "map_htm/inset_34/inset_34_015.htm";
	}
	else if(theMap.toLowerCase() == "braintree and bocking"){
	  newMap = "map_htm/inset_01/inset_01_050.htm";
	}
	else if(theMap.toLowerCase() == "witham"){
	  newMap = "map_htm/inset_02/inset_02_033.htm";
	}
	else if(theMap.toLowerCase() == "halstead town centre"){
	  newMap = "map_htm/inset_35/inset_35_021.htm";
	}
	else if(theMap.toLowerCase() == "black notley"){
	  newMap = "map_htm/inset_08/inset_08_008.htm";
	}
	else if(theMap.toLowerCase() == "braintree town centre"){
	  newMap = "map_htm/inset_10/inset_10_008.htm";
	}
	else if(theMap.toLowerCase() == "braintree bradford street"){
	  newMap = "map_htm/inset_11/inset_11_010.htm";
	}
	else if(theMap.toLowerCase() == "cressing (tye green)"){
	  newMap = "map_htm/inset_20/inset_20_011.htm";
	}
	else if(theMap.toLowerCase() == "panfield"){
	  newMap = "map_htm/inset_44/inset_44_008.htm";
	}
	else if(theMap.toLowerCase() == "rayne"){
	  newMap = "map_htm/inset_46/inset_46_010.htm";
	}
	else if(theMap.toLowerCase() == "rivenhall"){
	  newMap = "map_htm/inset_48/inset_48_005.htm";
	}
	else if(theMap.toLowerCase() == "rivenhall end"){
	  newMap = "map_htm/inset_49/inset_49_002.htm";
	}
	else if(theMap.toLowerCase() == "witham town centre"){
	  newMap = "map_htm/inset_66/inset_66_018.htm";
	}
	else if(theMap.toLowerCase() == "sturmer west and helions bumpstead north"){
	  newMap = "map_htm/inset_59/inset_59_011.htm";
	}
	else if(theMap.toLowerCase() == "proposals map"){
	  newMap = "map_htm/proposals/proposals_158.htm";
	}
	else{
	  newMap = "";
	}
	
	//Go to map location
	if(newMap != ""){
	  if(source == "propmap"){
				  newMap = "../../" + newMap;
	  }
	  eval("parent.location='" + newMap + "'");
	}
}
//^^^Insert pre- generated code above ^^^

//*********Image click (Map index page map > overview map ) This functionality only works for IE and Opera
function openOverview(e){

	//Set-up
	var imageWidth = 400; 								//Width of main overview image in pixels
	var imageHeight = 400; 								//Width of main overview image in pixels

	var tileWidth = 41000; 								//Width of main overview image in metres
	var tileHeight = 41000;								//Width of main overview image in metres
	var pixpermetreX =  tileWidth /imageWidth;
	var pixpermetreY =  tileHeight /imageHeight;

	var tileOriginX = 556500;							//Origin of main overview image in ground metres
	var tileOriginY = 207000;	
	
	tileOriginY = tileOriginY + tileHeight; 			//Make origin top left

	//Get user clicked location x,y (pixels).
	var theX = event.offsetX			
	var theY = event.offsetY

	//Convert to real world metres.
	theX = Number(theX) * pixpermetreX;	
	theY = Number(theY) * pixpermetreY; 
	theX =  tileOriginX + theX;
	theY =  tileOriginY - theY;
	
	//Check if the user clicked in an inset map area.		
	for(i=0;i<nofInsets;i++){
		
		//Define extent of each inset map area
		ovblx = theinsetsmaps[i][4]; 
		ovbly = theinsetsmaps[i][5]; 
		ovtrx = theinsetsmaps[i][6];
		ovtry = theinsetsmaps[i][7];
		var outSideX = "false";
		var outSideY = "false";
				
		if((theX >= ovtrx) | (theX <= ovblx)){
			outSideX = "true";		
		}
		if((theY >= ovtry) | (theY <= ovbly)){
			outSideY = "true";
		}

		if((outSideX == "false") & (outSideY == "false")){			//User has clicked within an inset map						
			var distx = theX - ovblx;
			var disty = theY - ovbly;
			
			var gridcnt = theinsetsmaps[i][8];
			var thecol = 1;
			while (gridcnt < distx){
				thecol = thecol + 1;
				gridcnt = gridcnt + (theinsetsmaps[i][8] - theinsetsmaps[i][9]);  
			}	
	 
			var gridcnt = theinsetsmaps[i][8];
			var therow = 1;  
			while (gridcnt < disty){
				therow = therow + 1;
				gridcnt = gridcnt + (theinsetsmaps[i][8] - theinsetsmaps[i][9]);  
			}			
			
			var theTileNo =  ((therow -1) * theinsetsmaps[i][11]) + thecol;

			//Adjust the tile number to agree with the standard "###"
			if(theTileNo < 10){
				theTileNo = "00" + theTileNo;
			}
			else if(theTileNo < 100){
				theTileNo = "0" + theTileNo;
			}
			else{
				theTileNo = String(theTileNo);
			}
						
			theURL = "map_opening.htm?" + theinsetsmaps[i][0];
						
			//Open the selected tile in same window 
			eval("parent.location='" + theURL + "'");				
			break;																	//Quit the loop as the inset map has been found.
		}
	
	}		
}

//*********Define the Browser window title to = map/inset name.
//vvv Insert pre- generated code below (js_definemaptitle.txt) vvv
function defineMapTitle(theMapNo){
	if(theMapNo.toLowerCase() == "inset_03"){
	  theTitle = "Ashen";
	}
	else if(theMapNo.toLowerCase() == "inset_04"){
	  theTitle = "Audley End";
	}
	else if(theMapNo.toLowerCase() == "inset_05"){
	  theTitle = "Belchamp Otten";
	}
	else if(theMapNo.toLowerCase() == "inset_06"){
	  theTitle = "Belchamp St Paul";
	}
	else if(theMapNo.toLowerCase() == "inset_07"){
	  theTitle = "Belchamp Walter";
	}
	else if(theMapNo.toLowerCase() == "inset_09"){
	  theTitle = "Bradwell";
	}
	else if(theMapNo.toLowerCase() == "inset_12"){
	  theTitle = "Bulmer";
	}
	else if(theMapNo.toLowerCase() == "inset_13"){
	  theTitle = "Bulmer Tye";
	}
	else if(theMapNo.toLowerCase() == "inset_15"){
	  theTitle = "Castle Hedingham";
	}
	else if(theMapNo.toLowerCase() == "inset_16"){
	  theTitle = "Coggeshall";
	}
	else if(theMapNo.toLowerCase() == "inset_17"){
	  theTitle = "Colne Engaine";
	}
	else if(theMapNo.toLowerCase() == "inset_18"){
	  theTitle = "Cornish Hall End";
	}
	else if(theMapNo.toLowerCase() == "inset_19"){
	  theTitle = "Cressing";
	}
	else if(theMapNo.toLowerCase() == "inset_21"){
	  theTitle = "Earls Colne Airfield";
	}
	else if(theMapNo.toLowerCase() == "inset_22"){
	  theTitle = "Earls Colne and White Colne West";
	}
	else if(theMapNo.toLowerCase() == "inset_23"){
	  theTitle = "Earls Colne and White Colne East";
	}
	else if(theMapNo.toLowerCase() == "inset_25"){
	  theTitle = "Finchingfield";
	}
	else if(theMapNo.toLowerCase() == "inset_26"){
	  theTitle = "Foxearth";
	}
	else if(theMapNo.toLowerCase() == "inset_27"){
	  theTitle = "Gestingthorpe";
	}
	else if(theMapNo.toLowerCase() == "inset_28"){
	  theTitle = "Gosfield";
	}
	else if(theMapNo.toLowerCase() == "inset_29"){
	  theTitle = "Great Bardfield";
	}
	else if(theMapNo.toLowerCase() == "inset_30"){
	  theTitle = "Great Maplestead";
	}
	else if(theMapNo.toLowerCase() == "inset_31"){
	  theTitle = "Great Saling";
	}
	else if(theMapNo.toLowerCase() == "inset_32"){
	  theTitle = "Great Yeldham";
	}
	else if(theMapNo.toLowerCase() == "inset_33"){
	  theTitle = "Greenstead Green";
	}
	else if(theMapNo.toLowerCase() == "inset_36"){
	  theTitle = "Hatfield Peverel";
	}
	else if(theMapNo.toLowerCase() == "inset_37"){
	  theTitle = "Helions Bumpstead";
	}
	else if(theMapNo.toLowerCase() == "inset_39"){
	  theTitle = "Lamarsh";
	}
	else if(theMapNo.toLowerCase() == "inset_40"){
	  theTitle = "Little Maplestead";
	}
	else if(theMapNo.toLowerCase() == "inset_41"){
	  theTitle = "Little Yeldham";
	}
	else if(theMapNo.toLowerCase() == "inset_42"){
	  theTitle = "North End";
	}
	else if(theMapNo.toLowerCase() == "inset_43"){
	  theTitle = "Nounsley";
	}
	else if(theMapNo.toLowerCase() == "inset_45"){
	  theTitle = "Pebmarsh";
	}
	else if(theMapNo.toLowerCase() == "inset_47"){
	  theTitle = "Ridgewell";
	}
	else if(theMapNo.toLowerCase() == "inset_50"){
	  theTitle = "Shalford";
	}
	else if(theMapNo.toLowerCase() == "inset_51"){
	  theTitle = "Shalford (Church End)";
	}
	else if(theMapNo.toLowerCase() == "inset_52"){
	  theTitle = "Sible Hedingham";
	}
	else if(theMapNo.toLowerCase() == "inset_53"){
	  theTitle = "Silver End";
	}
	else if(theMapNo.toLowerCase() == "inset_54"){
	  theTitle = "Stambourne Chapel End Way";
	}
	else if(theMapNo.toLowerCase() == "inset_55"){
	  theTitle = "Stambourne Dyers End";
	}
	else if(theMapNo.toLowerCase() == "inset_56"){
	  theTitle = "Steeple Bumpstead";
	}
	else if(theMapNo.toLowerCase() == "inset_57"){
	  theTitle = "Stisted";
	}
	else if(theMapNo.toLowerCase() == "inset_58"){
	  theTitle = "Sturmer East";
	}
	else if(theMapNo.toLowerCase() == "inset_60"){
	  theTitle = "Terling";
	}
	else if(theMapNo.toLowerCase() == "inset_61"){
	  theTitle = "Tilbury Juxta Clare";
	}
	else if(theMapNo.toLowerCase() == "inset_62"){
	  theTitle = "Toppesfield";
	}
	else if(theMapNo.toLowerCase() == "inset_63"){
	  theTitle = "Wethersfield";
	}
	else if(theMapNo.toLowerCase() == "inset_64"){
	  theTitle = "White Notley";
	}
	else if(theMapNo.toLowerCase() == "inset_65"){
	  theTitle = "Wickham St Paul";
	}
	else if(theMapNo.toLowerCase() == "inset_14"){
	  theTitle = "Bures Hamlet";
	}
	else if(theMapNo.toLowerCase() == "inset_24"){
	  theTitle = "Feering";
	}
	else if(theMapNo.toLowerCase() == "inset_38"){
	  theTitle = "Kelvedon";
	}
	else if(theMapNo.toLowerCase() == "inset_34"){
	  theTitle = "Halstead Town";
	}
	else if(theMapNo.toLowerCase() == "inset_01"){
	  theTitle = "Braintree and Bocking";
	}
	else if(theMapNo.toLowerCase() == "inset_02"){
	  theTitle = "Witham";
	}
	else if(theMapNo.toLowerCase() == "inset_35"){
	  theTitle = "Halstead Town Centre";
	}
	else if(theMapNo.toLowerCase() == "inset_08"){
	  theTitle = "Black Notley";
	}
	else if(theMapNo.toLowerCase() == "inset_10"){
	  theTitle = "Braintree Town Centre";
	}
	else if(theMapNo.toLowerCase() == "inset_11"){
	  theTitle = "Braintree Bradford Street";
	}
	else if(theMapNo.toLowerCase() == "inset_20"){
	  theTitle = "Cressing (Tye Green)";
	}
	else if(theMapNo.toLowerCase() == "inset_44"){
	  theTitle = "Panfield";
	}
	else if(theMapNo.toLowerCase() == "inset_46"){
	  theTitle = "Rayne";
	}
	else if(theMapNo.toLowerCase() == "inset_48"){
	  theTitle = "Rivenhall";
	}
	else if(theMapNo.toLowerCase() == "inset_49"){
	  theTitle = "Rivenhall End";
	}
	else if(theMapNo.toLowerCase() == "inset_66"){
	  theTitle = "Witham Town Centre";
	}
	else if(theMapNo.toLowerCase() == "inset_59"){
	  theTitle = "Sturmer West and Helions Bumpstead North";
	}
	else if(theMapNo.toLowerCase() == "proposals"){
	  theTitle = "Proposals Map";
	}
	else{
	theTitle = "";
	}
	return theTitle;
}

//^^^Insert pre- generated code above ^^^


//********Get the attribute and open the written doc in new window or open a list of policies (called on main map click/keypress).
function getatt(thePolRef,theDoc){

	if(theDoc.indexOf("inset") != -1){								//*****User has clicked on Inset hotpot -open the new inset map
		openMapAtCentre(thePolRef,'propmap');	
	}
	else if(theDoc.indexOf("plan") != -1){								//*****User has clicked on Inset hotpot -open the new inset map
		plansIndex(thePolRef);	
	}
	else if(thePolRef != ""){										//*****User has clicked on policy hotpot - open policy list or written statement
		var comm = thePolRef.indexOf(",");
		if(comm == -1){												//Only one policy selected - Open written statement
		
			//Remove any specifics eg (1) etc. from the policy reference.
			var test = thePolRef.indexOf(" ");
			if(test != -1){
				var newPolRef = thePolRef.substring(0,test);
				thePolRef = newPolRef;
			}
			
			thePolRef = "rlp" + thePolRef;
			
			theURL = "../../written/cpt" + theDoc + ".htm#" + thePolRef.toLowerCase();	
			winName =  "Written";  
			features = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=630,height=500";
			window.open(theURL,winName,features);
		}
		else														//More than one policy selected - Open the policy list
		{
			polIndex(thePolRef,theDoc);
		}
	}		
}	


//*********Opens index of policies realating to selected site the user has clicked on.
function polIndex(thePolRef,theDoc){																		
		theURL = "../../pol_index.htm?" + thePolRef + "&" + theDoc;	
		winName = "thePolIndex";
		features = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=500,height=400";
		window.open(theURL,winName,features);		
}

//*********Opens index of policies realating to selected site the user has clicked on.
function plansIndex(thePolRef){																		
		theURL = "../../plans_index.htm?" + thePolRef;	
		winName = "thePlansIndex";
		features = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=400,height=400";
		window.open(theURL,winName,features);		
}


//*******************Function to remove the space code %20 and ampersand code %38
function removePercentCode(theTitle){

	//Remove space code '%20'
	var newstring = "";																	
	var pos = theTitle.indexOf("%20");
	
	if(pos != -1){
		newstring = newstring + theTitle.substring(0,pos) + " "	;
		test = theTitle.substring((pos+3),theTitle.length);	
		pos = test.indexOf("%20");
	
		while (pos != -1){
			newstring = newstring + test.substring(0,pos) + " ";
			test = test.substring((pos+3),test.length);	
			pos = test.indexOf("%20");
		}
		
		newstring = newstring + test.substring(0,test.length);
	}
	else{
		newstring = theTitle;
	}

	//Remove ampersand code '%38'
	var newstring2 = "";																	
	var pos = newstring.indexOf("%38");
	
	if(pos != -1){
		newstring2 = newstring2 + newstring.substring(0,pos) + "&";	
		test = newstring.substring((pos+3),newstring.length);	
		pos = test.indexOf("%38");
	
		while (pos != -1){
			newstring2 = newstring2 + test.substring(0,pos) + "&";
			test = test.substring((pos+3),test.length);	
			pos = test.indexOf("%38");
		}
		
		newstring2 = newstring2 + test.substring(0,test.length);
	}
	else{
		newstring2 = newstring;
	}

	//Remove trailing and leading spaces.
	if(newstring2.indexOf(" ") == 0){
		newstring3 = newstring2.substring(1,newstring2.length);
	}
	else{
		newstring3 = newstring2;
	}
	if(newstring3.indexOf(" ") == (newstring3.length -1)){
		newstring4 = newstring3.substring(0,(newstring3.length-1));
	}
	else{
		newstring4 = newstring3;
	}
	
	return(newstring4);

}	

//*******************Replaces the policy ref number with the policy name (Used when printed to the policy index page pol_index.htm)
//vvv Insert pre- generated code below (js_getpolicyname.txt) vvv
function getPolicyName(polNum){
	if(polNum == "1"){
	  thePolName = "RLP 1 Housing Provision";
	}
	else if(polNum == "2"){
	  thePolName = "RLP 2 Town Development Boundaries and Village Envelopes";
	}
	else if(polNum == "3"){
	  thePolName = "RLP 3 Development within Town Development Boundaries and Village Envelopes";
	}
	else if(polNum == "4"){
	  thePolName = "RLP 4 Prevention of Town Cramming";
	}
	else if(polNum == "5"){
	  thePolName = "RLP 5 Affordable Housing in New Developments";
	}
	else if(polNum == "7"){
	  thePolName = "RLP 7 Housing and Mixed Use Sites";
	}
	else if(polNum == "8"){
	  thePolName = "RLP 8 House Types";
	}
	else if(polNum == "9"){
	  thePolName = "RLP 9 Design and Layout of Housing and Mixed Use Areas";
	}
	else if(polNum == "10"){
	  thePolName = "RLP 10 Residential Density";
	}
	else if(polNum == "22"){
	  thePolName = "RLP 22 Accessible Housing and Lifetime Housing";
	}
	else if(polNum == "28"){
	  thePolName = "RLP 28 Employment Land Provision";
	}
	else if(polNum == "29"){
	  thePolName = "RLP 29 Business Parks";
	}
	else if(polNum == "30"){
	  thePolName = "RLP 30 Diversity of Industrial and Commercial Premises";
	}
	else if(polNum == "31"){
	  thePolName = "RLP 31 Design and Layout of Business Parks";
	}
	else if(polNum == "32"){
	  thePolName = "RLP 32 Workplace Nurseries";
	}
	else if(polNum == "33"){
	  thePolName = "RLP 33 Employment Policy Areas";
	}
	else if(polNum == "34"){
	  thePolName = "RLP 34 Buffer Areas between Industry and Housing";
	}
	else if(polNum == "35"){
	  thePolName = "RLP 35 Non-Conforming and Un-Neighbourly Industry";
	}
	else if(polNum == "36"){
	  thePolName = "RLP 36 Industrial and Environmental Standards";
	}
	else if(polNum == "37"){
	  thePolName = "RLP 37 New Commercial and Industrial Activities within existing Residential Areas";
	}
	else if(polNum == "41"){
	  thePolName = "RLP 41 Employment Allocation, Springwood Drive, Braintree";
	}
	else if(polNum == "42"){
	  thePolName = "RLP 42 Employment Allocation North of Bluebridge Industrial Estate, Halstead";
	}
	else if(polNum == "43"){
	  thePolName = "RLP 43 Atlas Works Site, Earls Colne";
	}
	else if(polNum == "44"){
	  thePolName = "RLP 44 Rayne Foundry";
	}
	else if(polNum == "45"){
	  thePolName = "RLP 45 Riverside Business Park, Earls Colne";
	}
	else if(polNum == "46"){
	  thePolName = "RLP 46 Earls Colne Airfield";
	}
	else if(polNum == "47"){
	  thePolName = "RLP 47 Employment Allocation Inworth Road, Feering";
	}
	else if(polNum == "48"){
	  thePolName = "RLP 48 Comprehensive Development Area, Kelvedon";
	}
	else if(polNum == "49"){
	  thePolName = "RLP 49 Pedestrian Networks";
	}
	else if(polNum == "50"){
	  thePolName = "RLP 50 Cycleways";
	}
	else if(polNum == "51"){
	  thePolName = "RLP 51 Cycle Parking";
	}
	else if(polNum == "53"){
	  thePolName = "RLP 53 Generators of Travel Demand";
	}
	else if(polNum == "54"){
	  thePolName = "RLP 54 Transport Assessments";
	}
	else if(polNum == "55"){
	  thePolName = "RLP 55 Travel Plans";
	}
	else if(polNum == "56"){
	  thePolName = "RLP 56 Vehicle Parking";
	}
	else if(polNum == "57"){
	  thePolName = "RLP 57 Freeport Special Policy Area";
	}
	else if(polNum == "58"){
	  thePolName = "RLP 58 Galleys Corner Special Policy Area";
	}
	else if(polNum == "59"){
	  thePolName = "RLP 59 Panners Roundabout Special Policy Area";
	}
	else if(polNum == "61"){
	  thePolName = "RLP 61 New Road Schemes";
	}
	else if(polNum == "64"){
	  thePolName = "RLP 64 Contaminated Land";
	}
	else if(polNum == "66"){
	  thePolName = "RLP 66 Flood Risk in Developed and Urban Areas";
	}
	else if(polNum == "67"){
	  thePolName = "RLP 67 Flood Risk in Undeveloped Areas";
	}
	else if(polNum == "68"){
	  thePolName = "RLP 68 Functional Floodplains";
	}
	else if(polNum == "69"){
	  thePolName = "RLP 69 Sustainable Drainage";
	}
	else if(polNum == "70"){
	  thePolName = "RLP 70 Water Efficiency";
	}
	else if(polNum == "71"){
	  thePolName = "RLP 71 Water Supply, Sewerage and Land Drainage";
	}
	else if(polNum == "72"){
	  thePolName = "RLP 72 Water Quality";
	}
	else if(polNum == "73"){
	  thePolName = "RLP 73 Waste Minimisation";
	}
	else if(polNum == "74"){
	  thePolName = "RLP 74 Provision of Space for Recycling";
	}
	else if(polNum == "76"){
	  thePolName = "RLP 76 Renewable Energy";
	}
	else if(polNum == "77"){
	  thePolName = "RLP 77 Energy Efficiency";
	}
	else if(polNum == "79"){
	  thePolName = "RLP 79 Special Landscape Areas";
	}
	else if(polNum == "82"){
	  thePolName = "RLP 82 Sites of Special Scientific Interest";
	}
	else if(polNum == "83"){
	  thePolName = "RLP 83 Local Nature Reserves, Wildlife Sites, and Regionally Important Geological/Geomorphological Sites.";
	}
	else if(polNum == "86"){
	  thePolName = "RLP 86 River Corridors";
	}
	else if(polNum == "87"){
	  thePolName = "RLP 87 Protected Lanes";
	}
	else if(polNum == "90"){
	  thePolName = "RLP 90 Layout and Design of Development";
	}
	else if(polNum == "92"){
	  thePolName = "RLP 92 Accessibility";
	}
	else if(polNum == "93"){
	  thePolName = "RLP 93 Public Realm";
	}
	else if(polNum == "94"){
	  thePolName = "RLP 94 Public Art";
	}
	else if(polNum == "95"){
	  thePolName = "RLP 95 Preservation and Enhancement of Conservation Areas";
	}
	else if(polNum == "96"){
	  thePolName = "RLP 96 Demolition in Conservation Areas";
	}
	else if(polNum == "97"){
	  thePolName = "RLP 97 Changes of Use in Conservation Areas";
	}
	else if(polNum == "98"){
	  thePolName = "RLP 98 Environmental Improvements in Conservation Areas";
	}
	else if(polNum == "103"){
	  thePolName = "RLP 103 Parks and Gardens of Special Historic Interest";
	}
	else if(polNum == "104"){
	  thePolName = "RLP 104 Ancient Monuments and Sites of Archaeological Importance";
	}
	else if(polNum == "108"){
	  thePolName = "RLP 108 Fascias and Signs in Conservation Areas";
	}
	else if(polNum == "109"){
	  thePolName = "RLP 109 Illuminated Signs in Conservation Areas";
	}
	else if(polNum == "110"){
	  thePolName = "RLP 110 Retail and Town Centre Development - The Sequential Approach";
	}
	else if(polNum == "111"){
	  thePolName = "RLP 111 Retail Development";
	}
	else if(polNum == "112"){
	  thePolName = "RLP 112 Town Centre Uses";
	}
	else if(polNum == "113"){
	  thePolName = "RLP 113 Shopping Areas";
	}
	else if(polNum == "114"){
	  thePolName = "RLP 114 Retail Frontage Policy";
	}
	else if(polNum == "115"){
	  thePolName = "RLP 115 Accessibility";
	}
	else if(polNum == "116"){
	  thePolName = "RLP 116 Upper Floors in Shopping Areas";
	}
	else if(polNum == "117"){
	  thePolName = "RLP 117 Shopfronts in Conservation Areas";
	}
	else if(polNum == "118"){
	  thePolName = "RLP 118 Retail Warehouse Development";
	}
	else if(polNum == "119"){
	  thePolName = "RLP 119 Conversions to Retail Warehouse Use";
	}
	else if(polNum == "120"){
	  thePolName = "RLP 120 Braintree Town Centre Improvements";
	}
	else if(polNum == "121"){
	  thePolName = "RLP 121 Land East of Halstead High Street";
	}
	else if(polNum == "122"){
	  thePolName = "RLP 122 Environmental Improvements in Halstead";
	}
	else if(polNum == "123"){
	  thePolName = "RLP 123 The Centre, Halstead";
	}
	else if(polNum == "124"){
	  thePolName = "RLP 124 Environmental Improvements in Witham";
	}
	else if(polNum == "125"){
	  thePolName = "RLP 125 Newlands Precinct, Witham";
	}
	else if(polNum == "130"){
	  thePolName = "RLP 130 Indoor Sport and Leisure Site, Braintree Retail Park";
	}
	else if(polNum == "131"){
	  thePolName = "RLP 131 Swimming Pool Millennium Way, Braintree";
	}
	else if(polNum == "132"){
	  thePolName = "RLP 132 Community Swimming Pool, Ramsey School, Halstead";
	}
	else if(polNum == "136"){
	  thePolName = "RLP 136 Formal Recreation Policy";
	}
	else if(polNum == "137"){
	  thePolName = "RLP 137 Open Space Standards";
	}
	else if(polNum == "138"){
	  thePolName = "RLP 138 Provision of Open Space in New Housing Developments";
	}
	else if(polNum == "139"){
	  thePolName = "RLP 139 Allotments";
	}
	else if(polNum == "140"){
	  thePolName = "RLP 140 River Walks/Linear Parks and Disused Railway Lines";
	}
	else if(polNum == "141"){
	  thePolName = "RLP 141 Informal Countryside Recreation Areas";
	}
	else if(polNum == "142"){
	  thePolName = "RLP 142 Country Parks";
	}
	else if(polNum == "149"){
	  thePolName = "RLP 149 Primary School Site, Witham";
	}
	else if(polNum == "150"){
	  thePolName = "RLP 150 Educational Establishments";
	}
	else if(polNum == "151"){
	  thePolName = "RLP 151 Protection of Community Services";
	}
	else if(polNum == "152"){
	  thePolName = "RLP 152 Cemetery Extension, Bocking";
	}
	else if(polNum == "154"){
	  thePolName = "RLP 154 Community Uses Site, Coggeshall";
	}
	else if(polNum == "155"){
	  thePolName = "RLP 155 Village Hall Site, Great Yeldham";
	}
	else if(polNum == "156"){
	  thePolName = "RLP 156 Community Uses Site, Colchester Road, Halstead";
	}
	else if(polNum == "157"){
	  thePolName = "RLP 157 Community Uses Site, White Colne";
	}
	else if(polNum == "158"){
	  thePolName = "RLP 158 Community Uses Site, off Maltings Lane, Witham";
	}
	else if(polNum == "159"){
	  thePolName = "RLP 159 Community Uses Hatfield Hall, Hatfield Road, Witham";
	}
	else if(polNum == "163"){
	  thePolName = "RLP 163 Infrastructure and Community Facilities";
	}
	else if(polNum == "164"){
	  thePolName = "RLP 164 Environmental Impact Assessment";
	}
	else{
	  thePolName = "";
	}
	
	return(thePolName);

}
//^^^Insert pre- generated code above ^^^


//**********Updates the main map by clicking the region overview map. This functionality only works for IE and Opera
function updatemap1(e){

	//Set-up
	var imageWidth = 250; 								//Width of main overview image in pixels
	var tileWidth = 41000; 								//Width of main overview image in metres
	var pixpermetre =  tileWidth /imageWidth;
	var tileOriginX = 556500;							//Origin of main overview image in ground metres
	var tileOriginY = 207000;
	tileOriginY = tileOriginY + tileWidth; 				//Make origin top left

	//Get user clicked location x,y (pixels).
	var theX = event.offsetX;			
	var theY = event.offsetY;
	
	//Convert to real world metres.
	theX = Number(theX) * pixpermetre;	
	theY = Number(theY) * pixpermetre;  
	theX =  tileOriginX + theX;
	theY =  tileOriginY - theY;
	
	//Check if the user clicked in an inset map area.		
	for(i=0;i<nofInsets;i++){
		
		//Define extent of each inset map area
		ovblx = theinsetsmaps[i][4]; 
		ovbly = theinsetsmaps[i][5]; 
		ovtrx = theinsetsmaps[i][6]; 
		ovtry = theinsetsmaps[i][7];
		var outSideX = "false";
		var outSideY = "false";
				
		if((theX >= ovtrx) | (theX <= ovblx)){
			outSideX = "true";		
		}
		if((theY >= ovtry) | (theY <= ovbly)){
			outSideY = "true";
		}

		if((outSideX == "false") & (outSideY == "false")){			//User has clicked within an inset map						
			var distx = theX - ovblx;
			var disty = theY - ovbly;
			
			var gridcnt = theinsetsmaps[i][8];
			var thecol = 1; 
			while (gridcnt < distx){
				thecol = thecol + 1;
				gridcnt = gridcnt + (theinsetsmaps[i][8] - theinsetsmaps[i][9]);  
			}	
	 
			var gridcnt = theinsetsmaps[i][8];
			var therow = 1;  
			while (gridcnt < disty){
				therow = therow + 1;
				gridcnt = gridcnt + (theinsetsmaps[i][8] - theinsetsmaps[i][9]);  
			}			
			
			var theTileNo =  ((therow -1) * theinsetsmaps[i][11]) + thecol;

			//Adjust the tile number to agree with the standard "###"
			if(theTileNo < 10){
				theTileNo = "00" + theTileNo;
			}
			else if(theTileNo < 100){
				theTileNo = "0" + theTileNo;
			}
			else{
				theTileNo = String(theTileNo);
			}

			//Update main map frame
			var newloc = "../../map_htm/" + theinsetsmaps[i][0] + "/" + theinsetsmaps[i][0] + "_" + theTileNo + ".htm";		
			parent.window.location = newloc;	
			break;																	//Quit the loop as the inset map has nbeen found.
		}
	
	}

}

//**********Updates the main map by clicking the inset overview map. This functionality only works for IE and Opera
function updatemap2(e){

	//Get the current overview image.
	var cmdString = String(parent.document.location);
	
	var theSep;
	for (n=0;n<cmdString.length; n++){
		var teststring = cmdString.substring(n,(n + 1));
		if(teststring == "/"){
			theSep = n;
		}
	}
	var tempstring = cmdString.substring((theSep +1),(cmdString.length));
	for (n=0;n<tempstring.length; n++){
		var teststring =  tempstring.substring(n,(n + 1));
		if(teststring == "_"){
			theSep = n;
		}
	}	
	var theName = tempstring.substring(0,theSep);		
		
	//Define the current overview.	
	for(i=0;i<nofInsets;i++){
		if(theName.toUpperCase() == theinsetsmaps[i][0].toUpperCase()){
			var useIndex = i;
		}
	}
	
	var imageWidth = 250 ;																		//Width of inset overview image in pixels
	var pixpermetre =  theinsetsmaps[useIndex][3] / imageWidth;
	var origTLY  = theinsetsmaps[useIndex][2] + theinsetsmaps[useIndex][3];		//Make origin top left

	//Get user clicked location x,y (pixels).
	var theX = event.offsetX;			
	var theY =  event.offsetY;

	//Convert to real world metres.
	theX = Number(theX) * pixpermetre;	
	theY = Number(theY) * pixpermetre ;  
	theX =  theinsetsmaps[useIndex][1] + theX;
	theY =  origTLY - theY;

	//Define if user has clicked in the map area
	var outSideX = "false";
	var outSideY = "false";
	
	if((theX >= theinsetsmaps[useIndex][6]) | (theX <= theinsetsmaps[useIndex][4])){
		outSideX = "true";		
	}
	if((theY >= theinsetsmaps[useIndex][7]) | (theY <= theinsetsmaps[useIndex][5])){
		outSideY = "true";
	}

	//Define the new map image to load in.
	if((outSideX == "true") | (outSideY == "true")){			
		//alert("outside the area")
	}
	else{
		var distx = theX - theinsetsmaps[useIndex][4];
		var disty = theY - theinsetsmaps[useIndex][5];
		
		var gridcnt = theinsetsmaps[useIndex][8];
  		var thecol = 1; 
		while (gridcnt < distx){
			thecol = thecol + 1;
			gridcnt = gridcnt + (theinsetsmaps[useIndex][8] - theinsetsmaps[useIndex][9]);  
		}	
 
		var gridcnt = theinsetsmaps[useIndex][8];
  		var therow = 1; 
		while (gridcnt < disty){
			therow = therow + 1;
			gridcnt = gridcnt + (theinsetsmaps[useIndex][8] - theinsetsmaps[useIndex][9]);  
		}			
		
		var theTileNo =  ((therow -1) * theinsetsmaps[useIndex][11]) + thecol;

		//Adjust the tile number to agree with the standard "###"
		if(theTileNo < 10){
			theTileNo = "00" + theTileNo;
		}
		else if(theTileNo < 100){
			theTileNo = "0" + theTileNo;
		}
		else{
			theTileNo = String(theTileNo);
		}
		
		//Update main map frame
		var newloc =  theName + "_" + theTileNo + ".htm"; 
		parent.window.location = newloc;

	}
	
}

//**********Updates the main map by clicking the region overview map. This functionality only works for IE and Opera
function updatemap3(e){

	//Set-up
	var imageWidth = 400; 								//Width of main overview image in pixels
	var tileWidth = 41000; 								//Width of main overview image in metres
	var pixpermetre =  tileWidth /imageWidth;
	var tileOriginX = 556500;							//Origin of main overview image in ground metres
	var tileOriginY = 207000;
	tileOriginY = tileOriginY + tileWidth; 				//Make origin top left
	
	//Get user clicked location x,y (pixels).
	var theX = event.offsetX;			
	var theY = event.offsetY;
	
	//Convert to real world metres.
	theX = Number(theX) * pixpermetre;	
	theY = Number(theY) * pixpermetre;  
	theX =  tileOriginX + theX;
	theY =  tileOriginY - theY;
	
	//Check if the user clicked in an inset map area.		
	for(i=0;i<nofInsets;i++){
		
		//Define extent of each inset map area
		ovblx = theinsetsmaps[i][4]; 
		ovbly = theinsetsmaps[i][5]; 
		ovtrx = theinsetsmaps[i][6]; 
		ovtry = theinsetsmaps[i][7];
		var outSideX = "false";
		var outSideY = "false";
				
		if((theX >= ovtrx) | (theX <= ovblx)){
			outSideX = "true";		
		}
		if((theY >= ovtry) | (theY <= ovbly)){
			outSideY = "true";
		}

		if((outSideX == "false") & (outSideY == "false")){			//User has clicked within an inset map						
			var distx = theX - ovblx;
			var disty = theY - ovbly;
			
			var gridcnt = theinsetsmaps[i][8];
			var thecol = 1; 
			while (gridcnt < distx){
				thecol = thecol + 1;
				gridcnt = gridcnt + (theinsetsmaps[i][8] - theinsetsmaps[i][9]);  
			}	
	 
			var gridcnt = theinsetsmaps[i][8];
			var therow = 1;  
			while (gridcnt < disty){
				therow = therow + 1;
				gridcnt = gridcnt + (theinsetsmaps[i][8] - theinsetsmaps[i][9]);  
			}			
			
			var theTileNo =  ((therow -1) * theinsetsmaps[i][11]) + thecol;

			//Adjust the tile number to agree with the standard "###"
			if(theTileNo < 10){
				theTileNo = "00" + theTileNo;
			}
			else if(theTileNo < 100){
				theTileNo = "0" + theTileNo;
			}
			else{
				theTileNo = String(theTileNo);
			}

			//Update main map frame
			var newloc = "map_htm/" + theinsetsmaps[i][0] + "/" + theinsetsmaps[i][0] + "_" + theTileNo + ".htm";		
			parent.window.location = newloc;	
			break;																	//Quit the loop as the inset map has nbeen found.
		}
	
	}

}

//*********Opens mapping from the Proposals Maps
function openMap(selObj,theSource){ 

	//Get the inset number
	if (theSource == 1){
		var inString = selObj.options[selObj.selectedIndex].value;
	}
	else{
		var inString = selObj;
	}
	
	//Get the inset number
	var sep = inString.indexOf("_");
	var string1 = inString.substring(0,(sep+1));
	var string2 = inString.substring((sep+1),inString.length);
	var sep2 = string2.indexOf("_");
	if(sep2 != -1){
		var insetNo = string1 + string2.substring(0,sep2);
	}
	else{
		var insetNo = string1.substring(0,(string1.length -1));
	}

	//If using IE or opera open intermediate window for the user to select exact map location
	if(((is_ie == true) && (is_ie5up == true))|| ((is_opera == true) && (is_opera5up == true))){				//IE or Opera open overview mapping
		var mapLoc = "map_opening.htm?" + insetNo;				 
	}
	else{
		var mapLoc = "map_htm/" + insetNo + "/" + inString + ".htm";
	}

	//Open in current window
 	eval("parent.location='" + mapLoc + "'");
  	if (theSource == 1){
		selObj.selectedIndex=0;
	}
}

//*******************************Defines the map to load from the postcode search.
function getSelectedPC(tileLoc){
			
	//Get the inset number
	var sep = tileLoc.indexOf("_");
	var string1 = tileLoc.substring(0,(sep+1));
	var string2 = tileLoc.substring((sep+1),tileLoc.length);
	var sep2 = string2.indexOf("_");
	if(sep2 != -1){
		var insetNo = string1 + string2.substring(0,sep2);
	}
	else{
		var insetNo = string1.substring(0,(string1.length -1));
	}

	//Get the path of the selected tile
	var mapLoc = "map_htm/" + insetNo + "/" + tileLoc + ".htm";

	//Open in current window
 	eval("parent.location='" + mapLoc + "'");
								
}

//******************************Opens a map from a link on the written statement
function goToMapLoc(theMapRef){

	 if(theMapRef != ""){	
		var comm = theMapRef.indexOf(",");
		if(comm == -1){												//Only one location go straight to the map.						
			//Get the inset number
			var sep = theMapRef.indexOf("_");
			var string1 = theMapRef.substring(0,(sep+1));
			var string2 = theMapRef.substring((sep+1),theMapRef.length);
			var sep2 = string2.indexOf("_");
			if(sep2 != -1){
				var insetNo = string1 + string2.substring(0,sep2);
			}
			else{
				var insetNo = string1.substring(0,(string1.length -1));
			}
			
			var mapLoc = "../map_htm/" + insetNo + "/" + theMapRef + ".htm";
			    	     
			//Open in current window
 			eval("parent.location='" + mapLoc + "'");
		}	
		else{														//More than one location open intermediate window for user to choose.
			var theURL = "../loc_index.htm?" + theMapRef ;	
 			eval("parent.location='" + theURL + "'");
		}
	}		

}

//******************************Opens a map from the list of towns.
function openTown(selObj,theSource){

	//Get the inset number
	if (theSource == 1){
		var inString = selObj.options[selObj.selectedIndex].value;
	}
	else{
		var inString = selObj;
	}
	
	//Get the inset number
	var sep = inString.indexOf("_");
	var string1 = inString.substring(0,(sep+1));
	var string2 = inString.substring((sep+1),inString.length);
	var sep2 = string2.indexOf("_");
	if(sep2 != -1){
		var insetNo = string1 + string2.substring(0,sep2);
	}
	else{
		var insetNo = string1.substring(0,(string1.length -1));
	}

	var mapLoc = "map_htm/" + insetNo + "/" + inString + ".htm";

	//Open in current window
 	eval("parent.location='" + mapLoc + "'");

  	if (theSource == 1){
		selObj.selectedIndex=0;
	}
}

//******************************Opens a key from button
function openKey(){
	var keyWinWidth = 400;
	
	if(((is_ie == true) && (is_ie5up == true))|| ((is_opera == true) && (is_opera5up == true))){
		var docWidth = document.body.clientWidth; 
		var docLeft = window.screenLeft; 
		var docTop = window.screenTop;
	}
	else{	
		var docWidth = window.outerWidth
		var docLeft = window.screenX; 
		var docTop = window.screenY;
	}
		
	var posX = (docLeft + docWidth) - keyWinWidth;
	var posY = docTop;	
			
	theURL = "../../legend.htm";
	winName =  "Legend";  
	features = "menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + keyWinWidth + ",height=500," + "top=" + posY + "," + "left=" + posX;
	window.open(theURL,winName,features);
	
}

/*
***********END of Script
*/
