// JavaScript Document

function goToSecuredLoans(){	
  page = "http://loanapplication.relaxfinance.co.uk/?ssc=904";
  window.open(page, "win1","location=no,menubar=no,status=yes,resizable=yes,width=795,height=720,left=0,top=0,scrollbars=yes");
}

function addLink(){  
  page = "http://www.bluestarfinance.co.uk/resources/form.html";
    window.open(page, "win1","location=yes,menubar=yes,status=yes,toolbar=yes,resizable=yes,width=500,height=500,left=0,top=0,scrollbars=yes");    
}


function checkBlankField (txt)

			{

			var mint_txt = txt.length;

			var mstr_txt = txt;

			var mint_count = 0;

		    for (var iloop = 0; iloop<mint_txt; iloop++)

		    {

				        if (mstr_txt.charAt(iloop) == " ")

				        {

				           mint_count = mint_count+1;

				        }

			}

// if nothing entered in the field

   	 				if (txt == "")

   	 				{

					return false;

				    }

				    	 else if (mint_count == mint_txt)

				    	{

						return false;

						}

				return true;

				}



		function valid_email(eml)

			{

				//declare the required variables

				var mint_len;

				var mstr_eml=eml;

				var mint_at=0;

				var mint_atnum=0;

				var mint_dot=0;

				var mint_dotnum=0;



				mint_len=eml.length; //takes the length of the email address entered



				//checking for the symbol single quote. If found replace it with its html code

				if (mstr_eml.indexOf("'")!=-1)

				{

					mstr_eml=mstr_eml.replace("'","'");

				}



				//checking for the (@) & (.) symbol

				for(var iloop=0;iloop<mint_len;iloop++)

				{

					if(mstr_eml.charAt(iloop)=="@")

					{

						mint_at=iloop+1;

						mint_atnum=mint_atnum+1;

					}

					if(mstr_eml.charAt(iloop)==".")

					{

						mint_dot=iloop+1;

						mint_dotnum=mint_dotnum+1;

					}

				}



				//if nothing entered in the field

				if (mstr_eml=="")

				{

					return true;

				}



				//if @ entered more than once & dot (.) entered more than 4 times

				else

				if((mint_atnum!=1)||(mint_dotnum>4)||((mint_dot-mint_at)<2)||((mint_len-mint_dot)<2)||(mint_at<3))

				{

					return true;

				}



				//if any blank space is entered in the email address

				else if (mstr_eml.indexOf(" ")!=-1)

				{

					return true;

				}

				return false;

			}


function check()
 {


  if(checkBlankField(document.Form1.TextLoan.value) == false)
   {
   alert("Please enter the Loan Amount");
   document.Form1.TextLoan.select();
   return false;
   }

    if(isNaN(document.Form1.TextLoan.value) == true)
   {
   alert("Please enter the correct Loan Amount");
   document.Form1.TextLoan.select();
   return false;
   }


  if(document.Form1.DropLoanPurpose.selectedIndex <= 0)
	{
	alert("Please select the Loan Purpose");
	document.Form1.DropLoanPurpose.focus();
	return false;
	}

	if(document.Form1.Dropabout.selectedIndex <= 0)
	{
	alert("Please select the Heard about us from");
	document.Form1.Dropabout.focus();
	return false;
	}

	if(document.Form1.DropTitle.selectedIndex <= 0)
	{
	alert("Please select the Title");
	document.Form1.DropTitle.focus();
	return false;
	}

	if(checkBlankField(document.Form1.TxtFName.value) == false)
   {
   alert("Please enter the First Name");
   document.Form1.TxtFName.select();
   return false;
   }

   if(checkBlankField(document.Form1.TxtLName.value) == false)
   {
   alert("Please enter the Last Name");
   document.Form1.TxtLName.select();
   return false;
   }

   if(checkBlankField(document.Form1.TxtTelephone.value) == false)
   {
   alert("Please enter the Home telephone");
   document.Form1.TxtTelephone.select();
   return false;
   }

    /*if(isNaN(document.Form1.TxtTelephone.value) == true)
   {
   alert("Please enter the correct Home telephone");
   document.Form1.TxtTelephone.select();
   return false;
   }*/


   /* if(checkBlankField(document.Form1.TxtMob.value) == false)
   {
   alert("Please enter the Mobile No");
   document.Form1.TxtMob.select();
   return false;
   }*/

  /*  if(isNaN(document.Form1.TxtMob.value) == true)
   {
   alert("Please enter the correct Mobile No");
   document.Form1.TxtMob.select();
   return false;
   }*/

   if(checkBlankField(document.Form1.TxtEmail.value) == false)
   {
   alert("Please enter the Email Address");
   document.Form1.TxtEmail.select();
   return false;
   }

   if(valid_email(document.Form1.TxtEmail.value) == true)
   {
	alert("Plese enter correct E-mail address");
	document.Form1.TxtEmail.select();
    return false
   }

  if(checkBlankField(document.Form1.TxtEmail.value) == false)
   {
   alert("Please enter the Email Address");
   document.Form1.TxtEmail.select();
   return false;
   }

   if(checkBlankField(document.Form1.TxtHouseno.value) == false)
   {
   alert("Please enter the House Name/No");
   document.Form1.TxtHouseno.select();
   return false;
   }
   
      if(checkBlankField(document.Form1.TxtStreet.value) == false)
   {
   alert("Please enter the Street Name");
   document.Form1.TxtStreet.select();
   return false;
   }

   /*if(checkBlankField(document.Form1.TxtAddress2.value) == false)
   {
   alert("Please enter the Address2");
   document.Form1.TxtAddress2.select();
   return false;
   }*/

   if(checkBlankField(document.Form1.TxtTown.value) == false)
   {
   alert("Please enter the Town");
   document.Form1.TxtTown.select();
   return false;
   }
   
   /*if(checkBlankField(document.Form1.TxtCounty.value) == false)
   {
   alert("Please enter the County");
   document.Form1.TxtCounty.select();
   return false;
   }*/

   if(checkBlankField(document.Form1.TxtPostCode.value) == false)
   {
   alert("Please enter the post code");
   document.Form1.TxtPostCode.select();
   return false;
   }

  /* if(isNaN(document.Form1.TxtPostCode.value) == true)
   {
   alert("Please enter the correct Postal Code");
   document.Form1.TxtPostCode.select();
   return false;
   }*/

   }
   
   function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
/*              Utility functions                    */

function addEvent(obj, evType, fn) {
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}

