//<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
// aimsIdentify.js

/*

*  JavaScript template file for ArcIMS HTML Viewer

*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js, and aimsLayers.js

*		To be interactive, dependent also on aimsDHTML.js, aimsClick.js, and aimsNavigation.js

*/



aimsIdentifyPresent=true;



// hyperlink variables

var currentHyperLinkLayer="";

var currentHyperLinkField="";

var hyperlinkWindowWidth=500;

var hyperlinkWindowHeight=400;



// variable for search tolerance... dynamically set in app

var searchTolerance=0.01;

// starting record position for returned records

var queryStartRecord=0;



if (imsQueryURL=="") {

	imsQueryURL= imsURL + "&CustomService=Query";

	//alert(imsQueryURL);

}

var canQuery=true;

var newSelectCount=0;

var selectPoints = new Array();







/*

***************************************************************************************



Identify functions 



***************************************************************************************

*/



// identify feature

function identify(e) {

	highlightedOne="";

	var theX = mouseX;

	var theY = mouseY;

	getMapXY(theX,theY);

	searchTolerance = (xDistance/iWidth) * pixelTolerance;

	var tempWest = mapX - searchTolerance;

	var tempNorth = mapY + searchTolerance;

	var tempEast = mapX + searchTolerance;

	var tempSouth = mapY - searchTolerance;

	var theString = writeGetFeatures(tempWest,tempSouth,tempEast,tempNorth);

	//alert(theString);

	showRetrieveData();

	sendToServer(imsQueryURL,theString,identifyXMLMode);

}



// hyperlink from feature

function hyperLink(e) {
									if (currentHyperLinkLayer!="") {
												highlightedOne="";
												var theX = mouseX;
												var theY = mouseY;
												getMapXY(theX,theY);
            searchTolerance = (xDistance/iWidth) * pixelTolerance;
												var tempWest = mapX - searchTolerance;
												var tempNorth = mapY + searchTolerance;
												var tempEast = mapX + searchTolerance;
												var tempSouth = mapY - searchTolerance;
												var tempSwap = swapSelectFields;
												swapSelectFields=false;
												var tempSelect = selectFields;
												selectFields = LayerIDField[ActiveLayerIndex] + " " + LayerShapeField[ActiveLayerIndex] + " " + currentHyperLinkField;
												var theString = writeGetFeatures(tempWest,tempSouth,tempEast,tempNorth);
												selectFields = tempSelect;
												swapSelectFields=tempSwap;
												showRetrieveData();
												sendToServer(imsQueryURL,theString,hyperlinkXMLMode);

												if (parent.intPrjNo=="11598"){
															alert("Select Fields in hyperlink function : "+ selectFields);
												}
												


												//Carin - WOCAT - Select point
												if (parent.intPrjNo=="9644"){
															window.parent.opener.form1.apb_lat.value = mapX;
															window.parent.opener.form1.apb_long.value = mapY;
												}
												//Carin - WOCAT World Map - Select point
												else if (parent.intPrjNo=="11336"){
																	window.parent.opener.form1.apb_lat.value = mapX;
																	window.parent.opener.form1.apb_long.value = mapY;
												}
												//Carin - ORGANISATIONS - Select point
												else if (parent.intPrjNo=="9726"){
																	window.parent.opener.form1.apb_physical_lat.value = mapX;
																	window.parent.opener.form1.apb_physical_long.value = mapY;
																	//window.parent.opener.document.all.saveBut.style.visibility = "visible";
												}
												else {
												//alert(parent.intPrjNo)
																	//alert("This layer does not have any HyperLinks.");
												}
									}
}

// write out XML request to identify features

function writeGetFeatures(west1,south1,east1,north1) {

	if (swapSelectFields) {

		selectFields=parent.selFieldList[ActiveLayerIndex];

	}

	var useString = writeIdentifyXML(ActiveLayer,ActiveLayerType,selectFields,west1,south1,east1,north1,useLimitExtent);

	hightlightedOne="";

	return useString;

}



