
//***********************************************	
//***************** FUNCTIONS *******************
//***********************************************

// do landmark search
function doLandSearch(){
	if(isNav4){
		theForm = document.SearchLand.document.frmLand;
	} else {
		theForm = document.frmLand;
	}

	if (theForm.LandMark.options.selectedIndex == -1 || theForm.LandMark.options.selectedIndex == 0) {
		alert("Please select a landmark");
		return;
	} else {
		showLayer("loadLayer");

		var stringToSplit = theForm.LandMark.options[theForm.LandMark.selectedIndex].value;
		var arrayOfStrings = stringToSplit.split('*')

		if (arrayOfStrings.length == 5) {
			var sX_COORD = arrayOfStrings[0];
			var sY_COORD = arrayOfStrings[1];
			var sName = arrayOfStrings[2];
			var sLandAddr = arrayOfStrings[3];
			var sLandZip = arrayOfStrings[4];

			var fX_COORD = parseFloat(sX_COORD, 10);
			var fY_COORD = parseFloat(sY_COORD, 10);

			document.frmNavigation.SBY.value = 'LANDMARK';
			document.frmNavigation.Cmd.value = 'LANDMARK';
			document.frmNavigation.LM.value = sName;
			document.frmNavigation.GeoZC.value = sLandZip;
			document.frmNavigation.GeocodeLabel.value = sLandAddr;
			document.frmNavigation.GeocodePoint_X.value = sX_COORD;
			document.frmNavigation.GeocodePoint_Y.value = sY_COORD;
					
			document.frmNavigation.target="";

			document.frmNavigation.submit();
		}
	}
}

// do address search
function doAddrSearch(){
	if(isNav4){
		theForm = document.SearchAddr.document.frmAddr;
	} else {
		theForm = document.frmAddr;
	}
	HN = theForm.sHN1.value;
	Dir = theForm.sDir1.options[theForm.sDir1.options.selectedIndex].value;
	StN = theForm.sStN1.value;
	StT = theForm.sStT1.options[theForm.sStT1.options.selectedIndex].value;
	ZC = theForm.sZC1.value;
	
	if((HN == "")||(StN == "")){
		alert("Please enter a street number and name.");
	} else {
		showLayer("loadLayer");
		
		document.frmNavigation.HN1.value = HN;
		document.frmNavigation.Dir1.value = Dir;
		document.frmNavigation.StN1.value = StN ;
		document.frmNavigation.StT1.value = StT;
		document.frmNavigation.ZC1.value = ZC;

		document.frmNavigation.SBY.value = 'ADDRESS';
		document.frmNavigation.Cmd.value = 'ADDRESS';
		document.frmNavigation.target="";

		document.frmNavigation.submit();
	}
}

// do intersection search
function doInterSearch(){
	if(isNav4){
		theForm = document.SearchInter.document.frmInter;
	} else {
		theForm = document.frmInter;
	}

	var Dir1 = theForm.STDIR1.options[theForm.STDIR1.options.selectedIndex].value;
	var StN1 = theForm.STNAME1.value;
	var StT1 = theForm.STTYPE1.options[theForm.STTYPE1.options.selectedIndex].value;

	var Dir2 = theForm.STDIR2.options[theForm.STDIR2.options.selectedIndex].value;
	var StN2 = theForm.STNAME2.value;
	var StT2 = theForm.STTYPE2.options[theForm.STTYPE2.options.selectedIndex].value;

	var Zone = theForm.sZone.value;

	if((StN1 == "")||(StN2 == "")){
		alert("Please enter a street name.");
	} else {
		showLayer("loadLayer");

		document.frmNavigation.IDir1.value = Dir1;
		document.frmNavigation.IStN1.value = StN1;
		document.frmNavigation.IStT1.value = StT1;
				
		document.frmNavigation.IDir2.value = Dir2;
		document.frmNavigation.IStN2.value = StN2;
		document.frmNavigation.IStT2.value = StT2 ;

		document.frmNavigation.Zone.value = Zone;
				
		document.frmNavigation.SBY.value = 'INTERSECTION';
		document.frmNavigation.Cmd.value = 'INTERSECTION';
		document.frmNavigation.target="";

		document.frmNavigation.submit();
	}
}

// *************** ACTIVE.JS ********************

// set search tool
function setSearchTool(newTool) {
	var content = ""
	hideSearchLayers();
	if (newTool == "ADDRESS") {
		content = writeAddressForm();
		replaceLayerContent("SearchAddr", content);
		showLayer("SearchAddr");
	} else if (newTool == "INTERSECTION") {
		content = writeIntersectionForm();
		replaceLayerContent("SearchInter", content);
		showLayer("SearchInter");
	} else if (newTool == "LANDMARK") {
		content = writeLandmarkForm();
		replaceLayerContent("SearchLand", content);
		showLayer("SearchLand");
	} else if (newTool == "CSERVICES") {
		hideLayer("iFrameLayer");
		showLayer("floatframe");
	}
}

//hide search layers
function hideSearchLayers(){
	replaceLayerContent("SearchAddr", "");
	replaceLayerContent("SearchInter", "");
	replaceLayerContent("SearchLand", "");

	hideLayer("SearchAddr");
	hideLayer("SearchInter");
	hideLayer("SearchLand");
}

function swapImage(elImage, elSrc){

//ensure path to images directory is correct
	var path = '';
	var obj;

	if(document.images){
		// Check to see whether you are using a name, number, or object
		if (typeof(elImage) == 'string') {
			obj.src = (path + elSrc);
			obj.src = elSrc;
	  	} else if ((typeof(elImage) == 'object') && elImage && elImage.src) {
				elImage.src = elSrc;
		}
	}
}

function preloadImages() {
	//the call to this function should only be placed on the home page to cache images for whole site
	//ensure path to images directory is correct
	var themepath= 'images/Portal_img/';

	imagelist = new Array();
	imagelist[0] = themepath + 'gn_arrow_on.gif';
	imagelist[1] = themepath + 'gn_arrow_off.gif';

	document.preload = new Array();
	if (document.images) {
		for (var i = 0; i < imagelist.length; i++) {
			document.preload[i] = new Image();
			document.preload[i].src = imagelist[i];
		}
	}
}
