﻿//  function initializeToAddress(address,img){
//    map = new GMap2(document.getElementById('map_canvas'));
//    var geocoder = new GClientGeocoder();
//    geocoder.getLatLng(
//	address,
//	function(point) {
//       		if (!point) {
//       			alert(address + " not found");
//       		} else {
//			map.setCenter(point, 15);
//                        // call createMarker function
//			map.addOverlay(createMarker(address, point, img));
//       		}
//	}
//);
//        document.getElementById("tdadd").style.display='';
//        document.getElementById("map_canvas").style.display='';
//        document.getElementById("map").style.display='';
//        
//        
//}

//function createMarker(address, point, img) {
//	  // Create a lettered icon for this point using our icon class
//	  var marker = new GMarker(point);
//	  marker.image = "image/red.gif";
//      marker.bindInfoWindowHtml('<p style="color:#000; font-size:12px;"><Strong>Address:</Strong></p><p style="color:#000; font-size:11px;">'+address+'</p><p><img src="'+ img +'"</p>');	
//      return marker;
//}
//    

// JScript File
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
	var gmarkers = [];
	var htmlAddresses = [];
	var originalAddresses = [];
    var mquerystring='';
    var zone = 33;       // NORWAY
    var southhemi = false;
    var ErrorCode=0;
    var stret;
    var bounds = new GLatLngBounds();
    
    function initializeToAddress(street,propertyid,toaddress,img,name,phone,isstreet) {
      if (GBrowserIsCompatible()) {
       if (document.getElementById("map"))
            document.getElementById("map").style.display='';
        var m =document.getElementById("map_canvas");
        m.style.height = "480px"; m.style.width = "650px"; 
        map = new GMap2(m);
		map.addControl(new GLargeMapControl());
		map.addControl(new GHierarchicalMapTypeControl());
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
	 	geocoder = new GClientGeocoder();
        map.setCenter(new GLatLng(65.472024, 10.468946), 4);
        setDirections(street,propertyid,toaddress, 'no',img,name,phone,isstreet);
        document.getElementById("tdadd").style.display='';
        document.getElementById("tdadd").style.backgroundColor="White";
        document.getElementById("tdadd").style.textAlign="right";
        document.getElementById("tdadd").Height="35px;";
        document.getElementById("map").style.display='';
        document.getElementById("map").style.top='50px';
        document.getElementById("map").style.left='190px';
        document.getElementById("map").style.border='solid 1px black';
        map.checkResize();
      }
    }
    
    
    
      

   function initializesmall() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
          //map.removeMapType(G_HYBRID_MAP);
		  map.addControl(new GSmallMapControl());
		  //map.addControl(new GMapTypeControl());
		  map.addControl(new GHierarchicalMapTypeControl());
        mm = new GMarkerManager(map); 
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
		geocoder = new GClientGeocoder();
	    map.setCenter(new GLatLng(40.058324, -74.405661), 4);
      }
    }
    

    
    function setDirections(street,propertyid,toAddress, locale,img,name,phone,isstreet) {
		if(toAddress!='')
		   showAddress(propertyid,street,toAddress,locale,img,name,phone,isstreet);
		 return true;
    }

    function gup(name)
	{
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		var returnValue='';
		if( results != null )
		{
			returnValue = results[1];
		}
		return returnValue;
			
	}
    

	function handleErrors(){
		      
	   
	}

	function onGDirectionsLoad(){ 
      
	}
		
	function showAddress(propertyid,street,toAddress, locale,img,name,phone,isstreet)
	{  
	 	if (geocoder)
		{
		        
			var result=street+toAddress;
						
        geocoder.getLocations(result, function (result)
          { 
            // If that was successful
            if (result.Status.code == G_GEO_SUCCESS) {
              		var p = result.Placemark[0].Point.coordinates;
                    var lat = p[1];
                    var lng = p[0];
				    var adresse = result.Placemark[0].address;
                    CreatePlacemarker(lat, lng,street,toAddress, img,propertyid,name,phone,isstreet);
                if(result.Placemark.length==1)
				{
				    var p = result.Placemark[0].Point.coordinates;
                    map.setCenter(new GLatLng(p[1],p[0]),14);
				}
				    
             
            }
          
           
          } 
        );

		}
	}    
	   
    function CreatePlacemarker(lat, lng, street,toAddress, img,propertyid,name,phone,isstreet)
    {
        var  originaladdress="Contact Seller" + "<br/>" + toAddress;
        if (isstreet==1)
            originaladdress=street + "<br/> " + toAddress;
        toAddress=street + ", " + toAddress;
        var point = null;
        var html ="<table width='300' cellpadding='0' cellspacing='0'><tr><td width='80%' align='left'>";
        html+=" <table width='300' cellpadding='0' cellspacing='0'><tr><td valign='top' colspan='2' class='Light12 Gray13'><strong></strong></td></tr>";
        html+= "<tr><td class='Light11 Gray13' style='text-align:right;padding-right:3px;'><strong>ZAG#: </strong></td><td class='Light10 Gray13 Red15'><strong>"+ propertyid +"</strong></td></tr>";
        html+= "<tr><td class='Light11 Gray13' style='text-align:right;padding-right:3px;' valign='top' width='10%'><strong>Address: </strong></td><td width='90%' class='Light10 Gray13'>"+ originaladdress +"</td></tr>";
        html+= "<tr><td class='Light11 Gray13' style='text-align:right;padding-right:3px;' width='10%'><strong>Contact: </strong></td><td width='90%' class='Light10 Gray13'>"+ name +"</td></tr>";
        html+= "<tr><td class='Light11 Gray13' style='text-align:right;padding-right:3px;' width='10%'><strong>Phone: </strong></td><td width='90%' class='Light10 Gray13'>"+ phone +"</td></tr>";
        html+="</table></td><td width='20%' align='right'><img src='"+img+"' border='0' width='133' height='100' /></td>";
        html +="</tr></table>";
        
        if (lat==null)
        {
            geocoder.getLatLng(toAddress, function(point)
				    {
				        if(point!=null)
                            map.addOverlay(createMarker(point, name, html,  toAddress));
				    }
			    );
			    
	    }
        else
        {
            point = new GLatLng(lat,lng);
            map.addOverlay(createMarker(point, name, html,originaladdress));
        }        
    }
    
    
   function createMarker(point, name, html,originaladdress) {

  var marker = new GMarker(point);
      marker.name = name;

   GEvent.addListener(marker, "mouseover", function() {
    marker.openInfoWindowHtml(html);
   });
   GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
   });
   gmarkers.push(marker);
  htmlAddresses.push(html);
  originalAddresses.push(originaladdress);
  bounds.extend(point);
   zoomfit();   
  return marker;
 }


 
   
    function CP(street,toAddress, img,propertyid,name,phone,isstreet,statecd)
    {
         var  originaladdress="Contact Seller" + "<br/>" + toAddress;
        if (isstreet==1)
            originaladdress=street + "<br/> " + toAddress;
        toAddress=street + ", " + toAddress;
        var point = null;
        var html ="<table width='300' cellpadding='0' cellspacing='0'><tr><td width='80%' align='left'>";
        html+=" <table width='300' cellpadding='0' cellspacing='0'><tr><td valign='top' colspan='2' class='Light12 Gray13'><strong></strong></td></tr>";
        html+= "<tr><td class='Light11 Gray13' style='text-align:right;padding-right:3px;'><strong>ZAG#: </strong></td><td class='Light10 Gray13 Red15'><strong>"+ propertyid +"</strong></td></tr>";
        html+= "<tr><td class='Light11 Gray13' style='text-align:right;padding-right:3px;' valign='top' width='10%'><strong>Address: </strong></td><td width='90%' class='Light10 Gray13'>"+ originaladdress +"</td></tr>";
        html+= "<tr><td class='Light11 Gray13' style='text-align:right;padding-right:3px;' width='10%'><strong>Contact: </strong></td><td width='90%' class='Light10 Gray13'>"+ name +"</td></tr>";
        html+= "<tr><td class='Light11 Gray13' style='text-align:right;padding-right:3px;' width='10%'><strong>Phone: </strong></td><td width='90%' class='Light10 Gray13'>"+ phone +"</td></tr>";
        html+="</table></td><td width='20%' align='right'><img src='/PropertyImages/fpropertyimages/"+img+".jpg' border='0' width='133' height='100' /></td>";
        html +="</tr></table>";
        
        
         geocoder.getLatLng(toAddress, function(point)
				    {
				        if(point!=null)
				       
                            map.addOverlay(createMarker(point, name, html,  toAddress));
                       
				    }
			    );
			  
             
    }
    
        function zoomfit()
{
newzoom = map.getBoundsZoomLevel (bounds);
newcenter = bounds.getCenter();
map.setCenter (newcenter,newzoom);
}