
function SetInvoiceAddress() {
    if ($('#invoiceaddress').is(':checked'))
    {
        $("#invoiceaddr1").val($("#deliveryaddr1").val());
        $("#invoiceaddr2").val($("#deliveryaddr2").val());
        $("#invoiceaddr3").val($("#deliveryaddr3").val());
        $("#invoicecity").val($("#deliverycity option:selected").text());
        $("#invoicepostcode").val($("#deliverypostcode").val());
    }
    else {
        $("#invoiceaddr1").val("");
        $("#invoiceaddr2").val("");
        $("#invoiceaddr3").val("");
        $("#invoicecity").val("");
        $("#invoicepostcode").val("");
    }

}


// Synchronous Ajax call to retrieve a value
function ValidatePostcode(postcode) {
    var result;
    $.ajax({
        type: "GET",
        url: "ajax.aspx",
        async:false,
        data: { p: 2, postcode: postcode },
        success: function(data) { result = data; }
    });

    return result;
     }



function ValidateApplicationLE(f) {
    
    if (f.email.value == "") {
        alert('Please enter your email address');
        f.email.focus();
        return false;
    }

    else if ((f.firstname.value == "") || (f.lastname.value == "")) {
        alert('Please enter your firstname and lastname');
        return false;
    }

    else if ((f.password.value == "")  || (f.password2.value != f.password.value)) {
        alert('Please choose a password for your account');
        f.password.focus();
        return false;
    }

    else if ((f.deliveryaddr1.value == "") || (f.deliverycity.value == "") || (f.deliverypostcode.value == "")) {
        alert('Please make sure you have entered a valid property address, including a city and postcode\nThe postcode must be within the areas we cover');
        return false;
    }

    else if (ValidatePostcode(f.deliverypostcode.value) == "N") {
        alert('It looks like the postcode of your property is not within the areas we cover, so unfortunately we will not be able to process your application - however you are welcome to send us some details in our Enquiry Form');
        return false;
    }

    else if (f.bedrooms.selectedIndex == 0) {
        alert('Please select the number of bedrooms');
        f.bedrooms.focus();
        return false;
    }

    else if (f.lease_commencement.value == "") {
        alert('Please enter the date that your lease commenced');
        f.lease_commencement.focus();
        return false;
    }

    else if (f.lease_term.selectedIndex == 0) {
        alert('Please select the term of the lease at the commencement date');
        f.lease_term.focus();
        return false;
    }

//    else if (f.requesteddate.selectedIndex == 0) {
//        alert('Please select your chosen inspection time');
//        return false;
//       }


    else if ((f.invoiceaddr1.value == "") || (f.invoicecity.value == "") || (f.invoicepostcode.value == "")) {
        alert('Please make sure you have entered a valid billing address, including a city and postcode');
        return false;
    }


    else if (f.referralsource.selectedIndex == 0) {
        alert('Please tell us how you found out about us');
        f.referralsource.focus();
        return false;
    }

    else if (f.declaration.checked == false) {
        alert('Please confirm you have read our Terms and Conditions');
        f.declaration.focus();
        return false;
    }

    else

        return true;

}


function ValidateApplicationFP1(f) {

    if (f.email.value == "") {
        alert('Please enter your email address');
        f.email.focus();
        return false;
    }

    else if ((f.firstname.value == "") || (f.lastname.value == "")) {
        alert('Please enter your firstname and lastname');
        return false;
    }


    else if ((f.deliveryaddr1.value == "") || (f.deliverycity.value == "") || (f.deliverypostcode.value == "")) {
        alert('Please make sure you have entered a valid property address, including a city and postcode\nThe postcode must be within the areas we cover');
        return false;
    }

    else if (ValidatePostcode(f.deliverypostcode.value) == "N") {
        alert('It looks like the postcode of your property is not within the areas we cover, so unfortunately we will not be able to process your application - however you are welcome to send us some details in our Enquiry Form');
        return false;
    }

/*
    else if (f.referralsource.selectedIndex == 0) {
        alert('Please tell us how you found out about us');
        f.referralsource.focus();
        return false;
    }
*/
    else if (f.declaration.checked == false) {
        alert('Please confirm you have read our Terms and Conditions');
        f.declaration.focus();
        return false;
    }

    else

        return true;

}



function NotifyParticipants(f) {
    if (confirm('Are you sure you want to notify all the participants?')) {
        f.actionx.value = 1;
        f.submit();
        return true;
        }
    else
        return false;
}