function calcmix(form,index)
  // calculation of mixing cross
  // version 1, Sep. 2007, BCK
  // copyright, Cactus2000
{
  var ls = new Array(6);
  var indalt,inum;
  var d1,d2;
  ls[0]=parseInt(form.last1.value);
  ls[1]=parseInt(form.last2.value);
  ls[2]=parseInt(form.last3.value);
  ls[3]=parseInt(form.last4.value);
  ls[4]=parseInt(form.last5.value);
  ls[5]=parseInt(form.last6.value);

  if(index!=-1) {
    indalt = ls[index];
    for (var i=0; i<6; i++) {
      if (ls[i] < indalt) { ls[i]++; }}
    ls[index] = 0;

    inum=0;
    if (ls[0]<4) {inum++;}
    if (ls[1]<4) {inum++;}
    if (ls[2]<4) {inum++;}
    if (ls[3]<4) {inum++;}
    if (ls[4]<4) {inum++;}
    if (ls[5]<4) {inum++;}
    
    form.last1.value = ls[0];
    form.last2.value = ls[1];
    form.last3.value = ls[2];
    form.last4.value = ls[3];
    form.last5.value = ls[4];
    form.last6.value = ls[5];
  }
  a1 = parseFloat(form.c1.value); if(index==0) {if(!isFinite(a1) || a1<0) {warnings(1); return;}}
  a2 = parseFloat(form.c2.value); if(index==1) {if(!isFinite(a2) || a2<0) {warnings(1); return;}}
  a3 = parseFloat(form.cx.value); if(index==2) {if(!isFinite(a3) || a3<0) {warnings(1); return;}}
  b1 = parseFloat(form.m1.value); if(index==3) {if(!isFinite(b1) || b1<=0) {warnings(1); return;}}
  b2 = parseFloat(form.m2.value); if(index==4) {if(!isFinite(b2) || b2<=0) {warnings(1); return;}}
  b3 = parseFloat(form.mx.value); if(index==5) {if(!isFinite(b3) || b3<=0) {warnings(1); return;}}

  if (ls[0]<4 && ls[1]<4 && ls[2]<4) {
    if( !((a1<=a3 && a3<=a2) || (a1>=a3 && a3>=a2))) {warnings(2);return;}
    d1 = Math.abs( a2 - a3);
    d2 = Math.abs( a1 - a3);
    form.t1.value = ausga(form,d1);
    form.t2.value = ausga(form,d2);
    if (ls[3]<4) {
      b2 = b1 * d2 / d1;
      b3 = b1 + b2; }
    if (ls[4]<4) {
      b1 = b2 * d1 / d2;
      b3 = b1 + b2; }
    if (ls[5]<4) {
      b1 = b3 / (1. + d2/d1);
      b2 = b3 / (1. + d1/d2); }
    if (ls[3]<4 || ls[4]<4 || ls[5]<4) {
      form.m1.value = ausga(form,b1);
      form.m2.value = ausga(form,b2);
      form.mx.value = ausga(form,b3); }
  }
  else {
    if (ls[3]<4 && ls[4]<4) {
      b3 = b1 + b2;
      form.mx.value = ausga(form,b3); }
    if (ls[3]<4 && ls[5]<4) {
      if(b3 < b1) {warnings(2);return;}
      b2 = b3 - b1;
      form.m2.value = ausga(form,b2); }
    if (ls[4]<4 && ls[5]<4) {
      if(b3 < b2)  {warnings(2);return;}
      b1 = b3 - b2;
      form.m1.value = ausga(form,b1); }
    if (inum>=4) {
      if (ls[0]<4 && ls[1]<4) {
	a3 = (a1*b1 + a2*b2) / b3;
	form.cx.value = ausga(form,a3); }
      if (ls[0]<4 && ls[2]<4) {
	a2 = (a3*b3 - a1*b1) / b2;
	form.c2.value = ausga(form,a2); }
      if (ls[1]<4 && ls[2]<4) {
	a1 = (a3*b3 - a2*b2) / b1;
	form.c1.value = ausga(form,a1); }
      d1 = Math.abs( a2 - a3);
      d2 = Math.abs( a1 - a3);
      form.t1.value = ausga(form,d1);
      form.t2.value = ausga(form,d2);}
  }

  if (inum>=4) {
    if(ls[0]<4) document.getElementsByName('c1')[0].style.backgroundColor = '#F0FFF0';
    else document.getElementsByName('c1')[0].style.backgroundColor = '#FFF0F5';
    if(ls[1]<4) document.getElementsByName('c2')[0].style.backgroundColor = '#F0FFF0';
    else document.getElementsByName('c2')[0].style.backgroundColor = '#FFF0F5';
    if(ls[2]<4) document.getElementsByName('cx')[0].style.backgroundColor = '#F0FFF0';
    else document.getElementsByName('cx')[0].style.backgroundColor = '#FFF0F5';
    if(ls[3]<4) document.getElementsByName('m1')[0].style.backgroundColor = '#F0FFF0';
    else document.getElementsByName('m1')[0].style.backgroundColor = '#FFF0F5';
    if(ls[4]<4) document.getElementsByName('m2')[0].style.backgroundColor = '#F0FFF0';
    else document.getElementsByName('m2')[0].style.backgroundColor = '#FFF0F5';
    if(ls[5]<4) document.getElementsByName('mx')[0].style.backgroundColor = '#F0FFF0';
    else document.getElementsByName('mx')[0].style.backgroundColor = '#FFF0F5'; }

  return;
}
function backmix(form)
  // resets the display of mixing cross calculator
  // version 1, Sep. 2007, BCK
  // copyright, Cactus2000
{
  document.getElementsByName('c1')[0].style.backgroundColor = '#FFFFF0';
  document.getElementsByName('c2')[0].style.backgroundColor = '#FFFFF0';
  document.getElementsByName('cx')[0].style.backgroundColor = '#FFFFF0';
  document.getElementsByName('m1')[0].style.backgroundColor = '#FFFFF0';
  document.getElementsByName('m2')[0].style.backgroundColor = '#FFFFF0';
  document.getElementsByName('mx')[0].style.backgroundColor = '#FFFFF0';
  form.last1.value = 6;
  form.last2.value = 6;
  form.last3.value = 6;
  form.last4.value = 6;
  form.last5.value = 6;
  form.last6.value = 6;
  return;
}
