/*
* **************************************************************************
lp.js
Interactive Local Plan
Torbay Council
Ver 1.0
Lovell Johns Ltd.
08/04
****************************************************************************
*/

//*********************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 (4)
var nofInsets = 4;
theinsetsmaps[0] = new Array("inset_02",288220,59923.5,1485,288200,60100,289750,61200,100,50,21,30);
theinsetsmaps[1] = new Array("inset_01",291821,55744.7,1485,292000,55700,293100,57250,100,50,30,21);
theinsetsmaps[2] = new Array("inset_03",291010,62967,1576,291000,62900,292550,64550,100,50,32,30);
theinsetsmaps[3] = new Array("proposals",281909,53609,16254,284200,53600,296000,69900,400,100,54,39);
// ^^^^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 a new window
		//window.close("mapOV");
		//winName = "mapindex";
		//features = "toolbar=yes,scrollbars=yes,resizable=yes,status=yes,width=780,height=600";
		//window.open(theNewHTML,winName,features); 

		//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() == "proposals map"){
	  newMap = "map_htm/proposals/proposals_949.htm";
	}
	else if(theMap.toLowerCase() == "paignton"){
	  newMap = "map_htm/inset_02/inset_02_315.htm";
	}
	else if(theMap.toLowerCase() == "brixham"){
	  newMap = "map_htm/inset_01/inset_01_178.htm";
	}
	else if(theMap.toLowerCase() == "torquay"){
	  newMap = "map_htm/inset_03/inset_03_319.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 = 16254; 								//Width of main overview image in metres
	var tileHeight = 16254;								//Width of main overview image in metres

	var pixpermetreX =  tileWidth /imageWidth;
	var pixpermetreY =  tileHeight /imageHeight;

	var tileOriginX = 281909;							//Origin of main overview image in ground metres
	var tileOriginY = 53609;	
	
	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 a new window 	
			//winName = "mapOV";
			//features = "toolbar=no,scrollbars=yes,resizable=no,width=450,height=500";
			//window.open(theURL,winName,features);
			//break;
						
			//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() == "proposals"){
  theTitle = "Proposals Map";
}
else if(theMapNo.toLowerCase() == "inset_02"){
  theTitle = "Paignton";
}
else if(theMapNo.toLowerCase() == "inset_01"){
  theTitle = "Brixham";
}
else if(theMapNo.toLowerCase() == "inset_03"){
  theTitle = "Torquay";
}
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(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;
			}
			
			theURL = "../../written/cpt" + theDoc + ".htm#" + thePolRef.toLowerCase();	
			winName =  "Written";  
			features = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=630,height=500";
			//window.close(winName);
			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=630,height=500";
		//window.close(winName);
		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 == "H1"){
	  thePolName = "New housing on identified sites H1";
	}
	else if(polNum == "H1.22A"){
	  thePolName = "Former Dolphin Holiday Camp, Brixham H1.22A";
	}
	else if(polNum == "H1A"){
	  thePolName = "The management of housing provision through phasing H1A";
	}
	else if(polNum == "H2"){
	  thePolName = "New housing on unidentified sites H2";
	}
	else if(polNum == "H3"){
	  thePolName = "Residential accommodation in town centres H3";
	}
	else if(polNum == "H4"){
	  thePolName = "Conversion and sub-division into flats H4";
	}
	else if(polNum == "H5"){
	  thePolName = "Affordable housing on identified sites H5";
	}
	else if(polNum == "H6"){
	  thePolName = "Affordable housing on unidentified sites H6";
	}
	else if(polNum == "H7"){
	  thePolName = "Houses in multiple occupation (HMOs) H7";
	}
	else if(polNum == "H8"){
	  thePolName = "Change of use from housing to other uses H8";
	}
	else if(polNum == "H9"){
	  thePolName = "Layout, and design and community aspects H9";
	}
	else if(polNum == "H10"){
	  thePolName = "Housing densities H10";
	}
	else if(polNum == "H11"){
	  thePolName = "Open space requirements for new housing H11";
	}
	else if(polNum == "H12"){
	  thePolName = "New agricultural dwellings in the countryside H12";
	}
	else if(polNum == "H13"){
	  thePolName = "Residential caravans in the countryside H13";
	}
	else if(polNum == "H14"){
	  thePolName = "Caravan sites for travelling people H14";
	}
	else if(polNum == "H15"){
	  thePolName = "House extensions H15";
	}
	else if(polNum == "E1"){
	  thePolName = "New employment on identified sites E1";
	}
	else if(polNum == "E11A"){
	  thePolName = "Kerswell Gardens, Torquay E1.1(A)";
	}
	else if(polNum == "E12B"){
	  thePolName = "Riviera Way South, Torquay E1.2(B)";
	}
	else if(polNum == "E116C"){
	  thePolName = "Yalberton Road, Paignton E1.16(C)";
	}
	else if(polNum == "E119D"){
	  thePolName = "Long Road South, Paignton E1.19(D)";
	}
	else if(polNum == "E2"){
	  thePolName = "Town centre office sites E2";
	}
	else if(polNum == "E3"){
	  thePolName = "Business Investment Areas E3";
	}
	else if(polNum == "E4"){
	  thePolName = "Small Business Areas E4";
	}
	else if(polNum == "E5"){
	  thePolName = "Employment provision on unidentified sites E5";
	}
	else if(polNum == "E6"){
	  thePolName = "Retention of employment land E6";
	}
	else if(polNum == "E7"){
	  thePolName = "The Fishing industry and the Port and Waterfront of Brixham E7";
	}
	else if(polNum == "E8"){
	  thePolName = "Northern Arm Breakwater E8";
	}
	else if(polNum == "E9"){
	  thePolName = "Layout, design and sustainability E9";
	}
	else if(polNum == "E10"){
	  thePolName = "Home working E10";
	}
	else if(polNum == "TU1"){
	  thePolName = "Harbourside and waterfront regeneration TU1";
	}
	else if(polNum == "TU2"){
	  thePolName = "Proposals for new tourist facilities TU2";
	}
	else if(polNum == "TU3"){
	  thePolName = "New tourist facilities elsewhere TU3";
	}
	else if(polNum == "TU4"){
	  thePolName = "Water-based tourist facilities  TU4";
	}
	else if(polNum == "TU5"){
	  thePolName = "New holiday accommodation TU5";
	}
	else if(polNum == "TU6"){
	  thePolName = "Principal Holiday Accommodation Areas TU6";
	}
	else if(polNum == "TU7"){
	  thePolName = "Change of use or redevelopment of holiday accommodation outside Principal Holiday Accommodation Areas TU7";
	}
	else if(polNum == "TU8"){
	  thePolName = "Winter letting of holiday accommodation TU8";
	}
	else if(polNum == "TU9"){
	  thePolName = "Refurbishment and development of new holiday centres and parks TU9";
	}
	else if(polNum == "TU10"){
	  thePolName = "Change of use or redevelopment of holiday entres and parks TU10";
	}
	else if(polNum == "S1"){
	  thePolName = "Town Centres S1";
	}
	else if(polNum == "S2"){
	  thePolName = "Town centre mixed use developments S2";
	}
	else if(polNum == "S3"){
	  thePolName = "Primary shopping frontages S3";
	}
	else if(polNum == "S4"){
	  thePolName = "Secondary shopping frontages S4";
	}
	else if(polNum == "S5"){
	  thePolName = "New town centre shopping developments S5";
	}
	else if(polNum == "S6"){
	  thePolName = "Retail development outside identified Town, District and Local Centres S6";
	}
	else if(polNum == "S7"){
	  thePolName = "Amusement centres S7";
	}
	else if(polNum == "S8"){
	  thePolName = "Hot take-away food S8";
	}
	else if(polNum == "S9"){
	  thePolName = "District Centres S9";
	}
	else if(polNum == "S10"){
	  thePolName = "Local Centres S10";
	}
	else if(polNum == "S11"){
	  thePolName = "New Local Centres S11";
	}
	else if(polNum == "S12"){
	  thePolName = "Corner shops S12";
	}
	else if(polNum == "S13"){
	  thePolName = "Service station forecourt sales S13";
	}
	else if(polNum == "S14"){
	  thePolName = "Drive-through take-aways and restaurants S14";
	}
	else if(polNum == ""){
	  thePolName = "S15 Open markets and car boot sales S15";
	}
	else if(polNum == "CF1"){
	  thePolName = "Provision of new and improved community facilities CF1";
	}
	else if(polNum == "CF2"){
	  thePolName = "Crime prevention CF2";
	}
	else if(polNum == "CF3"){
	  thePolName = "Hostels CF3";
	}
	else if(polNum == "CF4"){
	  thePolName = "New cemeteries in Torbay CF4";
	}
	else if(polNum == "CF5"){
	  thePolName = "Refurbishment and community use of Torquay United Football Club CF5";
	}
	else if(polNum == "CF6"){
	  thePolName = "Community infrastructure contributions CF6";
	}
	else if(polNum == "CF7"){
	  thePolName = "Educational contributions CF7";
	}
	else if(polNum == "CF8"){
	  thePolName = "Primary school provision CF8";
	}
	else if(polNum == "CF9"){
	  thePolName = "Secondary school provision CF9";
	}
	else if(polNum == "CF10"){
	  thePolName = "New schools and improved school facilities CF10";
	}
	else if(polNum == "CF11"){
	  thePolName = "South Devon College CF11";
	}
	else if(polNum == "CF12"){
	  thePolName = "Language schools CF12";
	}
	else if(polNum == "CF13"){
	  thePolName = "Torbay hospital CF13";
	}
	else if(polNum == "CF14"){
	  thePolName = "Health centre, Great Parks CF14";
	}
	else if(polNum == "CF15"){
	  thePolName = "Accommodation for people in need of care CF15";
	}
	else if(polNum == "R1"){
	  thePolName = "Major indoor leisure and recreation developments R1";
	}
	else if(polNum == "R2"){
	  thePolName = "Outdoor recreation developments R2";
	}
	else if(polNum == "R3"){
	  thePolName = "New playing fields R3";
	}
	else if(polNum == "R4"){
	  thePolName = "New cricket grounds R4";
	}
	else if(polNum == "R5"){
	  thePolName = "Protection of public open spaces and playing fields R5";
	}
	else if(polNum == "R6"){
	  thePolName = "Urban play parks R6";
	}
	else if(polNum == "R7"){
	  thePolName = "Areas of amenity open space R7";
	}
	else if(polNum == "R8"){
	  thePolName = "Allotments R8";
	}
	else if(polNum == "R9"){
	  thePolName = "Country Parks R9";
	}
	else if(polNum == "R10"){
	  thePolName = "Heritage Farm Country Park, Occombe R10";
	}
	else if(polNum == "R11"){
	  thePolName = "Footpaths R11";
	}
	else if(polNum == "R12"){
	  thePolName = "New recreational footpaths R12";
	}
	else if(polNum == "IN1"){
	  thePolName = "Water, drainage and sewerage infrastructure IN1";
	}
	else if(polNum == "IN2"){
	  thePolName = "High voltage power lines IN2";
	}
	else if(polNum == "IN3"){
	  thePolName = "Telecommunications IN3";
	}
	else if(polNum == "IN4"){
	  thePolName = "Redundant telecommunications equipment IN4";
	}
	else if(polNum == "W1"){
	  thePolName = "Waste management facilities W1";
	}
	else if(polNum == "W2"){
	  thePolName = "Civic amenity sites W2";
	}
	else if(polNum == "W3"){
	  thePolName = "Protection of waste management sites and surroundings W3";
	}
	else if(polNum == "W4"){
	  thePolName = "Waste water treatment works W4";
	}
	else if(polNum == "W5"){
	  thePolName = "Waste water and sewage sludge treatment W5";
	}
	else if(polNum == "W6"){
	  thePolName = "New development and the minimisation of waste W6";
	}
	else if(polNum == "W7"){
	  thePolName = "Development and waste recycling facilities W7";
	}
	else if(polNum == "M1"){
	  thePolName = "Recycling, storage and processing of minerals M1";
	}
	else if(polNum == "M2"){
	  thePolName = "New mineral working M2";
	}
	else if(polNum == "L1"){
	  thePolName = "Areas of Outstanding Natural Beauty L1";
	}
	else if(polNum == "L2"){
	  thePolName = "Areas of Great Landscape Value L2";
	}
	else if(polNum == "L3"){
	  thePolName = "Coastal Preservation Areas L3";
	}
	else if(polNum == "L4"){
	  thePolName = "Countryside Zone L4";
	}
	else if(polNum == "L5"){
	  thePolName = "Urban Landscape Protection Area L5";
	}
	else if(polNum == "L6"){
	  thePolName = "Urban green spaces L6";
	}
	else if(polNum == "L7"){
	  thePolName = "Agricultural land L7";
	}
	else if(polNum == "L8"){
	  thePolName = "Protection of hedgerows, woodlands and other natural landscape features L8";
	}
	else if(polNum == "L9"){
	  thePolName = "Planting and retention of trees L9";
	}
	else if(polNum == "L10"){
	  thePolName = "Major development and landscaping L10";
	}
	else if(polNum == "NC1"){
	  thePolName = "Protected sites - internationally important sites NC1";
	}
	else if(polNum == "NC2"){
	  thePolName = "Protected sites - nationally important sites NC2";
	}
	else if(polNum == "NC3"){
	  thePolName = "Protected sites - locally important sites NC3";
	}
	else if(polNum == "NC4"){
	  thePolName = "Wildlife Corridors NC4";
	}
	else if(polNum == "NC5"){
	  thePolName = "Protected species NC5";
	}
	else if(polNum == "EP1"){
	  thePolName = "Energy efficient design EP1";
	}
	else if(polNum == "EP2"){
	  thePolName = "Renewable energy EP2";
	}
	else if(polNum == "EP3"){
	  thePolName = "Control of pollution EP3";
	}
	else if(polNum == "EP4"){
	  thePolName = "Noise EP4";
	}
	else if(polNum == "EP5"){
	  thePolName = "Light pollution EP5";
	}
	else if(polNum == "EP6"){
	  thePolName = "Derelict and under-used land EP6";
	}
	else if(polNum == "EP7"){
	  thePolName = "Contaminated land EP7";
	}
	else if(polNum == "EP8"){
	  thePolName = "Land stability EP8";
	}
	else if(polNum == "EP9"){
	  thePolName = "Groundwater EP9";
	}
	else if(polNum == "EP10"){
	  thePolName = "Water supply EP10";
	}
	else if(polNum == "EP11"){
	  thePolName = "Flood control EP11";
	}
	else if(polNum == "EP12"){
	  thePolName = "Coastal Protection Zone EP12";
	}
	else if(polNum == "BE1"){
	  thePolName = "Design of new development BE1";
	}
	else if(polNum == "BE2"){
	  thePolName = "Landscaping and design BE2";
	}
	else if(polNum == "BE3"){
	  thePolName = "Shopfront design BE3";
	}
	else if(polNum == "BE4"){
	  thePolName = "Advertisements BE4";
	}
	else if(polNum == "BE5"){
	  thePolName = "Policy in Conservation Areas BE5";
	}
	else if(polNum == "BE6"){
	  thePolName = "Development affecting listed buildings BE6";
	}
	else if(polNum == "BE7"){
	  thePolName = "New uses for historic buildings BE7";
	}
	else if(polNum == "BE8"){
	  thePolName = "Historic Parks and Gardens BE8";
	}
	else if(polNum == "BE9"){
	  thePolName = "Archaeological assessment of development proposals BE9";
	}
	else if(polNum == "BE10"){
	  thePolName = "Recording of archaeological remains BE10";
	}
	else if(polNum == "BE11"){
	  thePolName = "Edginswell hamlet envelope BE11";
	}
	else if(polNum == "BE12"){
	  thePolName = "Conversion of buildings to new uses in rural areas BE12";
	}
	else if(polNum == "T1"){
	  thePolName = "Development accessibility T1";
	}
	else if(polNum == "T2"){
	  thePolName = "Transport hierarchy T2";
	}
	else if(polNum == "T3"){
	  thePolName = "Cycling T3";
	}
	else if(polNum == "T4"){
	  thePolName = "Torquay Town Centre improvements T4";
	}
	else if(polNum == "T5"){
	  thePolName = "Paignton Town Centre improvements T5";
	}
	else if(polNum == "T6"){
	  thePolName = "Brixham Town Centre improvements T6";
	}
	else if(polNum == "T7"){
	  thePolName = "Access for people with disabilities T7";
	}
	else if(polNum == "T8"){
	  thePolName = "Lorry parking T8";
	}
	else if(polNum == "T9"){
	  thePolName = "Bus network T9";
	}
	else if(polNum == "T10"){
	  thePolName = "Transportation interchanges T10";
	}
	else if(polNum == "T11"){
	  thePolName = "Park and Ride T11";
	}
	else if(polNum == "T12"){
	  thePolName = "Lymington Road Coach Station T12";
	}
	else if(polNum == "T13"){
	  thePolName = "Railway land T13";
	}
	else if(polNum == "T14"){
	  thePolName = "New railway stations 14";
	}
	else if(polNum == "T15"){
	  thePolName = "Improvement of Paignton Railway Station T15";
	}
	else if(polNum == "T16"){
	  thePolName = "Redevelopment of Goodrington Railway Station T16";
	}
	else if(polNum == "T17"){
	  thePolName = "Water transport T17";
	}
	else if(polNum == "T18"){
	  thePolName = "Major Road Network T18";
	}
	else if(polNum == "T19"){
	  thePolName = "District Distributor Road Network T19";
	}
	else if(polNum == "T20"){
	  thePolName = "Road improvements T20";
	}
	else if(polNum == "T21"){
	  thePolName = "Improved northern approach road T21";
	}
	else if(polNum == "T22"){
	  thePolName = "Western Corridor T22";
	}
	else if(polNum == "T23"){
	  thePolName = "Torquay Northern Distributor Road T23";
	}
	else if(polNum == "T24"){
	  thePolName = "Traffic Management Zones T24";
	}
	else if(polNum == "T25"){
	  thePolName = "Car parking in new development T25";
	}
	else if(polNum == "T26"){
	  thePolName = "Access from development on to the highway T26";
	}
	else if(polNum == "T27"){
	  thePolName = "Servicing T27";
	}
	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 = 200; 								//Width of main overview image in pixels
	var tileWidth = 16254; 								//Width of main overview image in metres
	var pixpermetre =  tileWidth /imageWidth;
	var tileOriginX = 281909;							//Origin of main overview image in ground metres
	var tileOriginY = 53609;
	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 = 200 ;																		//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;

	}
	
}

