var siteCount		= 0;
var propertyCount	= 0;

var postalCode         = '';
var mappedObjectUTMs   = '';
var mappedObjectLabels = '';
var mappedObjectLinks  = '';
var mappedObjectClasses= '';
var mappedObjectStyles= '';
var mappedObjectCoordTypes= '';

var mappedObjectSpecificUTMs   = '';
var mappedObjectSpecificLabels = '';
var mappedObjectSpecificLinks  = '';
var mappedObjectSpecificClasses= '';
var mappedObjectSpecificStyles= '';
var mappedObjectSpecificCoordTypes= '';

var mappedAreaUTMs     = '';
var mappedAreaLabels   = '';
var mappedAreaLinks    = '';
var mappedAreaClasses  = '';
var mappedAreaStyles  = '';
var mappedAreaCoordTypes  = '';

var mappedAreaSpecificUTMs     = '';
var mappedAreaSpecificLabels   = '';
var mappedAreaSpecificLinks    = '';
var mappedAreaSpecificClasses  = '';
var mappedAreaSpecificStyles  = '';
var mappedAreaSpecificCoordTypes  = '';

var mappedImageUTMs    = '';
var mappedImageFiles   = '';
var mappedImageWidths   = '';
var mappedImageHeights   = '';
var mappedImageLabels  = '';
var mappedImageLinks   = '';
var mappedImageClasses = '';
var mappedImageStyles = '';
var mappedImageCoordTypes = '';

var mappedImageUTMsArray    = new Array();
var mappedImageFilesArray   = new Array();
var mappedImageWidthsArray   = new Array();
var mappedImageHeightsArray   = new Array();
var mappedImageLabelsArray  = new Array();
var mappedImageLinksArray   = new Array();
var mappedImageClassesArray = new Array();
var mappedImageStylesArray = new Array();
var mappedImageCoordTypesArray = new Array();

var moveableUTMX    = new Array();
var moveableUTMY   = new Array();
var moveableFormX   = new Array();
var moveableFormY   = new Array();
var moveableLabel  = new Array();
var moveableImage   = new Array();
var moveableWidth   = new Array();
var moveableHeight  = new Array();

var usingMultiple = true;

var checkBoxCounter = 0;

var LegendTitle  = '';
var LegendLabels = new Array;
var LegendColors = new Array;
var LegendImages = new Array;

function addSites( numSites )
{
	siteCount = siteCount + numSites;
}

function addProperties( numProperties )
{
	propertyCount = propertyCount + numProperties;
}

function setLegendVars(newTitle,newLabels,newColors)
{
	if (setLegendVars.arguments.length > 3) {
		newImages = setLegendVars.arguments[3];
	} else {
		newImages = new Array;
	}

	LegendTitle = newTitle;
	LegendLabels = newLabels;
	LegendColors = newColors;
	LegendImages = newImages;
}

function addToMoveableArray( utmx, utmy, formx, formy, label )
{
	moveableUTMX[moveableUTMX.length]    = utmx;
	moveableUTMY[moveableUTMY.length]   = utmy;
	moveableFormX[moveableFormX.length]   = formx;
	moveableFormY[moveableFormY.length]   = formy;
	moveableLabel[moveableLabel.length]  = label;

	if (addToMoveableArray.arguments.length > 5)
	{
		moveableImage[moveableImage.length]   = addToMoveableArray.arguments[5];
	} else {
		moveableImage[moveableImage.length]   = 'stations.gif';
	}	

	if (addToMoveableArray.arguments.length > 7)
	{
		moveableWidth[moveableWidth.length]   = addToMoveableArray.arguments[6];
		moveableHeight[moveableHeight.length]   = addToMoveableArray.arguments[7];
	} else {
		moveableWidth[moveableWidth.length]   = 20;
		moveableHeight[moveableHeight.length]   = 20;
	}	
}

function showMoveablePoints()
{
	addMultipleMoveablePoints(moveableUTMX,moveableUTMY,moveableFormX,moveableFormY,moveableLabel,moveableImage,moveableWidth,moveableHeight);
}


