﻿// JScript File
    
    
        
        var map; 
        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        var baseIcon = new GIcon();
        //baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(25, 30);
        //baseIcon.shadowSize = new GSize(25, 35);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        //baseIcon.infoShadowAnchor = new GPoint(18, 25);
        var arrStationDataAll;//coantains all the records of all the stations separated by "|".
        var arrStationDataIndividual;//contains individual records split by "/" for separating all field values of each station.
        function initialize(WeatherVariable,strStationData)
        {
            if (GBrowserIsCompatible())
            {
                map= new GMap2(document.getElementById("map_canvas"));                
                var mapControl = new GMapTypeControl();                                             
                map.addControl(mapControl); 
                map.addControl(new GLargeMapControl());
                map.setCenter(new GLatLng(33.7682, -116.3787), 13);
                map.setMapType(G_HYBRID_MAP);
                map.setZoom(10);  
                //var WeatherVariable="T";              
                createOverlay(WeatherVariable,strStationData);                                  
            }
        }
   
        // Creates a marker whose info window displays the letter corresponding
        // to the given index.
        function createMarker(point,strStationName,strCity,strTime,Temperature,wind,gust,Humidity,DewPoint,RainfallSinceMidNight,WeatherVariable,strLink)
         {  
            var strDisplayName=strStationName;
            //var WeatherVariable="T";  
            var checkSign="False";
                switch (WeatherVariable)
                {               
                    case "T":
                        WV=Temperature;
                        document.getElementById("divWP").innerText = "Current Temperatures";
                        document.getElementById("divWP").textContent = "Current Temperatures";
                        break;
                    case "W":
                        WV=wind;
                        document.getElementById("divWP").innerText = "Current Wind Speed";
                        document.getElementById("divWP").textContent = "Current Wind Speed";
                        break;
                    case "G":
                        WV=gust;
                        document.getElementById("divWP").innerText = "Current Wind Gust";
                        document.getElementById("divWP").textContent = "Current Wind Gust";
                        break;                       
                    case "H":
                        WV=Humidity;
                        document.getElementById("divWP").innerText = "Current Humidity";
                        document.getElementById("divWP").textContent = "Current Humidity";
                        break;
                    case "D":
                        WV=DewPoint;                        
                        document.getElementById("divWP").innerText = "Current Dew Point";
                        document.getElementById("divWP").textContent = "Current Dew Point";
                        break;
                    case "R":
                        WV=RainfallSinceMidNight;
                        document.getElementById("divWP").innerText = "Current Rainfall";
                        document.getElementById("divWP").textContent = "Current Rainfall";
                        break;
                }
            if(WV<0)
            {
                checkSign="True";  
                WV=-(WV);              
                            
            }

                
            
            if(WV=="-")
            {
                WV="";    
            }
            else
            {
                
                    
                if(WeatherVariable=="T" || WeatherVariable=="D")
                {
                  WV+="<sup>0</sup>" + "F";
                } 
                if(checkSign=="True")
                    WV="<table style='font-size: 12px;halign:left;color:white;'><tr><td>" + "-" + "</td><td>" + WV + "</td></tr></table>"
                else                    
                    WV="<div style='font-size: 12px;halign:left;color:white;direction:ltr;display:inline-table;text-decoration:'blink';>"+WV+"</div>";
            }              
            if(strStationName=="-")
            {
                strStationName="";    
            }
            else
            {
                strStationName= "<tr><td>" + "Station : " + strStationName + "</td></tr>";
            }       
            if(strCity=="-")
            {
                strCity="";    
            }
            else
            {
                strCity= "<tr><td>" + "City : " + strCity + "</td></tr>";
            }      
            if(strTime=="-")
            {
                strTime="";    
            }
            else
            {
                strTime= "<tr><td>" + "Latest Update : " + strTime + "</td></tr>";
            }         
            if(Temperature=="-")
            {
                Temperature="";    
            }
            else
            {
                Temperature= "<tr><td>" + "Temperature :" + Temperature + "&#176" + " F"+ "</td></tr>";
            }            
            
            if(wind=="-")
            {
                wind="";    
            }
            else
            {
                wind="<tr><td>" + "Wind : " + wind + "</td></tr>";
            }
            if(gust=="-")
            {
                gust="";    
            }
            else
            {
                gust="<tr><td>" + "Gust : " + gust + "</td></tr>";
            }            

            if(Humidity=="-")
            {
                Humidity="";    
            }
            else
            {
                Humidity="<tr><td>" + "Humidity : " + Humidity + "</td></tr>";
            }
            
            if(DewPoint=="-")
            {
                DewPoint="";    
            }
            else
            {
                DewPoint="<tr><td>" + "Dew Point :" + DewPoint + "&#176" + " F"  + "</td></tr>";
            }
            
            if(RainfallSinceMidNight=="-")
            {
                RainfallSinceMidNight="";    
            }
            else
            {
                RainfallSinceMidNight="<tr><td>" + "Rainfall Since Midnight : " + RainfallSinceMidNight + "</td></tr>";
            }
            //strStationData="Station ID : " + StationID + "</br>" + strTime + Temperature + wind + Humidity + DewPoint + RainfallSinceMidNight;            
            // Create a lettered icon for this point using our icon class
            // Set up our GMarkerOptions object
            //if(strTime!="-" && Temperature!="-" && wind!="-" && Humidity!="-" && DewPoint!="-" && RainfallSinceMidNight!="-")
            //{
                var icon = new GIcon();
                icon.image ='images/icHouse.png'//'http://gmaps-samples.googlecode.com/svn/trunk/markers/circular/redcirclemarker.png';
                if(WeatherVariable=='T' || WeatherVariable=='D' || WeatherVariable=='H' || WeatherVariable=='R')
                {
                    icon.iconSize = new GSize(50, 30);
                    }
                 else
                 {
                    icon.iconSize = new GSize(100, 30);   
                    }
                icon.iconAnchor = new GPoint(16, 16);
                icon.infoWindowAnchor = new GPoint(25, 7);
                //    letteredIcon.image = "images/orange-dot.png";
                //markerOptions = { icon:letteredIcon };
                //markerOptions.text="land";
                
               opts = { 
                  "icon": icon,
                  "clickable": true,
                  "title": strDisplayName,                  
                  "labelText": WV, 
                  "labelOffset": new GSize(-6, -10)
                };
                opts.text="land";
                var marker = new LabeledMarker(point, opts);
               
                //var marker = new GMarker(point, markerOptions);
                GEvent.addListener(marker, "click", function() {
                //marker.openInfoWindowHtml("<table border='0' style='font-size:x-small;'>" + "<tr><td>" + "StationID : " + StationID + "</td>" + "<tr><td>" + "Time Of Observation : " + strTime + "</td></tr>" + "<tr><td>" + "Temperature :" + Temperature + "</td></tr>" + "<tr><td>" + "Wind : " + wind + "</td></tr>" + "<tr><td>" + "Humidity : " + Humidity + "</td></tr>" + "<tr><td>" + "Dew Point :" + DewPoint + "</td></tr>" + "<tr><td>" + "Rainfall Since Midnight : " + RainfallSinceMidNight + "</td></tr></table>");
                
                marker.openInfoWindowHtml("<table border='0' style='font-size:8pt;width:200pt;'><tr><td>" + strStationName + strCity + strTime + Temperature + wind + gust + Humidity + DewPoint + RainfallSinceMidNight + "</td></tr><tr><td>" + "<a href='" + strLink + "' target='_blank' style='font-size:8pt;color:blue;'>Click Here for This Station’s complete Weather Page</a>"  + "</td></tr></table>");
                });
                return marker;
        }
        
        function createOverlay1(WeatherVariable)
        {
        try //Internet Explorer
          {
          xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
          }
        catch(e)
          {
          try //Firefox, Mozilla, Opera, etc.
            {
            xmlDoc=document.implementation.createDocument("","",null);
            }
          catch(e) {alert(e.message)}
          }
        try 
          {
              xmlDoc.async=false;
              xmlDoc.load("StationData.xml");
              x=xmlDoc.getElementsByTagName("LatLong");
              var la;
              var lo;
              for (i=0;i<x.length;i++)
              {
               la=(xmlDoc.getElementsByTagName("Latitude")[i].childNodes[0].nodeValue);
               lo=(xmlDoc.getElementsByTagName("Longitude")[i].childNodes[0].nodeValue);
               var latlng = new GLatLng(la,lo);
               var StationID=(xmlDoc.getElementsByTagName("StationID")[i].childNodes[0].nodeValue);
               var Temperature=(xmlDoc.getElementsByTagName("Temperature")[i].childNodes[0].nodeValue);
               var wind=(xmlDoc.getElementsByTagName("WindSpeedDirection")[i].childNodes[0].nodeValue);
               var gust=(xmlDoc.getElementsByTagName("WindGustDirection")[i].childNodes[0].nodeValue);
               var Humidity=(xmlDoc.getElementsByTagName("Humidity")[i].childNodes[0].nodeValue);
               var DewPoint=(xmlDoc.getElementsByTagName("DewPoint")[i].childNodes[0].nodeValue);
               var RainfallSinceMidNight=(xmlDoc.getElementsByTagName("RainfallSinceMidNight")[i].childNodes[0].nodeValue);
               var strTime=(xmlDoc.getElementsByTagName("TimeOfObservation")[i].childNodes[0].nodeValue);
               var strStationName=(xmlDoc.getElementsByTagName("StationName")[i].childNodes[0].nodeValue);
               var strCity=(xmlDoc.getElementsByTagName("City")[i].childNodes[0].nodeValue);
               var strLink=(xmlDoc.getElementsByTagName("srclink")[i].childNodes[0].nodeValue);
               var WVData="-";
               switch (WeatherVariable)
                {               
                    case "T":
                        WVData=Temperature;
                        break;
                    case "W":
                        WVData=wind;
                        break;
                    case "G":
                        WVData=gust;
                        break;                       
                    case "H":
                        WVData=Humidity;
                        break;
                    case "D":
                        WVData=DewPoint;                        
                        break;
                    case "R":
                        WVData=RainfallSinceMidNight;
                        break;
                }
               if (WVData!="-")
               {
                 if(strStationName !="-" || strCity !="-" || strTime !="-" || Temperature!="-" || wind!="-" || gust!="-" || Humidity !="-" || DewPoint!="-" || RainfallSinceMidNight!="-")
                 {
                    //alert(RainfallSinceMidNight);
                    map.addOverlay(createMarker(latlng,strStationName,strCity,strTime,Temperature,wind,gust,Humidity,DewPoint,RainfallSinceMidNight,WeatherVariable,strLink));                  
                 }      
               }
             
              }	     
          }
        catch(e) {alert(e.message)}
        }
      //------------------------
          
            function createOverlay(WeatherVariable,strStationData)
            {
            try
            {
                    
                    arrStationDataAll= strStationData.split("|");
                    for(var i=0;i<arrStationDataAll.length;i++)
                    {
                        arrStationDataIndividual=arrStationDataAll[i].split("^")
                        var la=arrStationDataIndividual[0];
                        var lo=arrStationDataIndividual[1];
                        var latlng = new GLatLng(la,lo);
                        var StationID=arrStationDataIndividual[2];
                        if(StationID==null)
                            StationID="-";
                        var Temperature=arrStationDataIndividual[3];
                        if(Temperature==null)
                            Temperature="-";    
                        var wind=arrStationDataIndividual[4];
                        if(wind==null)
                            wind="-";
                        var gust=arrStationDataIndividual[5];
                        if(gust==null)
                            gust="-";
                        var Humidity=arrStationDataIndividual[6];
                        if(Humidity==null)
                            Humidity="-"
                        var DewPoint=arrStationDataIndividual[7];
                        if(DewPoint==null)
                            DewPoint="-"
                        var RainfallSinceMidNight=arrStationDataIndividual[8];
                        if(RainfallSinceMidNight==null)
                            RainfallSinceMidNight="-";
                        var strTime=arrStationDataIndividual[9];
                        if(strTime==null)
                            strTime="-";
                        var strStationName=arrStationDataIndividual[10];
                        if(strStationName==null)
                            strStationName="-";
                        var strCity=arrStationDataIndividual[11];
                        if(strCity==null)
                            strCity="-";    
                        var strLink=arrStationDataIndividual[12];
                        if(strLink==null)
                            strLink="-";
                        var WVData="-";
                        switch (WeatherVariable)
                        {               
                            case "T":
                            WVData=Temperature;
                            break;
                            case "W":
                            WVData=wind;
                            break;
                            case "G":
                            WVData=gust;
                            break;                       
                            case "H":
                            WVData=Humidity;
                            break;
                            case "D":
                            WVData=DewPoint;                        
                            break;
                            case "R":
                            WVData=RainfallSinceMidNight;
                            break;
                        }
                        if (WVData!="-")
                        {
                            if(strStationName !="-" || strCity !="-" || strTime !="-" || Temperature!="-" || wind!="-" || gust!="-" || Humidity !="-" || DewPoint!="-" || RainfallSinceMidNight!="-")
                            {
                                //alert(RainfallSinceMidNight);
                                map.addOverlay(createMarker(latlng,strStationName,strCity,strTime,Temperature,wind,gust,Humidity,DewPoint,RainfallSinceMidNight,WeatherVariable,strLink));                  
                                //alert(arrStationDataIndividual[6])
                                //alert('</br>latlng='+latlng + '</br>strStationName=' + strStationName + '</br>strCity='+ strCity + '</br>strTime=' + strTime + '</br>Temperature=' + Temperature + '</br>wind=' + wind + '</br>gust=' + gust + '</br>Humidity=' + '</br>DewPoint='+ DewPoint + '</br>RainfallSinceMidNight=' + RainfallSinceMidNight + '</br>WeatherVariable=' + WeatherVariable + '</br>strLink='+ strLink)
                            }      
                       }
                       
                    } 
                    //WeatherVariable=WeatherVariable.replace("'","\'");
                    //alert(WeatherVariable);
                }
                catch(e) {alert(e.message);}
            }
          

         
        function initialize1(WeatherVariable)
        {
            if (GBrowserIsCompatible())
            {
                map= new GMap2(document.getElementById("map_canvas"));                
                var mapControl = new GMapTypeControl();                                             
                map.addControl(mapControl); 
                map.addControl(new GLargeMapControl());
                map.setCenter(new GLatLng(33.7682, -116.3787), 13);
                map.setMapType(G_HYBRID_MAP);
                map.setZoom(10);  
                //var WeatherVariable="T";              
                createOverlay2(WeatherVariable);                                  
            }
        }
              
              
              
              
            function createOverlay2(WeatherVariable)
            {
            try
            {
                    
                    
                    for(var i=0;i<arrStationDataAll.length;i++)
                    {
                        arrStationDataIndividual=arrStationDataAll[i].split("^")
                        var la=arrStationDataIndividual[0];
                        var lo=arrStationDataIndividual[1];
                        var latlng = new GLatLng(la,lo);
                        var StationID=arrStationDataIndividual[2];
                        if(StationID==null)
                            StationID="-";
                        var Temperature=arrStationDataIndividual[3];
                        if(Temperature==null)
                            Temperature="-";    
                        var wind=arrStationDataIndividual[4];
                        if(wind==null)
                            wind="-";
                        var gust=arrStationDataIndividual[5];
                        if(gust==null)
                            gust="-";
                        var Humidity=arrStationDataIndividual[6];
                        if(Humidity==null)
                            Humidity="-"
                        var DewPoint=arrStationDataIndividual[7];
                        if(DewPoint==null)
                            DewPoint="-"
                        var RainfallSinceMidNight=arrStationDataIndividual[8];
                        if(RainfallSinceMidNight==null)
                            RainfallSinceMidNight="-";
                        var strTime=arrStationDataIndividual[9];
                        if(strTime==null)
                            strTime="-";
                        var strStationName=arrStationDataIndividual[10];
                        if(strStationName==null)
                            strStationName="-";
                        var strCity=arrStationDataIndividual[11];
                        if(strCity==null)
                            strCity="-";    
                        var strLink=arrStationDataIndividual[12];
                        if(strLink==null)
                            strLink="-";
                        var WVData="-";
                        switch (WeatherVariable)
                        {               
                            case "T":
                            WVData=Temperature;
                            break;
                            case "W":
                            WVData=wind;
                            break;
                            case "G":
                            WVData=gust;
                            break;                       
                            case "H":
                            WVData=Humidity;
                            break;
                            case "D":
                            WVData=DewPoint;                        
                            break;
                            case "R":
                            WVData=RainfallSinceMidNight;
                            break;
                        }
                        if (WVData!="-")
                        {
                            if(strStationName !="-" || strCity !="-" || strTime !="-" || Temperature!="-" || wind!="-" || gust!="-" || Humidity !="-" || DewPoint!="-" || RainfallSinceMidNight!="-")
                            {
                                //alert(RainfallSinceMidNight);
                                map.addOverlay(createMarker(latlng,strStationName,strCity,strTime,Temperature,wind,gust,Humidity,DewPoint,RainfallSinceMidNight,WeatherVariable,strLink));                  
                                //alert(arrStationDataIndividual[6])
                                //alert('</br>latlng='+latlng + '</br>strStationName=' + strStationName + '</br>strCity='+ strCity + '</br>strTime=' + strTime + '</br>Temperature=' + Temperature + '</br>wind=' + wind + '</br>gust=' + gust + '</br>Humidity=' + '</br>DewPoint='+ DewPoint + '</br>RainfallSinceMidNight=' + RainfallSinceMidNight + '</br>WeatherVariable=' + WeatherVariable + '</br>strLink='+ strLink)
                            }      
                       }
                       
                    } 
                    //WeatherVariable=WeatherVariable.replace("'","\'");
                    //alert(WeatherVariable);
                }
                catch(e) {alert(e.message);}
            }

             
              
         
        
       
        
        /*
         switch(i)
                {
                    case 1:
                    {
                        
                    }
                    case 2:
                    {
                    
                    }
                    case 3:
                    {
                    
                    }
                    case 4:
                    {
                    
                    }
                    case 5:
                    {
                    
                    }
                    case 6:
                    {
                    
                    }
                    case 7:
                    {
                    
                    }
                    case 8:
                    {
                    
                    }
                    case 9:
                    {
                    
                    }
                    case 10:
                    {
                    
                    }
                    case 11:
                    {
                    
                    }
                    case 12:
                    {
                    
                    }
                    case 13:
                    {
                    
                    }
                    case 14:
                    {
                    
                    }
                    case 15:
                    {
                    
                    }
                    case 16:
                    {
                    
                    }
                    case 17:
                    {
                    
                    }
                    case 18:
                    {
                    
                    }
                    case 19:
                    {
                    
                    }
                    case 20:
                    {
                    
                    }
                    case 21:
                    {
                    
                    }
                    case 22:
                    {
                    
                    }
                    case 23:
                    {
                    
                    }
                    case 24:
                    {
                    
                    }
                    case 25:
                    {
                    
                    }
                    case 26:
                    {
                    
                    }
                    case 27:
                    {
                    
                    }
                    case 28:
                    {
                    
                    }
                    case 29:
                    {
                    
                    }
                    case 30:
                    {
                    
                    }
                    case 31:
                    {
                    
                    }
                    case 32:
                    {
                    
                    }
                    case 33:
                    {
                    
                    }
                    case 34:
                    {
                    
                    }
                    case 35:
                    {
                    
                    }
                    case 36:
                    {
                    
                    }
                    case 37:
                    {
                    
                    }
                    case 38:
                    {
                    
                    }
                    case 39:
                    {
                    
                    }
                    case 41:
                    {
                    
                    }
                    case 42:
                    {
                    
                    }
                    case 43:
                    {
                    
                    }
                    case 44:
                    {
                    
                    }
                    case 45:
                    {
                    
                    }
                    case 46:
                    {
                    
                    }
                    case 47:
                    {
                    
                    }
        */