var pageno;
var noperpage;
var HWI_DEBUG = 1;

var appurl = 'http://www.hwi.buffalo.edu/';

/**
 * Utility function to sum numeric array values
 * @author unknown/unconfirmed - google "array.prototype.sum()", "array.prototype.sum,max,min"
 * @see http://snippets.dzone.com, http://www.webscriptexpert.com/Javascript
 * @return sum
 */
Array.prototype.sum = function(){
	for(var i=0,sum=0; i<this.length;sum+=this[i++]);
	return sum;
};

/**
 * Utility function to find min() numeric array value
 * @author unknown/unconfirmed - google "array.prototype.sum()", "array.prototype.sum,max,min"
 * @see http://snippets.dzone.com, http://www.webscriptexpert.com/Javascript
 * @return min
 */
Array.prototype.min = function(){
	return Math.min.apply({},this);
};

/**
 * Utility function to find max() numeric array value
 * @author unknown/unconfirmed - google "array.prototype.sum()", "array.prototype.sum,max,min"
 * @see http://snippets.dzone.com, http://www.webscriptexpert.com/Javascript
 * @return max
 */
Array.prototype.max = function(){
	return Math.max.apply({}, this);
};


/******************************** OLD FUNCTIONS TO BE DEPRECATED ************************************/
function unixTS(){
	var months = ["0" + 1, "0" + 2, "0" + 3, "0" + 4, "0" + 5, "0" + 6, "0" + 7, "0" + 8, "0" + 9, 10, 11, 12];
	var fd = new Date();
	var y = fd.getFullYear();
	var d = fd.getDate();
	var m = months[fd.getMonth()];
	var th = fd.getHours();
	var tm = fd.getMinutes();
	var ts = fd.getSeconds();

	if(d.length == 1 ) { d = "0" + d; }
	if(th.length == 1) { th = "0" + th; }
	if(tm.length == 1) { tm = "0" + tm; }
	if(ts.length == 1) { ts = "0" + ts; }

	var TS = y + "-" + m + "-" + d + " " + th + ":" + tm + ":" + ts;
	return TS;
}

//thrown exceptions - the div you want an error message to appear, and the error message.
function catchErrArr(errDiv, err) {
	var errDiv = $(errDiv);
	while (errDiv.childNodes[0]) {
		errDiv.removeChild(errDiv.childNodes[0]);
	}

	var br = document.createElement('br');

	for ( var k in err) {
		switch(k) {
			case 'code':
				var txt = document.createTextNode("Code: " + err[k]);
				errDiv.appendChild(txt);
				errDiv.appendChild(br);
				break;
			case 'line':
				if(HWI_DEBUG) {
					var line = document.createTextNode("Line: " + err[k]);
					errDiv.appendChild(line);
					errDiv.appendChild(br);
				}
			case 'message':
				var txt = document.createTextNode(err[k]);
				errDiv.appendChild(txt);
				errDiv.appendChild(br);
				break;
			default:
				break;
		}
	}

}


function isInteger(s) {
	for (var i=0; i<s.length; i++) {
		var c = s.charAt(i);
		if ( !isDigit(c) ) return false;
	}
	return true;
}

function isDigit(c) {
	return ((c >= "0") && (c <="9"));
}