function addCheckBoxImage (utm, file, width, height, label, link)
{
	if (addCheckBoxImage.arguments.length > 6)
	{
		theClass = addCheckBoxImage.arguments[ 6 ];
	}
	else
	{
		theClass = 'markerImage';
	}
	if (addCheckBoxImage.arguments.length > 7)
	{
		coordType = addCheckBoxImage.arguments[ 7 ];
	}
	else
	{
		coordType = '';
	}
	if (addCheckBoxImage.arguments.length > 8)
	{
		theStyle = addCheckBoxImage.arguments[ 8 ];
	}
	else
	{
		theStyle = '';
	}
	label = label.replace(/\'/g,"\\'");

	document.write("<input type=checkbox name=\"checkbox"+checkBoxCounter+"\" onclick=\"if(this.checked==true){addImageToArray("+checkBoxCounter+",'"+utm+"','"+file+"','"+width+"','"+height+"','"+label+"','"+link+"','"+theClass+"','"+coordType+"','"+theStyle+"');}else{removeImageFromArray("+checkBoxCounter+");}\" />");

	mappedImageUTMsArray[checkBoxCounter] = '';
	mappedImageFilesArray[checkBoxCounter] = '';
	mappedImageWidthsArray[checkBoxCounter] = '';
	mappedImageHeightsArray[checkBoxCounter] = '';
	mappedImageLabelsArray[checkBoxCounter] = '';
	mappedImageLinksArray[checkBoxCounter] = '';
	mappedImageClassesArray[checkBoxCounter] = '';
	mappedImageStylesArray[checkBoxCounter] = '';
	mappedImageCoordTypesArray[checkBoxCounter] = '';

	checkBoxCounter++;
}

function selectAllCheckBoxes () {
	var c = document.getElementsByName( "CheckAll" )[0].value
	var theLink = document.getElementById( "selectAllLink" );
	if (c == "false"){
		bolCheck = 1
		document.getElementsByName( "CheckAll" )[0].value = "true";
		if (theLink != null)
			theLink.firstChild.data = "Select None";
	}else{
		bolCheck = 0
		document.getElementsByName( "CheckAll" )[0].value = "false";
		if (theLink != null)
			theLink.firstChild.data = "Select All";
	}
	
	for (i=0;i<checkBoxCounter;i++){
		document.getElementsByName( "checkbox"+i )[0].checked = bolCheck;
		document.getElementsByName( "checkbox"+i )[0].onclick();
	}
}

function addImageToArray( index, utm, file, width, height, label, link, theClass, coordType, theStyle )
{
	mappedImageUTMsArray[index] = utm;
	mappedImageFilesArray[index] = file;
	mappedImageWidthsArray[index] = width;
	mappedImageHeightsArray[index] = height;
	mappedImageLabelsArray[index] = label;
	mappedImageLinksArray[index] = link;
	mappedImageClassesArray[index] = theClass;
	mappedImageStylesArray[index] = theStyle;
	mappedImageCoordTypesArray[index] = coordType;
}

function removeImageFromArray( index )
{
	mappedImageUTMsArray[index] = '';
	mappedImageFilesArray[index] = '';
	mappedImageWidthsArray[index] = '';
	mappedImageHeightsArray[index] = '';
	mappedImageLabelsArray[index] = '';
	mappedImageLinksArray[index] = '';
	mappedImageClassesArray[index] = '';
	mappedImageStylesArray[index] = '';
	mappedImageCoordTypesArray[index] = '';
}

function showCheckBoxImagesOnMap()
{
	var mappedImageUTMsArrayString    = '';
	var mappedImageFilesArrayString   = '';
	var mappedImageWidthsArrayString   = '';
	var mappedImageHeightsArrayString   = '';
	var mappedImageLabelsArrayString  = '';
	var mappedImageLinksArrayString   = '';
	var mappedImageClassesArrayString = '';
	var mappedImageStylesArrayString = '';
	var mappedImageCoordTypesArrayString = '';

	for(x=0;x<mappedImageUTMsArray.length;x++){
		if(mappedImageUTMsArray[x]!=''){
			mappedImageUTMsArrayString    = mappedImageUTMsArrayString    + mappedImageUTMsArray[x]    + ';;';
			mappedImageFilesArrayString   = mappedImageFilesArrayString   + mappedImageFilesArray[x]   + ';;';
			mappedImageWidthsArrayString  = mappedImageWidthsArrayString  + mappedImageWidthsArray[x]  + ';;';
			mappedImageHeightsArrayString = mappedImageHeightsArrayString + mappedImageHeightsArray[x] + ';;';
			mappedImageLabelsArrayString  = mappedImageLabelsArrayString  + mappedImageLabelsArray[x]  + ';;';
			mappedImageLinksArrayString   = mappedImageLinksArrayString   + mappedImageLinksArray[x]   + ';;';
			mappedImageClassesArrayString = mappedImageClassesArrayString + mappedImageClassesArray[x] + ';;';
			mappedImageStylesArrayString = mappedImageStylesArrayString + mappedImageStylesArray[x] + '@@'; // can't use the semicolons here because things get messed up - in the future, why not just use arrays?
			mappedImageCoordTypesArrayString = mappedImageCoordTypesArrayString + mappedImageCoordTypesArray[x] + ';;';
		}
	}

	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
	}
	var warning = document.getElementById( "warning" );

	if ( typeof( svgMapFrameLoaded ) != "undefined" )
	{
		warning.style.visibility = "hidden";
		warning.style.position = "absolute";
		//set_primary_legend_vars(LegendTitle,LegendLabels,LegendColors,LegendImages);
		draw_locations( mappedObjectUTMs, mappedObjectLabels, mappedObjectLinks, mappedObjectClasses, mappedObjectCoordTypes, mappedObjectStyles );
		//draw_areas(mappedAreaUTMs, mappedAreaLabels, mappedAreaLinks, mappedAreaClasses, mappedAreaCoordTypes, mappedAreaStyles);
		//draw_images(mappedImageUTMsArrayString, mappedImageFilesArrayString, mappedImageWidthsArrayString, mappedImageHeightsArrayString, mappedImageLabelsArrayString, mappedImageLinksArrayString, mappedImageClassesArrayString, mappedImageCoordTypesArrayString, mappedImageStylesArrayString);
	}
	else
	{
		warning.style.position = "relative";
		warning.style.visibility = "visible";

		if (mapTimerGoing) {
			clearTimeout(mapTimedWindow);
		}

		mapTimerGoing = true;
		mapTimedWindow = setTimeout('showCheckBoxImagesOnMap()', 500 );
	}
}


