$(function(){
	//reset form values
	$("form")[0].reset();
	
	function flashForward(s) {
		currentStep += 1;
		$("#stepContainer" + (currentStep - 1)).hide();
		$("#prev").show();
		$("#next").css("opacity",".5");
		$("#stepContainer" + (currentStep)).show();
		$("#stepText").text(currentStep);
		if(s != "#degreeParent") $(s).change();
		stepValid(s);
		if(currentStep == stepDividers.length) {
	    	//IE absolute position fix
	    	if($.browser.msie) {
	    		$("#next").hide();
	    		$("#barContainer").hide();
	    	}
			finalLayout();
	    }
	}
	function moveToCorrectStep() {
		if($("#degreeParent").val() != "") {
			flashForward("#degreeParent");
			$("#bar").css("width","24%");
			if($("#education").val() != "") {
				flashForward("#education");
				$("#bar").css("width","36%");
				if($("#trueemail").val() != "") {
					flashForward("#trueemail");
					$("#bar").css("width","48%");
					if($("#zip").val() != "" || $("#country").val() != "") {
						if($("#country").val() != "" && $("#zip").val() == ""){
							$("#state").css({
								'display':'block'
							}).parent().prev("td").children("label").text("State").attr("for","state");
							$("h3:has(label[for='zip'])").after($("#zip"));
							$("#zipContainer").hide();
							$("#countryContainer").show();
						}
						flashForward("#zip");
					}
				}
			}
		}
	}

	//track fields in google analytics
	$(":input").live("blur",function(){
		if($(this).val() != "") pageTracker._trackPageview('/forms/inquiry/' + $(this).attr("id"));
	});
	
	//prevent submit on enter
	 $("form").bind("keypress", function(e) {
         if (e.keyCode == 13) {
        	 $(":input:focus").change();
        	 $("#next").click();
             return false;
        }
     });
	
	//show/hide list items
	$("li.expand div").before("<img src='images/right_arrow.png' class='arrow' style='margin-left:5px' />").hide().parent().css({
		'cursor':'pointer'
	}).click(function(){
		if($(this).children("div").not(":visible").length) {
			$("#content").animate({
				'height':$("#content").height() + $(this).children("div").outerHeight(true) + "px"
			});
			$(this).children("div").slideDown();
			$(this).children("img.arrow").attr("src","images/down_arrow.png");
		}
		else {
			$("#content").animate({
				'height':$("#content").height() - $(this).children("div").outerHeight(true) + "px"
			});
			$(this).children("div").slideUp();
			$(this).children("img.arrow").attr("src","images/right_arrow.png");
		}
	}).children("span").hover(function(){
		$(this).css("text-decoration","underline");
	},
	function(){
		$(this).css("text-decoration","none");
	});
	
	//show/hide citizenship
	if($("#citizen1")[0].checked) $("#citizenshipContainer").hide();
	$("#citizen1").click(function(){
		$("#citizenshipContainer").fadeOut(500);
	});
	$("#citizen2").click(function(){
		$("#citizenshipContainer").fadeIn(500);
	});
	
	//add CCA explanation
	$("div.CCA").wrapInner("<span />").append("<span>(why?)</span>").children("span:last").css({
		'color':'white',
		'cursor':'pointer',
		'font-style':'italic',
		'font-size':'10px',
		'margin-left':'10px'
	});
	setInfo($("div.CCA span:last"),"If your school participates in Franklin's 3+1 transfer program, you can earn three year's worth of credits toward your bachelor's at your community college, then finish your fourth year online at Franklin. Providing your community college information here will help us find ways to help you finish faster and save money on your degree.");
	
	//show/hide CCA questions
	$(".CCA").hide();
	$("#education").change(function(){
		if($(this).val() == "Associate's") {
			$(".CCA").show();
			$("div.CCA span:first").text("Where did you receive your Associates Degree?");
		}
		else if($(this).val() == "Pursuing Associate's") {
			$(".CCA").show();
			$("div.CCA span:first").text("Where are you pursuing your Associates Degree?");
		}
		else {
			$(".CCA").hide();
		}
	});
	
	//get degree/college vals
	degreeParent_value = $("#degree option:selected").parent().attr("label");
    degreeChild_value = $("#degree").val();
    collegeParent_value = $("#college option:selected").parent().attr("label");
    collegeChild_value = $("#college").val();
	
	//dynamic select boxes
	function dynamicSelect(selectID,parentSelectBoxText,childSelectBoxText) {
		var parentSelectBox = $("<select id='" + selectID + "Parent' name='" + selectID + "Parent'><option value=''>" + parentSelectBoxText + "</option></select>");
		var childSelectBox = $("<select id='" + selectID + "Child' name='" + selectID + "'><option value=''>" + childSelectBoxText + "</option></select>");
		var childSelectBoxOptions = [];
		$("#" + selectID + " optgroup").each(function(i){
			$("<option value=" + this.label + ">" + this.label + "</option>").appendTo(parentSelectBox);
			childSelectBoxOptions[i] = $.makeArray($(this).children());
		});
		$(parentSelectBox).change(function(e){
			$(childSelectBox).children(":not(:first-child)").remove();
			if(this.selectedIndex > 0) {
				for(var i = 0; i < childSelectBoxOptions[this.selectedIndex - 1].length; i++) {
					$("<option value='" + childSelectBoxOptions[this.selectedIndex - 1][i].value + "'>" + childSelectBoxOptions[this.selectedIndex - 1][i].text + "</option>").appendTo(childSelectBox);
				}
				//stupid IE fix
				$(childSelectBox).css({
					'display':'none'
				});
				$(childSelectBox).css({
					'display':'block'
				});
			}
		});
		$("#" + selectID).after(parentSelectBox).remove();
		$(childSelectBox).css({
			'display':'none'
		}).insertAfter(parentSelectBox);
	}
	dynamicSelect("degree","-- Select Degree Type --","-- Select Program --");
	$("#degreeParent").prev("h3").children("label").text("What type of degree are you seeking?");
	$("#form_content table:first").prepend("<tr><td><label for='degreeChild'>Program of Interest</label></td><td id='programContainer'></td></tr>");
	$("#degreeChild").appendTo($("#programContainer")).css({
		'display':'block'
	});
	//assign degree_level if it exists
	if($("#degree_level").val()) $("#degreeParent").val($("#degree_level").val()).change();
	if(typeof degreeParent_value != "undefined" && degreeParent_value != "") $("#degreeParent").val(degreeParent_value).change();
	if(typeof degreeChild_value != "undefined" && degreeChild_value != "") $("#degreeChild").val(degreeChild_value);
	dynamicSelect("college","-- Select College State --","-- Select College --");
	$("#collegeParent").parentsUntil("tr").last().parent().prev("tr").children("td:first").children("label").text("Select State").attr("for","collegeParent").parent().parent().append("<td><label for='collegeChild'>Select College</label></td>").next("tr").append("<td id='collegeContainer'></td>");
	$("#collegeChild").appendTo("#collegeContainer").css({
		'display':'block'
	});
	$("#collegeParent, #collegeChild").parent().css({
		'padding-bottom':'15px'
	});
	//assign college if it exists
	if(typeof collegeParent_value != "undefined" && collegeParent_value != "") $("#collegeParent").val(collegeParent_value).change();
	if(typeof collegeChild_value != "undefined" && collegeChild_value != "") $("#collegeChild").val(collegeChild_value);
	
	//add US/non-US logic
	$("#zip, h3:has(label[for='zip'])").wrapAll("<div id='zipContainer' />");
	$("<span>not in the U.S.?</span>").appendTo("#zipContainer").css({
		'cursor':'pointer',
		'color':'white',
		'text-decoration':'underline',
		'font-style':'italic',
		'font-size':'10px'
	}).click(function(){
		$("#zipContainer").fadeToggle(500,function(){
			$("#state").css({
				'display':'none'
			}).parent().append($("#zip")).prev("td").children("label").text("Postal Code").attr("for","zip");
			$("#countryContainer").fadeToggle(500);
			//validation
			if($("#country").val() != '') stepValid($("#country"));
			else stepInvalid($("#country"));
		});
	});
	$("#country, h3:has(label[for='country'])").wrapAll("<div id='countryContainer' />");
	$("#countryContainer").hide();
	$("<span>live in the U.S.?</span>").appendTo("#countryContainer").css({
		'cursor':'pointer',
		'color':'white',
		'text-decoration':'underline',
		'font-style':'italic',
		'font-size':'10px'
	}).click(function(){
		$("#countryContainer").fadeToggle(500,function(){
			$("#state").css({
				'display':'block'
			}).parent().prev("td").children("label").text("State").attr("for","state");
			$("h3:has(label[for='zip'])").after($("#zip"));
			$("#zipContainer").fadeToggle(500);
			//validation
			if($("#zip").val() != '') stepValid($("#zip"));
			else stepInvalid($("#zip"));
		});
	});
	  
	//store initial css values for final step transition
	function storeCssVal(el,att){
		el.data(att,el.css(att));
	}
	//IE background-position bug fix
	if($.browser.msie) $("#main").data("background-position",$("#main").css('background-position-x') + " " + $("#main").css('background-position-y'));
	else storeCssVal($("#main"),"background-position");
	storeCssVal($("#content_container"),"left");
	storeCssVal($("#content_header"),"color");
	storeCssVal($("#content_header"),"font-size");
	storeCssVal($("#form_content"),"height");
	storeCssVal($("#form_content"),"width");
	
	//zip autopopulate
	$("#zip").change(function(){
		if($(this).val().match(/\d{5}/) && $("#city:visible").length < 1){
			var d = new Date();
			var t = d.getTime();
			var url = "getlocality?zip=" + $(this).val() + "&" + t;
			$.getJSON(url, function(data) {
				if(typeof data != "undefined") $("#city").val(data.city).change();
				if(typeof data != "undefined") $("#state").val(data.state).change();
			});
		}
	});
	
	//make initial page changes for multistep format
	$("div.divider:first").remove();
	$("#form_content").children(":not(div)").wrapAll("<div id='whiteBox' />");
	$("#whiteBox").append("<div id='next'><img src='images/nextStep_button.png' /></div>");
	$("#next").css({
		'cursor':'pointer',
		'position':'absolute',
		'bottom':'30px',
		'opacity':'.5',
		'background-color':'#3b6e8f'
	});
	$("#privacy_policy").css({
		'position':'absolute'
	}).insertAfter("#next");
	if($.browser.msie && $.browser.version < 8) {
		$("#privacy_policy").css({
			'padding-bottom':'10px'
		})
	}
	
	//replace header text with URL var if applicable
	function replaceText(e){
		if(location.search != null && location.search != ""){
		    var pairs = location.search.substring(1).split("&");
		    for (var p = 0; p < pairs.length; ++p){
		        var pair = pairs[p].split("=");
		        if(typeof pair[0] != "undefined" && pair[0] == "hText" && typeof pair[1] != "undefined"){
		        	var name = pair[0];
			        var value = unescape( pair[1].replace(/\+/g, " ") );
			        if(name == "hText"){
			        	e.text(value);
			        }
		        }
		    }
		}
	}
	
	//size header text to available space
	function resizeText(e,w,h){
		var i = 1
		while(e.height() > h || e.width() > w){
			e.css({
				'width':'auto',
				'font-size':parseInt(e.css("font-size")) - 1 + "px",
				'line-height':parseInt(e.css("font-size")) - 1 + "px"
			});
			//alert(e.height() + "/" + e.width());
			i++;
			if(i>50) break;
		}
	}
	
	//change layout for multipstep format
	replaceText($("#content_header"));
	resizeText($("#content_header"),250,140);
	$("#content_header").data("font-size-final",$("#content_header").css("font-size"));
	$("#content_header").data("line-height-final",$("#content_header").css("line-height"));
	stepLayout();
	$("#content_header").css({
		'font-size':'40px',
		'line-height':'39px'
	});
	resizeText($("#content_header"),300,170);
	$("#content_header").data("font-size-step",$("#content_header").css("font-size"));
	$("#content_header").data("line-height-step",$("#content_header").css("line-height"));
	$("#content").css({
		'height':$("#content_container").offset().top + $("#content_container").height() + "px"
	}).data("height",$("#content").css("height"));
	function stepLayout(){
		$("#main").css({
			'background-position':'230px -3px'
		});
		$("#content_header").css({
			'color':'#002b54',
			'position':'absolute',
			'top':'70px',
			'left':'590px',
			'font-size':$("#content_header").data("font-size-step"),
			'line-height':$("#content_header").data("line-height-step")
		}).appendTo($("#main"));
		$("#content_container").css({
			'left':'400px'
		});
		$("p.body_copy").show();
		$("#copy li p").hide();
		$("#copy li img.arrow").attr("src","images/right_arrow.png");
		$(".secondary").hide();
		$(".primary").show();
		$("#next").show();
		$("#privacy_policy").css({
			'bottom':'5px',
			'left':'13px'
		})
		$("#barContainer").show();
		$("#stepContainer").append($("#prev")).show();
		$("#form_content").css({
			'width':'313px'
		});
		$("<img id='overlay_bg_light' src='images/overlay_bg_light.png' />").css({
			'position':'relative',
			'top':'-14px',
			'left':'-15px'
		}).insertBefore($("#whiteBox"));
		$("#whiteBox p:first").hide();
		$("#whiteBox h2").text("Learn more about Franklin!").css({
			'margin-top':'20px'
		});
		$("#whiteBox").css({
			'border':'1px solid white',
			'position':'relative',
			'height':'394px',
			'width':'290px',
			'padding':'10px'
		});
		$("#content").css({
			'height':$("#content").data("height")
		});
	}
	
	//change layout for final step
	function finalLayout(){
		$("#content").css({
			'height':'auto'
		});
		$("#main").css({
			'background-position':$("#main").data("background-position")
		});
		$("#content_container").css({
			'left':$("#content_container").data("left")
		});
		$("#content_header").css({
			'position':'static',
			'color':$("#content_header").data("color"),
			'font-size':$("#content_header").data("font-size-final"),
			'line-height':$("#content_header").data("line-height-final")
		}).prependTo($("#content_container"));
		$("p.body_copy").hide();
		$(".primary").hide();
		$(".secondary").show();
		$("#form_content").css({
			'width':'560px'
		});
		$("#bar").css({
			'width':'100%'
		});
		$("#overlay_bg_light").remove();
		$("#whiteBox h2").text("Almost Done!").css({
			'margin-top':'0'
		}).append("<span>(This will only take a minute)</span>").children("span").css({
			'font-size':'13px',
			'font-style':'italic',
			'font-weight':'normal',
			'position':'relative',
			'left':'15px',
			'top':'-4px',
			'text-transform':'none'
		});
		$("#whiteBox p").show();
		$("#whiteBox").css({
			'border-width':'0',
			'width':'auto',
			'height':'auto',
			'margin-top':'0px',
			'padding':'0'
		});
		$("#stepContainer").hide();
		$("#barContainer").hide();
		$("#next").hide();
		$("#privacy_policy").css({
			'bottom':'0px',
			'left':'3px'
		})
		$("#prev").appendTo($("#form_content"));
	  	$(this).fadeIn();
	}
	
	//convert to multipstep
	var stepDividers = ["degree","education","trueemail","zip","location1"];
	if($("label[for='" + stepDividers[0] + "']").parentsUntil("form").length > 0) {
		$("label[for='" + stepDividers[0] + "']").parentsUntil("form").last().before("<div id='barContainer'><div id='bar'></div></div><div id='stepContainer'>Step <span id='stepText'></span>/<span id='totalText'></span></div>");
	}
	else {
		$("label[for='" + stepDividers[0] + "']").before("<div id='barContainer'><div id='bar'></div></div><div id='stepContainer'>Step <span id='stepText'></span>/<span id='totalText'></span></div>");
	}
		$("#barContainer").css({
		'width':'99%',
		'height':'19px',
		'border':'1px solid #9bbacf',
		'margin':'30px 0 10px 0',
		'position':'relative'
	});
	$("#bar").css({
		'width':'0',
		'height':'19px',
		'background-image':'url("images/progress_bar.gif")',
		'color':'white',
		'text-align':'center',
		'font-size':'12px',
		'font-weight':'bold',
		'position':'relative'
	});
	$("#stepContainer").css({
		'position':'relative',
		'font-size':'14px',
		'margin-bottom':'70px'
	}).append("<span id='prev'>back</span>");
	$("#prev").css({
		'position':'absolute',
		'top':'0',
		'right':'3px',
		'display':'none',
		'cursor':'pointer'
	});
	for(i = 0; i <= stepDividers.length; i++){
		if($("label[for='" + stepDividers[i] + "']").parentsUntil("form").length > 0) {
			$("label[for='" + stepDividers[i] + "']").parentsUntil("form").last().addClass("step" + (i+1));
		}
		else $("label[for='" + stepDividers[i] + "']").addClass("step" + (i+1));
	}
	for(i = 0; i <= stepDividers.length; i++){
		$(".step" + (i)).nextUntil(".step" + (i+1)).andSelf().wrapAll("<div class='stepContainer' id='stepContainer" + i + "' />");
	}
	for(i = 2; i <= stepDividers.length; i++){
		$("#stepContainer" + i).hide();
	}
	var barWidth = 100/stepDividers.length;
	var currentStep = 1;
	$("#bar").width((barWidth * .6) + "%");
	$("#stepText").text(currentStep);
	$("#totalText").text(stepDividers.length);
	//IE fix
	if($.browser.msie) $("#stepContainer1").css("border","1px solid transparent");
	
	//next step
	$("#next").click(nextStep);
	function nextStep(){
		//if current step does not validate, return
		if($("div.stepContainer:visible").hasClass("invalid")) return;
		//kill button for one second
		$(this).unbind('click',nextStep);
		setTimeout(function(){$("#next").click(nextStep)},1000);
		//if on step 4, check for bad zips
		if(currentStep == 4) {
			var z = $("#zip").val();
			if(z == '01603' || z == '01604' || z == '01605' || z == '01606' || z == '01607' || z == '01608' || z == '01609' || z == '01610' || z == '01611' || z == '01612' || z == '01613' || z == '01001' || z == '01002' || z == '01003' || z == '01004' || z == '01010' || z == '01011' || z == '01012' || z == '01013' || z == '01026' || z == '01027' || z == '01005' || z == '01007' || z == '01008' || z == '01009' || z == '01014' || z == '01020' || z == '01021' || z == '01022' || z == '01028' || z == '01029' || z == '01032' || z == '01033' || z == '01034' || z == '01036' || z == '01037' || z == '01038' || z == '01039' || z == '01050' || z == '01030' || z == '01031' || z == '01035' || z == '01040' || z == '01041' || z == '01053' || z == '01054' || z == '01060' || z == '01061' || z == '01062' || z == '01063' || z == '01066' || z == '01073' || z == '01074' || z == '01075' || z == '01082' || z == '01083' || z == '01084' || z == '01056' || z == '01057' || z == '01059' || z == '01068' || z == '01069' || z == '01070' || z == '01071' || z == '01072' || z == '01077' || z == '01079' || z == '01080' || z == '01081' || z == '01085' || z == '01086' || z == '01088' || z == '01092' || z == '01093' || z == '01094' || z == '01095' || z == '01096' || z == '01097' || z == '01098' || z == '01103' || z == '01104' || z == '01105' || z == '01089' || z == '01090' || z == '01101' || z == '01102' || z == '01106' || z == '01107' || z == '01108' || z == '01109' || z == '01116' || z == '01118' || z == '01119' || z == '01128' || z == '01129' || z == '01151' || z == '01152' || z == '01201' || z == '01202' || z == '01203' || z == '01220' || z == '01222' || z == '01111' || z == '01115' || z == '01138' || z == '01139' || z == '01144' || z == '01199' || z == '01223' || z == '01224' || z == '01230' || z == '01235' || z == '01237' || z == '01238' || z == '01240' || z == '01242' || z == '01247' || z == '01252' || z == '01225' || z == '01226' || z == '01227' || z == '01229' || z == '01236' || z == '01243' || z == '01244' || z == '01245' || z == '01253' || z == '01258' || z == '01263' || z == '01264' || z == '01266' || z == '01267' || z == '01270' || z == '01301' || z == '01254' || z == '01255' || z == '01256' || z == '01257' || z == '01259' || z == '01260' || z == '01262' || z == '01302' || z == '01330' || z == '01331' || z == '01339' || z == '01340' || z == '01343' || z == '01344' || z == '01346' || z == '01350' || z == '01351' || z == '01354' || z == '01360' || z == '01364' || z == '01337' || z == '01338' || z == '01341' || z == '01342' || z == '01347' || z == '01349' || z == '01355' || z == '01366' || z == '01367' || z == '01368' || z == '01370' || z == '01373' || z == '01379' || z == '01380' || z == '01420' || z == '01430' || z == '01375' || z == '01376' || z == '01378' || z == '01431' || z == '01432' || z == '01436' || z == '01438' || z == '01440' || z == '01441' || z == '01452' || z == '01453' || z == '01460' || z == '01464' || z == '01467' || z == '01471' || z == '01472' || z == '01475' || z == '01477' || z == '01501' || z == '01503' || z == '01434' || z == '01450' || z == '01451' || z == '01462' || z == '01463' || z == '01468' || z == '01469' || z == '01470' || z == '01473' || z == '01474' || z == '01504' || z == '01508' || z == '01509' || z == '01510' || z == '01517' || z == '01518' || z == '01519' || z == '01505' || z == '01506' || z == '01507' || z == '01515' || z == '01516' || z == '01520' || z == '01521' || z == '01526' || z == '01527' || z == '01529' || z == '01531' || z == '01535' || z == '01536' || z == '01537' || z == '01538' || z == '01540' || z == '01541' || z == '01546' || z == '01550' || z == '01562' || z == '01564' || z == '01522' || z == '01523' || z == '01524' || z == '01525' || z == '01532' || z == '01534' || z == '01542' || z == '01543' || z == '01545' || z == '01560' || z == '01561' || z == '01566' || z == '01568' || z == '01580' || z == '01581' || z == '01583' || z == '01585' || z == '01588' || z == '01590' || z == '01569' || z == '01570' || z == '01571' || z == '01582' || z == '01586' || z == '01601' || z == '01602' || z == '01614' || z == '01615' || z == '01653' || z == '01654' || z == '01701' || z == '01702' || z == '01703' || z == '01718' || z == '01719' || z == '01721' || z == '01730' || z == '01731' || z == '01655' || z == '01704' || z == '01705' || z == '01720' || z == '01740' || z == '01741' || z == '01742' || z == '01746' || z == '01747' || z == '01748' || z == '01749' || z == '01757' || z == '01760' || z == '01770' || z == '01772' || z == '01773' || z == '01776' || z == '01778' || z == '01784' || z == '01745' || z == '01752' || z == '01754' || z == '01756' || z == '01775' || z == '01801' || z == '01803' || z == '01805' || z == '01812' || z == '01813' || z == '01815' || z == '01824' || z == '01826' || z == '01827' || z == '01833' || z == '01834' || z == '01835' || z == '01807' || z == '01810' || z == '01821' || z == '01822' || z == '01830' || z == '01831' || z == '01832' || z == '01840' || z == '01841' || z == '01842' || z == '01845' || z == '01850' || z == '01851' || z == '01862' || z == '01863' || z == '01865' || z == '01866' || z == '01867' || z == '01876' || z == '01886' || z == '01887' || z == '01843' || z == '01844' || z == '01852' || z == '01853' || z == '01854' || z == '01860' || z == '01864' || z == '01879' || z == '01880' || z == '01885' || z == '01888' || z == '01889' || z == '01902' || z == '01903' || z == '01904' || z == '01908' || z == '01910' || z == '01913' || z == '01922' || z == '01923' || z == '01929' || z == '01930' || z == '01890' || z == '01899' || z == '01901' || z == '01905' || z == '01906' || z == '01907' || z == '01915' || z == '01921' || z == '01931' || z == '01936' || z == '01937' || z == '01944' || z == '01945' || z == '01949' || z == '01951' || z == '01952' || z == '01965' || z == '01966' || z == '01969' || z == '01982' || z == '01983' || z == '01984' || z == '01985' || z == '01938' || z == '01940' || z == '01950' || z == '01960' || z == '01961' || z == '01970' || z == '01971' || z == '02018' || z == '02019' || z == '02026' || z == '02027' || z == '02030' || z == '02032' || z == '02038' || z == '02040' || z == '02041' || z == '02044' || z == '02045' || z == '02047' || z == '02020' || z == '02021' || z == '02025' || z == '02035' || z == '02043' || z == '02048' || z == '02050' || z == '02051' || z == '02054' || z == '02055' || z == '02056' || z == '02060' || z == '02061' || z == '02062' || z == '02066' || z == '02067' || z == '02070' || z == '02081' || z == '02090' || z == '02093' || z == '02052' || z == '02053' || z == '02059' || z == '02065' || z == '02071' || z == '02072' || z == '02108' || z == '02109' || z == '02110' || z == '02111' || z == '02116' || z == '02117' || z == '02118' || z == '02120' || z == '02121' || z == '02123' || z == '02124' || z == '02112' || z == '02113' || z == '02114' || z == '02115' || z == '02119' || z == '02122' || z == '02125' || z == '02126' || z == '02127' || z == '02128' || z == '02129' || z == '02130' || z == '02132' || z == '02133' || z == '02134' || z == '02136' || z == '02137' || z == '02131' || z == '02135' || z == '02138' || z == '02139' || z == '02140' || z == '02141' || z == '02143' || z == '02144' || z == '02150' || z == '02151' || z == '02155' || z == '02156' || z == '02142' || z == '02145' || z == '02148' || z == '02149' || z == '02152' || z == '02153' || z == '02163' || z == '02169' || z == '02170' || z == '02171' || z == '02176' || z == '02184' || z == '02185' || z == '02180' || z == '02186' || z == '02187' || z == '02190' || z == '02199' || z == '02201' || z == '02203' || z == '02206' || z == '02210' || z == '02211' || z == '02215' || z == '02217' || z == '02188' || z == '02189' || z == '02191' || z == '02196' || z == '02204' || z == '02205' || z == '02212' || z == '02222' || z == '02228' || z == '02238' || z == '02241' || z == '02266' || z == '02269' || z == '02295' || z == '02297' || z == '02304' || z == '02305' || z == '02322' || z == '02324' || z == '02283' || z == '02284' || z == '02293' || z == '02298' || z == '02301' || z == '02302' || z == '02303' || z == '02325' || z == '02327' || z == '02333' || z == '02334' || z == '02337' || z == '02339' || z == '02340' || z == '02341' || z == '02345' || z == '02346' || z == '02348' || z == '02349' || z == '02330' || z == '02331' || z == '02332' || z == '02338' || z == '02343' || z == '02344' || z == '02347' || z == '02350' || z == '02356' || z == '02357' || z == '02358' || z == '02361' || z == '02362' || z == '02364' || z == '02351' || z == '02355' || z == '02359' || z == '02360' || z == '02366' || z == '02367' || z == '02375' || z == '02379' || z == '02420' || z == '02421' || z == '02445' || z == '02446' || z == '02451' || z == '02452' || z == '02453' || z == '02456' || z == '02457' || z == '02368' || z == '02370' || z == '02381' || z == '02382' || z == '02447' || z == '02454' || z == '02455' || z == '02458' || z == '02459' || z == '02460' || z == '02461' || z == '02462' || z == '02464' || z == '02466' || z == '02467' || z == '02465' || z == '02468' || z == '02472' || z == '02474' || z == '02477' || z == '02478' || z == '02479' || z == '02481' || z == '02482' || z == '02492' || z == '02493' || z == '02494' || z == '02471' || z == '02475' || z == '02476' || z == '02495' || z == '02532' || z == '02536' || z == '02539' || z == '02540' || z == '02541' || z == '02542' || z == '02543' || z == '02552' || z == '02553' || z == '02554' || z == '02534' || z == '02535' || z == '02537' || z == '02538' || z == '02556' || z == '02557' || z == '02558' || z == '02559' || z == '02561' || z == '02562' || z == '02563' || z == '02568' || z == '02571' || z == '02573' || z == '02576' || z == '02584' || z == '02601' || z == '02630' || z == '02631' || z == '02564' || z == '02565' || z == '02574' || z == '02575' || z == '02632' || z == '02633' || z == '02634' || z == '02635' || z == '02641' || z == '02642' || z == '02643' || z == '02644' || z == '02646' || z == '02647' || z == '02648' || z == '02649' || z == '02652' || z == '02653' || z == '02655' || z == '02657' || z == '02659' || z == '02663' || z == '02664' || z == '02668' || z == '02669' || z == '02670' || z == '02671' || z == '02637' || z == '02638' || z == '02639' || z == '02645' || z == '02650' || z == '02651' || z == '02660' || z == '02661' || z == '02662' || z == '02666' || z == '02667' || z == '02672' || z == '02673' || z == '02702' || z == '02703' || z == '02715' || z == '02717' || z == '02718' || z == '02675' || z == '02712' || z == '02713' || z == '02714' || z == '02719' || z == '02720' || z == '02721' || z == '02722' || z == '02726' || z == '02738' || z == '02739' || z == '02743' || z == '02744' || z == '02745' || z == '02748' || z == '02760' || z == '02762' || z == '02763' || z == '02723' || z == '02724' || z == '02725' || z == '02740' || z == '02741' || z == '02742' || z == '02746' || z == '02747' || z == '02761' || z == '02764' || z == '02766' || z == '02769' || z == '02770' || z == '02771' || z == '02777' || z == '02790' || z == '02791' || z == '02767' || z == '02768' || z == '02779' || z == '02780' || z == '02783' || z == '05501' || z == '05544') {
				window.location.href = 'mass.jsp';
				return;
			}
		}
		//if not on last step
		if(currentStep < stepDividers.length) {
			currentStep += 1;
			$("#stepContainer" + (currentStep - 1)).fadeOut(500,function(){
				if(currentStep != 1) $("#prev").fadeIn(500);
				if(currentStep != stepDividers.length && $("#stepContainer" + (currentStep)).hasClass("invalid")) $("#next").fadeTo(500,.5);
				$("#stepContainer" + (currentStep)).fadeIn(500,function(){
					$(":input:visible:first").focus();
				});
			});
			$("#stepText").text(currentStep);
		    if(currentStep == stepDividers.length) {
		    	//IE absolute position fix
		    	if($.browser.msie) {
		    		$("#next").fadeOut();
		    		$("#barContainer").fadeOut();
		    	}
				$("body").fadeOut("normal",function(){
					finalLayout();
					$(this).fadeIn();
				});
		    }
		    else {
		    	$("#bar").animate({
		    		width: "+=" + (barWidth * .6) + "%"
		    	}, 1000);
		    }
		}
	}
	
	//previous step
	$("#prev").click(prevStep);
	function prevStep(){
		$(this).unbind('click',prevStep);
		setTimeout(function(){$("#prev").click(prevStep)},1000);
		if(currentStep > 1) {
			if(currentStep == 2) $("#prev").fadeOut(500);
			$("#stepContainer" + currentStep).fadeOut(500,function(){
				currentStep -= 1;
				$("#stepContainer" + (currentStep)).fadeIn(500,function(){
					$(":input:visible:first").focus();
				});
				if(!$("#stepContainer" + (currentStep)).hasClass("invalid")) $("#next").fadeTo(500,1);
			});
			$("#stepText").text(currentStep - 1);
			if(currentStep != stepDividers.length) {
				$("#bar").animate({
					width: "-=" + (barWidth * .6) + "%"
				}, 1000);
			}
		    if(currentStep == stepDividers.length) {
		    	$("body").fadeOut("normal",function(){
		    		$("#bar").css({
		    			'width':(100 - 100/stepDividers.length) * .6 + "%"
		    		});
		    		stepLayout();
		    		$(this).fadeIn();
		    	});
		    }
		}
	}
	
	//validate steps
	function stepValid(e) {
		$(e).parents("div.stepContainer:first").removeClass("invalid");
		if(currentStep != 5) $("#next").fadeTo(100,1);
	}
	function stepInvalid(e) {
		$(e).parents("div.stepContainer:first").addClass("invalid");
		$("#next").fadeTo(100,.5);
	}
	$(".stepContainer").addClass("invalid");
	$("#degreeParent, #education, #country").bind('change keyup',function(){
		if($(this).val() != '') stepValid(this);
		else stepInvalid(this);
	});
	$("#trueemail").attr("autocomplete","off").bind('change keyup',function(){
		if($(this).val().match(/^[^@\s]+@{1}[^@\s\.]+\.{1}[^@\s]+$/)) stepValid($(this));
		else stepInvalid(this);
	});
	$("#zip").attr("autocomplete","off").bind('change keyup',function(){
		if($("#state").css("display") != "none"){
			if($("#zip").val().match(/^\d{5}$/)) stepValid($("#zip"));
			else stepInvalid(this);
		}
	});
	
	//validate final step
	setValidation("firstName","Please enter a first name.");
	setValidation("middleName","Please enter a middle name.");
	setValidation("lastName","Please enter a last name.");
	setValidation("address","Please enter an address.");
	setValidation("city","Please enter a city.");
	setValidation("state","Please enter a state.",false,"$('#state:visible').length > 0");
	setValidation("phone","Please enter a 10-digit phone number.",validatePhone);
	setValidation("start","Please select a term.");
	setValidation("degreeChild","Please select a program of interest.");
	function validatePhone(e){
		if($("#country").val() == '') {
			$(this).val($(this).val().replace(/\D/g,''));
			if($(this).val().length == 10) $(this).val("(" + $(this).val().substr(0,3) + ") " + $(this).val().substr(3,3) + "-" + $(this).val().substr(6,4));
			$(this).val().match(/^\(\d{3}\)\s\d{3}-\d{4}/) ? makeValid(this) : makeInvalid(this);
		}
		else makeValid(this);
	}
	
	//move to correct step if URL parameters are available
	moveToCorrectStep();
	
	//focus initial input
	$(":input:visible:first").focus();
	
	//show body
	$("body").css("visibility","visible");
});
