/**********************************************************************************************/
// getElementsByClassName
// http://www.robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/
var getElementsByClassName=function(className,tag,elm){if(document.getElementsByClassName){getElementsByClassName=function(className,tag,elm){elm=elm||document;var elements=elm.getElementsByClassName(className),nodeName=(tag)?new RegExp("\\b"+tag+"\\b","i"):null,returnElements=[],current;for(var i=0,il=elements.length;i<il;i+=1){current=elements[i];if(!nodeName||nodeName.test(current.nodeName)){returnElements.push(current)}}return returnElements}}else if(document.evaluate){getElementsByClassName=function(className,tag,elm){tag=tag||"*";elm=elm||document;var classes=className.split(" "),classesToCheck="",xhtmlNamespace="http://www.w3.org/1999/xhtml",namespaceResolver=(document.documentElement.namespaceURI===xhtmlNamespace)?xhtmlNamespace:null,returnElements=[],elements,node;for(var j=0,jl=classes.length;j<jl;j+=1){classesToCheck+="[contains(concat(' ', @class, ' '), ' "+classes[j]+" ')]"}try{elements=document.evaluate(".//"+tag+classesToCheck,elm,namespaceResolver,0,null)}catch(e){elements=document.evaluate(".//"+tag+classesToCheck,elm,null,0,null)}while((node=elements.iterateNext())){returnElements.push(node)}return returnElements}}else{getElementsByClassName=function(className,tag,elm){tag=tag||"*";elm=elm||document;var classes=className.split(" "),classesToCheck=[],elements=(tag==="*"&&elm.all)?elm.all:elm.getElementsByTagName(tag),current,returnElements=[],match;for(var k=0,kl=classes.length;k<kl;k+=1){classesToCheck.push(new RegExp("(^|\\s)"+classes[k]+"(\\s|$)"))}for(var l=0,ll=elements.length;l<ll;l+=1){current=elements[l];match=false;for(var m=0,ml=classesToCheck.length;m<ml;m+=1){match=classesToCheck[m].test(current.className);if(!match){break}}if(match){returnElements.push(current)}}return returnElements}}return getElementsByClassName(className,tag,elm)};
// end of getElementsByClassName
/**********************************************************************************************/

/*
 submits a set of fields to a given page via query string.
 the function takes unlimited arguments. The first argument
 is the destination URL and all remaining arguments are IDs
 of form fields to append to the query string.
 */
function submitFields(){
	if(document.getElementById("searchType").value == "web"){
		window.location.href = "http://search.yahoo.com/search?fr=yscpb&p=" + document.getElementById("searchText").value
	}
	else{
		window.location.href = "/search?keywords=" + document.getElementById("searchText").value
	}
}

function changeFontSize(parent, direction){
    var parentElement = document.getElementById(parent);
    if (parentElement != null) {
        resizeFont(parentElement, "p", 1.0, 2, .8, direction);
        resizeFont(parentElement, "h1", 2.0, 3, 1.2, direction);
        resizeFont(parentElement, "h2", 1.2, 2.6, 1.0, direction);
        resizeFont(parentElement, "li", 1.0, 2.6, 1.0, direction);
    }

}

function resizeFont(parentElement, tag, defaultSize, maxSize, minSize, direction){
    var items = parentElement.getElementsByTagName(tag);
    // alert(items);
    for (i = 0; i < items.length; i++) {
        if (items[i].style.fontSize) {
            var s = parseFloat(items[i].style.fontSize.replace("em", ""));
        }
        else {
            var s = defaultSize
        }
        if ((s < maxSize) && (direction == "grow")) {
            s *= 1.1
        }
        if ((s > minSize) && (direction == "shrink")) {
            s *= 0.9;
        }
        items[i].style.fontSize = s + "em"

    }

}

// an empty function to capture events and do nothing with them
function nullFunction(){
}

function PrintPage(){
    window.print
}

function showhide(id){
    if (document.getElementById) {
        obj = document.getElementById(id);
        if (obj.style.display == "none") {
            obj.style.display = "";
        }
        else {
            obj.style.display = "none";
        }
    }
}

