//helper function for AJAX
function GetXmlHttp()
{
    var x = null;
    try
    {
        x = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
        try
        {
            x = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
            x = null;
        }            
    }
    if (!x && typeof XMLHttpRequest != "undefined")
    {
        x = new XMLHttpRequest();            
    }
    return x;
}



var UserIsMovingMap = false;

var GoToCountry;
  function DoAjaxQuery()
{
    //Build the url to call the server
    var url = "WorldMapHttpHandler.ajax?";
    url += "zoom=" + map.GetZoomLevel();
    var countryBox = document.getElementById('selectCountryList');
    var filterBox = document.getElementById('selectFilterList');
    url += "&country=" + countryBox.value;
    if(CurrentPageToShow == null)
    {   
     CurrentPageToShow = 1;
    }
     if(CurrentFilter == null)
    {   
     CurrentFilter = '';
     VievAllInLevel = '';
    }
    if(filterBox.value != null)
    {
	if(filterBox.value.length > 1)
	{
           CurrentFilter = filterBox.value;           
	}
    }
if(TempFilterValue != null)
{
CurrentFilter = TempFilterValue;
}
    
      url += "&filter=" + CurrentFilter;
      url += "&VievAllInLevel=" + VievAllInLevel;
url += "&isCached=true";
    
    url += "&currentPageToShowResultList=" + CurrentPageToShow;
    url += "&rowsPerPage=" + RowsPerPage;
    
    
      var TLpixel = new VEPixel(0, 0);
      var BRpixel = new VEPixel(490, 390);
    
          var TLmapLatLong = map.PixelToLatLong(TLpixel);
           var TLmapLat =  TLmapLatLong.Latitude;
            var TLmapLong =  TLmapLatLong.Longitude;

           var BRmapLatLong = map.PixelToLatLong(BRpixel);
             BRmapLat =  BRmapLatLong.Latitude;
           BRmapLong =  BRmapLatLong.Longitude;
    
    url += "&UserIsMovingMap" + UserIsMovingMap;
UserIsMovingMap = false;
    
     url += "&TLmapLat=" + TLmapLat;
      url += "&TLmapLong=" + TLmapLong;
       url += "&BRmapLat=" + BRmapLat;
        url += "&BRmapLong=" + BRmapLong;

    //put up a loading label
    //ShowLoading();

    //Start by getting the appropriate XMLHTTP object for the browser
    var xmlhttp = GetXmlHttp();
     //If we have a valid xmlhttp object

    if (xmlhttp)
    {

        xmlhttp.open("POST", url, true); // varAsync = true;
        
        //Set the callback.  This function is called when we 
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)  //4 is a success
            {
                //Server code creates javascript "on the fly" for us to
                //execute using eval()
                var result = xmlhttp.responseText;
//alert(result);
              eval(result);            
            }
        }
        xmlhttp.send(null);
    }
//setTimeout(DoAjaxQuery, 5000)
}

function SetCenterAndZoom(Lat, Long)
{
   var currentZoom = map.GetZoomLevel();
   var newZoom;
   if(currentZoom < 3)
   {
        newZoom = 3;
   }
   else
   {
        newZoom = 8;//currentZoom+4;
   }

    map.SetCenterAndZoom(new VELatLong(Lat, Long), newZoom);
}

 

function UpdateResultListHeader(currentPageToShowResultList, numberOfHits)
{
    NumberOfHits = numberOfHits;
   

     pagerPages = Math.ceil(numberOfHits / RowsPerPage);
    var gridView = document.getElementById('resultList');
    var currentHTMLtext = gridView.innerHTML;
    
       if(currentPageToShowResultList > pagerPages)
    {
    currentPageToShowResultList = 0;
    }
    
    if(currentPageToShowResultList > 0)
    {
        currentPageToShowResultList--;
    }
    var highIntervall = (currentPageToShowResultList * RowsPerPage)+ RowsPerPage;
    
    var lowIntervall;
    if(currentPageToShowResultList < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (currentPageToShowResultList) * RowsPerPage;
    }
    var lowestShowItem =  lowIntervall;
    if(numberOfHits > 0)
    {
        lowestShowItem++;
    }
        var highestShowItem;
        
        if(highIntervall > NumberOfHits)
        {
            highestShowItem = NumberOfHits;
        }
        else
        {
         highestShowItem = highIntervall;
        }
    
    gridView.innerHTML ="<div class='search-results'><h2>Results: "+lowestShowItem+" - "+highestShowItem+" of "+NumberOfHits+".</h2>";
    gridView.innerHTML += currentHTMLtext;
    gridView.innerHTML += "</div>";
}


function UpdateResultListEnd()
{
    var gridView = document.getElementById('resultList');
    gridView.innerHTML +="</div>";
}


  function UpdateResultListOLD(iRow,Lat,Long, Title, Type, currentPageToShowResultList)
  { 
// ResultList[iRow]="<ul class='result-listing'><li><h3><a><img src='"+ Type +"' border='0' /></a><a href='javascript:SetCenterAndZoom("+Lat+","+Long+")'>"+Title+"</a></h3></li>";
 ResultList[iRow]="<ul class='map-results-list'><li style='background-image: url("+Type+");'><a href='javascript:SetCenterAndZoom("+Lat+","+Long+")'>"+Title+"</a></li>";
    var gridView = document.getElementById('resultList');
      if(iRow == 0)
  {
  gridView.innerHTML = "";
  }


    if(currentPageToShowResultList > pagerPages)
    {
    currentPageToShowResultList = 0;
    }
    
    if(currentPageToShowResultList > 0)
    {
        currentPageToShowResultList--;
    }
    var highIntervall = (currentPageToShowResultList * RowsPerPage)+RowsPerPage;
    
    var lowIntervall;
    if(currentPageToShowResultList < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (currentPageToShowResultList) * RowsPerPage;
    }

 

    if(iRow < highIntervall && iRow >= lowIntervall) //length of list per page
    { 

    //update existing row
    var currentRow;
    if(currentPageToShowResultList > 1)
    {
      currentRow  = iRow - lowIntervall +1;
    }
    else
    {
        currentRow  = iRow - lowIntervall +1;
    }    
  
  if((pagerPages-1) == currentPageToShowResultList)
  {

     gridView.innerHTML = "";

  }

 if(iRow == lowIntervall)
 {
        var lowestShowItem =  lowIntervall +1;
        var highestShowItem;
        
        if(highIntervall > NumberOfHits)
        {
            highestShowItem = NumberOfHits;
        }
        else
        {
         highestShowItem = highIntervall;
        }
        
        //gridView.innerHTML +="<div class='search-results'><div class='search-info'><h2>Results <strong>"+lowestShowItem+"</strong> - <strong>"+highestShowItem+"</strong> of <strong>"+NumberOfHits+".</h2></div>";
 }
 


        gridView.innerHTML += "<ul class='result-listing'><li><h3><a>"+ Type +"</a><a href='javascript:SetCenterAndZoom("+Lat+","+Long+")'>"+Title+"</a></h3></li>";
 
 if(iRow ==(NumberOfHits -highIntervall))
 {
   // gridView.innerHTML +="</div>";
 }

    }
    
   
}

function UpdateListAgain(currentPageToShow, numberOfHits)
{

var gridView = document.getElementById('resultList');
gridView.innerHTML = "";
UpdateResultListHeader(currentPageToShow, numberOfHits);

   
//ResultList[iRow]="<ul class='result-listing'><li><h3><a>"+ Type +"</a><a href='javascript:SetCenterAndZoom("+Lat+","+Long+")'>"+Title+"</a></h3></li>";


if(currentPageToShow > pagerPages)
    {
    currentPageToShow = 0;
    }
    
    if(currentPageToShow > 0)
    {
        currentPageToShow--;
    }
    var highIntervall = (currentPageToShow * RowsPerPage)+ RowsPerPage;
    
    var lowIntervall;
    if(currentPageToShow < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (currentPageToShow) * RowsPerPage;
    }


    for(var iRow = 0; iRow <numberOfHits; iRow++)
    {
    if(iRow < highIntervall && iRow >= lowIntervall) //length of list per page
    { 

    //update existing row
    var currentRow;
    if(currentPageToShow > 1)
    {
      currentRow  = iRow - lowIntervall +1;
    }
    else
    {
        currentRow  = iRow - lowIntervall +1;
    }    
  
 

 if(iRow == lowIntervall)
 {
        var lowestShowItem =  lowIntervall +1;
        var highestShowItem;
        
        if(highIntervall > NumberOfHits)
        {
            highestShowItem = NumberOfHits;
        }
        else
        {
         highestShowItem = highIntervall;
        }
        
        
 }
 

gridView.innerHTML += ResultList[iRow];   

    }

//alert(iRow);
//alert(lowestShowItem);
     
 


}



UpdateResultListEnd();
}


