/*
	Global Javascript for:
		Museum of Science and Industry
	
	Authors:
	
		Aaron Clinger (aaron@odopod.com)
	
	Updated:
	
		02/28/2008
	
*/
var modalBox;

window.addEvent('domready', function () {					   

	// Get wrapper and set it to each page
	var cssCookie = readCookie("csswrapper");
	
	if(cssCookie==null) {	
		// If no wrapper is found read available ones
		if (avWrappers) {		
			// Randomly select one and assign it
			var wrappersArray =  avWrappers.split('|');			
			var randomWrapper = wrappersArray[Math.floor(Math.random()*wrappersArray.length)];
			//var curWrapperPath = $('wrapper').getProperty('href');
			//var randomWrapperPath = curWrapperPath.replace(/\w*\.css/, randomWrapper);
			var randomWrapperPath = 'fileadmin/templates/css/general_wrappers/'+randomWrapper;
			createCookie('csswrapper', randomWrapperPath);
			if($('wrapper')) {
				$('wrapper').setProperty('href', randomWrapperPath);
			}
		} 
	} else {
		if($('wrapper')) {
			$('wrapper').setProperty('href', cssCookie);
		}
	}
	
	//Sort itinerary items
	var itinerarySortables = new Sortables($('itineraryAssets'), {
		handles: $$('#itineraryAssets .itinerary h4'),
		onComplete: function(){
		itineraryArray = [];
			$$('#itineraryAssets li').each(function(li, i) {
				itineraryArray[i] = li.getFirst().getProperty('id');
			});
			Cookie.set('itineraries', itineraryArray, {path: itineraryCookiePath});
			//if itineraryGuid, do autosaving to the service
			if(itineraryGuid != ''){
				(msismartvisit_saveItinerary('<xjxquery><q>msismartvisit[itineraryGuid]='+itineraryGuid
					+ '&msismartvisit[itineraryName]=' + itineraryName
					+ '&msismartvisit[dayAttending]=' + dayAttending + '</q></xjxquery>'));	
			}
			
		},
		initialize: function(){
			var step = 0;
			this.elements.each(function(element, i){
				step = step + 35;
			});
		}
	});
	
	var itineraryArray = [];
	var itineraryEffects = [];
	$$('.removeItem', '.addItem').each( function(a){
			var itineraryItem = a.getParent();
			while (itineraryItem.getTag() != 'li') {
				itineraryItem = itineraryItem.getParent();
			}
			a.addEvent('click', handleItineraryAction.bindAsEventListener(a, itineraryItem));
	});
	
	
	function handleItineraryAction(e, itineraryItem) {
		e = new Event(e);
		if (this.getText() == "remove") {
			removeItem(itineraryItem, this);
		} else {
			addItem(itineraryItem, this);
		}
		e.stop();
	}
	
	function removeItem(el, link) {
		if($('recommendedItineraryAssets').getChildren().length >= 8) {
			if (!$('recommendedItineraryAssetsWrap').hasClass('hideMore')) $('recommendedItineraryAssetsWrap').addClass('hideMore')
		}
		var itineraryWrapper = new Element('div').injectAfter(el).adopt(el);
		el.setStyle('width', el.getCoordinates().width);
		//el.setStyle('background-color', '#ff0000');
		//itineraryWrapper.setStyle('width', itineraryWrapper.getCoordinates().width);
		//itineraryWrapper.setStyle('height', itineraryWrapper.getCoordinates().height);
		//itineraryWrapper.setStyle('text-align', 'left');
		//itineraryWrapper.setStyle('margin-left', 0);
		itineraryWrapper.setStyle('margin', el.getStyle('margin'));
		//itineraryWrapper.setStyle('margin', el.getStyle('margin'));
		itineraryWrapper.setStyle('overflow', 'hidden');
		itineraryWrapper.setProperty('id', 'wraper-'+el.getProperty('id'));
		el.setStyle('margin', 0);
		el.setStyle('float', 'left');
		var overlay = itineraryWrapper.getElement('.overlay');
		//el.setStyle('float', 'left');
		var fx = itineraryWrapper.effects({duration: 700, transition: Fx.Transitions.Quart.easeOut});
		if (overlay) {
			var fx2 = overlay.effects({duration: 700, transition: Fx.Transitions.Quart.easeOut});
			fx2.start({
				'opacity': 0
			});
		}
		fx.start({
			'opacity': 0
		}).chain(function(){
			//alert("end : " + itineraryWrapper.getElement('li').getProperty('id'));
			this.start({
				'height': itineraryWrapper.getCoordinates().height,
				'margin-top': -itineraryWrapper.getCoordinates().height
			});
			
		}).chain(showItineraryItem.bind(fx, [itineraryWrapper, el, link, fx2]));
	}

	function showItineraryItem(itineraryWrapper, el, link, overlayEffect) {
		itinerarySortables.removeItem(el);
		var fadeInElement = true;
		if (el.getProperty('id').contains('event')) {
			var eventNum = el.getProperty('id').substr(5);
			var recommendedItineraryAssets = $$('#recommendedItineraryAssets li');
			if (recommendedItineraryAssets.length > 0) {
				for (var i = 0; i < recommendedItineraryAssets.length; i++) {
					var li = recommendedItineraryAssets[i];
					var testEventNum = li.getProperty('id').substr(5)
					if (eventNum.toInt() < testEventNum.toInt() && i <= recommendedItineraryAssets.length - 1) {
						while (li.getParent().getTag() != 'ul') {
							li = li.getParent();
						}
						itineraryWrapper.injectBefore(li);
						break;
					} else {
						if (i == recommendedItineraryAssets.length - 1) {
					 		itineraryWrapper.injectInside($('recommendedItineraryAssets'));
						}
					}
				}
			} else {
				itineraryWrapper.injectInside('recommendedItineraryAssets');
			}
			link.setText('add');
			link.removeClass('removeItem');
			link.addClass('addItem')
			
			el.getElements('.raquoLink').each( function(c){
				c.getParent().removeClass('hide');
			});
		} else {
			itineraryWrapper.remove();
			fadeInElement = false;
			itineraryArray = [];
			$$('#itineraryAssets li').each(function(li, i) {
				itineraryArray[i] = li.getFirst().getProperty('id');
			});
			Cookie.set('itineraries', itineraryArray, {path: itineraryCookiePath});
			//if itineraryGuid, do autosaving to the service
			if(itineraryGuid != ''){
				(msismartvisit_saveItinerary('<xjxquery><q>msismartvisit[itineraryGuid]='+itineraryGuid
					+ '&msismartvisit[itineraryName]=' + itineraryName
					+ '&msismartvisit[dayAttending]=' + dayAttending + '</q></xjxquery>'));	
			}
		}		
		if (fadeInElement) {
			this.start({
					'height': itineraryWrapper.getCoordinates().height,
					'margin-top': 0
			}).chain(function(){
				this.start({
					'opacity': 1
				});	
				if (overlayEffect) {
					overlayEffect.start({
						'opacity': 1
					});	
				}
			}).chain(function(){
				itineraryWrapper.replaceWith(el);
				el.setStyle('float','none');
				el.setStyle('margin', itineraryWrapper.getStyle('margin'));
				itineraryArray = [];
				$$('#itineraryAssets li').each(function(li, i) {
					itineraryArray[i] = li.getFirst().getProperty('id');
				});
				Cookie.set('itineraries', itineraryArray, {path: itineraryCookiePath});
				//if itineraryGuid, do autosaving to the service
				if(itineraryGuid != ''){
					(msismartvisit_saveItinerary('<xjxquery><q>msismartvisit[itineraryGuid]='+itineraryGuid
						+ '&msismartvisit[itineraryName]=' + itineraryName
						+ '&msismartvisit[dayAttending]=' + dayAttending + '</q></xjxquery>'));	
				}
			});
		}
		
	}
	
	
	
	function fadeIn(itineraryWrapper) {
		this.start({
				'height': itineraryWrapper.getCoordinates().height,
				'margin-top': 0
		}).chain(function(){
			//alert(wrap.getElement('li').getProperty('id'));
			this.start({
				'opacity': 1
			});			
		}).chain(function(){
			itineraryWrapper.replaceWith(el); 
			el.setStyle('margin', itineraryWrapper.getStyles('margin'));
		});
	}
	
	function addItem(el,link) {
		if($('recommendedItineraryAssets').getChildren().length <= 8) {
			if ($('recommendedItineraryAssetsWrap').hasClass('hideMore')) $('recommendedItineraryAssetsWrap').removeClass('hideMore')
		}
		link.fireEvent('mouseout');
		el.setStyle('width', el.getCoordinates().width);
		itineraryWrapper = new Element('div', {'styles': {'height': el.getCoordinates().height}}).injectAfter(el).adopt(el);
		itineraryWrapper.setStyle('margin', el.getStyle('margin'));
		itineraryWrapper.setStyle('overflow', 'hidden');
		itineraryWrapper.setStyle('padding', '0');
		el.setStyle('margin', 0);
		el.setStyle('float', 'left');
		var overlay = itineraryWrapper.getElement('.overlay');
		var fx = itineraryWrapper.effects({duration: 700, transition: Fx.Transitions.Quart.easeOut});
		if (overlay) {
			var fx2 = overlay.effects({duration: 700, transition: Fx.Transitions.Quart.easeOut});
			fx2.start({
				'opacity': 0
			});
		}
		fx.start({
			'opacity': 0
		}).chain(function(){
			this.start({
				'height': itineraryWrapper.getCoordinates().height,
				'margin-top': -itineraryWrapper.getCoordinates().height
			});
		}).chain(showItineraryItemAdd.bind(fx, [itineraryWrapper, el, link, fx2]));
		
		
	
	}
	
	function showItineraryItemAdd(itineraryWrapper, el, link, overlayEffect) {
		//var last = $$('#itineraryAssets li').getLast();
		itinerarySortables.addItem(el);
		
		itineraryWrapper.injectInside($('itineraryAssets'));
		link.setText('remove');
		link.removeClass('addItem');
		link.addClass('removeItem')
		el.getElements('.raquoLink').each( function(c){
			c.getParent().addClass('hide');
		});
		this.start({
				//'height': itineraryWrapper.getCoordinates().height,
				'margin-top': 0
		}).chain(function(){
			this.start({
				'opacity': 1
			});		
			if (overlayEffect) {
				overlayEffect.start({
					'opacity': 1
				});	
			}
		}).chain(function(){
			el.setStyle('float','none');
			itineraryWrapper.replaceWith(el); 
			el.setStyle('margin', itineraryWrapper.getStyle('margin'));
			//Cookie.set('itineraries', itineraryArray.include([el.getProperty('id')]));
			itineraryArray = [];
			$$('#itineraryAssets li').each(function(li, i) {
				itineraryArray[i] = li.getFirst().getProperty('id');
			});
			Cookie.set('itineraries', itineraryArray, {path: itineraryCookiePath});
			//if itineraryGuid, do autosaving to the service
			if(itineraryGuid != ''){
				(msismartvisit_saveItinerary('<xjxquery><q>msismartvisit[itineraryGuid]='+itineraryGuid
					+ '&msismartvisit[itineraryName]=' + itineraryName
					+ '&msismartvisit[dayAttending]=' + dayAttending + '</q></xjxquery>'));	
			}
			//Cookie.set('itineraries', $$('itineraryAssets').);
		});			
	}

// Write Flash Embeds
	writeRequestedFlashEmbeds();	
	
	
	// Calendar
	if ($('choice1st')){
		
		myCal1 = new Calendar({ choice1st: 'm/d/Y' }, { direction: 1, tweak: { x: 6, y: 0 }});
	}
	if ($('choice2nd')){
		myCal2 = new Calendar({ choice2nd: 'm/d/Y' }, { direction: 1, tweak: { x: 6, y: 0 }});
	}
	if ($('datePlan')){
		myCal3 = new ItineraryCalendar({ datePlan: 'M d, Y' }, { days: ['su', 'm', 't', 'w', 'th', 'f', 's'], container :'itineraryCalendarContainer' , direction: 1 });
	}
	
	 if ($$('button.calendar')) {
	 	$$('button.calendar').each( function(a){
			a.addEvent("mouseover", function(){ 
				a.addClass('hover');
			});
		});
		$$('button.calendar').each( function(a){
			a.addEvent("mouseout", function(){ 
				a.removeClass('hover');
			});
		});
	 }
 

	/* Smart Visit Start */
	var test = Array($$('.fiveUp .module'), $$('.threeModulesUp .module'), $$('.showcasePane .module'),$$('.showcaseRelatedPane .module'), $$('.sharePhotoModuleContent .shareItem'), $$('.shareVideoModuleContent .shareItem'));
	test.each(function(el) {
		el.each( function(a){
			a.addEvent("mouseover", function(){ 
				a.getChildren().addClass('over');
			});
			a.addEvent("mouseout", function(){ 
				a.getChildren().removeClass('over');
			});
		});
	});
	
	
	if ($('moreAssetsContent')) {
		var sc1 = new Showcase({
			  pane_current : 0,
			  showcase_pane_class:'showcasePane',
			  showcase_next_id:'nextAsset',
			  showcase_prev_id:'previousAsset',
			  showcase_wrap_id:'showcaseWindow',
			  show_next_id:'noNextAsset',
			  show_prev_id:'noPreviousAsset'
   			});
	}
	if ($('relatedAssetsContent')) {
		var sc2 = new Showcase({
			  pane_current : 0,
			  showcase_pane_class:'showcaseRelatedPane',
			  showcase_next_id:'nextRelatedAsset',
			  showcase_prev_id:'previousRelatedAsset',
			  showcase_wrap_id:'showcaseRelWindow',
			  show_next_id:'noNextRelatedAsset',
			  show_prev_id:'noPreviousRelatedAsset'
			});
	}
	
//	var newTog = new Element('h5.date', {'class': 'toggler'});
//	var newEl = new Element('div', {'class': 'element'});
//	accordion.addSection(newTog, newEl, 0);

	// preload images
	new Asset.images(['fileadmin/templates/images/global/modules/popup/popup_bbg.png', 
					  'fileadmin/templates/images/global/modules/popup/popup_bg.png',
					  'fileadmin/templates/images/global/modules/popup/popup_tbg.png']);
	
	modalBox = new Modalizer();

	// Open Pop-ups
	$$("a.showWhyCreateAccount").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#whyCreateAccount').removeClass('hide');
					$$('#whyCreateAccount').addClass('show');
					modalBox.modalShow({element:$('whyCreateAccount')});					
				});
	  		}
		);
	$$("a.showforgotPass").each( function(a){
		a.addEvent("click", function(){ 
				$$('#forgotPass').removeClass('hide');
				$$('#forgotPass').addClass('show');
				$$('#yourEmail').getParent().getParent().removeClass('hide');
				$$('#yourEmail').getParent().getParent().addClass('show');
				$('yourEmail').focus();
				modalBox.modalShow({element:$('forgotPass')});
				});
	  		}
		);
	$$("a.showConfirmDelete").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#confirmDelete').removeClass('hide');
					$$('#confirmDelete').addClass('show');
					modalBox.modalShow({element:$('confirmDelete')});					
				});
	  		}
		);
	//added by Christine for hiding/showing 8 entries in CA-20
	$$("a.expandMore").each(  function(a){
		a.addEvent("click", function(){ 
					$$('.overEight').removeClass('hide');
					$$('.overEight').addClass('show');
					$$('a.expandMore').removeClass('show');
					$$('a.expandMore').addClass('hide');
					$$('a.expandFewer').removeClass('hide');
					$$('a.expandFewer').addClass('show');
				});
	  		}
		);
	$$("a.expandFewer").each(  function(a){
		a.addEvent("click", function(){ 
					$$('.overEight').removeClass('show');
					$$('.overEight').addClass('hide');
					$$('a.expandFewer').removeClass('show');
					$$('a.expandFewer').addClass('hide');
					$$('a.expandMore').removeClass('hide');
					$$('a.expandMore').addClass('show');
				});
	  		}
		);
	//end add
	
	$$("a.showConfirmCancel").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#confirmCancel').removeClass('hide');
					$$('#confirmCancel').addClass('show');
					modalBox.modalShow({element:$('confirmCancel')});					
				});
	  		}
		);
	$$("a.showConfirmRemove").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#confirmRemove').removeClass('hide');
					$$('#confirmRemove').addClass('show');
					modalBox.modalShow({element:$('confirmRemove')});					
				});
	  		}
		);
	$$("a.showEmailFriend").each(  function(a){
		a.addEvent("click", function(){ 
					var OS = navigator.platform.toLowerCase();
					// If Mac and FF 2
					if ((OS.indexOf("mac") != -1) && (navigator.userAgent.indexOf("Firefox/2")!=-1)) {
						$$('#flashVideoPlayerMediumHide').removeClass('hide');
						$$('#flashVideoPlayerMedium').addClass('hide');
						$$('#flashAudioPlayerMediumHide').removeClass('hide');
						$$('#flashAudioPlayerMedium').addClass('hide');
					}
					$$('#emailFriend').removeClass('hide');
					$$('#emailFriend').addClass('show');
					$$('#emailFriendContent').removeClass('hide');
					$$('#emailFriendContent').addClass('show');
					$$('#emailFriendThankYou').removeClass('show');
					$$('#emailFriendThankYou').addClass('hide');
					modalBox.modalShow({element:$('emailFriend')});					
				});
	  		}
		);
	$$("a.showShare").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#Share').removeClass('hide');
					$$('#Share').addClass('show');
					modalBox.modalShow({element:$('Share')});	
				});
	  		}
		);
	$$("a.showVlc").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#Vlc').removeClass('hide');
					$$('#Vlc').addClass('show');
					modalBox.modalShow({element:$('Vlc')});
				});
	  		}
		);
	
	$$("a.showEmbedCode").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#embedCode').removeClass('hide');
					$$('#embedCode').addClass('show');
					clip = new ZeroClipboard.Client();
					clip.setText(document.getElementById('embedText').value);
					clip.glue('copyToClipboard');
					modalBox.modalShow({element:$('embedCode')});					
				});
	  		}
		);
	$$("a.showSourceCode").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#sourceCode').removeClass('hide');
					$$('#sourceCode').addClass('show');
					modalBox.modalShow({element:$('sourceCode')});					
				});
	  		}
		);
	$$("a.whatIsScrapbooking").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#scrapbooking').removeClass('hide');
					$$('#scrapbooking').addClass('show');
					modalBox.modalShow({element:$('scrapbooking')});					
				});
	  		}
		);
	$$("a.dontHaveYourPin").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#dontHavePin').removeClass('hide');
					$$('#dontHavePin').addClass('show');
					modalBox.modalShow({element:$('dontHavePin')});					
				});
	  		}
		);
	$$("a.showEditMessage").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#editMessage').removeClass('hide');
					$$('#editMessage').addClass('show');
					modalBox.modalShow({element:$('editMessage')});					
				});
	  		}
		);
	$$("a.showAddTeam").each(  function(a){
		a.addEvent("click", function(){ 							 
					$$('#addTeam').removeClass('hide');
					$$('#addTeam').addClass('show');
					modalBox.modalShow({element:$('addTeam')});					
				});
	  		}
		);
	$$("li.createanother a").each(  function(a){
		a.addEvent("click", function(){ 							 
					$$('#saveItineraryLoggedIn').removeClass('hide');
					$$('#saveItineraryLoggedIn').addClass('show');
					modalBox.modalShow({element:$('saveItineraryLoggedIn')});					
				});
	  		}
		);
	$$("a.editItinerary").each(  function(a){
		a.addEvent("click", function(){ 							 
					$$('#saveItineraryLoggedIn2').removeClass('hide');
					$$('#saveItineraryLoggedIn2').addClass('show');
					modalBox.modalShow({element:$('saveItineraryLoggedIn2')});					
				});
	  		}
		);
	$$(".autoshow").each(  function(el){	 
				el.removeClass('hide');
				el.addClass('show');
				modalBox.modalShow({element:el});	
	  		}
		);
	$$("li.saveaccount a").each(  function(a){
		a.addEvent("click", function(){ 							 
					$$('#saveItineraryNotLoggedIn').removeClass('hide');
					$$('#saveItineraryNotLoggedIn').addClass('show');
					modalBox.modalShow({element:$('saveItineraryNotLoggedIn')});					
				});
	  		}
		);

