function inputRestrict(field, e, type)
{
  var key;
  var keychar;
  
  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key).toLowerCase();
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
  {
    return true;
  }
  else
  {
	// specific type keys
    if(type == "phone" && (("0123456789+/ ").indexOf(keychar) > -1))
      return true;
    else if(type == "email" && (("abcdefghijklmnopqrstuvwxyz@._-0123456789").indexOf(keychar) > -1))
      return true;
    else if(type == "url" && (("0123456789abcdefghijklmnopqrstuvwxyz:./@").indexOf(keychar) > -1))
      return true;
    else if(type == "alpha" && (("abcdefghijklmnopqrstuvwxyz").indexOf(keychar) > -1))
      return true;
    else if(type == "alphanumeric" && (("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
      return true;
    else if(type == "number" && (("-0123456789").indexOf(keychar) > -1))
      return true;
	else if(type == "unumber" && (("0123456789").indexOf(keychar) > -1))
      return true;  
    else if(type == "decimal" && (("-0123456789.").indexOf(keychar) > -1))
      return true;
	else if(type == "udecimal" && (("0123456789.").indexOf(keychar) > -1))
      return true;  
  }
  
  return false;
}

function trim(str)
{
  var str = str.replace(/^\s\s*/, ''), ws = /\s/, i = str.length;
  while (ws.test(str.charAt(--i)));
  return str.slice(0, i + 1);
}

function checkText(field, type)
{
  var val = field.value != null ? field.value : "";
  var text = trim(val);
  
  if(type == "email")
  {
    var regexp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(regexp.test(text.toLowerCase()))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
}
