/*
 * validate zip code form
 * 
 */

$(document).ready(function(){
	$("#step-1-form").mouseover(function(){
		createTooltips();
	});
	//$("#zip").change(selectTarget);
	//$("#zip").keypress(selectTarget);
	function createTooltips(){
		$("span.ui-icon").tooltip({
			bodyHandler:function(){
				return $(this).attr("tooltiptxt");
			}
		});
	}
	$("#step-1-form").validate();
	$("#submit-button").click(selectTarget);
	textboxes = $("input:text");
	if ($.browser.mozilla)
	{
		$(textboxes).keypress(checkForEnter);
	}
	else
	{
	    $(textboxes).keydown(checkForEnter);
	}
   function checkForEnter(event) {
      if (event.keyCode == 13) {
         currentTextboxNumber = textboxes.index(this);

         if (textboxes[currentTextboxNumber + 1] != null) {
           nextTextbox = textboxes[currentTextboxNumber + 1];
           nextTextbox.select();
         }
         event.preventDefault();
         return false;
      }
   }
 });

function selectTarget(){
	zip = $("#zip").val();
	$.post('estimate-ajax.php',
			{type:'zip',zip:zip},
			function(data){
				$("#step-1-form").attr("action",data);
				$("#step-1-form").submit();
			});
}


jQuery(document).ready(function($) {

	});