var ie = false;
var select_html = '<option value="">- select -</option>';
var education_level_priorities = new Array;
var program_data;
var last_state_group;

// Establish onload event.
	old_onload = window.onload;
	window.onload = function()
	{
		// IE gets wordwrapped options in select boxes.
		if (document.uniqueID && window.createPopup) 
		{ ie = true; }

		if (typeof(old_onload) == 'function') 
		{ old_onload(); }

		if (typeof(form_name) != 'undefined') 
		{
			switch (form_name) 
			{
				case '2step':
					load2StepForm();
				break;

				case '1step':
				case '1stepWithSpec':
					load1StepForm();
				break;

				case 'tec':
					loadTecForm();
				break;
			}
		}
	}

function load2StepForm()
{
	if (form_step == 1) 
	{
		$('#degree_program option:first').text('loading...');
		// Load education levels and education level priority table.
			$.ajax({
				url: '/global/cdm-server.php?path=http://ulm.datamark.com/cdm/clients/WAL0006/educationlevels',
				type: 'get',
				dataType: 'json',
				timeout: 5000,
				success: function(data)
				{
					var options = select_html;
					var edu = data.body;
					var url = "international.waldenu.edu";
					var site = String(window.location.hostname);
					for (var i = 0; i < edu.length; i++) 
					{
						if ( site != url || edu[i].EducationLevelCode != "HS" )
						{
							if (edu[i].EducationLevelCode != "SOMECOL" ) {
								education_level_priorities[edu[i].EducationLevelCode] = edu[i].EducationLevelPriority;
							}
						}
					}
					
					$('#education_level_code option:first').text('loading...');
				}
			});


		// Load program data.
			$.ajax({
				url: '/global/cdm-server.php?path=http://ulm.datamark.com/cdm/campuses/' + campus_code + '/categories/programs',
				type: 'get',
				dataType: 'json',
				timeout: 5000,
				success: function(data)
				{
					program_data = data;
					$('#degree_program option:first').text('-select-');
					
					$('#education_level_code option:first').text('-select-');
					$('#education_level_code').attr('disabled', false);
					
					if ( $('#education_level_code').val() != "" )
					{ $('#education_level_code').trigger('change'); }
				}
			});
	}
	else 
	{
		// Select Foreign Country by default in the state drop down for international.waldenu.edu
			if (document.location.href.indexOf('international.waldenu.edu') != -1)
			{
				// This will force the states drop down to populate
					$('#country').val('USA');
					$('#country').trigger('change');

					$('#state').val('FC');
					$('#state').trigger('change');

				// Set the country drop down back to 
					document.getElementById('country').selectedIndex = 0;
			}
			else 
			{
				// All microsites except for international.waldenu.edu should select USA by default in the country drop down
					$('#country').val('USA');
					$('#country').trigger('change');
			}

	}
}

function load1StepForm()
{
	// Load program data.
		$.ajax({
			url: service_url + '/cdm/campuses/' + campus_code + '/categories/programs',
			type: 'get',
			dataType: 'json',
			timeout: 5000,
			success: function(data)
			{
				program_data = data;
				loadPrograms();
			}
		});
}

function loadTecForm()
{
	if (form_step == 2) 
	{
		$('#country').val('USA');
		$('#country').trigger('change');
	}
}

