/*
** This file was created by Cuesta Systems Inc, May 2004
** It contains functions used on map load
** Created By: Monica Socol, Cuesta Systems
** On: June 04, 2004
*/

var xmlLayerListDoc;


/*
** A common xml loading funciton
** pre: fileName is fullpath to the xml you want to load
** post: returns a loaded XML upon success, NULL upon failure
*/
function loadXML(fileName){

	var cc = fileLoad.indexOf("\\")
	if (cc != -1)
	{
		var str = fileLoad.substr(0,cc);
		fileLoad = fileLoad.split("\\").join("\/");
		fileLoad = "file:///"+fileLoad;
	}
	var xmlDoc = null;
  if (window.ActiveXObject)
  { // If we're using an IE browser
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    var loaded = xmlDoc.load(fileLoad);
    if(loaded){
      return xmlDoc;
    } else {
      return null;
    }
  }
  else if (document.implementation && document.implementation.createDocument)
  { // code for Mozilla, Firefox, Opera, etc.
    xmlDoc=document.implementation.createDocument("","",null);
    var loaded = xmlDoc.load(fileLoad);
    xmlDoc.onload="";
    if(loaded){
      return xmlDoc;
    } else {
      return null;
    }
  }
  else
  {
    alert('Your browser does not meet the XML requirements of GeoPortal. Please use Internet Explorer version 5 or higher, or FireFox version 1.5 or higher.');
    return null;
  }
}

	function loadLayerListXML()
   {
		
  if (window.ActiveXObject)
		{
			strLayerListFile = "config/layerlist.xml";
			xmlLayerListDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlLayerListDoc.async=false;
			var bool = xmlLayerListDoc.load(strLayerListFile);
			if (bool == false)
			{
			   alert("Cuesta: The Layer List file is not valid for the application.\n        Please review the file!");
			   return;
			}
			if (xmlLayerListDoc.parseError.errorCode != 0)
			{
				  msg = 'Error loading data file.';
				  msg += '\nDescription: ' + xmlLayerListDoc.parseError.reason;
				  msg += '\nSource text: ' + xmlLayerListDoc.parseError.srcText;
				  msg += '\nLine: ' + xmlLayerListDoc.parseError.line ;
				  msg += '\nChar: ' + xmlLayerListDoc.parseError.linePos;

				  alert(msg);
			}
		}//end IE
		else
		{
				 xmlLayerListDoc = document.implementation.createDocument("", "", null);
				 xmlLayerListDoc.async=false;
				 xmlLayerListDoc.onload = createDisplay;
				 xmlLayerListDoc.load(strLayerListFile);
				 return;
		}
	}
/************************************************************************
** This function returns the directory path from an URL
** Created By: Monica Socol, June 22 2004
** Modified By: 
*/
function getPath(theFullPath) {
	var theSlash = theFullPath.lastIndexOf("/");
	var theDir = theFullPath.substring(0,theSlash);
	if (theDir==null) theDir="";
	theDir = theDir + "/";
	return theDir;
}
//************************************************************************

//************************************************************************
//** get window width		
//** Created By: Monica Socol, June 10 2004
//** Modified By: 
//*
function getWinWidth() {

    // var msg = "window.innerWidth = " + window.innerWidth + "\n";
    // msg += "document.documentElement.clientWidth = " + document.documentElement.clientWidth + "\n";
    // msg += "document.body.clientWidth = " + document.body.clientWidth;
    // alert(msg);

    return document.body.clientWidth;

}
//************************************************************************

//************************************************************************

function getWinHeight() {

	 return(document.body.clientHeight);

}


/***************************************************************************
** This function loads the layers arrays based on the map object properties 
** Created By: Monica Socol, June 2004
*/

function csy_initializeLayers(lId,lStatus, lLoaded, leg, legName, lMaxScale, lMinScale, cMaxScale, cMinScale, lExtent, lType, lOrder, cStatus, lConnType) 
{//AD June 2007, lLoaded no longer used. We are loading layer in legend, from new LayerOnLegend array.
	if (isReloaded)
	{ // re-load of map 	
		
		CurrentLayerOrder.length = 0;		
		
		for (var i=0; i<lId.length; i++)
		{
			CurrentLayerOrder[i] = "";//AD May 11, 2005 - intialize each index
			//in case LayerName.length>LayerOrderCurrentPHP.length
			LayerOrderCurrentPHP[i] = lOrder[i];
			for (var j=0; j<LayerID.length; j++)
			{	
									
				if (LayerOrderCurrentPHP[i] == LayerID[j])
				{
				  CurrentLayerOrder[i] = LayerName[j];			         
				}
				
				
				if (lId[i] == LayerID[j])
				{
					// test
					if(lId[i]=="Seismic Shotholes" && false){
						alert("Seismic Shotholes: LayerOnLegend: " + LayerOnLegend[j] + ", lLoaded: " + lLoaded[i] + ", lStatus: " + lStatus[i] )
					}
					LayerVisible[j] = lStatus[i];
					if (LayerisDynamic[j] == 1)
					{
						loadedLayers[j] = 1;
					}
					else	
					{
						// loadedLayers[j] = lLoaded[i]; //AD June 2007, added layeronlegend tag
						loadedLayers[j] = lStatus[i] || lLoaded[i];
					}

					if (leg[i] == "NOCLASSDEFINED") 
					{
						LayerLegendArray[j] = "";
						LayerLegendNameArray[j] = "";
					}
					else
					{
						LayerLegendArray[j] = leg[i];
						LayerLegendNameArray[j] = legName[i];
					}
						
					if (lMaxScale[i] < 0)
						LayerMaxScale[j] = 1.7976931348623157E308;
					else					
						LayerMaxScale[j] = lMaxScale[i];
					LayerMinScale[j] = lMinScale[i];
					
					if (cMaxScale[i] == "NOCLASSDEFINED") 
					{
						LayerClassMaxScale[j] = 1.7976931348623157E308;
						LayerClassMinScale[j] = -1;
						LayerClassStatus[j] = 1;						
					}
					else
					{
						var strMax = cMaxScale[i].split("#");
						if (strMax.length == 1)
						{
							if (cMaxScale[i] < 0)
								LayerClassMaxScale[j] = 1.7976931348623157E308;
							else
								LayerClassMaxScale[j] = cMaxScale[i];
						}
						else
							LayerClassMaxScale[j] = cMaxScale[i];
						LayerClassStatus[j] = cStatus[i];
						LayerClassMinScale[j] = cMinScale[i];	
					}
					//MS - March 11, 2005
					//to improve performance in reorder layers form
					//*****  BEGIN
					//j = LayerID.length;
					//*****  END		
				}
			}
		}
		 
		CurrentLayerOrder.reverse();
		 
	}
	else
	{		
		//initial number of layers
		mapLayersNumber = lId.length;
		//initialization of the arrays
		//alert("initialization")
		
		 
		CurrentLayerOrder.length = 0;
		 
		for (var i=0; i<lId.length; i++)
		{
			CurrentLayerOrder[i] = "";//AD May 11, 2005 - intialize each index
			//in case LayerName.length>LayerOrderCurrentPHP.length
			LayerOrderInitialPHP[i] = lId[i];
			LayerOrderCurrentPHP[i] = lId[i];
			for (var j=0; j<LayerID.length; j++)
			{
				 					
				if (LayerOrderCurrentPHP[i] == LayerID[j])
				{
				  CurrentLayerOrder[i] = LayerName[j];			         
				}
				 	
				
				if (lId[i] == LayerID[j])
				{
					LayerVisible[j] = lStatus[i];
					//loadedLayers[j] = lLoaded[i];
					loadedLayers[j] = LayerOnLegend[j];//AD June 2007
					LayerLegendArray[j] = leg[i];
					LayerLegendNameArray[j] = legName[i];

					if (lMaxScale[i] < 0)
						LayerMaxScale[j] = 1.7976931348623157E308;
					else					
						LayerMaxScale[j] = lMaxScale[i];
					LayerMinScale[j] = lMinScale[i];
					var strMax = cMaxScale[i].split("#");
					if (strMax.length == 1)
					{
						if (cMaxScale[i] < 0)
							LayerClassMaxScale[j] = 1.7976931348623157E308;
						else
							LayerClassMaxScale[j] = cMaxScale[i];
					}
					else
						LayerClassMaxScale[j] = cMaxScale[i];

					LayerClassMinScale[j] = cMinScale[i];
					LayerClassStatus[j] = cStatus[i];
					//AD Layer Extents
					LayerExtent[j] = lExtent[i];
					 
					LayerConnType[j] = lConnType[i];
					 				
					LayerType[j]=lType[i];				
					//if (lType[i].toLowerCase() == "misc")
					 
					if (lType[i].toLowerCase() == "point" || lType[i].toLowerCase() == "line" || lType[i].toLowerCase() == "polygon")
					{	//LayerIsFeature[j] = 0;
						LayerIsFeature[j] = 1;
					}
					else
					{	//LayerIsFeature[j] = 1;
						LayerIsFeature[j] = 0;
						
						//AD June 2007, for raster layer
						if (lType[i].toLowerCase() == "raster")
						{
							LayerisRaster[j] = 2;
							//LayerisRaster is set to 2, if originaly loaded from map file.
							//LayerisRaster is set to 1, if loaded dynamically as persistent layer.
						}
						//end AD June 2007
						
					}
					//dynamic data
					LayerisDynamic[j] = 0;
					LayerDataPath[j] = "";
					
					 	
				}//if are equal
			}
			 
		}
			//AD - April 1, 2005, reverse array here...
			CurrentLayerOrder.reverse();
		//SP 2008 	
		var strV ="";
		var strL ="";
		/*for (var i=0;i<t.LayerID.length; i++)
		{
			if ( t.LayerVisible[i] == 1 )
			{
				strV += t.LayerID[i] +"*"
			}
			if ( t.loadedLayers[i] == 1 )
			{
				strL += t.LayerID[i] +"*"
			}

		}*/
		for (var i=0;i<LayerID.length; i++)
		{
			if (LayerVisible[i] == 1 )
			{
				strV += LayerID[i] +"*"
			}
			if ( loadedLayers[i] == 1 )
			{
				strL += LayerID[i] +"*"
			}

		}

		strV = strV.substring(0,strV.length-1)
		strL = strL.substring(0,strL.length-1)
		
		sLyVisible = strV;
		sLyLoaded = strL;
			
	}	
	layerCount = LayerID.length;

}

