// vc_id = "$Id: listView.js 12929 2010-04-20 19:38:14Z robert $"
var thsListingQueue = new listingQueue('lq',-23);
var LAST_MIN_PRICE = null;
var LAST_MAX_PRICE = null;
var basepath = APPIMAGES ? APPIMAGES + "/" : "images/";

var maxRentalArray = new Array();
var minRentalArray = new Array();
minRentalArray[0] = new Array(
		'No Min Price',
		new Option('$500', 500),
		new Option('$1,000', 1000),
		new Option('$2,000', 2000),
		new Option('$3,000', 3000),
		new Option('$5,000', 5000),
		new Option('$10,000', 10000));
maxRentalArray[0] = new Array(
		'No Max Price',
		new Option('$500', 500),
		new Option('$1,000', 1000),
		new Option('$2,000', 2000),
		new Option('$3,000', 3000),
		new Option('$5,000', 5000),
		new Option('$10,000', 10000));
var maxForSaleArray = new Array();
var minForSaleArray = new Array();
maxForSaleArray[0] = new Array(
		'No Max Price',
		new Option('$10,000', 10000),
		new Option('$20,000', 20000),
		new Option('$30,000', 30000),
		new Option('$40,000', 40000),
		new Option('$50,000', 50000),
		new Option('$60,000', 60000),
		new Option('$70,000', 70000),
		new Option('$80,000', 80000),
		new Option('$90,000', 90000),
		new Option('$100,000', 100000),
		new Option('$125,000', 125000),
		new Option('$150,000', 150000),
		new Option('$175,000', 175000),
		new Option('$200,000', 200000),
		new Option('$225,000', 225000),
		new Option('$250,000', 250000),
		new Option('$275,000', 275000),
		new Option('$300,000', 300000),
		new Option('$325,000', 325000),
		new Option('$350,000', 350000),
		new Option('$375,000', 375000),
		new Option('$400,000', 400000),
		new Option('$425,000', 425000),
		new Option('$450,000', 450000),
		new Option('$475,000', 475000),
		new Option('$500,000', 500000),
		new Option('$550,000', 550000),
		new Option('$600,000', 600000),
		new Option('$650,000', 650000),
		new Option('$700,000', 700000),
		new Option('$750,000', 750000),
		new Option('$800,000', 800000),
		new Option('$850,000', 850000),
		new Option('$900,000', 900000),
		new Option('$950,000', 950000),
		new Option('$1,000,000', 1000000),
		new Option('$1,100,000', 1100000),
		new Option('$1,200,000', 1200000),
		new Option('$1,300,000', 1300000),
		new Option('$1,400,000', 1400000),
		new Option('$1,500,000', 1500000),
		new Option('$1,600,000', 1600000),
		new Option('$1,700,000', 1700000),
		new Option('$1,800,000', 1800000),
		new Option('$1,900,000', 1900000),
		new Option('$2,000,000', 2000000),
		new Option('$3,000,000', 3000000),
		new Option('$4,000,000', 4000000),
		new Option('$5,000,000', 5000000),
		new Option('$6,000,000', 6000000),
		new Option('$7,000,000', 7000000),
		new Option('$8,000,000', 8000000),
		new Option('$9,000,000', 9000000),
		new Option('$10,000,000', 10000000));
minForSaleArray[0] = new Array(
		'No Min Price',
		new Option('$10,000', 10000),
		new Option('$20,000', 20000),
		new Option('$30,000', 30000),
		new Option('$40,000', 40000),
		new Option('$50,000', 50000),
		new Option('$60,000', 60000),
		new Option('$70,000', 70000),
		new Option('$80,000', 80000),
		new Option('$90,000', 90000),
		new Option('$100,000', 100000),
		new Option('$125,000', 125000),
		new Option('$150,000', 150000),
		new Option('$175,000', 175000),
		new Option('$200,000', 200000),
		new Option('$225,000', 225000),
		new Option('$250,000', 250000),
		new Option('$275,000', 275000),
		new Option('$300,000', 300000),
		new Option('$325,000', 325000),
		new Option('$350,000', 350000),
		new Option('$375,000', 375000),
		new Option('$400,000', 400000),
		new Option('$425,000', 425000),
		new Option('$450,000', 450000),
		new Option('$475,000', 475000),
		new Option('$500,000', 500000),
		new Option('$550,000', 550000),
		new Option('$600,000', 600000),
		new Option('$650,000', 650000),
		new Option('$700,000', 700000),
		new Option('$750,000', 750000),
		new Option('$800,000', 800000),
		new Option('$850,000', 850000),
		new Option('$900,000', 900000),
		new Option('$950,000', 950000),
		new Option('$1,000,000', 1000000),
		new Option('$1,100,000', 1100000),
		new Option('$1,200,000', 1200000),
		new Option('$1,300,000', 1300000),
		new Option('$1,400,000', 1400000),
		new Option('$1,500,000', 1500000),
		new Option('$1,600,000', 1600000),
		new Option('$1,700,000', 1700000),
		new Option('$1,800,000', 1800000),
		new Option('$1,900,000', 1900000),
		new Option('$2,000,000', 2000000),
		new Option('$3,000,000', 3000000),
		new Option('$4,000,000', 4000000),
		new Option('$5,000,000', 5000000),
		new Option('$6,000,000', 6000000),
		new Option('$7,000,000', 7000000),
		new Option('$8,000,000', 8000000),
		new Option('$9,000,000', 9000000),
		new Option('$10,000,000', 10000000));