function poppoll(url, name, rs, w, h) {
  var resize = "resizable=no,";
  if (rs) {
    resize = "resizable=yes,";
  }
  popupWin = window.open(url, name, 'location=no,menubar=no,toolbar=no,scrollbars=no,status=no,' + resize + 'width=' + w + ',height=' + h);
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function createXMLHttpRequest()
{
    // activeX versions to check for in IE
    //var activeXs = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
    var activeXs = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];

    //test if IE first (XMLHttpRequest in IE7 is broken)
    if (window.ActiveXObject)
    {
        for (var i=0; i < activeXs.length; i++) {
            try {
                //alert("Returning ActiveXObject " + activeXs[i]);
                return new ActiveXObject(activeXs[i]);
            } catch(e) {
                displaySliderContentError("<span class='text_size'>Can't create " + activeXs[i] + " Object</span>");
            }
        }
    }
    // Mozilla, Safari etc
    else if (window.XMLHttpRequest) {
        var request = new XMLHttpRequest();

        //Override the mime type returned by the server (if any)
        if(request.overrideMimeType) {
            request.overrideMimeType('text/xml');
            return request;
        }
    }
    else {
        displaySliderContentError("<span class='text_size'>Your browser does not support XMLHttpRequest</span>");
    }

    return null;
}


function launchpopup(url,target,showtoolbar,width,height)
{
	var newWindow = window.open(url,target,"width=" + width + ", height=" + height)
	if(newWindow.focus)
		newWindow.focus()
}

/**********************************************************************************************/
// adds target attribute with specified value to <a> elements within for iframe use
function iframeFix(targetvalueobj)
{
	// initialize links within elements, you can change if preferred
	if (!document.getElementsByTagName("a")) return false;
	var gotlinks = document.getElementsByTagName("a");

	// attach event handlers
	for (var i=0;i<gotlinks.length;i++)
	{
		var gotlink = gotlinks[i];

		if (gotlink.getAttribute("href")) gotlink.target = targetvalueobj;
	}
} // end of iframeFix()
/**********************************************************************************************/

/**********************************************************************************************/
// certain popout ads have inline styles that control position of ad and popout section. However, not all popout ads have the same inline styles for some reason (left: 0; vs left: -80px;), despite being the same type of ad. This funtion resets the inline styles to the proper values.
function fixsideAds()
{
	// initialize gotsideAds as all elements with id of sideAds
	if (!document.getElementById("sideAds")) return false;
	var gotsideAds = document.getElementById("sideAds");

	// initialize gotdivs as all the div elements within sideAds
	if (!gotsideAds.getElementsByTagName("div")) return false;
	var gotdivs = gotsideAds.getElementsByTagName("div");

	// if the popout ad has funky inline styles, reset to proper values
	for (var i=0;i<gotdivs.length;i++)
	{
		switch(gotdivs[i].style.left)
		{
			case "-80px":
				gotdivs[i].style.left = "0";

				break;
			case "-260px":
				gotdivs[i].style.left = "-180px";

				break;
			default:
				gotdivs[i].style.left = gotdivs[i].style.left;
		}
	}

	// initialize gotads as all the div elements with a class of ad
	if (!getElementsByAnything("ad")) return false;
	var gotads = getElementsByAnything("ad");

	for (var i=0;i<gotads.length;i++)
	{
		// if the ad containers generate an ad containing floated content in Safari and Firefox, height will be small (14px, 17px, 18px) but should be full size
		if (gotads[i].offsetHeight == 14 || gotads[i].offsetHeight == 17 || gotads[i].offsetHeight == 18)
		{
			gotads[i].style.height = "60px";
		}

		// if the ad containers on the side do not generate an ad in IE, height will be small (16px, 12px) but messes with ad spacing. Change the size to zero and display to none for non-existent ads
		if (gotads[i].offsetHeight == 12 || gotads[i].offsetHeight == 16)
		{
			gotads[i].style.height = "0";
			gotads[i].style.display = "none";
		}

		// if the ad containers on the side do not generate an ad, change the size to zero and display to none for non-existent ads
		if (gotads[i].offsetHeight <= 1 || gotads[i].offsetHeight <= 1 && gotads[i].offsetHeight < 60)
		{
			gotads[i].style.height = "0";
			gotads[i].style.display = "none";
		}
	}
}

// end of fixsideAds()
/**********************************************************************************************/

/**********************************************************************************************/
// Client-side access to querystring name=value pairs
// http://adamv.com/dev/javascript/querystring

