<!--
//var rePhone = /^0[1-9]\d{1}\s?\d{4}\s?\d{4}$)|(^0[1-9]\d{2}\s?\d{3}\s?\d{4}$)|(^0[1-9]\d{2}\s?\d{4}\s?\d{3}$)|(^0[1-9]\d{3}\s?\d{3}\s?\d{2}$)|(^0[1-9]\d{3}\s?\d{3}\s?\d{3}$)|(^0[1-9]\d{4}\s?\d{3}\s?\d{2}$)|(^0[1-9]\d{4}\s?\d{2}\s?\d{3}$)|(^0[1-9]\d{4}\s?\d{2}\s?\d{2}$/

function Trim(StrValue)
{
  var st = StrValue;
  while ((st.length > 0) && (st.charAt(0) == " ")) 
	st = st.substring(1, st.length);
  while ((st.length > 0) && (st.charAt(st.length-1) == " "))    
    st = st.substring(0, st.length-1);  
  return st;
}

function blnCheckEmail(pstrEmail)
{
	var k, intFirstAtSignPos, intFirstDotPos, strLastDomainInAddress
	var strValidChar = new String("abcdefghijklmnopqrstuvwxyz1234567890-_.@");
	pstrEmail = Trim(pstrEmail);
	for (k = 0; k <= pstrEmail.length; k++)
		if (strValidChar.indexOf((pstrEmail.substr(k, 1)).toLowerCase()) == -1) return false;
	if (pstrEmail.indexOf("..") >= 0) return false;		
	intFirstAtSignPos = pstrEmail.indexOf("@")
	if(intFirstAtSignPos < 1) return false;
	if (pstrEmail.indexOf("@", (intFirstAtSignPos+1)) >= 0) return false;
	intFirstDotPos = pstrEmail.indexOf(".")
	if(intFirstDotPos < 0) return false;
	if (pstrEmail.indexOf("_", intFirstAtSignPos) != -1) return false;
	strLastDomainInAddress = pstrEmail.substr((pstrEmail.lastIndexOf(".") + 1))
	if (strLastDomainInAddress.length < 2 || strLastDomainInAddress.length > 4) return false;
	return true;
}

function CheckFAQMortSearch()
{
	var form = document.getElementById("applyfrm");
	with (form)
	{
		if (MortSearch2_mortPurpose.value == "0")
		{
			alert("Please select purpose of your mortgage");
			MortSearch2_mortPurpose.focus();
		}
		else if (MortSearch2_houseValue.value == "" )
		{
			alert("Please enter property value");	
			MortSearch2_houseValue.focus();
		}
		else if (!isFinite(MortSearch2_houseValue.value))
		{
			alert('Property value is not correct');
			MortSearch2_houseValue.focus();
		}
		else if (MortSearch2_houseValue.value < 500 )
		{
			alert("property value must be at least 500 pounds");	
			MortSearch2_houseValue.focus();
		}
		else if (MortSearch2_mortValue.value == "" )
		{
			alert("Please enter the amount you want to borrow");	
			MortSearch2_mortValue.focus();
		}
		else if (!isFinite(MortSearch2_mortValue.value))
		{
			alert('Mortgage amount is not correct');
			MortSearch2_mortValue.focus();
		}
		else if (MortSearch2_mortValue.value < 500 )
		{
			alert("Mortgage amount must be at least 500 pounds");	
			MortSearch2_mortValue.focus();
		}
//		else if (MortSearch2_mortValue.value > 100000 )
//		{
//			alert("Mortgage amount can not be more than 100000 pounds");	
//			MortSearch2_mortValue.focus();
//		}
		else if ((MortSearch2_mortValue.value)*1 > (MortSearch2_houseValue.value)*1)
		{
			alert("Mortgage amount can not be more than the property value ");
			MortSearch2_mortValue.focus();
		}
		else if ( !MortSearch2_adverse_0.checked && !MortSearch2_adverse_1.checked )
		{
			alert("Please select if you had any bad credit or CCJs");
		}
		else
		{
			return true;
		}
	}
	return false;
}

