function isNull(aValue) {
	return((("" + aValue) == "null") && (aValue != "null") &&
	(("" + aValue) != "undefined") && (aValue != "undefined"));
}

function isUndefined(aValue) {
	return(("" + aValue) == "undefined");
}

function isEmpty(s) {
	return (isNull(s) || isUndefined(s) || (s.length == 0) || (s == ""))
}

// featured listings roll arrays
var _flimages  = new Array();
var _flmlsIds  = new Array();
var _flremarks = new Array();
var _flcities  = new Array();
var _flprices  = new Array();
var _fltypes   = new Array();
var _flagents  = new Array();
var _floffices = new Array();

// banner adroll arrays
var _baimages  = new Array();
var _baurls	= new Array();


function addNewFLImage(_name, _mlsId, _city, _remarks, _price, _type, _agent, _office) {
	_flimages[_flimages.length?_flimages.length:0] = new Image();
	_flimages[_flimages.length-1].src=_name;
	_flmlsIds[_flmlsIds.length]=_mlsId;
	_flremarks[_flremarks.length]=_remarks;
	_flprices[_flprices.length]=_price;
	_flcities[_flcities.length]=_city;
	_fltypes[_fltypes.length]=_type;
	_flagents[_flagents.length]=_agent;
	_floffices[_floffices.length]=_office;
}

function addNewBAImage(_name, _adurl) {
	_baimages[_baimages.length?_baimages.length:0] = new Image();
	_baimages[_baimages.length-1].src='http://www.gardencitymls.com/banneradimages/' + _name;
	_baurls[_baurls.length]=_adurl;
}

function goDetail() {
	getDetail(_flmlsId);
}

var FLLOCATION = 1; // should be reset by the calling page for different starting point
var BALOCATION = 1; // should be reset by the calling page for different starting point

function rotateFLImages(_direction) {
	FLLOCATION += _direction > 0 ? 1 : -1;
	if (FLLOCATION < 0) FLLOCATION = _flimages.length - 1;
	if (FLLOCATION >= _flimages.length) FLLOCATION = 0;
	var _x = FLLOCATION;

	if (_flimages.length > 0) {	
		document.rotateimg1.src=_flimages[_x].src;
	
		document.rotateimg1.alt="Details for MLS ID " + _flmlsIds[_x];
		_flmlsId = _flmlsIds[_x];
		document.forms['searchresults'].rotateline1.value=_flprices[_x];
		document.forms['searchresults'].rotateline2.value=_fltypes[_x];
		document.forms['searchresults'].rotateline3.value=_flcities[_x];
		document.forms['searchresults'].rotateline4.value="MLS ID "+_flmlsIds[_x];
		document.forms['searchresults'].rotateline5.value=_flagents[_x];
		document.forms['searchresults'].rotateline6.value=_floffices[_x];
	}
}

function rotateBAImages(_direction) {
	BALOCATION += _direction > 0 ? 1 : -1;
	if (BALOCATION < 0) BALOCATION = _baimages.length - 1;
	if (BALOCATION >= _baimages.length) BALOCATION = 0;
	
	_str = "";
	for (i = 0; i < 3; i++) {
		_x = BALOCATION + i;
		//_str += "_x=" + _x + "\n";
		if (_x >= _baimages.length) _x -= _baimages.length;
		//_str += "after check, _x=" + _x + "\n";
		//_str += "document.baimg" + i + ".src=_baimages[_x].src;\n";
		eval("document.baimg" + i + ".src=_baimages[_x].src;");
		//_str += "_baurl" + i + "=_baurls[_x];\n";
		eval("_baurl" + i + "=_baurls[_x];");
	}
	//alert(_str);
}

var fltimer = null;
var batimer = null;
function stopFLAutoRotate() {
	if (fltimer != null) {
		clearInterval(fltimer);
		fltimer = null;
	}
}

function stopBAAutoRotate() {
	if (batimer != null) {
		clearInterval(batimer);
		batimer = null;
	}
}

var FLINTERVAL = 5000;// 1 second = 1000 milliseconds.
var BAINTERVAL = 7000;// 1 second = 1000 milliseconds.
function startFLAutoRotate(_d) {
	_flmlsId = _flmlsIds[FLLOCATION]
	stopFLAutoRotate();
	if (_d > 0)
		fltimer=setInterval('rotateFLImages(+1)',FLINTERVAL);
	else
		fltimer=setInterval('rotateFLImages(-1)',FLINTERVAL);
}

function startBAAutoRotate(_d) {
	_baurl = _baurls[BALOCATION]
	stopBAAutoRotate();
	if (_d > 0)
		batimer=setInterval('rotateBAImages(+1)',BAINTERVAL);
	else
		batimer=setInterval('rotateBAImages(-1)',BAINTERVAL);
}
