/**
** A sample validation code
*/
function ValidarAnyForm(form){ 

  input= document.anyForm.name;
  if (input.value.length == 0)
  {
    alert('Insert your name');
    input.focus();
    return false;
  }
  input= document.anyForm.email;
  return ValidEmail(input);

  return true;

} 

/**
** Quote calculator validation code
*/
function ValidateQuoteForm(form){ 

  input= document.paymentloancalc.amount;
  if (input.value.length == 0)
  {
    alert('Insert lease amount');
    input.focus();
    return false;
  }
  amount = new Number(input.value);
  if (isNaN(amount))
  {
    alert('Amount value must be a number');
    input.focus();
    return false;
  }
  if (amount < 1000)
  {
    alert('Amount value must be greater than $1,000');
    input.focus();
    return false;
  }

  input= document.paymentloancalc.customer;
  if (input.value.length == 0)
  {
    alert('Insert customer company name');
    input.focus();
    return false;
  }

  input= document.paymentloancalc.vendor;
  if (input.value.length == 0)
  {
    alert('Insert vendor company name');
    input.focus();
    return false;
  }
  return true;

} 

/**
** This is the validation of the Atlantic Application huge form
*/
function ValidateApplicationForm(form)
{
  // ^ BUSINESS CONTACT INFORMATION SECTION ^
  input= document.applicationForm.f101_business_name1;
  if (input.value.length == 0)
  {
    alert('Insert your business name');
    input.focus();
    return false;
  }
  input= document.applicationForm.f103_contact;
  if (input.value.length == 0)
  {
    alert('Insert the contact person name');
    input.focus();
    return false;
  }
  input= document.applicationForm.f104_business_address1;
  if (input.value.length == 0)
  {
    alert('Insert the business address');
    input.focus();
    return false;
  }
  input= document.applicationForm.f106_county;
  if (input.value.length == 0)
  {
    alert('Insert the county where the business is located');
    input.focus();
    return false;
  }
  input= document.applicationForm.f107_city;
  if (input.value.length == 0)
  {
    alert('Insert the city where the business is located');
    input.focus();
    return false;
  }
  input= document.applicationForm.f108_state;
  if (input.value.length == 0)
  {
    alert('Insert the state where the business is located');
    input.focus();
    return false;
  }
  input= document.applicationForm.f110_zip;
  if (input.value.length == 0)
  {
    alert('Insert the area zip code for your business');
    input.focus();
    return false;
  }
  input= document.applicationForm.f112_phone;
  if (input.value.length == 0)
  {
    alert('Insert the phone number for your business');
    input.focus();
    return false;
  }
  input= document.applicationForm.f115_email;
  if (!ValidEmail(input))
  {
    return false;
  }

  // ^ OWNERS / PARTNERS / STOCKHOLDERS SECTION ^

  input= document.applicationForm.f201_name;
  if (input.value.length == 0)
  {
    alert('Insert the name of at least one owner/parter/stockholder');
    input.focus();
    return false;
  }
  input= document.applicationForm.f202_title;
  if (input.value.length == 0)
  {
    alert('Insert the title of the owner/parter/stockholder');
    input.focus();
    return false;
  }
  input= document.applicationForm.f203_socialsec;
  if (input.value.length == 0)
  {
    alert('Insert the Social Security Number of the'
         + 'owner/parter/stockholder');
    input.focus();
    return false;
  }
  input= document.applicationForm.f204_address;
  if (input.value.length == 0)
  {
    alert('Insert the address of the owner/parter/stockholder');
    input.focus();
    return false;
  }
  input= document.applicationForm.f205_city;
  if (input.value.length == 0)
  {
    alert('Insert the city of the owner/parter/stockholder');
    input.focus();
    return false;
  }
  input= document.applicationForm.f206_state;
  if (input.value.length == 0)
  {
    alert('Insert the state of the owner/parter/stockholder');
    input.focus();
    return false;
  }
  input= document.applicationForm.f207_zip;
  if (input.value.length == 0)
  {
    alert('Insert the zip code of the owner/parter/stockholder');
    input.focus();
    return false;
  }

  // ^ EQUIPMENT INFORMATION SECTION ^

  input= document.applicationForm.f301_amount;
  if (input.value.length == 0)
  {
    alert('Insert the amount requested');
    input.focus();
    return false;
  }
  input= document.applicationForm.f303_equip;
  if (input.value.length == 0)
  {
    alert('Insert the equipment description');
    input.focus();
    return false;
  }
  input= document.applicationForm.f304_vendor;
  if (input.value.length == 0)
  {
    alert('Insert the equipment vendor name');
    input.focus();
    return false;
  }

  // ^ BANK SECTION ^

  input= document.applicationForm.f401_bname;
  if (input.value.length == 0)
  {
    alert('Insert the Bank name');
    input.focus();
    return false;
  }
  input= document.applicationForm.f402_account;
  if (input.value.length == 0)
  {
    alert('Insert the Bank checking account');
    input.focus();
    return false;
  }
  input= document.applicationForm.f403_phone;
  if (input.value.length == 0)
  {
    alert('Insert the Bank phone number');
    input.focus();
    return false;
  }
  input= document.applicationForm.f405_city;
  if (input.value.length == 0)
  {
    alert('Insert the city where the Bank is located');
    input.focus();
    return false;
  }
  input= document.applicationForm.f406_state;
  if (input.value.length == 0)
  {
    alert('Insert the state where the Bank is located');
    input.focus();
    return false;
  }

  // ^ LOANS OR LEASES SECTION ^
  // No validations to do...yet!

  // ^ TRADE REFERENCES SECTION ^

  input= document.applicationForm.f601_name;
  if (input.value.length == 0)
  {
    alert('Insert the name of your first supplier');
    input.focus();
    return false;
  }
  input= document.applicationForm.f602_account;
  if (input.value.length == 0)
  {
    alert('Insert the account number of your first supplier');
    input.focus();
    return false;
  }
  input= document.applicationForm.f603_phone;
  if (input.value.length == 0)
  {
    alert('Insert the phone number of your first supplier');
    input.focus();
    return false;
  }
  input= document.applicationForm.f611_name;
  if (input.value.length == 0)
  {
    alert('Insert the name of your second supplier');
    input.focus();
    return false;
  }
  input= document.applicationForm.f612_account;
  if (input.value.length == 0)
  {
    alert('Insert the account number of your second supplier');
    input.focus();
    return false;
  }
  input= document.applicationForm.f613_phone;
  if (input.value.length == 0)
  {
    alert('Insert the phone number of your second supplier');
    input.focus();
    return false;
  }

  // ^ AT LAST... The Contract Sign ^

  input= document.applicationForm.theSign;
  if (input.value.length == 0)
  {
    alert('Please write your name at the authorization area');
    input.focus();
    return false;
  }
  return true;
}