function CheckMortSearch()
{ 
	var form = document.getElementById("Form1");
	with (form)
	{
		if (mortPurpose.value == "0")
		{
			alert("Please select purpose of your mortgage");
			mortPurpose.focus();
		}
		else if (houseValue.value == "" )
		{
			alert("Please enter property value");	
			houseValue.focus();
		}
		else if (!isFinite(houseValue.value))
		{
			alert('Property value is not correct');
			houseValue.focus();
		}
		else if (houseValue.value < 500 )
		{
			alert("property value must be at least 500 pounds");	
			houseValue.focus();
		}
		else if (mortValue.value == "" )
		{
			alert("Please enter the amount you want to borrow");	
			mortValue.focus();
		}
		else if (!isFinite(mortValue.value))
		{
			alert('Mortgage amount is not correct');
			mortValue.focus();
		}
		else if (mortValue.value < 500 )
		{
			alert("Mortgage amount must be at least 500 pounds");	
			mortValue.focus();
		}
//		else if (mortValue.value > 100000 )
//		{
//			alert("Mortgage amount can not be more than 100000 pounds");	
//			mortValue.focus();
//		}
//		else if (n != "100" && (mortValue.value)*1 > (houseValue.value)*1)
//		{
//			alert("Mortgage amount can not be more than the property value ");
//			mortValue.focus();
//		}
		//else if (n == "100" && (mortValue.value)*1 != (houseValue.value)*1)
		else if ((mortValue.value)*1 > (houseValue.value)*1)
		{
			alert("Mortgage amount must be equal to property value ");
			mortValue.focus();
		}
		else if ( !adverse_0.checked && !adverse_1.checked )
		{
			alert("Please select if you had any bad credit or CCJs");
		}
		else if ( mortCatID_2.checked && (mortCatID_0.checked || mortCatID_1.checked || mortCatID_3.checked || mortCatID_4.checked || mortCatID_5.checked) )
		{
			mortCatID_0.checked = false;
			mortCatID_1.checked = false;
			mortCatID_3.checked = false;
			mortCatID_4.checked = false;
			mortCatID_5.checked = false;
			alert("Offset can not be selected with another types of mortgage");
		}
		else if (txtNumber.value == "") 
		{
			alert("Please enter security number");
		}
		else
		{
			return true;
		}
	}
	return false;
}

function SetMortValueFor100Percent()
{
	var form = document.getElementById("Form1");
	form.mortValue.value = form.houseValue.value;
}

