var listOfWindows = new Array();


// Object to represent an element in the pop-up window stack
function popupStackEntry(theWindow, callingWindow ){
  this.theWindow = theWindow;
  this.callingWindow = callingWindow;
}

//********************************************
// Get the first open window on our stack
// Return NULL if no such window exists
// Does not modify the state of listOfWindows
//********************************************
function getTopWindow(){

  var oWnd = null;
  while(true){
  
     // get the next window on the stack
     oWnd = listOfWindows.pop();
     
     // If we have a valid window
     if(oWnd && !oWnd.theWindow.closed){
        listOfWindows.push(oWnd);
        return oWnd;
     }
     // If we're out of windows
     if(listOfWindows.length == 0)
      return null;
  }
}

// need a function that would determin the metadata file name from the physical layer name
function csy_GetMetaLayerName(strPhysicalName)
{
	if(strPhysicalName != "")
	{
		//alert(strPhysicalName);
		var arrData = strPhysicalName.split('\\');
		// replace all of the unwanted characters with underscores (_)		
		var strTemp = arrData[arrData.length-1];
		
		strTemp = strTemp.replace("/", "_");
		strTemp = strTemp.replace(":", "_");
		strTemp = strTemp.replace(",", "_");
		strTemp = strTemp.replace(";", "_");
		strTemp = strTemp.replace("(", "_");
		strTemp = strTemp.replace(")", "_");
		strTemp = strTemp.replace(/ /g, "_");
		strTemp = strTemp.replace("'", "_");
		strTemp = strTemp.replace("&", "_");
		strTemp = strTemp.replace(".", "_");
		
		return strTemp;
	}
	return strPhysicalName;
}

function csyReplace(str,text,by)
{
	// Replaces text with by in string
	/*var i = string.indexOf(text), newstr = '';
	if ((!i) || (i == -1))
		return string;
	newstr += string.substring(0,i) + by;
	if (i+text.length < string.length)
		newstr += csyReplace(string.substring(i+text.length,string.length),text,by);
	return newstr;*/
	return str.replace(text, by); //???
}

//***********************************************************************
//* 	csy_setWindowFocus function
//* 	used to explicilty set a windows focus on a fractional delay
//*   Usefull as a workaround to IE7s multithreading which returns
//*   focus from a popup to the calling window.
//*
//*  FireFox requires the advanced javascript setting 'Raise or lower windows' to be checked
//*  in order to blur or set focus to a window. We may need to add this to the help.
//*
//*	Created by Josh Hevenor, Cuesta Systems, 2007
//*	Copyright Cuesta Systems, Ontario, Canada, 2007
//***********************************************************************
function csy_setWindowFocus(oWnd, callingWindow){
    // Default to the top of the stack
   var theTop = getTopWindow();

   
   if(theTop) 	theTop=theTop.theWindow;
   if(arguments.length==2) //SP     	
  	 callingWindow = callingWindow || theTop || window;
   
   callWait(50);
   if(oWnd && !oWnd.closed){ //sometimes "Permission denied on this line, because of the test oWnd.close, try to help with  callWait(1);
    // Initialize Array to track open windows
    if(!listOfWindows) listOfWindows = new Array();
    //Clean up any closed windows
    var tempWin = null;
    var l = listOfWindows.length
    while(l > 0){
     
      tempWin = listOfWindows.pop();
    
      if(tempWin && !tempWin.theWindow.closed)
      {
	if(oWnd!= tempWin.theWindow){
	     listOfWindows.push(tempWin);	            
	      }
 	  if(callingWindow == null || callingWindow==undefined)
          {
  
          	if((tempWin.theWindow)!= null && (oWnd.name!= tempWin.theWindow.name) )
      		{
      		
      			if(!tempWin.theWindow.closed)
      			{       			
      			   tempWin.theWindow.close();			      			   
       			}
     			
       			var ar=0;
 
      			
      			/*SP apr 2008 for (ss=0; ss<100;ss++)//instead of a sleep function
		       	{		    	
		       		if(!tempWin.theWindow.closed)	
		       		   callWait(500);		       		
		      		else
		      		   ss=1000001;
		      	}*/
		      	
		      if(listOfWindows.length>0)
       			 tempWin= listOfWindows.pop();//to remove from array
       			    			
      			
      		}
      		
           }  
           else
           {}

      }
      l--;
    }
    
   var w = new popupStackEntry(oWnd, callingWindow);
   listOfWindows.push(w);
   csy_setWindowSize(oWnd);

    var newTimeoutFunc = function () {  oWnd.focus(); };
    setTimeout(newTimeoutFunc, 500);

  } else {
    alert('Pop-up blocked.To see the window please turn off the pop-up blocker!')
  }
}
//***********************************************************************
//SP Nov 2007
//***********************************************************************
function callWait(valTimeout)
{
/*var ileft=screen.width-5;
var param= "left="+ileft+",top=0,width=5,height=5";
var sWindowTimeout='window.setTimeout(function(){window.close();},'+valTimeout+')';

var vtheW=window.open('javascript:document.writeln("<script>'+sWindowTimeout+'</script>")','waitWindow',param)
vtheW.moveTo(ileft+100,0)*/
}



//***********************************************************************
//* 	csy_setWindowSize function
//*  Used to standardize window position based on where the user has
//*  put the window in the past
//*
//*	Created by Josh Hevenor, Cuesta Systems, 2007
//*	Copyright Cuesta Systems, Ontario, Canada, 2007
//***********************************************************************
function csy_setWindowSize(oWnd){

  // Attach config function to window
  if(oWnd && oWnd.addEventListener){
   //Is handled before the window is open  oWnd.addEventListener("load",  configureWindowFromCookie, false);
    oWnd.addEventListener("beforeunload", saveWindowToCookie, false);
    oWnd.addEventListener("unload", setProperPopupFocus, false);
    // this was being called when the window loaded and was reseting the size some of the time.
    //oWnd.addEventListener("resize", saveWindowToCookie, false);
  } else if(oWnd && oWnd.attachEvent){
    //Is handled before the window is openoWnd.attachEvent("onload", configureWindowFromCookie);
    oWnd.attachEvent("onbeforeunload", saveWindowLocationToCookie);
    oWnd.attachEvent("onunload", setProperPopupFocus);
    //if( getWindowGroup(oWnd) == "GRP0_"){ 
    oWnd.attachEvent("onresize", saveWindowDimensionsToCookie);
    	//oWnd.attachEvent("onresize", saveWindowDimensionsToCookie)
 	  //}
  } else {
   // alert("Could not attach resize event to new window!\nYour browser may not support this.");
  }

}

//***********************************************************************
//* 	configureWindowFromCookie function
//*  Used to standardize window position based on where the user has put the
//*  window in the past. Looks up this position from a cookie. Attached to
//*  focus event
//*
//*	Created by Josh Hevenor, Cuesta Systems, 2007
//*	Copyright Cuesta Systems, Ontario, Canada, 2007
//***********************************************************************
function configureWindowFromCookie(){
    var doc = this.document;
    var mf = null;
    if(opener && opener.frames["MapFrame"])
      mf = opener.frames["MapFrame"];
    else if(top.frames["MapFrame"])
      mf = top.frames["MapFrame"];
      
    if (doc.cookie.length>0 && mf)
    { // If there is a cookie set
      //build the name of the cookie, GRP#_COOKIE_NAME
      var  oWndT = listOfWindows.pop();
      oWnd = oWndT.theWindow;
      
      var xName = mf.getWindowGroup(oWnd.name) + "WINDOW_X";
      var yName = mf.getWindowGroup(oWnd.name) + "WINDOW_Y";
      var wName = mf.getWindowGroup(oWnd.name) + "_" + oWnd.name + "_WINDOW_W";
      var hName = mf.getWindowGroup(oWnd.name) + "_" + oWnd.name + "_WINDOW_H";

      var x = mf.readCookie(xName);
      var y = mf.readCookie(yName);
      var w = mf.readCookie(wName);
      var h = mf.readCookie(hName);
      // Just in case
      if(w > screen.availWidth || h > screen.availHeight){
         w = screen.availWidth;
         h = screen.availHeight;
      }
      if(x > screen.availWidth || y > screen.availHeight){ // offscreen...so center
        x = (screen.availWidth - w)/2;
        y = (screen.availHeight - h)/2;
      }

      if(w != null && h != null){
        oWnd.resizeTo(w,h);
      }
      
      if(x != null && y != null)
        oWnd.moveTo(x,y);
      listOfWindows.push(oWndT);
     // alert("Window set to (x,y,w,h)=(" + x +","+y+","+w+","+h+")");
  }
  return false;  // Stop future events
}