var ResultList=new Array();

var VievAllInLevel;

var CurrentPageToShow;
var pagerPages;
var RowsPerPage = 8;
var NumberOfHits;

function UpdateListAndPagerOLD(currentPageToShow, numberOfHits)
{

  //DoAjaxQuery2(currentPageToShow, numberOfHits);
   

UpdateListAgain(currentPageToShow, numberOfHits);
    CreateResultListPager(currentPageToShow, numberOfHits);
    
}


function UpdateListAndPager2(currentPageToShow, numberOfHits)
{

  DoAjaxQuery2(currentPageToShow, numberOfHits);
   
    
}



function SetGoToCountry()
{
    GoToCountry = "true";
}






  function DoPostBackResultList(index)
  {
    var zoom = map.GetZoomLevel();
   // var countryBox = document.getElementById('CountryListDropDown');
    // var filterBox = document.getElementById('FilterDropDown');
   
    //var filter = filterBox.value;
   // url += "&country=" + countryBox.value;
   var currentMapPos = map.GetCenter();
   
        javascript:__doPostBack('','ResultPageChangedPostBack,'+index+","+zoom+","+currentMapPos);
  }
  
  function CreateResultListPagerNew(innerHTML)
  {
   var newResultListPager = document.getElementById('newResultListPager');
   newResultListPager.innerHTML = innerHTML;
  }


function RenderMapFilterBelowMapHead()
{
//var innerHTML = "";
//innerHTML += "<ul class='world-map-filter'>";

//var MapFilterDiv = document.getElementById('MapFilterDiv');
//   MapFilterDiv.innerHTML = innerHTML;

}

var BelowMapFilter = "";

function AddMapFilterBelowMap(filter, catID, oldcatID)
{
//alert(oldcatID);
//var MapFilterDiv = document.getElementById('MapFilterDiv');
BelowMapFilter  += "<li style='background-image: url(_layouts/se/Images/WorldMap/ListIcons/map_icon_"+oldcatID+".gif);'><a href='javascript:DoMapFilterAjaxQuery("+catID+");'>"+filter+"</a></li>";
 // MapFilterDiv.innerHTML += innerHTML;

}

function RenderMapFilterEnd()
{

var innerHTML = "";
innerHTML += "<ul class='world-map-filter'>";

//var innerHTML = "";
innerHTML += BelowMapFilter;

//innerHTML += "<li style='background-image: url(_layouts/se/Images/WorldMap/ListIcons/map_icon_multiple.gif);'><a>Multiple locations</a></li>";
innerHTML += "<li style='background-image: url(_layouts/se/Images/WorldMap/ListIcons/map_icon_multiple.gif);'>Multiple</li>";
innerHTML += "<li style='background-image: url(_layouts/se/Images/WorldMap/ListIcons/map_icon_all.gif);'><a href='javascript:DoMapFilterAjaxQuery(-1);'>Show all</a></li>";
                                                                
innerHTML += "</ul>  <br/>  <br/>";
var MapFilterDiv = document.getElementById('MapFilterDiv');
   MapFilterDiv.innerHTML += innerHTML;
}


var CurrentFilter;

function DoFilterAjaxQuery(filter)
{
 var filterBox = document.getElementById('selectFilterList');
//  filterBox.value = filter;
 CurrentFilter = filter;

 DoAjaxQuery();

}



function UpdateFilterBoxValue(filterValue)
{
  var filterBox = document.getElementById('selectFilterList');
  filterBox.value = filterValue;	
}

function SetRowsPerPage(rowsPerPage)
{
    RowsPerPage = 8;
}

var map = null;
function GetMap()
{
//alert('getmap');
    map = new VEMap('world-map');
//map.LoadMap();

    //map.onLoadMap = function(){DoAjaxQuery();};
}    


   function AddPin(lat, lon, iconurl, title, desc)

   {

             var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat,lon));

              shape.SetTitle(title);
//alert(desc);
                shape.SetDescription(desc);
              if(iconurl != null){
              shape.SetCustomIcon(iconurl);
              }
           map.AddShape(shape);

}








 function UpdateResultList(iRow,Lat,Long, Title, Type, currentPageToShowResultList)
  { 

// ResultList[iRow]="<ul class='map-results-list'><li style='background-image: //url("+Type+");'><a //href='javascript:SetCenterAndZoom("+Lat+","+Long+")'>"+Title+"</a></li>";
//    var gridView = document.getElementById('resultList');   


 ResultList[iRow]="<ul class='map-results-list'><li style='background-image: url("+Type+");'><a href='javascript:SetCenterAndZoom("+Lat+","+Long+")'>"+Title+"</a></li>";
    //var gridView = document.getElementById('resultList'); 


}

function InsertResultList(text)
{


//  var gridView = document.getElementById('resultList'); 

//gridView.innerHTML = text;
//alert('beforeff');
 map.Find('','', 1, ProcessResults);
//alert('after');
}



function UpdateResultListToMany()
{
   
    var gridView = document.getElementById('resultList'); 
    gridView.innerHTML ="<div class='search-results'><h2>Results: Too many results found.</h2>";
    gridView.innerHTML += "<ul class='map-results-list'><li><a>Too many results found please use the zoom to lower this result.</a></li>";;
    gridView.innerHTML += "</div>";
}