function MortgageApply()
{
	var form = document.getElementById("applyfrm");
	with (form)
	{
		if (title.value == "0")
		{
			alert("Please select your title");
			title.focus();
		}
		else if (fName.value == "" )
		{
			alert("Please complete your first name to proceed");	
			fName.focus();
		}
		else if (lName.value == "" )
		{
			alert("Please complete your surname to proceed");	
			lName.focus();
		}
		else if (streetName.value == "" )
		{
			alert("Please complete your address to proceed");	
			fillInAdd();
		//	streetName.focus();
		}
		else if (postTown.value == "" )
		{
			alert("Please complete your town to proceed");	
		//	postTown.focus();
		}
		else if (postcode.value == "" )
		{
			alert("Please complete your postcode to proceed");	
		//	postcode.focus();
		}
		else if (mortPurpose.value == "0")
		{
			alert("Please select the purpose of your mortgage");
			mortPurpose.focus();
		}
		else if (houseValue.value == "" )
		{
			alert("Please complete the value of property");	
			houseValue.focus();
		}
		else if (!isFinite(houseValue.value))
		{
			alert('property value is not correct');
			houseValue.focus();
		}
		else if (houseValue.value < 500 )
		{
			alert("property value must be at least 500 pounds");	
			houseValue.focus();
		}
		else if (mortValue.value == "" )
		{
			alert("Please complete the amount you want to borrow");	
			mortValue.focus();
		}
		else if (!isFinite(mortValue.value))
		{
			alert('Mortgage amount is not correct');
			mortValue.focus();
		}
		else if (mortValue.value < 500 )
		{
			alert("Mortgage amount must be at least 500 pounds");	
			mortValue.focus();
		}
//		else if (mortValue.value > 100000 )
//		{
//			alert("Mortgage amount can not be more than 100000 pounds");	
//			mortValue.focus();
//		}
		else if ((mortValue.value)*1 > (houseValue.value)*1)
		{
			alert("Mortgage amount can not be more than the property value ");
			mortValue.focus();
		}
		else if (((mortValue.value)*1 > (houseValue.value)*1*9/10) && (mortPurpose.value == 'Buy to Let'))
		{
			alert('Please note that the maximum amount you can borrow for a buy to let mortgage is 90% of the value of the property.  Please amend your details.');
			houseValue.focus();
		}
		else if (timescale.value == "0" )
		{
			alert("Please complete the time you need the mortgage");	
			timescale.focus();
		}
		else if ( !adverse_0.checked && !adverse_1.checked )
		{
			alert("Please select if you had any bad credit or CCJs");
		}
		else if (((mortValue.value)*1 == (houseValue.value)*1) && adverse_0.checked )
		{
			alert('Please note that the maximum amount you can borrow is 95% of the value of the property.  Please amend your details.');
			houseValue.focus();
		}
		else if (dayTeleNo.value == "")
		{
			alert("Please complete your daytime number to proceed");	
			dayTeleNo.focus();
		}
		else if (dayTeleNo.value.length<11)
		{
			alert("Please complete your daytime number correctly to proceed (must be 11 digits)");	
			dayTeleNo.focus();
		}
		else if (!CheckTelNo(dayTeleNo.value))
		{
			alert("Please enter your daytime number correctly to proceed");
			dayTeleNo.focus();
		}
		else if (nightTeleNo.value == "")
		{
			alert("Please complete your evening number to proceed");	
			nightTeleNo.focus();
		}
		else if (nightTeleNo.value.length<11)
		{
			alert("Please complete your evening number correctly to proceed (must be 11 digits)");	
			nightTeleNo.focus();
		}
		
		else if (!CheckTelNo(nightTeleNo.value))
		{
			alert("Please enter your evening number correctly to proceed");
			dayTeleNo.focus();
		}
		else if (!CheckTelNo(mobileNo.value))
		{
			alert("Please enter your mobile number correctly to proceed");
			dayTeleNo.focus();
		}
		else if ( day.value == "" || day.value.length < 1 || day.value > 31 || day.value < 1 || (day.value == 31 && (month.value==2 || month.value==4 || month.value==6 || month.value==9 || month.value==11)))
		{
			alert("Please complete your date of birth correctly to proceed");
			day.focus();
		}
		else if ( month.value == "" || month.value.length < 1 || month.value > 12 || month.value < 1)
		{
			alert("Please complete your date of birth correctly to proceed");
			month.focus();
		}
		else if ( year.value == "" || year.value.length <= 3 || year.value > 2000 || year.value < 1900 )
		{
			alert("Please complete your date of birth correctly to proceed");
			year.focus();
		}
		else if (email.value == "" )
		{
			alert("Please enter your email address");
			email.focus();
		}
		else if (!blnCheckEmail(email.value))
		{
			alert("Please enter a valid email address");
			email.focus();
		}
		else
		{
			return true;
		}
	}
	return false;
}

    
function InsuranceApply()
{
	var form = document.getElementById("applyfrm");
	with (form)
	{	
		
		if (Life_Cover_Amount.value == "")
		{
			alert("Please enter the cover amount");
			Life_Cover_Amount.focus();
		} 
		else if (Life_Cover_Term_Standard.value == "")
		{
			alert("Please enter the period of cover");
			Life_Cover_Term_Standard.focus();
		}  
		else if (Type_of_Lifecover_Premiums.value == "0")
		{
			alert("Please select the level of cover");
			Type_of_Lifecover_Premiums.focus();
		}
		else if (lifecover_Liability_repayment_mortgage.value == "0")
		{
			alert("Please select the type of premium");
			lifecover_Liability_repayment_mortgage.focus();
		} 
		else if (Title_First.value == "0")
		{
			alert("Please select your title");
			Title_First.focus();
		}
		else if (FullName_First.value == "" )
		{
			alert("Please complete your full name to proceed");	
			FullName_First.focus();
		}
		else if (Sex_First.value == "" )
		{
			alert("Please select your gender to proceed");	
			Sex_First.focus();
		}
		else if ( DOB_Day_First.value == "" || DOB_Day_First.value.length < 1 || DOB_Day_First.value > 31 || DOB_Day_First.value < 1 || (DOB_Day_First.value == 31 && (DOB_Month_First.value==2 || DOB_Month_First.value==4 || DOB_Month_First.value==6 || DOB_Month_First.value==9 || DOB_Month_First.value==11)))
		{
			alert("Please complete your date of birth correctly to proceed");
			DOB_Day_First.focus();
		}
		else if ( DOB_Month_First.value == "" || DOB_Month_First.value.length < 1 || DOB_Month_First.value > 12 || DOB_Month_First.value < 1)
		{
			alert("Please complete your date of birth correctly to proceed");
			DOB_Month_First.focus();
		}
		else if ( DOB_Year_First.value == "" || DOB_Year_First.value.length <= 3 || DOB_Year_First.value > 2000 || DOB_Year_First.value < 1900 )
		{
			alert("Please complete your date of birth correctly to proceed");
			DOB_Year_First.focus();
		}
		else if (dayTeleNo.value == "")
		{
			alert("Please complete your daytime number to proceed");	
			dayTeleNo.focus();
		}
		else if (dayTeleNo.value.length<11)
		{
			alert("Please complete your daytime number correctly to proceed (must be 11 digits)");	
			dayTeleNo.focus();
		}
		else if (!CheckTelNo(dayTeleNo.value))
		{
			alert("Please enter your daytime number correctly to proceed");
			dayTeleNo.focus();
		}
		 
		else if ((mobileNo.value.length>0) && (mobileNo.value.length<11))
		{
			alert("Please complete your mobile number correctly to proceed (must be 11 digits)");	
			mobileNo.focus();
		} 
		else if ((mobileNo.value.length>0) && (!CheckTelNo(mobileNo.value)) )
		{
			alert("Please enter your mobile number correctly to proceed");
			mobileNo.focus();
		}  
		else if (email.value == "" )
		{
			alert("Please enter your email address");
			email.focus();
		}
		else if (!blnCheckEmail(email.value))
		{
			alert("Please enter a valid email address");
			email.focus();
		}
		else if (second_person.checked)
		{
					if (Title_Second.value == "0")
					{
						alert("Please select the second person's title");
						Title_Second.focus();
					}
					else if (FullName_Second.value == "" )
					{
						alert("Please complete the second person's name to proceed");	
						FullName_Second.focus();
					}
					else if (Sex_Second.value == "" )
					{
						alert("Please select the second person's gender to proceed");	
						Sex_Second.focus();
					}
					else if ( DOB_Day_Second.value == "" || DOB_Day_Second.value.length < 1 || DOB_Day_Second.value > 31 || DOB_Day_Second.value < 1 || (DOB_Day_Second.value == 31 && (DOB_Month_Second.value==2 || DOB_Month_Second.value==4 || DOB_Month_Second.value==6 || DOB_Month_Second.value==9 || DOB_Month_Second.value==11)))
					{
						alert("Please complete the second person's date of birth correctly to proceed");
						DOB_Day_Second.focus();
					}
					else if ( DOB_Month_Second.value == "" || DOB_Month_Second.value.length < 1 || DOB_Month_Second.value > 12 || DOB_Month_Second.value < 1)
					{
						alert("Please complete the second person's date of birth correctly to proceed");
						DOB_Month_Second.focus();
					}
					else if ( DOB_Year_Second.value == "" || DOB_Year_Second.value.length <= 3 || DOB_Year_Second.value > 2000 || DOB_Year_Second.value < 1900 )
					{
						alert("Please complete the second person's date of birth correctly to proceed");
						DOB_Year_Second.focus();
					}
		} 
		else if (Smoker_First.value == "0")
		{
			alert("Please complete Smoked in last 12 months");
			Smoker_First.focus();
		}
		else if (Address.value == "" )
		{
			alert("Please complete your address to proceed"); 
			Address.focus();
		}
		else if (Town.value == "" )
		{
			alert("Please complete your town to proceed");	
		 	Town.focus();
		}
		else if (Postcode.value == "" )
		{
			alert("Please complete your postcode to proceed");	
		 	Postcode.focus();
		}   
		else
		{
			alert("this is true");	

			return true;
		}
	}
	return false;
}

