function starting_focus()
    {
        if (document.getElementById('first_name'))
            {
                document.download_ebook_form.first_name.focus();
            }
    }

function validate_download_ebook_form()
    {
        if (document.download_ebook_form.first_name.value=="")
            {
                window.alert("Please enter your first name");
                document.download_ebook_form.first_name.focus();
                return false;
            }

        if (document.download_ebook_form.last_name.value=="")
            {
                window.alert("Please enter your last/family name");
                document.download_ebook_form.last_name.focus();
                return false;
            }

        if (document.download_ebook_form.email.value=="")
            {
                window.alert("Please enter your email address");
                document.download_ebook_form.email.focus();
                return false;
            }

        if (document.download_ebook_form.phone_business.value=="")
            {
                window.alert("Please enter your phone number");
                document.download_ebook_form.phone_business.focus();
                return false;
            }

        var emailFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!(emailFilter.test(document.download_ebook_form.email.value)))
            {
                window.alert("Please enter a valid email address.");
                document.download_ebook_form.email.focus();
                return false;
            }
        return true;
    }

function validate_contact_us_message_form()
    {
        if (document.contact_us_message_form.contact_name.value=="")
            {
                window.alert("Please enter your name");
                document.contact_us_message_form.contact_name.focus();
                return false;
            }

        if (document.contact_us_message_form.contact_email.value=="")
            {
                window.alert("Please enter your email address");
                document.download_ebook_form.email.focus();
                return false;
            }

        if (document.contact_us_message_form.contact_subject.value=="")
            {
                window.alert("Please enter a subject for your message");
                document.contact_us_message_form.contact_subject.focus();
                return false;
            }

        if (document.contact_us_message_form.contact_message.value=="")
            {
                window.alert("Please enter a message before submitting");
                document.contact_us_message_form.contact_message.focus();
                return false;
            }


        var emailFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!(emailFilter.test(document.contact_us_message_form.contact_email.value)))
            {
                window.alert("Please enter a valid email address.");
                document.contact_us_message_form.contact_email.focus();
                return false;
            }
        return true;
    }


function validate_create_new_administrator_form()
    {
	if (document.create_new_administrator.name.value=="")
            {
                window.alert("Name cannot be blank");
                document.create_new_administrator.name.focus();
                return false;
            }

        if (document.create_new_administrator.email.value=="")
            {
                window.alert("Please enter email address");
                document.create_new_administrator.email.focus();
                return false;
            }

        if (document.create_new_administrator.password.value!=document.create_new_administrator.password_again.value)
            {
                window.alert("The two passwords do not match");
                document.create_new_administrator.password.focus();
                return false;
            }
	return true;
    }


function validate_administrator_form(theform)
    {
	if (theform.name.value=="")
            {
                window.alert("Name cannot be blank");
                theform.name.focus();
                return false;
            }

        if (theform.email.value=="")
            {
                window.alert("Please enter email address");
                theform.email.focus();
                return false;
            }

        if (theform.password.value!=theform.password_again.value)
            {
                window.alert("The two passwords do not match");
                theform.password.focus();
                return false;
            }
	return true;
    }


function validate_member_form(theform)
    {
	if (theform.first_name.value=="")
            {
                window.alert("First name cannot be blank");
                theform.first_name.focus();
                return false;
            }

        if (theform.last_name.value=="")
            {
                window.alert("Last name cannot be blank");
                theform.last_name.focus();
                return false;
            }

        if (theform.sub_domain.value=="")
            {
                window.alert("Subdomain cannot be blank");
                theform.sub_domain.focus();
                return false;
            }

        var subDomainFilter=/[\W_]/
	if (subDomainFilter.test(theform.sub_domain.value))
            {
                window.alert("Please enter a valid Subdomain.\nThe Subdomain can contain only letters and numbers");
                theform.sub_domain.focus();
                return false;
            }

        if (theform.email.value=="")
            {
                window.alert("Please enter email address");
                theform.email.focus();
                return false;
            }


        if (theform.password.value=="")
            {
                window.alert("Please enter a password");
                theform.password.focus();
                return false;
            }


        if (theform.password.value!=theform.password_again.value)
            {
                window.alert("The two passwords do not match");
                theform.password.focus();
                return false;
            }

	return true;
    }


function validate_unallocated_subscribers(theform)
    {
        if (theform.member_id.value==0)
        {
            window.alert("Please select a member to allocate the selected subscribers to");
            theform.member_id.focus();
            return false;
        }
    return true;
    }

function validate_subscriber_form(theform)
    {
	if (theform.first_name.value=="")
            {
                window.alert("First name cannot be blank");
                theform.first_name.focus();
                return false;
            }

        if (theform.last_name.value=="")
            {
                window.alert("Last name cannot be blank");
                theform.last_name.focus();
                return false;
            }

        if (theform.email.value=="")
            {
                window.alert("Please enter email address");
                theform.email.focus();
                return false;
            }



        if (theform.member_id.value==0)
            {
                window.alert("Please allocate this subscriber to a member");
                theform.member_id.focus();
                return false;
            }

	return true;
    }

