$( document ).ready( function() {
    //--------------------------------------------------------------------------------------------
    $("#tabs").tabs({
        show: function(event, ui) {
            //--------------------------------------------------------------------------------------------
            $("#accordionReleaseNotes").accordion({
                autoHeight: false
            });
            $("#accordionFAQ").accordion({
                autoHeight: false
            });

            //--------------------------------------------------------------------------------------------
			$('#contactForm').submit(function() {
				$(".error").hide();
				var hasError = false;
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				
				var emailFromVal = $("#name").val();
				if(emailFromVal == '') {
					$("#noname").css("display","block");
					hasError = true;
				} else{
					$("#noname").css("display","none");
				}
		
				var emailToVal = $("#eemail").val();
				if(emailToVal == '') {
					$("#noemail").css("display","block");
					hasError = true;
				} else if(!emailReg.test(emailToVal)) {	
					$("#noemail").css("display","none");
					$("#bademail").css("display","block");
					hasError = true;
				}else{
					$("#noemail").css("display","none");
					$("#bademail").css("display","none");
				}
				
				var messageVal = $("#message").val();
				if(messageVal == '') {
					$("#nomessage").css("display","block");
					hasError = true;
				}else{
					$("#nomessage").css("display","none");				
				}
		
				if(hasError == false) {
					var inputs = [];
					$(':input', this).each(function() {
						inputs.push(this.name + '=' + escape(this.value));
					})
					$.ajax({
						data: inputs.join('&'),
						url: this.action,
						timeout: 2000,
						error: function() {
							console.log("Failed to submit");
							// dont alert, just show a div to say the message was NOT posted and enable the post button
						},
						success: function(r) { 
							alert(r);
							// dont alert, just show a div to say the message was posted and disable the post button
						}
					}) 			  
				}
				// by default - we'll always return false so it doesn't redirect the user.
				return false;
			})
            //--------------------------------------------------------------------------------------------
        }
    });
});