function MortgageApplyNew()
{
	var form = document.getElementById("applyfrm");
	with (form)
	{
		if (mortApplyCtr21_title.value == "0")
		{
			alert("Please select your title");
			mortApplyCtr21_title.focus();
		}
		else if (mortApplyCtr21_fName.value == "" )
		{
			alert("Please complete your first name to proceed");	
			mortApplyCtr21_fName.focus();
		}
		else if (mortApplyCtr21_lName.value == "" )
		{
			alert("Please complete your surname to proceed");	
			mortApplyCtr21_lName.focus();
		}
		else if (mortApplyCtr21_streetName.value == "" )
		{
			alert("Please complete your address to proceed");	
			fillInAddNew();
		}
		else if (mortApplyCtr21_postTown.value == "" )
		{
			alert("Please complete your town to proceed");	
		}
		else if (mortApplyCtr21_postcode.value == "" )
		{
			alert("Please complete your postcode to proceed");	
		}
		else if (mortApplyCtr21_mortPurpose.value == "0")
		{
			alert("Please select the purpose of your mortgage");
			mortApplyCtr21_mortPurpose.focus();
		}
		else if (mortApplyCtr21_houseValue.value == "" )
		{
			alert("Please complete the value of property");	
			mortApplyCtr21_houseValue.focus();
		}
		else if (!isFinite(mortApplyCtr21_houseValue.value))
		{
			alert('property value is not correct');
			mortApplyCtr21_houseValue.focus();
		}
		else if (mortApplyCtr21_houseValue.value < 500 )
		{
			alert("property value must be at least 500 pounds");	
			mortApplyCtr21_houseValue.focus();
		}
		else if (mortApplyCtr21_houseValue.value == "" )
		{
			alert("Please complete the amount you want to borrow");	
			mortApplyCtr21_mortValue.focus();
		}
		else if (!isFinite(mortApplyCtr21_mortValue.value))
		{
			alert('Mortgage amount is not correct');
			mortApplyCtr21_mortValue.focus();
		}
		else if (mortApplyCtr21_mortValue.value < 500 )
		{
			alert("Mortgage amount must be at least 500 pounds");	
			mortApplyCtr21_mortValue.focus();
		}
		else if ((mortApplyCtr21_mortValue.value)*1 > (mortApplyCtr21_houseValue.value)*1)
		{
			alert("Mortgage amount can not be more than the property value");
			mortApplyCtr21_mortValue.focus();
		}
		else if (((mortApplyCtr21_mortValue.value)*1 > (mortApplyCtr21_houseValue.value)*1*9/10) && (mortApplyCtr21_mortPurpose.value == 'Buy to Let'))
		{
			alert('Please note that the maximum amount you can borrow for a buy to let mortgage is 90% of the value of the property.  Please amend your details.');
			mortApplyCtr21_houseValue.focus();
		}
		else if (mortApplyCtr21_timescale.value == "0" )
		{
			alert("Please complete the time you need the mortgage");	
			mortApplyCtr21_timescale.focus();
		}
		else if ( !mortApplyCtr21_adverse_0.checked && !mortApplyCtr21_adverse_1.checked )
		{
			alert("Please select if you had any bad credit or CCJs");
		}
		else if (((mortApplyCtr21_mortValue.value)*1 == (mortApplyCtr21_houseValue.value)*1) && mortApplyCtr21_adverse_0.checked )
		{
			alert('Please note that the maximum amount you can borrow is 95% of the value of the property.  Please amend your details.');
			mortApplyCtr21_houseValue.focus();
		}
		else if (mortApplyCtr21_dayTeleNo.value == "")
		{
			alert("Please complete your daytime number to proceed");	
			mortApplyCtr21_dayTeleNo.focus();
		}
		else if (mortApplyCtr21_dayTeleNo.value.length<11)
		{
			alert("Please complete your daytime number correctly to proceed (must be 11 digits)");
			mortApplyCtr21_dayTeleNo.focus();
		}
		else if (!CheckTelNo(mortApplyCtr21_dayTeleNo.value))
		{
			alert("Please enter your daytime number correctly to proceed");
			mortApplyCtr21_dayTeleNo.focus();
		}
		//else if (mortApplyCtr21_nightTeleNo.value == "")
		//{
		//	alert("Please complete your evening number to proceed");	
		//	mortApplyCtr21_nightTeleNo.focus();
		//}
		else if (mortApplyCtr21_nightTeleNo.value!=""&&mortApplyCtr21_nightTeleNo.value.length<11)
		{
			alert("Please complete your evening number correctly to proceed (must be 11 digits)");	
			mortApplyCtr21_nightTeleNo.focus();
		}
		else if (!CheckTelNo(mortApplyCtr21_nightTeleNo.value))
		{
			alert("Please enter your evening number correctly to proceed");
			mortApplyCtr21_nightTeleNo.focus();
		}
		else if (mortApplyCtr21_mobileNo.value == "")
		{
			alert("Please complete your mobile number to proceed");	
			mortApplyCtr21_mobileNo.focus();
		}
		else if (mortApplyCtr21_mobileNo.value.length<11)
		{
			alert("Please complete your mobile number correctly to proceed (must be 11 digits)");	
			mortApplyCtr21_mobileNo.focus();
		}
		else if (!CheckTelNo(mortApplyCtr21_mobileNo.value))
		{
			alert("Please enter your mobile number correctly to proceed");
			mortApplyCtr21_mobileNo.focus();
		}
		//else if ( mortApplyCtr21_day.value == "" || mortApplyCtr21_day.value.length < 1 || mortApplyCtr21_day.value > 31 || mortApplyCtr21_day.value < 1 || (mortApplyCtr21_day.value == 31 && (mortApplyCtr21_month.value==2 || mortApplyCtr21_month.value==4 || mortApplyCtr21_month.value==6 || mortApplyCtr21_month.value==9 || mortApplyCtr21_month.value==11)))
		//{
		//	alert("Please complete your date of birth correctly to proceed");
		//	mortApplyCtr21_day.focus();
		//}
		//else if ( mortApplyCtr21_month.value == "" || mortApplyCtr21_month.value.length < 1 || mortApplyCtr21_month.value > 12 || mortApplyCtr21_month.value < 1)
		//{
		//	alert("Please complete your date of birth correctly to proceed");
		//	mortApplyCtr21_month.focus();
		//}
		//else if ( mortApplyCtr21_year.value == "" || mortApplyCtr21_year.value.length <= 3 || mortApplyCtr21_year.value > 2000 || mortApplyCtr21_year.value < 1900 )
		//{
		//	alert("Please complete your date of birth correctly to proceed");
		//	mortApplyCtr21_year.focus();
		//}
		else if (mortApplyCtr21_email.value == "" )
		{
			alert("Please enter your email address");
			mortApplyCtr21_email.focus();
		}
		else if (!blnCheckEmail(mortApplyCtr21_email.value))
		{
			alert("Please enter a valid email address");
			mortApplyCtr21_email.focus();
		}
		else
		{
			return true;
		}
	}
	return false;
}

