 
function fOpenHelp(){
	window.open("Help/FireMapViewer_Quickstart.html","","Height=450,Width=535,SCROLLBARS=YES,RESIZABLE=YES");
}


function fValidateInput(){
	//alert(document.frmSearch.cboMapSeries.options[document.frmSearch.cboMapSeries.selectedIndex].text);
	// check to see if "Dam Inundation" was selected ... that is really just a group heading
	if (document.frmSearch.cboMapSeries.options[document.frmSearch.cboMapSeries.selectedIndex].text == "Dam Inundation") {
		alert("Please select a specific dam inundation series.");
		return false; 
	}
	//loop thru search options, find the selection 	
	var SearchOptionSelected;
	for(var i = 0; i<document.frmSearch.radioSearchOption.length-1; i++){
		if(document.frmSearch.radioSearchOption[i].checked==true){
			SearchOptionSelected=document.frmSearch.radioSearchOption[i].value;
		}
	}
	//which option was selected
	switch(SearchOptionSelected){	
		case 'FireMapNumber':
			var strFireMapNumber;
			strFireMapNumber = document.frmSearch.txtFireMapNumber.value;
			if (strFireMapNumber.length <4){
				alert(strFireMapNumber + ' is too short to be a valid Fire Map #.' );
				return false;
			}
			else if(strFireMapNumber.length >5){
				alert(strFireMapNumber + ' is too long to be a valid Fire Map #.' );
				return false;
			}
			break;
		case 'TRSQ':
			var strTRSQ
			//var strTRSQ_noSpace
			strTRSQ = document.frmSearch.txtTRSQ.value;
			//strTRSQ = strTRSQ.replace(' ','');	//remove spaces
			//strTRSQ_noSpace = strTRSQ.replace(' ','');
			 
			if (strTRSQ.length <5){
				alert(strTRSQ + ' is too short to be a valid value.' );
				return false;
			}
			else if(strTRSQ.length >7){
				alert(strTRSQ + ' is too long to be a valid value.' );
				return false;
			}
			break;
			
		case 'StreetAddress':
			var strNumber;
			var strSteetName;

			strNumber = document.frmSearch.txtAddressNumber.value;
			strSteetName = document.frmSearch.txtAddressStreetName.value;

			if (strNumber.length==0){
				alert('Please enter an address #.');
				return false;
			}
			else if(strSteetName.length==0){
				alert('Please enter a Street Name.');
				return false;
			}
			//document.frmSearch.selectAddressType.style.background='#FFFFFF';
			//document.frmSearch.selectAddressCityZip.style.background='#FFFFFF';
			////document.frmSearch.txtAddressZipcode.style.background='#FFFFFF';
			break;
			
		case 'Intersection':
			var strSteetName1;
			var strSteetName2;

			strSteetName1 = document.frmSearch.txtIntersectionStreetName1.value;
			strSteetName2 = document.frmSearch.txtIntersectionStreetName2.value;

			if (strSteetName1.length==0){
				alert('Please enter an intersection street name.');
				return false;
			}
			else if(strSteetName2.length==0){
				alert('Please enter a second intersection street name.');
				return false;
			}
			
			//document.frmSearch.selectIntersectionCityZip.style.background='#FFFFFF';
			//document.frmSearch.txtIntersectionZipcode.style.background='#FFFFFF';
			break;

		case 'GeoCoordinates':
			var strLatitude;
			var strLongitude;
			strLatitude = trim(document.frmSearch.txtLatitude.value);
			strLongitude = trim(document.frmSearch.txtLongitude.value);
			
			if(strLatitude.length==0){
				alert('Please enter a Latitude.');
				return false;
			}
			else if(strLongitude.length==0){
				alert('Please enter a Longitude.');
				return false;
			}
			else{
				//lets check the format of the input
				var dblLat   	//default is 0
                var dblLon		//default is 0
                var strMsg
                var strMsgTitle
                var intFirstSpacePlace
                //validate lat
                //whats the format?
                intFirstSpacePlace = strLatitude.indexOf(' ');

                //is there a space indicating DMS or DM format?
                if(intFirstSpacePlace>=2){
                    //its lat in DMS or DM...is there a 2nd space?
                    if (strLatitude.indexOf(' ', intFirstSpacePlace + 1)== -1){
                        //there is only 1 space, so this is in DM
                        dblLat = fDM2DD(strLatitude);
					}
                    else{
                       //its DMS cause there are 2 spaces
                        dblLat = fDMS2DD(strLatitude);
                   }
                }    
				//is lat in DD?
                else if(strLatitude.indexOf('.') >= 2 || intFirstSpacePlace == -1){      
					dblLat = strLatitude;
                }    
                else{
                    dblLat = 0;
				}
          
                if (dblLat == 0){
                    strMsg = 'Please enter Latitude in a proper format such as: \n' ; 
                    strMsg = 'Please enter Latitude in a proper format such as:\n\n';
                    strMsg = strMsg + 'Degree Minute Seconds (ie: 42 11 45)\n\n';
                    strMsg = strMsg + 'OR\n\n';
                    strMsg = strMsg + 'Decimal Degrees (ie: 42.195833)\n\n';
                    strMsg = strMsg + 'OR\n\n';
                    strMsg = strMsg + 'Degrees Minutes (ie: 42 11.8)';
                    strMsgTitle = 'Invalid Latitude Formatting';
               }
                //validate Lon
                //whats the format?
                intFirstSpacePlace = strLongitude.indexOf(' ');

                //is there a space indicating DMS or DM format?
                if(intFirstSpacePlace>=2){
                    //its Lon in DMS or DM...is there a 2nd space?
                    if (strLongitude.indexOf(' ', intFirstSpacePlace + 1)== -1){
                        //there is only 1 space, so this is in DM
                        dblLon = fDM2DD(strLongitude);
					}
                    else{
                       //its DMS cause there are 2 spaces
                        dblLon = fDMS2DD(strLongitude);
                   }
                }    
                else if(strLongitude.indexOf('.') >= 2 || intFirstSpacePlace == -1){      //is Lon in DD?
                    //dblLon = CDbl(strLongitude);
					dblLon = strLongitude;
                }    
                else{
                    dblLon = 0;
				}
                                
                if (dblLon == 0){
                    strMsg = 'Please enter Longitude in a proper format such as: \n' ; 
                    strMsg = 'Please enter Longitude in a proper format such as:\n\n';
                    strMsg = strMsg + 'Degree Minute Seconds (ie: 42 11 45)\n\n';
                    strMsg = strMsg + 'OR\n\n';
                    strMsg = strMsg + 'Decimal Degrees (ie: 42.195833)\n\n';
                    strMsg = strMsg + 'OR\n\n';
                    strMsg = strMsg + 'Degrees Minutes (ie: 42 11.8)';
                    strMsgTitle = 'Invalid Longitude Formatting';
               }
				//do we have properly formatted data?
                if (dblLat == 0) {
				    alert(strMsg);
					return false;
				}
                else if (dblLon == 0) {
				    alert(strMsg);
					return false;
                }
				else { 
					if (document.frmSearch.cboCounty.options[document.frmSearch.cboCounty.selectedIndex].text == 'Jackson') {
						if (dblLat < 42 || dblLat > 42.9) {			//OR
						   alert('Latitude is out of range for Jackson County, Oregon\n\nPlease enter a latitude between 42 and 42.9.');
							return false;
		                }
						else if (Math.abs(dblLon) < 122.2 || Math.abs(dblLon) > 123.2) {	//OR
						    alert('Longitude ' + dblLon +' is out of range for Jackson County, Oregon\n\nPlease enter a longitude between between -123.2 and -122.2.');
							return false;
		                }
					}
					else if	(document.frmSearch.cboCounty.options[document.frmSearch.cboCounty.selectedIndex].text == 'Josephine') {
						if (dblLat < 42 || dblLat > 42.8) {			//OR
						   alert('Latitude is out of range for Josehphine County, Oregon\n\nPlease enter a latitude between 42.7 and 42.39.');
							return false;
		                }
						else if (Math.abs(dblLon) < 123.19 || Math.abs(dblLon) > 124.1) {	//OR
						    alert('Longitude ' + dblLon +' is out of range for Josephine County, Oregon\n\nPlease enter a longitude between between -123.68 and -123.71.');
							return false;
		                }
					}
				}
			}
			document.frmSearch.hiddenLatitudeDD.value=dblLat;
			document.frmSearch.hiddenLongitudeDD.value=dblLon;
			break;
		case 'Milepost':
			var strMilepost;
			strMilepost = document.frmSearch.txtMilepost.value;
			
			if (document.frmSearch.selectHighway.selectedIndex<=0){
				alert('Please select a Highway.');
				return false;
			}
			else if(strMilepost.length==0){
				alert('Please enter a milepost.');
				return false;
			}

			break;
		case 'CommonPlaceName':
			var strCommonPlaceName;
			strCommonPlaceName = document.frmSearch.txtCommonPlaceName.value;
			if (strCommonPlaceName.length==0){
				alert('Please enter a common place search text.');
				return false;
			}
			break;
			
		case 'ClickMap':
			//alert('CLickMap');
			if (document.frmSearch.selectFireDistrict.selectedIndex<=0){
				alert('Please select a Fire District.');
				return false;
			}
			break;
	}
	fGetMap();
}
	
