//Capella IRF degree value arrays
var defaultNote = "Please select...";
var default2ndTierNote = "Please select Study Area";
var default3rdTierNote = "Please select a Degree Level";



var dropdownArray = new Array();

//dropdownArray["###Tier1Values###"] = [
//	[###Tier2PossibleValues###,
//		["###Tier3PossibleValues###"]
//	],
//];

dropdownArray[""] = [
	[default3rdTierNote,
		[default3rdTierNote]
	]
];


dropdownArray["BS"] = [
	[defaultNote,
		[""]
	],
	["Business",
		[defaultNote,"Accounting","Business Administration","Finance","Human Resource Mgmt","Management and Leadership","Marketing","Project Management","Retail Management","Undecided"]
	],
	["Public Safety",
		[defaultNote,"PublicSafety: Criminal Justice","PublicSafety: Emergency Mgmt","Undecided"]
	],
	["Technology",
		[defaultNote,"General","Graphics and Multimedia","Network Technology","Project Management","Information Assurance and Security","Health Informatics","Software Architecture","Undecided"]
	],
	["Undecided",
		["Undecided"]
	]
];


dropdownArray["MBA"] = [
	[defaultNote,
		[""]
	],
	["Business",
		[defaultNote,"Finance","General Business","Marketing","Accounting","Health Care Management","Information Technology Management","Project Management","Human Resource Mgmt","Undecided"]
	]
];


dropdownArray["Online MS"] = [
	[defaultNote,
		[""]
	],
	["Business",
		[defaultNote,"General","Human Resource Mgmt","Leadership","Undecided"]
	],
	["Education",
		[defaultNote,"Curriculum and Instruction","Enrollment Management","Instr. Design-Online Learning","Leadership for Higher Ed","Leadership in Ed Admin","Postsecondary Adult Ed","Professional Studies in Ed","Reading and Literacy","Train & Perform Improve","K-12 Studies in Education","Undecided"]
	],
	["Human Services",
		[defaultNote,"Counseling Studies","General","Health Care Admin","Management of Non-Profit","MCF Counseling Therapy","Mental Health Counseling","School Counseling","Social and Community Services","Undecided"]
	],
	["Psychology",
		[defaultNote,"Clinical","Counseling","Educational Psychology","General","Industrial/Organizational","School","Sport","Eval, Research & Measurement","Leadership Coaching Psychology","Organizational Leader Dev","Undecided"]
	],
	["Public Safety",
		[defaultNote,"PublicSafety: Criminal Justice","PublicSafety: Emergency Mgmt","PublicSafety: Leadership","Undecided"]
	],
	["Public Health",
		[defaultNote,"PublHlth: Health Mgmt & Policy","PublHlth: Social & Behavr Sci","Undecided"]
	],
	["Technology",
		[defaultNote,"General","Health Information Mgmt","Information Security","Network Architecture and Design","Project Management/Leadership","System Design and Development","Undecided"]
	],
	["Undecided",
		["Undecided"]
	]
];


dropdownArray["PhD"] = [
	[defaultNote,
		[""]
	],
	["Business",
		[defaultNote,"General","Human Resource Mgmt","IT Management","Leadership","Management Education","Project Management","Undecided"]
	],
	["Education",
		[defaultNote,"Instr. Design-Online Learning","Leadership for Higher Ed","Leadership in Ed Admin","Postsecondary Adult Ed","Professional Studies in Ed","Train & Perform Improve","K-12 Studies in Education","Curriculum and Instruction","Special Education Leadership","Undecided"]
	],
	["Human Services",
		[defaultNote,"Counseling Studies","General","Health Care Admin","Management of Non-Profit","Social and Community Services","Undecided"]
	],
	["Psychology",
		[defaultNote,"Educational Psychology","General","Industrial/Organizational","Undecided"]
	],
	["Public Safety",
		[defaultNote,"PublicSafety: Criminal Justice","PublicSafety: Emergency Mgmt","PublicSafety: Leadership","Undecided"]
	],
	["Technology",
		[defaultNote,"IT Education","General","Information Security","Project Management","Undecided"]
	],
	["Undecided",
		["Undecided"]
	]
];


dropdownArray["PsyD"] = [
	[defaultNote,
		[""]
	],
	["Psychology",
		[defaultNote,"Clinical","Counseling","Undecided"]
	]
];

dropdownArray["EdS"] = [
	[defaultNote,
		[""]
	],
	["Education",
		[defaultNote,"Curriculum and Instruction","Leadership in Ed Admin K-12","Undecided"]
	]
];