function MortgageApplyCtr()
{
	var form = document.getElementById("applyfrm");
	with (form)
	{
		if (mortApplyCtr21_title.value == "0")
		{
			alert("Please select your title");
			mortApplyCtr21_title.focus();
		}
		else if (mortApplyCtr21_fName.value == "" )
		{
			alert("Please complete your first name to proceed");
			mortApplyCtr21_fName.focus();
		}
		else if (mortApplyCtr21_lName.value == "" )
		{
			alert("Please complete your surname to proceed");
			mortApplyCtr21_lName.focus();
		}
		else if (mortApplyCtr21_streetName.value == "" )
		{
			alert("Please complete your address to proceed");
			fillInAdd();
		//	streetName.focus();
		}
		else if (mortApplyCtr21_postTown.value == "" )
		{
			alert("Please complete your town to proceed");
		//	postTown.focus();
		}
		else if (mortApplyCtr21_postcode.value == "" )
		{
			alert("Please complete your postcode to proceed");
		//	postcode.focus();
		}
		else if (mortApplyCtr21_mortPurpose.value == "0")
		{
			alert("Please select your purpose of mortgage");
			mortApplyCtr21_mortPurpose.focus();
		}
		else if (mortApplyCtr21_houseValue.value == "" )
		{
			alert("Please complete the value of property");	
			mortApplyCtr21_houseValue.focus();
		}
		else if (!isFinite(mortApplyCtr21_houseValue.value))
		{
			alert('property value is not correct');
			mortApplyCtr21_houseValue.focus();
		}
		else if (mortApplyCtr21_houseValue.value < 500 )
		{
			alert("property value must be at least 500 pounds");	
			mortApplyCtr21_houseValue.focus();
		}
		else if (mortApplyCtr21_mortValue.value == "" )
		{
			alert("Please complete the amount you want to borrow");	
			mortApplyCtr21_mortValue.focus();
		}
		else if (!isFinite(mortApplyCtr21_mortValue.value))
		{
			alert('Mortgage amount is not correct');
			mortApplyCtr21_mortValue.focus();
		}
		else if (mortApplyCtr21_mortValue.value < 500 )
		{
			alert("Mortgage amount must be at least 500 pounds");	
			mortApplyCtr21_mortValue.focus();
		}
//		else if (mortValue.value > 100000 )
//		{
//			alert("Mortgage amount can not be more than 100000 pounds");	
//			mortValue.focus();
//		}
		else if ((mortApplyCtr21_mortValue.value)*1 > (mortApplyCtr21_houseValue.value)*1)
		{
			alert("Mortgage amount can not be more than the property value ");
			mortApplyCtr21_mortValue.focus();
		}
		else if (((mortApplyCtr21_mortValue.value)*1 > (mortApplyCtr21_houseValue.value)*1*9/10) && (mortApplyCtr21_mortPurpose.value == 'Buy to Let'))
		{
			alert('Please note that the maximum amount you can borrow for a buy to let mortgage is 90% of the value of the property.  Please amend your details.');
			mortApplyCtr21_houseValue.focus();
		}
		else if (mortApplyCtr21_timescale.value == "0" )
		{
			alert("Please complete the time you need the mortgage");	
			mortApplyCtr21_timescale.focus();
		}
		else if ( !mortApplyCtr21_adverse_0.checked && !mortApplyCtr21_adverse_1.checked )
		{
			alert("Please select if you had any bad credit or CCJs");
		}
		else if (((mortApplyCtr21_mortValue.value)*1 == (mortApplyCtr21_houseValue.value)*1) && mortApplyCtr21_adverse_0.checked )
		{
			alert('Please note that the maximum amount you can borrow is 95% of the value of the property.  Please amend your details.');
			mortApplyCtr21_houseValue.focus();
		}
		else if (mortApplyCtr21_dayTeleNo.value == "")
		{
			alert("Please complete your daytime number to proceed");	
			mortApplyCtr21_dayTeleNo.focus();
		}
		else if (mortApplyCtr21_dayTeleNo.value.length<11)
		{
			alert("Please complete your daytime number correctly to proceed (must be 11 digits)");	
			mortApplyCtr21_dayTeleNo.focus();
		}
		else if (DuplicateChars(mortApplyCtr21_dayTeleNo.value))
		{
			alert("Please enter a valid daytime number to proceed");	
			mortApplyCtr21_dayTeleNo.focus();
		}
		else if (!CheckTelNo(mortApplyCtr21_dayTeleNo.value))
		{
			alert("Please enter your daytime number correctly to proceed");
			mortApplyCtr21_dayTeleNo.focus();
		}
		else if (mortApplyCtr21_mobileNo.value == "")
		{
			alert("Please complete your mobile number to proceed");	
			mortApplyCtr21_mobileNo.focus();
		}
		else if (mortApplyCtr21_mobileNo.value.length<11)
		{
			alert("Please complete your mobile number correctly to proceed (must be 11 digits)");	
			mortApplyCtr21_mobileNo.focus();
		}
		else if (DuplicateChars(mortApplyCtr21_mobileNo.value))
		{
			alert("Please enter a valid mobile number to proceed");	
			mortApplyCtr21_mobileNo.focus();
		}		
		else if (!CheckTelNo(mortApplyCtr21_mobileNo.value))
		{
			alert("Please enter your mobile number correctly to proceed");
			mortApplyCtr21_mobileNo.focus();
		}
//		else if ( mortApplyCtr21_day.value == "" || mortApplyCtr21_day.value.length < 1 || mortApplyCtr21_day.value > 31 || mortApplyCtr21_day.value < 1 || (mortApplyCtr21_day.value == 31 && (mortApplyCtr21_month.value==2 || mortApplyCtr21_month.value==4 || mortApplyCtr21_month.value==6 || mortApplyCtr21_month.value==9 || mortApplyCtr21_month.value==11)))
//		{
//			alert("Please complete your date of birth correctly to proceed");
//			mortApplyCtr21_day.focus();
//		}
//		else if ( mortApplyCtr21_month.value == "" || mortApplyCtr21_month.value.length < 1 || mortApplyCtr21_month.value > 12 || mortApplyCtr21_month.value < 1)
//		{
//			alert("Please complete your date of birth correctly to proceed");
//			mortApplyCtr21_month.focus();
//		}
//		else if ( mortApplyCtr21_year.value == "" || mortApplyCtr21_year.value.length <= 3 || mortApplyCtr21_year.value > 2000 || mortApplyCtr21_year.value < 1900 )
//		{
//			alert("Please complete your date of birth correctly to proceed");
//			mortApplyCtr21_year.focus();
//		}
		else if (mortApplyCtr21_email.value == "" )
		{
			alert("Please enter your email address");
			mortApplyCtr21_email.focus();
		}
		else if (!blnCheckEmail(mortApplyCtr21_email.value))
		{
			alert("Please enter a valid email address");
			mortApplyCtr21_email.focus();
		}
		else
		{
			return true;
		}
	}
	return false;
}

