﻿// display_mapidentify.js


var identifyFilePath = "";
var identifyImageType = "png";


 
// Set up Identify tool
function MapIdentify(divid) {
    //alert("Goes OK for MapIdentify !!!!");
    map = Maps[divid];
    MapPoint(map.controlName, "MapIdentify", false);
    map.divObject.onmousedown = MapIdClick;
}

function SISIdentify(divid) 
{
   // alert("Inside SISIdentify(divid)");
    map = Maps[divid];
    MapPoint(map.controlName, "SISIdentify", false);
    map.divObject.onmousedown = SISIdClick;
}

function SISIdClick(e) 
{
    
    document.all.testing.innerHTML = "<div style=\"float:center;top:35px;left:45px;position:relative;width:25px;height:25px;\" ><img src=images/sisLoad.gif align=\"center\"></img></div>";
    map.cursor = map.divObject.style.cursor;
	//map.divObject.style.cursor = "wait";
	getXY(e);
	var box = calcElementPosition(map.containerDivId);
	zleft = mouseX - box.left;
	ztop = mouseY - box.top;
    
	map.xMin=zleft;
	map.yMin=ztop;
	var div = document.getElementById("IdentifyLocation");
	if (div==null) 
	{
	    addIdentifyLocation();
	}
	
	map.getTopLeftTile();
	//var fpBody = document.getElementById('Results_TaskResults1');
	//var html = fpBody.innerHTML;
	//fpBody.innerHTML = "<div><img src='images/callbackActivityIndicator.gif' align='middle'/> Getting Information. . .</div>" + html;
	//showFloatingPanel('Results');
	//fpBody=document.getElementById('Results_BodyRow');
	//if (fpBody.style.display=="none")
	//    toggleFloatingPanelState('Results','images/collapse.gif','images/expand.gif');
    
	var message2 = "ControlID=Map1&ControlType=Map&EventArg=SISIdentify&Map1_mode=MapIdentify&minx=" + zleft + "&miny=" + ztop;
	var context = map.controlName;
	// alert("starting to invoke ");
	eval(identifyCallbackFunctionString2);
	// alert("invoked");
	var div = document.getElementById("IdentifyLocation");
	// point is bottom center... 2 pixels up for shadow
	var cWidth = Math.floor(div.clientWidth / 2);
	var cHeight = div.clientHeight;
	//alert(cWidth + " x " + cHeight); // width and height might not be available on first time.... if so, approximate size needed
	if (cWidth==0) cWidth = 12;
	if (cHeight==0) cHeight = 29;
	var idLeft = zleft - parseInt(map.divObject.style.left) - cWidth;
	var idTop = ztop - parseInt(map.divObject.style.top) - cHeight + 2; // add two back for icon bottom
    //	if (isIE) {
    //	    idTop+=2; 
    //	    //idLeft+=2;
    //	}
    //	window.setTimeout('moveLayer("IdentifyLocation", ' + idLeft + ', ' + idTop + '); showLayer("IdentifyLocation");', 0);
    //	map.mode = map.tempMode;
    //	map.actionType = map.tempAction;
    //	map.cursor = map.tempCursor;
	
  //  	alert("End of SISIdClick JS function");
	return false;
}