function CreateResultListPagerOLD(currentPageToShow, numberOfHits)
{

NumberOfHits = numberOfHits;
pagerPages = Math.ceil(numberOfHits / RowsPerPage);



     if(currentPageToShow > pagerPages)
    {
        currentPageToShow = 1;
        CurrentPageToShow = currentPageToShow;
        UpdateListAgain(currentPageToShow, numberOfHits);
    }
CurrentPageToShow = currentPageToShow;
var gridView = document.getElementById('resultList');
  
 
    if(NumberOfHits > 0)
    {
    

  
  
  if(numberOfHits > 0)
  {
//gridView.innerHTML += "<div class='search-results'>";
gridView.innerHTML += "<div class='search-results'><div class='paging'><strong class='structural'>Result Page:</strong>";
}

   
   
    
    var maxpoint;

if(pagerPages <= 5)
{
maxpoint  =pagerPages;
}
else
{
maxpoint = Math.max(5, Math.min(pagerPages, currentPageToShow + 2));
}

var lowpoint = Math.max(1, (currentPageToShow - 2)); 

     if (pagerPages > 1 && currentPageToShow > 1)
    {
    var prev = currentPageToShow -1;
         gridView.innerHTML +="<a class='prev' href='javascript:UpdateListAndPager("+prev+","+NumberOfHits+")'>Previous</a><span>, </span>";
    }
    //checkIfNearEnd = Math.max(1, (currentPageToShow - 2)); 
   if(currentPageToShow > 3 && currentPageToShow +2 >= pagerPages)
   {
     if(pagerPages - currentPageToShow == 0)
     {
      lowpoint = lowpoint - 2;
     }
      if(pagerPages - currentPageToShow == 1)
      {
          lowpoint = lowpoint - 1;
      }
    
   }

for (var i = lowpoint; i <= maxpoint ; i++)                
    
    {
   
    var pageLink = "Page$"+i;
    if(currentPageToShow == 0)
    {
         currentPageToShow++;
    }
    
  
  
   if(i == currentPageToShow)
   {
        gridView.innerHTML += "<em>"+i+"</em><span>, </span>";

   }
   else
   {

     
   
    
    gridView.innerHTML += "<a href='javascript:UpdateListAndPager("+i+","+NumberOfHits+")'>"+i+"</a><span>, </span>";
    }
      
      
      
    }
    //if(i == pagerPages && pagerPages > 1 && currentPageToShow < pagerPages)
         //if ((currentPageToShow + 1) != pagerPages && pagerPages > (currentPageToShow + 1))
         if (pagerPages > currentPageToShow)
      {
      var next = currentPageToShow+1;
       gridView.innerHTML += "<a class='next' href='javascript:UpdateListAndPager("+next+","+NumberOfHits+")'>Next</a></div></div>";
      }
     //gridView.innerHTML += "</div></div>";
//alert(gridView.innerHTML);

 
}}





 function DoAjaxQuery2(currentPageToShow, PinCount)
{
    //Build the url to call the server
    var url = "WorldMapHttpHandler.ajax?";
    url += "zoom=" + map.GetZoomLevel();
    var countryBox = document.getElementById('selectCountryList');
    var filterBox = document.getElementById('selectFilterList');
    url += "&country=" + countryBox.value;
    
     CurrentPageToShow = currentPageToShow;
    
     if(CurrentFilter == null)
    {   
     CurrentFilter = '';
     VievAllInLevel = '';
    }
    if(filterBox.value != null)
    {
	if(filterBox.value.length > 1)
	{
           CurrentFilter = filterBox.value;           
	}
    }
    
      url += "&filter=" + CurrentFilter;
      url += "&VievAllInLevel=" + VievAllInLevel;
    
    url += "&currentPageToShowResultList=" + CurrentPageToShow;
    url += "&rowsPerPage=" + RowsPerPage;
//url  += "&KeepPins=" + PinCount; 
    
    
      var TLpixel = new VEPixel(0, 0);
      var BRpixel = new VEPixel(490, 390);
    
          var TLmapLatLong = map.PixelToLatLong(TLpixel);
           var TLmapLat =  TLmapLatLong.Latitude;
            var TLmapLong =  TLmapLatLong.Longitude;

           var BRmapLatLong = map.PixelToLatLong(BRpixel);
             BRmapLat =  BRmapLatLong.Latitude;
           BRmapLong =  BRmapLatLong.Longitude;
    
    
    
     url += "&TLmapLat=" + TLmapLat;
      url += "&TLmapLong=" + TLmapLong;
       url += "&BRmapLat=" + BRmapLat;
        url += "&BRmapLong=" + BRmapLong;

    //put up a loading label
    //ShowLoading();

    //Start by getting the appropriate XMLHTTP object for the browser
    var xmlhttp = GetXmlHttp();
     //If we have a valid xmlhttp object

    if (xmlhttp)
    {

        xmlhttp.open("GET", url, true); // varAsync = true;
        
        //Set the callback.  This function is called when we 
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)  //4 is a success
            {
                //Server code creates javascript "on the fly" for us to
                //execute using eval()
                var result = xmlhttp.responseText;

              eval(result);            
            }
        }
        xmlhttp.send(null);
    }

}


function CreateResultListPager2(currentPageToShow, numberOfHits)
{

NumberOfHits = numberOfHits;
pagerPages = Math.ceil(numberOfHits / RowsPerPage);




     if(currentPageToShow > pagerPages)
    {
        currentPageToShow = 1;
        CurrentPageToShow = currentPageToShow;
        UpdateListAgain(currentPageToShow, numberOfHits);
    }
CurrentPageToShow = currentPageToShow;
var gridView = document.getElementById('resultList');
  
 
    if(NumberOfHits > 0)
    {
    

  
  
  if(numberOfHits > 0)
  {
//gridView.innerHTML += "<div class='search-results'>";
gridView.innerHTML += "<div class='search-results'><div  class='paging'><strong class='structural'>Result Page:</strong>";
}

   
   
    
    var maxpoint;

if(pagerPages <= 5)
{
maxpoint  =pagerPages;
}
else
{
maxpoint = Math.max(5, Math.min(pagerPages, currentPageToShow + 2));
}

var lowpoint = Math.max(1, (currentPageToShow - 2)); 

     if (pagerPages > 1 && currentPageToShow > 1)
    {
    var prev = currentPageToShow -1;
         gridView.innerHTML +="<a class='prev' href='javascript:UpdateListAndPager2("+prev+","+NumberOfHits+")'>Previous</a><span>, </span>";
    }
      //checkIfNearEnd = Math.max(1, (currentPageToShow - 2)); 
   if(currentPageToShow > 3 && currentPageToShow +2 >= pagerPages)
   {
     if(pagerPages - currentPageToShow == 0)
     {
      lowpoint = lowpoint - 2;
     }
      if(pagerPages - currentPageToShow == 1)
      {
          lowpoint = lowpoint - 1;
      }
    
   }

for (var i = lowpoint; i <= maxpoint ; i++)                
    
    {
   
    var pageLink = "Page$"+i;
    if(currentPageToShow == 0)
    {
         currentPageToShow++;
    }
    
  
  
   if(i == currentPageToShow)
   {
        gridView.innerHTML += "<em>"+i+"</em><span>, </span>";

   }
   else
   {

     
   
    
    gridView.innerHTML += "<a href='javascript:UpdateListAndPager2("+i+","+NumberOfHits+")'>"+i+"</a><span>, </span>";
    }
      
      
      
    }
    //if(i == pagerPages && pagerPages > 1 && currentPageToShow < pagerPages)
         //if ((currentPageToShow + 1) != pagerPages && pagerPages > (currentPageToShow + 1))
            if (pagerPages > currentPageToShow)
      {
      var next = currentPageToShow+1;
       gridView.innerHTML += "<a class='next' href='javascript:UpdateListAndPager2("+next+","+NumberOfHits+")'>Next</a></div></div>";
      }
     // gridView.innerHTML += "</div></div>";
//alert(gridView.innerHTML);
 
}}











function ProcessResults(findResults)
{
//alert('under');
 var gridView = document.getElementById('resultList'); 


  var results ="<table><tr><td colspan=3 align='center'>Find results</td></tr>";
  results += "<tr><td>Name</td><td>Description</td><td style='width: 100px;'>Phone</td></tr>";

  var numresults = 5;
  numresults = Math.min(numresults, findResults.length);

  for (r=0; r<numresults; r++)
  {
     results += "<tr><td>";
     if (findResults[r].Name!=null) //VEFindResult objects
     {

      results += findResults[r].Name + "</td><td>";
      results += findResults[r].Description + "</td><td style='width: 100px;'>";
      results += findResults[r].Phone;
     }
     else
     {
     results += "Unknown</td><td>N/A";
     }
     results += "</td></tr>";
  }
  results += "</table>";

//  var resultPane = document.getElementById('SearchResults');
  //resultPane.style.display = 'block';
//  resultPane.innerHTML = results;
gridView.innerHTML = text;
}




 function AddMyLayer()
{
var path = "GeoRSSProxy.ashx?source=" + url;
            var l = new VEShapeLayer();      
      var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, path, l);  
          map.ImportShapeLayerData(veLayerSpec, onFeedLoad); 
 }



 function ReadRSSFeed()
{
    //Build the url to call the server
    var url = "WorldMapHttpHandler.ajax?";
    url += "isCached=false";
    

var l = new VEShapeLayer();      
//alert(result);
//alert(url);
//alert('fff');
      var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, url, l);  
          map.ImportShapeLayerData(veLayerSpec, onFeedLoad); 

//    //Start by getting the appropriate XMLHTTP object for the browser
//    var xmlhttp = GetXmlHttp();
//     //If we have a valid xmlhttp object

//    if (xmlhttp)
//    {

//        xmlhttp.open("GET", url, true); // varAsync = true;
        
//        //Set the callback.  This function is called when we 
//        xmlhttp.onreadystatechange = function()
//        {
//            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)  //4 is a success
//            {
//                //Server code creates javascript "on the fly" for us to
//                //execute using eval()
//                var result = xmlhttp.responseText;
////alert(result);
//  //            eval(result);            