function addImageToMap( utm, file, width, height, label, link )
{
	if (addImageToMap.arguments.length > 6)
	{
		theClass = addImageToMap.arguments[ 6 ];
	}
	else
	{
		theClass = 'markerImage';
	}
	if (addImageToMap.arguments.length > 7)
	{
		coordType = addImageToMap.arguments[ 7 ];
	}
	else
	{
		coordType = '';
	}
	if (addImageToMap.arguments.length > 8)
	{
		theStyle = addImageToMap.arguments[ 8 ];
	}
	else
	{
		theStyle = '';
	}
	mappedImageUTMs    = mappedImageUTMs    + utm    + ';;';
	mappedImageFiles   = mappedImageFiles   + file   + ';;';
	mappedImageWidths  = mappedImageWidths  + width  + ';;';
	mappedImageHeights = mappedImageHeights + height + ';;';
	mappedImageLabels  = mappedImageLabels  + label  + ';;';
	mappedImageLinks   = mappedImageLinks   + link   + ';;';
	mappedImageClasses = mappedImageClasses + theClass + ';;';
	mappedImageStyles = mappedImageStyles + theStyle + '@@'; // can't use the semicolons here because things get messed up - in the future, why not just use arrays?
	mappedImageCoordTypes = mappedImageCoordTypes + coordType + ';;';
}


function addAreaToMap( utms, label, link )
{
	if (addAreaToMap.arguments.length > 3)
	{
		theClass = addAreaToMap.arguments[ 3 ];
	}
	else
	{
		theClass = 'markerArea';
	}
	if (addAreaToMap.arguments.length > 4)
	{
		coordType = addAreaToMap.arguments[ 4 ];
	}
	else
	{
		coordType = '';
	}
	if (addAreaToMap.arguments.length > 5)
	{
		theStyle = addAreaToMap.arguments[ 5 ];
	}
	else
	{
		theStyle = '';
	}
	mappedAreaUTMs   = mappedAreaUTMs   + utms  + ';;';
	mappedAreaLabels = mappedAreaLabels + label + ';;';
	mappedAreaLinks  = mappedAreaLinks  + link  + ';;';
	mappedAreaClasses  = mappedAreaClasses  + theClass + ';;';
	mappedAreaStyles  = mappedAreaStyles  + theStyle + '@@'; // can't use the semicolons here because things get messed up - in the future, why not just use arrays?
	mappedAreaCoordTypes  = mappedAreaCoordTypes  + coordType + ';;';
}
function addAreaSpecificToMap( utms, label, link )
{
	if (addAreaSpecificToMap.arguments.length > 3)
	{
		theClass = addAreaSpecificToMap.arguments[ 3 ];
	}
	else
	{
		theClass = 'markerArea';
	}
	if (addAreaSpecificToMap.arguments.length > 4)
	{
		coordType = addAreaSpecificToMap.arguments[ 4 ];
	}
	else
	{
		coordType = '';
	}
	if (addAreaSpecificToMap.arguments.length > 5)
	{
		theStyle = addAreaSpecificToMap.arguments[ 5 ];
	}
	else
	{
		theStyle = '';
	}
	mappedAreaSpecificUTMs   = mappedAreaSpecificUTMs   + utms  + ';;';
	mappedAreaSpecificLabels = mappedAreaSpecificLabels + label + ';;';
	mappedAreaSpecificLinks  = mappedAreaSpecificLinks  + link  + ';;';
	mappedAreaSpecificClasses  = mappedAreaSpecificClasses  + theClass + ';;';
	mappedAreaSpecificStyles  = mappedAreaSpecificStyles  + theStyle + '@@'; // can't use the semicolons here because things get messed up - in the future, why not just use arrays?
	mappedAreaSpecificCoordTypes  = mappedAreaSpecificCoordTypes  + coordType + ';;';
}
function resetAreaSpecifics()
{
	mappedAreaSpecificUTMs   = '';
	mappedAreaSpecificLabels = '';
	mappedAreaSpecificLinks  = '';
	mappedAreaSpecificClasses  = '';
	mappedAreaSpecificStyles  = '';
	mappedAreaSpecificCoordTypes  = '';
}


