function set_limit(isform) {
        if (isform.totalblue.value*1+isform.totalgray.value*1+isform.totalwhite.value*1 > isform.totalsalux.value*1){
                isform.totalwhite.value = (isform.totalblue.value*1+isform.totalgray.value*1> isform.totalsalux.value*1)?0:isform.totalsalux.value*1 - isform.totalblue.value*1 - isform.totalgray.value*1;
        }
        if (isform.totalblue.value*1+isform.totalgray.value*1 > isform.totalsalux.value*1){
                isform.totalgray.value = isform.totalsalux.value*1-isform.totalblue.value*1;
        }


        isform.totalblue.length  =isform.totalsalux.value*1+1;
        isform.totalgray.length  =isform.totalsalux.value-isform.totalblue.value*1+1;
        isform.totalwhite.length =isform.totalsalux.value-isform.totalblue.value-isform.totalgray.value*1+1;


        for(i=0;i<isform.totalblue.length;i++){
             isform.totalblue[i].value=isform.totalblue[i].text=i;
        }
        for(i=0;i<isform.totalgray.length;i++){
             isform.totalgray[i].value=isform.totalgray[i].text=i;
        }
        for(i=0;i<isform.totalwhite.length;i++){
             isform.totalwhite[i].value=isform.totalwhite[i].text=i;
        }
}

function validate_form(isform) {
        if(isform.totalsalux.value == 0){
                alert("You have not selected any Salux to buy.");
                return false;
        }
        if(isform.totalwhite.value != isform.totalwhite.length - 1){
                alert("The amount of colors selected does not equal to the amount you would like to purchase!");
                return false;
        }
        if(isform.totalblue.value == 0 && isform.totalgray.value == 0 && isform.totalwhite.value == 0){
                alert("Please reload page or press reset!");
                return false;
        }
        // calculate final total
        document.getElementById('amount').value = isform.totalsalux.value/6*25.5-(isform.totalsalux.value/6-1);
        // calculate name
        document.getElementById('item_name').value = isform.totalsalux.value + " Salux Super Hard Wash Cloths:  " + isform.totalblue.value + " blue, " + isform.totalgray.value + " gray, " + isform.totalwhite.value + " white.";

        return true;
}

function reset_form(isform){
        isform.totalblue.length  =1;
        isform.totalgray.length  =1;
        isform.totalwhite.length =1;
        isform.totalsalux.value ="0";
}