var path = document.location.pathname;
var run_mt = false;
var run_cr = false;
var mballval = new Array();
var mballtxt = new Array();
var pathstr = path + '';
if (pathstr.indexOf('/genforms1/') > -1 && pathstr.indexOf('/08x') > -1) {
	run_mt = true;
	if (pathstr.indexOf('/service.jsp') > -1 || pathstr.indexOf('/prequal.jsp') > -1) {
		run_cr = true;
	}
}
/* Center pv */
function doPVFocus() {
	if (document.form.PropertyValue.value == '') {
		document.form.PropertyValue.value = '375000';
		limit_mb();
	}	
	return;
}
/* Copy mb */
function doMBCopy() {	
	var mbform = document.form.MortgageBalance.options;	
	for (i = 1; i < mbform.length; i++) {
		mballval[i] = mbform[i].value;
		mballtxt[i] = mbform[i].text;
	}	
}
/* Limit the options offered using the selected property value. */
function limit_mb() {	
	var mbform = document.form.MortgageBalance.options;
	var pvsel = document.form.PropertyValue.options.selectedIndex;
	var mbbound = -1;	
	if (pvsel != -1) {
		var pv = document.form.PropertyValue.options[pvsel].value;
		mbbound = 1.3 * pv;
	}
	mbform.length = 1;
	for (j = 1; j < mballval.length; j++) {		
		if (parseInt(mballval[j]) > parseInt(mbbound)) {			
			break;
		} else {
			mbform[j] = new Option(mballtxt[j], mballval[j]);
		}
	}
	show_ltv();
}
/* Show ltv next to each option in mortgage balance. */
function show_ltv() {
  	var pvval = document.form.PropertyValue != null ? document.form.PropertyValue.value : 0; 
  	var mboptions = document.form.MortgageBalance.options;  	 	
  	for (var i=1; i<mboptions.length; i++) {  	
  		var mbval = mboptions[i].value;
  		var mbtxt = mboptions[i].text;  	
  		var ltv = mbval/pvval;
  		var ltvp = Math.round(ltv * 100);
  		mbtxt = mbtxt.indexOf("(") > 0 ? mbtxt.substring(0,mbtxt.indexOf("(")-1) : mbtxt;
  		mboptions[i].text = mbtxt + " (" + ltvp + "%) ";
  	}
}
/* Highlight credit and display description. */
function highlight_credit(choice) {
	if (choice == 'Excellent') {
		document.getElementById("cr_Excellent").style.backgroundColor = "#CCCCCC";
		document.getElementById("cr_Good").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Fair").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Poor").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_desc_box").innerHTML = "<strong>Perfect credit history with no negative credit marks.</strong> You have consistently paid your bills on time over a long period of time.";
	} else if (choice == 'Good') {
		document.getElementById("cr_Good").style.backgroundColor = "#CCCCCC";
		document.getElementById("cr_Excellent").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Fair").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Poor").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_desc_box").innerHTML = "<strong>Most credit histories fall into this category.</strong> You almost always pay your bills on time, but may have been late on a few payments in the past.";
	} else if (choice == 'Fair') {
		document.getElementById("cr_Fair").style.backgroundColor = "#CCCCCC";
		document.getElementById("cr_Excellent").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Good").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Poor").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_desc_box").innerHTML = "<strong>The most common category for people with bad credit.</strong> Consistently have been 60 days or more past due on payments.";
	} else if (choice == 'Poor') {
		document.getElementById("cr_Poor").style.backgroundColor = "#CCCCCC";
		document.getElementById("cr_Excellent").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Good").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Fair").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_desc_box").innerHTML = "<strong>Few people have bad credit histories that are this severe.</strong> Extremely bad credit with a long history of late payments.";
	} else {
		document.getElementById("cr_Poor").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Excellent").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Good").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_Fair").style.backgroundColor = document.getElementById("container").style.backgroundColor;
		document.getElementById("cr_desc_box").style.backgroundColor = document.getElementById("container").style.backgroundColor;
	}
}
/* Toggle credit selection and display description. */
function toggle_credit(radio) {
	var choice = radio.value + '';
	highlight_credit(choice);
}
/* Toggle credit selection on load. */
function onload_credit() {	
	var cr = document.form.CreditRating;
	var choice = -1;
	for (var i = 0; i < cr.length; i++) {
		if (cr[i].checked) {			
			choice = i;
		}
	}
	if (choice == -1) {
		for (var i = 0; i < cr.length; i++) {
			if (cr[i].value == 'Good') {
				cr[i].checked = 'true';			
			}
		}
	}
}

function doPopUnder(url) {
		var ref;
		ref = window.open(url, 'poppartner');
		ref.blur();
		return false;
}


function doPopUnderClose() {
	var ref;
	ref = window.open('', 'poppartner');
	ref.close();
	return false;
}

function info(obj){
	window.open(obj.href,'',obj.rel+',directories=0,menubar=0,location=0,screenX=100,screenY=75,left=100,top=75,copyhistory=0',false);
	return false;
}

function displayQuestion()
{      
        if(document.form.A152[0].checked)
		{  
		document.getElementById('g-q-new').className = 'thide';
		}
		else
		{ 
		document.getElementById("g-q-new").className = 'tshow';
		}
	}