function validate()
{
    if (!isNaturalNumber(document.byc.c, " for the current price."))
    {
        return false;
    }

    if (!isNaturalNumber(document.byc.p, " for the Par value."))
    {
        return false;
    }

    if (!isValueInRange(document.byc.r, 1, 100, " for the Coupon rate."))
    {
        return false;
    }

    if (!isNaturalNumber(document.byc.n, " for the Years to maturity."))
    {
        return false;
    }

    return true;
}

function calc1()
{
    var c = document.byc.c.value;
    var p = document.byc.p.value;
    var r = (document.byc.r.value) / 100;
    var n = document.byc.n.value;
    var y1 = document.byc.ytm.value;
    var cy = document.byc.cy.value
    var y = parseFloat(((p * r) + (p - c) / n) / (0.4 * p + 0.6 * c));
    y1 = y * 100;
    cy = parseFloat((p * r) / c);
    document.byc.cy.value = round(cy * 100, 2);
    document.byc.ytm.value = round(y1, 2);

    if(document.byc.cy.value < document.byc.r.value)
    {
        document.byc.bs.value = "Premium";
    }
    else if(document.byc.cy.value > document.byc.r.value)
    {
        document.byc.bs.value = "Discount";
    }
    else if(document.byc.cy.value == document.byc.r.value)
    {
        document.byc.bs.value = "Par value";
    }
}

function clean()
{
    document.byc.c.value = "";
    document.byc.p.value = "";
    document.byc.r.value = "";
    document.byc.n.value = "";
    document.byc.ytm.value = "";
    document.byc.cy.value = "";
    document.byc.bs.value = "";
}