function addstationToMap( utm, label, link )
{
	if (addstationToMap.arguments.length > 3)
	{
		theClass = addstationToMap.arguments[ 3 ];
	}
	else
	{
		theClass = 'zoningCircle';
	}
	if (addstationToMap.arguments.length > 4)
	{
		coordType = addstationToMap.arguments[ 4 ];
	}
	else
	{
		coordType = '';
	}
	if (addstationToMap.arguments.length > 5)
	{
		theStyle = addstationToMap.arguments[ 5 ];
	}
	else
	{
		theStyle = '';
	}
	mappedObjectUTMs   = mappedObjectUTMs   + utm   + ';;';
	mappedObjectLabels = mappedObjectLabels + label + ';;';
	mappedObjectLinks  = mappedObjectLinks  + link + ';;';
	mappedObjectClasses  = mappedObjectClasses  + theClass + ';;';
	mappedObjectStyles  = mappedObjectStyles  + theStyle + '@@'; // can't use the semicolons here because things get messed up - in the future, why not just use arrays?
	mappedObjectCoordTypes  = mappedObjectCoordTypes  + coordType + ';;';
}

function showImageOnMap( utmx, utmy, imagename, width, height, hinttext )
{
	if (showImageOnMap.arguments.length > 6)
	{
		theClass = showImageOnMap.arguments[ 6 ];
	}
	else
	{
		theClass = 'markerImage';
	}
	if (showImageOnMap.arguments.length > 7)
	{
		theStyle = showImageOnMap.arguments[ 7 ];
	}
	else
	{
		theStyle = 'markerImage';
	}
	

	var index;
	while ( ( index = imagename.indexOf( "\\" ) ) != -1 )
	{
		imagename = imagename.substring( 0, index ) + "/" + imagename.substring( index + 1, imagename.length );
	}
	while ( ( index = imagename.indexOf( "/" ) ) != -1 )
	{
		imagename = imagename.substring( 0, index ) + "%2F" + imagename.substring( index + 1, imagename.length );
	}
	while ( ( index = imagename.indexOf( "&" ) ) != -1 )
	{
		imagename = imagename.substring( 0, index ) + "%26" + imagename.substring( index + 1, imagename.length );
	}
	while ( ( index = imagename.indexOf( "'" ) ) != -1 )
	{
		imagename = imagename.substring( 0, index ) + "%27" + imagename.substring( index + 1, imagename.length );
	}
	while ( ( index = hinttext.indexOf( "&" ) ) != -1 )
	{
		hinttext = hinttext.substring( 0, index ) + "%26" + hinttext.substring( index + 1, hinttext.length );
	}
	while ( ( index = hinttext.indexOf( "'" ) ) != -1 )
	{
		hinttext = hinttext.substring( 0, index ) + "%27" + hinttext.substring( index + 1, hinttext.length );
	}
	usingMultiple = false;
	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
		ifrm.src = "svg_map_php/map.php?appId=40&utm=" + utmx + "," + utmy + "&x=" + utmx + "&y=" + utmy +
			"&zoom=2&hinttext=" + hinttext + "&sr_formSend=true&myparent=true&imagefilename=" + imagename +
			"&imagewidth=" + width + "&imageheight=" + height + "&theClass=" + theClass + "&theStyle=" + theStyle;
	} else {
		newMapWindow = window.open ("svg_map_php/map.php?appId=40&utm=" + utmx + "," + utmy + "&x=" + utmx + "&y=" + utmy +
			"&zoom=2&hinttext=" + hinttext + "&sr_formSend=true&myparent=true&imagefilename=" + imagename +
			"&imagewidth=" + width + "&imageheight=" + height + "&theClass=" + theClass + "&theStyle=" + theStyle, "newMapWindow");
	}
}

