function validation()
{
	//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
//***************************************************************************************************************************************************
	//Date of birth
	var chk = IsNumeric(document.frm.DOBDD.value)
	if(chk == false)
	{
		alert("Please enter the Date of Birth, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.DOBDD.focus();
		return false;
	}
	if((document.frm.DOBDD.value >31) || ((document.frm.DOBDD.value ==0)))
	{
		alert("Invalid Date of Birth");
		document.frm.DOBDD.focus();
		return false;
	}
	
	
	var chk = IsNumeric(document.frm.DOBMM.value)
	if(chk == false)
	{
		alert("Please enter the Date of Birth, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.DOBMM.focus();
		return false;
	}
	if((document.frm.DOBMM.value >12) || ((document.frm.DOBMM.value ==0)))
	{
		alert("Invalid Date of Birth");
		document.frm.DOBMM.focus();
		return false;
	}
	
	var chk = IsNumeric(document.frm.DOBYYYY.value)
	if(chk == false)
	{
		alert("Please enter the Date of Birth, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.DOBYYYY.focus();
		return false;
	}
	if((document.frm.DOBYYYY.value <1910) || (document.frm.DOBYYYY.value >1991)) 
	{
		alert("Invalid Date of Birth Year(eg.. 1920)");
		document.frm.DOBYYYY.focus();
		return false;
	}
	
	
	
	if((document.frm.DOBDD.value !="") && (document.frm.DOBMM.value !="") && (document.frm.DOBYYYY.value !="")) 
	{
		var chk = isDate(document.frm.DOBMM.value+"/"+document.frm.DOBDD.value+"/"+document.frm.DOBYYYY.value)
		if(chk == false)
		{
			alert("Invalid Date of Birth.");
			document.frm.DOBDD.focus();
			return false;
		}
	}
	//end validation Dob
	//Validation of Marital Status
	if(document.frm.MaritalStatus.selectedIndex==0)
	{
		alert("Please select the Marital Status");
		
		document.frm.MaritalStatus.focus();
		return false;
	}
	//End of validation Status
	
	//****************************************************************************
	//Validation for Valid EMail(Check for blank email)
	if(document.frm.email.value=="")
	{
		alert("Please enter the Email");
		
		document.frm.email.focus();
		return false;
	}
	if(!(document.frm.email.value == ""))
    {//(check for '@' symbol)
		if(document.frm.email.value.indexOf("@") == -1)
    	{
     		alert("Please enter valid email");
			
      		document.frm.email.focus();
      		return false;
   		}
    	//(check '.' symbol)
    	if(document.frm.email.value.indexOf(".") == -1)
    	{
			alert("Please enter valid email");
			
			document.frm.email.focus();
			return false;
   		 }
	}
	//end of validation
	//validation for (door/house no/name)
	if(document.frm.house_No.value=="")
	{
		alert("Please enter the house no.");
		
		document.frm.house_No.focus();
		return false;
	}
	//(check for blank space)
	if(document.frm.house_No.value.indexOf(" ") == 0)
	{
		alert("There should not be any space before the house no.");

		
		document.frm.house_No.focus();
		return false;
	}
	//(check for first zero in house no.)
	if(document.frm.house_No.value.indexOf("0") == 0)
	{
		alert("Please enter the proper house no.");
		
		document.frm.house_No.focus();
		return false;
	}
	//end of validation
	//****************************************************************************
	
	//validation for address1
	if(document.frm.address1.value=="")
	{
		alert("Please enter the Street");
		
	    document.frm.address1.focus();
	    return false;
	}	
	//end of validation	
	//***************************************************************************
	if(document.frm.address2.value == "")
	{
		alert("Please enter the Town");
		
		document.frm.address2.focus();
		return false;
	}
	if(document.frm.Country.selectedIndex==0)
	{
		alert("Please select the County");
		
		document.frm.Country.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
	//Residential Status Validation
	if(document.frm.r_status.selectedIndex==0)
	{
		alert("Please select Residential status.");
		document.frm.r_status.focus();
		return false;
	}
	//End Residential Status Validation
	//Time at address
	var chk = IsNumeric(document.frm.addtimeyear.value)
	if(chk == false)
	{
		alert("Please enter the Time at address year, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.addtimeyear.focus();
		return false;
	}
	if((document.frm.addtimeyear.value <1900) || (document.frm.addtimeyear.value >2009))
	{
		alert("Invalid Time at address year(eg...1975)");
		document.frm.addtimeyear.focus();
		return false;
	}
	var chk = IsNumeric(document.frm.addtimemonth.value)
	if(chk == false)
	{
		alert("Please enter the Time at address month, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.addtimemonth.focus();
		return false;
	}
	if(document.frm.addtimemonth.value >11) 
	{
		alert("Invalid time at address month ");
		document.frm.addtimemonth.focus();
		return false;
	}
	//Validation for Home Telephone & Mobile Phone
	if((document.frm.mobile.value=="")&&(document.frm.H_telephone.value==""))
	{
		alert("Please enter at least one contact no");
		document.frm.mobile.focus();
		return false;
	}
	//validation for mobile Number
	if((!document.frm.mobile.value==""))
	{
		if ((!(document.frm.mobile.value.length==10)) && (!(document.frm.mobile.value.length==11))) 
    	{
    		alert("Please enter the valid mobile no.");
			document.frm.mobile.focus();
	  		return false;
    	} 
	
		//(check for Numeric value only)
		var chk = IsNumeric(document.frm.mobile.value)
		if(chk == false)
		{
			alert("Please enter valid mobile no.");
			document.frm.mobile.focus();
			return false;
		} 
		if(((!(document.frm.mobile.value.indexOf("0")==0 )) || (!(document.frm.mobile.value.indexOf("7")==1)))&&(!(document.frm.mobile.value.indexOf("7")==0)))
    	{
	   		alert("Please enter valid mobile no.");
			document.frm.mobile.focus();
	   		return false;
    	}	
		if((document.frm.mobile.value.indexOf("0")==0 ) && (document.frm.mobile.value.length<11))
    		{
	   			alert("Please enter valid mobile no.");
				document.frm.mobile.focus();
	   			return false;
    		}
			if(!(document.frm.mobile.value.indexOf("0")==0 ) && (document.frm.mobile.value.length==11))
    		{
	   			alert("Please enter valid mobile no.");
				document.frm.mobile.focus();
	   			return false;
    		}
			if((document.frm.mobile.value.indexOf("00")==0))
    		{
	   			alert("Please enter valid mobile no.");
				document.frm.mobile.focus();
	   			return false;
    		}
	}
	
	//End of Validation
	if(!(document.frm.H_telephone.value==""))
	{
		//Validation for Home Telephone
		if(document.frm.H_telephone.value=="")
		{
			alert("Please enter the home telephone no.")
			document.frm.H_telephone.focus();
			return false;
		}
			//(check for valid telephone no.)
		if ((!(document.frm.H_telephone.value.length==10)) && (!(document.frm.H_telephone.value.length==11))) 
    	{
    		alert("Length of home telephone no. should  be upto 10-11 digit");
			document.frm.H_telephone.focus();
			return false;
    	} 
		//(check for Numeric value only)
		var chk = IsNumeric(document.frm.H_telephone.value)
		if(chk == false)
		{
			alert("Home telephone no. should be in numeric");
			document.frm.H_telephone.focus();
			return false;
		} 
		if((document.frm.H_telephone.value.indexOf("0")==0 ) && (document.frm.H_telephone.value.indexOf("7")==1))
    	{
	   		alert("Please enter valid home telephone no.");
			document.frm.H_telephone.focus();
	   		return false;
    	}
		if((document.frm.H_telephone.value.indexOf("0")==0 ) && (document.frm.H_telephone.value.length<11))
    		{
	   			alert("Please enter valid home telephone no.");
				document.frm.H_telephone.focus();
	   			return false;
    		}
			if(!(document.frm.H_telephone.value.indexOf("0")==0 ) && (document.frm.H_telephone.value.length==11))
    		{
	   			alert("Please enter valid home telephone no.");
				document.frm.H_telephone.focus();
	   			return false;
    		}
			if((document.frm.H_telephone.value.indexOf("00")==0))
    		{
	   			alert("Please enter valid home telephone no.");
				document.frm.H_telephone.focus();
	   			return false;
    		}
			//end of validation
	}
	//**************************************************************************
	//Validataion Best contact time
	if(document.frm.CallBackTime.selectedIndex==0)
	{
		alert("Please select the best contact time");
		
		document.frm.CallBackTime.focus();
		return false;		
	}
	if(document.frm.loanstartyear.selectedIndex==0)
	{
		alert("Please select the loan start year");
		document.frm.loanstartyear.focus();
		return false;
	}
 	//Validation of loan amount
	if(!((document.frm.Loan_amt.value >0)&&(document.frm.Loan_amt.value<=100000)))
	{
		alert("Loan amount field should be between 1 and 100000");
		document.frm.Loan_amt.focus();
		return false;
	}
	if(document.frm.Loan_amt.value == "")
	{
		alert("Loan amount field cannot be blank");
		document.frm.Loan_amt.focus();
		return false;
	}
	if(document.frm.Loan_amt.value.indexOf("0") == 0)
	{
		alert("Amount cannot be zero");
		document.frm.Loan_amt.focus();
		return false;
	}
	
	var chk = IsNumeric(document.frm.Loan_amt.value)
	if(chk == false)
	{
		alert("Please enter the loan amount as a number, with no decimal points and no characters like ‘£‘, ‘,’ etc.");
		document.frm.Loan_amt.focus();
		return false;
	}
	//end validation loan Amt
	if(document.frm.l_name.value == "")
	{
		alert("Lender amount field cannot be blank");
		document.frm.l_name.focus();
		return false;
	}
	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 divhide()
{
	if(document.frm.Loan_Type.selectedIndex==0)
	{
		document.getElementById('divloan').style.display = 'none';
		//document.getElementById('divempdet').style.display = 'block';
		document.getElementById('divpropdet').style.display = 'none';
		document.getElementById('divcardet').style.display = 'none';
		document.getElementById('divfindet').style.display = 'none';
		document.getElementById('divtickarea').style.display = 'none';
		document.getElementById('divbnkdet').style.display = 'block';
		document.getElementById('divCreditor').style.display = 'none';
	}
	if(document.frm.Loan_Type.selectedIndex==1)
	{
		document.getElementById('divloan').style.display = 'block';
		//document.getElementById('divempdet').style.display = 'block';
		document.getElementById('divpropdet').style.display = 'block';
		document.getElementById('divcardet').style.display = 'none';
		document.getElementById('divfindet').style.display = 'none';
		document.getElementById('divtickarea').style.display = 'none';	
		document.getElementById('divbnkdet').style.display = 'block';
		document.getElementById('divCreditor').style.display = 'none';
	}
	if(document.frm.Loan_Type.selectedIndex==2)
	{
		document.getElementById('divloan').style.display = 'block';
		//document.getElementById('divempdet').style.display = 'block';
		document.getElementById('divpropdet').style.display = 'none';
		document.getElementById('divcardet').style.display = 'none';
		document.getElementById('divfindet').style.display = 'none';
		document.getElementById('divtickarea').style.display = 'none';	
		document.getElementById('divbnkdet').style.display = 'block';
		document.getElementById('divCreditor').style.display = 'block';
	}
	if(document.frm.Loan_Type.selectedIndex==3)
	{
		document.getElementById('divloan').style.display = 'block';
		//document.getElementById('divempdet').style.display = 'none';
		document.getElementById('divpropdet').style.display = 'none';
		document.getElementById('divcardet').style.display = 'none';
		document.getElementById('divfindet').style.display = 'none';
		document.getElementById('divtickarea').style.display = 'none';	
		document.getElementById('divbnkdet').style.display = 'block';
		document.getElementById('divCreditor').style.display = 'block';
	}
	if(document.frm.Loan_Type.selectedIndex==4)
	{
		document.getElementById('divloan').style.display = 'block';
		document.getElementById('divempdet').style.display = 'none';
		document.getElementById('divpropdet').style.display = 'none';
		document.getElementById('divcardet').style.display = 'block';
		document.getElementById('divfindet').style.display = 'none';
		document.getElementById('divtickarea').style.display = 'none';	
		document.getElementById('divbnkdet').style.display = 'none';
		document.getElementById('divCreditor').style.display = 'none';
	}
	if(document.frm.Loan_Type.selectedIndex==5)
	{
		document.getElementById('divloan').style.display = 'none';
		document.getElementById('divempdet').style.display = 'none';
		document.getElementById('divpropdet').style.display = 'none';
		document.getElementById('divcardet').style.display = 'none';
		document.getElementById('divfindet').style.display = 'block';
		document.getElementById('divtickarea').style.display = 'block';
		document.getElementById('divbnkdet').style.display = 'none';
		document.getElementById('divCreditor').style.display = 'none';
	}
	if(document.frm.OCC_STAT.selectedIndex==0)
	{
		document.getElementById('divempdet').style.display = 'none';
	}
	if((document.frm.OCC_STAT.selectedIndex!=0) && (document.frm.Loan_Type.selectedIndex==1))
	{
		document.getElementById('divempdet').style.display = 'block';
	}
	if((document.frm.OCC_STAT.selectedIndex!=0) && (document.frm.Loan_Type.selectedIndex==2))
	{
		document.getElementById('divempdet').style.display = 'block';
	}
	if((document.frm.OCC_STAT.selectedIndex!=0) && (document.frm.Loan_Type.selectedIndex==3))
	{
		document.getElementById('divempdet').style.display = 'block';
	}
}
//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;
}
//***************************************************************************************************************************************************
var dtCh= "/";
var minYear=1910;
var maxYear=1991;

function isInteger(s){
	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;
}

function stripCharsInBag(s, bag){
	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) {
	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 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("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		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")
		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; 
	} 
} 