

function timeToString(hr,min){
  if(hr>11&&hr<24){
    work='pm'
    if(hr>12){
      hr=hr-12
    }
  }else{
    work='am'
    if(hr==0||hr==24){
      hr=12
    }
  }
  if(min<10){
    min='0'+min
  }
work=hr+":"+min+work
  return work
}


/*
Chart 1 day tall and this.days long
*/
// Class
function Chart(x, y) { // x, y, upper left coordinate 
// SuperClass Attributes
this.days = 5
this.maxY = 144
this.maxX = this.days * this.maxY
this.timePerPixel = ((this.maxY/24)/60)*100 // divide by 24 to get pixels per hour.  Divide by 60 to get minutes each pixel represents.  Multiply by 100 to make it work
this.currentPosition =0
this.currentHour=0
this.stormTotal=0
this.hourX = 676+2
this.hourY = 246
// Attributes
this.startX = x
this.startY = y
this.raining=false
this.snowing=false
this.dailyStormTotals=0
}
// Constructors
Chart.prototype.ChartStart=function(){
  this.currentPosition=this.startPosition
  this.Chart()
  chart.displayCurrent()
}
Chart.prototype.Chart=function(){
  var pixels = 0
  var a = 0//to step through day arrays
  var z = 0//work var to clip 'stary night' pics
  this.x = this.startX
  this.y = this.startY
  this.history =new Array(3)
  this.historyPrecipitation=new Array(3)
  this.stormTotal=0
  this.raining=false
  this.snowing=false
  for(a=0;a<this.history.length;a++){
    this.history[a]=0
    this.historyPrecipitation[a]=0
  }
  jg.clear()
//  jg.drawImage("bezel5.png", this.x-50,this.y-61,820,264); moved to chart level function 
  jg.drawImage("5-day.png", this.startX,this.startY,this.maxX,this.maxY);
//the screen draws before we have data so, we need to make sure we have data
//currentPosition is set after data has loaded
  if(this.currentPosition>0){//if we have data, we don't at first
    pixels = this.timeToPixels(this.sunRiseHr[this.currentPosition],this.sunRiseMin[this.currentPosition])
    z=60-pixels//shrink to fit
    jg.drawImage("5-night1.png", this.x,this.y+pixels-60+z,this.maxX,60-z+10);
    pixels = this.timeToPixels(this.sunSetHr[this.currentPosition],this.sunSetMin[this.currentPosition])
    z=144-50-pixels+1
    jg.drawImage("5-night2.png", this.x,this.y+pixels,this.maxX,50+z)
  }
  jg.setStroke(1);
  jg.setColor("#CCCCCC"); // grey
  jg.drawLine(this.startX,this.startY,this.startX,this.startY+this.maxY)
  jg.drawLine(this.startX,this.startY,this.startX+this.maxX,this.startY)
  jg.drawLine(this.startX,this.startY+this.maxY,this.startX+this.maxX,this.startY+this.maxY)
  jg.drawLine(this.startX+this.maxX,this.startY,this.startX+this.maxX,this.startY+this.maxY)
  if(this.currentPosition>0){
    jg.setStroke(1);
    jg.setColor("#333333"); // dark grey
    jg.drawString("Moon Phase shown at Transit - Moon Rise is before Transit",430,250)
    jg.setColor("#CCCCCC"); // grey
    jg.drawString("Moon Phase shown at Transit - Moon Rise is before Transit",431,249)
    var $sunColor="#FFFF33"
    var $sunBkgd="#666633"
    var $moonColor="#FF9900"
    var $moonBkgd="#993300"
    
    this.PlotTime($sunColor,$sunBkgd,"Sun in Yellow",132,250)
    this.PlotTime($moonColor,$moonBkgd,"Moon in Orange",270,250)
    this.x = this.startX
    this.y = this.startY
    // currentPosition is the last day, so we start this.days before
    for(a=this.currentPosition-this.days+1;a<=this.currentPosition;a++)  {
      jg.setStroke(1);
      jg.setColor("#CCCCCC"); // grey
      jg.drawLine(this.x+144,this.startY,this.x+144,this.startY+this.maxY)
      if(this.moonTranHr[a]>=0) {
        work="moon"+this.moonPhase[a]+".png"
        pixels=this.timeToPixels(this.moonTranHr[a],this.moonTranMin[a])
        jg.drawImage(work, this.x+pixels-18,this.y+pixels-18,36,36); //moon
      }
      this.dailyStormTotals=0
      if(a==this.currentPosition){//last day, add the year
        var temp=this.dateString[a]+' '+this.year[a]
      }else{
        var temp=this.dateString[a]
      }
      this.makeLabel(this.sunRiseHr[a],this.sunRiseMin[a],$sunColor,$sunBkgd)
      this.makeLabel(this.sunSetHr[a],this.sunSetMin[a],$sunColor,$sunBkgd)
      if(this.moonRiseHr[a]==-1){//-1 is null
      }else{
        this.makeLabel(this.moonRiseHr[a],this.moonRiseMin[a],$moonColor,$moonBkgd)
      }
      if(this.moonTranHr[a]==-1){//-1 is null
      }else{
        this.makeLabel(this.moonTranHr[a],this.moonTranMin[a],$moonColor,$moonBkgd)
      }
      if(this.moonSetHr[a]==-1){///-1 is null
      }else{
        this.makeLabel(this.moonSetHr[a],this.moonSetMin[a],$moonColor,$moonBkgd)
      }
      jg.setColor("#333333"); // dark-grey
      jg.drawStringRect(this.dayName[a],this.x+35 ,65, 80,"center")
      jg.drawStringRect(temp,this.x+35 ,80, 80,"center")
      jg.setColor("#CCCCCC"); // grey
      jg.drawStringRect(this.dayName[a],this.x+35+1 ,65-1, 80,"center")
      jg.drawStringRect(temp,this.x+35+1 ,80-1, 80,"center")
 //     this.x=this.x+144
      this.PlotTemperature('temperature',this.temperature[a],"#FFFFFF",a)
      this.PlotBarometer(this.barometer[a],a)
      this.PlotTemperature('humidity',this.humidity[a],"#0000FF",a)
      this.PlotTemperature('dewpoint',this.dewpoint[a],"#00CCFF",a)
      this.PlotWind(this.windDegrees[a],this.windMPH[a],this.windGust[a],a)
      this.PlotPrecipitation(this.precipHour[a],this.precipDay[a],a)
      this.x=this.x+144
    }
    if(!this.temperature[a-1]){
    }else{
      this.currentHour=this.temperature[a-1].length-1
    }
  }else{//no data yet
    this.displayItem('','Loading...')
  }
  jg.paint();
}

