$(document).ready(function()
{

    $(function()
    {
        if (typeof GoogleMapShow == 'function')
        {
            GoogleMapShow();
        }

        $('#txtcbname, #txtcbemail, #txtcbphone').focus( function ()
        {
            var v = $(this).val();
            var t = $(this).attr('title');
            if (v == t)
            {
                $(this).val('');
            }
        });
        $('#txtcbname, #txtcbemail, #txtcbphone').blur( function ()
        {
            var v = $(this).val();
            var t = $(this).attr('title');
            if (v === '')
            {
                $(this).val(t);
            }
        });
        
        $('#callback').submit( function()
        {
            var boolValid = true;
            if (boolValid === true && ($('#txtcbname').val() == $('#txtcbname').attr('title') || $('#txtcbname').val() === ""))
            {
                boolValid = false;
                alert("Please enter your name");
                $('#txtcbname').focus();
            }
            if (boolValid === true && ($('#txtcbemail').val() == $('#txtcbemail').attr('title') || $('#txtcbemail').val() === ""))
            {
                boolValid = false;
                alert("Please enter your email address");
                $('#txtcbemail').focus();
            }
            if (boolValid === true && ($('#txtcbphone').val() == $('#txtcbphone').attr('title') || $('#txtcbphone').val() === ""))
            {
                boolValid = false;
                alert("Please enter your phone number");
                $('#txtcbphone').focus();
            }
            return boolValid;
        });
        
        $('#contactform').submit( function()
        {
            var boolValid = true;
            if (boolValid === true && ($('#txtfirstname').val() === ""))
            {
                boolValid = false;
                alert("Please enter your first name");
                $('#txtfirstname').focus();
            }
            if (boolValid === true && ($('#txtemail').val() === "" && $('#txttelephone').val() === ""))
            {
                boolValid = false;
                alert("Please enter your telephone number or email address");
                $('#txttelephone').focus();
            }
            if (boolValid === true && ($('#txtemail').val() !== ""))
            {
                var e = $('#txtemail').val();
                var regEmail = new RegExp(/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)+)@(([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)){2,}\.([A-Za-z]){2,4}$/gim);
                if (regEmail.test(e) === false)
                {
                    boolValid = false;
                    alert("Please enter a valid email address");
                    $('#txtemail').focus();
                }
            }
            
            
            if (boolValid === true && ($('#txtcomments').val() === '' || $('#txtcomments').val().length < 2))
            {
                boolValid = false;
                alert("Please enter your feedback");
                $('#txtcomments').focus();
            }
            
            return boolValid;
        });
    });
});
