
function validate_form(){

if(validate_surname()==false){}

else if(validate_name()==false){}

else if(validate_email()==false){}

else if(validate_ph()==false){}

else if(validate_legal()==false){}

else if(validate_acceptance()==false){}

else{

//document.creditform.action="financetext.php?post=t";
//document.creditform.Send.value="Send";
document.creditform.form_from.value = document.creditform.txtemail.value;
document.creditform.submit();

} 

}



function validate_surname(){

if(document.creditform.txtsurname.value=="")

{alert("You have not filled in the surname field.");document.creditform.txtsurname.focus();return false;} 

else return true;

}	



function validate_name(){

if(document.creditform.txtname.value=="")

{alert("You have not filled in the name field.");document.creditform.txtname.focus();return false;}

else return true;

}



function validate_ph(){

if((document.creditform.txtPRIphone.value=="")&&(document.creditform.txtBUSphone.value=="")&&(document.creditform.txtMOBphone.value==""))

{alert("You must fill in at least one phone number.");document.creditform.txtPRIphone.focus();return false;}

else return true;

}



function validate_legal(){

if((!document.creditform.radlegal[0].checked)&&(!document.creditform.radlegal[1].checked))

{alert("You must select the either yes or no for legal declaration at the bottom of the form.");return false;}

else return true;

}



function validate_acceptance(){

if(!document.creditform.chktermsandconditions.checked)

{alert("You must accept the terms and conditions before sending the form.");return false;}

else return true;

}



function validate_email(){

if(document.creditform.txtemail.value=="")

{alert("You must fill in your email address.");document.creditform.txtemail.focus();return false;}

else return true;

}





function add_AS1(){

  if(validate_AS1()==false){}

  else{calculate_assets();}

}

function add_AS2(){

  if(validate_AS2()==false){}

  else{calculate_assets();}

}

function add_AS3(){

  if(validate_AS3()==false){}

  else{calculate_assets();}

}

function add_AS4(){

  if(validate_AS4()==false){}

  else{calculate_assets();}

}

function add_AS5(){

  if(validate_AS5()==false){}

  else{calculate_assets();}

}

function add_AS6(){

  if(validate_AS6()==false){}

  else{calculate_assets();}

}



function calculate_assets(){

  var asset_total = 0;

  if (document.creditform.txtAS1.value!=""){asset_total += parseFloat(document.creditform.txtAS1.value)};

  if (document.creditform.txtAS2.value!=""){asset_total += parseFloat(document.creditform.txtAS2.value)};

  if (document.creditform.txtAS3.value!=""){asset_total += parseFloat(document.creditform.txtAS3.value)};

  if (document.creditform.txtAS4.value!=""){asset_total += parseFloat(document.creditform.txtAS4.value)};

  if (document.creditform.txtAS5.value!=""){asset_total += parseFloat(document.creditform.txtAS5.value)};

  if (document.creditform.txtAS6.value!=""){asset_total += parseFloat(document.creditform.txtAS6.value)};

  

  if ((asset_total!=0))

  {

    document.creditform.txtAS7.value=(asset_total);

    if (document.creditform.txtAS7.value!="")

	{

	  document.creditform.txtAS7.value=(currency_convert(document.creditform.txtAS7.value));

	}	

  } 

  else

  {

	document.creditform.txtAS7.value="";	  

  }

	

  if ((document.creditform.txtLIA5.value!="")&&(document.creditform.txtAS7.value!=""))

  {

	document.creditform.txtLIA6.value=(document.creditform.txtAS7.value-document.creditform.txtLIA5.value);

	document.creditform.txtLIA6.value=(currency_convert(document.creditform.txtLIA6.value));

  }

  else

  {

	document.creditform.txtLIA6.value="";    

  }

}



