// CivXplorer Custom Functionality
// Suzanne Fliege
// PlanSight, LLC
// contains custom functions

//******************************************************************************
// client-specific custom functions and variables
//******************************************************************************
// dialog for searching E911 address data
function showE911searchDialog() {
	var theString = "";
	theString += '<form id="E911QueryStuff" name="E911QueryStuff" onsubmit="return false;">';
	theString += '<table cellpadding="3" cellspacing="0" width="100%">';
	theString += '<tr><td class="header1" width="100%" align="right"><a href="#" onmousedown="hideAttributeDisplay();"><img src="images/CXclose.gif" align="top"></a></td></tr>';
	theString += '<tr><td class="header1" align="center">Search E911 Addresses</td></tr>';
	// address
	theString += '<tr><td class="toolInfo1" align="center">House Number:</td></tr>';
	theString += '<tr><td align="center"><input type="Text" name="NumbQueryString" size="25" maxlength="10" tabindex="1" value=""></td></tr>';
	theString += '<tr><td class="toolInfo1" align="center">Street Name:</td></tr>';
	theString += '<tr><td align="center"><input type="Text" name="StreetQueryString" size="25" maxlength="35" tabindex="2" value=""></td></tr>';
	theString += '<tr><td class="toolInfoSmall" align="center"><i>For Best Results Enter Only Street Name.<br>ex. <b>"MAIN"</b> instead of<br>"MAIN ST W"</i></td></tr>';
	theString += '<tr><td class="toolInfo2" align="center"><input type="checkbox" class="tocInput" name="AddToPropertySelection">Add to Current Selection</td></tr>';
	theString += '<tr><td align="center"><input class="toolInfo1" type="submit" value="Find By Address" onclick="if(!waitForMap) doE911searchAddress();return false;" name="submitAddress"></td></tr>'; 
	theString += '</table>';
	theString += '</form>';
	setupInputFormSidebar();
	updateContent("cxAttributeBottom",theString);
	return false;
}



function doE911searchAddress() {
	if (!waitForMap) {
		//if ((document.E911QueryStuff.NumbQueryString.value == null) && (document.E911QueryStuff.StreetQueryString.value == null)) {
			var theString = "";
			if (parseInt(document.E911QueryStuff.NumbQueryString.value) > 0) theString += "NUM_ADD = " + document.E911QueryStuff.NumbQueryString.value;
			if (document.E911QueryStuff.StreetQueryString.value != "") {
				if (theString != "") theString += " AND ";
				theString += "ROADNAME LIKE " + dQuote + "%"  + document.E911QueryStuff.StreetQueryString.value.toUpperCase() + "%" + dQuote;	  
			}
			clickFunction("nothing");
			showBuffer = false;
			showGeocode = false;
			zoomToSelected = true;
			setActiveLayer("grouped-parcel-e911",false,false);
			groupedLayerVisible[0][5] = "true";
			LayerVisible[ActiveLayerIndex] = "true";
			if (document.E911QueryStuff.AddToPropertySelection != null) {
				if (document.E911QueryStuff.AddToPropertySelection.checked) {
					//currentParcelQueryAddToSel = true;
					SetSelectBlurb();
					if (selectBlurb != "") theString += " OR " + selectBlurb;
				}
			}
			document.getElementById('cxAttributeBottom').style.visibility = "hidden";
			sendQueryString(theString);
		//} else {
			//alert("No selection parameters specified!\nNo features have been selected.");
			//return false;
		//}
	} else {
		alert("Please wait for previous map request to finish!");
		return false;
	}
}

// open RVI
function openRVIwindow(theRVIURL) {
	rviWin=window.open()
	rviWin.document.location = theRVIURL;
}

//******************************************************************************
// do not edit below here!
//******************************************************************************
useCustomFunctions = true;

//******************************************************************************
// custom menu items/help
//******************************************************************************
// custom tool item(s) - go in sidebar
function addCustomToolItems() {

	//CustomSidebarMenuCount = 1;
}
function resetCustomToolItems() {

}

// adds custom menu items to dropdown menus
function addCustomMenuItems(tempMenu) {
	switch(tempMenu) {
	case 'menuNav':
		//document.writeln(createMenuItem("menuItem_Custom1","customTask();","Custom Nav"));
		break
	case 'menuFind':
		document.writeln(createMenuItem("menuItem_E911search","showE911searchDialog();","Address Search"));
		break
	case 'menuQuery':
		//document.writeln(createMenuItem("menuItem_Custom1","customTask();","Custom Query"));
		break
	case 'menuReports':
		//document.writeln(createMenuItem("menuItem_Custom1","customTask();","Custom Report"));
		break
	case 'menuSettings':
		//document.writeln(createMenuItem("menuItem_RVI","openRVIwindow('RVIaccess.htm');","Open Land Survey Records Website (pop-up)"));
		//document.writeln(createMenuItem("menuItem_RVIinstructions","openRVIwindow('RVI_survey_search.pdf');","Open Land Survey Records Instructions (pop-up)"));
		break
	}
	return false;
}

// add custom quick tool buttons
function addCustomQuickTools() {
	var tempString = '';
	//tempString += '<tr><td><img src="images/CXzoomin.gif" name="zoominpic" onmousedown="clickFunction(\'zoomin\');" class="quickToolNoBorder" onmouseover="setMenus(\'nothing\');if (showUserHelp) showHelp(\'menuItem_ZoomIn\');" ></td></tr>';
	return tempString;
}

