// TIPS .. Like to find a Better way of doing this
var rspsavedsearchtips = new Array()
rspsavedsearchtips[0] = "Display Properties in a Saved Search by clicking on it's title";

var redbpropertytrackertips = new Array()
redbpropertytrackertips[0] = "View Saved Properties by Clicking on the Price or Image";

// JQUERY ONLOAD FUNCTION
$(document).ready(function(){	
	if ($.browser.msie && $.browser.version >= 7 || $.browser.mozilla){
		$("#redbsearchtools").corner("5px");
		$("#redbstatusbar").corner("5px");	
	}
	
	$("#redbsearchtoolbar a").click(function () {
		toggleREDBPanels($(this).attr("name"));
    	return false;
	});
	//Prepare the Panels
	toggleREDBPanels();
	
	
	//$("#dfields #listingtype option[value=res]").attr("selected",true);
	//$("#listingtype option[text=Residential]").attr("selected",true);
	//if(_citytownname) $("#citytownname option[value="+_citytownname+"]").attr("selected",true);
	
	if ( !typeof  _mlnum == "undefined" && _mlnum) $("#dfields #mlnum").val(_mlnum);
	if ( !typeof  _baths == "undefined" && _baths) $("#dfields #baths option[value="+_baths+"]").attr("selected",true);
	if ( !typeof  _beds == "undefined" && _beds)  $("#dfields #beds option[value="+_beds+"]").attr("selected",true);
	if ( !typeof  _minlp == "undefined" && _minlp) $("#dfields #min_listprice option[value="+_minlp+"]").attr("selected",true);
	if ( !typeof  _maxlp == "undefined" && _maxlp) $("#dfields #max_listprice option[value="+_maxlp+"]").attr("selected",true);
	
	if( !typeof  _quad == "undefined" && _quad){
		$("#dfields #citytownname option[value="+_quad+"]").attr("selected",true);
		 popSelectSP('redbab.communities','redblud_val','redblud_desc','id',_quad,'district','redblud_desc');
		 $("#citytownname").attr("name","notneeded"); 
	}
	
	if( !typeof  _listingtype == "undefined" && _listingtype){
		if(_propclass=="@COND") $("#dfields #listingtype option[text=Condo]").attr("selected",true);
		else {
			if(_listingtype="res") $("#dfields #listingtype option[text=Single Family]").attr("selected",true);
			else $("#dfields #listingtype option[value="+_listingtype+"]").attr("selected",true);
		}
	}


	
});
function popSelectSP(tb,val,name,fltf,filtv,opt,or){
	$.getJSON("/php-bin/gmaps_ab.php",{overlord: "gfilters", tb: tb, val: val, name: name, fltf: fltf, filtv : filtv, ord: or },function(j){
           	var optn = '';
			optn += '<option value="">Select Community </option>';
			for (var i = 0; i < j.length; i++) {
				optn += '<option value="@' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}	
			$('#'+opt).html(optn);
			if(_district) $("#dfields #district option[value="+_district+"]").attr("selected",true);
        })

}
//TOGGLE PANELS
function toggleREDBPanels(panel){
	$("#redbsearchpanels > div").hide();
	(!panel) ? panel="redbquicksearchpanel" : panel=panel+"panel" ;
	$("#"+panel).show();
	switch (panel){
		case "redbquicksearchpanel":
			$("#redbquicksearchcontainer").show();
		break;
		case "redbsavedsearchespanel":
			getREDBAjaxContent("/php-bin/index_ab.php?overlord=ListSavedSearch", "redbsavedsearchescontainer")
			$("#redbstatusbar").inlineTip(rspsavedsearchtips);
		break;
		case "redbpropertytrackerpanel":
			getREDBAjaxContent("/php-bin/index_ab.php?overlord=ListSavedProperty", "redbpropertytrackercontainer")
			$("#redbstatusbar").inlineTip(redbpropertytrackertips);	
		break;
	}
}

// DELETE COOKIE - DEBUG
function deletecookie(){
	redbsearchtoolscookiejar.destroy()
}
// PRELOADER
var imagesLoaded = 0;
function increaseImageLoadCount(){
	imagesLoaded++
	if(imagesLoaded == $("#redbdetailedviewslideshowcontainer img").not(".ldrgif").size()){
		$("#redbdetailedviewslideshowcontainer").slideView();
	}
}
// AJAX FUNCTIONS
function getREDBAjaxContent(contenturl,dest){
	$.ajax({
		url: contenturl,
		cache: false,
		success: function(data) {
			$('#'+dest).empty();
			$('#'+dest).html(data);
		}
	});
}
function delete_ss(dest){
	$.ajax({
			url: dest,
			beforeSend: function(){
				$(dest).html('<ul><li><img src="/gssi/redb/new/i/ajax-loader.gif" alt="loading"></li></ul>');	
			},
			cache: false,
			success: function(data) { 
				$('#redbsavedsearchescontainer').empty();
				$('#redbsavedsearchescontainer').html(data);
							
			}
		});	
}
<!--Delete Saved Property-->
function delete_sp(dest){
	$.ajax({
			url: dest,
			cache: false,
			success: function(data) { 
				$('#redbpropertytrackercontainer').empty();
				$('#redbpropertytrackercontainer').html(data);
			
			}
		});	
}