
//***********************************************	
//***************** FUNCTIONS *******************
//***********************************************
//doReefNameSearch()' 
function doAlert(){
	alert("The Reef selected is located at the center of the Reefsite because the exact coordinates are unavailable.");
}
// do code search
function doCode(){

	if(isNav4){
		theForm = document.SearchResults.document.frmCode;
	} else {
		theForm = document.frmCode;
	}

	showLayer("loadLayer");
	
	var theProblem = theForm.Code.options[theForm.Code.selectedIndex].value;

	document.frmNavigation.Cmd.value = 'SNAPSHOT';
	document.frmNavigation.Problem.value = theProblem;
	document.frmNavigation.ShowWhat.value = "";
			
	document.frmNavigation.target="";
	//document.frmNavigation.action = 'map.asp';
			
	document.frmNavigation.submit();
}

// do advance search
function doAdvSearch(){
	var theForm;

	if(isNav4){
		theForm = document.AdvSearch.document.frmAdvSearch;
	} else {
		theForm = document.frmAdvSearch;
	}
	if (theForm.FROMTIME.value == "") {
		theForm.FROMTIME.value =  "00:00";
	}
	if (theForm.TOTIME.value == "") {
		theForm.TOTIME.value =  "23:59";
	}
	if (theForm.FROMTIME.value > theForm.TOTIME.value) {
		alert("To Time must occur after From Time.");
		//return false;
	} else {
		if (theForm.FROMDATE.value == "") {
//			theForm.FROMDATE.value = theForm.MD_MDY.value;
			theForm.FROMDATE.value = document.frmNavigation.MD_MDY.value;
		}
		if (theForm.TODATE.value == "") {
//			theForm.TODATE.value = theForm.RD_MDY.value;
			theForm.TODATE.value = document.frmNavigation.RD_MDY.value;
		}
		if ( !checkdate(theForm.FROMDATE, "FD") ) {
			return;
		}
		if ( !checkdate(theForm.TODATE, "TD") ) {
			return;
		}
		if (Date.parse(theForm.FROMDATE.value) > Date.parse(theForm.TODATE.value)) {
			alert("To date must occur after the from date.");
			return;
		} else {
			showLayer("loadLayer");
			document.frmNavigation.ULD.value = theForm.FROMDATE.value;
			document.frmNavigation.URD.value = theForm.TODATE.value;

			document.frmNavigation.ULT.value = theForm.FROMTIME.value;
			document.frmNavigation.URT.value = theForm.TOTIME.value;

			document.frmNavigation.UDOW.value = theForm.DAYOFWEEK.options[theForm.DAYOFWEEK.selectedIndex].value;
			document.frmNavigation.UI.value = theForm.INCIDENT.options[theForm.INCIDENT.selectedIndex].value;

			document.frmNavigation.Cmd.value = 'SNAPSHOT';
			document.frmNavigation.target="";

			document.frmNavigation.submit();
		}
	}
}

// do landmark search
function doLandSearch(){
	if(isNav4){
		theForm = document.SearchLand.document.frmLand;
	} else {
		theForm = document.frmLand;
	}

	if (theForm.LandMark.options.selectedIndex == -1) {
		alert("Please select a landmark");
		//return;
	} else {
		showLayer("loadLayer");
		var theString = theForm.LandMark.options[theForm.LandMark.selectedIndex].value;
		var sX_COORD = theString.substring(0,13);
		var sY_COORD = theString.substring(13,26);
		var sName = theString.substring(26,theString.length);
		var fX_COORD = parseFloat(sX_COORD, 10);
		var fY_COORD = parseFloat(sY_COORD, 10);
				
		document.frmNavigation.Cmd.value = 'LANDMARK';
		document.frmNavigation.LM.value = theString;
		document.frmNavigation.GeocodeLabel.value = sName;
		document.frmNavigation.GeocodePoint_X.value = sX_COORD;
		document.frmNavigation.GeocodePoint_Y.value = sY_COORD;
		document.frmNavigation.ShowWhat.value = "";
				
		document.frmNavigation.target="";
		//document.frmNavigation.action = 'map.asp';
				
		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;
	
	var add1 = HN + " " + Dir + " " + StN + " " + StT;
	var Zone = ZC;
	
	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.Address1.value = add1;
		document.frmNavigation.Zone.value = ZC;
				
		document.frmNavigation.Cmd.value = 'ADDRESS';
		document.frmNavigation.target="";
		//document.frmNavigation.action = 'SexMap.asp';
				
		document.frmNavigation.submit();
	}
}


