function reset_contact_form()
{
    $('#txtName').val('');
    $('#txtEmail').val('');
    $('#txtCompany').val('');
    $('#txtFirstName').val('');
    $('#txtLastName').val('');
    $('#txtCity').val('');
    $('#txtState').val('');
    $('#txtZip').val('');
    $('#txtCountry').val('');
    $('#txtMessage').val('');
    $('#txtPhone').val('');
    $('#txtAddressOne').val('');
    $('#txtAddressTwo').val('');
}
function contact_us_get_msg()
{
    var msg = '<div class="popup-notice-message">';
    msg += 'Hi,<br />';
    msg += 'Thank you for your interest in PSWS!<br />';
    msg += 'We will read your email as soon as we can and act accordingly.<br />';
    msg += 'You can expect a response within 48hrs.<br />';

    msg += '<br />Best regards,<br />';

    msg += '<br />Pure Safe Water System</div>';
    return msg;
}
$(document).ready(function()
{
    $('#btn-submit-contact-us').click(function(){
        
        var _Data = {};
        _Data.Name = $('#txtName').val();
        _Data.Email = $('#txtEmail').val();
        _Data.Company = $('#txtCompany').val();
        _Data.FirstName = $('#txtFirstName').val();
        _Data.LastName = $('#txtLastName').val();
        _Data.City = $('#txtCity').val();
        _Data.State = $('#txtState').val();
        _Data.Zip = $('#txtZip').val();
        _Data.Country = $('#txtCountry').val();
        _Data.Message = $('#txtMessage').val();
        _Data.Phone = $('#txtPhone').val();
        _Data.AddressOne = $('#txtAddressOne').val();
        _Data.AddressTwo = $('#txtAddressTwo').val();
        _Data.ValidCode = 'hello';

        var _valid = true;
        var rEmail = new RegExp('[a-zA-Z0-9_-]{1,}@[a-zA-Z0-9_-]{1,}\.[a-zA-z]{2,3}');
        var msg = '<div class="popup-notice-error"><b>Error:</b><br /><ol>';
        if(_Data.Email.length == 0 || !_Data.Email.match(rEmail))
        {
            msg +='<li>Email not valid</li>';
            _valid = false;
        }
        if(_Data.Message.length==0)
        {
            msg +='<li>You need to enter message</li>';
            _valid = false;
        }

        if(!_valid)
        {
            msg+='</ol></div>';
            $('#popup_modal').html(msg);
            hbc_popup('popup_modal', '?w=300');
            return false;
        }
        $('#loading-window').css("opacity", 0.8);
        $('#loading-window').fadeIn(150);

        $.post('/contact-us',
            _Data
            , function(data){
                if(data.success)
                {
                    reset_contact_form();
                    $('#popup_modal').html(contact_us_get_msg());
                    hbc_popup('popup_modal', '?w=400');
                }
                else
                {
                    $('#popup_modal').html('<div class="popup-notice-error">Your Email was not sent, please try again later.</div>');
                    hbc_popup('popup_modal', '?w=200&h=100', true);
                }
                $('#loading-window').fadeOut(150);
            }, 'json');
        return false;
    });
});
