/*-------------------------------------------------------------------
Fills a dropdown listbox with values from a string.
Values must be separated by "%^" ("percent caret")

cboTemp  -- the select box to prop
strVals  -- values in a string separated by percent caret
strTexts -- it's ugly to have #2/1/2001# so strTexts is added to
		show what should be displayed in the select boxes
		window
--------------------------------------------------------------------*/
function propCbo(cboTemp,strVals,strTexts) {
//	alert(strVals);
	cboTemp.options.length = 0;		// clear the values in this list
	aStrVals = strVals.split('%^');		// hopefully "percent caret" will never appear in a field
	aStrTexts = strTexts.split('%^');

	cboTemp.options[cboTemp.options.length] = new Option("Please select a value","no_data");
	for (i=0;i < aStrVals.length;i++) {	// run through the key field
		cboTemp.options[cboTemp.options.length] = new Option(aStrTexts[i],aStrVals[i]);
	};
	cboTemp.options[0].selected = true;	// select the first entry
	return true;
};


function checkKeywords(key1, key2, col1, col2)	{
	booRet = true;

	//alert(key1 + " :: " + key2 + " :: " + col1 + " :: " + col2);

	if (col1 == 'no_data')	{
		alert('Please enter a Search Field and Keyword in the first Search Field and Keyword entry blocks.');
		booRet = false;
	}	else	{
		if (key1 == 'no_data')	{
			alert('No keyword has been selected for your first Search Field.\nPlease reselect your Search Field and Keyword.');
			booRet = false;
		}	// else we're golden in col1 and key1
	}
	if (col2 != 'no_data' && key1 != 'no_data' && col1 != 'no_data')	{	// don't sweat it if no_data -- no second col selected
	           // if col1 or key1 == 'no_data' then we gotz other problems already.  Don't sweat reporting this part.
		if (key2 == 'no_data')	{
			if (!confirm('No keyword has been selected for your second Search Field though you have selected a field.\nPlease press "Cancel" to reselect your second Search Field and second Keyword or "OK" to continue this search without a second Keyword.'))	{
				booRet = false;
			}	// if it's true then we keep whatever we already had.
		}
	}
	return booRet;
}


function initPage()	{
	//alert(document.forms['rest_search'].elements['whichColumn'].value);
	if (document.forms['rest_search'].elements['whichColumn'].value != 'no_data')	{
		srcs = window.open ('getKeywords.asp?ordPos=' + escape(document.forms['rest_search'].elements['whichColumn'].options[document.forms['rest_search'].elements['whichColumn'].selectedIndex].value), 'SrcWin',
	   		'scrollbars=yes,status=yes,width=650,height=200');
	}
	if (document.forms['rest_search'].elements['whichColumn2'].value != 'no_data')	{
		//alert(document.forms['rest_search'].elements['whichColumn2'].value);
        	srcs = window.open ('getKeywords.asp?whichElem=2&ordPos=' + escape(document.forms['rest_search'].elements['whichColumn2'].options[document.forms['rest_search'].elements['whichColumn2'].selectedIndex].value), 'SrcWin',
        		'scrollbars=yes,status=yes,width=650,height=200');
	}
}

function openResults()	{
	if (checkKeywords(document.forms['rest_search'].elements['keyword'].options[document.forms['rest_search'].elements['keyword'].selectedIndex].value, document.forms['rest_search'].elements['keyword2'].options[document.forms['rest_search'].elements['keyword2'].selectedIndex].value, document.forms['rest_search'].elements['whichColumn'].options[document.forms['rest_search'].elements['whichColumn'].selectedIndex].value, document.forms['rest_search'].elements['whichColumn2'].options[document.forms['rest_search'].elements['whichColumn2'].selectedIndex].value))	{
		// escape the values so that the operators, quotes, etc are taken out
		strPageName = './mergeReport.asp?whichColumn=' + escape(document.forms['rest_search'].elements['whichColumn'].options[document.forms['rest_search'].elements['whichColumn'].selectedIndex].value);
		strPageName = strPageName + '&whichColumn2=' + escape(document.forms['rest_search'].elements['whichColumn2'].options[document.forms['rest_search'].elements['whichColumn2'].selectedIndex].value);
		strPageName = strPageName + '&keyword=' + escape(document.forms['rest_search'].elements['keyword'].options[document.forms['rest_search'].elements['keyword'].selectedIndex].value);
		strPageName = strPageName + '&keyword2=' + escape(document.forms['rest_search'].elements['keyword2'].options[document.forms['rest_search'].elements['keyword2'].selectedIndex].value);
		if (document.forms['rest_search'].elements['boo1'][0].checked)	{
			strPageName = strPageName + '&boo1=' + escape(document.forms['rest_search'].elements['boo1'][0].value);
		}	else	{	// b/c there are only two choices, "and" or "or", we can go ahead and assume which one
			strPageName = strPageName + '&boo1=' + escape(document.forms['rest_search'].elements['boo1'][1].value);
		}
		
		resultWin = window.open (strPageName, 'ResultsWin');
	
		//alert(strPageName)
	}
}

