// aimsCustom.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js,
*		aimsLayers.js, aimsDHTML.js
*		aimsClick.js, aimsNavigation.js,
*/

// global variables
	aimsCustomPresent=true;
	// change these to send XML response to custom function.
	// use numbers >= 1000 and match in useCustomFunction()
	// defaults are defined in aimsXML.js and use standard functions
	
	// xml response mode for selection
	selectXMLMode = 6;
	// xml response mode for identify
	identifyXMLMode = 7;
	// xml response mode for query
	queryXMLMode = 8;
	// xml response mode for find
	findXMLMode = 14;
	// xml response mode hyperlink
	hyperlinkXMLMode = 15;




// custom function for handling clicks 
// 		flow redirected here when
//		toolMode set to >=1000
function customMapTool(e) {
				if (toolMode == 1001) {
						// insert code here
						return false;
					
				}
				if (toolMode == 1002) {
						// insert code here

				}

}

// send  XML response to custom function
//		flow  redirected here when
//		XMLMode >=1000
function useCustomFunction(theReply) {
	if (XMLMode==1001) {
		// insert code here
	} else if (XMLMode==1002) {
		// insert code here
	} else {
		alert(msgList[55] + XMLMode + msgList[56]);
	}
	hideLayer("LoadData");
}

// add custom stuff to Map XML request. . . between selection and geocode
function addCustomToMap1(){
	var customString = "";
	/*
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		customString += '<OBJECT units="PIXEL">\n<TEXT coords="5,' + (iHeight-10) + '" label="This is a test">\n';
		customString += '<TEXTMARKERSYMBOL fontstyle="BOLD" fontsize="12" font="ARIAL" fontcolor="' + modeMapColor + '" ';
		customString += 'threed="TRUE" glowing="' + modeMapGlow + '" />\n</TEXT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
	*/
	return customString;
}

// add custom stuff to Map XML request. . . between clickpoints and copyright
function addCustomToMap2(){
	var customString = "";
	
	return customString;
}

// add custom stuff to Map XML request. . . under modeOnMap
function addCustomToMap3(){
	var customString = "";
		/*
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		customString += '<OBJECT units="PIXEL">\n<TEXT coords="5,' + (iHeight-10) + '" label="This is a test">\n';
		customString += '<TEXTMARKERSYMBOL fontstyle="BOLD" fontsize="12" font="ARIAL" fontcolor="' + modeMapColor + '" ';
		customString += 'threed="TRUE" glowing="' + modeMapGlow + '" />\n</TEXT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
		alert(customString);
		*/
	return customString;
}

// add custom stuff to Map XML request. . . on top of everything
function addCustomToMap4(){
	var customString = "";
	
	return customString;
}

// extract layers to download
function extractIt() {
	hideLayer("measureBox");
	alert(msgList[51]);
}



/*  ************************
*	Active Layer info display function
*	************************
*/
// write out ActiveLayerInfo page
function writeALFrame() {
	parent.ALFrame.document.location= appDir + "ALFrame.htm";
}

// write new Services Menu
function updateServicesMenu() {
	parent.CustFrame.document.location= appDir + "Services.htm";
}

function StepIn(ZoomValue) {

  if (ZoomValue > 1) {
 // parent.ToolFrame.document.location= appDir + "toolbar.htm";
	var tempLeft = eLeft;
	var tempRight = eRight;
	var tempTop = eTop;
	var tempBottom = eBottom;
// Save Last Extent
	saveLastExtent();
// Step In
	eLeft = (tempRight + tempLeft)/2 - (tempRight - tempLeft)/(2*ZoomValue);
	eRight =(tempRight + tempLeft)/2 + (tempRight - tempLeft)/(2*ZoomValue);
	eTop = (tempTop + tempBottom)/2 + (tempTop - tempBottom)/(2*ZoomValue);
	eBottom = (tempTop + tempBottom)/2 - (tempTop - tempBottom)/(2*ZoomValue);

	sendMapXML();
	
	
	tempLeft=null;
	tempRight=null;
	tempTop=null;
	tempBottom=null;
  }
}

function StepOut(ZoomValue) {	

  if (ZoomValue > 1) {
  //  parent.ToolFrame.document.location= appDir + "toolbar.htm";

	var tempLeft = eLeft;
	var tempRight = eRight;
	var tempTop = eTop;
	var tempBottom = eBottom;

	
// Save Last Extent
	saveLastExtent();
	
// Step Out
	eLeft = tempLeft - ((tempRight - tempLeft)/2)*(ZoomValue-1);
	eRight =tempRight + ((tempRight - tempLeft)/2)*(ZoomValue-1);
	eTop = tempTop  + ((tempTop - tempBottom)/2)*(ZoomValue-1);
	eBottom = tempBottom - ((tempTop - tempBottom)/2)*(ZoomValue-1);

	sendMapXML();
	
	tempLeft=null;
	tempRight=null;
	tempTop=null;
	tempBottom=null;
  }
}