/*
*/
function configureOpenWindowFromCookie(winName, defaultX, defaultY, defaultWidth, defaultHeight, overRidePosition, overRideDimension){

  defaultX =  defaultX || -1;
  defaultY =  defaultY || -1;
  defaultWidth =  defaultWidth || -1;
  defaultHeight =  defaultHeight || -1;
  overRidePosition = overRidePosition || false;
  overRideDimension = overRideDimension || false;

  var x = 0;
  var y = 0;
  var w = 0;
  var h = 0;


    var doc = this.document;
  
    if (doc.cookie.length>0)
    {
      var mf = this;
      // If we have an override parameter then use it
      if(!overRidePosition){
        var xName = mf.getWindowGroup(winName) + "WINDOW_X";
        var yName = mf.getWindowGroup(winName) + "WINDOW_Y";
        x = mf.readCookie(xName);
        y = mf.readCookie(yName);
      } else {
        x = defaultX;
        y = defaultY;
      }
      
      // If we have an override parameter then use it
      if(!overRideDimension){
        var wName = mf.getWindowGroup(winName) + "_" + winName + "_WINDOW_W";
        var hName = mf.getWindowGroup(winName) + "_" + winName + "_WINDOW_H";
	if(mf.readCookie(wName)!=null || mf.readCookie(hName)!=null)
	{
        w = mf.readCookie(wName);
        h = mf.readCookie(hName);
        }
        else
        {
        w = defaultWidth;
        h = defaultHeight;
        }
      } else {
        w = defaultWidth;
        h = defaultHeight;
      }

  } else {
    x = defaultX;
    y = defaultY;
    w = defaultWidth;
    h = defaultHeight;
  }
  
  // If we're bigger than the screen size then set the window equal to the screen size
  if(w > screen.availWidth || h > screen.availHeight || w == null || h == null){
     w = screen.availWidth*0.9;
     h = screen.availHeight*0.9;
  }
  // If we're not on the screen then reset to the center of the screen
  if(x > screen.availWidth || y > screen.availHeight || x==null || y==null){
    x = (screen.availWidth - w)/2;
    y = (screen.availHeight - h)/2;
  }

  dimension = "width="+w+",height="+h;
  winLocation = "left="+x+",top="+y;
  return winLocation + "," + dimension;
}

//***********************************************************************
//* 	saveWindowToCookie function
//*  Used to standardize window position based on where the user has put the
//*  window in the past. Save the position/size of a window to a cookie when the
//*  the window is moved. We need the mouse coordinates to calculate the window
//*  position so this must be attached to a mouse event.
//*
//*	Created by Josh Hevenor, Cuesta Systems, 2007
//*	Copyright Cuesta Systems, Ontario, Canada, 2007
//***********************************************************************
function saveWindowToCookie(oEvent){

    var t = this;
    if(oEvent.target) t = oEvent.target;
    else if(oEvent.srcElement) t = oEvent.srcElement;
    var mf = null;
    if(opener && opener.frames["MapFrame"])
      mf = opener.frames["MapFrame"];
    else if(top.frames["MapFrame"])
      mf = top.frames["MapFrame"];
      
    if(mf != null){
      var statusText = "";

      var oWnd = getTopWindow();
      oWnd = oWnd.theWindow;
      if(!oWnd) return false;
      
        var x = 0;
        var y = 0;
        if(oWnd.screenX){
          x = oWnd.screenX;
          y = oWnd.screenY;
        } else {
          x = 50;
          y = 50;
        }

        statusText = ("Saving Position: (" + oEvent.screenX  + "-" +  oEvent.clientX + "=" + (oEvent.screenX - oEvent.clientX) + ", " + oEvent.screenY  + "-" +  oEvent.clientY + "=" + (oEvent.screenY - oEvent.clientY) + ")  ");
        var grp = mf.getWindowGroup(oWnd.name);
        mf.createCookie(grp + "WINDOW_X",x, 90);
        mf.createCookie(grp + "WINDOW_Y",y, 90);

      //if(grp == "GRP0_"){  // only save dimension for GMETA, REF, SHOWINGS
	  if(true){  // save whatever we like
        this.status = statusText + ("Saving Dimension: (w, h) = (" + t.outerWidth + ", " + t.outerHeight + ")");
        var w, h;
        if(oWnd.outerWidth){
          w = oWnd.outerWidth;
          h =oWnd.outerHeight-20;
        } else {
          w = 600;
          h = 400;
        }
        mf.createCookie(mf.getWindowGroup(oWnd.name) + "_" + oWnd.name + "_WINDOW_W",w, 90);
        mf.createCookie(mf.getWindowGroup(oWnd.name) + "_" + oWnd.name + "_WINDOW_H",h, 90);
      }

      //t.document.cookie = mf.getWindowGroup(this) + "WINDOW_W=" + t.outerWidth + ";expires=" + d + ";path=/;";
      //t.document.cookie = mf.getWindowGroup(this) + "WINDOW_H=" + t.outerHeight + ";expires=" + d + ";path=/;";
    } else {
    //  alert("No MapFrame Reference!");
      return false;
    }
}

//***********************************************************************
//* 	saveWindowDimensionsToCookie function
//*  Used to standardize window position based on where the user has put the
//*  window in the past. Save the size of a window to a cookie when the
//*  the window is resized.
//*
//*	Created by Josh Hevenor, Cuesta Systems, 2007
//*	Copyright Cuesta Systems, Ontario, Canada, 2007
//***********************************************************************
function saveWindowDimensionsToCookie(oEvent){

    var t = this;
    if(oEvent.target) t = oEvent.target;
    else if(oEvent.srcElement) t = oEvent.srcElement;

    var mf = null;
    if(opener && opener.frames["MapFrame"])
      mf = opener.frames["MapFrame"];
    else if(top.frames["MapFrame"])
      mf = top.frames["MapFrame"];

    if(mf != null){
      var oWndT = listOfWindows.pop();
       oWnd = oWndT.theWindow;
      var w, h;
    /*  var tmp = "innerWidth: " + oWnd.innerWidth + "\n";
      tmp += "document.documentElement.clientWidth: " + oWnd.document.documentElement.clientWidth + "\n";
      tmp += "document.body.clientWidth: " + oWnd.document.body.clientWidth + "\n";
     alert(tmp);
     */  
      if(oWnd.document && oWnd.document.body && oWnd.document.body.clientWidth) {
        w = oWnd.document.body.clientWidth;
        h = oWnd.document.body.clientHeight; // this is innerheight...if there's a statusbar we're off
      }
     
      mf.createCookie(mf.getWindowGroup(oWnd.name) + "_" + oWnd.name + "_WINDOW_W",w, 90);
      mf.createCookie(mf.getWindowGroup(oWnd.name) + "_" + oWnd.name + "_WINDOW_H",h-20, 90);
      listOfWindows.push(oWndT);
      
    } else {
      alert("No MapFrame Reference!");
      return false;
    }
}