function loadOption2 () 
{
	var education_level = $('#education_level_code').val();
	var education_level_priority = education_level_priorities[education_level];
	var options;
	var cat = program_data.body;

	for (var i = 0, ii = cat.length; i < ii; i++) 
	{
		if ( cat[i].CategoryName != "School of Public Policy & Administration Certificate Programs" ) 
		{
			var option = '';
			var pro_count = 0;
			var added_programs = [""];

			if (typeof(cat[i].Programs) != 'undefined' ) 
			{
				var pro = cat[i].Programs;
				
				for (var j = 0, jj = pro.length; j < jj; j++) 
				{
					if (education_level_priority >= pro[j].EducationLevelRange['MinEducationLevelPriority'] ) 
					{
						pro_count++;
						
						for ( var k=0, kk = added_programs.length; k<kk; k++ )
						{ 
							var found = false;
							
							if ( added_programs[k] == pro[j].ProgramName)
							{  found = true; }
						}
												
						if ( !found )
						{ 
							added_programs[added_programs.length] = pro[j].ProgramName; 
							option += '<option class="' + pro[j].ProgramName + '" value="' + pro[j].ProgramName + '" title="' + pro[j].ProgramName + '">' + pro[j].ProgramName + '</option>';
						}
					}
				}
			}

			// Only show the category if there are programs available.
				if (pro_count > 0 ) 
				{ option = '<optgroup title="' + cat[i].CategoryName + '" label="' + cat[i].CategoryName + '">' + option; }
				
				option += '</optgroup>';
				options += option;
		}
	}

	// Load options and enable/disable.
	$('#degree_program2').html(select_html + options);
	
	if ( $('#program_code option').size() == 2 )
	{ $('#degree_program2 option[value="'+$('#degree_program').val()+'"]').parent().remove(); }
	
	$('#option2').show();
}

function loadOption3 () 
{
	var education_level = $('#education_level_code').val();
	var education_level_priority = education_level_priorities[education_level];
	var options;
	var cat = program_data.body;

	for (var i = 0, ii = cat.length; i < ii; i++) 
	{
		if ( cat[i].CategoryName != "School of Public Policy & Administration Certificate Programs" ) 
		{
			var option = '';
			var pro_count = 0;
			var added_programs = [""];

			if (typeof(cat[i].Programs) != 'undefined') 
			{
				var pro = cat[i].Programs;
				
				for (var j = 0, jj = pro.length; j < jj; j++) 
				{
					if (education_level_priority >= pro[j].EducationLevelRange['MinEducationLevelPriority']) 
					{
						pro_count++;
						
						for ( var k=0, kk = added_programs.length; k<kk; k++ )
						{ 
							var found = false;
							
							if ( added_programs[k] == pro[j].ProgramName)
							{  found = true; }
						}
						
						if ( !found )
						{ 
							added_programs[added_programs.length] = pro[j].ProgramName; 
							option += '<option class="' + pro[j].ProgramName + '" value="' + pro[j].ProgramName + '" title="' + pro[j].ProgramName + '">' + pro[j].ProgramName + '</option>';
						}
					}
				}
			}

			// Only show the category if there are programs available.
				if (pro_count > 0) 
				{ option = '<optgroup title="' + cat[i].CategoryName + '" label="' + cat[i].CategoryName + '">' + option; }
				
				option += '</optgroup>';
				options += option;
		}
	}

	// Load options and enable/disable.
	$('#degree_program3').html(select_html + options);
	
	if ( $('#program_code2 option').size() == 2 )
	{ $('#degree_program3 option[value="'+$('#degree_program2').val()+'"]').parent().remove(); }
	
	$('#option3').show();
}

