//This function checks for proper email format
//including any spcecial chracters in email address
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }
 	var iChars = "*|,\":<>[]{}`\';()&$#%";
	for (var i = 0; i < str.length; i++) {
		if (iChars.indexOf(str.charAt(i)) != -1){
			return false;
		}
	}
	return true;
}

//Removes leading spaces
function LTrim( value ) {
   var re = /\s*((\S+\s*)*)/;
   return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
   var re = /((\s*\S+)*)\s*/;
   return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
   return LTrim(RTrim(value));
}

//Checks if Enter key is pressed for event e
function checkEnter(e){ 
	//e is event object passed from function invocation
	var characterCode;  //literal character code will be stored in this variable
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		validate();
	} else {
		return false;
	}
}

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;
}