
//***********************************************	
//***************** FUNCTIONS *******************
//***********************************************

// 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 ( !checktime(theForm.FROMTIME, "FT") ) return;
	
	if ( !checktime(theForm.TOTIME, "TT") ) return;

	if (theForm.FROMTIME.value > theForm.TOTIME.value) {
		alert("To Time must occur after From Time.");
		return;
	}

	if (theForm.FROMDATE.value == "") {
		theForm.FROMDATE.value = document.frmNavigation.MD_MDY.value;
	}
	if (theForm.TODATE.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;
	}
	
	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 theString = theForm.LandMark.options[theForm.LandMark.selectedIndex].value;
		var arrayOfStrings = theString.split(';');

		if (arrayOfStrings.length == 3) {
		    var sX_COORD = arrayOfStrings[0];
		    var sY_COORD = arrayOfStrings[1];
		    var sName = arrayOfStrings[2];
		    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();
		}else{
		    alert("Error loading landmark");
        }
	}
}

// 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 = 'seop.asp';
				
		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();
	}
}

// do folio search
function doFolioSearch(){
	if(isNav4){
		theForm = document.SearchFolio.document.frmFolio;
	} else {
		theForm = document.frmFolio;
	}
	var sFolio = theForm.txtfolio.value;
	if(sFolio == ""){
		alert("Please enter a folio number.");
	} else {
		showLayer("loadLayer");
		document.frmNavigation.Cmd.value = 'FOLIO';
		document.frmNavigation.folio.value = sFolio;
		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 == "FOLIO") {
		content = writeFolioForm();
		replaceLayerContent("SearchFolio", content);
		showLayer("SearchFolio");
	} else if (newTool == "LANDMARK") {
		showLayer("SearchLand");
	} else if (newTool == "ADVSEARCH") {
		content = writeSearchForm();
		replaceLayerContent("AdvSearch", content);
		showLayer("AdvSearch");
	} else if (newTool == "RESULTS") {
		showLayer("SearchResults");
	} else if (newTool == "SCHOOL") {
		showLayer("SearchSchool");
	} else if (newTool == "MPOSEARCH") {
		content = writeMPOSearchForm();
		replaceLayerContent("AdvSearch", content);
		showLayer("AdvSearch");
	}
}

//hide search layers
function hideSearchLayers(){
	hideLayer("SearchAddr");
	hideLayer("SearchInter");
//	hideLayer("SearchFolio");
	hideLayer("SearchLand");
	hideLayer("AdvSearch");
	hideLayer("SearchResults");
}

