﻿

function tagglingTabs(){
           dojo.byId("eventReport").innerHTML="<div id='eventReportText'><span class='addresstext'>(Street, City, State, Zip Code) </span><br/> &nbsp;&nbsp;<input id='text1' title='Enter an Address' type='text' onkeypress='return searchKeyPress(event)'/> &nbsp;&nbsp; <input id='btnfindlocation' type='button' value='find' onclick='locate();'/></div><div id=\"addressResult\"></div>"; 
           dojo.byId("addresstab").innerHTML="<img id='addressImg' src='images/address3.jpg'/>";
           
           //for address tab 
           dojo.query(".address","queryWrapper").onclick(function(evt){
           dojo.byId("eventReport").innerHTML="<div id='eventReportText'><span class='addresstext'>(Street, City, State, Zip Code) </span><br/> &nbsp;&nbsp;<input id='text1' title='Enter an Address' type='text' onkeypress='return searchKeyPress(event)'/> &nbsp;&nbsp; <input id='btnfindlocation' type='button' value='find' onclick='locate();'/></div><div id=\"addressResult\"></div>"; 
            //set address tab as active
           dojo.byId("addresstab").innerHTML="<img id='addressImg' src='images/address3.jpg'/>";
            //set remaining tabs inactive
            dojo.byId("layerstab").innerHTML="<img id='layersImg' onmouseover=\"rolloverOn('layersImg')\" onmouseout=\"rolloverOff('layersImg')\" src='images/layers1.jpg'/>";
            dojo.byId("printtab").innerHTML="<img id=\"printImg\" onmouseover=\"rolloverOn('printImg')\" onmouseout=\"rolloverOff('printImg')\" src='images/print1.jpg'  alt=\"Click to print the map\"/>";
            dojo.byId("text1").value=addressText;
           });
           
           //for layers tab
           dojo.query(".layers", "queryWrapper").onclick(function(evt) {
               dojo.byId("eventReport").innerHTML = "<div id='eventReporttext'><span class='layersText'> <input id=\"windSpeedLayer\" value=\"LA_BWSLayer\" type=\"checkbox\" onclick='turnOn_OffLayers(this);' checked/> Wind Speed</span>&nbsp;&nbsp;<input type='button' value='Speed layer info' onclick='speedLayerInfo();'/>&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='Elevation info' onclick='ElevationInfo();'/></div>";
               //add parishes to the drop down
               try {
                   //if wind speed layers is visible then check the wind speed check box else unchekc the box

                   dojo.byId("windSpeedLayer").checked = (map.getLayer("LA_BWSLayer").visible) ? true : false;

//                   if (map.getLayer("LA_BWSLayer").visible) {
//                       dojo.byId("").checked = true;
//                   }
//                   else {
//                       dojo.byId("").checked = true;
//                   }
               }
               catch (Error) {
                   window.alert(Error.description);
               }



               //set layers tab as active tab
               dojo.byId("layerstab").innerHTML = "<img id='layersImg' src='images/layers3.jpg'/>";
               //set remaining tabs inactive
               dojo.byId("addresstab").innerHTML = "<img id='addressImg' onmouseover=\"rolloverOn('addressImg')\" onmouseout=\"rolloverOff('addressImg')\" src='images/address1.jpg'/>";
               dojo.byId("printtab").innerHTML = "<img id=\"printImg\" onmouseover=\"rolloverOn('printImg')\" onmouseout=\"rolloverOff('printImg')\" src='images/print1.jpg'  alt=\"Click to print the map\"/>";

           });
           
          
           
           //for print tab
            dojo.query(".print", "queryWrapper").onclick(function(evt){                
             dojo.byId("eventReport").innerHTML = "<div class='eventReporttext'><span style='font-size:8pt; font-weight:bold; padding:2px 5px 0 5px;'>Title <input type='text' id=\"titlePrint\" style='width:200px;' id='mapName' /> &nbsp; &nbsp;<input type='button' text='Preview'  value='Preview' onclick='openNewWindow();'/></span></div>";
             //set print tab active
             dojo.byId("printtab").innerHTML="<img id='printImg' src='images/print3.jpg'/>";
             //set remaining tabs inactive
            dojo.byId("addresstab").innerHTML="<img id='addressImg' onmouseover=\"rolloverOn('addressImg')\" onmouseout=\"rolloverOff('addressImg')\" src='images/address1.jpg'/>";
            dojo.byId("layerstab").innerHTML="<img id='layersImg' onmouseover=\"rolloverOn('layersImg')\" onmouseout=\"rolloverOff('layersImg')\" src='images/layers1.jpg'/>";
      
          });
          
          
          //for roads button
          dojo.byId("roadsImgDiv").innerHTML="<img id=\"roadImg\" onclick=\"changeMap('streetMap');\" src='images/roads3.jpg'/>";
          dojo.query(".roads","roads_aerial_hybrid").onclick(function(evt){
                      dojo.byId("roadsImgDiv").innerHTML="<img id=\"roadImg\" onclick=\"changeMap('streetMap');\" src='images/roads3.jpg'/>";
                      dojo.byId("hybridImgDiv").innerHTML="<img id=\"hybridImg\" onclick=\"changeMap('hybridMap');\" onmouseover=\"rolloverOn('hybridImg');\" onmouseout=\"rolloverOff('hybridImg');\" src='images/hybrid1.jpg'/>";
                      dojo.byId("aerialImgDiv").innerHTML="<img id=\"aerialImg\" onclick=\"changeMap('aerialMap');\" onmouseover=\"rolloverOn('aerialImg');\" onmouseout=\"rolloverOff('aerialImg');\" src='images/aerial1.jpg'/>"; 
          });
          
           //for aerial button
          dojo.query(".aerial","roads_aerial_hybrid").onclick(function(evt){
                      dojo.byId("aerialImgDiv").innerHTML="<img id=\"aerialImg\" onclick=\"changeMap('aerialMap');\" src='images/aerial3.jpg'/>"; 
                      dojo.byId("roadsImgDiv").innerHTML="<img id=\"roadImg\"  onmouseover=\"rolloverOn('roadImg');\" onmouseout=\"rolloverOff('roadImg');\" onclick=\"changeMap('streetMap');\" src='images/roads1.jpg'/>";
                      dojo.byId("hybridImgDiv").innerHTML="<img id=\"hybridImg\" onclick=\"changeMap('hybridMap');\" onmouseover=\"rolloverOn('hybridImg');\" onmouseout=\"rolloverOff('hybridImg');\" src='images/hybrid1.jpg'/>";

          });
          
          //for hybrid button
          dojo.query(".hybrid","roads_aerial_hybrid").onclick(function(evt){
                      dojo.byId("roadsImgDiv").innerHTML="<img id=\"roadImg\"  onmouseover=\"rolloverOn('roadImg');\" onmouseout=\"rolloverOff('roadImg');\" onclick=\"changeMap('streetMap');\" src='images/roads1.jpg'/>";
                      dojo.byId("hybridImgDiv").innerHTML="<img id=\"hybridImg\" onclick=\"changeMap('hybridMap');\" src='images/hybrid3.jpg'/>";
                      dojo.byId("aerialImgDiv").innerHTML="<img id=\"aerialImg\" onclick=\"changeMap('aerialMap');\" onmouseover=\"rolloverOn('aerialImg');\" onmouseout=\"rolloverOff('aerialImg');\" src='images/aerial1.jpg'/>"; 
          });
          
         
}