function csy_loadToolsAssist(xDoc){
  loadProjXML(xDoc);
  loadEmailSettings(xDoc);
  loadSaveMapSettings(xDoc);
}
// Dennis Christopher March 14th 2006
// Initializes the value of MapServerParams.js mapProjection, mapProjectionName
// modified the name to csy_loadToolsXML by IM
// FF compatible, JH 2007
function csy_loadToolsXML()
{
	var xmlDoc;
	var fileLoad = "config/tools.xml";
  // code for Mozilla, Firefox, Opera, etc.  ... now IE as well?
  if (document.implementation && document.implementation.createDocument)
  {
    xmlDoc=document.implementation.createDocument("","",null);
    xmlDoc.async=false;
    xmlDoc.load(fileLoad);
    xmlDoc.onload=csy_loadToolsAssist(xmlDoc);

  } else if (window.ActiveXObject)
  {
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    var loaded = xmlDoc.load(fileLoad);
    if(!loaded){
      alert("Cuesta: The tools configuration file is not valid.\n Please contact the system administrator to report this problem.");
		self.close();
    }
    if (xmlDoc.parseError.errorCode != 0)
		{
		      msg = 'Error loading data file.';
		      msg += '\nDescription: ' + xmlDoc.parseError.reason;
		      msg += '\nSource text: ' + xmlDoc.parseError.srcText;
		      msg += '\nLine: ' + xmlDoc.parseError.line ;
		      msg += '\nChar: ' + xmlDoc.parseError.linePos;

		      alert(msg);
		}
    csy_loadToolsAssist(xmlDoc);
  } else {
    alert('Your browser does not meet the XML requirements of GeoPortal. Please use Internet Explorer version 5 or higher, or FireFox version 1.5 or higher.');
  }
}

function loadSaveMapSettings(xmlDoc)
{
		/*
		** modified for FF compliance, jh, 2007
		*/
		if(xmlDoc != null){
		 var a=xmlDoc.getElementsByTagName("Disclaimer");
     if(a.length > 0)
        strDisclaimer = a.item(0).childNodes[0].nodeValue;
     var b=xmlDoc.getElementsByTagName("FileSizeWarning");
     if(b.length > 0)
        strAllowedFileSize = b.item(0).childNodes[0].nodeValue;
  } else {
    alert("Received null xmlDocument. loadSaveMapSettings");
  }
}
	// IM on April 26, 2006 this is no longer needed
	// now we need to load the distributable layers
	/*loadLayerListXML();
	if (xmlLayerListDoc.documentElement.nodeName == "layergroups")
	{
		nodes = xmlLayerListDoc.documentElement.childNodes;
		if (nodes.length > 0)
		{ 
			var intDistLayerCnt = -1;
			for (var i=0; i<nodes.length; i++)
			{//for LayerGroup
				if (nodes.item(i).nodeName == "layergroup")
				{ 
					if (nodes.item(i).attributes.length>0)
					{
						// takes the layers
						strNode = nodes.item(i).childNodes;
						if (strNode.length > 0)
						{ // if - each Layer
							for ( var j=0; j<strNode.length; j++)
							{ // for each Layer
								var layerName = "";
								if (strNode.item(j).nodeName == "layer")
								{
									lNode = strNode.item(j).childNodes;
									// does isDistributable Node exists
									var blnIsDistExist = false;
									var DistNode = "";
									for ( var k=0; k<lNode.length; k++)
									{
										if (lNode.item(k).nodeName == "layerID")
										{	
											layerID = lNode.item(k).firstChild.nodeValue; 
										}
										if (lNode.item(k).nodeName == "isDistributable")
										{	
											blnIsDistExist = true;
											DistNode = lNode.item(k);
										}
									}//for inside layer
									//gets the name to be displayed
									if (strNode.item(j).attributes.length>0)	
										layerName = strNode.item(j).attributes.item(0).firstChild.nodeValue; 
									else	
										layerName = layerID; 
									if(blnIsDistExist == true)
									{
										if(DistNode.text == "true")
										{
											intDistLayerCnt++;
											DistributableLayers[intDistLayerCnt] = layerName;
										}
									}
								}
							} // for each Layer
						} // if - each Layer
					}//if 1
				} //if 0
			}//for LayerGroup
		}  //nodes>0; layer Group
	} 
	else 
	{
		alert("Cuesta: The selected file is not well formatted.\n      Please review the file!");
		self.close();
	}*/


// Dennis Christopher March 14th 2006
// Combined with loadProjectionsCC, JH Jan 2007
// initialize the MapServerParams.js projection variables
function loadProjXML(xmlDoc)
{
  var theProj = "";
  var theProjName = "";

  var projections=xmlDoc.getElementsByTagName("projection");

  for(i=0;i<projections.length;i++){
    var attlist=projections.item(i).attributes;
    var name = attlist.getNamedItem("name").value;
    var epsg = attlist.getNamedItem("epsg").value;
    var deflt = attlist.getNamedItem("default").value;
    var units = attlist.getNamedItem("units").value;

    if (deflt == "true")
         {
         		theProj = "init=epsg:"+epsg;
         		theProjName = name;
         		break;
         }
  }
  
  mapProjection = theProj;
  mapProjectionName = theProjName;
  //used to call loadProjectionsCC...not needed
}

