
var images = new Array;
var linkObjs = new Array;
var divleft;
var divtop;
var firstAccess = false;

function decideMovieOrImage() {
    var flashObj = document.getElementById('movieObj');
    var homeImageObj = document.getElementById('imageObj');
    var flashinstalled = DetectFlashVer(6, 0, 0);
    if(flashinstalled) {
       	flashObj.style.display = 'block';
       	homeImageObj.style.display = 'none';
    } else {
       	flashObj.style.display = 'none';
       	homeImageObj.style.display = 'block';
    }
}

function cacheImages(tagName) {
	var singleImageSize = 100;
    images.length = 0;
    var divObj;
    var divObj1 = document.getElementById("thumbnailContainer1");
    var divObj2 = document.getElementById("thumbnailContainer2");
    if (divObj1 != null) {
        divObj = divObj1;
    } else {
        if (divObj2 != null) {
            divObj = divObj2;
        } else {
            return;
        }
    }
    var imageObjects = new Array;
    var childObj = divObj.childNodes[navigator.appName == 'Netscape' ? 1 : 0].getElementsByTagName('TD');
    linkObjs = divObj.childNodes[navigator.appName == 'Netscape' ? 1 : 0].getElementsByTagName('A');
    for (var i = 0; i < childObj.length; ++i) {
        images.push(childObj[i].firstChild);
    }
    if(images.length < 6) {
   		//divObj.style.width = singleImageSize * images.length + 'px';
 		
   		var height = null;   		
   		if(divObj.style.height.length > 0){
   			height = divObj.style.height.replace('px', '');
   		}else{
   			height = 133;
   		}
   		divObj.style.height = (height - 16) + 'px';
   	} 
}

/*
Right now, just used for the photo gallery pop up
*/
function cachePropertyImages() {
    images.length = 0;
    var divObj = document.getElementById("thumbnailContainer1");
   
    var imageObjects = new Array;
    var tds = divObj.childNodes[navigator.appName == 'Netscape' ? 1 : 0].getElementsByTagName('TD');

    for (var i = 0; i < tds.length; ++i) {
		var tdNode = tds[i].attributes.getNamedItem('thumbnail');
		if(tds[i].childNodes[navigator.appName == 'Netscape' ? 1 : 0].tagName == "IMG"){
			images.push(tds[i].childNodes[navigator.appName == 'Netscape' ? 1 : 0]);
		}else if(tds[i].childNodes[navigator.appName == 'Netscape' ? 1 : 0].tagName == "A"){
			linkObjs.push(tds[i].childNodes[navigator.appName == 'Netscape' ? 1 : 0]);
		}
    }
}

function cacheListingImages() {
    images.length = 0;
    var divObj = document.getElementById("thumbnailContainer");
    var imageObjects = new Array;
    var tdObjs = divObj.getElementsByTagName("input");
    for (var i = 0; i < tdObjs.length; ++i) {
        imageObjects.push(tdObjs[i]);
    }
    var nemImage = null;
    for (var i = 0; i < imageObjects.length; ++i) {
        nemImage = new Image(150, 150);
        nemImage.src = imageObjects[i].src;
        nemImage.alt = imageObjects[i].alt;
        images.push(nemImage);
    }
}

//Calls center on all of the popup controls
function updatePopupImageGallery() {
    var divLeft, divTop;
    centerControl(document.getElementById("listingForm:photoGalleryPopUp"), 400, 300);
    cacheListingImages();
}
function updatePopupHomeMovie() {
    var divLeft, divTop;
    centerControl(document.getElementById("listingForm:homeMoviePopUp"), 400, 300);
}

 
 //Centers the given control on the users visible screen