dropdownArray["Certificate"] = [
	[defaultNote,
		[""]
	],
	["Business",
		[defaultNote,"Leadership","Human Resource Mgmt","PHR/SPHR Preparation","Undecided"]
	],
	["Human Services",
		[defaultNote,"Addiction Counseling","Diversity Studies","Marriage and Family Services","Professional Counseling","Social Work and Community Services","Criminal Justice","Health Care Admin","Management of Non-Profit","Undecided"]
	],
	["Psychology",
		[defaultNote,"School Psychology"]
	],
	["Technology",
		[defaultNote,"Information Security","Professional Project Management","Undecided"]
	],
	["Undecided",
		["Undecided"]
	]
];

dropdownArray["Post Masters Cert"] = [
	[defaultNote,
		[""]
	],
	["Education",
		[defaultNote,"College Teaching","Enrollment Mgmt","Undecided"]
	]
];


// Fade functions

// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1-m
// @author    Adam Michela
// @modified  Richard Livsey / 28/04/05
// @modiified for form validation Tom Wallace / 10/10/05

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (!o.id)
					o.id = 'fader_'+Math.floor(Math.random()*100);
		
				Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFF33";
		if (!to) to = this.get_bgcolor(id);

		if (this.timers[id])
			this.cancel_fade(id);
			
		this.timers[id] = new Array();
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		this.end = false;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			this.timers[id][this.timers[id].length] = setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		this.timers[id][this.timers[id].length] = setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	cancel_fade : function(id)
	{
		if (!this.timers[id])
			return;
		
		for (var i=0; i<this.timers[id].length; i++)
			clearTimeout(this.timers[id][i]);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.backgroundColor = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	},
	timers : new Array()
}

window.onload = function(){Fat.fade_all();}

function Querystring(qs) { 
	this.params = new Object()
	this.get=Querystring_get
	if (qs == null)
		qs=location.search.substring(1,location.search.length)
	if (qs.length == 0) return
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') 
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0]).toLowerCase();
		if (pair.length == 2)
			value = unescape(pair[1]).toLowerCase();
		else
			value = name.toLowerCase();
		this.params[name] = value.toLowerCase();
	}
}

function Querystring_get(key, default_) {
	if (default_ == null) default_ = null;
	var value=this.params[key]
	if (value==null) value=default_;
	return value
}

function highlightError(field)
{
	var p = window.location.pathname; //path and filename, but not domain
	var l = window.location.host; //domain name only, but not path or filename
	var qs = new Querystring();
	if((qs.get("fader") && qs.get("fader") == "on") ||  l.indexOf("capellauniversityonline") > -1|| l.indexOf("capellaphd.degreereview") > -1)
	{ //Check querystring to see if it contains "fader=on", or if url contains "capellauniversityonline" or "degreereview". if so, run highlight code
		if(document.getElementById("fadeError"))
		//if some other field is highlighted, clear it first before highlighting a new field
		{
			document.getElementById("fadeError").style.backgroundColor = "transparent";
			document.getElementById("fadeError").id = '';
		}
		//sets the id of the grandparent of the form field that has an error to "fadeError", 
		//thereby triggering the fader effect on the table row containing it
		field.parentNode.parentNode.id = 'fadeError';
		//setup default fade colors and allow querystring to overwrite default color settings
		//sfcolor = start fade color, best to make this the same as the background color of the form
		//efcolor = end fade color
		if(qs.get("sfcolor") != null){var sfcolor = qs.get("sfcolor");}
		else{var sfcolor = "F0F0F0";}
		if(qs.get("efcolor") != null){var efcolor = qs.get("efcolor");}
		else{var efcolor = "B4B4B4";}
		if(p.indexOf("pmg.web.sites.capella") > -1 || l.indexOf("capellauniversityonline") > -1){sfcolor = "E0D0B2";efcolor = "A89779";}
		if(l.indexOf("capellaphd.degreereview") > -1){sfcolor = "615B56";efcolor = "FFFFE4";}
		//run fade effect on any element with id fadeError
		//parameters are (id of element to fade, fps, duration of effect in milliseconds, starting color of effect, ending color of effect)
		Fat.fade_element("fadeError", 30, 1700, "#" +sfcolor, "#" +efcolor);
	}
}

// end fade functions
/* :::::: AUTO TAB FUNCTIONS :::::: */
var phone_field_length=0;

function TabNext(obj,event,len,next_field)
{
	if(document.all)
	{	
		var key_pressed = window.event.keyCode;
		
		if (event == "down")
		{
			phone_field_length=obj.value.length;
		}
		else if (event == "up")
		{
			if (key_pressed != 8 && key_pressed != 9 && key_pressed != 16 && key_pressed != 17 && key_pressed != 18 && key_pressed != 35 && key_pressed != 36 && key_pressed != 45 && key_pressed != 46 && key_pressed != 144)
			{
				if (obj.value.length != phone_field_length)
				{
					phone_field_length=obj.value.length;
					if (phone_field_length == len)
					{
						next_field.focus();
					}
				}
			}
			else
			{
				window.event.cancelBubble = true;
			}
		}
	}
	else
	{
		return;
	}
}

