 var origMaprow,origTag, MapRow ='', ID;
 var printmapname = "Map of Available Now Housing";

 
 function toggleHeader(MyDiv)
    {
       for(var c=1; c < MyDiv.childNodes.length; c++) {
            MyDiv.childNodes[c].style.display = MyDiv.childNodes[c].style.display == "block" ? MyDiv.childNodes[c].style.display = "none" :MyDiv.childNodes[c].style.display = "block";
       }
    }
    
    function toggleDetails(MyDiv)
    {
       for(var c=1; c < MyDiv.childNodes.length; c++) {
            MyDiv.childNodes[c].style.display = MyDiv.childNodes[c].style.display == "block" ? MyDiv.childNodes[c].style.display = "none" :MyDiv.childNodes[c].style.display = "block";
       }
    }
    
    

function openHousingMap(myItem)
{






 myAddress = myItem.parentNode.parentNode.parentNode.childNodes[5].childNodes[0].innerHTML;

 myAddress = myAddress.substr(0, myAddress.indexOf('('));
// alert(myAddress);
//if (!/WebKit/i.test(navigator.userAgent))//not safari
//{
    if (myItem.innerHTML.indexOf("Close")<0)
     {
         if(MapRow == '')// create map from scratch
         {  
            curtable =  myItem.parentNode.parentNode.parentNode.parentNode;
             MapRow = curtable.insertRow(myItem.parentNode.parentNode.parentNode.rowIndex);
             var dx = MapRow.insertCell(0);
             dx.style.height = "600px";

	     document.getElementById( 'myMap').style.width = '600px';
	     document.getElementById( 'myMap').style.height = '500px';
	     factor = 500;
          
           
            document.getElementById( 'moveableMapDiv').style.top = findPosTop(MapRow) - 160 + "px";
            MapRow.scrollTop = document.getElementById( 'moveableMapDiv').offsetTop;
            document.getElementById( 'moveableMapDiv').style.left = "85px";
            
            
         }
         else{ //move map
         
           factor = 400;
           origMaprow = MapRow;
           MapRowhtml = MapRow.innerHTML;
           curtable.deleteRow(MapRow.rowIndex-1);
           curtable =  myItem.parentNode.parentNode.parentNode.parentNode;
           MapRow = curtable.insertRow(myItem.parentNode.parentNode.parentNode.rowIndex);
           var dx = MapRow.insertCell(0);
            dx.style.height = "600px";

           document.getElementById( 'moveableMapDiv').style.top = findPosTop(MapRow)- 160 + "px";
           MapRow.scrollTop = document.getElementById( 'moveableMapDiv').offsetTop;
           document.getElementById( 'moveableMapDiv').style.left =  "85px";
          
            origTag.innerHTML = origTag.innerHTML.replace("Close", "View");
          
          
         }
         
       document.getElementById('moveableMapDiv').style.display = "block";
    
    
    myItem.innerHTML = myItem.innerHTML.replace("View", "Close");
    origTag = myItem;    
     
   
  showCAGPoint(myItem.childNodes[1].childNodes[0].data ,true);
     
   // openMap(myItem.childNodes[1].childNodes[0].data, myAddress, '','', 'ZoomtoUPRN');
    
    
      }
    else
    {
       
        CloseMap();
        myItem.innerHTML = myItem.innerHTML.replace("Close", "View"); 
    } 
 
//dijit.byId("butStrip")._calcHitGrid();
}


function findPosTop(obj) {
	curtop = 0;
    if (obj.offsetParent) {
    do {
			curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    return curtop;
}
}
function findPosLeft(obj) {
	cur = 0;
    if (obj.offsetParent) {
    do {
			cur += obj.offsetLeft;
    } while (obj = obj.offsetParent);
    return cur;
}
}

function CloseMap()
{

 if (document.getElementById('moveableMapDiv').style.display == "block")
 {
    
    document.getElementById('moveableMapDiv').style.display = "none";
    curtable.deleteRow(MapRow.rowIndex-1);
   MapRow ='';
   }
}

function toggleFAQ(mydiv)
{
  
    myHeight = 0;
    thediv = mydiv.parentNode;
    // close all other sections
   for(var c=0; c < thediv.childNodes.length; c++) {
        if( thediv.childNodes[c].childNodes[1] != mydiv.childNodes[1])
        {
        
            
                thediv.childNodes[c].childNodes[1].style.display = "none";
            
        }
      }
       
       //Open close current section
    mydiv.childNodes[1].style.display == "block"? mydiv.childNodes[1].style.display = "none" : mydiv.childNodes[1].style.display = "block";
  
       CloseMap()
    origTag.innerHTML = origTag.innerHTML.replace("Close", "View"); 
 

}

function CreateAHPDF()
{
        

       minx = "&xmin=" + myMap.extent.xmin.toString();
       miny = "&yMin=" + myMap.extent.ymin.toString();
       maxx = "&xMax=" + myMap.extent.xmax.toString();
       maxy = "&yMax=" + myMap.extent.ymax.toString();
       imWidth = "&ImageWidth=1000";
       imH = "&ImageHeight=1000";
       orientation = "&orientation=portrait";
       Webservice = "&mapservice=PrintLocMap";
       theVal = "&UPRN=" + ID;
       strJsonGraphic = "&strJsonGraphic=";
       theTitle = "&theTitle=" + "Available_Now_Properties";
       
     
        
    
     dojo.xhrGet({
    url: "/forms/jQproxy.php?myurl=http://mapsonline.dundeecity.gov.uk/DCC_WEB_SERVICES/Createpdf_em.asmx/CreateAnyPDFPH"+minx + miny + maxx + maxy + orientation +Webservice + theTitle + theVal,
    load: function(response, ioArgs){
         if (window.ActiveXObject)
        {
            pdfPath = response.childNodes[1].childNodes[0].nodeValue;
        }
        else
        {
            pdfPath = response.firstChild.textContent;
        }
            window.open(pdfPath, "LoPR2");
        
      return response;
    },
    error: function(response, ioArgs){
      
      alert ("address not Found");
      return response;
    },
    handleAs: "xml"
  });
    
    
}
function LoadPDF()
{
     if ((xmlhttprequest.readyState == 4) &&( xmlhttprequest.status == 200))
  {
   
    var myXml = xmlhttprequest.responseXML;
    

    
    if (window.ActiveXObject)
    {
        pdfPath = myXml.childNodes[1].childNodes[0].nodeValue;
    }
    else
    {
        pdfPath = myXml.firstChild.textContent;
    }
        window.open(pdfPath, "LoPR2");
 }  
}