// optionally pass a querystring to parse
function Querystring(qs)
{
	this.params = {};
	this.get=Querystring_get;

	if (qs == null);
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0)
		return;

	// Turn <plus> back to <space>
	// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');

	// Turn ampersands into ampersands
	qs = qs.replace(/\%26/g, '&');

	// Turn equals signs into equals signs
	qs = qs.replace(/\%3D/g, '=');

	var args = qs.split('&'); // parse out name/value pairs separated via &

// split out each name=value pair
	for (var i=0;i<args.length;i++)
	{
		var pair = args[i].split('=');
		var name = unescape(pair[0]);

		var value = (pair.length==2)
			? unescape(pair[1])
			: name;

		this.params[name] = value;
	}
}

function Querystring_get(key, default_)
{
	var value=this.params[key];
	return (value!=null) ? value : default_;
}
/**********************************************************************************************/

/**********************************************************************************************/
function adicioHeader()
{
	// capture the querystring
	var q = new Querystring();

	// parse the querystring values
	var gotqTerms = q.get("qTerms");
	var gotqSearchTab = q.get("qSearchTab");

	// check to see if this a homes or rentals search
	if (gotqTerms == "rent" || gotqSearchTab == "rent")
	{
		// change document title
		document.title = "JSOnline Rentals";

		// change stylesheet
		if (!document.getElementsByTagName("link")) return false;
		var gotlinks = document.getElementsByTagName("link");

		for (var i=0;i<gotlinks.length;i++)
		{
			if (gotlinks[i].getAttribute("href") == "http://www.jsonline.com/templates/JSO_global.css?p=homes")
			{
				gotlinks[i].setAttribute("href","http://www.jsonline.com/templates/JSO_global.css?p=rentals");
			}
		}

		// initialize header element
		if (!document.getElementById("jsonline-classified-header")) return false;
		var gotheader = document.getElementById("jsonline-classified-header");
	}
}
// end of adicioHeader()
/**********************************************************************************************/

/**********************************************************************************************/
// allow enter keypress to submit form on input or select element, pass id of form element and id of submit element
// primarily for "psuedo-forms"; forms that have janky action-bypassing requirements
// submit element must be input element
// http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-2651361
function submitOnEnterKey(formidobj,submitidobj)
{
	// form element
	gotform = get_element(formidobj);
	if (!gotform) return false;

	// all input elements within form
	if (!gotform.getElementsByTagName("input")) return false;
	var gotinputs = gotform.getElementsByTagName("input");

	// all select elements within form
	if (!gotform.getElementsByTagName("select")) return false;
	var gotselects = gotform.getElementsByTagName("select");

	// submit element
	gotsubmit = get_element(submitidobj);
	if (!gotsubmit) return false;

	// attach event handlers to all input elements
	for (var i=0;i<gotinputs.length;i++)
	{
		gotinputs[i].onkeypress = function onEnterPress(e)
		{
			//define any varible
			var KeyPress;

			if(!e) e = window.event;

			KeyPress = e.keyCode ? e.keyCode : e.which;

			//13 is the key code of enter key
			if(KeyPress == 13)
			{
				//frmLogin is the name of form
				gotsubmit.click();

				return false;
			}
			else
			{
				return true;
			}
		}
	}

	// attach event handlers to all select elements
	for (var i=0;i<gotselects.length;i++)
	{
		gotselects[i].onkeypress = function onEnterPress(e)
		{
			//define any varible
			var KeyPress;

			if(!e) e = window.event;

			KeyPress = e.keyCode ? e.keyCode : e.which;

			//13 is the key code of enter key
			if(KeyPress == 13)
			{
				//frmLogin is the name of form
				gotsubmit.click();

				return false;
			}
			else
			{
				return true;
			}
		}
	}
}
// end of submitOnEnterKey()
/**********************************************************************************************/

