<!--
// **********************************************************************************************
//
// file			: ckmail.js
// Author		: Giovambattista Fazioli (e-lementi.com)
// Web			: http://e-lementi.com
// E-mail		: info (at) e-lementi (dot) (com)
// Created		: 21/09/2006 21.24
// Modified		: 22/09/2006 0.05
//
// Copyright (C) 2002-2006 e-lementi
//
// CHANGE LOG
//
// **********************************************************************************************														*/

var oCKMail = {
	__release: "1.0",
	__filter: /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i,
	__username: "",
	__domain: "",
	__ext: "",

	// TO DO
	getUsername: function(e) {
		if(this.__init(e)) return(this.__username);
		return(false);
	},

	// TO DO
	getDomain: function(e) {
		if(this.__init(e)) return(this.__domain);
		return(false);
	},

	// TO DO
	getExtension: function(e) {
		if(this.__init(e)) return(this.__ext);
		return(false);
	},

	// TO DO
	__init: function(e) {
		if( !this.__filter.test(e) ) return(false);
		var t = e.split("@");
		this.__username = t[0];
		this.__domain = t[1];
		t = this.__domain.split(".");
		this.__ext = t[1];
		return(true);
	},

	// TO DO
	// synopsis
	//	check(e,extlist,domainlist);
	// Esegue una serie di controlli standard su un indirizzo e-mail.
	//	extlist		- Si puņ passare un secondo parametro opzionale che corrisponde ad un array di estensioni che
	//	   			sono ammesse o escluse (include/exclude extension) in base al primo valore dell'array, tutte le
	//	   			altre saranno considerate errore.
	//	   			Eg. [true,"it","com"] passano (include list)
	//	   			Eg. [false,"it","com"] NON passano (exclude list)
	//	   			Se -1 non viene preso in considerazione
	//	domainlist	- Si puņ passare un terzo parametro opzionale che corrisponde ad un array di domini che
	//	   			sono ammessi o esclusi (include/exclude domain) in base al primo valore dell'array, tutte gli
	//	   			altri saranno considerate errore.
	//	   			Eg. [true,"alice.it","mac.com"] passano (include list)
	//	   			Eg. [false,"alice.it","mac.com"] NON passano (exclude list)
	//	   			Se -1 non viene preso in considerazione
	//
	check: function(e) {
		if( this.__init(e) ) {
			// check domainExt array check
			if( arguments.length > 1 ) {
				if( typeof( arguments[1] ) == "object" ) {
					if( arguments[1][0] ) { // include list
						for(var i=0; i < arguments[1].length; i++) {
							if( this.__ext == arguments[1][i].toLowerCase() ) return(true);
						}
					} else { // exclude list
						for(var i=0; i < arguments[1].length; i++) {
							if( this.__ext == arguments[1][i].toLowerCase() ) return(false);
						}
						return(true);
					}
					return(false);
				}
			}
			// check domainName array check
			if( arguments.length > 2 ) {
				if( typeof( arguments[2] ) == "object" ) {
					if( arguments[2][0] ) { // include list
						for(var i=1; i < arguments[2].length; i++) {
							if( this.__domain == arguments[2][i].toLowerCase() ) return(true);
						}
					} else { // exclude list

						for(var i=1; i < arguments[2].length; i++) {
							if( this.__domain == arguments[2][i].toLowerCase() ) return(false);
						}
						return(true);
					}
					return(false);
				}
			}
			return(true); // email correct
		}
		return(false); // error
	}
};

//-->