function loadProjectionsCC(projNode)
{

    // combined with loadProjXML
  //  alert("Deprecated!! jh Jan 2007")
    
    /*
		var cNodes = projNode.childNodes;
		var theProj = "";
		var theProjName = "";

   	for (var i=0; i<cNodes.length; i++)
  	{
         var name = cNodes.item(i).getAttribute("name");
         var epsg = cNodes.item(i).getAttribute("epsg");
         var deflt = cNodes.item(i).getAttribute("default");
         var cmd = cNodes.item(i).getAttribute("cmd");
         
         if (deflt=="true")
         {
         		theProj = "init=epsg:"+epsg;
         		theProjName = name;
         		break;
         }
    }
    mapProjection = theProj;
    mapProjectionName = theProjName;
    */
}

/*
** Requires documentation
*/

function loadEmailSettings(xmlDoc)
{
	/*
	** Changed for FF compliance
	*/

  var a=xmlDoc.getElementsByTagName("UseEmail");
  if(a.length > 0)
    UseEmail = a.item(0).childNodes[0].nodeValue;
  var b=xmlDoc.getElementsByTagName("MailServer");
  if(b.length > 0)
    mailServer = b.item(0).childNodes[0].nodeValue;
  var c=xmlDoc.getElementsByTagName("FromEmailAddress");
  if(c.length > 0)
    fromEmailAddress = c.item(0).childNodes[0].nodeValue;
}


// Dennis Christopher March 10th 2006
/*function loadProjXML(xmlDoc)
{
		var projNode = xmlDoc.documentElement;
		var nodes = projNode.childNodes;
		var theProj = "";
		var theProjName = "None";

   	for (var i=0; i<nodes.length; i++)
  	{
         var name = nodes.item(i).getAttribute("name");
         var epsg = nodes.item(i).getAttribute("epsg");
         var deflt = nodes.item(i).getAttribute("default");
         var cmd = nodes.item(i).getAttribute("cmd");
         
         if (deflt=="true")
         {
         		theProj = cmd;
         		theProjName = name;
         		break;
         }
    }
    mapProjection = theProj;
    mapProjectionName = theProjName;
}*/

//*************************************************************************

//***********************************************************************
//* 	csy_loadLayersXML function
//* 	used to load the Layers Array from the config xml
//*
//*	Created by Monica Socol, Cuesta Systems, 2004
//*	Copyright Cuesta Systems, Ontario, Canada, 2004
//***********************************************************************
var xmlDoc;

function csy_loadLayersXML()
{
	//hua comment out on May 3,2006
	//if (!is5up)
	//{
	//	alert("The browser does not support XML!");
	//	return;
	//}
	//end of comment
	
	var fileLoad = "config/layerList.xml";
	//var str = "";

 if (window.ActiveXObject)
	{
		
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		
		var bool = xmlDoc.load(fileLoad);
		if (bool == false)
		{
		   alert("Cuesta: The LayerList file is not valid for the application.\n        Please review the file!");
		   self.close();
		}

		if (xmlDoc.parseError.errorCode != 0)
		{
		      msg = 'Error loading data file.';
		      msg += '\nDescription: ' + xmlDoc.parseError.reason;
		      msg += '\nSource text: ' + xmlDoc.parseError.srcText;
		      msg += '\nLine: ' + xmlDoc.parseError.line ;
		      msg += '\nChar: ' + xmlDoc.parseError.linePos;

		      alert(msg);
		}
		
		 loadLayersXML();
		 
	}
 else if (document.implementation && document.implementation.createDocument)
	{
			xmlDoc = document.implementation.createDocument("", "", null);
			xmlDoc.onload =  loadLayersXML;
      xmlDoc.load(fileLoad);
	} else {
    alert('Your browser does not meet the XML requirements of GeoPortal. Please use Internet Explorer version 5 or higher, or FireFox version 1.5 or higher.');
  }
	
}