function centerControl(ctrlName, width, height) {
    var divLeft, divTop;
    var ctrl = document.getElementById(ctrlName);
    if (ctrl != null) {
        if (ctrl.style.display != "none") {
            if (document.documentElement != null) {
                divLeft = ((document.body.clientWidth - width) / 2) + document.body.scrollLeft;
                divTop = ((document.body.clientHeight - height) / 2) + document.body.scrollTop;
            } else {
                divLeft = ((document.body.clientWidth - width) / 2) + document.body.scrollLeft;
                divTop = ((document.body.clientHeight - height) / 2) + document.body.scrollTop;
            }
       //alert('Setting divLeft to ['+divLeft+'] and divTop to ['+divTop+']. Computed from clientHeight ['+document.documentElement.clientHeight+'] and scrollTop of ['+document.documentElement.scrollTop+']');
            ctrl.style.left = divLeft + "px";
            ctrl.style.top = divTop + "px";
        }
    }
}
var isStopped = true;
var timerId = -1;
var imageIndex = 0;
function getIndex(imageSrc) {
    for (var i = 0; i < images.length; ++i) {
        if (images[i].src.indexOf(imageSrc) >= 0) {
            return i;
        }
    }
    return -1;
}
function changeImage(formName, argument) {
    changeImages(formName, argument, true);
}
function changeImages(formName, argument, isDirectCall) {
    if (isDirectCall) {
        isStopped = true;
    }
    var imageContainer = document.getElementById(formName + ":imagePreviewContainer");
    var imageCaption = document.getElementById(formName + ":thumbnailCaption");
    if (images.length > 0) {
        if (isNaN(argument)) {
            imageIndex = getIndex(argument);
        } else {
            imageIndex = argument;
        }
        imageContainer.src = images[imageIndex].src;
        if (imageCaption != null) {
            imageCaption.innerHTML = images[imageIndex] != null ? images[imageIndex].alt : "";
        }
        clearBorder();
        images[imageIndex].style.border = "1px solid red";
        if(linkObjs.length > 0) {
            if(linkObjs[imageIndex] != null) {
                linkObjs[imageIndex].focus();
            } else {
                linkObjs[imageIndex].focus();
                resetScrollBar();
            }
        }
    }
}

function resetScrollBar() {
    var divObj = null;
    var divObj1 = document.getElementById("thumbnailContainer1");
    var divObj2 = document.getElementById("thumbnailContainer2");
    divObj = divObj1 == null ? divObj2 : divObj1;
    divObj.scrollLeft = 0;
}

function clearBorder() {
    for(var i=0;i<images.length;++i) {
        if(images[i].style != null)
            images[i].style.border = "1px solid white";
    }
}

function startSlideShow(formName) {
    imageIndex = imageIndex == 0 ? 0 : imageIndex;
    isStopped = false;
    start(formName);
}
function stopSlideShow() {
    isStopped = true;
    window.clearTimeout(timerId);
}
function next(formName) {
    clearBorder();
    if (images.length > 0) {
        imageIndex = imageIndex >= images.length - 1 ? 0 : imageIndex + 1;
        changeImage(formName, imageIndex);
    }
}
function previous(formName) {
    clearBorder();
    if (images.length > 0) {
        imageIndex = imageIndex <= 0 ? images.length - 1 : imageIndex - 1;
        changeImage(formName, imageIndex);
    }
}
function start(formName) {
    if (!isStopped && images.length > 0) {
        changeImages(formName, imageIndex, false);
        imageIndex = imageIndex + 1 >= images.length ? 0 : imageIndex + 1;
        timerId = window.setTimeout("start('" + formName + "')", 2000);
    }
}
function handlePreview(doFlag) {
    var previewDiv = document.getElementById("previewPanel");
    if (doFlag) {
        previewDiv.style.visibility = "";
    } else {
        previewDiv.style.visibility = "hidden";
    }
    window.status = previewDiv.style.visibility;
}
var map = null;
var pin = null;
function getFormElements() {
    var name = "";
    var eleArray = document.getElementsByTagName("input");
    for (var i = 0; i < eleArray.length; ++i) {
        name = name + " : " + eleArray[i].name;
    }
}
function initMap() {
    var divObj = document.getElementById("nemMap");
    if (divObj == null) {
        window.setTimeout("initMap()", 50);
    } else {
        GetMap();
    }
}
function initOfficeMap() {
    var divObj = document.getElementById("nemMap");
    if (divObj == null) {
        window.setTimeout("initOfficeMap()", 50);
    } else {
        GetOffDtlMap();
    }
}

function GetOfficeMap() {
    var latitude = document.getElementById("latitude").value;
    var longitude = document.getElementById("longitude").value;
    var officeAddress = document.getElementById("officeAddress").value;
    var officeTown = document.getElementById("officeTown").value;
    var officeState = document.getElementById("officeState").value;
    try {
        map = new VEMap("nemMap");
        map.SetDashboardSize(VEDashboardSize.Normal);
        if(latitude.length == 0 && longitude.length == 0) {
            if(officeAddress != "") {
    			officeAddress += ", ";
    		}
    		officeAddress += officeTown + " " + officeState;
		    if(officeAddress.length > 0) {
		    	map.LoadMap();
		    	map.Find(null, officeAddress, null, null, null, null, null, null, null, null, onFoundResults);

		    	//var imageURL = document.getElementById("imageURL").value;
    			//var thumnailImages = "<center><img id='pinImageCntr' src='" + imageURL + "' width='100px' height='75px' style='padding-bottom:5px'/></center><hr size='1'>";
		    	
		    	//pin = new VEPushpin(1, map.GetCenter(), "/images/icon_mappushpin.gif", 
		    	//officeAddress, thumnailImages +  "</font>", "nemIconStyle", "nemTitleStyle", "nemBodyStyle");
        		//map.AddPushpin(pin);
		    } else {
		    	//alert('why?');
		    	map.LoadMap();
		    }
        } else {
        	//alert('why2?');
        	map.LoadMap(new VELatLong(latitude, longitude), 13, "r", false, VEMapMode.Mode2D, true);
        	map.ShowDashboard();
        	createPushPin();
        }

    }
    catch (exception) {}
}


