
function validate(theForm)
{

  if (IsNumeric(theForm.Total_Owed.value) == false || theForm.Total_Owed.value=="")
  {
    alert("Please enter numbers only for \"Total Owed\".");
    theForm.Total_Owed.focus();
    return (false);
  }
  
  if (theForm.x_C1Forename.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.x_C1Forename.focus();
    return (false);
  }

  if (theForm.x_C1Forename.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"First Name\" field.");
    theForm.x_C1Forename.focus();
    return (false);
  }

  if (theForm.x_C1Forename.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"First Name\" field.");
    theForm.x_C1Forename.focus();
    return (false);
  }

  if (theForm.x_C1Surname.value == "")
  {
    alert("Please enter a value for the \"Second Name\" field.");
    theForm.x_C1Surname.focus();
    return (false);
  }

  if (theForm.x_C1Surname.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Second Name\" field.");
    theForm.x_C1Surname.focus();
    return (false);
  }

  if (theForm.x_C1Surname.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Second Name\" field.");
    theForm.x_C1Surname.focus();
    return (false);
  }
  
   if (theForm.x_C1HouseNumber.value == "")
  {
    alert("Please enter a value for the \"House No\" field.");
    theForm.x_C1HouseNumber.focus();
    return (false);
  }

  if (theForm.x_C1HouseNumber.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"House No\" field.");
    theForm.x_C1HouseNumber.focus();
    return (false);
  }

  if (theForm.x_C1HouseNumber.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"House No\" field.");
    theForm.x_C1HouseNumber.focus();
    return (false);
  }

  if (theForm.x_C1Postcode.value == "")
  {
    alert("Please enter a value for the \"Postcode\" field.");
    theForm.x_C1Postcode.focus();
    return (false);
  }

  if (theForm.x_C1Postcode.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Postcode\" field.");
    theForm.x_C1Postcode.focus();
    return (false);
  }

  if (theForm.x_C1Postcode.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Postcode\" field.");
    theForm.x_C1Postcode.focus();
    return (false);
  }
  
   if (theForm.x_C1Email.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    theForm.x_C1Email.focus();
    return (false);
  }

  if (theForm.x_C1Email.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Email\" field.");
    theForm.x_C1Email.focus();
    return (false);
  }

  if (theForm.x_C1Email.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"Email\" field.");
    theForm.x_C1Email.focus();
    return (false);
  }


/*
  if (theForm.homephone.value == "")
  {
    alert("Please enter a value for the \"Day Tel\" field.");
    theForm.homephone.focus();
    return (false);
  }

  if (theForm.homephone.value.length < 11)
  {
    alert("Please enter at least 11 characters in the \"Day Tel\" field.");
    theForm.homephone.focus();
    return (false);
  }

  if (theForm.homephone.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Day Tel\" field.");
    theForm.Preferred_Number.focus();
    return (false);
  }
  */
  //Validate phone numbers
var c1hTel = theForm.x_C1HomeTel.value;
var c1mTel = theForm.x_C1MobilePhoneNo.value;
if (c1hTel == "" && c1mTel == "") {
	if (!EW_onError(theForm, theForm.x_C1HomeTel, "TEXT", "You must provide either a preferred or mobile phone number"))
		return false;
}
if (!c1hTel == ""){	
	if (!verifyTel(c1hTel)) {
		document.getElementById('x_C1HomeTel').select();
	    alert (telNumberErrors[telNumberErrorNo]); 
		return false;
	}
	else {
	    document.getElementById('x_C1HomeTel').value =  verifyTel(c1hTel);	 
		 
	}
}		
if (!c1mTel == ""){	
	if (!verifyTel(c1mTel)) {
		document.getElementById('x_C1MobilePhoneNo').select();	
	    alert (telNumberErrors[telNumberErrorNo]); 
		 return false;
	}
	else {
	    document.getElementById('x_C1MobilePhoneNo').value =  verifyTel (c1mTel);	 
	}
}

  if (theForm.Contact_Time.selectedIndex < 0)
  {
    alert("Please select one of the \"Contact Time\" options.");
    theForm.Contact_Time.focus();
    return (false);
  }

  if (theForm.Contact_Time.selectedIndex == 0)
  {
    alert("The first \"Contact Time\" option is not a valid selection.  Please choose one of the other options.");
    theForm.Contact_Time.focus();
    return (false);
  }

    				if (IsNumeric(theForm.x_MonthlyIncome.value) == false || theForm.x_MonthlyIncome.value=="")
		  		{
    				alert("Please enter numbers only for \"Monthly Income\".");
				    theForm.x_MonthlyIncome.focus();
					return (false);
	  			}

  
  if (theForm.x_C1EmploymentStatus.selectedIndex == 0)
  {
    alert("Please select one of the \"Nature of Income\" field.");
    theForm.x_C1EmploymentStatus.focus();
    return (false);
  }
  
  if (IsNumeric(theForm.Monthly_Expenses.value) == false || theForm.Monthly_Expenses.value=="")
{
	alert("Please enter numbers only for \"Monthly Expenses\".");
	theForm.Monthly_Expenses.focus();
	return (false);
}
  

  /*
  if (theForm.Income_Period.selectedIndex == 0)
  {
    alert("Please select if the combined household income is Weekly, Monthly and Yearly");
    theForm.Income_Period.focus();
    return (false);
  }

  if (theForm.Monthly_Income.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Monthly_Income\" field.");
    theForm.Monthly_Income.focus();
    return (false);
  }

  if (theForm.Monthly_Income.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Monthly_Income\" field.");
    theForm.Monthly_Income.focus();
    return (false);
  }

 if (theForm.Total_Owed.value.length < 3)
  {
    alert("Please enter \"Total_Owed\".");
    theForm.Total_Owed.focus();
    return (false);
  }

  

  if (theForm.Number_of_Creditors.selectedIndex < 0)
  {
    alert("Please select one of the \"Number_of_Creditors\" options.");
    theForm.Number_of_Creditors.focus();
    return (false);
  }
*/
 if (IsNumeric(theForm.Number_of_Creditors.value) == false || theForm.Number_of_Creditors.value=="")
  {
    alert("Please enter numbers only for \"Number of Debts\" .");
    theForm.Number_of_Creditors.focus();
    return (false);
  }
  
  if (theForm.x_ResidentialStatus.selectedIndex == 0)
  {
    alert("Please select one of the \"Residency Status\" field.");
    theForm.x_ResidentialStatus.focus();
    return (false);
  }
     
  return (true);
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