var frm = document.forms[0];

function detectCountry()
{//hide country code row on page load if value is usa or can
	if(frm.country_code[frm.country_code.selectedIndex].value == "USA" || frm.country_code[frm.country_code.selectedIndex].value == "CAN")
	{//hide phone country code and make sure state field is visible for USA/CAN
		document.getElementById("phoneCountryCodeRow").className = "hidden";
		document.getElementById("stateRow").className = "visible";
	}
	else if(frm.country_code[frm.country_code.selectedIndex].value != "") //if a country value exists, and it's not USA or CAN, hide the state field
		document.getElementById("stateRow").className = "hidden";
	else //else make sure phone country code is visible for non-USA/CAN countries
		document.getElementById("phoneCountryCodeRow").className = "visible";
}

function shiftFocus(this_field, next_field, length)
{
	var currentField = document.getElementById(this_field);
	var acode = currentField.value; 
	currentField.value = acode.replace(/\D/g, ''); //strip non numeric keys before checking count
	if(currentField.value.length ==  length)
	{
		document.getElementById(next_field).focus();
	}
}

/* :::::: FORM VALIDATION :::::: */

// Validator Object code
//___________________________________________
function AreaZipMismatch(str)
{
	if(confirm(str))
	{
		document.forms[0].areazipoverride.value='yes';
		document.forms[0].submit();
	}
}

function Validator()
{
	this.isValid = true;
	this.fullMatchProfanity = new Array('shit','piss','cunt','tits','ass');
	this.partialMatchProfanity = new Array('fuck','cocksucker','motherfucker','asshole');
	this.validNumbers = '0123456789';
	this.validPhoneCharacters = '0123456789';
	this.validZipCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ';
	this.validTextCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ';
}

new Validator();

function V_raiseError(message)
{
	if (this.isValid) alert(message);
	this.isValid = false;
}

function V_containsProfanity(field)
{
	for (var i=0; i<this.fullMatchProfanity.length; i++)
	{
		if (field.toLowerCase() == this.fullMatchProfanity[i]) return true;
	}
	for (var i=0; i<this.partialMatchProfanity.length; i++)
	{
		if (field.toLowerCase().indexOf(this.partialMatchProfanity[i]) > -1) return true;
	}
	return false;
}

function V_validateText(text, label)
{
	if (!this.isValid) return;
	if (text.value == '' || text.value.replace(/ /gi,'')=='')
	{
		this.raiseError('Please enter your ' + label + '.');
		text.value='';
		highlightError(text);
		text.focus();
	}
	else if (this.containsProfanity(text.value))
	{
		this.raiseError(label + ' must not contain profane content.');
		highlightError(text);
		text.select();
	}
}
// for text only like first and last name
function V_validateTextChars(text, label)
{
	if (!this.isValid) return;
	if (text.value == '' || text.value.replace(/ /gi,'')=='' || text.value.length < 2)
	{
		this.raiseError('Please enter your ' + label + '.');
		text.value='';
		highlightError(text);
		text.focus();
		
	}
	else if (this.containsProfanity(text.value))
	{
		this.raiseError(label + ' must not contain profane content.');
		highlightError(text);
		text.select();
	}
	else if (!this.isTextValid(text.value))
	{
		this.raiseError(label + ' contains invalid characters.');
		highlightError(text);
		text.select();
	}
}

function V_validatePhone(phone, label)
{
	if (!this.isValid) return;
	
	if (phone.value == '')
	{
		this.raiseError(label + ' phone number must not be blank.');
		highlightError(phone);
		phone.focus();
	}
	else if (phone.value.length < 7)
	{
		this.raiseError(label + ' phone number should have at least seven numbers.');
		highlightError(phone);
		phone.focus();
	}
	else if (!this.isPhoneNumeric(phone.value))
	{
		this.raiseError(label + ' phone number should have only numbers.');
		highlightError(phone);
		phone.focus();
	}
}

function V_validateZip(zip, label)
{
	if (!this.isValid) return;
	if (zip.value == '')
	{
		this.raiseError(label + ' must not be blank.');
		highlightError(zip);
		zip.focus();
	}
	else if (zip.value.length < 5)
	{
		this.raiseError(label + ' must be at least five characters.');
		highlightError(zip);
		zip.focus();
	}
	else if (!this.isZipValid(zip.value.toLowerCase()))
	{
		this.raiseError(label + ' contains invalid characters.');
		highlightError(zip);
		zip.select();
	}
}

function V_validateZipCanada(zip, label)
{
	if (!this.isValid) return;
	if (zip.value == '')
	{
		this.raiseError(label + ' must not be blank.');
		highlightError(zip);
		zip.focus();
	}
	else if (zip.value.length < 6)
	{
		this.raiseError(label + ' must be at least six characters.');
		highlightError(zip);
		zip.focus();
	}
	else if (!this.isZipValid(zip.value.toLowerCase()))
	{
		this.raiseError(label + ' contains invalid characters.');
		highlightError(zip);
		zip.select();
	}
}