/**********************************************************************************************/
// toggle element visibility, pass id of element and mode (show, hide or toggle)
function jsonlineToggleElementVisibility(idobj,modeobj)
{
	// element
	if (!document.getElementById(idobj)) return false;
	var gotelement = document.getElementById(idobj);

	switch(modeobj)
	{
		case("show"):
			// show element
			gotelement.style.visibility = "visible";

			break;
		case("hide"):
			// hide element
			gotelement.style.visibility = "hidden";

			break;
		default:
			// toggle element visibility
			if(gotelement.style.visibility == "hidden")
			{
				gotelement.style.visibility = "visible";
			}
			else
			{
				gotelement.style.visibility = "hidden";
			}
	}
} // end of jsonlineToggleElementVisibility()
/**********************************************************************************************/
/**********************************************************************************************/
// pass it something, check if is valid element or if it is id to get element, returns element if found. Sanity check for functions and if you use this function 20 times through all your functions calls to get the same element you only do 1 DOM traverse by using whatever it returns
function get_element(thing)
{
	if (typeof(thing) == 'undefined' || !thing)
	{
		return null;
	}
	else if (typeof(thing.tagName) == 'undefined' || !thing.tagName)
	{
		if (document.all)
		el = document.getElementById(thing) ? document.getElementById(thing) : document.all[thing];
	else
		el = document.getElementById(thing);

		if (el)
			return el;
		else
			return null;
	}
	else if (thing.tagName)
	{
		return thing;
	}
	else
	{
		return null;
	}
} // end of get_element()
/**********************************************************************************************/

/**
Checks if an element has a class
@param  el              element to check. Can be the id or the actual element
@param  searched_class  class to checked

@return boolean
**/
function has_class(el, searched_class)
{
  if (typeof(searched_class) == 'undefined')
    return false;

  // check valid parameter
 el = get_element(el);

  if (!el)
    return false;

  var class_array = el.className.split(' ');

  for(var i in class_array)
  {
    if (class_array[i] == searched_class)
      return true;
  }
  return false;
}

/**
Adds a class to an element
@param  el            element whose class to add. Can be the id or the actual element
@param  add_class     class to be added

@return nothing
**/
function add_class(el, added_class)
{
  if (typeof(added_class) == 'undefined')
    return false;

  // check valid parameter
  el = get_element(el);

  // if element doesn't exist, or class already there, or no class to add
  if (!el || has_class(el, added_class))
      return false;

  el.className = el.className + ' ' + added_class;

  return true;
}

/**
Removes a class from an element
@param  el            element whose class to remove. Can be the id or the actual element
@param  remove_class  class to be removed

@return nothing
**/
function remove_class(el, removed_class)
{
  if (typeof(removed_class) == 'undefined')
    return false;

  // check valid parameter
  el = get_element(el);

  // if element doesn't exist, or class not there, or no class to remove
  if (!el)
    return false;

  var class_array = el.className.split(' ');
  var class_changed = false;

  for (var i in class_array)
  {
    if (class_array[i] == removed_class)
    {
      // delete removed_class
      class_array.splice(i, 1);
      class_changed = true;
    }
  }

  if (class_changed)
    el.className = class_array.join(' ');

  return class_changed;
}

/**
Changes class of element
@param  el            element whose class to toggle. Can be the id or the actual element
@param  add_class     class to be added
@param  remove_class  clas to be removed

@return nothing
**/
// function toggle_class(el, added_class, removed_class)
// {
//   if (added_class)
//     add_class(el, added_class);
//
//   if (removed_class)
//     remove_class(el, removed_class);
// }

// new function to be tested
function toggle_class(el, added_class, removed_class)
{
  // check if adding
  add = false;
  if (typeof(added_class) != 'undefined' && added_class)
    add = true;

  // check if removing
  remove = false;
  if (typeof(removed_class) != 'undefined' && removed_class)
    remove = true;

  // if not adding or removing return
  if (!add && !remove )
    return false;

  el = get_element(el);

  // if element doesn't exist
  if (!el)
    return false;

  var class_array = el.className.split(' ');
  var class_changed = false;

  for (var i in class_array)
  {
    if (remove && class_array[i] == removed_class)
    {
      // delete removed_class
      class_array.splice(i, 1);
      class_changed = true;
    }

    if (add && class_array[i] == added_class)
      add = false;
  }

  if (add)
  {
    class_array[class_array.length] = added_class;
    class_changed = true;
  }

  if (class_changed)
    el.className = class_array.join(' ');

  return class_changed;
}