function getValues(strWhich)	{
       switch (document.forms['rest_search'].elements['whichColumn' + strWhich].options[document.forms['rest_search'].elements['whichColumn' + strWhich].selectedIndex].value)	{
		case "Restoration Type":
	        	strTempTexts = 'Aesthetic View%^Barrier Beach Restoration%^Buffer Management%^Contaminant Removal%^Eelgrass Restoration%^Erosion Control%^Fish Passage Restoration%^Fish/Shellfish Habitat%^Hydrologic Restoration%^Invasives Control%^Mosquito Control%^Phragmites Control%^Reduce Nutrient Loading%^Reduce Pathogens%^Reef Restoration%^Restoration of Tidal Elevations%^Shellfish Beds%^Stormwater Management%^Tide Gates to Restore Flow%^Transplant Eelgrass%^Water Quality%^Wildlife Restoration'
	        	propCbo(document.forms['rest_search'].elements['keyword' + strWhich],strTempTexts,strTempTexts);
	        	break;
        	case "Public Use":       
	        	strTempTexts = 'Beach%^Boat Ramp%^Conservation/ Wildlife Area%^Fishing Area%^Parking Area%^Path to Shore%^Public Park%^Scenic View';
	        	propCbo(document.forms['rest_search'].elements['keyword' + strWhich],strTempTexts,strTempTexts);
	        	break;
        	case "Federal Share ($)":
        		//alert('fed share');
        		strTempTexts = '< 10,000%^10,000-25,000%^25,001-50,000%^50,001-100,000%^100,000-500,000%^> 500,000';
        		strTempValues = '1%^2%^3%^4%^5%^6';
        		propCbo(document.forms['rest_search'].elements['keyword' + strWhich],strTempValues,strTempTexts);
        		break;
        	case "Non-Federal Share ($)":
        		//alert('nonfed share');
        		strTempTexts = '< 10,000%^10,000-25,000%^25,001-50,000%^50,001-100,000%^100,000-500,000%^> 500,000';
        		strTempValues = '1%^2%^3%^4%^5%^6';
        		propCbo(document.forms['rest_search'].elements['keyword' + strWhich],strTempValues,strTempTexts);
        		break;
        	case "Total Cost ($)":
        		//alert('total');
        		strTempTexts = '< 10,000%^10,000-25,000%^25,001-50,000%^50,001-100,000%^100,000-500,000%^> 500,000';
        		strTempValues = '1%^2%^3%^4%^5%^6';
        		propCbo(document.forms['rest_search'].elements['keyword' + strWhich],strTempValues,strTempTexts);
        		break;
        	case "Minimum Cost ($)":
        		//alert('min');
        		strTempTexts = '< 10,000%^10,000-25,000%^25,001-50,000%^50,001-100,000%^100,000-500,000%^> 500,000';
        		strTempValues = '1%^2%^3%^4%^5%^6';
        		propCbo(document.forms['rest_search'].elements['keyword' + strWhich],strTempValues,strTempTexts);
        		break;
        	case "Max Cost ($)":
        		//alert('max cost');
        		strTempTexts = '< 10,000%^10,000-25,000%^25,001-50,000%^50,001-100,000%^100,000-500,000%^> 500,000';
        		strTempValues = '1%^2%^3%^4%^5%^6';
        		propCbo(document.forms['rest_search'].elements['keyword' + strWhich],strTempValues,strTempTexts);
        		break;
        	case "Acres":
        		//alert('acres');
        		strTempTexts = '< 1%^1-5%^6-10%^11-20%^> 20%^unknown';
        		strTempValues = '1%^2%^3%^4%^5%^6';
        		propCbo(document.forms['rest_search'].elements['keyword' + strWhich],strTempValues,strTempTexts);
        		break;
		default:
        	// no idea why I'm using the var name "ordpos".  It's not very good.
        		srcs = window.open ('getKeywords.asp?whichElem=' + strWhich + '&ordPos=' + escape(document.forms['rest_search'].elements['whichColumn' + strWhich].options[document.forms['rest_search'].elements['whichColumn' + strWhich].selectedIndex].value), 'SrcWin',
        			'scrollbars=yes,status=yes,width=650,height=200');
        }	// end switch
}