
//function to check for the validity of email addresses
//Email address cannot start with a "." and cannot end with "."
//Should have only one "@" symbol in the middle
//Should not have a "." immediately before or after the "@" symbol

function isemail(s) {
	return ((trim(s).length > 0) && (s.indexOf("@") > 0) && (s.substring(s.length-1) != "@") &&  (s.indexOf("@") == s.lastIndexOf("@")) && (s.indexOf(".") > 0) && (s.substring(s.length-1) != ".") && (s.indexOf(".@") == -1) && (s.indexOf("@.") == -1) && (s.indexOf("..") == -1) && (s.indexOf(" ") == -1) && (s.indexOf("\t") == -1) && (s.indexOf("\n") == -1) && (s.indexOf("\r") == -1));
}

//function to remove the whitespaces from the start and end of a string

function trim(s) {
	regl = /^[ \t\n\r]*/
	regr = /[ \t\n\r]*$/
	return s.replace(regl,"").replace(regr,"");
}

//function to check whether the value passed is a number or not
//This can also accept numbers with decimal points

function isnumeric(n) {
	reg = /^[0-9]*\.*[0-9]*$/
	return reg.test(trim(n));
}

//function to check whether the value passed is an integer or not
//This will not accept decimal places

function isinteger(n) {
	return (!isNaN(parseInt(n)) && parseInt(trim(n)).toString().length == trim(n).toString().length);
}

// function to check for a valid date

function isDate(y, m, d){
	var dd = new Date(y, m-1, d);
	return (dd.getDate() == parseInt(d) && dd.getMonth() == parseInt(m-1) && dd.getFullYear() == parseInt(y));
}

// DHTML email validation script

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){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		 //alert("dot: " + str.charAt(lstr-1) + "\n" + "leng: " + lstr);
		 if (str.charAt(lstr-1) == dot)
		 {
		    return false 
		 }

		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}