/**************************************************************
 * Flash Client Application TestPage/SDK                      *
 *------------------------------------------------------------*
 * File: 	demo.js    		                      *
 * Author:	BV 				              *
 * Desc:	This script handles the javascript functions  *
 *					for this testpage/sdk *								              *
 *------------------------------------------------------------*
 *(C) Bentley Systems Netherlands BV, 2006                    *
 **************************************************************/

/**************************************************************
 ************ Constants and global variables ******************
 **************************************************************/
 
var isIE = (document.all) ? true : false;
var sVersion = "2.0.0";
var xmlns = "http://www.bentley.com/FlexiMap"
var xmlns_xsi = "http://www.w3.org/2001/XMLSchema-instance";
var xsi_schemaLocation = "http://www.bentley.com/FlexiMap FMRequest.xsd";
var tempXML;
var host = window.location.hostname;
var sqList = new Array(); //array to store all the available searches for a service

var bSecureService; // boolean defining if service is secure (useservicekey = true)

var exposedParams; //string that will be used to catch all the parameters exposed by Flash

// Global variables used in demo catch functions

var flash_mapWidth=700;
var flash_mapHeight=700;

var sServiceName = "Parkeren";
var sSearchName = "Punten";
var sColumnName1 = "ACTIEF";
var sColumnName2 = "ID";
//var sxCoord = 195946;		// hart van overzichtskaart (variable werkt niet; invoeren onder functie StartParams())
//var syCoord = 321121;		// hart van overzichtskaart (variable werkt niet; invoeren onder functie StartParams())
//var sMapResolution = 24;	// resolutie waarmee Flash-map opgestart wordt (variable werkt niet; invoeren onder functie StartParams())
        
var var_SHOW_COLUMNS = 1;

var service;
var mapwidth;
var mapheight;
var mapresolution;
var xcoord;
var ycoord;
var servicekey;
var maplayers;
var fm;
var rlpoint = new Array();
var searchCoords;

/**************************************************************
 ************************* Functions **************************
 **************************************************************/

/*------------------------------------------------------------*
 * function called from report (shows links in report)        *
 *------------------------------------------------------------*/
 
function showLink(sUrl)
{
  window.open(sUrl,'win');
}

/*------------------------------------------------------------*
 * fleximap:                                                  *
 * This function will be used by Flash to expose parameters   *
 * Function must be named "fleximap" and accept 1 parameter   *
 * Content can be adjusted to suit specific needs             *
 *------------------------------------------------------------*/
 
function fleximap(params)
{
	//alert(params);
	var arrAllParams = params.split('|');
	for (var i = 0;i< arrAllParams.length;i++)
	{
		var tmp = arrAllParams[i];
		var arrOneParam = arrAllParams[i].split('=');
		var param = arrOneParam[0].toLowerCase();
		var val= arrOneParam[1];

		switch (param) {
		case 'fm':
			fm=val;
			break;
		case 'servicekey':
			servicekey=val;
			break;
		case 'service':
			service=val;
			break;
		case 'mapwidth':
			mapwidth=val;
			break;
		case 'mapheight':
			mapheight=val;
			break;
		case 'mapresolution':
			mapresolution=val;
			break;
		case 'xcoord':
			xcoord=val;
			break;
		case 'ycoord':
			ycoord=val;
			break;
		case 'maplayers':
			maplayers=val;
			break;
		case 'redline':
			if (val.toUpperCase()=='CLEAR') {
				rlpoint.length=0;
			}
			else {
				rlpoint.addItem(val);
			}
			break;
	 	case 'info':
			//infopoint.addItem(val);
			searchCoords=val;
			break;
		}
	}
	//now clear the variables that have been exposed
	exposedParams='';
	return;
}

/*------------------------------------------------------------*
 * addParams:                                                 *
 * This function will be used by Flash to expose parameters   *
 * Function must be named "addParams" and accept 1 parameter  *
 * ==============Content must NOT be changed================= *
 * If string from Flash is too long, this function will be    *
 * called until entire string is passed                       *
 *------------------------------------------------------------*/
 