////DO stuff
// var l = new VEShapeLayer();      
//alert(result);
//      var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, url, l);  
//          map.ImportShapeLayerData(veLayerSpec, onFeedLoad); 

//            }
//        }
//        xmlhttp.send(null);
//    }

}

function onFeedLoad(feed)         {            alert('RSS or Collection loaded. There are ' + feed.GetShapeCount() + ' items in this list.');         }




var layer = null;
var selIndex = 0;
var index = 0;
var shapes = "";
var shapeID = null;
var ShapeCountInLayer = 0;

function CreateLayer(CatID)
{
	layer = "layer"+ CatID;
layer = new VEShapeLayer();
layer.SetTitle("layer"+ CatID);
//alert(layer.GetTitle());
	
	map.AddShapeLayer(layer);
}


function GetSpecificLayer(layerID)
{
	layer = map.GetShapeLayerByIndex(i);
}

function GetLayerShapeCount(layerID)
{
	layer = map.GetShapeLayerByIndex(i);
	ShapeCountInLayer = layer.GetShapeCount();
}

function GetCurrentLayerShapeCount()
{

	if(layer != null)
	{
		ShapeCountInLayer = layer.GetShapeCount();
	}
}

var savedTempLayer = null;
//var savedTempLayerIndex;


function ShowLayer()
{

if(selIndex != -1)
{

    layer = map.GetShapeLayerByIndex(selIndex);

    if(CurrentCountryName == "Show all")
    {
        if(!layer.IsVisible())
        {	
            layer.Show();
        }
    }
    else
    {
        if(savedTempLayer == null)
        {
            savedTempLayer = new VEShapeLayer();  
        }
        savedTempLayer.DeleteAllShapes();
        if(!layer.IsVisible())
        {	   
            for (r=layer.GetShapeCount()-1; r>=0; r--)
            {
                var currentShape = layer.GetShapeByIndex(r);
                if(CurrentCountryName != null && CurrentCountryName != "Show all")
                {
		    var currentPinCountry = currentShape.GetDescription();
                    var exists = currentPinCountry.match(CurrentCountryName);

                    if(exists != null)
                    {
                        var shape = new VEShape(VEShapeType.Pushpin, currentShape.GetPoints());
                        shape.SetTitle(currentShape.GetTitle());
                        shape.SetDescription(currentShape.GetDescription());
                        shape.SetPhotoURL(currentShape.GetPhotoURL());

                        if(currentShape.GetCustomIcon() != null)
                        {
          	                shape.SetCustomIcon(currentShape.GetCustomIcon());
                        }

                        savedTempLayer.AddShape(shape);


                    }
                }
            }       
        }
        try
        {
            map.AddShapeLayer(savedTempLayer);
        }
        catch(err)
        {
        }

        layer = savedTempLayer;

        savedTempLayer.Show();
        
    }
}
else
{
if(savedTempLayer == null)
        {
            savedTempLayer = new VEShapeLayer();  
        }
savedTempLayer.DeleteAllShapes();
var arrayOfIndexNotToUse = LayerIndexesNotToUseInShowAll.split(",")

	 for (layerIndex=map.GetShapeLayerCount()-1; layerIndex>=0; layerIndex--)
         {
		var stepToNextLayer = "false";

			for(m=0; m < arrayOfIndexNotToUse.length; m++)
			{


				if(parseInt(arrayOfIndexNotToUse[m]) == layerIndex)
				{
				stepToNextLayer = "true";
					
				}

			}


if(stepToNextLayer != "true")
{


 		currentLayer =	map.GetShapeLayerByIndex(layerIndex);


  for (r=currentLayer.GetShapeCount()-1; r>=0; r--)
            {

                var currentShape = currentLayer.GetShapeByIndex(r);

                if(CurrentCountryName != null && CurrentCountryName != "Show all")
                {
		    var currentPinCountry = currentShape.GetDescription();
                    var exists = currentPinCountry.match(CurrentCountryName);

                    if(exists != null)
                    {
                        var shape = new VEShape(VEShapeType.Pushpin, currentShape.GetPoints());
                        shape.SetTitle(currentShape.GetTitle());
                        shape.SetDescription(currentShape.GetDescription());
                        shape.SetPhotoURL(currentShape.GetPhotoURL());

                        if(currentShape.GetCustomIcon() != null)
                        {
          	                shape.SetCustomIcon(currentShape.GetCustomIcon());
                        }

                        savedTempLayer.AddShape(shape);


                    }
                }
            }  
		
	 }
    try
        {

            map.AddShapeLayer(savedTempLayer);
        }
        catch(err)
        {
        }
}

        layer = savedTempLayer;
//alert(savedTempLayer.GetShapeCount());
if(!savedTempLayer.IsVisible())
        {	
            savedTempLayer.Show();
        }
      
}
}



function ShowAllLayers()
{


var currentZooom = map.GetZoomLevel();
var LongLat = map.GetCenter();


	map.ShowAllShapeLayers();
 map.SetCenterAndZoom(LongLat , currentZooom);

}

function HideAllLayers()
{
	map.HideAllShapeLayers();
}


function AddPinToLayerByBatch(shapeArray, layerID)
{
           layer = map.GetShapeLayerByIndex(layerID);
           layer.AddShape(shapeArray);
}

  function AddPinToLayer(lat, lon, iconurl, title, desc, layerID, resultListTitle)

   {
             var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat,lon));

              shape.SetTitle(title);
                shape.SetDescription(desc);

shape.SetPhotoURL(resultListTitle);

              if(iconurl != null){
              shape.SetCustomIcon(iconurl);
              }
	layer = map.GetShapeLayerByIndex(layerID);
           layer.AddShape(shape);

}





function CreatePinResultsTable()
{
	var startIndex = 0;	
var count = layer.GetShapeCount();

if(CurrentPageToShow == null || CurrentPageToShow == 1)
{
CurrentPageToShow = 0;

}
CurrentPageToShow = 0;

 var highIntervall = (CurrentPageToShow * RowsPerPage)+ RowsPerPage;
    
    var lowIntervall;
    if(CurrentPageToShow < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (CurrentPageToShow) * RowsPerPage;
    }


        var lowestShowItem =  lowIntervall +1;
        var highestShowItem;
        
        if(highIntervall > count)
        {
            highestShowItem = count;
        }
        else
        {
         highestShowItem = highIntervall;
        }
        
        
 


	if(layer == null)
	{
		layer = map.GetShapeLayerByIndex(0);
	}
	
	var resultTable = document.getElementById('resultList'); 
	resultTable.innerHTML = "";

if(count > 0)
{
	var resultText = "Results: Listing " + (startIndex + 1) + "-" + highestShowItem + " of " + count + ".";
	resultTable.innerHTML += "<div class='search-results'><h2>" + resultText + "</h2><ul class='map-results-list'>";


	for (i=startIndex; i<count && i < highestShowItem; i++)
	{
			






		  var shape = layer.GetShapeByIndex(i);










		var url = shape.GetCustomIcon();
		var ImageUrl = url.CustomHTML;
		var Title = shape.GetPhotoURL();
		//alert(shape.GetDescription());
		var points = shape.GetPoints();

		var Lat = points[0].Latitude;
		var Long = points[0].Longitude;



		resultTable.innerHTML += "<ul class='map-results-list'><li style='background-image: url(" + ImageUrl + ");'><a href='javascript:SetCenterAndZoom(" + Lat + "," + Long + ")'>" + Title + "</a></li>";
//		                         "<li style=\"background-image: url(" + ImageUrl + ");\"><a href=\"javascript:SetCenterAndZoom(" + Lat + "," + Long + ")\">" + Title + "</a></li>";
}

	


resultTable.innerHTML += "</div>";
}
else
{
var resultText = "Results: No results where found.";
	resultTable.innerHTML = "<div class='search-results'><h2>" + resultText + "</h2>";
}


	


CreateResultListPager(CurrentPageToShow, count);


}