function turnOn_OffLayers(cb)
    {
        
        var layer=map.getLayer(String(cb.value));
        
        if(cb.checked == true)
            {
                layer.show();               
                toggleWind(1);
                dijit.byId("on_off").setChecked(true);
               //countVisibleLayers() 
            }
        else
            {
                layer.hide();
                toggleWind(0);
                dijit.byId("on_off").setChecked(false);
            //countVisibleLayers()
            }
    }
    
    
function openNewWindow()
    {
       var data="";//=dojo.byId("dataPoints").innerHTML ;
       var tit=dojo.byId("titlePrint").value;
       
       var g=map.graphics.graphics;
                      for(var x=0; x<g.length; x+=2)
                        {
                             if(x%2 == 0)
                                {
                                   data+="Lat:" + g[x].attributes.Yval+ ",Long:" + g[x].attributes.Xval + ",Speed:" + g[x].attributes.Speed +",Elevation:" + g[x].attributes.Elevation + "_";
                                }                         
                            
                        }
            var layers="";            
//        for(var lay=0; lay < map.layerIds.length; lay++)
//            {
//                if(map.getLayer(map.layerIds[lay]).visible)
//                    {
//                        layers+=map.getLayer(map.layerIds[lay]).id +",";
//                    }
//            }

            for (var lay = 0; lay < 3; lay++) {
                if (map.getLayer(map.layerIds[lay]).visible) {
                    //alert(lay + " " +map.getLayer(map.layerIds[lay]).id);
                    layers += map.getLayer(map.layerIds[lay]).id;
                }
            }    
                         
        var s = "";
      s = "XMin="+ map.extent.xmin
      +"&YMin=" + map.extent.ymin
      +"&XMax=" + map.extent.xmax
      +"&YMax=" + map.extent.ymax 
      +"&data=" + data + "&l=" + layers;
      if(tit !=="")
        {
            s+="&t=" + tit;
        }

        var Xmin,Ymin,Xmax,Ymax,layer1,layer2, g1x,g1y,g2x,g2y;
        //window.alert(map.getLevel());
//        var winPrint = window.open('print.htm?' + s, '', '');
        if (navigator.appName == "Microsoft Internet Explorer") {
            var winPrint = window.open('print.aspx?' + s, '', '');
        } else {
            var winPrint = window.open('print.htm?' + s, '', '');
        } 
        
        
    }
    