function loadLayersXML()
{//modified by MS Oct 2004 to support joins	
	var featCount = -1;
	if (xmlDoc.documentElement.nodeName == "layergroups")
	{
		nodes = xmlDoc.documentElement.childNodes;
		if (nodes.length > 0)
		{   //layerGroup		
			for (var i=0; i<nodes.length; i++)
			{
				if (nodes.item(i).nodeName == "layergroup")
				{
					// takes the layers
					strNode = nodes.item(i).childNodes;
					for ( var j=0; j<strNode.length; j++)
					{								
						if (strNode.item(j).nodeName == "layer")
						{
							featCount++;
							
							//AD May 17, 2005, initialize all layer arrays
							LayerVisible[featCount]="";
							LayerMinScale[featCount]="";
							LayerMaxScale[featCount]="";
							LayerClassMinScale[featCount]="";
							LayerClassMaxScale[featCount]="";
							LayerClassStatus[featCount]="";
							LayerType[featCount]="";
							LayerLegendArray[featCount]="";
							LayerLegendNameArray[featCount]="";
							loadedLayers[featCount]="";
							KTCustomLayerString[featCount]="";
							KTCustomLabelString[featCount]="";
							KTDefaultLayerString[featCount]="";
							KTDefaultLabelString[featCount]="";
							KTCustomType[featCount]="";
							KTDefaultType[featCount]="";
							KTType[featCount]="";
							KTTypeDef[featCount]="";
							KTDataset[featCount]="";
							KTCustomized[featCount]=0;														
							KTSymbologyCustomized[featCount] = 0;//SP Jun 2006
							KTSymbologyCustomized[featCount] = 0;//SP Jun 2006
							
							
							LayerName[featCount]="";
							LayerID[featCount]="";
							LayerFieldList[featCount]="";
							LayerFieldAliasList[featCount]="";							
							LayerJNameList[featCount]="";
							LayerJTabList[featCount]=""; //AD Nov 19, 2004
							LayerJConnectionList[featCount]="";
							LayerJSourceFieldList[featCount]="";
							LayerJFieldList[featCount]="";
							LayerJFieldAliasList[featCount]="";
							LayerJClauseList[featCount]="";
							LayerJTargetFieldTypeList[featCount]="";
							//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
							LayerFieldTypeList[featCount]="";
							LayerConnectionName[featCount]="";
							LayerConnectionTable[featCount]="";
							LayerJTargetTableList[featCount]="";
							LayerJTargetFieldList[featCount]="";
							LayerJFieldTypeList[featCount]="";
							//AD May 27, 2005 - set new variables in MS GeoPortal 4.0
							LayerHyperLinkField[featCount]="";
							LayerHyperLinkPrefix[featCount]="";
							LayerHyperLinkSuffix[featCount]="";
							LayerJHyperLinkField[featCount]="";
							LayerJHyperLinkPrefix[featCount]="";
							LayerJHyperLinkSuffix[featCount]="";
							//AD June 6, 2005 - set new variables in MS GeoPortal 4.0, to get subjoin data
							LayerSJFieldList[featCount] = "";
							LayerSJFieldTypeList[featCount] = "";
							LayerSJFieldAliasList[featCount] = "";
							LayerSJHyperLinkField[featCount] = "";
							LayerSJHyperLinkPrefix[featCount] = "";
							LayerSJHyperLinkSuffix[featCount] = "";
							LayerJFieldList_FINAL[featCount] = "";
							LayerJFieldAliasList_FINAL[featCount] = "";
							LayerJFieldTypeList_FINAL[featCount] = "";
							LayerJHyperLinkField_FINAL[featCount]="";
							LayerJHyperLinkPrefix_FINAL[featCount]="";
							LayerJHyperLinkSuffix_FINAL[featCount]="";
							//end AD June 6, 2005
							LayerFieldWidthList[featCount] = ""; //SP Mar 2006
							LayerJSourceFieldTypeWidth[featCount] =""; //SP Mar 2006
							DistributableLayers[featCount] =0;//IM Apr 2006
							LayerOnLegend[featCount] = ""; //AD June 2007
							LayerFieldVisibleList[featCount] = ""; //AD June 2007
							LayerJFieldVisibleList[featCount] = ""; //AD June 2007
							LayerSJFieldVisibleList[featCount] = ""; //AD June 2007
							LayerisRaster[featCount] = 0; //AD June 2007
							//--------------------------------------------------------
							//LM March 28
							LayerIdentifyFields[featCount]="";
							LayerIdentifyFieldsHeader[featCount]="";
							//--------------------------------------------------------
							// takes the layer children
							lNode = strNode.item(j).childNodes;
							for ( var k=0; k<lNode.length; k++)
							{					
								if (lNode.item(k).nodeName == "layerID")
								{
									if(lNode.item(k).firstChild != null)
										LayerID[featCount] = lNode.item(k).firstChild.nodeValue;
								}
								if (lNode.item(k).nodeName == "selFields")
								{
									if(lNode.item(k).firstChild != null)
										LayerFieldList[featCount] = lNode.item(k).firstChild.nodeValue; 
								}
								//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
								if (lNode.item(k).nodeName == "selFieldsType")
								{
									if(lNode.item(k).firstChild != null)
										LayerFieldTypeList[featCount] = lNode.item(k).firstChild.nodeValue; 
								}						
								if (lNode.item(k).nodeName == "selFieldsAlias")			
								{
									if(lNode.item(k).firstChild != null)
										LayerFieldAliasList[featCount] = lNode.item(k).firstChild.nodeValue;
								}
								//AD May 27, 2005 - set new variables in MS GeoPortal 4.0
								if (lNode.item(k).nodeName == "hyperlinkFields")
								{
									if(lNode.item(k).firstChild != null)
										LayerHyperLinkField[featCount] = lNode.item(k).firstChild.nodeValue; 
								}
								if (lNode.item(k).nodeName == "hyperlinkFieldsPrefix")
								{
									if(lNode.item(k).firstChild != null)
										LayerHyperLinkPrefix[featCount] = lNode.item(k).firstChild.nodeValue; 
								}						
								if (lNode.item(k).nodeName == "hyperlinkFieldsSuffix")			
								{
									if(lNode.item(k).firstChild != null)
										LayerHyperLinkSuffix[featCount] = lNode.item(k).firstChild.nodeValue;
								}//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
								
								//SP Mar 2006 
								if (lNode.item(k).nodeName == "selFieldsWidth")
								{
									if(lNode.item(k).firstChild != null)
									{LayerFieldWidthList[featCount] = lNode.item(k).firstChild.nodeValue; }

								}
								//AD June 2007 
								if (lNode.item(k).nodeName == "layerOnLegend")
								{
									if(lNode.item(k).firstChild != null)
										LayerOnLegend[featCount] = lNode.item(k).firstChild.nodeValue;

								} 
								if (lNode.item(k).nodeName == "selFieldsVisible")
								{
									if(lNode.item(k).firstChild != null)
										LayerFieldVisibleList[featCount] = lNode.item(k).firstChild.nodeValue;

								}	
								//
								if (lNode.item(k).nodeName == "isDistributable")
								{	
									
									DistNode = lNode.item(k);
									if(DistNode.text == "true")																
										DistributableLayers[featCount] = 1;									
								}
								
								//---------------------------------------------
								//LM March 28
								if (lNode.item(k).nodeName == "identifyFields")
								{
									if(lNode.item(k).firstChild != null)
									LayerIdentifyFields[featCount] = lNode.item(k).firstChild.nodeValue; 
								}
								if (lNode.item(k).nodeName == "identifyHeaderField")
								{
									if(lNode.item(k).firstChild != null)
									LayerIdentifyFieldsHeader[featCount] = lNode.item(k).firstChild.nodeValue; 
								}
								//---------------------------------------------
								
								if (lNode.item(k).nodeName == "layerConnection")
								{
									if(lNode.item(k).firstChild != null)
										LayerConnectionName[featCount] = lNode.item(k).firstChild.nodeValue; 
								}
								//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
								if (lNode.item(k).nodeName == "layerConnectionTable")
								{
									if(lNode.item(k).firstChild != null)
										LayerConnectionTable[featCount] = lNode.item(k).firstChild.nodeValue; 
								}						
								if (lNode.item(k).nodeName == "joins")			
								{ //joins
									var jname = "";
									var jtab = ""; //AD Nov 19, 2004
									var jconn = "";									
									var jsourcefield = "";
									var jsourcefieldTW = ""; //SP Mar 2006
									var jtargetfieldtype="";
									var jfield = "";
									var jfieldalias = "";									
									var jcond = "";
									//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
									var jtargettable = "";
									var jtargerfield = "";
									var jfieldtype = "";
									//AD May 27, 2005 - set new variables in MS GeoPortal 4.0
									var jhyperfields = "";
									var jhyperprefix = "";
									var jhypersuffix = "";
									//AD June 6, 2005
									var jfield_final = "";
									var jfieldalias_final = "";
									var jfieldtype_final = "";
									var jhyperfields_final = "";
									var jhyperprefix_final = "";
									var jhypersuffix_final = "";
									//end AD June 6, 2005
									var jfieldvisible = "";//AD June 2007
									
																		
									joinNode = lNode.item(k).childNodes;																
									for ( var ct=0; ct<joinNode.length; ct++)
									{								
										if (joinNode.item(ct).nodeName == "join")
										{   
											//AD Nov 30, 2004 - re-initialize variables
											jname = "";
											jtab = "";
											jconn = "";									
											jsourcefield = "";
											jsourcefieldTW = ""; //SP MAr 2006
											jtargetfieldtype="";
											jfield = "";
											jfieldalias = "";									
											jcond = "";
											//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
											jtargettable = "";
											jtargerfield = "";
											jfieldtype = "";
											//AD May 27, 2005 - set new variables in MS GeoPortal 4.0
											jhyperfields = "";
											jhyperprefix = "";
											jhypersuffix = "";
											//AD June 6, 2005
											jfield_final = "";
											jfieldalias_final = "";
											jfieldtype_final = "";
											jhyperfields_final = "";
											jhyperprefix_final = "";
											jhypersuffix_final = "";
											//end AD June 6, 2005
											jfieldvisible = "";//AD June 2007
									
											if (joinNode.item(ct).attributes.length>0)								
											{	jname = joinNode.item(ct).attributes.item(0).nodeValue;	}
											else
											{	jname = ct + ","; }
											
											joinChildNode = joinNode.item(ct).childNodes;		
											for ( var crt=0; crt<joinChildNode.length; crt++)
											{		

												//AD Nov 19, 2004, addition of join tabs
												if (joinChildNode.item(crt).nodeName == "tabname")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jtab = joinChildNode.item(crt).firstChild.nodeValue;
												}												
												if (joinChildNode.item(crt).nodeName == "connection")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jconn = joinChildNode.item(crt).firstChild.nodeValue;
												}
												if (joinChildNode.item(crt).nodeName == "sourceField")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jsourcefield = joinChildNode.item(crt).firstChild.nodeValue;
												}
												//SP Mar 2006
												if (joinChildNode.item(crt).nodeName == "sourceFieldTypeWidth")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jsourcefieldTW = joinChildNode.item(crt).firstChild.nodeValue;
												}
												//SPMar
												if (joinChildNode.item(crt).nodeName == "targetFieldType")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jtargetfieldtype = joinChildNode.item(crt).firstChild.nodeValue;
												}			
												//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
												if (joinChildNode.item(crt).nodeName == "targetTableName")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jtargettable = joinChildNode.item(crt).firstChild.nodeValue;
												}			
												//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
												if (joinChildNode.item(crt).nodeName == "targetFieldName")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jtargetfield = joinChildNode.item(crt).firstChild.nodeValue;
												}												
												if (joinChildNode.item(crt).nodeName == "joinSelFields")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jfield = joinChildNode.item(crt).firstChild.nodeValue;																											
												}			
												//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
												if (joinChildNode.item(crt).nodeName == "joinSelFieldsType")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jfieldtype = joinChildNode.item(crt).firstChild.nodeValue;
												}												
												if (joinChildNode.item(crt).nodeName == "joinSelFieldsAlias")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jfieldalias = joinChildNode.item(crt).firstChild.nodeValue;
												}
												
												//AD June 2007
												if (joinChildNode.item(crt).nodeName == "joinSelFieldsVisible")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jfieldvisible = joinChildNode.item(crt).firstChild.nodeValue;
												}
												//
												
												//AD May 27, 2005 - set new variables in MS GeoPortal 4.0
												if (joinChildNode.item(crt).nodeName == "hyperlinkFields")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jhyperfields = joinChildNode.item(crt).firstChild.nodeValue;
												}												
												if (joinChildNode.item(crt).nodeName == "hyperlinkFieldsPrefix")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jhyperprefix = joinChildNode.item(crt).firstChild.nodeValue;
												}												
												if (joinChildNode.item(crt).nodeName == "hyperlinkFieldsSuffix")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jhypersuffix = joinChildNode.item(crt).firstChild.nodeValue;
												}
												if (joinChildNode.item(crt).nodeName == "sqlStatement")			
												{
													if(joinChildNode.item(crt).firstChild != null)
														jcond = joinChildNode.item(crt).firstChild.nodeValue;
												}

												//AD June 6, 2005 - set new variables in MS GeoPortal 4.0, to get subjoin data
												if (joinChildNode.item(crt).nodeName == "subjoins")
												{
													var subjfield = "";
													var subjfieldtype = "";
													var subjfieldalias = "";
													var subjhyperfield = "";
													var subjhyperprefix = "";
													var subjhypersuffix = "";
													var subjfieldvisible = "";//AD June 2007

													subjoinNode = joinChildNode.item(crt).childNodes;
													for ( var sct=0; sct<subjoinNode.length; sct++)
													{
														if (subjoinNode.item(sct).nodeName == "subjoin")
														{	
															subjoinChildNode = subjoinNode.item(sct).childNodes;
															for ( var scrt=0; scrt<subjoinChildNode.length; scrt++)
															{
																if (subjoinChildNode.item(scrt).nodeName == "subjoinSelFields")
																{
																	if(subjoinChildNode.item(scrt).firstChild != null)
																		subjfield += subjoinChildNode.item(scrt).firstChild.nodeValue;
																	subjfield += "^";
																}
																if (subjoinChildNode.item(scrt).nodeName == "subjoinSelFieldsType")
																{
																	if(subjoinChildNode.item(scrt).firstChild != null)
																		subjfieldtype += subjoinChildNode.item(scrt).firstChild.nodeValue;
																	 subjfieldtype += "^";
																}
																if (subjoinChildNode.item(scrt).nodeName == "subjoinSelFieldsAlias")
																{
																	if(subjoinChildNode.item(scrt).firstChild != null)
																		subjfieldalias += subjoinChildNode.item(scrt).firstChild.nodeValue;
																	subjfieldalias += "^";
																}
																if (subjoinChildNode.item(scrt).nodeName == "hyperlinkFields")
																{
																	if(subjoinChildNode.item(scrt).firstChild != null)
																		subjhyperfield += subjoinChildNode.item(scrt).firstChild.nodeValue;
																	subjhyperfield += "^";
																}
																if (subjoinChildNode.item(scrt).nodeName == "hyperlinkFieldsPrefix")
																{
																	if(subjoinChildNode.item(scrt).firstChild != null)
																		subjhyperprefix += subjoinChildNode.item(scrt).firstChild.nodeValue;
																	 subjhyperprefix += "^";
																}
																if (subjoinChildNode.item(scrt).nodeName == "hyperlinkFieldsSuffix")
																{
																	if(subjoinChildNode.item(scrt).firstChild != null)
																		subjhypersuffix += subjoinChildNode.item(scrt).firstChild.nodeValue;
																	subjhypersuffix += "^";
																}
																//AD June 2007
																if (subjoinChildNode.item(scrt).nodeName == "subjoinSelFieldsVisible")
																{
																	if(subjoinChildNode.item(scrt).firstChild != null)
																		subjfieldvisible += subjoinChildNode.item(scrt).firstChild.nodeValue;
																	subjfieldvisible += "^";
																}
																//
															}//for subjoinChild
														}//if
													}//for subjoin
													subjfield = subjfield.substring(0, subjfield.length -1 );
													subjfieldtype = subjfieldtype.substring(0, subjfieldtype.length - 1);
													subjfieldalias = subjfieldalias.substring(0,subjfieldalias.length - 1);
													subjhyperfield = subjhyperfield.substring(0,subjhyperfield.length - 1);
													subjhyperprefix = subjhyperprefix.substring(0,subjhyperprefix.length - 1);
													subjhypersuffix = subjhypersuffix.substring(0,subjhypersuffix.length - 1);
													subjfieldvisible = subjfieldvisible.substring(0,subjfieldvisible.length - 1);//AD June 2007
												}//if subjoins	
												//end AD June 6, 2005
												
											}//for joinChild
											LayerJNameList[featCount] += jname + "~";
											LayerJTabList[featCount] += jtab + "~";//AD Nov 19, 2004
											LayerJConnectionList[featCount] += jconn + "~";										
											LayerJSourceFieldList[featCount] += jsourcefield + ",";
											//SP mar 2006
											LayerJSourceFieldTypeWidth[featCount] +=jsourcefieldTW + ",";
											//SP
											LayerJTargetFieldTypeList[featCount] += jtargetfieldtype + "~";
											LayerJFieldList[featCount] += jfield + "~";											
											LayerJFieldAliasList[featCount] += jfieldalias + ",";
											LayerJClauseList[featCount] += jcond + "~";
											//AD Mar 11, 2005 - set new variables in MS GeoPortal 4.0
											LayerJTargetTableList[featCount] += jtargettable + "~";
											LayerJTargetFieldList[featCount] += jtargetfield + "~";
											LayerJFieldTypeList[featCount] += jfieldtype + "~";
											//AD May 27, 2005 - set new variables in MS GeoPortal 4.0
											LayerJHyperLinkField[featCount] += jhyperfields + "~";
											LayerJHyperLinkPrefix[featCount] += jhyperprefix + "~";
											LayerJHyperLinkSuffix[featCount] += jhypersuffix + "~";
																						
											LayerJFieldVisibleList[featCount] += jfieldvisible + "~";//AD June 2007
											
							
											//AD Nov 23, 2004, force all join fields in LayerFieldList array
											var tmpStr = LayerFieldList[featCount];
											if (tmpStr.indexOf(jsourcefield) == -1)
												LayerFieldList[featCount] = jsourcefield + "," + tmpStr;
												
											//AD June 6, 2005 - set new variables in MS GeoPortal 4.0, to get subjoin data
											LayerSJFieldList[featCount] += subjfield + "~";
											LayerSJFieldTypeList[featCount] += subjfieldtype + "~";
											LayerSJFieldAliasList[featCount] += subjfieldalias + "~";
											LayerSJHyperLinkField[featCount] += subjhyperfield + "~";
											LayerSJHyperLinkPrefix[featCount] += subjhyperprefix + "~";
											LayerSJHyperLinkSuffix[featCount] += subjhypersuffix + "~";
											LayerSJFieldVisibleList[featCount] += subjfieldvisible + "~";//AD June 2007
						
											jfield_final = jfield +","+subjfield.replace(/\^/g,",");
											var tmp=jfield_final.split(",");
											for ( var num=0; num<tmp.length; num++)
											{	if (Trim(tmp[num]).length>0){
													LayerJFieldList_FINAL[featCount]+=tmp[num]+",";
												}
													
											}
											if (LayerJFieldList_FINAL[featCount].length>0 && LayerJFieldList_FINAL[featCount].charAt(LayerJFieldList_FINAL[featCount].length-1)==",")
												LayerJFieldList_FINAL[featCount] = LayerJFieldList_FINAL[featCount].substring(0,LayerJFieldList_FINAL[featCount].length-1);
											LayerJFieldList_FINAL[featCount] += "~";
											
											jfieldalias_final = jfieldalias +","+subjfieldalias.replace(/\^/g,",");
											var tmp=jfieldalias_final.split(",");
											for ( var num=0; num<tmp.length; num++)
											{	if (Trim(tmp[num]).length>0){
													LayerJFieldAliasList_FINAL[featCount]+=tmp[num]+",";
												}
													
											}
											if (LayerJFieldAliasList_FINAL[featCount].length>0 && LayerJFieldAliasList_FINAL[featCount].charAt(LayerJFieldAliasList_FINAL[featCount].length-1)==",")
												LayerJFieldAliasList_FINAL[featCount] = LayerJFieldAliasList_FINAL[featCount].substring(0,LayerJFieldAliasList_FINAL[featCount].length-1);
											LayerJFieldAliasList_FINAL[featCount] += ",";

											jfieldtype_final = jfieldtype +","+subjfieldtype.replace(/\^/g,",");
											var tmp=jfieldtype_final.split(",");
											for ( var num=0; num<tmp.length; num++)
											{	if (Trim(tmp[num]).length>0){
													LayerJFieldTypeList_FINAL[featCount]+=tmp[num]+",";
												}
													
											}
											if (LayerJFieldTypeList_FINAL[featCount].length>0 && LayerJFieldTypeList_FINAL[featCount].charAt(LayerJFieldTypeList_FINAL[featCount].length-1)==",")
												LayerJFieldTypeList_FINAL[featCount] = LayerJFieldTypeList_FINAL[featCount].substring(0,LayerJFieldTypeList_FINAL[featCount].length-1);
											LayerJFieldTypeList_FINAL[featCount] += "~";
											
											jhyperfields_final = jhyperfields +","+subjhyperfield.replace(/\^/g,",");
											var tmp=jhyperfields_final.split(",");
											for ( var num=0; num<tmp.length; num++)
											{	if (Trim(tmp[num]).length>0){
													LayerJHyperLinkField_FINAL[featCount]+=tmp[num]+",";
												}
													
											}
											if (LayerJHyperLinkField_FINAL[featCount].length>0 && LayerJHyperLinkField_FINAL[featCount].charAt(LayerJHyperLinkField_FINAL[featCount].length-1)==",")
												LayerJHyperLinkField_FINAL[featCount] = LayerJHyperLinkField_FINAL[featCount].substring(0,LayerJHyperLinkField_FINAL[featCount].length-1);
											LayerJHyperLinkField_FINAL[featCount] += "~";
											
											jhyperprefix_final = jhyperprefix +","+subjhyperprefix.replace(/\^/g,",");
											var tmp=jhyperprefix_final.split(",");
											for ( var num=0; num<tmp.length; num++)
											{	if (Trim(tmp[num]).length>0){
													LayerJHyperLinkPrefix_FINAL[featCount]+=tmp[num]+",";
												}
													
											}
											if (LayerJHyperLinkPrefix_FINAL[featCount].length>0 && LayerJHyperLinkPrefix_FINAL[featCount].charAt(LayerJHyperLinkPrefix_FINAL[featCount].length-1)==",")
												LayerJHyperLinkPrefix_FINAL[featCount] = LayerJHyperLinkPrefix_FINAL[featCount].substring(0,LayerJHyperLinkPrefix_FINAL[featCount].length-1);
											LayerJHyperLinkPrefix_FINAL[featCount] += "~";

											jhypersuffix_final = jhypersuffix +","+subjhypersuffix.replace(/\^/g,",");
											var tmp=jhypersuffix_final.split(",");
											for ( var num=0; num<tmp.length; num++)
											{	if (Trim(tmp[num]).length>0){
													LayerJHyperLinkSuffix_FINAL[featCount]+=tmp[num]+",";
												}
													
											}
											if (LayerJHyperLinkSuffix_FINAL[featCount].length>0 && LayerJHyperLinkSuffix_FINAL[featCount].charAt(LayerJHyperLinkSuffix_FINAL[featCount].length-1)==",")
												LayerJHyperLinkSuffix_FINAL[featCount] = LayerJHyperLinkSuffix_FINAL[featCount].substring(0,LayerJHyperLinkSuffix_FINAL[featCount].length-1);
											LayerJHyperLinkSuffix_FINAL[featCount] += "~";
											//end AD June 6, 2005
											
										}//if join
									}//for join										
									LayerJNameList[featCount] = LayerJNameList[featCount].substring(0,LayerJNameList[featCount].length - 1);							
									LayerJTabList[featCount] = LayerJTabList[featCount].substring(0,LayerJTabList[featCount].length - 1); //AD Nov 19, 2004
									LayerJConnectionList[featCount] = LayerJConnectionList[featCount].substring(0,LayerJConnectionList[featCount].length - 1);
									LayerJSourceFieldList[featCount] = LayerJSourceFieldList[featCount].substring(0,LayerJSourceFieldList[featCount].length - 1);
									//SP mar 2006
									LayerJSourceFieldTypeWidth[featCount] = LayerJSourceFieldTypeWidth[featCount].substring(0,LayerJSourceFieldTypeWidth[featCount].length - 1);
									//Sp mar 2006									
									LayerJTargetFieldTypeList[featCount] = LayerJTargetFieldTypeList[featCount].substring(0,LayerJTargetFieldTypeList[featCount].length - 1);
									LayerJFieldList[featCount] = LayerJFieldList[featCount].substring(0, LayerJFieldList[featCount].length -1 );
									LayerJFieldAliasList[featCount] = LayerJFieldAliasList[featCount].substring(0, LayerJFieldAliasList[featCount].length - 1);
									LayerJClauseList[featCount] = LayerJClauseList[featCount].substring(0,LayerJClauseList[featCount].length - 1);									
									LayerJTargetTableList[featCount] = LayerJTargetTableList[featCount].substring(0, LayerJTargetTableList[featCount].length -1 );
									LayerJTargetFieldList[featCount] = LayerJTargetFieldList[featCount].substring(0, LayerJTargetFieldList[featCount].length - 1);
									LayerJFieldTypeList[featCount] = LayerJFieldTypeList[featCount].substring(0,LayerJFieldTypeList[featCount].length - 1);
									//AD May 27, 2005 - set new variables in MS GeoPortal 4.0
									LayerJHyperLinkField[featCount] = LayerJHyperLinkField[featCount].substring(0, LayerJHyperLinkField[featCount].length -1 );
									LayerJHyperLinkPrefix[featCount] = LayerJHyperLinkPrefix[featCount].substring(0, LayerJHyperLinkPrefix[featCount].length - 1);
									LayerJHyperLinkSuffix[featCount] = LayerJHyperLinkSuffix[featCount].substring(0,LayerJHyperLinkSuffix[featCount].length - 1);
									//AD June 6, 2005 - set new variables in MS GeoPortal 4.0, to get subjoin data
									LayerSJFieldList[featCount] = LayerSJFieldList[featCount].substring(0, LayerSJFieldList[featCount].length -1 );
									LayerSJFieldTypeList[featCount] = LayerSJFieldTypeList[featCount].substring(0, LayerSJFieldTypeList[featCount].length - 1);
									LayerSJFieldAliasList[featCount] = LayerSJFieldAliasList[featCount].substring(0,LayerSJFieldAliasList[featCount].length - 1);
									LayerSJHyperLinkField[featCount] = LayerSJHyperLinkField[featCount].substring(0, LayerSJHyperLinkField[featCount].length -1 );
									LayerSJHyperLinkPrefix[featCount] = LayerSJHyperLinkPrefix[featCount].substring(0, LayerSJHyperLinkPrefix[featCount].length - 1);
									LayerSJHyperLinkSuffix[featCount] = LayerSJHyperLinkSuffix[featCount].substring(0,LayerSJHyperLinkSuffix[featCount].length - 1);									
									LayerJFieldList_FINAL[featCount] = LayerJFieldList_FINAL[featCount].substring(0, LayerJFieldList_FINAL[featCount].length -1 );
									LayerJFieldAliasList_FINAL[featCount] = LayerJFieldAliasList_FINAL[featCount].substring(0, LayerJFieldAliasList_FINAL[featCount].length -1 );
									LayerJFieldTypeList_FINAL[featCount] = LayerJFieldTypeList_FINAL[featCount].substring(0, LayerJFieldTypeList_FINAL[featCount].length -1 );
									LayerJHyperLinkField_FINAL[featCount] = LayerJHyperLinkField_FINAL[featCount].substring(0, LayerJHyperLinkField_FINAL[featCount].length -1 );
									LayerJHyperLinkPrefix_FINAL[featCount] = LayerJHyperLinkPrefix_FINAL[featCount].substring(0, LayerJHyperLinkPrefix_FINAL[featCount].length -1 );
									LayerJHyperLinkSuffix_FINAL[featCount] = LayerJHyperLinkSuffix_FINAL[featCount].substring(0, LayerJHyperLinkSuffix_FINAL[featCount].length -1 );
									//end AD June 6, 2005
									
									//AD June 2007
									LayerJFieldVisibleList[featCount] = LayerJFieldVisibleList[featCount].substring(0, LayerJFieldVisibleList[featCount].length -1 );
									LayerSJFieldVisibleList[featCount] = LayerSJFieldVisibleList[featCount].substring(0, LayerSJFieldVisibleList[featCount].length -1 );
									//
								}				
							}//for inside layer
							
							LayerName[featCount] = LayerID[featCount]; 							
							
						}//if node = layer
					}//for j
				}// if node = layergroup
			}//for i			
		}  //nodes>0
	} else {
	   alert("Cuesta: The selected file is not well formatted.\n      Please review the file!");
	}
	layerCount = LayerName.length;