function V_validateNumericOnly(myField, label)
{
	if (!this.isValid) return;
	if (myField.value == '')
	{
		this.raiseError(label + ' must not be blank.');
		highlightError(myField);
		myField.focus();
	}
	else if (myField.value.length < 4)
	{
		this.raiseError(label + ' must be four characters long.');
		highlightError(myField);
		myField.focus();
	}
}

function V_validateEmail(email, label)
{
	if (!this.isValid) return;
	if (email.value == '')
	{
		this.raiseError(label + ' must not be blank.');
		highlightError(email);
		email.focus();
	}
	// Email validation
	if (email.value != '')
	{
		var str = email.value;
		var instancecounter = 0;

		str += '';
		intAt = str.indexOf( '@', 1 );		// the "@"
		intDot = str.lastIndexOf( '.' );		// the last "."
		namestr = str.substring( 0, intAt );		// everything before the "@"
		domainstr = str.substring( intAt +1, str.length );		// everything after the "@"
		toplevelstr = str.substring( intDot +1, str.length);		// everything after the last "."
		
		if ((str.indexOf('test@') > -1) || (str.indexOf('@test.') > -1))
		{
			this.raiseError(label + ' appears to be invalid.');
			highlightError(email);
			email.select();
		}
		
		if ((str.indexOf(" ")!=-1) || (intAt == -1) || (intDot == -1 ) || (namestr.length == 0) || (domainstr.length == 0) || (intAt > intDot) || (domainstr.indexOf(".") <= 0) || (toplevelstr.length <= 1))
		{
			this.raiseError(label + ' appears to be invalid.');
			highlightError(email);
			email.select();
		} 
		else
		{
			// iterate through email address checking for
			// more than 1 @ sysmbol, or none at all
			for ( i = 0; i < str.length; i++ )
			{
				if ((str.substring(i,i+1)) == "@" )
				{
					instancecounter = instancecounter + 1;
				}
			}
			// Check to see if we have none, or more than one @ symbol
			if ((instancecounter > 1) || (instancecounter == 0 ))
			{
				this.raiseError(label + ' appears to be invalid.');
				highlightError(email);
				email.select();
			}
		}
	}
}

function V_isNumeric(field)
{
	for (var i=0; i<field.length; i++)
	{
		if (this.validNumbers.indexOf(field.charAt(i),0) == -1) return false;
	}
	return true;
}

function V_isPhoneNumeric(field)
{
	for (var i=0; i<field.length; i++)
	{
		if (this.validPhoneCharacters.indexOf(field.charAt(i),0) == -1) return false;
	}
	return true;
}

function V_isZipValid(field)
{
	for (var i=0; i<field.length; i++)
	{
		if (this.validZipCharacters.indexOf(field.charAt(i),0) == -1) return false;
	}
	return true;
}

function V_isTextValid(field)
{
	for (var i=0; i<field.length; i++)
	{
		if (this.validTextCharacters.indexOf(field.charAt(i),0) == -1) return false;
	}
	return true;
}

Validator.prototype.raiseError = V_raiseError;
Validator.prototype.validateText = V_validateText;
Validator.prototype.validateTextChars = V_validateTextChars;
Validator.prototype.validatePhone = V_validatePhone;
Validator.prototype.validateZip = V_validateZip;
Validator.prototype.validateZipCanada = V_validateZipCanada;
Validator.prototype.validateNumericOnly = V_validateNumericOnly;
Validator.prototype.isNumeric = V_isNumeric;
Validator.prototype.isZipValid = V_isZipValid;
Validator.prototype.isTextValid = V_isTextValid;
Validator.prototype.isPhoneNumeric = V_isPhoneNumeric;
Validator.prototype.validateEmail = V_validateEmail;
Validator.prototype.containsProfanity = V_containsProfanity;


//---------- custom functions ----------

function checkDegree()
{
	switch(frm.program_code[frm.program_code.selectedIndex].value)
	{
		case '368':
		case '370':
		case '373':
		case '622':
			alert('Thank you for your interest in Capella University.  The specialization you have selected is for current K-12 professionals interested in extending their education with a graduate degree.  Please be aware that this specialization does not lead to initial teacher licensure.');
			break;
		default:
			break;
	}
}

function checkCountry()
{
	if (frm.country_code[frm.country_code.selectedIndex].value != '' && frm.country_code[frm.country_code.selectedIndex].value != 'USA' && frm.country_code[frm.country_code.selectedIndex].value != 'CAN')
	{
		document.getElementById("stateRow").className = 'hidden';
		document.getElementById("phoneCountryCodeRow").className = 'visible';
	}
	else
	{
		document.getElementById("stateRow").className = 'visible';
		document.getElementById("phoneCountryCodeRow").className = 'hidden';
		frm.phone_country_code.value = '1';
	}
}

