 /**
 *@author mumale
 * JavaScript for ContactUs.html file 
 * version 0.1.1
 *
 *Modified by Amol AC on Dec 06 2006 for joining mailing list
 *
 **/ 

 
function validateEmail1(man,db) 
{
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) 
{
   if (document.JoinMailingList.emailaddress.value.indexOf(invalidChars.charAt(i),0) > -1) 
   {
      if (db) alert('email address contains invalid characters');
      return false;
   }
}
for (i=0; i<document.JoinMailingList.emailaddress.value.length; i++) 
{
   if (document.JoinMailingList.emailaddress.value.charCodeAt(i)>127) 
   {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}
var atPos = document.JoinMailingList.emailaddress.value.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('Invalid email Address.\n Email address must contain an @');
   return false;
}
if (atPos == 0) 
{
   if (db) alert('Invalid email Address.\n Email address must not start with @');
   return false;
}
if (document.JoinMailingList.emailaddress.value.indexOf('@', atPos + 1) > - 1) 
{
   if (db) alert('Invalid email Address.\n Email address must contain only one @');
   return false;
}
if (document.JoinMailingList.emailaddress.value.indexOf('.', atPos) == -1) 
{
   if (db) alert('Invalid email Address.\n Email address must contain a period in the domain name');
   return false;
}
if (document.JoinMailingList.emailaddress.value.indexOf('@.',0) != -1)
{
   if (db) alert('Invalid email Address.\n period must not immediately follow @ in email address');
   return false;
}
if (document.JoinMailingList.emailaddress.value.indexOf('.@',0) != -1)
{
   if (db) alert('Invalid email Address.\n  period must not immediately precede @ in email address');
   return false;
}
if (document.JoinMailingList.emailaddress.value.indexOf('..',0) != -1) 
{
   if (db) alert('Invalid email Address.\n two periods must not be adjacent in email address');
   return false;
}
var suffix = document.JoinMailingList.emailaddress.value.substring(document.JoinMailingList.emailaddress.value.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') 
{
   if (db) alert('Invalid email Address.\n  invalid primary domain in email address');
   return false;
}
return true;
}



function isEmpty1() 
{
if ((document.JoinMailingList.fullname.value=="") ||
 (document.JoinMailingList.fullname.value==null)) 
 {
return true;
}
else { return false; }
}

function isEmpty2() 
{
if ((document.JoinMailingList.emailaddress.value=="") ||
 (document.JoinMailingList.emailaddress.value==null)) 
 {
return true;
}
else { return false; }
}
  

  
  
function validate1() 
{
// will return true or false
// Step 1: check that required fields are
// filled in, alert and exit without
// submitting if not


// check that the your name field is valued
if (isEmpty1()) {
	alert("Please enter your name.");
	document.JoinMailingList.fullname.focus();
	return false;
}

// check that the email field is valued
if (isEmpty2()) {
	alert("Please enter your email address.");
	document.JoinMailingList.emailaddress.focus();
	return false;
}

// Step 2: check that the email address is
// even close, alert and exit without
// submitting if not
if (!validateEmail1(1,1)) {
	
	document.JoinMailingList.emailaddress.focus();
	return false;
}

// if we get this far everthing is ok, so
// let the form submit
return true;

}  

 
 
 
function setFocus(aField) {
document.forms[1][aField].focus();
}
function validateEmail(aTextField,man,db) {
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (document.ContactUs.emailaddress.value.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('email address contains invalid characters');
      return false;
   }
}
for (i=0; i<document.ContactUs.emailaddress.value.length; i++) {
   if (document.ContactUs.emailaddress.value.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}
var atPos = document.ContactUs.emailaddress.value.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('Invalid email Address.\n Email address must contain an @');
   return false;
}
if (atPos == 0) {
   if (db) alert('Invalid email Address.\n Email address must not start with @');
   return false;
}
if (document.ContactUs.emailaddress.value.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('Invalid email Address.\n Email address must contain only one @');
   return false;
}
if (document.ContactUs.emailaddress.value.indexOf('.', atPos) == -1) {
   if (db) alert('Invalid email Address.\n Email address must contain a period in the domain name');
   return false;
}
if (document.ContactUs.emailaddress.value.indexOf('@.',0) != -1) {
   if (db) alert('Invalid email Address.\n period must not immediately follow @ in email address');
   return false;
}
if (document.ContactUs.emailaddress.value.indexOf('.@',0) != -1){
   if (db) alert('Invalid email Address.\n  period must not immediately precede @ in email address');
   return false;
}
if (document.ContactUs.emailaddress.value.indexOf('..',0) != -1) {
   if (db) alert('Invalid email Address.\n two periods must not be adjacent in email address');
   return false;
}
var suffix = document.ContactUs.emailaddress.value.substring(document.ContactUs.emailaddress.value.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('Invalid email Address.\n  invalid primary domain in email address');
   return false;
}
return true;
}



function isEmptyC_US_EML(aTextField) {
if ((document.ContactUs.emailaddress.value.length==0) ||
 (document.ContactUs.emailaddress.value==null)) {
return true;
}
else { return false; }
}

function isEmptyC_US_SUB(aTextField) {
if ((document.ContactUs.contactus_subject.value.length==0) ||
 (document.ContactUs.contactus_subject.value==null)) {
return true;
}
else { return false; }
}

function isEmptyC_US_FN(aTextField) {
if ((document.ContactUs.fullname.value.length==0) ||
 (document.ContactUs.fullname.value==null)) {
return true;
}
else { return false; }
}

function isEmptyC_US_DES(aTextField) {
if ((document.ContactUs.contactus_desc.value.length==0) ||
 (document.ContactUs.contactus_desc.value==null)) {
return true;
}
else { return false; }
}
function validate() {
// will return true or false
// Step 1: check that required fields are
// filled in, alert and exit without
// submitting if not

// check that the subject field is valued
if (isEmptyC_US_SUB("contactus_subject")) {
	alert("Please enter subject.");
	setFocus("contactus_subject");
	return false;
}


// check that the your name field is valued
if (isEmptyC_US_FN("fullname")) {
	alert("Please enter your name.");
	setFocus("fullname");
	return false;
}

// check that the email field is valued
if (isEmptyC_US_EML("emailaddress")) {
	alert("Please enter your email address.");
	setFocus("emailaddress");
	return false;
}

// Step 2: check that the email address is
// even close, alert and exit without
// submitting if not
if (!validateEmail("emailaddress",1,1)) {
	
	setFocus("emailaddress");
	return false;
}

// check that the Message field is valued
if (isEmptyC_US_DES("contactus_desc")) {
	alert("Please enter message.");
	setFocus("contactus_desc");
	return false;
}

// if we get this far everthing is ok, so
// let the form submit
return true;

}
  
  
