var mygraphmontharray=new Array('Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь');

function  mygraph(x,y,width,height,minx,miny,maxx,maxy,month,aareacolor,awindow){
if (awindow.closed==false){
this.graphwindow=awindow;
this.xposition=x;
this.yposition=y;
this.minx=minx;
this.miny=miny;
this.maxx=maxx;
this.maxy=maxy;
this.textx='День';
this.texty='Балл';
this.text=mygraphmontharray[month-1];
this.areacolor=aareacolor;
this.dx=20;
this.dy=25;
this.ddy=40;
this.ddx=20;
this.width=width;
this.height=height;
this.grapharray=new Array();

this.putpixel=putpixel;
this.putrect=putrect;
this.puttext=puttext;
this.putline=putline;
this.positionnull=positionnull;
this.drawpole=drawpole;
this.drawgrapharray=drawgrapharray;
positionnull();
}
}

function drawgrapharray(grapharray){
if (this.graphwindow.closed==false){
if (grapharray.length>0){
for (var i=0;i<grapharray.length;i++){
if (i<this.maxx){
if (grapharray[i]>=0){color='#0066ff';}
else{color='#ff0066';}
var text=''+grapharray[i];

putrect(this.nullx+Math.floor(this.deltax*(i+1))-3,this.nully-Math.floor(this.deltay*grapharray[i]),this.nullx+Math.floor(this.deltax*(i+1))+5,this.nully,color,text);
}
}
}
}
}


function positionnull(){
if (this.graphwindow.closed==false){
var s='';
if (Math.abs(this.maxy)>=Math.abs(this.miny)){
s=s+Math.abs(this.maxy);}
else {
s=s+Math.abs(this.miny);}
if ((this.maxy>=0)&&(this.miny>=0)){this.miny=0};
if ((this.maxy<=0)&&(this.miny<=0)){this.maxy=0};
this.deltay=(this.height-this.dy-this.ddy)/(this.maxy-this.miny);
this.nully=Math.floor(this.deltay*this.maxy)+this.dy;
this.nullx=this.dx+(s.length+1)*10;
this.deltax=(this.width-this.dx-this.ddx-this.nullx)/(this.maxx-this.minx);
var N=Math.abs(this.maxy-this.miny);
var A=Math.abs(N)/Math.exp(Math.round(Math.log(Math.abs(N))/Math.log(10))*Math.log(10));
if (A>=1){
 this.B=0.5*Math.exp(Math.round(Math.log(Math.abs(N))/Math.log(10))*Math.log(10))}
else {
 this.B=0.1*Math.exp(Math.round(Math.log(Math.abs(N))/Math.log(10))*Math.log(10));}
}
}




function drawpole(){
if (this.graphwindow.closed==false){
this.graphwindow.document.write('<div id=GraphArea align='+'"'+'center'+'"'+' style="position: ABSOLUTE;border-width: 2px;border-style: ridge;background-color: '+this.areacolor+'; width: '+this.width+'px; height: '+this.height+'px; left: '+this.xposition+'px; top: '+this.yposition+'px; z-index: 10;font-size: 1pt"></div>');
putline(this.nullx-10,this.nully,this.dx+(this.width-this.dx-this.ddx),this.nully,'#000000');
for (var i=0;i<=this.maxx;i++){
putline(this.nullx+Math.floor(this.deltax*i),this.nully-3,this.nullx+Math.floor(this.deltax*i),this.nully+5,'#000000');
}
var st='';
for (var i=1;i<=this.maxx;i=i+2){
st='';
st=st+i;
puttext(this.nullx+Math.floor(this.deltax*i-st.length*8/2+2),this.height-this.ddy,st,'#000000',10);
}
putline(this.nullx,this.dy,this.nullx,this.dy+(this.height-this.dy-this.ddy),'#000000');
this.graphwindow.document.write('<div style="position: ABSOLUTE;border-width: 2px;border-style: ridge;background-color: #ffffff; width: '+Math.floor(this.text.length*14)+'px; height: 22px; left: '+Math.floor((this.width-this.nullx-this.ddx)/2-this.text.length/2*14+this.nullx+this.xposition-7)+'px; top: '+Math.floor(this.yposition+2)+'px; z-index: 10;font-size: 1pt"></div>');
puttext(Math.floor((this.width-this.nullx-this.ddx)/2-this.text.length/2*14+this.nullx),2,this.text,'#003399',14);
puttext(Math.floor((this.width-this.nullx-this.ddx)/2-this.textx.length/2*10+this.nullx),this.height-24,this.textx,'#000000',14);
var s='';
for (var i=0;i<=10;i++){
s='';
if (this.B*(i+1)+0<this.maxy){
putline(this.nullx-5,this.nully-Math.floor(this.deltay*(this.B*(i+1)+0)),this.nullx+5,this.nully-Math.floor(this.deltay*(this.B*(i+1)+0)),'#000000');
s=s+Math.round(this.B*(i+1)+0);
puttext(this.nullx-Math.floor(s.length*6+s.length),this.nully-Math.floor(this.deltay*(this.B*(i+1)+0)),s,'#000000',10);
}
s='';
if (-this.B*(i+1)+0>this.miny){
putline(this.nullx-5,this.nully-Math.floor(this.deltay*(-this.B*(i+1)+0)),this.nullx+5,this.nully-Math.floor(this.deltay*(-this.B*(i+1)+0)),'#000000');
s=s+Math.round(-this.B*(i+1)+0);
puttext(this.nullx-Math.floor(s.length*6),this.nully-Math.floor(this.deltay*(-this.B*(i+1)+0)),s,'#000000',10);
}
}
for (var i=0;i<=this.texty.length;i++){
puttext(4,Math.floor((this.height-this.dy-this.ddy)/2-this.texty.length/2*14+this.dy)+i*14,this.texty.charAt(i),'#000000',14);
}
}
}