function showstationOnMap( utmx, utmy, hinttext, link )
{
//	var myFindMsg = document.getElementById( "findCurrently" );
//	myFindMsg.style.visibility = "visible";
	if (showstationOnMap.arguments.length > 4)
	{
		theClass = showstationOnMap.arguments[ 4 ];
	}
	else
	{
		theClass = 'zoningCircle';
	}

	if (showstationOnMap.arguments.length > 5)
	{
		coordType = showstationOnMap.arguments[ 5 ];
	}
	else
	{
		coordType = '';
	}

	if (showstationOnMap.arguments.length > 6)
	{
		theStyle = showstationOnMap.arguments[ 6 ];
	}
	else
	{
		theStyle = '';
	}

	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
	}
	var warning = document.getElementById( "warning" );

	if ( typeof( svgMapFrameLoaded ) != "undefined" )
	{
		warning.style.visibility = "hidden";
		warning.style.position = "absolute";
		//set_primary_legend_vars(LegendTitle,LegendLabels,LegendColors,LegendImages);
		
		//alert( utmx+","+utmy+";;, "+ hinttext+";;, "+ link+";;, "+ theClass+";;, "+ coordType+";;, "+ theStyle+"@@" );
		
		draw_locations( utmx+","+utmy+";;", hinttext+";;", link+";;", theClass+";;", coordType+";;", theStyle+"@@" );
		draw_areas();
		//draw_areas(mappedAreaUTMs, mappedAreaLabels, mappedAreaLinks, mappedAreaClasses, mappedAreaCoordTypes, mappedAreaStyles);
		//draw_images(mappedImageUTMs, mappedImageFiles, mappedImageWidths, mappedImageHeights, mappedImageLabels, mappedImageLinks, mappedImageClasses, mappedImageCoordTypes, mappedImageStyles);
	}
	else
	{
		warning.style.position = "relative";
		warning.style.visibility = "visible";

		if (mapTimerGoing) {
			clearTimeout(mapTimedWindow);
		}
		mapTimerGoing = true;
		mapTimedWindow = setTimeout('showstationOnMap("'+utmx.replace(/"/g,'\\"')+'","'+utmy.replace(/"/g,'\\"')+'"'+((typeof(hinttext)!='undefined')?',"'+hinttext.replace(/"/g,'\\"')+'"':',""')+((typeof(link)!='undefined')?',"'+link.replace(/"/g,'\\"')+'"':',""')+((typeof(theClass)!='undefined')?',"'+theClass.replace(/"/g,'\\"')+'"':',""')+((typeof(coordType)!='undefined')?',"'+coordType.replace(/"/g,'\\"')+'"':',""')+((typeof(theStyle)!='undefined')?',"'+theStyle.replace(/"/g,'\\"')+'"':',""')+')', 500 );
	}

	/*
	// no need to reload the SVG window when the code is already there...
	var index;
	while ( ( index = hinttext.indexOf( "&" ) ) != -1 )
	{
		hinttext = hinttext.substring( 0, index ) + "%26" + hinttext.substring( index + 1, hinttext.length );
	}
	while ( ( index = hinttext.indexOf( "'" ) ) != -1 )
	{
		hinttext = hinttext.substring( 0, index ) + "%27" + hinttext.substring( index + 1, hinttext.length );
	}
	usingMultiple = false;
	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
		if (utmx > 1000000)
			ifrm.src = "svg_map_php/map.php?appId=40&utm=" + utmx + "," + utmy + "&pointx=" + utmx + "&pointy=" + utmy +
				"&zoom=2&pointText=" + hinttext + "&sr_formSend=true&myparent=true&theClass=" + theClass + "&coord_type=" + coordType + "&theStyle=" + theStyle;
		else
			ifrm.src = "svg_map_php/map.php?appId=40&utm=" + utmx + "," + utmy + "&pointx=" + utmx + "&pointy=" + utmy +
				"&zoom=2&pointText=" + hinttext + "&sr_formSend=true&myparent=true&theClass=" + theClass + "&coord_type=" + coordType + "&theStyle=" + theStyle;
	} else {
		if (utmx > 1000000)
			newMapWindow = window.open ("svg_map_php/map.php?appId=40&utm=" + utmx + "," + utmy + "&x=" + utmx + "&y=" + utmy +
				"&zoom=2&hinttext=" + hinttext + "&sr_formSend=true&myparent=true&theClass=" + theClass + "&coord_type=" + coordType + "&theStyle=" + theStyle, "newMapWindow");
		else
			newMapWindow = window.open ("svg_map_php/map.php?appId=40&utm=" + utmx + "," + utmy + "&x=" + utmx + "&y=" + utmy +
				"&zoom=2&hinttext=" + hinttext + "&sr_formSend=true&myparent=true&theClass=" + theClass + "&coord_type=" + coordType + "&theStyle=" + theStyle, "newMapWindow");
	}
	*/
}



function showAreaOnMap( coords, hinttext, link )
{
	if (showAreaOnMap.arguments.length > 3)
	{
		theClass = showAreaOnMap.arguments[ 3 ];
	}
	else
	{
		theClass = 'markerArea';
	}

	if (showAreaOnMap.arguments.length > 4)
	{
		coordType = showAreaOnMap.arguments[ 4 ];
	}
	else
	{
		coordType = '';
	}

	if (showAreaOnMap.arguments.length > 5)
	{
		theStyle = showAreaOnMap.arguments[ 5 ];
	}
	else
	{
		theStyle = '';
	}

	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
	}
	var warning = document.getElementById( "warning" );

	if ( typeof( svgMapFrameLoaded ) != "undefined" )
	{
		warning.style.visibility = "hidden";
		warning.style.position = "absolute";
		//set_primary_legend_vars(LegendTitle,LegendLabels,LegendColors,LegendImages);
		
		//alert( utmx+","+utmy+";;, "+ hinttext+";;, "+ link+";;, "+ theClass+";;, "+ coordType+";;, "+ theStyle+"@@" );
		
		//draw_locations( utmx+","+utmy+";;", hinttext+";;", link+";;", theClass+";;", coordType+";;", theStyle+"@@" );
		draw_locations();
		draw_areas( coords+";;", hinttext+";;", link+";;", theClass+";;", coordType+";;", theStyle+"@@" );
		//draw_areas(mappedAreaUTMs, mappedAreaLabels, mappedAreaLinks, mappedAreaClasses, mappedAreaCoordTypes, mappedAreaStyles);
		//draw_images(mappedImageUTMs, mappedImageFiles, mappedImageWidths, mappedImageHeights, mappedImageLabels, mappedImageLinks, mappedImageClasses, mappedImageCoordTypes, mappedImageStyles);
	}
	else
	{
		warning.style.position = "relative";
		warning.style.visibility = "visible";

		if (mapTimerGoing) {
			clearTimeout(mapTimedWindow);
		}
		mapTimerGoing = true;
		mapTimedWindow = setTimeout('showAreaOnMap("'+coords.replace(/"/g,'\\"')+'"'+((typeof(hinttext)!='undefined')?',"'+hinttext.replace(/"/g,'\\"')+'"':',""')+((typeof(link)!='undefined')?',"'+link.replace(/"/g,'\\"')+'"':',""')+((typeof(theClass)!='undefined')?',"'+theClass.replace(/"/g,'\\"')+'"':',""')+((typeof(coordType)!='undefined')?',"'+coordType.replace(/"/g,'\\"')+'"':',""')+((typeof(theStyle)!='undefined')?',"'+theStyle.replace(/"/g,'\\"')+'"':',""')+')', 500 );
	}
}