function updateCapellaDegrees()
{
	var schoolOfInterest = document.getElementById("institution");
	var degreeProgram = document.getElementById("program_code");	
	var degreeProgramLen = degreeProgram.length;
	
	frm.program_code.disabled = false;
	
	// empty list	
	for(var i = 0; i <= degreeProgramLen; i++)
	{
		degreeProgram.options[0] = null;
	}
	
	//create new list
	switch (schoolOfInterest[schoolOfInterest.selectedIndex].value)
	{
		// Business selected
		case '1':
			var arrCapellaDegreeBusiness = ["Select one"];
			arrCapellaDegreeBusiness = arrCapellaDegreeBusiness.concat(arrCapellaDegree0);
			for (var i = 0; i < arrCapellaDegreeBusiness.length; i++)
			{
				var pipeLocation = arrCapellaDegreeBusiness[i].indexOf('|')
				var curDegreeCode = arrCapellaDegreeBusiness[i].substring(0, pipeLocation)
				var curDegree = arrCapellaDegreeBusiness[i].substring(pipeLocation + 1, arrCapellaDegreeBusiness[i].length)
				
				degreeProgram.options[i] = new Option(curDegree, curDegreeCode)
			}
			break;
		// Technology selected
		case '2':
			var arrCapellaDegreeTechnology = ["Select one"];
			arrCapellaDegreeTechnology = arrCapellaDegreeTechnology.concat(arrCapellaDegree1);
			for (var i = 0; i < arrCapellaDegreeTechnology.length; i++)
			{
				var pipeLocation = arrCapellaDegreeTechnology[i].indexOf('|')
				var curDegreeCode = arrCapellaDegreeTechnology[i].substring(0, pipeLocation)
				var curDegree = arrCapellaDegreeTechnology[i].substring(pipeLocation + 1, arrCapellaDegreeTechnology[i].length)
				
				degreeProgram.options[i] = new Option(curDegree, curDegreeCode)
			}
			break;
		// Education selected
		case '3':
			var arrCapellaDegreeEducation = ["Select one"];
			arrCapellaDegreeEducation = arrCapellaDegreeEducation.concat(arrCapellaDegree2);
			for (var i = 0; i < arrCapellaDegreeEducation.length; i++)
			{
				var pipeLocation = arrCapellaDegreeEducation[i].indexOf('|')
				var curDegreeCode = arrCapellaDegreeEducation[i].substring(0, pipeLocation)
				var curDegree = arrCapellaDegreeEducation[i].substring(pipeLocation + 1, arrCapellaDegreeEducation[i].length)
				
				degreeProgram.options[i] = new Option(curDegree, curDegreeCode)
			}
			break;
		// Psychology selected
		case '4':
			var arrCapellaDegreePsychology = ["Select one"];
			arrCapellaDegreePsychology = arrCapellaDegreePsychology.concat(arrCapellaDegree3);
			for (var i = 0; i < arrCapellaDegreePsychology.length; i++)
			{
				var pipeLocation = arrCapellaDegreePsychology[i].indexOf('|')
				var curDegreeCode = arrCapellaDegreePsychology[i].substring(0, pipeLocation)
				var curDegree = arrCapellaDegreePsychology[i].substring(pipeLocation + 1, arrCapellaDegreePsychology[i].length)
				
				degreeProgram.options[i] = new Option(curDegree, curDegreeCode)
			}
			break;
		// Human Services selected
		case '5':
			var arrCapellaDegreeHuman = ["Select one"];
			arrCapellaDegreeHuman = arrCapellaDegreeHuman.concat(arrCapellaDegree4);
			for (var i = 0; i < arrCapellaDegreeHuman.length; i++)
			{
				var pipeLocation = arrCapellaDegreeHuman[i].indexOf('|')
				var curDegreeCode = arrCapellaDegreeHuman[i].substring(0, pipeLocation)
				var curDegree = arrCapellaDegreeHuman[i].substring(pipeLocation + 1, arrCapellaDegreeHuman[i].length)
				
				degreeProgram.options[i] = new Option(curDegree, curDegreeCode)
			}
			break;
		// unknown selection
		default:
			degreeProgram.options[0] = new Option('Select one', '')
			degreeProgram.disabled = true;
			break;
	}	
}

function setSelectedDegree()
{
	var schoolOfInterest = document.getElementById("education_level");
	var degreeProgram = document.getElementById("program_code");	
	var degreeProgramLen = degreeProgram.length;
	
	if (schoolOfInterest[schoolOfInterest.selectedIndex].value != '' && schoolOfInterest[schoolOfInterest.selectedIndex].value != null && frm.selectedDegree != '' && frm.selectedDegree != null)
	{
		var theDegree = frm.selectedDegree.value;
		for (var i = 0; i < degreeProgramLen; i ++)
		{
			if (degreeProgram.options[i].value == theDegree)
			{
				degreeProgram.options[i].selected = true;
				break;
			}
		}
	}
}

