var map;
var bounds;
var htmls = new Array();
var gMarkers = new Array();
var from_htmls = new Array();
var to_htmls = new Array();
var map;
var waitMarker;

function GenerateOfficeMap() 
{       
      
     // map.setCenter(new GLatLng(28.513918,81.384838),10,G_NORMAL_MAP);
     
        //clear the House markers
        map.clearOverlays();
       
        //show the Loading gif
        dispWaitIcon();
  
        
        //set the initial value for the xml elements
        document.getElementById(strHdnVar).value = 0;
        
        //set the properties for the house markers
         baseIcon = new GIcon();
         baseIcon.image = "../Images/Icons/watsonlogo.gif";
   // baseIcon.shadow = "../Images/Icons/shadow-watsonlogo.png";
    baseIcon.iconSize = new GSize(32.0, 17.0);
    baseIcon.shadowSize = new GSize(72.0, 19.0);
    baseIcon.iconAnchor = new GPoint(16.0, 8.0);
    baseIcon.infoWindowAnchor = new GPoint(16.0, 8.0);
   // baseIcon.infoShadowAnchor = new GPoint(9, 32);
    
        
      //  baseIcon.transparent = "../Images/SearchMap/icon10_transparent.png";
       
      
  DispAllHouses();
}
 

function DispAllHouses()
{
  
  var boolInd = false;
  var vLat;
  var vLng;
     
            loadXML("../Search/Misc/OfficeSearchMap.xml");
             boolInd = true;
  
         
      map.removeOverlay(waitMarker);

      if (boolInd == true)
      {
        if(window.ActiveXObject)
        {
          for (var i = 0; i < xmlObj.childNodes.length; i++) {
         
          document.getElementById(strHdnVar).value = parseInt(document.getElementById(strHdnVar).value) + 1;
          
          if(xmlObj.childNodes(i).childNodes(8).firstChild.text != "0")
          {
         var point = new GLatLng(parseFloat(xmlObj.childNodes(i).childNodes(8).firstChild.text),parseFloat(xmlObj.childNodes(i).childNodes(7).firstChild.text));
         map.addOverlay(createHouseMarker(point, i));
         
            // ==== Each time a point is found, extent the bounds and include it =====
            bounds.extend(point);
         } 
       }
      }       
     
             // ===== determine the zoom level from the bounds =====
          map.setZoom(map.getBoundsZoomLevel(bounds));
         
          // ===== determine the centre from the bounds ======
          map.setCenter(bounds.getCenter());
          
     }  
       
         //document.getElementById("divLoading").style.display= "none";
}

function loadXML(xmlFile) 
{ 
if (window.ActiveXObject)
  {
 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
 xmlDoc.async="false"; 
 xmlDoc.onreadystatechange=verify; 
 xmlDoc.load(xmlFile); 
 xmlObj=xmlDoc.documentElement; 
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xmlDoc=document.implementation.createDocument("","",null);
  var isLoaded = xmlDoc.load(xmlFile);
  if (isLoaded == true)
  { xmlDoc.onload= function(){

    for (var i = 0; i < recCnt; i++) {
   
      document.getElementById(strHdnVar).value = parseInt(document.getElementById(strHdnVar).value) + 1;
      
      if(xmlDoc.getElementsByTagName("Latitude")[i].childNodes[0].nodeValue != "0")
      {
         var point = new GLatLng(parseFloat(xmlDoc.getElementsByTagName("Latitude")[i].childNodes[0].nodeValue),parseFloat(xmlDoc.getElementsByTagName("Longitude")[i].childNodes[0].nodeValue));
          map.addOverlay(createMarkerFF(point, i));
         
            // ==== Each time a point is found, extent the bounds and include it =====
            bounds.extend(point);
         } 
     }
  }
  }
  }
else
  {
  alert('Your browser cannot handle this script');
  return;
  }
}
function verify() 
{ 
 if (xmlDoc.readyState != 4) 
 { 
   return false; 
 } 
}  