// Event handler for Identify
function MapIdClick(e) {
  //  alert(map.containerDivId);
    map.cursor = map.divObject.style.cursor;
	//map.divObject.style.cursor = "wait";
	getXY(e);
	var box = calcElementPosition(map.containerDivId);
	zleft = mouseX - box.left;
	ztop = mouseY - box.top;

	map.xMin=zleft;
	map.yMin=ztop;
	var div = document.getElementById("IdentifyLocation");
	if (div==null) 
	{
	    addIdentifyLocation();
	}
	
	map.getTopLeftTile();
	var fpBody = document.getElementById('Results_TaskResults1');
	var html = fpBody.innerHTML;
	fpBody.innerHTML = "<div><img src='images/callbackActivityIndicator.gif' align='middle'/> Getting Information. . .</div>" + html;
	showFloatingPanel('Results');
	fpBody=document.getElementById('Results_BodyRow');
	if (fpBody.style.display=="none")
	    toggleFloatingPanelState('Results','images/collapse.gif','images/expand.gif');

	var message = "ControlID=Map1&ControlType=Map&EventArg=MapIdentify&Map1_mode=MapIdentify&minx=" + zleft + "&miny=" + ztop;
	var context = map.controlName;
	eval(map.identifyCallbackFunctionString);
	
	var div = document.getElementById("IdentifyLocation");
	// point is bottom center... 2 pixels up for shadow
	var cWidth = Math.floor(div.clientWidth / 2);
	var cHeight = div.clientHeight;

	//alert(cWidth + " x " + cHeight); // width and height might not be available on first time.... if so, approximate size needed

	if (cWidth==0) cWidth = 12;
	if (cHeight==0) cHeight = 29;
	var idLeft = zleft - parseInt(map.divObject.style.left) - cWidth;
	var idTop = ztop - parseInt(map.divObject.style.top) - cHeight + 2; // add two back for icon bottom

//	if (isIE) {
//	    idTop+=2; 
//	    //idLeft+=2;
//	}

    window.setTimeout('moveLayer("IdentifyLocation", ' + idLeft + ', ' + idTop + '); showLayer("IdentifyLocation");', 0);
	map.mode = map.tempMode;
	map.actionType = map.tempAction;
	map.cursor = map.tempCursor;
	
	// alert("End of Map Identify JS function");
	return false;
}

function addIdentifyLocation() 
{
    var content = '<div id="IdentifyLocation" style="position: absolute; left: 0px; top: 0px; visibility: hidden;">';
    if (isIE  && ieVersion < 7 && (identifyImageType.toLowerCase()=="png")) 
	    content += '<img src="' + identifyFilePath + 'images/blank.gif" alt="" border="0"  hspace="0" vspace="0" style="filter:  progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + identifyFilePath + 'images/identify-map-icon.png\');" />\n';
	else
	    content += '<img src="' + identifyFilePath + 'images/identify-map-icon.png" alt="" border="0"  hspace="0" vspace="0" />\n';
    content += '</div>';
    map.overlayObject.insertAdjacentHTML("BeforeEnd", content);
}



