function calculation(){
  var a = parseInt(document.one.first.value);
  if (parseInt(document.zero.nums.value)<6) {a=0}
  var b = parseInt(document.one.second.value);
  if (parseInt(document.zero.nums.value)<5) {b=0}
  var c = parseInt(document.one.third.value);
  if (parseInt(document.zero.nums.value)<4) {c=0}
  var d = parseInt(document.one.fourth.value);
  if (parseInt(document.zero.nums.value)<3) {d=0}
  var e = parseInt(document.one.fifth.value);
  if (parseInt(document.zero.nums.value)<2) {e=0}
  var f = parseInt(document.one.sixth.value);
  var ra = a;
  var rb = b-a;
  var rc = c-b;
  var rd = d-c;
  var re = e-d;
  var rf = f-e;
  document.one.first.value=ra;
  document.one.second.value=rb;
  document.one.third.value=rc;
  document.one.fourth.value=rd;
  document.one.fifth.value=re;
  document.one.sixth.value=rf;
  if(parseInt(document.zero.nums.value)<6) {document.one.first.value=" "}
  if(parseInt(document.zero.nums.value)<5) {document.one.second.value=" "}
  if(parseInt(document.zero.nums.value)<4) {document.one.third.value=" "}
  if(parseInt(document.zero.nums.value)<3) {document.one.fourth.value=" "}
  if(parseInt(document.zero.nums.value)<2) {document.one.fifth.value=" "}

}

function calculation2(){
   var a = parseInt(document.one.first.value);
   if (parseInt(document.zero.nums.value)<6) {a=0}
   var b = parseInt(document.one.second.value);
   if (parseInt(document.zero.nums.value)<5) {b=0}
   var c = parseInt(document.one.third.value);
   if (parseInt(document.zero.nums.value)<4) {c=0}
   var d = parseInt(document.one.fourth.value);
   if (parseInt(document.zero.nums.value)<3) {d=0}
   var e = parseInt(document.one.fifth.value);
   if (parseInt(document.zero.nums.value)<2) {e=0}
   var f = parseInt(document.one.sixth.value);
   var ra = a;
   var rb = ra+b;
   var rc = rb+c;
   var rd = rc+d;
   var re = rd+e;
   var rf = re+f;
   document.one.first.value=ra;
   document.one.second.value=rb;
   document.one.third.value=rc;
   document.one.fourth.value=rd;
   document.one.fifth.value=re;
   document.one.sixth.value=rf;
   if(parseInt(document.zero.nums.value)<6) {document.one.first.value=" "}
   if(parseInt(document.zero.nums.value)<5) {document.one.second.value=" "}
   if(parseInt(document.zero.nums.value)<4) {document.one.third.value=" "}
   if(parseInt(document.zero.nums.value)<3) {document.one.fourth.value=" "}
   if(parseInt(document.zero.nums.value)<2) {document.one.fifth.value=" "}
}

function clr(){
   document.one.first.value="";
   document.one.second.value="";
   document.one.third.value="";
   document.one.fourth.value="";
   document.one.fifth.value="";
   document.one.sixth.value="";
}

function odr(){
   var x=0
   var p = parseInt(document.one.first.value);
   if (parseInt(document.zero.nums.value)<6) {p=0}
   var q = parseInt(document.one.second.value);
   if (parseInt(document.zero.nums.value)<5) {q=0}
   var r = parseInt(document.one.third.value);
   if (parseInt(document.zero.nums.value)<4) {r=0}
   var s = parseInt(document.one.fourth.value);
   if (parseInt(document.zero.nums.value)<3) {s=0}
   var t = parseInt(document.one.fifth.value);
   if (parseInt(document.zero.nums.value)<2) {t=0}
   var u = parseInt(document.one.sixth.value);
   while(x<5){ 
     // bubble sort
     var a = p - q;
     a += (Math.abs(a) - a) / 2;
     p -= a;
     q += a;
     var b = q - r;
     b += (Math.abs(b) - b) / 2;
     q -= b;
     r += b;
     var c = r - s;
     c += (Math.abs(c) - c) / 2;
     r -= c;
     s += c;
     var d = s - t;
     d += (Math.abs(d) - d) / 2;
     s -= d;
     t += d;
     var e = t - u;
     e += (Math.abs(e) - e) / 2;
     t -= e;
     u += e;
     x++
   }
   document.one.first.value = p;
   document.one.second.value = q;
   document.one.third.value = r;
   document.one.fourth.value = s;
   document.one.fifth.value = t;
   document.one.sixth.value = u;
   if(parseInt(document.zero.nums.value)<6) {document.one.first.value=" "}
   if(parseInt(document.zero.nums.value)<5) {document.one.second.value=" "}
   if(parseInt(document.zero.nums.value)<4) {document.one.third.value=" "}
   if(parseInt(document.zero.nums.value)<3) {document.one.fourth.value=" "}
   if(parseInt(document.zero.nums.value)<2) {document.one.fifth.value=" "}
}

