function disableOrEnableDiv(radElemId, currentdivElemId, searchDivElemId)
{
    var radElem = document.getElementById(radElemId);
    var divElem = document.getElementById(currentdivElemId);

    var searchdivElem = document.getElementById(searchDivElemId);            
    if(searchdivElem != null )
    {
        searchdivElem.style.display= 'none';
    }
    if(radElem != null && divElem != null)
    {            
        if( radElem.checked )
        {               
            divElem.style.display= 'block';
        }
    }
    //This is for popup iFrame. This function exist in NearbysearchPopup.aspx and will reszie the popup according to page content.
    //if (window.init){init();}
}


function PopupNearbySearchWindow()
{
    OpenNearbySearchWindow(false);
}

function ShowNearbySearchWindow()
{
    OpenNearbySearchWindow(true);
}
function OpenNearbySearchWindow(clearSelections)
{
    var path = "/Webpages/Search/NearbySearchPopup.aspx?CLEARSELECTIONS=" + clearSelections;   
    if(window.NGServerUrl)
    {
        path = NGServerUrl() + path;
	}
	else
	{
	    var protocol = window.location.protocol;
		var theHost = window.location.hostname;
		var port = window.location.port;
		
		if (port)
		{
		    port=":"+ port;
		}
		
		var ThePath = window.location.pathname;    
		ThePath = ThePath.substring(0, ThePath.indexOf("/", 1));    
		path = protocol + "//" + theHost + port + ThePath + path;
			
    }
    var searchUrl = path;    
	 //If the function to open this in a iFrame exist then call it else open to a new window.        
	if(window.HandleNearbySearchFrame)
	{
	    HandleNearbySearchFrame(searchUrl);
    }
	else
	{
   	    window.open(searchUrl,"NearbySearchWindow","toolbar=no, directories=no, location=no,status=yes, menubar=no, resizable=yes, scrollbars=auto, width=550, height=500");
	}	
}

function NearbyItemSelected(id,itemId)
{  
   
    //PageMethod to set current item in SecuredNearby
    PageMethods.SetNearbySelectedItem(itemId,PopupNearbySearchWindow);
}

function drpSearchesList_change(drpElementId, hidElementId)
{
    if(drpElementId != null && hidElementId != null)
    {      
        var hidElement = document.getElementById(hidElementId);
        var drpElement = document.getElementById(drpElementId);
        
        if(hidElement != null && drpElement != null)
        {            
            hidElement.value = drpElement.value;               
        }
    }
}
function HideNearbySearchPopupWindow()
{
    var mapViewPage = "/Webpages/Map/MapViewer.aspx";
    try
    {
        mapViewPage = m_mapViewerPage;
    }
    catch(e){}
    try
    {
        var currentPage = window.top.location.href;
        //compare current page with mapViewPage
        if (IsSamePage(mapViewPage.toUpperCase(),currentPage.toUpperCase(),".ASPX"))
        {
            if(window.top.HideNearbySearchWindow)
	        {
	            window.top.HideNearbySearchWindow();
            }
            NgRefreshParentWindow();
        }
        else
        {
            window.top.location.href = mapViewPage;      
        }
    }
    catch (e){}
}

function HandleNearbySearchFrame(url)
{
     
    var nearbysearch = NgGetElementById(_NearbySearchControlLayer);

    if (nearbysearch !=null)
    {
        ShowLayer(_NearbySearchControlLayer, null,null);
        nearbysearch.style.visibility='visible';   

        if(url==null)
        {
            url=NgGetElementById(_NearbySearchURLHolder).value;        
        }

        if (url !=null)
        {
            PopulateiFrame(_NearbySearchiFrame,url,null,null);
            NgGetElementById(_NearbySearchURLHolder).value=url;
        }
    }
    return;
}

function HideNearbySearchWindow()
{
    if(_NearbySearchiFrame != null && _NearbySearchControlLayer != null)
    {
        var _iFrame;
        try
        {
            _iFrame=NgGetElementById(_NearbySearchiFrame);
        }
        catch(e){}

        if (_NearbySearchControlLayer !=null)
        {
            var _iFrameLayer;
            try
            {
                _iFrameLayer=NgGetElementById(_NearbySearchControlLayer);
            }
            catch(e){}

            if (_iFrameLayer!=null)
            {
                HideLayer(_NearbySearchControlLayer,null,null);
                _iFrameLayer.style.visibility='hidden';            
            }
        }      
        if (_iFrame!=null)
        {
            _iFrame.style.display = 'none';
            HideLayer(_NearbySearchiFrame,null,null);
            window.top.frames[_NearbySearchiFrame].location.href='about:blank';
        } 
    }
}
function IsSamePage(page1, page2,extension)
{     
    var trimmedPage1 = _ExtractPage(page1,extension);   
    var trimmedPage2 = _ExtractPage(page2,extension);       
    return trimmedPage1 == trimmedPage2;
} 
function _ExtractPage(page,extension)
{
    var lastFSlash = page.lastIndexOf("/");
    var lastPageExt = page.indexOf(extension,lastFSlash);    
    var trimmedPage = page.substring(lastFSlash,lastPageExt);    
    return trimmedPage;
}