function writeIdentifyXML(theLayer,theLayerType,theFields,leftX,bottomY,rightX,topY,hasLimit) {

	var theString = '<ARCXML VERSION="1.0.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" envelope="false" geometry="false">\n';

	theString += '<LAYER id="' + theLayer + '" />';

	var addString = ""
	if (theLayer == 280)
	{
		addString += parent.MapFrame.theSpatialQueryString;
	}					

	theString += '<SPATIALQUERY subfields="' + theFields + '" '+addString+'>';

	//theString += '<SPATIALQUERY subfields="' + theFields + '">';

	theString += '<SPATIALFILTER relation="area_intersection" >';

	theString += '<ENVELOPE maxy="' + topY + '" maxx="' + rightX + '" miny="' + bottomY + '" minx="' + leftX + '" />';

	theString += '</SPATIALFILTER>';

	theString += '</SPATIALQUERY>';

	if (hasLimit) {

		// keep this within the limitExtent

		theString += '<SPATIALFILTER relation="area_intersection">\n';

		theString += '<ENVELOPE maxx="' + limitRight + '" maxy="' + limitTop + '" minx="' + limitLeft + '" miny="' + limitBottom + '" />\n';

		theString += '</SPATIALFILTER>\n';

	}

	theString += '</GET_FEATURES>';

	theString += '</REQUEST>';

	theString += '</ARCXML>';

	return theString;



}



// parse XML response for selected features

