Ext.onReady(function() {
	if (Ext.get('State') && Ext.get('DegreeSeeking')) {
		Ext.get('State').on('change', checkStates);
		Ext.get('DegreeSeeking').on('change', checkStates);
	}
});

function checkStates() {
	var msg = 'Northcentral does not meet current licensure requirements in these states:\n\nIllinois, Louisiana, Mississippi and New York.';
	var state = Ext.get('State').getValue();
	var degree = Ext.get('DegreeSeeking').getValue();

	if ((state == 'IL' || state == 'LA' || state == 'MS' || state == 'NY') && (degree == 'MFTMPSY' || degree == 'PHD-MFT')) {
		alert(msg);
	}
}

var ajaxCount = 1;

function getInfo(input, replacementName, replacementValue) {
	var functionName = 'generated' + ajaxCount++,
	url = input.getAttribute('src');

	window[functionName] = function(data) {
		var textName = input.getAttribute('text'),
		valueName = input.getAttribute('datavalue'),
		path = input.getAttribute('path'),
		i, option;

		if (path) {
			path = path.split('.');

			for (i = 0; i < path.length; i++) {
				if (!data) {
					continue;
				}

				data = data[path[i]];
			}
		}

		if (!textName) {
			textName = 'text';
		}

		if (!valueName) {
			valueName = 'value';
		}

		input.options.length = 0;

		if (!data) {
			return;
		}

		option = document.createElement("option");
		option.text = "Select One...";
		option.value = "";
		
		try {
			input.add(option, null);
		} catch(ex) {
			input.add(option);
		}
		
		
		for (i = 0; i < data.length; i++) {
			option = document.createElement("option");

			option.text = data[i][textName];
			option.value = data[i][valueName];

			try {
				input.add(option, null); // standards compliant
			}
			catch(ex) {
				input.add(option);
			}
		}
		
		// select first option by default
		input.selectedIndex = 0;
		input.disabled = false;
	};

	input.options.length = 0;

	if (!replacementValue) {
		return;
	}

	if (replacementName && replacementValue) {
		url = url.replace('@' + replacementName, replacementValue);
	}

	if (url.indexOf('?') == -1) {
		url += '?';
	} else {
		url += '&';
	}

	url += 'format=json&callback=' + functionName;

	var scriptTag = document.createElement("script");

	scriptTag.type = "text/javascript";
	scriptTag.src = url;

	document.body.appendChild(scriptTag);
}