function loadMapByAddress() {
	var propertyAddress = document.getElementById("propertyAddress") != null ? document.getElementById("propertyAddress").value : "";
    var propertyTown = document.getElementById("propertyTown") != null ? document.getElementById("propertyTown").value : "";
    var propertyState = document.getElementById("propertyState") != null ? document.getElementById("propertyState").value : "";
    var zip = document.getElementById("zip") != null ? document.getElementById("zip").value : "";
    
    if(propertyAddress != "") {
    	propertyAddress += ", ";
    }
    propertyAddress += propertyTown + " " + propertyState;
//    alert('propertyAddress : '+propertyAddress);
    if(propertyAddress.length > 0) {
    	map.LoadMap();
    	map.Find(null, propertyAddress, null, null, null, null, null, null, null, null, GeocodeCallback);
    } else {
    	map.LoadMap();
    }
}

function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg) {
    if (places) {
	   var location = places[0].LatLong;   
	   var newShape = new VEShape(VEShapeType.Pushpin, location);
	   
	   var desc = "Latitude: " + location.Latitude + ", Longitude:" + location.Longitude;
       //alert('Description = '+desc);
       //newShape.SetDescription(desc);
   	   //newShape.SetTitle(bestPlace.Name);
       //map.AddShape(newShape);
       addPinByLatLong(location.Latitude, location.Longitude)
    
 	   //map.AddShape(new VEShape(VEShapeType.Pushpin,places[0].LatLong));
    }
    else alert("Could not find location!");
}

function onFoundResults(e) {
	if(e != null) {
		document.getElementById("latitude").value = e[0].LatLong.Latitude;
	    document.getElementById("longitude").value = e[0].LatLong.Longitude;
		addPin(2);
	}
}

//function dosearch() {
  //  map.Find(null, propertyAddress, null, null, null, null, null, null, null, true, onFound);
//}