/***
 * Uses above price arrays to populate min/max price objects based off of selection.
**/
function checkRentals (curVal) {

	var thisForm = document.forms['searchListingForm'];
	
	with (thisForm) {
		
		MaxPrice.options.length = 0;
		minPrice.options.length = 0;
		
		// if Rentals is checked
		if ((ptyp[5].checked) && (curVal == 6)) {
			// Set checked to false for all
			for (var i = 0; i < ptyp.length; i++) {
				ptyp[i].checked = false;
			}
			// Set Checked for rentals true
			ptyp[5].checked = true;
			
			// Change the font colors for the labels accordingly
			for (var p = 0; p < 5; p++) {
				document.getElementById('ptypFS' + p).style.color = '#666666';
			}
			document.getElementById('ptypRT0').style.color = '#000000';
			
			// Populate the price options with appropriate values based off of array
			for (var j = 0; j < maxRentalArray[0].length; j++) {
				
				if (isNumeric(maxRentalArray[0][j])) {
					MaxPrice.options[j] = maxRentalArray[0][j];
					minPrice.options[j] = minRentalArray[0][j];
				} else {
					MaxPrice.options[j] = new Option('No Max Price', '');
					minPrice.options[j] = new Option('No Min Price', '');
				}
			}
			
			MaxPrice.options[0].selected = true;
			minPrice.options[0].selected = true;
		} else {
			// Rentals checked = false
			ptyp[5].checked = false;
			
			// Check to see if any are checked (incase user unchecks rentals without checking something else)
			var oneChecked = 0;
			for (var i = 0; i < ptyp.length; i++) {
				if (ptyp[i].checked) {
					oneChecked = 1;
				}
			}
			
			// If user has simply unchecked rentals then default Residential
			if (oneChecked == 0) {
				ptyp[0].checked = true;
			}
			
			// Set label font colors appropriately
			for (var p = 0; p < 5; p++) {
				document.getElementById('ptypFS' + p).style.color = '#000000';
			}
			document.getElementById('ptypRT0').style.color = '#666666';
			
			// Populate Price options appropriately from array
			var thsCount = 0;
			var minPriceArrayKey = 0;
			var maxPriceArrayKey = 0;
			for (var j = 0; j < maxForSaleArray[0].length; j++) {
				if (isNumeric(maxForSaleArray[0][j])) {
					MaxPrice.options[j] = maxForSaleArray[0][j];
					minPrice.options[j] = minForSaleArray[0][j];
					
					// Because of how Safari handles the dynamic JS form option, I hold the values of the last selected price values.
					if (minForSaleArray[0][j].value == LAST_MIN_PRICE) {
						//alert(minForSaleArray[0][j].value + ' | ' + LAST_MIN_PRICE);
						minPriceArrayKey = j;
					}
					if (maxForSaleArray[0][j].value == LAST_MAX_PRICE) {
						//alert(minForSaleArray[0][j].value + ' | ' + LAST_MAX_PRICE);
						maxPriceArrayKey = j;
					}
				} else {
					MaxPrice.options[j] = new Option('No Max Price', '');
					minPrice.options[j] = new Option('No Min Price', '');
				}
			}
			// Because of how Safari handles the dynamic JS form option, I hold the values of the last selected price values.
			if ((LAST_MIN_PRICE != null) && (LAST_MIN_PRICE > 3000)) {
				minPrice.options[minPriceArrayKey].selected = true;
			} else {
				minPrice.options[0].selected = true;	
			}
			if ((LAST_MAX_PRICE != null) && (LAST_MAX_PRICE > 3000)) {
				MaxPrice.options[maxPriceArrayKey].selected = true;
			} else {
				MaxPrice.options[0].selected = true;
			}
		}
	}
	
}