function createHouseMarker(point, number) {
      
     //set icon
     var letteredIcon = new GIcon(baseIcon);  
     letteredIcon.image = "../Images/Icons/watsonlogo.gif";
 
      markerOptions = { icon:letteredIcon }; 
     
      var marker = new GMarker(point, markerOptions);
      marker.value = number;
      
      //gmarkers[iarr] = marker;
      
      
     var iInd = document.getElementById(strHdnVar).value;
     var pImgUrl;
     var myHtml;


       if (xmlObj.childNodes(iInd-1).childNodes(14).firstChild.text == "NA")
        { pImgUrl = '../../images/design/noimage.jpg'; }
        else
        { pImgUrl = 'http://images.watsonrealtycorp.com/newphotos/' + xmlObj.childNodes(iInd-1).childNodes(14).firstChild.text; }
        
            myHtml = "<table class='OfficeShadeTabs' width='260px' border='0'><tr><td width='40%'><a href='/Search/OfficeDetails.aspx?ID=" + xmlObj.childNodes(iInd-1).childNodes(0).firstChild.text + "&lat=" + xmlObj.childNodes(iInd-1).childNodes(8).firstChild.text + "&lg=" + xmlObj.childNodes(iInd-1).childNodes(7).firstChild.text + "&e=i&map=1' target=_blank><img src='" + pImgUrl + "' width=100 height=85 alt='House Image' border='0' onError='ImgError(this)' /></a>";
            myHtml += "</td><td align='left' width='60%'>"
          
            if(xmlObj.childNodes(iInd-1).childNodes(2).firstChild.text != "NA")
            {
              myHtml += "<b>" + xmlObj.childNodes(iInd-1).childNodes(2).firstChild.text + "</b>" 
            }
           
            //myHtml += xmlObj.childNodes(iInd-1).childNodes(2).firstChild.text + "&nbsp;";
            
            
            myHtml += "<br />";
            myHtml += xmlObj.childNodes(iInd-1).childNodes(3).firstChild.text + "<br />" +  xmlObj.childNodes(iInd-1).childNodes(4).firstChild.text +"<br />";
            myHtml += xmlObj.childNodes(iInd-1).childNodes(5).firstChild.text + "&nbsp;" + xmlObj.childNodes(iInd-1).childNodes(6).firstChild.text + "<br />";
            myHtml += "<a href='/Search/OfficeDetails.aspx?ID=" + xmlObj.childNodes(iInd-1).childNodes(0).firstChild.text + "&lat=" + xmlObj.childNodes(iInd-1).childNodes(8).firstChild.text + "&lg=" + xmlObj.childNodes(iInd-1).childNodes(7).firstChild.text + "&e=i&map=1' target=_blank><span style='font-size:x-small;padding-top:0px'>More Details</span><a></td></tr></table>"
    
                
             GEvent.addListener(marker,"click", function() {
                  map.openInfoWindowHtml(point, myHtml, {noCloseOnClick:false});
              });


	  return marker;
 }

function createMarkerFF(point, number) {
      
     //set icon
     var letteredIcon = new GIcon(baseIcon);  
     letteredIcon.image = "../Images/SearchMap/icon10.png";

      markerOptions = { icon:letteredIcon }; 
     
      var marker = new GMarker(point, markerOptions);
      marker.value = number;
      
      
     var iInd = document.getElementById(strHdnVar).value;
     var pImgUrl;
     var myHtml;
     
        if (xmlDoc.getElementsByTagName("Photo")[iInd-1].childNodes[0].nodeValue == "No")
        { pImgUrl = '../../images/design/noimage.jpg'; }
        else
        { pImgUrl = 'http://images.watsonrealtycorp.com/newphotos/' + xmlDoc.getElementsByTagName("Photo")[iInd-1].childNodes[0].nodeValue; }
        
        var myHtml =  "<table class='OfficeShadeTabs' width='230px' border='0'><tr><td width='40%'><a href='/Search/SearchDetails.aspx?ID=" + xmlDoc.getElementsByTagName("ID")[iInd-1].childNodes[0].nodeValue + "&lat=" + xmlDoc.getElementsByTagName("Latitude")[iInd-1].childNodes[0].nodeValue + "&lg=" + xmlDoc.getElementsByTagName("Longitude")[iInd-1].childNodes[0].nodeValue + "&e=i' target=_blank><img src='" + pImgUrl + "' width=70 height=65 alt='House Image' border='0'/></a>";
                 myHtml += "</td><td align='left' width='60%'>"
          
            if(xmlDoc.getElementsByTagName("StreetNumber")[iInd-1].childNodes[0].nodeValue != "0")
            {
              myHtml += xmlDoc.getElementsByTagName("StreetNumber")[iInd-1].childNodes[0].nodeValue + " " 
            }
            myHtml += xmlDoc.getElementsByTagName("Street")[iInd-1].childNodes[0].nodeValue + "&nbsp;";
            
            var streetType = xmlDoc.getElementsByTagName("StreetType")[iInd-1].childNodes[0].nodeValue;
            if(streetType != 'Not Available')
              myHtml += streetType.substring(0,1).toUpperCase() + streetType.substring(1, streetType.length).toLowerCase();
            
            myHtml += "<br />Beds:&nbsp;";
            myHtml += xmlDoc.getElementsByTagName("Bedrooms")[iInd-1].childNodes[0].nodeValue + "<br />Baths:&nbsp;" +  xmlDoc.getElementsByTagName("Baths")[iInd-1].childNodes[0].nodeValue +"<br />Price&nbsp;";
            myHtml += xmlDoc.getElementsByTagName("Price")[iInd-1].childNodes[0].nodeValue + "<br />";
            myHtml += "<a href='/Search/SearchDetails.aspx?ID=" + xmlDoc.getElementsByTagName("ID")[iInd-1].childNodes[0].nodeValue + "&lat=" + xmlDoc.getElementsByTagName("Latitude")[iInd-1].childNodes[0].nodeValue + "&lg=" + xmlDoc.getElementsByTagName("Longitude")[iInd-1].childNodes[0].nodeValue + "&e=i' target=_blank>More Details<a></td></tr></table>"
     
      
     GEvent.addListener(marker,"click", function() {
          map.openInfoWindowHtml(point, myHtml, {noCloseOnClick:false});
      });
       
       
     
       //htmls[iarr] = myHtml;
       // _arrIDSno[iarr] = iarr + '|' + xmlDoc.getElementsByTagName("ID")[iInd-1].childNodes[0].nodeValue
  
    //iarr++;
    
	  return marker;
 }


