var sum=0;
var height=0;
var timerlen=100;
var endheight=0;
var preheight=0;
var chaarr=new Array('green','blue','gray','red');
var perarr=new Array('green1','blue1','gray1','red1')
var vals=new Array();
function findPosX(obj)
{
        var curleft = 0;
        if (obj.offsetParent)
        {
        while (obj.offsetParent)
        {
        curleft += obj.offsetLeft
        obj = obj.offsetParent;
        }
      }
  else if (obj.x)
        curleft += obj.x;
  return curleft;
}
function findPosY(obj)
{
        var curtop = 0;
        if (obj.offsetParent)
        {
        while (obj.offsetParent)
                {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
                }
        }
        else if (obj.y)
                curtop += obj.y;
        return curtop;
}

function calculate_height()
{
  document.getElementById('green').style.height=0;
  document.getElementById('blue').style.height=0;
  document.getElementById('gray').style.height=0;
  document.getElementById('red').style.height=0;

  var img1=parseInt(document.getElementById("text1").value);
  var img2=parseInt(document.getElementById("text2").value);
  var img3=parseInt(document.getElementById("text3").value);
  var img4=parseInt(document.getElementById("text4").value);
  sum=img1+img2+img3+img4;
  vals[0]=img1;
  vals[1]=img2;
  vals[2]=img3;
  vals[3]=img4;
 height=parseInt(document.getElementById("tabhei").style.height);
  var p1=Math.round((img1/sum)*height);
  var p2=Math.round((img2/sum)*height);
  var p3=Math.round((img3/sum)*height);
  var p4=Math.round((img4/sum)*height);

  var dd=document.getElementById('main');
  var ddleft=findPosX(dd);
  var ddtop=findPosY(dd);

  var ff=document.getElementById('span1');
  ff.style.top=ddtop-(p1+11); 
  ff.style.left=ddleft+4;
  ff.innerHTML=p1;

  var gg=document.getElementById('span2');
  gg.style.top=ddtop-(p2+11); 
  gg.style.left=ddleft+23;
  gg.innerHTML=p2;

  var gg=document.getElementById('span3');
  gg.style.top=ddtop-(p3+11); 
  gg.style.left=ddleft+43;
  gg.innerHTML=p3;

  var hh=document.getElementById('span4');
  hh.style.top=ddtop-(p4+11); 
  hh.style.left=ddleft+60;
  hh.innerHTML=p4;   

  for(var i=0;i<vals.length;i++)
  {
      chartAnimation(chaarr[i],vals[i]);
  }
    
}
function chartAnimation(iid, hei)
{
     var ele=document.getElementById(iid);
       
             endheight=Math.round((hei/sum)*height);
             if(ele){

                  preheight = parseInt(ele.style.height);
                  preheight = preheight+2;
                  ele.style.height = preheight+"px";
                  preheight=parseInt(ele.style.height);
                  if(preheight < endheight)
                  {
                   setTimeout("chartAnimation('"+iid+"',"+hei+")",timerlen);
                  }
         }
}

function ctck()
{
var sds = document.getElementById("dum");
if(sds == null){alert("You are using a free package.\n You are not allowed to remove the tag.\n");}
var sdss = document.getElementById("dumdiv");
if(sdss == null){alert("You are using a free package.\n You are not allowed to remove the tag.\n");}
}


