


function fnchekbox(chekbox, mes)
	{
      frm=document.frmIndex.dprotect;
	  checked =frm.checked;
      if (!checked)
	   {
       alert(mes);
	   return true;
	   }
	   else
	   {
	    return false;
	   }
  
}
joint="no";
var dge=document.getElementById;
function cl_colall(a){
  if(!dge)return;
  document.getElementById(a)
    document.getElementById(a).style.display='none';
}
function cl_expcol(a){
  if(!dge)return;
    document.getElementById(a).style.display = 
      (document.getElementById(a).style.display=='none')?
      'block':'none';
}


function go1(vall)
{
stat=vall
//alert(stat)
if (stat=="yes")
 {cl_expcol('jointmarried')}
//alert(val)
//alert("MarStat"+val)
}


function funHideControl()
{		
 	window.divGroup.style.display =  "none";		
}		
function GetPurpose()
{
	mem=document.frmIndex.LoanPurpose;
	for(var i=0; i<mem.length; i++)
	  { if (mem.options[i].selected) 	
			{ 	
			  if(mem.options[i].value=="Other")
			  {
			  	document.getElementById('divGroup').style.display=''
				//window.divGroup.style.display ="";	
				//alert("Please Enter Other Loan Purpose")
				document.frmIndex.OtherPurpose.focus();
			  }		
			  else
			  {
			  
			    document.getElementById('divGroup').style.display='none';
			  // window.divGroup.style.display ="none";	
			  }
			}
	 }	
}


   //----------------------------
   //Allow Numbers only to enter

