/*===========================================================================
	Behavior
	
	This JavaScript executes dynamic behaviors such as:
	* Preloading images
	* Flash Replacements (i.e. sIFR, UFO, SWFObject, etc.)
	* Decorate the DOM with presentational elements
	* Collapsing/expanding sections
	* Form validation
	* Popup windows
===========================================================================*/

/* Contact Us - Form Validation
===========================================================================*/
if (typeof jQuery != 'undefined') {
    $(document).ready(function() {
        $("#contact-form").submit(function() {
            // Reset border colors
            $(this).find("fieldset input").css("border", "1px solid #fff");
            var error = "";

            // Check name
            var name = $("input#name").val();

            if (name == null || name == "") {
                error += "Please enter your name \n";
                $("input#name").css("border", "1px solid red");
            }

            // Check email		
            var email = $("input#email").val();

            if (email == null || email == "") {
                // email address was not entered
                error += "Please enter your email address \n";
                $("input#email").css("border", "1px solid red");
            } else {
                // check for email address validity
                apos = email.indexOf("@");
                dotpos = email.indexOf(".");
                if (apos < 1 || dotpos - apos < 2) {
                    error += "Please enter a valid email address \n";
                    $("input#email").css("border", "1px solid red");
                }
            }

            // Check phone number
            var phone = $("input#phone").val();

            if (phone == null || phone == "") {
                // phone number was not entered
                error += "Please enter your phone number \n";
                $("input#phone").css("border", "1px solid red");
            } else {
                // check for phone number validity
                var stripped = phone.replace(/[\(\)\.\-\ ]/g, '');
                if (isNaN(parseInt(stripped))) {
                    error += "Please enter a valid phone number";
                    $("input#phone").css("border", "1px solid red");
                }
            }

            if (error) {
                alert(error);
                return false;
            } else {
                return true
            }
        });

        //Featured planes pager
        $(".featuredPager a").click(function(i) {
            var whatElem = $(this).attr("rel");
            $(".featuredPager a").removeClass("active");
            $(this).addClass("active");
            $("#featuredPlanes .pages").hide();

            $('#featuredPlanes #page-' + whatElem + '').show();
        });
        if (jQuery().cycle) {
            $('#hero').cycle({
                timeout: 5000,
                pause: 1
            });
        }
    });
}