// do Reef Name search
function doReefNameSearch(){
	if(isNav4){
		theForm = document.SearchReef.document.frmReefname;
	} else {
		theForm = document.frmReefname;
	}
	RNT = theForm.reefname.options[theForm.reefname.options.selectedIndex].text;
	RN = theForm.reefname.options[theForm.reefname.options.selectedIndex].value;
	// RT = theForm.reeftype.options[theForm.reeftype.options.selectedIndex].value;
	// RD = theForm.reefdepth.options[theForm.reefdepth.options.selectedIndex].value;

		
	if(RN == ""){
		alert("Please enter a Reef name.");
	} else {
		showLayer("loadLayer");
		document.frmNavigation.reefname.value = RN;
		document.frmNavigation.GeocodeLabel.value = RNT;
		document.frmNavigation.GeoLabelFlag.value = 'Y';					
		document.frmNavigation.Cmd.value = 'REEFNAME';
		document.frmNavigation.Choice.value = 1;
		document.frmNavigation.reefsite.value="";
		document.frmNavigation.tablestatus.value=1;													
		document.frmNavigation.target="";
				
		document.frmNavigation.submit();
	}
}
// do All Reef search
function doAllReefSearch(){
	if(isNav4){
		theForm = document.SearchReef.document.frmAllReef;
	} else {
		theForm = document.frmAllReef;
	}
	ALLRT = theForm.reeftype.options[theForm.reeftype.options.selectedIndex].value;
	ALLRT = ALLRT.toUpperCase();
	ALLRD = theForm.reefdepth.options[theForm.reefdepth.options.selectedIndex].value;	
		
	if((ALLRT == "")&&(ALLRD == "")){
		alert("Please enter a Reef Type OR a Reef Depth.");
	} else {
		showLayer("loadLayer");
		document.frmNavigation.reeftype.value = ALLRT;
		document.frmNavigation.reefdepth.value = ALLRD ;
		document.frmNavigation.GeoLabelFlag.value = 'Y';										
		document.frmNavigation.Cmd.value = 'ALLREEF';
		document.frmNavigation.Choice.value = 3;
		document.frmNavigation.target="";
		document.frmNavigation.reefname.value="";
		document.frmNavigation.reefsite.value="";	
		document.frmNavigation.tablestatus.value=3;
		document.frmNavigation.submit();
	}
}

// do Reef Site search
function doReefSiteSearch(){
	if(isNav4){
		theForm = document.SearchReef.document.frmReefSite;
	} else {
		theForm = document.frmReefSite;
	}
	RS = theForm.reefsite.options[theForm.reefsite.options.selectedIndex].value;
		
	if(RS == ""){
		alert("Please enter a Reef Site");
	} else {
		showLayer("loadLayer");
		document.frmNavigation.reefsite.value = RS;
						
		document.frmNavigation.Cmd.value = 'REEFSITE';
		document.frmNavigation.Choice.value = 2;
		document.frmNavigation.target="";
		document.frmNavigation.reefname.value="";
		document.frmNavigation.tablestatus.value=2;							
		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;

	if((StN1 == "")||(StN2 == "")){
		alert("Please enter a street name.");
	} else {
		showLayer("loadLayer");

		document.frmNavigation.Address1.value = Dir1 + " " + StN1 + " " + StT1;
		document.frmNavigation.Address2.value = Dir2 + " " + StN2 + " " + StT2;
				
		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.Cmd.value = 'INTERSECTION';
		document.frmNavigation.target="";
		//document.frmNavigation.action = 'map.asp';
				
		document.frmNavigation.submit();
	}
}

// *************** ACTIVE.JS ********************

// set search tool
function setSearchTool(newTool) {
    
var content
//	setSearchToolImage(newTool);

	hideSearchLayers();
	if (newTool == "REEFNAME") {
		content = "";									// This is a trick to remove the scroll bar
		replaceLayerContent("SearchReefname", content);		// in the landmark layer when in N6
		content = writeReefnameForm();
		replaceLayerContent("SearchReefname", content);
		showLayer("SearchReefname");
	} else if (newTool == "REEFSITE") {
		content = "";									// This is a trick to remove the scroll bar
		replaceLayerContent("SearchReefname", content);		// in the landmark layer when in N6
		content = writeReefSiteForm();
		replaceLayerContent("SearchReefSite", content);
		showLayer("SearchReefSite");
	} else if (newTool == "ALLREEF") {
		content = "";									// This is a trick to remove the scroll bar
		replaceLayerContent("SearchReefname", content);		// in the landmark layer when in N6
		content = writeAllReefForm();
		replaceLayerContent("SearchAllReef", content);
		showLayer("SearchAllReef");
	} else if  (newTool == "ADDRESS") {
		content = "";									// This is a trick to remove the scroll bar
		replaceLayerContent("SearchLand", content);		// in the landmark layer when in N6
		content = writeAddressForm();
		replaceLayerContent("SearchAddr", content);
		showLayer("SearchAddr");
	} else if (newTool == "INTERSECTION") {
		content = "";									// This is a trick to remove the scroll bar
		replaceLayerContent("SearchLand", content);		// in the landmark layer when in N6
		content = writeIntersectionForm();
		replaceLayerContent("SearchInter", content);
		showLayer("SearchInter");
	} else if (newTool == "LANDMARK") {
		showLayer("SearchLand");
	} else if (newTool == "ADVSEARCH") {
		content = writeSearchForm();
		replaceLayerContent("AdvSearch", content);
		showLayer("AdvSearch");
	} else if (newTool == "RESULTS") {
		showLayer("SearchResults");
	}
//	document.frmNavigation.searchtool.value = newTool;

}

//hide search layers
function hideSearchLayers(){
	hideLayer("SearchReefSite");
	hideLayer("SearchAllReef");
	hideLayer("SearchReefName");
	hideLayer("SearchAddr");
	hideLayer("SearchInter");
	hideLayer("SearchLand");
	hideLayer("AdvSearch");
	hideLayer("SearchResults");
}