//alert(LayerFieldVisibleList+"********"+LayerJFieldVisibleList);
	//MS Oct 2004
}



/********************************************************************************
** This function sets the initial size for the map, depending on the frame size 
** Created By: Monica Socol, June 2004
** Modified By: 
*/
function csy_initializeApp()
{		
	//MS: gets the internal window's width and height
	//and creates the map size depending on them
	var iWidth = getWinWidth();
	var iHeight = getWinHeight();
		
	mapWidth = iWidth - 36;
	mapHeight = iHeight - 36;
	//alert(mapWidth + "-" + mapHeight);	
}
//***************************************************************************

/********************************************************************************
** This function sets the selection query variables, to store shape results, 
** for add selection option.
** Created By: Aida Dodo, August 2004
** Modified By: AD June 17, 2005, to set hasQueryResults variable.
//hasQueryResults="true" if selection result founds, and layer fields defined
//hasQueryResults="1": No fields defined for this layer
//hasQueryResults="0": otherwise
*/
function csy_setqryShpResults(str)
{
	if (str != "0") {
		qryResults = str;
		var arrTemp = str.split("|");
		
		sqryShpResults = arrTemp[2];
		sqryLayerName = ActiveLayerID;
		hasQueryResults="true";//AD June 16, 2005
		//alert(sqryShpResults);
		//alert(sqryLayerName);
	}
	else
	{
		qryResults = "";
		sqryShpResults = "";
		sqryLayerName = "";
		
		//AD June 16, 2005
		if ( str.substring(0,3) == "-1|") hasQueryResults="1";
		else hasQueryResults="0";
		//end AD June 16, 2005
	}
}
//***************************************************************************

