
/*******************************************************************************
 *                                                                             *
 * time4sleep - code for validating individual forms                           *
 *                                                                             *
 *******************************************************************************/

function checkPriceOption(f)
{
    var formok = true;
    var errmsg = "The following fields are required:\n\n";

    if (f.size.value == "")
    {
        formok = false;
        errmsg += "- Size\n";
    }

    if (f.rrp.value == "")
    {
        formok = false;
        errmsg += "- RRP\n";
    }
    else if (!isNumber(f.rrp.value))
    {
        formok = false;
        errmsg += "- RRP must be numeric\n";
    }

    if (f.our_price.value == "")
    {
        formok = false;
        errmsg += "- Our Price\n";
    }
    else if (!isNumber(f.our_price.value))
    {
        formok = false;
        errmsg += "- Our price must be numeric\n";
    }

    if (!formok)
    {
        errmsg += "\nPlease try again.";
        alert(errmsg);
    }

    return formok;
}

function checkSearch(f)
{
    var formok = true;
    var errmsg = "The following fields are required:\n\n";

    /*
    if (f.fieldname.value == "")
    {
        formok = false;
        errmsg += "- Fieldname\n";
    }
    */

    if (!formok)
    {
        errmsg += "\nPlease try again.";
        alert(errmsg);
    }

    return formok;
}

function setBilling(f)
{
    if (f.make_same.checked == true)
    {
        f.shipping_address1.value = f.billing_address1.value;
        f.shipping_address2.value = f.billing_address2.value;
        f.shipping_address3.value = f.billing_address3.value;
        f.shipping_city.value = f.billing_city.value;
        f.shipping_county.value = f.billing_county.value;
        f.shipping_postcode.value = f.billing_postcode.value;
    }
    else
    {
        f.shipping_address1.value = "";
        f.shipping_address2.value = "";
        f.shipping_address3.value = "";
        f.shipping_city.value = "";
        f.shipping_county.value = "";
        f.shipping_postcode.value = "";
    }

    return;
}

function checkCheckout(f)
{
    // validates checkout form
    var formok = true;
    var errmsg = "The following fields are required:\n\n";

    if (f.forename.value == "" || f.surname.value == "")
    {
        formok = false;
        errmsg += "- Forname and Surname\n";
    }

    if (f.email.value == "")
    {
        formok = false;
        errmsg += "- E-mail Address\n";
    }
    else if (!validateEmail(f.email.value))
    {
        formok = false;
        errmsg += "- Valid E-mail Address\n";
    }

    if (f.daytime_telephone.value == "")
    {
        formok = false;
        errmsg += "- Daytime Telephone\n";
    }

    if (f.billing_address1.value == "")
    {
        formok = false;
        errmsg += "- Shipping Address\n";
    }

    if (f.billing_city.value == "")
    {
        formok = false;
        errmsg += "- Shipping Town/City\n";
    }

    if (f.billing_county.value == "")
    {
        formok = false;
        errmsg += "- Shipping County\n";
    }

    if (f.billing_postcode.value == "")
    {
        formok = false;
        errmsg += "- Shipping Postcode\n";
    }

    if (f.shipping_address1.value == "")
    {
        formok = false;
        errmsg += "- Shipping Address\n";
    }

    if (f.shipping_city.value == "")
    {
        formok = false;
        errmsg += "- Shipping Town/City\n";
    }

    if (f.shipping_county.value == "")
    {
        formok = false;
        errmsg += "- Shipping County\n";
    }

    if (f.shipping_postcode.value == "")
    {
        formok = false;
        errmsg += "- Shipping Postcode\n";
    }

    if (f.agree.checked == false)
    {
        formok = false;
        errmsg += "- You must agree to our Terms and Conditions\n";
    }


    if (!formok)
    {
       errmsg += "\nPlease try again.";
       alert(errmsg);
    }

    return formok;
}

function checkContact(f)
{
    // validates contact form
    var formok = true;
    var errmsg = "The following fields are required:\n\n";

    if (f.contact_name.value == "")
    {
        formok = false;
        errmsg += "- Name\n";
    }

    if (f.contact_email.value == "")
    {
        formok = false;
        errmsg += "- E-mail address\n";
    }
    else if (!validateEmail(f.contact_email.value))
    {
        formok = false;
        errmsg += "- Valid E-mail address required\n";
    }

    if (f.enquiry.value == "")
    {
        formok = false;
        errmsg += "- Enquiry or comment\n";
    }

    if (!formok)
    {
       errmsg += "\nPlease try again.";
       alert(errmsg);
    }

    return formok;
}