function loadPrograms(s)
{
	if (typeof(form_name) != 'undefined' && (form_name == '1step' || form_name == '1stepWithSpec')) 
	{ var education_level_priority = 99; }
	else 
	{
		var education_level = s.options[s.selectedIndex].value;
		var education_level_priority = education_level_priorities[education_level];
	}

	var options;
	var cat = program_data.body;

	for (var i = 0, ii = cat.length; i < ii; i++) 
	{
		if ( cat[i].CategoryName != "School of Public Policy & Administration Certificate Programs" ) 
		{
			var option = '';
			var pro_count = 0;
			var added_programs = [""];

			if (typeof(cat[i].Programs) != 'undefined') 
			{
				var pro = cat[i].Programs;
				
				for (var j = 0, jj = pro.length; j < jj; j++) 
				{
					if (education_level_priority >= pro[j].EducationLevelRange['MinEducationLevelPriority']) 
					{
						pro_count++;
						
						for ( var k=0, kk = added_programs.length; k<kk; k++ )
						{ 
							var found = false;
							
							if ( added_programs[k] == pro[j].ProgramName)
							{  found = true; }
						}
						
						if ( !found )
						{ 
							added_programs[added_programs.length] = pro[j].ProgramName; 
							option += '<option class="' + pro[j].ProgramName + '" value="' + pro[j].ProgramName + '" title="' + pro[j].ProgramName + '">' + pro[j].ProgramName + '</option>';
						}
					}
				}
			}

			// Only show the category if there are programs available.
				if (pro_count > 0) 
				{ option = '<optgroup title="' + cat[i].CategoryName + '" label="' + cat[i].CategoryName + '">' + option; }
				
				option += '</optgroup>';
				options += option;
		}
	}

	// Load options and enable/disable.
		$('#degree_program').html(select_html + options);
		
		if (options) 
		{
			if (typeof(purl_program) != 'undefined' && purl_program) 
			{
				$('#degree_program').val(purl_program);
				$('#degree_program').trigger('change');
			}
			
			$('#degree_program').attr('disabled', false);
		}
		else
		{ $('#degree_program').attr('disabled', true); }
}

function loadSpecializations(s)
{
	var opt = s.options[s.selectedIndex];
	var category = opt.parentNode.title;
	var program = opt.value;
	var options = '';
	var cat = program_data.body;
	
	for (var i = 0, ii = cat.length; i < ii; i++) 
	{
		if (cat[i].CategoryName == category) 
		{
			var pro = cat[i]['Programs'];
			
			for (var j = 0, jj = pro.length; j < jj; j++) 
			{
				if (pro[j].ProgramName == program) 
				{
					options += '<option value="' + pro[j].ProgramCode + '">' + pro[j].Emphasis + '</option>';
				}
			}
		}
	}

	// Load options and show/hide.
		$('#program_code').html(select_html + options);

	if (typeof(form_name) != 'undefined' && form_name == '1step') 
	{ $('#program_code')[0].selectedIndex = 1; }
	else 
	{
		if (options) 
		{ $('#specialization').show(); }
		else 
		{ $('#specialization').hide(); }

		// These rules are regexes to be more accomodating of program name changes.
			(program.match(/bachelor/i) || program.match(/b\.s\./i)) ? $('#hidden-bachelor').show() : $('#hidden-bachelor').hide();
			(program.match(/\(m\.s\.\) in education/i) || program.match(/doctor of education/i)) ? $('#hidden-education').show() : $('#hidden-education').hide();
			(program.match(/engineering/i)) ? $('#hidden-engineering').show() : $('#hidden-engineering').hide();
			(program.match(/nursing/i)) ? $('#hidden-nursing').show() : $('#hidden-nursing').hide();
	}
}

function loadSpecializations2 (s)
{
	var opt = s.options[s.selectedIndex];
	var category = opt.parentNode.title;
	var program = opt.value;
	var options = '';
	var cat = program_data.body;
	
	for (var i = 0, ii = cat.length; i < ii; i++) 
	{
		if (cat[i].CategoryName == category) 
		{
			var pro = cat[i]['Programs'];
			
			for (var j = 0, jj = pro.length; j < jj; j++) 
			{
				if (pro[j].ProgramName == program && pro[j].ProgramCode != $('#program_code').val() ) 
				{
					options += '<option value="' + pro[j].ProgramCode + '">' + pro[j].Emphasis + '</option>';
				}
			}
		}
	}

	// Load options and show/hide.
		$('#program_code2').html(select_html + options);

	if (typeof(form_name) != 'undefined' && form_name == '1step') 
	{ $('#program_code2')[0].selectedIndex = 1; }
	else 
	{
		if (options) 
		{ $('#specialization2').show(); }
		else 
		{ $('#specialization2').hide(); }

		// These rules are regexes to be more accomodating of program name changes.
			if (program.match(/bachelor/i) || program.match(/b\.s\./i)) { $('#hidden-bachelor').show(); }
			if (program.match(/\(m\.s\.\) in education/i) || program.match(/doctor of education/i)) { $('#hidden-education').show(); }
			if (program.match(/engineering/i)) { $('#hidden-engineering').show(); }
			if (program.match(/nursing/i)) { $('#hidden-nursing').show(); }
	}
}