function GetMap() {	
	var latitude = document.getElementById("latitude").value;
	var longitude = document.getElementById("longitude").value;
	try {
		map = new VEMap("nemMap");
		map.SetDashboardSize(VEDashboardSize.Normal);
	
		if(latitude.length == 0 && longitude.length == 0) {
			loadMapByAddress();
		} else {
			map.LoadMap(new VELatLong(latitude, longitude), 13, "r", false, VEMapMode.Mode2D, true);
			map.ShowDashboard();
			addPin(2);
		}
		
		if (map != null && document.getElementById("loggedIn").value == "false") {
			map.SetZoomLevel(9);
		} 
	}
	catch (exception) {}
}
function createPushPin() {
    var latitude = document.getElementById("latitude").value;
    var longitude = document.getElementById("longitude").value;
    var officeAddress = document.getElementById("officeAddress").value;
    var officeTown = document.getElementById("officeTown").value;
    var officeState = document.getElementById("officeState").value;
    var officeName = document.getElementById("officeName").value;
    var imageURL = document.getElementById("imageURL").value;
    var thumnailImages = "<center><img id='pinImageCntr' src='" + imageURL + "' width='100px' height='75px' style='padding-bottom:5px'/></center><hr size='1'>";
    pin = new VEPushpin(1, new VELatLong(latitude, longitude), 
               "/images/icon_mappushpin.gif",  officeAddress, thumnailImages +  "</font>", "nemIconStyle", "nemTitleStyle", "nemBodyStyle");
    map.AddPushpin(pin);
}
function zoom(flag) {
    if (flag) {
        map.ZoomIn();
    } else {
        map.ZoomOut();
    }
}
function changeMapType(mapTypeRadio) {
    map.SetMapStyle(mapTypeRadio.value);
}
function addPin(choice) {
    var latitude = document.getElementById("latitude").value;
    var longitude = document.getElementById("longitude").value;
    var propertyAddress = document.getElementById("propertyAddress") != null ? document.getElementById("propertyAddress").value : "";
    var propertyTown = document.getElementById("propertyTown") != null ? document.getElementById("propertyTown").value : "";
    var propertyState = document.getElementById("propertyState") != null ? document.getElementById("propertyState").value : "";
    var mlsNumber = document.getElementById("globalListingId") != null ? document.getElementById("globalListingId").value : "";
    var basePath = document.getElementById("basePath") != null ? document.getElementById("basePath").value : "";
    var imageURL = document.getElementById("imageURL") != null ? document.getElementById("imageURL").value : "";
    if (pin != null) {
        map.DeleteAllPushpins();
        pin = null;
    }
    if (choice == 1) {
        pin = new VEPushpin(2, new VELatLong(latitude, longitude), null, mlsNumber, propertyAddress + ", " + propertyTown + ", " + propertyState);
    } else {
		var thumnailImages = "<center><img id='pinImageCntr' src='" + imageURL + "' width='100px' height='75px' style='padding-bottom:5px'/></center><hr size='1'>";
		propertyAddress = propertyAddress.toLowerCase();
		propertyTown = propertyTown.toLowerCase();
		propertyAddress = "<font style='text-transform:capitalize;'>" + propertyAddress
        propertyAddress += ', ' + propertyTown + ', ' + propertyState + "</font>";
        thumnailImages += "<font style='color:#003366;font-size:11px;'>";
        pin = new VEPushpin(1, new VELatLong(latitude, longitude), 
            basePath + "/images/icon_mappushpin.gif",  propertyAddress, thumnailImages +  'MLS# ' + mlsNumber + "</font>", "nemIconStyle", "nemTitleStyle", "nemBodyStyle");
    }
    map.AddPushpin(pin);
}
function addPinByLatLong(latitude, longitude) {
    var propertyAddress = document.getElementById("propertyAddress") != null ? document.getElementById("propertyAddress").value : "";
    var propertyTown = document.getElementById("propertyTown") != null ? document.getElementById("propertyTown").value : "";
    var propertyState = document.getElementById("propertyState") != null ? document.getElementById("propertyState").value : "";
    var mlsNumber = document.getElementById("globalListingId") != null ? document.getElementById("globalListingId").value : "";
    var basePath = document.getElementById("basePath") != null ? document.getElementById("basePath").value : "";
    var imageURL = document.getElementById("imageURL") != null ? document.getElementById("imageURL").value : "";
    if (pin != null) {
        map.DeleteAllPushpins();
        pin = null;
    }
    
	var thumnailImages = "<center><img id='pinImageCntr' src='" + imageURL + "' width='100px' height='75px' style='padding-bottom:5px'/></center><hr size='1'>";
	propertyAddress = propertyAddress.toLowerCase();
	propertyTown = propertyTown.toLowerCase();
	propertyAddress = "<font style='text-transform:capitalize;'>" + propertyAddress
    propertyAddress += ', ' + propertyTown + ', ' + propertyState + "</font>";
    thumnailImages += "<font style='color:#003366;font-size:11px;'>";
    pin = new VEPushpin(1, new VELatLong(latitude, longitude), 
           basePath + "/images/icon_mappushpin.gif",  propertyAddress, thumnailImages +  'MLS# ' + mlsNumber + "</font>", "nemIconStyle", "nemTitleStyle", "nemBodyStyle");
   
    map.AddPushpin(pin);
}
function changePinImage(imgCntr) {
    var imgPrvCntr = document.getElementById("pinImageCntr");
    imgPrvCntr.src = imgCntr.src;
}
function getRoute() {
    var propertyAddress = document.getElementById("propertyAddress").value;
    var propertyTown = document.getElementById("propertyTown").value;
    var propertyState = document.getElementById("propertyState").value;
    var toAddress = propertyAddress + ', ' + propertyTown + ', ' + propertyState;
    
    var address = document.getElementById("address").value;
    var latitude = document.getElementById("latitude").value;
    var longitude = document.getElementById("longitude").value;
    map.GetRoute(address,toAddress, null,null,onGotRoute);
}


function getOfficeRoute() {
    var propertyAddress = document.getElementById("officeAddress").value;
    var propertyTown = document.getElementById("officeTown").value;
    var propertyState = document.getElementById("officeState").value;
    var toAddress = propertyAddress + ', ' + propertyTown + ', ' + propertyState;
    
    var address = document.getElementById("address").value;
    var latitude = document.getElementById("latitude").value;
    var longitude = document.getElementById("longitude").value;
    map.GetRoute(address,toAddress, null,null,onGotRoute);
}


