//-------------------------
//use MapViewerLoad.AddOnloadMethod('name of method to be called') to call client side methos(s) on document load

function DocumentOnload()
{
      this.methods = new Array();
      this.AddOnloadMethod = function(functionName){
            this.methods.push(functionName);
      }
      this.ClearMethods=function(){
            this.methods=new Array();
      }
      this.Execute = function(){
            for(var i=0;i<this.methods.length;i++)    {
                  try{eval(this.methods[i] + '();');}catch(ex){}
            }
      }
}

MapViewerLoad=new DocumentOnload();
 //-------------------------
    function doconload()
    {
          MapViewerLoad.Execute();
    }

    window.onload=doconload;


    //-------------------------
    // Call the functions that needs to be run on OnLoad Event of the page.
      MapViewerLoad.AddOnloadMethod('ReadCookies');
    //-------------------------


 var selDiv;
 //-------------------------
 function init() 
 {
   
 OverrideASPNetMenuFunction();
 HandleMoreSearchLink();

// set selection list to block onload 
try{
if(NgGetElementById(_SearchListContainer).style.display=='')
{

    NgGetElementById(_SearchListContainer).style.display='block';
}
} catch(e){ }


//To close the Common popup window on postback
try
{  
if (NgGetElementById(_CommonPopupLayer)!=null)
{
if(NgGetElementById(_CommonPopupLayer).style.display=='block')
if (window.NgClosePopup)
{
NgClosePopup();
}    
}
}catch(e){} 

try
{
if (NgGetElementById(_MapOverViewLayer)!=null)
{
if(NgGetElementById(_MapOverViewLayer).style.display=='block')
HandleOverviewMapFrame(null);
}
}catch(e){}      

try{
if(NgGetElementById(_InfoLayer).style.display=='block')
{
HandleInfoToolFrame(null);
}
} catch(e){ }

//Legend
try{
if(NgGetElementById(_LegendLayer).style.display=='block')
{
     HandleLegendFrame(null);
}
} catch(e){ }

//Print Pan
try{
if(NgGetElementById(_PrintLayer).style.display=='block')
{

     HandlePrintFrame(null);
}
} catch(e){ }


//Reports Pan
try{
if(NgGetElementById(_ReportsLayer).style.display=='block')
{

     HandleReportsFrame(null);
}
} catch(e){ }


//Search Pan
try{
if(NgGetElementById(_SearchControlLayer).style.display=='block')
{

     HandleSearchFrame(null);
}
} catch(e){ }

//NearbySearch Pan
try{
if(NgGetElementById(_NearbySearchControlLayer).style.display=='block')
{

     HandleNearbySearchFrame(null);
}
} catch(e){ }

//Attribute Editor Pan
try{

if(NgGetElementById(_AttributeEditorLayer).style.display=='block')
{
      // This function is located in editorcontrol.js and is called to rebuild the AttributeEditor Window/popup.
      ShowAttributeEditor();
}
} catch(e){ }


//Set the Vertex Editing toolbar to False on Submit
try{

if(NgGetElementById(_VertexToolbarPan)!=null )
{  
if(NgGetElementById(_VertexToolbarPan).style.display!='none')
    HideLayer(_VertexToolbarPan);
}

//            if(NgGetElementById(_EditingVertexToolbarPan)!=null )
//            { 
//             if( NgGetElementById(_EditingVertexToolbarPan).style.display !='none')
//                 HideLayer(_EditingVertexToolbarPan);
//            }

} catch(e){ }


try{
if(NgGetElementById(_RetriveSelectionLayer).style.display=='block')
{
     HandleRetriveSelectionFrame(null);
}
} catch(e){ }


try{
if(NgGetElementById(_GenerateUrlLayer).style.display=='block')
{
     HandleGenerateUrlFrame(null);
}
} catch(e){ }



}
        