function speedLayerInfo()
    {
        
         var infoWindow=window.open('','','left=0,top=0,width=340,height=600,toolbar=no,scrollbars=yes');
        infoWindow.document.write("<html><head></head><body style='background-color:#D8DCE0;font-size:10pt;'>");
        infoWindow.document.write("<div style='width:280px;height:380px; text-align:justify;'>");
        infoWindow.document.write("<p>The Winds Layer was created from a dataset provided by ICF International for the 2003 IRC/IBC Wind Speed Map for the State of Louisiana.<p/>" +

                "<p>The original dataset was a set of polylines that was digitized by FEMA from a hard copy of wind contour maps. " +
                "The contours were then digitized at 10 mph interval. "+
                "For the purpose of the study conducted by ICF international, this dataset was modified from its original state by employing several geo-processing steps:</p>" +

                "<p><ul><li>The Wind Speed line data was converted to points.</li>"+ 
                "<li>The shape point file was then dissolved and converted to a shape file for the State of LA to polyline.</li>"+ 
                "<li>The Wind speed lines were converted to vertices are then interpolated to raster using the Natural Neighbor interpolation method from the 3D Analyst toolset.</li>"+ 
                "<li>The interpolated raster was then contoured using the 3D Surface analysis tool.</li>"+ 
                "<li>The contours warranted some manual editing (Edit the gaps in the interpolated lines) </li>"+
                "<li>Merged the Wind speed lines and the dissolved state of LA polygon.</li>"+ 
                "<li>Converted the merged Wind speed lines and the LA to a polygon using the feature to polygon tool.</li></ul></p>"+

                "<p>The result is a wind contour map with 1 mph increments.</p>");        
        infoWindow.document.write("</div></body></html>");
    }   
    
function ElevationInfo()
    {
        var infoWindow=window.open('','','left=0,top=0,width=340,height=400,toolbar=no,scrollbars=yes');
        infoWindow.document.write("<html><head></head><body style='background-color:#D8DCE0;font-size:10pt;'>");
        infoWindow.document.write("<div style='width:280px;height:380px; text-align:justify;'>");
        infoWindow.document.write("<p>The elevation information is being provided courtesy of <a href='http://www.usgs.gov/'>USGS's</a> Elevation Query Web Service. </p>" +

                                   "<p>The Elevation Query Web Service returns the elevation in feet or meters for a specific latitude/longitude point from the USGS Seamless Elevation data sets hosted at USGS/EROS. "+
                                   "The elevation values are returned default to the best-available (highest resolution) data source available at the specified point. Alternately, this service may return the value from a specified data source, or from all data sources."+
                                   " If unable to find data at the requested point, this services returns an extremely large, negative value.</p>");

        infoWindow.document.write("</div></body></html>");
    } 
    
     //function to disable form submission when enter key is pressed to locate an address
    function searchKeyPress(e)
        {
      
            var key;
            if(window.event)
                key=window.event.keyCode; //IE
            else
                key=e.which; //FF
            if(key == 13)
                {
                    dojo.byId("btnfindlocation").onclick();
                }    
           return (key != 13);
          
        }