function onGotRoute(route) {
    var routeinfo="<b>Route info:</b><br/>";
    routeinfo+="Total distance: ";
    routeinfo+=   "<b>" +  route.Itinerary.Distance+" ";
    routeinfo+=   route.Itinerary.DistanceUnit+"</b><br/>";
    var steps="";
    var len = route.Itinerary.Segments.length;
    steps += "<table>";
    for(var i = 0; i < len ;i++) {
        steps+= "<tr><td style='padding-right:5px;'>" + eval(i+1) + '. ' + "</td><td>";
        steps+="<font style='font-size:11px;'>" + route.Itinerary.Segments[i].Instruction+" -- (";
        steps+=route.Itinerary.Segments[i].Distance+") ";
        steps+=route.Itinerary.DistanceUnit+"</font></td></tr>";
    }
    routeinfo+="<b>Steps:</b><br/>"+steps;
    var divObj = document.getElementById("directionsDiv");
    divObj.style.display = "block";
    var tdObj = document.getElementById("directionsTD");
    tdObj.innerHTML = routeinfo;
}

function closeDirectionsPopup() {
    var divObj = document.getElementById("directionsDiv");
    divObj.style.display = "none";
}


function removeText(inputObj) {
    if (inputObj.value == "Enter City, address, or landmark") {
        inputObj.value = "";
        inputObj.style.color = "black";
    }
}
function putText(inputObj) {
    if (inputObj.value.length == 0) {
        inputObj.value = "Enter City, address, or landmark";
        inputObj.style.color = "gray";
    }
}
function mailMe(linkObj, email) {
    this.location = "mailto:" + email;
    return true;
}
function togglePointer(selectedTD) {
    var tdObj = document.getElementById(selectedTD);
    var trObj = tdObj.parentNode;
    var imageSrc = '';
    var tempTdObj = null;
    for (var j = 0; j < trObj.childNodes.length; ++j) {
        tempTdObj = trObj.childNodes[j];
        if (tempTdObj.childNodes[tempTdObj.childNodes.length - 1].nodeName == "/IMG") {
            imageSrc = tempTdObj.childNodes[tempTdObj.childNodes.length - 2].src;
            tempTdObj.removeChild(tempTdObj.childNodes[tempTdObj.childNodes.length - 2]);
        }
    }
    if (tdObj.childNodes.length == 5) {
        tdObj.removeChild(tdObj.childNodes[tdObj.childNodes.length - 2]);
        appendPointerImage(tdObj,imageSrc);
    } else {
        appendPointerImage(tdObj,imageSrc);
    }
    togglePropertyTabs("4", 6);
}
function appendPointerImage(tdObj,imageSrc) {
    var pointerImg = document.createElement("img");
    pointerImg.src = imageSrc;
    pointerImg.width = 32;
    pointerImg.height = 10;
    tdObj.appendChild(pointerImg);
}
function emailFriend(gid) {
    var body = "Take a look at this property I found on ColdwellBanker.com:\n" + window.location.href;
    this.location = "mailto:" + " " + "?subject=ColdwellBanker.com Listing #" + gid + "&body=" + body;
}
function changeStateandTowns() {
    var zip = document.getElementById("qSearchForm:qSearchTabSet:zip").value;
    if (zip != null && zip.length > 0) {
        document.getElementById("qSearchForm:qSearchTabSet:state").disabled = true;
        document.getElementById("qSearchForm:qSearchTabSet:town").disabled = true;
    } else {
        document.getElementById("qSearchForm:qSearchTabSet:state").disabled = false;
        document.getElementById("qSearchForm:qSearchTabSet:town").disabled = false;
    }
}
function changeZipbyState() {
    var state = document.getElementById("qSearchForm:qSearchTabSet:state").value;
    var townObj = document.getElementById("qSearchForm:qSearchTabSet:town");
    townObj.value = "";
    var town = townObj.value;
    if ((state == null && town == null)) {
        document.getElementById("qSearchForm:qSearchTabSet:zip").disabled = false;
    } else {
        if (state == "-1" && town.length == 0) {
            document.getElementById("qSearchForm:qSearchTabSet:zip").disabled = false;
        } else {
            document.getElementById("qSearchForm:qSearchTabSet:zip").disabled = true;
        }
    }
}
function changeZipbyTown() {
    var state = document.getElementById("qSearchForm:qSearchTabSet:state").value;
    var town = document.getElementById("qSearchForm:qSearchTabSet:town").value;
    if ((state == null && town == null)) {
        document.getElementById("qSearchForm:qSearchTabSet:zip").disabled = false;
    } else {
        if (state == "-1" && town.length == 0) {
            document.getElementById("qSearchForm:qSearchTabSet:zip").disabled = false;
        } else {
            document.getElementById("qSearchForm:qSearchTabSet:zip").disabled = true;
        }
    }
}
var selectedPropertyTabIndex = 0;
function togglePropertyTabs(tabIndex, tabCount) {
    //alert(tabIndex +  " : " + tabCount);
    var propertyTabCount = 0;
    for (var i = 0; i < tabCount; i++) {
        var tabObj = document.getElementById("tab" + i);
        if (tabObj == null) {
            continue;
        }
        propertyTabCount++;
    }
    for (var i = 0; i < propertyTabCount; i++) {
        deactivateTab(i, propertyTabCount);
    }
    activateTab(parseInt(tabIndex), propertyTabCount);
    selectedPropertyTabIndex = tabIndex;
    /*if (tabIndex == 1) {
        GetMap();
    }*/
}
function activateTab(tabIndex, tabCount) {
    var tabObj = document.getElementById("tab" + tabIndex);
    if(tabObj != null) {
        tabObj.className = "nemTabSetTabOn";
    }
    var tabSep_1 = document.getElementById("tabSeparator" + tabIndex);
    if(tabSep_1 != null) {
        if (tabIndex == 0) {
            tabSep_1.className = "nemTabSetTabSeparatorLA";
        } else {
            tabSep_1.className = "nemTabSetTabSeparatorMIA";
        }
    }
    
    var tabSep_2 = document.getElementById("tabSeparator" + (tabIndex + 1));
    if(tabSep_2 != null) {
        if (tabIndex < tabCount) {
            tabSep_2.className = "nemTabSetTabSeparatorMAI";
        } else {
            tabSep_2.className = "nemTabSetTabSeparatorRA";
        }
    }
}