function MoreResults(layer, resultsArray, places, hasMore, veErrorMessage)
         {
            if(hasMore)
            {
               var r = "<a href='#' onclick='javascript:FindLoc(parseInt(txtNumResults.value));'>" +
                       "Click for More Results</a>";
               document.getElementById('results').innerHTML = r;
            }
            else
            {
//alert(places);
//alert(resultsArray);
//alert( veErrorMessage);

if(resultsArray != null)
{
		var count = resultsArray.length;

		for (i=0; i<count; i++)
		{
		var resultTable = document.getElementById('resultList');
		var shape = resultsArray[0].Shape;
		var url = shape.GetCustomIcon();
		var ImageUrl = url.CustomHTML;
		var Title = shape.GetPhotoURL();
		//alert(shape.GetDescription());
		var points = shape.GetPoints();

		var Lat = points[0].Latitude;
		var Long = points[0].Longitude;



		resultTable.innerHTML += "<ul class='map-results-list'><li style='background-image: url(" + ImageUrl + ");'><a href='javascript:SetCenterAndZoom(" + Lat + "," + Long + ")'>" + Title + "</a></li>";

	        }  

            }
         }
}


function CreatePinResultsTableOLD()
{

if(layer != null)
{
//alert(layer.GetTitle());
	var results = map.Find('E',null, null, layer, index, 8, true, true, true, true, MoreResults);                               
}
}









function CreateResultListPager(currentPageToShow, numberOfHits)
{
CurrentPageToShow = currentPageToShow;
CreateResultListPagerFind(currentPageToShow, numberOfHits);
}






function CreateResultListPagerFind(currentPageToShow, numberOfHits)
{

NumberOfHits = numberOfHits;
pagerPages = Math.ceil(numberOfHits / RowsPerPage);

var currentResultPagerString = '';

     if(currentPageToShow > pagerPages)
    {
        currentPageToShow = 1;
        CurrentPageToShow = currentPageToShow;
        UpdateListAgain(currentPageToShow, numberOfHits);
    }
CurrentPageToShow = currentPageToShow;
var gridView = document.getElementById('resultList');
  
 
    if(NumberOfHits > 0)
    {
    

  
  
  if(numberOfHits > 0)
  {

currentResultPagerString  += "<div class='search-results'><div  class='paging'><strong class='structural'>Result Page:</strong>";
}

   
   
    
    var maxpoint;

if(pagerPages <= 5)
{
maxpoint  =pagerPages;
}
else
{
maxpoint = Math.max(5, Math.min(pagerPages, currentPageToShow + 2));
}

var lowpoint = Math.max(1, (currentPageToShow - 2)); 

     if (pagerPages > 1 && currentPageToShow > 1)
    {
    var prev = currentPageToShow -1;
         currentResultPagerString  +="<a class='prev' href='javascript:UpdateListAndPager("+prev+","+NumberOfHits+")'>Previous</a><span>, </span>";
    }
     //checkIfNearEnd = Math.max(1, (currentPageToShow - 2)); 
   if(currentPageToShow > 3 && currentPageToShow +2 >= pagerPages)
   {
     if(pagerPages - currentPageToShow == 0)
     {
      lowpoint = lowpoint - 2;
     }
      if(pagerPages - currentPageToShow == 1)
      {
          lowpoint = lowpoint - 1;
      }
    
   }

for (var i = lowpoint; i <= maxpoint ; i++)                
    
    {
   
    var pageLink = "Page$"+i;
    if(currentPageToShow == 0)
    {
         currentPageToShow++;
    }
    
  
  
   if(i == currentPageToShow)
   {
        currentResultPagerString  += "<em>"+i+"</em><span>, </span>";

   }
   else
   {

     
   
    
    currentResultPagerString  += "<a href='javascript:UpdateListAndPager("+i+","+NumberOfHits+")'>"+i+"</a><span>, </span>";
    }
      
      
      
    }
    //if(i == pagerPages && pagerPages > 1 && currentPageToShow < pagerPages)
        // if ((currentPageToShow + 1) != pagerPages && pagerPages > (currentPageToShow + 1))
           if (pagerPages > currentPageToShow)
      {
      var next = currentPageToShow+1;
       currentResultPagerString  += "<a class='next' href='javascript:UpdateListAndPager("+next+","+NumberOfHits+")'>Next</a>";
      }

currentResultPagerString  += "</div></div>";
      gridView.innerHTML += currentResultPagerString;


 
}}

function UpdateListAndPager(currentPageToShow, numberOfHits)
{


   

CreatePinResultsTableNewPage(currentPageToShow, numberOfHits);
  
    CreateResultListPager(currentPageToShow, numberOfHits);
}




function CreatePinResultsTableNewPage(currentPageToShow, numberOfHits)
{
	var startIndex = 0;	
var count = numberOfHits;

CurrentPageToShow = currentPageToShow -1;



 var highIntervall = (CurrentPageToShow * RowsPerPage)+ RowsPerPage;
    
    var lowIntervall;
    if(CurrentPageToShow < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (CurrentPageToShow) * RowsPerPage;
    }


        var lowestShowItem =  lowIntervall +1;
        var highestShowItem;
        
        if(highIntervall > count)
        {
            highestShowItem = count;
        }
        else
        {
         highestShowItem = highIntervall;
        }
        
        	
	
	var resultTable = document.getElementById('resultList'); 
	resultTable.innerHTML = "";

if(count > 0)
{ 
	var resultText = "Results: Listing " + (lowIntervall + 1) + "-" + highestShowItem + " of " + count + ".";
	resultTable.innerHTML += "<div class='search-results'><h2>" + resultText + "</h2><ul class='map-results-list'>";
	for (i=lowIntervall; i<count && i < highestShowItem; i++)
	{
		  var shape = layer.GetShapeByIndex(i);
		var url = shape.GetCustomIcon();
		var ImageUrl = url.CustomHTML;
		var Title = shape.GetPhotoURL();
		//alert(shape.GetDescription());
		var points = shape.GetPoints();

		var Lat = points[0].Latitude;
		var Long = points[0].Longitude;



		resultTable.innerHTML += "<ul class='map-results-list'><li style='background-image: url(" + ImageUrl + ");'><a href='javascript:SetCenterAndZoom(" + Lat + "," + Long + ")'>" + Title + "</a></li>";
//		                         "<li style=\"background-image: url(" + ImageUrl + ");\"><a href=\"javascript:SetCenterAndZoom(" + Lat + "," + Long + ")\">" + Title + "</a></li>";

	}
resultTable.innerHTML += "</div>";
}
else
{
var resultText = "Results: No results where found.";
	resultTable.innerHTML = "<div class='search-results'><h2>" + resultText + "</h2>";
}


	





}


function DoMapFilterAjaxQuery(filter)
{
 var filterBox = document.getElementById('selectFilterList');
  filterBox.value = filter;

GoButton_Clicked()

}


   var CurrentCountryName;

function GoButton_Clicked()
{
      var countryBox = document.getElementById('selectCountryList');
      var countryValue = countryBox.value;
      var filterBox = document.getElementById('selectFilterList');
      var filterValue = filterBox.value;


CurrentCountryName = countryValue;

if(countryValue != null && countryValue != '')
{


if(countryValue == "Show all")
{
  map.SetCenterAndZoom(new VELatLong(34,-39), 1);
}
else
{

 map.Find(null, countryValue);
}

}

if(filterValue != null && filterValue != '')
{


if(filterValue == "-1" && countryValue == "Show all")
{

	ShowAllLayers();
	//CreateResultPinShowAll();
	
	CreateResultPinShowAllNoMultipleLoc();

}
else
{
HideAllLayers();
selIndex = filterValue;
ShowLayer();
if(filterValue == "-1")
{
    CreatePinResultsTableNoMultipleLoc();
}
else
{
    CreatePinResultsTable();
}
}


 
}

   
}





