



function closeWindows() {
		map.closeInfoWindow();
}

function loadSearch(){
	new Ajax.Updater('searchcontent','mlxsearch/search_ajax.cfm', {
		parameters: {
		}
		,onSuccess: function(){
		}
		,onComplete: function(){	
		}
	});
}	

function showProperty(mlid, fid) {
	$('current_mlid').value = mlid;


		new Ajax.Updater('searchcontent','mlxsearch/searchDetail_ajax.cfm', {
			evalScripts:true
			,parameters:Form.serialize($(fid))
			,onComplete:function(){
				Lightview.updateViews();
				/**
				if (map!=null) {
					GUnload();
				}
				*/	
				GMapLoad();
			}
		});
	
}

// direct link to the property
function showPropertyDirect(mlid,ptype) {

		var prams = new Hash();
		
		if (ptype == 'L' || ptype == 'l') ptype = 'Land';
		if (ptype == 'M' || ptype == 'm') ptype = 'Multifamily';
		if (ptype == 'R' || ptype == 'r') ptype = 'Residential';

		prams.set('current_mlid',mlid);
		prams.set('result_type',ptype);
		prams.set('mlid',mlid);

		new Ajax.Updater('searchcontent','mlxsearch/searchDetail_ajax.cfm', {
			evalScripts:true
			,parameters: prams.toQueryString()
			,onComplete:function(){
				Lightview.updateViews();
				/**	
				if (map!=null) {
					GUnload();
				}
				*/	

				GMapLoad();
			}
		});

}
function refineSearch(fidSrc,fidDest) {

	$(fidDest).cp.value = 1;

	//update search field values only when something is specified

	if ($(fidSrc).strt1.value !='') $(fidDest).strt.value = $(fidSrc).strt1.value;
	if ($(fidSrc).zip1.value !='') $(fidDest).zip.value = $(fidSrc).zip1.value;
	if ($(fidSrc).kw1.value !='')$(fidDest).kw.value = $(fidSrc).kw1.value;
	if ($(fidSrc).mlid1.value) $(fidDest).mlid.value = $(fidSrc).mlid1.value;
	if ($(fidSrc).price11.value) $(fidDest).price1.value = $(fidSrc).price11.value;
	//$(fidDest).price2.value = $(fidSrc).price21.value;
	if ($(fidSrc).bdr1.value) $(fidDest).bdr.value = $(fidSrc).bdr1.value;
	if ($(fidSrc).bth1.value) $(fidDest).bth.value = $(fidSrc).bth1.value;
	if ($('srt1')!=null && $('rsp1')!=null) {
		$(fidDest).srt.value = $('srt1').value;
		$(fidDest).rsp.value = $('rsp1').value;
	}
	validateForm(fidDest);

}
function showResults(resulttype, fid, resetpaging) {
	//$('result_type').value=resulttype;
	$(fid).result_type.value=resulttype;
	//if (resetpaging) $('cp').value = 1;
	if (resetpaging) {
		$(fid).cp.value = 1;
		if ($('srt1')!=null && $('rsp1')!=null) {
			$(fid).srt.value = $('srt1').value;
			$(fid).rsp.value = $('rsp1').value;
		}
	}
	
	validateForm(fid,true);
}
function showPage(fid,page,resulttype){
	//$('cp').value = page;
	//$('result_type').value=resulttype;
	$(fid).cp.value = page;
	$(fid).result_type.value = resulttype;
	validateForm(fid);
}



function nwlarSearch(el,page,vars){
	setLoader(el);
	//new Ajax.Updater(el,page,{asynchronous:true,evalScripts:true,parameters:vars,method:'post',onComplete:function () {GMapLoad();}});	
	new Ajax.Updater(el,page,{asynchronous:true,evalScripts:true,parameters:vars,method:'post',onComplete:function () {GMapLoad();}});	
	return;
}
function sendToFriend(el,fid) {
		
	if ($(fid).from_name.value == '' || $(fid).to_name.value == '') {
		alert('Sender and Receiver Names may not be empty.');
		return false;
	}

	//if ( ! (isvalidemail( $(fid).from_email.value.trim() ) && isvalidemail( $(fid).to_email.value.trim() ) {
	if ( ! (isvalidemail( $(fid).to_email.value.trim() ) ) ) {
		alert('Please enter a valid Receiver Email.');
		return false;
	}

	ajax_update_vars(el,'/mlxsearch/searchEmailToFriend_ajax.cfm',Form.serialize($(fid)));
}