function deactivateTab(tabIndex, tabCount) {
    var tabObj = document.getElementById("tab" + tabIndex);
    if(tabObj != null) {
        tabObj.className = "nemTabSetTabOff";
    }
        
    var tabSep_1 = document.getElementById("tabSeparator" + tabIndex);
    if(tabSep_1 != null) {
        if (tabIndex == 0) {
            tabSep_1.className = "nemTabSetTabSeparatorLI";
        } else {
            tabSep_1.className = "nemTabSetTabSeparatorMII";
        }
    }
    
    var tabSep_2 = document.getElementById("tabSeparator" + (tabIndex + 1));
    if(tabSep_2 != null) {
        if (tabIndex < tabCount) {
            tabSep_2.className = "nemTabSetTabSeparatorMII";
        } else {
            tabSep_2.className = "nemTabSetTabSeparatorRI";
        }
    }
}
function refresh() {
    window.location.reload();
}
function toggleqSearchTabs(tabIndex, tabCount) {
    for (var i = 0; i < tabCount; i++) {
        deactivateTab(i, tabCount);
    }
    activateTab(parseInt(tabIndex), tabCount);
}
function toggleOffDirSearchTabs(tabIndex, tabCount) {
    for (var i = 0; i < tabCount; i++) {
        deactivateTab(i, tabCount);
    }
    activateTab(parseInt(tabIndex), tabCount);
}
function toggleOffDtlTabs(tabIndex, tabCount) {
    for (var i = 0; i < tabCount; i++) {
        deactivateTab(i, tabCount);
    }
    activateTab(parseInt(tabIndex), tabCount);
}
function validatePropertyType() {
    var propertyTypeObj = null;
    var selected = false;
    propertyTypeObj = document.getElementsByName('advancedPropertySearch:propertyType');
    for (var i =0; i < propertyTypeObj.length; ++i) {
        if (propertyTypeObj[i].checked) {
            selected = true;
            break;
        }
    }
    var propertyTypeDiv = document.getElementById("propertyTypeDiv");
    var propertyTypeErrorMsg = document.getElementById("advancedPropertySearch:propertyTypeErrorMsg");
    if (!selected) {
        propertyTypeDiv.style.border = "1px solid red";
        propertyTypeErrorMsg.style.display = "inline";
        return false;
    } else {
        propertyTypeDiv.className = "none";
        propertyTypeErrorMsg.style.display = "none";
        return true;
    }
}
function displayPriceError(errorCompIds) {
    var errorComp = null;
    var index = errorCompIds.indexOf("|");
    if (index > 0) {
        do {
            errorCompIds = errorCompIds.substring(0, index);
            errorComp = document.getElementById(errorCompIds + "ErrorDiv");
            errorComp.className = "ErrorStyle";
            index = errorCompIds.indexOf("|");
        } while (index > 0);
    }
}
function checkPlayerSetting(playBtn) {
    var divObj = document.getElementById("playerTypeErrorDiv");
    var tableObj = divObj.childNodes[2];
    var errorText = divObj.childNodes[0];
    var tds = tableObj.getElementsByTagName("TD");
    if (tds[0].firstChild.checked || tds[1].firstChild.checked) {
        divObj.className = "nonErrorStyle";
        errorText.style.display = "none";
        playBtn.disabled = true;
        return true;
    } else {
        divObj.className = "ErrorStyle";
        errorText.style.display = "inline";
        playBtn.disabled = false;
        return false;
    }
}