function CreateResultPinShowAll()
{

	var startIndex = 0;	
var count = 0;

  var layerscount = map.GetShapeLayerCount();
	for (i=0; i<layerscount; i++)
	{


		var stepToNextLayer = "false";

		if(LayerIndexesNotToUseInShowAll != null)
		{
			var arrayOfIndexNotToUse = LayerIndexesNotToUseInShowAll.split(",")

			for(m=0; m < arrayOfIndexNotToUse.length; m++)
			{


				if(parseInt(arrayOfIndexNotToUse[m]) == i)
				{
				stepToNextLayer = "true";
					
				}

			}
		}

if(stepToNextLayer != "true")
{
		var currlayer = map.GetShapeLayerByIndex(i);
		count = count +currlayer.GetShapeCount();
}
	} 

if(CurrentPageToShow == null || CurrentPageToShow == 1)
{
CurrentPageToShow = 0;

}

CurrentPageToShow = 0;
 var highIntervall = (CurrentPageToShow * RowsPerPage)+ RowsPerPage;
    
    var lowIntervall;
    if(CurrentPageToShow < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (CurrentPageToShow) * RowsPerPage;
    }


        var lowestShowItem =  lowIntervall +1;
        var highestShowItem;
        
        if(highIntervall > count)
        {
            highestShowItem = count;
        }
        else
        {
         highestShowItem = highIntervall;
        }
               	
	
	var resultTable = document.getElementById('resultList'); 
	resultTable.innerHTML = "";

if(count > 0)
{
	var resultText = "Results: Listing " + (startIndex + 1) + "-" + highestShowItem + " of " + count + ".";
	resultTable.innerHTML += "<div class='search-results'><h2>" + resultText + "</h2><ul class='map-results-list'>";
var addedPinindex = 0;
var index = 0;
	//for (i=startIndex; i<count && i < highestShowItem; i++)
	//{

			var breaker= "false";

		 var layerscount = map.GetShapeLayerCount();

	for (j=0; j<layerscount; j++)
	{
if(breaker == "true")
{

break;
}
		var stepToNextLayer = "false";
		if(LayerIndexesNotToUseInShowAll != null)
		{
			var arrayOfIndexNotToUse = LayerIndexesNotToUseInShowAll.split(",")

			for(m=0; m < arrayOfIndexNotToUse.length; m++)
			{


				if(parseInt(arrayOfIndexNotToUse[m]) == j)
				{
				stepToNextLayer = "true";
					
				}

			}
		}

if(stepToNextLayer != "true")
{
		var currlayer = map.GetShapeLayerByIndex(j);
	   for (k=0; k<currlayer.GetShapeCount(); k++)
	   {
		//index = index +currlayer.GetShapeCount();

		if(index >= lowIntervall && index < highestShowItem)
		 {
				  var shape = currlayer.GetShapeByIndex(k);
		var url = shape.GetCustomIcon();
		var ImageUrl = url.CustomHTML;
		var Title = shape.GetPhotoURL();
		//alert(shape.GetDescription());
		var points = shape.GetPoints();

		var Lat = points[0].Latitude;
		var Long = points[0].Longitude;



		resultTable.innerHTML += "<ul class='map-results-list'><li style='background-image: url(" + ImageUrl + ");'><a href='javascript:SetCenterAndZoom(" + Lat + "," + Long + ")'>" + Title + "</a></li>";
		//addedPinindex++;
		}
if(index > highestShowItem)
{
breaker = "true";
break;
}
		index++;
           }
	}
	//} 
}

	
resultTable.innerHTML += "</div>";
}
else
{
var resultText = "Results: No results where found.";
	resultTable.innerHTML = "<div class='search-results'><h2>" + resultText + "</h2>";
}
CreateResultListPagerFindShowAll(CurrentPageToShow, count);
}


function UpdateListAndPagerShowAll(currentPageToShow, numberOfHits)
{


   

CreatePinResultsTableNewPageShowAll(currentPageToShow, numberOfHits);
  
    CreateResultListPagerFindShowAll(currentPageToShow, numberOfHits);
}






function CreatePinResultsTableNewPageShowAll(currentPageToShow, numberOfHits)
{
	var startIndex = 0;	
var count = numberOfHits;

CurrentPageToShow = currentPageToShow -1;



 var highIntervall = (CurrentPageToShow * RowsPerPage)+ RowsPerPage;
    
    var lowIntervall;
    if(CurrentPageToShow < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (CurrentPageToShow) * RowsPerPage;
    }


        var lowestShowItem =  lowIntervall +1;
        var highestShowItem;
        
        if(highIntervall > count)
        {
            highestShowItem = count;
        }
        else
        {
         highestShowItem = highIntervall;
        }
        
        	
	
	var resultTable = document.getElementById('resultList'); 
	resultTable.innerHTML = "";

if(count > 0)
{
	//var resultText = "Results: Found " + (lowIntervall + 1) + "-" + highestShowItem + " of " + count + ".";
		var resultText = "Results: Listing " + (lowestShowItem) + "-" + highestShowItem + " of " + count + ".";
	resultTable.innerHTML += "<div class='search-results'><h2>" + resultText + "</h2><ul class='map-results-list'>";
var addedPinindex = 0;
var index = 0;
	//for (i=startIndex; i<count && i < highestShowItem; i++)
	//{

			var breaker= "false";

		 var layerscount = map.GetShapeLayerCount();

	for (j=1; j<layerscount; j++)
	{
if(breaker == "true")
{

break;
}
		var stepToNextLayer = "false";
		if(LayerIndexesNotToUseInShowAll != null)
		{
			var arrayOfIndexNotToUse = LayerIndexesNotToUseInShowAll.split(",")

			for(m=0; m < arrayOfIndexNotToUse.length; m++)
			{


				if(parseInt(arrayOfIndexNotToUse[m]) == j)
				{
				stepToNextLayer = "true";
					
				}

			}
		}

if(stepToNextLayer != "true")
{
		var currlayer = map.GetShapeLayerByIndex(j);
	   for (k=0; k<currlayer.GetShapeCount(); k++)
	   {
		//index = index +currlayer.GetShapeCount();

		if(index >= lowIntervall && index < highestShowItem)
		 {
				  var shape = currlayer.GetShapeByIndex(k);
		var url = shape.GetCustomIcon();
		var ImageUrl = url.CustomHTML;
		var Title = shape.GetPhotoURL();
		//alert(shape.GetDescription());
		var points = shape.GetPoints();

		var Lat = points[0].Latitude;
		var Long = points[0].Longitude;



		resultTable.innerHTML += "<ul class='map-results-list'><li style='background-image: url(" + ImageUrl + ");'><a href='javascript:SetCenterAndZoom(" + Lat + "," + Long + ")'>" + Title + "</a></li>";
		//addedPinindex++;
		}
if(index > highestShowItem)
{
breaker = "true";
break;
}
		index++;
           }
	}
	//} 
}

	
resultTable.innerHTML += "</div>";
}
else
{
var resultText = "Results: No results where found.";
	resultTable.innerHTML = "<div class='search-results'><h2>" + resultText + "</h2>";
}


	





}