function loadSpecializations3 (s)
{
	var opt = s.options[s.selectedIndex];
	var category = opt.parentNode.title;
	var program = opt.value;
	var options = '';
	var cat = program_data.body;
	
	for (var i = 0, ii = cat.length; i < ii; i++) 
	{
		if (cat[i].CategoryName == category) 
		{
			var pro = cat[i]['Programs'];
			
			for (var j = 0, jj = pro.length; j < jj; j++) 
			{
				if (pro[j].ProgramName == program && pro[j].ProgramCode != $('#program_code').val() && pro[j].ProgramCode != $('#program_code2').val() ) 
				{
					options += '<option value="' + pro[j].ProgramCode + '">' + pro[j].Emphasis + '</option>';
				}
			}
		}
	}

	// Load options and show/hide.
		$('#program_code3').html(select_html + options);

	if (typeof(form_name) != 'undefined' && form_name == '1step') 
	{ $('#program_code3')[0].selectedIndex = 1; }
	else 
	{
		if (options) 
		{ $('#specialization3').show(); }
		else 
		{ $('#specialization3').hide(); }

		// These rules are regexes to be more accomodating of program name changes.
			if (program.match(/bachelor/i) || program.match(/b\.s\./i)) { $('#hidden-bachelor').show(); }
			if (program.match(/\(m\.s\.\) in education/i) || program.match(/doctor of education/i)) { $('#hidden-education').show(); }
			if (program.match(/engineering/i)) { $('#hidden-engineering').show(); }
			if (program.match(/nursing/i)) { $('#hidden-nursing').show(); }
	}
}

function loadCategory(s)
{
	var opt = s.options[s.selectedIndex];
	var category = opt.parentNode.title;
	var cat = program_data.body;

	for (var i = 0, ii = cat.length; i < ii; i++) 
	{
		if (cat[i].CategoryName == category) 
		{ var catCode = cat[i].CategoryCode; }
	}

	document.getElementById('category_code').value = catCode;
}

function loadCategory2 ()
{
	var category1 = $("#degree_program :selected").parent().attr('title');
	var category2 = $("#degree_program2 :selected").parent().attr('title');
	var cat = program_data.body;
	
	for (var i = 0, ii = cat.length; i < ii; i++) {
		if (cat[i].CategoryName == category1) {
			var catCode1 = cat[i].CategoryCode;
		}
		
		if (cat[i].CategoryName == category2) {
			var catCode2 = cat[i].CategoryCode;
		}
	}
	
	var newCode = catCode1+","+catCode2;
	
	$('#category_code').val(newCode);
}

function loadCategory3 ()
{
	var category1 = $("#degree_program :selected").parent().attr('title');
	var category2 = $("#degree_program2 :selected").parent().attr('title');
	var category3 = $("#degree_program3 :selected").parent().attr('title');
	var cat = program_data.body;
	
	for (var i = 0, ii = cat.length; i < ii; i++) {
		if (cat[i].CategoryName == category1) {
			var catCode1 = cat[i].CategoryCode;
		}
		
		if (cat[i].CategoryName == category2) {
			var catCode2 = cat[i].CategoryCode;
		}
		
		if (cat[i].CategoryName == category3) {
			var catCode3 = cat[i].CategoryCode;
		}
	}
	
	var newCode = catCode1+","+catCode2+","+catCode3;
	
	$('#category_code').val(newCode);
}

function validateHider(e) 
{
	var self = e.objRef;
	var parent = e.objRef.parentNode;
	var gparent = e.objRef.parentNode.parentNode;
	
	if (self.style.display != 'none' && parent.style.display != 'none' && gparent.style.display != 'none') 
	{
		e.type = e.objRef.type;
		
		return DtmkValidator.runValidate(e);
	}
	else 
	{ return true; }
}