function _gel(a)
{
	return document.getElementById(a)
}

function calcDate() 
{
	var f = document.getElementById("applyfrm");
	if (f) {                              
		var mm = parseInt(f["month"].value, 10);
		var dd = parseInt(f["day"].value, 10);
		var yy = parseInt(f["year"].value, 10);
		f["fullDate"].value = dd + "/" + mm + "/" + yy;
	}
}

function onlyNumeric()
{
	if ((event.keyCode < 48) || (event.keyCode > 57)) event.returnValue = false;			
}

function monthOnKeyUp(objTxtSortCode, intPart) 
{
	var intValue = objTxtSortCode.value;
	if (intValue&&intValue.length==2) {
		_gel(intPart).focus();
		if(intPart.indexOf("_year")>=0||intPart.indexOf("year")>=0)
			_gel(intPart).value="19";
	}
}
		
function yearOnKeyUp(objTxtAccNum, intPart) 
{
	var intValue = objTxtAccNum.value;
	if (intValue&&intValue.length==4) {	
		_gel(intPart).focus();
	}
}

function addDisplay()
{
	_gel("PanelAddLine").className="addbox_start";
	_gel("PanelAdd").className="addbox_after";
	return false;
}

function addDisplayCtr()
{
	MortApplyCtr1_PanelAddLine.className="addbox_start";
	MortApplyCtr1_PanelAdd.className="addbox_after";
	return false;
}

