function LTrim(str)
        {
               var whitespace = new String(" \t\n\r");
               var s = new String(str);
                if (whitespace.indexOf(s.charAt(0)) != -1) {

                    var j=0, i = s.length;
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;
                    s = s.substring(j, i);
                }

                return s;
        }
function RTrim(str)
       {
                var whitespace = new String(" \t\n\r");
                var s = new String(str);
                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
                    var i = s.length - 1;       
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;
                    s = s.substring(0, i+1);
                }

                return s;
        }


function Trim(str)
        {
                return RTrim(LTrim(str));
        }
function Validate(theForm) {
	
		if (Trim(theForm.primary_last_name.value) == "")
  {
    alert("Please enter primary last name.");
    theForm.primary_last_name.focus();
    return (false);
  }
  	if (Trim(theForm.primary_first_name.value) == "")
  {
    alert("Please enter primary first name.");
    theForm.primary_first_name.focus();
    return (false);
  }
      if (Trim(theForm.email.value) == "")
  {
    alert("Please enter your email address.");
    theForm.email.focus();
    return (false);
  }
	var checkStr = theForm.email.value;
	var ch = checkStr.indexOf('@');

	if (ch==0 || ch==-1) {
		alert("Please enter a valid email address.");
		theForm.email.focus();
		return (false);
	}
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789@.-+_'!#$%&()*,/";
	var checkStr = theForm.email.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
	}
	if (!allValid) {
		alert("Please enter a valid email address.");
		theForm.email.focus();
		return (false);
	}	
   if (Trim(theForm.residential_address.value) == "")
  {
    alert("Please enter residential address.");
    theForm.residential_address.focus();
    return (false);
  }	
   if (Trim(theForm.residential_city.value) == "")
  {
    alert("Please enter residential city.");
    theForm.residential_city.focus();
    return (false);
  }	
  
   if (Trim(theForm.residential_state.value) == "")
  {
    alert("Please enter residential state.");
    theForm.residential_state.focus();
    return (false);
  }	
 

if (Trim(theForm.residential_zip.value) == "")
  {
    alert("Please enter residential zip code.");
    theForm.residential_zip.focus();
    return (false);
  }	
 
  if (Trim(theForm.home_phone.value) == "")
  {
    alert("Please enter home phone number.");
    theForm.home_phone.focus();
    return (false);
  }
  
   var checkOK = "()-0123456789";
	var checkStr = theForm.home_phone.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
	}
	if (!allValid) {
		alert("Please enter only digit in the \"Home Phone \" field.");
		theForm.home_phone.focus();
		return (false);
	}
 
  if (Trim(theForm.rent_or_own.value) == "")
  {
    alert("Please enter if you own or rent.");
    theForm.rent_or_own.focus();
    return (false);
  }	
  
   if (Trim(theForm.years_in_residence.value) == "")
  {
    alert("Please enter total years of residence in this address.");
    theForm.years_in_residence.focus();
    return (false);
  }	
  
    if (Trim(theForm.firm_name.value) == "")
  {
    alert("Please enter firm name.");
    theForm.firm_name.focus();
    return (false);
  }	
   if (Trim(theForm.type_of_business.value) == "")
  {
    alert("Please enter type of business .");
    theForm.type_of_business.focus();
    return (false);
  }	
    if (Trim(theForm.position.value) == "")
  {
    alert("Please enter your position .");
    theForm.position.focus();
    return (false);
  }	
   if (Trim(theForm.years_in_position.value) == "")
  {
    alert("Please enter total years in position .");
    theForm.years_in_position.focus();
    return (false);
  }
    if (Trim(theForm.business_address.value) == "")
  {
    alert("Please enter business address.");
    theForm.business_address.focus();
    return (false);
  }	
    if (Trim(theForm.business_city.value) == "")
  {
    alert("please enter business city");
    theForm.business_city.focus();
    return (false);
  }	
     if (Trim(theForm.business_state.value) == "")
  {
    alert("please enter business state");
    theForm.business_state.focus();
    return (false);
  }	
     if (Trim(theForm.business_zip.value) == "")
  {
    alert("please enter business zip code");
    theForm.business_zip.focus();
    return (false);
  }	
     if (Trim(theForm.business_country.value) == "")
  {
    alert("please enter business country");
    theForm.business_country.focus();
    return (false);
  }	
  
       if (Trim(theForm.business_phone.value) == "")
  {
    alert("please enter business phone number");
    theForm.business_phone.focus();
    return (false);
  }	
  
      var checkOK = "()-0123456789";
	var checkStr = theForm.business_phone.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
	}
	if (!allValid) {
		alert("Please enter only digit in the \"Business Phone \" field.");
		theForm.business_phone.focus();
		return (false);
	}
 
    if (Trim(theForm.primary_dob.value) == "")
  {
    alert("please enter primary date of birth");
    theForm.primary_dob.focus();
    return (false);
  }	
  
      if (Trim(theForm.primary_social_security_number.value) == "")
  {
    alert("please enter primary social security number");
    theForm.primary_social_security_number.focus();
    return (false);
  }	
  
   var checkOK = "0123456789";
	var checkStr = theForm.primary_social_security_number.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
	}
	if (!allValid) {
		alert("Please enter only digit in the \"Social Security \" field.");
		theForm.primary_social_security_number.focus();
		return (false);
	}
	
	   var checkOK = "0123456789";
	var checkStr = theForm.secondary_social_security_number.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
	}
	if (!allValid) {
		alert("Please enter only digit in the \"Social Security \" field.");
		theForm.secondary_social_security_number.focus();
		return (false);
	}
    
      if (Trim(theForm.credit_amount_requested.value) == "")
  {
    alert("please enter credit amount requested");
    theForm.credit_amount_requested.focus();
    return (false);
  }	
      if (Trim(theForm.bank1_name.value) == "")
  {
    alert("please enter bank name");
    theForm.bank1_name.focus();
    return (false);
  }	
  
     if (Trim(theForm.bank1_aba.value) == "")
  {
    alert("please enter ABA");
    theForm.bank1_aba.focus();
    return (false);
  }	
  
  if (Trim(theForm.bank1_account_type.value) == "")
  {
    alert("please enter account type");
    theForm.bank1_account_type.focus();
    return (false);
  }	
  
   if (Trim(theForm.bank1_account_number.value) == "")
  {
    alert("please enter account number");
    theForm.bank1_account_number.focus();
    return (false);
  }	
  
  if (Trim(theForm.bank1_city.value) == "")
  {
    alert("please enter city for bank location");
    theForm.bank1_city.focus();
    return (false);
  }	
  
  if (Trim(theForm.bank1_state.value) == "")
  {
    alert("please enter state for bank location");
    theForm.bank1_state.focus();
    return (false);
  }	
  
  if (Trim(theForm.bank1_zip.value) == "")
  {
    alert("please enter zip code for bank location");
    theForm.bank1_zip.focus();
    return (false);
  }	
  
  if ((theForm.disclaimer_approval.checked==false))
{
   alert("Please check the terms and conditions agreement.");
   theForm.disclaimer_approval.focus();
   return (false);
} 
 
 
  
		return (true);
}