function validateMLS() {
    var mlsObj = document.getElementById('qSearchForm:mlsId');
    var mlsNumber = mlsObj.value;
    var tdobj = document.getElementById('mlsErrorTD');
    if(isNaN(parseInt(mlsNumber)) || mlsNumber < 0) {
        tdobj.style.display = 'block';
        return false;
    } else {
        tdobj.style.display = 'none';
        return true;
    }
}

//***********THE BELOW SCRIPT IS FOR THE IMAGE MOUSEOVERS**************

icona = new Image()   
icona.src = "/images/menu/btn_propsearch_on.gif"  

iconb = new Image()
iconb.src = "/images/menu/btn_propsearch_off.gif"

iconc = new Image()   
iconc.src = "/images/menu/btn_salesassoc_on.gif"  

icond = new Image()
icond.src = "/images/menu/btn_salesassoc_off.gif"

icong = new Image()   
icong.src = "/images/menu/btn_relocation_on.gif"  

iconh = new Image()
iconh.src = "/images/menu/btn_relocation_off.gif"

iconi = new Image()   
iconi.src = "/images/menu/btn_ourservices_on.gif"  

iconj = new Image()
iconj.src = "/images/menu/btn_ourservices_off.gif"

iconk = new Image()   
iconk.src = "/images/menu/btn_careers_on.gif"  

iconl = new Image()
iconl.src = "/images/menu/btn_careers_off.gif"

iconm = new Image()   
iconm.src = "/images/menu/btn_officesearch_on.gif"  

iconn = new Image()
iconn.src = "/images/menu/btn_officesearch_off.gif"

function imageChange(imgName,imgSrc){
document.images[imgName].focus();
document.images[imgName].src = eval(imgSrc +".src")
}