function updateStudyArea(hashIndx,f)
{
	var objTier2 = f.school;
	var objTier3 = f.specialization;
	objTier2.options.length = 0;
	objTier3.options.length = 0;

	for (j=0; j<dropdownArray[hashIndx].length; j++){
		var strOptVal = dropdownArray[hashIndx][j][0];
		if (strOptVal.indexOf("Please") != -1){
			strOptVal = "";//set value to null for validation script
		}
		else if (strOptVal.indexOf("Public Safety") != -1 && hashIndx == "BS"){
			strOptVal = "Technology";//set value = Technology cause technically school of PS can't exist and HS doesn't exist in undergrad
		}
		else if (strOptVal.indexOf("Public Safety") != -1 || strOptVal.indexOf("Public Health") != -1){//Everything other than BS
			strOptVal = "Human Services";//set value = HS cause technically school of PS can't exist
		}
		objTier2.options[j] = new Option(dropdownArray[hashIndx][j][0],strOptVal);
	}
	if (hashIndx == ""){
		objTier3.options[0] = new Option(default3rdTierNote,"");
	}
	else{
		objTier3.options[0] = new Option(default2ndTierNote,"");
	}
}

function updateSpecialization(nestedIndx,f)
{
	if ((nestedIndx == "Human Services" || nestedIndx == "Technology") && f.school.options[f.school.selectedIndex].text == "Public Safety"){
		nestedIndx = "Public Safety";//has to switch to get the right values out of array
	}
	else if (nestedIndx == "Human Services" && f.school.options[f.school.selectedIndex].text == "Public Health"){
		nestedIndx = "Public Health";//has to switch to get the right values out of array
	}
	var objTier1 = f.program;
	var objTier3 = f.specialization;
	var firstDropDown = objTier1.options[objTier1.selectedIndex].value;
	objTier3.options.length = 0;

	for (k=0; k<dropdownArray[firstDropDown].length; k++){
		if (dropdownArray[firstDropDown][k][0] == nestedIndx){
			for (m=0; m<dropdownArray[firstDropDown][k][1].length; m++){
				var strOptVal = dropdownArray[firstDropDown][k][1][m];
				if (strOptVal.indexOf("Please") != -1){
					strOptVal = "";//set value to null for validation script
				}
				objTier3.options[m] = new Option(dropdownArray[firstDropDown][k][1][m],strOptVal);
			}
			break;
		}
	}
}

function CkEduMisMatch()
{
	var progD = frm.program.options[frm.program.selectedIndex].value;
	var highEdVal = frm.education_level.options[frm.education_level.selectedIndex].value;
	var msg = "Your highest level of education may not meet entrance requirements\nfor the degree you are seeking.\n\nPlease verify your selection before submitting this form.";

	if (progD != "BS" && progD != "Certificate" && highEdVal != ""){
		var limitLevel1 = "1::2::3::4::5::6::7::8::9::";
		var limitLevel2 = limitLevel1 + "10::";

		if ((progD == "Online MS" || progD == "MBA") && limitLevel1.indexOf(highEdVal + "::") > -1){
			alert(msg);
			FlagAlert(frm.program);
			FlagAlert(frm.education_level);
		}
		else if ((progD == "PhD" || progD == "PsyD") && limitLevel2.indexOf(highEdVal + "::") > -1){
			alert(msg);
			FlagAlert(frm.program);
			FlagAlert(frm.education_level);
		}
	}
}

function FlagAlert(objF){
	objF.focus();
	objF.style.backgroundColor = "#ffcccc";
}

function populateDegreeSelection()
{
	if(capellaProgram != null && capellaProgram != '' && capellaSchool != null && capellaSchool != '' && capellaSpecialization != null && capellaSpecialization != '')
	{
		var f = document.uData;
	
		for(var i=0; i<f.program.length; i++)
		{
			if(f.program.options[i].value == capellaProgram)
			{
				f.program.options[i].selected = true;
			}
		}
		
		updateStudyArea(f.program.options[f.program.selectedIndex].value, f);
		
		for(var j=0; j<f.school.length; j++)
		{
			if(f.school.options[j].value == capellaSchool)
			{
				f.school.options[j].selected = true;
			}
		}
		
		updateSpecialization(f.school.options[f.school.selectedIndex].value, f);
		
		for(var x=0; x<f.specialization.length; x++)
		{
			if(f.specialization.options[x].value == capellaSpecialization)
			{
				f.specialization.options[x].selected = true;
			}
		}
	}
}