function ZoomLevel(LevelValue) {
if (LevelValue > 1) parent.ToolFrame.document.location= appDir + "toolbar.htm";
	// Property Level	
	if (LevelValue == 2) var levelScaleFactor = 0.9;
	// Quarter Section
	if (LevelValue == 3) var levelScaleFactor = 3.0;
	// Street Level
	if (LevelValue == 4) var levelScaleFactor = 6.0;
	if ((LevelValue > 1) && (LevelValue < 5)) {
		if (mapScaleFactor > levelScaleFactor) {
			// zoomin to *** level
			StepIn(mapScaleFactor/levelScaleFactor);
		}
		else {
			// zoomout to *** level
			StepOut(levelScaleFactor/mapScaleFactor);
		}
	}
}


function SearchBy(theValue) {
if (theValue<=6) {
	    parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
		parent.CustFrame.document.location= appDir + "asp/Search.asp?ST="+theValue+"0";
	}
	else {
		if (theValue==7) {
		// search by section
		    parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
			parent.CustFrame.document.location= appDir + "SearchSection.htm";
		}
		if (theValue==8) {
		// search by SERVICES
		    parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
			parent.CustFrame.document.location= appDir + "SearchServices.htm";
		}
		if (theValue==9) {
// Real estate Search - added by Yelena Markova on Aug 5th, 2004
		    parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
			parent.CustFrame.document.location= appDir + "SearchRealEstate.htm";
		}
                if (theValue==10) {
                // search by Parks
                    parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
                        parent.CustFrame.document.location= appDir + "SearchParks.htm";
                }               
 
	}
}

function searchRealEstate(theValue1, theValue2, theValue3) {
// Real estate Search - added by Yelena Markova on Aug 5th, 2004
	if (theValue1 =='1' ||  theValue1=='2'){
		var addToL = theValue1 -1;
		var myQString="priceval >= " + theValue2*100000 + " and priceval <= " + theValue3*100000;
	}
	else {
		var addToL = 2;
		var myQString="proptype = " + dQuote + theValue1 + dQuote + " and priceval >= " + theValue2*100000 + " and priceval <= " + theValue3*100000;
	}
	var reLayer = resAttachPos+ addToL;
	ActiveLayer=LayerID[reLayer];
	ActiveLayerType=LayerType[reLayer];
	ActiveLayerIndex=reLayer;
	LayerVisible[reLayer]=1;
//	sendQueryString(myQString);
	parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
	//Win1 = open(appDir + "asp/SearchRE.asp?PT=" + theValue1 + "&PR1=" + theValue2 + "&PR2=" + theValue3 + " ","QueryWindow","width=575,height=150,scrollbars=yes,resizable=yes");
	parent.CustFrame.document.location= appDir + "asp/SearchRE.asp?PT=" + theValue1 + "&PR1=" + theValue2 + "&PR2=" + theValue3;
}

function searchRSN(theValue, theMapValue, reValue1, reValue2, reValue3) {
// save property RSN for printing
prRSN=theValue;
// set PROPERTY as Active Layer
ActiveLayer=LayerID[0];
ActiveLayerType=LayerType[0];
ActiveLayerIndex=0;
// upadte Active Layer Information
writeALFrame();
// Show Search results in Custom Frame
// add information about real estate layers visibility
//alert('theValue = ' + prRSN + ' and theMapValue = ' + theMapValue);

VL='3'+LayerVisible[resAttachPos]+LayerVisible[resDetdPos]+LayerVisible[OthrRealEstPos]
if (reValue1 == '0') {
parent.CustFrame.document.location= appDir + "asp/PropertyInfo.asp?RSN="+VL+theValue;
} else {
parent.CustFrame.document.location= appDir + "asp/SearchRE.asp?PT="+reValue1+"&PR1="+reValue2+"&PR2="+reValue3;
}

// Get Property Features and SHAPE
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n';
	theString +='<GET_FEATURES attributes ="true"  outputmode="xml" geometry="false" envelope="true" feturelimit="1" beginrecord="1" >\n';
	theString +='<LAYER id="Property" />\n';
	theString +='<SPATIALQUERY where="RSN=';
	theString += theMapValue;
	theString += '"/>\n';
	theString += '</GET_FEATURES>\n</REQUEST>\n</ARCXML>';
	showRetrieveData();
	sendToServer(imsQueryURL,theString,22);
}		

function searchSection(theValue) {
// set Quarter Sections as Active Layer
ActiveLayer=LayerID[84];
ActiveLayerType=LayerType[84];
ActiveLayerIndex=84;
// Show Search results in Custom Frame
//Find Quater Section on the Map
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n';
	theString +='<GET_FEATURES attributes ="false"  outputmode="xml" geometry="false" envelope="true" feturelimit="1" beginrecord="1" >\n';
	theString +='<LAYER id="QuaterSections" />\n';
	theString +='<SPATIALQUERY where="SECTION_NO=&apos;';
	theString += theValue;
	theString += '&apos;"/>\n';
	theString += '</GET_FEATURES>\n</REQUEST>\n</ARCXML>';
	showRetrieveData();
	sendToServer(imsQueryURL,theString,13);
    parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
	parent.CustFrame.document.location= appDir + "SearchSection.htm";
}			