// sets or resets a box on focus/blur
function handle_edit_box(box, default_value, focused, disabledclass)
{
  var box = get_element(box);

  if (!box) return false;

    // old and busted
    //var val = trim(box.value).toLowerCase();

    // new hotness
	//var val = box.value.trim().toLowerCase();
	var val = box.value;
	val = val.toLowerCase();

	var def_val = default_value.toLowerCase();

  // if focused and non-default, value and black
  // if non-focused and non-default, value and black
  if (val !== def_val && val !== '')
  {
    remove_class(box, disabledclass);
    box.style.color='#000';
    return;
  }

  // if focused and default value, blank and black
  if (focused && (val === def_val || val === ''))
  {
    box.style.color = '#000';
    remove_class(box, disabledclass);
    box.value = '';
    return;
  }

  // if non-focused and default value, default and gray
  if (!focused)
  {
    if (val === def_val || val === '')
    {
      box.style.color = '#999';
      add_class(box, disabledclass);
      box.value = default_value;
    }
    else
    {
      box.style.color = '#000';
      remove_class(box, disabledclass);
    }
    return;
  }
}
/**********************************************************************************************/

/**********************************************************************************************/
function doclearInput(inputobj,stringobj,classobj)
{
	// initialize input element
	if (!get_element(inputobj)) return false;
	var gotinput = get_element(inputobj);

	gotinput.onfocus = function()
	{
		handle_edit_box(gotinput,stringobj,true,classobj);
	}
}
// end of doclearInput()
/**********************************************************************************************/

/**********************************************************************************************/
function doresetInput(inputobj,stringobj,classobj)
{
	// initialize input element
	if (!get_element(inputobj)) return false;
	var gotinput = get_element(inputobj);

	gotinput.onblur = function()
	{
		handle_edit_box(gotinput,stringobj,false,classobj);
	}
}
// end of doresetInput()
/**********************************************************************************************/

