﻿/*
$(document).ready(function () {
    $('#BusinessDevelopmentCancelSend').click(function () {
        $(".contact_details").hide("slow");
        $(".contact_form_main").hide("slow");
        $(".title_contacts").show("slow");
        $("#SurveyorsListAndMap").show("slow");
    });
})
*/
function hideContactForm(hide) {
    if (!hide) {
        $(".contact_details").show("slow");
        $(".contact_form_main").show("slow");
        $(".title_contacts").hide("slow");
        $("#SurveyorsListAndMap").hide("slow");
    } else {
        $(".contact_details").hide("slow");
        $(".contact_form_main").hide("slow");
        $(".title_contacts").show("slow");
        $("#SurveyorsListAndMap").show("slow");
    }
}

$(document).ready(function () {
    $('#BusinessDevelopmentSubmit').click(function () {

        // Validate Email 

        var email = $("#enqEmail").val();
        if (!IsValidEmail(email)) {
            $('#enqEmail').focus();
            return false;
        }

        var phone = $("#enqPhone").val();
        if (!IsValidTelephone(phone)) {
            $('#enqPhone').focus();
            return false;
        }

        var msg = $("#enqMessage").val();
        if (msg.length == 0) {
            alert("Please enter a message");
            $('#enqMessage').focus();
            return false;
        }
        slideContact();

        var div_focus = document.getElementById('div_focus').value;
        div_focus = "." + div_focus;
        $(div_focus).slideToggle("slow");
        $(".loader_contact").slideToggle("slow");

        var arForm = $("#BusinessDevelopmentForm").serializeArray();
        $.ajax({
            type: 'POST',
            url: '/FormInput/BusinessDevelopment',
            data: arForm,
            success: function (result) {

                //do something with the response

                $(".loader_contact").show("slow");

                if (result == "true") {
                    $(".contact_results").show("slow");
                    $(".loader_contact").hide("slow");
                    document.getElementById('enq_contact_message').innerHTML = "Thank you for your enquiry. We will be in touch shortly.<br/><br/>";
                    $("#enqName").val("");
                    $("#enqEmail").val("");
                    $("#enqPhone").val("");
                    $("#enqMessage").val("");
                    $("#enqCompany").val("");
                    $("#enqPostCode").val("");
                } else {
                    $(".contact_results").show("slow");
                    $(".loader_contact").hide("slow");
                    document.getElementById('enq_contact_message').innerHTML = "Oops there's been a problem with our systems, your message has not been sent.</br></br> <img src=\"../../Content/Images/template/button-cancel.gif\" onclick=\"clearContact();\" alt=\"Cancel\" width=\"190\" height=\"17\">";
                }

            },
            error: function (req, status, error) {
                alert("Sorry! We could not process your request at this time, please try again" +
                        " If the problem persists please contact CVS Customer Support on: 0161 291 0330");
            }
        });
    });
})

$(document).ready(function () {
    $('#CalculatorEquiryFormSubmit').click(function () {

        var name = $("#ceName").val();
        if (name.length == 0) {
            $('#ceName').focus();
            alert("Please enter a contact name");
            return false;
        }

        var phone = $("#cePhone").val();
        if (!IsValidTelephone(phone)) {
            $('#cePhone').focus();
            return false;
        }

        var email = $("#ceEmail").val();
        if (!IsValidEmail(email)) {
            $('#ceEmail').focus();
            return false;
        }

        togglevis('slideLoader', 'block', 'visible');
        slideContact();

        $(".business_rates_loader").slideToggle("slow");

        var arForm = $("#CalculatorEquiryForm").serializeArray();
        $.ajax({
            type: 'POST',
            url: '/FormInput/RatesAppeal',
            data: arForm,
            success: function (result) {

                //do something with the response

                $(".loader_contact").show("slow");

                if (result == "true") {

                    $(".contact_results").show("slow");
                    $(".business_rates_loader").hide("slow");

                    document.getElementById('calc_contact_message').innerHTML = "Thank you for your enquiry. We will be in touch shortly.<br/><br/>";
                    $("#ceName").val("");
                    $("#cePhone").val("");
                    $("#ceEmail").val("");
                    $("#enqMessage").val("");
                } else {

                    //alert("email failed");

                    $(".contact_results").show("slow");
                    $(".loader_contact").hide("slow");

                    document.getElementById('calc_contact_message').innerHTML = "Oops there's been a problem with our systems, your message has not been sent.</br></br> <img src=\"../../Content/Images/template/button-cancel.gif\" onclick=\"clearContact();\" alt=\"Cancel\" width=\"190\" height=\"17\">";


                }

            },
            error: function (req, status, error) {
                alert("Sorry! We could not process your request at this time, please try again" +
                        " If the problem persists please contact CVS Customer Support on: 0161 291 0330");
            }
        });
    });
})