function CreateResultListPagerFindShowAll(currentPageToShow, numberOfHits)
{
CurrentPageToShow = currentPageToShow;
NumberOfHits = numberOfHits;
pagerPages = Math.ceil(numberOfHits / RowsPerPage);


var currentPagerString = "";
     if(currentPageToShow > pagerPages)
    {
        currentPageToShow = 1;
        CurrentPageToShow = currentPageToShow;
        UpdateListAgain(currentPageToShow, numberOfHits);
    }
CurrentPageToShow = currentPageToShow;
var gridView = document.getElementById('resultList');
  
 
    if(NumberOfHits > 0)
    {
    

  
  
  if(numberOfHits > 0)
  {

 currentPagerString += "<div class='search-results'><div  class='paging'><strong class='structural'>Result Page:</strong>";
}

   
   
    
    var maxpoint;

if(pagerPages <= 5)
{
maxpoint  =pagerPages;
}
else
{
maxpoint = Math.max(5, Math.min(pagerPages, currentPageToShow + 2));
}

var lowpoint = Math.max(1, (currentPageToShow - 2)); 

     if (pagerPages > 1 && currentPageToShow > 1)
    {
    var prev = currentPageToShow -1;
         currentPagerString  +="<a class='prev' href='javascript:UpdateListAndPagerShowAll("+prev+","+NumberOfHits+")'>Previous</a><span>, </span>";
    }
    
   //checkIfNearEnd = Math.max(1, (currentPageToShow - 2)); 
   if(currentPageToShow > 3 && currentPageToShow +2 >= pagerPages)
   {
     if(pagerPages - currentPageToShow == 0)
     {
      lowpoint = lowpoint - 2;
     }
      if(pagerPages - currentPageToShow == 1)
      {
          lowpoint = lowpoint - 1;
      }
    
   }

for (var i = lowpoint; i <= maxpoint ; i++)                
    
    {
   
    var pageLink = "Page$"+i;
    if(currentPageToShow == 0)
    {
         currentPageToShow++;
    }
    
   if(i == currentPageToShow)
   {
        currentPagerString  += "<em>"+i+"</em><span>, </span>";

   }
   else
   {

     
   
    
    currentPagerString  += "<a href='javascript:UpdateListAndPagerShowAll("+i+","+NumberOfHits+")'>"+i+"</a><span>, </span>";
    }
      
      
      
    }
    //if(i == pagerPages && pagerPages > 1 && currentPageToShow < pagerPages)
       //  if ((currentPageToShow + 1) != pagerPages && pagerPages > (currentPageToShow + 1))
//          if (pagerPages > (currentPageToShow + 1))
if (pagerPages > currentPageToShow)
      {
      var next = currentPageToShow+1;
       currentPagerString  += "<a class='next' href='javascript:UpdateListAndPagerShowAll("+next+","+NumberOfHits+")'>Next</a>";
      }

currentPagerString += "</div></div>";
      gridView.innerHTML += currentPagerString;

// alert(gridView.innerHTML);
}}



function SetCountryAndCategory(country, catID)
{
//	var countryBox = document.getElementById('selectCountryList');
//    	var filterBox = document.getElementById('selectFilterList');
//	countryBox.value = country;
//TempFilterValue = catID;
//	filterBox.value = "-2";
SetCategory(catID);
SetCountry(country);
//alert(country);

}

var TempFilterValue;

function SetCategory(catID)
{

    	var filterBox = document.getElementById('selectFilterList');
	filterBox.value = catID;
//alert('catidchanged');

}

function SetCountry(countryName)
{

    var countryBox = document.getElementById('selectCountryList');

var capitalizedFirstLeterCountryName = countryName.substring(0,1).toUpperCase();

var capitalizedCountryName = capitalizedFirstLeterCountryName + countryName.substring(1,countryName.length).toLowerCase();

	countryBox.value = capitalizedCountryName;


}


var LayerIndexesNotToUseInShowAll;


function SaveLayerIndexesNotToUseInShowAll(layerIndexesNotToUse)
{

	LayerIndexesNotToUseInShowAll = layerIndexesNotToUse;
}

function GetHoverBlockTime(e)
{

    if(e.elementID != null)
    {
        shape = map.GetShapeByID(e.elementID);
        var points = shape.GetPoints();
currentShape = shape;
//if(CurrentHoverBlock != '')
//{

//shape.SetDescription(CurrentHoverBlock);
//CurrentHoverBlock = '';


//}
//else
//{

shape.SetDescription('Loading contact information');
//}

        DoAjaxQueryGetHoverBlock(points[0].Latitude, points[0].Longitude);  



    }
}

function SetCurrentHoverBlock(hoverBlock)
{
map.HideInfoBox();
CurrentHoverBlock = hoverBlock;

if(currentShape != null)
{
currentShape.SetDescription(CurrentHoverBlock);

map.ShowInfoBox(shape);

//GetHoverBlockTime(currentShape);

}
}

var currentShape;
var CurrentHoverBlock = '';

function DoAjaxQueryGetHoverBlock(lat, long)
{
    //Build the url to call the server
    var url = "WorldMapHttpHandler.ajax?";

   
    url += "&getHoverBlock=true";
    url += "&HoverLat=" + lat;
	url += "&HoverLong=" + long;
	
	
	//also include the current filter to see if the hoverblock should contain mulptiple location info
	 var filterBox = document.getElementById('selectFilterList');
  
    if(filterBox.value != null)
    {
	    
           CurrentFilter = filterBox.value;           
	    
    }
  
      url += "&filter=" + CurrentFilter;
               

    //put up a loading label
    //ShowLoading();

    //Start by getting the appropriate XMLHTTP object for the browser
    var xmlhttp = GetXmlHttp();
     //If we have a valid xmlhttp object

    if (xmlhttp)
    {

        xmlhttp.open("POST", url, true); // varAsync = true;
        
        //Set the callback.  This function is called when we 
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)  //4 is a success
            {
                //Server code creates javascript "on the fly" for us to
                //execute using eval()
                var result = xmlhttp.responseText;
//alert(result);
              eval(result);            
            }
        }
        xmlhttp.send(null);
    }

}





 function callPopUp(e)
 {
    if(e.elementID != null)
    {
        shape = map.GetShapeByID(e.elementID);
        var points = shape.GetPoints();

        SetCenterAndZoom(points[0].Latitude, points[0].Longitude);
      //  DoAjaxQuery();
    }
    else
    {

    }
 }
 

function CreateResultPinShowAllInCountry()
{
alert('allincountry');

	var startIndex = 0;	
var count = 0;

  var layerscount = map.GetShapeLayerCount();
	for (i=0; i<layerscount; i++)
	{


		var stepToNextLayer = "false";

		if(LayerIndexesNotToUseInShowAll != null)
		{
			var arrayOfIndexNotToUse = LayerIndexesNotToUseInShowAll.split(",")

			for(m=0; m < arrayOfIndexNotToUse.length; m++)
			{


				if(parseInt(arrayOfIndexNotToUse[m]) == i)
				{
				stepToNextLayer = "true";
					
				}

			}
		}

if(stepToNextLayer != "true")
{
		var currlayer = map.GetShapeLayerByIndex(i);






//for(




//   for (k=0; k<currlayer.GetShapeCount(); k++)
//	   {
//		//index = index +currlayer.GetShapeCount();

//		if(index >= lowIntervall && index < highestShowItem)
//		 {
//				  var shape = currlayer.GetShapeByIndex(k);
//if(CurrentCountryName != null && CurrentCountryName != "Show all")
//                {
//		    var currentPinCountry = shape.GetDescription();
//                  var exists = currentPinCountry.match(CurrentCountryName);

















		count = count +currlayer.GetShapeCount();
}
	} 

if(CurrentPageToShow == null || CurrentPageToShow == 1)
{
CurrentPageToShow = 0;

}


 var highIntervall = (CurrentPageToShow * RowsPerPage)+ RowsPerPage;
    
    var lowIntervall;
    if(CurrentPageToShow < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (CurrentPageToShow) * RowsPerPage;
    }


        var lowestShowItem =  lowIntervall +1;
        var highestShowItem;
        
        if(highIntervall > count)
        {
            highestShowItem = count;
        }
        else
        {
         highestShowItem = highIntervall;
        }
               	
	
	var resultTable = document.getElementById('resultList'); 
	resultTable.innerHTML = "";

if(count > 0)
{
	var resultText = "Results: Listing " + (startIndex + 1) + "-" + highestShowItem + " of " + count + ".";
	resultTable.innerHTML += "<div class='search-results'><h2>" + resultText + "</h2><ul class='map-results-list'>";
var addedPinindex = 0;
var index = 0;
	//for (i=startIndex; i<count && i < highestShowItem; i++)
	//{

			var breaker= "false";

		 var layerscount = map.GetShapeLayerCount();

	for (j=0; j<layerscount; j++)
	{
if(breaker == "true")
{

break;
}
		var stepToNextLayer = "false";
		if(LayerIndexesNotToUseInShowAll != null)
		{
			var arrayOfIndexNotToUse = LayerIndexesNotToUseInShowAll.split(",")

			for(m=0; m < arrayOfIndexNotToUse.length; m++)
			{


				if(parseInt(arrayOfIndexNotToUse[m]) == j)
				{
				stepToNextLayer = "true";
					
				}

			}
		}

if(stepToNextLayer != "true")
{
		var currlayer = map.GetShapeLayerByIndex(j);
	   for (k=0; k<currlayer.GetShapeCount(); k++)
	   {
		//index = index +currlayer.GetShapeCount();

		if(index >= lowIntervall && index < highestShowItem)
		 {
				  var shape = currlayer.GetShapeByIndex(k);
if(CurrentCountryName != null && CurrentCountryName != "Show all")
                {
		    var currentPinCountry = shape.GetDescription();


                    var exists = currentPinCountry.match(CurrentCountryName);

                    if(exists != null)
                    {

		var url = shape.GetCustomIcon();
		var ImageUrl = url.CustomHTML;
		var Title = shape.GetPhotoURL();
		//alert(shape.GetDescription());
		var points = shape.GetPoints();

		var Lat = points[0].Latitude;
		var Long = points[0].Longitude;



		resultTable.innerHTML += "<ul class='map-results-list'><li style='background-image: url(" + ImageUrl + ");'><a href='javascript:SetCenterAndZoom(" + Lat + "," + Long + ")'>" + Title + "</a></li>";
		//addedPinindex++;

		}
if(index > highestShowItem)
{
breaker = "true";
break;
}
		index++;

}
}

           }
	}
	//} 
}

	
resultTable.innerHTML += "</div>";
}
else
{
var resultText = "Results: No results where found.";
	resultTable.innerHTML = "<div class='search-results'><h2>" + resultText + "</h2>";
}
CreateResultListPagerFindShowAll(CurrentPageToShow, count);

	
}
