function validate_AS1(){

var input_str=document.creditform.txtAS1.value;

var input_len=input_str.length;

if ((document.creditform.txtAS1.value)!=""){

  for (var l=0; l<input_len; l++){

       var ch=input_str.substring(l, l+1);

	 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtAS1.focus();return false;}

     } 

  }

  if (document.creditform.txtAS1.value!=""){document.creditform.txtAS1.value=(currency_convert(document.creditform.txtAS1.value));}

  return true;

}

function validate_AS2(){

var input_str=(document.creditform.txtAS2.value);

var input_len=input_str.length;

if ((document.creditform.txtAS2.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtAS2.focus();return false;}

     } 

  }

  if (document.creditform.txtAS2.value!=""){document.creditform.txtAS2.value=(currency_convert(document.creditform.txtAS2.value));}

  return true;

}

function validate_AS3(){

var input_str=(document.creditform.txtAS3.value);

var input_len=input_str.length;

if ((document.creditform.txtAS3.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtAS3.focus();return false;}

     } 

  }

  if (document.creditform.txtAS3.value!=""){document.creditform.txtAS3.value=(currency_convert(document.creditform.txtAS3.value));}

  return true;

}

function validate_AS4(){

var input_str=(document.creditform.txtAS4.value);

var input_len=input_str.length;

if ((document.creditform.txtAS4.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtAS4.focus();return false;}

     } 

  }

  if (document.creditform.txtAS4.value!=""){document.creditform.txtAS4.value=(currency_convert(document.creditform.txtAS4.value));}

  return true;

}

function validate_AS5(){

var input_str=(document.creditform.txtAS5.value);

var input_len=input_str.length;

if ((document.creditform.txtAS5.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtAS5.focus();return false;}

     } 

  }

  if (document.creditform.txtAS5.value!=""){document.creditform.txtAS5.value=(currency_convert(document.creditform.txtAS5.value));}

  return true;

}

function validate_AS6(){

var input_str=(document.creditform.txtAS6.value);

var input_len=input_str.length;

if ((document.creditform.txtAS6.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtAS6.focus();return false;}

     } 

  }

  if (document.creditform.txtAS6.value!=""){document.creditform.txtAS6.value=(currency_convert(document.creditform.txtAS6.value));}

  return true;

}



 

 

function add_LIA1(){

  if(validate_LIA1()==false){}

  else{calculate_liabilities();}

} 

function add_LIA2(){

  if(validate_LIA2()==false){}

  else{calculate_liabilities();}

} 

function add_LIA3(){

  if(validate_LIA3()==false){}

  else{calculate_liabilities();}

} 

function add_LIA4(){

  if(validate_LIA4()==false){}

  else{calculate_liabilities();}

} 



function calculate_liabilities(){

  var liabilities_total = 0;

  if (document.creditform.txtLIA1.value!=""){liabilities_total += parseFloat(document.creditform.txtLIA1.value)};

  if (document.creditform.txtLIA2.value!=""){liabilities_total += parseFloat(document.creditform.txtLIA2.value)};

  if (document.creditform.txtLIA3.value!=""){liabilities_total += parseFloat(document.creditform.txtLIA3.value)};

  if (document.creditform.txtLIA4.value!=""){liabilities_total += parseFloat(document.creditform.txtLIA4.value)};

  

  if (liabilities_total!=0)

  {

    document.creditform.txtLIA5.value=liabilities_total;

	if (document.creditform.txtLIA5.value!="")

	{

	  document.creditform.txtLIA5.value=(currency_convert(document.creditform.txtLIA5.value));

	}

  }

  else

  {

	document.creditform.txtLIA5.value="";    

  }

  

  if ((document.creditform.txtLIA5.value!="")&&(document.creditform.txtAS7.value!=""))

  {

	document.creditform.txtLIA6.value=(document.creditform.txtAS7.value-document.creditform.txtLIA5.value);

	document.creditform.txtLIA6.value=(currency_convert(document.creditform.txtLIA6.value));

  }

  else

  {

	document.creditform.txtLIA6.value="";    

  } 

}