/********************************************************************************
** This function sets the initialize sqryNotificationResults variables, to store query results, 
** for Notification.
** Created By: Aida Dodo, Sept 2004
** Modified By: 
*/
function csy_setqryNotificationResults(str)
{
	//if (str != "0") {
	if (Trim(str).length>0 && str != "0") {//AD June 17, 2005 - check for not null string
		var arrTemp = str.split("|");
		qryNotificationResults = arrTemp[1].split("*");
		//alert(qryNotificationResults);
	}
	else
	{
		qryNotificationResults = "";
	}
}
//***************************************************************************

/********************************************************************************
** This function sets the bufferShapeIndexes variables, to store buffered shapes
** for buffer tool.
** Created By: Monica Socol, August 2004
** Modified By: Silvia Petcu Apr 2006
*/
function csy_setbufferShapeIndexes(str)
{
	if (str != "")
		if (str != "-1")
			bufferShapeIndexes = str;	
		else
		{
			if(bufferDistance != "0")
				alert("No features from " + bufferTargetLayer+" layer within "+bufferDistance+" "+ScaleBarUnits+" from the selected features!");
			else
				alert("No features found from " + bufferTargetLayer+" layer!");
		}
	else
		bufferShapeIndexes = "";
	sqryBufferSel = str;//SP Apr 2006
	
}

