// Check whether string s is empty.
//-------------------------
function isEmpty(s){
   return ((s == null) || (s.length == 0))
}
//-------------------------
function trim(TXT){
   	return TXT.replace(/(^\s+)|(\s+$)/g,"");
}
//-------------------------
// Returns true if character c is a digit  (0 ...9)
function isDigit (c){
   return ((c >= "0") && (c <= "9"))
}
//-------------------------
function isInteger (s){
   var i;

  //  if (isEmpty(s)) 
  //     if (isInteger.arguments.length == 1) return defaultEmptyOK;
  //     else return (isInteger.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}
//-------------------------
function isPercentage(txtfld){
	var txt =trim(txtfld);
//	var reg=/^\d*\.?\d+%?$/;
var reg=/^\d*\.?\d*$/;
	return( reg.test(txt));
}
//-------------------------
function MakeTen(expr,decimal){
     var str="" + Math.round(eval(expr) * Math.pow(10,decimal))
     while (str.length <= decimal){
        str = "0" + str
     }
     var decpoint = str.length - decimal
     return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

//-------------------------
function isDecimal(txtfld){
var txt=trim(txtfld);
var reg=/^-?\d*\.?\d*$/;
return( reg.test(txt));
}

function isPositiveInteger(txtfld){
	var txt=trim(txtfld);
	return (isEmpty(txtfld) || !isInteger(txtfld) ||isNaN(num=parseInt(txtfld))|| num <= 0);
	}
//-------------------------
// Removes all characters which do NOT appear in string bag 
// from string s.
function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
}
//-------------------------
function getDecimal(str){
var s= stripCharsNotInBag (trim(str), "0123456789.");
if (s=="") return (0.00);
else return (s);
}
//-------------------------
function formatAsMoney(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
//-------------------------
/*Parse number to currency format:
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/
//Remove the $ sign if you wish the parse number to NOT include it
function parseelement(thisone){
var prefix=""; //"$"
var wd;
var formatted_str="";
wd="w"
var tempnum=thisone.value;
for (i=0;i<tempnum.length;i++){
	if (tempnum.charAt(i)=="."){
		wd="d";
		break;
	}
}
if (wd=="w")
	formatted_str=prefix+tempnum+".00";
else{
		if (tempnum.charAt(tempnum.length-2)=="."){
			formatted_str=prefix+tempnum+"0";
		}
		else{
			//formatted_str=thisone.value;
			//tempnum=Math.round(tempnum*100)/100;
			thisone.value=trim(prefix+tempnum);
			return ;
		}
	}
	
thisone.value=trim(formatted_str);
}

//-------------------------
function formatDecimal(thisone){

str=thisone.value
if (trim(str) ==""){  /// convert space to 0.00
	thisone.value = "0.00";
	return true;
}
if (!isDecimal(thisone.value)){
	alert ("Please Enter a valid decimal number field");
	thisone.focus();
	return false;
}
parseelement2(thisone);
return true;
}
//-------------------------
function parseelement2(thisone){
	var num=Number(thisone.value);
	num=Math.round(num*100)/100;
	var intpart= parseInt(num);
	var decimal =( num -intpart)*100 ;
	decimal=Math.round(decimal*100)/100;

//alert ("remainder="+ decimal+" "+decimal % 10);
	if (decimal == 0)
		thisone.value=String(intpart) +'.00';
	else{
  		if ((decimal % 10)== 0){		
 	 		thisone.value= String(num) +'0';
 	 	}else
  			thisone.value=String(num);
		}
}
//-------------------------
function makedecimal(num){
	num=Math.round(num*100)/100;
	var intpart= parseInt(num);
	var decimal =( num -intpart)*100 ;
	decimal=Math.round(decimal*100)/100;

//alert ("remainder="+ decimal+" "+decimal % 10);
	if (decimal == 0)
		return String(intpart) +'.00';
	else{
  		if ((decimal % 10)== 0){		
 	 		return String(num) +'0';
 	 	}else
  		return String(num);
	}
}
//-----------------------------------
function validate_email(email) {
 re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
 return re.test(email) ;

} 