function tTabs ( tabname ) {
	var  tabSearch = document.getElementById('tabSearch');
	var  tabProperty = document.getElementById('tabProperty');
	var contentSearch = document.getElementById('contentSearch');
	var contentProperty = document.getElementById('contentProperty');
	var tabOn = basepath + 'map/pp3TabOn.gif';
	var tabOff = basepath + 'map/pp3TabOff.gif';
	var clippingsOn = basepath + 'map/pp3TabClippingsOn.gif';

	if (tabname == 'Search') {
		document.getElementById('tabSearch').style.borderBottom = '1px solid #97b1d8';
		document.getElementById('tabProperty').style.borderBottom = '1px solid #000';
		document.getElementById('tabClippings').style.borderBottom = '1px solid #000';
		document.getElementById('tabSearch').style.color = '#000';
		document.getElementById('tabProperty').style.color = '#fff';
		document.getElementById('tabClippings').style.color = '#fff';
		document.getElementById('tabSearch').style.backgroundImage = "url('" + tabOn + "')";
		document.getElementById('tabProperty').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('tabClippings').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('contentSearch').style.display = 'block';
		document.getElementById('contentProperty').style.visibility = 'hidden';
		document.getElementById('contentProperty').style.display = 'none';
	} else if (tabname == 'Property') {
		document.getElementById('tabSearch').style.borderBottom = '1px solid #000';
		document.getElementById('tabProperty').style.borderBottom = '1px solid #97b1d8';
		document.getElementById('tabClippings').style.borderBottom = '1px solid #000';
		document.getElementById('tabSearch').style.color = '#fff';
		document.getElementById('tabProperty').style.color = '#000';
		document.getElementById('tabClippings').style.color = '#fff';
		document.getElementById('tabSearch').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('tabProperty').style.backgroundImage = "url('" + tabOn + "')";
		document.getElementById('tabClippings').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('contentSearch').style.display = 'none';
		document.getElementById('contentProperty').style.visibility = 'visible';
		document.getElementById('contentProperty').style.display = 'block';
	}
}

function showClippings(divID){
	if (divID == 'LQholder'){
		document.getElementById('LQholder').style.display = 'block';
		document.getElementById('LQholder').style.left = (findPosX(tabClippings) - 68) + 'px';
		document.getElementById('LQholder').style.top = (findPosY(tabClippings) + 25) + 'px';
		document.getElementById('LQholder').style.backgroundColor = '#FFFFFF';
		document.getElementById('LQholder').style.padding = 10 +'px';
		document.getElementById('LQholder').style.borderTop = 'none';
		document.getElementById('LQholder').style.borderRight = '1px solid black';
		document.getElementById('LQholder').style.borderBottom = '1px solid black';
		document.getElementById('LQholder').style.borderLeft = '1px solid black';	
	}
}

function resizeClippings(){ 
	if ((document.getElementById('LQholder')) && (document.getElementById('LQholder').style.display == 'block')) {
		showClippings('LQholder')
	}
}

function hideClippings(){
	var tabOff = basepath + 'map/pp3TabOff.gif';
	document.getElementById('LQholder').style.display = 'none';
	document.getElementById('tabClippings').style.backgroundImage = "url('" + tabOff + "')";
	document.getElementById('tabClippings').style.borderBottom = '1px solid #000';
	document.getElementById('tabClippings').style.color = '#fff';


}

function autoIframe(ths) {
	try{
		var frame = ths;
		var innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		var objToResize = (frame.style) ? frame.style : frame;
		objToResize.height = (innerDoc.body.scrollHeight + 10) + "px";
	}
	catch(err){
		window.status = err.message;
	}
}

function triggerPropertyDetails( url, frame, pid ) {
	currentTab = 'tabProperty';
	tTabs('Property');
	if (returnScrollHeight() > 125) { //header height
		window.location = '#lvTop';
	}
	document.getElementById('contentPropertyFrame').src = url;
}

function isNumeric(strString) {
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
 }

function returnScrollHeight () {
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0) {
		if (window.pageYOffset)
		ScrollTop = window.pageYOffset;
		else
		ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}

	return ScrollTop;
}
