// This code is based on some original work by an unknown author
// and has been heavily modified for use with FreeWX and FreeWX-Wi.
// Andy Keir, March 4 2005  7:00pm.

// Last Modified 12 Jan 06 - DNB (Burger).
// Version: DNB 130106A
// See comments for mods.

// ******** USER SETTINGS START HERE ********
var wdcompass = 1
var gtitlefont = "Verdana,Arial,Helvetica"
var gtitlesize = "-1"
var gtitlecolor = ""
var gaxisfont = "Arial,Helvetica"
var gaxissize = "-2"
var gaxiscolor = ""
var ott = ""
var oht = ""
var bt = ""
var dpt = ""
var awt = ""
var wdt = ""
var rft = "Peak rainfall rate: last 24 hours"
var itt = ""
var iht = ""
var otl = ""
var ohl = ""
var bl = ""
var dpl = ""
var awl = ""
var wdl = "n"
var rfl = "mm/hr"
var itl = ""
var ihl = ""
var wdgraphline = 1
var wdglsize = 2
var negline = 0
var barimage = "bar.gif"
var wdbarimage = "bar.gif"
var altbarimage = "bar.gif"
var negbarimage = "bar.gif"
var altnegbarimage = "bar.gif"
var gwidth = 260
var gheight = 160
// ******** USER SETTINGS END HERE ********

var shtab = 0
var imbrd = 0
var tdstyle = "font-size: 1px; margin: 0px; padding: 0px; border-width: 0px; line-height: 0px;"