function addDisplayCtr2()
{
	mortApplyCtr21_PanelAddLine.className="addbox_start";
	mortApplyCtr21_PanelAdd.className="addbox_after";
	return false;
}

function fillInAdd()
{
	if(_gel("PanelAdd").className=="addbox_start")
	{
		_gel("PanelAddLine").className="addbox_start";
		_gel("PanelAdd").className="addbox_after";
	}
}
function fillInAddNew()
{
	if(_gel("mortApplyCtr21_").className=="addbox_start")
	{
		_gel("mortApplyCtr21_PanelAddLine").className="addbox_start";
		_gel("mortApplyCtr21_PanelAdd").className="addbox_after";
	}
}

function onlyAlphabetic()
{
	//	if ((event.keyCode < 48) || (event.keyCode > 57)) event.returnValue = true;
	if ((event.keyCode == 32) || (event.keyCode>64 && event.keyCode<91) || (event.keyCode>96 && event.keyCode<123)) event.returnValue = true;
	else event.returnValue = false;
}

function onlyTel()
{
	if (!((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32)) event.returnValue = true;
	else event.returnValue = false;
}

function checkRefineSearch() // for button tag
{
	var form = document.forms[0]; // for button tag
	if (form.houseValue.value == "" )
	{
		alert("Please enter property value");	
		form.houseValue.focus();
		return false;
	}
	else if (form.houseValue.value < 500 )
	{
		alert("property value must be at least 500 pounds");	
		form.houseValue.focus();
		return false;
	}
	else if (form.mortAmt.value == "" )
	{
		alert("Please enter the amount you want to borrow");	
		form.mortAmt.focus();
		return false;
	}
	else if (form.mortAmt.value < 500 )
	{
		alert("Mortgage amount must be at least 500 pounds");	
		form.mortAmt.focus();
		return false;
	}
	else if ((form.mortAmt.value)*1 > (form.houseValue.value)*1)
	{
		alert("Mortgage amount can not be more than the property value ");
		form.mortAmt.focus();
		return false;
	}
	else return true;
}

//-----------------------------------
function DuplicateChars(strString)
{
	var IsDuplicate = true;
	var strvalue = "";
	
	if (strString.length>0)
	{
		for (var k = 0; k < strString.length; k++)
		{
			if (k == 0)	
			{
				strvalue = strString.charAt(0);
			}
			else
			{
				if (strString.charAt(k) != strvalue)
				{
					IsDuplicate = false;
					break;
				}
			}
		}
	}
	
	return IsDuplicate;
}


function CheckTelNo(pstrTelNo)
{
	pstrTelNo = Trim(pstrTelNo);
	if (pstrTelNo.length >= 4)
	{
		if (pstrTelNo.substring(0, 4) == "0704")
			return false;
		else
			return true;
	}
	else
	{
		return true;
	}
}

//-->