function getGoogleCoor()
{
 
  var x = document.all.GoogleDiv.innerHTML; 

 // [ENVELOPE minx=-88.3161855227344 miny=23.6792190932863 maxx=-78.7851284252297 maxy=31.4071032263982 minz=NaN maxz=NaN]
   
 var temp = new Array();
 temp = x.split(' ');

 // -----------------------------------------
 
// alert(temp[1]);
 var tempMinXstr = new Array();
 tempMinXstr = temp[1].split("=");
 
 var tempMinX = new Array();
 tempMinX = (+tempMinXstr[1]);
 
 // -----------------------------------------
 
 var tempMinYstr = new Array();
 tempMinYstr = temp[2].split("=");
 
 var tempMinY = new Array();
 tempMinY = (+tempMinYstr[1]);  
   
 // -----------------------------------------  
   
 var tempMaxXstr = new Array();
 tempMaxXstr = temp[3].split("=");
 
 var tempMaxX = new Array();
 tempMaxX = (+tempMaxXstr[1]);
 
 // -----------------------------------------
 
 var tempMaxYstr = new Array();
 tempMaxYstr = temp[4].split("=");
 
 var tempMaxY = new Array();
 tempMaxY = (+tempMaxYstr[1]);  
   
 // -----------------------------------------  
   
var midPtX = (+((tempMaxX + tempMinX) / 2))
var midPtY = (+((tempMaxY + tempMinY) / 2))

//alert("tempMinX" + tempMinX + tempMinY);

//alert(tempMinX + ";" + tempMinY + ";" + tempMaxX + ";" + tempMaxY); 

//xx = Math.abs(tempMaxX);
//alert(xx);  

//alert(Math.abs(tempMinY));  
var diff = Math.abs( Math.round(Math.abs(tempMaxX) - Math.abs(tempMinX)));

//alert("orriginal diff = " + diff);

diff  = ((9.531057 - diff) * 1.0506607) + 6


//  
//return midPtX + ";" + midPtY  + ";" + Math.round(diff);  
return midPtX + ";" + midPtY  + ";" + tempMinY + ";" + tempMinX+ ";" + tempMaxY + ";" + tempMaxX;  


}
 
 
function openGoogle()
{ 

var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');

if(mine)
    {
    var popUpsBlocked = false;
     mine.close();
    }
 else
    {
    var popUpsBlocked = true;
    alert('Please disable your pop-up blocker to use the Google Map feature.');
    mine.close();
    return;
    }

 //alert("yes inside open google");
 var GoogleCoor =  getGoogleCoor();

 values = new Array();
 values = GoogleCoor.split(";");
 lon=values[0];
 lat=values[1];
 
// alert(values[0]);

HTMLstring = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
HTMLstring+= '<html xmlns="http://www.w3.org/1999/xhtml">\n'
HTMLstring+= '<head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>\n'
HTMLstring+= '<title>GOOGLE MAP</title>\n'
HTMLstring+= '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAB94pBwy_sdqIFBoIhGHokRRXZKmwEIIkg6m7_8n3AtOSuF9wYhRmNAk0SlzXQBDF-fF0kBLNYD0UNQ" type="text/javascript"></scr'+'ipt>\n'
HTMLstring+='<script type="text/javascript">\n'
HTMLstring+='function load() {   if (GBrowserIsCompatible()) {\n'
HTMLstring+= 'var map = new GMap2(document.getElementById("map"));\n'
HTMLstring+= ' map.addControl(new GSmallMapControl());\n'
HTMLstring+= 'map.addControl(new GMapTypeControl());\n'
// HTMLstring+= 'map.setMapType(G_SATELLITE_MAP);\n' 

HTMLstring+= 'var bounds = new GLatLngBounds(new GLatLng(' + values[2] + ',' + values[3] + '), new GLatLng(' + values[4] + ',' + values[5] + '));\n' 
HTMLstring+= 'var zoom = map.getBoundsZoomLevel(bounds,map.getSize());\n'
HTMLstring+= 'zoom = (zoom * 1);\n'
HTMLstring+= 'map.setCenter(new GLatLng('+ lat + ',' + lon + '),  zoom ,G_HYBRID_MAP);  } } \n'


//HTMLstring+= 'map.setCenter(new GLatLng('+ lat + ',' + lon + '), '+ zoom + ',G_HYBRID_MAP);  } } \n'
HTMLstring+= '</scr' + 'ipt>'
HTMLstring+= '</head>\n'

HTMLstring+= '<body onload="load()" onunload="GUnload()" bgcolor="black">\n'
HTMLstring+= '<div id="map" style="width: 600px; height: 600px"></div>\n'
HTMLstring+= '<div id="Disclaimer" style="color:white;">Google map feature of the tool is only a add on free feature.</div>\n'
HTMLstring+= '</body> </html>\n'

//alert(HTMLstring);
newwindow=window.open("", "newwin", "left=500,top=100,height=630, width=620,toolbar=no,scrollbars="+scroll+",menubar=no");
newdocument=newwindow.document;
newdocument.write(HTMLstring);
newdocument.location.reload();
newdocument.close();
newdocument.focus();
self.name="main"
} 