// Accessors - getters and setters
this.method=function(){
}
// Public Interface Methods
Chart.prototype.addTime=function(time,direction){
  if(time=='Hour'){
    var count=1
    if(!this.temperature[this.currentPosition]){
      var readingsToday=0
    }else{
      var readingsToday=this.temperature[this.currentPosition].length-1
      jg.setStroke(2)
      jg.setColor("#000018"); // dk blue to remove position before move
      pixels=this.timeToPixels(this.hour[this.currentPosition][this.currentHour],0)
      jg.drawLine(this.hourX+pixels,this.hourY,this.hourX+pixels,this.hourY+3)
      jg.paint();
    }
    if(direction<0){//negative is going backwards
      if(this.currentHour+direction<0){//if we fall before midnight
        this.addTime('Day',direction)
      }else{
        this.currentHour=this.currentHour+direction        
      }
    }else{//direction >0
      if(this.currentHour+direction>readingsToday){//if we go past midnight
        this.addTime("Day",direction)
//reset mark at last reading of the day
        if(this.currentHour>0){//if we have weather data on the next day
          jg.setStroke(2)
          jg.setColor("#000024"); // dk blue to remove position before move
          pixels=this.timeToPixels(this.hour[this.currentPosition][this.currentHour],0)
          jg.drawLine(this.hourX+pixels,this.hourY,this.hourX+pixels,this.hourY+3)
          jg.paint();
        }
        this.currentHour=0// override default setting of last reading of the day if scrolling through hour by hour
      }else{
        this.currentHour=this.currentHour+direction        
      }
    }
  }else{
    if(time=='Day'){
      var count=1
    }else if(time=='Week'){
      var count=7
    }else if(time='Month'){
      var count=30
    }
    if(direction<0){
      var item='back'+time
    }else{
      var item='add'+time
    }
    var hi=this.sunRiseHr.length-5
    count=count*direction
    this.currentPosition=this.currentPosition+count
    if(this.currentPosition<this.days){
      this.currentPosition=this.days-1
    }else if(this.currentPosition>hi){
      this.currentPosition=hi
    }
    if(!this.temperature[this.currentPosition]){
      this.currentHour=0
    }
    this.Chart()
  }
  this.displayCurrent()
}

