// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function handleFailedAjax(response){
	if(response.status == 401){
		document.location.href = '/sessions/new';
	} // else {
	// 		document.location.reload();
	// 	}
	// 	
}

function showPrintButton(instantPrint){
	var showHideElement = instantPrint ? ['show', 'hide'] : ['hide', 'show'];
	showHideByClass(showHideElement[0], '.showprint');
	showHideByClass(showHideElement[1], '.deferprint');
	
	showHideByClass('hide', '.noprint');
	showHideByClass('hide', '.printspin');
	showHideByClass('hide', '.delayedprintmessage');
}

function showPrintSpin() {
	showHideByClass('hide', '.showprint');
	showHideByClass('hide', '.deferprint');
	showHideByClass('hide', '.noprint');
	showHideByClass('hide', '.delayedprintmessage');

	showHideByClass('show', '.printspin');
}


function showPrintMessage(){
	showHideByClass('hide', '.showprint');
	showHideByClass('hide', '.deferprint');
	showHideByClass('hide', '.printspin');
	showHideByClass('show', '.noprint');
	showHideByClass('show', '.delayedprintmessage');
	setTimeout('fadePrintMessage()', 1500);
}
function fadePrintMessage() {
	$$('.delayedprintmessage').each(function(ele){new Effect.Fade(ele)});
}

function delayedPrint(printUrl, token) {
	showPrintSpin();
	new Ajax.Request(printUrl, {
		method: "post",
		parameters: {"authenticity_token" : token},
		onComplete: showPrintMessage
	});
}

function showHideByClass(showOrHide, className){
	$$(className).each(function(ele){Element[showOrHide](ele)});
}