function searchService(theValue1, theValue2, theValue3) {
// set selected Layer as Active Layer
ActiveLayer=LayerID[theValue1];
ActiveLayerType=LayerType[theValue1];
ActiveLayerIndex=theValue1;
// set selected Layer as Visible Layer
LayerVisible[theValue1]=1;
// Show Search results in Custom Frame
//Find Service on the Map
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n';
	theString +='<GET_FEATURES attributes ="true"  outputmode="xml" geometry="false" envelope="true" feturelimit="1" beginrecord="1" >\n';
	theString +='<LAYER id="' + theValue2 + '"/>\n';
	if (theValue2=="golf") {
		theString +='<SPATIALQUERY where="ID=';
		theString += theValue3;
		theString += '"/>\n';
	}
	else {
		theString +='<SPATIALQUERY where="NAME Like &apos;';
		theString += '%' + theValue3 + '%';
		theString += '&apos;"/>\n';
	}
	theString += '</GET_FEATURES>\n</REQUEST>\n</ARCXML>';
	showRetrieveData();
	sendToServer(imsQueryURL,theString,12);
    parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
}

                
function initLayerValues() {
// load park names into an array XMLresp

        var slayer = 'parks';
        var parkn = '^';
        
//Find Parks on the Map
        var theString = '<ARCXML version="1.1">\n<REQUEST>\n';
        theString +='<GET_FEATURES attributes ="true"  outputmode="xml" geometry="false" envelope="true" feturelimit="1" beginrecord="1" >\n';
        theString +='<LAYER id="' + slayer + '"/>\n';
                theString +='<SPATIALQUERY subfields="#ALL#" where="PARK_NAME > &apos;';
                theString += '%' + parkn + '%';
                theString += '&apos;"/>\n';
        theString += '</GET_FEATURES>\n</REQUEST>\n</ARCXML>';

        sendToServer(imsQueryURL,theString,23);
ParkNameArray[0] = "changed";
}

function parksMap(theValue1, theValue2, theValue3) {
// set selected Layer as Active Layer
ActiveLayer=LayerID[theValue1];
ActiveLayerType=LayerType[theValue1];
ActiveLayerIndex=theValue1;
// set selected Layer as Visible Layer
LayerVisible[theValue1]=1;

// Show Search results in Custom Frame
//Find Parks on the Map
        var theString = '<ARCXML version="1.1">\n<REQUEST>\n';
        theString +='<GET_FEATURES attributes ="true"  outputmode="xml" geometry="false" envelope="true" feturelimit="1" beginrecord="1" >\n';
        theString +='<LAYER id="' + theValue2 + '"/>\n';
//                theString +='<SPATIALQUERY where="PARK_NAME Like &apos;';
//                theString += '%' + theValue3 + '%';
//                theString += '&apos;"/>\n';

                theString +='<SPATIALQUERY where="PARK_NAME =';
                theString += '&apos;' + theValue3;
                theString += '&apos;"/>\n';

        theString += '</GET_FEATURES>\n</REQUEST>\n</ARCXML>';
//alert(imsQueryURL)
        showRetrieveData();
        sendToServer(imsQueryURL,theString,12);
    parent.AddToolFrame.document.location= appDir + "addtoolbar.htm";
}               
       
		
function writeStreet() {

//alert(parent.CustFrame.document.forms[0].House.value);
	//parent.MapFrame.document.location= appDir + "findStreet.asp";
	parent.CustFrame.document.forms[0].Unit.value =  parent.CustFrame.document.forms[0].House.value; 
}
		
function resizeMap() {

//alert(eLeft);
//alert(eRight);
//alert(eTop);
//alert(eBottom);
//alert(iWidth);
// get window height
  	if (isNav) {
	    iHeight = window.innerHeight;
	    iWidth = window.innerWidth;
	}
	else {
	    iHeight = document.body.clientHeight;
	    iWidth = document.body.clientWidth;
	}

// Resize Map
//alert(iHeight);
//alert(iWidth);

//sendMapXML();
//var theString = writeXML();
//sendToServer(imsURL,theString,900);
	showRetrieveMap();
	var tempWidth = iWidth;
	var tempHeight = iHeight;
  	if (isNav) {
	    iHeight = window.innerHeight;
	    iWidth = window.innerWidth;
	}
	else {
	    iHeight = document.body.clientHeight;
	    iWidth = document.body.clientWidth;
	}
	legVis2=legendVisible;
	if (aimsLegendPresent) legendVisible=true;
	var theString = writeXML();
	iWidth=tempWidth;
	iHeight = tempHeight;
	legendVisible = legVis2;
	sendToServer(imsURL,theString,101);
	tempWidth=null;
	tempHeight=null;
	theString=null;
	parent.MapFrame.document.location = appDir +"MapFrame.htm";
	hideRetrieveMap();
//parent.MapFrame.document.location= appDir + "MapFrame.htm";

}

function savePropRSN(theValue) {
	prRSN = theValue;
}

function searchAddr(theValue) {
	clearSelection();
	parent.CustFrame.document.location= appDir + "asp/SearchAddress.asp?ST="+theValue;
}

function initStr() {
	alert("init str");
}