function sfHover() {
	var sfEls = document.getElementById('mainNav').getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(" sfhover", "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

  $(document).ready(function(){ 
        $("ul.mainNavSubMenu").bgIframe({left:30}); 
    });

//***********THE ABOVE SCRIPT IS FOR THE IMAGE MOUSEOVERS**************
    
//This function (pop) opens a daughter-window in the center of the screen

function popWin(windowName, loc, w, h, setToolbar, setLocation, setDirectories, setStatus, setMenubar, setScrollbars, setResizable, setCopyhistory)

{



  // Determine pop-up position to center on screen

  LeftPosition = (screen.availWidth) ? (screen.availWidth-w)/2 : 0;

  TopPosition = (screen.availHeight) ? (screen.availHeight-h)/2 : 0;


  settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar='+setToolbar+',location='+setLocation+',directories='+setDirectories+',status='+setStatus+',menubar='+setMenubar+',scrollbars='+setScrollbars+',resizable='+setResizable+',copyhistory='+setCopyhistory;


  var opp = window.open(loc, windowName, settings);
  opp.focus();

}

/**
  * Opens the location in the window that opened this one.  If no
  * such window exists, a new window is opened.
  */
  function popUpOpener(location, title) {
   if (window.opener && !window.opener.closed) {
      window.opener.location = location;
      window.opener.focus();
   
    } else {
      popWin(title, location, 800, 600, "yes", "yes", "no", "no", "no", "yes", "yes", "no");
    }
  }

function popNeighborhood()
{
  popWin("eneighborhood", 'http://www.onboardnavigator.com/webContent/OBWC_Results.aspx?AID=127-8fcbcd0035b6&SearchType=1&DataType=1', 645, 560, "yes", "no", "no", "yes", "yes", "yes", "yes", "no");
}

function popSchoolInfo()
{
  popWin("eneighborhood", 'http://www.onboardnavigator.com/webContent/OBWC_Search.aspx?&AID=127-8fcbcd0035b6&CD_SID=SC001', 645, 560, "yes", "no", "no", "yes", "yes", "yes", "yes", "no");
}

function scrollToTop() {
    document.body.scrollTop = 0;
    var btn = document.getElementById('listingForm:upperSortSubmit');
    var btn1 = document.getElementById('listingForm:upperSaveSearch');
    if(btn != null) {
        btn.focus();
        btn1.focus();
    }
}

function closeMoviePopUp(actionName) {
    var div = null;
    if(actionName == 'officeSearch') {
        div = document.getElementById('officeDetailForm:viewOffDetailsTabSet:homeMoviePopUp');
    } else {
        div = document.getElementById('listingForm:homeMoviePopUp');
    }
    div.style.visibility='hidden';
    firstAccess = false;
}

function closePhotoGalleryPopUp(actionName) {
    var div = null;
    if(actionName == 'officeSearch') {
        div = document.getElementById('officeDetailForm:viewOffDetailsTabSet:photoGalleryPopUp');
    } else {
        div = document.getElementById('listingForm:photoGalleryPopUp');
    }
    div.style.visibility='hidden';
    firstAccess = false;
}

function adjustWidth() {
    var imgObj = document.getElementById('topBoder');
    if(imgObj != null) {
        if(navigator.appName == 'Netscape') {
            imgObj.style.display = "none";
        } else {
            imgObj.width = "100%";
        }
    }
}

function popOtherWebsite(name, url)
{

  popWin(name, url, 640, 580, "yes", "no", "no", "yes", "yes", "yes", "yes", "no");

}

function popOtherWebsite(name, url, width, height)
{

  popWin(name, url, width, height, "yes", "no", "no", "yes", "yes", "yes", "yes", "no");

}
function cover(topObjectId, bottomObjectId) {
	var topObject = document.getElementById(topObjectId);
	var bottomObject = document.getElementById(bottomObjectId);
	
	if(topObject && bottomObject) {
		topObject.style.left = bottomObject.style.left;
		topObject.style.top = bottomObject.style.top;
		topObject.style.zIndex = 1000;
		topObject.style.display = "block";
	}
}

function clearQuickSearchForm() {
	var selectFieldArray = ['qSearchForm:state','qSearchForm:propertyType','qSearchForm:baths','qSearchForm:baths','qSearchForm:beds','qSearchForm:priceLowerLimit'];
	document.getElementById('qSearchForm:town').value = 'Select a State';
	document.getElementById('qSearchForm:town').disabled = true;
	document.getElementById('qSearchForm:zip').value = '';
	document.getElementById('qSearchForm:mlsId').value = '';
	document.getElementById('qSearchForm:onlyOpenHouses').checked=false;
	document.getElementById('qSearchForm:newListing').checked=false;
	
	for(var i =0;i<selectFieldArray.length;++i) {
		resetSelectBox(selectFieldArray[i],0);
	}
	
	var priceUpperObj = document.getElementById('qSearchForm:priceUpperLimit');
	priceUpperObj.options[priceUpperObj.options.length-1].selected = true;
}

function resetSelectBox(fieldId,newSelection) {
	var  fieldObj = document.getElementById(fieldId);
	if(fieldObj != null) {
		fieldObj.options[0].selected = true;
	}
}

function clearAssociateQuickSearchForm() {
	document.getElementById('qSearchForm:firstName').value = '';
	document.getElementById('qSearchForm:lastName').value = '';
}

function clearOfficeQuickSearchForm() {
	resetSelectBox("qSearchForm:officeState",0);
	document.getElementById('qSearchForm:officeTown').value = 'Select a State';
	document.getElementById('qSearchForm:officeTown').disabled = true;
}

/* 
Given one sort by field, this function derives the other and sets 
it's selected index to the same as the provided 
*/
function syncronizeSortBy(selectObject){
	//Array, splits at the ":" in JSF component ids
	var idArray = selectObject.id.split(":");
	var formId = idArray[0];
	var selectId = idArray[1];
	var otherSelectId = '';
	
	if(selectId.indexOf("upper") > -1){
		otherSelectId = selectId.replace("upper","lower");
	}else{
		otherSelectId = selectId.replace("lower","upper");
	}
	var otherSelectObject = document.getElementById(formId + ":" + otherSelectId);
	otherSelectObject.selectedIndex = selectObject.selectedIndex;
}