var mapTimerGoing, mapTimedWindow;
function showstationsOnMap()
{
	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
	}
	var warning = document.getElementById( "warning" );

	//alert( 'showLocationsOnMap2(mapheading.js):\n mappedObjectUTMs = "' + mappedObjectUTMs + '"\n mappedObjectLabels = "' + mappedObjectLabels + '"\n mappedObjectLinks = "' + mappedObjectLinks + '"\nmappedObjectClasses = "' + mappedObjectClasses + '"\nmappedObjectStyles = "' + mappedObjectStyles + '"' );

	// The drawing function is implemented in the SVG code, which
	// is loaded into an iframe;  thus, the following statement should
	// be included somewhere in the initialization sequence for that code:
	//   parent.svgMapFrameLoaded = name_of_some_implemented_function
	// The function takes three parameters: a list of UTM co-ordinates "utme,utmn",
	// a list of fly-over text labels and a list of URLs, where each
	// list is comprised of elements separated by two semi-colons
	// A warning is displayed if the SVG plug-in is not completely loaded
	// and the drawing function cannot be found yet.
	if ( typeof( svgMapFrameLoaded ) != "undefined" )
	{
		warning.style.visibility = "hidden";
		warning.style.position = "absolute";
		//set_primary_legend_vars(LegendTitle,LegendLabels,LegendColors,LegendImages);
		draw_locations( mappedObjectUTMs, mappedObjectLabels, mappedObjectLinks, mappedObjectClasses, mappedObjectCoordTypes, mappedObjectStyles );
		//draw_areas(mappedAreaUTMs, mappedAreaLabels, mappedAreaLinks, mappedAreaClasses, mappedAreaCoordTypes, mappedAreaStyles);
		//draw_images(mappedImageUTMs, mappedImageFiles, mappedImageWidths, mappedImageHeights, mappedImageLabels, mappedImageLinks, mappedImageClasses, mappedImageCoordTypes, mappedImageStyles);
	}
	else
	{
		warning.style.position = "relative";
		warning.style.visibility = "visible";

		if (mapTimerGoing) {
			clearTimeout(mapTimedWindow);
		}

		mapTimerGoing = true;
		mapTimedWindow = setTimeout('showstationsOnMap()', 500 );
	}
}
function showstationsSpecificOnMap()
{
	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
	}
	var warning = document.getElementById( "warning" );

	if ( typeof( svgMapFrameLoaded ) != "undefined" )
	{
		warning.style.visibility = "hidden";
		warning.style.position = "absolute";
		draw_locations( mappedObjectSpecificUTMs, mappedObjectSpecificLabels, mappedObjectSpecificLinks, mappedObjectSpecificClasses, mappedObjectSpecificCoordTypes, mappedObjectSpecificStyles );
		//draw_areas(mappedAreaSpecificUTMs, mappedAreaSpecificLabels, mappedAreaSpecificLinks, mappedAreaSpecificClasses, mappedAreaSpecificCoordTypes, mappedAreaSpecificStyles);
	}
	else
	{
		warning.style.position = "relative";
		warning.style.visibility = "visible";

		if (mapTimerGoing) {
			clearTimeout(mapTimedWindow);
		}

		mapTimerGoing = true;
		mapTimedWindow = setTimeout('showstationsSpecificOnMap()', 500 );
	}
}


