// Copyright  ©1999-2003 Simple Joe, Inc., All rights reserved.

// Visit http://www.simpejoe.com for information on purchasing and using this and other JavaScript calculators.
// Custom calculators can be created upon request.  Reasonable pricing; low one-time fees; no subscriptions, 
// renewals, or traffic-based charges.

function sortInsertSort(arr, length) {var j, i, v;for (i=1, j=i, v=arr[i]; i<length; arr[j+1]=v, i++, j=i, v=arr[i])while (j-- >= 0 && arr[j] > v)arr[j+1]=arr[j];} function sortQuickSortSub(arr, first, last) {var i, j, m, p, temp, lim=8, lim1=lim + 1;while (first>=0) {i=first - 1; j=last;m = Math.floor(first + (last-first)/2);if (arr[m] < arr[first]) {temp=arr[m];arr[m]=arr[first];arr[first]=temp;}if (arr[last] < arr[m]) {temp=arr[m];arr[m]=arr[last];arr[last]=temp;}if (arr[m] < arr[first]) {temp=arr[m];arr[m]=arr[first];arr[first]=temp;}p = arr[m];while (++i < j)if (arr[i] > p)while (arr[j] > p && --j > i)if(j > i) {temp=arr[j];arr[j]=arr[i];arr[i]=temp;}if (--i - first > last - i - 1) {if (last > i + lim1)sortQuickSortSub(arr, i + 1, last);if (i > first + lim)last=i;elsefirst=-1; } else {if( i > first + lim)sortQuickSortSub(arr, first, i);if( last > i + lim1)first=i+1;elsefirst=-1; } } } function sortQuickSort(arr, length) {sortQuickSortSub(arr, 0, length - 1);sortInsertSort(arr, length);} function sort2dInsertSort(arr, length, element) {if (element==null) element=0;var j, i, v;for (i=1, j=i, v=arr[i][element], a=arr[i]; i<length; arr[j+1]=a, i++, j=i, v=arr[Math.min(i,length-1)][element], a=arr[Math.min(i,length-1)])while (j-->=0 && j>=0 && arr[j][element]>v)arr[j+1]=arr[j];} function sort2dQuickSortSub(arr, first, last, element) {if (element==null) element=0;var i, j, m, p, temp, lim=8, lim1=lim + 1;while (first>=0) {i = first - 1;j = last;m = Math.floor(first + (last-first)/2);if (arr[m][element] < arr[first][element]){temp=arr[m];arr[m]=arr[first];arr[first]=temp;}if (arr[last][element] < arr[m][element]) {temp=arr[m];arr[m]=arr[last];arr[last]=temp;}if (arr[m][element] < arr[first][element]) {temp=arr[m];arr[m]=arr[first];arr[first]=temp;}p = arr[m][element];while (++i < j)if (arr[i][element] > p)while (arr[j][element] > p && --j > i)if ( j > i) {temp=arr[j];arr[j]=arr[i];arr[i]=temp;} if (--i - first > last - i - 1) {if (last > i + lim1)sort2dQuickSortSub(arr, i + 1, last, element);if (i > first + lim)last=i;elsefirst=-1; } else {if (i > first + lim)sort2dQuickSortSub(arr, first, i, element);if (last > i + lim1)first=i+1;elsefirst=-1; } } } function sort2dQuickSort(arr, length, element) {if (element==null) element=0;sort2dQuickSortSub(arr, 0, length - 1, element);sort2dInsertSort(arr, length, element);} 