function fnNumberOnly(txtfld, mes)
{
	var Num="0123456789";
	var txtString= fnTrim(txtfld.value)
	for(var i=0; i < txtString.length; i++)
	{
	if(Num.indexOf(txtString.charAt(i))== -1)
	{	
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	return false;
	}
			
}
function checkDay1()
{
	frm=document.frmIndex;
	if(frm.cmbDay1.value<1 || frm.cmbDay1.value>31)
	{
		alert("Day should be In between 1 and 31")
		frm.cmbDay1.select();
		return true;
	}
	return false;
}


function checkYear1(){
	frm=document.frmIndex;
	if(frm.cmbYear1.value<1920 || frm.cmbYear1.value>2000){
		alert("Year should be In between 1920 and 2000")
		frm.cmbYear1.select();
		return true;
	}
	return false;
	}

function checkMonth1(){
	frm=document.frmIndex;
	if(frm.cmbMonth1.value<1 || frm.cmbMonth1.value>12){
		alert("Month should be In between 1 and 12")
		frm.cmbMonth1.select();
		return true;
	}
	return false;
}

function fnJoint(chekbox, mes)
{

	 var a=0;
	 for (var i = 0; i<chekbox.length; i++)
	  {
      checked =chekbox[i].checked;
      if (checked)
	   {
         val=chekbox[i].value;
		 a=a+1;
		 if (val=="yes")
		 {
			if(fnIsNull(frm.B2_FirstName,"Please enter Joint applicant Name"))
			   return true;
			else if(fnIsValidChar1(frm.B2_FirstName,"Joint applicant Name is not valid "))
			   return true;
			else if(fnIsNull(frm.cmbDay1,"Please Enter Joint applicant day of Birth"))
				return true;	
			else if(AllowNumeric(frm.cmbDay1,"Please Provide us a valid Date"))
					return true;	
			else if(checkDay1())		
					return true;			
			else if(fnIsNull(frm.cmbMonth1,"Please Enter Joint applicant month of Birth"))
					return true;	
			else if(AllowNumeric(frm.cmbMonth1,"Please Provide us a valid Date"))
					return true;	
			else if(checkMonth1())		
					return true;					
			else if(fnIsNull(frm.cmbYear1,"Please Enter Joint applicant year of Birth"))
					return true;	
			else if(AllowNumeric(frm.cmbYear,"Please Provide us a valid Date"))
					return true;	
			else if(checkYear1())		
					return true;				
				 
		 }
	   }
	   }


	   if(a>0)
	   {
	 return false;
	   }
	    else
		 {
	   alert(mes);
	   return true;
	    }

}

function emailcheck(txtfld, mes)
{
var str;
var string1=txtfld.value;
 str = "";
if (string1.indexOf("@")==-1){
	str = "NO";}
else if (string1.indexOf("@")==0){
	str = "NO";}
else if (string1.indexOf(".")==-1){
	str = "NO";}
else if (string1.indexOf(".")==0){
	str = "NO";}
else if (string1.indexOf("@") + 1 == string1.indexOf(".")){
	str = "NO";}
else if (string1.indexOf("@") + 1== string1.length){
	str = "NO";}
else if(string1.lastIndexOf(".") + 1== string1.length){
	str = "NO";}
else if(string1.indexOf("@") != string1.lastIndexOf("@")){
	str = "NO";}

else{
	str = "YES";}

if (str=="NO"){	
	alert(mes);
	txtfld.select();
	txtfld.focus();
	return true;
	}
	else{
		return false;}
}





//..............................................................................
//To check for special characters.

function fnIsValidChar2(txtfld, mes)
{
	spChar = "`~!@#$%^&*()_-+=|\\}}{{\"' :;<>?/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ£";
	var txtString= fnTrim(txtfld.value);
	for(var i=0; i<txtString.length; i++)
	{
	if(spChar.indexOf(txtString.charAt(i))!= -1)
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	}
	return false;
		
}
//check atleast one rediobutton box

function fnchekrdiobutton(chekbox, mes){
	
	 var a=1;
	 for (var i = 0; i<chekbox.length; i++)
	  {
      checked =chekbox[i].checked;
      if (checked)
	   {
       a=a+1;
	   }
	   }


	   if(a>1)
	   {
	 return false;
	   }
	    else
		 {
	   alert(mes);
	   return true;
	    }

}

//----------------------------------------------------------------------------------------------
//To check single and double quotes.

function fnIsQuotes(txtfld, mes){
	var a_strString = fnTrim(txtfld.value)
	if(a_strString.indexOf('"') != -1)
	  {
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	if(a_strString.indexOf("'") != -1)
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	
	return false
}


function checkDay()
{
	frm=document.frmIndex;
	if(frm.cmbDay.value<1 || frm.cmbDay.value>31)
	{
		alert("Day should be In between 1 and 31")
		frm.cmbDay.select();
		return true;
	}
	return false;
}

function checkMonth(){
	frm=document.frmIndex;
	if(frm.cmbMonth.value<1 || frm.cmbMonth.value>12){
		alert("Month should be In between 1 and 12")
		frm.cmbMonth.select();
		return true;
	}
	return false;
}


function checkYear(){
	frm=document.frmIndex;
	if(frm.cmbYear.value<1920 || frm.cmbYear.value>2000){
		alert("Year should be In between 1920 and 2000")
		frm.cmbYear.select();
		return true;
	}
	return false;
	}

//chech whether its numeric or not
function AllowNumeric(textfield, msg)
{
var val=textfield.value;
	if (val.length>0){
		var charBag = '<>/?;:"~`!#$%^&*()=+\|[]{}abcdefghijklmnopqrstuvwxyz';
		//loop for not allowed special chars
		for (j=0;j<charBag.length; j++){
			if (val.indexOf(charBag.charAt(j))==0){
				alert(msg);
				textfield.focus();
				textfield.select();
				return true;
			}
		}
	}
	return false;
}

//To check for special characters.

function fnIsValidChar1(txtfld, mes)
{
	spChar = "`~!@#$%^&*()_-+=|\\}}{{\"':;<,>.?/123456789";
	var txtString= fnTrim(txtfld.value);
	for(var i=0; i<txtString.length; i++)
	{
	if(spChar.indexOf(txtString.charAt(i))!= -1)
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	}
	return false;
		
}

// Checks if the input string is null or blanks

function fnIsNull(txtfld, mes)
{
	   var string=txtfld.value;
       if (fnTrim(string) == null || fnTrim(string) == "" )
       {
	   	alert(mes);
		txtfld.focus();
		txtfld.select();
     	return true;
       }
		return false;
}

function fnIsNull_nofocus(txtfld, mes)
{
	   var string=txtfld.value;
       if (fnTrim(string) == null || fnTrim(string) == "" )
       {
	   	alert(mes);
		return true;
       }
		return false;
}


// Trims the input string of leading and trailing spaces and returns the new string

function fnTrim(string)
{
	var cnt;	
	len = string.length;
	str = string;
	begin = -1;
	for(cnt=0;cnt<len;cnt++)
	{
		if (str.charAt(cnt) == " ")
		{	
			begin = cnt;
		}	
		else
		break;
		
	}
	str = str.slice(begin+1,len);
	len = str.length;
	end = len;
	for(cnt=len-1;cnt>=0;cnt--)
	{
		if (str.charAt(cnt) == " ")
		{	
			end = cnt;
		}	
		else
		break;
	}
	str = str.slice(0,end);
	return str;
}

//-------------------------------------
function dropDownMenu(menu, mes) 
   {
   var myindex=menu.selectedIndex;
   if (myindex==0)
      {
      alert(mes);
      menu.focus();
	  return true;
	  }
	else 
		{
		return false;
		}
   }

function checkMonths(){
	frm=document.frmIndex;
	if(frm.hlMonths.value>12){
		alert("Months should not be more than 12")
		frm.hlMonths.select();
		return true;
	}
	return false;
}

function fnvalidate() {
		frm=document.frmIndex;
	if(dropDownMenu(frm.AmtRequired,"Please Select the Loan Amount"))
		return false;		
	else if(dropDownMenu(frm.LoanPurpose,"Please Select the purpose of loan"))		
		return false;	
	else if((frm.LoanPurpose.value=="Other")&&(fnTrim(frm.OtherPurpose.value) == null || fnTrim(frm.OtherPurpose.value) == "" ))
		{
			alert("Please enter Purpose");
			
			 return false;
	  	  	//if(fnIsNull_nofocus(frm.OtherPurpose,"Please enter Reason for other purpose"))
	   }
	else if(fnIsNull(frm.FirstName,"Please enter your first name"))
		return false;
	else if(fnIsValidChar1(frm.FirstName,"First name is not valid name"))
		return false;
	//else if(fnIsValidChar1(frm.MiddleName,"Middle name is not a valid name"))
		//return false;	
	else if(fnIsNull(frm.LastName,"Please enter your last name"))
		return false;
	else if(fnIsValidChar1(frm.LastName,"Last name is not a valid name"))
		return false;
	else if(fnIsNull(frm.cmbDay,"Please Enter your day of Birth"))
		return false;	
	else if(AllowNumeric(frm.cmbDay,"Please Provide us a valid Date"))
			return false;	
	else if(checkDay())		
			return false;			
	else if(fnIsNull(frm.cmbMonth,"Please Enter your month of Birth"))
			return false;	
	else if(AllowNumeric(frm.cmbMonth,"Please Provide us a valid Date"))
			return false;	
	else if(checkMonth())		
			return false;					
	else if(fnIsNull(frm.cmbYear,"Please Enter your year of Birth"))
			return false;	
	else if(AllowNumeric(frm.cmbYear,"Please Provide us a valid Date"))
			return false;	
	else if(checkYear())		
			return false;	
	else if(dropDownMenu(frm.FmpStatus,"Please enter your employment status"))
		return false;
	else if(fnIsNull(frm.Postcode,"Please enter your Postcode"))
		return false;
	else if(fnIsQuotes(frm.Postcode,"Postcode is not valid"))
		return false;		
	else if(fnIsNull(frm.a_address1,"Please Enter the House number and Street"))
		return false;
	else if(fnIsQuotes(frm.a_address1,"Please Enter the House number and Street"))
		return false;
	else if(fnIsNull(frm.hlYears,"Please enter Years"))
		return false;		
	else if(AllowNumeric(frm.hlYears,"Please enter valid years at Address"))
		return false;	
	else if(fnIsQuotes(frm.hlYears,"Please enter valid years at Address"))
		return false;
		
	else if(fnIsNull(frm.hlMonths,"Please enter months at Address"))
		return false;	
    else if(checkMonths())
		return false;
	else if(AllowNumeric(frm.hlMonths,"Please enter valid Months"))
		return false;
	else if(fnIsQuotes(frm.hlMonths,"Please enter valid Months"))
		return false;			
	else if(fnIsNull(frm.Telephone,"Please Provide us your Telephone number"))
		return false;
	else if(AllowNumeric(frm.Telephone,"Phone number not valid"))
		return false;		
	else if(fnIsValidChar2(frm.Telephone,"Phone number not valid"))
		return false;		
	else if(fnIsNull(frm.mnumber,"Please Provide us your Mobile number"))
		return false;	
	else if(AllowNumeric(frm.mnumber,"Please enter your mobile number"))
		return false;
	else if(fnIsValidChar2(frm.mnumber,"Mobile number is not valid"))
		return false;	
	else if(fnIsNull(frm.Email,"Please provide us a valid Email"))
		return false;	
	else if(fnIsQuotes(frm.Email,"Please provide us a valid Email"))
		return false;				
	else if(emailcheck(frm.Email,"Please provide us a valid Email"))
		return false;
	else if(dropDownMenu(frm.besttime,"Please Select the Best time to contact you"))
		return false;	
	else if(fnchekrdiobutton(frm.hometype, "Please Provide us your Homeowner Type"))
   		 return false;	
	else if(fnJoint(frm.jointApp, "Please Provide us is it Joint Application?"))
   		 return false;		
	else if(fnIsNull(frm.houseworth,"Please enter your houseworth"))
		return false;
	else if(fnNumberOnly(frm.houseworth,"Amount not Valid"))
		return false;	
	else if(fnIsNull(frm.mortage,"Please enter your mortage"))
		return false;
	else if(fnNumberOnly(frm.mortage,"Amount not Valid"))
		return false;	
	else if(fnIsValidChar2(frm.mortage,"Amount not Valid"))
		return false;		
	else if(fnchekbox(frm.dprotect, "Please Check the data protection notice "))
		return false;	
	
}



 var IE = document.all? true : false;

var tnt=0
IE4 = document.forms['frmIndex'];
function fn_tenant()
{   tnt=tnt+1;
 formContents="?se=http://www.cheap-car-loan-uk.co.uk"
 t=newConfirm("Loan Confirmation","Based on the information provided by you, the right solution for you would be a debt management ??",1,1,0)
 if(t) 
 { for(i=0; i<IE4.length; i++)
  {
     if(IE4[i].name!=null && IE4[i].value!=null)
     formContents=formContents+"&"+IE4[i].name+"="+IE4[i].value
  }
  location.href="http://www.www-debtmanagement.co.uk"+formContents 
 }  
}
function newConfirm(title,mess,icon,defbut,mods)
{   if (IE) {
      icon = (icon==0) ? 0 : 2;
      defbut = (defbut==0) ? 0 : 1;
      retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
      retVal = (retVal==6);
   }
   else {
      retVal = confirm(mess);
   }
   return retVal;
}


var referingtest;
referingtest= document.referrer;
document.frmIndex.teting.value=referingtest;