$(document).ready(function () {
    $('#CalculatorPageEnquirySubmit').click(function () {

        var name = $("#cpeName").val();
        if (name.length == 0) {
            $('#cpeName').focus();
            alert("Please enter a contact name");
            return false;
        }

        var phone = $("#cpePhone").val();
        if (!IsValidTelephone(phone)) {
            $('#cpePhone').focus();
            return false;
        }

        var email = $("#cpeEmail").val();
        if (!IsValidEmail(email)) {
            $('#cpeEmail').focus();
            return false;
        }

        togglevis('slideLoader', 'block', 'visible');
        slideContact();

        $(".loader_contact").slideToggle("slow");

        var arForm = $("#CalculatorPageEnquiryForm").serializeArray();
        $.ajax({
            type: 'POST',
            url: '/FormInput/RatesAppeal',
            data: arForm,
            success: function (result) {

                //do something with the response

                $(".loader_contact").show("slow");

                if (result == "true") {

                    // alert("email sent");

                    $(".contact_results").show("slow");
                    $(".loader_contact").hide("slow");
                    document.getElementById('calcpages_contact_message').innerHTML = "Thank you for your enquiry. We will be in touch shortly.<br/><br/>";
                    $("#cpeName").val("");
                    $("#cpePhone").val("");
                    $("#cpeEmail").val("");
                } else {
                    $(".contact_results").show("slow");
                    $(".loader_contact").hide("slow");
                    document.getElementById('calcpages_contact_message').innerHTML = "Oops there's been a problem with our systems, your message has not been sent.</br></br> <img src=\"../../Content/Images/template/button-cancel.gif\" onclick=\"clearContact();\" alt=\"Cancel\" width=\"190\" height=\"17\">";
                }
            },
            error: function (req, status, error) {
                alert("Sorry! We could not process your request at this time, please try again" +
                        " If the problem persists please contact CVS Customer Support on: 0161 291 0330");
            }
        });
    });
})

$(document).ready(function () {
    $('#AffiliatesFormSubmit').click(function () {

        var name = $("#AffName").val();
        if (name.length == 0) {
            alert("Please enter a contact name");
            $('#AffName').focus();
            return false;
        }

        var phone = $("#AffPhone").val();
        if (!IsValidTelephone(phone)) {
            $('#AffPhone').focus();
            return false;
        }

        var email = $("#AffEmail").val();
        if (!IsValidEmail(email)) {
            $('#AffEmail').focus();
            return false;
        }

        submitForm('AffiliatesForm', 'loader_side');

        var arForm = $("#AffiliatesForm").serializeArray();
        $.ajax({
            type: 'POST',
            url: '/FormInput/Affiliates',
            data: arForm,
            success: function (result) {

                //do something with the response
                $(".loader_contact").show("slow");
                if (result == "true") {
                    $(".contact_results").show("slow");
                    $(".loader_side").hide("slow");
                    document.getElementById('aff_contact_message').innerHTML = "Thank you for your enquiry. We will be in touch shortly.<br/><br/>";
                    $("#AffName").val("");
                    $("#AffCompany").val("");
                    $("#AffPhone").val("");
                    $("#AffEmail").val("");
                    $("#AffAddress").val("");
                } else {
                    $(".contact_results").show("slow");
                    $(".loader_contact").hide("slow");
                    document.getElementById('aff_contact_message').innerHTML = "Oops there's been a problem with our systems, your message has not been sent.</br></br> <img src=\"../../Content/Images/template/button-cancel.gif\" onclick=\"clearContact();\" alt=\"Cancel\" width=\"190\" height=\"17\">";
                }
            },
            error: function (req, status, error) {
                alert("Sorry! We could not process your request at this time, please try again" +
                        " If the problem persists please contact CVS Customer Support on: 0161 291 0330");
            }
        });
    });
})