// added by IM on April 18, 2006
// this function will be called from csy.php after the extract is done to pass in a zip file size
function csy_saveFileSize(str)
{
	strExportFileSize = str;
}

//***************************************************************************


/****************************************************************************
** This function sets the layer Field Type in LayerFieldType array, 
** Created By: Aida Dodo, August 23 2004
** Modified By: Aida Dodo Aug 30, 2004, to added initialization of LayerDataSet
** Modified By: Monica Socol Sept 1, 2004, to handle dynamic layers (get all field names for the dynamic layers)
** Modified By: Aida Dodo Mar 12, 2005, updates for MS GeoPortal 4.0
**	- removed initialization of LayerFieldType array, no longer used.
**	- set of Layer DataSets, split into csy_initializeLayerData() function.
**	- added new parameters: theLayerID, theLayerIndex.
**	- added initialization of LayerFieldTypeList array.
*/
function csy_initializeFieldTypes(lyrFieldType,theLayerID, theLayerIndex) 
{	
	var j = theLayerIndex;
	if (!(j>=0 && j<layerCount))
	{
		for(i = 0;i<layerCount;i++)
		{
			if (theLayerID == LayerName[i])
			{
				var j = i;
				i = layerCount;
			}
		}
	}

	var tmp = lyrFieldType.split(',');		
	var selF = "";
	var selFA = ""
	for (var k=0; k<tmp.length; k++)
	{
		var st = tmp[k].split(':');
		selF += st[0] + ",";
		selFA += st[0] + ":" + st[0] + ",";
	}
	selF = selF.substr(0,selF.length -1);
	selFA = selFA.substr(0,selFA.length -1);
	LayerFieldTypeList[j] = lyrFieldType;//AD Mar 12, 2005, new array in Ms GeoPortal4.0
	
	if (LayerisDynamic[j] == 1)
	{
		LayerFieldList[j] = selF;
		LayerFieldAliasList[j] = selFA;		
	}
	if (LayerisPersist[j] == 1) 
	{
		LayerFieldList[j] = selF;
		//LayerFieldAliasList[j] = selFA;		
	}
	
	
}
//***************************************************************************