/**********************************************************************************************/
// search form in jsonline top bar
function jsonlineTopbarSearch()
{
	// search form container
	if (!document.getElementById("jsonline-topbar-search")) return false;
	var gotformcontainer = document.getElementById("jsonline-topbar-search");

	// search forms
	if (!gotformcontainer.getElementsByTagName("form")) return false;
	var gotforms = gotformcontainer.getElementsByTagName("form");

	for (var i=0;i<gotforms.length;i++)
	{
		// search form
		if (!gotforms[i]) return false;
		var gotform = gotforms[i];
	}

	// select elements

	if (!gotform.getElementsByTagName("select")) return false;
	var gotselects = gotform.getElementsByTagName("select");

	for (var i=0;i<gotselects.length;i++)
	{
		// select element
		if (!gotselects[i]) return false;
		var gotselect = gotselects[i];
	}

	// input elements
	if (!gotform.getElementsByTagName("input")) return false;
	var gotinputs = gotform.getElementsByTagName("input");

	for (var i=0;i<gotinputs.length;i++)
	{
		// current input element
		if (!gotinputs[i]) return false;
		var gotinput = gotinputs[i];

		// current input element type
		if (!gotinput.getAttribute("type")) return false;
		var gotinputtype = gotinput.getAttribute("type");

		switch(gotinputtype)
		{
			case("text"):
				// text input element
				var gottextinput = gotinput;

				break;
			case("hidden"):
				// hidden input element
				var gothiddeninput = gotinput;

				break;
			case("image"):
				// submit input element
				var gotsubmitinput = gotinput;

				break;
			default:
		}
	}

	// default form action
	if (!gotform.action) return false;
	var gotdefaultaction = gotform.action;

	// default keyword field name
	if (!gottextinput.name) return false;
	var gotdefaultkeywordname = gottextinput.name;

	// set defaults if keyword value is blank
	if(gottextinput.value === "")
	{
		// set default keyword field value and class
		gottextinput.value = "enter keywords";
		add_class(gottextinput, "disabled-text");
	}

	// attach event handlers to keyword field
	doclearInput(gottextinput,"enter keywords","disabled-text");
	doresetInput(gottextinput,"enter keywords","disabled-text");

	gotselect.onchange = function()
	{
		// after seach type is selected, place cursor in search text element
		gottextinput.focus();

		// capture selected search type
		if (!gotselect.options[gotselect.selectedIndex].value) return false;
		var gotselectedtype = gotselect.options[gotselect.selectedIndex].value;

		switch(gotselectedtype)
		{
			case("web"):
				// remove default class
				remove_class(gottextinput,"disabled-text");

				// blank text if default text
				if(gottextinput.value === "enter keywords")
				{
					gottextinput.value = "";
				}

				// change action to Yahoo! search
				// http://search.yahoo.com/info/ysearchbox_instructions.html
				gotform.action = "http://search.yahoo.com/search";

				// change keyword field name
				gottextinput.setAttribute("name", "p");

				// change hidden field name
				gothiddeninput.setAttribute("name", "fr");

				// change hidden field value
				gothiddeninput.setAttribute("value", "yscpb");

				// attach event handlers to keyword field
				doclearInput(gottextinput,"","powered-by-yahoo");
				doresetInput(gottextinput,"","powered-by-yahoo");

				break;
			case("jobs"):
				// remove yahoo class
				remove_class(gottextinput,"powered-by-yahoo");

				// change action to Monster search
				gotform.action = "http://jobnoggin.monster.com/search.aspx";

				// change keyword field name
				gottextinput.setAttribute("name", "q");

				// change hidden field name
				gothiddeninput.setAttribute("name", "where");

				// change hidden field value
				gothiddeninput.setAttribute("value", "Milwaukee, WI");

				// attach event handlers to keyword field
				doclearInput(gottextinput,"enter keywords","disabled-text");
				doresetInput(gottextinput,"enter keywords","disabled-text");

				break;
			case("realestate"):
				// remove yahoo class
				remove_class(gottextinput,"powered-by-yahoo");

				// change action to Adicio search
				gotform.action = "http://realestate.jsonline.com/properties/search/index.php";

				// change keyword field name
				gottextinput.setAttribute("name", "qKeywords");

				// change hidden field name
				gothiddeninput.setAttribute("name", "qAction");

				// change hidden field value
				gothiddeninput.setAttribute("value", "search");

				// attach event handlers to keyword field
				doclearInput(gottextinput,"enter keywords","disabled-text");
				doresetInput(gottextinput,"enter keywords","disabled-text");

				break;
			case("pets"):
				// remove yahoo class
				remove_class(gottextinput,"powered-by-yahoo");

				// change action to Gadzoo search
				gotform.action = "http://www.gadzoo.com/jsonline/adsearch.aspx";

				// change keyword field name
				gottextinput.setAttribute("name", "keyword");

				// attach event handlers to keyword field
				doclearInput(gottextinput,"enter keywords","disabled-text");
				doresetInput(gottextinput,"enter keywords","disabled-text");

				break;
			default:
				// remove yahoo class
				remove_class(gottextinput,"powered-by-yahoo");

				// reset form action to default action
				gotform.action = gotdefaultaction;

				// reset keyword field to default name
				gottextinput.setAttribute("name", gotdefaultkeywordname);

				// attach event handlers to keyword field
				doclearInput(gottextinput,"enter keywords","disabled-text");
				doresetInput(gottextinput,"enter keywords","disabled-text");
		}
	}

	// prepare input values upon form submit
	gotform.onsubmit = function()
	{
		// blank text if default text
		if(gottextinput.value === "enter keywords")
		{
			gottextinput.value = "";
		}

		// blank image map values
		gotsubmitinput.value = "";
	}
} // end of jsonlineTopbarSearch()
/**********************************************************************************************/

/**********************************************************************************************/
// Subscriber Services Dropdown
// Requires: JQuery library (no plugins)
function jsonlineTopbarSubscriberServicesDropdown()
{
	// container element
	var gotcontainer = $("#jsonline-topbar-subscriber-services");

	// menu control element
	var gottrigger = $(gotcontainer).find("img");

	// menu element
	var gotmenu = $(gotcontainer).find("ul");

	// ids of ads to hide
	var gotads = ["topBoxAd_Ext","peelad"];

	$(gottrigger).click(function()
	{
		// toggle menu when trigger is clicked
		$(gotmenu).toggle();

		// toggle header ads visibility when trigger is clicked (why not just use built in JQuery function? Because function changes display property, NOT visibility property)
		jQuery.each(gotads, function()
		{
			if($("#" + this).css("visibility") == "hidden")
			{
				$("#" + this).css({"visibility" : "visible"});
			}
			else
			{
				$("#" + this).css({"visibility" : "hidden"});
			}
		});
	});

	$(gotcontainer).bind("mouseleave", function()
	{
		// hide menu when mouse leaves menu
		$(gotmenu).hide();

		// show header ads when mouse leaves menu (why not just use built in JQuery function? Because function changes display property, NOT visibility property)
		jQuery.each(gotads, function()
		{
			$("#" + this).css({"visibility" : "visible"});
		});
	});
} // end of jsonlineTopbarSubscriberServicesDropdown()
/**********************************************************************************************/