function isvalidemail(email) {
	return (! ( email == '' || email.split('@').length !=2 || email.split('.').length < 2)  )
}
function validateForm(fid) {
	var result = true;
	var vars = Form.serialize($(fid));
	if (result) {
			//ajax_update_vars('searchcontent','/custom_code_includes/mlxsearch/searchResults_ajax.cfm',Form.serialize($(fid)));

			if (arguments.length ==2 && arguments[1] == true) {
				nwlarSearch('searchcontent','mlxsearch/searchResults_ajax.cfm',Form.serialize($(fid)));
			} else {
				//ajax_update_vars('searchcontent','/custom_code_includes/mlxsearch/searchResults_ajax.cfm',Form.serialize($(fid)));
				nwlarSearch('searchcontent','mlxsearch/searchResults_ajax.cfm',Form.serialize($(fid)));
			}
			return;
	}
}

function getrecentlistings(fid,rdom) {
	$(fid).dom.value = rdom;
	validateForm(fid);		

}

function gettowncondos(fid,twncnd) {
	$(fid).thm.value = twncnd ;
	$(fid).result_type.value = 'Residential' ;
	validateForm(fid);

}
function showMap(id)
{
	//Effect.toggle(id, 'slide', { delay: 0.2 })
	$(id).style.display = ($(id).style.display == 'none') ? 'block' : 'none';
	chkResize();
	map.setCenter(new GLatLng(32.37494, -93.70333), 12);

}

function toggleLayer(id)
{
	//Effect.toggle(id, 'slide', { delay: 0.2 })
	$(id).style.display = ($(id).style.display == 'none') ? 'block' : 'none';

}

function swap(obj, imgTarget, lnkTarget) {
	document[imgTarget].src = obj.href;
}

function doBookMark(title,url) {

	bookmarkSite(title,url);
	$('bookmark').innerHTML = '<p>Property Added to Favorites.</p>';

}

function bookmarkSite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function showPrint(mlid,ptype) {
	
	//new Ajax.Request('/custom_code_includes/mlxsearch/searchPrintProperty.cfm',{parameters: Form.serialize($(fid))});	

	//popup('/custom_code_includes/mlxsearch/searchPrintProperty.cfm' + '?mlid=' +  mlid + '&ptype=' + ptype,800,800);	
	popup('mlxsearch/searchPrintProperty.cfm',800,800);	
}


/***
if(window.addEventListener) {
	//addEventListener("load", myload, true);
	addEventListener("unload", GUnload, true);
} else {
	if (window.attachEvent) {
				//attachEvent("onload",myload);
				attachEvent("onunload",GUnload);
	}
}
	
***/


//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06

var enabletabpersistence=1 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
if (thetab.getAttribute("rel"))
expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("a")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
}
} //end outer for loop
}


function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}

function calcDownPayment(){
	var f = document.calc;
	var price = stripNumber(f.property_value.value);
	var percent = stripNumber(f.percentage_down.value) / 100;

	f.down_payment.value = formatNumber(price * percent);
}

function calcDownPaymentPercent(){
	var f = document.calc;
	var price = stripNumber(f.property_value.value);
	var down = stripNumber(f.down_payment.value);
	var percent = down / price;

	f.percentage_down.value = Math.floor(percent * 100);
}

