var loggingon=false
var busysaving=false
var historymatrix=[]
var historymatrixindex=-1
var defaulttimeout=3600*1000
var warningtimeout=5*60*1000 // 5 mins
var timeleft=defaulttimeout
var throbinterval=10000  // 10 sec

//========== logs
function logthis (what) {
if (!loggingon) return
	$("#jqfeedbackholder").append('<div class=jqfeedback>'+what+'</div>').show()
}
function logclear() {
	$('.jqfeedback').remove()
	$('#jqfeedbackholder').html()
}

function stripalpha (s) {
var v = "0123456789";
var w = "";
	for (i=0; i < s.length; i++) {
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	return w
}

function setupcalendar() {
//  alert('setupcal')
		$('.calendarButton').not('.caldone')
			.calendar({autoPopUp: 'both', 
					buttonImageOnly: true, 
					buttonImage: 'calendar.gif', 
					buttonText: 'Calendar',
					dateFormat: 'YMD-', 
					minDate : new Date(2007, 1 - 1, 26),
					maxDate : new Date(2020, 1 - 1, 26),
					dateFormat : 'YMD-'
					})
			.addClass('caldone');
		$('.calinput').attr('readonly','true')
}

function restoretimeout() {
	timeleft=defaulttimeout
	$('#timeoutwarn').removeClass('errormsg').show()
}

function warntimeout() {
	timeleft=timeleft-throbinterval
	if (timeleft<=0) {
			$('#timeoutwarn').html('You have been logged off due to inactivity')
				DoenAjaxLogoff('yes') // auto=yes
	} 
	else {
		if (timeleft<warningtimeout) {
			$('#timeoutwarn').addClass('errormsglarge').show()
			var timeleftinsecs = timeleft/1000
			$('#timeoutwarn').html('You will be logged off in '+timeleftinsecs+' seconds<br>Click here to stay logged in.')
		}
		else  {
			$('#timeoutwarn').html(timeleft+'.'+warningtimeout).hide()
		}
		window.setTimeout("warntimeout()",throbinterval)
	}
}

function pollserver() {
		$.ajax({
   			type: "POST",
   			url: 'ajq_gettimeout.php',
// 			data: "username_forlogo="+$('#username_forlogo').val(),
			dataType: "json",
   			success: function(jr){
				$('#timeoutwarn').html(jr.respz.timeout)
				restoretimeout()
   			}
 		});
}
// ==================================================

function whenenter(e,dothis) { //e is event object passed from function invocation
var characterCode 			   //literal character code will be stored in this variable
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
}
else{
	e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
	//document.forms[0].submit() //submit the form
	dothis()
}
else{ }
}