/**********************************************************************************************/
// displays Newsletter Signup Links
function displayNewsletterSignupLinks()
{
    document.write ("\n<script language=\"javascript\" type=\"text/javascript\">\n    //alert(\"UID = \" + cookiejar.fetch(\"UID\") + \"\\ncurUserInfo = \" + subcookiejar.fetch(\"curUserInfo\", \"userName\"));    \n    document.write(\'<div class=\"newsletterSignupLinks\">\');\n    var url = window.location.href;\n    \n    if(cookiejar.fetch(\"UID\"))\n    {\n        if(subcookiejar.fetch(\"curUserInfo\"))\n        {\n            document.write(\'<p>Visit the member center to <a href=\"http://www.mymuskegonow.com/s?action=editReg&rurl=\' + url + \'\" style=\"padding:2px 0 2px 0;\">add</a> newsletters to your account.<p>\');\n        }\n    }\n    else\n    {\n        document.write(\'<p>Already a member of JSOnline?<br/>\');\n        document.write(\'<a href=\"http://www.mymuskegonow.com/s?action=login&rurl=\' + url + \'\">Login</a> to manage your account and add newsletters.<p>\');\n        \n        document.write(\'<p><p>Not a member of JSOnline yet?<br/>\');\n        document.write(\'<a href=\"http://www.mymuskegonow.com/s?action=reg&rurl=\' + url + \'\">Register</a> to become a member and get the newsletters you want.<p>\');\n    }\n    document.write(\'</div>\');\n</script>\n");
}
// end of displayNewsletterSignupLinks
/**********************************************************************************************/

/**********************************************************************************************/
// truncate string, pass string and number of characters to be displayed before appending ellipsis
// intended for simple client side strings (usernames, etc.) does not account for sentences, spaces
// do not user for server side purposes! use "Create Shortened String" template
// Example: "CheeseHead4Life" becomes "CheeseH..."
function jsonlineTruncate(stringobj,lengthobj)
{
	// string to truncate
	if (!stringobj) return ("");
	var gotstring = stringobj;

	// number of characters to be displayed before appending ellipsis
	var gotlength = lengthobj;

	// default number of characters if none specified
	if (!gotlength)
	{
		gotlength = 10;
	}

	return ((gotlength) < gotstring.length?(gotstring.slice(0,gotlength) + "&hellip;"):gotstring);
} // end of jsonlineTruncate()
/**********************************************************************************************/

/**********************************************************************************************/
// Requires: JQuery library (no plugins)
function jsonlineRentalsSearchFormDropdown(containerobj)
{
	// menu container
	var gotcontainer = $(containerobj);

	// menu trigger
	var gottrigger = $(gotcontainer).find("p");

	// menu element
	var gotmenu = $(gotcontainer).find(".inputgroup");

	// menu items
	var gotitem = $(gotcontainer).find("label");

	// menu item input
	var gotinput = $(gotcontainer).find("input:checked");

	// start off with all menus hidden
	$(gotmenu).hide();

	// show menus where sub inputs are checked/selected
	$(gotinput).each(function()
	{
		$(gotmenu).show();
	});

	$(gottrigger).click(function()
	{
		// toggle menu when trigger is clicked
		$(gotmenu).toggle();
	});

	$(gotitem).bind("mouseover", function()
	{
		// highlight item on hover
		$(this).addClass("active");
	});

	$(gotitem).bind("mouseleave", function()
	{
		// hide menu when mouse leaves menu
		$(this).removeClass("active");
	});
} // end of jsonlineRentalsSearchFormDropdown()
/**********************************************************************************************/

/**********************************************************************************************/
function jsonlineClassifiedInit(obj)
{
	switch(obj)
	{
		case("marketplace"):
			// search form
			milwaukeeMarketplaceSearchForm("mktsearchform","Keyword, Business Name, or Zip Code");

			break;
		default:
			// example
	}
} // end of jsonlineClassifiedInit()
/**********************************************************************************************/