function CreatePinResultsTableNoMultipleLoc()
{
	var startIndex = 0;	
var count = layer.GetShapeCount();
 

CurrentPageToShow = 0;




 var highIntervall = 8;
    
    var lowIntervall = 0;


        var lowestShowItem =  lowIntervall +1;
       var highestShowItem;
        
        if(highIntervall > count)
        {
            highestShowItem = count;
        }
        else
        {
         highestShowItem = highIntervall;
        }
             
	
	var resultTable = document.getElementById('resultList'); 
	resultTable.innerHTML = "";

if(count > 0)
{
	
	var pinsHtml = "";
	var multipleLocationsFound = 0;
	for (index=0; index<count; index++)
	{
		var shape = layer.GetShapeByIndex(index);
		var Title = shape.GetPhotoURL();
		var isMuliplePin = Title.match('Multiple');
		if(isMuliplePin != null)
		{

			multipleLocationsFound++;
		}
	}

var temphighestShowItem = highestShowItem;
var tempCount = count;
	for (i=startIndex; i<count && i < temphighestShowItem; i++)
	{	

		var shape = layer.GetShapeByIndex(i);

		var Title = shape.GetPhotoURL();

                var isMuliplePin = Title.match('Multiple');

                if(isMuliplePin != null)
                {					 
			temphighestShowItem++;
		}
		else
		{


		  
		var url = shape.GetCustomIcon();
		var ImageUrl = url.CustomHTML;
	
		//alert(shape.GetDescription());
		var points = shape.GetPoints();

		var Lat = points[0].Latitude;
		var Long = points[0].Longitude;



		pinsHtml += "<ul class='map-results-list'><li style='background-image: url(" + ImageUrl + ");'><a href='javascript:SetCenterAndZoom(" + Lat + "," + Long + ")'>" + Title + "</a></li>";
		}

	}

	var highestShowItemNMultipleLoc = highestShowItem-multipleLocationsFound;

if((count - multipleLocationsFound) >8)
{
highestShowItemNMultipleLoc = 8;
}
	var countNoMulipleLoc = count-multipleLocationsFound;	

	var resultText = "Results: Listing " + (startIndex + 1) + "-" + highestShowItemNMultipleLoc + " of " + countNoMulipleLoc + ".";
	resultTable.innerHTML += "<div class='search-results'><h2>" + resultText + "</h2><ul class='map-results-list'>";
	resultTable.innerHTML += pinsHtml;
resultTable.innerHTML += "</div>";
}
else
{
var resultText = "Results: No results where found.";
	resultTable.innerHTML = "<div class='search-results'><h2>" + resultText + "</h2>";
}
	


CreateResultListPager(CurrentPageToShow, countNoMulipleLoc);


}











function CreateResultPinShowAllNoMultipleLoc()
{

	var startIndex = 0;	
var count = 0;

  var layerscount = map.GetShapeLayerCount();
	for (i=1; i<layerscount; i++)
	{


		var stepToNextLayer = "false";

		if(LayerIndexesNotToUseInShowAll != null)
		{
			var arrayOfIndexNotToUse = LayerIndexesNotToUseInShowAll.split(",")

			for(m=0; m < arrayOfIndexNotToUse.length; m++)
			{


				if(parseInt(arrayOfIndexNotToUse[m]) == i)
				{
				stepToNextLayer = "true";
					
				}

			}
		}

if(stepToNextLayer != "true")
{
		var currlayer = map.GetShapeLayerByIndex(i);
		count = count +currlayer.GetShapeCount();
}
	} 

if(CurrentPageToShow == null || CurrentPageToShow == 1)
{
CurrentPageToShow = 0;

}

CurrentPageToShow = 0;
 var highIntervall = (CurrentPageToShow * RowsPerPage)+ RowsPerPage;
    
    var lowIntervall;
    if(CurrentPageToShow < 1)
    {
        lowIntervall = 0;
    }
    else
    {
      lowIntervall = (CurrentPageToShow) * RowsPerPage;
    }


        var lowestShowItem =  lowIntervall +1;
        var highestShowItem;
        
        if(highIntervall > count)
        {
            highestShowItem = count;
        }
        else
        {
         highestShowItem = highIntervall;
        }
               	
	
	var resultTable = document.getElementById('resultList'); 
	resultTable.innerHTML = "";

if(count > 0)
{
	var resultText = "Results: Listing " + (startIndex + 1) + "-" + highestShowItem + " of " + count + ".";
	resultTable.innerHTML += "<div class='search-results'><h2>" + resultText + "</h2><ul class='map-results-list'>";
var addedPinindex = 0;
var index = 0;
	//for (i=startIndex; i<count && i < highestShowItem; i++)
	//{

			var breaker= "false";

		 var layerscount = map.GetShapeLayerCount();

	for (j=1; j<layerscount; j++)
	{
if(breaker == "true")
{

break;
}
		var stepToNextLayer = "false";
		if(LayerIndexesNotToUseInShowAll != null)
		{
			var arrayOfIndexNotToUse = LayerIndexesNotToUseInShowAll.split(",")

			for(m=0; m < arrayOfIndexNotToUse.length; m++)
			{


				if(parseInt(arrayOfIndexNotToUse[m]) == j)
				{
				stepToNextLayer = "true";
					
				}

			}
		}

if(stepToNextLayer != "true")
{
		var currlayer = map.GetShapeLayerByIndex(j);
	   for (k=0; k<currlayer.GetShapeCount(); k++)
	   {
		//index = index +currlayer.GetShapeCount();

		if(index >= lowIntervall && index < highestShowItem)
		 {
				  var shape = currlayer.GetShapeByIndex(k);
		var url = shape.GetCustomIcon();
		var ImageUrl = url.CustomHTML;
		var Title = shape.GetPhotoURL();
		//alert(shape.GetDescription());
		var points = shape.GetPoints();

		var Lat = points[0].Latitude;
		var Long = points[0].Longitude;



		resultTable.innerHTML += "<ul class='map-results-list'><li style='background-image: url(" + ImageUrl + ");'><a href='javascript:SetCenterAndZoom(" + Lat + "," + Long + ")'>" + Title + "</a></li>";
		//addedPinindex++;
		}
if(index > highestShowItem)
{
breaker = "true";
break;
}
		index++;
           }
	}
	//} 
}

	
resultTable.innerHTML += "</div>";
}
else
{
var resultText = "Results: No results where found.";
	resultTable.innerHTML = "<div class='search-results'><h2>" + resultText + "</h2>";
}
CreateResultListPagerFindShowAll(CurrentPageToShow, count);
}