function addCustomHelp(tempTool) {
	var tempString = '';
	switch(tempTool) {
	// E911 search
	case 'menuItem_E911search':
		tempString += '<tr><td background="images/CXhelpLeft.gif" width="12"></td><td class="toolInfo1" align="center" width="*">E911 Address Search</td><td background="images/CXhelpRight.gif" width="12"></td></tr>';
		tempString += '<tr><td background="images/CXhelpLeft.gif"></td><td class="body1" align="center">';
		tempString += 'Search E911 Address data by House Number, Street, Owner or Parcel Tax ID';
		//tempString += '<hr>';
		tempString += '</td><td background="images/CXhelpRight.gif"></td></tr>';
		break
	// RVI webpage
	case 'menuItem_RVI':
		tempString += '<tr><td background="images/CXhelpLeft.gif" width="12"></td><td class="toolInfo1" align="center" width="*">Land Records Survey Website</td><td background="images/CXhelpRight.gif" width="12"></td></tr>';
		tempString += '<tr><td background="images/CXhelpLeft.gif"></td><td class="body1" align="center">';
		tempString += 'Search Land Records Survey documents';
		tempString += '</td><td background="images/CXhelpRight.gif"></td></tr>';
		break
	// RVI webpage
	case 'menuItem_RVIinstructions':
		tempString += '<tr><td background="images/CXhelpLeft.gif" width="12"></td><td class="toolInfo1" align="center" width="*">Land Records Survey Instructions</td><td background="images/CXhelpRight.gif" width="12"></td></tr>';
		tempString += '<tr><td background="images/CXhelpLeft.gif"></td><td class="body1" align="center">';
		tempString += 'Information on how to search Land Records Survey documents';
		tempString += '</td><td background="images/CXhelpRight.gif"></td></tr>';
		break
	// sample
	case 'menuItem_Custom1':
		tempString += '<tr><td background="images/CXhelpLeft.gif" width="12"></td><td class="toolInfo1" align="center" width="*">Custom Help Sample</td><td background="images/CXhelpRight.gif" width="12"></td></tr>';
		tempString += '<tr><td background="images/CXhelpLeft.gif"></td><td class="body1" align="center">';
		tempString += 'blah blah blah';
		tempString += '<hr>';
		tempString += '</td><td background="images/CXhelpRight.gif"></td></tr>';
		break
	default:
		tempString += '<tr><td background="images/CXhelpLeft.gif" width="12"></td><td class="toolInfo1" align="center" width="*">' + tempTool+ '</td><td background="images/CXhelpRight.gif" width="12"></td></tr>';
	}
	return tempString;
}

//******************************************************************************
// custom XML mode tasks
//******************************************************************************
// process the return XML based on custom XML mode
function processCustomXML(theReply) {
	switch(XMLMode) {
		case 901:
			//showGeneralParcelReport();
			break
		default:
			alert("Not a valid XML mode (custom or standard)!\nUnable to process response.");
	}
	return false;
}

function customMapTool(e) {
	switch(toolMode) {
	default:
		alert("no such tool!");
	}
	return false;
}

//******************************************************************************
// custom reporting support
//******************************************************************************
// add custom reporting to user report dialog
function addCustomReportsToDialog() {
	var theString = '';
	theString += '<tr><td><hr></td></tr>';
	theString += '<tr><td class="toolInfo1" align="center">Custom Reports:</td></tr>';
	if (ActiveLayer == "some custom report layer ID") {
		if ((currentSelectionStrings[ActiveLayerIndex] != null) && (currentSelectionObjectIDs[ActiveLayerIndex].length > 0)) {
			theString += '<tr><td align="center"><input class="toolInfo1" type="submit" value="Create\nPDF-Formatted\nParcel Report" name="submit" onclick="if(!waitForMap) getGeneralParcelReport();return false;"></td></tr>'; 
		} else {
			theString += '<tr><td class="toolInfoSmall" align="center"><i>Nothing is Selected!<br>No Report Available</i></td></tr>';
		}
	} else {
		theString += '<tr><td class="toolInfoSmall" align="center"><i>No Custom Reports Available</i></td></tr>';
	}
	return theString;
}

//******************************************************************************
// custom mapping support
//******************************************************************************
// add custom maps to user map dialog
function addCustomMapsToDialog() {
	var tempString = '';
	tempString += '<tr><td class="toolInfo1" align="center">Custom Maps:</td></tr>';
		tempString += '<tr><td class="toolInfoSmall" align="center"><i>No Custom Maps Available</i></td></tr>';
	tempString += '<tr><td><hr></td></tr>';
	return tempString;
}

//******************************************************************************
// custom on-load support
//******************************************************************************
// tasks to do on-load
function doCustomOnloadTasks(cmdString) {
	return false;
}

//******************************************************************************
// custom map load support
//******************************************************************************
// tasks to do before drawing the first map
function doCustomMapLoad(cmdString) {
	if ((webParams != "") && (cmdstartAvailable)) {
		getCXCommandLineParams(webParams);
	} else {
		sendMapRequest();
	}
}

//******************************************************************************
// custom map layer support
//******************************************************************************
// tasks to do based on layer visibility
function doCustomMapLayerTasks() {
	return false;
}

//******************************************************************************
// custom map draw support
//******************************************************************************
// tasks to do before drawing the first map
function addCustomToMap() {
	var tempString = '';
	return tempString;
}