/**********************************************************************************************/
// Milwaukee Marketplace search form
function milwaukeeMarketplaceSearchForm(formidobj,exampleobj)
{
	// search form
	if (!document.getElementById(formidobj)) return false;
	var gotform = document.getElementById(formidobj);

	// example text
	var gotexample = exampleobj;

	// input elements
	if (!gotform.getElementsByTagName("input")) return false;
	var gotinputs = gotform.getElementsByTagName("input");

	for (var i=0;i<gotinputs.length;i++)
	{
		// current input element
		if (!gotinputs[i]) return false;
		var gotinput = gotinputs[i];

		// current input element type
		if (!gotinput.getAttribute("type")) return false;
		var gotinputtype = gotinput.getAttribute("type");

		switch(gotinputtype)
		{
			case("text"):
				// text input element
				var gottextinput = gotinput;

				break;
			case("image"):
				// submit input element
				var gotsubmitinput = gotinput;

				break;
			case("submit"):
				// submit input element
				var gotsubmitinput = gotinput;

				break;
			default:
		}
	}

	// select elements
	if (!gotform.getElementsByTagName("select")) return false;
	var gotselects = gotform.getElementsByTagName("select");

	for (var i=0;i<gotselects.length;i++)
	{
		// select element
		if (!gotselects[i]) return false;
		var gotselect = gotselects[i];

		// vendor requirement for fill_category()
		gotselect.id = "category";
	}

	// DPC function
	// http://marketplace.milwaukeemarketplace.com/javascript/search-widget.js
	fill_category();

	// set defaults if text input value is blank
	if(gottextinput.value === "")
	{
		// set default text input value and class
		gottextinput.value = gotexample;
		add_class(gottextinput,"disabled-text");
	}

	// attach event handlers to text input
	doclearInput(gottextinput,gotexample,"disabled-text");
	doresetInput(gottextinput,gotexample,"disabled-text");

	// submit on enter key
	submitOnEnterKey(gotform,gotsubmitinput);

	gotform.onsubmit = function()
	{
		// blank text if default text
		if(gottextinput.value === gotexample)
		{
			gottextinput.value = "";
		}

		if(gotselect.value != 1)
		{
			gotform.action = 'http://marketplace.milwaukeemarketplace.com/search/marketplace/' + 'mp_root:' + gotselect.value + '/' + '?keyword=' + gottextinput.value;
		}

		// DPC function
		// http://marketplace.milwaukeemarketplace.com/javascript/search-widget.js
		//submit_search_all();
	}
} // end of milwaukeeMarketplaceSearchForm()
/**********************************************************************************************/

/**********************************************************************************************/
// sets element with specified class to be clickable, default destination is first <a> element within specified element
function jsonlineClickable(classobj)
{
	// initialize clickable element
	if (!getElementsByClassName(classobj)) return false;
	var gotelements = getElementsByClassName(classobj);

	// attach event handlers
	for (var i=0;i<gotelements.length;i++)
	{
		gotelements[i].onmouseover = function setClassCurrent()
		{
			add_class(this,"clickable");
		}

		gotelements[i].onmouseout = function setClassNothing()
		{
			remove_class(this,"clickable");
		}

		gotelements[i].onclick = function()
		{
			// initialize links within divs
			if (!this.getElementsByTagName("a")) return false;
			var gotlinks = this.getElementsByTagName("a");

			location.href = gotlinks[0].href;
		}
	}
} // end of jsonlineClickable()
/**********************************************************************************************/



function resizeGridImages(el,im){
var elmz = getElementsByClassName(el);
var imgelmz = getElementsByClassName(im);

for(x=0; x<elmz.length; x++)
{
var gridThumbWidth = parseInt(elmz[x].style.width) || elmz[x].offsetWidth;
var gridThumbHeight = ((gridThumbWidth * 70)/100);
elmz[x].style.height = gridThumbHeight + 'px';
imgelmz[x].style.width = gridThumbWidth + 'px';

var gridThumbImgHeight = parseInt(imgelmz[x].style.height) || imgelmz[x].offsetHeight;

if(gridThumbImgHeight < gridThumbHeight){
imgelmz[x].style.height = gridThumbHeight + 'px';
imgelmz[x].style.width = '';
}

}
}