function Graph(width, height, backcol, offset, IsWind, NonMetric, time24) {
 this.backcol = backcol;
 if(offset<0 && negline==1){this.offset = 0}else{this.offset=offset};
 this.IsWind = IsWind;
 this.NonMetric = NonMetric;
 if (gwidth != 0) { this.width = gwidth } else { this.width = width || 400 };
 if (gheight != 0) { this.height = gheight } else { this.height = height || 200 };
 this.rows = new Array();
 this.addRow = _addRowGraph;
 this.setXScale = _setXScaleGraph;
 this.setXScaleValues = _setXScaleValuesGraph;
 this.setTime = _setStartTimeGraph;
 this.build = _buildGraph;
 this.time24 = time24;
 return this;
}
function _addRowGraph() {
 this.rows[this.rows.length] = new Array();
 var row = this.rows[this.rows.length-1];
 for(var i = 0; i < arguments.length; i++)
 row[row.length] = arguments[i];
}
function _rescaleGraph(g) {
 g.posMax = 0, g.negMax = 0, g.c = 0;
 for(var i = 0; i < g.rows.length; i++) {
  for(var j = 0; j < g.rows[i].length; j++) {
   g.c++;
   if(g.rows[i][j] > g.posMax) g.posMax = g.rows[i][j];
   if(g.rows[i][j] < -100) g.rows[i][j] = g.negMax;
   if(g.rows[i][j] < g.negMax) g.negMax = g.rows[i][j];
  }
 }
 if(g.NonMetric == 0){
  if(g.posMax < 1 && g.posMax >= 0) g.posMax = 1;
 }
 if(g.NonMetric == 0){
  if(g.negMax > -1 && g.negMax < 0) g.negMax = -1;
 }
 if(g.NonMetric == 1){
  if(g.posMax < .03 && g.posMax >= 0) g.posMax = 0.03;
 }
 if(g.NonMetric == 1){
  if(g.negMax > -.03 && g.negMax < 0) g.negMax = -0.03;
 }
 if(g.IsWind == 1){
  g.posMax = 360;
  g.negMax = 0
 }
 g.vscale = g.height/(g.posMax-g.negMax);
 g.hscale = Math.floor(g.width/g.c-1/g.rows[0].length);
}
function _checkgtitle(gt){
 switch(gt){
  case("Temperature: last 24 hours"):if(ott != ""){gt = ott};break;
  case("Humidity: last 24 hours"):if(oht != ""){gt = oht};break;
  case("Barometer: last 24 hours"):if(bt != ""){gt = bt};break;
  case("Dew Point: last 24 hours"):if(dpt != ""){gt = dpt};break;
  case("Avg. wind speed: last 24 hours"):if(awt != ""){gt = awt};break;
  case("Wind direction: last 24 hours"):if(wdt != ""){gt = wdt};break;
  case("Rainfall: last 24 hours"):if(rft != ""){gt = rft};break;
  case("Indoor temperature: last 24 hours"):if(itt != ""){gt = itt};break;
  case("Indoor humidity: last 24 hours"):if(iht != ""){gt = iht};break;
 }
 return(gt);
}
function _checkglegend(gt,gl){
 switch(gt){
  case("Temperature: last 24 hours"):if(otl != ""){gl = otl};break;
  case("Humidity: last 24 hours"):if(ohl != ""){gl = ohl};break;
  case("Barometer: last 24 hours"):if(bl != ""){gl = bl};break;
  case("Dew Point: last 24 hours"):if(dpl != ""){gl = dpl};break;
  case("Avg. wind speed: last 24 hours"):if(awl != ""){gl = awl};break;
  case("Wind direction: last 24 hours"):if(wdl != ""){gl = wdl};break;
  case("Rainfall: last 24 hours"):if(rfl != ""){gl = rfl};break;
  case("Indoor temperature: last 24 hours"):if(itl != ""){gl = itl};break;
  case("Indoor humidity: last 24 hours"):if(ihl != ""){gl = ihl};break;
 }
 if(gl=="n"){gl="&nbsp;&nbsp;"};
 return(gl);
}
function _buildRegGraph(g, doc) {
 var str = "";
 if(shtab==1) str += "<TABLE BORDER=1 CELLPADDING=2 CELLSPACING=0>\n";
 else str += "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
 if(g.title) {
  str += "<TR>\n";
  if(g.scale) str += "<TD COLSPAN=3 HEIGHT=20><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n";
  if(g.yLabel) str += "<TD><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n";
  str += "<TH VALIGN=TOP HEIGHT=20 COLSPAN="+(g.c)+">\n";
  str += "<FONT FACE='"+gtitlefont+"' SIZE="+gtitlesize+" COLOR="+gtitlecolor+">";
  str += _checkgtitle(g.title);
  str += "</FONT></TH></TR>\n";
 }
 if(g.yLabel) {
  g.yLabel = g.yLabel.split(" ");
  g.yLabel = g.yLabel.join("<BR>\n");
  str += "<TR>\n";
  var r = 2; if(g.negMax && g.posMax) r++;
  str += "<TH ROWSPAN="+r+" ALIGN=LEFT WIDTH=20 NOWRAP>\n";
  str += "<FONT FACE='"+gtitlefont+"' SIZE="+gtitlesize+" COLOR="+gtitlecolor+">"+_checkglegend(g.title,g.yLabel)+"</FONT></TD>\n";
 }
 if(g.posMax > 0) {
  if(!g.yLabel) str += "<TR>\n";
  if(g.scale) str += _writeScaleGraph(g, 0, g.posMax);
  str += "<TD VALIGN=BOTTOM width="+(g.hscale+1);
  if(g.bgColor) str += " BGCOLOR=\""+g.bgColor+"\"";
  str += " style='"+tdstyle+"'>";
  var colcount = 1
  for(var j = 0; j < g.rows[0].length; j++) {
   for(var i = 0; i < g.rows.length; i++) {
    if(parseInt(g.vscale*g.rows[i][j]) > 0) {
	 if(g.IsWind && wdgraphline==1){
	  str += "<Table cellpadding=0 cellspacing=0 border=0 height="+parseInt(g.vscale*g.rows[i][j])+" width="+(parseInt(g.hscale)+1)+">";
	  str += "<tr><td valign=top>";
	  str += "<a href=\"#\" title=\""; 
      if(g.legends && g.legends[i]) str += g.legends[i]+": "; 
      str += Math.round((g.rows[i][j]+g.offset)*100)/100;
      if(g.dates) str += ", "+g.dates[j]; 
      str += "\">";
      str += "<IMG BORDER=0 SRC=\""+wdbarimage+"\" ";
      str += "ALT=\"";
      if(g.legends && g.legends[i]) str += g.legends[i]+": ";
      str += Math.round((g.rows[i][j]+g.offset)*100)/100;
      if(g.dates) str += ", "+g.dates[j];
      str += "\" ";
      str += "WIDTH="+parseInt(g.hscale)+" ";
      str += "HEIGHT="+wdglsize+"></a>";
   	  str += "</td></tr></table>";
	 } else {
	  str += "<a href=\"#\" title=\""; 
      if(g.legends && g.legends[i]) str += g.legends[i]+": "; 
      str += Math.round((g.rows[i][j]+g.offset)*100)/100;
      if(g.dates) str += ", "+g.dates[j]; 
      str += "\">";
      if (i==0) { str += "<IMG BORDER=0 SRC=\""+barimage+"\" ";
	  } else { str += "<IMG BORDER=0 SRC=\""+altbarimage+"\" "; }
      str += "ALT=\"";
      if(g.legends && g.legends[i]) str += g.legends[i]+": ";
      str += Math.round((g.rows[i][j]+g.offset)*100)/100;
      if(g.dates) str += ", "+g.dates[j];
      str += "\" ";
      str += "WIDTH="+parseInt(g.hscale)+" ";
      str += "HEIGHT="+parseInt(g.vscale*g.rows[i][j])+" ";
	  str += "></a>"; 
     }
    } else {
     str += "<IMG SRC=clear.gif WIDTH="+parseInt(g.hscale)+" HEIGHT=5 BORDER="+imbrd+">";
    }
	str += "</TD>\n"
	if (colcount < g.rows[0].length*g.rows.length){
	 str += "<TD VALIGN=BOTTOM width="+(g.hscale+1);
     if(g.bgColor) str += " BGCOLOR=\""+g.bgColor+"\"";
     str += " style='"+tdstyle+"'>";
	}	
	colcount ++
   }
  }
  if(j < g.rows[0].length) str += "</TD>\n";
 }
 if(g.scale || g.xScale) {
  if(g.posMax) str += "</TR><TR HEIGHT=1>\n";
  else str += "</TR><TR HEIGHT=1><TD COLSPAN=2 style='"+tdstyle+" height: 1px'><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n";
  str += "<TD VALIGN=BOTTOM ALIGN=LEFT BGCOLOR="+g.backcol+" COLSPAN="+(g.c+1)+" style='"+tdstyle+" height: 1px'>";
  str += "<IMG SRC=tic.gif BORDER="+imbrd+" HEIGHT=1 WIDTH="; 
  str += parseInt(g.rows[0].length*(g.hscale+1)+2)+" BORDER="+imbrd+">";
  str += "</TD></TR>\n";
 }
 if(g.xScale && !g.negMax) str += _writeXScaleGraph(g);
 if(g.negMax < 0) {
  if(g.posMax != 0 && !g.scale) str += "</TR>";
  str += "<TR>\n";
  if(g.scale) str += _writeNegScaleGraph(g, g.negMax, 0);
  str += "<TD VALIGN=TOP width="+(g.hscale+1);
  if(g.bgColor) str += " BGCOLOR=\""+g.bgColor+"\"";
  str += " style='"+tdstyle+"'>";
  var colcount = 1
  for(var j = 0; j < g.rows[0].length; j++) {
   for(var i = 0; i < g.rows.length; i++) {
    if(parseInt(g.vscale*g.rows[i][j]) < 0) {
	 str += "<a href=\"#\" title=\""; 
     if(g.legends && g.legends[i]) str += g.legends[i]+": "; 
     str += Math.round((g.rows[i][j]+g.offset)*100)/100;
     if(g.dates) str += ", "+g.dates[j]; 
     str += "\">";
	 if (i==0) str += "<IMG BORDER=0 ALIGN=TOP SRC="+negbarimage+" WIDTH=";
	 else str += "<IMG BORDER=0 ALIGN=TOP SRC="+altnegbarimage+" WIDTH=";
     str += parseInt(g.hscale)+" HEIGHT=";
     str += parseInt(-1*g.vscale*g.rows[i][j]);
     str += " ALT=\"";
     if(g.legends && g.legends[i]) str += g.legends[i]+": ";
     str += Math.round((g.rows[i][j]+g.offset)*100)/100;
     if(g.dates) str += ", "+g.dates[j];
     str += "\" >";
    } else {
     str += "<IMG SRC=clear.gif ALIGN=TOP BORDER="+imbrd+" WIDTH="+parseInt(g.hscale)+" HEIGHT=5>";
    }
	str += "</TD>\n"
	if(colcount < g.rows[0].length*g.rows.length) {
	 str += "<TD VALIGN=TOP width="+(g.hscale+1);
     if(g.bgColor) str += " BGCOLOR=\""+g.bgColor+"\"";
     str += " style='"+tdstyle+"'>";
	}
	colcount ++
   }
  }
  str += "</TD>\n";
 }
 str += "</TR>\n";
 if(g.warning){
  str += "<tr><td colspan=4><IMG SRC=clear.gif HEIGHT=1 WIDTH=1></td><td COLSPAN="+(g.c)+">\n";
  str += "<table cellpadding=3 cellspacing=0 border=0 width=100%><tr><td>";
  str += "<table cellpadding=3 cellspacing=0 border=1 width=100% bgcolor=#FF0000><tr><th>";
  str += "<FONT FACE='"+gtitlefont+"' SIZE="+gtitlesize+" COLOR=#FFFFFF>";
  str += "'Y' Scale too big to display units!";
  str += "</font></th></tr></table></td></tr></table></td></tr>";
 }
 str += "</TABLE>\n";
 doc.write(str); 
}