function addParams(params)
{
	// DO NOT PUT ALERT BOXES IN THIS FUNCTION
	// FUNCTION IS CALLED WITH AN INTERVAL
	exposedParams += params;
}

/*------------------------------------------------------------*
 * submitParams:                                              *
 * This function will be called from Flash when the entire    *
 * string is transferred to addParams                         *
 * Now a function can be called to process the exposed params *
 *------------------------------------------------------------*/
 
function submitParams()
{
	//alert(exposedParams);

	//now call the function fleximap, to be backward compatible
	fleximap(exposedParams);
}

/*------------------------------------------------------------*
 * getServicekey:                                             *
 * This function will start a serverside script to obtain a   *
 * service key.                                               *
 * Use of ServiceKey necessary if service is secure           *
 *------------------------------------------------------------*/
 
function getServiceKey()
{
  var selService = document.getElementById("services");
  var sServiceName = selService.options[selService.selectedIndex].value;
  var sUrl = 'servicekey.asp?' + sServiceName;
  parent.fraExec.location.href = sUrl;
}

/*------------------------------------------------------------*
 * storeServicekey:                                           *
 * This function will store the generated servicekey.         *
 * Will be used in buildStartParams.                          *
 * NOTE:This function is called from a child frame,           *
 * so parent needs to be used to access variables.            *
 *------------------------------------------------------------*/
 
function storeServiceKey(sKey)
{
	// store the generated key
	parent.document.frmmain.key.value = sKey;

	if (parent.bSecureService)
	{
		var sLogoHtml= '<center><img src="./images/bentleylogo_big2.gif"></center>';
	}
	else
	{
		var sLogoHtml= '<center><img src="./images/bentleylogo_big.gif"></center>';
	}
	sLogoHtml += '<center><font class="bannertlt"><b>';
	sLogoHtml += sKey;
	sLogoHtml += '</b></font></center>';
	var divFlash = parent.document.getElementById("flashMovie");
  divFlash.innerHTML = sLogoHtml;
}

/*------------------------------------------------------------*
 * showParams:                                                *
 * This function shows all the parameters exposed by Flash    *
 * These parameters have been "catched" & stored in function  *
 * "fleximap"                                                 *
 *------------------------------------------------------------*/
 
function showParams()
{
	var sHTMLtext = '<br><font class="txt"><b>Values that have been exposed by the flash movie:</b><br>';
	sHTMLtext += 'fm= ' + fm + '<br>';
	sHTMLtext += 'service= ' + service + '<br>';
	sHTMLtext += 'servicekey= ' + servicekey + '<br>';
	sHTMLtext += 'mapwidth= ' + mapwidth + '<br>';
	sHTMLtext += 'mapheight= ' + mapheight + '<br>';
	sHTMLtext += 'mapresolution= ' + mapresolution + '<br>';
	sHTMLtext += 'xcoord= ' + xcoord + '<br>';
	sHTMLtext += 'ycoord= ' + ycoord + '<br>';
	sHTMLtext += 'maplayers= ' + maplayers + '<br>';

	if (searchCoords != '')
	{
		sHTMLtext += 'search coordinates= ' + searchCoords + '<br>';
	}

  if(rlpoint.length > 0)
  {
    for(var idx = 0; idx < rlpoint.length; idx++)
    {
			sHTMLtext += 'redlined object= ' + rlpoint[idx] + '<br>';
    }
  }

	sHTMLtext += '</font>';

	var oInfo = document.getElementById("divInfo");
	oInfo.innerHTML = sHTMLtext;
	oInfo.style.height = '500px';
	oInfo.style.width = '350px';
	var oIFrame = parent.document.getElementById("fraExec");
	oIFrame.style.height = '0px';
}

/*------------------------------------------------------------*
 * showMap:                                                   *
 * This function will create and show a GetMap request        *
 * based on the parameters exposed by Flash                   *
 *------------------------------------------------------------*/
 