function validate_LIA1(){

var input_str=(document.creditform.txtLIA1.value);

var input_len=input_str.length;

if ((document.creditform.txtLIA1.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtLIA1.focus();return false;}

     } 

  }

  if (document.creditform.txtLIA1.value!=""){document.creditform.txtLIA1.value=(currency_convert(document.creditform.txtLIA1.value));}

  return true;

}

function validate_LIA2(){

var input_str=(document.creditform.txtLIA2.value);

var input_len=input_str.length;

if ((document.creditform.txtLIA2.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtLIA2.focus();return false;}

     } 

  }

  if (document.creditform.txtLIA2.value!=""){document.creditform.txtLIA2.value=(currency_convert(document.creditform.txtLIA2.value));}

  return true;

}

function validate_LIA3(){

var input_str=(document.creditform.txtLIA3.value);

var input_len=input_str.length;

if ((document.creditform.txtLIA3.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtLIA3.focus();return false;}

     } 

  }

  if (document.creditform.txtLIA3.value!=""){document.creditform.txtLIA3.value=(currency_convert(document.creditform.txtLIA3.value));}

  return true;

}

function validate_LIA4(){

var input_str=(document.creditform.txtLIA4.value);

var input_len=input_str.length;

if ((document.creditform.txtLIA4.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtLIA4.focus();return false;}

     } 

  }

  if (document.creditform.txtLIA4.value!=""){document.creditform.txtLIA4.value=(currency_convert(document.creditform.txtLIA4.value));}

  return true;

}

 

 

function add_INC1(){

  if(validate_INC1()==false){}

  else{calculate_income();}

} 

function add_INC2(){

  if(validate_INC2()==false){}

  else{calculate_income();}

} 

function add_INC3(){

  if(validate_INC3()==false){}

  else{calculate_income();}

} 

function calculate_income(){

  var income_total = 0;

  if (document.creditform.txtINC1.value!=""){income_total += parseFloat(document.creditform.txtINC1.value)};

  if (document.creditform.txtINC2.value!=""){income_total += parseFloat(document.creditform.txtINC2.value)};

  if (document.creditform.txtINC3.value!=""){income_total += parseFloat(document.creditform.txtINC3.value)};

  

  if ((income_total!=0))

  {

    document.creditform.txtINC4.value=(income_total);

    if (document.creditform.txtINC4.value!="")

	{

	  document.creditform.txtINC4.value=(currency_convert(document.creditform.txtINC4.value));

	}	

  } 

  else

  {

	document.creditform.txtINC4.value="";	  

  }

}

function validate_INC1(){

var input_str=(document.creditform.txtINC1.value);

var input_len=input_str.length;

if ((document.creditform.txtINC1.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtINC1.focus();return false;}

     } 

  }

  if (document.creditform.txtINC1.value!=""){document.creditform.txtINC1.value=(currency_convert(document.creditform.txtINC1.value));}

  return true;

}

function validate_INC2(){

var input_str=(document.creditform.txtINC2.value);

var input_len=input_str.length;

if ((document.creditform.txtINC2.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtINC2.focus();return false;}

     } 

  }

  if (document.creditform.txtINC2.value!=""){document.creditform.txtINC2.value=(currency_convert(document.creditform.txtINC2.value));}

  return true;

}

function validate_INC3(){

var input_str=(document.creditform.txtINC3.value);

var input_len=input_str.length;

if ((document.creditform.txtINC3.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtINC3.focus();return false;}

     } 

  }

  if (document.creditform.txtINC3.value!=""){document.creditform.txtINC3.value=(currency_convert(document.creditform.txtINC3.value));}

  return true;

}





function add_EXP1(){

  if(validate_EXP1()==false){}

  else{calculate_expenses();}

} 

function add_EXP2(){

  if(validate_EXP2()==false){}

  else{calculate_expenses();}

} 

function add_EXP3(){

  if(validate_EXP3()==false){}

  else{calculate_expenses();}

} 

function add_EXP4(){

  if(validate_EXP4()==false){}

  else{calculate_expenses();}

} 