Chart.prototype.Test=function(item) {
this.change(item)
  this.Chart()
  this.displayCurrent()
 this.change(item)
 
}
Chart.prototype.displayCurrent=function(){
  var chr=''
  var value=chr
  if(!this.currentPosition){
  }else{
    if(!this.temperature[this.currentPosition]){
    }else if(!this.temperature[this.currentPosition][this.currentHour]){//no temp?
    }else{
      var value=this.temperature[this.currentPosition][this.currentHour]+'&deg;'
      itemID=document.getElementById('precip')
      if(!itemID){
      }else{
        if(this.temperature[this.currentPosition][this.currentHour]>35){  
          itemID.setAttribute('src','rain.png')
        }else{
          itemID.setAttribute('src','snow.png')
        }
      }
    }
    this.displayItem('temperature',value)
    value=chr
    if(!this.barometer[this.currentPosition]){
    }else if(!this.barometer[this.currentPosition][this.currentHour]){//no temp?
    }else{
      var value=this.barometer[this.currentPosition][this.currentHour]+'"'
    }
    this.displayItem('barometer',value)
    value=chr
    if(!this.humidity[this.currentPosition]){
    }else if(!this.humidity[this.currentPosition][this.currentHour]){//no temp?
    }else{
      var value=this.humidity[this.currentPosition][this.currentHour]+'%'
    }
    this.displayItem('humidity',value)
    value=chr
    if(!this.dewpoint[this.currentPosition]){
    }else if(!this.dewpoint[this.currentPosition][this.currentHour]){//no temp?
    }else{
      var value=this.dewpoint[this.currentPosition][this.currentHour]+'&deg;'
    }
    this.displayItem('dewpoint',value)
    value=chr
    if(!this.windMPH[this.currentPosition]){
    }else if(!this.windMPH[this.currentPosition][this.currentHour]){
      value='Calm'
    }else{
      if(!this.windDirection[this.currentPosition]){
      }else if(!this.windDirection[this.currentPosition][this.currentHour]){//no temp?
      }else{
        var value=this.windDirection[this.currentPosition][this.currentHour]+' @ '+this.windMPH[this.currentPosition][this.currentHour]+'/g '+this.windGust[this.currentPosition][this.currentHour]
      }
    }
    this.displayItem('wind',value)
    if(this.stormTotal==0){
      value=chr
    }else{
      var hr = Math.round(this.stormTotal*100)/100
      value=hr+'" total'
      value=chr
    }
    if(!this.precipHour[this.currentPosition]){
    }else if(!this.precipHour[this.currentPosition][this.currentHour]){//no temp?
    }else{
      var hr = Math.round(this.precipHour[this.currentPosition][this.currentHour]*100)/100
      var day = Math.round(this.stormTotal*100)/100
      var value=hr+'"/hr '
    }
    this.displayItem('precip',value)
    value=chr
    if(!this.hour[this.currentPosition]){
//    }else if(!this.hour[this.currentPosition][this.currentHour]){//this.currentHour[0] doesn't work when using this???
    }else{//I'm assuming this.minute and this.dateString exist too
      value=this.dateString[this.currentPosition]+' '+timeToString(this.hour[this.currentPosition][this.currentHour],this.minute[this.currentPosition][this.currentHour])
      pixels=this.timeToPixels(this.hour[this.currentPosition][this.currentHour],0)
      jg.setStroke(2)
      jg.setColor("#006600"); // dark green to mark position
      jg.drawLine(this.hourX+pixels-1,this.hourY+1,this.hourX+pixels-1,this.hourY+3+1)
      jg.setColor("#00FF00"); // green to mark position
      jg.drawLine(this.hourX+pixels,this.hourY,this.hourX+pixels,this.hourY+3)
//      jg.drawLine(this.hourX+pixels+1,this.hourY-1,this.hourX+pixels+1,this.hourY+3-1)
      jg.paint();
    }
    this.displayItem('',value)
  }
}

// Private Implementation Methods

Chart.prototype.displayItem=function(item,value){
  elem=document.getElementById(item+'Span')
  if(elem!=null){
      elem.innerHTML=value
  }else{
  }
}

