﻿function warp(form) {

    if (form.jumpitem[form.jumpitem.selectedIndex].value == "none") return false;

    window.location = form.jumpitem[form.jumpitem.selectedIndex].value

    return false
}


function cleartotal(form) {
    form.total.value = ""
}

function prc(form) {

    var total_sqft = parseInt(form.width_feet.value) + (form.width_inches.selectedIndex / 12)

    total_sqft *= parseInt(form.height_feet.value) + (form.height_inches.selectedIndex / 12)

    fract_total_sqft = total_sqft - Math.floor(total_sqft)


    if (fract_total_sqft > .5) {
        total_sqft = Math.floor(total_sqft) + 1
    }

    if (fract_total_sqft <= .5) {
        if (fract_total_sqft > .101) {
            total_sqft = Math.floor(total_sqft) + .5
        } else
            total_sqft = Math.floor(total_sqft)
    }



    if (form.state[form.state.selectedIndex].value == "West") {
        if (total_sqft > 0) {
            form.total.value = moneyFormat(total_sqft * "24.56");
        }
        if (total_sqft > 16.5) {
            form.total.value = moneyFormat(total_sqft * "24.18");
        }
        if (total_sqft > 29.5) {
            form.total.value = moneyFormat(total_sqft * "23.86");
        }
        if (total_sqft > 49.5) {
            form.total.value = moneyFormat(total_sqft * "23.54");
        }
        if (total_sqft > 99.5) {
            form.total.value = moneyFormat(total_sqft * "22.74");
        }
        if (total_sqft > 149.5) {
            form.total.value = moneyFormat(total_sqft * "21.84");
        }
        if (total_sqft > 199.5) {
            form.total.value = moneyFormat(total_sqft * "20.90");
        }
    }
    if (form.state[form.state.selectedIndex].value == "East") {
        if (total_sqft > 0) {
            form.total.value = moneyFormat(total_sqft * "22.38");
        }
        if (total_sqft > 16.5) {
            form.total.value = moneyFormat(total_sqft * "21.94");
        }
        if (total_sqft > 29.5) {
            form.total.value = moneyFormat(total_sqft * "21.70");
        }
        if (total_sqft > 49.5) {
            form.total.value = moneyFormat(total_sqft * "21.50");
        }
        if (total_sqft > 99.5) {
            form.total.value = moneyFormat(total_sqft * "20.72");
        }
        if (total_sqft > 149.5) {
            form.total.value = moneyFormat(total_sqft * "19.86");
        }
        if (total_sqft > 199.5) {
            form.total.value = moneyFormat(total_sqft * "19.06");
        }
    }
    if (form.state[form.state.selectedIndex].value == "Non-US") {
        form.total.value = "Call for Quote"
    }
}


function moneyFormat(input) {
    var dollars = Math.floor(input)
    var cents = "" + Math.round(input * 100)
    cents = cents.substring(cents.length - 2, cents.length)
    /* input = dollars + "." + cents  */
    /* return input */

    /*'-----Insert commas in thousands place.*/
    dollarStr = '' + dollars;
    strLength = dollarStr.length;
    position = 1;
    newDollarStr = "";
    while (position < strLength + 1) {
        newDollarStr = dollarStr.substring(strLength - (position - 1), strLength - position) + newDollarStr;
        if (position / 3 == parseInt(position / 3) && (position < strLength)) {
            newDollarStr = "," + newDollarStr;
        }
        position = position + 1
    }
    /*'----- Done inserting commas, Now work on pennies.*/

    pennyStr = cents.substring(0, 2)
    while (pennyStr.length < 2) {
        pennyStr = pennyStr + "0"
    }

    input = "$" + newDollarStr + "." + pennyStr;

    return input
}