// JavaScript Document

//Email validation functions against recognized personal and competitor email domains
//Email syntax validation is done against the field values onchange()

//////////////////////////////////////////
//		PERSONAL EMAIL VALIDATION		//
//////////////////////////////////////////

function ispersonalemail(email)
{
	
var debug = false;
if(debug) alert("validateemail-fs.js\nDebug mode on");

if(debug) alert("ispersonalemail()");		

//Define and populate array for personal email domains
var personal_arr = new Array(
"hotmail.com", 
"verizon.net",
"optonline.net",
"shaw.ca",
"yahoo.co.uk",
"compuserve.com",
"rr.com",
"att.net",
"cs.com",
"msn.com",
"altavista.com",
"canada.com",
"mail.com",
"email.com",
"prodigy.net",
"aol.com",
"yahoo.com",
"mindspring.com",
"earthlink.com",
"telus.net",
"earthlink.net",
"comcast.net",
"gmail.com",
"bloglines.com",
"mailinator.com",
"klassmaster.com",
"fakeinformation.com",
"mailinater.com",
"mailinator.net",
"sogetthis.com",
"fastmail.fm",
"rediffmail.com",
"mail.ru",
"rocketmail.com",
"lycos.com",
"icqmail.com"
);

var exception_arr = new Array(
"stevejauch@comcast.net"
);

var personal_arr_length = personal_arr.length;	//store length of personal array
var exception_arr_length = exception_arr.length;	//store length of exception array

email = email.toLowerCase(); //store as lowercase

//bypass domain matching for these exception email addresses:
//search for domain match from list of personal email domains. return true if match is found else do nothing.
for (var exception_arr_index = 0; exception_arr_index < (exception_arr_length); exception_arr_index++)
	{
		var exception_match_str = exception_arr[exception_arr_index].match(email)
		if(debug) alert('value of exception_match_str is: ' + exception_match_str);
		if (exception_match_str == email)
			{
			if(debug) alert('this is an exception email');
			var debug = false;
			return false;
			} 
	}

var at_location = email.indexOf("@") + 1;	//temp var for location after @ sign
email = email.slice(at_location);	//extract domain from email
if(debug) alert('value of email during personal test is: ' + email);


//search for domain match from list of personal email domains. return true if match is found else do nothing.
for (var personal_arr_index = 0; personal_arr_index < (personal_arr_length); personal_arr_index++)
	{
		var personal_match_str = personal_arr[personal_arr_index].match(email)
		if(debug) alert('value of personal_match_str is: ' + personal_match_str);
		if (personal_match_str == email)
			{
			if(debug) alert('this is a personal email');
			return true;
			} 
	}
	
if(debug) alert('this is NOT a personal email');
var debug = false;
return false;  //email is not a personal account
}


//////////////////////////////////////////
//		CORPORATE EMAIL VALIDATION		//
//////////////////////////////////////////

function iscorporateemail(email)
{

var debug = false;
if(debug) alert("validateemail-fs.js\nDebug mode on");

if(debug) alert("iscorporateemail()");		

//Define and populate array for corporate email domains
var corporate_arr = new Array(
"averythang.com",
"siebel.com",
"peoplesoft.com",
"oracle.com",
"onyx.com",
"salesforce.com",
"epiphany.com",
"sap.com",
"chordiant.com",
"builder1440.com",
"corrigo.com",
"connecture.com",
"saleslogix.com",
"barasco.com",
"riverwood.com",
"connecture.net"
);

arr_length = corporate_arr.length;	//store length of corporate array
email = email.toLowerCase(); //store as lowercase
var at_location = email.indexOf("@") + 1;	//temp var for location after @ sign
email = email.slice(at_location);	//extract domain from email
if(debug) alert('value of email during competitor test is: ' + email);

//search for domain match from list of personal email domains. return true if match found else do nothing.
for (var arr_index = 0; arr_index < (arr_length); arr_index++)
	{
		match_str = corporate_arr[arr_index].match(email)
		if(debug) alert('value of match_str is: ' + match_str);
		if (match_str == email) {return true;}
	}
	
return false;	//email is not a competitor account
}



//////////////////////////////////////////
//		EXTRA EMAIL VALIDATION		    //
//////////////////////////////////////////
/* 

This function is commented out because it cannot accommodate multiple periods in e-mail addresses - Ted Ratcliffe

function extraEmailValidation(email)
{	
	var debug = false;
	if(debug) alert("extraEmailValidation(" + email + ")");

	var validEmailExt = new Array("info","aero","museum","name","travel","mobi","jobs","coop","arpa");

	var pat = new RegExp("^(\\w|-|\\w\\.\\w)+@(\\w|-|\\w\\.\\w)+\\.\\w{2,3}$") ;
	patmatch = pat.test(email);
	if(patmatch)
	{
		return true;
	}
	else
	{
		for(a=0;a<validEmailExt.length;a++)
		{
			pat.compile("^(\\w|-|\\w\\.\\w)+@(\\w|-|\\w\\.\\w)+\\."+ validEmailExt[a] +"$");
			patmatch = pat.test(email);
			if(patmatch)
			{
				return true;
			}
			else
			{
				continue;
			}
		}
	}
	return false;	
}
*/


// NEW Validation function to include multiple periods and extras > implemented by Ted from Lorne M.
function extraEmailValidation(email) { 

    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

    return re.test(email); 

}