Chart.prototype.PlotTime=function(color,bkgd,description,x,y) {
  var a = 0
  var startDay=this.currentPosition-this.days+1
  var endDay=startDay+this.days
  this.x = this.startX
  this.y = this.startY
  jg.setColor(bkgd)
  jg.drawString(description,x,y)
  jg.setColor(color)
  jg.drawString(description,x+1,y-1)
//  jg.paint();
}
Chart.prototype.PlotTemperature=function(item,array,color,current) {
  var item=document.getElementById(item+'CB')
  if(item.alt=='on'){
    var pixels=0
    var a=0
    if(!array){//empty
    }else{
      pixels=this.timeToPixels(this.hour[current][a],this.minute[current][a])
      var lastPixels=pixels
      for(a=0;a<=array.length;a++){//start at second enter 
        pixels=this.timeToPixels(this.hour[current][a],this.minute[current][a])
        var position = ((120-array[a]-40)/160)*this.maxY+48
        var position2 = ((120-array[a-1]-40)/160)*this.maxY+48
        jg.setStroke(1)
        jg.setColor(color)
        jg.drawLine(this.x+pixels,this.y+position,this.x+lastPixels,this.y+position2)
        lastPixels=pixels
      }
    }
  }
}
Chart.prototype.PlotBarometer=function(array,current) {
  var item=document.getElementById('barometerCB')
  if(item.alt=='on'){
    if(!array){//empty
    }else{
 //barometric pressure range 28.5 to 31.5
      var points=0
      var a=0
      for(a=0;a<3;a++){
        if(this.history[a]==0){
          this.history[a]=array[0]
        }
      }
      for(a=0;a<=array.length;a++){//start at second enter
        points=0
        pixels=this.timeToPixels(this.hour[current][a],this.minute[current][a])
        if(array[a]>28){//10/26/8 to reject bad data
          var position = this.maxY-((array[a]-28.5)/3)*this.maxY
          jg.setColor("#FF0000") //red
          jg.setStroke(2)
          if(array[a]>28.9 && array[a]<29.6){
            points=points+1
          }
          if(array[a]>30.4 && array[a]<31.5){
            points=points+1
          }
          this.history[2]=this.history[1]
          var minusTwo=this.history[2]
          this.history[1]=this.history[0]
          var minusOne=this.history[1]
          this.history[0]=array[a]
          if( array[a]>minusOne){
            if( minusOne>minusTwo || (array[a] -minusTwo)>.06){
              points=points+(array[a]-minusTwo)*100
            }
          }
          if( array[a]<minusOne){
            if( minusOne<minusTwo){
              points=points+(minusTwo-array[a])*100
            }
          }
          if(points>2) {
            jg.setStroke(points)
            jg.setColor("#FFFF00") //yellow
            if(points>6){
              jg.setColor("#006600") //green 
            }
          }  
          jg.drawLine(this.x+pixels,this.y+position,this.x+pixels,this.y+position)
        }//don't draw fi bad data
      }
    }
  }
}
Chart.prototype.PlotWind=function(degrees,mph,gust,current) {
 //color code direction
 //wind range 0 to 80.0
  var item=document.getElementById('windCB')
  var maxWind=120
  if(item.alt=='on'){
    if(!degrees){//empty
    }else{
      var a=0
      for(a=0;a<degrees.length;a++){
        var pixels=this.timeToPixels(this.hour[current][a],this.minute[current][a])-1
//        var position = ((60-mph[a])/60)*this.maxY
        var position = (1-((maxWind-mph[a])/maxWind))*this.maxY
        if(degrees[a]<160){
          jg.setColor("#FF0000"); // red
        }else if(degrees[a]<180){
          jg.setColor("#FFFF00"); // yellow
        }else if(degrees[a]<330){
          jg.setColor("#00FF00"); // green
        }else{
          jg.setColor("#FFFF00"); // yellow
        }
//        jg.setStroke(3);
//        jg.drawLine(this.x+pixels,this.y+1,this.x+pixels,this.y+position+1)
//        pixels=pixels+1
//        position = (1-((maxWind-gust[a])/maxWind))*this.maxY
//        jg.setStroke(1);
//        jg.drawLine(this.x+pixels,this.y+1,this.x+pixels,this.y+position+1)
        jg.setStroke(1);
        var wind=this.y+position+1
        jg.drawLine(this.x+pixels,this.y+1,this.x+pixels,wind)
//        pixels=pixels+1
        position = (1-((maxWind-gust[a])/maxWind))*this.maxY
        jg.setStroke(2);
        jg.drawLine(this.x+pixels,wind,this.x+pixels,this.y+position+1)
      }
    }
  }    
}
Chart.prototype.PlotPrecipitation=function(perHour,perDay,current) {
 //color code direction
 //snow range 0 to 84 inches (7ft)
  var $maxInches=8;
  $snowTemp=32;
  var item=document.getElementById('precipCB')
  if(item.alt=='on'){
    if(!perHour){//empty perHour array
    }else{
      var a=0
      var storm=0
      for(a=0;a<perHour.length;a++){
        var pixels=this.timeToPixels(this.hour[current][a],this.minute[current][a])+2// to center
        if((!perHour[a])|(perHour[a]<0)){//empty perHour with null entries //10/26/8 or bad data
          var hourx=0
          var safePer=0
        }else{
          var safePer=perHour[a]
          if(!this.temperature[current]){
          }else if(!this.temperature[current][a]){
          }else{
            if(this.temperature[current][a]>$snowTemp){  
              var safePer=perHour[a]
            }else{
// it appears that precip is changed at the weather station Nov or so
//              var safePer=perHour[a]*100
              var safePer=perHour[a]*10
            }
          }
          if(safePer>0){
            this.stormTotal=this.stormTotal+safePer
          }
          var storm=Math.round((this.stormTotal/$maxInches)*this.maxY*100)/100
          var hourx=(safePer/$maxInches)*this.maxY
          if(safePer>0){
            this.stormTotalCheck(current,a,storm,pixels)
          }
          if(storm>1){
            jg.setColor("#9999CC"); // grey
            jg.setStroke(6);
            jg.drawLine(this.x+pixels-6,this.y+this.maxY-5,this.x+pixels-6,this.y+this.maxY-storm-5)
          }
          jg.setColor("#FFFFFF"); // white
          if(perHour[a]<1){
            jg.setStroke(1);
          }else{
            jg.setStroke(3);
          }
          jg.drawLine(this.x+pixels-3,this.y+this.maxY-5,this.x+pixels-3,this.y+this.maxY-hourx-5)
        }
        this.historyPrecipitation[2]=this.historyPrecipitation[1]
        this.historyPrecipitation[1]=this.historyPrecipitation[0]
        this.historyPrecipitation[0]=safePer
        var b=0
        var rain=false
        for(b=0;b<2;b++){
          if(this.historyPrecipitation[b]>0){
            if(this.raining||this.snowing){
              rain=true
            }
          }
        }
        if(!rain){
          this.stormTotalDisplay(current,a,storm,pixels)
        }
      }
    }
  }
}
Chart.prototype.stormTotalCheck=function(current,a,storm,pixels) {
  if(this.temperature[current][a]>35){
    if(!this.raining){//it just started
      if(this.snowing){//if it was snowing, post a total
        this.stormTotalDisplay(current,a,storm,pixels)
      }
      this.raining=true
      this.snowing=false
    }
  }else{
    if(!this.snowing){//it just started
      if(this.raining){//if it was raining, post a total
        this.stormTotalDisplay(current,a,storm,pixels)
      }
      this.snowing=true
      this.raining=false
    }
  }
}
Chart.prototype.stormTotalDisplay=function(current,a,storm,pixels) {
  if(this.stormTotal>0){
    var x = Math.round(this.stormTotal*10)/10
    if(this.snowing){
      var foreground="#FFFFFF" // white
      var background="#666666" // dark grey
   }else{
      var foreground="#0000EE" // blue
      var background="#999999" // light grey
    }
    jg.setColor(background)
    jg.drawString(x+'"',this.x+pixels,this.y+this.maxY-storm+this.dailyStormTotals)
    jg.setColor(foreground)
    jg.drawString(x+'"',this.x+pixels+1,this.y+this.maxY-storm+this.dailyStormTotals-1)
//    this.dailyStormTotals=this.dailyStormTotals+12
    this.stormTotal=0
  }
}
Chart.prototype.timeToPixels=function(hr,min) {
  //return pixels
  var pixels = ((hr*60)+min)/this.timePerPixel
  return pixels
}