//*********Opens mapping from the map index page
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 + "'");
	//Open in new window
	//theURL = selObj.options[selObj.selectedIndex].value ;	
	//winName = "mapWindow";
	//features = "toolbar=no,scrollbars=no,resizable=no,width=450,height=500";
	//window.open(theURL,winName,features);
  	if (theSource == 1){
		selObj.selectedIndex=0;
	}
}

//*********Defines how the map list is shown on the map index page (Keyboard accessible list or combo box)
function getMapList(toShow){
	if(toShow == "combo") {									//Show combo box
		eval("parent.location='map_index.htm?false'");
	} else { 										//Show as text list
		eval("parent.location='map_index.htm?true'");
	}
}

//*******************************Defines the map to load from the postcode search.
function getSelectedPC(selObj){
	
	//Passed tile location.
	var tileLoc = selObj.options[selObj.selectedIndex].value;
			
	//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 + "'");
	//Open in new window
	//theURL = selObj.options[selObj.selectedIndex].value ;	
	//winName = "mapWindow";
	//features = "toolbar=no,scrollbars=no,resizable=no,width=450,height=500";
	//window.open(theURL,winName,features);
								
}

//******************************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 + "'");
	//Open in new window
	//theURL = selObj.options[selObj.selectedIndex].value ;	
	//winName = "mapWindow";
	//features = "toolbar=no,scrollbars=no,resizable=no,width=450,height=500";
	//window.open(theURL,winName,features);
  	if (theSource == 1){
		selObj.selectedIndex=0;
	}
}

//******************************Opens a key from button
function openKey(){
	theURL = "../../key.htm";
	winName =  "Written";  
	features = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=630,height=500";
	window.open(theURL,winName,features);
}

//******************************Opens a driagram window from the written statement
function openDiagram(theMapRef){

	//Open in new window;
	theURL = "diag.htm?" + theMapRef;	
	winName = "Diagram";
	features = "toolbar=no,scrollbars=yes,resizable=yes,width=500,height=500";
	window.open(theURL,winName,features);		

}

/*
***********END of Script
*/
