var dt = new Date();
var bustcacheparameter = "?" + dt.getMonth() + dt.getDate();
var jsonCounty = eval('(' + getFileBody('http://' + self.location.host + '/mortgage/json/counties.json' + bustcacheparameter) + ')');
function getLoDataSearch(sCounty, sPrettyCounty) {
	var sLO = '';
	var sBody = '<br><br><u><span class=LOName>'+ sPrettyCounty + '</span></u><br><br>';
	//write loan officer info
	for (j=0; j<jsonCounty[sCounty].length; j++) {
		sLO = jsonCounty[sCounty][j];
		var jsonLO = eval('(' + getFileBody('http://' + self.location.host + '/mortgage/staff/' + sLO + '.json') + ')');
		sBody += '<br><br>';
		sBody += '<table cellspacing="0" cellpadding="0" width="80%" align="center" border="0">';
		sBody += '<tr><td rowspan="4" width="1%" align="center">';
		sBody += '<a href="/mortgage/' + sLO + '.html"><img alt="" src="staff/' + sLO + '_thb.png" style="border-style:none"></a></td>';
		sBody += '<td rowspan="4" width="1%" align="center">&nbsp;</td>';
		sBody += '<td class=LOName><a href="/mortgage/' + sLO + '.html" style="text-decoration:none">' + jsonLO.name + '</a></td></tr>';
		sBody += '<tr><td class=LOTitle><a href="/mortgage/' + sLO + '.html" style="text-decoration:none">' + jsonLO.title + '</td></tr>';
		sBody += '<tr><td class=LOItems><a href="/mortgage/' + sLO + '.html" style="text-decoration:none">' + jsonLO.streetaddress + '</td></tr>';
		sBody += '<tr><td class=LOItems><a href="/mortgage/' + sLO + '.html" style="text-decoration:none">' + jsonLO.citystatezip + '</td></tr></table>';
	}
	d = document.getElementById("loan_officer_area");
	d.innerHTML = sBody;
	//if viewing county with one LO, rewrite link to pass LO's 1003 id as arg
	var origid=jsonCounty[sCounty].length==1?jsonLO.ids['1003']:"";
	document.getElementById("online_mortgage").innerHTML='<a href="http://www.independentbank.com/personal/online_mortgage_app?origid='+origid+'" title="online mortgage">online mortgage</a>';
}
function getCountyLOs(sCounty, sPrettyCounty) {
	d = document.getElementById("loan_officer_area");
	d.innerHTML = '<br><br><span class=LOName>Loading Loan Officers for ' + sPrettyCounty + '...</span>';
	var tJS = 'getLoDataSearch("' + sCounty + '", "' + sPrettyCounty +'");'
	setTimeout(tJS,1);
}
function initBodySearch() {
	//greeting
	d = document.getElementById("loan_officer_area");
	d.innerHTML = '<br><br><br><br><span class=LOName>Please click on a county on the map to find a loan officer</span>';
	setTimeout('getRates();',1);
}
function getRates() {
	// rates
	var nocache = "?" + new Date().getTime();
	var jsonRates = eval('(' + getFileBody('http://' + self.location.host + '/mortgage/json/rates.json'+ nocache) + ')');
	var sRateBody='<table cellspacing="0" cellpadding="0" width="100%" border="0" id="rateTable1" summary="layout table">';
	for (i=0; i<jsonRates.prodsrates.length; i++) {
		if (i==0 || jsonRates.prodsrates[i].desc!=jsonRates.prodsrates[i-1].desc) {
			sRateBody+='<tr align="center"><td class="TodayRateHeader" colspan="3">' + jsonRates.prodsrates[i].desc + '</td></tr>';
			sRateBody+='<tr><td class="TodayRateDetailTitle">&nbsp;Rate</td><td class="TodayRateDetailTitle">&nbsp;APR</td><td class="TodayRateDetailTitle">&nbsp;Points</td></tr>';
		}
		sRateBody+='<tr>';
		sRateBody+='<td class="TodayRateDetail">&nbsp;' + jsonRates.prodsrates[i].rate + '</td>';
		sRateBody+='<td class="TodayRateDetail">&nbsp;' + jsonRates.prodsrates[i].apr + '</td>';
		sRateBody+='<td class="TodayRateDetail">&nbsp;' + jsonRates.prodsrates[i].points + '</td>';
		sRateBody+='</tr>';
	}
	sRateBody+='</table>';
	document.getElementById("rates").innerHTML=sRateBody;
	
	// footers
	var sRateFooter='<br><span class="TodayRateDetail"><ul>';
	for (i=0; i<jsonRates.footers.length; i++) {
		sRateFooter+='<li>' + jsonRates.footers[i] + '</li>';
	}
	sRateFooter+='</ul></span>';
	document.getElementById("rate_footer").innerHTML=sRateFooter;
	
	//var t1 = new ScrollableTable(document.getElementById('rateTable1'), min(100,jsonRates.prodsrates.length * 60));
	
}
function getLoDataDetail() {
	var bustcacheparameter = "?" + new Date().getTime();
	var sFileHandle = getFileHandle();
	var jsonLO = eval('(' + getFileBody('http://'+self.location.host+'/mortgage/staff/'+sFileHandle+'.json'+bustcacheparameter) + ')');
	// LO image
	document.getElementById("lo_pic").innerHTML='<IMG alt="" src="staff/'+sFileHandle+'.png" border=0>';
	// LO contact info
	var sLoBody='<TABLE cellSpacing=0 cellPadding=0 width="100%"><TBODY>';
	sLoBody+='<TR><TD class=LOName>' + jsonLO.name + '</TD></TR>';
	sLoBody+='<TR><TD class=LOTitle>' + jsonLO.title + '<BR><BR></TD></TR>';
	sLoBody+='<TR><TD class=LOItems>' + jsonLO.streetaddress + '<BR>' + jsonLO.citystatezip + '<BR><BR></TD></TR>';
	sLoBody+='<TR><TD class=LOItems>' + jsonLO.other01 + '</TD></TR>';
	sLoBody+='<TR><TD class=LOItems>' + jsonLO.other02 + '</TD></TR>';
	sLoBody+='<TR><TD class=LOItems>' + jsonLO.other03 + '</TD></TR>';
	sLoBody+='<TR><TD class=LOItems>' + jsonLO.other04 + '</TD></TR>';
	sLoBody+='<TR><TD class=LOItems><BR>Email: <A onclick="javascript:alert(\'Please be aware email is not a secure method of communication. Do not use email to send us confidential or sensitive information such as passwords, account numbers or social security numbers. If you need to provide this type of information, contact us by phone, fax or regular mail.\');" href="mailto:';
	sLoBody+=jsonLO.email + '">' + jsonLO.email + '</A></TD></TR></TBODY></TABLE>';
	document.getElementById("lo_contact").innerHTML=sLoBody;
	// LO bio
	document.getElementById("lo_bio").innerHTML=jsonLO.biography;
	// online mortgage url
	document.getElementById("online_mortgage").innerHTML=
		'<a href="http://www.independentbank.com/personal/online_mortgage_app?origid='+jsonLO.ids['1003']
		+'" title="online mortgage">Apply for a Mortgage</a>'
}