Chart.prototype.makeLabel=function(hr,min,color,bkgd) {
  var pixels = this.timeToPixels(hr,min)
  var yAdj = 0
  jg.setStroke(3);
  yAdj=-7//how far away in the y direction
  var work=timeToString(hr,min)
  if(hr<14){
    jg.setColor(bkgd)
    jg.drawStringRect(work,this.x+pixels+6,this.y+pixels+yAdj, 60,"left")
    jg.setColor(color)
    jg.drawStringRect(work,this.x+pixels+6+1,this.y+pixels+yAdj-1, 60,"left")
    }else{
    jg.setColor(bkgd)
    jg.drawStringRect(work,this.x+pixels-66,this.y+pixels+yAdj, 60,"right")
    jg.setColor(color)
    jg.drawStringRect(work,this.x+pixels-66+1,this.y+pixels+yAdj-1, 60,"right")
  }
  jg.setStroke(5);
  jg.setColor(bkgd)
  jg.drawLine(this.x+pixels,this.y+pixels,this.x+pixels,this.y+pixels)
  jg.setStroke(3);
  jg.setColor(color)
  jg.drawLine(this.x+pixels+1,this.y+pixels,this.x+pixels+1,this.y+pixels)
}
//copied from cb
Chart.prototype.change=function(cb){
  var item=document.getElementById(cb+'CB')
  if(item.alt=='on'){
    item.src='unchecked.png'
    item.alt='off'
  }else{
    item.src='checked.png'
    item.alt='on'
  }
  chart.Chart()
  chart.displayCurrent()
  }