function RequireAge()
{
	if (frm.education_level[frm.education_level.selectedIndex].value == '1' ||frm.education_level[frm.education_level.selectedIndex].value == '2' || frm.education_level[frm.education_level.selectedIndex].value == '3' || frm.education_level[frm.education_level.selectedIndex].value == '4' || frm.education_level[frm.education_level.selectedIndex].value == '5')
		return true;
	else
		return false;
}

function showAge()
{
	if(RequireAge())
		document.getElementById('ageRow').className = 'visible';
	else
		document.getElementById('ageRow').className = 'hidden';
}

//---------- form validation function ----------
function VerifyAndSubmitStep1(strGoToStep2){
	var degID = 0;
	var v = new Validator();

	// verify first name is not blank
	v.validateTextChars(frm.first_name, 'First Name');
	
	// verify last name is not blank
	v.validateTextChars(frm.last_name, 'Last Name');

	//verify country
	if (frm.country_code[frm.country_code.selectedIndex].value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please select your country.');
			highlightError(frm.country_code);
			frm.country_code.focus();
		}
	}
	else if (frm.country_code[frm.country_code.selectedIndex].value != 'USA' && frm.country_code[frm.country_code.selectedIndex].value != 'CAN')
	{
		checkCountry();
	}
	else
	{
		// verify state is not blank	
		
		if (frm.state_code[frm.state_code.selectedIndex].value == '')
		{
			if (v.isValid)
			{
				v.raiseError('Please select your state.');
				highlightError(frm.state_code);
				frm.state_code.focus();
			}
		}
	}
	
	// verify phone fields
	//verify phone_country_code
	if (frm.phone_country_code.value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please enter your phone country code');
			highlightError(frm.phone_country_code);
			frm.phone_country_code.focus();
		}
	}
	
	// verify home area code
	if (frm.h_area_code.value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please enter your home area code');
			highlightError(frm.h_area_code);
			frm.h_area_code.focus();
		}
	}
	
	if (frm.h_area_code.value != '' && frm.h_area_code.value.length < 3)
	{
		if (v.isValid)
		{
			v.raiseError('Home area code must have 3 digits');
			highlightError(frm.h_area_code);
			frm.h_area_code.focus();
		}
	}
	
	if (frm.h_area_code.value != '' && frm.h_area_code.value.length == 3 && !v.isPhoneNumeric(frm.h_area_code.value))
	{
		if (v.isValid)
		{
			v.raiseError('Home area code should contain only numbers.');
			highlightError(frm.h_area_code);
			frm.h_area_code.focus();
		}
	}
	if (frm.h_area_code.value == '111' || frm.h_area_code.value == '123' || frm.h_area_code.value == '222' || frm.h_area_code.value == '333' || frm.h_area_code.value == '444' || frm.h_area_code.value == '555' || frm.h_area_code.value == '666' || frm.h_area_code.value == '777' || frm.h_area_code.value == '888' || frm.h_area_code.value == '999' || frm.h_area_code.value == '911' || frm.h_area_code.value == '000' || frm.h_area_code.value == '098')
	{
		if (v.isValid)
		{
			v.raiseError('Home area code apears to be invalid.');
			highlightError(frm.h_area_code);
			frm.h_area_code.focus();
		}
	}
	
	// verify home phone number
	if (frm.h_phone.value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please enter your home phone number');
			highlightError(frm.h_phone);
			frm.h_phone.focus();
		}
	}
	
	if (frm.h_phone.value != '' && frm.h_phone.value.length < 7)
	{
		if (v.isValid)
		{
			v.raiseError('Home phone number must have 7 digits');
			highlightError(frm.h_phone);
			frm.h_phone.focus();
		}
	}
	
	if (frm.h_phone.value != '' && frm.h_phone.value.length >= 7 && !v.isPhoneNumeric(frm.h_phone.value))
	{
		if (v.isValid)
		{
			v.raiseError('Home phone number should contain only numbers.');
			highlightError(frm.h_phone);
			frm.h_phone.focus();
		}
	}
	if (frm.h_phone.value.replace(/-/gi,'')=='1111111' || frm.h_phone.value.replace(/-/gi,'')=='1234567' || frm.h_phone.value.replace(/-/gi,'')=='4567890' || frm.h_phone.value.replace(/-/gi,'')=='0000000' || frm.h_phone.value.replace(/-/gi,'')=='2222222' || frm.h_phone.value.replace(/-/gi,'')=='3333333' || frm.h_phone.value.replace(/-/gi,'')=='4444444' || frm.h_phone.value.replace(/-/gi,'')=='5555555' || frm.h_phone.value.replace(/-/gi,'')=='6666666' || frm.h_phone.value.replace(/-/gi,'')=='7777777' || frm.h_phone.value.replace(/-/gi,'')=='8888888' || frm.h_phone.value.replace(/-/gi,'')=='9999999' || frm.h_phone.value.replace(/-/gi,'')=='00000000' || frm.h_phone.value.replace(/-/gi,'')=='000000')
	{
		if (v.isValid)
		{
			v.raiseError('Home phone number appears to be invalid.');
			highlightError(frm.h_phone);
			frm.h_phone.focus();
		}
	}
	if (frm.h_phone.value.indexOf('000') == 0 || frm.h_phone.value.indexOf('911') == 0 || frm.h_phone.value.indexOf('555') == 0 || frm.h_phone.value.indexOf('1234') == 0 || frm.h_phone.value.indexOf('0123') == 0)
	{
		if (v.isValid)
		{
			v.raiseError('Home phone number appears to be invalid.');
			highlightError(frm.h_phone);
			frm.h_phone.focus();
		}
	}

	//validate best_time_to_call field
	if (frm.best_time_to_call[frm.best_time_to_call.selectedIndex].value == '') {
	    if (v.isValid) {
	        v.raiseError('Please select the best time to call.');
	        highlightError(frm.best_time_to_call);
	        frm.best_time_to_call.focus();
	    }
	}
	
	// verify e-mail address is not blank and verify valid format
	v.validateEmail(frm.email, 'Email Address');
	
	//verify email confirm is not blank and that it has the same value as email
	if (frm.email_confirm.value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please confirm your e-mail address');
			highlightError(frm.email_confirm);
			frm.email_confirm.focus();
		}
	}
	
	else
	{
		if (frm.email_confirm.value != frm.email.value)
		{
			if (v.isValid)
			{
				v.raiseError('E-mail addresses do not match');
				highlightError(frm.email_confirm);
				frm.email_confirm.focus();
			}
		}
	}
	
	// verify program
	if (frm.program[frm.program.selectedIndex].value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please indicate your degree level.');
			highlightError(frm.program);
			frm.program.focus();
		}
	}
	
	// verify school
	if (frm.school[frm.school.selectedIndex].value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please indicate your area of study.');
			highlightError(frm.school);
			frm.school.focus();
		}
	}
	
	// verify specialization
	if (frm.specialization[frm.specialization.selectedIndex].value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please indicate your specialization.');
			highlightError(frm.specialization);
			frm.specialization.focus();
		}
	}
	
	//verify start date
	if (frm.month_completion_date[frm.month_completion_date.selectedIndex].value == '' || frm.year_completion_date[frm.year_completion_date.selectedIndex].value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please indicate your projected start date.');
			highlightError(frm.month_completion_date);
			frm.month_completion_date.focus();
		}
	}
	
	//verify that start date is in the future
	var date = new Date();
	var currentMonth = (date.getMonth() +1);
	var currentYear = date.getFullYear();
	if(frm.year_completion_date[frm.year_completion_date.selectedIndex].value == currentYear && frm.month_completion_date[frm.month_completion_date.selectedIndex].value <= currentMonth)
	{
		v.raiseError('Please select a future date.');
		highlightError(frm.month_completion_date);
		frm.month_completion_date.focus();
	}
	
	// verify education_level
	if (frm.education_level[frm.education_level.selectedIndex].value == '')
	{
		if (v.isValid)
		{
			v.raiseError('Please indicate your highest level of education.');
			highlightError(frm.education_level);
			frm.education_level.focus();
		}
	}
	
	//verify age if required
	if(RequireAge())
	{
		//make sure age row is visible (form errors can cause it to be invisible, but still required)
		if(document.getElementById('ageRow').className != 'visible')
			document.getElementById('ageRow').className = 'visible';
		if(frm.age_21[frm.age_21.selectedIndex].value == '')
		{
			if (v.isValid)
			{
				v.raiseError('Please indicate your age.');
				highlightError(frm.age_21);
				frm.age_21.focus();
			}
		}
	}	
		
	if (v.isValid) 
	{
		for (var i=0; i<document.links.length; i++)
		{
			if (document.links[i].href.toLowerCase() == 'javascript:validateform();')
			{
				document.links[i].href = '#';
				break;
			}
		}
		
		frm.submit();
	}
}

function VerifyAndSubmitStep2()
{
	var v = new Validator();

	//if one of the address fields is filled in, validate the others
	if (v.isValid) 
	{
		if(frm.address)//first check to see if field exists (only visible if user selects USA/CAN in step 1)
		{
			if((frm.address2.value != '' || frm.city.value != '') && frm.address.value == '')
			{
				v.raiseError('Please enter your address.');
				highlightError(frm.address);
				frm.address.focus();
			}
			if((frm.address.value != '' || frm.address2.value != '') && frm.city.value == '')
			{
				v.raiseError('Please enter your city.');
				highlightError(frm.city);
				frm.city.focus();
			}
		}
	}
	
	if (v.isValid) 
	{
		for (var i=0; i<document.links.length; i++)
		{
			if (document.links[i].href.toLowerCase() == 'javascript:validateform();')
			{
				document.links[i].href = '#';
				break;
			}
		}
		frm.submit();
	}
}	
	