function phoneFormat(f) 
{
	if (f.country.value == 'USA' || f.country.value == '' || f.country.value == 'CAN' || f.country.value == 'PRI') 
	{
		document.getElementById('phone_format_intl').style.display = 'none';
		document.getElementById('phone_format_na1').style.display = 'block';
		document.getElementById('phone_format_na2').style.display = 'block';
	} 
	else
	{
		document.getElementById('phone_format_intl').style.display = 'block';
		document.getElementById('phone_format_na1').style.display = 'none';
		document.getElementById('phone_format_na2').style.display = 'none';
	}
}

function zipFormat(f) 
{
	if (f.country.value == 'USA' || f.country.value == '') 
	{
		document.getElementById('zip_format_usa').style.display = 'inline';
		document.getElementById('zip_format_can').style.display = 'none';
	} 
	else if (f.country.value == 'CAN') 
	{
		document.getElementById('zip_format_usa').style.display = 'none';
		document.getElementById('zip_format_can').style.display = 'inline';
	}
	else
	{
		document.getElementById('zip_format_usa').style.display = 'none';
		document.getElementById('zip_format_can').style.display = 'none';
	}
}

function openWindow(name,url,width,height,scrollbar) 
{
	var assetWindow = window.open(url,name,'toolbar=0,location=0,directories=0,menubar=0,status=1,scrollbars=' + scrollbar + ',resizable=0,width=' + width + ',height=' + height);
	
	if(window.focus)
	{ assetWindow.focus(); }	
}

function wordWrap(str, int_width, str_break, cut) 
{
	// http://kevin.vanzonneveld.net

	// PHP Defaults
		var m = ((arguments.length >= 2) ? arguments[1] : 75 );
		var b = ((arguments.length >= 3) ? arguments[2] : "\n" );
		var c = ((arguments.length >= 4) ? arguments[3] : false);
		var i, j, l, s, r;

	if (m < 1) 
	{ return str; }

	for (i = -1, l = (r = str.split("\n")).length; ++i < l; r[i] += s) 
	{
		for(s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : ""))
		{
			j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
		}
	}

	return r.join("\n");
}