function showMap()
{
	var sHTMLtext ='<form name="infoForm" encoding="text/plain">';
  sHTMLtext += '<input type="hidden" name="xml"/></form>';
	document.getElementById("divInfo").innerHTML = sHTMLtext;
  setTimeout("ReCreateMap()", 100);
  return;
}

/*------------------------------------------------------------*
 * retrieveXML:                                               *
 * Post XML to server and return the XML response             *
 *------------------------------------------------------------*/
 
function retrieveXML(sendXML)
{
  var xmlObj;
  if(isIE)
  {
    xmlObj = new ActiveXObject("MSXML2.XMLHTTP");
  }
  else
  {
    xmlObj = new XMLHttpRequest();
  }
  xmlObj.open("POST","http://" + window.location.hostname + "/scripts/fleximap.dll", false);
  xmlObj.setRequestHeader("Content-Length", sendXML.length);
  xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
  xmlObj.send(sendXML);

  return xmlObj.responseXML;
}

/*------------------------------------------------------------*
 * Array_addItem:                                             *
 *------------------------------------------------------------*/
 
function Array_addItem(item)
{
  this[this.length] = item;
  return item;
}
Array.prototype.addItem = Array_addItem;

/*------------------------------------------------------------*
 * ReCreateMap:                                               *
 * Create a GetMap request (called from showMap)              *
 *------------------------------------------------------------*/
 
function ReCreateMap()
{
  var frag;
  // Create a new XMLDOM object
  if(isIE)
  {
    frag = new ActiveXObject("Microsoft.XMLDOM");
  }
  else
  {
    frag = document.implementation.createDocument("", "", null);
  }

  var fragRoot = frag.createElement("fragroot");
  frag.appendChild(fragRoot);

  var fragRequest = frag.createElement("FMGetMap");
  fragRoot.appendChild(fragRequest);
  fragRequest.setAttribute("version", sVersion);
  fragRequest.setAttribute("xmlns", xmlns);
  fragRequest.setAttribute("xmlns:xsi", xmlns_xsi);
  fragRequest.setAttribute("xsi:schemaLocation", xsi_schemaLocation);

  var fragService = frag.createElement("Service");
  var fragServiceText = frag.createTextNode(service);
  fragService.appendChild(fragServiceText);
  fragRequest.appendChild(fragService);

	// add the servicekey element if needed
	if (bSecureService)
	{
		var secKey = parent.document.frmmain.key.value;
		if (secKey == '')
		{
			alert('This is a secure service, please get a valid servicekey');
			return false;
		}
		else
		{
			var fragServiceKey = frag.createElement("ServiceKey");
			var fragServiceKeyText = frag.createTextNode(secKey);
		  fragServiceKey.appendChild(fragServiceKeyText);
  		fragRequest.appendChild(fragServiceKey);
		}
	}

  var fragContentType = frag.createElement("ContentType");
  fragRequest.appendChild(fragContentType);
  fragContentType.appendChild(frag.createTextNode("image/png"));

  var fragMapWidth = frag.createElement("MapWidth");
  fragRequest.appendChild(fragMapWidth);
  fragMapWidth.appendChild(frag.createTextNode(mapwidth));

  var fragMapHeight = frag.createElement("MapHeight");
  fragRequest.appendChild(fragMapHeight);
  fragMapHeight.appendChild(frag.createTextNode(mapheight));

  var fragMapRes = frag.createElement("MapResolution");
  fragRequest.appendChild(fragMapRes);
  fragMapRes.appendChild(frag.createTextNode(mapresolution));

  var fragXCoord = frag.createElement("XCoord");
  fragRequest.appendChild(fragXCoord);
  fragXCoord.appendChild(frag.createTextNode(xcoord));

  var fragYCoord = frag.createElement("YCoord");
  fragRequest.appendChild(fragYCoord);
  fragYCoord.appendChild(frag.createTextNode(ycoord));

  if(rlpoint.length > 0)
  {
    var fragRLInfo = frag.createElement("RedlineInfo");
    fragRequest.appendChild(fragRLInfo);

    for(var idx = 0; idx < rlpoint.length; idx++)
    {
      var fragRedline = frag.createElement("Redline");
      fragRLInfo.appendChild(fragRedline);
      fragRedline.appendChild(frag.createTextNode(rlpoint[idx]));
    }
  }

  var sendXML;
  if(isIE)
  {
    sendXML = fragRequest.xml;
  }
  else
  {
    var ser = new XMLSerializer();
    sendXML = ser.serializeToString(fragRequest);
  }

  tempXML = sendXML;
  setTimeout("waitAndSend(document.infoForm)", 100);

  var oIFrame = document.getElementById('fraExec');
	oIFrame.style.height = '500px';
	var oInfo = document.getElementById("divInfo");
	oInfo.style.height = '0px';

  return;
}