function OverrideASPNetMenuFunction()
{
        
      try
     {
       
        var oldMenu_HideItems = Menu_HideItems;	
        if(oldMenu_HideItems)
        {
            Menu_HideItems = function(items)
            {
                if (!items || ((typeof(items.tagName) == "undefined") && (items instanceof Event)))
                {
                    items = __rootMenuItem;
                }
                if(items && items.rows && items.rows.length == 0)
                {
                    items.insertRow(0); 
                }
	            return oldMenu_HideItems(items);
            } 
        }
    }
    catch(e){}
     
    
  
  
}

        
        

    //-------------------------
    function HandleInfoToolFrame(url){   

          if (url==null)
                {
                  url=NgGetElementById(_InfoURLHolder).value;
                }
        
        if (NgGetElementById(_InfoLayer)!=null)
       	    {
	         ShowLayer(_InfoLayer, null,null);
	       
            if (url !=null)
                {
                 PopulateiFrame(_InfoiFrame,url,null,null)
                 //Save the URL for postback.
                 NgGetElementById(_InfoURLHolder).value=url;
		        }
	   }
	   return;	
	}
	
    //-------------------------	
    function HandleLegendFrame(url)
        {            
        
           if (url==null)
            {
                  url=NGServerUrl()+ "/Webpages/Map/Legend.aspx";
            }      

            try{
                if (NgGetElementById(_LegendLayer)!=null)
                 {
                    ShowLayer(_LegendLayer,null,null);
                    PopulateiFrame(_LegendiFrame,url,null,null);
                 }
            }catch(e){}
        }


    //-------------------------	
    function HandlePrintFrame(url)
    {
       if (url ==null)
              url=NgGetElementById(_PrintURLHolder).value;
    
       if (NgGetElementById(_PrintLayer)!=null)
              ShowLayer(_PrintLayer, null,null);
                
            if (url !=null){
                 if (NgGetElementById(_PrintiFrame)!=null)
                     {
                      PopulateiFrame(_PrintiFrame,url,null,null);
                      NgGetElementById(_PrintURLHolder).value=url;
                     }
              }        
      
        return;
      
    }

  //-------------------------
    function  HandleOverviewMapFrame(url){
 
   try{
        if (url ==null)
        {
          if (window.NGServerUrl)
                {
	                url=NGServerUrl()+"/WebPages/Map/OverviewMap.aspx";
	            }
            else
	            {
		            url=appBasePath + "/WebPages/Map/OverviewMap.aspx";
	            }
        }
        if(NgGetElementById(_MapOverViewLayer) !=null)
        {
            ShowLayer(_MapOverViewLayer, null,null);

            if (NgGetElementById(_MapOverViewiFrame)!= null)
            {
                PopulateiFrame(_MapOverViewiFrame,url,null,null); 
            }

        }
    }catch(e){}
   return; 
    
  }
    
      //-------------------------
      function HandleAttributeEditerFrame(url){   
        
         if(NgGetElementById(_AttributeEditorLayer) !=null)
         {
               ShowLayer(_AttributeEditorLayer, null,null);   
            
                if (url ==null)
                    url=NgGetElementById(_AttributeEditorURLHolder).value;
                
                if (url !=null)
                {
                  PopulateiFrame(_AttributeeditoriFrame,url,null,null); 
		          //keep the URL for postback.
		          NgGetElementById(_AttributeEditorURLHolder).value=url;
		        }
         }
            
		    return;

        }

    //-------------------------	
    function HandleReportsFrame(url)
    {
  
       if (NgGetElementById(_ReportsLayer)!=null)
        {
            ShowLayer(_ReportsLayer, null,null);

            if(url==null)
                {
                    url=NgGetElementById(_ReportsURLHolder).value;        
                }

            if (url !=null)
                {
                    PopulateiFrame(_ReportsiFrame,url,null,null);
                    NgGetElementById(_ReportsURLHolder).value=url;
                }
        }
        return;
    }
  //-------------------------	
   
  //-------------------------	
    function HandleSearchFrame(url)
    {
    
       if (NgGetElementById(_SearchControlLayer)!=null)
        {
            ShowLayer(_SearchControlLayer, null,null);

            if(url==null)
                {
                    url=NgGetElementById(_SearchControlURLHolder).value;        
                }

            if (url !=null)
                {
                    PopulateiFrame(_SearchControliFrame,url,null,null);
                    NgGetElementById(_SearchControlURLHolder).value=url;
                }
        }
        return;
    }

  //-------------------------	
     function PopulateiFrame(iFrameId,url,iWidth,iHeight)
        {            
            var _iFrame;
                   try{
                         
                      _iFrame=NgGetElementById(iFrameId);
                     } 
                   catch(e){}
              
             if (_iFrame!=null)
                {
                    
                   
                 _iFrame.style.display = 'block';
                 _iFrame.style.visibility='visible';
                 frames[iFrameId].location.href=url;
                //alert(frames[iFrameId].location.href);
                 if (iHeight!=null)
                   _iFrame.height= the_height;
                 if (iWidth!=null)
                   _iFrame.width= the_width;
                }
         }
    
    //-------------------------	
     function CleariFrame(iFrameId)
        {            
            var _iFrame;
            try{
                 _iFrame=NgGetElementById(iFrameId);
               } catch(e){}
            
             if (_iFrame!=null)
                {
                 
                  window.top.frames[iFrameId].location.href='about:blank';
                   _iFrame.style.display = 'none';
                 _iFrame.style.visibility='hidden'
                }
                
         }
         
    //-------------------------	
