
/******************************************************************************
 *                                                                            *
 * embark- client-side form validation functions                             *
 *                                                                            *
 ******************************************************************************/

/*
function CheckFormTemplate(f)
{
    var formok = true;
    var errmsg = "Please complete the following field(s):\n\n";

    if (f.fieldname.value == "")
    {
        formok = false;
        errmsg += "- Company Name\n";
    }

    if (!formok)
    {
        errmsg += "\nPlease try again.";
        alert(errmsg);
    }

    return formok;
}
*/



/********************************** customer details **********************************/

function checkNewsletterForm(f)
{
    // checks registration form
    errors = "The following errors have been found: \n\n";
    valid = true;

      
   if (f.email.value == "")
    {
        errors +="- Email address must be completed.\n";
         valid = false;
    }
    else if (!validateEmail(f.email.value))
    {
        errors +="- Valid Email address must be completed.\n";
         valid = false;
    }
    

    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
        return false;
    }
    else
    {
        return true;
    }
}

function checkCustomerDetails(f)
{
    // checks registration form
    errors = "The following errors have been found: \n\n";
    valid = true;

    if (f.contact_name.value == "")
    {
        errors += "- Contact name must be completed.\n";
        valid = false;
    }
  
   if (f.email.value == "")
    {
        errors +="- Email address must be completed.\n";
         valid = false;
    }
    else if (!validateEmail(f.email.value))
    {
        errors +="- Valid Email address must be completed.\n";
         valid = false;
    }
    

    if (f.password.value == "" || f.passwordc.value == "")
    {
         errors += "- Password and password confirmation must be completed.\n";
         valid = false;
    }
    else
    {
        if (f.password.value != f.passwordc.value)
        {
            errors += "- Password and password confirmation do not match.\n";
            valid = false;
        }
        else if (f.password.value.length < 6)
        {
            errors += "- Password must be at least 6 characters in length.\n";
            valid = false;
        }
    }

    if (f.billing_line1.value == "")
    {
        errors += "- Billing address must be completed.\n";
        valid = false;
    }

    if (f.billing_town.value == "")
    {
        errors += "- Billing town must be completed.\n";
        valid = false;
    }

    if (f.billing_postcode.value == "")
    {
        errors += "- Billing postcode must be completed.\n";
        valid = false;
    }


    if (f.shipping_line1.value == "")
    {
        errors += "- Shipping address must be completed.\n";
        valid = false;
    }

    if (f.shipping_town.value == "")
    {
        errors += "- Shipping town must be completed.\n";
        valid = false;
    }

    if (f.shipping_postcode.value == "")
    {
        errors += "- Shipping postcode must be completed.\n";
        valid = false;
    }

    if (f.tel.value == "")
    {
        errors += "- Telephone must be completed.\n";
        valid = false;
    }

    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
        return false;
    }
    else
    {
        return true;
    }
}

function checkEnquiry(f)
{
    var formok = true;
    var errmsg = "Please complete the following field(s):\n\n";

    if (f.firstname.value == "")
    {
        formok = false;
        errmsg += "- Firstname\n";
    }

    if (f.surname.value == "")
    {
        formok = false;
        errmsg += "- Surname\n";
    }

    if (f.email.value == "")
    {
        formok = false;
        errmsg += "- Email address\n";
    }
    if (f.telephone.value == "")
    {
        formok = false;
        errmsg += "- Telephone Number\n";
    }
    else if (!validateEmail(f.email.value))
    {
        formok = false;
        errmsg += "- Valid Email address required\n";
    }

    if (f.enquiry.value == "")
    {
        formok = false;
        errmsg += "- Enquiry\n";
    }

    if (!formok)
    {
        errmsg += "\nPlease try again.";
        alert(errmsg);
    }

    return formok;
}


function sendNewsletter(f)
{

	errors = "The following errors have been found: \n\n";
	valid = true;
	
    if (f.email.value == "")
    {
        errors += "- email must be completed.\n";
        valid = false;
    }
    else
    {
    	email_errors = validateEmail(f.email.value);
    	if(email_errors != "")
    	{
    		errors += email_errors;
    		valid = false;
    	}
    }
    
    if(valid)
    {
    	f.submit();
    }
    else
    {
         errors += "\nPlease try again";
        alert(errors);   
    }
}

function copyAddress(f)
{
    f.shipping_line1.value = f.billing_line1.value;
    f.shipping_line2.value = f.billing_line2.value;
    f.shipping_line3.value = f.billing_line3.value;
    f.shipping_town.value = f.billing_town.value;
    f.shipping_county.value = f.billing_county.value;
    f.shipping_postcode.value = f.billing_postcode.value;
    f.shipping_country_id.value = f.billing_country_id.value;
}

function checkConfirmOrder(f)
{
    var agree_terms = f.agree_terms.checked;

    if (agree_terms)
    {
        f.submit();
    }
    else
    {
        alert("You must agree to our Terms and Conditions to proceed");
    }
}

/*************************** check out ****************************/

function checkCheckout(f)
{

    // checks registration form
    errors = "The following errors have been found: \n\n";
    valid = true;

    if (f.contact_name.value == "")
    {
        errors += "- Contact Name must be completed.\n";
        valid = false;
    }
    
    if (f.email.value == "")
    {
        errors +="- Email address must be completed.\n";
         valid = false;
    }
    else if (!validateEmail(f.email.value))
    {
        errors +="- Valid Email address must be completed.\n";
         valid = false;
    }
    
    if(f.tel.value == "" )
    {
     errors += "- Telephone number must be completed.\n";
    }
    
    if (f.billing_line1.value == "")
    {
        errors += "- Billing address must be completed.\n";
        valid = false;
    }

    if (f.billing_town.value == "")
    {
        errors += "- Billing town must be completed.\n";
        valid = false;
    }

    if (f.billing_postcode.value == "")
    {
        errors += "- Billing postcode must be completed.\n";
        valid = false;
    }
    
    if (f.billing_country_id.value == "")
    {
        errors += "- Billing country must be completed.\n";
        valid = false;
    }

    if (f.shipping_line1.value == "")
    {
        errors += "- Shipping address must be completed.\n";
        valid = false;
    }

    if (f.shipping_town.value == "")
    {
        errors += "- Shipping town must be completed.\n";
        valid = false;
    }

    if (f.shipping_postcode.value == "")
    {
        errors += "- Shipping postcode must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_country_id.value == "")
    {
        errors += "- Shipping country must be completed.\n";
        valid = false;
    }

    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
        return false;
    }
    else
    {
        return true;
    }

}

function changeDelivery(url,s)
{
	var nxt_day = s[s.selectedIndex].value;
	url += "?del_type="  +  nxt_day;
	
	document.location.href=url;
}

function checkFilePage(f)
{
    formok = true;
    errmsg = "The following fields are required:\n\n";


    if (f.display_text.value == "")
    {
        formok = false;
        errmsg += "- Display Text\n";
    }

   
    if (!formok)
    {
        errmsg += "\nPlease try again.";
        alert(errmsg);
    }

    return formok;
}