/****************************************************************************
** This function sets the layer Data Sets for all layers. Was initially included in
** csy_initializeFieldTypes() function.
** Created By: Aida Dodo, March 12 2005
** Modified By: 
**
*/
function csy_initializeLayerData(lyrValues) {
	for (var i=0;i< lyrValues.length;i++) {
		// modified by IM on June 7, 2006
		// used star (*) char to separate layer properties... a fix for the case where layer names have commas (,)
		var lyrData = lyrValues[i].split('*');
		var lyrID = lyrData[0];
		var lyrFieldType = lyrData[1];
		var lyrMetaData = lyrData[2];
		//get layer index in LayerName array order
		for (var j=0;j< LayerID.length;j++) {
			if (LayerID[j] == lyrID) {
				LayerDataSet[j] = lyrMetaData;
				j = LayerID.length;
				
				//AD Mar 12, 2005, added for Ms GeoPortal4.0
				//for DGN layer, field list is hardcoded
				if (lyrFieldType.length>0)
				{
					csy_initializeFieldTypes(lyrFieldType,lyrID,j);
				}
				break; //SP MAr 2007
			}
		}
		
	}
}
//***************************************************************************

/****************************************************************************
** This function sets the initialize the Street Name 2 pull down for the street intersection, 
** Created By: Aida Dodo, Sept 17, 2004
** Modified By: Aida Dodo, Oct 13, 2004 for browser compatibility
** - Used getElementById to get field.
** - Browser check implemented for using StreetName2_OnChange()/StreetName2_OnChangeNET() function
*/
/*AD May 3, 2005, FUNCTION NO LONGER USED
function csy_processStreetIntersect(rsp) {
//var txtForm = top.TextFrame.document.all;
var txtForm = top.TextFrame.document;
	res = "";
	var values = rsp.sort();
	if (isNav) {
		res += "<Select id='StreetName2' name='StreetName2' onchange='StreetName2_OnChangeNET()' style='FONT: 8pt Times Roman;' >";
	}
	else
	{
		res += "<Select id='StreetName2' name='StreetName2' onchange='StreetName2_OnChange()' style='FONT: 8pt Times Roman;' >";		
	}
	res += "<option selected value=''>";
		lastVal = "";
		for (var i=0;i<values.length;i++)
		{
			if (values[i].length>0){
				if (values[i] != lastVal)
				{
					res += "<option value='" + values[i] + "'>" + values[i] + "</option>";
				}
				lastVal = values[i];
			}
		}
	res += "</SELECT><br>";
	//SelectName2Str = res;
	//txtForm.StreetName2.innerHTML = res;
	setTimeout('setStreetName2()',2000); //AD Jan 4, 2005 - added to wait for end of jsForm submission
	//txtForm.getElementById("StreetName2").innerHTML = res; //AD Jan 4, 2005 commented

}
/*FUNCTION NO LONGER USED
function setStreetName2() {
	var txtForm = top.TextFrame.document;
	txtForm.getElementById("StreetName2").innerHTML = res;
}
*/
//***************************************************************************

//***************************************************************************
//* 	initVar function
//* 	used in toolbar to clear some of the variables
//*
//*	Created by Aida Dodo, Cuesta Systems, 2004
//*	Copyright Cuesta Systems, Ontario, Canada, 2004
//***************************************************************************
function initVar()
{
//initialize variables here...
	useNotification = false;
	useStandardReport = false; //AD Apr 26, 2005, added new variable.
	annotationAction="";//AD July 27, 2005, reset new variable.
	// added by IM on Feb 27, 2006
	// need to reset this variable
	t.arrTempCheckedLayers = new Array();
}
//****************************************************************************

//***************************************************************************
//* 	csy_saveNotificationResults function
//* 	used to save Query Results for Property Layer
//*
//*	Created by Aida Dodo, Cuesta Systems, 2004
//***************************************************************************
function csy_saveNotificationResults(strValues)
{ //we only want to save the OBJECTID values
	var tmp = strValues.split("|");
	PropertySelectedFeatures = tmp[1].split("*");
	//alert(PropertySelectedFeatures);
}
//***************************************************************************
//***************************************************************************
//* 	csy_setNonConnected function
//* 	used to update the array of layers that MapServer could not draw()
//*
//*	Created by Silvia Petcu DPRA 2006
//***************************************************************************

function csy_setNonConnected(strBrowkenLyr)
{  
	 flagISBroken=0;
	
	var arrBrowkenLayer=strBrowkenLyr.split("~");
	for(var j = 0; j<arrBrowkenLayer.length; j++)
	{
		for (var i = 0; i<LayerID.length; i++)
		{
			if(arrBrowkenLayer[j].toUpperCase() == LayerID[i].toUpperCase())
			{
			
				LayerNotConnectedList[i] = 1;
				flagISBroken=1;
			}
		}
	}

}
//***************************************************************************
//* 	csy_isNonConnected function
//* 	used to check if the layer is part of the NonConnected layer list 
//*
//*	 DPRA 2006
//***************************************************************************

function csy_isConnected(lN)
{  
	var returnval = true;	
	
	for (var i = 0; i<LayerID.length; i++)
	{		
		if(lN == LayerID[i])
		{
		     if(LayerNotConnectedList[i] == 1)
		     {
		    	returnval = false;
		    	
		     }
		     break;
		}
	}
	
	return returnval
}
//***************************************************************************
//Used to test connection for layers//* SP Feb 2007

function GetBrowkenConnList(strConnection)
{
  var strReturn="";
  var oXMLHTTP = null;
  if(window.ActiveXObject) oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
  if(window.XMLHttpRequest) oXMLHTTP = new XMLHttpRequest();
	var sURL =  t.cuestaJspURL+"getFailedConnection.jsp" ;
	

	oXMLHTTP.open( "POST", sURL, false );
	oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	oXMLHTTP.send("connection="+strConnection);
//alert(strConnection)
	strReturn = oXMLHTTP.responseText;
	strReturn=t.Trim(strReturn)
//alert(strReturn);
	if(strReturn.length > 0)
	{	
		strReturn = strReturn.replace(/&nbsp/g," ");
		strReturn = strReturn.replace(/~/g,"\|");
	}
	else
		strReturn = "";		
	oXMLHTTP = null;
	arrReturn= new Array();
	if( strReturn.substring(0,5).toUpperCase()=="ERROR") strReturn="";	
	
	return strReturn
}
//***************************************************************************

function GetBrowkenLyrList()
{
	var strReturn="";
	var oXMLHTTP = null;
	if(window.ActiveXObject) oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
	if(window.XMLHttpRequest) oXMLHTTP = new XMLHttpRequest();
	var sURL = t.cuestaJspURL+"GetBadMapLayer.php" ;

	oXMLHTTP.open( "GET", sURL, false );
	//oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXMLHTTP.send(null);
	strReturn = oXMLHTTP.responseText;
	strReturn= ""+Trim(strReturn);
	
	oXMLHTTP = null;

	return strReturn
}


function csy_GetFailedConnList()
{
var brokenLyr="";
/*
//For this to work , be sure that the connection information used in mapfile are identical with connection information in layerlist.xml 
var connType ="";
var connUser ="";
var connPassword ="";
var connDriver = "";
var connLayer= "";
var connTable= "";
var conn = "";

for (var i=0;i<t.LayerID.length;i++)
{
	 connType = t.getXMLValue("config/connections.xml","type", t.LayerConnectionName[i]);
	 connUser = t.getXMLValue("config/connections.xml","user", t.LayerConnectionName[i]);
	 connPassword = t.getXMLValue("config/connections.xml","password", t.LayerConnectionName[i]);
	 connDriver = t.getXMLValue("config/connections.xml","driver", t.LayerConnectionName[i]);
	 connLayer =t.LayerID[i] ;
	 connTable = t.LayerConnectionTable[i];
	if(connType.toUpperCase()!="WMS") //bad connection for wms layers don't stop the site from working properly.
	{
		if(conn!="")
			conn += "!"+ connType +"~"+ connUser + "~" + connPassword + "~"+connDriver+ "~" + connLayer + "~" + connTable;
		else
			conn = connType  +"~"+ connUser + "~" + connPassword + "~"+connDriver+ "~" + connLayer + "~" + connTable;;
	}
}//for
brokenLyr=GetBrowkenConnList(conn);
*/
brokenLyr = GetBrowkenLyrList();
return brokenLyr;
 }