//end copy 


/*
Check Box - item is the menu item
*/
// Class
function CB(item,anchor) {
// SuperClass Attributes
// Attributes
  this.cb=document.createElement('img')
  this.cb.setAttribute('id',item+'CB')
  anchor.appendChild(this.cb)

}
// Constructors

// Accessors - getters and setters
CB.prototype.Reset=function(cb){
  var item=document.getElementById(cb+'CB')
  item.src='unchecked.png'
  item.alt='off'
}
CB.prototype.Sett=function(cb){
  var item=document.getElementById(cb+'CB')
  item.src='checked.png'
  item.alt='on'
}
CB.prototype.change=function(cb){
  var item=document.getElementById(cb+'CB')
  if(item.alt=='on'){
    item.src='unchecked.png'
    item.alt='off'
  }else{
    item.src='checked.png'
    item.alt='on'
  }
  chart.Chart()
  chart.displayCurrent()
  }
// Public Interface Methods
CB.prototype.checked=function(cb){
  var item=document.getElementById(cb+'CB')
  if(item.alt=='on'){
    return true
  }else{
    return false
  }
}
CB.prototype.test=function(cb){
  var item=document.getElementById(cb+'CB')
  if(item.alt=='on'){
    if(item.src=='http://info-tran.com/chart/checked.png'){
    item.alt='off'
    }
  }
  if(item.alt=='off'){
    if(item.src=='unchecked.png'){
    item.alt='on'
  }
  }
  chart.Chart()
  chart.displayCurrent()
}
// Private Implementation Methods