/*------------------------------------------------------------*
 * waitAndSend:                                               *
 *------------------------------------------------------------*/
 
function waitAndSend(myForm)
{
  myForm.xml.value = tempXML;
  myForm.method = "post";
  myForm.action = "http://" + window.location.hostname + "/scripts/FlexiMap.dll";
  myForm.target= "fraExec";
  myForm.submit();
  return;
}

/*----------------------------------------------------------------*
 * Search:                                                        *
 * Constructor for SearchObject                                   *
 *----------------------------------------------------------------*/
 
function Search(SQname, colnames, aliases)
{
	this.name = SQname;				// Initialize SearchName
  this.columns = colnames;				// Initialize column names (seperated by pipes)
  this.aliases = aliases;				// Initialize column aliases (seperated by pipes)
	this.answers ='';				// Used to store the answers (seperated by pipes)
}

/*------------------------------------------------------------*
 * getServices:                                               *
 * Get a list of available services on this Server            *
 * This function is called in the onload event of the website *
 *------------------------------------------------------------*/
 
function getServices()
{
  var frag;
  if(isIE)
  {
    frag = new ActiveXObject("Microsoft.XMLDOM");
  }
  else
  {
    frag = document.implementation.createDocument("", "", null);
  }

  var fragRoot = frag.createElement("fragroot");
  frag.appendChild(fragRoot);

  var fragRequest = frag.createElement("FMGetServiceList");
  fragRoot.appendChild(fragRequest);
  fragRequest.setAttribute("version", sVersion);
  fragRequest.setAttribute("xmlns", xmlns);
  fragRequest.setAttribute("xmlns:xsi", xmlns_xsi);
  fragRequest.setAttribute("xsi:schemaLocation", xsi_schemaLocation);

  var sendXML;
  if(isIE)
  {
    sendXML = fragRequest.xml;
  }
  else
  {
    var ser = new XMLSerializer();
    sendXML = ser.serializeToString(fragRequest);
  }

  var responseXML = retrieveXML(sendXML);
  var responseTag = responseXML.documentElement.tagName;

  var elServices = responseXML.documentElement.getElementsByTagName("Services")[0];
  var cboServ = document.getElementById("services");

  cboServ.options.length = 0;
  cboServ.options[0] = new Option("-- Select --", "");

  for(idx = 0; idx < elServices.childNodes.length; idx++)
  {
    elItem = elServices.childNodes[idx];
    if(elItem.childNodes.length > 0)
    {
    	cboServ.options[cboServ.options.length] = new Option(elItem.childNodes[0].nodeValue, elItem.childNodes[0].nodeValue);
		}
  }
  return true;
}

/*----------------------------------------------------------------*
 * storeAnswers:                                                  *
 * Store the selected answers to search questions                 *
 * This function is called from getQuestion                       *
 *----------------------------------------------------------------*/
 
function storeAnswers(oSearch, iQuestionNum)
{
	var arrCols = oSearch.columns.split('|');
	var sAnswer='';
	for(var i = 0; i < iQuestionNum; i++)
	{
		var oCol = document.getElementById(arrCols[i]);
		sAnswer += '|' + oCol.options[oCol.selectedIndex].value;
	}
	oSearch.answers = sAnswer.substr(1);
}

