function validation()
{

	//**************************************************************************************
	//validation for Debt Amount(check first 0)
	if(document.frm.txtDebtAmt.value == "")
	{
		alert("Loan amount field cannot be blank");
		document.frm.txtDebtAmt.focus();
		return false;
	}
	if(document.frm.txtDebtAmt.value.indexOf("0") == 0)
	{
		alert("Amount cannot be zero");
		document.frm.txtDebtAmt.focus();
		return false;
	}
	//Validation for Loan Amount
	var chk = IsNumeric(document.frm.txtDebtAmt.value)
	if(chk == false)
	{
		alert("Please enter the Debt amount as a number, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.txtDebtAmt.focus();
		return false;
	}
	//end validation Debt Amt
	//*********************************************************************************
	
	//validation for purpose of application
	//if(document.frm.ddlPurpose.selectedIndex==0)
	//{
		//alert("Please select the purpose of application");
		
	//	document.frm.ddlPurpose.focus();
		//return false;
	//}
	//end of validation
	//*******************************************************************************
	
			
	//validation for Title
	
	//end of valiation
	//******************************************************************************



	//Validation For First Name(Check for Blank Name)
	if(document.frm.First_Name.value=="")
	{
		alert("Please enter the first name");
		
		document.frm.First_Name.focus();
		return false;
	}
	//(Check for Blank Space)
	if(document.frm.First_Name.value.indexOf(" ")==0)
	{
		alert("There should not be any space before the name")
		
		document.frm.First_Name.focus();
		return false;
	}
	//(Check for Charectors only Name)
	var chk = Ischar(document.frm.First_Name.value)
	if(chk == false)
	{
		alert("Please use characters only");
		document.frm.First_Name.focus();
		return false;
	}
	//end of validation
	//****************************************************************************

	//Validation for Last Name(Check for Blank Name)
	if(document.frm.Last_name.value=="")
	{
		alert("Please enter the last name");
		
		document.frm.Last_name.focus();
		return false;
	}
	//(Check for Blank Space)
	if(document.frm.Last_name.value.indexOf(" ")==0)
	{
		alert("There should not be any space before the name")
		
		document.frm.Last_name.focus();
		return false;
	}
	//(Check for Charectors only)
	var chk = Ischar(document.frm.Last_name.value)
	if(chk == false)
	{
		alert("Please use characters only");
		
		document.frm.Last_name.focus();
		return false;
	}
	//end validation
	//****************************************************************************
	//validation for (Date Of Birth)
	/*if(document.frm.dob.value=="")
	{
		alert("Please enter the Date of Birth.");
		
		document.frm.dob.focus();
		return false;
	}
	var dtStr=document.frm.dob.value;
	if(isDate(dtStr)==false)
	{
		document.frm.dob.focus();
		return false;
	}
	
	//end validation*/
	//****************************************************************************
	//Validation For Marital Status(Check for Blank Name)
	
	//end of validation
	//****************************************************************************
	//Validation For Address(Check for Blank Name)
	if(document.frm.Address1.value=="")
	{
		alert("Please enter the House No");
		
		document.frm.Address1.focus();
		return false;
	}
	if(document.frm.Address2.value=="")
	{
		alert("Please enter the Street");
		
		document.frm.Address2.focus();
		return false;
	}
	if(document.frm.Address3.value=="")
	{
		alert("Please enter the Town");
		
		document.frm.Address3.focus();
		return false;
	}
	//Validation for PostCode
	if(document.frm.postcode.value == "")
	{
		alert("Please enter the postcode");
		
		document.frm.postcode.focus();
		return false;
	}
	
	var chk = postit(document.frm.postcode.value)
	if(chk == false)
	{
		alert("Please enter valid postcode");
		document.frm.postcode.focus();
		return false;


	}
	//end of validation
	//***************************************************************************
	//email
	if(document.frm.emailaddress.value == "")
	{
		alert("Please enter the Email");
		
		document.frm.emailaddress.focus();
		return false;
	}
	//Validation for Valid EMail(Check for blank email)
	if(!(document.frm.emailaddress.value == ""))
    {//(check for '@' symbol)
		if(document.frm.emailaddress.value.indexOf("@") == -1)
    	{
     		alert("Please enter valid email");
			
      		document.frm.emailaddress.focus();
      		return false;
   		}
    	//(check '.' symbol)
    	if(document.frm.emailaddress.value.indexOf(".") == -1)
    	{
			alert("Please enter valid email");
			
			document.frm.emailaddress.focus();
			return false;
   		 }
	}
	//end of validation
	//**************************************************************************
	//Validation for Contact No & Mobile No
	if((document.frm.contactno.value=="") && (document.frm.mobileno.value==""))
	{
		alert("Please enter any one phone number");
		document.frm.contactno.focus();
		return false;
	}
	else
	{
			//Validation for Contact No
			//if(document.frm.contactno.value=="")
			//{
				//alert("Please enter the contact no.")
				//document.frm.contactno.focus();
				//return false;
			//}
	
			//(check for valid Contact No.)
			if ((!(document.frm.contactno.value.length==0)) && (!(document.frm.contactno.value.length==10)) && (!(document.frm.contactno.value.length==11))) 
    		{
       			alert("Length of contact no. should  be upto 10-11 digit");
	   			document.frm.contactno.focus();
	   			return false;
    		} 
	
			//(check for Numeric value only)
			if (!(document.frm.contactno.value.length==0))
			{
			var chk = IsNumeric(document.frm.contactno.value)
			if(chk == false)
			{
				alert("Contact no. should be in numeric");
				document.frm.contactno.focus();
				return false;
			}
			}
			if((document.frm.contactno.value.indexOf("0")==0 ) && (document.frm.contactno.value.indexOf("7")==1))
      		{
	    		alert("Please enter valid home telephone no.");
				document.frm.contactno.focus();
	    		return false;
       		}
			//end of validation
		//validation for mobile Number
		if(!(document.frm.mobileno.value==""))
		{
			if ((!(document.frm.mobileno.value.length==10)) && (!(document.frm.mobileno.value.length==11))) 
    		{
      			alert("Please enter the valid mobile no.");
	 			document.frm.mobileno.focus();
		  		return false;
    		} 
	
			//(check for Numeric value only)
			var chk = IsNumeric(document.frm.mobileno.value)
			if(chk == false)
			{
				alert("Please enter valid mobile no.");
				document.frm.mobileno.focus();
				return false;
			} 
			if(((!(document.frm.mobileno.value.indexOf("0")==0 )) || (!(document.frm.mobileno.value.indexOf("7")==1)))&&(!(document.frm.mobileno.value.indexOf("7")==0)))
     		{
	    		alert("Please enter valid mobile no.");
				document.frm.mobileno.focus();
	    		return false;
       		}	
		}
	
	//validation for check box
	}
	//validation for check box
	
	//End of Validation
	
	
	//validation for Residential Status
	//if(document.frm.ddlResidentialStatus.selectedIndex==0)
	//{
		//alert("Please select the Residential Status");
		
		//document.frm.ddlResidentialStatus.focus();
		//return false;		
	//}
	//end of valiation
	//******************************************************************************
	//validation for No of Debts
	//if(document.frm.ddlNoofdebts.selectedIndex==0)
	//{
		//alert("Please select the no of debts");
		
		//document.frm.ddlNoofdebts.focus();
		//return false;		
	//}
	//end of valiation
	//******************************************************************************
	//validation for Monthly Income
	if(document.frm.monthlyincome.value == "")
	{
		alert("Monthly Income field cannot be blank");
		document.frm.monthlyincome.focus();
		return false;
	}
	if(document.frm.monthlyincome.value.indexOf("0") == 0)
	{
		alert("Monthly Income cannot be zero");
		document.frm.monthlyincome.focus();
		return false;
	}
	//Validation for Loan Amount
	var chk = IsNumeric(document.frm.monthlyincome.value)
	if(chk == false)
	{
		alert("Please enter the Monthly Income as a number, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.monthlyincome.focus();
		return false;
	}
	//end validation Monthly Income
	//*********************************************************************************
	//Monthly Expenditure
	if(document.frm.monthlyexpenditure.value == "")
	{
		alert("Monthly Expenditure field cannot be blank");
		document.frm.monthlyexpenditure.focus();
		return false;
	}
	if(document.frm.monthlyexpenditure.value.indexOf("0") == 0)
	{
		alert("Monthly Expenditure cannot be zero");
		document.frm.monthlyexpenditure.focus();
		return false;
	}
	//Validation for Loan Amount
	var chk = IsNumeric(document.frm.monthlyexpenditure.value)
	if(chk == false)
	{
		alert("Please enter the Monthly Expenditure as a number, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.monthlyexpenditure.focus();
		return false;
	}
	//End of Monthly Expenditure
	//validation for (Date Of Birth)
	if(document.frm.DOBDD.selectedIndex==0)
	{
		alert("Please select the Dob (Day)");
		
		document.frm.DOBDD.focus();
		return false;
	}
	if(document.frm.DOBMM.selectedIndex==0)
	{
		alert("Please select the Dob (Month)");
		
		document.frm.DOBMM.focus();
		return false;
	}
	if(document.frm.DOBYYYY.selectedIndex==0)
	{
		alert("Please select the Dob (Year)");
		
		document.frm.DOBYYYY.focus();
		return false;
	}
	//End validation of DOB
	if(document.frm.chkData.checked==false)
	{
		alert("Please confirm that you have read and agree \n with the Terms and Conditions");
		return false;
	}
	return true;
}
function isInteger(s)
{
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	var i;
    for (i = 0; i < s.length; i++)
	{   
    	// Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
//check for valid numerical strings
function IsNumeric(strString)
{
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
   //  test strString consists of valid characters listed above
   for (j = 0; j < strString.length && blnResult == true; j++)
   {
     strChar = strString.charAt(j);
     if (strValidChars.indexOf(strChar) == -1)
     {
        blnResult = false;
     }
   }
   return blnResult;
}	
	
//check for valid charector strings
function Ischar(strString)
{
  var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;
 //  test strString consists of valid characters listed above
  for (j = 0; j < strString.length && blnResult == true; j++)
  {
     strChar = strString.charAt(j);
     if (strValidChars.indexOf(strChar) == -1)
     {
        blnResult = false;
     }
  }
  return blnResult;
}
//function for postcode
function postit(strString)
{//check postcode format is valid
 	test = strString; size = test.length
 	test = test.toUpperCase(); //Change to uppercase
 	while (test.slice(0,1) == " ") //Strip leading spaces
  	{
		test = test.substr(1,size-1);size = test.length
  	}
 	while(test.slice(size-1,size)== " ") //Strip trailing spaces
  	{	
		test = test.substr(0,size-1);size = test.length
  	}
 	//document.details.pcode.value = test; //write back to form field
 	if (size < 6 || size > 8)
	{ //Code length rule
    		return false;
  	}
 	if (!(isNaN(test.charAt(0))))
	{ //leftmost character must be alpha character rule
      		return false;
  	}
 	if(isNaN(test.charAt(size-3)))
	{ //first character of inward code must be numeric rule
     		return false;
  	}
 	if (!(isNaN(test.charAt(size-2))))
	{ //second character of inward code must be alpha rule
     		return false;
  	}
 	if (!(isNaN(test.charAt(size-1))))
	{ //third character of inward code must be alpha rule
      		return false;
  	}
 	//if(!(test.charAt(size-4) == " "))
	//{//space in position length-3 rule
     // 		return false;
   //	}
 	//count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 	//if (count1 != count2)
	//{//only one space rule
    // 		return false;
  	//}
	return true;
}

function dateCheck(m, d, y) 
{
	if(m != '')
	{//alert(m)
		if(m == "Apr" || m == "Jun" || m == "Sep" || m == "Nov")
		{//alert("hello")
			if(d == "31")
			{ 
				return false; 
			} 
		} 
		if(m == "Feb")
		{ 
			if(parseInt(y)%4 != 0 && d == "29")
			{	 
				return false; 
			} 
			else if(d == 30 || d== 31)
			{ 
				return false; 
			} 
		} 
	return true; 
	} 
} 
function stripCharsInBag(s, bag)
{
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
	{   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n)
{	
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	for(var i = 1; i <= n; i++)
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr)
{
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Please enter date format should be : MM/DD/YYYY")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month [Format:MM/DD/YYYY]")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day [MM/DD/YYYY]");
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date [MM/DD/YYYY]")
		return false
	}
return true
}
