
    function validateform( page, isAgent ) {

        validated = 1;

          switch( page ) {

            case "busreg":

                // terms and conditions checkbox
                if ( !document.outform.terms.checked ) {
                    validated = 0;
                    alert ( "You must agree to the terms and conditions to register." );
                } else {
                    // text fields
                    if (    ( document.getElementById('name').value == '' )
                         || ( document.getElementById('firstpass').value.length < 6 )
                         || ( document.getElementById('company').value == '' )
                         || ( document.getElementById('email').value == '' )
                         || ( document.getElementById('phone').value == '' )
                         || ( document.getElementById('address').value == '' )
                         || ( document.getElementById('postcode').value == '' )   )
                    {
                       validated = 0;
                       alert ( "You must fill in all required fields to register." );
                    } else { // business type checkboxes
                        checkerschecked = 0;
                        for ( b=0; b<15; b++ ) {
                            if ( document.getElementById( 'buschecks' + b ).checked ) {
                                checkerschecked = 1;
                            }
                        }
                        if ( checkerschecked == 0 ) {
                            validated = 0;
                            alert ( "You must choose at least one business type to register." );
                        } else { // marker placed check
                            if ( document.getElementById('position').value == '' ) {
                               validated = 0;
                               alert ( "You must locate your business on the map to register." );
                            }
                        }
                    }
                }

            break;

            case "busreg2":

                // terms and conditions checkbox
                if ( !document.outform.terms.checked ) {
                    validated = 0;
                    alert ( "You must agree to the terms and conditions to register." );
                } else {
                    // text fields
                    if (    ( document.getElementById("name").value == "" )
                         || ( document.getElementById("firstpass").value.length < 6 )
                         || ( document.getElementById("company").value == "" )
                         || ( document.getElementById("email").value == "" )
                         || ( document.getElementById("phone").value == "" )
                         || ( document.getElementById("address").value == "" )
                         || ( document.getElementById("postcode").value == "" )   )
                    {
                       validated = 0;
                       alert ( "You must fill in all required fields to register." );
                    }

                    // business type checkboxes
                    else {

                        var checkerschecked = 0;
                        $("#businessCategories input[type=checkbox]").each( function() {
                            console.log( this.id );
                            if ( this.checked == true ) {
                                checkerschecked = 1;
                            }
                        } );

                        if ( checkerschecked == 0 ) {
                            validated = 0;
                            alert ( "You must choose at least one business type to register." );
                        }

                        // marker placed check
                        else {
                            if ( document.getElementById("lat").value == "" ) {
                               validated = 0;
                               alert ( "You must locate your business on the map to register." );
                            }
                        }
                    }
                }

            break;

            case "ownerreg":

                // terms and conditions checkbox
                if ( !document.outform.terms.checked ) {

                    validated = 0;
                    alert ( 'You must agree to the terms and conditions to register.' );

                } else {

                    passChecked = false;
                    if ( isAgent == true ) {
                        passChecked = true;
                    } else {
                        if ( document.getElementById( 'firstpass' ).value.length >= 6 ) {
                            passChecked = true;
                        }
                    }

                    var useAgentMail = false;
                    if ( document.getElementById( 'useAgentMail' ) ) {
                        useAgentMail = document.getElementById('useAgentMail').checked;
                    }

                    var emailOkay = false;
                    if ( ( document.getElementById( 'email' ).value != '' ) || ( useAgentMail == true ) ) {
                        emailOkay = true;
                    }

                    // text / input fields
                    //     || ( handleOkay == false )
                    //     || ( document.getElementById( 'handle' ).value == '' )
                    if (    ( document.getElementById( 'ownername' ).value == '' )
                         || ( passChecked == false )
                         || ( emailOkay == false )
                         || ( emailChecked == false )
                         || ( document.getElementById( 'address' ).value == '' )
                         || ( document.getElementById( 'postcode' ).value == '' )

                         || ( document.getElementById( 'woodname' ).value == '' )
                         || ( document.getElementById( 'mapname' ).value == '' )
                         || ( document.getElementById( 'compname' ).value == '' )
                         || ( document.getElementById( 'grant' ).value == '' )
                         || ( document.getElementById( 'access' ).selectedIndex == 0 )
                       ) {
                        validated = 0;
                        alert ( 'You must fill in all required fields to register.' );
                    } else { // polygon check
                        if ( document.getElementById( 'polyvals' ).value == '' ) {
                            validated = 0;
                            alert ( 'You must locate your woodland on the map to register.' );
                        } else {
                            if ( document.getElementById( 'polyarea' ).value > 1000 ) {
                               validated = 0;
                               alert ( 'Your mapped area is too large. Please check you have marked out your woodland properly.' );
                            }
                        }
                    }
                }

            break;

            case "addcomp":

                // text / input fields
                if (    ( document.getElementById('compname').value == '' )
                     || ( document.getElementById('grant').value == '' )
                     || ( document.getElementById('access').selectedIndex == 0 )    )
                {
                   validated = 0;
                   alert ( "You must fill in all required fields to register." );
                } else { // polygon check
                    if ( document.getElementById( 'polyvals' ).value == '' ) {
                       validated = 0;
                       alert ( "You must locate your woodland on the map." );
                    } else {
                        if ( document.getElementById( 'polyarea' ).value > 500 ) {
                            validated = 0;
                            alert ( 'Your mapped area is too large. Please check you have marked out your woodland properly.' );
                        } else {
                            var gladeSelected = document.getElementById( 'gladeSelector' ).checked;
                            if ( gladeSelected == false ) {
                                if ( checkComposition() != 100 ) {
                                    validated = 0;
                                    alert( 'Please make sure your tree compositions add up to 100% ( making sure you have entered a composition value for each tree )' );
                                }
                            }
                        }
                    }
                }

            break;

            case "agent":

                // terms and conditions checkbox
                if ( !document.outform.terms.checked ) {
                    validated = 0;
                    alert ( "You must agree to the terms and conditions to register." );
                } else {
                    // text fields
                    if (    ( document.getElementById( 'name' ).value == '' )
                         || ( document.getElementById( 'firstpass' ).value.length < 6 )
                         || ( document.getElementById( 'email' ).value == '' )
                         || ( document.getElementById( 'address' ).value == '' )
                         || ( document.getElementById( 'postcode' ).value == '' )   )
                    {
                       validated = 0;
                       alert ( "You must fill in all required fields to register." );
                    }
                }

            break;
          }

          if ( validated == 0 ) {
              return false;
          } else {
              document.outform.submit();
          }
    }

    // checks passwords are minimumm 6 characters
    function passChecker() {
        if ( $("#firstpass").val().length > 5 ) {
            $("#passcheck").html( "<span style='color:green;font-weight:bold;'>Good</span>");
        } else {
            $("#passcheck").html( "<span style='color:red;font-weight:bold;'>minimum 6 characters</span>" );
        }
    }

    // checks both password fields match
    function checkPassMatch() {

        if ( $("#repeatpass").val() != "" ) {
            if ( $("#firstpass").val() != $("#repeatpass").val() ) {
                emailChecked = false;
                $("#passwordAlert").show();
            } else {
                emailChecked = true;
                $("#passwordAlert").hide();
            }
        }
    }


