$(function() {
		 
    $(".submit-btn").click(function() {
        $("#contact-form").validate({
            rules: {
                tname: {
                    required: true,
                    minlength: 2
                },
                temail: {
                    required: true,
                    email: true
                },
                tpostalcode: {
                    required: true,
                    postalcode: true
                }
            },
            messages: {
                tname: {
                    required: "Name required!",
                    minlength: "Minimum length is 2!"
                },
                temail: {
                    required: "Email required!",
                    email: "Invalid email!"
                },
                tpostalcode: {
                    required: "Postal Code required!",
                    postalcode: "Invalid postal code!"
                }
            },
            errorElement: "div",
            errorPlacement: function(error, element) {
                offset = element.offset();
                error.insertBefore(element)
                error.addClass('message');  // add a class to the wrapper
                error.css('float', 'right');
                error.css('margin-top', '5px');
                //error.css('left', offset.left + element.outerWidth());
                //error.css('top', offset.top);
            },
            submitHandler: function(form) {
                var tEmail = $("input#temail").val();
                var tName = $("input#tname").val();
                var tPostalCode = $("input#tpostalcode").val();	

                var dataString = '&t-email=' + tEmail + '&t-name=' + tName + '&t-postal-code=' + tPostalCode;
                document.getElementById('contact-location').innerHTML = "<img src='http://www.t-zonevibration.com/images/t-zone/ajax-loader.gif' />";
	
                $.ajax({
                    type: "POST",
                    url: "http://www.t-zonevibration.com/scripts/contact.php",
                    data: dataString,
                    success: function() {
                        $('#contact-location').html("<h2>Information Successfully Received!</h2>")
                        .append("<p>We will contact you soon with the closest location based on the information provided.</p>")
                        .hide()
                        .fadeIn(500, function() {
                            //$('#message').append("<img id='checkmark' src='images/check.png' />");
                        });
                    }
                });
            }

        });
    });

    $(".submit-btn-float").click(function() {
        $("#tell-friend").validate({
            rules: {
                semail: {
                    required: true,
                    email: true
                }
            },
            messages: {
                semail: {
                    required: "Required Field!",
                    email: "Invalid Email!"
                }
            },
            submitHandler: function(form) {
                //form.submit();
                var email = $("input#semail").val();
                var dataString = '&email=' + email;
            
                $.ajax({
                    type: "POST",
                    url: "http://www.t-zonevibration.com/scripts/process.php",
                    data: dataString,
                    success: function() {
                        $(".submit-button-float").attr("disabled", "true"); 
                        $('#tell-a-friend').html("<div style='padding: 55px 10px 0 10px;'><h2 style='color: #FFF;'>Email Submitted!</h2><p style='color: #FFF;'>Your friend will be informed momentarily.</p></div>")
                        .hide()
                        .fadeIn(500, function() {
                            //$('#message').append("<img id='checkmark' src='images/check.png' />");
                        });
                    }
                });
            }
        });
    });
    


//2010-12-17 by selenwoo
    $(".submit-contact-btn").click(function() {
        $("#contact-us-form").validate({
            rules: {
                tname: {
                    required: true,
                    minlength: 2
                },
                temail: {
                    required: true,
                    email: true
                }
            },
            messages: {
                tname: {
                    required: "Name required!",
                    minlength: "Minimum length is 2!"
                },
                temail: {
                    required: "Email required!",
                    email: "Invalid email!"
                }
            },
            errorElement: "div",
            errorPlacement: function(error, element) {
                offset = element.offset();
                error.insertBefore(element)
                error.addClass('message');  // add a class to the wrapper
                error.css('float', 'right');
                error.css('margin-top', '5px');
                //error.css('left', offset.left + element.outerWidth());
                //error.css('top', offset.top);
            },
            submitHandler: function(form) {
                var tEmail = $("input#temail").val();
                var tName = $("input#tname").val();
                var tPhone = $("input#tphone").val();
				var tCity =	 $("input#tcity").val();

                var dataString = '&t-email=' + tEmail + '&t-name=' + tName + '&t-phone=' + tPhone+ '&t-city=' + tCity;
                document.getElementById('contact-us').innerHTML = "<img src='http://www.t-zonevibration.com/images/t-zone/ajax-loader.gif' />";
	
                $.ajax({
                    type: "POST",
                    url: "http://www.t-zonevibration.com/scripts/contactus.php",
                    data: dataString,
                    success: function() {
                        $('#contact-us').html("<h2>Information Successfully Received!</h2>")
                        .append("<p>We will contact you soon based on the information provided.</p>")
                        .hide()
                        .fadeIn(500, function() {
                            //$('#message').append("<img id='checkmark' src='images/check.png' />");
                        });
                    }
                });
            }

        });
    });
});
