
/* Check at startup to see if the javascript logger is running */
if (document.getElementById('myLogger')){
	var oLogReader = new YAHOO.widget.LogReader("myLogger");
	/* 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("toledolegalnavigation", { 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) {}

if (document.getElementById('saletabs')){
	var osaleView = new YAHOO.widget.TabView('saletabs');
}

/* Handle the Rich text editing of the content for articles. */
/*	if (!mobile) {
	YAHOO.namespace ("YAHOO.articles"); // Make up my namespace to attach these items.
	YAHOO.namespace ("YAHOO.articles.edit"); // Make up my namespace to attach these items.
	YAHOO.articles.edit.getcontent = function() {
		YAHOO.articles.edit.oPostContent.saveHTML();
		YAHOO.articles.edit.oPostContent.saveHTML(); 
	} 
	if (document.getElementById('post_excerpt')){
		YAHOO.articles.edit.oPostExcerpt = new YAHOO.widget.Editor('post_excerpt', {
			height: '150px',
			width: '552px',
			dompath: true, //Turns on the bar at the bottom
			animate: false,	//Animates the opening, closing and moving of Editor windows 
			handleSubmit: false,	// Allows the items to put the recieved content back into the textedit.
			draggabble: true,
			titlebar: "Article Excerpt"
		});
		YAHOO.articles.edit.oPostExcerpt.collapse(true);
		YAHOO.articles.edit.oPostExcerpt.render();
	}
	if (document.getElementById('post_content')){
		YAHOO.articles.edit.oPostContent = new YAHOO.widget.Editor('post_content', {
			height: '300px',
			width: '552px',
			dompath: true, //Turns on the bar at the bottom
			animate: false,	//Animates the opening, closing and moving of Editor windows 
			handleSubmit: false,	// Allows the items to put the recieved content back into the textedit.
			draggable: true,
			titlebar:"Article Content"
		});
		YAHOO.articles.edit.oPostContent.collapse(true);
		YAHOO.articles.edit.oPostContent.render();
		var edititem = document.getElementById('edit');
		if (edititem){
				YAHOO.util.Event.addListener(edititem, "click", YAHOO.articles.edit.getcontent); 
		}
		var additem = document.getElementById('add');			
		if (additem){
				YAHOO.util.Event.addListener(additem, "click", YAHOO.articles.edit.getcontent); 
		}
	}
} */

function setCaseTypeStart (e)
{
	var casetype = new YAHOO.util.Element('type');
	var complaint = new YAHOO.util.Element('complaint');
	if (document.getElementById('complaint')){
		var template = '';
		if (complaint.get('value')===''){
			switch (casetype.get('value')){
				case 'AUTO':
					template = 'Action for monetary judgt w/int & costs alleged due for negligence, negligence per se, permanent personal injury, lost wages, w/jury demand.';
					break;
				
				case 'BWC':
					template = 'Action for judgt that plff has the right to participate in benefits of Workers\' Comp Law, with jury demand.';
					break;
				
				case 'CPO':
					template = 'Filed as Civil Protection Order';
					break;
					
				case 'FOR':
					template = 'Action for judgt for $(enter) with int & costs alleged due on prom note, foreclosure of mtg on: (enter), marshaling of liens order of sale.';
					break;
					
				case 'JUDGT':
					template = 'Action for judgt of $(entry) w/ int & costs alleged due for';
					break;
					
				case 'MEDMAL':
					template = 'Action for monetary judgt w/int & costs alleged due for negligence, departure from accepted standard of medical care & treatment, permanent personal injury, lost wages, diminished earning capacity, loss of consortium w/jury demand.';
					break;
					
				case 'MISC':
					template = 'Action for judgt';
					break;
					
				case 'MON':
					template = 'Action for monetary judgt w/int & costs alleged due for';
					break;
					
				default:
					template = 'You have made a selection that does not exist.';
					break;
			}
			complaint.set('value',template,false);
		}
	}		
}


if (document.getElementById('commonpleas')){
	if (document.getElementById('commonpleas')){
		var casetype = new YAHOO.util.Element('type');
		casetype.on ('blur',setCaseTypeStart);
		casetype.on ('change',setCaseTypeStart);
	}
}
if (document.getElementById('GoogleMap')){
	MapGood = false;
	var point;
	if (page_data && page_data['prop_lat'] > 1 && page_data['prop_lat'] < 380){
		MapGood = true; // We are good data is there.
		point = new GLatLng(page_data['prop_lat'], page_data['prop_long']);
	}
	if (MapGood){
		if (GBrowserIsCompatible()) {
			var mapOptions = {
				googleBarOptions : {
					style : "new",
					adsOptions: {
						client: "pub-8159460987916032",
						channel: "ToledoLegalNews - Googlemaps",
						adsafe: "high",
						language: "en"
					}
				}
			}
			var map = new GMap2(document.getElementById("GoogleMap"),mapOptions);
			map.addControl(new GMapTypeControl());
			var adsManagerOptions = {
			  maxAdsOnMap : 2,
			  style: 'adunit'
			};

			var adsManager = new GAdsManager(map, "pub-8159460987916032", adsManagerOptions);
				adsManager.enable();
				adsManager.channel='7510568549';
			map.setCenter(point, 15);			
			var bounds = map.getBounds();
			var southWest = bounds.getSouthWest();
			var northEast = bounds.getNorthEast();
			var lngSpan = northEast.lng() - southWest.lng();
			var latSpan = northEast.lat() - southWest.lat();
			map.addOverlay(new GMarker(point));
			map.addMapType(G_SATELLITE_3D_MAP);
			var trafficOptions = {incidents:true};
 			trafficInfo = new GTrafficOverlay(trafficOptions);
			map.addOverlay(trafficInfo);
			map.setUIToDefault();
  			map.enableGoogleBar();
		}
	} 
}

function handleNoFlash(errorCode) {
  if (errorCode == 603) {
    alert("Error: Flash doesn't appear to be supported by your browser");
    return;
  }
}
if (document.getElementById('GoogleStreetView')){
	if (page_data && page_data['prop_lat'] > 1 && page_data['prop_lat'] < 380){
		MapGood = true; // We are good data is there.
		point = new GLatLng(page_data['prop_lat'], page_data['prop_long']);
	}
	panoClient = new GStreetviewClient(); 
	var myPano = new GStreetviewPanorama(document.getElementById("GoogleStreetView"));
	myPano.setLocationAndPOV(point);
	GEvent.addListener(myPano, "error", handleNoFlash);
}


var streetAddress = new YAHOO.util.Element('data1qq0qqstreet_address');

function copyAddr1Addr2 (e) {
	var addr2=new YAHOO.util.Element('data1qq0qqstreet_address2');
	var addr= new YAHOO.util.Element('data1qq0qqstreet_address');
	var adrvalue = addr.get('value');
	if (addr2.get('value')==='') {
		addr2.set('value',adrvalue,false);
		if (addr2.hasChildNodes){
			var myChildNodes = addr.get('childNodes');
			addr2.appendChild(myChildNodes);
		}
	}
}

if (streetAddress){
//	addEvent (streetAddress,'blur',checkAddress, false);
	streetAddress.on ('blur',copyAddr1Addr2);
//	addEvent (streetAddress,'change',checkAddress, false);
}
var ssale = document.getElementById('sheriffsale');
var tsale = document.getElementById('taxsale');
if (ssale || tsale){
/* This is a sheriff sale or tax sale page Only do the JS stuff for them here. */

	var defendants = document.getElementById('data1qq0qqdefendant');
	if (defendants){
		YAHOO.namespace ("YAHOO.sheriffsale"); // Make up my namespace to attach these items.
		YAHOO.namespace ("YAHOO.sheriffsale.defendant"); // Make up my namespace to attach these items.

		YAHOO.sheriffsale.defendant.oACDS = new YAHOO.widget.DS_XHR ("/sheriffsale/ajax/field/defendant/",["ResultSet", "owner","direction","streetnumber","address","city","state","zip","legal","parcel"]);

		YAHOO.sheriffsale.defendant.oACDS.maxCacheEntries = 20;
		YAHOO.sheriffsale.defendant.oACDS.queryMatchSubset = true;

		//Instantiate second AutoComplete 
		YAHOO.sheriffsale.defendant.oAutoComp = new YAHOO.widget.AutoComplete('data1qq0qqdefendant','ysearchdefendant', YAHOO.sheriffsale.defendant.oACDS);
		YAHOO.sheriffsale.defendant.oAutoComp.queryDelay = 0;
		YAHOO.sheriffsale.defendant.oAutoComp.maxResultsDisplayed = 20;
		YAHOO.sheriffsale.defendant.oAutoComp.formatResult = function(aResultItem, sQuery) {
				var sResult = aResultItem[0] + ":" + aResultItem[1] + " " + aResultItem[2] + ", " + aResultItem[3] + " " + aResultItem[4] + " " + aResultItem[5];
				if(sResult) {
					return sResult;
				}
				else {
					return "";
				}
			};

			//define your itemSelect handler function:
		var myItemSelectEvent = function(sType, aArgs) {
			YAHOO.log(sType); //this is a string representing the event;
							  //e.g., "itemSelectEvent"
			var oMyAcInstance = aArgs[0]; // your AutoComplete instance
			var elListItem = aArgs[1]; //the <li> element selected in the suggestion
									   //container
			var aData = aArgs[2]; //array of the data for the item as returned by the DataSource
			var address = aData[1] + " " + aData[2] + " " + aData[3];				
			var defendant = new YAHOO.util.Element('data1qq0qqdefendant');
			var legal = new YAHOO.util.Element('data1qq0qqlegal_description');			
			var city = new YAHOO.util.Element('data1qq0qqcity');
			var state = new YAHOO.util.Element('data1qq0qqstate');
			var zip = new YAHOO.util.Element('data1qq0qqzip');
			var addr2=new YAHOO.util.Element('data1qq0qqstreet_address2');
			var addr= new YAHOO.util.Element('data1qq0qqstreet_address');
			var parcel = new YAHOO.util.Element('data1qq0qqparcel_numbero');
			var parcel1 = new YAHOO.util.Element('data1qq0qqparcel_number0');
			if (addr.get('value')==='') {
				addr.set('value',address,false);
			}	
			if (parcel.get('value')==='') {
				parcel.set('value',aData[8],false);
			}	
			if (parcel1.get('value')==='') {
				parcel1.set('value',aData[8],false);
			}	
			if (addr2.get('value')==='') {
				addr2.set('value',address,false);
			}
			if (city.get('value')==='') {
				city.set('value',aData[4],false);
			}
			if (state.get('value')==='') {
				state.set('value',aData[5],false);
			}
			if (zip.get('value')==='') {
				zip.set('value',aData[6],false);
			}
			if (legal.get('value')==='') {
				legal.set('value',aData[7],false);
			}				
		};
		
		//subscribe your handler to the event, assuming
		//you have an AutoComplete instance myAC:
		YAHOO.sheriffsale.defendant.oAutoComp.itemSelectEvent.subscribe(myItemSelectEvent);
		
	}
	

	var parcel_numbero = document.getElementById('data1qq0qqparcel_numbero');
	if (parcel_numbero){
		YAHOO.namespace ("YAHOO.sheriffsale"); // Make up my namespace to attach these items.
		YAHOO.namespace ("YAHOO.sheriffsale.parcel_numbero"); // Make up my namespace to attach these items.

		YAHOO.sheriffsale.parcel_numbero.oACDS = new YAHOO.widget.DS_XHR ("/sheriffsale/ajax/field/parcel_numbero/",["ResultSet","parcel", "owner","direction","streetnumber","address","city","state","zip","legal"]);

		YAHOO.sheriffsale.parcel_numbero.oACDS.maxCacheEntries = 20;
		YAHOO.sheriffsale.parcel_numbero.oACDS.queryMatchSubset = true;

		//Instantiate second AutoComplete 
		YAHOO.sheriffsale.parcel_numbero.oAutoComp = new YAHOO.widget.AutoComplete('data1qq0qqparcel_numbero','ysearchparcel_numbero', YAHOO.sheriffsale.parcel_numbero.oACDS);
		YAHOO.sheriffsale.parcel_numbero.oAutoComp.queryDelay = 0;
		YAHOO.sheriffsale.parcel_numbero.oAutoComp.maxResultsDisplayed = 20;
		YAHOO.sheriffsale.parcel_numbero.oAutoComp.formatResult = function(aResultItem, sQuery) {
				var sResult = aResultItem[0] + ":" + aResultItem[1] + ":" + aResultItem[3] + " " + aResultItem[2] + ", " + aResultItem[4] + " " + aResultItem[5];
				if(sResult) {
					return sResult;
				}
				else {
					return "";
				}
			};

			//define your itemSelect handler function:
		var myItemSelectEventParcel = function(sType, aArgs) {
			YAHOO.log(sType); //this is a string representing the event;
							  //e.g., "itemSelectEvent"
			var oMyAcInstance = aArgs[0]; // your AutoComplete instance
			var elListItem = aArgs[1]; //the <li> element selected in the suggestion
									   //container
			var aData = aArgs[2]; //array of the data for the item as returned by the DataSource
			var address = aData[3] + " " + aData[2] + " " + aData[4];				
			var defendant = new YAHOO.util.Element('data1qq0qqdefendant');
			var legal = new YAHOO.util.Element('data1qq0qqlegal_description');			
			var city = new YAHOO.util.Element('data1qq0qqcity');
			var state = new YAHOO.util.Element('data1qq0qqstate');
			var zip = new YAHOO.util.Element('data1qq0qqzip');
			var addr2=new YAHOO.util.Element('data1qq0qqstreet_address2');
			var addr= new YAHOO.util.Element('data1qq0qqstreet_address');
			var parcel = new YAHOO.util.Element('data1qq0qqparcel_numbero');
			var parcel1 = new YAHOO.util.Element('data1qq0qqparcel_number0');
			if (addr.get('value')==='') {
				addr.set('value',address,false);
			}	
			if (parcel.get('value')==='') {
				parcel.set('value',aData[0],false);
			}	
			if (parcel1.get('value')==='') {
				parcel1.set('value',aData[0],false);
			}	
			if (addr2.get('value')==='') {
				addr2.set('value',address,false);
			}
			if (city.get('value')==='') {
				city.set('value',aData[5],false);
			}
			if (state.get('value')==='') {
				state.set('value',aData[6],false);
			}
			if (zip.get('value')==='') {
				zip.set('value',aData[7],false);
			}
			if (legal.get('value')==='') {
				legal.set('value',aData[8],false);
			}				
		};
		
		//subscribe your handler to the event, assuming
		//you have an AutoComplete instance myAC:
		YAHOO.sheriffsale.parcel_numbero.oAutoComp.itemSelectEvent.subscribe(myItemSelectEventParcel);
		
	}
	
	var atty = document.getElementById('data1qq0qqatty');
	if (atty){
		YAHOO.namespace ("YAHOO.sheriffsale"); // Make up my namespace to attach these items.
		YAHOO.namespace ("YAHOO.sheriffsale.atty"); // Make up my namespace to attach these items.

		YAHOO.sheriffsale.atty.oACDS = new YAHOO.widget.DS_XHR ("/sheriffsale/ajax/field/atty/",["ResultSet", "atty", "firm_name", "firm_address", "firm_city", "firm_state", "firm_zip", "firm_phone"]);
		YAHOO.sheriffsale.atty.oACDS.maxCacheEntries = 20;
		YAHOO.sheriffsale.atty.oACDS.queryMatchSubset = true;
		//Instantiate second AutoComplete 
		YAHOO.sheriffsale.atty.oAutoComp = new YAHOO.widget.AutoComplete('data1qq0qqatty','attyAutoComplete', YAHOO.sheriffsale.atty.oACDS);
		YAHOO.sheriffsale.atty.oAutoComp.animhoriz = true;
		YAHOO.sheriffsale.atty.oAutoComp.maxResultsDisplayed = 20;			
		YAHOO.sheriffsale.atty.oAutoComp.queryDelay = 0;
		
			//define your itemSelect handler function:
		var myAttyItemSelectEvent = function(sType, aArgs) {
			YAHOO.log(sType); //this is a string representing the event;
							  //e.g., "itemSelectEvent"
			var oMyAcInstance = aArgs[0]; // your AutoComplete instance
			var elListItem = aArgs[1]; //the <li> element selected in the suggestion
									   //container
			var aData = aArgs[2]; //array of the data for the item as returned by the DataSource
			var fname = new YAHOO.util.Element('data1qq0qqlaw_firm');
			var faddress = new YAHOO.util.Element('data1qq0qqatty_address');			
			var fcity = new YAHOO.util.Element('data1qq0qqatty_city');
			var fstate = new YAHOO.util.Element('data1qq0qqatty_state');
			var fzip = new YAHOO.util.Element('data1qq0qqatty_zip');
			var fphone=new YAHOO.util.Element('data1qq0qqatty_phone');
			var fatty= new YAHOO.util.Element('data1qq0qqatty');

			if (fname.get('value')==='') {
				fname.set('value',aData[1],false);
			}	
			if (faddress.get('value')==='') {
				faddress.set('value',aData[2],false);
			}	
			if (fcity.get('value')==='') {
				fcity.set('value',aData[3],false);
			}
			if (fstate.get('value')==='') {
				fstate.set('value',aData[4],false);
			}
			if (fzip.get('value')==='') {
				fzip.set('value',aData[5],false);
			}
			if (fphone.get('value')==='') {
				fphone.set('value',aData[6],false);
			}
		};
		
		//subscribe your handler to the event, assuming
		//you have an AutoComplete instance myAC:
		YAHOO.sheriffsale.atty.oAutoComp.itemSelectEvent.subscribe(myAttyItemSelectEvent);
	}
}


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);
    
    }

}


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

oMenuBar.subscribe("beforeShow", onSubmenuBeforeShow);
oMenuBar.subscribe("show", onSubmenuShow);


