
function setError(id)
{
    $(id).css("color", "red");
}

function validateForm()
{
    $(".callback").css("color", "black");

    var has_error = false;
    tel = $("#telephone").val()
    if (tel == "") {
        has_error = true;
        setError('#telephone_error');
    }
    tel = tel.replace(/ /g, "");
    $('#telephone').val(tel);

    if ($("#firstname").val() == '') {
        has_error = true;
        setError('#firstname_error');
    }

    if ($("#surname").val() == '') {
        has_error = true;
        setError('#surname_error');
    }

    if ($('#delay').val() == '999')
    {
        has_error = true;
        setError('#delay_error');

    }

    if (has_error) {
        return false;
    } else {
        return true;
    }
}


function callBack() 
{
    $("#error_msg").hide();
    if (validateForm()) {
        $.post("/scripts/a_callback.php", $('#callback_form').serialize());
		$("#error_msg").show();
        $("#error_msg").html("Thank you for requesting a call back. We will contact you shortly.</b>");
		$("#firstname").attr("value","");
		$("#surname").attr("value","");
		$("#telephone").attr("value","");
		$("#delay").attr("value","999");

        //$('#applynow').html(' <p class="applynow"><a href="apply-now/"><img src="applybutt.jpg" alt="Apply Now" border="0" /></a></p> <p>Thank you for requesting a call back. We will contact you shortly.</p>');
    } else {
        $("#error_msg").show();
        $("#error_msg").html("Please enter the missing information highlighted in red");
    }
    return false;
}
