function isValidEmail(mail_address){
	// check if the address contains a " "
	if(mail_address.indexOf(' ')!=-1) return false;
	
	// check if the address contains only 1 "@"
	mail_address = mail_address.split('@');
	if(mail_address.length!=2) return false;
	
	// Init vars for reading purposes
	var firstPart,lastPart;
	firstPart = mail_address[0];
	lastPart = mail_address[1];
	
	// check if both parts of the mail-address contain only valid characters 
	// and also if the '@' is not the first or the last char in the address
	if(!stringCheck(firstPart) || !stringCheck(lastPart)) return false;
	
	// check if the last part of the address contains a "."
	lastPart = lastPart.split('.');
	if(lastPart.length<2) return false;
	
	// check if the address doesn't contain ".." and check extension
	for(var i=0;i<lastPart.length;i++){
		// check for ".."
		if(lastPart[i].length==0) return false;
		// check extension
		if(i==lastPart.length-1 && !extensionCheck(lastPart[i])) return false;
	}
	
	// check if the first part of the address doesn't contain ".."
	firstPart = firstPart.split('.');
	for(var i=0;i<firstPart.length;i++){
		if(firstPart[i].length==0) return false;
	}
	
	return true;
}

function stringCheck(mailpart){
	// A zero-length string indicates that the @ is the first or the last character in the given email-address
	if(mailpart.length==0) return false;
	
	// check on the chars used in the address
	var validChars = "@abcdefghijklmnopqrstuvwxyz0123456789.-+_";
	for(var i=0;i<mailpart.length;i++){
		if(validChars.indexOf(mailpart.charAt(i).toLowerCase())==-1) return false;
	}
	
	return true;
}

function extensionCheck(extension){
	var validExtensions = new Array('com','org','int','gov','edu','net','info','biz','aero','coop','mil','museum','net','ac','ad','ae','af','ag','ai','al','am','an','ao','aq','ar','as','at','au','aw','az','ba','bb','bd','be','bf','bg','bh','bi','bj','bm','bn','bo','br','bs','bt','bv','bw','by','bz','ca','cc','cd','cf','cg','ch','ci','ck','cl','cm','cn','co','cr','cu','cv','cx','cy','cz','de','dj','dk','dm','do','dz','ec','ee','eg','eh','er','es','et','eu','fi','fj','fk','fm','fo','fr','ga','gd','ge','gf','gg','gh','gi','gl','gm','gn','gp','gq','gr','gs','gt','gu','gw','gy','hk','hm','hn','hr','ht','hu','id','ie','il','im','in','io','iq','ir','is','it','je','jm','jo','jp','ke','kg','kh','ki','km','kn','kp','kr','kw','ky','kz','la','lb','lc','li','lk','lr','ls','lt','lu','lv','ly','ma','mc','md','mg','mh','mk','ml','mm','mn','mo','mp','mq','mr','ms','mt','mu','mv','mw','mx','my','mz','na','nc','ne','nf','ng','ni','nl','no','np','nr','nu','nz','om','pa','pe','pf','pg','ph','pk','pl','pm','pn','pr','ps','pt','pw','py','qa','re','ro','ru','rw','sa','sb','sc','sd','se','sg','sh','si','sj','sk','sl','sm','sn','so','sr','st','sv','sy','sz','tc','td','tf','tg','th','tj','tk','tm','tn','to','tp','tr','tt','tv','tw','tz','ua','ug','uk','um','us','uy','uz','va','vc','ve','vg','vi','vn','vu','wf','ws','ye','yt','yu','za','zm','zr','zw');
	for(var i=0;i<validExtensions.length;i++){
		if(validExtensions[i]==extension) return true;
	}
	return false;
}
