var contactForm;
function InitPage() {
  var contactFormFields = {
                            to : new FormField("to", "hidTo", "text", "To", "string", false, "steve.falzon@tdpg.com", "steve.falzon@tdpg.com"),
                            subject : new FormField("subject", "subject", "text", "Subject", "string", false, "New Homes Contact/Feedback", "New Homes Contact/Feedback"),
											      name : new FormField("name", "name", "text", "Name", "string", false, "your name here", "your name here", ReturnSubmitHandler, null, true),
											      from : new FormField("from", "from", "text", "Email", "string", true, "your email here", "your email here", ReturnSubmitHandler, null, true),
											      telephone : new FormField("telephone", "telephone", "text", "Telephone", "string", false, "your telephone number here", "your telephone number here", ReturnSubmitHandler, null, true),
											      company : new FormField("company", "company", "text", "Company Name", "string", false, "your company name here", "your company name here", ReturnSubmitHandler, null, true),
											      query : new FormField("query", "query", "select", "Query", "string", false, "Site Feedback", "Site Feedback", ReturnSubmitHandler, null, true),
											      other : new FormField("other", "other", "textarea", "Other Query", "string", false, "Anything else you'd like to add here", "Anything else you'd like to add here", ReturnSubmitHandler, null, true),
											      submit : new FormField("submit", "submitForm", "button", "Submit", "string", false, "Send", "Send", function() {SubmitForm();})
                           };
  contactFormFields.from.validator = new FieldValidator(contactFormFields.from, "resultSpan", true, "email", "You must fill in your email address", true, true);
  contactForm = new EmailForm (
                                "NewHomes Contact Form <steve.falzon@tdpg.com>",
                                null,
                                false,
                                "contactFormContainer",
                                contactFormFields,
                                "resultSpan",
                                true
                              );
  contactForm.initialiseFormFields();

  contactForm.sendSuccessHandler = function(response, context) {
                                  if (response.value > 0) {
                                    context.setFormStatusMessage("<h2>Email sent successfully!</h2>");
                                    if(context._hideFormOnSucess == true)
                                      Element.hide(context._formDiv);
                                    context.setFormEnabled(true);
                                  } else {
                                    context.setFormStatusMessage("<h2>Sorry failed to send e-mail!</h2>");
                                    context.setFormEnabled(true);
                                    contactFormFields.submit.initialiseField();
                                  }
                                };
 
}

function ReturnSubmitHandler (e) { 
    if (clearMe(this, contactForm._formFields[this.id].initialValue)) { 
        return submitenter(this, (e || event), SubmitForm); 
    }
    
    return true;
}

function SubmitForm () {
  if (contactForm.validateForm().isValid == true) {
    contactForm.sendMail();
  }
}