function mixup(){
//enigma style shuffling
var p = parseInt(document.one.first.value);
if(parseInt(document.zero.nums.value)<6) {p=0}
var q = parseInt(document.one.second.value);
if(parseInt(document.zero.nums.value)<5) {q=0}
var r = parseInt(document.one.third.value);
if(parseInt(document.zero.nums.value)<4) {r=0}
var s = parseInt(document.one.fourth.value);
if(parseInt(document.zero.nums.value)<3) {s=0}
var t = parseInt(document.one.fifth.value);
if(parseInt(document.zero.nums.value)<2) {t=0}
var u = parseInt(document.one.sixth.value);
var x=0
while(x<100){
  var m=Math.random()
  if(m < .33){
    var a=r
    var b=t
    var c=q
    var d=u
    var e=s
    var f=p
    p=a
    q=b
    r=c
    s=d
    t=e
    u=f
  }
  var m=Math.random()
  if(m < .33){
    var a=s
    var b=u
    var c=p
    var d=q
    var e=r
    var f=t
    p=a
    q=b
    r=c
    s=d
    t=e
    u=f
  }
  var m=Math.random()
  if(m < .33){
    var a=t
    var b=p
    var c=r
    var d=s
    var e=u
    var f=q
    p=a
    q=b
    r=c
    s=d
    t=e
    u=f
  }
  var m=Math.random()
  if(m < .33){
    var a=p
    var b=s
    var c=u
    var d=t
    var e=q
    var f=r
    p=a
    q=b
    r=c
    s=d
    t=e
    u=f
  }
  var m=Math.random()
  if(m < .33){
    var a=t
    var b=r
    var c=u
    var d=q
    var e=s
    var f=p
    p=a
    q=b
    r=c
    s=d
    t=e
    u=f
  }
 x++
 }
 if (q==0) {q=p;p=0}
 if (r==0) {r=p;p=0}
 if (r==0) {r=q;q=0}
 if (s==0) {s=p;p=0}
 if (s==0) {s=q;q=0}
 if (s==0) {s=r;r=0}
 if (t==0) {t=p;p=0}
 if (t==0) {t=q;q=0}
 if (t==0) {t=r;r=0}
 if (u==0) {u=p;p=0}
 if (u==0) {u=q;q=0}
 if (u==0) {u=r;r=0}
 document.one.first.value = p;
 document.one.second.value = q;
 document.one.third.value = r;
 document.one.fourth.value = s;
 document.one.fifth.value = t;
 document.one.sixth.value = u;
 if(parseInt(document.zero.nums.value)<6) {document.one.first.value=" "}
 if(parseInt(document.zero.nums.value)<5) {document.one.second.value=" "}
 if(parseInt(document.zero.nums.value)<4) {document.one.third.value=" "}
 if(parseInt(document.zero.nums.value)<3) {document.one.fourth.value=" "}
 if(parseInt(document.zero.nums.value)<2) {document.one.fifth.value=" "}
}

function pickit(){
  var w = parseInt(document.zero.max.value)
  var z = w * .70
  var y=0
  while(y==0){
    document.one.first.value = Math.round(Math.random() * w);
    document.one.second.value = Math.round(Math.random() * w);
    document.one.third.value = Math.round(Math.random() * w);
    document.one.fourth.value = Math.round(Math.random() * w);
    document.one.fifth.value = Math.round(Math.random() * w);
    document.one.sixth.value = Math.round(Math.random() * w);
    if (parseInt(document.zero.nums.value)>2){
     odr()
     calculation()
     odr()
     y=1
     if(parseInt(document.one.first.value)>1 && parseInt(document.zero.nums.value)>5){
       y=0
     }
     if(parseInt(document.one.first.value)<1 && parseInt(document.zero.nums.value)>5){
       y=0
     }
     if(parseInt(document.one.second.value)<1 && parseInt(document.zero.nums.value)>4){
       y=0
     }
     if(parseInt(document.one.third.value)<1 && parseInt(document.zero.nums.value)>3){
       y=0
     }
     if(parseInt(document.one.sixth.value)>(w/3) && parseInt(document.zero.nums.value)>3){
       y=0
     }
     mixup()
     calculation2()
     if(parseInt(document.one.sixth.value)<z && parseInt(document.zero.nums.value)>3){
       y=0
     } }
    if(parseInt(document.zero.nums.value)<3){
    y=1
    odr()
    if( parseInt(document.one.sixth.value)==parseInt(document.one.fifth.value)){y=0}
    }
    if(parseInt(document.zero.nums.value)<6) {document.one.first.value=" "}
    if(parseInt(document.zero.nums.value)<5) {document.one.second.value=" "}
    if(parseInt(document.zero.nums.value)<4) {document.one.third.value=" "}
    if(parseInt(document.zero.nums.value)<3) {document.one.fourth.value=" "}
    if(parseInt(document.zero.nums.value)<2) {document.one.fifth.value=" "}
  }  
}