function loadStates(f, latam) 
{
	var c = f.country.value;
	var new_state_group;

	if (latam && c == 'BRA') 
	{
		var states = ['AC|Acre', 'Al|Algoas', 'AP|Amap&aacute;', 'AM|Amazonas', 'BA|Bahia', 'CE|Cear&aacute;', 'DF|Distrito Federal', 'ES|Esp&iacute;rito Santo', 'GO|Goi&aacute;s', 'MA|Maranh&atilde;o', 'MT|Mato Grosso', 'MS|Mato Grosso do Sul', 'MG|Minas Gerais', 'PA|Par&aacute;', 'PB|Para&iacute;ba', 'PR|Paran&aacute;', 'PE|Pernambuco', 'PI|Piau&iacute;', 'RJ|Rio de Janeiro', 'RN|Rio Grande do Norte', 'RS|Rio Grande do Sul', 'RO|Rond&ocirc;nia', 'RR|Roraima', 'SC|Santa Catarina', 'SP|S&atilde;o Paulo', 'SE|Sergipe', 'TO|Tocantins'];
		new_state_group = 'BRA';
	}
	else if (latam && c == 'MEX') 
	{
		var states = ['AGS|Aguascalientes', 'BC|Baja California', 'BCS|Baja California Sur', 'CAM|Campeche', 'CHIS|Chiapas', 'CHIH|Chihuahua', 'COAH|Coahuila', 'COL|Colima', 'DF|Distrito Federal', 'DGO|Durango', 'GTO|Guanajuato', 'GRO|Guerrero', 'HGO|Hidalgo', 'JAL|Jalisco', 'MEX|Mexico', 'MICH|Michoac&aacute;n', 'MOR|Morelos', 'NAY|Nayarit', 'NL|Nuevo Le&oacute;n', 'OAX|Oaxaca', 'PUE|Puebla', 'QRO|Quer&eacute;taro', 'QR|Quintana Roo', 'SLP|San Luis Potos&iacute;', 'SIN|Sinaloa', 'SON|Sonora', 'TAB|Tabasco', 'TAMS|Tamaulipas', 'TLAX|Tlaxcala', 'VER|Veracruz', 'YUC|Yucat&aacute;n', 'ZAC|Zacatecas'];
		new_state_group = 'MEX';
	}
	else
	{
		var states = ['AL|Alabama', 'AK|Alaska', 'AS|American Samoa', 'AZ|Arizona', 'AR|Arkansas', 'CA|California', 'CZ|Canal Zone', 'CO|Colorado', 'CT|Connecticut', 'DE|Delaware', 'DC|District of Columbia', 'FM|Fed. States of Micronesia', 'FL|Florida', 'GA|Georgia', 'GU|Guam', 'HI|Hawaii', 'ID|Idaho', 'IL|Illinois', 'IN|Indiana', 'IA|Iowa', 'KS|Kansas', 'KY|Kentucky', 'LA|Louisiana', 'ME|Maine', 'MH|Marshall Islands', 'MD|Maryland', 'MA|Massachusetts', 'MI|Michigan', 'MN|Minnesota', 'MS|Mississippi', 'MO|Missouri', 'MT|Montana', 'NE|Nebraska', 'NV|Nevada', 'NH|New Hampshire', 'NJ|New Jersey', 'NM|New Mexico', 'NY|New York', 'MP|Northern Mariana Islands', 'NC|North Carolina', 'ND|North Dakota', 'OH|Ohio', 'OK|Oklahoma', 'OR|Oregon', 'PW|Palau', 'PA|Pennsylvania', 'PR|Puerto Rico', 'RI|Rhode Island', 'SC|South Carolina', 'SD|South Dakota', 'TN|Tennessee', 'TX|Texas', 'UT|Utah', 'VT|Vermont', 'VI|Virgin Islands', 'VA|Virginia', 'WA|Washington', 'WV|West Virginia', 'WI|Wisconsin', 'WY|Wyoming', '|-------------------------', 'AA|Armed Forces - Americas (AA)', 'AE|Armed Forces - Europe (AE)', 'AP|Armed Forces - Pacific (AP)', '|-------------------------', 'AB|ALBERTA', 'BC|BRITISH COLUMBIA', 'MB|MANITOBA', 'NU|NUNAVUT', 'NB|NEW BRUNSWICK', 'NF|NEWFOUNDLAND', 'NS|NOVA SCOTIA', 'NT|NORTHWEST TERRITORY', 'ON|ONTARIO', 'PE|PRINCE EDWARD ISLAND', 'QC|QUEBEC', 'SK|SASKATCHEWAN', 'YT|YUKON TERRITORY', '|-------------------------', 'FC|Foreign Country'];
		new_state_group = 'USA';
	}

	if (new_state_group != last_state_group) 
	{
		// Populate state dropdown.
			var options = select_html;
			
			for (var i = 0; i < states.length; i++) 
			{
				var st = states[i].split('|');
				options += '<option value="' + st[0] + '" title="' + st[1] + '">' + st[1] + '</option>'
			}

			$('#state').html(options);
	}

	// Automatically choose "Foreign Country" if we don't have a state list.
		if (c!= '' && c != 'USA' && c != 'CAN' && c != 'BRA' && c!= 'MEX')
		{ document.getElementById('state').value = 'FC'; }
		else if (new_state_group != last_state_group)
		{ document.getElementById('state').value = ''; }
		else 
		{
			if (c!= '' && c != 'USA' && c != 'CAN')
			{ document.getElementById('state').value = 'FC'; }
			else if (new_state_group != last_state_group)
			{ document.getElementById('state').value = ''; }
		}

		last_state_group = new_state_group;
}

