/*!
 * Express Scripts, Inc. Global Library
 *
 * Copyright (c) 2009 Express Scripts, inc.
 * Author: Lance E. Leonard (lleonard@express-scripts.com)
 *
 * Date: 2009-07-13
 */


/*
 * showPleaseWaitOverlay
 * 
 * Build and display a jQuery Dialog with spinner graphic and "Please Wait..." 
 * text to overlay site. Disables navigation to prevent users from getting
 * impatient during long running processes. */
// updated for QC 37032 -- scroll issue
showPleaseWaitOverlay = function() {
	setTimeout("com.express_scripts.dialog.createDialogForTPharm({html: \"<img src='/web/member/resources/images/pleaseWait.gif' alt='' style='vertical-align: middle; margin-right: 10px;'/> <span style='font-size: 1.2em;'>Loading &hellip;</span>\", showTitle: false, height: 50, width: 175, show: 'fade',style:'hidden'}).dialog('open');",1000);
	return true;
}

/*
 * initPleaseWaitOverlay
 * 
 * Add handlers to links requiring the "Please Wait..." dialog. To enable a link,
 * simply add class="pleaseWait" to any link. 
 * 
 * The #forwardRefillPrescription id is used because, at this time, we cannot
 * add a class to the left nav since it is built from a menu xml. */
initPleaseWaitOverlay = function() {
	$('#forwardRefillPrescription').click(showPleaseWaitOverlay);
	$('.pleaseWait').click(showPleaseWaitOverlay);
}
 
initButtons = function() {
 	$("button").each(function(i) {
		var btn = $(this);
		var btnText = btn.text();
		if(btn.attr("name").substr(0, 8) == "_eventId" ) {
			btn.click(function () {
				$("button").attr("disabled", true);
				btn.attr("disabled", false);
			});
		}
		btn.html("<b>" + btnText + "</b>");
	});
}

function initTableControls() {
	$('.sortBy').change(function() {
		var tblName = '#' + $(this).attr("id").substring(0,$(this).attr("id").indexOf('_'));
		var index = $(this).val();
		var sorting = [[index,0]];
		$(tblName).trigger("sorton",[sorting]);
	});
}



/*
 * Add global event handlers when DOM is ready.
 */
$(document).ready(initPleaseWaitOverlay);
$(document).ready(initButtons);
$(document).ready(initTableControls);
