/***********************************************************************
 * supportUtil.js
 *
 * Copyright 2007 CCH, a Wolters Kluwer Business
 *
 * A collection of Javascript utilities that may or may not be useful
 * on support.cch.com.
 ***********************************************************************/

////////////////////
// EventAttacher
// obj: the object that the event is to be attached to.
// evt: the name of the event.  Do not add the "on".
// fnc: the function pointer that is to be called.
function EventAttacher(obj, evt, fnc)
{
	var thisEvent = evt;
	
	// Strip off the "on", because we know that SOMEBODY
	// is going to leave it there and wonder why this thing
	// doesn't work.
	if (thisEvent.toLowerCase().substr(0, 2) == "on")
	{
		thisEvent = thisEvent.substr(2);
	}
	
	if (obj.addEventListener)
	{
		obj.addEventListener(thisEvent, fnc, false);
	}
	else if (obj.attachEvent)
	{
		obj.attachEvent("on" + thisEvent, fnc);
	}
	else
	{
		// Older browser.  This might not even work.
		if (obj["on" + thisEvent] != null)
		{
			var sfx = "" + (Math.floor(Math.random() * 8675309) % 1000); // Jenny (867-5309)
			var p = "old" + thisEvent + sfx;
			window[p] = [obj["on" + thisEvent], fnc];
			obj["on" + thisEvent] = new Function("for (var i = 0; i < window[\"" + p + "\"].length; i++){window[\"" + p + "\"][i]();}");
		}
		else
		{
			obj["on" + thisEvent] = fnc;
		}
	}
}
////////////////////
// EventDetacher
// obj: the object that you want to detach the event from
// evt: the name of the event.  Do not add the "on".
// fnc: the function pointer that is to be detached.
function EventDetacher(obj, evt, fnc)
{
	var thisEvent = evt;
	if (thisEvent.toLowerCase().substr(0, 2) == "on")
	{
		thisEvent = thisEvent.substr(2);
	}
	
	if (obj.removeEventListener)
	{
		obj.removeEventListener(thisEvent, fnc, false);
	}
	else if (obj.detachEvent)
	{
		obj.detachEvent("on" + thisEvent, fnc);
	}
	else
	{
		// In this case, we lose ALL event handlers.
		obj["on" + thisEvent] = null;
	}
}
// Cookie Parser
function siCookieParser_getValue(name)
{
	if (this.cookies[name])
	{
		return this.cookies[name];
	}
	return null;
}
function siCookieParser(cookieString)
{
	this.cookies = new Object();
	var cookieValues = cookieString.split(/;\s*/);
	this.cookieCount = cookieValues.length;
	for (var i = 0; i < cookieValues.length; i++)
	{
		var cookie = cookieValues[i].split("=");
		this.cookies[cookie[0]] = cookie[1];
	}
}
siCookieParser.prototype.getValue = siCookieParser_getValue;
EventAttacher(window, "load", function( )
{
	$("#siTabList img").each(function( )
	{
		if ($(this).attr("width") == "90")
		{
			$(this).attr("width", "80");
		}
		else if ($(this).attr("width") == "115")
		{
			$(this).attr("width", "105");
		}
	});
});