/*	$$("a.showEditTeam").each(  function(a){
		a.addEvent("click", function(){ 			 
					$$('#editTeam').removeClass('hide');
					$$('#editTeam').addClass('show');
					modalBox.modalShow({element:$('editTeam')});					
				});
	  		}
		);*/
/*	
	$$("a.showAddEditTeamMembers").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#addEditTeamMembers').removeClass('hide');
					$$('#addEditTeamMembers').addClass('show');
					modalBox.modalShow({element:$('addEditTeamMembers')});					
				});
	  		}
		);*/
	if($E(".showinvalidPIN")){
					$$('#invalidPIN').removeClass('hide');
					$$('#invalidPIN').addClass('show');
					modalBox.modalShow({element:$('invalidPIN')});					
	  		}
	
/*	if($E(".showNotification")){
					$$('#notification').removeClass('hide');
					$$('#notification').addClass('show');
					modalBox.modalShow({element:$('notification')});					
	  		}*/
			
	// iFrame fix for ie6.
	if($('why')) {
		var whyDivShim = new IframeShim({
			element: 'why',
			display: false,
			name: 'whyDivShimName'
		});			
	}
	$$("a.showWhy").each( function(a){
		a.addEvent("click", function(){ 
				//showMyFloatingDiv();
				$$('#why').removeClass('hide');
				$$('#why').addClass('show');
				whyDivShim.show();
				modalBox.modalShow({element:$('why')});
				});
	  		}
		);

	// iFrame fix for ie6.
	if($('cscExplanation')) {
		var cscExplanationDivShim = new IframeShim({
			element: 'cscExplanation',
			display: false,
			name: 'cscExplanationDivShimName'
		});			
	}
	$$("a.showWhat").each( function(a){
		a.addEvent("click", function(){ 
				$$('#cscExplanation').removeClass('hide');
				$$('#cscExplanation').addClass('show');
				cscExplanationDivShim.show();
				modalBox.modalShow({element:$('cscExplanation')});
				});
	  		}
		);
	

	
	// Close Pop-ups
	$$(".close").each( function(a){
	a.addEvent("click", function(){ 
     		modalBox.modalHide();
			$$('#whyCreateAccount').removeClass('show');
			$$('#whyCreateAccount').addClass('hide');
			
			$$('#confirmDelete').removeClass('show');
			$$('#confirmDelete').addClass('hide');
			
			$$('#notification').removeClass('show');
			$$('#notification').addClass('hide');
			
			$$('#editMessage').removeClass('show');
			$$('#editMessage').addClass('hide');
			
			$$('#addTeam').removeClass('show');
			$$('#addTeam').addClass('hide');
			
			$$('#editTeam').removeClass('show');
			$$('#editTeam').addClass('hide');
			
			$$('.addEditTeamMembers').removeClass('show');
			$$('.addEditTeamMembers').addClass('hide');
			
			$$('#confirmRemove').removeClass('show');
			$$('#confirmRemove').addClass('hide');
			
			$$('#confirmCancel').removeClass('show');
			$$('#confirmCancel').addClass('hide');
			
			var OS = navigator.platform.toLowerCase();
			// If Mac and FF 2
			if ((OS.indexOf("mac") != -1) && (navigator.userAgent.indexOf("Firefox/2")!=-1)) {
				$$('#flashVideoPlayerMedium').removeClass('hide');
				$$('#flashVideoPlayerMediumHide').addClass('hide');
				$$('#flashAudioPlayerMedium').removeClass('hide');
				$$('#flashAudioPlayerMediumHide').addClass('hide');
			}
			$$('#emailFriend').removeClass('show');
			$$('#emailFriend').addClass('hide');
			
			$$('#saveItineraryLoggedIn').removeClass('show');
			$$('#saveItineraryLoggedIn').addClass('hide');
			
			$$('#saveItineraryLoggedIn2').removeClass('show');
			$$('#saveItineraryLoggedIn2').addClass('hide');
			
			$$('#saveItineraryNotLoggedIn').removeClass('show');
			$$('#saveItineraryNotLoggedIn').addClass('hide');

			//Clear form fields when close the popup
			if ($('emailFriendForm')){
				//alert('test');
				if ($('yourFriendsEmail').getTag() == 'input' || $('message').getTag() == 'textarea' || $('captcha').getTag() == 'input' || $('receiveEmail').getTag() == 'input') {
					if ($('yourFriendsEmail').value != '') {$('yourFriendsEmail').value= '';}
					if ($('message').value != '') {$('message').value= '';}
					if ($('captcha').value != '') {$('captcha').value= '';}
					if ($('receiveEmail').checked) {$('receiveEmail').removeProperty('checked','checked');}
				}
				$('submitButton').removeClass('hide');
				$('submitButton').getNext().removeClass('hide');
				document.getElementById('loading_image').style.display = 'none';
				if ($('advice-validate-multiEmail-yourFriendsEmail')){
					$$('.validation-advice').setStyle('display','none');
				}
				if ($('advice-validate-multiEmail-yourFriendsEmail') || $('advice-required-message-message') || $('advice-captcha_required_empty-captcha') || $('advice-required-name-yourName') || $('advice-validate-email-yourEmail')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
			if ($('emailFriendItineraryForm')){
				//alert('test');
				if ($('yourFriendsEmail').getTag() == 'input' || $('message').getTag() == 'textarea' || $('captcha').getTag() == 'input' || $('receiveEmail').getTag() == 'input') {
					if ($('yourFriendsEmail').value != '') {$('yourFriendsEmail').value= '';}
					if ($('message').value != '') {$('message').value= '';}
					if ($('captcha').value != '') {$('captcha').value= '';}
					if ($('receiveEmail').checked) {$('receiveEmail').removeProperty('checked','checked');}
				}
				$('submitButton').removeClass('hide');
				$('submitButton').getNext().removeClass('hide');
				document.getElementById('loading_image').style.display = 'none';
				if ($('advice-validate-multiEmail-yourFriendsEmail')){
					$$('.validation-advice').setStyle('display','none');
				}
				if ($('advice-validate-multiEmail-yourFriendsEmail') || $('advice-required-message-message') || $('advice-captcha_required_empty-captcha') || $('advice-required-name-yourName') || $('advice-validate-email-yourEmail')){
					$$('.validation-advice').setStyle('display','none');
				}
			}

			if ($('addTeamForm')) {
				if ($('teamName').getTag() == 'input'){
					if ($('team_name').value != '') {$('team_name').value= '';}
				}
				if ($('advice-required_empty-team_name')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
			if ($('editTeamForm')) {
				if ($('team_name').getTag() == 'input'){
					if ($('teamName').value != '') {$('teamName').value= '';}
				}
				if ($('advice-required_empty-teamName')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
			if ($('createItineraryForm')) {
				if ($('itineraryName').getTag() == 'input'){
					if ($('itineraryName').value != '') {$('itineraryName').value= '';}
				}
				if ($('advice-required_empty-itineraryName')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
			if ($('createItineraryForm2')) {
				if ($('advice-required_empty-itineraryName2')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
						
			
			$$('#Share').removeClass('show');
			$$('#Share').addClass('hide');
			
			if (document.getElementById('Vlc') && document.getElementById('Vlc').className == 'popup show'){
				window.location.href = document.getElementById('downloadAssetUrl').value;
			}
			$$('#Vlc').removeClass('show');
			$$('#Vlc').addClass('hide');
			
			$$('#embedCode').removeClass('show');
			$$('#embedCode').addClass('hide');
			if ($E('p.codeCopied')) {$E('p.codeCopied').remove();}
			if ($E('div.copyText')) {$E('div.copyText').remove();}
				
			$$('#sourceCode').removeClass('show');
			$$('#sourceCode').addClass('hide');	
				
			$$('#scrapbooking').removeClass('show');
			$$('#scrapbooking').addClass('hide');

			$$('#dontHavePin').removeClass('show');
			$$('#dontHavePin').addClass('hide');
			
			$$('#invalidPIN').removeClass('show');
			$$('#invalidPIN').addClass('hide');
			
			$$('#forgotPass').removeClass('show');
			$$('#forgotPass').addClass('hide');
			if ($$("form#forgotPassForm input#yourEmail").getTag() == 'input') {
					if ($('yourEmail').value != '') {
						$('user').focus();
						$('yourEmail').value= '';
					}
			}
			if (document.getElementById('advice-validate-email_address-yourEmail')){
				$$('.validation-advice').setStyle('display','none');
			}
			$$('#ajaxMessage').setStyle('margin-top','0');	
			$$('#ajaxMessage').setStyle('display','none');
			$$('#ajaxMessage').setHTML('');
			if ($('closeButton')){
				$('submitButton').removeClass('hide');
				$('closeButton').removeClass('buttonClose');
				$('closeButton').addClass('cancel');				
			}
			
			// Check if the shim iframe has been created before hiding it
			if(whyDivShim) whyDivShim.hide();
			$$('#why').removeClass('show');
			$$('#why').addClass('hide');
			
			// Check if the shim iframe has been created before hiding it			
			if(cscExplanationDivShim) cscExplanationDivShim.hide();
				$$('#cscExplanation').removeClass('show');
				$$('#cscExplanation').addClass('hide');
			});
		}
	);
	
	// keyboard ESC press
	$(window.document).addEvent('keydown',function(e){
		if(e.key == 'esc'){ 
			modalBox.modalHide();
			$$('#whyCreateAccount').removeClass('show');
			$$('#whyCreateAccount').addClass('hide');
			
			$$('#confirmDelete').removeClass('show');
			$$('#confirmDelete').addClass('hide');
			
			$$('#notification').removeClass('show');
			$$('#notification').addClass('hide');
			
			$$('#editMessage').removeClass('show');
			$$('#editMessage').addClass('hide');
			
			$$('#addTeam').removeClass('show');
			$$('#addTeam').addClass('hide');
			
			$$('#editTeam').removeClass('show');
			$$('#editTeam').addClass('hide');
			
			$$('.addEditTeamMembers').removeClass('show');
			$$('.addEditTeamMembers').addClass('hide');
			
			$$('#confirmCancel').removeClass('show');
			$$('#confirmCancel').addClass('hide');
			
			$$('#confirmRemove').removeClass('show');
			$$('#confirmRemove').addClass('hide');
			
			var OS = navigator.platform.toLowerCase();
			// If Mac and FF 2
			if ((OS.indexOf("mac") != -1) && (navigator.userAgent.indexOf("Firefox/2")!=-1)) {
				$$('#flashVideoPlayerMedium').removeClass('hide');
				$$('#flashVideoPlayerMediumHide').addClass('hide');
				$$('#flashAudioPlayerMedium').removeClass('hide');
				$$('#flashAudioPlayerMediumHide').addClass('hide');
			}
			$$('#emailFriend').removeClass('show');
			$$('#emailFriend').addClass('hide');
			
			$$('#saveItineraryLoggedIn').removeClass('show');
			$$('#saveItineraryLoggedIn').addClass('hide');
			
			$$('#saveItineraryLoggedIn2').removeClass('show');
			$$('#saveItineraryLoggedIn2').addClass('hide');
			
			$$('#saveItineraryNotLoggedIn').removeClass('show');
			$$('#saveItineraryNotLoggedIn').addClass('hide');
			
			//Clear form fields when close the popup
			if ($('emailFriendForm')){
//				$('submitButton').focus();
				if ($('yourFriendsEmail').getTag() == 'input' || $('message').getTag() == 'textarea' || $('captcha').getTag() == 'input' || $('receiveEmail').getTag() == 'input') {
					if ($('yourFriendsEmail').value != '') {$('yourFriendsEmail').value= ''; $('yourFriendsEmail').blur();}
					if ($('message').value != '') {$('message').value= '';}
					if ($('captcha').value != '') {$('captcha').value= ''; $('captcha').blur();}
					if ($('receiveEmail').checked) {$('receiveEmail').removeProperty('checked','checked');}
				}
				$('submitButton').removeClass('hide');
				$('submitButton').getNext().removeClass('hide');
				document.getElementById('loading_image').style.display = 'none';
				$$('.validation-advice').setStyle('display','none');
			}
			if ($('emailFriendItineraryForm')){
//				$('submitButton').focus();
				if ($('yourFriendsEmail').getTag() == 'input' || $('message').getTag() == 'textarea' || $('captcha').getTag() == 'input' || $('receiveEmail').getTag() == 'input') {
					if ($('yourFriendsEmail').value != '') {$('yourFriendsEmail').value= ''; $('yourFriendsEmail').blur();}
					if ($('message').value != '') {$('message').value= '';}
					if ($('captcha').value != '') {$('captcha').value= ''; $('captcha').blur();}
					if ($('receiveEmail').checked) {$('receiveEmail').removeProperty('checked','checked');}
				}
				$('submitButton').removeClass('hide');
				$('submitButton').getNext().removeClass('hide');
				document.getElementById('loading_image').style.display = 'none';
				$$('.validation-advice').setStyle('display','none');
			}

			if ($('addTeamForm')) {
				if ($('teamName').getTag() == 'input'){
					if ($('teamName').value != '') {$('teamName').value= '';}
				}
				if ($('advice-required_empty-team_name')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
			if ($('editTeamForm')) {
				if ($('team_name').getTag() == 'input'){
					if ($('team_name').value != '') {$('team_name').value= '';}
				}
				if ($('advice-required_empty-teamName')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
			if ($('createItineraryForm')) {
				if ($('itineraryName').getTag() == 'input'){
					if ($('itineraryName').value != '') {$('itineraryName').value= '';}
				}
				if ($('advice-required_empty-itineraryName')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
			if ($('createItineraryForm2')) {
				if ($('advice-required_empty-itineraryName2')){
					$$('.validation-advice').setStyle('display','none');
				}
			}
			
			if ($('classNotificationContent')) {
				//alert('esc pressed');
				//window.location.href=window.location.href;
				//closeBtn.fireEvent('click');
				location.reload(true);
			}
			
			$$('#Share').removeClass('show');
			$$('#Share').addClass('hide');
			$$('#Vlc').removeClass('show');
			$$('#Vlc').addClass('hide');
			
			$$('#embedCode').removeClass('show');
			$$('#embedCode').addClass('hide');
			if ($E('p.codeCopied')) {$E('p.codeCopied').remove();}
			if ($E('div.copyText')) {$E('div.copyText').remove();}
			
			$$('#sourceCode').removeClass('show');
			$$('#sourceCode').addClass('hide');	
			
			$$('#scrapbooking').removeClass('show');
			$$('#scrapbooking').addClass('hide');
			
			$$('#dontHavePin').removeClass('show');
			$$('#dontHavePin').addClass('hide');
			
			$$('#invalidPIN').removeClass('show');
			$$('#invalidPIN').addClass('hide');

			$$('#forgotPass').removeClass('show');
			$$('#forgotPass').addClass('hide');
			if ($$("form#forgotPassForm input#yourEmail").getTag() == 'input') {
				if ($('yourEmail').value != '') {
					$('user').focus();
					$('yourEmail').value= '';
				}
			}
			if (document.getElementById('advice-validate-email_address-yourEmail')){
				$$('.validation-advice').setStyle('display','none');
			}
			$$('#ajaxMessage').setStyle('display','none');
			$$('#ajaxMessage').setStyle('margin-top','0');
			$$('#ajaxMessage').setHTML('');
			if ($('closeButton')){
				$('submitButton').removeClass('hide');
				$('closeButton').removeClass('buttonClose');
				$('closeButton').addClass('cancel');				
			}
			
			// Check if the shim iframe has been created before hiding it
			if(whyDivShim) whyDivShim.hide();
			$$('#why').removeClass('show');
			$$('#why').addClass('hide');

			// Check if the shim iframe has been created before hiding it
			if(cscExplanationDivShim) cscExplanationDivShim.hide();			
			$$('#cscExplanation').removeClass('show');
			$$('#cscExplanation').addClass('hide');
		};
	}.bindWithEvent(this));
	
	// Image Sizes
	$$("p.changeEmbedSmall a").each(  function(a){
		a.addEvent("click", function(){ 
					var embedText = document.getElementById('embedText').value;
					embedText = embedText.replace(/(width="476"|width="600")/, 'width="300"');
					embedText = embedText.replace(/(height="317"|height="400")/, 'height="200"');
					document.getElementById('embedText').value = embedText;
					clip.setText(document.getElementById('embedText').value);
					// Make this Active
					a.className = "isactive";
					$$("#embedMedium").removeClass('isactive');
					$$("#embedLarge").removeClass('isactive');
				});
	  		}
		);
	$$("p.changeEmbedMedium a").each(  function(a){
		a.addEvent("click", function(){ 
					var embedText = document.getElementById('embedText').value;
					embedText = embedText.replace(/(width="300"|width="600")/, 'width="476"');
					embedText = embedText.replace(/(height="200"|height="400")/, 'height="317"');
					document.getElementById('embedText').value = embedText;
					clip.setText(document.getElementById('embedText').value);
					// Make this Active
					a.className = "isactive";
					$$("#embedSmall").removeClass('isactive');
					$$("#embedLarge").removeClass('isactive');
				});
	  		}
		);
	$$("p.changeEmbedLarge a").each(  function(a){
		a.addEvent("click", function(){ 
					var embedText = document.getElementById('embedText').value;
					embedText = embedText.replace(/(width="300"|width="476")/, 'width="600"');
					embedText = embedText.replace(/(height="200"|height="317")/, 'height="400"');
					document.getElementById('embedText').value = embedText;
					clip.setText(document.getElementById('embedText').value);
					// Make this Active
					a.className = "isactive";
					$$("#embedSmall").removeClass('isactive');
					$$("#embedMedium").removeClass('isactive');
				});
	  		}
		);
	
	// Audio Player Sizes
	$$("p.changeEmbedSmallAudio a").each(  function(a){
		a.addEvent("click", function(){ 
					var embedText = document.getElementById('embedText').value;
					embedText = embedText.replace(/(width="482"|width="608")/g, 'width="400"');
					//embedText = embedText.replace(/(height="142")/, 'height="142"');
					document.getElementById('embedText').value = embedText;
					clip.setText(document.getElementById('embedText').value);
					// Make this Active
					a.className = "isactive";
					$$("#embedMediumAudio").removeClass('isactive');
					$$("#embedLargeAudio").removeClass('isactive');
				});
	  		}
		);
	$$("p.changeEmbedMediumAudio a").each(  function(a){
		a.addEvent("click", function(){ 
					var embedText = document.getElementById('embedText').value;
					embedText = embedText.replace(/(width="400"|width="608")/g, 'width="482"');
					//embedText = embedText.replace(/(height="142")/, 'height="142"');
					document.getElementById('embedText').value = embedText;
					clip.setText(document.getElementById('embedText').value);
					// Make this Active
					a.className = "isactive";
					$$("#embedSmallAudio").removeClass('isactive');
					$$("#embedLargeAudio").removeClass('isactive');
				});
	  		}
		);
	$$("p.changeEmbedLargeAudio a").each(  function(a){
		a.addEvent("click", function(){ 
					var embedText = document.getElementById('embedText').value;
					embedText = embedText.replace(/(width="400"|width="482")/g, 'width="608"');
					//embedText = embedText.replace(/(height="142")/, 'height="142"');
					document.getElementById('embedText').value = embedText;
					clip.setText(document.getElementById('embedText').value);
					// Make this Active
					a.className = "isactive";
					$$("#embedSmallAudio").removeClass('isactive');
					$$("#embedMediumAudio").removeClass('isactive');
				});
	  		}
		);
	

	//Hightlight Email in --Change Email or Password-- form
	if ($$("form#changeEmailPassword input#email")) {
		function hightlight(){
			if ($$("form#changeEmailPassword input#email").getTag() == 'input') {
				$("email").focus();
				$("email").select();
			}
		}
		hightlight();
	};
	
	// MY Profile - Contact Info
	// My billing information is the same as my mailing address
	$$("input.unchecked_billing_info").each( function(a){
		a.addEvent("click", function(){ 
			if (a.checked) {
				$$('#billingInfo').addClass('hide');
				$$('#billingInfo').removeClass('show');
				$$('#donorBillingInfo').addClass('hide');
				$$('#donorBillingInfo').removeClass('show');
			} else {
				$$('#billingInfo').removeClass('hide');
				$$('#billingInfo').addClass('show');
				$$('#donorBillingInfo').removeClass('hide');
				$$('#donorBillingInfo').addClass('show');
				}
			});
		}
	);
	
	
	// Expand/Collapse Calendar in Itineraries
	$$(".formHeader p.togglerCalendarOpen").each( function(a){
		a.addEvent("click", function(){ 
				//hideItineraryCalendar();
				//myCal3.toggle(myCal3);
				$$('.dayattending').getElement('button').fireEvent('click');
			});
		}
	);
	$$(".formHeader p.togglerCalendarClose").each( function(a){
		a.addEvent("click", function(){ 
				$$('.dayattending').getElement('button').fireEvent('click');
			});
		}
	);
	
	if($('displayDate')){
		$('displayDate').addEvent('click', function(e) {
			
			e = new Event(e);
			$$('.dayattending').getElement('button').fireEvent('click');
			e.stop();
			
		});
		
		if($('datePlan').value == ''){
			$$('.dayattending').getElement('button').fireEvent('click');
		}
	}
	
	
	// Expand/Collapse Interests in Itineraries
	$$(".formHeader p.togglerOpen").each( function(a){
		a.addEvent("click", function(){ 
				$$('.itineraryInterests').addClass('hide');
				$$('.itineraryInterests').removeClass('show');
				$$('.formHeader p.togglerOpen').addClass('hide');
				$$('.formHeader p.togglerOpen').removeClass('show');
				$$('.formHeader p.togglerClose').addClass('show');
				$$('.formHeader p.togglerClose').removeClass('hide');
			});
		}
	);
	$$(".formHeader p.togglerClose").each( function(a){
		a.addEvent("click", function(){ 
				$$('.itineraryInterests').addClass('show');
				$$('.itineraryInterests').removeClass('hide');
				$$('.formHeader p.togglerOpen').addClass('show');
				$$('.formHeader p.togglerOpen').removeClass('hide');
				$$('.formHeader p.togglerClose').addClass('hide');
				$$('.formHeader p.togglerClose').removeClass('show');
			});
		}
	);
	
	// If "I am making this reservation for another person" is checked
	$$("input#reservationForAnother").each( function(a){
		if (a.checked) {
				$$('#otherReservation').removeClass('hide');
				$$('#otherReservation').addClass('show');
			} else {
				$$('#otherReservation').addClass('hide');
				$$('#otherReservation').removeClass('show');
				}
		a.addEvent("click", function(){ 
			if (a.checked) {
				$$('#otherReservation').removeClass('hide');
				$$('#otherReservation').addClass('show');
			} else {
				$$('#otherReservation').addClass('hide');
				$$('#otherReservation').removeClass('show');
				}
			});
		}
	);
	
	if($("arrangement")){
		if ($("arrangement").getTag() == 'select') {
			var selected = $("arrangement")[$("arrangement").selectedIndex].value;
			
			if (selected == "boxLunch"){
					$('lunch_boxes').removeClass('hide');
					$('lunch_boxes').addClass('show');
					if($('lunch_time')){
						$('lunch_time').removeClass('hide');
						$('lunch_time').addClass('show');
					}
				} else if (selected == "bagLunch"){
					$('lunch_boxes').addClass('hide');
					$('lunch_boxes').removeClass('show');
					if($('lunch_time')){
						$('lunch_time').removeClass('hide');
						$('lunch_time').addClass('show');
					}
				} else {
					$('lunch_boxes').addClass('hide');
					$('lunch_boxes').removeClass('show');
					if($('lunch_time')){
						$('lunch_time').addClass('hide');
						$('lunch_time').removeClass('show');
					}
				}
			
			$("arrangement").addEvent("change", function(){
				var selected = $("arrangement")[$("arrangement").selectedIndex].value;
				if (selected == "boxLunch"){
					$('lunch_boxes').removeClass('hide');
					$('lunch_boxes').addClass('show');
					if($('lunch_time')){
						$('lunch_time').removeClass('hide');
						$('lunch_time').addClass('show');
					}
				} else if (selected == "bagLunch"){
					$('lunch_boxes').addClass('hide');
					$('lunch_boxes').removeClass('show');
					if($('lunch_time')){
						$('lunch_time').removeClass('hide');
						$('lunch_time').addClass('show');
					}
				} else {
					$('lunch_boxes').addClass('hide');
					$('lunch_boxes').removeClass('show');
					if($('lunch_time')){
						$('lunch_time').addClass('hide');
						$('lunch_time').removeClass('show');
					}
				}
			});
		}
	}
	
	// Reset learning lab times if user selects not to have a learning lab
	if($("secLearningLab")){
		if($("secLearningLab").value == ''){
			$("secChoiceTime1st").selectedIndex = 0;
			$("secChoiceTime2nd").selectedIndex = 0;
		}
		
		$("secLearningLab").addEvent("change", function(){
			if($("secLearningLab").value == ''){
				$("secChoiceTime1st").selectedIndex = 0;
				$("secChoiceTime2nd").selectedIndex = 0;
			}
		});
	}
	if($("firstLearningLab")){
		if($("firstLearningLab").value == ''){
			$("flchoiceTime1st").selectedIndex = 0;
			$("flchoiceTime2nd").selectedIndex = 0;
		}
		
		$("firstLearningLab").addEvent("change", function(){
			if($("firstLearningLab").value == ''){
				$("flchoiceTime1st").selectedIndex = 0;
				$("flchoiceTime2nd").selectedIndex = 0;
			}
		});
	}
	

	
	// Donations: Make a gift - corporate gift
	$$("input.corporateGift").each( function(a){
		a.addEvent("click", function(){ 
			if (a.checked) {
				$$('#corporateGiftMessage').removeClass('hide');
				$$('#corporateGiftMessage').addClass('show');
			} else {
				$$('#corporateGiftMessage').addClass('hide');
				$$('#corporateGiftMessage').removeClass('show');
				}
			});
		}
	);
	
	// Donations: Make a gift - Honor of
	$$("input.honorOf").each( function(a){
		a.addEvent("click", function(){ 
			if (a.checked) {
				$$('#honorInfo').removeClass('hide');
				$$('#honorInfo').addClass('show');
			} else {
				$$('#honorInfo').addClass('hide');
				$$('#honorInfo').removeClass('show');
				}
			});
		}
	);
	
	// Donations: Make a gift - Memory of
	$$("input.memoryOf").each( function(a){
		a.addEvent("click", function(){ 
			if (a.checked) {
				$$('#memoryInfo').removeClass('hide');
				$$('#memoryInfo').addClass('show');
			} else {
				$$('#memoryInfo').addClass('hide');
				$$('#memoryInfo').removeClass('show');
				}
			});
		}
	);
	
	// My Profile - Communication Preferences
	// If I would like to receive SMS alerts is checked
	$$("input#smsAlerts").each( function(a){
		if (a.checked) {
			$$('.phoneInformation').removeClass('hide');
			$$('.phoneInformation').addClass('show');
		} else {
			$$('.phoneInformation').addClass('hide');
			$$('.phoneInformation').removeClass('show');
			}
		a.addEvent("click", function(){ 
			if (a.checked) {
				$$('.phoneInformation').removeClass('hide');
				$$('.phoneInformation').addClass('show');
			} else {
				$$('.phoneInformation').addClass('hide');
				$$('.phoneInformation').removeClass('show');
				}
			});
		}
	);
	
	// I would like to receive email communications from the Museum 
	// and General Imformation checked
	if ($("receiveEmailCom")) {
		if ($("receiveEmailCom").getTag() == 'input') {
			if ($("receiveEmailCom").value == 'yes') {
				var input = $("receiveEmailCommunications");
				var input2 = $("generalInformation");
				input.setProperty('checked', 'checked');
				input2.setProperty('checked', 'checked');
			}
		}
	};

	// Membership Degree Selection
	if ($("membershipDegree")) {
			if ($("membershipDegree").getTag() == 'select') {
				// Get selected Amount
				var selectedAmount = $("membershipDegree")[$("membershipDegree").selectedIndex].title;
				// If there is a discount
				if (document.getElementById('discount').value!=0) {
					// Get the discount value from the hidden field
					var discount = document.getElementById('discount').value;
					// Print the old and new prices
					$("amount").setHTML('<span class="oldprice">$'+selectedAmount+'</span> <span class="specialprice">$'+(selectedAmount-discount)+'</span>');
					// Add the new amount to the hidden price field
					document.getElementById('price').value = (selectedAmount-discount);
				}
				else {
					// Print the amount
					$("amount").setHTML('$'+selectedAmount);
					// Add the amount to the hidden price field
					document.getElementById('price').value = selectedAmount;
				}
				// Show or hide the Master and Doctorate extra fields
				if ($("membershipDegree").value == 'Associate - Student' || $("membershipDegree").value == 'Associate - Senior' || $("membershipDegree").value == 'Bachelor of Science - Ind') {
					$('md_content').removeClass('show');
					$('md_content').addClass('hide');
				} else {
					$('md_content').addClass('show');
					$('md_content').removeClass('hide');
				}
			}
		$("membershipDegree").addEvent("change", function(){
			if ($("membershipDegree").getTag() == 'select') {
				// Get selected Amount
				var selectedAmount = $("membershipDegree")[$("membershipDegree").selectedIndex].title;
				// If there is a discount
				if (document.getElementById('discount').value!=0) {
					// Get the discount value from the hidden field
					var discount = document.getElementById('discount').value;
					// Print the old and new prices
					$("amount").setHTML('<span class="oldprice">$'+selectedAmount+'</span> <span class="specialprice">$'+(selectedAmount-discount)+'</span>');
					// Add the new amount to the hidden price field
					document.getElementById('price').value = (selectedAmount-discount);
				}
				else {
					// Print the amount
					$("amount").setHTML('$'+selectedAmount);
					// Add the amount to the hidden price field
					document.getElementById('price').value = selectedAmount;
				}
				// Show or hide the Master and Doctorate extra fields
				if ($("membershipDegree").value == 'Associate - Student' || $("membershipDegree").value == 'Associate - Senior' || $("membershipDegree").value == 'Bachelor of Science - Ind') {
					$('md_content').removeClass('show');
					$('md_content').addClass('hide');
				} else {
					$('md_content').addClass('show');
					$('md_content').removeClass('hide');
				}
			}
		});
	}

	// Disable e-newsletter communications checkboxes 
	// if the I would like to receive email communications from the Museum is not checked
	if ($("receiveEmailCommunications")) {
		if ($("receiveEmailCommunications").checked) {
			$$(".newsletterCheck").removeProperty('disabled', 'disabled');
			$$(".newsletterCheck").getParent().getParent().getParent().getParent().removeClass('inactive');
		} else {
			$$(".newsletterCheck").setProperty('disabled', 'disabled');
			$$(".newsletterCheck").getParent().getParent().getParent().getParent().addClass('inactive');
			}
		$("receiveEmailCommunications").addEvent("click", function(){ 
			if ($("receiveEmailCommunications").checked) {				 
				$$(".newsletterCheck").removeProperty('disabled', 'disabled');
				$$(".newsletterCheck").getParent().getParent().getParent().getParent().removeClass('inactive');
			} else {
				$$(".newsletterCheck").setProperty('disabled', 'disabled');
				$$(".newsletterCheck").getParent().getParent().getParent().getParent().addClass('inactive');
				}
		});
	}

// Highlight checkboxes when checked
	$$("#interests div.checkboxGroup dl.checkbox input.checkbox").each( function(a){
		if (!a.checked) {
			a.getParent().getPrevious().getChildren().addClass('inactive');
		} else {
			a.getParent().getPrevious().getChildren().removeClass('inactive');
			}
		a.addEvent("click", function(){ 
			if (a.checked) {
				a.getParent().getPrevious().getChildren().removeClass('inactive');
			} else {
				a.getParent().getPrevious().getChildren().addClass('inactive');
				}
			});
		}
	);
	
	// If Gift Amount >= $100, display "For gifts of $100 or more, list me in the Annual Report as" box
	function getRadio() {
		$('otherContributeAmount').addEvent("focus", function() {
			$$('form#makeGift .radio').each(function (radio) {
				if (radio.getProperty('checked')) {
					radio.removeProperty('checked');
				}
			});
			$('otherAmount').setProperty('checked','checked');
		});
		$('otherContributeAmount').addEvent("blur", function() {
			if ($('otherAmount').checked && $('otherContributeAmount').value != "") {
					if ($('otherContributeAmount').value >= 100) {
						$('listAnnualReportBox').removeClass('hide');
						$('listAnnualReportBox').addClass('show');
					} else {
						$('listAnnualReportBox').addClass('hide');
						$('listAnnualReportBox').removeClass('show');
					}
				
			}
		});
			
		$$('form#makeGift .radio').each(function (radio) {
				if (radio.getProperty('checked')) {
					
					if (!$('otherAmount').checked) {
						$('otherContributeAmount').value = "";
					}
					
					if (radio.value >= 100 ) {
						$('listAnnualReportBox').removeClass('hide');
						$('listAnnualReportBox').addClass('show');
					} else if (radio.value < 100 && radio.value != ""){
						$('listAnnualReportBox').addClass('hide');
						$('listAnnualReportBox').removeClass('show');
					} else if ($('otherAmount').checked && $('otherContributeAmount').value != "") {
						
							if ($('otherContributeAmount').value >= 100) {
								$('listAnnualReportBox').removeClass('hide');
								$('listAnnualReportBox').addClass('show');
							} else {
								$('listAnnualReportBox').addClass('hide');
								$('listAnnualReportBox').removeClass('show');
							}
						
					} else {
						$('listAnnualReportBox').addClass('hide');
						$('listAnnualReportBox').removeClass('show');
					}
				}
				
				
			radio.addEvent("click", function() {
					if (radio.getProperty('checked')) {
					
					if (!$('otherAmount').checked) {
						$('otherContributeAmount').value = "";
					}
					
					if (radio.value >= 100) {
						$('listAnnualReportBox').removeClass('hide');
						$('listAnnualReportBox').addClass('show');
					} else if (radio.value < 100 && radio.value != ""){
						$('listAnnualReportBox').addClass('hide');
						$('listAnnualReportBox').removeClass('show');
					} else if ($('otherAmount').checked && $('otherContributeAmount').value != ""){
												
							if ($('otherContributeAmount').value >= 100) {
								$('listAnnualReportBox').removeClass('hide');
								$('listAnnualReportBox').addClass('show');
							} else {
								$('listAnnualReportBox').addClass('hide');
								$('listAnnualReportBox').removeClass('show');
							}
						
						$('otherContributeAmount').addEvent('blur', function () {
							
							if ($('otherContributeAmount').value >= 100) {
								$('listAnnualReportBox').removeClass('hide');
								$('listAnnualReportBox').addClass('show');
							} else if ($('otherContributeAmount').value < 100) {
								$('listAnnualReportBox').addClass('hide');
								$('listAnnualReportBox').removeClass('show');
							}
							
						});
					} else {
						$('listAnnualReportBox').addClass('hide');
						$('listAnnualReportBox').removeClass('show');
					}
				}
			});
			
		});
	}
	
	function getRadioGroupPayment() {
		$('otherAmountPrice').addEvent("focus", function() {
			$$('form#groupPayment .radio').each(function (radio) {
				if (radio.getProperty('checked')) {
					radio.removeProperty('checked');
				}
			});
			$('otherAmountValue').setProperty('checked','checked');
		});
	}
	
	if ($E('form#makeGift')) {
		getRadio();
	}
	if ($E('form#groupPayment')) {
		getRadioGroupPayment();
	}
/* Smart Visit End */	  
									  
									  
	// Add Print Links
	if ($('pageActions')) {
		var printLi = new Element('li');
		printLi.addClass('print');
		printLi.setProperty('id', 'printLink');
		
		$('pageActions').adopt(printLi);
		
		addPrintLink('printLink', 'Print Page');
	}
	if ($('printPage')) {
		var printPageDiv = new Element('div');
		printPageDiv.setProperty('id', 'printPageLink');
		$('printPage').adopt(printPageDiv);
		
		addPrintLink('printPageLink', 'Print Page');
	}
	if ($('printItinerary')) {
		var printPageDiv = new Element('div');
		printPageDiv.setProperty('id', 'printPageLink');
		$('printItinerary').adopt(printPageDiv);
		
		addPrintLink('printPageLink', 'Print');
	}

	
	// Make Submit Buttons Links
	$ES('input.plain').each(function (input) {
		var subLink = new Element('a');
		subLink.setProperty('href', '#');
		subLink.setText(input.value);
		subLink.setProperty('tabindex', input.getProperty('tabindex'));	
		//added by Christine
		subLink.setProperty('class', input.getProperty('class'));
		
		//added so that there can be forms that validate and ones that don't on the same page for CA-20
		var parent = input;
		while (parent.getTag() != 'form') {
			parent = parent.getParent();
		}
		
		subLink.addEvent('click', function (e) {
			e = new Event(e);
			// CML code - start. check if form validation is required - affects only forms

			if (parent.hasClass('validate')) {
				/*$$("form#forgotPassForm p.submit a").each( function(a){
						if (document.getElementById('advice-validate-email_address-yourEmail')){
							$$('.validation-advice').setStyle('display','block');
							$$('#ajaxMessage').setStyle('display','block');
						}
				});*/
					
				submitValidParentForm(this);
			} else {// CML code - end
				submitParentForm(this);
			}
			e.stop();
		});
		input.replaceWith(subLink);
	});
	
	// Reset Textarea
	$ES('input.reset').each(function (input) {
		var subLink = new Element('a');
		subLink.setProperty('href', '#');
		subLink.setText(input.value);
		subLink.setProperty('tabindex', input.getProperty('tabindex'));	
		
		subLink.addEvent('click', function (e) {
			e = new Event(e);
			
			resetParentForm(this);
			e.stop();
		});
		input.replaceWith(subLink);
	});
	
	function resetParentForm(el){
		var parent = el.getParent();
		while (parent.getTag() != 'form') {
			parent = parent.getParent();
		}
		parent.reset();
	}
	
	// CML: link for the Edit Form with Anchor tag
	$ES('a.editForm').each(function (a) {
		editURL = a.href;
		a.href = "#";
		a.addEvent('click', function (e) {
			document.forms[$$('.validate').getProperty('id')].action = editURL+'#'+a.title;
			e = new Event(e);
				submitParentForm(this);
			e.stop();
		});
	});
	
	//show the delete confirmation box
	$$("a.showConfirmDelete").each(function(a, i){
		var hrefArray = new Array();
		hrefArray[i] = a.href;
		//edited by Christine
		a.href = 'javascript:void(0);';
		a.addEvent("click", function(){ 			 
					if ($('yesDelete')) $('yesDelete').setProperty('href', hrefArray[i]);
					$('confirmDelete').removeClass('hide');
					$('confirmDelete').addClass('show');
					modalBox.modalShow({element:$('confirmDelete')});					
			});
		if ($('yesDelete')) {
			$('yesDelete').addEvent("click", function(){ 		
				if($('yesDelete').getParent().getParent().hasClass('loadingbtn')) {	
					$('yesDelete').getParent().addClass('hide');
					$('yesDelete').getParent().getNext().addClass('hide');
					$('yesDelete').getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
					$('yesDelete').getParent().getNext().getNext().style.display = 'block';	
					}
				});
		}
		});
	
	// CML: link for the addAnotherGift button
	$ES('a.addAnotherGift').each(function (a) {
		editURL = a.href;
		a.href = "#";
		a.addEvent('click', function (e) {
			document.forms[$$('.validate').getProperty('id')].action = editURL+'#'+a.title;
			e = new Event(e);
			if(formValid.validate()){
				submitValidParentForm(this);
			}
			e.stop();
		});
	});
	
	$$("a.makeChangeRequest").each(  function(a){
		a.addEvent("click", function(){ 
					$$('#makeChangeRequestBox').removeClass('hide');
					$$('#makeChangeRequestBox').addClass('show');
				});
	  		}
		);
	
	// CML: link for the make Reservation Back Buttons
	$ES('a.makeReservationBack').each(function (a) {
		editURL = a.href;
		a.href = "#";
		a.addEvent('click', function (e) {
			document.forms[$$('.validate').getProperty('id')].action = editURL;
			e = new Event(e);
				if(a.getParent().getParent().hasClass('loadingbtn')) {	
					a.getParent().addClass('hide');
					a.getParent().getNext().addClass('hide');
					a.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
					a.getParent().getNext().getNext().style.display = 'block';	
				}
				submitParentForm(this);
			e.stop();
		});
	});
	
	// CML: link for the edit Reservation form
	$ES('a.editReservation').each(function (a, i) {
		var hrefArray = new Array();
		hrefArray[i] = a.href;
		a.href = "#";
		a.addEvent('click', function (e) {
			document.forms[$$('.validate').getProperty('id')].action = hrefArray[i];
			e = new Event(e);
				submitParentForm(this);
			e.stop();
		});
	});
	
	// CML: Check Source Code on apply button click
	$ES('p.apply a').each(function (a) {
		a.addEvent('click', function (e) {
			e = new Event(e);
			// If you have a source code value and it is different than the one that was submitted previously
			if (document.getElementById('source_code').value && (document.getElementById('source_code').value != document.getElementById('srcCode').value)) {
				// Remove Invalid Source Code message
				$('invalidSourceCode').removeClass('show');
				$('invalidSourceCode').addClass('hide');
				// Hide Apply button
				$('applyButton').addClass('hide');
				// Show loading image
				document.getElementById("apply_loading_image").style.display = 'block';
				// Get selected Amount
				var selectedAmount = $("membershipDegree")[$("membershipDegree").selectedIndex].title;
				// Run AJAX call
				(msismartvisit_checkSourceCode('<xjxquery><q>msismartvisit[sourcecode]='+document.getElementById('source_code').value+'&msismartvisit[baseprice]='+selectedAmount+'</q></xjxquery>'));
			}
			e.stop();
		});
	});
	
	
	
	
	// CML: Display settings have been saved message
	
	
	// CML: Check Source Code on souce code field exit
	$ES('input.applySourceCode').each(function (input) {
		input.addEvent('blur', function (e) {
			e = new Event(e);
			// If you have a source code value and it is different than the one that was submitted previously
			if (document.getElementById('source_code').value && (document.getElementById('source_code').value != document.getElementById('srcCode').value)) {
				// Remove Invalid Source Code message
				$('invalidSourceCode').removeClass('show');
				$('invalidSourceCode').addClass('hide');
				// Hide Apply button
				$('applyButton').addClass('hide');
				// Show loading image
				document.getElementById("apply_loading_image").style.display = 'block';
				// Get selected Amount
				var selectedAmount = $("membershipDegree")[$("membershipDegree").selectedIndex].title;
				// Run AJAX call
				(msismartvisit_checkSourceCode('<xjxquery><q>msismartvisit[sourcecode]='+document.getElementById('source_code').value+'&msismartvisit[baseprice]='+selectedAmount+'</q></xjxquery>'));
			}
			e.stop();
		});
	});
	
	// CML: Check if a barcode requires a PIN
	$ES('input.validate-barcode').each(function (input) {
		
		input.addEvent('keyup', function (e) {
			e = new Event(e);
			var re5digit=/^\w{13}$/;
			
			if (input.value.search(re5digit)!=-1 && (input.value != document.getElementById(input.id+'Value').value)){
				if ($('submitButton')){
					$('submitButton').removeClass('submit'); 
					$('submitButton').addClass('submitbutton');
				}
				input.blur();
				input.focus();
				//$('addBarcode').focus();
			}
			e.stop();
		});
		
		input.addEvent('blur', function (e) {
			e = new Event(e);
			// If Barcode has 13 chars and it is different than the one that was submitted previously, then check if Barcode requires Pin
			var re5digit=/^\w{13}$/;
			if (input.value.search(re5digit)!=-1 && (input.value != document.getElementById(input.id+'Value').value)) {
				
				if ($('submitButton')){
					$('submitButton').removeClass('submit'); 
					$('submitButton').addClass('submitbutton');
				}
				// Add the new barcode to the hidden barcode field
				document.getElementById(input.id+'Value').value = input.value;
				// Hide PIN fields
				$(input.id+'pin').removeClass('show');
				$(input.id+'pin').addClass('hide');
				// Show loading image
				$(input.id+'_loading_image').style.display = 'block';
				// Run AJAX call
				(msismartvisit_barcodeRequiresPin('<xjxquery><q>msismartvisit[barcode]='+input.value+'&msismartvisit[barcodeID]='+input.id+'</q></xjxquery>'));
				// Validate the form
				formValid.validate();
			}
			e.stop();
		});
	});
	
	// Limit Textarea characters: Scrapbook - Email to a friend
	$ES('textarea.maxlength').each(function (textarea) {
		textarea.addEvent('keyup', function () {
			if (textarea.value.length > 200) {
				textarea.value = textarea.value.substring(0, 200);
			}
		});
	});
	
	// Limit Textarea characters to 1000
	$ES('textarea.maxlength5000').each(function (textarea) {
		textarea.addEvent('keyup', function () {
			if (textarea.value.length > 5000) {
				textarea.value = textarea.value.substring(0, 5000);
			}
		});
	});
	
	// Add open in new window functionality
	$E('html').getElements('a[rel=external]').each(function(a) {
		a.addEvent('click', function(e) {
			e = new Event(e);
			window.open(a.href);
			e.stop();
		})
	})
		
	// Removes Guide Text in Inputs
	$ES('.guide').each(function (input) {
		if (input.getTag() == 'input' || input.getTag() == 'textarea') {
			if (input.value != '') {
				input.defaultText = input.value;
				input.addEvent('click', function () {
					if (this.value == this.defaultText) {
						this.value = '';
					}
				});
				input.addEvent('blur', function () {
					if (this.value == '' && this.defaultText) {
						this.value = this.defaultText;
					}
				});
			}
		}
	});
	
	$ES('.guidetext').each(function (input) {
		if (input.getTag() == 'input' || input.getTag() == 'textarea') {
			if (input.title != '') {
				input.defaultText = input.title;
				if (input.value == "") {
					input.value = input.defaultText;
				}				
				input.addEvent('click', function () {
					if (this.value == this.defaultText) {
						this.value = '';
					}
				});
				input.addEvent('blur', function () {
					if (this.value == '' && this.defaultText) {
						this.value = this.defaultText;
					}
				});
			}
		}
	});	
	
	// Arrow Links
	$ES('a.laquoLink').each(function (link) {
		createArrowLink(link, false);
	});
	$ES('a.raquoLink').each(function (link) {
		createArrowLink(link, true);
	});
	
	// Replace Horz Rules
	$$('hr').each(function (hr) {
		var span = new Element('span');
		span.addClass('hr');
		span.injectBefore(hr);
		span.adopt(hr);
	});
	
	// Add Separators
	addSeparatorsToUl($('globalNavLogin'), '|');
	addSeparatorsToUl($('legal'), '|');
	addSeparatorsToUl($('sectionNav'), '|');
	addSeparatorsToUl($E('#howToFooter ul'), '|');
	addSeparatorsToUl($E('dl.pageNumbers dd ul'), '|');
	addSeparatorsToUl($E('#calendarControls ul'), '|');
	addSeparatorsToUl($E('.pagination ul.pageTurn'), '|');
	addSeparatorsToUl($E('.details', 'mainExhibitPromo'), '|');
	
	$ES('.linkList ul.pageTurn').each(function (ul) {
		addSeparatorsToUl(ul, '|');
	});
	$ES('.seeShow ul').each(function (ul) {
		addSeparatorsToUl(ul, '|');
	});
	$ES('ul.separatorList').each(function (ul) {
		addSeparatorsToUl(ul, '|');
	});
		
	// Tab Module (Happing Now/Coming Soon)
	$ES('dl.eventsScheduleModule').each(function (tabModule) {
		var isFirstTab = true;
		var firstTab;
		
		tabModule.addClass('eventsScheduleModuleJS');
		
		tabModule.getChildren().each(function (tab) {
			if (tab.getTag() == 'dt') {
				tab.addEvent('click', function (e) {
					var activeContent = false;
					
					this.getParent().getChildren().each(function (child) {
						switch (child.getTag()) {
							case 'dt' :
								if (child == tab) {
									activeContent = true;
									child.removeClass('inactive');
									child.removeClass('hand');
								} else {
									child.addClass('inactive');
									child.addClass('hand');
								}
								break;
							case 'dd' :
								if (activeContent) {
									child.removeClass('hide');
									activeContent = false;
								} else {
									child.addClass('hide');
								}
								break;
						}
					});
				});
				
				if (isFirstTab) {
					firstTab   = tab;
					isFirstTab = false;
					tab.addClass('first');
				} else {
					tab.addClass('second');

				}
			}
		});
		
		firstTab.fireEvent('click');
	});
	
	// Calendar Select
	if ($('calendarModule')) {
		$E('form input', 'calendarModule').addClass('hide');
		$E('form select', 'calendarModule').addEvent('change', function (e) {
			location.href = this.value;
		});
	}
	
	// Adds Check/Uncheck controls to e-newsletter
	if ($('checkUncheckControls')) {
		var checkUl   = new Element('ul');
		var checkLi   = new Element('li');
		var uncheckLi = new Element('li');
		var checkA    = new Element('a');
		var uncheckA  = new Element('a');
		
		checkA.setProperty('href', '#');

		uncheckA.setProperty('href', '#');
		checkA.setText('check all');
		uncheckA.setText('uncheck all');
		
		checkA.addEvent('click', function (e) {
			e = new Event(e);
			checkAllInForm(this, true);
			e.stop();
		});
		uncheckA.addEvent('click', function (e) {
			e = new Event(e);
			checkAllInForm(this, false);
			e.stop();
		});
		
		checkLi.adopt(checkA);
		uncheckLi.adopt(uncheckA);
		checkUl.adopt(checkLi);
		checkUl.adopt(uncheckLi);
		$('checkUncheckControls').adopt(checkUl);
		
		addSeparatorsToUl(checkUl, '|');
	}
	
	// Logo Rollover
	var logo = $E('h1 span a');
	var home = $E('ul li.home a', 'nav');
	if (logo) {
		logo.addEvent('mouseover', function () {
			home.addClass('hover');
		});
		logo.addEvent('mouseout', function () {
			home.removeClass('hover');
		});
	}
	
	// Add last class to last li in ul#mainsubnav
	if ($E('ul#mainSubNav', 'main')) {
		$E('ul#mainSubNav', 'main').getLast().addClass('last');
	}
	
	// Updates How-To Controls
	if ($('howToControls')) {
		var isAfter = false;
		$ES('ol li', 'howToControls').each(function (li) {
			if (isAfter) {
				li.getFirst().addClass('jsAfterActive');
				isAfter = false;
			} else if (li.getFirst().hasClass('active')) {
				isAfter = true;
			}
		});
		
		var howToTips = new Tips($ES('ol li a', 'howToControls'), {offsets:{x:0, y:22}});
	}
	
	// CML addition - set HTTP_REFERER value to hidden field of send to a friend form
	if ($('suggest_page')) {
		$('suggest_page').value = readCookie('HTTP_REFERER');
	}
	
	setTimeout(setLoginFocus, 100);
	
/*	if ($('rootLineWrapper')) {}
	else {
		writeLogo();
	}*/

//	initAccordion(0);
});

function writeLogo() {
	// New Logo
	var msiLogoDiv = new Element('h1', { id : 'msiLogo' });
	msiLogoDiv.setHTML('<h1><span class="msiLogoImage"><a accesskey="h" href="../../.." title="Return to the home page">Museum of Science and Industry</a></span><div id="msiLogoHide" class="hide"></div>');
	$('body').getElement('h1').replaceWith(msiLogoDiv);
	
	var logoSWF = new SWFObject("http://www.msichicago.org/fileadmin/templates/swf/msi_header.swf", "msiLogo", "600", "130", "9.0.0", "#DFD9D2");
	logoSWF.addVariable('num_days', '10');
	logoSWF.addParam("wmode", "transparent");
	logoSWF.addParam("allowScriptAccess", "always");
	logoSWF.addParam("allowFullScreen", "true");
	logoSWF.write("msiLogo");
}

function hideItineraryCalendar() {
	$('itineraryCalendarContainer').addClass('hide');
	$('itineraryCalendarContainer').removeClass('show');
	$$('.formHeader p.togglerCalendarOpen').addClass('hide');
	$$('.formHeader p.togglerCalendarOpen').removeClass('show');
	$$('.formHeader p.togglerCalendarClose').addClass('show');
	$$('.formHeader p.togglerCalendarClose').removeClass('hide');
}

function showItineraryCalendar() {
	$('itineraryCalendarContainer').addClass('show');
	$('itineraryCalendarContainer').removeClass('hide');
	$$('.formHeader p.togglerCalendarOpen').addClass('show');
	$$('.formHeader p.togglerCalendarOpen').removeClass('hide');
	$$('.formHeader p.togglerCalendarClose').addClass('hide');
	$$('.formHeader p.togglerCalendarClose').removeClass('show');
}




function changeContentForDay(dayAttending){
	//ex: 12/31/2009
	
	//createCookie(name,value,days)
	
	//create a cookie with the itinerary's info
	var value = itineraryGuid + '|' + itineraryName + '|' + dayAttending;

	Cookie.set('itineraryInfo',value,{path: itineraryCookiePath});
	
	//if itineraryGuid, do autosaving to the service
	if(itineraryGuid != ''){
		(msismartvisit_saveItinerary('<xjxquery><q>msismartvisit[itineraryGuid]='+itineraryGuid
			+ '&msismartvisit[itineraryName]=' + itineraryName
			+ '&msismartvisit[dayAttending]=' + dayAttending + '</q></xjxquery>'));	
	}

	var	href = window.location.href;
	var i = href.indexOf('/Itinerary/');
	if(i != -1){
		href = href.substring(0,i);
	}

	//reload the page (to recalculate content)
	window.location.href = href;
	
	
	//get the grades and interests
	/*var gradeInputsArr = $$('.grade');
	var interestInputsArr = $$('.topic');
	
	//get the values of the checked boxes in a comma separated list
	var gradeIdsArr = [];
	for(var i=0, j=0; i<gradeInputsArr.length; i=i+1){
		if(gradeInputsArr[i].checked==true){
			gradeIdsArr[j] = gradeInputsArr[i].value;
			j=j+1;
		}
	}
	var interestIdsArr = [];
	for(var i=0, j=0; i<interestInputsArr.length; i=i+1){
		if(interestInputsArr[i].checked==true){
			interestIdsArr[j] = interestInputsArr[i].value;
			j=j+1 ;
		}
	}

	//change the recommended events
	//note, arrays are implicitly imploded into comma separated strings
	(msismartvisit_changeContentForDay('<xjxquery><q>msismartvisit[dayAttending]=' + dayAttending
		+ '&msismartvisit[interestIdsStr]=' + interestIdsArr + '&msismartvisit[gradeIdsStr]=' + gradeIdsArr
		+ '</q></xjxquery>'));*/
}

//My Scrapbook - Accordion
function initAccordion(id) {
	var accordion = new Accordion('h5.date', 'div.assetsContent', {
		opacity: true,
		alwaysHide: true,
		show: id,
		duration: 500,
		onActive: function(toggler, element){
			toggler.setStyle('cursor','pointer');
			toggler.addClass('togglerOpen');
			toggler.removeClass('togglerClose');
			toggler.getNext().removeClass('hide');
		},
		onBackground: function(toggler, element){
			toggler.removeClass('togglerOpen');
			toggler.addClass('togglerClose');
			toggler.setStyle('cursor','pointer');
			toggler.getNext().addClass('hide');
		}
	}, $('accordion'));

}



function setLoginFocus() {
		// set focus on login form, add submit on enter event
	if ($('loginForm')) {
		$('user').focus();
		$('user').addEvent("keyup", function(e) {
			e = new Event(e);								   
			if ((e.key == "enter") && ($('pass').getValue() != "")) {
				submitForm($('loginForm').getElement('.plain'));
			}
			e.stop();
		});
		$('pass').addEvent("keyup", function(e) {
			e = new Event(e);								   
			if ((e.key == "enter") && ($('pass').getValue() != "")) {
				submitForm($('loginForm').getElement('.plain'));
			}
			e.stop();
		});

	}
}


function submitForm(el) {
	if ($E('.validate')) {			
		/*$$("form#forgotPassForm p.submit a").each( function(a){
			if (document.getElementById('advice-validate-email_address-yourEmail')){
				$$('.validation-advice').setStyle('display','block');
				$$('#ajaxMessage').setStyle('display','block');
			}
		});*/
		submitValidParentForm(el);
	} else {// CML code - end
		submitParentForm(el);
	}
}

var requestedFlashEmbeds = new Array();
function requestFlashEmbed(swfObj, kind) {
	requestedFlashEmbeds.push({obj:swfObj, type:kind})
}

function writeRequestedFlashEmbeds() {
	requestedFlashEmbeds.each(function (request) {
		var embed = request.obj;
		embed.addParam('quality', 'high');
		embed.addParam('menu', 'false');
		embed.addParam('salign', 'tl');
		
		switch (request.type.toLowerCase()) {
			case 'altertheoutcome':
				embed.write('alterTheOutcome');
				break;
			case 'promo' :
				embed.addVariable('jsCallbackMethod', 'updateFeatureInformation');
				embed.write('mainExhibitPromoImage');
				break;
			case 'polltrivia' :
				formatPollTrivia(embed.write('museumInfoContent'));
				break;
			case 'planyourvisit' :
				embed.addVariable('selectedItem', getPlanVisitorType());
				embed.addVariable('jsCallbackMethod', 'upforgotPasswordYourVisitValue');
				formatPlanYourVisit(embed.write('planYourVisitHeader'));
				break;
			case 'timeline' :
				embed.addVariable('jsCallbackMethod', 'updateTimelineCaption');
				formatTimeline(embed.write('flashTimeline'));
				break;
			case 'timelinelarge' :
				$E('#focusedContent').addClass('timelineLarge');
				
				embed.addVariable('jsCallbackMethod', 'updateTimelineCaption');
				formatTimeline(embed.write('flashTimelineLarge'));
				break;
			case 'slideshow' :
				embed.addVariable('jsCallbackMethod', 'updateSlideImageCaption');
				formatSlideshow(embed.write('flashSlideshow'));
				break;
			case 'slideshowlarge' :
				$E('#slideshowContent').addClass('large');
				
				embed.addVariable('jsCallbackMethod', 'updateSlideImageCaption');
				formatSlideshow(embed.write('flashSlideshowLarge'));
				break;
			case 'map' :
				$E('li#printLink', 'pageActions').addClass('hide');
			
				embed.write('map');
				break;
			case 'videolarge' :
				embed.addVariable('isEmbeddedOnMSISite', 'true');
				embed.addVariable('videoPlayerSize', 'large');
				embed.write('flashVideoPlayerLarge');
				break;
			case 'videomedium' :
				
				embed.addVariable('isEmbeddedOnMSISite', 'true');
				embed.addVariable('videoPlayerSize', 'medium');
				embed.write('flashVideoPlayerMedium');
				if ($('flashVideoPlayerAlt')) {
					$('flashVideoPlayerAlt').removeClass('hide');
				}
				break;
			case 'audiolarge' :
				embed.addVariable('isEmbeddedOnMSISite', 'true');
				embed.write('flashAudioPlayerLarge');
				break;
			case 'audiomedium' :
				embed.addVariable('isEmbeddedOnMSISite', 'true');
				embed.write('flashAudioPlayerMedium');
				if ($('flashAudioPlayerAlt')) {
					$('flashAudioPlayerAlt').removeClass('hide');
				}
				break;
		}
	});
}

function updateFeatureInformation(name, desc, dateRange, location, detailsLinkTitle, detailsLinkUrl, link1Title, link1Url, link2Title, link2Url) {
	var detailsLink = $E('ul.details li a.raquoLink', 'focusedContent');
	var details     = $ES('ul.details li', 'focusedContent');
	var links       = $ES('ul', 'focusedContent')[1];
	var li;
	var a;
	
	$('mainExhibitPromoImage').addClass('jsHasFlash');
	
	h3a = new Element('a');
	h3a.setProperty('href', link1Url);
	h3a.setText(name);
	
	$E('h3').setText('');
	$E('h3').appendChild(h3a);

	$E('p', 'focusedContent').setText(desc);
	
	details[0].setText(dateRange);
	details[2].setText(location);
	detailsLink.setText(detailsLinkTitle);
	detailsLink.setProperty('href', detailsLinkUrl);
	createArrowLink($E('ul.details li a.raquoLink', 'focusedContent'), true);
	
	links.empty();
	
	if (link1Title) {
		li = new Element('li');
		a  = new Element('a');
		a.setText(link1Title);
		a.setProperty('href', link1Url);
		createArrowLink(a, true);
		li.appendChild(a);
		links.appendChild(li);
	}
	if (link2Title) {
		li = new Element('li');
		a  = new Element('a');
		a.setText(link2Title);
		a.setProperty('href', link2Url);
		createArrowLink(a, true);
		li.appendChild(a);
		links.appendChild(li);
	}
}

function formatSlideshow(hasFlash) {
	$E('dt', 'slideshowContent').addClass('hide');
	
	$ES('dd ol li', 'slideshowContent').each(function (slide) {

		if(slide.getFirst().getText().length > 1) {
			var p   = new Element('p');
			var em  = new Element('em');
			var img = new Element('img');

			em.setText(slide.getFirst().getText());
			img.setProperty('src', slide.getFirst().getProperty('href'));
			img.setProperty('alt', slide.getFirst().getText());
			p.appendChild(em);
			p.addClass('caption');

			slide.empty();

			if (hasFlash) {
				slide.addClass('hide');
				slide.addClass('jsHasFlash');
			} else {
				slide.appendChild(img);
			}

			slide.appendChild(new Element('hr'));
			slide.appendChild(p);
			slide.appendChild(new Element('hr'));
			
		} else {
			$ES('dd ol li a', 'slideshowContent').addClass('hide');
			slide.appendChild(new Element('hr'));
			
		}
	});
	
	if (hasFlash) {
		if ($('flashSlideshow')) {
			$('flashSlideshow').addClass('jsHasFlash');
		} else if ($('flashSlideshowLarge')) {
			$('flashSlideshowLarge').addClass('jsHasFlash');
		}
	} else {
		$E('dd ol li img', 'slideshowContent').addClass('first');
	}
}

function formatTimeline(hasFlash) {
	if (hasFlash) {
		$('focusedContent').addClass('jsHasFlash');
		$('timeline').addClass('jsHasFlash');
		
		$ES('dd.timelineContent', 'timeline').each(function (dd) {
			dd.addClass('hide');
		});
		$E('dd.timelineContent', 'timeline').removeClass('hide');
	} else {
		$ES('div.imageLink', 'timeline').each(function (linkWrapper) {
			var img = new Element('img');
			img.setProperty('src', linkWrapper.getFirst().getProperty('href'));
			linkWrapper.replaceWith(img);
		});
	}
}

function updateTimelineCaption(index) {
	var i = -1;
	$ES('dd.timelineContent', 'timeline').each(function (dd) {
		if (++i == index) {
			dd.removeClass('hide');
		} else {
			dd.addClass('hide');
		}
	});
}

var planVisitFormFade;
function formatPlanYourVisit(hasFlash) {
	if (hasFlash) {
		$('who').addClass('hide');
		$('visitPlanner').addClass('hide');
		$E('p', 'mainHeader').addClass('hide');
		$E('.headSep', 'mainHeader').addClass('hide');
		$('planYourVisitHeader').addClass('jsHasFlash');
		planVisitFormFade = new Fx.Style('visitPlanner', 'opacity', {duration: 900});
	}
}

function getPlanVisitorType() {
	var i        = -1;
	var selected = -1;
	$ES('dl dt input', 'who').each(function (radio) {
		i++;
		if (radio.getProperty('checked')) {
			selected = i;
		}
	});
	
	return selected;
}

function updatePlanYourVisitValue(index, isCompact) {
	$('visitPlanner').removeClass('hide');
	$('planYourVisitHeader').addClass('jsFlashCompressed');
	$ES('dl dt input', 'who')[index].setProperty('checked', true);
	
	if (isCompact == false) {
		planVisitFormFade.set(0);
		planVisitFormFade.start(0, 1);
	}
}

function formatPollTrivia(hasFlash) {
	if (hasFlash) {
		$('museumInfo').setProperty('id', 'jsPollTrivia');
	}
}

function createArrowLink(el, right) {
	if (right) {
		el.setHTML(el.firstChild.nodeValue + ' <span class="raquo">&raquo;</span>');
	} else {
		el.setHTML('<span class="laquo">&laquo;</span> ' + el.firstChild.nodeValue);
	}
}

function updateSlideImageCaption(index) {
	var i = -1;
	$ES('dd ol li', 'slideshowContent').each(function (caption) {
		if (++i == index) {
			caption.removeClass('hide');
		} else {
			caption.addClass('hide');
		}
	});
}

function addSeparatorsToUl(ulEl, sep) {
	if (!ulEl)
		return;
	
	var first = true;
	
	$ES('li', ulEl).each(function (li) {
		if (first) {
			first = false;
			return;
		}
		if (!li.hasClass('printOnly')) {
			var pipe = new Element('li');
			pipe.addClass('separatorLi');
			pipe.setText(sep);
			pipe.injectBefore(li);
		}
	});
}

function checkAllInForm(formChild, check) {
	var formEl = formChild.getParent();
	while (formEl.getTag() != 'form') {
		formEl = formEl.getParent();
	}
	
	$ES('input', formEl).each(function (input) {
		if (input.getProperty('type').toLowerCase() == 'checkbox') {
			if (check) {
				input.setProperty('checked', 'checked');
			} else {
				input.removeProperty('checked');
			}
		}
	});
}

function addPrintLink(el, text) {
	var link = new Element('a');
	link.setProperty('href', '#');
	link.setText(text);
	link.addEvent('click', function (e) {
		e = new Event(e);
		window.print();
		e.stop();
	});
	
	$(el).appendChild(link);
}

function submitParentForm(el) {
	var parent = el.getParent();
	while (parent.getTag() != 'form') {
		parent = parent.getParent();
	}
	parent.submit();
}
// CML Code - show Edit Team Modal - Added by Christine
function showEditTeam(teamId, teamName){
	$('teamName').value = teamName;
	$('teamToEditId').value = teamId;
	
	$$('#editTeam').removeClass('hide');
	$$('#editTeam').addClass('show');
	modalBox.modalShow({element:$('editTeam')});	
}
// CML Code - show Remove Team Modal Added by Christine
function showRemoveTeam(teamId){
	$('teamToDeleteId').value = teamId;
}

// CML Code - show Remove Team Modal Added by Christine
function showRemoveTeamMember(teamId,studentId){
	$('memberTeamId').value = teamId;
	$('memberToDeleteId').value = studentId;
}

function showAddEditTeamMember(teamId){
	var modalId = 'addEditTeamMembers'+'_MARKER_'+teamId;
	$(modalId).removeClass('hide');
	$(modalId).addClass('show');
	modalBox.modalShow({element:$(modalId)});					
}

// CML Code - start same as submitParentForm just added validation before submit - affects only forms
function submitValidParentForm(el) {
	
	var parent = el.getParent();
	while (parent.getTag() != 'form') {
		parent = parent.getParent();
	}
	
	switch (parent.id)
	  {
		case 'loginForm': { 
			if(validateLogin.validate()){
					if(el.getParent().getParent().hasClass('loading')) {	
						el.getParent().addClass('hide');
						el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
						el.getParent().getNext().style.display = 'block';	
					}
					parent.submit();
					
					
					
				} 
				break;
		}
		case 'forgotPassForm': { 
				if(validateForgotPass.validate()){
					parent.submit();
				} 
				break; 
		}
		case 'editTeamForm': { 
				if(validateEditTeamForm.validate()){
					if(el.getParent().getParent().hasClass('loadingbtn')) {	
						if ((el.getParent().hasClass('submit')) || (el.getParent().hasClass('update')) || (el.getParent().hasClass('save'))) {
							el.getParent().getNext().addClass('hide');
							el.getParent().addClass('hide');
							el.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().getNext().style.display = 'block';	
						} else {
							el.getParent().addClass('hide');
							el.getParent().getPrevious().addClass('hide');
							el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().style.display = 'block';	
						}
					}
					parent.submit();
				} 
				break; 
		}
		case 'addTeamForm': { 
				if(validateAddTeamForm.validate()){
					if(el.getParent().getParent().hasClass('loadingbtn')) {	
						if ((el.getParent().hasClass('submit')) || (el.getParent().hasClass('update')) || (el.getParent().hasClass('save'))) {
							el.getParent().getNext().addClass('hide');
							el.getParent().addClass('hide');
							el.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().getNext().style.display = 'block';	
						} else {
							el.getParent().addClass('hide');
							el.getParent().getPrevious().addClass('hide');
							el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().style.display = 'block';	
						}
					}
					parent.submit();
				} 
				break; 
		}
		case 'createItineraryForm': { 
				if(validateCreateItineraryForm.validate()){
					if(el.getParent().getParent().hasClass('loadingbtn')) {	
						if ((el.getParent().hasClass('submit')) || (el.getParent().hasClass('update')) || (el.getParent().hasClass('save'))) {
							el.getParent().getNext().addClass('hide');
							el.getParent().addClass('hide');
							el.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().getNext().style.display = 'block';	
						} else {
							el.getParent().addClass('hide');
							el.getParent().getPrevious().addClass('hide');
							el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().style.display = 'block';	
						}
					}
					parent.submit();
				}
				break; 
		}
		case 'createItineraryForm2': { 
				if(validateCreateItineraryForm2.validate()){
					if(el.getParent().getParent().hasClass('loadingbtn')) {	
						if ((el.getParent().hasClass('submit')) || (el.getParent().hasClass('update')) || (el.getParent().hasClass('save'))) {
							el.getParent().getNext().addClass('hide');
							el.getParent().addClass('hide');
							el.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().getNext().style.display = 'block';	
						} else {
							el.getParent().addClass('hide');
							el.getParent().getPrevious().addClass('hide');
							el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().style.display = 'block';	
						}
					}
					parent.submit();
				}
				break; 
		}
		case 'addEditTeamMembersForm': { 
				if(validateAddEditTeamMembersForm.validate()){
					if(el.getParent().getParent().hasClass('loadingbtn')) {	
						if ((el.getParent().hasClass('submit')) || (el.getParent().hasClass('update')) || (el.getParent().hasClass('save'))) {
							el.getParent().getNext().addClass('hide');
							el.getParent().addClass('hide');
							el.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().getNext().style.display = 'block';	
						} else {
							el.getParent().addClass('hide');
							el.getParent().getPrevious().addClass('hide');
							el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().style.display = 'block';	
						}
					}
					parent.submit();
				} 
				break; 
		}
		case 'emailFriendItineraryForm': {
					
				if(validateEmailFriendForm.validate()){
					//$('submitEmailFriendButton').removeClass('show');
					$('submitButton').addClass('hide');
					//$('closeEmailFriendButton').removeClass('show');
					$('closeButton').addClass('hide');
					$('loading_image').innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
					$('loading_image').style.display = 'block';	
					
					
					//
//					if(el.getParent().getParent().hasClass('loadingbtn')) {
//						if ((el.getParent().hasClass('submit')) || (el.getParent().hasClass('update')) || (el.getParent().hasClass('save'))) {
//							el.getParent().getNext().addClass('hide');
//							el.getParent().addClass('hide');
//							el.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
//							el.getParent().getNext().getNext().style.display = 'block';	
//						} else {
//							el.getParent().addClass('hide');
//							el.getParent().getPrevious().addClass('hide');
//							el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
//							el.getParent().getNext().style.display = 'block';	
//						}
//					}
					parent.submit();
				} 
				break; 
		}
		case 'logoutForm': { 
				parent.submit();
				break; 
		}
		/*case 'saveClassSettingsForm': {
			if(formValid.validate()){
					if(el.getParent().getParent().hasClass('loading')) {	
						el.getParent().addClass('hide');
						el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
						el.getParent().getNext().style.display = 'block';	
					}
					if(el.getParent().getParent().hasClass('loadingbtn')) {	
						if ((el.getParent().hasClass('submit')) || (el.getParent().hasClass('update')) || (el.getParent().hasClass('save'))) {
							el.getParent().getNext().addClass('hide');
							el.getParent().addClass('hide');
							el.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().getNext().style.display = 'block';	
						} else {
							el.getParent().addClass('hide');
							el.getParent().getPrevious().addClass('hide');
							el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().style.display = 'block';	
						}
					}
			
					//if the form is saving classroom settings, run an ajax call instead of submitting the form
					$ES('p.saveSettingsButton a').each(function () {
							//if the saved settings message is shown, hide it during the save
							$('changesSavedMessage').removeClass('show');
							$('changesSavedMessage').addClass('hide');
							
							// Run AJAX call
							(msismartvisit_saveSettings('<xjxquery><q>msismartvisit[classroomId]='+document.getElementById('classroomId').value+'&msismartvisit[classroomName]='+document.getElementById('classname').value+'&msismartvisit[classroomGrade]='+document.getElementById('grades').value+'&msismartvisit[classroomDesc]='+document.getElementById('description').value+'</q></xjxquery>'));	
					});
			}
			break;
		}*/
		default: { 
				if(formValid.validate()){
					if(el.getParent().getParent().hasClass('loading')) {	
						el.getParent().addClass('hide');
						el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
						el.getParent().getNext().style.display = 'block';	
					}
					if(el.getParent().getParent().hasClass('loadingbtn')) {	
						if ((el.getParent().hasClass('submit')) || (el.getParent().hasClass('update')) || (el.getParent().hasClass('save'))) {
							el.getParent().getNext().addClass('hide');
							el.getParent().addClass('hide');
							el.getParent().getNext().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().getNext().style.display = 'block';	
						} else {
							el.getParent().addClass('hide');
							el.getParent().getPrevious().addClass('hide');
							el.getParent().getNext().innerHTML = '<img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">One moment, please.</p>';
							el.getParent().getNext().style.display = 'block';	
						}
					}
					
					parent.submit();
					
				}
				break; 
		}
	  }

}
// CML Code - end

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// Get the page url and store it in a session cookie. First make sure that the page is not send-to-a-friend or home page
var sPath = window.location.pathname;
if (sPath.match('index.php')==null && sPath.match('send-to-a-friend')==null) {

	//Store HTTP_REFERER for the entire sesion
	createCookie('HTTP_REFERER','http://'+window.location.hostname+sPath);
} 
// CML Code - end

//Create a function to get the class from an HTML tag
function getElementsByClassName(className){
	var arr = new Array();
	var elems = document.getElementsByTagName("*");
	
	for(var i = 0; i < elems.length; i++) {
		var elem = elems[i];
		var id = elem.getAttribute("id");
		var cls = elem.getAttribute("class");
		
		if(cls == className) {
			arr[arr.length] = id;
		}
	}
	return arr;
}

// Embed Audio File
function embedWin(){
	modalBox.modalShow({element:document.getElementById('embedCode')});
	document.getElementById('embedCode').className = 'popup show';
	// focus, so that ESC key works
	document.getElementById('wrap').focus();
	clip = new ZeroClipboard.Client();
	clip.setText(document.getElementById('embedText').value);
	clip.glue('copyToClipboard');
}

function showPIN() {
		modalBox.modalShow({element:document.getElementById('dontHavePin')});
		document.getElementById('dontHavePin').className = 'popup show';
}

function addNewBarcode() {
	// If previous barode entries are valid, then add another Barcode field
	if (formValid.validate()) {
		// Get Next Item Number
		for (i=1; i<=10; i++) {
			if (!document.getElementById('barcode'+i)) {
				break;
			}
		}
		// Create new Div
		var el = new Element('div');
		el.setProperty('id','newBarcode'+(i));
		el.setProperty('class','barcodeWrapper');
		// Create new Input
		var barcodeInput = new Element('input');
		barcodeInput.setProperty('type','text');
		barcodeInput.setProperty('id','barcode'+(i));
		barcodeInput.setProperty('class','text barcode empty-barcode validate-barcode_unique');
		barcodeInput.setProperty('name','msismartvisit[barcode][]');
		barcodeInput.setProperty('tabindex',(i*2)-1);
		barcodeInput.setProperty('maxlength',13);
		
		// Add onkeyup Event for new Input
		barcodeInput.addEvent('keyup', function (e) {
			e = new Event(e);
			var re5digit=/^\w{13}$/;
			
			if (barcodeInput.value.search(re5digit)!=-1 && (barcodeInput.value != document.getElementById(barcodeInput.id+'Value').value)){
				if ($('submitButton')){
					$('submitButton').removeClass('submit'); 
					$('submitButton').addClass('submitbutton');
				}
				barcodeInput.blur();
				barcodeInput.focus();
				//$('addBarcode').focus();
			}
			e.stop();
		});
		// Add onBlur Event for new Input
		barcodeInput.addEvent('blur', function (e) {
			e = new Event(e);
			// If Barcode has 13 chars and it is different than the one that was submitted previously, then check if Barcode requires Pin
			var re5digit=/^\w{13}$/;
			if (barcodeInput.value.search(re5digit)!=-1 && (barcodeInput.value != document.getElementById(barcodeInput.id+'Value').value)) {
				
				if ($('submitButton')){
					$('submitButton').removeClass('submit'); 
					$('submitButton').addClass('submitbutton');
				}
				// Add the new barcode to the hidden barcode field
				document.getElementById(barcodeInput.id+'Value').value = barcodeInput.value;
				// Hide PIN fields
				$(barcodeInput.id+'pin').removeClass('show');
				$(barcodeInput.id+'pin').addClass('hide');
				// Show loading image
				$(barcodeInput.id+'_loading_image').style.display = 'block';
				// Run AJAX call
				(msismartvisit_barcodeRequiresPin('<xjxquery><q>msismartvisit[barcode]='+barcodeInput.value+'&msismartvisit[barcodeID]='+barcodeInput.id+'</q></xjxquery>'));
				// Validate the form
				formValid.validate();
			}
			e.stop();
		});
		// Add new HTML inside the new Div
		el.injectAfter($("newBarcode"+(i-1)+"")).innerHTML = '<input type="hidden" id="barcode'+i+'Value" /><input type="hidden" id="pin'+i+'Required" name="msismartvisit[pinRequired][]" value="0" /><div class="clearfix"><dl class="inline"><dt><label>Barcode #</label></dt><dd id="barcodeInput'+i+'"></dd></dl> '+ 
														  '<div class="barcodeindicator" id="barcode'+i+'_loading_image" style="display:none"><img class="indicatorImage" width="24" height="24" src="fileadmin/templates/images/global/icons/waiter.gif" alt="" /><p class="indicatorMsg">Checking for PIN.</p></div><div class="hide" id="barcode'+i+'pin"><dl class="inline"><dt><label>PIN</label></dt><dd><input type="text" id="barcodepin'+i+'" class="text pin" size="4" maxlength="4" name="msismartvisit[pin][]" tabindex="'+(i*2)+'" /> <a href="javascript:showPIN();" class="dontHaveYourPin">Don\'t have your PIN?</a></dd></dl></div></div>\n';
		// Add new input inside the Div
		barcodeInput.injectInside($('barcodeInput'+i));
	}
}


