var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		pre_hl_spd_save_icon_ro = newImage('images/hl_spd_save_icon_ro.gif');
		pre_hl_spd_share_icon_ro = newImage('images/hl_spd_share_icon_ro.gif');
		pre_hl_spd_adnote_icon_ro = newImage('images/hl_spd_adnote_icon_ro.gif');
		pre_hl_spd_rate_icon_ro = newImage('images/hl_spd_rate_icon_ro.gif');
		pre_hl_spd_pricealert_icon_ro = newImage('images/hl_spd_pricealert_icon_ro.gif');
		preloadFlag = true;
	}
}

function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}

function changeImages() {
	changeImagesArray(changeImages.arguments);
}

function toggleImages() {
	for (var i=0; i<toggleImages.arguments.length; i+=2) {
		if (selected == toggleImages.arguments[i])
			changeImagesArray(toggleImages.arguments[i+1]);
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
    function GotoProperty(idx, max)
    {
        val = getQuerystring("PropertyIdx");
        if(val != "")
        {
            newval = parseInt(val) + idx; 
            if(newval < 0) newval = 1;
            if(newval > (max -1)) newval = max - 1;
            querystring = ReplaceQueryString(location.href, "PropertyIdx", newval);
        }
        else
        {
            querystring = ReplaceQueryString(location.href, "PropertyIdx", "1");
        }
        location.replace(querystring)
    }
    
    function BackToResults()
    {
        queryString = ReplaceQueryString(location.search, "PropertyIdx", "");
        queryString = ReplaceQueryString(queryString, "PropertyItem", "");
        //queryString = ReplaceQueryString(queryString, "RecordType", "180");
        //alert(queryString);
        location.replace("PropertyResult.aspx" + queryString);
    }
    
    function GoRefineSearch() {
        var tab = getQuerystring("tab", "1");
        
        switch(parseInt(tab))
        {
            case 1: document.location.replace('PropertySearch.aspx' + location.search); break;
            case 2: document.location.replace('PropertySearchMap.aspx' + location.search); break;
            case 3: document.location.replace('PropertySearchSubdivision.aspx' + location.search); break;
            case 4: document.location.replace('PropertySearchRadius.aspx' + location.search); break;
            case 5: document.location.replace('PropertySearchAddress.aspx' + location.search); break;
            case 6: document.location.replace('PropertySearchOpenHome.aspx' + location.search); break;
            case 7: document.location.replace('PropertySearchSchool.aspx' + location.search); break;
            case 8: document.location.replace('PropertySearchPayment.aspx' + location.search); break;
        }
    }

    function Propertyprint()
    {   
        //location.replace("PropertyPrint.aspx" + location.search);
        window.open("PropertyPrint.aspx" + location.search,'Print','','');
    }

//    function SetShowingTime(BoardId, MlsNumber, Broker) {
//        var oImgShowingTime = new Image(10, 10);
//        oImgShowingTime.src = "http://links.showingtime.com/showingalert/images/wbShowingAlert_dtl.gif?SITEID=www.FIRSTREALTYAUBURN.com&broker=" + Broker + "MLSID=" + BoardId + "&listingid=" + MlsNumber + "&source=S";
    //    }


    function inArray(needle, haystack) {
        var key = '';
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
        return false;
    }