function putpixel(x,y,color){
if (this.graphwindow.closed==false){
var posx=x+this.xposition;
var posy=y+this.yposition;
this.graphwindow.document.write('<div style="position: ABSOLUTE; background-color: '+color+'; width: 1px; height: 1px; left: '+posx+'px; top: '+posy+'px; z-index: 10;font-size: 1pt"></div>');
}
}



function putrect(x1,y1,x2,y2,color,text){
if (this.graphwindow.closed==false){
var x=0;
var y=0;
var width=0;
var height=0;
if (x1>x2){x=x1;x1=x2;x2=x;};
if (y1>y2){y=y1;y1=y2;y2=y;};
width=x2-x1;
height=y2-y1;
var posx=x1+this.xposition;
var posy=y1+this.yposition;
if (text==''){this.graphwindow.document.write('<div style="position: ABSOLUTE; background-color: '+color+'; width: '+width+'px; height: '+height+'px; left: '+posx+'px; top: '+posy+'px; z-index: 10;font-size: 1pt"></div>');}
else {this.graphwindow.document.write('<div style="position: ABSOLUTE; background-color: '+color+'; width: '+width+'px; height: '+height+'px; left: '+posx+'px; top: '+posy+'px; z-index: 10;font-size: 1pt" title='+'"'+text+'"></div>');};
}
}



function puttext(x,y,text,color,size){
if (this.graphwindow.closed==false){
var posx=x+this.xposition;
var posy=y+this.yposition;
var mytext='';
if (size==10){this.graphwindow.document.write('<div style='+'"'+'position: ABSOLUTE;height: '+size+'px; left: '+posx+'px; top: '+posy+'px; z-index: 10;font-size: '+size+'pt'+'"'+'><p'+' style:'+'"'+'font-size: '+size+'pt;'+' margin-top: 0pt; margin-bottom: 0pt; margin-left: 0pt; font-size: 8pt;'+'"'+'><font color='+'"'+color+'"'+' style:'+'"'+'font-size: '+size+'pt;'+'"'+'>'+text+'</font></p></div>');}
else {this.graphwindow.document.write('<div style='+'"'+'position: ABSOLUTE;height: '+size+'px; left: '+posx+'px; top: '+posy+'px; z-index: 10;font-size: '+size+'pt'+'"'+'><p'+' style:'+'"'+'font-size: '+size+'pt;'+' margin-top: 0pt; margin-bottom: 0pt; margin-left: 0pt; font-size: 14pt; font-weight: bold;'+'"'+'><font color='+'"'+color+'"'+' style:'+'"'+'font-size: '+size+'pt;'+'"'+'>'+text+'</font></p></div>');};
}
}



function putline(x1,y1,x2,y2,color){
if (this.graphwindow.closed==false){
var I=0;
var J=0;
var T=0;
var Mx=0;
var My=0;
var HMy=0;
var HMx=0;
var width=0;
var height=0;
if (x1>x2){x=x1;x1=x2;x2=x;};
if (y1>y2){y=y1;y1=y2;y2=y;};
width=x2-x1;
height=y2-y1;
var posx=x1+this.xposition;
var posy=y1+this.yposition;
if (x1==x2) 
   {
    this.graphwindow.document.write('<div style="position: ABSOLUTE; background-color: '+color+'; width: 1px; height: '+height+'px; left: '+posx+'px; top: '+posy+'px; z-index: 10;font-size: 1pt"></div>');
   }
else 
   {
    if (y1==y2) 
       {
        this.graphwindow.document.write('<div style="position: ABSOLUTE; background-color: '+color+'; width: '+width+'px; height: 1px; left: '+posx+'px; top: '+posy+'px; z-index: 10;font-size: 1pt"></div>');
       }
}
}
}