/*---------------------------------------------------------------------*
 * buildStartParams:                                                   *
 * Initialize Flash with parameters provided in the website            *
 * This function is called from getQuestion OR the "start Flash"Button *
 *---------------------------------------------------------------------*/
 
function buildStartParams(startMode)
{
  // variables sServicename is already set, xcoord, ycoord en mapresolutiun hier invoeren

   // content van het INFO div veld
   var sHTMLtext ='<table width="300">';

	// build string with startparmaters for Flash Client
	// centrale x+y en mapresolutie van overzichtskaart invoeren in laatste regel
	sClientParams = "fmClient.swf?fm=http://"+ host + "/Scripts/FlexiMap.dll";
	sClientParams += "&commurl=report.asp&commtarget=fraExec";
	sClientParams += "&service=" + sServiceName;
	sClientParams += "&xcoord=195950&ycoord=322020&mapresolution=2.6";
	
	switch (startMode)
  {
	  case 0: //start flash without sq or xy parameters
		  //only servicename and optionally servicegroup) need to be passed
		  break;

	  case 1: //start flash with sq parameters
		  break;

	  case 2: //start flash with xy parameters
		  break;

  }

	// call function that (re)initializes Flash
	startFlash(sClientParams);
	//alert(sClientParams);

      // Lijst opvragen van huidige projecten
      // stap 1:      FMGetList       resulteert in lijst met ID's
      // stap 2:      FMGetLocation   geeft bij een ID de XY-coordinaten
      // stap 3:      FMGetInfo       geeft bij XY-coordinaten de gegevens
      
      // STAP 1
      
       //////////////////////////////////////////////////////////////////////////////////////
         
	var frag;

	if(isIE)
	{
		frag = new ActiveXObject("Microsoft.XMLDOM");
	}
	else
	{
		frag = document.implementation.createDocument("", "", null);
	}     
	
        var fragRoot;
        var fragRequest;
        var fragService;
        var fragServiceText;
        var fragSQ;
        var fragSQCol;
        
        var sendXML;
	var ser;
	var responseXML;
	var responseTag;
	var elColumn;
	
        fragRoot = frag.createElement("fragroot");
	frag.appendChild(fragRoot);

	fragRequest = frag.createElement("FMGetList");
	fragRoot.appendChild(fragRequest);
	fragRequest.setAttribute("version", sVersion);
	fragRequest.setAttribute("xmlns", xmlns);
	fragRequest.setAttribute("xmlns:xsi", xmlns_xsi);
	fragRequest.setAttribute("xsi:schemaLocation", xsi_schemaLocation);

	fragService = frag.createElement("Service");
	fragServiceText = frag.createTextNode(sServiceName);
	fragService.appendChild(fragServiceText);
	fragRequest.appendChild(fragService);

	fragSQ = frag.createElement("SearchQuery");
	fragSQ.setAttribute("name", sSearchName);
	fragRequest.appendChild(fragSQ);

	fragSQCol = frag.createElement("Column");
	fragSQCol.setAttribute("name", sColumnName1 );
	fragSQ.appendChild(fragSQCol);
	
	//ACTIEF moet 1 zijn
	
	var value_actief;
	value_actief = "1";
	
        fragSQCol.appendChild(frag.createTextNode(value_actief));
	fragSQ.appendChild(fragSQCol);

	fragSQCol = frag.createElement("Column");
	fragSQCol.setAttribute("name", sColumnName2 );
	fragSQ.appendChild(fragSQCol);

	// occupy a dropdownlist with the result
	if(isIE)
	{
		sendXML = fragRequest.xml;
	}
	else
	{
		ser = new XMLSerializer();
		sendXML = ser.serializeToString(fragRequest);
	}

	responseXML = retrieveXML(sendXML);
	responseTag = responseXML.documentElement.tagName;

	if(responseTag == "FMServiceExceptionReport")
	{
		alert("An error has occurred:\nReason: " +
			responseXML.getElementsByTagName("Reason")[0].childNodes[0].nodeValue + "\nDescription: " +
			responseXML.getElementsByTagName("Description")[0].childNodes[0].nodeValue);
		return false;
	}

	//alert(new XMLSerializer().serializeToString(responseXML.documentElement));
	
	elColumn = responseXML.documentElement.getElementsByTagName("Column")[0];
	
	var list_IDS;
	
	list_IDS = "";
	
	for(idx = 0; idx < elColumn.childNodes.length; idx++)
	{
		elItem = elColumn.childNodes[idx];
		if(elItem.childNodes.length > 0)
		{
	   	   list_IDS = list_IDS + elItem.childNodes[0].nodeValue + "|" ;
		}
	}
         
       var array_listIDS = list_IDS.split("|");
       
       // STAP 2
       //////////////////////////////////////////////////////////////////////////////////////
       var part_num=0;

       var current_ID;   // bevat primary ID van het object
       
       while (part_num < array_listIDS.length-1)
       {
          
         current_ID = array_listIDS[part_num];
         part_num+=1;
 

		if(isIE)
		{
			frag = new ActiveXObject("Microsoft.XMLDOM");
		}
		else
		{
			frag = document.implementation.createDocument("", "", null);
		}     

		fragRoot = frag.createElement("fragroot");
		frag.appendChild(fragRoot);

		fragRequest = frag.createElement("FMGetLocation");
		fragRoot.appendChild(fragRequest);
		fragRequest.setAttribute("version", sVersion);
		fragRequest.setAttribute("xmlns", xmlns);
		fragRequest.setAttribute("xmlns:xsi", xmlns_xsi);
		fragRequest.setAttribute("xsi:schemaLocation", xsi_schemaLocation);

		fragService = frag.createElement("Service");
		fragServiceText = frag.createTextNode(sServiceName);
		fragService.appendChild(fragServiceText);
		fragRequest.appendChild(fragService);

		fragSQ = frag.createElement("SearchQuery");
		fragSQ.setAttribute("name", sSearchName);
		fragRequest.appendChild(fragSQ);

		fragSQCol = frag.createElement("Column");
		fragSQCol.setAttribute("name", sColumnName1 );
		fragSQ.appendChild(fragSQCol);

		//ACTIEF moet 1 zijn

		var value_actief;
		value_actief = "1";

		fragSQCol.appendChild(frag.createTextNode(value_actief));
		fragSQ.appendChild(fragSQCol);

		fragSQCol = frag.createElement("Column");
		fragSQCol.setAttribute("name", sColumnName2 );
		fragSQ.appendChild(fragSQCol);

                // current_ID is de huidige ID van het object
                fragSQCol.appendChild(frag.createTextNode(current_ID));
		fragSQ.appendChild(fragSQCol);

		if(isIE)
		{
			sendXML = fragRequest.xml;
		}
		else
		{
			ser = new XMLSerializer();
			sendXML = ser.serializeToString(fragRequest);
		}

		responseXML = retrieveXML(sendXML);
		responseTag = responseXML.documentElement.tagName;

		if(responseTag == "FMServiceExceptionReport")
		{
			alert("An error has occurred:\nReason: " +
				responseXML.getElementsByTagName("Reason")[0].childNodes[0].nodeValue + "\nDescription: " +
				responseXML.getElementsByTagName("Description")[0].childNodes[0].nodeValue);
			return false;
		}

		//alert(new XMLSerializer().serializeToString(responseXML.documentElement));

		var xCoord = responseXML.documentElement.getElementsByTagName("XCoord")[0].childNodes[0].nodeValue;
                var yCoord = responseXML.documentElement.getElementsByTagName("YCoord")[0].childNodes[0].nodeValue;
		
		
		// STAP 3 : ophalen van gegevens bij elke ID en XY
        //////////////////////////////////////////////////////////////////////////////////////
	
            		if(isIE)
      		{
      			frag = new ActiveXObject("Microsoft.XMLDOM");
      		}
      		else
      		{
      			frag = document.implementation.createDocument("", "", null);
      		}     
      
      		fragRoot = frag.createElement("fragroot");
      		frag.appendChild(fragRoot);
      
      		fragRequest = frag.createElement("FMGetInfo");
      		fragRoot.appendChild(fragRequest);
      		fragRequest.setAttribute("version", sVersion);
      		fragRequest.setAttribute("xmlns", xmlns);
      		fragRequest.setAttribute("xmlns:xsi", xmlns_xsi);
      		fragRequest.setAttribute("xsi:schemaLocation", xsi_schemaLocation);
      
      		fragService = frag.createElement("Service");
      		fragServiceText = frag.createTextNode(sServiceName);
      		fragService.appendChild(fragServiceText);
      		fragRequest.appendChild(fragService);
      
                var fragClickPnt = frag.createElement("ClickPoint");
                fragRequest.appendChild(fragClickPnt);
                fragClickPnt.appendChild(frag.createTextNode(xCoord + " " + yCoord));
      
                var mapRes = "24";
                
        	var fragMapRes = frag.createElement("MapResolution");
        	fragRequest.appendChild(fragMapRes);
        	fragMapRes.appendChild(frag.createTextNode(mapRes));

        	var fragMapWidth = frag.createElement("MapWidth");
        	fragRequest.appendChild(fragMapWidth);
        	fragMapWidth.appendChild(frag.createTextNode(flash_mapWidth));

        	var fragMapHeight = frag.createElement("MapHeight");
        	fragRequest.appendChild(fragMapHeight);
        	fragMapHeight.appendChild(frag.createTextNode(flash_mapHeight));
      
      		if(isIE)
      		{
      			sendXML = fragRequest.xml;
      		}
      		else
      		{
      			ser = new XMLSerializer();
      			sendXML = ser.serializeToString(fragRequest);
      		}
      
      		responseXML = retrieveXML(sendXML);
      		responseTag = responseXML.documentElement.tagName;
      
      		if(responseTag == "FMServiceExceptionReport")
      		{
      			alert("An error has occurred:\nReason: " +
      				responseXML.getElementsByTagName("Reason")[0].childNodes[0].nodeValue + "\nDescription: " +
      				responseXML.getElementsByTagName("Description")[0].childNodes[0].nodeValue);
      			return false;
      		}
      
      		//alert(new XMLSerializer().serializeToString(responseXML.documentElement));
            	
            	

		var colElem = responseXML.documentElement.getElementsByTagName("Records")[0];
		if(!colElem)
		{
			alert("Invalid response, no Column element present!");
			return;
		}

		var itemElems = colElem.getElementsByTagName("Item");
				
		if(itemElems.length == 0)
		{
			// No results found
			alert("There are no results found at this click point");
			return;
		}
		else if(itemElems.length == 1)
		{

		}
		else
		{
		// Multiple results found, create select list
                        
                        var this_item;
                        this_item = "";
               
			for(idx = 0; idx < itemElems.length-1; idx++)
			{
			  if( null==  itemElems[idx].childNodes[0] )
			  {
			    this_item = this_item + " |"
			  }
			  else
			  {
			    var sItmVal = itemElems[idx].childNodes[0].nodeValue;
		            this_item = this_item + sItmVal + "|"
		          } 	          
			  
			}   
			
			var array_info = this_item.split("|");
			
			// EERSTE kolommen worden getoond, variabel var_SHOW_COLUMNS
			
			var ii;
			ii = 0;
			var doorgeef_data;
			
			doorgeef_data = "";
			
			 while (ii < array_info.length-1 )
			 {
			    doorgeef_data = doorgeef_data + array_info[ii] + "|";
			    ii+=1;
			 }

			ii = 0
			
			 while (ii < var_SHOW_COLUMNS)
			 {
			    sHTMLtext += '<tr>';
			    sHTMLtext += '<td>';
			    
			    if( ii == 0)
			    {
			      sHTMLtext += '<B><a href="project.asp?data=' + doorgeef_data + '">' + array_info[ii] + '</a></B>';
			    
			    }
			    else
			    {
			      sHTMLtext += array_info[ii];
			    }  
			    sHTMLtext += '</td>';
			    sHTMLtext += '</tr>';
                            ii+=1;
			 }		 			
                
		}

       //////////////////////////////////////////////////////////////////////////////////////                
	
          sHTMLtext += '';
 
 
       }  // einde while loop

	
   sHTMLtext += '</table>';
                
   document.getElementById("divInfo").innerHTML = sHTMLtext;
      
      
}