function calcMonthlyPayment(){
	var f = document.calc;
	var taxable_amount	= 0;
	var price = stripNumber(f.property_value.value);		// get price
	var down_payment = stripNumber(f.down_payment.value);	// get down payment

	// get interest rate and loan term - pre-populate if empty
	var interest_rate = (isNaN(stripNumber(f.interest_rate.value)) || f.interest_rate.value == "") ? 8.25 : stripNumber(f.interest_rate.value)
	var loan_term = (isNaN(stripNumber(f.loan_term.value)) || f.loan_term.value == "")  ? 30 : stripNumber(f.loan_term.value)

	var principle = price - down_payment;				// calc principle
	var m_interest_rate = (interest_rate / 100) / 12;	// calc monthly interest rate
	var	m_loan_term = loan_term * 12;					// calc monthly loan term

	// MONTHLY PAYMENT
	var monthly_payment = Math.floor((principle * m_interest_rate)/(1 - Math.pow((1 + m_interest_rate),(-1 * m_loan_term))) * 100) / 100;

	// populate fields
	f.property_value.value = formatNumber(price);
	f.down_payment.value = formatNumber(down_payment);
	f.interest_rate.value = interest_rate;
	f.loan_term.value = loan_term;
	f.monthly_mortgage_costs.value = formatNumber(monthly_payment);
	
	// MONTHLY INSURANCE
	var pmi_factor	= 0;
	
	if(f.percentage_down.value >= 0 && f.percentage_down.value <= 4.999)
		pmi_factor	= .0008;
	else if(f.percentage_down.value >= 5 && f.percentage_down.value <= 9.999)
		pmi_factor	= .00065;
	else if(f.percentage_down.value >= 10 && f.percentage_down.value <= 14.999)
		pmi_factor	= .00044;
	else if(f.percentage_down.value >= 15 && f.percentage_down.value <= 19.999)
		pmi_factor	= .00027;
	
	f.monthly_mi_costs.value	= formatNumber(Math.floor(pmi_factor * price));
	
	// HOME OWNER'S INSURANCE
	f.monthly_hi_costs.value	= formatNumber(Math.floor(.00045 * price));
	
	// homestead exemption is 75K
	if(price > 75000)
	  taxable_amount	= Math.floor(price) - 75000;
	else
	  taxable_amount	= 0;
	
	// PROPERTY TAXES - PARISH
	if(f.loc_parish.value == 'Caddo')
	  f.monthly_parish_costs.value	= formatNumber(Math.floor(.0012 * taxable_amount));
	
	else if(f.loc_parish.value == 'Bossier')
	  f.monthly_parish_costs.value	= formatNumber(Math.floor(.00083 * taxable_amount));
	  
	else
	  f.monthly_parish_costs.value	= 0; 
	  
	// PROPERTY TAXES - CITY
	if(f.loc_city.value == 'Shreveport')
	  f.monthly_city_costs.value	= formatNumber(Math.floor(.0004 * price));
	
	else if(f.loc_city.value == 'Bossier')
	  f.monthly_city_costs.value	= formatNumber(Math.floor(.0002 * price));
	  
	else
	  f.monthly_city_costs.value	= 0; 
		
	f.monthly_total_costs.value	= formatNumber(monthly_payment + Math.floor(f.monthly_mi_costs.value) + Math.floor(f.monthly_hi_costs.value) + Math.floor(f.monthly_city_costs.value) + Math.floor(f.monthly_parish_costs.value));
		
	if (f.total_loan_amount) f.total_loan_amount.value = formatNumber(principle);
	if (f.total_amount_repaid) f.total_amount_repaid.value = formatNumber(monthly_payment * m_loan_term);	
	
	// CLOSING COSTS
	f.closing_costs.value	= formatNumber(Math.floor(.0135 * (stripNumber(f.property_value.value) - stripNumber(f.down_payment.value)))   + 1200);
}


function stripNumber(val){
	val = val.replace(/[^0123456789.]/g, "");
	val = Number(val);

	return val;
}

function formatNumber(val){
	val = (val).toLocaleString();
	return val;
}

function clearSearch()
{
	document.mlxform.strt.value = "";
	document.mlxform.price1.value = "";
	document.mlxform.price2.value = "";
	document.mlxform.mlid.value = "";
	//document.mlxform.kw.value = "";
	document.mlxform.flrs.selectedIndex = 0;
	document.mlxform.bdr.selectedIndex = 0;
	document.mlxform.bth.selectedIndex = 0;
	document.mlxform.sqft1.selectedIndex = 0;
	//document.mlxform.sqft2.selectedIndex = 0;
	//document.mlxform.yearLessThan.selectedIndex = 0;
	document.mlxform.ltd1.checked = false;
	document.mlxform.ltd2.checked = false;
	//document.mlxform.ltd3.checked = false;
	//document.mlxform.ltd4.checked = false;
	document.mlxform.ltd5.checked = false;
	//document.mlxform.ltd6.checked = false;
	document.mlxform.ltd7.checked = false;
	document.mlxform.dom.value = "";
	//document.mlxform.pht.checked = false;
	document.mlxform.vrt.checked = false;
	document.mlxform.srt.selectedIndex = 0;
	document.mlxform.pl1.checked = false;
	document.mlxform.pl2.checked = false;
	document.mlxform.prsp1.selectedIndex = 0;
	document.mlxform.sch_dist.selectedIndex = 0;
	document.mlxform.strtnum.value = "";
	resetselect('sd');
}

function resetselect(objID)
{
	selObject = document.getElementById(objID);
	
	for (i=0;i<selObject.options.length;i++)
	{
		selObject.options[i].selected=false; 
	}
}