String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function trim (str)
{
   str = this != window? this : str;
   return str.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.startsWith = function(str)
{
   return (this.match("^"+str)==str)
}

String.prototype.endsWith = function(str)
{
   return (this.match(str+"$")==str)
}

//  check for valid numeric strings	
function isNumeric(strString)
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) 
      return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   return blnResult;
}

function checkEmail(str)
{
   var at="@"
   var dot="."
   var lat=str.indexOf(at)
   var lstr=str.length
   var ldot=str.indexOf(dot)

   if (str.indexOf(at)==-1){
      return false
   }

   if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
      return false
   }

   if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      return false
   }

   if (str.indexOf(at,(lat+1))!=-1){
      return false
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      return false
   }

   if (str.indexOf(dot,(lat+2))==-1){
      return false
   }

   if (str.indexOf(" ")!=-1){
      return false
   }

   return true
}

function isEmpty(str) {
   if (str == null || str.length == 0) {
      return true;
   }else{
      return false;
   }
}	

function checkRequired(element)
{
   return trim(element.value) != "";
}

function limiter(element, count){
   var tex = element.value;
   var len = tex.length;
   if(len > count){
      tex = tex.substring(0, count);
      element.value = tex;
      return false;
   }
}

function emptyDiv(divId)
{
   document.getElementById(divId).innerHTML = "";
}

function setDivText(divId, strText)
{
   document.getElementById(divId).innerHTML = strText;
}

function checkAlphaNumeric(element)
{
   var numeric = element.value;
   
   for(var j=0; j<numeric.length; j++)
   {
      var alphaa = numeric.charAt(j);
      var hh = alphaa.charCodeAt(0);
      
      if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123)){
      }else{
         return false;
      }
   }
   
   return true;
}