function addObjectToMap(postalCode, label, link )
{
	if (addObjectToMap.arguments.length > 3) {
		theClass = addObjectToMap.arguments[3];
	} else {
		theClass = 'zoningCircle';
	}
	if (addObjectToMap.arguments.length > 4) {
		coordType = addObjectToMap.arguments[4];
	} else {
		coordType = '';
	}
	if (addObjectToMap.arguments.length > 5) {
		theStyle = addObjectToMap.arguments[5];
	} else {
		theStyle = '';
	}
		
	mappedObjectUTMs   = mappedObjectUTMs   + postalCode.replace(" ","") + ';;';
	mappedObjectLabels = mappedObjectLabels + label + ';;';
	mappedObjectLinks  = mappedObjectLinks  + link + ';;';
	mappedObjectClasses  = mappedObjectClasses  + theClass + ';;';
	mappedObjectStyles  = mappedObjectStyles  + theStyle + '@@'; // can't use the semicolons here because things get messed up - in the future, why not just use arrays?
	mappedObjectCoordTypes  = mappedObjectCoordTypes  + coordType + ';;';
}
function addObjectSpecificToMap(postalCode, label, link )
{
	if (addObjectSpecificToMap.arguments.length > 3) {
		theClass = addObjectSpecificToMap.arguments[3];
	} else {
		theClass = 'zoningCircle';
	}
	if (addObjectSpecificToMap.arguments.length > 4) {
		coordType = addObjectSpecificToMap.arguments[4];
	} else {
		coordType = '';
	}
	if (addObjectSpecificToMap.arguments.length > 5) {
		theStyle = addObjectSpecificToMap.arguments[5];
	} else {
		theStyle = '';
	}
		
	mappedObjectSpecificUTMs   = mappedObjectSpecificUTMs   + postalCode.replace(" ","") + ';;';
	mappedObjectSpecificLabels = mappedObjectSpecificLabels + label + ';;';
	mappedObjectSpecificLinks  = mappedObjectSpecificLinks  + link + ';;';
	mappedObjectSpecificClasses  = mappedObjectSpecificClasses  + theClass + ';;';
	mappedObjectSpecificStyles  = mappedObjectSpecificStyles  + theStyle + '@@'; // can't use the semicolons here because things get messed up - in the future, why not just use arrays?
	mappedObjectSpecificCoordTypes  = mappedObjectSpecificCoordTypes  + coordType + ';;';
}
function resetObjectSpecifics()
{
	mappedObjectSpecificUTMs   = '';
	mappedObjectSpecificLabels = '';
	mappedObjectSpecificLinks  = '';
	mappedObjectSpecificClasses  = '';
	mappedObjectSpecificStyles  = '';
	mappedObjectSpecificCoordTypes  = '';
}

