/* Created by jankoatwarpspeed.com */

(function($) {
    $.fn.formToWizard = function(options) {
        options = $.extend({  
            submitButton: "" 
        }, options); 
        
        var element = this;

        var steps = $(element).find("fieldset");
        var count = steps.size();
        var submmitButtonName = "#" + options.submitButton;
        $(submmitButtonName).hide();

        // 2


        steps.each(function(i) {
            $(this).wrap("<div id='step" + i + "'></div>");
            $(this).append("<p id='step" + i + "commands'></p>");

            // 2
            var name = $(this).find("legend").html();

            if (i == 0) {
                createNextButton(i);
                selectStep(i);
            }
            else if (i == count - 1) {
                $("#step" + i).hide();
                createPrevButton(i);
            }
            else {
                $("#step" + i).hide();
                createPrevButton(i);
                createNextButton(i);
            }
        });

        function createPrevButton(i) {
            var stepName = "step" + i;
            $("#" + stepName + "commands").append("<a href='#back' id='" + stepName + "Prev' class='prev'>< Back</a>");

            $("#" + stepName + "Prev").bind("click", function(e) {
                $("#" + stepName).hide();
                $("#step" + (i - 1)).show();
                $(submmitButtonName).hide();
                selectStep(i - 1);
            });
        }

        function createNextButton(i) {
            var stepName = "step" + i;
            $("#" + stepName + "commands").append("<a href='#next' id='" + stepName + "Next' class='next button'>Next ></a>");
            $("#" + stepName + "Next").bind("click", function(e) {
	$('.error').hide();
  	  var name = $("input#Name1").val();
  		if (name == "Name" || "") {
        $("label#name_error").show();
		$("input#Name1").focus();
        return false;
      }
	  var email = $("input#Email1").val();
  		if (email == "Email" || "") {
        $("label#email_error").show();
		$("input#Email1").focus();
        return false;
      }
                $("#" + stepName).hide();
                $("#step" + (i + 1)).show();
                if (i + 2 == count)
                    $(submmitButtonName).show();
                selectStep(i + 1);
            });
        }

        function selectStep(i) {
            $("#steps li").removeClass("current");
            $("#stepDesc" + i).addClass("current");
        }

    }
})(jQuery); 
  $(function() {
    $('.error').hide();
    $(".send").click(function() {					  
  	  var name = $("input#Name1").val();
	  var email = $("input#Email1").val();
	  var phone = $("input#Phone").val();
	  var subject = $("input#Subject").val();
	  var additional = $("textarea#Additional").val();
	  var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone+ '&subject=' + subject+ '&additional=' + additional;  
  $.ajax({
    type: "POST",
    url: "../contact-us/process.php",
    data: dataString,
    success: function() {
      $('#wizard').html("<div id='message'></div>");
      $('#message').html("<h3>Contact Form Submitted!</h3>")
      .append("<p>We will be in touch soon.</p>")
      .hide()
      .fadeIn(1500, function() {
        $('#message').append("<img src='../img/contact/check.jpg' alt='Form Submitted' />");
      });
    }
  });
  return false;
  

    });
  });
  