function fGetMap(){ 
	//Submit the form 
	//document.forms(0).submit();
	document.forms[0].submit();
}

//function fSetSearchOption(iiEnable){
function fSetSearchOption(parRadioOptionName){
	//loop thru all search radion options, clearing them
	//set true radio via index
	for(var i = 0; i<=document.frmSearch.radioSearchOption.length-1; i++){
		document.frmSearch.radioSearchOption[i].checked=false;
		if(document.frmSearch.radioSearchOption[i].id == parRadioOptionName){
			document.frmSearch.radioSearchOption[i].checked=true;
		}
	}
	//document.frmSearch.radioSearchOption[iiEnable].checked=true;
}

function fEnableSearchOption(strOptionSelected,strCounty){
	//alert('fEnableSearchOption(' + strOptionSelected +')');
	//clear the input & grey controls out
	fClearInputControls(strOptionSelected,strCounty);
	
	//set our radio option & whiten input controls for our selected option
	switch(strOptionSelected){
		case 'FireMapNumber':
			//fSetSearchOption(0);
			fSetSearchOption('radioSearchOption_FireMapNumber');
			document.frmSearch.txtFireMapNumber.style.background='#FFFFFF';
			break;
		case 'TRSQ':
			//fSetSearchOption(1);
			fSetSearchOption('radioSearchOption_TRS');
			document.frmSearch.txtTRSQ.style.background='#FFFFFF';
			break;
		case 'StreetAddress':
			if (strCounty=="JACKSON") {
				//fSetSearchOption(2);
				fSetSearchOption('radioSearchOption_StreetAddress');
				document.frmSearch.txtAddressNumber.style.background='#FFFFFF';
				document.frmSearch.selectAddressNEWS.style.background='#FFFFFF';
				document.frmSearch.txtAddressStreetName.style.background='#FFFFFF';
				document.frmSearch.selectAddressType.style.background='#FFFFFF';
				document.frmSearch.selectAddressCityZip.style.background='#FFFFFF';
				//document.frmSearch.txtAddressZipcode.style.background='#FFFFFF';
			}
			else {
				fClearInputControls('StreetAddress',strCounty)
			
				document.frmSearch.txtAddressNumber.disabled=true;
				document.frmSearch.selectAddressNEWS.disabled=true;
				document.frmSearch.txtAddressStreetName.disabled=true;
				document.frmSearch.selectAddressType.disabled=true;
				document.frmSearch.selectAddressCityZip.disabled=true;
			}
			break;
		case 'Intersection':
			if (strCounty=="JACKSON") {
				fSetSearchOption('radioSearchOption_Intersection');
				document.frmSearch.selectIntersectionNEWS1.style.background='#FFFFFF';
				document.frmSearch.txtIntersectionStreetName1.style.background='#FFFFFF';
				document.frmSearch.selectIntersectionStreetType1.style.background='#FFFFFF';
			
				document.frmSearch.selectIntersectionNEWS2.style.background='#FFFFFF';
				document.frmSearch.txtIntersectionStreetName2.style.background='#FFFFFF';
				document.frmSearch.selectIntersectionStreetType2.style.background='#FFFFFF';	
			
				document.frmSearch.selectIntersectionCityZip.style.background='#FFFFFF';
				//document.frmSearch.txtIntersectionZipcode.style.background='#FFFFFF';
			}
			else {
				fClearInputControls('Intersection',strCounty)
				
				document.frmSearch.selectIntersectionNEWS1.disabled=true;
				document.frmSearch.txtIntersectionStreetName1.disabled=true;
				document.frmSearch.selectIntersectionStreetType1.disabled=true;
			
				document.frmSearch.selectIntersectionNEWS2.disabled=true;
				document.frmSearch.txtIntersectionStreetName2.disabled=true;
				document.frmSearch.selectIntersectionStreetType2.disabled=true;	
			
				document.frmSearch.selectIntersectionCityZip.disabled=true;
			}
			break;
		case 'GeoCoordinates':
			fSetSearchOption('radioSearchOption_GeoCoordinates');
			document.frmSearch.txtLatitude.style.background='#FFFFFF';
			document.frmSearch.txtLongitude.style.background='#FFFFFF';
			break;
		case 'Milepost':
			fSetSearchOption('radioSearchOption_Milepost');
			document.frmSearch.selectHighway.style.background='#FFFFFF';
			document.frmSearch.txtMilepost.style.background='#FFFFFF';
			break;
		case 'CommonPlaceName':
			fSetSearchOption('radioSearchOption_CommonPlaceName');
			document.frmSearch.txtCommonPlaceName.style.background='#FFFFFF';
			if (strCounty=="JACKSON") {
				document.frmSearch.selectCommonPlaceCity.style.background='#FFFFFF';
			}
			break;
		case 'ClickMap':
			fSetSearchOption('radioSearchOption_ClickMap');
			document.frmSearch.selectFireDistrict.style.background='#FFFFFF';
			break;
	}


}