/*
Control used for all navigation
*/
// Class
function Control() { 
// SuperClass Attributes
  this.name = ""  //assigned by each control constructor
  this.over = ""
  this.out = ""
  this.on = ""
  this.down = ""
  this.click = ""
// Attributes
}
// Constructors
Control.prototype.Menu=function(menu,filler){
  this.name=menu
  this.menuID=document.getElementById(menu)
  var dl=document.createElement('dl')
  dl.setAttribute('id',menu+'Menu')
  this.menuID.appendChild(dl)
  var image=document.createElement('img')
  image.setAttribute('src',filler)
  dl.appendChild(image)
}
Control.prototype.Link=function(item,newline,filler,label,padding,alt){
  //item - text name of the menu item, blank item name gets no checkbox
  //newline - boolean
  //filler - text img.src of image to occur before the link
  //label - text img.src of image to click
  //padding - text img.src of image before label to include in anchor
  //img.src can be '' if no space is required
  //alt - text for img alt
  var klass = 'toy'
  if(newline){//each link starts with a newline, so the first call should be true
    //this allows a variety of objects to be included in the link
    var dt=document.createElement('dt')
    dt.setAttribute('id',this.Menu.name+'Header')
    this.menuID.appendChild(dt)
  }
  var dd=document.createElement('dd')
  dd.setAttribute('id',item+'Item')
  this.menuID.appendChild(dd)
  itemID=document.getElementById(item+'Item')
  if (!(!( filler||false ))){ //i stole this from http://jehiah.cz/archive/javascript-isdefined-function
    var image=document.createElement('img')
    image.setAttribute('src',filler)
    itemID.appendChild(image)
  }
  if(item!=''){//ignore empty items
    var anchor=document.createElement('a')
    anchor.setAttribute('id',item+'Anchor')
    anchor.setAttribute('class',klass)
    itemID.appendChild(anchor)
    if (!(!( padding||false ))){//ignore empty padding
      var image=document.createElement('img')
      image.setAttribute('src',padding)
      anchor.appendChild(image)
    }
    if(this.name=='data'){//add a checkbox to each item on the data menu
      var cb=new CB(item,anchor)
      cb.Reset(item)
      anchor.onclick=function(){cb.change(item)}
//      anchor.onmouseover=function(){cb.test(item)}
//      anchor.onmouseout=function(){cb.test(item)}
    }
    var image=document.createElement('img')
    image.setAttribute('src',label)
    image.setAttribute('alt',alt)
    image.setAttribute('id',item)
    anchor.appendChild(image)
  }
  return anchor
}
Control.prototype.TimeLink=function(time,filler,label,padding){
  if(time=='Hour'){
    var alt='Go Back an '+time
  }else if(time=='Day'){
    var alt='Back a '+time
  }else {
    var alt='Last '+time
  }
  var item="back"+time
  var arrow='leftArrow.png'
  var itemID=this.Link(item,true,filler,arrow,padding,alt)
  itemID.onclick=function(){chart.addTime(time,-1)}
  var dd=document.createElement('dd')
  dd.setAttribute('id',time)
  this.menuID.appendChild(dd)
  var image=document.createElement('img')
  image.setAttribute('src',label)
  dd.appendChild(image)
  if(time=='Hour'){
    var alt='Add an '+time
  }else if(time=='Day'){
    var alt='Add a '+time
  }else {
    var alt='Next '+time
  }
  var item="add"+time
  var arrow="rightArrow.png"
  var filler=""//item filler
  var padding=''
  var itemID=this.Link(item,false,filler,arrow,padding,alt)
  itemID.onclick=function(){chart.addTime(time,1)}
}
Control.prototype.DataLink=function(item,filler){
  if(item!=""){
    var padding=item+'Legend.png'
    var label=item+'.png'
  }else{
    var padding=''
    var label=''
  }
  var alt='Switch '+item
  var itemID=this.Link(item,true,filler,label,padding,alt)
  if (!(!( filler||false ))){ //i stole this from http://jehiah.cz/archive/javascript-isdefined-function
    var dd=document.createElement('dd')
    dd.setAttribute('id',item)
    this.menuID.appendChild(dd)
  }
  var span=document.createElement('span')
  span.setAttribute('id',item+'Span')
  span.setAttribute('class','current')
  dd.appendChild(span)
}
// Accessors - getters and setters
Control.prototype.Back=function(){
  var menu='back'
  var item='back'
  var label='back.png'
  var header="../mt/mt27x27.png"
  this.Menu(menu,header)
  var filler="../mt/mt15x17.png"
  var padding=''
  var alt='Back to Projects'
  var itemID=this.Link(item,true,filler,label,padding,alt)
  itemID.href='../projects.html'
}
Control.prototype.Today=function(){
  var menu='today'
  var item='today'
  var label='today.png'
  var header="../mt/mt27x27.png"
  this.Menu(menu,header)
  var filler="../mt/mt11x11.png"//item filler
  var padding=''
  var alt='Go to Today'
  var itemID=this.Link(item,true,filler,label,padding,alt)
  itemID.onclick='chart.ChartStart()'
  itemID.onclick=function(){chart.ChartStart()}
}
Control.prototype.Time=function(){
  var menu='time'
  var header="../mt/mt15x17.png"
  this.Menu(menu,header)
  var filler="../mt/mt15x17.png"//item filler
  var item='Hour'
  var label='hour.png'
  var padding="../mt/mt3x17.png"//arrow padding
  this.TimeLink(item,filler,label,padding)
  var item='Day'
  var label='day.png'
  var padding="../mt/mt7x17.png"//arrow padding
  this.TimeLink(item,filler,label,padding)
  var item='Week'
  var label='week.png'
  var padding="../mt/mt3x17.png"//arrow padding
  this.TimeLink(item,filler,label,padding)
  var item='Month'
  var label='month.png'
  var padding=""//arrow padding
  this.TimeLink(item,filler,label,padding)

}
Control.prototype.Data=function(){
  var menu='data'
  var header="../mt/mt13x17.png"
//  var header=''
  this.Menu(menu,header)
  var filler="../mt/mt15x17.png"//item filler
  var item='temperature'
  this.DataLink(item,filler)
  var item='barometer'
  this.DataLink(item,filler)
  var item='humidity'
  this.DataLink(item,filler)
  var item='dewpoint'
  this.DataLink(item,filler)
  var item='wind'
  this.DataLink(item,filler)
  var item='precip'
  this.DataLink(item,filler)
  var item=''
  var filler="../mt/mt65x17.png"//item filler
  this.DataLink(item,filler)
}
/*
Connection
*/
// Class
function Connection(latC, lonC, latW, lonW){
// SuperClass Attributes

// Attributes
  this.http=false;
  this.method='GET'
  this.async=true
  this.status=null
  this.statusText=''
  this.responseText=null
  this.timesChanged=0
 var con = false
  //this.connection=this.Connection()
this.Connect2(latC, lonC, latW, lonW)

}
// Constructors
Connection.prototype.Connect2=function(latC, lonC, latW, lonW){
  var httpRequest;
  var url='getData.php/'+latC+'/'+lonC+'/'+latW+'/'+lonW
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
    if (httpRequest.overrideMimeType) {
      httpRequest.overrideMimeType('text/xml');
    }
  }else if (window.ActiveXObject) { // IE
    try {
      httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
      try {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {}
    }
  }
  if (!httpRequest) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
  }
  httpRequest.onreadystatechange = function() {
    if(window.myCon){
      myCon.timesChanged=myCon.timesChanged+1
    }
    if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
        eval(httpRequest.responseText)
        chart.Chart()
        chart.displayCurrent()
      }
    }
  }
  httpRequest.open('GET', url, true);
  httpRequest.send('');
}
Connection.prototype.Connection=function(){
  var httpRequest=false
  //http://www.jibbering.com/2002/4/httprequest.html
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
   try {
    httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
     httpRequest = false;
    }
   }
  @end @*/
  if (!httpRequest && typeof XMLHttpRequest!='undefined') {
  	try {
  		httpRequest = new XMLHttpRequest();
  	} catch (e) {
  	httpRequest=false;
  	}
  }
  if (!httpRequest && window.createRequest) {
  	try {
  	httpRequest = window.createRequest();
  	} catch (e) {
  	httpRequest=false;
  	}
  }
 return httpRequest
