// JavaScript Document
function isInteger (s){
	var i;
	
	if (isEmpty(s))
	if (isInteger.arguments.length == 1) return 0;
	else return (isInteger.arguments[1] == true);
	
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	
	return true;
}

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

function isDigit (c){
	return ((c >= "0") && (c <= "9"))
}

function FormatNumber(number){
	return number.toFixed(2);
}

function RemoveAllNonDigits(str) {
	return str.replace(/[^\d]/g, "");
}

function isCurrency(s){
	var oRegExp = /^-?\d{1,6}(\.\d{1,2})?$/;
	return oRegExp.test(s);
}

function isEmail(myEmail) {
	return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myEmail));
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function trim (myString) { 
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'') 
}

function rnd(lowerbound, upperbound) {
	//Aléatoire de lowerbound à upperbound
	return parseInt((upperbound - lowerbound + 1) * Math.random( ) + lowerbound);
}

function validPass(str){
	var oRegExp = /[\/+\n'&\s;\\"%]/;
	return !oRegExp.test(str);
}


function generatePass(nbChar){

	var LowerChar = "0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ");
	var UpperChar = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split(" ");
	var SpecialChar = "# ! $ ? ( ) *".split(" ");
    var myString = "";
	
	for (i = 1; i <= nbChar; i++) myString += LowerChar[rnd(0, LowerChar.length-1)];
    
	if (nbChar > 4) {
		rndUpperCharPos = rnd(1, nbChar);
		
		do
			rndSpecialChar = rnd(1, nbChar);
		while (rndUpperCharPos == rndSpecialChar);

		UpperChar = UpperChar[rnd(0, UpperChar.length-1)];
		SpecialChar = SpecialChar[rnd(0, SpecialChar.length-1)];

		myString = Left(myString, rndUpperCharPos - 1) + UpperChar + Right(myString, nbChar - rndUpperCharPos);
		myString = Left(myString, rndSpecialChar - 1) + SpecialChar + Right(myString, nbChar - rndSpecialChar);
	}
    
	return myString;

}

function OnEnter(event, FunctionName){
	if (event){
		var charCode = (event.which) ? event.which : event.keyCode
		if (charCode == 13){
			eval(FunctionName);
			return false;
		}
	}
}

function currencyFormat(fld, milSep, decSep, e) {
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}