function createMarker(point, tabNames) {
      
        var icon = new GIcon();

    icon.image = "../Images/Icons/watsonlogo.gif";
    icon.shadow = "../Images/Icons/shadow-watsonlogo.png";
    icon.iconSize = new GSize(32.0, 17.0);
    icon.shadowSize = new GSize(42.0, 19.0);
    icon.iconAnchor = new GPoint(16.0, 8.0);
    icon.infoWindowAnchor = new GPoint(16.0, 8.0);

  
     //set icon
     var letteredIcon = new GIcon(icon);  
    letteredIcon.image = "../Images/Icons/watsonlogo.gif";
   
      var markerOptions = { icon:letteredIcon }; 
     
      var marker = new GMarker(point, markerOptions);
      
      var i = 0;
      var html = "";
      
html = "<div style='text-align:left'><b>" + document.getElementById("strHdnAddress").value + "&nbsp;" ;
html += "</b><br>"
html += "Ph&nbsp;&nbsp;: " + document.getElementById("OfficeSearchMap1_hdnContact").value + "&nbsp;&nbsp;"
html += "Fax&nbsp;: " + document.getElementById("OfficeSearchMap1_hdnFax").value
html += "</div><br>";
html +=  '<div style="text-align:left">' +
           '<input type="text" SIZE=30 MAXLENGTH=60 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" type="button" style="font-size:x-small" onClick="CallSForm()">' +
           '<input type="hidden" name="daddr" value="' + document.getElementById("strHdnAddress").value + 
           '"/></div>';
    
      

              // The info window version with the "to here" form open
        to_htmls2[i] = html + '<div style="text-align:left">Directions: <b>To here</b> - <a href="javascript:from(' + i + ')">From here</a>' +
           '<br>Start address:<br>' +
           '<input type="text" SIZE=30 MAXLENGTH=60 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" type="button" style="font-size:x-small" onClick="CallSForm()">' +
           '<input type="hidden" name="daddr" value="' + document.getElementById("strHdnAddress").value +
           '"/></div>';
    
        from_htmls2[i] = html + '<div style="text-align:left">Directions: <a href="javascript:toDir(' + i + ')">To here</a> - <b>From here</b>' +
           '<br>End address:<br>' +
           '<input type="text" SIZE=30 MAXLENGTH=60 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" type="button" style="font-size:x-small" onClick="CallSForm()">' +
           '<input type="hidden" name="saddr" value="' + document.getElementById("strHdnAddress").value +
           '"/></div>';
    
        // The inactive version of the direction info
       // html += '<div style="text-align:left">Directions: <a href="javascript:toDir('+i+')">To here</a> - <a href="javascript:from('+i+')">From here</a></div>';
        
        
        var a= 10;
        var OfficeImg = document.getElementById("OfficeSearchMap1_hdnPhoto").value;
        
         GEvent.addListener(marker,"mouseover", function() {
                var tabs = [];
                tabs.push(new GInfoWindowTab(tabNames[0],"<div style='text-align:center'><img src='http://images.watsonrealtycorp.com/Office_images/"+ OfficeImg + "' style='width:200px;height:80px;' /><br><a href='javascript:ShowStreetForm()'>Click here</a> for Street view</div>"));
                tabs.push(new GInfoWindowTab(tabNames[1],html)); 
          
          marker.openInfoWindowTabsHtml(tabs);
           });

        gmarkers2[i] = marker;
        
        htmls2[i] = html;
        
        

      	  return marker;

}

 function dispWaitIcon()
{          
// to display the waiticon
//SECTION STARTS
    var center = map.getCenter();
          
    var baseIcon2 = new GIcon(); 
  
    baseIcon2.iconAnchor = new GPoint(9, 34); 

      var markerIcon2 = new GIcon(baseIcon2); 
      
     markerIcon2.image = "../RadControls/Window/Skins/Default2006/Img/Splash.gif";
     markerOptions2 = { draggable: false, icon: markerIcon2 }; 

    waitMarker = new GMarker(center, markerOptions2); 
   
    map.addOverlay(waitMarker);
   
//SECTION ENDS
}


    
