  google.load("maps", "2");
  google.load("jquery", "1");
  google.load('visualization', '1', {packages: ['table','annotatedtimeline']});
  var base_url=window.location.protocol+'//'+window.location.host+'/';
  var unitConverter=function(){
      
      return{
          convert2En:function(obs,sensors,timezoneConverter){
              var i=0;
              var j=0;
              var len=0;
              var converter=null;
              //var converterU=null;
              if(obs==null||sensors==null)
                  return null;
              var data=new google.visualization.DataTable();
              data.addColumn('datetime','Timestamp');
              var type=null;
              for(i=0;i<sensors.length;++i)
                  if(obs[sensors[i].id]!=null&&len<obs[sensors[i].id].length)
                      len=obs[sensors[i].id].length;
              for(i=0;i<sensors.length;++i)
              {
                  if(obs[sensors[i].id]!=null&&obs[sensors[i].id].length==len)
                  {
                      type=convertUnitName(sensors[i].measureType.uomDisplay);
                      data.addColumn('number',sensors[i].sensorType.typeName+'('+type+')');
                  }
              }   
              data.addRows(len);
              var timeset=false;
              var count=1;
              for(i=0;i<sensors.length;++i)
              {
                  if(obs[sensors[i].id]==null)
                      continue;
                  if(obs[sensors[i].id].length<len)
                      continue;
                  if('m/s'==sensors[i].measureType.uomDisplay)
                  {
                      converter=ms2kts;
                      
                  }
                  else if('deg C'==sensors[i].measureType.uomDisplay)
                  {
                      converter=degc2degf;
                      
                  }
                  else if('mb'==sensors[i].measureType.uomDisplay)
                  {
                      converter=mb2inchhg;
                     
                  }
                  else if('m'==sensors[i].measureType.uomDisplay)
                  {
                      converter=m2feet;
                  }
                  else
                      converter=null;
                  if(obs[sensors[i].id]!=null)
                  {
                      for(j=0;j<obs[sensors[i].id].length;++j)
                      {
                          if(timeset==false)
                          {
	                          if(timezoneConverter!=null)
	                              data.setValue(j,0,timezoneConverter(obs[sensors[i].id][j].dateTime));
	                          else
	                              data.setValue(j,0,new Date(obs[sensors[i].id][j].dateTime));
	                      }
	                      if(converter!=null)
	                          data.setValue(j,count,parseFloat(converter(obs[sensors[i].id][j].value).toFixed(2)));
	                      else
	                          data.setValue(j,count,obs[sensors[i].id][j].value);
                      }
                      timeset=true;
                      ++count;
                  }
              }
              
              return data;
             
          },
          convertTimeZone:function(obs,sensors,timezoneConverter)
          {
              var i=0;
              var j=0;
              var converter=null;
              //var converterU=null;
              if(obs==null||sensors==null)
                  return null;
              var data=new google.visualization.DataTable();
              data.addColumn('datetime','Timestamp');
              var type=null;
              for(i=0;i<sensors.length;++i)
              {
                  data.addColumn('number',sensors[i].sensorType.typeName+'('+sensors[i].measureType.uomDisplay+')');
              }   
              data.addRows(obs[sensors[0].id].length);
              for(i=0;i<sensors.length;++i)
              {
                  if(obs[sensors[i].id]!=null)
                  {
                      for(j=0;j<obs[sensors[i].id].length;++j)
                      {
                          if(i==0)
                          {
	                          if(timezoneConverter!=null)
	                              data.setValue(j,0,timezoneConverter(obs[sensors[i].id][j].dateTime));
	                          else
	                              data.setValue(j,0,new Date(obs[sensors[i].id][j].dateTime));
	                      }
	                      data.setValue(j,i+1,obs[sensors[i].id][j].value);
                      }
                  }
              }
              
              return data;
          },
          convertUnitName:function(u)
	      {
	          if(u=='m/s')
	              return ms2ktsU();
	          else if(u=='deg C')
	              return degc2degfU();
	          else if(u=='mb')
	              return mb2inchhgU();
	          else
	              return u;
	      }
      };
      
      function convertUnitName(u)
      {
          if(u=='m/s')
              return ms2ktsU();
          else if(u=='deg C')
              return degc2degfU();
          else if(u=='mb')
              return mb2inchhgU();
          else if(u=='m')
              return m2feetU();
          else
              return u;
      }
      function m2feetU()
      {
          return 'feet';
      }
      function m2feet(val)
      {
          return val*3.281;
      }
      function ms2ktsU()
      {
          return 'knots';
      }
      function ms2kts(val)
      {
          return val/0.514;
      }
      function degc2degfU()
      {
          return 'deg F';
      }
      function degc2degf(val)
      {
          return val*9.0/5.0+32.0;
      }
      function mb2inchhgU()
      {
          return 'inHg';
      }
      function mb2inchhg(val)
      {
          return val/33.86389;
      }
  }();
  var PIVOT_HOUR=168; 
  var headerHeight=105;
  var pageTop="30px";//20"165px";//
  var tableTop="10px";//"145px";//
  var bversion=navigator.appVersion;
  var bversion=parseFloat(bversion);
  /*if(navigator.appName!="Microsoft Internet Explorer")
  {
      pageTop="27px";
      tableTop="10px";
  }
  else if(bversion>4)
  {
      pageTop="27px";
      tableTop="10px";
  }*/
  var bFold=false;
  var bIe=false;
  var curTab=null; 
  var map=null;
  var curPlt=null;
  var curSens=null;
  
  
  var mkCache={3:new Array(),1:new Array(),2:new Array(),4:new Array(),
               15:new Array(),7:new Array(),8:new Array(),9:new Array(),
               11:new Array(),12:new Array(),13:new Array(),
               993:new Array(),//H WVHT
               994:new Array(),//H WGST
               995:new Array(),//L WTMP
               996:new Array(),//H WTMP
               997:new Array(),//L ATMP
               998:new Array(),//H ATMP
               
               999:new Array(),1000:new Array()};
  
  function initialize() {
      resizeApp(false);
      map = new google.maps.Map2(document.getElementById("map"));
      map.setCenter(new google.maps.LatLng(45.4, -84.6), 5);
      map.setUIToDefault();
      var height=document.getElementById('map').style['height'];
      document.getElementById('div_lyrCtl').style['height']=height;
      document.getElementById('div_pltInfo').style['height']=height;
      document.getElementById('panel').style['display']='block';
      document.getElementById('togglebar').style['display']='block';
      //document.getElementById('paneltabs').style['display']='block';
      //loadExhibit();
      loadExhibitExamples();
  }
  google.setOnLoadCallback(initialize);
  function loadExhibitExamples()
  {
       var d=new Date();
       var url=base_url+"glos_obs/exhibit.glos?n=10&ie="+d.getMilliseconds();
       /*$.getJSON(url, function (data) {
    		if (data) {
        
                     if(data.length>0)
                     {
                        examples=data;
                        loadExhibit();
                     }
                }
      
       });*/
       var ajax=getXmlHttpObject();
       if(ajax!=null)
       {
           ajax.onreadystatechange=function(){
                                       if(ajax.readyState==4)
                                       {
                                           if(ajax.status==200)
                                           {
                                               examples=eval('('+ajax.responseText+')');
                                               loadExhibit();
                                           }
                                       }                    

                                   };
           ajax.open("GET",url,true);
           ajax.send(null);
       }
  }
  function getImgById(tid)
  {
      switch(tid)
      {
          case "999"://search result
              return "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
          break;
          case "1000"://search result
              return "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
          break;
          case "1":
              return "./imgs/weatherstation.png";
          case "2":
              return "./imgs/waterlevelstation.png";
          case "3":
              return "./imgs/cmanstation.png";
          case "4":
              return "./imgs/glosweatherstation.png";
          case "15":
              return "./imgs/glosbuoy.png";
          case "7":
              return "./imgs/3mdiscusbuoy.png";
          case "8":
              return "./imgs/canadianbuoy.png";
          case "9":
              return "./imgs/nerssweatherstation.png";
          case "11":
              return "./imgs/aoss-station.png";
          case "12":
              return "./imgs/othermarinereports.png";
          case "13":
              return "./imgs/shipreport.png";
          case "993":
	      return "./imgs/hiwaves.png";
          case "994":
              return "./imgs/hiwind.png";
          case "995":
              return "./imgs/lowatertemp.png";
          case "996":
              return "./imgs/hiwatertemp.png";
          case "997":
              return "./imgs/loairtemp.png";
          case "998":
              return "./imgs/hiairtemp.png";
          default:
              return "http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png";
          break;
      }
  }
  function isURLValid(a)
  {
      return a.href!=window.location.href;
  }
  function setButtons(bValid,pname,pid)
  {
      var a_more=document.getElementById('a_more');
      var a_sub=document.getElementById('a_sub');
      var style=bValid?"button":"nullbutton";
      
      if(bValid)
      {
          if(pname.length>40)
              pname=pname.substring(0,39)+'...';
          a_more.innerHTML="View more data on "+pname+" ";
          a_sub.innerHTML="Subscribe to data on "+pname+" ";
          a_more.href="./station/"+cur_lyr+'-'+pid+'.html';
          //a_sub.href=base_url+"glos_obs/rss/"+cur_lyr+"-"+pid+"-0"+"-0.xml";
          a_sub.onclick=function(){ showRSSDialog(pid,cur_lyr);return false;};
      }
      else
      {
         a_more.innerHTML="View more station data";
         a_sub.innerHTML="Subscribe to station data";
         a_sub.onclick=function(){return isURLValid(a_sub);};
         a_more.href=window.location.href;
         a_sub.href=window.location.href; 
      }
      changeClass(a_more,style);
      changeClass(a_sub,style);
      
  }
  String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
  }
  var cur_lyr=null;
  var cur_marker=null;
  var cur_popup_content=null;
  var cur_center=null;
  var recordTexts={
               993:'Wave Height',// (meter)',//H WVHT
               994:'Wind Gust',// (m/s)',//H WGST
               995:'Water Temperature',// (Celcius)',//L WTMP
               996:'Water Temperature',// (Celcius)',//H WTMP
               997:'Air Temperature',// (Celcius)',//L ATMP
               998:'Air Temperature' //(Celcius)'//H ATMP
               };
  function setRecordContent(plt,tid)
  {
      var temp="<span style='font-weight:bold;'>";
      temp+=recordTexts[tid]+": </span>";
      temp+=plt.obsValue;
      if(tid==993)
      {
          temp+=' meter ';
          temp+="<span style='color:#a5a5a5;'>("+(3.2808399*plt.obsValue).toFixed(2)+" feet)</span>";
      }
      else if(tid==994)
      {
          temp+=' m/s ';
          temp+="<span style='color:#a5a5a5;'>("+(1.94384449*plt.obsValue).toFixed(2)+" knots)</span>";
      }
      else
      {
          temp+=' C ';
          temp+="<span style='color:#a5a5a5;'>("+(1.8*plt.obsValue+32.0).toFixed(2)+" F)</span>";
      }
      temp+="<br/>";
      temp+="<table cellpadding=0 cellspacing=0>";
      temp+="<tr>";
      temp+="<td>";
      temp+="<span style='font-weight:bold;'>";
      temp+="Reported Time: </span>";
      temp+="</td>";
      var l_time=Date.parse(plt.obsEntryDate+' GMT');
      temp+="<td style='padding-left:4px;'>";
      temp+=plt.obsEntryDate+' GMT';
      temp+="</td><tr><td></td><td>"
      temp+="<span style='color:#a5a5a5;padding-left:4px;'>("+l_time.toString("yyyy/MM/dd hh:mm:ss tt")+" Local Time)";
;
      temp+="</td></tr></table><br/>";
      return temp;
  }
  function loadLayer(tid)
  {
      var url=null;
      if(tid==999||tid==1000) 
      {
          var val=null;
          if(tid==999)
          {
              url=base_url+"glos_obs/platform.glos?handle=";
              val=document.getElementById('in_sid').value.trim();
          }
          else if(tid==1000)
          {
              url=base_url+"glos_obs/platform.glos?pname=";
              val=document.getElementById('in_pname').value.trim();
          }
          if(val==null||val=='')
              return;
          else
              url=url+val;
      }
      else if(tid>=993&&tid<=998)
      {
          url=base_url+"glos_obs/records.glos?";
          switch(tid)
          {
              case "993":
	          url=url+"name=WVHT&type=1";
                  break;
              case "994":
                  url=url+"name=GST&type=1";
                  break;
              case "995":
                  url=url+"name=WTMP&type=0";
                  break;
              case "996":
                  url=url+"name=WTMP&type=1";
                  break;
              case "997":
                  url=url+"name=ATMP&type=0";
                  break;
              case "998":
                  url=url+"name=ATMP&type=1";
                  break;
              default:
                  url+="";
          }
      }
      else
          url=base_url+"glos_obs/platform.glos?tid="+tid;
      var baseIcon = new google.maps.Icon(G_DEFAULT_ICON);
	  baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
      baseIcon.iconSize = new google.maps.Size(32, 32);
	  baseIcon.shadowSize = new google.maps.Size(42, 30);
	  baseIcon.iconAnchor = new google.maps.Point(16, 32);
	  baseIcon.infoWindowAnchor = new google.maps.Point(16, 16);
	  var pDiv=document.getElementById('div_pltInfo');
      function createMarker(point,plt) {
          var picon=new google.maps.Icon(baseIcon);
          var img=getImgById(tid);
          if(img!=null)
              picon.image=img;
          markerOptions={icon:picon};
          var marker=new google.maps.Marker(point,markerOptions);
          google.maps.Event.addListener(marker,"infowindowclose",function(){
                                                              if(map!=null&&cur_center!=null)
                                                              {
                                                                  map.setCenter(cur_center);
                                                              }             
                                                          });
          google.maps.Event.addListener(marker,"click",function(){
                                                    curPlt=plt;
                                                if(tid>=900)//bogus
                                                    cur_lyr=plt.pt.id;
                                                
                                                else
                                                    cur_lyr=tid;
                                                    cur_marker=marker;
          											var ts={'className':'bold-green-font'};
                                                    var temp="<span style='font-weight:bold;font-size:123%;'>"+plt.shortName+"</span><br/>";
                                                    if(tid>=993&&tid<=998)
                                                    {
                                                        temp+="<br/>";
                                                        temp+=setRecordContent(plt,tid);
          					        //temp+="<span style='font-weight:bold;'>";
							//temp+=recordTexts[tid]+": </span>";
							//temp+=plt.obsValue+"</span>";
							//temp+="<br/>";
							//temp+="<span style='font-weight:bold;'>";
							//temp+="Datetime (UTC/GMT): </span>";
							//temp+=plt.obsEntryDate;
							//temp+="<br/>";
                                                    }
                                                    else
                                                    {
                                                        if(plt.imgUrl!=null&&plt.imgUrl!='')
                                                        {
                                                            temp+="<img style='width:350px;height:250px' src='"+plt.imgUrl+"' />";
                                                        }
                                                    }
                                                    cur_popup_content=temp;
                                                    cur_center=map.getCenter();
              	                                    marker.openInfoWindowHtml(temp);
              	                                    var table=new google.visualization.DataTable();
              	                                    table.addColumn('string','');
              	                                    table.addColumn('string','');
              	                                    table.addRows(17);
              	                                    table.setCell(0,0,"Station Name: ",null,ts);
                                                    table.setCell(1,0,"Last Update: ",null,ts);
              	                                    table.setCell(2,0,"Organization: ",null,ts);
              	                                    table.setCell(3,0,"Longitude: ",null,ts);
              	                                    table.setCell(4,0,"Latitude: ",null,ts);
              	                                    table.setCell(5,0,"Elevation: ",null,ts);
						    table.setCell(6,0,"Anemometer Height",null,ts);
              	                                    table.setCell(7,0,"Air Temp Height",null,ts);
                                                    table.setCell(8,0,"Barometer Elevation",null,ts);
                                                    table.setCell(9,0,"State: ",null,ts);
              	                                    table.setCell(10,0,"Description: ",null,ts);
              	                                    table.setCell(11,0,"NDBC ID: ",null,ts);
              	                                    table.setCell(12,0,"NOS ID: ",null,ts);
              	                                    table.setCell(13,0,"NWS ID: ",null,ts);
              	                                    table.setCell(14,0,"ICAO ID: ",null,ts);
              	                                    table.setCell(15,0,"COOP ID: ",null,ts);
              	                                    table.setCell(16,0,"WMO ID: ",null,ts);
              	                                    //table.setCell(13,0,"Radio Call Sign: ",null,ts);
              	                                    if(plt.longName!=null&&plt.longName!="")
              	                                        table.setCell(0,1,plt.longName);
              	                                    else
              	                                        table.setCell(0,1,plt.shortName);
                                                    if(plt.lastDataUpdate!="Never")
                                                        table.setCell(1,1,plt.lastDataUpdate+' GMT');
                                                    else
                                                        table.setCell(1,1,'Never');
              	                                    if(plt.org!=null)
              	                                    {
              	                                        if(plt.org.longName!=null&&plt.org.longName!='')
              	                                            table.setCell(2,1,plt.org.longName);
              	                                        else
              	                                            table.setCell(2,1,plt.org.shortName);
              	                                    }
              	                                    else
              	                                        table.setCell(2,1,'');
                                                    if(cur_lyr!=13)
                                                    {
              	                                        table.setCell(3,1,plt.lon+' degree');
              	                                        table.setCell(4,1,plt.lat+' degree');
                                                        table.setCell(5,1,plt.zvalue+' meter');
                                                    }
                                                    else
                                                    {
                                                        table.setCell(3,1,'N/A');
                                                        table.setCell(4,1,'N/A');
                                                        table.setCell(5,1,'N/A');
                                                        
                                                    }
						    if(plt.anemoHeight!=-99999.0)
                                                        table.setCell(6,1,plt.anemoHeight+' meter');
                                                    else
                                                        table.setCell(6,1,'N/A');
                                                    if(plt.airtempHeight!=-99999.0)
                                                        table.setCell(7,1,plt.airtempHeight+' meter');
                                                    else
                                                        table.setCell(7,1,'N/A');
                                                    if(plt.barometerElev!=-99999.0)
                                                        table.setCell(8,1,plt.barometerElev+' meter');
                                                    else
                                                        table.setCell(8,1,'N/A');
              	                                    table.setCell(9,1,plt.state);
              	                                    table.setCell(10,1,plt.description);
              	                                    table.setCell(11,1,plt.ndbcHandler);
              	                                    table.setCell(12,1,plt.nosHandler);
              	                                    table.setCell(13,1,plt.nwsHandler);
              	                                    table.setCell(14,1,plt.icaoHandler);
              	                                    table.setCell(15,1,plt.coopHandler);
              	                                    table.setCell(16,1,plt.wmoHandler);
              	                                    //table.setCell(13,1,plt.radioCallSign);
              	                                    cleanTabs();
              	                                    var visual=new google.visualization.Table(pDiv);
                                                    var old_tstring=null;
                                                    var old_elev={};
              	                                    google.visualization.events.addListener(visual,'select',function(event){
               var rows=visual.getSelection();
    	       if(rows!=null&&rows.length==1)//only single selection is allowed
    	       {
    		            										    if(rows[0].row==0&&cur_marker!=null&&cur_popup_content!=null)
    		      marker.openInfoWindowHtml(temp);
                   else if(rows[0].row==1)
                   {
                       var tstr=table.getValue(1,1);
                       if(tstr!=null&&tstr!='Never')
                       {
                           if(tstr.substring(tstr.length-3,tstr.length)=='GMT')
                           {
                               iff=new Date(Date.parse(tstr));
                               old_tstring=tstr;
                               table.setValue(1,1,iff.toString("yyyy/MM/dd hh:mm:ss tt")+" Local Time");
                               visual.draw(table,null);
                           }
                           else
                           {
                               table.setValue(1,1,old_tstring);
                               visual.draw(table,null);
                           }
                       }
                   }
                   else if(rows[0].row>=5&&rows[0].row<=8)//elevations
                   {
                       var row_idx=rows[0].row;
                       var estr=table.getValue(row_idx,1);
                       if(estr!=null&&estr!='N/A')
                       {
                           if(estr.substring(estr.length-5,estr.length)=='meter')
                           {
                               var ft_el=parseFloat(estr)*3.2808399;
                               table.setValue(row_idx,1,ft_el.toFixed(2)+' feet');
                               visual.draw(table,null);
                               old_elev[row_idx]=estr;
                           }
                           else
                           {
                               table.setValue(row_idx,1,old_elev[row_idx]);
                               visual.draw(table,null);
                           }
                       }
                   }
                }
    	    });//end of addListener
              	                                    visual.draw(table,null);
              	                                    cleanupChart();
              	                                    changeTab('tab1');
                                                    setButtons(true,plt.shortName,plt.id);
              	                                });
          return marker;
        }
      $.getJSON(url, function (data) {
    		if (data) {
        
        if(data.length>0)
        {
            var len=data.length;
            var i=0;
            var count=0;
            for(;i<len;++i)
            {
                if(data[i].lat!=null&&data[i].lon!=null&&data[i].lat!=0.0&&data[i].lon!=0.0)
                {  
                  
                  var marker=createMarker(new google.maps.LatLng(data[i].lat,data[i].lon),data[i]);
              	  mkCache[tid][i]=marker;
              	          	  
                  map.addOverlay(marker);
                  ++count;
                }
		else if(tid>=993)//record
		{
		    if(data[i].obsLat!=null&&data[i].obsLon!=null)
		    {
                        
                        var marker=createMarker(new google.maps.LatLng(data[i].obsLat,data[i].obsLon),data[i]);
              	        mkCache[tid][i]=marker;
              	          	  
                        map.addOverlay(marker);
                    }
		}
	    }
	    if(tid==999||tid==1000)
	    {
	        displayResultCount(count);
                showCleanSearchLink(true);
	    }
            var counterd=document.getElementById('count'+tid);
            if(counterd!=null&&counterd.innerHTML=="")
                counterd.innerHTML='('+count+')';
        }
        else
        {
          if(tid==999||tid==1000)
          {
              displayResultCount(0);
          }
        }
      
      }
      
    });
  }
  function doSearch(type)
  {
      removeSearchResult();
      if(type!=null&&type!='undefined')
      {
          if(type==1)
              loadLayer("999");
          else if(type==2)
              loadLayer("1000");
      }
      else
      {
          var temp=document.getElementById('in_sid').value;
          if(temp!=null&&temp!=''&&temp!='undefined')
              loadLayer("999");
          else
              loadLayer("1000");
      }
  }
  function removeSearchResult()
  {
      var i=0;
      if(mkCache[999].length>0)
      {
          for(;i<mkCache[999].length;++i)
          {
              if(mkCache[999][i]!=null)
                  map.removeOverlay(mkCache[999][i]);
          }
          mkCache[999]=new Array();
      }
      if(mkCache[1000].length>0)
      {
          for(;i<mkCache[1000].length;++i)
          {
              if(mkCache[1000][i]!=null)
                  map.removeOverlay(mkCache[1000][i]);
          }
          mkCache[1000]=new Array();
      }
      removeShipIcons();
      clearResultCount();
  }
  function showCleanSearchLink(bShow)
  {
      if(bShow)
          document.getElementById('a_csr').style['display']='block';
      else
          document.getElementById('a_csr').style['display']='none';
  }
  function removeShipIcons()
  {
     if(mkCache[13].length>0)
     {
         var i=0;
         for(;i<mkCache[13].length;++i)
         {
             map.removeOverlay(mkCache[13][i]);
             mkCache[13]=new Array();
         }
     }
  }
  function clearResultCount()
  {
      document.getElementById('p_result').innerHTML='';
      document.getElementById('p_result').style['display']='none';
  }
  function displayResultCount(count)
  {
      document.getElementById('p_result').style['display']='block';
      var img_url=getImgById("1000");
      document.getElementById('p_result').innerHTML='<img src="'+img_url+'" style="width:32px;height:32px;" />'+count+' result(s) returned.';
  }
  function switchLyr(id)
  {
      if(id==null)return;
      var val=id.value;
      if(id.checked)
      {
          removeSearchResult();
          if(val>=993&&val<=998)//no cache allowed for record layers
          {
              loadLayer(val);
              return;
          }
          if(mkCache[val].length>0)
          {
              var len=mkCache[val].length;
              var i=0;
              for(;i<len;++i)
                  mkCache[val][i].show();
          }
          else
          {
              loadLayer(val);
          }
      }
      else if(false==id.checked&&mkCache[val].length>0)
      {
          var len=mkCache[val].length;
          var i=0;
          for(;i<len;++i)
          {
              mkCache[val][i].hide();
              mkCache[val][i].closeInfoWindow();
          }
          if(cur_lyr==val)
          {
              cleanTabs();
              cleanupChart();
              cur_lyr=null;
              curPlt=null;
          }
      }
  }
    var bWidth=0;
    var resizeCount=0;
    var fLoad=true;
    var _width=0;
    function resizeApp(bForFold)
    {
        if(fLoad==true)
            fLoad=false;
        else
        {
            if(bForFold==false&&navigator.appName=="Microsoft Internet Explorer")
            {
                if(resizeCount++==0)
                    return;
                else
                   resizeCount=0;
            }
        }
        var myWidth = 0, myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' )
        {
            //Non-IE
    	    myWidth = window.innerWidth;
    	    myHeight = window.innerHeight;
  	    } 
        else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
        {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
            bIe=true;
        }
        else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
        {
           //IE 4 compatible
           myWidth = document.body.clientWidth;
           myHeight = document.body.clientHeight;
           bIe=true;
        }
        if(_width==myWidth&&false==bForFold)return;
        _width=myWidth
        bWidth=myWidth
		/*myHeight-=headerHeight;
		var factorY=0;
		var factorX=0.51;
		if(bIe==true)
		    factorY=0.80;
		else
		    factorY=0.75;*/
		document.getElementById("page").style["top"]=pageTop;
		document.getElementById("tab").style["top"]=tableTop;
		if(bFold==false)
		{
	        document.getElementById("map").style["width"]="51%";//myWidth*factorX+"px";
	        document.getElementById("togglebar").style["left"]="51%";//myWidth*factorX-20+"px";
		    //document.getElementById("panel").style["left"]="53%";
		    document.getElementById("panel").style["right"]="4px";
	        document.getElementById("panel").style["display"]="block";
		}
		else
		{
		    document.getElementById("panel").style["display"]="none";
		    document.getElementById("map").style["width"]="100%";//(myWidth-24)+"px";
		    document.getElementById("togglebar").style["left"]="100%";//myWidth-17+"px";
		   
		}
		//document.getElementById("div_chart").style["width"]=myWidth-45+"px";
        if(map!=null)
        {
            var c=map.getCenter();
            map.checkResize();
            map.setCenter(c);
        }
        //if(myWidth>817&&bForFold==false)
        if(bForFold==false)
        {
            resizeGoogleTable(myWidth);
        }
        if(div_mask!=null)
        {
            var temp=myWidth>=818?myWidth:818;
            if(div_mask.style['display']=='block')
                div_mask.style['width']=temp+'px';
        }  
    }
    function resizeGoogleTable(width)
    {
        if(curData!=null)
        {
            var chart=document.getElementById('div_chart');
            var fly=document.getElementById('div_fly');
            
            if(chart!=null)
            {
                if(fly!=null)
                {
                    chart=fly;
                    /*if(navigator.appName=="Microsoft Internet Explorer")
                    {
                        chart.style["width"]=width/2-20+"px";
                    }*/
                }
                chart.innerHTML="";
                if(document.getElementById('rad_view2').checked)
                    drawGoogleTable(chart,curData);
                else
                {
                    if(fly==null)//ship report doesn't have chart view
                        drawGoogleChart(chart,curData);
                    else
                       fly.innerHTML='Chart can not be applied on this dataset.';
                }
            }
        }
    }
