
sNewLine = "\n";
var sSpecialChars = "&\\~`!?[]\"%$<+=^>}{|:;*";
var msg = "CDOcalc provides financial analytics on-line services.\n " 
	+ "It is our expectation that our customers and prospects\n "
	+ "are affiliated with formal organizations\n "
	+ "and do not use free email accounts.\n "
	+ "Please enter your work email address.\n "
	+ "If you feel you are getting this message in error,\n "
	+ "please call our San Francisco office 1-650 266 9660\n "
	+ "or send email to cdocalc@wsainc.com.\n"
/////////////////////////////
function isFreeEMail(str)
{
/*
	arrayMail = new Array (
	"@yahoo.",
	"@hotmail.",
	"@aol.",
	"@mail.",	
	"@bigfoot.",
	"@canada.com",
	"@address.",
	"@fastmail.",
	"@freemail.",
	"@freeemail.",
	"@freebox.",
	"@Inbox.",
	"@la.com",
	"@lycos.com",
	"@email.",
	"@netscape.net",	
	"@popmail.",
	"@s-mail.com",
	"@icqmail.com",
	"@themail.");
	
	for(var i = 0; i < arrayMail.length; i++ )
	{
		if( str.indexOf(arrayMail[ i ]) > -1 )
		{
			return true;			
		}
	}

	if( str.indexOf(".edu") == str.length - ".edu".length )
	{
		return true;			
	}
*/
	return false;
}
////////////////////////////////////////
function isPhoneNumber(str)
{
	if( str == "" )
	{
		alert( "Please fill in all required fields." );
		return false;
	}

	strStripped = stripCharsInBag(str, digits);
	digitsNum = str.length - strStripped.length; 
	
	if( stripCharsInBag(str, validUSPhoneChars) == '' 
			&& digitsNum <= 14 
			&& digitsNum >= 10 )
	{
		return true;
	}
	else
	{
		var sMsg = "";
		if( stripCharsInBag(str, validUSPhoneChars) != '' )
		{
			sMsg += 'Phone number contains invalid characters.\n';
		}
		if( digitsNum > 14 )
		{
			sMsg += "Phone number contains too many digits.\n";
		}
		
		if( digitsNum < 10 )
		{
			sMsg += "Phone number is too short.\n";
		}
		alert ( sMsg );
		
		return false;
	}
}
//////////////////////////////////////////////////////
function checkSpecialChars(eMailForm)
{
return hasSpecialChars(eMailForm.firstname.value) 
	|| hasSpecialChars(eMailForm.lastname.value) 
	|| hasSpecialChars(eMailForm.company.value) 
	|| hasSpecialChars(eMailForm.email.value) 
	|| hasSpecialChars(eMailForm.phone.value)
}
//////////////////////////////////////////////////////
function hasSpecialChars(str)
{
	if(str=="")
	{
		return false;
	}

	if( str != stripCharsInBag (str, sSpecialChars) ) 
	{
		return true;
	}

	return false;
}
////////////////////////////////////
function fieldsOK(eMailForm, needPhone)
{
	var phone = eMailForm.phone.value;
	if( checkSpecialChars(eMailForm) )
	{
		alert ( 'Please do not use symbols ' + sSpecialChars 
			+ ' in your contact information.\nThese symbols are reserved for the system purpose.\n' );
	}
	else if( (needPhone || phone != "") && ! isPhoneNumber(phone) )
	{
		
	}
	else if( isFreeEMail(eMailForm.email.value) )
	{
		alert ( msg );
	}
	else
	{
		return true;
	}
	return false;
}
////////////////////////////////////

function sendMail( sSubject, sTextStart, sTextEnd, eMailForm, needCompany, needPhone )
{
	if( fieldsOK(eMailForm, needPhone)  )
	{
		var email   = /*escape*/( stripInitialWhitespace(eMailForm.email.value) );
		var fname   = /*escape*/( stripInitialWhitespace(eMailForm.firstname.value) );
		var lname   = /*escape*/( stripInitialWhitespace(eMailForm.lastname.value) );
		var company = /*escape*/( stripInitialWhitespace(eMailForm.company.value) );
		var phone   = /*escape*/( stripInitialWhitespace(eMailForm.phone.value) );
		var ext   = /*escape*/( stripInitialWhitespace(eMailForm.ext.value) );
		var title   = /*escape*/( stripInitialWhitespace(eMailForm.title.value) );

		if( email && lname && fname && (!needCompany || company) && (!needPhone || phone) )
		{
			
			var sText = sTextStart
			  + "    Name: " + fname + " " + lname + "," + sNewLine
			  + ( (title != "") ? ("    Title: " + title + "," + sNewLine) : "" )
			  + ( (company != "") ? ("    Company: " + company + "," + sNewLine) : "" )
			  + "    EMail: " + email 
			  + ( (phone != "") ? ("," + sNewLine + "    " + "Phone: " + phone ) : "" )
			  + ( (ext != "") ? ("," + sNewLine + "    " + "Extension: " + ext + sNewLine) : "" )
			  + sTextEnd;

			document.forms[0].msgText.value = sText;
			document.forms[0].msgSubject.value = sSubject;
			document.forms[0].action = "absrequest_action.jsp";
			document.forms[0].submit();
		}
		else
		{
			alert("Please fill in all required fields.");
		}
	}
}

////////////////////////////////////

function sendRequest()	
{

	var	eMailForm = window.document.mailForm;
	var sSubject = "ABScalc information request.";
	var sTextStart = "Please send me information about ABScalc." 
	+ sNewLine + "Thank you." 
	+ sNewLine + "My contact information:" 
	+ sNewLine + sNewLine ;

	sendMail( sSubject, sTextStart, "", eMailForm, true, true );
}