//***********************************************************************
//* 	saveWindowDimensionsToCookie function
//*  Used to standardize window position based on where the user has put the
//*  window in the past. Save the size of a window to a cookie when the
//*  the window is resized.
//*
//*	Created by Josh Hevenor, Cuesta Systems, 2007
//*	Copyright Cuesta Systems, Ontario, Canada, 2007
//***********************************************************************
function saveWindowLocationToCookie(oEvent){
    var t = this;
    if(oEvent.target) t = oEvent.target;
    else if(oEvent.srcElement) t = oEvent.srcElement;
    var mf = null;
    if(opener && opener.frames["MapFrame"])
      mf = opener.frames["MapFrame"];
    else if(top.frames["MapFrame"])
      mf = top.frames["MapFrame"];
    if(mf != null){

     var oWndT = getTopWindow();
      oWnd = oWndT.theWindow;
      
      if(!oWnd) return false;

    /*  var tmp = "screenTop: " + oWnd.screenTop + "\n";
      tmp += "oEvent.screenY= " + oEvent.screenX + " oEvent.clientX=" + oEvent.clientX + "\n"
     alert(tmp);
    */
      mf.createCookie(mf.getWindowGroup(oWnd.name) + "WINDOW_X",oWnd.screenLeft, 90);
      mf.createCookie(mf.getWindowGroup(oWnd.name) + "WINDOW_Y",oWnd.screenTop-25, 90);
      //mf.createCookie(mf.getWindowGroup(oWnd.name) + "WINDOW_X",oEvent.screenX - oEvent.clientX, 1);
      //mf.createCookie(mf.getWindowGroup(oWnd.name) + "WINDOW_Y",oEvent.screenY - oEvent.clientY-30, 1);

    } else {
    // alert("No MapFrame Reference!");
      return false;
    }
}
/* Things get a little screwy when popups call the map to popup new popups
*  This function, called from the popups unload event (after beforeunload)
*  should take care of things
*  Update: FF doesn't denote a window closed until all it's events are finished (requires confirmation)
*          So getTopWindow returns closing popup
*/
function setProperPopupFocus(){

 

    var oWnd = getTopWindow();
    if (!oWnd || oWnd.callingWindow == undefined) return false; //SP nov 2006 Too much trouble to set the focus right (strange permission error )


    if(oWnd ){
      // These windows are closing...so check twice if they're open
    setTimeout(function(){if(oWnd && oWnd.callingWindow!=undefined && oWnd.callingWindow && !oWnd.callingWindow.closed) oWnd.callingWindow.focus();}, 100);
    //setTimeout(function(){if(oWnd && oWnd.theWindow && !oWnd.theWindow.closed) oWnd.theWindow.focus();}, 200); 
    
    }  


    return false;
}

//***********************************************************************
//* 	getWindowGroup function
//*  Used to standardize window position based on where the user has put the
//*  window in the past. Lookup which position/size group the window belongs
//*  to and returns the group name. Names are currently created by the convention
//*  GRP#_ where # is determined by which row in the array the window name is found
//*
//*	Created by Josh Hevenor, Cuesta Systems, 2007
//*	Copyright Cuesta Systems, Ontario, Canada, 2007
//***********************************************************************
function getWindowGroup(winName){

 /* for(i in WINDOW_GROUPS){
    for(j in WINDOW_GROUPS[i]){
      //alert("(group, window)=(" + i + ", " + WINDOW_GROUPS[i][j] + ")");
      if(oWnd.name == WINDOW_GROUPS[i][j])
        return "GRP" + i + "_";
    }
  }
 */
 /* if(winName == "showingsquery" || winName ==  "referencequery" || winName == "gmetaquery" || "QueryWindow")
    return "GRP0_";
  else
   return "GRP1_"; //SP Feb 2007
  return "";
  */ return winName;  // jul08-Each window should remember it's own position
}

/**
/** Write a note to the status bar for debugging purposes
/**
**/
function debugNoteToStatus(str){
  // change to false for production version
  if(true)
    this.status = str;
}

/**
*** Cookie functions, based off sample code from pothoven's blog.
*** Updated to work.
**/
function createCookie(name, value, days) {
 if (days) {
  var date = new Date();

  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = ";expires="+date.toGMTString();
 }
 else {
  var expires = "";
 }
 document.cookie = name + "=" + value + expires + ";path=/";
}

function readCookie(name) {
 if(document.cookie.length > 0){
  //alert(document.cookie);
  var nameEQ = name + "=";
  var cookies = document.cookie.split(';');
  for(i in cookies) {
    var cookie = cookies[i];
    cookie = cookie.replace(/ /g, "");
    if (cookie.indexOf(nameEQ) == 0) {
      return cookie.substring(nameEQ.length, cookie.length);
    }
  }
  return null;
 } else {
    return null; // no cookie set
 }
//eraseCookie(name); //SP TEST
}


function eraseCookie(name) {
 createCookie(name, "", -1);
}


//***********************************************************************
//* 	csy_addServiceLayer function
//* 	used to display Manage Layers window
 function csy_addServiceLayer()
{ 
	 
 	setPrevious();
	var iwidth=325; //(screen.width*.30);//(screen.width*.25);
	var ileft= (screen.width - iwidth)/2;
	var iheight = (screen.height*.85);

  var addLayerWin;
  var parm = "scrollbars=yes,menubar=no,resizable=no"
  //parm = parm + "," +" scrollbars=yes,menubar=no,top=20,left="+ileft+",width="+iwidth+",height="+iheight
	
 //NOT FROM COOKIE -special type :parm = parm + "," + configureOpenWindowFromCookie("addLayerWin",ileft,20,iwidth,iheight, false, true);
 parm = parm + "," + configureOpenWindowFromCookie("addLayerWin",ileft,20,iwidth,iheight, false, true);
 addLayerWin = window.open(cuestaJspURL+"addLayerWin.htm","addLayerWin", parm);
  csy_setWindowFocus(addLayerWin);
}
 
//***********************************************************************
//* 	csy_displayLayerList function
//* 	used to display the Layer List in the text frame
 function csy_displayLayerList()
{
	//if (navigator.appName.indexOf("Netscape")>=0)
	//	{parent.TextFrame.document.location= appDir+"toc.htm";}
	//else
	//	{parent.TextFrame.document.location= "http://"+hostName+"/"+cuestaURL+ "toc.htm";}
 parent.TextFrame.document.location= appDir+"toc.htm";
}

//**********************************************************************
// used to support wms layer

function setWmsVar(strIdentifyGML)
{
	strGML = strIdentifyGML;
	//alert(strGML);
}
 