function changeClass(control,name)
    {
        if(bIe==true)
            control.className=name;
        else
            control.setAttribute("class",name);
    }
    var cur_ships=null;
    function showShips(div)
    {
        if(div==null)return;
        var url=base_url+"glos_obs/platform.glos?tid=13";
        if(cur_ships!=null)
        {
            //var visual=new google.visualization.Table(div);
            //visual.draw(cur_ships,null);
            return;
        }
        $.getJSON(url, function (data) {
    		    if (data) 
    		    {
        
			        if(data.length>0)
			        {
			            var len=data.length;
			            var i=0;
			            var table=new google.visualization.DataTable();
              	        table.addColumn('string','Ship Name');
              	        table.addColumn('string','Radio Call Sign');
              	        table.addColumn('string','Organization Name');
              	        table.addRows(len);
			            for(;i<len;++i)
			            {
			                table.setCell(i,0,data[i].shortName);
			                table.setCell(i,1,data[i].radioCallSign);
			                table.setCell(i,2,data[i].org.shortName);
					    }
					    cur_ships=table;
					    var visual=new google.visualization.Table(div);
              	        visual.draw(table,null);
			        }
			        google.visualization.events.addListener(visual,'select',
    		        function(event){
    		            var rows=visual.getSelection();
    		            
    		            if(rows!=null&&rows.length>0)
    		            {
    		                document.getElementById("div_chart").style['height']="360px";
    		                //var twidth="51%";
                                var twidth="100%";
    		                /*if(div.id=='div_fly')
                            {
                                if(navigator.appName=="Microsoft Internet Explorer")
                                {
                                    twidth=bWidth/2-20+"px";
                                }
                            }*/
                            
    		                //document.getElementById("div_chart").innerHTML='<div id="div_fly" style="float:left;width:'+twidth+';height:320px;position:relative;"></div><div id="togglebar_1" style="cursor:pointer;left:51%;" onclick="fold_1()"></div><img src="'+data[rows[0].row].imgUrl+'" style="left:53%;width:47%;height:355px;right:1px;border:2px outset black;float:right;" id="img_fly"/>';
                                document.getElementById("div_chart").innerHTML='<div id="div_fly" style="float:left;width:'+twidth+';height:320px;position:relative;"></div>';
                                var shortName=data[rows[0].row].shortName;
                                var spid=data[rows[0].row].id;
    		                var url=base_url+"glos_obs/sensor.glos?pid="+spid;
					        $.getJSON(url, function (data) {
					    		if (data) 
					    		{
					    		    
					              	var temp="";
							        var utemp="";
							        var i=0;
							        var obs_url="";
							        for(;i<data.length;++i)
							        {
							            temp=temp+data[i].id;
							            utemp=utemp+data[i].measureType.uomName;
							            if(i!=data.length-1)
							            {
							                temp=temp+",";
							                utemp=utemp+",";
							            }
							        }
							        cur_url=base_url+"glos_obs/obs.glos?sids="+temp;
							        var hours=document.getElementById('sel_hours').value;
							        if(hours<0||hours>720)
							            hours=48;
							        if(hours<=PIVOT_HOUR)
							            obs_url=cur_url+"&hours="+hours;
							        else
							        {
							            obs_url=cur_url+"&hours="+hours+"&unit="+cur_unit+"&uname="+utemp+"&tzone="+cur_timezone_offset;
							        }
							        obs_url=obs_url+"&em=0";
					              	curSensors=data;
					              	document.getElementById('rad_view1').checked=false;
					              	document.getElementById('rad_view2').checked=true;
                                                        cleanTabs();
                                                        curPlt=null;
                                                        cur_lyr=13;
                                                        setButtons(true,shortName,spid);
					              	showObs(obs_url,data,'div_fly');
							        
					    		       
					    		}
					        });
    		                
    		            }
    		        });
			      
			     }
      
            });
    }
    function showSensors(div)
    {
        if(div==null||curPlt==null)return;
        var url=base_url+"glos_obs/sensor.glos?pid="+curPlt.id;
        
        $.getJSON(url, function (data) {
    		if (data) {
    		    curSens=data;
    		    var cssClassNames = {
                    'headerRow': 'bold-green-font'
                  };

                var options = {'allowHtml': true, 'cssClassNames': cssClassNames};
    		    var ts={'className':'even'};
    		    var table=new google.visualization.DataTable();
              	table.addColumn('string','Short Name');
              	table.addColumn('string','Type Name');
              	table.addColumn('string','Description');
              	var len=data.length;
              	var sname=null;
              	var tname=null;
              	var desc=null;
              	table.addRows(len);
              	for(var i=0;i<len;++i)
              	{
              	    sname=data[i].shortName==null?"":data[i].shortName;
              	    table.setCell(i,0,sname,null,ts);
              	    if(data[i].sensorType!=null&&data[i].sensorType.typeName!=null)
              	        tname=data[i].sensorType.typeName.replace('_',' ');
              	    else
              	        tname="";
              	    table.setCell(i,1,tname,null,ts);
              	    if(data[i].measureType!=null&&data[i].measureType.obsTypeDef!=null)
              	        desc=data[i].measureType.obsTypeDef;
              	    else
              	        desc="";
              	    table.setCell(i,2,desc,null,null);
              	}
              	var visual=new google.visualization.Table(div);
              	visual.draw(table,options);
              	
    		    google.visualization.events.addListener(visual,'select',
    		        function(event){
    		            var rows=visual.getSelection();
    		            
    		            if(rows!=null&&rows.length>0)
    		            {
    		                var obs_url=buildObsUrl(rows,data);
    		                var arr=new Array(rows.length);
    		                var j=0;
    		                for(;j<rows.length;++j)
    		                    arr[j]=data[rows[j].row];
    		                return showObs(obs_url,arr);
    		                /*$.getJSON(obs_url, function (res) {
    		                       if (res) {
    		                                  alert(res);
    		                              }
    		                          });*/
    		            }
    		        });
    		}
        });
    }
    var cur_url=null;
    function buildObsUrl(rows,data)
    {
        if(rows==null||data==null)return "";
        var temp="";
        var utemp="";
        var i=0;
        for(;i<rows.length;++i)
        {
            temp=temp+data[rows[i].row].id;
            utemp=utemp+data[rows[i].row].measureType.uomName;
            if(i!=rows.length-1)
            {
                temp=temp+",";
                utemp=utemp+",";
            }
        }
        cur_url=base_url+"glos_obs/obs.glos?sids="+temp;
        if(cur_lyr!=null)
            cur_url=cur_url+"&pt="+cur_lyr;
        if(curPlt!=null)
            cur_url=cur_url+"&pid="+curPlt.id;
        var hours=document.getElementById('sel_hours').value;
        if(hours<0||hours>720)
            hours=48;
        if(hours<=PIVOT_HOUR)
            return cur_url+"&hours="+hours;
        else
        {
            return cur_url+"&hours="+hours+"&unit="+cur_unit+"&uname="+utemp+"&tzone="+cur_timezone_offset;
        }
    }
    function getXmlHttpObject()
    {
	    var xmlHttp=null;
	    try
	    {   //Firefox, Opera 8.0+, Safari
	        xmlHttp=new XMLHttpRequest();
	    }
	    catch(e)
	    {//ie
	        try
	        {
	            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
	            xmlHttp=new ActiveXObject("Microfost.XMLHTTP");
	        }
	    }
	    return xmlHttp;
    }
    
    var curSensors=null;
    var curData=null;
    var obsLoading=false;
    var draw_div=null;
    function showObs(url,sensors,div)
    {
        if(obsLoading==true)
        {
            alert('Loading other obs...');
            return;
        }
        else
            obsLoading=true;
        if(div==null)
            draw_div='div_chart';
        else
            draw_div=div;
        var ajax=getXmlHttpObject();
        curSensors=sensors;
        if(ajax!=null)
        {
            document.getElementById(draw_div).innerHTML='<span style="background-color:red;right:49%;position:absolute;color:white;padding:6px;">loading...</span>';
            ajax.onreadystatechange=function obsHandler()
    {
        
        if(ajax.readyState==4)
        {
            if(ajax.status==200)
            {
                if(draw_div==null)
                {
                    div='div_chart';
                    draw_div='div_chart';
                }
                else
                    div=draw_div;
                if(ajax.responseText==null||ajax.responseText=='')
                {
                    document.getElementById(div).innerHTML="No data available...";
                    return;
                }
                var obs=eval('('+ajax.responseText+')');
                if(obs!=null)
                {
                    document.getElementById(div).innerHTML='<span style="background-color:blue;right:49%;position:absolute;color:white;padding:6px;">Rendering...</span>';
                    curObs=obs;
                    
                    
                    var i=0;
                    var len=0;
                    for(var k in obs)
                    {
                        if(draw_div!='div_fly')//ugly temp fix
                        {
                        if((obs[k]==null)||(len>0&&len!=obs[k].length))
                        {
                            setToolbar();
                            document.getElementById(div).innerHTML="<a target='_blank' href='./help.php#nodata'>No data available in last "+document.getElementById('sel_hours').value+" hours or time series for multiple variables don't exactly match...</a>";
                            return;
                        }
                        }
                        if(obs[k]!=null)//temp fix
                            len=obs[k].length;
                            
                    }
                    i=0;
                    var hours=document.getElementById('sel_hours').value;
                    var data=new google.visualization.DataTable();
                    data.addColumn('datetime','Timestamp');
                    
                    for(;i<curSensors.length;++i)
                    {
                        if(null==obs[curSensors[i].id])
                            continue;
                        if(obs[curSensors[i].id].length<len)
                            continue;
                        if(cur_unit=='m')
                            data.addColumn('number',curSensors[i].sensorType.typeName+'('+curSensors[i].measureType.uomDisplay+')');
                        else 
                        {
	                        if(hours<=PIVOT_HOUR)
	                            data.addColumn('number',curSensors[i].sensorType.typeName+'('+curSensors[i].measureType.uomDisplay+')');
	                        else
	                            data.addColumn('number',curSensors[i].sensorType.typeName+'('+unitConverter.convertUnitName(curSensors[i].measureType.uomDisplay)+')');
                        }
                    }
                    
                    i=0;
                    //data.addColumn('string','title1');
                    //data.addColumn('string','text1');
                    data.addRows(len);
                    var j=0;
                    //var temp=0;
                    var count=1;
                    var timeset=false;
                    
                    for(;i<curSensors.length;++i)
                    {
	                    if(null==obs[curSensors[i].id])
                            continue;
                        if(obs[curSensors[i].id].length<len)
                            continue;
	                    for(;j<len;++j)
	                    {
	                        if(timeset==false)
	                        {
	                            //data.setValue(j,0,new Date(obs[curSensors[i].id][j].dateTime));
	                            if(hours<=PIVOT_HOUR)
	                                data.setValue(j,0,getDatetime(obs[curSensors[i].id][j].dateTime));
	                            else
	                                data.setValue(j,0,new Date(obs[curSensors[i].id][j].dateTime));
	                            
	                        }
	                        if(obs[curSensors[i].id][j]!=null)
	                            data.setValue(j,count,obs[curSensors[i].id][j].value);
	                        else
	                            data.setValue(j,count,-9999);
	                        /*if(temp!=0)
	                        {
	                            data.setValue(i,2,obs[i].value+'');
	                            data.setValue(i,3,'');
	                        }
	                        temp=temp==0?1:0;*/
	                    }
	                    ++count;
	                    timeset=true;
	                    j=0;
	                    
                    }
                    
                    curData=data;
                    tableViewData=data;
                    
                    if(hours<=PIVOT_HOUR)
                    {
                        cur_unit='m';
                        cur_timezone_offset=0;             
                        paint(div);
                    }
                    else
                        onDraw(data,div);
                    setToolbar();
                }
            }
            
        }
        obsLoading=false;
    };
            ajax.open("GET",url,true);
            ajax.send(null);
            
        }
    		                 
    }
    
    
     
    
    function changeDataByUnit(unit,tzoneoffset)
    {
        var data=null;
        if(cur_unit!=unit||cur_timezone_offset!=tzoneoffset)
        {
	        cur_unit=unit;
	        
	        if(unit=='m')
	        {
	            if(cur_timezone_offset==tzoneoffset)
	                data=curData;
	            else
	            {
	                cur_timezone_offset=tzoneoffset;
	                data=unitConverter.convertTimeZone(curObs,curSensors,getDatetime);
	            }
	        }
	        else if(unit=='e')
	        {
	            cur_timezone_offset=tzoneoffset;
	            data=unitConverter.convert2En(curObs,curSensors,getDatetime);
	            
	        }
	        tableViewData=data;
	        return data;
        }
        else
            return tableViewData;
    }
    function changeDuration(id)
    {
        var hours=id.value;
        if(hours<0||hours>720)
            return;
        if(curSensors!=null)
        {
            if(hours<=PIVOT_HOUR)
                showObs(cur_url+"&hours="+hours,curSensors,draw_div);
            else
            {
                largeQuery(hours);
            }
                
        }
    }
    function largeQuery(hours)
    {
        cur_timezone_offset=document.getElementById('sel_tzone').value;
        cur_unit=document.getElementById('sel_unit').value;
        var i=0;
        var temp="";
        for(;i<curSensors.length;++i)
        {
            temp=temp+curSensors[i].measureType.uomName;
            if(i!=curSensors.length-1)
            {
                temp=temp+",";
            }
        }
        showObs(cur_url+"&hours="+hours+"&unit="+cur_unit+"&uname="+temp+"&tzone="+cur_timezone_offset,curSensors,draw_div);
    }
    function paint(div)
    {
        var data=null;
        var hours=document.getElementById('sel_hours').value;
        if(hours<=PIVOT_HOUR)
            data=changeDataByUnit(document.getElementById('sel_unit').value,
                                  document.getElementById('sel_tzone').value);
        else
        {
            if(cur_timezone_offset==document.getElementById('sel_tzone').value&&
               cur_unit==document.getElementById('sel_unit').value)
                onDraw(curData,div);
            else
            {
	            largeQuery(hours);
	            
            }
            return;
        }
        onDraw(data,div);
    }
    function onDraw(data,div)
    {
        if(div==null)
            div='div_chart';
        document.getElementById(div).style["height"]="360px";
        document.getElementById(div).style["border"]="none";
        if(document.getElementById('rad_view1').checked==true&&cur_lyr!=13)
            drawGoogleChart(document.getElementById(div),data);
        else if(document.getElementById('rad_view2').checked==true)
        {
            drawGoogleTable(document.getElementById(div),data);
        }
        else if(cur_lyr==13)//reach here only it's a extreme record and reported from a ship
        {
            document.getElementById('rad_view2').checked=true;
            document.getElementById('rad_view1').checked=false;
            drawGoogleTable(document.getElementById(div),data);
        }
    }
    function drawGoogleChart(div,data)
    {
        if(data==null)
            data=curData;
        var chart = new google.visualization.AnnotatedTimeLine(div);
        //if(data.getNumberOfRows()>100)
        {
            //alert(typeof data.getValue(99,0));
            //chart.setVisibleChartRange(null,data.getValue(99,0));
        }
        chart.draw(data, {displayZoomButtons:false,displayAnnotations: true,allowHtml: true,displayExactValues:true});
        //if(data.getNumberOfRows()>100)
        //{
            //var c=data.getNumberOfRows();
            //alert(c);
            //chart.setVisibleChartRange(data.getValue(c-101,0),data.getValue(c-1,0));
        //}
    }
    function drawGoogleTable(div,data)
    {
        if(data==null)
            data=curData;
        
        var table=new google.visualization.Table(div);
        
        if('div_fly'==div.id)
        {
            
            google.visualization.events.addListener(table,'select',
    		        function(event){
    		            var rows=table.getSelection();
    		            if(curObs!=null&&curData!=null)
    		            {
    		                var k=null;
    		                for(k in curObs)
    		                {
    		                    if(curObs[k]!=null&&curData.getNumberOfRows()==curObs[k].length)
    		                        break;
    		                }
    		                if(k==null)
              	                return;
              	            removeShipIcons();
                            var baseIcon = new google.maps.Icon(G_DEFAULT_ICON);
	                        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
                            baseIcon.iconSize = new google.maps.Size(32, 32);
	                        baseIcon.shadowSize = new google.maps.Size(42, 32);
	                        baseIcon.iconAnchor = new google.maps.Point(6, 32);
	                        baseIcon.infoWindowAnchor = new google.maps.Point(16, 16);
                            var picon=new google.maps.Icon(baseIcon);
                            var img=getImgById("13");
                            if(img!=null)
                                picon.image=img;
                            markerOptions={icon:picon};
                            var marker=new google.maps.Marker(new google.maps.LatLng(curObs[k][rows[0].row].lat,
                                                                           curObs[k][rows[0].row].lon),
                                                                           markerOptions);
                            var temp="<div style='font-size:11px;'><p>Longitude: "+curObs[k][rows[0].row].lon+" Deg.</p>"+"<p>Latitude: "+
                                          curObs[k][rows[0].row].lat+" Deg.</p></div>";
                            cur_center=map.getCenter();
                            google.maps.Event.addListener(marker,"infowindowclose",function(){
                                                              if(map!=null&&cur_center!=null)
                                                              {
                                                                  map.setCenter(cur_center);
                                                              }             
                                                          });
                            google.maps.Event.addListener(marker,"click",function(){
                                 
                                 marker.openInfoWindowHtml(temp);
                             });
                            
              	            mkCache[13][0]=marker;
              	          	  
                            map.addOverlay(marker);
    		                marker.openInfoWindowHtml(temp);
    		            }
    		        });
        }
        var _page=12;
        //Button Out of bound problem seems to be fixed by Google, comment out two lines below 
        //if(navigator.appName=="Microsoft Internet Explorer"&&div.id=='div_fly')
        //    _page=6;
        table.draw(data,{page:'enable',pageSize:_page,sortAscending:false,sortColumn:0});
    }
    function setToolbar()
    {
        if(document.getElementById('div_toolbar').style['display']!="block")
        {
            document.getElementById('div_toolbar').style['display']="block";
            document.getElementById('sel_hours').selectedIndex=1;
        }
    }
    
    var cur_unit='m';
    //var cur_EngData=null;
    function changeUnit(id)
    {
        //var val=id.value;
        
        //if(val!=cur_unit)
        {
	        //cur_unit=val;
	        paint(draw_div);
	        
        }
        
    }
    var cur_timezone_offset=0;
    function changeTimezone(id)
    {
        //var val=id.value;
        //if(val!=cur_timezone_offset)
        {
            //cur_timezone_offset=val;
            
            paint(draw_div);
        }
    }
    function getDatetime(val)
    {
        var gmt=new Date(val);
        var temp=gmt.getTime()+3600000*cur_timezone_offset;
        return new Date(temp);
    }
    var tableViewData=null;
    
    function switchDataDisplay(type)
    {
        
        /*if(type=='chart')
           drawGoogleChart(document.getElementById('div_chart'),data);
        else
           drawGoogleTable(document.getElementById('div_chart'),data);*/
        var err="<a href='./help.php#chartv' target='_blank'>Chart View can not be applied on ship report.</a>";
        if(draw_div!='div_chart'&&type=='chart')
        {
            document.getElementById(draw_div).innerHTML=err;
        }
        else if(cur_lyr==13&&type=='chart')
        {
            document.getElementById(draw_div).innerHTML=err;
        }
        else
            paint(draw_div);  
    }
    function fold()
    {
		if(bFold==false)
	    {
			bFold=true;
			//changeClass(document.getElementById("panelarrow"),"left-arrow");
		}
		else
		{
			bFold=false;
			//changeClass(document.getElementById("panelarrow"),"right-arrow");
		}
		resizeApp(true);
	    
    }
    var bFold_1=false;
    function fold_1()
    {
        if(bFold_1==false)
        {
            document.getElementById('img_fly').style['display']="none";
            document.getElementById('div_fly').style['width']="100%";
            document.getElementById('togglebar_1').style['left']="100%";
            bFold_1=true;
        }
        else
        {
            document.getElementById('img_fly').style['display']="block";
            document.getElementById('div_fly').style['width']="51%";
            document.getElementById('togglebar_1').style['left']="51%";
            bFold_1=false;
        }
        resizeGoogleTable(0);
    }
    function changeTab(tabid)
    {
	    if(curTab==null)
	        curTab=document.getElementById('tab0');
	    var temp=document.getElementById(tabid);
	    if(temp==null||(temp==curTab&&bFold==false))
	        return;
	    if(curTab!=null)
	        changeClass(curTab,"tabOff");
        curTab=temp;
	    changeClass(curTab,"tabOn");
            //fold (resize) must be done before changing display css, otherwise won't work
            //for ie7
	    if(bFold==true)
            {
                fold();
            }
	    if(tabid=="tab0")
	    {
	        document.getElementById("div_lyrCtl").style['display']='block';
	        document.getElementById("div_pltInfo").style['display']='none';
	        document.getElementById("div_senInfo").style['display']='none';
	        document.getElementById("div_senLabel").style['display']='none';
	        document.getElementById("div_search").style['display']='none';
	        document.getElementById("div_shipRep").style['display']='none';
	        document.getElementById("div_shipLabel").style['display']='none';
                document.getElementById("div_recordLabel").style['display']='none';
	        document.getElementById("div_recordOD").style['display']='none';
	    }
	    else if(tabid=="tab1")
	    {  
	        document.getElementById("div_pltInfo").style['display']='block';
	        document.getElementById("div_lyrCtl").style['display']='none';
	        document.getElementById("div_senInfo").style['display']='none';
	        document.getElementById("div_senLabel").style['display']='none';
	        document.getElementById("div_search").style['display']='none';
	        document.getElementById("div_shipRep").style['display']='none';
	        document.getElementById("div_shipLabel").style['display']='none';
                document.getElementById("div_recordLabel").style['display']='none';
	        document.getElementById("div_recordOD").style['display']='none';
	    }
	    else if(tabid=="tab2")
	    {
	        document.getElementById("div_senInfo").style['display']='block';
	        document.getElementById("div_senLabel").style['display']='block';
	        document.getElementById("div_lyrCtl").style['display']='none';
	        document.getElementById("div_pltInfo").style['display']='none';
	        document.getElementById("div_search").style['display']='none';
	        document.getElementById("div_shipRep").style['display']='none';
	        document.getElementById("div_shipLabel").style['display']='none';
                document.getElementById("div_recordLabel").style['display']='none';
	        document.getElementById("div_recordOD").style['display']='none';
	        showSensors(document.getElementById("div_senInfo"));
	        
	    }
	    else if(tabid=="tab3")
	    {
	        document.getElementById("div_search").style['display']='block';
	        document.getElementById("div_senInfo").style['display']='none';
	        document.getElementById("div_senLabel").style['display']='none';
	        document.getElementById("div_lyrCtl").style['display']='none';
	        document.getElementById("div_pltInfo").style['display']='none';
	        document.getElementById("div_shipRep").style['display']='none';
	        document.getElementById("div_shipLabel").style['display']='none';
                document.getElementById("div_recordLabel").style['display']='none';
	        document.getElementById("div_recordOD").style['display']='none';
	    }
	    else if(tabid=="tab4")
	    {
	        document.getElementById("div_shipRep").style['display']='block';
	        document.getElementById("div_shipLabel").style['display']='block';
	        document.getElementById("div_search").style['display']='none';
	        document.getElementById("div_senInfo").style['display']='none';
	        document.getElementById("div_senLabel").style['display']='none';
	        document.getElementById("div_lyrCtl").style['display']='none';
	        document.getElementById("div_pltInfo").style['display']='none';
                document.getElementById("div_recordLabel").style['display']='none';
	        document.getElementById("div_recordOD").style['display']='none';
	        showShips(document.getElementById('div_shipRep'));
	    }
            else if(tabid=="tab5")
            {
                document.getElementById("div_recordLabel").style['display']='block';
	        document.getElementById("div_recordOD").style['display']='block';
                document.getElementById("div_shipRep").style['display']='none';
	        document.getElementById("div_shipLabel").style['display']='none';
	        document.getElementById("div_search").style['display']='none';
	        document.getElementById("div_senInfo").style['display']='none';
	        document.getElementById("div_senLabel").style['display']='none';
	        document.getElementById("div_lyrCtl").style['display']='none';
	        document.getElementById("div_pltInfo").style['display']='none';
                map.setCenter(new google.maps.LatLng(45.4, -84.6), 5);
            }
	    /*if(bFold==true)
	    {
	        fold();
	    }*/
	    
    }
    function getURLParam(strParamName)
    {
        var strReturn = "";
        var strHref = window.location.href;
        if ( strHref.indexOf("?") > -1 )
        {
            var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
            var aQueryString = strQueryString.split("&");
            for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
            {
                if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
                {
                    var aParam = aQueryString[iParam].split("=");
                    strReturn = aParam[1];
                    break;
                }
            }
        }
        return unescape(strReturn);
    }
    function onEnter(event,id,type)
    {
        var keycode=0;
        if(event.which)
            keycode=event.which;
        else if(event.keyCode)
            keycode=event.keyCode;
        if(keycode==13)
        {
            doSearch(type);
            return false;
        }
        return true;
    }
    function cleanupChart()
    {
        document.getElementById('div_chart').innerHTML='<span style="font-weight:bold;font-size:14px;">Pick a parameter from the Available Data tag to do a quick view on the latest data(up to 7 days)</span>';
        document.getElementById("div_chart").style["height"]="30px";
        document.getElementById("div_chart").style["border"]="1px dashed #D3D9E5"
        document.getElementById('div_toolbar').style['display']="none";
    }
    function cleanTabs()
    {
        document.getElementById('div_pltInfo').innerHTML="<p>Click the icon on the map to display the platform/station information.</p>";
        document.getElementById("div_senInfo").innerHTML="<p>Select a platform to get the list of available sensors.</p>";
        setButtons(false);
    }
    function initControls()
    {
        
        document.getElementById('rad_view1').checked=true;
        //document.getElementById('rad_view2').checked=false;
        
        document.getElementById('chk_cman').checked=false;
        document.getElementById('img_cman').src=getImgById("3");
        
        document.getElementById('chk_ws').checked=false;
        document.getElementById('img_ws').src=getImgById("1");
        
        document.getElementById('chk_wl').checked=false;
        document.getElementById('img_wl').src=getImgById("2");
        
        document.getElementById('chk_mb').checked=false;
        document.getElementById('img_mb').src=getImgById("15");
        document.getElementById('chk_gw').checked=false;
        document.getElementById('img_gw').src=getImgById("4");
        document.getElementById('chk_db').checked=false;
        document.getElementById('img_db').src=getImgById("7");
        document.getElementById('chk_cb').checked=false;
        document.getElementById('img_cb').src=getImgById("8");
        document.getElementById('chk_news').checked=false;
        document.getElementById('img_news').src=getImgById("9");
        document.getElementById('chk_as').checked=false;
        document.getElementById('img_as').src=getImgById("11");
        document.getElementById('chk_omr').checked=false;
        document.getElementById('img_omr').src=getImgById("12");
        //document.getElementById('chk_sr').checked=false;
        //document.getElementById('img_sr').src=getImgById("13");
        document.getElementById('sel_hours').selectedIndex=1;
        document.getElementById('sel_unit').selectedIndex=0;
        document.getElementById('sel_tzone').selectedIndex=0;
        document.getElementById('in_sid').value="";
        document.getElementById('a_more').href=window.location.href;
        document.getElementById('a_sub').href=window.location.href;
        
        document.getElementById('chk_rod_hatemp').checked=false;
        document.getElementById('chk_rod_latemp').checked=false;
	document.getElementById('chk_rod_hwtemp').checked=false;
	document.getElementById('chk_rod_lwtemp').checked=false;
	document.getElementById('chk_rod_hwgust').checked=false;
	document.getElementById('chk_rod_hwave').checked=false;
        cleanTabs();
    }
    var div_mask=null;
    var div_rssdiag=null;
    var base_rss=null;
    var rss_url=null;
    var rss_time=0;
    var rss_unit=0;
    
    function showRSSDialog(pid,ptid)
    {
        base_rss=base_url+"glos_obs/rss/"+ptid+"-"+pid;//+"-0"+"-0.xml";
        if(div_mask==null)
            div_mask=document.getElementById('div_mask');
        if(div_rssdiag==null)
            div_rssdiag=document.getElementById('div_rssdiag');
        if(div_mask!=null&&div_rssdiag!=null)
        {
            document.getElementById("div_chart").style['display']='none';
            div_mask.style['display']='block';
            div_rssdiag.style['display']='block';
            rss_time=Math.abs(document.getElementById('sel_rss_tzone').value);
            var temp=document.getElementById('sel_rss_unit').value;
            if('m'==temp)
                rss_unit=0;
            else
                rss_unit=1;
            rss_url=base_rss+"-"+rss_time+"-"+rss_unit+".xml";
            updateRSS();
        }
    }
    function hideMask()
    {
        if(div_mask==null)
            div_mask=document.getElementById('div_mask');
        if(div_rssdiag==null)
            div_rssdiag=document.getElementById('div_rssdiag');
        if(div_mask!=null&&div_rssdiag!=null)
        {
            div_mask.style['display']='none';
            div_rssdiag.style['display']='none';
            document.getElementById('div_chart').style['display']='block';
        }
    }
    function changeRSSTimezone(id)
    {
        rss_time=Math.abs(id.value);
        rss_url=base_rss+"-"+rss_time+"-"+rss_unit+".xml";
        updateRSS();
    }
    function changeRSSUnit(id)
    {
        if('m'==id.value)
            rss_unit=0;
        else
            rss_unit=1;
        rss_url=base_rss+"-"+rss_time+"-"+rss_unit+".xml";
        updateRSS();
    }
    function updateRSS()
    {
        document.getElementById('rss_basic').href=rss_url;
        document.getElementById('rss_yahoo').href="http://add.my.yahoo.com/rss?url="+rss_url;   
        document.getElementById('rss_google').href="http://fusion.google.com/add?source=atgs&feedurl="+rss_url;
        document.getElementById('rss_newsgator').href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url="+rss_url;
        document.getElementById('rss_bloglines').href="http://www.bloglines.com/sub/"+rss_url;
        document.getElementById('rss_aol').href="http://feeds.my.aol.com/add.jsp?url="+rss_url;
        document.getElementById('rss_netvibes').href="http://www.netvibes.com/subscribe.php?url="+rss_url;
    }
    function cleanSearch()
    {
        removeSearchResult();
        showCleanSearchLink(false);
        
    }