/*----------------------------------------------------------------*
 * startFlash:                                                    *
 * Initialize Flash with specific startparameters                 *
 * This function is called from buildStartParams OR highlightObj  *
 *----------------------------------------------------------------*/
 
function startFlash(sClientParams)
{
	var flashHtml = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	flashHtml += "codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0'";
	flashHtml += "WIDTH='"+ flash_mapWidth + "' HEIGHT='"+ flash_mapHeight + "' id='fmClient' ALIGN='middle'>";
	flashHtml += "<param name=movie value='"+ sClientParams + "'>";
	flashHtml += "<param name=allowScriptAccess value='sameDomain'>";
	flashHtml += "<param name=quality value='high'>";
	flashHtml += "<param name=bgcolor value='#'>";
	flashHtml += "<param name=scale value='noscale'>";
	flashHtml += "<embed src='"+ sClientParams + "' quality=high bgcolor=# WIDTH='"+ flash_mapWidth + "' HEIGHT='"+ flash_mapHeight + "' scale='noscale' NAME='fmClient'";
	flashHtml += "align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed>";
	flashHtml += "</object>";

/*

	var flashHtml = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	flashHtml += "codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0'";
	flashHtml += "WIDTH='100%' HEIGHT='100%' id='fmClient' ALIGN='middle'>";
	flashHtml += "<param name=movie value='"+ sClientParams + "'>";
	flashHtml += "<param name=allowScriptAccess value='sameDomain'>";
	flashHtml += "<param name=quality value='high'>";
	flashHtml += "<param name=bgcolor value='#'>";
	flashHtml += "<param name=scale value='noscale'>";
	flashHtml += "<param name=wmode value='transparent'>";
	flashHtml += "<embed src='"+ sClientParams + "' quality=high wmode='transparent' bgcolor=# WIDTH='" + flash_mapWidth + "' HEIGHT='" + flash_mapHeight + "' scale='noscale' NAME='fmClient'";
	flashHtml += "align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed>";
	flashHtml += "</object>";
*/


   //alert(flashHtml);

  var divFlash = document.getElementById("flashMovie");
  divFlash.innerHTML = flashHtml;


	var divonTop = document.getElementById("onTop");
  //divonTop.innerHTML = 'dit is een ontop test';

}


/*----------------------------------------------------------------*
 * highlightObj:                                                  *
 * Initialize Flash with layer and keys	parameters to highlight   *
 * This function is called from a Report                          *
 *----------------------------------------------------------------*/
 
function highlightObj(param)
{
	var sClientParams = "fmClient.swf?fm=http://"+ host + "/Scripts/FlexiMap.dll";
	sClientParams += "&commurl=report.asp&commtarget=fraExec";
	sClientParams += "&service=" + service;
	//sClientParams += "&mapResolution=" + sMapResolution;

	if (maplayers != ''){
		sClientParams += "&startlayers=" + maplayers;
	}

/*	// add the servicekey parameter if needed
	if (bSecureService)
	{
		var secKey = parent.document.frmmain.key.value;
		if (secKey == '')
		{
			alert('This is a secure service, please get a valid servicekey');
			return false;
		}
		else
		{
			sClientParams += "&servicekey=" + secKey;
		}
	}*/
	
	sClientParams += "&highlight=true";
	sClientParams += "&xcoord=" + xcoord + "&ycoord=" + ycoord;
	sClientParams += "&mapresolution=" + mapresolution;
	//sClientParams += "&" + param;

	// now start Flash
	startFlash(sClientParams);
}
