
function checkfield(data)
{
if (rmspaces(data) == "") return false
else return true;
};

function roundOff(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
};


function checkfieldn(data,len)
{
if ( (rmspaces(data)).length < len) return false
else return true;
};

function noblank()
{
if (event.keyCode==32)
	return false;
if(event.keyCode>57 ||(event.keyCode<48 && event.keyCode!=46))
	return false;
}


function countchar(textarea,cpro,limit) //validate textarea characters
{
	if (textarea.value.length > limit)
		textarea.value = textarea.value.substring(0, limit);
	else
		cpro.value = limit - textarea.value.length;
}

function rmspaces(x) {
var leftx = 0;
var rightx = x.length -1;
while ( x.charAt(leftx) == ' ') leftx++;
while ( x.charAt(rightx) == ' ') --rightx;
var q = x.substr(leftx,rightx-leftx + 1); 
if ( (leftx == x.length) && (rightx == -1) ) q ='';
return(q)
};

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isdate (day,month,year)
{
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ((y2k(test.getYear()) == year)&&(month == test.getMonth())&&(day == test.getDate()))
        return true;
    else
        return false
}


function todate(fday,fmon,fyear , tday,tmon,tyear)
{
var fromdt;
var todt;

   fm = parseFloat(fmon) - 1;
   tm = parseFloat(tmon) - 1;
   var fromdt = new Date(fyear,fm,fday);   
   var todt = new Date(tyear,tm,tday);

      if (todt < fromdt)
          return false;
       else
          return true;
}

function dateequal(fday,fmon,fyear , tday,tmon,tyear)
{
  if (  (parseFloat(fday) == parseFloat(tday)) && (parseFloat(fmon) == parseFloat(tmon)) && (parseFloat(fyear) == parseFloat(tyear)) )
     {
       return true;
     }
  else
     {
       return false;
     };
}



function isnumeric(data)
 {
 var flag = ( (rmspaces(data)).length > 0);
 var isdot = 0;
  if (flag)
  {
        for (i=0;i<data.length && flag;i++)
    if ( data.charAt(i) > '9' || data.charAt(i) < '0')
       {
         if (data.charAt(i) != '.' || isdot > 0)
            {
              flag = false;
      }
           else
            {
         isdot = 1;
      }
       };
  }
 return flag
  }
  
  
  
  function isinteger(data)
   {
   var flag = ( (rmspaces(data)).length > 0);
   
    if (flag)
    {
          for (i=0;i<data.length && flag;i++)
                if ( data.charAt(i) > '9' || data.charAt(i) < '0')   flag = false;       
         
    };
    
   return flag
  }

function isemail(data){
var flag = false;
if (  (data.indexOf('@',0)  == -1) || (data.indexOf('\\',0)  != -1) || (data.indexOf('/',0)  != -1) ||!checkfield(data) || ( data.indexOf('.',0)  == -1 ) || ( data.indexOf('@')  == 0 ) || ( data.lastIndexOf('.') < data.lastIndexOf('@')  ) || ( data.lastIndexOf('.') == (data.length - 1)  ) ||        ( data.lastIndexOf('@')   !=   data.indexOf('@') ) || (data.indexOf(',',0)  != -1) ||  (data.indexOf(':',0)  != -1) || (data.indexOf(';',0)  != -1)  )return flag
else         {
             var temp = rmspaces(data);
             if (temp.indexOf(' ',0) != -1) flag = true;
             var d3 = temp.lastIndexOf('.') + 4;
             var d4 = temp.substring(0,d3);
             var e2 = temp.length  -  temp.lastIndexOf('.')  - 1 ;
             var i1 = temp.indexOf('@') ;
          if (  (temp.charAt(i1+1) == '.') || ( e2 > 3 )  ||  ( e2 < 2 )    ) flag = true;
          return !flag;
                   };
   };// End Of Function