//***********************************************************************
//* 	csy_displayIdentifyResults function
//* 	used to display the Query Results Window
 function csy_displayIdentifyResults(strValues, strLayer)
{ 

	//alert(strLayer);
	var windowName = "QueryWindow";
	switch(strLayer){
	 case "References": windowName = "RefQueryWindow"; break;
	 case "Showings, by Commodity": windowName = "ShowQueryWindow"; break;
	 case "G-Meta": windowName = "GmetaQueryWindow"; break;
	 default: windowName = "QueryWindow";
	}
	
	var blnIsWMSLayer = false;
	// need to determine if this layer is a WMS layer then do the following
	for (var intCnt=0;intCnt<LayerName.length;intCnt++) 
	{
		if(strLayer == LayerName[intCnt])
		{
			// need to see if this layer is not a WMS layer
			strConnection = LayerConnectionName[intCnt];
			var connType = getXMLValue("config/connections.xml","type", strConnection);
	 
			
			if(connType.toLowerCase() == "wms")
			{
				blnIsWMSLayer = true;
			}
			break;
		}
	}

	if(blnIsWMSLayer == true)
	{
	     var iWidth = screen.width;
		var iHeight = screen.height;
		if(window.top.innerWidth){
		 iWidth = window.top.innerWidth;
		 iHeight = window.top.innerHeight;
		}
		if(top.document.body.offsetWidth){
		  iWidth = top.document.body.offsetWidth;
		  iHeight = top.document.body.offsetHeight;
		}
		var iwidth=(screen.width * 0.6);
		var ileft= (screen.width - iwidth)/2;
		var iheight = (screen.height*.8);
		var parm = "scrollbars=yes,resizable=yes,menubar=no";
   		 parm = parm + "," + configureOpenWindowFromCookie("wmsWin",null,null,iWidth*0.9,iHeight*0.9,false, true);
		
		wmsWin= window.open(appDir+"WMSLayerAttributes.htm","wmsWin", parm);
    		csy_setWindowFocus(wmsWin);
	}
	else
	{
		qryLayerFields.length = 0;
		qryLayerValues.length = 0;
		qryLayerShapeIndex.length = 0;
		qryLayerJoinValues.length = 0;

		 
		if ( strValues.substring(0,3) == "-1|")
		{ 	alert("No fields defined for this layer!"); return;}
		 
		// set selection query results variables with Identify results
		 
		if(isBuffer != true)
			csy_setqryShpResults(strValues);
		useStandardReport=false;
		 
		if (strValues.length > 1)
		{
			var featureCount = 0;
			var arrTemp = strValues.split("|");
			if (arrTemp[0].length>0)
				qryLayerFields = arrTemp[0].split("^");		
			if (arrTemp.length>1)
			{
				if (arrTemp[1].length>0)			
					//values to be displayed
					qryLayerValues = arrTemp[1].split("*");	
				//extents of the selected features
				qryLayerShapeIndex = arrTemp[2].split("^");
				featureCount = t.qryLayerShapeIndex.length;
			}
			var iheight = 100+(30 * featureCount);
			if (iheight >screen.height)
			{
				iheight = screen.height*0.9;
			}
			var iwidth = 25 +(75 * qryLayerFields.length)
			if (iwidth >screen.width)
			{
				iwidth = screen.width*0.9;
			}		

			 
			if (arrTemp.length>3) 
			{
				qryLayerJoinValues = arrTemp[3];
				var alidx = -1;

				//  added to consider buffer target, as opposed to Active Layer.
				if (isBuffer) {
				//for Buffer
					for (var j=0; j<LayerID.length; j++)
					{
						if (LayerID[j]==bufferTargetLayer)
						{
							alidx = j;
							j = LayerID.length;
						}
					}
				}
				else
				{//if active Layer is selected query layer
					for (var j=0; j<LayerID.length; j++)
					{
						if (LayerID[j]==ActiveLayerID)
						{
							alidx = j;
							j = LayerID.length;
						}
					}			
				}

				//   corrected to support join tabs
					qryLayerJoinIndex = alidx;
				var iWidth = screen.width;
				var iHeight = screen.height;
				if(window.top.innerWidth){
				 iWidth = window.top.innerWidth;
				 iHeight = window.top.innerHeight;
				}
				if(top.document.body.offsetWidth){
				  iWidth = top.document.body.offsetWidth;
				  iHeight = top.document.body.offsetHeight;
				}
				var parm = configureOpenWindowFromCookie(windowName,null,null,iWidth*0.9,iHeight*0.9, false, false) + ",scrollbars=yes,resizable=yes";
				// increase window width from 'screen.width/2' to 'screen.width*3/4'
				if (navigator.appName.indexOf("Netscape")>=0)

					{Win1 = window.open(appDir+"qryAttribWindow.htm",windowName,parm);}
				else
					{Win1 = window.open("qryAttribWindow.htm",windowName,parm);}
			
		     }
			else
			{
				var Win1;
				var iWidth = screen.width;
				var iHeight = screen.height;
				if(window.top.innerWidth){
       			 	  iWidth = window.top.innerWidth;
       		   		  iHeight = window.top.innerHeight;}
       			        if(top.document.body.offsetWidth){
       			           iWidth = top.document.body.offsetWidth;
       			           iHeight = top.document.body.offsetHeight;}

					
				
				if(identifyMode==1 && toolMode == 'identify' && t.sTheCommand !="ALL_PERSISTED")
				{
					var parm = configureOpenWindowFromCookie("QueryIdentify",null,null,300,375, false, true) + ",scrollbars=no,resizable=yes";
					if (navigator.appName.indexOf("Netscape")>=0)
							Win1 = window.open(appDir+"quickIdentifyMain.htm","QueryIdentify",parm);
					else
							Win1 = window.open("quickIdentifyMain.htm","QueryIdentify", parm);
				}
				else
				{
					 var parm = configureOpenWindowFromCookie(windowName,null,null,iWidth*0.9,iHeight*0.9, false, false) + ",scrollbars=yes,resizable=yes";
					if (navigator.appName.indexOf("Netscape")>=0)
						{Win1 = window.open(appDir+"qryAttribWindow.htm",windowName,parm);}
					else
						{Win1 = window.open("qryAttribWindow.htm",windowName,parm);}
				}
			    	csy_setWindowFocus(Win1);
			}
		}
		else
		{	
		
			if ( strValues == "0")		
			{
			    if( modeName=='Identify' || modeName=='Select by Box' || modeName=='Select by Point' || modeName=='Select by Line' || modeName=='Select by Shape')
				 alert("No features found from " + strLayer + " at the selected location!");		  
			    else
				 alert("No features found from " + strLayer + " matching the given criteria!");
			}
			else 
				if ( strValues == "1")		
				{ 	alert("No additional information available for this layer!"); }
		}
		
	}		
}
 
//***********************************************************************
//* 	zoomToBoundary function
//* 	used to display zoom to boundary form
//*
 function csy_displayZoomToBoundary()
{
	var strURL =cuestaJspURL + "storedquery.jsp";//jspAppDir + appDir
	parent.TextFrame.document.location= strURL;
}

//***********************************************************************
//* 	csy_selectProjection function
//* 	used to display projection form
//*
 function csy_selectProjection()
{
	//for NTGO
	var iwidth = 780;
	var iheight = 680;
	ileft = (screen.width - iwidth)/2;
	//top=200,left="+150+",
	var parm = "scrollbars=no,resizable=no,menubar=no ";
	var projWin;
	 parm = parm + "," + configureOpenWindowFromCookie("ProjsForm",ileft,null,780,680, false, true);
	 projWin= window.open(appDir+"ProjsForm.html","ProjsForm", parm);

	csy_setWindowFocus(projWin);
	
	//NTGO Want this in a window not frame: csy_displayGeneralPage("ProjsForm.html");
	//
}
//***********************************************************************
//* 	csy_zoomToBoundaryIt function
//* 	used to display zoom to boundary form
 //***********************************************************************
function csy_zoomToBoundaryIt(layerName)
{
	toolMode = 'zoomToBoundary';//AD June 2007, no longer needed.
	//csy_setMode(toolMode);//AD June 2007, no longer needed.
	writeModeFrame();	
	
	//sets the selected layer as the active layer	
	setActiveLayer(layerName);
	//puts the active layer ON
	t.setActiveLayerON(layerName);

	
	for(var i = 0; i< AdminBoundLayers.length;i++)
	{		
		if (layerName.toUpperCase() == AdminBoundLayers[i].toUpperCase())
		{
			layerIndex = i;
			layerField = BoundLayerField[i];
			i = AdminBoundLayers.length;
		}
	}	
	//jspAppDir + appDir
	var strURL =cuestaJspURL  + "storedquery.jsp?SELECTEDLAYER=" + layerName +"&SELECTEDID=" + layerIndex + "&FIELD=" +layerField;
	
	//  added CONNECTION parameter in jsp
	var connParams=getJSPConnString("STOREDQUERY",layerName);
	strURL += connParams;
 	
 	var tableParams=getLayerTableName(layerName);
	if (tableParams != "" && layerName != "")
		strURL += "&LAYERTABLE=" + tableParams;
	 
	
	parent.TextFrame.document.location= strURL;
}		 


