﻿function clearStatus() {
	window.status = 'Done';	
	return true;
}		

function popupWin(hwndPopup, windowName, closeFirst, sURL, Height, Width, toolbar, status, loc, menu, resize, scroll) {
	var	opts = "toolbar=" + (toolbar == false ? 0 : 1) + ",status=" + (status == false ? 0 : 1) + ",location=" + (loc == false ? 0 : 1) + ",menubar=" + (menu == false ? 0 : 1) + ",resizable=" + (resize == false ? 0 : 1) + ",";
	opts = opts + "height=" + Height + ",width=" + Width + ",scrollbars=" + (scroll == false ? 0 : 1);

	if (hwndPopup == null || hwndPopup.closed) {
		newPopup = window.open(sURL, windowName, opts);
		newPopup.focus();
		return newPopup;
	}

	if (closeFirst) {
		if (hwndPopup != null) { hwndPopup.close(); }
		newPopup = window.open(sURL, windowName, opts);
		newPopup.focus();
		return newPopup;
	}

	hwndPopup.location.href = sURL;
	hwndPopup.focus();
	return hwndPopup;			
}

function autoTab(inputId, nextInputId, event) {
	var input = document.getElementById(inputId);
	
	if(input.value.length >= input.maxLength && isKeyCodeOfInterest(getKeyCode(event))) {
		input.value = input.value.slice(0, input.maxLength);
		document.getElementById(nextInputId).focus();
	}
}

function isKeyCodeOfInterest(keyCode) {
	var filter = [0,8,9,16,17,18,37,38,39,40,46];

	for(var i = 0; i < filter.length; i++) {
		if(keyCode == filter[i]) {
			return false;
		}
	}
	
	return true;
}

function getKeyCode(event) {
	if(event.keyCode) {
		return event.keyCode;
	} else {
		return event.which;
	}
}

