// Utilizing MooTools Library http://www.mootools.net

// Custom event handler to prevent conflict between libraries using window.addEvent 
var AC = {
	addEvent: function (el, type, fn) {
		if (el.attachEvent) {
			el['e'+type+fn] = fn;
			el[type+fn] = function(){el['e'+type+fn](window.event);}
			el.attachEvent('on'+type,el[type+fn]);
		} else {
			el.addEventListener(type,fn,false);
		}
	},
	removeEvent: function (el, type, fn) {
		if (el.detachEvent) {
			el.detachEvent('on'+type,el[type+fn]);
			el[type+fn] = null;
		} else {
			el.removeEventListener(type,fn,false);
		}
	}
};

window.onload = function(){
	
	checkQueryString();

	if (document.getElementById("CheckWorkflowIDRedirect") == undefined) {
			// DO NOTHING
	} else {
			checkWorkFlowID();
			//alert('found it');
	}
	
	// Initialize 'Jump to' Select menus
	var SelectBoxMenu = new Class({
		options: {
			menus: []
		}, 
		initialize: function(options){
			this.setOptions(options)
			this.menus = [];
			this.addMenus(this.options.menus);
		},
		addMenus: function(menus) {
			$$(menus).each(function(menu){
				this.menus.include($(menu));
				menu.addEvent('change', function(){
					location.href=menu.get('value');
				});
			}, this);
		} 
		
	});
	SelectBoxMenu.implement(new Options, new Events);
	
	new SelectBoxMenu({menus: $$('.AC-Jump')});

	
	// Accordian Effect
	var accordion = new Accordion('div.toggleHead', 'div.toggleBody', {opacity: false, show: -1, alwaysHide: true, start: 'all-closed', duration: 500, onActive: function(tog){tog.addClass('selected');}, onBackground: function(tog){tog.removeClass('selected');}}, $('AC-Accordion'));

	// Thumbnail News Photos
	if($chk($('AC-NewsPhotoList'))){ var PhotoThumb = new ACThumbnailer('AC-NewsPhotoList','AC-PhotoLoader','AC-NewsPhotoImage','AC-NewsStory'); }

	// Todolist Effect
	var ACTodoList = new Class({
		initialize: function(){
			this.header = $$('.AC-TodoHeader')[0];
			this.footer = $$('.AC-TodoFooter')[0];
			this.content = $$('.AC-TodoContent')[0];
			this.todoOpen = false;
			this.heightChange = new Fx.Tween(this.content,{property: 'height', duration:700}, Fx.Transitions.Sine.easeInOut);
			this.header.getElements('a')[0].removeProperty('href');
			this.header.addEvent('click', function() { this.todoToggle() }.bind(this) );
			this.footer.addEvent('click', function() { this.todoToggle() }.bind(this) );
		},
		todoToggle: function() {
			if(this.todoOpen == false) {
				this.heightChange.cancel();
				this.header.addClass('AC-TodoOpen');
				this.footer.setStyle('display','block');
				this.heightChange.start(this.content.getScrollSize().y);
				this.todoOpen = true;
			} else {
				var main = this;
				this.heightChange.cancel();
				this.heightChange.start(0).chain(function(){
					if(main.content.getStyle('height').toInt() == 0) {
						main.header.removeClass('AC-TodoOpen');
						main.footer.setStyle('display','none');
					}
				});
				this.todoOpen = false;
			}
		}		
	});

	if($$('.AC-Todolist').length > 0){ var TodoList = new ACTodoList(); }


}

/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
function checkQueryString()
	{
		var qs = new Querystring();
		var v1 = qs.get("FAQTYPE");
		if(v1 == "Dining")
		{
			if (document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.value != "47b683c1-8437-4d3d-824f-32edb0bd0816") {
				var i=0;
				while ((document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options[i].value != "47b683c1-8437-4d3d-824f-32edb0bd0816") && (i < document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options.length))
					{i++;}
				if (i < document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options.length)
					{document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.selectedIndex = i;}
				__doPostBack('centerColumnAudienceControl$88a706d4_774e_4735_afc9_75f6f74f1782$TextImageButtonSearch$ImageButton$Button','');
			}
		
		}
		if(v1 == "FA")
		{
			if (document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.value != "802ce413-6a66-4e93-8e79-e0155fb8b070") {
				var i=0;
				while ((document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options[i].value != "802ce413-6a66-4e93-8e79-e0155fb8b070") && (i < document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options.length))
					{i++;}
				if (i < document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options.length)
					{document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.selectedIndex = i;}
				__doPostBack('centerColumnAudienceControl$88a706d4_774e_4735_afc9_75f6f74f1782$TextImageButtonSearch$ImageButton$Button','');
			}
		
		}
		if(v1 == "StuAcct")
		{
			if (document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.value != "9fba5032-2fff-47c3-926e-a32cfb5fbc72") {
				var i=0;
				while ((document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options[i].value != "9fba5032-2fff-47c3-926e-a32cfb5fbc72") && (i < document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options.length))
					{i++;}
				if (i < document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.options.length)
					{document.Form1.centerColumnAudienceControl_88a706d4_774e_4735_afc9_75f6f74f1782_iQueryBuilderWebControl0_DropDownListValue_ListControl.selectedIndex = i;}
				__doPostBack('centerColumnAudienceControl$88a706d4_774e_4735_afc9_75f6f74f1782$TextImageButtonSearch$ImageButton$Button','');
			}
		
		}
	}
function checkWorkFlowID() 
	{
			var CurrentURL=window.location.href;
			//alert(' Current URL is ' + window.location.href);
			//alert(' Value of indexOf is '  + CurrentURL.indexOf('WorkflowItemID'));
			if (CurrentURL.indexOf('WorkflowItemID') == -1){
				window.location.href = '/applying/applytousp/applicationListing.aspx';
			}
}