/* Update jul 30 10:29 a*/

function trim (str) {
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
/* Check at startup to see if the javascript logger is running */
if (document.getElementById('myLogger')){
	var myConfigs = {
	    width: "150em",
	    height: "30em",
	    newestOnTop: true,
	    footerEnabled: true
	};
	var myLogReader = new YAHOO.widget.LogReader("myLogger", myConfigs);
		myLogReader.show();
		
	/* check to see if the console is avalable. If not then don't log to it. */
	if(window.console) {
		YAHOO.widget.Logger.enableBrowserConsole();
	} 
}

/* Yuk browser detection but needed to work well */
var mobile = false, ua = navigator.userAgent, m;

if (YAHOO.env.ua.webkit) {
	if (/ Mobile\//.test(ua)) {
		mobile = "iPhone";
	} else {
		m=ua.match(/NokiaN[^\/]*/);
		if (m) {
			mobile = m[0]; // Nokia N-series, ex: NokiaN95
		}
	}
} else if (YAHOO.env.ua.opera) {
	m=ua.match(/Opera Mini[^;]*/);
	if (m) {
		mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
	}
}
if (YAHOO.env.ua.ie === 7) {
	YAHOO.util.Dom.addClass(document.body, "ie7");
}

/* Instantiate and render the menu bar */
var oMenuBar = new YAHOO.widget.MenuBar("productsandservices", { autosubmenudisplay: true, hidedelay: 750, lazyload: true });

/*
	 Call the "render" method with no arguments since the markup for 
	 this menu already exists in the DOM.
*/

oMenuBar.render();

/* Added hide then show after render to fix IE 7 bug that causes menubar to not render right. */

YAHOO.util.Event.on(window, "focus", function () {
	oMenuBar.hide();
	oMenuBar.show();
});
/* fix for ie6 flickering of background elements */
try {
document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}



var ua = YAHOO.env.ua,
    oAnim;  // Animation instance


/*
     "beforeshow" event handler for each submenu of the MenuBar
     instance, used to setup certain style properties before
     the menu is animated.
*/

function onSubmenuBeforeShow(p_sType, p_sArgs) {

    var oBody,
        oElement,
        oShadow,
        oUL;


    if (this.parent) {
        oElement = this.element;
        /*
             Get a reference to the Menu's shadow element and 
             set its "height" property to "0px" to syncronize 
             it with the height of the Menu instance.
        */

        oShadow = oElement.lastChild;
        oShadow.style.height = "0px";
        
        /*
            Stop the Animation instance if it is currently 
            animating a Menu.
        */ 
    
        if (oAnim && oAnim.isAnimated()) {
            oAnim.stop();
            oAnim = null;
        }

        /*
            Set the body element's "overflow" property to 
            "hidden" to clip the display of its negatively 
            positioned <ul> element.
        */ 

        oBody = this.body;

        //  Check if the menu is a submenu of a submenu.

        if (this.parent && 
            !(this.parent instanceof YAHOO.widget.MenuBarItem)) {

            /*
                There is a bug in gecko-based browsers where 
                an element whose "position" property is set to 
                "absolute" and "overflow" property is set to 
                "hidden" will not render at the correct width when
                its offsetParent's "position" property is also 
                set to "absolute."  It is possible to work around 
                this bug by specifying a value for the width 
                property in addition to overflow.
            */
            if (ua.gecko) {
                oBody.style.width = oBody.clientWidth + "px";
            }

            /*
                Set a width on the submenu to prevent its 
                width from growing when the animation 
                is complete.
            */
            
            if (ua.ie == 7) {
                oElement.style.width = oElement.clientWidth + "px";
            }
        }

        oBody.style.overflow = "hidden";

        /*
            Set the <ul> element's "marginTop" property 
            to a negative value so that the Menu's height
            collapses.
        */ 

        oUL = oBody.getElementsByTagName("ul")[0];

        oUL.style.marginTop = ("-" + oUL.offsetHeight + "px");
    
    }
}


/*
    "tween" event handler for the Anim instance, used to 
    syncronize the size and position of the Menu instance's 
    shadow and iframe shim (if it exists) with its 
    changing height.
*/

function onTween(p_sType, p_aArgs, p_oShadow) {

    if (this.cfg.getProperty("iframe")) {
    
        this.syncIframe();

    }

    if (p_oShadow) {

        p_oShadow.style.height = this.element.offsetHeight + "px";
    
    }

}


/*
    "complete" event handler for the Anim instance, used to 
    remove style properties that were animated so that the 
    Menu instance can be displayed at its final height.
*/

function onAnimationComplete(p_sType, p_aArgs, p_oShadow) {

    var oBody = this.body,
        oUL = oBody.getElementsByTagName("ul")[0];

    if (p_oShadow) {
        p_oShadow.style.height = this.element.offsetHeight + "px";
    }

    oUL.style.marginTop = "";
    oBody.style.overflow = "";
    
    //  Check if the menu is a submenu of a submenu.

    if (this.parent && 
        !(this.parent instanceof YAHOO.widget.MenuBarItem)) {

        // Clear widths set by the "beforeshow" event handler
        if (ua.gecko) {
            oBody.style.width = "";
        }
        if (ua.ie == 7) {
            this.element.style.width = "";
        }
    }
}


/*
     "show" event handler for each submenu of the MenuBar 
     instance - used to kick off the animation of the 
     <ul> element.
*/

function onSubmenuShow(p_sType, p_sArgs) {

    var oElement,
        oShadow,
        oUL;

    if (this.parent) {
        oElement = this.element;
        oShadow = oElement.lastChild;
        oUL = this.body.getElementsByTagName("ul")[0];

        /*
             Animate the <ul> element's "marginTop" style 
             property to a value of 0.
        */

        oAnim = new YAHOO.util.Anim(oUL, 
            { marginTop: { to: 0 } },
            .5, YAHOO.util.Easing.easeOut);

        oAnim.onStart.subscribe(function () {
            oShadow.style.height = "100%";
        });

        oAnim.animate();

        /*
            Subscribe to the Anim instance's "tween" event for 
            IE to syncronize the size and position of a 
            submenu's shadow and iframe shim (if it exists)  
            with its changing height.
        */

        if (YAHOO.env.ua.ie) {
            
            oShadow.style.height = oElement.offsetHeight + "px";

            /*
                Subscribe to the Anim instance's "tween"
                event, passing a reference Menu's shadow 
                element and making the scope of the event 
                listener the Menu instance.
            */
            oAnim.onTween.subscribe(onTween, oShadow, this);
        }

        /*
            Subscribe to the Anim instance's "complete" event,
            passing a reference Menu's shadow element and making 
            the scope of the event listener the Menu instance.
        */
        oAnim.onComplete.subscribe(onAnimationComplete, oShadow, this);
    }
}

// Handle the clicks to the item.
function centerandbaloon(event)
{

	var contentString = 'Hello World CaseNumber:  RecordType:';
	var targetObject = YAHOO.util.Event.getTarget(event);
//	YAHOO.log ('Title' + targetObject.nodeName);
	if (YAHOO.env.ua.ie > 0) { // This annoyance only exists in IE.
		while (targetObject.id != "container") {
			if(targetObject.nodeName.toUpperCase() == "DIV") {
				//yes, an div: so write out a message to the log
				YAHOO.log("The clicked li had an id of " + targetObject.id + " and title of " + targetObject.title , "info", "clickExample");
				//and then stop looking:
				break;
			} else {
				//wasn't the container, but wasn't an div; so
				//let's step up the DOM and keep looking:
				targetObject = targetObject.parentNode;
			}
		}
//		YAHOO.log ('Title:' + targetObject.title + ' NodeName:' + targetObject.nodeName);		
	}
	var myObject = targetObject.title.split(":");
//	YAHOO.log ('Object ' + myObject);
	var i = myObject[2];
	var myData = null;
	var sURL = null;
	var myCaseRecord = null;
	switch (myObject[0])
	{
		case 'SS':
			myData = fsSaleList[i];
			sURL = '/mashup/sslookup';
			myCaseRecord = fsSaleList[i].id;
			break;
			
		case 'TS':
			myData = tsSaleList[i];
			sURL = '/mashup/tslookup';
			myCaseRecord = tsSaleList[i].id;
			break;
			
		case 'TR':
			myData = transfers[i];
			sURL = '/mashup/trlookup';
			myCaseRecord = transfers[i].id;
			break;
			
		case 'FC':
			myData = cpForclosures[i];
			sURL = '/mashup/cplookup';
			myCaseRecord = cpForclosures[i].caseNumber;
			break;
	}
	if (myData != null){
		map.setCenter(myData.latlng);  
	
		var handleSsSuccess = function(o){
			var results;
			if(o.responseText !== undefined){
				results = "Transaction id: " + o.tId;
				results += "HTTP status: " + o.status;
				results += "Status code message: " + o.statusText;
			//	results += "PHP response: " + o.responseText;
			//	YAHOO.log ('Server Response:' + results);
				var myResults = '';
				if (o.responseText != ''){
					// First we will try to do native JSON parsing. To get the best speed.
					//	If that fails then we will fallback to the Yahoo JSON parser.
					try{
						if (JSON){
				//			YAHOO.log ('We have native JSON parsing.');
							var myResults = JSON.parse(o.responseText);
						} else {
				//			YAHOO.log ('We have to use YUI JSON parsing.');
							var myResults = YAHOO.lang.JSON.parse(o.responseText);
						}
					} catch (e) {
				//		YAHOO.log ('We have catch YUI JSON parsing.');
						var myResults = YAHOO.lang.JSON.parse(o.responseText);
					}
				}
				
				switch (myObject[0])
				{
					case 'SS':
						htmltext = myResults.ResultSet.results;
						break;
						
					case 'TS':
						htmltext = myResults.ResultSet.results;
						break;
						
					case 'TR':
						htmltext = myResults.ResultSet.results;
						break;
						
					case 'FC':
						htmltext = myResults.ResultSet.results;
						break;
				}
				myInfoWindow.setContent(htmltext);
				var myTabs;
				myInfoWindow.open(map, myData.latlngmarker);
			}
		};
		
		var HandleSsFailure = function(o){
			YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");
			var results;
			if(o.responseText !== undefined){
				results = "<li>Transaction id: " + o.tId + "</li>";
				results += "<li>HTTP status: " + o.status + "</li>";
				results += "<li>Status code message: " + o.statusText + "</li>";
			}
			YAHOO.log ('Response:' + results);
		};
		var ssCallback =
		{
		  success:handleSsSuccess,
		  failure: HandleSsFailure
		};
		YAHOO.util.Connect.abort(PrObj);
		var ssPostData = "caserecord=" + myCaseRecord;
		PrObj = YAHOO.util.Connect.asyncRequest('POST', sURL, ssCallback, ssPostData);
		
		
	}
}

// Clear Map Pins scripts
function clearMapPinsSS ()
{
	if (fsSaleList) 
	{
		for (var i=0; i<fsSaleList.length; i++)
		{
			if (fsSaleList[i].eventlistener)	google.maps.event.removeListener(fsSaleList[i].eventlistener);
			if (fsSaleList[i].latlngmarker)		fsSaleList[i].latlngmarker.setMap(null);
			delete (fsSaleList[i].latlngmarker);
		}
	}
	myInfoWindow.close();
}

function clearMapPinsTS ()
{
	if (tsSaleList) 
	{
		for (var i=0; i<tsSaleList.length; i++)
		{
			if (tsSaleList[i].eventlistener)	google.maps.event.removeListener(tsSaleList[i].eventlistener);
			if (tsSaleList[i].latlngmarker)		tsSaleList[i].latlngmarker.setMap(null);
			delete (tsSaleList[i].latlngmarker);
		}
	}
	myInfoWindow.close();
}

function clearMapPinsTR ()
{
	if (transfers) 
	{
		for (var i=0; i<transfers.length; i++)
		{
			if (transfers[i].eventlistener) google.maps.event.removeListener(transfers[i].eventlistener);
			if (transfers[i].latlngmarker)	transfers[i].latlngmarker.setMap(null);
			delete (transfers[i].latlngmarker);
		}
	}
	myInfoWindow.close();
}

function clearMapPinsFC ()
{
	if (cpForclosures) 
	{
		for (var i=0; i<cpForclosures.length; i++)
		{
			if (cpForclosures[i].eventlistener)	google.maps.event.removeListener(cpForclosures[i].eventlistener);
			if (cpForclosures[i].latlngmarker)	cpForclosures[i].latlngmarker.setMap(null);
			delete (cpForclosures[i].latlngmarker);
		}
	}
	myInfoWindow.close();
}

var maplat_min	=	0;
var maplat_max	=	0;
var maplong_min	=	0;
var maplong_max	=	0;

var ssmaplat_min	=	0;
var ssmaplat_max	=	0;
var ssmaplong_min	=	0;
var ssmaplong_max	=	0;

var stmaplat_min	=	0;
var stmaplat_max	=	0;
var stmaplong_min	=	0;
var stmaplong_max	=	0;

var trmaplat_min	=	0;
var trmaplat_max	=	0;
var trmaplong_min	=	0;
var trmaplong_max	=	0;

var fcmaplat_min	=	0;
var fcmaplat_max	=	0;
var fcmaplong_min	=	0;
var fcmaplong_max	=	0;

var myInfoWindow;

// Calculate the minmax to use for the map. 
function mapMinMaxCalc ()
{
	maplong_min = maplong_max = -84.1916;
	maplat_min = maplat_max = 39.7588;
	// if sheriff forclosure sales are 0 then no not include them.
    if (ssmaplong_min	!=	0) maplong_min =	Math.min (maplong_min,	ssmaplong_min);
    if (ssmaplong_max	!=	0) maplong_max =	Math.max (maplong_max,	ssmaplong_max);
    if (ssmaplat_min	!=	0) maplat_min =	Math.min (maplat_min,	ssmaplat_min);
    if (ssmaplat_max	!=	0) maplat_max =	Math.max (maplat_max,	ssmaplat_max);

	// if sheriff tax sales are 0 then no not include them.
    if (stmaplong_min	!=	0) maplong_min =	Math.min (maplong_min,	stmaplong_min);
    if (stmaplong_max	!=	0) maplong_max =	Math.max (maplong_max,	stmaplong_max);
    if (stmaplat_min	!=	0) maplat_min =	Math.min (maplat_min,	stmaplat_min);
    if (stmaplat_max	!=	0) maplat_max =	Math.max (maplat_max,	stmaplat_max);

	// if real estate transfers are 0 then no not include them.
    if (trmaplong_min	!=	0) maplong_min =	Math.min (maplong_min,	trmaplong_min);
    if (trmaplong_max	!=	0) maplong_max =	Math.max (maplong_max,	trmaplong_max);
    if (trmaplat_min	!=	0) maplat_min =	Math.min (maplat_min,	trmaplat_min);
    if (trmaplat_max	!=	0) maplat_max =	Math.max (maplat_max,	trmaplat_max);

	// if common pleas forclosure cases are 0 then no not include them.
    if (fcmaplong_min	!=	0) maplong_min =	Math.min (maplong_min,	fcmaplong_min);
    if (fcmaplong_max	!=	0) maplong_max =	Math.max (maplong_max,	fcmaplong_max);
    if (fcmaplat_min	!=	0) maplat_min =	Math.min (maplat_min,	fcmaplat_min);
    if (fcmaplat_max	!=	0) maplat_max =	Math.max (maplat_max,	fcmaplat_max);

	var sw = new google.maps.LatLng(maplat_min, maplong_min);
	var ne = new google.maps.LatLng (maplat_max, maplong_max);
	var bounds = new google.maps.LatLngBounds(sw,ne);
//	YAHOO.log ('final SWNE: ' + maplat_min + ' ' + maplong_min + ' ' + maplat_max + ' ' + maplong_max);
	
	map.fitBounds (bounds);
}

// Build map pins for site
function mapsMakePinsSS ()
{
//	YAHOO.log ('Make my pins Sheriff Sale (Forclosure)');
	if (fsSaleList)
	{
		if (fsSaleList.length>0 && fsSaleList[0].prop_long) 
		{
			var imageShadow = '/public/graphics_mainsite/mm_20_shadow.png';
			var imageSS		=	'/public/graphics_mainsite/ss.png';
		    // First time initialization of the variables
	        ssmaplong_min	= fsSaleList[0].prop_long;
	        ssmaplong_max	= fsSaleList[0].prop_long;
	        ssmaplat_min	= fsSaleList[0].prop_lat;
	        ssmaplat_max	= fsSaleList[0].prop_lat;
			
			YAHOO.log ('SSRecords: ' + fsSaleList.length);
			for (var i=1; i<fsSaleList.length; i++)
			{
				if (fsSaleList[i].prop_lat!= 380){
					fsSaleList[i].latlng = new google.maps.LatLng(fsSaleList[i].prop_lat, fsSaleList[i].prop_long);
					fsSaleList[i].latlngmarker = new google.maps.Marker({
						position: fsSaleList[i].latlng, 
						map: map,
						title: 'SS:' + fsSaleList[i].case_number + ':' + i,
						icon: imageSS,
						shadow: imageShadow
					});   
					var sale_type = fsSaleList[i].type;
				    fsSaleList[i].eventlistener = google.maps.event.addListener(fsSaleList[i].latlngmarker, 'click', function(event){centerandbaloon(event)});
				    ssmaplat_min	=	Math.min(ssmaplat_min, fsSaleList[i].prop_lat);
				    ssmaplat_max	=	Math.max(ssmaplat_max, fsSaleList[i].prop_lat);
				   	ssmaplong_min	=	Math.min(ssmaplong_min, fsSaleList[i].prop_long);
				    ssmaplong_max	=	Math.max(ssmaplong_max, fsSaleList[i].prop_long);
				}
			}
		}
	}
}

function mapsMakePinsTS ()
{
	if (tsSaleList) 
	{
		if (tsSaleList.length>0 && tsSaleList[0].prop_long) 
		{
			var imageTS		=	'/public/graphics_mainsite/ts.png';
			var imageShadow = '/public/graphics_mainsite/mm_20_shadow.png';
		    // First time initialization of the variables
	        stmaplong_min	= tsSaleList[0].prop_long;
	        stmaplong_max	= tsSaleList[0].prop_long;
	        stmaplat_min	= tsSaleList[0].prop_lat;
	        stmaplat_max	= tsSaleList[0].prop_lat;
			
			for (var i=0; i<tsSaleList.length; i++)
			{
				if (tsSaleList[i].prop_lat!= 380){
					tsSaleList[i].latlng = new google.maps.LatLng(tsSaleList[i].prop_lat, tsSaleList[i].prop_long);
					tsSaleList[i].latlngmarker = new google.maps.Marker({
						position: tsSaleList[i].latlng, 
						map: map,
						title: 'TS:' + tsSaleList[i].case_number + ':' + i,
						icon: imageTS,
						shadow:imageShadow
					});
					var casenumber = tsSaleList[i].case_number
				    tsSaleList[i].eventlistener = google.maps.event.addListener(tsSaleList[i].latlngmarker, 'click',  function(event){centerandbaloon(event)});
				    stmaplat_min	=	Math.min(stmaplat_min, tsSaleList[i].prop_lat);
				    stmaplat_max	=	Math.max(stmaplat_max, tsSaleList[i].prop_lat);
				    stmaplong_min	=	Math.min(stmaplong_min, tsSaleList[i].prop_long);
				    stmaplong_max	=	Math.max(stmaplong_max, tsSaleList[i].prop_long);
				}
			}
		}
	}
}

function mapsMakePinsTR ()
{
	if (transfers)
	{
		if (transfers.length>0 && transfers[0].prop_long) 
		{
			var imageTrans = '/public/graphics_mainsite/transfers.png';
			var imageShadow = '/public/graphics_mainsite/mm_20_shadow.png';
		    // First time initialization of the variables
	        trmaplong_min	= transfers[0].prop_long;
	        trmaplong_max	= transfers[0].prop_long;
	        trmaplat_min	= transfers[0].prop_lat;
	        trmaplat_max	= transfers[0].prop_lat;
	
			for (var i=0; i<transfers.length; i++)
			{
			    if (transfers[i].prop_lat!= 380){
					transfers[i].latlng = new google.maps.LatLng(transfers[i].prop_lat, transfers[i].prop_long);
					transfers[i].latlngmarker = new google.maps.Marker({
						position: transfers[i].latlng, 
						map: map,
						title: 'TR:' + transfers[i].street_address2 + ':' + i,
						icon: imageTrans,
						shadow: imageShadow,
						myMarkerType: 'transfer',
						myMarkerID: transfers[i].id
					});   
					var templatlng = transfers[i].latlng;
				    transfers[i].eventlistener = google.maps.event.addListener(transfers[i].latlngmarker, 'click', function(event){centerandbaloon(event)});
				    trmaplat_min	=	Math.min(trmaplat_min, transfers[i].prop_lat);
				    trmaplat_max	=	Math.max(trmaplat_max, transfers[i].prop_lat);
				    trmaplong_min	=	Math.min(trmaplong_min, transfers[i].prop_long);
				    trmaplong_max	=	Math.max(trmaplong_max, transfers[i].prop_long);
			    }
			}
		}
	}
}

function mapsMakePinsFC ()
{
	if (cpForclosures)
	{
		if (cpForclosures.length>0 && cpForclosures[0].prop_long) 
		{
			var imageShadow = '/public/graphics_mainsite/mm_20_shadow.png';
			var imageFC		=	'/public/graphics_mainsite/fc.png';
		    // First time initialization of the variables
	        fcmaplong_min	= cpForclosures[0].prop_long;
	        fcmaplong_max	= cpForclosures[0].prop_long;
	        fcmaplat_min	= cpForclosures[0].prop_lat;
	        fcmaplat_max	= cpForclosures[0].prop_lat;
			for (var i=0; i<cpForclosures.length; i++)
			{
				if (cpForclosures[i].prop_lat!= 380){
					cpForclosures[i].latlng = new google.maps.LatLng(cpForclosures[i].prop_lat, cpForclosures[i].prop_long);
					cpForclosures[i].latlngmarker = new google.maps.Marker({
						position: cpForclosures[i].latlng, 
						map: map,
						title: 'FC:' + cpForclosures[i].newCaseNumber + ':' + i,
						icon: imageFC,
						shadow: imageShadow
					});
				    cpForclosures[i].eventlistener = google.maps.event.addListener(cpForclosures[i].latlngmarker, 'click', function(event){centerandbaloon(event)});
					cpForclosures[i].eventlistener.myPinType = 'cpFor';
					cpForclosures[i].eventlistener.caseIndex = cpForclosures[i].caseNumber;
				    fcmaplat_min	=	Math.min(fcmaplat_min, cpForclosures[i].prop_lat);
				    fcmaplat_max	=	Math.max(fcmaplat_max, cpForclosures[i].prop_lat);
				    fcmaplong_min	=	Math.min(fcmaplong_min, cpForclosures[i].prop_long);
				    fcmaplong_max	=	Math.max(fcmaplong_max, cpForclosures[i].prop_long);
			    }
			}
		}
	}
}

function sendAjaxSs (e) {
	var handleSsSuccess = function(o){
		var results;
		if(o.responseText !== undefined){
			results = "Transaction id: " + o.tId;
			results += "HTTP status: " + o.status;
			results += "Status code message: " + o.statusText;
		//	results += "PHP response: " + o.responseText;
			var myResults = '';
			if (o.responseText != ''){
				// First we will try to do native JSON parsing. To get the best speed.
				//	If that fails then we will fallback to the Yahoo JSON parser.
				try{
					if (JSON){
		//				YAHOO.log ('We have native JSON parsing.');
						myResults = JSON.parse(o.responseText);
					} else {
		//				YAHOO.log ('We have to use YUI JSON parsing.');
						myResults = YAHOO.lang.JSON.parse(o.responseText);
					}
				} catch (e) {
		//			YAHOO.log ('We have catch YUI JSON parsing.');
					myResults = YAHOO.lang.JSON.parse(o.responseText);
				}
			}
			clearMapPinsSS ();
			delete fsSaleList;
			fsSaleList = null; /* Clear out the lists */
			if (myResults.ResultSet.ssForclosure)
			{	
				fsSaleList = myResults.ResultSet.ssForclosure;
			}
			mapsMakePinsSS();
			mapMinMaxCalc();
			oMyPanelCount--;
			YAHOO.log ('PanelCount:' + oMyPanelCount);
			if (oMyPanelCount <=0)
			{
				oMyPanelCount =0;
				oMyPanel.hide();
			}
		}
	};
	var HandleSsFailure = function(o){
		var results;
		if(o.responseText !== undefined){
			results = "<li>Transaction id: " + o.tId + "</li>";
			results += "<li>HTTP status: " + o.status + "</li>";
			results += "<li>Status code message: " + o.statusText + "</li>";
		}
		oMyPanelCount--;
		YAHOO.log ('PanelCount:' + oMyPanelCount);
		if (oMyPanelCount <=0)
		{
			oMyPanelCount =0;
			oMyPanel.hide();
		}
	};
	var ssCallback =
	{
	  success:handleSsSuccess,
	  failure: HandleSsFailure
	};
	var sURL = '/mashup/newssquery';
	YAHOO.util.Connect.abort(SsObj);
	YAHOO.util.Connect.setForm('mashupFormSs');
	var fc = document.getElementById('ssForclosureCb').checked;
	if (fc)
	{
		oMyPanelCount++;
		oMyPanel.show();
		SsObj = YAHOO.util.Connect.asyncRequest('POST', sURL, ssCallback);
	} else {
			clearMapPinsSS ();
			delete fsSaleList;
			fsSaleList = null; /* Clear out the lists */
	}
}

function sendAjaxTs (e) {
	var handleTsSuccess = function(o){
		var results;
		if(o.responseText !== undefined){
			results = "Transaction id: " + o.tId;
			results += "HTTP status: " + o.status;
			results += "Status code message: " + o.statusText;
		//	results += "PHP response: " + o.responseText;
			var myResults = '';
			if (o.responseText != ''){
				// First we will try to do native JSON parsing. To get the best speed.
				//	If that fails then we will fallback to the Yahoo JSON parser.
				try{
					if (JSON){
			//			YAHOO.log ('We have native JSON parsing.');
						myResults = JSON.parse(o.responseText);
					} else {
			//			YAHOO.log ('We have to use YUI JSON parsing.');
						myResults = YAHOO.lang.JSON.parse(o.responseText);
					}
				} catch (e) {
			//		YAHOO.log ('We have catch YUI JSON parsing.');
					myResults = YAHOO.lang.JSON.parse(o.responseText);
				}
			}
			clearMapPinsTS();
			delete tsSaleList;
			tsSaleList = null; /* Clear out the lists */
			if (myResults.ResultSet.ssTax)
			{
				tsSaleList = myResults.ResultSet.ssTax;
			}
			mapsMakePinsTS();
			mapMinMaxCalc();
			oMyPanelCount--;
			YAHOO.log ('PanelCount:' + oMyPanelCount);
			if (oMyPanelCount <=0)
			{
				oMyPanelCount =0;
				oMyPanel.hide();
			}
		}
	};
	var HandleTsFailure = function(o){
	//	YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");
		var results;
		if(o.responseText !== undefined){
			results = "<li>Transaction id: " + o.tId + "</li>";
			results += "<li>HTTP status: " + o.status + "</li>";
			results += "<li>Status code message: " + o.statusText + "</li>";
		}
//		YAHOO.log ('Response:' + results);
		oMyPanelCount--;
		YAHOO.log ('PanelCount:' + oMyPanelCount);
		if (oMyPanelCount <=0)
		{
			oMyPanelCount =0;
			oMyPanel.hide();
		}
	};
	var ssCallback =
	{
	  success:handleTsSuccess,
	  failure: HandleTsFailure
	};
	var sURL = '/mashup/newstquery';
	YAHOO.util.Connect.abort(TsObj);
	YAHOO.util.Connect.setForm('mashupFormSt');
	var fc = document.getElementById('ssTaxCb').checked;
	if (fc)
	{
		oMyPanelCount++;
		oMyPanel.show();
		TsObj = YAHOO.util.Connect.asyncRequest('POST', sURL, ssCallback);
	} else {
			clearMapPinsTS();
			delete tsSaleList;
			tsSaleList = null; /* Clear out the lists */
	}
}

function sendAjaxTr (e) {
	var handleTrSuccess = function(o){
		var results;
		if(o.responseText !== undefined){
			results = "Transaction id: " + o.tId;
			results += "HTTP status: " + o.status;
			results += "Status code message: " + o.statusText;
	//		results += "PHP response: " + o.responseText;
			YAHOO.log ('Server Response:' + results);
			var myResults = '';
			if (o.responseText != ''){
				// First we will try to do native JSON parsing. To get the best speed.
				//	If that fails then we will fallback to the Yahoo JSON parser.
				try{
					if (JSON){
//						YAHOO.log ('We have native JSON parsing.');
						myResults = JSON.parse(o.responseText);
					} else {
//						YAHOO.log ('We have to use YUI JSON parsing.');
						myResults = YAHOO.lang.JSON.parse(o.responseText);
					}
				} catch (e) {
//					YAHOO.log ('We have catch YUI JSON parsing.');
					myResults = YAHOO.lang.JSON.parse(o.responseText);
				}
			}
			clearMapPinsTR();
			delete transfers;
			transfers = null; /* Clear out the lists */
			if (myResults.ResultSet.reTransfer)
			{
				transfers = myResults.ResultSet.reTransfer;
			}
			mapsMakePinsTR();
			mapMinMaxCalc();
			oMyPanelCount--;
			YAHOO.log ('PanelCount:' + oMyPanelCount);
			if (oMyPanelCount <=0)
			{
				oMyPanelCount =0;
				oMyPanel.hide();
			}
		}
	};
	var HandleTrFailure = function(o){
		YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");
		var results;
		if(o.responseText !== undefined){
			results = "<li>Transaction id: " + o.tId + "</li>";
			results += "<li>HTTP status: " + o.status + "</li>";
			results += "<li>Status code message: " + o.statusText + "</li>";
		}
		YAHOO.log ('Response:' + results);
		oMyPanelCount--;
		YAHOO.log ('PanelCount:' + oMyPanelCount);
		if (oMyPanelCount <=0)
		{
			oMyPanelCount =0;
			oMyPanel.hide();
		}
	};
	var ssCallback =
	{
	  success:handleTrSuccess,
	  failure: HandleTrFailure
	};
	var sURL = '/mashup/newtrquery';
	YAHOO.util.Connect.abort(TrObj);
	YAHOO.util.Connect.setForm('mashupFormTr');
	var fc = document.getElementById('transfersCb').checked;
	if (fc)
	{
		oMyPanelCount++;
		oMyPanel.show();
		TrObj = YAHOO.util.Connect.asyncRequest('POST', sURL, ssCallback);
	} else {
			clearMapPinsTR();
			delete transfers;
			transfers = null; /* Clear out the lists */
	}
}

function sendAjaxCp (e) {
	var handleCpSuccess = function(o){
		var results;
		if(o.responseText !== undefined){
			results = "Transaction id: " + o.tId;
			results += "HTTP status: " + o.status;
			results += "Status code message: " + o.statusText;
	//		results += "PHP response: " + o.responseText;
			YAHOO.log ('Server Response:' + results);
			var myResults = '';
			if (o.responseText != ''){
				// First we will try to do native JSON parsing. To get the best speed.
				//	If that fails then we will fallback to the Yahoo JSON parser.
				try{
					if (JSON){
//						YAHOO.log ('We have native JSON parsing.');
						myResults = JSON.parse(o.responseText);
					} else {
//						YAHOO.log ('We have to use YUI JSON parsing.');
						myResults = YAHOO.lang.JSON.parse(o.responseText);
					}
				} catch (e) {
//					YAHOO.log ('We have catch YUI JSON parsing.');
					myResults = YAHOO.lang.JSON.parse(o.responseText);
				}
			}
			clearMapPinsFC();
			delete cpForclosures;
			cpForclosures = null; /* Clear out the lists */
			if (myResults.ResultSet.cpForclosure)
			{
				cpForclosures = myResults.ResultSet.cpForclosure;
			}
			mapsMakePinsFC();
			mapMinMaxCalc();
			oMyPanelCount--;
			YAHOO.log ('PanelCount:' + oMyPanelCount);
			if (oMyPanelCount <=0)
			{
				oMyPanelCount =0;
				oMyPanel.hide();
			}
		}
	};
	var HandleCpFailure = function(o){
		YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");
		var results;
		if(o.responseText !== undefined){
			results = "<li>Transaction id: " + o.tId + "</li>";
			results += "<li>HTTP status: " + o.status + "</li>";
			results += "<li>Status code message: " + o.statusText + "</li>";
		}
		YAHOO.log ('Response:' + results);
		oMyPanelCount--;
		YAHOO.log ('PanelCount:' + oMyPanelCount);
		if (oMyPanelCount <=0)
		{
			oMyPanelCount =0;
			oMyPanel.hide();
		}
	};
	var ssCallback =
	{
	  success:handleCpSuccess,
	  failure: HandleCpFailure
	};
	var sURL = '/mashup/newcpquery';
	YAHOO.util.Connect.abort(CpObj);
	YAHOO.util.Connect.setForm('mashupFormCp');
	var fc = document.getElementById('cpForclosuresCb').checked;
	if (fc)
	{
		oMyPanelCount++;
		oMyPanel.show();
//		YAHOO.log ('Send AJAX Query.');
		CpObj = YAHOO.util.Connect.asyncRequest('POST', sURL, ssCallback);
	} else {
			clearMapPinsFC();
			delete cpForclosures;
			cpForclosures = null; /* Clear out the lists */
	}
}


var SsObj;			/* Global object for Ajax transfer of form data. */
var TsObj;			/* Global object for Ajax transfer of form data. */
var TrObj;			/* Global object for Ajax transfer of form data. */
var CpObj;			/* Global object for Ajax transfer of form data. */
var PrObj;			/* Global object for Ajax transfer of form data. */

var fsSaleList; 	/* List of Forclosure Sheriff sales */
var tsSaleList; 	/* List of Tax Sheriff sales */
var transfers;		/* List of Real estate transfers */
var cpForclosures;	/* List of Common Pleas Transfers */

/*
     Subscribe to the "beforeShow" and "show" events for 
     each submenu of the MenuBar instance.
*/



var Event = YAHOO.util.Event,
    Dom = YAHOO.util.Dom,
    myCalDialog,
    calendar;

var showBtn = null;



function HandlePopupCalendar (e)	{
	YAHOO.log ('Handle a popup calendar event.');
	showBtn = YAHOO.util.Event.getTarget(e);
    // Lazy Dialog Creation - Wait to create the Dialog, and setup document click listeners, until the first time the button is clicked.
    if (!myCalDialog) {
        try {
	        Event.on(document, "click", function(e) {
	            var el = Event.getTarget(e);
	            var dialogEl = myCalDialog.element;
	            if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn && !Dom.isAncestor(showBtn, el)) {
	                myCalDialog.hide();
	            }
	        });
	
	        function resetHandler() {
	            // Reset the current calendar page to the select date, or 
	            // to today if nothing is selected.
	            var selDates = calendar.getSelectedDates();
	            var resetDate;
	
	            if (selDates.length > 0) {
	                resetDate = selDates[0];
	            } else {
	                resetDate = calendar.today;
	            }
	            calendar.cfg.setProperty("pagedate", resetDate);
	            calendar.render();
	        }
	
	        function closeHandler() {
	            myCalDialog.hide();
	        }
			

	        myCalDialog = new YAHOO.widget.Dialog("container", {
	            visible:false,
	            context:["show", "tl", "bl"],
	            buttons:[ {text:"Reset", handler: resetHandler, isDefault:true}, {text:"Close", handler: closeHandler}],
	            draggable:false,
	            close:true
	        });
	        var myCalObject = showBtn.id;
	        var myPosition	=	Dom.getXY(myCalObject);
	        myCalDialog.setHeader('Pick A Date');
	        myCalDialog.setBody('<div id="cal"></div>');
	     //   dialog.setProperty("y", 200);
	        myCalDialog.render(document.body);
			
	        myCalDialog.showEvent.subscribe(function() {
	            if (YAHOO.env.ua.ie) {
	                // Since we're hiding the table using yui-overlay-hidden, we 
	                // want to let the dialog know that the content size has changed, when
	                // shown
	                myCalDialog.fireEvent("changeContent");
	            }
	        });
        }
		catch (e) {
			YAHOO.log("Cannot make Dialog box. Error # " + e.number + "Description: " + e.description);
		}
    }
    // Lazy Calendar Creation - Wait to create the Calendar until the first time the button is clicked.
    if (!calendar) {
		try {
	        calendar = new YAHOO.widget.Calendar("cal", {
	            iframe:false,          // Turn iframe off, since container has iframe support.
	            hide_blank_weeks:true,  // Enable, to demonstrate how we handle changing height, using changeContent
	            PAGES:3,
	            SHOW_WEEK_HEADER:true
	        });
	        calendar.render();
		
	        calendar.selectEvent.subscribe(function() {
	            if (calendar.getSelectedDates().length > 0) {
	
	                var selDate = calendar.getSelectedDates()[0];
	
	                // Pretty Date Output, using Calendar's Locale values: Friday, 8 February 2008
	                var dStr = selDate.getDate();
	                var mStr = calendar.cfg.getProperty("MONTHS_LONG")[selDate.getMonth()];
	                var yStr = selDate.getFullYear();
					var myCalObject = showBtn.id;
					var newName = myCalObject.substring(0,myCalObject.length-4);
	         	    Dom.get(newName).value =  mStr + " " + dStr + " " + yStr;
	         	    // Triger the same as an onChange event for the date fields.
	            } else {
	          //      showBtn.tlnSibling.value = "";
	            }
	            myCalDialog.hide();
	        });
	
	        calendar.renderEvent.subscribe(function() {
	            // Tell Dialog it's contents have changed, which allows 
	            // container to redraw the underlay (for IE6/Safari2)
	            myCalDialog.fireEvent("changeContent");
	        });
        }
		catch (e) {
			YAHOO.log("Cannot make calendar");
			YAHOO.log(e.number);
			YAHOO.log(e.description);
		}
    }
    var seldate = calendar.getSelectedDates();

    if (seldate.length > 0) {
        // Set the pagedate to show the selected date if it exists
        calendar.cfg.setProperty("pagedate", seldate[0]);
        calendar.render();
    }
    	// Use this to seth the Y position
    var myPosition	=	Dom.getXY(showBtn.id);
    	// Use this to set the X position
	var newName = showBtn.id.substring(0,showBtn.id.length-4);
	var myBasePosition	=	Dom.getXY(newName);
	YAHOO.util.Dom.setXY('container_c', myBasePosition);
    myCalDialog.show();
};