//    function ResetiFrames()
//     {
//         for (i=0; i<this.frames.length; i++){
//             //  this.frames[i].location.href='about:blank';
//         }
//     }
 
    //-------------------------      
    function calcHeight(iFrameId)
        {
          //find the height of the internal page
          var the_height= document.getElementById(iFrameId).contentWindow.document.body.scrollHeight + 'px';
            //change the height of the iframe
            document.getElementById(iFrameId).height= the_height;
            document.getElementById(iFrameId).style.height= the_height;
         
        }
    
   //------------------------- 
    function calcWidth(iFrameId)
    {
      //find the Width of the internal page
      var the_width= document.getElementById(iFrameId).contentWindow.document.body.scrollWidth + 'px';
      //change the Width of the iframe
      document.getElementById(iFrameId).width= the_width;
      document.getElementById(iFrameId).style.width= the_width;
       
        
    }

 //-------------------------  
    function CollapseExpand(LayerToShow, imageElem){ 
     
         var visible = ToggleLyrVisibility(LayerToShow);
    if (visible)
    {
        imageElem.src=imageElem.getAttribute('collapseimage');
    }
    else
    {
        imageElem.src=imageElem.getAttribute('expandimage');
    }
}

    //-------------------------
    function HideElementByTime(elem, time)
        {
        var the_timeout = setTimeout("HideLayer(" + elem + ",null,null);",time);
        return;
        }
        
        
   
   //-------------------------
   function ResetiFrames(iFrameId, url)
     {
     if(url==null)
         {
            url=NGServerUrl()+'/Webpages/Loading.aspx';
         }
            
         try
         {
         if (NgGetElementById(iFrameId) !=null)
            {
                PopulateiFrame(iFrameId,url,null,null);
            }
         }catch(e){}
     }
    
    

//-----------------------------------

