
// Returns the selected value
function returnText(thefield, value){
	if (thefield.value==""){
		thefield.value = value;}
}

// Clears the textfield
function clearText(thefield, value){
	if (value==thefield.value){
		thefield.value = "";}
}

// Goes to next textbox
function next(that, next) 
{
	if ( that.value.length == that.maxLength) 
	{
		that.form.elements[next].select();
	}
}

// Add onload event
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// checks if string is numeric
function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber; 
}

// checks key press
function getKeyCode(e)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

// Only allows integers to be typed
function keyRestrict(e) {
	var validchars = '0123456789';
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}