//***********************************************************************
//* 	csy_find function
//* 	used to display the Find form
 //***********************************************************************
function csy_find()
{	
 	
	if (Trim(qfcaller)==length) qfcaller="NONE";//AD June 10, 2005 - set as None
	var url = cuestaJspURL+"find.jsp?CALLER="+qfcaller;//jspAppDir + appDir
	var connParams=getJSPConnString("FIND",qfcaller);
	url += connParams;
	//end AD May 11, 2005
  	parent.TextFrame.document.location= url;	  	
}


//***********************************************************************
//* 	csy_selection function
//* 	used to display the Selection form
 //***********************************************************************
function csy_selection()
{	
	var url = appDir+"Selection.htm";
	parent.TextFrame.document.location= url;	  	
}

//***********************************************************************
//* 	csy_buffer function
//* 	used to display the Buffer form
 //***********************************************************************
function csy_buffer()
{	
 	  var url = appDir + "SpatialQuery.htm";		
  	parent.TextFrame.document.location= url;	  	
}

function csy_spatialquery()
{	
	var url = appDir + "SpatialQuery.htm";		
  	parent.TextFrame.document.location= url;	  	
}

//************************************************************************
//** This function dislays the HELP window
//** Created By: Monica Socol, June 28 2004
 //***********************************************************************
var wnd = null;
function csy_showHelp(anchor, openingWindow)
{
	//Modified by Ali Aug 24, 2004
	var parm = configureOpenWindowFromCookie("helpWindow",null,null,900,500, false, false) + ",resizable=yes";
	if (anchor==null)
		{
		 var url = appDir+'Help/Help.htm';
		 wnd = window.open(url, 'helpWindow', parm);
		}
	else
		{
		 var url = appDir+'Help/Help.htm';
		 wnd = window.open(url, 'helpWindow', parm);
		 localanchor = anchor;
		 setTimeout("LoadHelpIndex(localanchor)",1500);
		}	
    csy_setWindowFocus(wnd, openingWindow);
}
 
function LoadHelpIndex(anchor)
{
	wnd.HelpFrame.document.location = appDir + "Help/HelpFile.htm#"+ anchor;
}
//************************************************************************
//** This function dislays the HELP window
 //***********************************************************************
function csy_showHelpParam()
{
   var parm = configureOpenWindowFromCookie("helpWindow",null,null,900,500, false, false) + ",resizable=yes";
	 window.open(appDir+'Help/Help.htm', 'helpWindow', 'width=900, height=500, resizable=yes');
 }

//***********************************************************************
//* 	csy_saveSession function
//* 	used to display save settings form
 //***********************************************************************
function csy_saveSession()
{
	 
		
	var newWinSs;
	var iwidth=(screen.width*.75);
	var ileft= (screen.width - iwidth)/2;
	var iheight = (screen.height*.32);
//for NTGO
iwidth=780
iheight=680
//top=20,left="+ileft+",;

 var parm = "scrollbars=yes,menubar=no"; //width="+iwidth+",height="+iheight
 parm = parm + "," + configureOpenWindowFromCookie("SaveSession",ileft,null,780,680, false, true);
 newWinSs= window.open(appDir+"SaveSession.htm","SaveSession", parm);
 csy_setWindowFocus(newWinSs);
}
 
//***********************************************************************
//* 	csy_loadSession function
//* 	used to display load settings form
 //***********************************************************************
function csy_loadSession()
{

	var newWinLs;
	var iwidth=(screen.width*.75);
	var ileft= (screen.width - iwidth)/2;
	var iheight = (screen.height*.29);

	//for NTGO
	iwidth=780
	iheight=680 // Should this be in csyCommon?

	var parm = "scrollbars=yes,menubar=no,status=yes,";
	parm = parm + "," + configureOpenWindowFromCookie("LoadSession",ileft,0,780,680, false, true);
	//newWinLs = window.open(appDir+"LoadSession.htm","LoadSession", parm);
	newWinLs = window.open(appDir+"LoadSession.php","LoadSession", parm);
	csy_setWindowFocus(newWinLs);
}


//***********************************************************************
//* 	csy_manageBookmarks function
//* 	used to display save Bookmarks form
//***********************************************************************
function csy_manageBookmarks()
{
 	     
	var newWinMB;
	var iwidth=(screen.width*.75);
	var ileft= (screen.width - iwidth)/2;
	var iheight = (screen.height*.60);
		//For NTGO
	iwidth=780
	iheight=680
		//for NTGO end
	var parm = "scrollbars=yes,menubar=no";
	parm = parm + "," + configureOpenWindowFromCookie("ManageBookmarks",ileft,0,780,680, false, true);

	newWinMB = window.open(cuestaJspURL+"manageBookmarks.htm","ManageBookmarks", parm);
	csy_setWindowFocus(newWinMB);
	
}
//************************************************************************


//************************************************************************
//* 	csy_displayGeneralPage function
//* 	used to display any html page sent as a parameter into the TextFrame	
 //***********************************************************************
function csy_displayGeneralPage(pgName,frameID)
{
	//*****   POSSIBLE PARAMETER LIST	
	//***** this list can be further customized
	//New Window		0
	//Default: TextFrame	1
	//TopFrame		2
	//MapFrame		3
	//BottomFrame		4	
	//BlankFrame		5
	//MainToolbarFrame	6
	//MainToolbar1Frame	7
	//DynamicToolbarFrame	8
	//StandardToolbarFrame	9
	//RightLeftFrame	10
	//MainToolBar_RightFrame 11
	//RightRightFrame	12
	//ModeFrame		13
	//*****   END
	//if (navigator.appName.indexOf("Netscape")>=0)
	//	{ var url = appDir+pgName;}
	//else
	//	{ var url = "http://" + t.hostName + t.appDir +pgName;}
	var url = appDir+pgName;

	switch(frameID)
	{
		case 0: window.open(url, 'pageWindow', 'width=900, height=500, resizable=yes'); break;
		case 1: parent.TextFrame.document.location= url; break;			
		case 2:	parent.TopFrame.document.location= url;	break;
		case 3:	parent.MapFrame.document.location= url;	break;	
		case 4:	parent.BottomFrame.document.location= url; break;				
		case 5:	parent.BlankFrame.document.location= url; break;
		case 6:	parent.MainToolbarFrame.document.location= url;	break;			
		case 7:	parent.MainToolbar1Frame.document.location= url;break;
		case 8:	parent.DynamicToolbarFrame.document.location= url;break;	
		case 9:	parent.StandardToolbarFrame.document.location= url;break;	
		case 10:parent.RightLeftFrame.document.location= url;break;
		case 11:parent.MainToolBar_RightFrame.document.location= url;break;			
		case 12:parent.RightRightFrame.document.location= url;break;
		case 13:parent.ModeFrame.document.location= url;break;	
		default:parent.TextFrame.document.location= url;break;
	}
}
 
//***********************************************************************
//* 	loadSavedProject function
//* 	loads a saved project knowing the file name
 //***********************************************************************