function HidePopupWindow(commoniFrame, commoniFrameWraper)
{

    if(commoniFrame != null && commoniFrameWraper != null)
    {
        var _iFrame;
        try{
                  _iFrame=window.top.NgGetElementById(commoniFrame);
        } catch(e)
        {
        
        }
        
        if (commoniFrameWraper !=null)
        {
            var _iFrameLayer;
              try{
                      _iFrameLayer=window.top.NgGetElementById(commoniFrameWraper);
                 } catch(e){}
                   
            if (_iFrameLayer!=null)
                {
                 HideLayer(commoniFrameWraper,null,null);
                 _iFrameLayer.style.visibility='hidden';            
                }
        }      
        if (_iFrame!=null)
        {
             _iFrame.style.display = 'none';
             HideLayer(commoniFrame,null,null);
             window.top.frames[commoniFrame].location.href='about:blank';
        } 
    }
} 
    function  HandleSessionExpired()
    { 
        
//           If Session is not expired,then Obj contains the value of SessionId;
            
			if(sessionExpired!=false)
			{     
			    alert("Your current Session has Expired.Please Close this window & Login again");			 
			}
	}
	
	
	function VerifySessionExpired()
	{	    
	    var retval = _OnPointWebControls.SessionChecker.CheckSessionExpiry();
	    
	    if(retval.value)
		{
			  sessionExpired = true;
	    }
			
	}



	 function AbandonSession()
{
   // store left top position of border control on browser close

     
    //lanuch a new window, which will check if parent is open after 1 sec.
    //if open, it will just close itself
    //if not open, then it will abandon session     
     var url="/WebPages/Abandon.aspx";;;
     if (window.NGServerUrl)
        {
	        url=NGServerUrl()+url;
        }
    else
        {    	 
	        url = appBasePath + url;
        }
    
    var loc = "width=10,height=10,left=2000,top=2000,titlebar=no,toolbar=no,menubar=no,location=no,status=no";
    
    window.open(url,"onpoint_abandon_session",loc,true);
}

//Function check for visible and invisible of more search links
function HandleMoreSearchLink()
{
    
try{
        var d1= document.getElementById('MoreSearchPan');
        var d2= document.getElementById('MoreSearchesDiv');
        if (d1 !=null){
            d2.innerHTML=d2.innerHTML + d1.innerHTML;
            d1.style.display='none';
        }
        else
        {
            d2.style.display='none';
        }
    }catch(e){}

}


 function HandleRetriveSelectionFrame(url)
    {
       
  
       if (NgGetElementById(_RetriveSelectionLayer)!=null)
        {
            ShowLayer(_RetriveSelectionLayer, null,null);

            if(url==null)
                {
                    url=NgGetElementById(_RetriveSelectionURLHolder).value;        
                }

            if (url !=null)
                {
                    PopulateiFrame(_RetriveSelectionIframe,url,null,null);
                    NgGetElementById(_RetriveSelectionURLHolder).value=url;
                }
        }
        return;
    }


    function HandleSaveSelectionFrame(url)
    {
       
  
       if (NgGetElementById(_SaveSelectionLayer)!=null)
        {
            ShowLayer(_SaveSelectionLayer, null,null);

            if(url==null)
                {
                    url=NgGetElementById(_SaveURLHolder).value;        
                }

            if (url !=null)
                {
                    PopulateiFrame(_SaveSelectionIframe,url,null,null);
                    NgGetElementById(_SaveURLHolder).value=url;
                }
        }
        return;
    }


   function HandleGenerateUrlFrame(url)
    {
    
  
       if (NgGetElementById(_GenerateUrlLayer)!=null)
        {
            ShowLayer(_GenerateUrlLayer, null,null);

            if(url==null)
                {
                    url=NgGetElementById(_GenerateUrlURLHolder).value;        
                }

            if (url !=null)
                {
                    PopulateiFrame(_GenerateUrlIframe,url,null,null);
                    NgGetElementById(_GenerateUrlURLHolder).value=url;
                }
        }
        return;
    }

function HideSearchWindow()
{
   
     HidePopupWindow(_SearchIframe,_SearchLayer);      
}

function HandleSearch(SearchId)
{
  
    var url;
    if(SearchId == null)
    { 
        url=NGServerUrl()+ "/Webpages/Search/SearchPopup.aspx"
    }
    else
    {
        url=NGServerUrl()+ "/Webpages/Search/SearchPopup.aspx?SEARCHID=" + SearchId
    }
    try
    {
        if (NgGetElementById(_SearchLayer)!=null)
        {
            ShowLayer(_SearchLayer,null,null);
            NgGetElementById(_SearchLayer).style.visibility='visible'; 
            PopulateiFrame(_SearchIframe,url,null,null);
        }
    }catch(e){} 
}