/**
** This is the new user form validation
*/
function ValidarNewUserForm(form) 
{
  input= document.newUserForm.name;
  if (input.value.length == 0)
  {
    alert('Insert your name');
    input.focus();
    return false;
  }
  input= document.newUserForm.user;
  if (input.value.length == 0)
  {
    alert('Insert your desired user name');
    input.focus();
    return false;
  }
  input= document.newUserForm.pass;
  if (input.value.length == 0)
  {
    alert('Insert your desired password');
    input.focus();
    return false;
  }
  input= document.newUserForm.email;
  return ValidEmail(input);

  return true;
} 

function ValidEmail(input){
	var pos1, pos2, bOk = true; 
	var sDir = input.value; 
	if (sDir == ""){ 
		alert("Insert your email address"); 
		input.focus(); 
		return false; 
	} 
	pos1 = sDir.indexOf('@', 0); 
	pos2 = sDir.indexOf('.', 0); 
	bOk = bOk && (pos1 > 0); 
	bOk = bOk && (pos2 != -1); 
	bOk = bOk && (pos1 < pos2 - 1); 
	bOk = bOk && (pos2 < sDir.length - 1); 
	if (!bOk){ 
		alert("Invalid email address"); 
		input.focus(); 
		return false; 
	}   
	return true;
}
