function validEmail(str){
	var ok, msg1,msg2,msg3, msg4, msg5;
	msg1="";
	msg2="";
	msg3="";
	msg4="";
	msg5="";
	ok = true;
	if(str=="")	{
		msg1 = "Email Address Required\n";
		ok = false;
	}

	if(str.indexOf("'")!=-1){ // if check ' sign is in the Email Address
		msg2 = "Invalid Character in Email Address\n";
		ok = false;
	}

	if(str.indexOf("@")==-1){	// if @ sign is not present
		msg3 = "Incomplete Email Address\n";
		ok = false;
	}

	if(str.indexOf("@")==0){	// if @ sign is at the start of Email Address
		msg3 = "Incomplete Email Address\n";
		ok = false;
	}

	if(str.indexOf("@")==str.length-1){	// if @ sign is at the end of the Email Address
		msg3 = "Incomplete Email Address\n";
		ok = false;
	}

	if(str.indexOf(".")==-1){	// if . sign is not present in Email Address
		msg3 = "Incomplete Email Address\n";
		ok = false;
	}

	if(str.indexOf(".")==0){	// if . sign is at the start of Email Address
		msg4 = "Invalid Format of Email Address\n";
		ok = false;
	}

	if(str.indexOf(".")==str.length-1){	// if . sign is at the end of Email Address
		msg3 = "Incomplete Email Address\n";
		ok = false;
	}

	if(str.indexOf(" ")!=-1){	// if empty space is present in Email Address
		msg5 = "Empty space is not allow in Email Address\n";
		ok = false;
	}

	if(str.indexOf("@")+1==str.indexOf(".")){	// if @ and . sign is together
		msg4 = "Invalid Format of Email Address\n";
		ok = false;
	}

	if(str.charAt(str.indexOf(".")+1)=="."){// if . and . sign is together
		msg4 = "Invalid Format of Email Address\n";
		ok = false;
	}

	if(str.charAt(str.indexOf(".",str.indexOf(".")+1)+1)=="."){	// if second . and . sign is together
		msg4 = "Invalid Format of Email Address\n";
		ok = false;
	}

	if(str.charAt(str.indexOf(".",str.indexOf(".",str.indexOf(".")+1)+1)+1)=="."){	// if third . and . sign is together
		msg4 = "Invalid Format of Email Address\n";
		ok = false;
	}

	if(str.indexOf(".")+1==str.indexOf("@")){	// if . and @ sign is together
		msg4 = "Invalid Format of Email Address\n";
		ok = false;
	}

	if(str.indexOf("@",str.indexOf("@")+1)!=-1){	// if two @ sign is present in Email Address
		msg4 = "Invalid Format of Email Address\n";
		ok = false;
	}

	msg = msg1 + msg2 + msg3 + msg4 + msg5;
	return ok;

}

function trim(str){
	var currentcharacter,finalstring;
	finalstring = "";
	for(i=0;i<str.length;i++){
		currentcharacter = str.charAt(i);
		if(currentcharacter==" "){
			if(i>0 && i<str.length && i!=str.length-1){
				if(str.charAt(i+1)!=" ")
					finalstring = finalstring + currentcharacter
			}
		}
		else
			finalstring = finalstring + currentcharacter
	}
	if(finalstring.charAt(0)==" ")
		finalstring = finalstring.substring(1,finalstring.length);
	return finalstring;
}