var nbsp = 160;// non-breaking space char
var node_text = 3;// DOM text node-type
var emptyString = /^\s*$/ ;
var global_valfield;// retain valfield for timer thread

// Declaring required variables
var digits = "0123456789";

function isInteger(s){   
	var i;
    for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) {
			return false;
		}
    }
    // All characters are numbers.
    return true;
}



function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
} //end function trim

// --------------------------------------------
//                  msg
// Display warn/error message in HTML element.
// commonCheck routine must have previously been called
// --------------------------------------------

function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  // setting an empty string can give problems if later set to a 
  // non-empty string, so ensure a space present. (For Mozilla and Opera one could 
  // simply use a space, but IE demands something more, like a non-breaking space.)
  //alert("entered msg");
  var dispmessage;
  if (emptyString.test(message)) {
    dispmessage = String.fromCharCode(nbsp);    
  } else  {
    dispmessage = message;
  }
  
  
  var elem = document.getElementById(fld);
  if(elem.firstChild == null) {
	//alert("new node");
  	var newText = document.createTextNode(""); 
	elem.appendChild(newText);
	
  }
  elem.firstChild.nodeValue = dispmessage;  
  
  elem.className = msgtype;   // set the CSS class to adjust appearance of message
  //alert("exiting msg");
} //end function msg



// --------------------------------------------
//                  setfocus
// Delayed focus setting to get around IE bug
// --------------------------------------------

function setFocusDelayed()
{
  global_valfield.focus();
}

function setfocus(valfield)
{
  // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}

