// JavaScript Document

function checkStatusUnsec(loantype, loanamount, loanterm) {
	var rowOutput;
	var julie = loantype;
	var aprfontsize		= "11px";
	var strnoloans = false;

	if (loanamount == ""){loanamount = document.form1.hid_amount.value;}
	if (loanterm == ""){loanterm = document.form1.hid_term.value;}

	rowOutput = '<table cellpadding="0" cellspacing="0" border="0" style="width:685px;">';
	for(i = 0; i < appArray.length; i++) { 
		// build the output row
	  if(appArray[i]['lc_loan_type'] == julie && appArray[i]['lc_min_amount']*1 <= loanamount*1  && appArray[i]['lc_max_amount']*1  >= loanamount*1  && appArray[i]['lc_min_term']*1 <= loanterm*1  && appArray[i]['lc_max_term']*1  >= loanterm*1  ){
		if(appArray[i]['lc_provider'] == 'Loan Approvalls'){aprfontsize		= "12px";document.getElementById("hid_loanapprovallsunsec").value = appArray[i]['lc_apr'];}
		//alert( appArray[i]['lc_max_amount'] + '   ' + appArray[i]['lc_provider']);

		//if(loanamount > 0 && loanterm > 0){
		if( document.form1.hid_amount.value > 0){
			A = loanamount;
			T = loanterm;
			R = appArray[i]['lc_apr'];

			var princ = A;
			var term  = T*12
			var intr   = R / 1200;
			P = princ * intr / (1 - (Math.pow(1/(1 + intr), term)));
			P = poundsPence(P);
			TR = P*term;
			TR = addCommas(TR.toFixed(2));		
		}
		else{
			P = "";
			TR="";}

		rowOutput += '<tr style="height:50px;"><td><table cellpadding="0" cellspacing="0" border="0" style="font-size:11px;">';
		rowOutput += '<tr><td style="width:122px; text-align:center;"><img src="images/lenderlogos/' + appArray[i]['lc_img_url'];
		rowOutput += '"/>';
		rowOutput += '</td><td style="width:65px; text-align:center;font-size:' + aprfontsize ;
		rowOutput += '"><input type="hidden" name="R'+ i+'" id="R'+i+'" value="'+ appArray[i]['lc_apr'];
		rowOutput += '" size="3" style="font-size:' + aprfontsize ;
		rowOutput += '; border:0; text-align:right;"/>'+ appArray[i]['lc_apr']+'%&nbsp;&nbsp;&nbsp;<br/>Typical</td>';
		rowOutput += '<td style="width:65px; text-align:center;">&pound;'+ appArray[i]['lc_min_amount'];
		rowOutput += '<br/>to<br/> &pound;'+ appArray[i]['lc_max_amount'];
		rowOutput += '</td>';
		rowOutput += '<td style="width:55px; text-align:center;">'+ appArray[i]['lc_min_term'] +' - '+ appArray[i]['lc_max_term'] +'<br/>years</td>';
		rowOutput += '<td style="width:80px;text-align:center;"><input size="5" onkeyup="computeField(this,'+ i + ','+ appArray[i]['lc_min_amount'] + ','+ appArray[i]['lc_max_amount'] +'); document.form1.hid_amount.value=this.value;" size="6" name="A' + i + '" id="A' + i + '"value="' + document.form1.hid_amount.value + '"/></td>';
		rowOutput += '<td style="width:85px;text-align:center;"><input size="5" onkeyup="computeField(this,' + i+','+ appArray[i]['lc_min_term'] +',' +appArray[i]['lc_max_term']+'); document.form1.hid_term.value=this.value;" size="3" name="T'  + i + '" id="T' + i + '" value="' + document.form1.hid_term.value + '"/></td>';
		rowOutput += '<td style="width:80px;text-align:center;"><input size="5" name="Cm' + i + '" id="Cm' + i + '" readonly value="' + P + '"/></td>';
		//rowOutput += '<td style="text-align:center;"><img name="app' + i + '" src="images/buttons/btn_continue.png" onmousedown="movepic(this.name,\'images/buttons/btn_continue_down.png\');"  onmouseup="movepic(this.name,\'images/buttons/btn_continue.png\');" onmouseover="this.style.cursor=\'pointer\';movepic(this.name,\'images/buttons/btn_continue_over.png\');" onmouseout="movepic(this.name,\'images/buttons/btn_continue.png\');" onclick="confirmfilterchange(\'Unsecured\', \'' + document.form1.hid_amount.value + '\', \'' + document.form1.hid_term.value + '\', \'' +  appArray[i]['lc_min_term'] + '\', \'' +  appArray[i]['lc_max_term'] + '\', \'' +  appArray[i]['lc_min_amount'] + '\', \'' +  appArray[i]['lc_max_amount'] + '\', \'' +  appArray[i]['lc_destination'] + '\', \'' +  appArray[i]['lc_destination_url'] + '\', \'' +  appArray[i]['lc_provider'] + '\'); "/></td></tr>';
		rowOutput += '<td style="text-align:center;" ><a class="loan_continue" name="app' + i + '" onclick="confirmfilterchange(\'Unsecured\', \'' + document.form1.hid_amount.value + '\', \'' + document.form1.hid_term.value + '\', \'' +  appArray[i]['lc_min_term'] + '\', \'' +  appArray[i]['lc_max_term'] + '\', \'' +  appArray[i]['lc_min_amount'] + '\', \'' +  appArray[i]['lc_max_amount'] + '\', \'' +  appArray[i]['lc_destination'] + '\', \'' +  appArray[i]['lc_destination_url'] + '\', \'' +  appArray[i]['lc_provider'] + '\'); "><span>Continue</span></a></td></tr>';
		
		rowOutput += '<tr><td name="Ill' + i + '" id="Ill' + i + '" class="illustrativedata" colspan="8">The total illustrative cost of borrowing £' + document.form1.hid_amount.value + ' over ' + document.form1.hid_term.value + ' years at the representitive rate of '+ appArray[i]['lc_apr'] +'% APR is £' +  TR + '</td></tr>';
		
		rowOutput += '<tr><td style="padding-left:5px"; colspan="8"><hr/></td></tr>';
		rowOutput += '</table></td></tr>';
	}
	}
		if(rowOutput == '<table cellpadding="0" cellspacing="0" border="0" style="width:685px;">'){
			rowOutput += '<tr><td class="noLendersMsg">Unfortunately we have no Unsecured lenders who can supply a loan of &pound;' + document.form1.hid_amount.value + ' over ' + document.form1.hid_term.value + ' years. <br/>Please Click continue on your preferred secured lender above or click restart and amend your requirements</td></tr>';
			strnoloans = true;
	}

	rowOutput += '<tr><td class="comparison_tbl_restart"><img name="unsec_reset" src="/images/buttons/btn_restart.png" alt="Restart Button" title="" onmousedown="movepic(this.name,\'images/buttons/btn_restart_down.png\');"  onmouseup="movepic(this.name,\'images/buttons/btn_restart.png\');" onmouseover="this.style.cursor=\'pointer\';movepic(this.name,\'images/buttons/btn_restart_over.png\');" onmouseout="movepic(this.name,\'images/buttons/btn_restart.png\');" onmouseover="this.style.cursor=\'pointer\';" onclick="document.form1.hid_amount.value =\'\';document.form1.hid_term.value =\'\';document.form1.inp_loanamount.value =\'\';document.form1.inp_loanterm.value =\'\'; checkStatusUnsec(\'Unsecured\', \'10000\', \'1\'); hideOtherLenderMsg(\'Unsecured\');"/></td></tr>';
	 rowOutput += '<tr valign="middle" style="height:20px;"><td><span class="loans_footer"><br/>For impartial guidance on any of the above lenders acceptance criteria or monitored service standards<br/>- please telephone 0844 4 10 60 61</span></td></tr>';
	rowOutput += '</table>';
	document.getElementById('unsecuredlist').innerHTML = rowOutput;
	if 	(strnoloans){
		hideOtherLenderMsg('Unsecured');}

// End checkStatusUnsec(loantype, loanamount, loanterm)
}