function _setXScaleGraph(s, skip, inc) {
 this.xScale = true;
 this.s = s || 0;
 this.skip = skip || 1;
 this.inc = inc || 1;
}

function _setXScaleValuesGraph() {
 this.xScale = true;
 this.s = 0;
 this.skip = 1;
 this.inc = 1;
 this.dates = new Array();
 for(var i = 0; i < arguments.length; i++)
 this.dates[this.dates.length] = arguments[i];
}

function _setStartTimeGraph(hour, min, skip, inc) {
 this.xScale = true;
 this.sTime = new Date(0, 0, 0, hour, min);
 this.skip = skip || 1;
 this.inc = inc || 1;
}
function _setDatesArrayGraph(g) {
 if(g.dates) return;
 g.dates = new Array();
 for(var i = 0; i < g.rows[0].length; i++) {
  var dateStr = "";
  if(g.sDate) {
   if(g.showDay) {
    eval('switch(g.sDate.getDay()) {'+
    'case 0: dateStr += "Sun"; break;'+
    'case 1: dateStr += "Mon"; break;'+
    'case 2: dateStr += "Tue"; break;'+
    'case 3: dateStr += "Wed"; break;'+
    'case 4: dateStr += "Thu"; break;'+
    'case 5: dateStr += "Fri"; break;'+
    'case 6: dateStr += "Sat"; break;'+
    '}'
   )
   dateStr += " ";
  }
  if(g.longDate && g.showDate) {
   dateStr += g.sDate.getDate()+"-";
   eval('switch(g.sDate.getMonth()) {'+
   'case 0: dateStr += "Jan"; break;'+
   'case 1: dateStr += "Feb"; break;'+
   'case 2: dateStr += "Mar"; break;'+
   'case 3: dateStr += "Apr"; break;'+
   'case 4: dateStr += "May"; break;'+
   'case 5: dateStr += "Jun"; break;'+
   'case 6: dateStr += "Jul"; break;'+
   'case 7: dateStr += "Aug"; break;'+
   'case 8: dateStr += "Sep"; break;'+
   'case 9: dateStr += "Oct"; break;'+
   'case 10: dateStr += "Nov"; break;'+
   'case 11: dateStr += "Dec"; break;'+
   '}'
  );
 } else if(g.showDate) dateStr += (g.sDate.getMonth()+1)+"/"+g.sDate.getDate();
  if(g.showYear && g.showDate) {
   if(g.longDate) dateStr += "-";
   else dateStr += "/";
  }
  if(g.showYear) {
   if(g.longYear) dateStr += g.sDate.getFullYear();
   else dateStr += (g.sDate.getFullYear()%100);
  }
  g.sDate.setDate(g.sDate.getDate()+ g.inc);
 } else if(g.sTime) {
  var hrs = g.sTime.getHours();
  if(!g.time24) {
   var pm = false;
   if(hrs == 0) { hrs = 12; }
   else if(hrs >= 12) { if(hrs > 12) hrs -= 12; pm = true; }
  } else 
  if(hrs < 10) hrs = "0" + hrs;
  dateStr = hrs + ":";
  var min = g.sTime.getMinutes();
  if(min < 10) min = "0" + min;
  dateStr += min;
  if(!g.time24) { !pm ? dateStr += "am" : dateStr += "pm" ; }
  g.sTime.setMinutes(g.sTime.getMinutes()+ g.inc); 
 } else dateStr = g.s+i*g.inc;
  g.dates[i] = dateStr;
 }
}
function _writeXScaleGraph(g) {
 var st = "";
 if(!g.c) g.c = g.rows[0].length*2-1;
 st += "<TR>\n";
 if(g.scale) st += "<TD COLSPAN=2><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n";
 if(g.yLabel) st += "<TD><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n";
 st += "<TD VALIGN=TOP ALIGN=LEFT COLSPAN="+(g.c+1)+" style='"+tdstyle+"'>";
 st += "<IMG SRC=tic.gif HEIGHT=10 WIDTH=1 BORDER="+imbrd+">";
 st += "<IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+">";
 var n = g.rows[0].length;
 var mult = g.rows.length;
 for(var i = 0; i < n; i++) {
  st += "<IMG SRC=clear.gif BORDER="+imbrd+" HEIGHT=1 WIDTH="+(g.hscale*mult)+">";
  if((i+1) % g.skip) st += "<IMG SRC=clear.gif HEIGHT=10 WIDTH=1 BORDER="+imbrd+">";
  else st += "<IMG SRC=tic.gif HEIGHT=10 WIDTH=1 BORDER="+imbrd+">";
 }
 st += "</TD></TR><TR>\n";
 if(g.scale) st += "<TD COLSPAN=3><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n";
 if(g.yLabel) st += "<TD><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n";
 var cspan = g.rows.length;
 cspan *= g.skip;
 if(g.sDate || g.sTime) _setDatesArrayGraph(g);
 var t = 0;
 for(var i = 0; i < Math.floor(g.rows[0].length/g.skip); i++) {
  st += "<TD VALIGN=TOP ALIGN=LEFT";
  st += " COLSPAN="+cspan; t += cspan;
  st += "><FONT FACE='"+gaxisfont+"' SIZE="+gaxissize+" COLOR="+gaxiscolor+">";
  st += g.dates[i*g.skip] || "";
  st += "</FONT></TD>\n";
 }
 var len = g.rows[0].length;
 if(i < Math.ceil(g.rows[0].length/g.skip)) {
  st += "<TD VALIGN=TOP";
  st += " COLSPAN="+(len-t);
  st += "><FONT FACE='"+gaxisfont+"' SIZE="+gaxissize+" COLOR="+gaxiscolor+">";
  st += g.dates[i*g.skip];
  st += "</FONT></TD>\n";
 }
 st += "</TR>\n"; 
 return st;
}
function _writeNegScaleGraph(g, min, max) {
 var h = Math.ceil(g.height/(g.posMax-g.negMax)*g.scale);
 var p = -1*g.negMax/(g.posMax-g.negMax);
 var n = Math.floor(g.height*p/h);
 var st = "";
 if(h < 15) {
  st += "<TD><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD><TD><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD><TD><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n"
  return st;
 }
 st += "<TD VALIGN=TOP ALIGN=RIGHT>";
 st += "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD VALIGN=BOTTOM HEIGHT="+h+">";
 for(var i = 0; i < n; i++) {
  st += "<DIV ALIGN=RIGHT><FONT FACE="+gaxisfont+" SIZE="+gaxissize+" COLOR="+gaxiscolor+">"+(g.scale*-1*(i+1)+g.offset)+"</FONT></DIV>";
  if (i<(n-1)) st += "</TD></TR><TR><TD VALIGN=BOTTOM HEIGHT="+h+">";
 }
 st += "</TD></TR></TABLE>";
 st += "</TD>\n";
 st += "<TD VALIGN=TOP ALIGN=RIGHT style='"+tdstyle+"'>";
 for(var i = 0; i < n; i++) {
  st += "<IMG SRC=clear.gif BORDER="+imbrd+" WIDTH=1 HEIGHT="+(h-1)+"><BR>\n";
  st += "<IMG SRC=tic.gif BORDER="+imbrd+" WIDTH=6 HEIGHT=1><BR>\n";
 }
 if(n == 0) st += "<IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+">\n";
 st += "</TD>\n";
 st += "<TD VALIGN=TOP width=2 align=left style='"+tdstyle+"'>";
 st += "<IMG SRC=tic.gif BORDER="+imbrd+" WIDTH=1 HEIGHT="+(g.height*p)+">";
 st += "</TD>\n"
 return st;
}