var xmlDoc;
function csy_loadSaveProject(fileLoad)
{
 	
	var cc = fileLoad.indexOf("\\")
	if (cc != -1)
	{
		var str = fileLoad.substr(0,cc);
		fileLoad = fileLoad.split("\\").join("\/");
		fileLoad = "file:///"+fileLoad;
	}
  // JH re-wrote Jan 2007
  if (window.ActiveXObject)
  {
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    var loaded = xmlDoc.load(fileLoad);
    if(loaded){
      csy_loadXmlDoc();
    } else {
      alert("Failed to load: " + fileLoad);
    }
  }
  // code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation && document.implementation.createDocument)
  {
    xmlDoc=document.implementation.createDocument("","",null);
    xmlDoc.load(fileLoad);
    xmlDoc.onload=csy_loadXmlDoc;
  }
  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 csy_loadXmlDoc()
{
	csy_loadProjectFile(xmlDoc);
}

//***********************************************************************
//* 	customizeLayer function
//* 	used to customize the active layer
 //***********************************************************************
function csy_customizeLayer()
{
	var iwidth=(screen.width*.6);
	var ileft= (screen.width - iwidth)/2;
	
	if (ActiveLayerType == "point")
	{	var iheight = (screen.height*.95);}
	else {
		if (ActiveLayerType == "line")
		{	var iheight = (screen.height*.90);}
		else { 	var iheight = (screen.height*.90);}
	}
iwidth=600;
iheight=600;
//"top=50,left="+ileft+
	var parm = "scrollbars=yes,resizable=yes,menubar=no";
  parm = parm + "," + configureOpenWindowFromCookie("customizeLayerWin",ileft,0,iwidth,iheight, false, true);
	if (ActiveLayerID.length == 0)
	{
		alert("Please select an Active Layer from the Layer List");
		if (useTextFrame) parent.TextFrame.document.location= appDir + "toc.htm";
	}
	else
	{
		//setActiveLayer(ActiveLayerIndex);

 //SP FEB 2007 this variable is used in few files, must be declared in other place, failed on NTGO   var customizeLayerWin;
		//check the layer type
		switch(ActiveLayerType) {
			case "point":
//				if (useTextFrame) parent.TextFrame.document.location= appDir + "CustomizeLayer.htm";
				customizeLayerWin = window.open(appDir+"CustomizeLayer.htm","customizeLayerWin", parm);
				break;	
			case "line":
//				if (useTextFrame) parent.TextFrame.document.location= appDir + "CustomizeLayer.htm";
				customizeLayerWin = window.open(appDir+"CustomizeLayer.htm","customizeLayerWin", parm);
				break;
			case "polygon":
//				if (useTextFrame) parent.TextFrame.document.location= appDir + "CustomizeLayer.htm";
				customizeLayerWin = window.open(appDir+"CustomizeLayer.htm","customizeLayerWin", parm);
				break;
			default:
				//alert("Cannot customize this type of layer!"); ///LM March 7 2006 - must open page
				if (useTextFrame) parent.TextFrame.document.location= appDir + "toc.htm";
				customizeLayerWin = window.open(appDir+"CustomizeLayer.htm","customizeLayerWin", parm);
				break;
		}
		csy_setWindowFocus(customizeLayerWin);
	}
}
  
//***********************************************************************
//* 	csy_displayJspGeneralPage() function
//* 	used to display general jsp page
//*
 //***********************************************************************
function csy_displayGeneralJspPage(jspPage)
{
	var url =cuestaJspURL + jspPage;//jspAppDir + appDir 
	parent.TextFrame.document.location = url;
}
 
//***********************************************************************
//* 	csy_reorderLayer function
//* 	used to reorder the service layers
 //***********************************************************************
function csy_reorderLayer()
{
	reorderCaller = "usual";
	if (ActiveLayerID == "")
	{
		alert("Please select an Active Layer from the Layer List");
		if (useTextFrame) parent.TextFrame.document.location= appDir + "toc.htm";
	}
	else
	{
		reorderCalle = "usual";
		var iwidth =350;
		var ileft= (screen.width - iwidth)/2;
		var iheight = (screen.height*.85);
   		
 		var parm = "scrollbars=yes,resizable=no,menubar=no";
		//parm = parm + "," +" scrollbars=yes,menubar=no,top=20,left="+ileft+",width="+iwidth+",height="+iheight
		//NOT FROM COOKIE- special type: parm = parm + "," + configureOpenWindowFromCookie("reorderWin",ileft,20,iwidth,iheight, false, true);
		parm = parm + "," + configureOpenWindowFromCookie("reorderWin",ileft,20,iwidth,iheight, false, true);
		reorderWin = window.open(appDir+"CustomizeOrder.htm","reorderWin", parm);
    		csy_setWindowFocus(reorderWin);
	}
}
 //***********************************************************************
//* 	csy_displayReportResults function
//* 	used to display the Report Window for Standard Reports
 //***********************************************************************
function csy_displayReportResults(strValues, strLayer)
{ 
	qryLayerFields.length = 0;
	qryLayerValues.length = 0;
	qryLayerShapeIndex.length = 0;

	 
	if ( strValues.substring(0,3) == "-1|")
	{ 	alert("No fields defined for this layer!"); return;}
	 

	//  set standard report selected
	useStandardReport=true;
	 
	
	if (strValues.length > 1)
	{
		var featureCount = 0;
		var arrTemp = strValues.split("|");
		qryLayerFields = arrTemp[0].split("^");		
		if (arrTemp.length>1)
		{
			//values to be displayed
			qryLayerValues = arrTemp[1].split("*");
			featureCount = t.qryLayerValues[0].split("^").length;
			//extents of the selected features
			qryLayerShapeIndex = arrTemp[2].split("^");
		}
	
		var iheight = 100+(30 * featureCount);
		if (iheight >screen.height)
		{
			iheight = screen.height*0.9;
		}
		var iwidth = 25 +(75 * qryLayerFields.length)
		if (iwidth >screen.width)
		{
			iwidth = screen.width*0.9;
		}	
		
 		//JOINS
 		if (arrTemp.length>3) 
		{
			qryLayerJoinValues = arrTemp[3];
			var alidx = -1;
			
			for (var j=0; j<LayerID.length; j++)
			{
				if (LayerID[j]==ActiveLayerID)
				{
					alidx = j;
					j = LayerID.length;
				}
			}			

			qryLayerJoinIndex = alidx;
		}
		reorderWin
		Win1 = window.open(appDir+"stdnReportWindow.htm","ReportWindow",configureOpenWindowFromCookie("ReportWindow",0,0,screen.width,screen.height, false, false) +",scrollbars=yes,resizable=yes,menubar=1");
		csy_setWindowFocus(Win1);
	}
	else
	{	
		if ( strValues == "0")		
		{
		    if( modeName=='Identify' || modeName=='Select by Box' || modeName=='Select by Point' || modeName=='Select by Line' || modeName=='Select by Shape')
		  	 alert("No features found from " + strLayer + " at the selected location!");		  
		    else
		   	 alert("No features found from " + strLayer + " matching the given criteria!");
		}
		else 
			if ( strValues == "1")		
			{ 	alert("No additional information available for this layer!"); }
	}		
}
//***********************************************************************


//***********************************************************************
//* 	csy_addDynamicLayer function
//* 	used to display manage local data form
 //***********************************************************************
function csy_addDynamicLayer()
{
	useDynamicLayers = true;
	aimsCustomPresent = true;
	var iwidth=(screen.width*.38);
	var ileft= (screen.width - iwidth)/2.2;
	var iheight = (screen.height*.65);

	var parm = "scrollbars=yes,resizable=yes,menubar=no";
        parm = parm + "," + configureOpenWindowFromCookie("addDynLayerWin",ileft,20,iwidth,iheight, false, false);
	addDynLayerWin = window.open(appDir+"addLocalData.htm","addDynLayerWin", parm);
	csy_setWindowFocus(addDynLayerWin);
}
//***********************************************************************

//***********************************************************************
//* 	openMetaPage function
//* 	used to call layer metadata report 
 //***********************************************************************
function openMetaPage()
{
	
 	setPrevious();
	var iwidth=(screen.width * 0.95);
	var ileft= (screen.width - iwidth)/2;
	var iheight = (screen.height*.8);
	//for NTGO
	iwidth=780;
	iheight=680;
	var parm = "scrollbars=yes,resizable=yes,menubar=no,status=no";
	parm = parm + "," + configureOpenWindowFromCookie("metaWin",ileft,20,iwidth,iheight, false, true);

	metaWin= window.open(appDir+"metadata.htm","metaWin", parm);
	if(arguments.length==0) //SP : is ==1 when is comming from addLayerCenter, and represent the window
		csy_setWindowFocus(metaWin);
	else
		csy_setWindowFocus(metaWin,arguments[1]);

}

//************************************************************************
//** Point click functions, for Capture X,Y. Opens the Capture X,Y form and populate point coordinates.
//***********************************************************************
 
function csy_displayCaptureXY()
{
     mapCaptureX = "";
     mapCaptureY = "";

	//AD May 2007
	/*
	//var parm = "top=200,left="+150+",scrollbars=no,resizable=no,menubar=no,width="+screen.width/4+",height="+screen.width/6;
	//SP DEC for NTGO" 
	//var parm =
	 "top=200,left=" +150+",scrollbars=no,resizable=no, menubar=no,width="+2*(screen.width/5)+",height="+4*(screen.height/11);
	var iwidth=780;
	var iheight=680;
	var parm = "scrollbars=no,resizable=no,menubar=no,width="+iwidth +",height="+ iheight;
	captWin = window.open(appDir + "captureXY.htm","captureXYWindow",parm);
	csy_setWindowFocus(captWin);
      	*/
      	csy_displayGeneralPage("captureXY.htm");
      	//
}
//************************************************************************

//***********************************************************************
//* 	csy_displayZoomToBox function
//*  displays ZoomtoBox dialog
//***********************************************************************
function csy_displayZoomToBox()
{

	//AD June 207
	/*var iwidth=780;
	var iheight=680;
	var parm = "scrollbars=no,status=no,resizable=yes,menubar=no,width="+iwidth +",height="+ iheight;
	var zoomBoxWin;

	 
	zoomBoxWin = window.open(appDir+"zoomToBox.html","ZoomBoxWindow",parm);
	csy_setWindowFocus(zoomBoxWin);
	*/
	csy_displayGeneralPage("zoomToBox.html");
	//

}


//************************************************************************
//* 	cuestaFindIt function =cuestaFind with parameter
//* 	used to display the Find form parameterized
//************************************************************************
function csy_cuestaFindIt(val)
{	

	toolMode = 'quickFind';
	//csy_setMode(toolMode);//AD June 2007, no longer needed.
	writeModeFrame();	
	
 	var url="";
	if (Trim(val.toString()).length>0)
		url = cuestaJspURL+"find.jsp?CALLER="+ val.toString();//jspAppDir + appDir
	else
		url =cuestaJspURL +"find.jsp?CALLER=NONE";//jspAppDir + appDir
 	var connParams=getJSPConnString("FIND",val.toString());
	url += connParams;
 	parent.TextFrame.document.location= url;	  
}		 
		

function cuestaFindItDisplay(val){
	var url = cuestaJspURL+"find.jsp?CALLER="+ val.toString(); //jspAppDir + appDir
 	var connParams=getJSPConnString("FIND",val.toString());
	url += connParams;
   	parent.TextFrame.document.location= url;	  
}
//************************************************************************

function csy_showing()
{	
 	if (Trim(qfcaller)==length) qfcaller="NONE";
	var url = cuestaJspURL +"showing_query.jsp";//jspAppDir + appDir
	var connParams=getJSPConnString("SHOWING","NORMINA");
	url += connParams;
        var parm = configureOpenWindowFromCookie("showingsquery",null,null,750,700, false, false) + ",toobars=no,scrollbars=yes,resizable=yes";
  	var win = window.open(url,"showingsquery", parm) ; //left=5,top=5,
  	csy_setWindowFocus(win);
}

function csy_referece()
{	
	if (Trim(qfcaller)==length) qfcaller="NONE";
	var url =cuestaJspURL +"reference_query.jsp";//jspAppDir + appDir
	 
  	var parm = configureOpenWindowFromCookie("referencequery",null,null,750,700, false, false) + ",toobars=no,scrollbars=yes,resizable=yes";
  	var win = window.open(url,"referencequery",parm);//left=5,top=5,
  	csy_setWindowFocus(win);
}

 function csy_gmeta()
{	
	var url = cuestaJspURL+"gmeta_query.jsp";//jspAppDir + appDir
 	  var parm = configureOpenWindowFromCookie("gmetaquery",null,null,750,700, false, false) + ",toobars=no,scrollbars=yes,resizable=yes";
	var win = window.open(url,"gmetaquery",parm);//left=5,top=5,
	csy_setWindowFocus(win);
}

function csy_diamonds()
{	
	var url = cuestaJspURL+"diamond_query.jsp";//jspAppDir + appDir
 	  var parm = configureOpenWindowFromCookie("diamondquery",null,null,750,700, false, false) + ",toobars=no,scrollbars=yes,resizable=yes";
	var win = window.open(url,"diamondquery",parm);//left=5,top=5,
	csy_setWindowFocus(win);
}

 
function csy_openRefenceDetailPage(referenceId)
{	
	var url = cuestaJspURL+"reference_details.jsp?referenceID="+referenceId;//jspAppDir + appDir
	//alert(url);
	//window.open(url,"gmetaquery")  	
  var parm = configureOpenWindowFromCookie("ReferenceDetailReport",null,null,750,700, false, false) + ",toobars=no,scrollbars=yes,resizable=yes";
	window.open(url,"ReferenceDetailReport",parm)
}

//***********************************************************************
//* 	standardReports function
//* 	used to display standard reports form
 //***********************************************************************
function csy_standardReports()
{	
 	if (hasQueryResults == "1")
	{
		alert("No fields defined for this layer!");
		return;
	}
 	
	if (sqryLayerName == "" || Trim(sqryShpResults).length == 0)
	{
		alert("Please select the features from '" + ActiveLayerID + "' layer first!");
		return;
	}
	
	if (sqryLayerName != ActiveLayerID)
	{
		alert("The selected features do not belong to the active layer. Please make a selection from the active layer."); 
		return;
	}
	
	if (Trim(sqryShpResults).length>0) 
	{//selection query results
		var theForm = top.PostFrame.document.forms[0];
		theForm.CMD.value = 'STDREPORT';

		var strURL = cuestaJspURL+ "stdnReport.jsp";//jspAppDir + appDir 		
		parent.TextFrame.document.location = strURL;
	}
	else
	{
		alert("Please select the features from '" + ActiveLayerID + "' layer first!");
	}	

}
//***********************************************************************************


//***********************************************************************************
//* 	standardReports function PARAMETERIZED
//* 	used to display standard reports form and launch the selected report
 //***********************************************************************************
function csy_standardReportsParm(val)
{	
 	if (hasQueryResults == "1")
	{
		alert("No fields defined for this layer!");
		return;
	}
 	
	if (sqryLayerName == "" || Trim(sqryShpResults).length == 0)
	{
		alert("Please select the features from '" + ActiveLayerID + "' layer first!");
		return;
	}
	
	if (sqryLayerName != ActiveLayerID)
	{
		alert("The selected features do not belong to the active layer. Please make a selection from the active layer."); 
		return;
	}
	
	if (Trim(sqryShpResults).length>0) 
	{//selection query results
		var theForm = top.PostFrame.document.forms[0];
		theForm.CMD.value = 'STDREPORT';

		var strURL = cuestaJspURL + "stdnReport.jsp?CALLER="+val;	//jspAppDir + appDir	
		parent.TextFrame.document.location = strURL;
	}
	else
	{
		alert("Please select the features from '" + ActiveLayerID + "' layer first!");
	}	

}
//***********************************************************************************

//***********************************************************************
//* 	QuickFindGenerator function
//* 	used to display the quick find on the left side
 //***********************************************************************

function csy_QuickFindGenerator()
{
	toolMode = 'quickFind';
	//csy_setMode(toolMode);//AD June 2007, no longer needed.
	writeModeFrame();
	//if (useTextFrame) parent.TextFrame.document.location= cuestaJspURL+"QuickFind.jsp";
	if(arguments.length==0)
	{//if (useTextFrame) parent.TextFrame.document.location= cuestaJspURL+"QuickFind.jsp";
	 if (useTextFrame) parent.TextFrame.document.location= cuestaJspURL+"QuickFindAccMenu.html";
	}
	else
	{	
		var argJSP=arguments[0].replace(/~/g,"&");
		//if (useTextFrame) parent.TextFrame.document.location= cuestaJspURL+"QuickFind.jsp?"+argJSP;
		if (useTextFrame) parent.TextFrame.document.location= cuestaJspURL+"QuickFindAccMenu.html?"+argJSP;
		//if (useTextFrame) parent.TextFrame.document.location= cuestaJspURL+"QuickFindAccMenu.html?"+argJSP;
	}
	//argJSP: FormAction=SearchName&SrchName=Address";
	//argJSP: FormAction=Category~CategName=NTS
	//argJSP: FormAction=SearchData&SrchName=ola&Data=municip='CUESTA'";
	
}

//***********************************************************************
//* 	csy_openSaveLayer function
//* 	used to display Save Layers window
 //***********************************************************************
function csy_SaveLayer()
{
 	 //not from cookie, special  var parm = configureOpenWindowFromCookie("PersistSelection",null,null,500,300, false, false) + ",toobars=no,scrollbars=yes,resizable=yes";
	var iwidth=550;
	var iheight=280;
	var ileft= (screen.width - iwidth)/2;

	parm = " scrollbars=yes,menubar=no,resizable=no,top=20,left="+ileft+",width="+iwidth+",height="+iheight
        var parm = configureOpenWindowFromCookie("PersistSelection",ileft,20,iwidth,iheight, true, true) + ",toobars=no,scrollbars=yes,resizable=no,menubar=no";
	Win1 = window.open(appDir+"PersistSelection.htm","SaveLayerWindow",parm);
        if(arguments.length==0) //SP : is ==1 when is comming from qryAttributeWindow, and represent the window
		csy_setWindowFocus(Win1);
	else
		csy_setWindowFocus(Win1,arguments[1]);
}
 
//***********************************************************************
//* 	csy_extractData function
//* 	used to display extract data form
 //***********************************************************************
function csy_extractData()
{
	var newWinE;
	var iwidth=(screen.width*.75);
	var ileft= (screen.width - iwidth)/2;
	var iheight = (screen.height*.85);
//for NTGO
iwidth=780
iheight=680
//top=20,left="+ileft+",

  var parm = configureOpenWindowFromCookie("ExtractData",ileft,20,iwidth,iheight, false, true) + ",toobars=no,scrollbars=yes,resizable";
  newWinE = window.open(appDir+"Extract.htm","ExtractData", parm);
  csy_setWindowFocus(newWinE);
}
//***********************************************************************
//* 	csy_extractData function
//* 	used to display extract data form
//*  SP,Sep 2007 
 //***********************************************************************
function csy_extractDataFull()
{
	var newWinEf;
	var iwidth=(screen.width*.75);
	var ileft= (screen.width - iwidth)/2;
	var iheight = (screen.height*.85);
//for NTGO
iwidth=780
iheight=680
//top=20,left="+ileft+",

  var parm = configureOpenWindowFromCookie("ExtractData_full",ileft,20,iwidth,iheight, false, true) + ",toobars=no,scrollbars=yes,resizable";
  newWinEf = window.open(appDir+"Extract_full.htm","ExtractData_full", parm);
  csy_setWindowFocus(newWinEf);
}
//***********************************************************************
//* 	csy_extractWizard function
//* 	used to display download wizard form
//*   JH Mar 2009
 //***********************************************************************
function csy_extractWizard()
{
	var newWinEf;
	var iwidth=(screen.width*.75);
	var ileft= (screen.width - iwidth)/2;
	var iheight = (screen.height*.85);
	//for NTGO
	iwidth=780
	iheight=680
	//top=20,left="+ileft+",

  var parm = configureOpenWindowFromCookie("extractWizard",ileft,20,iwidth,iheight, false, true) + ",toobars=no,scrollbars=yes,resizable";
  newWinEf = window.open(appDir+"extractWizard.htm","extractWizard", parm);
  csy_setWindowFocus(newWinEf);
}
//***********************************************************************
//* 	csy_saveIntermediate function
//* 	used to display the IE7 download warning
//*   jh, Apr 2007
//***********************************************************************
function csy_saveIntermediate()
{//seams that is not used
	var newWinSi;
	

	//identical with values from csy_showExtractURL function
	iwidth=358;
	iheight=500;
	var ileft= (screen.width - iwidth)/2;

	var parm = configureOpenWindowFromCookie("Download Warning",ileft,20,iwidth,iheight, false, true) + ",toobars=no,scrollbars=yes,menubar=no,resizable=no";
	newWinSi = window.open(appDir+"saveIntermediate.htm","Download Warning", parm);
	csy_setWindowFocus(newWinSi);
}
//***********************************************************************
//* 	csy_SaveImage function
//* 	used to display saveimage form
//*
 function csy_SaveImage()
{
	
	var iwidth = 600;
	var iheight = 400;
	ileft = (screen.width - iwidth)/2;
	var parm = "scrollbars=yes,resizable=no,menubar=no ";
	var saveImage;
	 parm = parm + "," + configureOpenWindowFromCookie("SaveImage",ileft,null,iwidth,iheight, false, true);
	 saveImage= window.open(appDir+"saveimage.jsp","SaveImage", parm);

	csy_setWindowFocus(saveImage);
	
	//NTGO Want this in a window not frame: csy_displayGeneralPage("saveimage.jsp");
	//
}
//***********************************************************************
//* 	csy_SaveImage function
//* 	used to display setUnits form
//*
 function csy_setUnits()
{
	
	var iwidth = 400;
	var iheight = 250;
	ileft = (screen.width - iwidth)/2;
	var parm = "scrollbars=no,resizable=no,menubar=no ";
	var setUnits;
	 parm = parm + "," + configureOpenWindowFromCookie("setUnits",ileft,null,iwidth,iheight, false, true);
	 setUnits= window.open(appDir+"setUnits.htm","setUnits", parm);

	csy_setWindowFocus(setUnits);
	
	//NTGO Want this in a window not frame: csy_displayGeneralPage("setUnits.htm");
	//
}
//***********************************************************************
//* 	csy_PrintForm function
//* 	used to display PrintForm form
//*
 function csy_PrintForm()
{
	
	var iwidth = 780;
	var iheight = 500;
	ileft = (screen.width - iwidth)/2;
	var parm = "scrollbars=no,resizable=no,menubar=no ";
	var setUnits;
	 parm = parm + "," + configureOpenWindowFromCookie("setUnits",ileft,null,iwidth,iheight, false, true);
	 printform= window.open(appDir+"printform.htm","setUnits", parm);

	csy_setWindowFocus(printform);
	
	//NTGO Want this in a window not frame: csy_displayGeneralPage("setUnits.htm");
	//
}