// JavaScript Document 2nd part land javascript1.1
	function submitHandler() {
		var i = document.searchform.county_id.selectedIndex;
		if (i == -1) {
			alert("A county must first be selected.");
			document.searchform.county_id.focus();
			return false;
		} else {
			// check to ensure that elements other than county_id and status have been selected
			// to refine the scope of the search
			var mycounter = 0;
			for (i = 0; i <= document.searchform.elements.length - 1; i++) {
				if (document.searchform.elements[i].type == "text") {
					if (document.searchform.elements[i].value != "") {
						mycounter = mycounter + 1;
					}
				}else if (document.searchform.elements[i].type == "select-multiple") {
					if ((document.searchform.elements[i].name != "county_id") && (document.searchform.elements[i].name != "status")) {
					// if it is not county or status fields
						if (document.searchform.elements[i].selectedIndex != -1) {
							mycounter = mycounter + 1;
						}
					}
				}else if (document.searchform.elements[i].type == "select-one") {			
					if (document.searchform.elements[i].selectedIndex != 0) {
						var selectName = document.searchform.elements[i].name;
						if (selectName.substr(selectName.length - 3, 3) != "_op") {
							// if it is not the options for to, exactly, more or less
							mycounter = mycounter + 1;
						}
					}											
				}else if(document.searchform.elements[i].type == "radio") {
					radioName = document.searchform.elements[i].name;
					radioLength = eval("document.searchform." + radioName + ".length")
					// check to ensure that check is not for E or 2 meaning "either"
					for (j=0;j<=radioLength-1;j++) {
						if ((eval("document.searchform." + radioName + "[j].value") != 2) && (eval("document.searchform." + radioName + "[j].value") != "E")) {
							if (eval("document.searchform." + radioName + "[j].checked") == true) {
								mycounter = mycounter + 1;
							}
						}
					}
				}
			}
		}				
		if (mycounter > 0) {
			return true;
		}else{
			alert("Search results are too large.\nPlease refine search criteria.");
		return false;
		}
	}	
	
	function validateCounty() {
		var selectedCounties = 0;
		for (i = 0; i <= document.searchform.county_id.length - 1; i++) {
			if (document.searchform.county_id.options[i].selected == true) {
				selectedCounties = selectedCounties + 1;
				if (selectedCounties > 3) {
					alert("A maximum of 3 counties are allowed.\nPlease re-select counties.");
					document.searchform.county_id.selectedIndex = -1;
				}
			}
		}
//		updatehiddenlists();
	}
	
	function selectList(selectName) {
		var incrementer = 0;
		var list = "";
		
		switch(selectName){
  			case "county_id":
				for (i = 0; i <= document.searchform.county_id.length - 1; i++) {
					if (document.searchform.county_id.options[i].selected == true) {
						incrementer = incrementer + 1;
						if (incrementer == 1) {
							list=list + document.searchform.county_id[i].value ;
						}
						else {
							list=list + "," + document.searchform.county_id[i].value ;
						}					
					}
				}
				document.searchform.county_idlist.value = list;
  				break;
  			case "perc_type":
				for (i = 0; i <= document.searchform.perc_type.length - 1; i++) {
					if (document.searchform.perc_type.options[i].selected == true) {
						incrementer = incrementer + 1;
						if (incrementer == 1) {
							list=list + document.searchform.perc_type[i].value ;
						}
						else {
							list=list + "," + document.searchform.perc_type[i].value ;
						}					
					}
				}
				document.searchform.perc_typelist.value = list;
  				break;
  			case "street_dir":
				for (i = 0; i <= document.searchform.street_dir.length - 1; i++) {
					if (document.searchform.street_dir.options[i].selected == true) {
						incrementer = incrementer + 1;
						if (incrementer == 1) {
							list=list + document.searchform.street_dir[i].value ;
						}
						else {
							list=list + "," + document.searchform.street_dir[i].value ;
						}					
					}
				}
				document.searchform.street_dirlist.value = list;
  				break;
			}
	}
	
	function updatehiddenlists(){
		selectList("county_id");	
		//selectList("street_dir");
		selectList("perc_type");
	}
	
	function updateSearch(SearchID) {
		if (submitHandler()) {	
//			updatehiddenlists();
			document.searchform.target = "_self";
			document.searchform.action = "/user_ControlPanel/inserteditsearch.cfm?classification=Lot%20Land&process=edit&search_id=" + SearchID;
			document.searchform.submit();
		}
	}
	
	function saveSearch() {
		if (submitHandler()) {	
			searchName = prompt("Please enter a Search Name", "");
			if ((searchName != "") && (searchName != null)) {
//				updatehiddenlists();
				document.searchform.target = "_self";
				document.searchform.action = "http://dutydesk.mris.com/user_ControlPanel/inserteditsearch.cfm?classification=Lot%20Land&process=insert&search_name=" + searchName;
				document.searchform.submit();	
			}else if (searchName == "") {
				alert("You must enter a name to save a search.\n\nPlease Try Again.");
			}
		}
	}
	
		function resetSearchForm() {
			document.searchform.reset();
		}
		
		function startSearch() {
			if (submitHandler()) {
//				updatehiddenlists();
//				document.searchform.action="http://dutydesk.mris.com/search_results.cfm?classification=Lot%20Land&search_type=search";
				document.searchform.action="http://dutydesk.mris.com/lot_land/search_results.cfm?classification=Lot%20Land";
				document.searchform.target="_self";

				document.searchform.submit();					
			}
		}
		
		function clearFormValues() {
		// the purpose of this function is to reset all value on the form if the user
		// the purpose of this function is to clear all form values when the user selects 
		// to perform a new search
			for (i = 0; i <= document.searchform.elements.length - 1; i++) {
				if (document.searchform.elements[i].type == "text") {
					document.searchform.elements[i].value = "";
				}else if (document.searchform.elements[i].type == "select-multiple") {
					document.searchform.elements[i].selectedIndex = -1;
				}else if (document.searchform.elements[i].type == "select-one") {
					document.searchform.elements[i].selectedIndex = 0;				
				}
			}
		}
		
		function runviewcriteria(){
			if (submitHandler()) {		
//				updatehiddenlists();
//			openWin('/user_ControlPanel/search_criteria.cfm?fromForm=1','Criteria');
				document.searchform.action = "/user_controlpanel/search_criteria_ff.cfm?classification=classification%3D%3Ccfoutput%3ELot%20Land%3C%2Fcfoutput%3E";
				document.searchform.submit();
			}
		}
				
		function openWin( windowURL, item ) {
			if (submitHandler()) {
				switch(item){
		  			case "Criteria":
		   				var mywidth = 640;
		   				var myheight = 480;  
		  				break;
				}
				var winl = parseInt((screen.width - mywidth) / 2);
				var wint = parseInt((screen.height - myheight) / 2);
				var myWindowName = "ViewCriteriaWin";
				var myURL = windowURL;
				windowFeatures = "height=" + myheight+ ",width=" + mywidth + ",top=" + wint + ",left=" + winl + ",scrollbars,resizable,menubar";
		  		if (window.myWin && window.myWin.open && !window.myWin.closed) {  
					myWin.close();
				}	
			  	myWin = window.open(myURL, myWindowName, windowFeatures);
			  	myWin.focus();
				document.searchform.action=myURL ;
				document.searchform.target=myWindowName; 
				document.searchform.submit() ;
			}
		}
