<!--
// OKI Sept 22, 2005
// Routines for form validation

/*  copy/paste alert styles
	alert("You have not entered any comments!");
	val = confirm("wanna quit?");  returns OK Cancel
	val = prompt("how many?",2);  returns entered number
	message()
*/



// var mailmsg = Server.CreateObject("CDONTS.NewMail"); 
function SendMailMessage( fromName, fromAddress, recipientName, recipientAddress, theSubject, theBodyText )
{
	var mailmsg = Server.CreateObject("SMTPsvg.Mailer");
	 mailmsg.FromName = fromName;  
	 mailmsg.FromAddress = fromAddress; 
	 mailmsg.AddRecipient (recipientName, recipientAddress ) ;
	 mailmsg.Subject = theSubject;
	 mailmsg.BodyText = theBodyText;
	// mailmsg.RemoteHost = "localhost";   mrelay.perfora.net
	 mailmsg.RemoteHost = "mrelay.perfora.net";   
	return ( mailmsg.SendMail() );
}

function PhoneIsCorrect( theForm )
{
	// check for stupid
	if ( theForm.phone.value == "123-456-7890" ) 
	{ alert("Pretty funny phone number"); return false;}
	if ( theForm.phone.value == "xxx-xxx-xxx" ) 
	{ alert("'xxx-xxx-xxx' was an example..."); return false;}
	// check for alpha chars here
	// hmm, they might have them in foreign lan...never mind..
	if ( theForm.phone.value.length >= 10 ) return true;

	return (false);
}

// see if ends in ".com" or ".net"
function IsDotComOrDotNet( inValue )
{	
	inValue = inValue.toUpperCase()
	goodSoFar = false;
	// gotta have a "."  to be a .com or .net
	for ( var index = 0; index < inValue.length; index++ )
	{	
		if ( inValue.charAt(index) == "." )
		{
			goodSoFar = true; // found one
			break; // escape loop
		}
	}
	if ( !goodSoFar ) return ( false );
		
	// OK, we got a . now a "com"?
	if ( inValue.charAt( inValue.length-1 ) =="M" &&
	 	 inValue.charAt( inValue.length-2 ) =="O" &&
		 inValue.charAt( inValue.length-3 ) =="C" ) return ( true );
	// now a "NET"?
	if ( inValue.charAt( inValue.length-1 ) =="T" &&
	 	 inValue.charAt( inValue.length-2 ) =="E" &&
		 inValue.charAt( inValue.length-3 ) =="N" ) return ( true );

	return ( false );
}

function EmailIsCorrect( theForm )
{	
	var fromAddress = theForm.email.value;
	//alert("email correct validation");
	var goodSoFar = false;
	// has to have something in it to be valid...
	if ( theForm.email.value.length <= 0 )
	{
		alert("Your email address is blank. We need your address to be able to mail you.");
		theForm.email.value = "sample@myCompany.com";
		//theForm.email.value.length = 20;
		theForm.email.focus();
		return ( false );
	}
	if ( theForm.email.value == "?" )
	{
		alert("Please enter a valid e-mail address.");
		theForm.email.value = "sample@myCompany.com";
		//theForm.email.value.length = 20;
		theForm.email.focus();
		return ( false );
	}
	if ( theForm.email.value == "sample@myCompany.com" )
	{
		alert("Please use your own email address, not the sample one!");
		theForm.email.value = "?";
		//theForm.email.value.length = 1;
		theForm.email.focus();
		return ( false );
	}
	
	// now see if there is an @ sign
	for ( var index = 0; index < theForm.email.value.length; index++ )
	{	
		if ( theForm.email.value.charAt(index) == "@" )
		{
			goodSoFar = true; // found one
			break; // escape loop
		}
		//return ( false );
	}
	
	
	if ( !goodSoFar ) 
	{
		alert("Your email address appears to be invalid. Please enter in this format \"name@myCompany.com\" ");
		theForm.email.value = "name@myCompany.com";
		theForm.email.value.length = 20;
		theForm.email.select();
		theForm.email.focus();
		return ( false );  // "@" check failed
	}
	
	// check for .com and or .net
	if ( !IsDotComOrDotNet( theForm.email.value ) )
	{	// not a .com or .net.  Hmm.  
		// Ask if its right and then take their word for it. Could be 192.168.1.6
		if ( confirm("Your not a .com or .net member?! Finish form submital anyway?") == false )
			return ( false );  // just return and process mail, other wise check the site for www
	}	
	// check for www at that address
	return ( goodSoFar );
}


// make sure we at a min get a first name	
function fullNameGiven( theForm )
{
	var theFullName = theForm.fullName.value;
	if ( theForm.fullName.value.length <= 0 ) {
		alert("We really would like to have your first name so that we can recognize you later.");
		theForm.fullName.value = "";  
		//theForm.fullName.value.length = 1;
		theForm.fullName.focus();
		return ( false );	
	}
	return ( true );
}


// called when submit is clicked.
// verify based on radio button check selection input form
function FormIsGood( theForm ) { 

	// we need at a minimum their first name
	if ( ! fullNameGiven(theForm) )
		 return( false ); 
		 
		 
	// if e-mail is empty.
	if ( ! EmailIsCorrect(theForm) )
		 return( false ); 

	
	// its a go.  mail the form
	return (true );
	




}





//-->