var astRegExDigit = "^[0-9]{1,}$";
var arForbiddenCaract 		= new Array("&" ,  "\"" , "{" , "}", "[" , "]" , "<"  , ">" , ";" , "%"   , "#" ,  	  "|" , "~" , "²" , "\\" , "€"   , "$"   , "¤" , "¨" , "§" , "£"   , "=" , "!" , "+" , "-", ":", "/", " ");
var arReplaceCaract 		= new Array("and", "''" , "(" , ")", "(" , ")" , "gt" , "lt", "," , "pct" , "" , "." , "." , "2" , "/"  , "Eur" , "USD" , "." , "." , "." , "GBP" , "=" , "!" , "+" , "-", "-", "",  " ");
var arReplaceCaractSearch 	= new Array("and", "''" , "." , ".", "." , "." , "gt" , "lt", "." , "pct" , "" , "." , "." , "2" , "."  , "Eur" , "USD" , "." , "." , "." , "GBP" , "." , "." , "." , ".", ".", "",  " ");


function astFormValidation(expression){
	
	if(expression == undefined || expression.length <= 0){return false;}
	
	if(astDetectForbiddenChar(expression)){return false;}
		
 return true; 
		
}

// retourne true si detection de merdouille ou chaine vide
function astDetectForbiddenChar(expression){
	if(expression == undefined || expression.length <= 0) return true;
	
	for (i=0; i < expression.length; i++){
		for (j=0; j < arForbiddenCaract.length; j++){
			if (expression.charAt(i) == arForbiddenCaract[j]){
				return true;
			}
		}
	}
	return false;
}

function astReplaceForbidden(expression){
	var chaineRetourne = expression;
	if(chaineRetourne == undefined || chaineRetourne.length <= 0) return chaineRetourne;
	
	for (i=0; i < chaineRetourne.length; i++){
		for (j=0; j < arForbiddenCaract.length; j++){
			if (chaineRetourne.charAt(i) == arForbiddenCaract[j]){
				chaineRetourne=astRemplace(chaineRetourne, chaineRetourne.charAt(i) , arReplaceCaract[j]);
			}
		}
	}
	return chaineRetourne;
}

function astReplaceForbidden4Search(expression){
	var chaineRetourne = expression;
	if(chaineRetourne == undefined || chaineRetourne.length <= 0) return chaineRetourne;
	
	for (i=0; i < chaineRetourne.length; i++){
		for (j=0; j < arForbiddenCaract.length; j++){
			if (chaineRetourne.charAt(i) == arForbiddenCaract[j]){
				chaineRetourne=astRemplace(chaineRetourne, chaineRetourne.charAt(i) , arReplaceCaractSearch[j]);
			}
		}
	}
	return chaineRetourne;
}


function astRemplace(expr,a,b) {
  var i=0
  while (i!=-1) {
     i=expr.indexOf(a,i);
     if (i>=0) {
        expr=expr.substring(0,i)+b+expr.substring(i+a.length);
        i+=b.length;
     }
  }
  return expr
}

function isDigit(expression){
	var regBis = new RegExp(astRegExDigit,"gi");
	if (regBis.test(expression)) {return true;}
	else {return false;}
}