function checkStatusSec(loantype, loanamount, loanterm) {
	var rowOutput;
	var julie = loantype;
	var aprfontsize		= "11px";
	var i = 0;
	var strnoloans = false;

	if (loanamount == ""){loanamount = document.form1.hid_amount.value;}
	if (loanterm == ""){loanterm = document.form1.hid_term.value;}

	rowOutput = '<table cellpadding="0" cellspacing="0" border="0" style="width:685px;">';
	for(i = 0; i < appArray.length; i++) {
		// build the output row
	  if(appArray[i]['lc_loan_type'] == julie && appArray[i]['lc_min_amount']*1 <= loanamount*1  && appArray[i]['lc_max_amount']*1  >= loanamount*1  && appArray[i]['lc_min_term']*1 <= loanterm*1  && appArray[i]['lc_max_term']*1  >= loanterm*1  ){
		if(appArray[i]['lc_provider'] == 'Loan Approvalls'){aprfontsize		= "12px";document.getElementById("hid_loanapprovallssec").value = appArray[i]['lc_apr'];}
		//alert( appArray[i]['lc_max_amount'] + '   ' + appArray[i]['lc_provider']);

		//if(loanamount > 0 && loanterm > 0){
		if( document.form1.hid_amount.value > 0){
			A = loanamount;
			T = loanterm;
			R = appArray[i]['lc_apr'];

			var princ = A;
			var term  = T*12
			var intr   = R / 1200;
			P = princ * intr / (1 - (Math.pow(1/(1 + intr), term)));
			P = poundsPence(P);
			TR = P*term;
			TR = TR.toFixed(2);	
			}
		else{
			P = "";
			TR="";}

		rowOutput += '<tr style="height:50px;"><td><table cellpadding="0" cellspacing="0" border="0" style="font-size:11px;">';
		rowOutput += '<tr><td style="width:122px; text-align:center;"><img src="images/lenderlogos/' + appArray[i]['lc_img_url'];
		rowOutput += '"/>';
		rowOutput += '</td><td style="width:65px; text-align:center;font-size:' + aprfontsize ;
		rowOutput += '"><input type="hidden" name="R'+ i+'" id="R'+i+'" value="'+ appArray[i]['lc_apr'];
		rowOutput += '" size="3" style="font-size:' + aprfontsize ;
		rowOutput += '; border:0; text-align:right;"/>'+ appArray[i]['lc_apr']+'%&nbsp;&nbsp;&nbsp;<br/>Typical</td>';
		rowOutput += '<td style="width:65px; text-align:center;">&pound;'+ appArray[i]['lc_min_amount'];
		rowOutput += '<br/>to<br/> &pound;'+ appArray[i]['lc_max_amount'];
		rowOutput += '</td>';
		rowOutput += '<td style="width:55px; text-align:center;">'+ appArray[i]['lc_min_term'] +' - '+ appArray[i]['lc_max_term'] +'<br/>years</td>';
		rowOutput += '<td style="width:80px;text-align:center;"><input size="5" onkeyup="computeField(this,'+ i + ','+ appArray[i]['lc_min_amount'] + ','+ appArray[i]['lc_max_amount'] +'); document.form1.hid_amount.value=this.value;" size="6" name="A' + i + '" id="A' + i + '"value="' + document.form1.hid_amount.value + '"/></td>';
		rowOutput += '<td style="width:85px;text-align:center;"><input size="5" onkeyup="computeField(this,' + i+','+ appArray[i]['lc_min_term'] +',' +appArray[i]['lc_max_term']+'); document.form1.hid_term.value=this.value;" size="3" name="T'  + i + '" id="T' + i + '" value="' + document.form1.hid_term.value + '"/></td>';
		rowOutput += '<td style="width:80px;text-align:center;"><input size="5" name="Cm' + i + '" id="Cm' + i + '" readonly value="' + P + '"/></td>';
		//rowOutput += '<td style="text-align:center;"><img name="app' + i + '" src="images/buttons/btn_continue.png" onmousedown="movepic(this.name,\'images/buttons/btn_continue_down.png\');"  onmouseup="movepic(this.name,\'images/buttons/btn_continue.png\');" onmouseover="this.style.cursor=\'pointer\';movepic(this.name,\'images/buttons/btn_continue_over.png\');" onmouseout="movepic(this.name,\'images/buttons/btn_continue.png\');" onclick="confirmfilterchange(\'Secured\', \'' + document.form1.hid_amount.value + '\', \'' + document.form1.hid_term.value + '\', \'' +  appArray[i]['lc_min_term'] + '\', \'' +  appArray[i]['lc_max_term'] + '\', \'' +  appArray[i]['lc_min_amount'] + '\', \'' +  appArray[i]['lc_max_amount'] + '\', \'' +  appArray[i]['lc_destination'] + '\', \'' +  appArray[i]['lc_destination_url'] + '\', \'' +  appArray[i]['lc_provider'] + '\'); "/></td></tr>';
		rowOutput += '<td style="text-align:center;" ><a class="loan_continue" name="app' + i + '" onclick="confirmfilterchange(\'Secured\', \'' + document.form1.hid_amount.value + '\', \'' + document.form1.hid_term.value + '\', \'' +  appArray[i]['lc_min_term'] + '\', \'' +  appArray[i]['lc_max_term'] + '\', \'' +  appArray[i]['lc_min_amount'] + '\', \'' +  appArray[i]['lc_max_amount'] + '\', \'' +  appArray[i]['lc_destination'] + '\', \'' +  appArray[i]['lc_destination_url'] + '\', \'' +  appArray[i]['lc_provider'] + '\'); "><span>Continue</span></a></td></tr>';

		rowOutput += '<tr><td name="Ill' + i + '" id="Ill' + i + '" class="illustrativedata"  colspan="8">The total amount payable is £' +  TR + '. The illustrative cost of borrowing £' + document.form1.hid_amount.value + ' over ' + document.form1.hid_term.value + ' years at the representitive rate of '+ appArray[i]['lc_apr'] +'% APR</td></tr>';

		rowOutput += '<tr><td style="padding-left:5px"; colspan="8"><hr/></td></tr>';
		rowOutput += '</table></td></tr>';
	}
	}
		if(rowOutput == '<table cellpadding="0" cellspacing="0" border="0" style="width:685px;">'){
			rowOutput += '<tr><td class="noLendersMsg">Unfortunately we have no Secured lenders who can supply a loan of &pound;' + document.form1.hid_amount.value + ' over ' + document.form1.hid_term.value + ' years. <br/>Please Click continue on your preferred unsecured lender below or click restart and amend your requirements</td></tr>';
			strnoloans = true;
	}

	rowOutput += '<tr><td class="comparison_tbl_restart"><img name="sec_reset" src="/images/buttons/btn_restart.png" alt="Restart Button" title="" onmousedown="movepic(this.name,\'images/buttons/btn_restart_down.png\');"  onmouseup="movepic(this.name,\'images/buttons/btn_restart.png\');" onmouseover="this.style.cursor=\'pointer\';movepic(this.name,\'images/buttons/btn_restart_over.png\');" onmouseout="movepic(this.name,\'images/buttons/btn_restart.png\');" onclick="document.form1.hid_amount.value =\'\';document.form1.hid_term.value =\'\'; document.form1.inp_loanamount.value =\'\';document.form1.inp_loanterm.value =\'\'; checkStatusSec(\'Secured\', \'10000\', \'5\'); hideOtherLenderMsg(\'Secured\');"/></td></tr>';

	 rowOutput += '<tr valign="middle" style="height:20px;"><td><span class="loans_footer"><br/>For impartial guidance on any of the above lenders acceptance criteria or monitored service standards<br/>- please telephone 0844 4 10 60 61</span></td></tr>';

	rowOutput += '</table>';
	document.getElementById('securedlist').innerHTML = rowOutput;
	if 	(strnoloans){
		hideOtherLenderMsg('Secured');}

// End checkStatusSec(loantype, loanamount, loanterm)
}