function validate_newsletter_form(theform)
    {
	if (theform.newsletter_type_id.value=="0")
            {
                window.alert("Please select the newsletter type");
                theform.newsletter_type_id.focus();
                return false;
            }

        if (theform.title.value=="")
            {
                window.alert("Newsletter title cannot be blank");
                theform.title.focus();
                return false;
            }

        if (theform.interval_for_1st_mail.value<0 || theform.interval_for_1st_mail.value>365)
            {
                window.alert("Please select a valid interval for 1st mail. It must be between 0 and 365");
                theform.interval_for_1st_mail.focus();
                return false;
            }

        if (theform.interval_for_message.value<1 || theform.interval_for_1st_mail.value>365)
            {
                window.alert("Please select a valid interval between mails. It must be between 1 and 365");
                theform.interval_for_message.focus();
                return false;
            }

	return true;
    }


function validate_newsletter_email_form(theform)
    {
	if (theform.subject.value=="")
            {
                window.alert("Please enter a subject for the email");
                theform.subject.focus();
                return false;
            }

	return true;
    }


function validate_contact_group_form(theform)
    {
	if (theform.title.value=="")
            {
                window.alert("Please enter a name for the group");
                theform.title.focus();
                return false;
            }
	return true;
    }

function validate_contact_form(theform)
    {
	if (theform.first_name.value=="")
            {
                window.alert("First name cannot be blank");
                theform.first_name.focus();
                return false;
            }

        if (theform.last_name.value=="")
            {
                window.alert("Last name cannot be blank");
                theform.last_name.focus();
                return false;
            }

        if (theform.email.value=="")
            {
                window.alert("Please enter email address");
                theform.email.focus();
                return false;
            }



        if (theform.member_id.value==0)
            {
                window.alert("Please allocate this subscriber to a member");
                theform.member_id.focus();
                return false;
            }

	return true;
    }

    function do_select_all(theformelement)
            {
            count = theformelement.length;
            if (count)
                {

            for (i=0; i < count; i++)
                    {
                    theformelement[i].checked = 1;
                    }
                }
            else
              theformelement.checked=1;

            }

    function do_invert_selection_all(theformelement)
            {
            count = theformelement.length;
            if (count)
                {
                for (i=0; i < count; i++)
                    {
                        if (theformelement[i].checked==0)
                        theformelement[i].checked=1;
                        else
                        theformelement[i].checked=0
                    }
                }
                else
                    {
                        if (theformelement.checked==0)
                        theformelement.checked=1;
                        else
                        theformelement.checked=0
                    }
            }

    function do_clear_selection_all(theformelement)
            {
            count = theformelement.length;
            if (count)
                {
                for (i=0; i < count; i++)
                    {
                    theformelement[i].checked = 0;
                    }
                }
                else
                theformelement.checked=0
            }


function validate_member_frontend_form(theform)
    {
	if (theform.first_name.value=="")
            {
                window.alert("First name cannot be blank");
                theform.first_name.focus();
                return false;
            }

        if (theform.last_name.value=="")
            {
                window.alert("Last name cannot be blank");
                theform.last_name.focus();
                return false;
            }

        if (theform.sub_domain.value=="")
            {
                window.alert("Subdomain cannot be blank");
                theform.sub_domain.focus();
                return false;
            }


        var subDomainFilter=/[\W_]/
	if (subDomainFilter.test(theform.sub_domain.value))
            {
                window.alert("Please enter a valid Subdomain.\nThe Subdomain can contain only letters and numbers");
                theform.sub_domain.focus();
                return false;
            }


        if (theform.email.value=="")
            {
                window.alert("Please enter email address");
                theform.email.focus();
                return false;
            }


        if (theform.password.value=="")
            {
                window.alert("Please enter a password");
                theform.password.focus();
                return false;
            }


        if (theform.password.value!=theform.password_again.value)
            {
                window.alert("The two passwords do not match");
                theform.password.focus();
                return false;
            }



        if (theform.member_category_id[0].checked==false && theform.member_category_id[1].checked==false)
            {
                window.alert("Please select the member category that you wish to join as");
                theform.member_category_id[1].focus();
                return false;
            }

        if (theform.address_line1.value=="")
            {
                window.alert("Please enter the 1st line of your address");
                theform.address_line1.focus();
                return false;
            }


        if (theform.city.value=="")
            {
                window.alert("Please enter your city");
                theform.city.focus();
                return false;
            }


        if (theform.postcode.value=="")
            {
                window.alert("Please enter your postcode");
                theform.postcode.focus();
                return false;
            }

        if (theform.country.value=="")
            {
                window.alert("Please select a country from the drop down");
                theform.country.focus();
                return false;
            }


        if (theform.phone_business.value=="")
            {
                window.alert("Please enter a business phone number");
                theform.phone_business.focus();
                return false;
            }

	return true;
    }


function validate_event_form(theform)
    {
	if (theform.title.value=="")
            {
                window.alert("Event title cannot be blank");
                theform.title.focus();
                return false;
            }
	return true;
    }
