var mim = {
selected_tab : null,
init : function () {
	if ( $ ( 'member_search_init' ) ) {
		$ ( 'member_search_init' ).onclick = function () {
			if ( $ ( 'member_search' ).style.display == 'none' ) {
				new Effect.BlindDown ( $ ( 'member_search' ), { duration : .3 } );
				new Effect.Appear ( $ ( 'member_search' ), { duration : .3 } );
			} else {
				new Effect.BlindUp ( $ ( 'member_search' ), { duration : .3 } );
				new Effect.Fade ( $ ( 'member_search' ), { duration : .3 } );
			}
		};
	}
	if ( $ ( 'form_team_search' ) ) {
		var selected;
		var selectors = $ ( 'form_team_search' ).select ( '.selector' );
		selectors.each ( function ( selector, i ) {
			selector.onclick = function () {
				$ ( 'Country_US' ).checked = 'checked';
				var city = $ ( this.readAttribute ( 'selector' ) );
				if ( selected ) { selected.hide (); }
				selected = city;
				selected.show ();
			}
		});
		$ ( 'local_content' ).onclick = function () {
			Element.addClassName ( this, 'selected' );
			$ ( 'virtual_content' ).removeClassName ( 'selected' );
			$ ( 'search_form' ).show ();
			$ ( 'form_local' ).show ();
			$ ( 'Model' ).value = 'Local';
		};
		$ ( 'virtual_content' ).onclick = function () {
			Element.addClassName ( this, 'selected' );
			$ ( 'local_content' ).removeClassName ( 'selected' );
			$ ( 'search_form' ).show ();
			$ ( 'form_local' ).hide ();
			$ ( 'Model' ).value = 'Virtual';
		};
	}
	if ( $ ( 'form_login' ) ) {
		var inputs = $ ( 'form_login' ).select ( '.input' );
		inputs.each ( function ( input, i ) {
			input.value = input.readAttribute ( 'defaultvalue' );
			input.onfocus = function () {
				if ( this.value == this.readAttribute ( 'defaultvalue' ) ) { this.value = ''; }
				if ( this.id == 'login_password_default' ) { this.hide (); $ ( 'login_password' ).show (); $ ( 'login_password' ).focus (); }
				if ( this.readAttribute ( 'password' ) ) { this.type = 'password'; }
			}
			input.onblur = function () {
				if ( this.id == 'login_password' ) {
					if ( this.value.blank () ) { this.hide (); $ ( 'login_password_default' ).show (); }
				} else if ( this.value.blank () ) { this.value = this.readAttribute ( 'defaultvalue' ); }
			}
		});
	}
	if ( $ ( 'form_log_Year' ) ) {
		$ ( 'form_log_Year' ).onchange = function () { window.location.href = '/members/training-log.aspx?Year=' + $F ( 'form_log_Year' ); }
	}
	var form_handlers = $$ ( '#container .formhandler' );
	form_handlers.each ( function ( item, i ) {
		item.onclick = function () {
			this.setOpacity ( .35 );
			this.oldHTML = this.innerHTML;
			this.update ( 'processing &hellip;' );
			var valid = true;
			var form = this.readAttribute ( 'form' );
			var inputs = $ ( form ).select ( 'input[required="true"],select[required="true"],textarea[required="true"]' );
			inputs.each ( function ( input, i ) {
				if ( $ ( input.id + '_errorlabel' ) ) { $ ( input.id + '_errorlabel' ).remove (); }
				if ( input.value.blank () ) {
					valid = false;
					var errorlabel = new Element ( 'div', { 'id' : input.id + '_errorlabel', 'class' : 'error_label' } ).update ( input.readAttribute ( 'errormsg' ) );
					input.up ().insert ( { top : errorlabel } );
				}
			});
			if ( valid ) {
				var func = function () { $ ( form ).submit (); };
				setTimeout ( func, 100 );
			}
			else { new Effect.Appear ( this, { from : .35, to : 1 } ); this.update ( this.oldHTML ); }
		};
	});
	var accordions = $$ ( '#container .accordion_hdr' );
	accordions.each ( function ( item, i ) {
		item.onclick = function () {
			var item_content = $ ( this.id + '_content' );
			if ( this.hasClassName ( 'selected' ) ) {
				this.removeClassName ( 'selected' );
				new Effect.BlindUp ( item_content, { duration : .3 } );
				new Effect.Fade ( item_content, { duration : .3 } );
			} else {
				this.addClassName ( 'selected' );
				new Effect.BlindDown ( item_content, { duration : .3 } );
				new Effect.Appear ( item_content, { duration : .3 } );
				if ( this.hasClassName ( 'tab' ) ) {
					var current_tab = this;
					var tabs = $$ ( '#container .accordion_hdr.tab' );
					tabs.each ( function ( tab, k ) {
						if ( tab != current_tab ) {
							var tab_content = $ ( tab.id + '_content' );
							tab.removeClassName ( 'selected' );
							new Effect.BlindUp ( tab_content, { duration : .3 } );
							new Effect.Fade ( tab_content, { duration : .3 } );
						}
					});
				}
			}
		};
	});
	var popups = $$ ( '#container a[popup="true"]' );
	popups.each ( function ( item ) {
		item.observe ( 'click',
			popWrapper.bindAsEventListener ( null, item.readAttribute ( 'popupw' ), item.readAttribute ( 'popuph' ), $ ( 'popup' ), .5, .35, 'popup_content', item.readAttribute ( 'popupurl' ) )
		);
	});
	$ ( 'popup_close' ).observe ( 'click', mim.kill_popup );
	var tabs = $$ ( '#container ul.tab_nav li.item[tab!=""]' );
	tabs.each ( function ( item ) {
		item.observe ( 'click', function () {
			if ( item.readAttribute ( 'url' ) ) {
				window.location.href = item.readAttribute ( 'url' );
			} else {
				tabs.each ( function ( item2 ) {
					if ( item2.readAttribute ( 'tab' ) ) {
						if ( $ ( item2.readAttribute ( 'tab' ) ) ) { $ ( item2.readAttribute ( 'tab' ) ).hide (); }
					}
				});
				if ( mim.selected_tab ) {
					mim.selected_tab.removeClassName ( 'selected' );
				}
				mim.selected_tab = this;
				mim.selected_tab.addClassName ( 'selected' );
				if ( $ ( mim.selected_tab.readAttribute ( 'tab' ) ) ) {
					$ ( mim.selected_tab.readAttribute ( 'tab' ) ).show (); }
			}
		});
	});
},
kill_popup : function () {
	var target = pAndD.scanPopDivColl ( 'popup' );
	if ( target != null ) pAndD.hidePopDiv ( target );
},
check_teammates : function () {
	var teammates = $ ( 'teammates' ).select ( 'div.column' );
	if ( teammates.length < 1 ) {
		$ ( 'teammates' ).update ( '<div class="part">Member doesn\'t have any teamates yet.</div>' );
	}
}
};
Event.observe ( window, 'load', mim.init, false );