function _writeScaleGraph(g, min, max) {
 var h;
 var p = g.posMax/(g.posMax-g.negMax);
 h = Math.ceil(g.height/(g.posMax-g.negMax)*g.scale);
 var n = Math.floor(g.height*p/h);
 var st = "";
 if(h < 15) {
  st += "<TD ROWSPAN=2><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD><TD ROWSPAN=2><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD><TD><IMG SRC=clear.gif HEIGHT=1 WIDTH=1 BORDER="+imbrd+"></TD>\n"
  g.warning = 1
  return st;
 }
 st += "<TD VALIGN=BOTTOM ALIGN=RIGHT ROWSPAN=2>";
 st += "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD VALIGN=BOTTOM HEIGHT=15>";
 for(var i = 0; i <= n; i++) {
  label = Math.round((g.scale*(n)-g.scale*i+g.offset)*100)/100
  if(g.IsWind && wdcompass==1){
   switch(label){
    case 0:label="N";break;
    case 45:label="NE";break;
    case 90:label="E";break;
    case 135:label="SE";break;
    case 180:label="S";break;
    case 225:label="SW";break;
    case 270:label="W";break;
    case 315:label="NW";break;
    case 360:label="N";break;
   }
  }
  st += "<DIV ALIGN=RIGHT><FONT FACE="+gaxisfont+" SIZE="+gaxissize+" COLOR="+gaxiscolor+">"+label+"</FONT></DIV>";
  if (i<n) st += "</TD></TR><TR><TD VALIGN=BOTTOM HEIGHT="+h+">";
 }
 st += "</TD></TR></TABLE>";
 st += "</TD>\n";
 st += "<TD VALIGN=BOTTOM ROWSPAN=2 ALIGN=RIGHT style='"+tdstyle+"'>";
 for(var i = 0; i < n; i++) {
  st += "<IMG SRC=tic.gif BORDER="+imbrd+" WIDTH=6 HEIGHT=1></IMG><BR>\n";
  st += "<IMG SRC=clear.gif BORDER="+imbrd+" WIDTH=1 HEIGHT="+(h-1)+"></IMG><BR>\n";
 }
 st += "<IMG SRC=tic.gif BORDER="+imbrd+" WIDTH=6 HEIGHT=1><BR>\n";
 st += "</TD>\n";
 st += "<TD VALIGN=BOTTOM width=2 align=left style='"+tdstyle+"' HEIGHT="+((g.height*p)+15)+">";
 st += "<IMG SRC=tic.gif BORDER="+imbrd+" WIDTH=1 HEIGHT="+(g.height*p)+">";
 st += "</TD>\n"
 return st;
}
function _adjustOffsetGraph(g) {
 for(var i = 0; i < g.rows.length; i++)
 for(var j = 0; j < g.rows[i].length; j++)
 g.rows[i][j] -= g.offset;
}
function _buildGraph(d) {
 doc = d || document;
 if(!this.rows) return;
 if(this.rows.length == 0) {
  doc.write("<TABLE><TR><TD><TT>[empty graph]</TT></TD></TR></TABLE>\n");
  return;
 }
 _adjustOffsetGraph(this);
 if(this.xScale) _setDatesArrayGraph(this);
 _rescaleGraph(this);
 _buildRegGraph(this, doc);
}