function openLegend()
{ 

var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=yes');

if(mine)
    {
    var popUpsBlocked = false;
     mine.close();
    }
 else
    {
    var popUpsBlocked = true;
    alert('Please disable your pop-up blocker to view the Map Legend.');
    mine.close();
    return;
    }

HTMLstring = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
HTMLstring+= '<html xmlns="http://www.w3.org/1999/xhtml">\n'
HTMLstring+= '<head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>\n'
HTMLstring+= '<title>LEGEND</title>\n'
HTMLstring+= '</head>\n'
HTMLstring+= '<body bgcolor="gray">\n'
HTMLstring+= '<div id="legend" style="width: 400px; height: 400px"><img src=images/Legend.JPG align=\"center\"></img></div>\n'
HTMLstring+= '</body> </html>\n'
//alert(HTMLstring);
newwindow=window.open("", "newwin2", "left=500,top=100,height=580, width=800,toolbar=no,scrollbars=yes,menubar=no, resizable=yes");
newdocument=newwindow.document;
newdocument.write(HTMLstring);
newdocument.location.reload();
newdocument.close();
newdocument.focus();
self.name="Legend"

} 
  
function getResult(x) 
{
 // alert("function getResult(x)");
  openindex(x);
 // callPostBack();
 // alert ("End function getResult(x)");	   
}
function openindex(str1)
{
  var HTMLstring = "";
   
  values1 = new Array();
  
  values1 = str1.split("@@");
   
 
 if (values1[0] == "")
 {
  document.all.testing.innerHTML = "<div style=\"float:left;text-align:left;font-size:medium;font-style:italic;font-weight:bold;color:Green;top:35px;left:45px;position:relative;width:350px;height:25px;border:solid 0px White;\" > Please zoom in closer and click on a SIS facility</div>";
  return;
 }
 
 if (values1[0] == "Planned Corridors")
 {
    HTMLstring+= '    <table  align ="center"   border="2" bgcolor="F0FFF0" bordercolor="blue" width="375" CELLPADDING=1 cellspacing=1>\n'
    HTMLstring+= '\n'
    HTMLstring+= '     <tr >\n'
    HTMLstring+= '     <td class = "nhead" style="color:white;" bgcolor ="light gray" COLSPAN=6> <b> Planned Facility Data </b> </font></td>\n'
    HTMLstring+= '     </tr>\n'
    HTMLstring+= '\n'
    HTMLstring+= '\n'
    HTMLstring+= '     <tr>\n'
    HTMLstring+= '     <td class = "rcell" width=240 >Projected to meet designation criteria within three years of opening </td>\n'
    HTMLstring+= '     <td class = "ncell2"colspan=5 > <b> ' + "Yes" + ' </b></td>\n'
    HTMLstring+= '\n'
    HTMLstring+= '\n'
    HTMLstring+= '     </tr>\n'
    HTMLstring+= '\n'
    HTMLstring+= '      <tr>\n'
    HTMLstring+= '     <td class = "rcell" width=240>Financially feasible</td>\n'
    HTMLstring+= '     <td class = "ncell2" colspan=5> <b> ' + "Yes" + ' </b></td>\n'
    HTMLstring+= '\n'
    HTMLstring+= '\n'
    HTMLstring+= '     </tr>\n'
    HTMLstring+= '\n'
    HTMLstring+= '     <tr>\n'
    HTMLstring+= '     <td class = "rcell" width=240>Evidence of partner consensus</td>\n'
    HTMLstring+= '     <td class = "ncell2" colspan=5> <b> ' + "Yes" + ' </b></td>\n'
    HTMLstring+= '\n'
    HTMLstring+= '\n'
    HTMLstring+= '     </tr>\n'
    HTMLstring+= '\n'
    HTMLstring+= '\n'
    HTMLstring+= '    </table>\n'
    HTMLstring+= '    <br> <h4 align="center"> Please note that there is no activity data currently available for this planned facility </h4>'
    document.all.testing.innerHTML = HTMLstring;
  //return;
 }
  
           var control;
           sisidss= "";
            for ( var ii=0; ii < values1.length; ii++ )
            {  
                 str = "";
                 str = values1[ii]; 
              //   alert("values1[" + ii + "] = " + values1[ii]);  
                                 if (str != "") 
                                 {   
                                             values = new Array();
                                             values = str.split(";");
                                            //    document.all.TabContainer1_TabPanel1_txtSISID.value = "";  
                                                  
                                                 for ( var i=0; i < values.length; i++ )
                                                 {
                                                        //  alert(values[i]);                                                          
                                                          if (values[i] == "STD_ID")
                                                          {
                                                        //        document.all.TabContainer1_TabPanel1_txtSIStyp.value = "2";
                                                        //        document.all.TabContainer1_TabPanel1_txtSISID.value = values[i+1];
                                                             sisidss = sisidss + "/" + values[i+1];
                                                      //          document.all.TabContainer1_TabPanel1_txtFacName.value = values[0];
//                                                             var btn = document.getElementById("TabContainer1_TabPanel3_btnSubmit");
//                                                             if (btn) btn.click();
                                                          }  
                                                          
                                                          else if (values[i] == "STD_ID(04)")
                                                          {
                                                           //     document.all.TabContainer1_TabPanel1_txtSIStyp.value = "2";
//                                                             if(document.all.TabContainer1_TabPanel1_txtSISID.value == "0")
//                                                             {
//                                                              document.all.TabContainer1_TabPanel1_txtSISID.value = "(04)" + values[i+1];
//                                                              sisidss = sisidss + "/" + values[i+1];
//                                                             }
//                                                             else
//                                                             {
//                                                              document.all.TabContainer1_TabPanel1_txtSISID.value = document.all.TabContainer1_TabPanel1_txtSISID.value + "(04)" + values[i+1];
//                                                              sisidss = sisidss + "/" + values[i+1];
//                                                             }
//                                                             document.all.TabContainer1_TabPanel1_txtFacName.value = values[0];
//                                                             var btn = document.getElementById("TabContainer1_TabPanel3_btnSubmit");
//                                                             if (btn) btn.click();
                                                          }  
                                                          
                                                           else if (values[i] == "STD_ID(05)")
                                                          {
//                                                             document.all.TabContainer1_TabPanel1_txtSIStyp.value = "2";
//                                                             if(document.all.TabContainer1_TabPanel1_txtSISID.value == "0")
//                                                             {
//                                                              document.all.TabContainer1_TabPanel1_txtSISID.value = "(05)" + values[i+1];
//                                                              sisidss = sisidss + "/" + values[i+1];
//                                                             }
//                                                             else
//                                                             {
//                                                              document.all.TabContainer1_TabPanel1_txtSISID.value = document.all.TabContainer1_TabPanel1_txtSISID.value + "(05)" + values[i+1];
//                                                              sisidss = sisidss + "/" + values[i+1];
//                                                             } 
//                                                             document.all.TabContainer1_TabPanel1_txtFacName.value = values[0];
////                                                             var btn = document.getElementById("TabContainer1_TabPanel3_btnSubmit");
//                                                             if (btn) btn.click();
                                                          }  
                                                   }  // for ( var i=0; i < values.length; i++ )
                                     
                                        //   alert(str);
                                     
                                           HTMLstring =  HTMLstring + '</br>' +  MakeDataView(str);
                                          
                                         //  alert(str);
                              
                                     } // if (str != "") 
                                     
            } //for ( var ii=0; ii < values1.length; ii++ )
    
    
    if (HTMLstring == "</br>")
    {
         if (values1[0] == "Please Zoom in closer and Select a Single Highway Link.")
         {
           HTMLstring =  '</br>&nbsp&nbsp<span style=\"color:red; font-weight:bold;\">Please Zoom in closer and Select a Single Highway Link.</span></br>' + HTMLstring
         }
    }
    else
    {
         HTMLstring =  '</br>&nbsp&nbsp<span style=\"color:red; font-weight:bold;\">Click on Links for Explanations</span></br>' + HTMLstring
    }
   
     //   alert("HTMLstring = " + HTMLstring);
        
     document.all.testing.innerHTML = HTMLstring; 
    
     //var control = document.getElementById("HiddenField1");
 
    // control.value =  sisidss;
     
    // PanelUpdate();
  
}