function checkValidation() 
{
	if ( $('#country').val() == "USA" ||  $('#country').val() == "CAN")
	{
		// Canada/US validation
		$('#postal_code').parent().html('<label for="postal_code">Postal Code<span class="req">*</span></label><input type="text" name="postal_code" id="postal_code" maxlength="50" dtmk:validation="{required:true,type:\'postalCode\',options:{format:\'canus\'},message:\'Please enter a valid postal code.\'}" value="'+postal_code+'" /><br /><span id="zip_format_usa" class="exp">(ex: 12345 or 12345-1234)</span><span id="zip_format_can" class="exp" style="display: none;">(ex: A1A 1A1)</span>');
		
		$('#phone').parent().html('<label for="phone">Home Phone<span class="req">*</span></label><input type="text" name="phone" id="phone" maxlength="100" dtmk:validation="{required:true,type:\'regex\',options:{pattern:\'^[0-9]{3}[ .-]?[0-9]{3}[ .-]?[0-9]{4}$\'},message:\'Please enter a valid home phone number.\'}" value="'+phone+'" /><br /><span id="phone_format_na1" class="exp">(ex: 555-555-5555)</span>');
		
		$('#phone2').parent().html('<label for="phone2">Work Phone<span class="req">*</span></label><input type="text" name="phone2" id="phone2" maxlength="100" dtmk:validation="{required:true,type:\'regex\',options:{pattern:\'^[0-9]{3}[ .-]?[0-9]{3}[ .-]?[0-9]{4}$\'},message:\'Please enter a valid work phone number.\'}" /><br /><span id="phone_format_na2" class="exp">(ex: 555-555-5555)</span>');
	}
	else
	{
		//International validation
		$('#postal_code').parent().html('<label for="postal_code">Postal Code<span class="req">*</span></label><input type="text" name="postal_code" id="postal_code" maxlength="50" dtmk:validation="{required:true,type:\'postalCode\',options:{format:\'intl\'},message:\'Please enter a valid postal code.\'}" value="'+postal_code+'" /><br /><span id="zip_format_usa" class="exp">(ex: 12345 or 12345-1234)</span><span id="zip_format_can" class="exp" style="display: none;">(ex: A1A 1A1)</span>');
		
		$('#phone').parent().html('<label for="phone">Home Phone<span class="req">*</span></label><input type="text" name="phone" id="phone" maxlength="100" dtmk:validation="{required:true,type:\'phone\',options:{format:\'intl\'},message:\'Please enter a valid home phone number.\'}" value="'+phone+'" /><br /><span id="phone_format_na1" class="exp">(ex: 555-555-5555)</span>');
		
		$('#phone2').parent().html('<label for="phone2">Work Phone<span class="req">*</span></label><input type="text" name="phone2" id="phone2" maxlength="100" dtmk:validation="{required:true,type:\'phone\',options:{format:\'intl\'},message:\'Please enter a valid work phone number.\'}" /><br /><span id="phone_format_na2" class="exp">(ex: 555-555-5555)</span>');
	}
}

// Phone type selection switches -----------
	// Only allows each type of phone to be selected once
	// Shows/Hides mobile opt in question base on phone types selected
		var phoneTypeDefault = $('#phone_type').html();
		
		function optIn_showHide()
		{
			if ( $('#country').val() == "USA" && ( $('#phone_type').val() == "Mobile" || $('#phone2_type').val() == "Mobile" ) )
			{ $('#opt_in').show(); }
			else
			{ 
				$('#mobile_opt_in').attr('checked', false);
				$('#opt_in').hide(); 
			}
		}
		
		function phoneType_valueFilter( phoneType )
		{
			switch ( phoneType )
			{
				case "phone_type":
					var currentType_selector = "#phone_type";
					var opppositeType_selector = "#phone2_type";
				break;
				
				case "phone2_type":
					var currentType_selector = "#phone2_type";
					var opppositeType_selector = "#phone_type";
				break;
			}
			
			var opppositeType_value = $(opppositeType_selector).val();
			
			$(opppositeType_selector).html(phoneTypeDefault);
			
			$(opppositeType_selector+' option').each( 
				function () { 
					if( $(this).val() == $(currentType_selector).val() && $(this).val() != "" ) 
					{ $(this).remove(); } 
				} 
			);
			
			$(opppositeType_selector).val(opppositeType_value);
		}
		
		$('#phone_type, #phone2_type').change(function() {
			phoneType_valueFilter( $(this).attr('id') );
			optIn_showHide();
		});
				
		$('#country').change(function () { optIn_showHide(); });
	