function fClearInputControls(strDontClearOption,strCounty){
	//alert('fClearInputControls(' + strDontClearOption + ')');

	//firemap#
	if(strDontClearOption != 'FireMapNumber'){
	    document.frmSearch.txtFireMapNumber.value="";
		document.frmSearch.txtFireMapNumber.style.background='#CCCCCC';
	}
	
	//trsq
	if(strDontClearOption != 'TRSQ'){
		document.frmSearch.txtTRSQ.value="";
		document.frmSearch.txtTRSQ.style.background='#CCCCCC';
	}
	
	//street address
	if (strCounty=="JACKSON") {
		if(strDontClearOption != 'StreetAddress'){
			document.frmSearch.txtAddressNumber.value="";
			document.frmSearch.selectAddressNEWS.value="";
			document.frmSearch.txtAddressStreetName.value="";
			document.frmSearch.selectAddressType.value="";
			document.frmSearch.selectAddressCityZip.value="";
			//document.frmSearch.txtAddressZipcode.value="";
			
			document.frmSearch.txtAddressNumber.style.background='#CCCCCC';
			document.frmSearch.selectAddressNEWS.style.background='#CCCCCC';
			document.frmSearch.txtAddressStreetName.style.background='#CCCCCC';
			document.frmSearch.selectAddressType.style.background='#CCCCCC';
			document.frmSearch.selectAddressCityZip.style.background='#CCCCCC';
			//document.frmSearch.txtAddressZipcode.style.background='#CCCCCC';
		}
	}

	//intersection
	if (strCounty=="JACKSON") {
		if(strDontClearOption != 'Intersection'){
			document.frmSearch.selectIntersectionNEWS1.value="";
			document.frmSearch.txtIntersectionStreetName1.value="";
			document.frmSearch.selectIntersectionStreetType1.value="";
			document.frmSearch.selectIntersectionNEWS2.value="";
			document.frmSearch.txtIntersectionStreetName2.value="";
			document.frmSearch.selectIntersectionStreetType2.value="";	
			document.frmSearch.selectIntersectionCityZip.value="";
			//document.frmSearch.txtIntersectionZipcode.value="";
		
			document.frmSearch.selectIntersectionNEWS1.style.background='#CCCCCC';
			document.frmSearch.txtIntersectionStreetName1.style.background='#CCCCCC';
			document.frmSearch.selectIntersectionStreetType1.style.background='#CCCCCC';
			document.frmSearch.selectIntersectionNEWS2.style.background='#CCCCCC';
			document.frmSearch.txtIntersectionStreetName2.style.background='#CCCCCC';
			document.frmSearch.selectIntersectionStreetType2.style.background='#CCCCCC';	
			document.frmSearch.selectIntersectionCityZip.style.background='#CCCCCC';
			//document.frmSearch.txtIntersectionZipcode.style.background='#CCCCCC';
		}
	}

	
	
	//GeoCoordinates
	if(strDontClearOption != 'GeoCoordinates'){
		document.frmSearch.txtLatitude.value="";
		document.frmSearch.txtLongitude.value="";
		document.frmSearch.txtLatitude.style.background='#CCCCCC';
		document.frmSearch.txtLongitude.style.background='#CCCCCC';
	}	
		
	//milepoint
	if(strDontClearOption != 'Milepost'){
		document.frmSearch.selectHighway.value="";
		document.frmSearch.txtMilepost.value="";
		document.frmSearch.selectHighway.style.background='#CCCCCC';
		document.frmSearch.txtMilepost.style.background='#CCCCCC';
	}
	//CommonPlaceName
	if(strDontClearOption != 'CommonPlaceName'){
		document.frmSearch.txtCommonPlaceName.value="";
		document.frmSearch.txtCommonPlaceName.style.background='#CCCCCC';
		if (strCounty=="JACKSON") {
			document.frmSearch.selectCommonPlaceCity.value="";
			document.frmSearch.selectCommonPlaceCity.style.background='#CCCCCC';
		}
	}
	//clickmap
	if(strDontClearOption != 'ClickMap'){
		document.frmSearch.selectFireDistrict.value="";
		document.frmSearch.selectFireDistrict.style.background='#CCCCCC';
	}
}





function fDMS2DD(par_strDMS){
  //converts DMS to decimal degrees
  var arrDMS
  var dblDD

  arrDMS = par_strDMS.split(' ');
  dblDD = Math.abs(arrDMS[0]) + (arrDMS[1] / 60) + (arrDMS[2] / 3600);

  if (arrDMS[0] < 0){ 
    dblDD = dblDD * -1;
  }

  //dblDD = Math.round(dblDD);		//lookout round to 6th place 
  dblDD = Math.round(dblDD*1000000)/1000000;		//lookout round to 6th place 
  return dblDD;
}



function fDM2DD(par_strDM){
  //converts DM to decimal degrees
  var arrDM
  var dblDD
  
  arrDM = par_strDM.split(' ');
    
  dblDD = Math.abs(arrDM[0]) + (arrDM[1] / 60);
  if(arrDM[0] < 0){
    dblDD = dblDD * -1;
  }

  //dblDD = Math.ceil(dblDD);		//lookout round to 6th place 
  dblDD = Math.round(dblDD*1000000)/1000000;		//lookout round to 6th place
  return dblDD;
}







function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   //result = trim(inputString);

   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


