function chkInt(num)
{
var parsednum;
var pat;
var res = new Array();
pat = /(\.)/g;
res = num.match(pat);
if(res!=null)
if(res.length>0)
return false;
pat=/(\D)/g;
res=num.match(pat);
if(res!=null)
if(res.length>1)
return false;
else //If Length is one
if(res[0]=='-')
{
parsednum=parseInt(num);
if(parsednum==num)
return true;
else
return false;
}
else
return false;
else
return true;
}

function right(str, n)
{
  if (n <= 0)     // Invalid bound, return blank string
     return "";
  else if (n > String(str).length)   // Invalid bound, return
     return str;                     // entire string
  else { // Valid bound, return appropriate substring
     var iLen = String(str).length;
     return String(str).substring(iLen, iLen - n);
  }
}


function ltrim ( s )
{
	return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}


function trim ( s )
{
	return rtrim(ltrim(s));
}


function popupwin1(mode, url, ht, wid, name, str) 
{

str=(str==''?"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,height="+ht+",width="+wid:str+",height="+ht+",width="+wid);
//str += ",width=" + wid + ",innerWidth=" + wid;
if (window.screen) {
   var ah = screen.availHeight - 30;
   var aw = screen.availWidth - 10;

   var xc = (aw - wid) / 2;
   var yc = (ah - ht) / 2;

   str += ",left=" + xc + ",screenX=" + xc;
   str += ",top=" + yc + ",screenY=" + yc;
}
 if (mode==0)
    return window.open(url, name,str);
 else
 {
    var var_image = new Image();
    var_image.src = url;
    return window.open(var_image.src, name,str);
 }
}


function popupwin2(mode, url, ht, wid, name, str) 
{

str=(str==''?"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,height="+ht+",width="+wid:str+",height="+ht+",width="+wid);
//str += ",width=" + wid + ",innerWidth=" + wid;
if (window.screen) {
   var ah = screen.availHeight - 30;
   var aw = screen.availWidth - 10;

   var xc = (aw - wid) / 2;
   var yc = (ah - ht) / 2;

   str += ",left=" + xc + ",screenX=" + xc;
   str += ",top=" + yc + ",screenY=" + yc;
}
 if (mode==0)
    window.open(url, name,str);
 else
 {
    var var_image = new Image();
    var_image.src = url;
    window.open(var_image.src, name,str);
 }
}

function trimstring (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function getNextElement (field) {
  var form = field.form;
  for (var e = 0; e < form.elements.length; e++)
    if (field == form.elements[e])
      break;
  return form.elements[++e % form.elements.length];
}

function tabOnEnter (field, evt) {
  var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
  if (keyCode != 13)
    return true;
  else {
    getNextElement(field).focus();
    // field.focus();
    return false;
  }
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