function add_EXP5(){

  if(validate_EXP5()==false){}

  else{calculate_expenses();}

} 



function calculate_expenses(){

  var expenses_total = 0;

  if (document.creditform.txtEXP1.value!=""){expenses_total += parseFloat(document.creditform.txtEXP1.value)};

  if (document.creditform.txtEXP2.value!=""){expenses_total += parseFloat(document.creditform.txtEXP2.value)};

  if (document.creditform.txtEXP3.value!=""){expenses_total += parseFloat(document.creditform.txtEXP3.value)};

  if (document.creditform.txtEXP4.value!=""){expenses_total += parseFloat(document.creditform.txtEXP4.value)};

  if (document.creditform.txtEXP5.value!=""){expenses_total += parseFloat(document.creditform.txtEXP5.value)};



  if ((expenses_total!=0))

  {

    document.creditform.txtEXP6.value=(expenses_total);

    if (document.creditform.txtEXP6.value!="")

	{

	  document.creditform.txtEXP6.value=(currency_convert(document.creditform.txtEXP6.value));

	}	

  } 

  else

  {

	document.creditform.txtEXP6.value="";	  

  }

}



function validate_EXP1(){

var input_str=(document.creditform.txtEXP1.value);

var input_len=input_str.length;

if ((document.creditform.txtEXP1.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtEXP1.focus();return false;}

     } 

  }

  if (document.creditform.txtEXP1.value!=""){document.creditform.txtEXP1.value=(currency_convert(document.creditform.txtEXP1.value));}

  return true;

}

function validate_EXP2(){

var input_str=(document.creditform.txtEXP2.value);

var input_len=input_str.length;

if ((document.creditform.txtEXP2.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);

 

     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtEXP2.focus();return false;}

     } 

  }

  if (document.creditform.txtEXP2.value!=""){document.creditform.txtEXP2.value=(currency_convert(document.creditform.txtEXP2.value));}

  return true;

}

function validate_EXP3(){

var input_str=(document.creditform.txtEXP3.value);

var input_len=input_str.length;

if ((document.creditform.txtEXP3.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);



     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtEXP3.focus();return false;}

	 } 



  }

  if (document.creditform.txtEXP3.value!=""){document.creditform.txtEXP3.value=(currency_convert(document.creditform.txtEXP3.value));}

  return true;

}

function validate_EXP4(){

var input_str=(document.creditform.txtEXP4.value);

var input_len=input_str.length;



if ((document.creditform.txtEXP4.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);



     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtEXP4.focus();return false;}

     } 

  }

  if (document.creditform.txtEXP4.value!=""){document.creditform.txtEXP4.value=(currency_convert(document.creditform.txtEXP4.value));}

  return true;

}

function validate_EXP5(){

var input_str=(document.creditform.txtEXP5.value);

var input_len=input_str.length;

if ((document.creditform.txtEXP5.value)!=""){

  for (var l=0; l<input_len; l++){

     var ch=input_str.substring(l, l+1);



     if ((ch==".")||(ch=="0")||(ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")){}else 

	   {alert("Please enter a valid currency value.");document.creditform.txtEXP5.focus();return false;}

     } 

  }

  if (document.creditform.txtEXP5.value!=""){document.creditform.txtEXP5.value=(currency_convert(document.creditform.txtEXP5.value));}

  return true;

}







function currency_convert(oldc){

var input_str=oldc;

var input_len=input_str.length;

var dec=0;

var exe=false;

var newc="";



for (var i=0; i<input_len; i++){

  var chr=input_str.substring(i, i+1);  

  if (chr=="."){exe=true;}

  if (exe==true){dec++;}

}

if (dec==0){

  newc=oldc+".00";

}

if (dec==1){

  newc=oldc+"00";

}

if (dec==2){

  newc=oldc+"0";

}

if (dec==3){

  newc=oldc;

}

if (dec>3){

  newc=oldc.substring(0, (oldc.length-(dec-3)));

}

return(newc);

}
