

/**
This function registers the onkeydown event on the popup (ie, a div that has the classname keyFormWrapper)
When 'Enter' key is pressed, it finds a link which has class name 'ajaxSubmit' inside that keyFormWrapper popup
and simulate click event on it. If you have more than one links with that class name in the popup then
there is problem. You must use some resolution strategy to select the proper one. Currently it is 
selecting the first one. 
**/
var initForms = function(){
	$$('.keyFormWrapper input').each(function(el){
		el.observe('keypress', function(e){
			
			var keycode = -1;
			if(window.event){
				keycode = window.event.keyCode;
			}else{
				keycode = e.which;
			}
			if (keycode == 13){
				var parent = el.up('.keyFormWrapper');
				if (parent!= null){
					parent.down('.ajaxSubmit').onclick();
					e.stop();
				}
			}
		}.bind(this));
	   });	
	};
	
document.observe('dom:loaded', function() {
	initForms();   
});

function manualInitializationPopEnterKeyPress(){
	initForms();   
}

/**
This is a global list of all the popups in the fastlane. Whenever you create a new popup push the id in this array.
This array is searched to find any open popup so far in the screen. If there is any, then we need to close it before
opening new one.
**/
var popupIds = new Array();
popupIds.push('signinWidget');
popupIds.push('changeProgramLocationOverlay');
popupIds.push('enrollmentTabForm');
popupIds.push('setLocation');



function closeAnyOpenedPopupWidget(){
	var len = popupIds.length;
	for(var x = 0; x < len ;x++){
		var popupWidget = $(popupIds[x]);
		if(popupWidget != null && popupWidget.style.display != 'none'){
			new Effect.Fade(popupWidget,{duration:0.5});
		}
	}
}

	