//this.RequestData(con,'celestial',1.234,5.678)
//  var url='test.txt'
//con.open("GET",url,true)
// con.onreadystatechange=function(){
//    //GetData(obj)}
//  alert("readyState = "+con.readyState+" status = "+con.status+" responseText = "+con.responseText);
//  if (con.readyState == 4) {
//      if (con.status == 200) {
//      }
//  }
//}
//  con.send(null)
}
// Accessors - getters and setters
Connection.prototype.RequestData=function(type,lat,lon){
  var url='getData.php?'+type+','+lat+','+lon
  var url='infotran.com/chart/getWeatherData.php'
if(this.connection!=null){
this.connection.open("GET",url,true)
var httpRequest = this.connection
var y = function(){this.GetData(x)}
//  x.onreadystatechange=function(){y()}
        httpRequest.onreadystatechange = function() {
//alertContents(httpRequest); };
//alert("readyState = "+httpRequest.readyState+" status = "+httpRequest.status+" responseText = "+httpRequest.responseText)
          var item=document.getElementById('temperatureSpan')
          item.innerHTML='readyState = '+httpRequest.readyState
          var item=document.getElementById('barometerSpan')
          item.innerHTML='status = '+httpRequest.status
          var item=document.getElementById('humiditySpan')
          item.innerHTML='response = '+httpRequest.responseText
          if(window.myCon){
            myCon.timesChanged=myCon.timesChanged+1
            var item=document.getElementById('dewpointSpan')
            item.innerHTML='times changed = '+myCon.timesChanged
          }
          if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
              alert(httpRequest.responseText);
            }
          }
        }
   var item=document.getElementById('temperatureSpan')
  item.innerHTML='Before send status = '+httpRequest.status
//alert(this.http.status)
  httpRequest.send(null)
  var item=document.getElementById('barometerSpan')
  item.innerHTML='After send status = '+httpRequest.status

}
  

}
Connection.prototype.GetData=function(httpObject){
//function GetData(httpObject){
//  alert("readyState = "+httpObject.readyState+" status = "+httpObject.status+" responseText = "+httpObject.responseText)
  var item=document.getElementById('temperatureSpan')
  item.innerHTML='readyState = '+httpObject.readyState
  var item=document.getElementById('barometerSpan')
  item.innerHTML='status = '+httpObject.status
  var item=document.getElementById('humiditySpan')
  item.innerHTML='response = '+httpObject.responseText
//  var item=document.getElementById('humiditySpan')
//  item.innerHTML='readyState = '+httpObject.readyState+' status = '+httpObject.status
//  alert("text="+httpObject.ResponseText)
  if (httpObject.readyState == 4) {
      if (httpObject.status == 200) {
//        alert("text="+httpObject.ResponseText)
      }else{
//        alert('HTTP Status='+httpObject.status)
      }
  }else{
//        alert('readyState='+httpObject.readyState)
  }
  if(window.myCon){
    myCon.timesChanged=myCon.timesChanged+1
    var item=document.getElementById('dewpointSpan')
    item.innerHTML='times changed = '+myCon.timesChanged
  }
}
// Public Interface Methods
this.method=function(){
}
// Private Implementation Methods
this.method=function(){
}
