function validateEmail(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	//check if '@' is in the email address
	if (str.indexOf(at)==-1){
	   alert("Please, insert a valid e-mail address.");
	   return false;
	}
	//check if '@' is not at the beginning or at the end of the email address
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Please, insert a valid e-mail address.");
	   return false;
	}
	//check if there is '.' and it is not at the beginning or at the end of the email address
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please, insert a valid e-mail address.");
		return false;
	}
	//check if there is another '@' after the frist one
	if (str.indexOf(at,(lat+1))!=-1){
		alert("Please, insert a valid e-mail address.");
		return false;
	}
	//check if the char before or after the '@' is a dot
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please, insert a valid e-mail address.");
		return false;
	}
	//check if there is a dot after the first char close to the '@'
	if (str.indexOf(dot,(lat+2))==-1){
		alert("Please, insert a valid e-mail address.");
		return false;
	}
	//check if there is no white space in the email address
	if (str.indexOf(" ")!=-1){
		alert("Please, insert a valid e-mail address.");
		return false;
	}
	//check if there is minimum length
	if (str.length <= 5){
		alert("Please, insert a valid e-mail address.");
		return false;
	}
	 return true;					
}

function remove_XS_whitespace(str){
  //this function clear all the white space at the beginning and at
  //the end of the string and remove all the exceding white space between two words
  //item.value = item.value.replace(/\r/g, " ");
  //item.value = item.value.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");
  //item.value = item.value.replace(/'/g, "");
  str = str.replace(/ +/g, " ");
  str = str.replace(/^\s/g, "");
  str = str.replace(/\s$/g, "");
  if (str == ' '){str = ''};
  return str;
}

function remove_startend_whitespace(str){
  while( (str.length > 0 ) && (str.charAt(0) == " ") ){
    str = str.replace(/^\s/g, "");
  }
  while( (str.length > 0 ) && (str.charAt(str.length-1) == " ") ){
    str = str.replace(/\s$/g, "");
  }
  if (str == ' '){str = ''};
  return str;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
