var jsonData;// store for user browse page originvar savedAreaOfStudy = $('select.areaOfStudy').val();var programOfInterest = {    element: $('select.programOfInterest'),    reset: function(){        dynamicQuestions.reset();        programOfInterest.element.empty();        programOfInterest.element.append('<option value="">---Select---</option>');    },    update: function(programs){        programOfInterest.reset();        if(programs.length == 0) {        	alert('We\'re sorry, there are no programs that match your criteria. Please try selecting a different area of study.');        }else{			$(programs).each(function(){				programOfInterest.element.append('<option value="'+this.value+'">'+this.label+'</option>');			});        }        //Preselect if the option exists        if(preSelectedProgram != "") {        //IE6 throws unspecified error that prevents setting programOfInterest, try catch method works around this          try{        	  $('select.programOfInterest').val(preSelectedProgram);        	  $('.degrees').show();          }          catch(err) {        	  //alert('catchblock: '+preSelectedProgram);          }          //If pre-pop show dynamic questions          dynamicQuestions.reveal( $('select.programOfInterest').val());        }    },    checkDependency: function(){    	//removed edu dependency so getPrograms will execute regardless        if (programOfInterest.getAreaOfStudy() == ""){            //programOfInterest.reset();            return false;        }    	// updated to always return false since we are taking out the high level dependency completely        return true;    },    getPrograms: function(){    	$('.degrees').hide();    	$("select.programOfInterest").val('');    	$("select.programOfInterest option[value='']").text(' loading...');        $("select.programOfInterest").attr("disabled","disabled");        $.ajax({        	type	: 	'GET',         	url		: 	'/dynamic/school-form/programs',         	data	: 	'highestLevelOfEducation='+programOfInterest.getLevelOfEducation()+'&programCategoryGroups='+programOfInterest.getAreaOfStudy(),            cache	:	false,            success	: 	function(jsonObject){			                jsonData = eval('(' + jsonObject + ')');			                programOfInterest.update(jsonData.programs);			                $("select.programOfInterest").attr("disabled","");			                checkDegree();            		  	}        });    },    getLevelOfEducation: function(){    	// hack to get around numberFormatException when highestLevelOfEducation is blank    	if($('select.levelOfEducation').val() == "") {    		var d = 99;    		return d;	    	}else{    		// changing to always return 99 so high level is no longer taken into account    		var d = 99;    		return d;	    	}    },    getAreaOfStudy: function(){        return $('select.areaOfStudy').val();    }};var checkDegree=function(){	if($("select.programOfInterest").val()!=''){		$('div.degrees').append('<div class="programCopy"><h4>'+programCopy[$('select.programOfInterest').val()].title+'</h4><p>'+programCopy[$('select.programOfInterest').val()].description+'</p></div>');		$('.degrees').show();	}}var dynamicQuestions = {    reset: function(){        $('.questions').hide();        $('input#directoryQuestions').val('');    },    reveal: function(programId){        $(jsonData.questionIdsByProgramId[programId]).each(function(){            $('.dynamicQuestion\\['+this+'\\]').parents('.questions').show();            $('.dynamicRadio\\['+this+'\\]').show();            $('.dynamicText\\['+this+'\\]').show();        });        //populate hidden field for validation        var questionIds = new Array();        //determine the question number by parsing class name        $("*[class^=dynamicQuestion]").each(function(){    		if($(this).parents('.questions').css('display')=='block'){    			questionIds.push($(this).attr('name').substring($(this).attr('name').indexOf('[')+1,$(this).attr('name').indexOf(']')));    		}        });        $("[class*=dynamicRadio]").each(function(){        	if($(this).css('display')=='block'){        		if($(this).attr('class').indexOf('radioQuestions')>-1){        			questionIds.push($(this).attr('class').substring($(this).attr('class').indexOf('[')+1,$(this).attr('class').indexOf(']')));        		}        	}        });        $("[class*=dynamicText]").each(function(){        	if($(this).css('display')=='block'){        		questionIds.push($(this).attr('class').substring($(this).attr('class').indexOf('[')+1,$(this).attr('class').indexOf(']')));        	}        });        var questionOrder = '';        $(questionIds).each(function(index){            questionOrder += this;            if (index != ($(questionIds).length - 1)){                questionOrder += ',';            }        });        $('input#directoryQuestions').val(questionOrder);		if( $('input[name="answersMap[14]"]:checked').val() == '0,14') {			$('.dynamicText\\[15\\]').show();		}else{			$('.dynamicText\\[15\\]').hide();		}			    }};var sidebar = {    update: {        byAreaOfStudy: function(){            var areaOfStudyId = $('select.areaOfStudy').val();            sidebar.reset();            if (areaOfStudyId != ""){                $('div.degrees div[class!="programTypeByCategory['+areaOfStudyId+']"]').each(function(){                    $(this).hide();                });            }        },        bySavedAreaOfStudy: function(){        	sidebar.hideAll();        },        byAllDegrees: function(){        	sidebar.hideAll();        },        bySingleDegree: function(){        	sidebar.reset();        },                byProgramOfInterest: function(){            sidebar.reset();            sidebar.hideAll();            checkDegree();        }    },    reset: function(){        $('div.degrees div.programCopy').remove();    },    hideAll: function(){        $('div.degrees').children().each(function(){            $(this).hide();        });    }};var userResets = {	byDeepLink: {		resetProgOfInterest: function(){			sidebar.update.byAllDegrees();    		programOfInterest.reset();					},		resetAreaOfStudy: function(){    		if($('select.areaOfStudy').val() == ""){    			sidebar.update.byAllDegrees();    		}else{    			sidebar.update.byAreaOfStudy();    		}		}				},	fromDegreeBrowseOrigin: {		categorySelect: function(){			if($('select.areaOfStudy').val() == ""){    			sidebar.update.bySingleDegree();			}		},		degreeSelect: function(){			if($('select.programOfInterest').val() == ""){  			    			sidebar.update.bySingleDegree();    			}			}			},		fromCategoryBrowseOrigin: {			categorySelect: function(){			if($('select.areaOfStudy').val() == ""){    			sidebar.update.bySavedAreaOfStudy();			}		},		degreeSelect: function(){			if($('select.programOfInterest').val() == ""){  			    			sidebar.update.bySavedAreaOfStudy();			}		}		}			};var cursor = {    busy: function(){        $('body').addClass('operationBusy');    },    reset: function(){        $('body').removeClass('operationBusy');    }};var stateField = {    setToOtherValue: function() {        $('select.state')[0].value = "-223344";    },    setToLastSelected: function() {        if(stateField.selectedField == null) {            $('select.state')[0].value = "";        }else{            $('select.state')[0].value = stateField.selectedField;        }    },    selectedField: null}var phoneFields = {    setToInternationalPhoneField: function() {                phoneFields.clearBothFields();		//phoneFields.clearUSAPhoneFields();        var phoneAreaDay = $("input[name='phoneAreaDay']").remove();        $("input[name='countryCodeDay']").after(phoneAreaDay);        $($("input[name='intlPhoneNumDay']")[0].parentNode).show();        $($("input[name='phonePrefixDay']")[0].parentNode).hide();        var phoneAreaEvening = $("input[name='phoneAreaEvening']").remove();        $("input[name='countryCodeEve']").after(phoneAreaEvening);        $($("input[name='intlPhoneNumEve']")[0].parentNode).show();        $($("input[name='phonePrefixEvening']")[0].parentNode).hide();        $("input[name='internationalForm']")[0].value = "true";		phoneFields.enableIntPhone();        pageInit.attachAutoTab();    },    setToUSAPhoneFields: function() {        //phoneFields.clearBothFields();		phoneFields.clearIntPhoneFields();		//phoneAreaDay is shared by USA and International-this will clear the field when going from international to US.		if(activeCountryValue != '0' && activeCountryValue != null && activeCountryValue != '') {			$("input[name='phoneAreaDay']")[0].value = "";			$("input[name='phoneAreaEvening']")[0].value = "";		}        var phoneAreaDay = $("input[name='phoneAreaDay']").remove();        $("input[name='phonePrefixDay']").before(phoneAreaDay);        $($("input[name='intlPhoneNumDay']")[0].parentNode).hide();        $($("input[name='phonePrefixDay']")[0].parentNode).show();        var phoneAreaEvening = $("input[name='phoneAreaEvening']").remove();        $("input[name='phonePrefixEvening']").before(phoneAreaEvening);        $($("input[name='intlPhoneNumEve']")[0].parentNode).hide();        $($("input[name='phonePrefixEvening']")[0].parentNode).show();        $("input[name='internationalForm']")[0].value = "false";		phoneFields.disableIntPhone();        pageInit.attachAutoTab();    },    clearBothFields : function() {        $("input[name='phoneAreaDay']")[0].value = "";        $("input[name='phonePrefixDay']")[0].value = "";        $("input[name='phoneStationDay']")[0].value = "";        $("input[name='phoneAreaEvening']")[0].value = "";        $("input[name='phonePrefixEvening']")[0].value = "";        $("input[name='phoneStationEvening']")[0].value = "";        $("input[name='countryCodeDay']")[0].value = "";        $("input[name='intlPhoneNumDay']")[0].value = "";        $("input[name='countryCodeEve']")[0].value = "";        $("input[name='intlPhoneNumEve']")[0].value = "";    },    clearIntPhoneFields : function() {        $("input[name='countryCodeDay']")[0].value = "";        $("input[name='intlPhoneNumDay']")[0].value = "";        $("input[name='countryCodeEve']")[0].value = "";        $("input[name='intlPhoneNumEve']")[0].value = "";    },        clearUSAPhoneFields : function() {        $("input[name='phoneAreaDay']")[0].value = "";        $("input[name='phonePrefixDay']")[0].value = "";        $("input[name='phoneStationDay']")[0].value = "";        $("input[name='phoneAreaEvening']")[0].value = "";        $("input[name='phonePrefixEvening']")[0].value = "";        $("input[name='phoneStationEvening']")[0].value = "";    	    },     	disableIntPhone : function() {		$("input[name='intlPhoneNumDay']").attr("disabled","disabled");   		$("input[name='intlPhoneNumEve']").attr("disabled","disabled");   	},	enableIntPhone : function() {		$("input[name='intlPhoneNumDay']").attr("disabled","");   		$("input[name='intlPhoneNumEve']").attr("disabled","");   	}	      };var activeCountryValue;$('select.country').change(function() {    if(this.value == "0" || this.value == "") {        phoneFields.setToUSAPhoneFields();        if($('select.state')[0].value == '-223344'){            stateField.setToLastSelected();        }        activeCountryValue = this.value;    } else {        if($('select.state')[0].value != "" && $('select.state')[0].value != "-223344") {            stateField.selectedField = $('select.state')[0].value;        }        phoneFields.setToInternationalPhoneField();        stateField.setToOtherValue();        activeCountryValue = this.value;    }});var setDirectoryQuestions=function(){	if($('.dynamicText\\[13\\]').css('display')=='block'){		if($('#directoryQuestions').val()==''){			$('#directoryQuestions').val('13');		}else{			$('#directoryQuestions').val($('#directoryQuestions').val()+',13');		}	}	if($('.dynamicText\\[15\\]').css('display')=='block'){		if($('#directoryQuestions').val()==''){			$('#directoryQuestions').val('15');		}else{			$('#directoryQuestions').val($('#directoryQuestions').val()+',15');		}	}};var resizeText = function(textContainer,maxWidth) {  el = document.getElementById(textContainer);  elFontSize = $("#"+textContainer+"").css("font-size");  elFontSize= elFontSize.replace(/px/,"");  elWidth = el.offsetWidth;  while (elWidth > maxWidth) {    elFontSize = elFontSize-1;    $("#"+textContainer+"").css("font-size",elFontSize+"px");    elWidth = el.offsetWidth;    }};//Run through default pre-pop actions onload$(function() {    resizeText("preText","275");    sidebar.hideAll();    //This is unlikely b/c coming from a category browse page    if (isCategory == 'true' && preSelectedProgram == '') {        var matchAreaOfStudyId = $('select.areaOfStudy').val();    }    //Initiate dynamic questions and fill programs if programs are prepopped regardless of EDU level. Most likely coming from a category browse page.    if ($('select.areaOfStudy').val() != "") {        //fill programs             $.ajax({type: 'POST', url: '/dynamic/school-form/programs', data: 'highestLevelOfEducation=' + programOfInterest.getLevelOfEducation() + '&programCategoryGroups=' + programOfInterest.getAreaOfStudy(),            cache: false,            success: function(jsonObject) {                 jsonData = eval('(' + jsonObject + ')');                programOfInterest.update(jsonData.programs);                cursor.reset();                var programId = preSelectedProgram;                //show relevant questions and program description                                   if (programId != "" && jsonData.programs.length != 0) {                	dynamicQuestions.reset();                    dynamicQuestions.reveal(programId);                    sidebar.update.byProgramOfInterest();                }            }        });    }    //From a degree browse page and/or area of study is blank || from the backpage then pre-pop program of interest and show dynamic questions.  Condition is redundent just in case.	if ( (preSelectedProgram != '' &&  paramBrowseType != "" && isCategory == 'false')  || (preSelectedProgram != '' && $('select.areaOfStudy').val() == '') ) {	  $.ajax({type: 'POST', url: '/dynamic/school-form/programs',            cache: false,            success: function(jsonObject) {          	                jsonData = eval('(' + jsonObject + ')');                programOfInterest.update(jsonData.programs);                cursor.reset();                var programId = preSelectedProgram;                //show relevant questions and program description                                     if (programId != "" && jsonData.programs.length != 0) {                	dynamicQuestions.reset();                    dynamicQuestions.reveal(programId);                    sidebar.update.byProgramOfInterest();                }                            }        });	}   $("input[name='intlPhoneNumDay']").attr("disabled","disabled");   $("input[name='intlPhoneNumEve']").attr("disabled","disabled");         $('select.areaOfStudy').change(function(){		if($('select.programOfInterest').val() == "" ){			userResets.byDeepLink.resetProgOfInterest();		}		if (programOfInterest.checkDependency()){			programOfInterest.getPrograms();			sidebar.update.byAreaOfStudy();		}		//From a browsepage    	    if(paramBrowseType != "" && $(this).val() == ''){	    	if(isCategory == 'true'){				//from a category browse page				userResets.fromCategoryBrowseOrigin.degreeSelect();    		    }else{				//from a degree browse page				userResets.fromDegreeBrowseOrigin.degreeSelect();		    }	    }	});	$('select.programOfInterest').change(function(){	    dynamicQuestions.reset();	    var programId = $(this).val();	    //show relevant questions	    if (programId != ""){	        dynamicQuestions.reveal(programId);	        sidebar.update.byProgramOfInterest();	        $('.degrees').show();	    }else{			userResets.byDeepLink.resetAreaOfStudy();  			$('.degrees').hide();	    }	 	if(paramBrowseType != "" && $(this).val() == ''){   				if(isCategory == 'true'){				//from a category browse page				userResets.fromCategoryBrowseOrigin.categorySelect();    			}			//from a degree browse page			else {				userResets.fromDegreeBrowseOrigin.categorySelect();    				}	 	}	});	$('input[name="answersMap[14]"]').click(function(){		if( $('input[name="answersMap[14]"]:checked').val() == '0,14') {			$('.dynamicText\\[15\\]').show();		}else{			$('.dynamicText\\[15\\]').hide();		}	});		$('select.state').change(function() {	    if(this.value != "-223344") {	        $('select.country')[0].value = "0";	        phoneFields.setToUSAPhoneFields();	    } else {	        phoneFields.setToInternationalPhoneField();	    }	});		if(clientId == '25137') {		$('div.campusCopy').append("<div><a href=\"#\" onclick=\"popup.openWindow('http://www.aionline.edu/about-us/aio_320x240.swf',320,240);return false;\">Launch your creative career: view our video.</a></div>");	}});/*************************************** * One question at a time pagination **************************************///page load defaultsvar currQuestion = 0;var highestQuestion = 0;var questionBlocks=0;var graphLength;var page2Check=function(){	$('#errorMessage').remove();	var isValidZip = /(^\d{5}$)|(^\d{5}-\d{4}$)/.test($("input[name='zipCodeInput']").val());	if(isValidZip==false || $("input[name='zipCodeInput']").val()==''){		$("input[name='zipCodeInput']").parent('p').append('<p class="errorMessage" id="errorMessage">Please enter your ZIP code.</p>');		$("input[name='zipCodeInput']").focus();		return false;	} else {        $.ajax({            type	: 	'GET',             url		: 	'/dynamic/school-form/lookupCityStateListForZip',             data	: 	'zip='+$("input[name='zipCodeInput']").val(),            cache	:	false,            success	: 	function(jsonCityStateList){                        var jsonCityStateData = eval('(' + jsonCityStateList + ')');						$("select#state").val(jsonCityStateData.zips[0].stateName);						var i;               						for(i=0;i<jsonCityStateData.zips.length;i++){                            var createOption = document.createElement("option");						    console.log(jsonCityStateData.zips[i].city);                            createOption.value=jsonCityStateData.zips[i].city;                            createOption.innerHTML=jsonCityStateData.zips[i].city;                            $("#city").append(createOption);						}                        $("select#country").val("United States");						$("input#zipCode").attr("readonly","readonly");                        }        });     }	$("form:first").submit();	if($("input[name='emailAddress']").val()!=''){		if($('#errorMessage').parents('p').siblings('p.label').text()!='What is your email address?'){			$("input[name='emailAddressConfirmation']").val($("input[name='emailAddress']").val());			$('.headline > h1').text('Last step!');			$('#errorMessage').remove();			$('select').removeClass('errorBorder');			$('#zipCode').removeClass('errorBorder');			$('#zipCodeP1').remove();			$('#formPage2').hide();			$('#formPage3').show();			setDirectoryQuestions();		}	}};//remove hidden questions from blockvar removeHiddenQuestions=function(){	$('#dynamicContainer').append($('input[name="answersMap[13]"]').parents('div.questions'));	$('#dynamicContainer').append($('.dynamicText\\[15\\]'));	$('#questionBlock13').remove();	$('#questionBlock15').remove();	$('.questions').each(function(){		if($(this).css('display')=='none'){			$(this).parents('.questionBlockRow').remove();		}	});	questionBlocks=$('.questionBlockRow').length;	graphLength=118 / questionBlocks;};// form question paginationvar showQuestion=function(){	if(currQuestion==-1){		$('#formPage2').hide();		$('#formPage1').show();		$('.degrees').show();		currQuestion=0;	}else{		$('#progressLength').css('width',parseInt((currQuestion+1)*graphLength));		$('.questionBlockRow').hide();		$('.questionBlockRow:eq('+currQuestion+')').fadeIn('fast');		if(currQuestion >= 0){			$('#prevQuestion').fadeIn('fast');		}else{			$('#prevQuestion').hide();		}		if(currQuestion < highestQuestion){			$('#nextQuestion').fadeIn('fast');		}else{			$('#nextQuestion').hide();		}		if((currQuestion+1) === $('.questionBlockRow').length){			$('#continueRow').fadeIn('fast');		}else{			$('#continueRow').hide();		}		if($('.questionBlockRow:eq('+currQuestion+')').children('#militaryOptions').length > 0){			if($("input[name='militaryAffiliated']:checked").val()=='yes'){				$('#militaryOptions').show();				if($('#militaryAffiliation').val()=='0,7'){					$('#nextQuestion').hide();				}			}		}	}};// prev paginationvar showPrev=function(){	currQuestion--;	showQuestion();}//next paginationvar showNext=function(){	currQuestion++;	showQuestion();}$(function(){	// grab headline from content element to show when returning from page 3 	var initHeadline=$('.headline > h1').text();	$('#state').val('');	$('.blockQuestion').val('');	$('.blockRadio').attr('checked',false);	$('.page1GoBtn').click(function(){		if($('select#programCategoryGroups').val()!='' && $('select.programOfInterest').val()!=''){			$('.degrees').hide();			$('#formPage1').hide();			$('#formPage2').show();			removeHiddenQuestions();			showQuestion();		}else{			$("form:first").submit();		}	});		$('.page2GoBtn').click(page2Check);		$('#prevQuestionPage3').click(function(){		$('#formPage3').hide();		$('#formPage2').show();		$('.headline > h1').text(initHeadline);	});		$('#prevQuestion').click(showPrev);	$('#nextQuestion').click(showNext);	$('.blockRadio').bind(($.browser.msie ? "click" : "change"),function(){		currQuestion++;		if(highestQuestion < currQuestion){			highestQuestion=currQuestion;		}		showQuestion();	});		$('.blockQuestion').change(function(){		if($(this).val() != ''){			currQuestion++;			if(highestQuestion < currQuestion){				highestQuestion=currQuestion;			}			showQuestion();		}else{			$('#nextQuestion').hide();		}	});	$("form:first").bind("keydown", function(e) {  		if (e.keyCode == 13) {  			return false; //prevent default behaviour  		}  	});  	$("input[name='zipCodeInput']").keyup(function(e){		$("input[name='zipCode']").val($(this).val());		if(e.keyCode == 13) {			page2Check();		}	});	$("input[name='emailAddress']").keyup(function(e) {		if(e.keyCode == 13) {			page2Check();		}	});});