﻿// JScript File

	function DisplayPostecodeResults(places)
	{
	
	        
            var resHtml = "";
            var latitude;
            var longitude;
            var postalcode;

            /**  if there are no results, display the error message and return */
            if (places == null)
            {
               alert( "There were no results for the specified Postcode, please check your query."  );
               return;
            }
            
            if (places.PostalCodes == null)
            {
               alert( "There were no results for the specified Postcode, please check your query."  );
               return;
            }
            
            
            resHtml = resHtml + "<div class ='dlg' ><table>";
            /**  Create an entry for each VEPlace in the result set */
            for (var p = 0; p < places.PostalCodes.length; p++)
            {
               /**  Gather some info up front */
               var place = places.PostalCodes[p];
               var countryCode = place.CountryCode;
                postalcode = place.PostalCode;
                latitude = place.Latitude;
                longitude = place.Longitude;
               var title =  place.Name;
               var state = place.AdminName1;
               var stateCode = place.AdminCode1;
               var district = place.AdminName2;
               var districtCode = place.AdminCode2; 
               var taluk = place.AdminName2;
               var talukCode = place.AdminCode2;                        

      
               /**  create the info box description */
               var desc = "Latitude: " + latitude + "<br/>" + "Longitude: " + longitude;
               desc = desc + "<br>location: " + district;
              // desc = desc + "<br>Precision: " + precString;
               desc = desc + "<br>postalcode: " + postalcode;
             if (VEVisible)
             createMarkerOnVE(latitude, longitude, p, title, desc,0);
             if(GGVisible)
               g_map.addOverlay(createNonDragableMarkeronGMap(new GLatLng(latitude, longitude), p, title + '<br/>' + desc)); 
               if(YYVisible)
               {
		        var currentGeoPoint = new YGeoPoint(latitude, longitude);
				CreateMarkerOnYMap(currentGeoPoint,title + '<br/>' + desc);     
				}          
                    
               /**  Add the information to the resultsDiv html, including a link */
               /**  that recenters the map over the pin */
               resHtml = resHtml + "<tr class='dlg'><td class='dlg' width= 50px;>";
               resHtml = resHtml + 
                         "<a href='javascript:GotoLocation(" +
                         latitude +
                         "," +
                         longitude +
                         ", 10"  + 
                         ");'>";
               resHtml = resHtml + 
                         "#" +  (p+1) +
                         "</a></td><td class='dlg' width= 150px;> ";
                         
               resHtml = resHtml + 
                         "<a href='javascript:GotoLocation(" +
                         latitude +
                         "," +
                         longitude +
                         ", 10"  + 
                         ");'>";                         
              resHtml = resHtml + title + ", Postal code= " + postalcode;
                   resHtml = resHtml + "</a></td><td class='dlg'>"  ;
               resHtml = resHtml + "Location: " + district+ "," + formatstring(districtCode) + formatstring(state)  + formatstring(stateCode) + formatstring(taluk)  + formatstring(talukCode) ;                                
                resHtml = resHtml + "</td>"  ;     
                if(trackLatitude)
                {     resHtml = resHtml + "<td class='dlg'>Distance: " + place.Distance + "</td>"  ;  
                }    
                 resHtml = resHtml + "</tr>"  ;  
             }
            resHtml = resHtml + "</table></div>";
            
      
            
            if(trackLatitude){
                ZWDialog.Alert(resHtml, "Postcode lookup results for " + document.getElementById("txtLatitude").value.substring(0,6) + ',' + document.getElementById("txtLongitude").value.substring(0,6) )  ;
            }
            else
            ZWDialog.Alert(resHtml, "Postcode search results for " + document.getElementById("txtPostCodeSearch").value);

             

         try
         {   
            if (latitude != 0)
                GotoLocation(latitude,longitude,10);
        }
  	    catch(err)
        {
            /**alert("Error! in init",err.message);  */
        }
                  

	}
	
	
	function DisplayIndianPostecodeResults(places)
	{
	
	        
            var resHtml = "";
            var latitude;
            var longitude;
            var postalcode;

            /**  if there are no results, display the error message and return */
            if (places == null)
            {
               alert( "There were no results for the specified Postcode, please check your query."  );
               return;
            }
            
            if (places.PostalCodes == null)
            {
               alert( "There were no results for the specified Postcode, please check your query."  );
               return;
            }
            
            
            resHtml = resHtml + "<div class ='dlg' ><table>";
            /**  Create an entry for each VEPlace in the result set */
            for (var p = 0; p < places.PostalCodes.length; p++)
            {
               /**  Gather some info up front */
               var place = places.PostalCodes[p];
                postalcode = place.PostalCode;
                latitude = place.Latitude;
                longitude = place.Longitude;
               var title =  place.Name;
               var state = place.AdminName1;
                        

      
               /**  create the info box description */
               var desc = "Latitude: " + latitude + "<br/>" + "Longitude: " + longitude;
               desc = desc + "<br>location: " + state;
              // desc = desc + "<br>Precision: " + precString;
               desc = desc + "<br>postalcode: " + postalcode;
             if (VEVisible && latitude !='NA')
             createMarkerOnVE(latitude, longitude, p, title, desc,0);
             if(GGVisible && latitude !='NA')
               g_map.addOverlay(createNonDragableMarkeronGMap(new GLatLng(latitude, longitude), p, title + '<br/>' + desc)); 
               if(YYVisible && latitude !='NA')
               {
		        var currentGeoPoint = new YGeoPoint(latitude, longitude);
				CreateMarkerOnYMap(currentGeoPoint,title + '<br/>' + desc);     
				}          
                    
               /**  Add the information to the resultsDiv html, including a link */
               /**  that recenters the map over the pin */
               resHtml = resHtml + "<tr class='dlg'><td class='dlg' width= 50px;>";
               if (latitude !='NA')
               {
               resHtml = resHtml + 
                         "<a href='javascript:GotoLocation(" +
                         latitude +
                         "," +
                         longitude +
                         ", 10"  + 
                         ");'>";
               resHtml = resHtml + 
                         "#" +  (p+1) +
                         "</a></td><td class='dlg' width= 150px;> ";
                         
               resHtml = resHtml + 
                         "<a href='javascript:GotoLocation(" +
                         latitude +
                         "," +
                         longitude +
                         ", 10"  + 
                         ");'>";    
                resHtml = resHtml + title + ", Postal code= " + postalcode;
                 resHtml = resHtml + "</a></td><td class='dlg'>"  ;
                        
                }       
                else
                {
                

               resHtml = resHtml + 
                         "#" +  (p+1) +
                         "</td><td class='dlg' width= 150px;> ";
                resHtml = resHtml + title + ", Postal code= " + postalcode;
                 resHtml = resHtml + "</td><td class='dlg'>"  ;                
                
                }              
               resHtml = resHtml + "Location: " +  formatstring(state)  ;                                
                resHtml = resHtml + "</td>"  ;     
                if(trackLatitude)
                {     resHtml = resHtml + "<td class='dlg'>Distance: " + place.Distance + "</td>"  ;  
                }    
                 resHtml = resHtml + "</tr>"  ;  
             }
            resHtml = resHtml + "</table></div>";
            
      
            
            ZWDialog.Alert(resHtml, "Local DB Postcode search results for " + document.getElementById("txtPostCodeSearch").value);

             

         try
         {   
            if (latitude != 0)
                GotoLocation(latitude,longitude,10);
        }
  	    catch(err)
        {
            /**alert("Error! in init",err.message);  */
        }
                  

	}	
	function formatstring (strinput)
	{
	if (strinput.length == 0)
	return  strinput;
	else 
	return  ", " + strinput;
	}
	 
