function isSearch(elm) {
	var elmstr = elm.value +"";
	var re = /^[\'\(\)\+\[\]]/gi;
	if (elmstr.search(re) != -1) return false;
	return true;
}

function isValidChar(elm) {
	var elmstr = elm.value + "";
	elmstr = elmstr.substring(0,elmstr.indexOf("@"));
	var re = /[\s\'\"\|\?\,\;\:\!\/\`\\\[\]]/gi;
	if (elmstr.search(re) != -1  )		return false;
	return true;
}

// Is the variable empty ?
function isEmpty(elm) {
    var elmstr = elm.value + "";
    if (elmstr.length == 0) return true;
    return false;
}

function isSelected(elm) {
	var myelm = elm.selectedIndex;
	if (myelm==0)	return false;
	else return true;
}
/********** 
 *	EMAIL
 *********/
// Check for email address: look for [@] and [.] and NOT [ ]
function isEmail(elm) {
        if ((elm.value.indexOf(" ") + "" == "-1"
        && elm.value.indexOf("@") + "" != "-1"
		&& elm.value.indexOf("@") + "" != "0"
        && (elm.value.lastIndexOf(".") > elm.value.indexOf("@")+1)
		&& (elm.value.lastIndexOf(".") < elm.value.length-2)
		&& (isValidChar(elm) == true) && (isValidExt(elm) == true)
        && elm.value != "")) return true;
        else return false;
}
// Is the account valid?
function isValidChar(elm) {
	var elmstr = elm.value + "";
	elmstr = elmstr.substring(0,elmstr.indexOf("@"));
	var re = /[\s\'\"\|\?\,\;\:\!\/\`\\\[\]]/gi;
	if (elmstr.search(re) != -1  )		return false;
	return true;
}

//is the Ext valid?
function isValidExt(elm) {
	var elmstr = elm.value +"";
	elmstr = elmstr.substring(elmstr.lastIndexOf(".")+1, elmstr.length);
	var re1 = /[0-9]/gi;
	var re2 = /[\s\'\"\|\?\,\;\:\!\/\`\\\[\]]/gi;
	if ((elmstr.search(re1) != -1 )||(elmstr.search(re2) != -1 )) 		return false;
	return true;
}
/********** 
 *	/EMAIL
 *********/

function isLen(elm, N) {
	var elmstr = elm.value + "";
	if (elmstr.length < N)
		return true;
	else
		return false;
}

//Check the length, the length must be > to N. elm is numeric, N is numeric (borne)
function isNlength(elm,N) {
        var elmstr = elm.value + "";
        if (elmstr.length < N) return false;
        for (var i = 0; i < elmstr.length; i++) {
                if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9") return false;
        }
        return true;
}

// Check if the elm is exact length.
function isExactNlength(elm,N) {
        var elmstr = elm.value + "";
        if (elmstr.length != N) return false;
        for (var i = 0; i < elmstr.length; i++) {
                if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9") return false;
        }
        return true;
}

// check that one checkbox is checked
function isChecked(elm) {
       for (var i=0; i<elm.length; i++) {
         if (elm[i].checked==true) return true;
       }
       return false;
}

// Check for number (tel or zip)
function isNum(elm) {
 	Verif = false
	myNum = "" + elm.value;
	if (myNum.length > 1) {
		Verif = true;
	  	for(i=0;i<myNum.length;i++) {
	    	var c = myNum.substring(i,i+1);
	    	if((c == "0")||(c == "1")||(c == "2")||(c == "3")||(c == "4")||(c == "5")||(c == "6")||(c == "7")||(c == "8")||(c == "9"))
        	{
          		//Verif = true;
        	} else {
		  		Verif = false;
			}
	  	}
	  	if (Verif == true) {
	  		return true;
	  	} else {
	    	return false;
	  	}
	} else {
		return true;
	}
}

function isTel(elm) {
 	Verif = false
	myNum = "" + elm.value;
	if ((myNum.length > 1)&&(myNum.length < 18)) {
		Verif = true;
	  	for(i=0;i<myNum.length;i++) {
	    	var c = myNum.substring(i,i+1);
	    	if((c == "0")||(c == "1")||(c == "2")||(c == "3")||(c == "4")||(c == "5")||(c == "6")||(c == "7")||(c == "8")||(c == "9")||(c == ".")||(c == " "))
        	{
          		//Verif = true;
        	} else {
		  		Verif = false;
			}
	  	}
	  	if (Verif == true) {
	  		return true;
	  	} else {
	    	return false;
	  	}
	} else {
		return true;
	}
}

function isNumNaiss(elm) {
 	Verif = false
	myNum = "" + elm;
	if (myNum.length > 1) {
		Verif = true;
	  	for(i=0;i<myNum.length;i++) {
	    	var c = myNum.substring(i,i+1);
	    	if((c == "0")||(c == "1")||(c == "2")||(c == "3")||(c == "4")||(c == "5")||(c == "6")||(c == "7")||(c == "8")||(c == "9"))
        	{
          		//Verif = true;
        	} else {
		  		Verif = false;
			}
	  	}
	  	if (Verif == true) {
	  		return true;
	  	} else {
	    	return false;
	  	}
	} else {
		return true;
	}
}

function Empty(elm) {
	var elmstr = elm.value + "";
	if (trimStr(elmstr).length == 0) return true;
	return false;
}

function trimStr(str) {
	var i=0, j=str.length-1;
	while (i<j && str.charAt(i)==" ") { i++; }
	while (j>=i && str.charAt(j)==" ") { j--; }
	return str.substr(i, j-i+1);
}

function isDate(day, month, year) {
 if (month.value>=1 && month.value <=12 && year.value>1753 && year.value<9999) {
     if( month.value==2 && day.value>29 ) return false;
     else if ((month.value == 1 ||month.value == 3 || month.value == 5|| month.value == 7|| month.value == 8|| month.value == 10|| month.value == 12) && day.value>31) return false;
     else if(day.value >30) return false;
     return true;
 }
 return false;
}

function checkRadio( radio ) {
 for( i = 0; i < radio.length && radio[i].checked == false; i++ ) ;
       return i < radio.length ;
}

function getRadioValue( radio ) {
 for( i = 0; i < radio.length && radio[i].checked == false; i++ ) ;
    if ( i < radio.length)
         return radio[i].value;
    else return false;
}


function getSelectedOption ( select ) {
   return select.options[select.selectedIndex ].value;
}

//Check if the radio is checked with the txt value
function isCheckValue(elm,txt) {
var valeur = new String();
valeur = txt;
    for (var i=0; i<elm.length; i++) {
      if ( (elm[i].checked==true)&& (elm[i].value==valeur)) return true;
    }
    return false;
  }


