
/*
 * Filename: val_userinfo.js
 * Version:  1.0
 * Purpose:  Validation routines for various jsp files that add and update rpa_userinfo DB
 *			 Called by subscribe, quickturn, email_reg, design_401k, affiliate_reg 
 *			 and existing_proposal jsp files.
 * Created:  1 Oct 01
 * Author:   Jeff Black 
 *
 * Change Log:
 *		10/01/01 Jeff Black (jeff.black@black-canvas.com) - Initial Delivery
 *
 *		03/07/02 Robert Lacey - Zfire Communications (robert@zfire.net)
 *		Added code to prevent validation check if administrator choose delete option
 *
 *
 */


// ------------------------------------------------------------------------
//
//  javascript form validation functions for rpa user input forms
//
// ------------------------------------------------------------------------

var reInteger      = /^[\d,]+$/
var reAlphabetic   = /^[a-zA-Z]+$/
var reAlphanumeric = /^[a-zA-Z0-9]+$/
var reString       = /^[a-zA-Z0-9\s\.\@,#']+$/

var rePwd      = /^[a-zA-Z0-9!%&*\.\@\^',]+$/
var reZip      = /^[\d]{5}(-\d{4})?$/
var reEmail    = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/
//var reEmail    = /^[\w\.]+@[a-zA-Z_\-]+?\.[a-zA-Z]{2,3}$/
var reMoney    = /^[\d,]+$/
var rePhone_a  = /\d{3}/
var rePhone_3  = /\d{3}/
var rePhone_4  = /\d{4}/
var rePhone_x  = /\d{1,5}?/
var reFax_a    = /\d{3}/
var reFax_3    = /\d{3}/
var reFax_4    = /\d{4}/
var reFunds    = /^[\w\s0-9!%&*\.\@\^',]+$/
var reComments = /^[\w\s0-9!%&*\.\@\^',]+$/

// ------------------------------------------------------------------------
// For form quickturn
// ------------------------------------------------------------------------

function validate_frm_quickturn() {
  
  var msg = "";
  
  with (document.f9) {

  
  	
  	if ((which_submit.value == "Delete") ||
	    (which_submit.value == "Cancel"))
	{ return true; }
  
    mutual_funds.value = mutual_funds.value.replace(/'/g,"");

    yourfirstname.value = yourfirstname.value.replace(/'/g,"");
    if (!(yourfirstname.value.length > 0)) {
      msg += " * First Name is a required field\n";
    }

    client_firstname.value = client_firstname.value.replace(/'/g,"");
      if (!(client_firstname.value.length > 0)) {
      msg += " * Contact Person is a required field\n";
    }

    yourlastname.value = yourlastname.value.replace(/'/g,"");
    if (!(yourlastname.value.length > 0)) {
      msg += " * Last Name is a required alphabetic field\n";
    }

    if (!(rePhone_a.test(yourphone_a.value))) {
      msg += " * Telephone area code must be 3 digits only\n";
    }
    if (!(rePhone_3.test(yourphone_3.value))) {
      msg += " * Telephone must start with 3 digits only\n";
    }
    if (!(rePhone_4.test(yourphone_4.value))) {
      msg += " * Telephone must end with 4 digits only\n";
    }
    if (yourphone_x.value.length > 0) {
      if (!(rePhone_x.test(yourphone_x.value))) {
        msg += " * Telephone extension is optional, but must be digits only\n";
      }
    }

     if (!(rePhone_a.test(client_phone_a.value))) {
      msg += " * Client Telephone area code must be 3 digits only\n";
    }
    if (!(rePhone_3.test(client_phone_3.value))) {
      msg += " * Client Telephone must start with 3 digits only\n";
    }
    if (!(rePhone_4.test(client_phone_4.value))) {
      msg += " * Client Telephone must end with 4 digits only\n";
    }
    if (client_phone_x.value.length > 0) {
      if (!(rePhone_x.test(client_phone_x.value))) {
        msg += " * Client Telephone extension is optional, but must be digits only\n";
      }
    }

    if (!(reEmail.test(youremail.value) && youremail.value.length > 0)) {
      msg += " * Email must be valid\n";
    }

    yourcompany.value = yourcompany.value.replace(/'/g,"");
    if (!(yourcompany.value.length > 0)) {
      msg += " * Company Name is a required field\n";
    }

    client_website.value = client_website.value.replace(/'/g,"");
    if (!(client_website.value.length > 0)) {
      msg += " * Client Web Site is a required field\n";
    }

    client_company.value = client_company.value.replace(/'/g,"");
    if (!(client_company.value.length > 0)) {
      msg += " * Client Company Name is a required field\n";
    }

    //if (!(reString.test(add_street.value) && add_street.value.length > 0)) {
    client_street.value = client_street.value.replace(/'/g,"");
    if (!(client_street.value.length > 0)) {
      msg += " * Client Address Street is a required field\n";
    }

    client_city.value = client_city.value.replace(/'/g,"");
    if (!(client_city.value.length > 0)) {
      msg += " * Client Address City is a required field\n";
    }
    
    if (!(reZip.test(client_zip.value) && (client_zip.value.length==5 || client_zip.value.length==10))) {
      msg += " * Client Address Zip Code must be a 5 or 9 digit U.S. ZIP Code (like 94043)\n";
    }

      if (!(reInteger.test(number_employees.value) && number_employees.value > 0)) {
      msg += " * Number of Employees must be an integer > 0\n";
    }

    if (!(reInteger.test(number_participants.value) && number_participants.value >= 0)) {
      msg += " * Number of Participants must be an integer > 0\n";
    }

    dollar_amount.value = dollar_amount.value.replace(/'/g,"");
    if (!(reMoney.test(dollar_amount.value) && dollar_amount.value >= 0)) {
      msg += " * Amount of Assets In Plan must not contain $ , or . (i.e. use 1000000 for 1 million) \n";
    }

    amount_deposited.value = amount_deposited.value.replace(/'/g,"");
    if (!(reMoney.test(amount_deposited.value) && amount_deposited.value >= 0)) {
      msg += " * Amount of Assets Flowing Into Plan must not contain $ , or . (i.e. use 250000 for two hundred fifty thousand)\n";
    }

//    if (!(reString.test(current_tpa.value) && current_tpa.value.length > 0)) {
    current_tpa.value = current_tpa.value.replace(/'/g,"");
    if (!(current_tpa.value.length > 0)) {
      msg += " * Current TPA To Be Replace is a required alphanumeric field\n";
    }

    competing_with.value = competing_with.value.replace(/'/g,"");
    
//    if (!(reString.test(type_plan.value) && type_plan.value.length > 0)) {
    type_plans.value = type_plans.value.replace(/'/g,"");
    if (!(type_plans.value.length > 0)) {
      msg += " * Type of Plan is a required alphanumeric field\n";
    }

    //if (!(reFunds.test(mutual_funds.value) && mutual_funds.value.length > 0)) {
    //  msg += " * Mutual Funds is a required alphanumeric field\n";
    //}

    invest_adjust.value = invest_adjust.value.replace(/'/g,"");

    comments.value = comments.value.replace(/'/g,"");
    //if (comments.value.length > 0) {
    //  if (!(reComments.test(comments.value))) {
    //    msg += " * Comments field contains invalid characters\n";
    //  }
    //}

  }
  
  if (msg != "") {
    alert("Please correct the following form errors: \n\n" + msg);
    return false;
  } else {

    with (document.f9) {
      yourphone.value = "(" + yourphone_a.value + ")" + yourphone_3.value + "-" + yourphone_4.value;
      if (yourphone_x.value.length > 0) { yourphone.value += " xt" + yourphone_x.value; }
      clientphone.value = "(" + client_phone_a.value + ")" + client_phone_3.value + "-" + client_phone_4.value;
      if (client_phone_x.value.length > 0) { clientphone.value += " ext" + client_phone_x.value; }
    }

    return true;
  }
  
}

// ------------------------------------------------------------------------
// For form email registration
// ------------------------------------------------------------------------

function validate_frm_emailreg() {
  
  var msg = "";
  
  with (document.f9) {

    
  	
	if ((which_submit.value == "Delete") ||
	    (which_submit.value == "Cancel"))
	{ return true; }
  
//    if (!(reString.test(firstname.value) && firstname.value.length > 0)) {
    firstname.value = firstname.value.replace(/'/g,"");
    if (!(firstname.value.length > 0)) {
      msg += " * First Name is a required alphabetic field\n";
    }
  
//    if (!(reString.test(lastname.value) && lastname.value.length > 0)) {
    lastname.value = lastname.value.replace(/'/g,"");
    if (!(lastname.value.length > 0)) {
      msg += " * Last Name is a required alphabetic field\n";
    }

//    if (!(reString.test(title.value) && title.value.length > 0)) {
    title.value = title.value.replace(/'/g,"");
    if (!(title.value.length > 0)) {
      msg += " * Title is a required alphanumeric field\n";
    }

    if (!(rePhone_a.test(phone_a.value))) {
      msg += " * Telephone area code must be 3 digits only\n";
    }
    if (!(rePhone_3.test(phone_3.value))) {
      msg += " * Telephone must start with 3 digits only\n";
    }
    if (!(rePhone_4.test(phone_4.value))) {
      msg += " * Telephone must end with 4 digits only\n";
    }
    if (phone_x.value.length > 0) {
      if (!(rePhone_x.test(phone_x.value))) {
        msg += " * Telephone extension is optional, but must be digits only\n";
      }
    }
     
    if (!(reEmail.test(email.value) && email.value.length > 0)) {
      msg += " * Email must be valid\n";
    }

    if (email.value != email2.value) {
      msg += " * Email verification didn't match first email address\n";
    }

//    if (!(reString.test(company.value) && company.value.length > 0)) {
    company.value = company.value.replace(/'/g,"");
    if (!(company.value.length > 0)) {
      msg += " * Company Name is a required alphanumeric field\n";
    }

//    if (!(reString.test(add_street.value) && add_street.value.length > 0)) {
    add_street.value = add_street.value.replace(/'/g,"");
    if (!(add_street.value.length > 0)) {
      msg += " * Address Street is a required alphanumeric field\n";
    }

    add_street2.value = add_street2.value.replace(/'/g,"");
//    if (add_street2.value.length > 0) {
//      if (!(reString.test(add_street2.value))) {
//        msg += " * Address Street 2 is an optional alphanumeric field\n";
//      }
//    }
    
//    if (!(reString.test(add_city.value) && add_city.value.length > 0)) {
    add_city.value = add_city.value.replace(/'/g,"");
    if (!(add_city.value.length > 0)) {
      msg += " * Address City is a required alphanumeric field\n";
    }
    
    if (!(reZip.test(add_zip.value) && (add_zip.value.length==5 || add_zip.value.length==10))) {
      msg += " * Address Zip Code must be a 5 or 9 digit U.S. ZIP Code (like 94043)\n";
    }
  
    comments.value = comments.value.replace(/'/g,"");
//    if (comments.value.length > 0) {
//    if (!(reComments.test(comments.value))) {
//        msg += " * Comments field contains invalid characters\n";
//      }
//    }

  }
  
  if (msg != "") {
    alert("Please correct the following form errors: \n\n" + msg);
    return false;
  } else {

    with (document.f9) {
      phone.value = "(" + phone_a.value + ")" + phone_3.value + "-" + phone_4.value;
      if (phone_x.value.length > 0) { phone.value += " ext" + phone_x.value; }
    }

    return true;
  }
  
}

// ------------------------------------------------------------------------
// For form affiliate registration
// ------------------------------------------------------------------------

function validate_frm_affiliate() {
  
  var msg = "";
  
  with (document.f9) {

    	
		if ((which_submit.value == "Delete") ||
	        (which_submit.value == "Cancel"))
	     { return true; }
  
//    if (!(reString.test(firstname.value) && firstname.value.length > 0)) {
    firstname.value = firstname.value.replace(/'/g,"");
    if (!(firstname.value.length > 0)) {
      msg += " * First Name is a required alphabetic field\n";
    }
  
//    if (!(reString.test(lastname.value) && lastname.value.length > 0)) {
    lastname.value = lastname.value.replace(/'/g,"");
    if (!(lastname.value.length > 0)) {
      msg += " * Last Name is a required alphabetic field\n";
    }

//    if (!(reString.test(title.value) && title.value.length > 0)) {
    title.value = title.value.replace(/'/g,"");
    if (!(title.value.length > 0)) {
      msg += " * Title is a required alphanumeric field\n";
    }

    if (!(rePhone_a.test(phone_a.value))) {
      msg += " * Telephone area code must be 3 digits only\n";
    }
    if (!(rePhone_3.test(phone_3.value))) {
      msg += " * Telephone must start with 3 digits only\n";
    }
    if (!(rePhone_4.test(phone_4.value))) {
      msg += " * Telephone must end with 4 digits only\n";
    }
    if (phone_x.value.length > 0) {
      if (!(rePhone_x.test(phone_x.value))) {
        msg += " * Telephone extension is optional, but must be digits only\n";
      }
    }
	
	if (cellphone_a.value.length > 0) {
		if (!(rePhone_a.test(cellphone_a.value))) {
      		msg += " * Cellular Telephone area code is optional, but must be 3 digits only\n";
    	}
	}
	if (cellphone_3.value.length > 0) {
    	if (!(rePhone_3.test(cellphone_3.value))) {
      		msg += " * Cellular Telephone is optional, but must start with 3 digits only\n";
    	}
	}
	if (cellphone_4.value.length > 0) {
    	if (!(rePhone_4.test(cellphone_4.value))) {
      		msg += " * Cellular Telephone is optional, but must end with 4 digits only\n";
    	}
	}
	
    if (!(reFax_a.test(fax_a.value))) {
      msg += " * Fax area code must be 3 digits only\n";
    }
    if (!(reFax_3.test(fax_3.value))) {
      msg += " * Fax must start with 3 digits only\n";
    }
    if (!(reFax_4.test(fax_4.value))) {
      msg += " * Fax must end with 4 digits only\n";
    }

    if (!(reEmail.test(email.value) && email.value.length > 0)) {
      msg += " * Email must be valid\n";
    }

    if (email.value != email2.value) {
      msg += " * Email verification didn't match first email address\n";
    }

//    if (!(reString.test(company.value) && company.value.length > 0)) {
    company.value = company.value.replace(/'/g,"");
    if (!(company.value.length > 0)) {
      msg += " * Company Name is a required alphanumeric field\n";
    }

//    if (!(reString.test(add_street.value) && add_street.value.length > 0)) {
    add_street.value = add_street.value.replace(/'/g,"");
    if (!(add_street.value.length > 0)) {
      msg += " * Address Street is a required alphanumeric field\n";
    }
    
    add_street2.value = add_street2.value.replace(/'/g,"");
//    if (add_street2.value.length > 0) {
//      if (!(reString.test(add_street2.value))) {
//        msg += " * Address Street 2 is an optional alphanumeric field\n";
//      }
//    }
    
//    if (!(reString.test(add_city.value) && add_city.value.length > 0)) {
    add_city.value = add_city.value.replace(/'/g,"");
    if (!(add_city.value.length > 0)) {
      msg += " * Address City is a required alphanumeric field\n";
    }
    
    if (!(reZip.test(add_zip.value) && (add_zip.value.length==5 || add_zip.value.length==10))) {
      msg += " * Address Zip Code must be a 5 or 9 digit U.S. ZIP Code (like 94043)\n";
    }
  
    if (!(rePwd.test(pwd.value) && pwd.value.length >= 5)) {
      msg += " * Password must be an alphanumeric between 5 and 10 characters\n";
      msg += "   -- valid characters a-z, A-Z, 0-9, !, %, &, * , ., @, ^\n";
    }

    if (pwd.value != pwd2.value) {
      msg += " * Password verification doesn't match\n";
    }

    comments.value = comments.value.replace(/'/g,"");
//    if (comments.value.length > 0) {
//      if (!(reComments.test(comments.value))) {
//        msg += " * Comments field contains invalid characters\n";
//      }
//    }
        
  }
  
  if (msg != "") {
    alert("Please correct the following form errors: \n\n" + msg);
    return false;
  } else {

    with (document.f9) {
      phone.value = "(" + phone_a.value + ")" + phone_3.value + "-" + phone_4.value;
      if (phone_x.value.length > 0) { phone.value += " xt" + phone_x.value; }
	  
      fax.value   = "(" + fax_a.value   + ")" + fax_3.value   + "-" + fax_4.value;
	  cellphone.value = "(" + cellphone_a.value + ")" + cellphone_3.value + "-" + cellphone_4.value;
    }

    return true;
  }
  
}

// ------------------------------------------------------------------------
// For form design a 401K plan
// ------------------------------------------------------------------------

function validate_frm_design401() {
  
  var msg = "";
  
  with (document.f9) {

    // ------ section 2 ----------
   
   		
     if ((which_submit.value == "Delete") ||
	     (which_submit.value == "Cancel"))
	    { return true; }
   
      
    vesting_structure_custom.value = vesting_structure_custom.value.replace(/'/g,"");

//    if (!(reString.test(firstname.value) && firstname.value.length > 0)) {
    firstname.value = firstname.value.replace(/'/g,"");
    if (!(firstname.value.length > 0)) {
      msg += " * First Name is a required alphabetic field\n";
    }
  
//    if (!(reString.test(lastname.value) && lastname.value.length > 0)) {
    lastname.value = lastname.value.replace(/'/g,"");
    if (!(lastname.value.length > 0)) {
      msg += " * Last Name is a required alphabetic field\n";
    }

//    if (!(reString.test(title.value) && title.value.length > 0)) {
    title.value = title.value.replace(/'/g,"");
    if (!(title.value.length > 0)) {
      msg += " * Title is a required alphanumeric field\n";
    }

    if (!(rePhone_a.test(phone_a.value))) {
      msg += " * Telephone area code must be 3 digits only\n";
    }
    if (!(rePhone_3.test(phone_3.value))) {
      msg += " * Telephone must start with 3 digits only\n";
    }
    if (!(rePhone_4.test(phone_4.value))) {
      msg += " * Telephone must end with 4 digits only\n";
    }
    if (phone_x.value.length > 0) {
      if (!(rePhone_x.test(phone_x.value))) {
        msg += " * Telephone extension is optional, but must be digits only\n";
      }
    }
        
    if (!(reEmail.test(email.value) && email.value.length > 0)) {
      msg += " * Email must be valid\n";
    }

    if (email.value != email2.value) {
      msg += " * Email verification didn't match first email address\n";
    }

//    if (!(reString.test(company.value) && company.value.length > 0)) {
    company.value = company.value.replace(/'/g,"");
    if (!(company.value.length > 0)) {
      msg += " * Company Name is a required alphanumeric field\n";
    }
  
    if (!(reInteger.test(num_emp.value) && num_emp.value > 0)) {
      msg += " * Number of Employees must be an integer > 0\n";
    }
  
//    if (!(reString.test(add_street.value) && add_street.value.length > 0)) {
    add_street.value = add_street.value.replace(/'/g,"");
    if (!(add_street.value.length > 0)) {
      msg += " * Address Street is a required alphanumeric field\n";
    }

    add_street2.value = add_street2.value.replace(/'/g,"");
//    if (add_street2.value.length > 0) {
//      if (!(reString.test(add_street2.value))) {
//        msg += " * Address Street 2 is an optional alphanumeric field\n";
//      }
//    }
    
//    if (!(reString.test(add_city.value) && add_city.value.length > 0)) {
    add_city.value = add_city.value.replace(/'/g,"");
    if (!(add_city.value.length > 0)) {
      msg += " * Address City is a required alphanumeric field\n";
    }
    
    if (!(reZip.test(add_zip.value) && (add_zip.value.length==5 || add_zip.value.length==10))) {
      msg += " * Address Zip Code must be a 5 or 9 digit U.S. ZIP Code (like 94043)\n";
    }
    
    decision_comments.value = decision_comments.value.replace(/'/g,"");
//    if (decision_comments.value.length > 0) {
//      if (!(reComments.test(decision_comments.value))) {
//        msg += " * Decision Maker Comments field contains invalid characters\n";
//      }
//    }
    
    // ------ section 2 ----------

    wait_comments.value = wait_comments.value.replace(/'/g,"");
//    if (wait_comments.value.length > 0) {
//      if (!(reComments.test(wait_comments.value))) {
//        msg += " * Waiting Period Comments field contains invalid characters\n";
//      }
//    }
  
    if ((vesting_structure[5].checked) && (vesting_structure_custom.value == "")) {
      msg += " * Custom Vesting Structure is blank\n";
    }

    // ------ section 3 ----------

    expenses_comments.value = expenses_comments.value.replace(/'/g,"");
//    if (expenses_comments.value.length > 0) {
//      if (!(reComments.test(expenses_comments.value))) {
//        msg += " * Budgeted Expenses Comments field contains invalid characters\n";
//      }
//    }

    investment_comments.value = investment_comments.value.replace(/'/g,"");
//    if (investment_comments.value.length > 0) {
//      if (!(reComments.test(investment_comments.value))) {
//        msg += " * Investment Choices Comments field contains invalid characters\n";
//      }
//    }

    comments.value = comments.value.replace(/'/g,"");
//    if (comments.value.length > 0) {
//      if (!(reComments.test(comments.value))) {
//        msg += " * Comments field contains invalid characters\n";
//      }
//    }
  
  }
  
  if (msg != "") {
    alert("Please correct the following form errors: \n\n" + msg);
    return false;
  } else {

    with (document.f9) {
      phone.value = "(" + phone_a.value + ")" + phone_3.value + "-" + phone_4.value;
      if (phone_x.value.length > 0) { phone.value += " xt" + phone_x.value; }
    }

    return true;
  }
  
}

// ------------------------------------------------------------------------
// For form subscribe to newsletter
// ------------------------------------------------------------------------

function validate_frm_newsletter() {
  
  var msg = "";
  
  with (document.f9) {

    	
		if ((which_submit.value == "Delete") ||
	    	(which_submit.value == "Cancel"))
			{ return true; }
  
//    if (!(reString.test(firstname.value) && firstname.value.length > 0)) {
    firstname.value = firstname.value.replace(/'/g,"");
	if(!(firstname.value.length > 0)) {
	  msg += " * First Name is a required alphabetic field\n";
    }
  
//    if (!(reString.test(lastname.value) && lastname.value.length > 0)) {
    lastname.value = lastname.value.replace(/'/g,"");
	if (!(lastname.value.length > 0)) {
	  msg += " * Last Name is a required alphabetic field\n";
    }

//    if (!(reString.test(title.value) && title.value.length > 0)) {
    title.value = title.value.replace(/'/g,"");
    if (!(title.value.length > 0)) {
      msg += " * Title is a required alphanumeric field\n";
    }

    if (!(rePhone_a.test(phone_a.value))) {
      msg += " * Telephone area code must be 3 digits only\n";
    }
    if (!(rePhone_3.test(phone_3.value))) {
      msg += " * Telephone must start with 3 digits only\n";
    }
    if (!(rePhone_4.test(phone_4.value))) {
      msg += " * Telephone must end with 4 digits only\n";
    }
    if (phone_x.value.length > 0) {
      if (!(rePhone_x.test(phone_x.value))) {
        msg += " * Telephone extension is optional, but must be digits only\n";
      }
    }
           
    if (!(reEmail.test(email.value) && email.value.length > 0)) {
      msg += " * Email must be valid\n";
    }

    if (email.value != email2.value) {
      msg += " * Email verification didn't match first email address\n";
    }

//    if (!(reString.test(company.value) && company.value.length > 0)) {
    company.value = company.value.replace(/'/g,"");
    if (!(company.value.length > 0)) {
      msg += " * Company Name is a required alphanumeric field\n";
    }

//    if (!(reString.test(add_street.value) && add_street.value.length > 0)) {
    add_street.value = add_street.value.replace(/'/g,"");
    if (!(add_street.value.length > 0)) {
		msg += " * Address Street is a required alphanumeric field\n";
    }
    
    add_street2.value = add_street2.value.replace(/'/g,"");
//    if (add_street2.value.length > 0) {
//      if (!(reString.test(add_street2.value))) {
//        msg += " * Address Street 2 is an optional alphanumeric field\n";
//      }
//    }

//    if (!(reString.test(add_city.value) && add_city.value.length > 0)) {
    add_city.value = add_city.value.replace(/'/g,"");
    if (!(add_city.value.length > 0)) {
      msg += " * Address City is a required alphanumeric field\n";
    }
    
    if (!(reZip.test(add_zip.value) && (add_zip.value.length==5 || add_zip.value.length==10))) {
      msg += " * Address Zip Code must be a 5 or 9 digit U.S. ZIP Code (like 94043)\n";
    }

    comments.value = comments.value.replace(/'/g,"");
//    if (comments.value.length > 0) {
//      if (!(reComments.test(comments.value))) {
//        msg += " * Comments field contains invalid characters\n";
//      }
//    }
    
  }
  
  if (msg != "") {
    alert("Please correct the following form errors: \n\n" + msg);
    return false;
  } else {

    with (document.f9) {
      phone.value = "(" + phone_a.value + ")" + phone_3.value + "-" + phone_4.value;
      if (phone_x.value.length > 0) { phone.value += " xt" + phone_x.value; }
    }

    return true;
  }
  
}

// ------------------------------------------------------------------------
// For form request a proposal
// ------------------------------------------------------------------------

function validate_frm_proposal() {
  
  var msg = "";
  
  with (document.f9) {

  	
    if ((which_submit.value == "Delete") ||
	    (which_submit.value == "Cancel"))
		{ return true; }
  
    mutual_fund.value = mutual_fund.value.replace(/'/g,"");

//    if (!(reString.test(firstname.value) && firstname.value.length > 0)) {
    firstname.value = firstname.value.replace(/'/g,"");
    if (!(firstname.value.length > 0)) {
      msg += " * First Name is a required alphabetic field\n";
    }
  
//    if (!(reString.test(lastname.value) && lastname.value.length > 0)) {
    lastname.value = lastname.value.replace(/'/g,"");
    if (!(lastname.value.length > 0)) {
      msg += " * Last Name is a required alphabetic field\n";
    }

//    if (!(reString.test(title.value) && title.value.length > 0)) {
    title.value = title.value.replace(/'/g,"");
    if (!(title.value.length > 0)) {
      msg += " * Title is a required alphanumeric field\n";
    }

    if (!(rePhone_a.test(phone_a.value))) {
      msg += " * Telephone area code must be 3 digits only\n";
    }
    if (!(rePhone_3.test(phone_3.value))) {
      msg += " * Telephone must start with 3 digits only\n";
    }
    if (!(rePhone_4.test(phone_4.value))) {
      msg += " * Telephone must end with 4 digits only\n";
    }
    if (phone_x.value.length > 0) {
      if (!(rePhone_x.test(phone_x.value))) {
        msg += " * Telephone extension is optional, but must be digits only\n";
      }
    }
           
    if (!(reEmail.test(email.value) && email.value.length > 0)) {
      msg += " * Email must be valid\n";
    }

    if (email.value != email2.value) {
      msg += " * Email verification didn't match first email address\n";
    }

//    if (!(reString.test(company.value) && company.value.length > 0)) {
    company.value = company.value.replace(/'/g,"");
    if (!(company.value.length > 0)) {
      msg += " * Company Name is a required alphanumeric field\n";
    }

//    if (!(reString.test(add_street.value) && add_street.value.length > 0)) {
    add_street.value = add_street.value.replace(/'/g,"");
    if (!(add_street.value.length > 0)) {
      msg += " * Address Street is a required alphanumeric field\n";
    }

    add_street2.value = add_street2.value.replace(/'/g,"");
//    if (add_street2.value.length > 0) {
//      if (!(reString.test(add_street2.value))) {
//        msg += " * Address Street 2 is an optional alphanumeric field\n";
//      }
//    }
    
//    if (!(reString.test(add_city.value) && add_city.value.length > 0)) {
    add_city.value = add_city.value.replace(/'/g,"");
    if (!(add_city.value.length > 0)) {
      msg += " * Address City is a required alphanumeric field\n";
    }
    
    if (!(reZip.test(add_zip.value) && (add_zip.value.length==5 || add_zip.value.length==10))) {
      msg += " * Address Zip Code must be a 5 or 9 digit U.S. ZIP Code (like 94043)\n";
    }
  
    if (!(reInteger.test(num_emp.value) && num_emp.value > 0)) {
      msg += " * Number of Employees must be an integer > 0\n";
    }

    if (!(reInteger.test(num_emp_inplan.value) && num_emp_inplan.value >= 0)) {
      msg += " * Number of Employees In Plan must be an integer > 0\n";
    }

    assets_inplan.value = assets_inplan.value.replace(/'/g,"");
    if (!(reMoney.test(assets_inplan.value) && assets_inplan.value >= 0)) {
      msg += " * Amount of Assets In Plan must not contain $ , or . (i.e. use 1000000 for one million) \n";
    }

    assets_flow.value = assets_flow.value.replace(/'/g,"");
    if (!(reMoney.test(assets_flow.value) && assets_flow.value >= 0)) {
      msg += " * Amount of Assets Flowing Into Plan must not contain $ , or . (i.e. use 250000 for two hundred fifty thousand)\n";
    }

//    if (!(reString.test(current_tpa.value) && current_tpa.value.length > 0)) {
    current_tpa.value = current_tpa.value.replace(/'/g,"");
    if (!(current_tpa.value.length > 0)) {
      msg += " * Current TPA To Be Replace is a required alphanumeric field\n";
    }
    
//    if (!(reString.test(type_plan.value) && type_plan.value.length > 0)) {
    type_plan.value = type_plan.value.replace(/'/g,"");
    if (!(type_plan.value.length > 0)) {
      msg += " * Type of Plan is a required alphanumeric field\n";
    }

    //if (!(reFunds.test(mutual_fund.value) && mutual_fund.value.length > 0)) {
    if (!(mutual_fund.value.length > 0)) {
      msg += " * Mutual Funds is a required alphanumeric field\n";
    }

    comments.value = comments.value.replace(/'/g,"");
//    if (comments.value.length > 0) {
//      if (!(reComments.test(comments.value))) {
//        msg += " * Comments field contains invalid characters\n";
//      }
//    }
    
  }
  
  if (msg != "") {
    alert("Please correct the following form errors: \n\n" + msg);
    return false;
  } else {

    with (document.f9) {
      phone.value = "(" + phone_a.value + ")" + phone_3.value + "-" + phone_4.value;
      if (phone_x.value.length > 0) { phone.value += " xt" + phone_x.value; }
    }
    
    return true;
  }
  
}
