String.prototype.Trim=
                 new Function("return this.replace(/^\\s+|\\s+$/g,'')"); 

function swichFields (aValue) {	
	if (aValue == 1)	{
		slidedown('applicant_2');
	} else {
		slideup('applicant_2');
	}
}

function getRadioValue()
{
for (var i=0; i < document.quick_apply_form.joint_application.length; i++)
   {
	//alert(document.quick_apply_form.joint_application[i].checked);
   if (document.quick_apply_form.joint_application[i].checked)
      {

      return document.quick_apply_form.joint_application[i].value;
      }
   }
   return 0;
}
function checkDublin(val){
	if(val == "Dublin City"){
		document.getElementById("dublin_c").style.display="block";
		
	}
	else
	{
		document.getElementById("dublin_c").style.display="none";
		
	}
		
}

function validEmail(addr){
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=addr.match(emailPat)
	
	if (matchArray==null) {
		//alert("Please enter a valid email address (check @ and .'s)")
		return false
	}
	
	var user=matchArray[1]
	var domain=matchArray[2]
	
	if (user.match(userPat)==null) {
		//alert("The username doesn't seem to be valid.")
		return false
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!")
				return false
			}
		}
		return true
	}
	
	var domainArray=domain.match(domainPat)
	
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
		return false
	}
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		//alert("The address must end in a three-letter domain, or two letter country.")
		return false
	}
	if (len<2) {
		//alert("This address is missing a hostname!")
		return false
	}
	return true;
} 

function sendForm() {
	var send = true;
	emessage=" Please Fill the  Following  Fileds :\n------------------------------------------------\n";
	if (document.quick_apply_form.name_1.value.Trim() == '' || document.quick_apply_form.lname_1.value.Trim() == '' || 
			document.quick_apply_form.phone_1.value.Trim() == '' || 		document.quick_apply_form.interested.value.Trim() == '0' || 	
			document.quick_apply_form.mobile_1.value.Trim() == '' || 
			document.quick_apply_form.loan_amount.value.Trim() == '' || 
			document.quick_apply_form.prop_value.value.Trim() == '' || 
			document.quick_apply_form.outstanding_loans.value.Trim() == '' || 

			validEmail(document.quick_apply_form.email_1.value) == false || document.quick_apply_form.at__at__sbv__HeardAboutIMC.selectedIndex==0 ||  (document.quick_apply_form.at__at__sbv__HeardAboutIMC.selectedIndex==20 && document.quick_apply_form.at__at__HeardAboutIMCOther.value.trim()=='' )){

		
					if (document.quick_apply_form.interested.value.Trim() == '0')
					emessage +=" -- Enter In which You are Interested \n";
				if (document.quick_apply_form.name_1.value.Trim() == '')
					emessage +=" -- Enter Applicant First Name\n";

				if (document.quick_apply_form.lname_1.value.Trim() == '')
					emessage +=" -- Enter Applicant Last Name\n";
					
				if (document.quick_apply_form.phone_1.value.Trim() == '')
					emessage +=" -- Enter Phone Number\n";
					if (document.quick_apply_form.phone_1.value.Trim() != '' && document.quick_apply_form.phone_1.value.length >0  )
					{
				if (!checkphone(document.quick_apply_form.phone_1.value))
					emessage +=" -- Enter Valid Phone Number\n";
					}
				if (document.quick_apply_form.mobile_1.value.Trim() == '')
					emessage +=" -- Enter Mobile Number\n";
				if (document.quick_apply_form.loan_amount.value.Trim() == '')
					emessage +=" -- Enter Loan Amount \n";
				if (document.quick_apply_form.prop_value.value.Trim() == '')
					emessage +=" -- Enter Property Value\n";
				if (document.quick_apply_form.outstanding_loans.value.Trim() == '')
					emessage +=" -- Enter Outstanding Loan Amount\n";
				if (validEmail(document.quick_apply_form.email_1.value) == false)
					emessage +=" -- Enter Valid E-mail Address \n";
					if (document.quick_apply_form.at__at__sbv__HeardAboutIMC.selectedIndex==0)
					emessage +=" -- Please Provide us where did you heard from \n";
					
					if (document.quick_apply_form.cAddress.selectedIndex==0)
					emessage +=" -- Enter Your Address \n";
if 	(document.quick_apply_form.cAddress.selectedIndex==1 && document.quick_apply_form.cPost.value.Trim()=='' )
{
				emessage +=" -- Enter Post Code\n ";
}


		send = false;

	}
	if (getRadioValue() == 1) {

		if (document.quick_apply_form.name_2.value.Trim() == '' ||  document.quick_apply_form.lname_2.value.Trim() == '' || 
				document.quick_apply_form.phone_2.value.Trim() == '' || 				
				document.quick_apply_form.mobile_2.value.Trim() == '' || 
				validEmail(document.quick_apply_form.email_2.value) == false){

				if (document.quick_apply_form.name_2.value.Trim() == '')
						emessage +=" -- Enter Second  Applicant First Name\n";
						if (document.quick_apply_form.lname_2.value.Trim() == '')
						emessage +=" -- Enter Second  Applicant Last Name\n";
					if (document.quick_apply_form.phone_2.value.Trim() == '')
						emessage +=" -- Enter Second  Applicant Phone Number\n";
					if (document.quick_apply_form.mobile_2.value.Trim() == '')
						emessage +=" -- Enter Second  Applicant Mobile Number\n";
					if (validEmail(document.quick_apply_form.email_2.value) == false)
						emessage +=" -- Enter Second  Applicant Valid E-mail Address\n";
			send = false;

		}
		
	} else {
		document.quick_apply_form.name_2.value =  '';
		document.quick_apply_form.phone_2.value =  '';				
		document.quick_apply_form.mobile_2.value =  '';
		document.quick_apply_form.email_2.value = '';
	}
var  pv = document.quick_apply_form.prop_value.value.Trim();
var la= document.quick_apply_form.loan_amount.value.Trim();

if  (la>pv )
emessage +=" -- Loan amount cannot be  greater than Property value\n";


	if (send == false) {
		//alert('Please fill all fields');
		alert(emessage);
		emessage="";
	} else {
		emessage="";
		document.quick_apply_form.submit();
	}
	return send;

}


function checkoth(va)
{
 if  (va==20 )
 document.getElementById("otherhead").style.display="block";
 else
 document.getElementById("otherhead").style.display="none";
 
}


function checkphone(fld,mes)
{
	var x = fld;
	var filter  = /^\d{7,11}$/;
	if (!filter.test(x)) 
	return false;
	else
	return true;
	
	
	
}