function showLocationOnMap(postalCode, text)
{	
	if (showLocationOnMap.arguments.length > 2) {
		theClass = showLocationOnMap.arguments[2];
	} else {
		theClass = 'zoningCircle';
	}
	if (showLocationOnMap.arguments.length > 3) {
		theStyle = showLocationOnMap.arguments[3];
	} else {
		theStyle = 'zoningCircle';
	}
	
	var index;
	while ((index = text.indexOf("&")) != -1)
	{	text = text.substring(0,index) + "%26" + text.substring(index + 1, text.length);
	}
	while ((index = text.indexOf("'")) != -1)
	{	text = text.substring(0,index) + "%27" + text.substring(index + 1, text.length);
	}
	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
		ifrm.src = "svg_map_php/map.php?appId=40&amp;postalCode=" + postalCode.replace(" ","") + "&amp;hinttext= " + text + "&amp;theClass=" + theClass + "&amp;theStyle=" + theStyle;
	} else {
		newMapWindow = window.open ("svg_map_php/map.php?appId=40&amp;postalCode=" + postalCode.replace(" ","") + "&amp;hinttext= " + text + "&amp;theClass=" + theClass + "&amp;theStyle=" + theStyle, "newMapWindow");
	}
}



function showLocationsOnMap()
{
	if ( typeof(newMapWindow) == "undefined") {
		var ifrm = document.getElementById( "ap_iframe" );
		ifrm.width = "99%";
		ifrm.height = 700;
	}
	var warning = document.getElementById( "warning" );
	// alert( 'mappedObjectUTMs = "' + mappedObjectUTMs+ '"\nmappedObjectLabels = "' + mappedObjectLabels+ '"\nmappedObjectLinks = "' + mappedObjectLinks + '"' );

	// This function is implemented in the SVG application.
	// The following code should be located somewhere within it:
	// parent.svgMapFrameLoaded = name_of_some_implemented_function
	// which takes two parameters - display warning if SVG not loaded totally
	// and function cannot be found yet.
	if (typeof(svgMapFrameLoaded) != "undefined")
	{	warning.style.visibility = "hidden";
		warning.style.position = "absolute";
		//set_primary_legend_vars(LegendTitle,LegendLabels,LegendColors,LegendImages);
		draw_locations(mappedObjectUTMs, mappedObjectLabels, mappedObjectLinks, mappedObjectClasses, mappedObjectCoordTypes, mappedObjectStyles);
		draw_areas(mappedAreaUTMs, mappedAreaLabels, mappedAreaLinks, mappedAreaClasses, mappedAreaCoordTypes, mappedAreaStyles);
		//draw_images(mappedImageUTMs, mappedImageFiles, mappedImageWidths, mappedImageHeights, mappedImageLabels, mappedImageLinks, mappedImageClasses, mappedImageCoordTypes, mappedImageStyles);
	}
	else
	{	warning.style.position = "relative";
		warning.style.visibility = "visible";
		
		if (mapTimerGoing) {
			clearTimeout(mapTimedWindow);
		}

		mapTimerGoing = true;
		mapTimedWindow = setTimeout('showLocationsOnMap()', 500 );
	}
}

function updateForm(t, px, py, cx, cy, r, x1, x2, y1, y2)
{
	var frm;
	//if ( document.getElementById )
	//{
	//	frm = document.getElementById( "searchForm" );
	//}
	if ( document.getElementsByName )
	{
		frm = document.getElementsByName( "searchForm" );
		if(typeof(frm[0])!="undefined") frm=frm[0];
	}
	else
	{
		frm = document.forms[ "searchForm" ];
	}
	if(frm == null) { frm = document.forms[ "searchForm" ]; }
	frm.searchType.value = t;
	frm.searchPointX.value = px;
	frm.searchPointY.value = py;
	frm.searchCenterX.value = cx;
	frm.searchCenterY.value = cy;
	frm.searchRadius.value = r;
	frm.X1.value = x1;
	frm.X2.value = x2;
	frm.Y1.value = y1;
	frm.Y2.value = y2;
}

// updateSVGx -- when an admin form for a water source is displayed, a map with
//               editable utmX and utmY fields is displayed;  utmX specifies
//               updateSVGx as an onchange="" function to pass the changed value
//               to the mapping subsystem
function updateSVGx( x )
{
	window.set_x( x );
}
function updateSVGy( y )
{
	window.set_y( y );
}