function displayAttributeData(theReply) {

	//alert(theReply);

	setLayerFields(ActiveLayerIndex);

	var theError = getXMLErrorMessage(theReply);

	var fList="";

	var lpos1 = 1;

	var lpos2 = 1;

	var epos = 1;

	var spos = 1;

	var morePoints=true;

	var moreFeatures=true;

	var featureCount = justGetFeatureCount(theReply);

	//alert(featureCount);

	var pos = 0;

	var startpos = 0;

	var endpos = xmlEndPos;

	var stillMore = false

	pos = theReply.indexOf('hasmore="true"',endpos);

	if (pos!=-1) stillMore = true;

	pos=0;

	var tempCount = 0;

	var selectedData="";

	var inData="";

	var xStr="";

	var yStr="";

	var eNorth="";

	var eSouth="";

	var eWest="";

	var eEast="";

	var fCount = featureCount;

	//alert("displayAttributeData()[featurecount=" + featureCount + "]");

	selectCount = 0;

	var tempString="";

	var Win1 = parent.TextFrame;

	var theFrame = "parent.MapFrame";

	if (featureCount > 0) {

		newSelectCount += 1;





		if (showSelectedData) {

			//alert("displayAttributeData()[opening html page]");

			if ((useExternalWindow) || (!useTextFrame)) {

				Win1 = window.open("","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");

				theFrame = "opener";

				if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";

			} else {

				Win1 = parent.TextFrame;

				Win1.document.open();

			}

			Win1.document.open();

			Win1.document.writeln('<html><head><title>Query/Selection Results</title></head>');

			Win1.document.writeln('<body bgcolor="' + textFrameBackColor + '" text="Black" link="Blue" vlink="Gray" LEFTMARGIN=0 onload="window.focus()">');

			Win1.document.writeln('<center><FONT FACE="Arial" SIZE="-1"><b>' + LayerName[ActiveLayerIndex] + '</b>');

			Win1.document.writeln('<table border="1" cellspacing="0" cellpadding="2" nowrap bgcolor="' + tableBackColor + '">');

		}

		endpos = 1;

		

		for (var i=0;i<fCount;i++) {

			//alert(endpos);

			if (toolMode!=4) {

				var theXYs = getEnvelopeXYs(theReply, endpos)
                    
					//alert(toolMode +" : " +theXYs+ " : " + theReply);

				selectLeft[selectCount] = theXYs[0];

				selectBottom[selectCount] = theXYs[1];

				selectRight[selectCount] = theXYs[2];

				selectTop[selectCount] = theXYs[3];

				endpos = xmlEndPos;

			}

			//alert(endpos);

			inData = parseRecordString(theReply, endpos);

			endpos = xmlEndPos;

			selectedData = clearLeadingSpace(inData);

			

			epos = theReply.indexOf("</FEATURE",endpos);

			if (showSelectedData) {

				//alert("2\n" + selectedData);

				var showHyper = false;

				if (parent.hyperLinkLayers!=null) {

					for (var s1=0;s1<parent.hyperLinkLayers.length;s1++) {

						if (parent.hyperLinkLayers[s1] == LayerName[ActiveLayerIndex]) showHyper=true;

					}

				}

					

				var fName1 = getFieldNames(selectedData);

				var fValue1 = getFieldValues(selectedData);

				selectPoints[selectCount] = getIdValue(fName1, fValue1);

				

				if (selectCount==0) {

					Win1.document.write('<tr><th><FONT FACE="Arial" SIZE="-2">Rec</FONT></a></th>');

					for (var f=0;f<fName1.length;f++) {
					
					//Rudolf : New code to hide shape and id fields

					//alert(fName1[f].toUpperCase() + " " +  LayerShapeField[ActiveLayerIndex].toUpperCase() + " " + fName1[f].toUpperCase() + " " + LayerIDField[ActiveLayerIndex].toUpperCase());
					
					if (fName1[f].toUpperCase() == LayerShapeField[ActiveLayerIndex].toUpperCase() || fName1[f].toUpperCase() == LayerIDField[ActiveLayerIndex].toUpperCase()) continue; 

						var f2 = -1;

						if (useFieldAlias) {

							for (var f3=0;f3<AliasFieldName.length;f3++) {

								if (AliasFieldName[f3].toUpperCase()==fName1[f].toUpperCase()) f2 = f3;

								//if (parent.intPrjNo=="11598"){
								
								//alert(AliasFieldName[f3].toUpperCase() + " : " + fName1[f].toUpperCase() + " : " + AliasFieldAlias[f3] + " : " +  (AliasFieldName[f3].toUpperCase()==fName1[f].toUpperCase()));
								//}

							}

						}

						if (f2!=-1) {
						//Carin - NFR farm report replace SG Code with Report
							if (parent.intPrjNo=="5695" || parent.intPrjNo=="5597"){
								if (AliasFieldAlias[f2] == "SG Code"){
									 Win1.document.write('<th><FONT FACE="Arial" SIZE="-2">Report</FONT></a></th>');
								}
								else {
									 Win1.document.write('<th><FONT FACE="Arial" SIZE="-2">' + AliasFieldAlias[f2] + '</FONT></a></th>');
								}
							}
							else {
							
							Win1.document.write('<th><FONT FACE="Arial" SIZE="-2">' + AliasFieldAlias[f2] + '</FONT></a></th>');

							}
							
						} else {

							Win1.document.write('<th><FONT FACE="Arial" SIZE="-2">' + fName1[f] + '</FONT></a></th>');

						}

					}
					
					if (parent.productID=="nfr"){
					Win1.document.write('<form name="form1"><input type="hidden" name="gisKey" value="' + fValue1[0] + '"></form>');
					}
					Win1.document.writeln('</tr>');

				}

				Win1.document.write('<tr><td>');

				if (toolMode!=4) Win1.document.write('<a href="javascript:' + theFrame + '.showHighlight(' + selectCount + ')">');
				Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + (selectCount+queryStartRecord+1) + '</FONT>');
				if (toolMode!=4) Win1.document.write('</a>');
				Win1.document.writeln('</td>');
				for (var f=0;f<fName1.length;f++) {	
    			//Rudolf : New code to hide shape and id fields
						if (fName1[f].toUpperCase() == LayerShapeField[ActiveLayerIndex].toUpperCase() || fName1[f].toUpperCase() == LayerIDField[ActiveLayerIndex].toUpperCase()) continue; 

					Win1.document.write('<TD>');

					var isHyper=false;
					if (showHyper) {
						for (var s1=0;s1<parent.hyperLinkFields.length;s1++) {
					
						if (parent.hyperLinkFields[s1]!=null) {//Rudolf add code to prevent hyperlinkfield values that are empty

							if (parent.hyperLinkFields[s1].toUpperCase()==fName1[f].toUpperCase()) {//Rudolf add uppercase to match values


				//Carin - NFR area selection with link
								if (parent.intPrjNo=="5695" || parent.intPrjNo=="5597"){
									Win1.document.write('<a href="http://www.agis.agric.za/agisweb/new_window_n.html?tag=nfr_area_ppf_report&gisKey=' + fValue1[f] + '" target="_blank">');
								}
				//Carin - FIVIMS-ZA link to graph
								else if ((parent.intPrjNo=="9426") && (LayerName[ActiveLayerIndex] =="FIVIMS Nutritional status")){
 								//alert(LayerName[ActiveLayerIndex])
								//alert(fValue1[f])
 								Win1.document.write('<a href="http://www.agis.agric.za/agisweb/image_view_h.html?heading=NUTRITIONAL STATUS RADAR GRAPH&image_id=radar_' + fValue1[f] + '" target="_blank">');
								}
				//Carin - WOCAT select point
								else if ((parent.intPrjNo=="9644") && (LayerName[ActiveLayerIndex] == "WOCAT Points")){
								   //alert(fValue1[f])
								   Win1.document.write('<a href="http://www.agis.agric.za/agisweb/infobooks_tech/'+ fValue1[f] +'.pdf" target="_blank">');
								}
				//Carin - WOCAT view point
								else if ((parent.intPrjNo=="8639") && (LayerName[ActiveLayerIndex] == "WOCAT Points")){
								   Win1.document.write('<a href="http://www.agis.agric.za/agisweb/infobooks_tech/'+ fValue1[f] +'.pdf" target="_blank">');
								}
				//Carin - WOCAT All points
								else if ((parent.intPrjNo=="11000") && (LayerName[ActiveLayerIndex] == "WOCAT Points")){
								   Win1.document.write('<a href="http://www.agis.agric.za/agisweb/infobooks_tech/'+ fValue1[f] +'.pdf" target="_blank">');
								}
				//Carin - WOCAT - QM
								else if ((parent.intPrjNo=="11102") && (LayerName[ActiveLayerIndex] == "WOCAT Points")){
								   Win1.document.write('<a href="http://www.agis.agric.za/agisweb/infobooks_tech/'+ fValue1[f] +'.pdf" target="_blank">');
								}
				//Carin - WOCAT area selection with link
								else if (parent.intPrjNo=="8639" || parent.intPrjNo=="8651"){
									Win1.document.write('<a href="http://www.agis.agric.za/agisweb/infobooks_tech/' + fValue1[f] + '.pdf" target="_blank">');
								}
				//Carin - WOCAT World Map select point
								else if ((parent.intPrjNo=="11336") && (LayerName[ActiveLayerIndex] == "World countries")){
								   //alert(fValue1[f])
								   //Win1.document.write('<a href="http://www.agis.agric.za/agisweb/infobooks_tech/'+ fValue1[f] +'.pdf" target="_blank">');
								}								
				//Carin - Organisation Points
								else if (((parent.intPrjNo=="9726")||(parent.intPrjNo=="9738")||(parent.intPrjNo=="9789")) && (LayerName[ActiveLayerIndex] == "Organisation Points")){
								   alert(fValue1[f])
								   Win1.document.write('<a href="http://www.agis.agric.za/agisweb/new_window_h.html?tag=org_factsheet&org_id='+ fValue1[f] +'" target="_blank">');
								}
								// Moenie Identify Hyperlink insit vir A-Stat nie! start ------------------------------------------------------
								else if (parent.intPrjNo=="6220"){ }
								// Moenie Identify Hyperlink insit vir A-Stat nie! stop -------------------------------------------------------
								else{
								 //alert("in")
									Win1.document.write('<a href="'+ parent.hyperPrefix[parent.specifiedLayer] + fValue1[f] + parent.hyperSuffix[parent.specifiedLayer] + '" target="_blank">');							
								}
								isHyper=true;
								
								// Moenie Identify Hyperlink insit vir A-Stat nie! start ------------------------------------------------------
								if (parent.intPrjNo=="6220"){ isHyper=false; }
								// Moenie Identify Hyperlink insit vir A-Stat nie! stop -------------------------------------------------------
							}
						} //end null if
						}
					}
					var s2 = -1;
					for (var s1=0;s1<LayerFields.length;s1++) {
						if (fName1[f]==LayerFields[s1]) s2=s1;
					}
					if (LayerFieldType[s2]=="91") {

						//alert(fName1[f]);

						if (isNaN(fValue1[f])) {

							var theDate = fValue1[f];

						} else {

							//var theDate = new Date(parseInt(fValue1[f]));

							var theDateObj = new Date(parseFloat(fValue1[f]));

							var theDate = theDateObj.toGMTString();

						}

						Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + theDate + '</FONT>');

						theDate=null;

					} else {
					//Rudolf changes
					if (isHyper) {
					 // Carin change to graph image
						if ((parent.intPrjNo=="9426") && (LayerName[ActiveLayerIndex] =="FIVIMS Nutritional status")){
							Win1.document.write("<center><img src='http://www.agis.agric.za/saagis_images/graph.gif' border='0' alt='Radar Graph'></center>");
						}
						// Carin WOCAT view point
						else if ((parent.intPrjNo=="8639") && (LayerName[ActiveLayerIndex] == "WOCAT Points")){
							Win1.document.write("<center><img src='http://www.agis.agric.za/saagis_images/report2.jpg' border='0' alt='Detailed info'></center>");
						}
						//Carin WOCAT select point
						else if ((parent.intPrjNo=="9644") && (LayerName[ActiveLayerIndex] == "WOCAT Points")){
							Win1.document.write("<center><img src='http://www.agis.agric.za/saagis_images/report2.jpg' border='0' alt='Detailed info'></center>");
						}
						// Carin WOCAT view points
						else if ((parent.intPrjNo=="11000") && (LayerName[ActiveLayerIndex] == "WOCAT Points")){
							Win1.document.write("<center><img src='http://www.agis.agric.za/saagis_images/report2.jpg' border='0' alt='Detailed info'></center>");
						}
						// Carin WOCAT - QM
						else if ((parent.intPrjNo=="11102") && (LayerName[ActiveLayerIndex] == "WOCAT Points")){
							Win1.document.write("<center><img src='http://www.agis.agric.za/saagis_images/report2.jpg' border='0' alt='Detailed info'></center>");
						}
						else {
						Win1.document.write("<center><img src='http://www.agis.agric.za/saagis_images/report2.jpg' border='0' alt='Detail Information'></center>");
						}
            } else {
						Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + fValue1[f] + '</FONT>');}
					}

					if (isHyper) Win1.document.write('</a>');

					Win1.document.writeln('</td>');

				}

				Win1.document.writeln('</tr>');

				fName1 = null;

				fValue1 = null;

				

			}

			selectCount += 1;

					

		}

		if (showSelectedData) {

			

			Win1.document.writeln('</table>');

			if (toolMode!=25) {

				if (queryStartRecord>0) {

					var prevRecord = queryStartRecord - maxFeaturesReturned;

					if (prevRecord<0) prevRecord=0;

					Win1.document.write('<a href="javascript:' + theFrame + '.getMoreData(' + prevRecord + ')">Previous ' + maxFeaturesReturned + ' Records</a>&nbsp;&nbsp;&nbsp;');

				}

				if (stillMore) {

					var nextRecord=featureCount + queryStartRecord;

					Win1.document.writeln('<a href="javascript:' + theFrame + '.getMoreData(' + nextRecord + ')">More Records</a>');

				}

			}

			Win1.document.writeln('</font></center></body></html>');

			Win1.document.close();

		}

		//alert("toolMode:" + toolMode);

		

		if ((queryStartRecord==0) && (toolMode!=4) && (toolMode!=9) && (toolMode!=25)) {

			if ((selectCount==1) && (zoomToSingleSelect)) {

				var fWidth = selectRight[0] - selectLeft[0];

				var fHeight = selectTop[0] - selectBottom[0];

				var mWMargin = 0;

				var mHMargin = 0;

				if (selectType=="point") {			

					mWMargin = fullWidth * selectPointMargin;

					mHMargin = fullHeight * selectPointMargin;

					if (mWMargin > xDistance/2) {

						mWMargin = xDistance/2;

						mHMargin = yDistance/2;

					}

				} else {

					mWMargin = fWidth * selectMargin;

					mHMargin = fHeight * selectMargin; 

				}

				saveLastExtent();

				left = selectLeft[0] - mWMargin;

				right = selectRight[0] + mWMargin;

				top = selectTop[0] + mHMargin;

				bottom = selectBottom[0] - mHMargin;

			}

			sendMapXML();

		}

		

		

			

	} else {

		//alert(tempString);

		if ((useExternalWindow) || (!useTextFrame)) {

			Win1 = window.open("","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");

		} else {

			Win1 = parent.TextFrame;

			Win1.document.open();

		}

		Win1.document.writeln('<html><head>');

		Win1.document.writeln('	<title>Select Results</title>');

		Win1.document.writeln('</head>');

		Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');

		Win1.document.writeln('<FONT FACE="Arial"><B>' + LayerName[ActiveLayerIndex] +'</B></font><FONT FACE="Arial" size="-2">');

		Win1.document.writeln('<br>No Features Found.');

		if (debugOn>0) {

			Win1.document.writeln('<p>Returned ArcXML Response:<br>');

			Win1.document.writeln(untag(theReply));

		} else {

			if (theError!="") {

				Win1.document.writeln('<p>Server returned:<br>');

				Win1.document.writeln(theError);

			}

		}

		Win1.document.writeln('</FONT>');

		Win1.document.writeln('</body></html>');

		Win1.document.close();

	}

	if ((toolMode==4) || (toolMode==9))  selectCount=0;

	Win1=null;

	hideRetrieveData();

}



