// JavaScript Document

////// SHORT APPLICATION FORM VALIDATION STARTS HERE //////

function isEmail(string)  // VALIDATE THE EMAIL
{
if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
else
	return false;
}
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function validateshortform()
{

 if(document.applynow.UK.checked==false && document.applynow.USA.checked==false)
 {
 	 alert("Please select Country");
	 document.applynow.UK.focus();
	 return false;
 }

 if(document.applynow.status.value=="")
 {
 	 alert("Please select your Status");
	 document.applynow.status.focus();
	 return false;
 }
 if(document.applynow.firstname.value=="")
 {
 	 alert("Please fill your First Name");
	 document.applynow.firstname.focus();
	 return false;
 }
 if(document.applynow.lastname.value=="")
 {
 	 alert("Please fill your Last Name");
	 document.applynow.lastname.focus();
	 return false;
 }
 if(document.applynow.day.value=="")
 {
 	 alert("Please select your Day of Birth");
	 document.applynow.day.focus();
	 return false;
 }
 if(document.applynow.month.value=="")
 {
 	 alert("Please select your Month of Birth");
	 document.applynow.month.focus();
	 return false;
 }
 if(document.applynow.year.value=="")
 {
 	 alert("Please select your Year of Birth");
	 document.applynow.year.focus();
	 return false;
 }  
 
  if(document.applynow.homephone.value=="")
 {
 	 alert("Please fill your home phone number");
	 document.applynow.homephone.focus();
	 return false;
 }
 else if (IsNumeric(document.applynow.homephone.value) == false) 
      {
      alert("Please fill numeric value in home phone !");
	  document.applynow.homephone.focus();
		  return false;
      }
  if(document.applynow.mobilephone.value=="")
 {
 	 alert("Please fill your mobile number");
	 document.applynow.mobilephone.focus();
	 return false;
 }
 else if (IsNumeric(document.applynow.mobilephone.value) == false) 
      {
      alert("Please fill numeric value in mobile phone !");
	  document.applynow.mobilephone.focus();
		  return false;
      }
 if(!isEmail(document.applynow.email.value))
	  {
	  	alert("Please fill a valid email ");
		document.applynow.email.focus();
		  return false;
	  }
 if(document.applynow.address.value=="")
 {
 	 alert("Please fill your Address");
	 document.applynow.address.focus();
	 return false;
 }
 if(document.applynow.postalcode.value=="")
 {
 	 alert("Please fill your Postcode");
	 document.applynow.postalcode.focus();
	 return false;
 }
 if(document.applynow.loanpurpose.value=="")
 {
 	 alert("Please select your Loan Purpose");
	 document.applynow.loanpurpose.focus();
	 return false;
 }
 if(document.applynow.loanamount.value=="")
 {
 	 alert("Please fill your Loan Amount");
	 document.applynow.loanamount.focus();
	 return false;
 } 
 if(document.applynow.agreed.checked=="")
 {
 	 alert("Please check the DPA declaration");
	 document.applynow.loanpurpose.focus();
	 return false;
 } 



var s = document.applynow.elements['txt_interested[]'];
flag = 0;
for (var i = 0; i < s.length; i++) {
if (s[i].selected) 
if(s[i].value != '') {
flag = 1;
}
}
if(flag == 1)
	return true;
else {
alert("Please select at least one Interest");
return false;
}
}

////// SHORT APPLICATION FORM VALIDATION STARTS HERE //////





////// APPLICATION FORM VALIDATION STARTS HERE //////

function reset() {
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function validRequired(formField,fieldLabel)
{
	var result = true;

	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}

	return result;
}
function validChecked(formField,fieldLabel)
{
	var result = true;

	if (formField.checked == false)
	{
		alert('Please Select "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}

	return result;
}



function validateForm(theForm)
{

	if (!validRequired(theForm.status,"Status",true))
		return false;
	
	if (!validRequired(theForm.firstname,"First Name",true))
		return false;

	if (!validRequired(theForm.lastname,"Last Name",true))
		return false;

	if (!validRequired(theForm.day,"Day"))
		return false;

	if (!validRequired(theForm.month,"month",true))
		return false;
		
	if (!validRequired(theForm.year,"Year",true))
		return false;
	
	if (!validRequired(theForm.homephone,"Home phone Number",true))
		return false;
	
	if (!validRequired(theForm.mobilephone,"Mobile Phone Number",true))
		return false;
		
	if (!validRequired(theForm.email,"Email",true))
		return false;
		
			if (echeck(theForm.email.value)==false)
			{
				theForm.email.value=""
				theForm.email.focus()
				return false;
			}
			
		if (!validRequired(theForm.address,"Address",true))
		return false;
		
		if (!validRequired(theForm.postalcode,"Postal code",true))
		return false;
		
		if (!validRequired(theForm.employmentstatus,"Employment Status",true))
		return false;
		
		if (!validRequired(theForm.employersname,"Employers Name",true))
		return false;
		
		if (!validRequired(theForm.workphone,"Work Phone Number",true))
		return false;
		
		if (!validRequired(theForm.monthlyincome,"Monthly Income",true))
		return false;
		
		if (!validRequired(theForm.loanpurpose,"Loan Purpose",true))
		return false;
		
		if (!validRequired(theForm.loanamount,"Loan Amount",true))
		return false;
		
		if (!validChecked(theForm.agreed,"Terms and Conditions",true))
		return false;
		
		if (!validRequired(theForm.security_code,"Verification",true))
		return false;
			
		
	return true;
}

////// APPLICATION FORM VALIDATION STARTS HERE //////




////// CONTACT US FORM VALIDATION STARTS HERE //////

function isEmail(string)  // VALIDATE THE EMAIL
{
if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
else
	return false;
}
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function validatecontact()
{
 if(document.contactform.name.value=="")
 {
 	 alert("Please fill your name");
	 document.contactform.name.focus();
	 return false;
 }

if(document.contactform.telephone.value=="")
 {
 	 alert("Please fill Telephone Number");
	 document.contactform.telephone.focus();
	 return false;
 }
 else if (IsNumeric(document.contactform.telephone.value) == false) 
      {
      alert("Please fill numeric value in Telephone !");
	  document.contactform.telephone.focus();
		  return false;
      }

 if(!isEmail(document.contactform.email.value))
	  {
	  	alert("Please fill a valid Email ");
		document.contactform.email.focus();
		  return false;
	  }

 if(document.contactform.enquiry.value=="")
 {
 	 alert("Please fill your queries");
	 document.contactform.enquiry.focus();
	 return false;
 }

}

////// CONTACT US FORM VALIDATION ENDS HERE //////