var map;
var oMyPanel;
var oMyPanelCount=0;
function init() { 
	oMenuBar.subscribe("beforeShow", onSubmenuBeforeShow);
	oMenuBar.subscribe("show", onSubmenuShow);
	oMyPanel = new YAHOO.widget.Panel("pleasewait", {
		visible:false,
		close:false,
		draggable:false
	});
	oMyPanel.render();
	
	/* Get the google maps running */
	if (document.getElementById('newmap')){
		var latlng = new google.maps.LatLng(39.7588, -84.1916);
		var myOptions = {
			zoom: 12,
			mapTypeControl: true,
			sensor: true,
			center: latlng,
			navigationControl: true,
			scaleControl: true,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		map = new google.maps.Map(document.getElementById("newmap"), myOptions);
		
		myInfoWindow = new google.maps.InfoWindow({
	    	content: ""
		});
	};


	/* Create the actions and attach to the calendar buttons only if they exist as objects */
	
	var fdssfs = new YAHOO.util.Element('fileDateStartSsForclosureShow');
	if (fdssfs) fdssfs.on('click', HandlePopupCalendar);
	
	var fdsstfs = new YAHOO.util.Element('fileDateStopSsForclosureShow');
	if (fdsstfs) fdsstfs.on('click', HandlePopupCalendar);
	
	var fdssts = new YAHOO.util.Element('fileDateStartSsTaxShow');
	if (fdssts) fdssts.on('click', HandlePopupCalendar);
	
	var fdsstts = new YAHOO.util.Element('fileDateStopSsTaxShow');
	if (fdsstts) fdsstts.on('click', HandlePopupCalendar);
	
	var fdsts = new YAHOO.util.Element('fileDateStartTransfersShow');
	if (fdsts) fdsts.on('click', HandlePopupCalendar);
	
	var fdstts = new YAHOO.util.Element('fileDateStopTransfersShow');
	if (fdstts) fdstts.on('click', HandlePopupCalendar);
	
	var fdscfs = new YAHOO.util.Element('fileDateStartCpForclosuresShow');
	if (fdscfs) fdscfs.on('click', HandlePopupCalendar);
	
	var fdstcfs =  new YAHOO.util.Element('fileDateStopCpForclosuresShow');
	if (fdstcfs) fdstcfs.on('click', HandlePopupCalendar);
	
	/* Handle the mashup code fort he page. */
	var ssale = new YAHOO.util.Element('ssForclosureCb');
	ssale.on('change', sendAjaxSs);
	
	// Form elements for Forclosure sheriff sales.
	var ausf = new YAHOO.util.Element('allUpcomingSsForclosure');
	ausf.on('change', sendAjaxSs);
	var lwsf = new YAHOO.util.Element('lastWeekSsForclosure');
	lwsf.on('change', sendAjaxSs);
	var nwsf = new YAHOO.util.Element('nextWeekSsForclosure');
	nwsf.on('change', sendAjaxSs);
	
	// Form elements for paid
	var fdssf = new YAHOO.util.Element('fileDateStartSsForclosure');
	fdssf.on('change', sendAjaxSs);
	var fdstsf = new YAHOO.util.Element('fileDateStopSsForclosure');
	fdstsf.on('change', sendAjaxSs);
	var csf = new YAHOO.util.Element('citySsForclosure');
	csf.on('change', sendAjaxSs);
	var zsf = new YAHOO.util.Element('zipSsForclosure');
	zsf.on('change', sendAjaxSs);
	
	
	var tsale = new YAHOO.util.Element('ssTaxCb');
	tsale.on('change',  sendAjaxTs);
	
	// Form elements for Tax sheriff sales.
	var aust = new YAHOO.util.Element('allUpcomingSsTax');
	aust.on('change', sendAjaxTs);
	var lwst = new YAHOO.util.Element('lastWeekSsTax');
	lwst.on('change', sendAjaxTs);
	var nwst = new YAHOO.util.Element('nextWeekSsTax');
	nwst.on('change', sendAjaxTs);
	
	// Form elements for paid
	var fdsst = new YAHOO.util.Element('fileDateStartSsTax');
	fdsst.on('change', sendAjaxTs);
	var fdstst = new YAHOO.util.Element('fileDateStopSsTax');
	fdstst.on('change', sendAjaxTs);
	var cst = new YAHOO.util.Element('citySsTax');
	cst.on('change', sendAjaxTs);
	var zst = new YAHOO.util.Element('zipSsTax');
	zst.on('change', sendAjaxTs);
	
	// 
	var rest = new YAHOO.util.Element('transfersCb');
	rest.on('change',  sendAjaxTr);
	
	// Form elements for Real estate transfers.
	var lwt = new YAHOO.util.Element('lastWeekTransfers');
	lwt.on('change', sendAjaxTr);
	var lmt = new YAHOO.util.Element('lastMonthTransfers');
	lmt.on('change', sendAjaxTr);
	
	// Form elements for paid
	var fdst = new YAHOO.util.Element('fileDateStartTransfers');
	fdst.on('change', sendAjaxTr);
	var fdstt = new YAHOO.util.Element('fileDateStopTransfers');
	fdstt.on('change', sendAjaxTr);
	var ct = new YAHOO.util.Element('cityTransfers');
	ct.on('change', sendAjaxTr);
	var zt = new YAHOO.util.Element('zipTransfers');
	zt.on('change', sendAjaxTr);
	
	
	var fc = new YAHOO.util.Element('cpForclosuresCb');
	fc.on('change',  sendAjaxCp);
	
	// Form elements for Common pleas forclosure.
/*	var lwcf = new YAHOO.util.Element('lastWeekCpForclosures');
	lwcf.on('change', sendAjaxCp);
	var lmcf = new YAHOO.util.Element('lastMonthCpForclosures');
	lmcf.on('change', sendAjaxCp);
	
	// Form elements for paid
	var fdscf = new YAHOO.util.Element('fileDateStartCpForclosures');
	fdscf.on('change', sendAjaxCp);
	var fdstcf = new YAHOO.util.Element('fileDateStopCpForclosures');
	fdstcf.on('change', sendAjaxCp);
	var ccf = new YAHOO.util.Element('cityCpForclosures');
	ccf.on('change', sendAjaxCp);
	var zcf = new YAHOO.util.Element('zipCpForclosures');
	zcf.on('change', sendAjaxCp);	*/

//	YAHOO.log ('Send SS Query.');
	sendAjaxSs(); // When we finish loading then start the query.
//	YAHOO.log ('Send TS Query.');
	sendAjaxTs();
//	YAHOO.log ('Send TR Query.');
	sendAjaxTr();
//	YAHOO.log ('Send CP Query.');
//	sendAjaxCp();	
} 

YAHOO.util.Event.onDOMReady(init); 