function parseHyperLink(theReply) {


				if (parent.intPrjNo=="11598"){
				alert(theReply);
			    }

	//alert(theReply);

	var fList="";

	var lpos1 = 1;

	var lpos2 = 1;

	var pos = 0;

	var startpos = 0;

	var endpos = 0;

	var fString = theReply.substring(startpos,endpos);

	var featureCount = justGetFeatureCount(theReply);

	var linkString = "width=" + hyperlinkWindowWidth + ",height=" + hyperlinkWindowHeight + ",scrollbars=yes,resizable=yes"

	var selectedData="";

	var fCount = featureCount;

	//alert("displayAttributeData()[featurecount=" + featureCount + "]");

	selectCount = 0;

	var tempString="";

	if (featureCount > 0) {

		var searchStr = currentHyperLinkField + "=";

		

		newSelectCount += 1;



		endpos = 1;

		pos = theReply.indexOf(searchStr,1);

		startpos = pos + searchStr.length + 1;

		endpos =theReply.indexOf(dQuote,startpos);

		inData = theReply.substring(startpos,endpos);
		//FIVIMS-ZA Hyperlink to radar graph	
		if ((parent.intPrjNo=="9426") && (LayerName[ActiveLayerIndex] =="FIVIMS Nutritional status")){
			//alert(theReply)
			inData = "http://www.agis.agric.za/agisweb/image_view_h.html?heading=NUTRITIONAL STATUS RADAR GRAPH&image_id=radar_" +theReply.substring(startpos,endpos);
        //alert(inData)
		}

		if (parent.TextFrame!=null) {

			parent.TextFrame.document.open();

			parent.TextFrame.document.writeln('<html><head>');

			parent.TextFrame.document.writeln('	<title>Select Results</title>');

			parent.TextFrame.document.writeln('</head>');

			parent.TextFrame.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');

			parent.TextFrame.document.writeln('<FONT FACE="Arial"><B>' + LayerName[ActiveLayerIndex] +'</B></font><FONT FACE="Arial" size="-2">');

			parent.TextFrame.document.writeln('<br>HyperLink to ' + inData);

			parent.TextFrame.document.writeln('</FONT>');

			parent.TextFrame.document.writeln('</body></html>');

			parent.TextFrame.document.close();

		}
		// A-Stat begin ---------------------------------------------------------------------------------------
		//if (parent.intPrjNo=="6220"){
		//	inData = parent.hyperPrefix[parent.specifiedLayer] + inData + parent.hyperSuffix[parent.specifiedLayer];
		//}
		
		//alert("Indata : ActiveLayer" + inData + " : " + parent.specifiedLayer);
		// A-Stat stop ----------------------------------------------------------------------------------------

		//FIVIMS-ZA Hyperlink to radar graph	
		if ((parent.intPrjNo=="9426") && (LayerName[ActiveLayerIndex] =="FIVIMS Nutritional status")){
        //alert(inData)
		}
		else {
		inData = parent.hyperPrefix[parent.specifiedLayer] + inData + parent.hyperSuffix[parent.specifiedLayer];
		}
		var Win1=open(inData,"",linkString);


	} else {

	

		//alert(tempString);

		if (parent.TextFrame!=null) {

			parent.TextFrame.document.open();

			parent.TextFrame.document.writeln('<html><head>');

			parent.TextFrame.document.writeln('	<title>Select Results</title>');

			parent.TextFrame.document.writeln('</head>');
			
		//Carin changes for WOCAT select point
 			if (parent.intPrjNo=="9644"){
				parent.TextFrame.document.writeln('<body BGCOLOR="#C0C0C0" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
				parent.TextFrame.document.writeln('<FONT FACE="Arial"><B>' + LayerName[ActiveLayerIndex] +'</B></font><FONT FACE="Arial" size="-2">');
				parent.TextFrame.document.writeln('<FONT FACE="Arial" size="2pt">');
				parent.TextFrame.document.writeln('<br><br>Point selected = ');
				parent.TextFrame.document.writeln(mapX +' , '+ mapY);
				parent.TextFrame.document.writeln('<br><br><input type="button" value="Set location" onClick="javascript:window.parent.close()">');
				parent.TextFrame.document.writeln('</FONT>');
			}
			 //Carin changes for WOCAT World Map select point
 			else if (parent.intPrjNo=="11336"){
				parent.TextFrame.document.writeln('<body BGCOLOR="#C0C0C0" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
				parent.TextFrame.document.writeln('<FONT FACE="Arial"><B>' + LayerName[ActiveLayerIndex] +'</B></font><FONT FACE="Arial" size="-2">');
				parent.TextFrame.document.writeln('<FONT FACE="Arial" size="2pt">');
				parent.TextFrame.document.writeln('<br><br>Point selected = ');
				parent.TextFrame.document.writeln(mapX +' , '+ mapY);
				parent.TextFrame.document.writeln('<br><br><input type="button" value="Set location" onClick="javascript:window.parent.close()">');
				parent.TextFrame.document.writeln('</FONT>');
			}
			 //Carin changes for ORGANISATIONS select point
 			else if (parent.intPrjNo=="9726"){
				parent.TextFrame.document.writeln('<body BGCOLOR="#C0C0C0" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
				parent.TextFrame.document.writeln('<FONT FACE="Arial"><B>' + LayerName[ActiveLayerIndex] +'</B></font><FONT FACE="Arial" size="-2">');
				parent.TextFrame.document.writeln('<FONT FACE="Arial" size="2pt">');
				parent.TextFrame.document.writeln('<br><br>Point selected = ');
				parent.TextFrame.document.writeln(mapX +' , '+ mapY);
				parent.TextFrame.document.writeln('<br><br><input type="button" value="Set location" onClick="javascript:window.parent.close()">');
				parent.TextFrame.document.writeln('</FONT>');
			}
			else {

			parent.TextFrame.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');

			parent.TextFrame.document.writeln('<FONT FACE="Arial"><B>' + LayerName[ActiveLayerIndex] +'</B></font><FONT FACE="Arial" size="-2">');

			parent.TextFrame.document.writeln('<br>Unable to hyperlink with submitted request.');
      }
			if (debugOn>0) {

				parent.TextFrame.document.writeln('<p>Returned ArcXML Response:<br>');

				parent.TextFrame.document.writeln(untag(theReply));

			}

			parent.TextFrame.document.writeln('</FONT>');

			parent.TextFrame.document.writeln('</body></html>');

			parent.TextFrame.document.close();

		} else {

			var msg = "Unable to hyperlink.";

			if (debugOn>0) {

				msg = msg + "\nServer ArcXML response:\n" + theReply;

			}

			alert(msg);

		}

	}

	hideRetrieveData();

}



// are there any selected features?

function checkSelected() {

	var isOk = false;

	if (selectCount>0) isOk = true;

	return isOk;

}



function checkHyperLinkLayer(layerIndex) {

	var canLink = false;

	//alert(hyperLinkLayers.length);

	for (var i=0; i<parent.hyperLinkLayers.length; i++) {

			if (LayerName[layerIndex]==parent.hyperLinkLayers[i]) {

				canLink=true;

				currentHyperLinkLayer=LayerName[layerIndex];

				currentHyperLinkField=parent.hyperLinkFields[i];

				if (parent.intPrjNo=="11598"){
				alert(LayerName[layerIndex] + " : " + parent.hyperLinkLayers[i] + " : " + parent.hyperLinkFields[i] + " : "  + (LayerName[layerIndex]==parent.hyperLinkLayers[i]));
			}

			}

	}

	return canLink;



}