// END Phone type selection switches -----------

/* New tracking codes for form
----------------------------------------------------------------------------------------------*/
	if ( typeof(_gaq) != 'undefined' )
	{
		$(
			function () {
				$(':input').each(
					function ()
					{
						var currentElement = $(this).attr('name');
						
						switch( currentElement )
						{
							case "education_level_code":
								$(this).bind('change', function () {_gaq.push(['_trackEvent', 'Forms', 'education_level_code']);});
							break;
							
							case "degree_program":
								$(this).bind('change',function () {_gaq.push(['_trackEvent', 'Forms', 'degree_program']);});
							break;
							
							case "program_code":
								$(this).bind('change', function () {_gaq.push(['_trackEvent', 'Forms', 'program_code']);});
							break;
							
							case "degree_program2":
								$(this).bind('change', function () {_gaq.push(['_trackEvent', 'Forms', 'degree_program2']);});
							break;
							
							case "age_requirement":
								$(this).bind('click', function () {_gaq.push(['_trackEvent', 'Forms', 'age_requirement']);});
							break;
							
							case "rn_license":
								$(this).bind('click', function () {_gaq.push(['_trackEvent', 'Forms', 'rn_license']);});
							break;
							
							case "start_date":
								$(this).bind('change', function () {_gaq.push(['_trackEvent', 'Forms', 'start_date']);});
							break;
							
							case "segmentation_question":
								$(this).bind('change', function () {_gaq.push(['_trackEvent', 'Forms', 'segmentation_question']);});
							break;
							
							case "next":
								$(this).bind('click', 
									function () 
									{
										_gaq.push(['_trackEvent', 'Forms', 'next']);
										_gaq.push(['_trackPageview','/form/continue']);
									}
								);
							break;
							
	
							case "first_name":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'first_name']);});
							break;
	
							case "last_name":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'last_name']);});
							break;
							
							case "address":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'address1']);});
							break;
							
							case "address2":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'address2']);});
							break;
							
							case "city":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'city']);});
							break;
							
							case "state":
								$(this).bind('change', function () {_gaq.push(['_trackEvent', 'Forms', 'state']);});
							break;
							
							case "postal_code":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'postal_code']);});
							break;
							
							case "country":
								$(this).bind('change', function () {_gaq.push(['_trackEvent', 'Forms', 'country']);});
							break;
							
							case "phone":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'phone']);});
							break;
							
							case "phone2":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'phone2']);});
							break;
							
							case "email":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'email']);});
							break;
							
							case "call_time":
								$(this).bind('change', function () {_gaq.push(['_trackEvent', 'Forms', 'call_time']);});
							break;
							
							case "submit":
								$(this).bind('click',
									function () {
										_gaq.push(['_trackEvent', 'Forms', 'submit']);
										_gaq.push(['_trackPageview','/form/filled']);
									});
							break;
							
							case "undergrad_degree":
								$(this).bind('click', function () {_gaq.push(['_trackEvent', 'Forms', 'undergrad_degree']);});
							break;
							
							case "teaching_certificate":
								$(this).bind('click', function () {_gaq.push(['_trackEvent', 'Forms', 'teaching_certificate']);});
							break;
							
							case "upcoming_term":
								$(this).bind('click', function () {_gaq.push(['_trackEvent', 'Forms', 'upcoming_term']);});
							break;
							
							case "grades_teaching":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'grades_teaching']);});
							break;
							
							case "school_name":
								$(this).bind('focus', function () {_gaq.push(['_trackEvent', 'Forms', 'school_name']);});
							break;
						}
					}
				);
			}
		);
	}
