String.prototype.trim = function(s) { return s.replace(/^\s+|\s+$/g, ''); };
String.prototype.find = function(s) { return(this.indexOf(s) >= 0 ? true : false); }

// Various utility functions used throughout the framework
var Util = {

// oObj is either an object or the id of an  object
Get: function (oObj) { return (typeof oObj === 'string') ? document.getElementById(oObj) : oObj; },

// oObj is an object, the id of an object, an array of ids/objects. Returns an array of objects.
Gets: function (oObj)
{
	// We were passed an array of ids and objects
	if (!(oObj instanceof Array)) return [ Util.Get(oObj) ];
	
	for (var i = 0; i < oObj.length; i ++)
		oObj[i] = Util.Get(oObj[i]);
		
	return oObj;
},

// Makes an xmlHTTPRequest to sUrl and calls function f when the request returns. Be sure to append "?sid=" + Math.random() to sUrl
LoadXMLDoc: function (sUrl, f) {
 	var xmlHttp;
 	
    if (window.XMLHttpRequest)
        xmlHttp = new XMLHttpRequest();
    else if (window.ActiveXObject)
		 xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	
	if (f) xmlHttp.onreadystatechange =  function () { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) f(xmlHttp.responseText); };
	
    xmlHttp.open('GET', sUrl, true);
    xmlHttp.send(null);
},

// AddEvent(window, 'load', fFoo)
AddEvent: function (oObj, sEventType, fCallback) {
	oObj = Util.Get(oObj);
	if (oObj.addEventListener) {
		oObj.addEventListener(sEventType, fCallback, false);
		return true;
	} else if (oObj.attachEvent) {
		return oObj.attachEvent('on' + sEventType, fCallback);
	} else
		return false;
},

// iOpacity is an integer between 0 and 100
SetOpacity: function (oObj, iOpacity) {
	oObj = Util.Get(oObj);
    oObj.style.opacity = (iOpacity / 100);
    oObj.style.MozOpacity = (iOpacity / 100);
    oObj.style.KhtmlOpacity = (iOpacity / 100);
    oObj.style.filter = 'alpha(opacity=' + iOpacity + ')';
},

GetElementWidth: function(oObj) {
	oObj = Util.Get(oObj);
	return oObj.clientWidth || oObj.offsetWidth;
},

GetElementHeight: function(oObj) {
	oObj = Util.Get(oObj);
	return oObj.clientHeight || oObj.offsetHeight;
},

GetWindowHeight: function() { return document.documentElement.clientHeight || document.body.clientHeight || self.innerHeight || 0; },
GetWindowWidth: function() { return document.body.clientWidth || self.innerWidth || document.documentElement.clientWidth || 0; },

//	Returns the position of the left side of an object on the page.
GetLeft: function (oObj) {
	oObj = Util.Get(oObj);
	var pL = 0;
	while(oObj) { pL += oObj.offsetLeft; oObj = oObj.offsetParent; }
	return pL;
},

//	Returns the position of the top of an object on the page.
GetTop: function (oObj) {
	oObj = Util.Get(oObj);
	var pL = 0;
	while(oObj) { pL += oObj.offsetTop; oObj = oObj.offsetParent; }
	return pL;
},

QueryString: function (key) {
	var tmp = (location.search.substring(1));
	var i = tmp.toUpperCase().indexOf(key.toUpperCase() + '=');
	
	if (i >= 0)	{
		tmp = tmp.substring(key.length + i + 1);
		i = tmp.indexOf('&');
		return unescape(tmp = tmp.substring(0, (i >= 0) ? i : tmp.length));
	}
	return '';
},

CreatePopup: function (sURL, iWidth, iHeight, iTop, iLeft) {
	var sParams = 'width=' + iWidth + ',height=' + iHeight + ',titlebar=no,scrollbars=yes,resizable=yes,top=' + iTop + ',left=' + iLeft;
	window.open(sURL, null, sParams);
},

ToggleVisibility: function (oObj) {
	oObj = Util.Get(oObj);
	oObj.style.visibility = oObj.style.visibility == 'visible' ? 'hidden' : 'visible';
},

// Disables selection of text via clicking and highlighting w/ the mouse for the provided object
DisableSelection: function(oObj) {
	oObj = Util.Get(oObj);
	
	oObj.style.MozUserSelect = 'none';
	oObj.style.KhtmlUserSelect = 'none';
	oObj.onselectstart = function() { return false; };
},

EnableSelection: function(oObj) {
	oObj = Util.Get(oObj);
	
	oObj.style.MozUserSelect = 'text';
	oObj.style.KhtmlUserSelect = 'auto';
	oObj.onselectstart = function() { return true; };
},

FixIE_PNGs: function () {
	var arVersion = navigator.appVersion.split("MSIE") 
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (document.body.filters)) {
	   for(var i=0; i<document.images.length; i++) {
	      var img = document.images[i]
	      var imgName = img.src.toUpperCase()
	      if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
	         var imgID = (img.id) ? "id='" + img.id + "' " : ""
	         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	         var imgStyle = "display:inline-block;" + img.style.cssText 
	         if (img.align == "left") imgStyle = "float:left;" + imgStyle
	         if (img.align == "right") imgStyle = "float:right;" + imgStyle
	         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	         var strNewHTML = "<span " + imgID + imgClass + imgTitle
	         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
	         img.outerHTML = strNewHTML
	         i = i-1
	      }
	   }
	}
}

};
/*
var WhiteSpace = {

IsAllWs: function(nod) { return !(/[^\t\n\r ]/.test(nod.data)); },
IsIgnorable : function(nod) { return (nod.nodeType == 8) || ((nod.nodeType == 3) && WhiteSpace.IsAllWs(nod)); },

NodeBefore: function (sib) {
    while ((sib = sib.previousSibling)) {
        if (!WhiteSpace.IsIgnorable(sib)) return sib;
    }
    return null;
},

NodeAfter: function (sib) {
    while ((sib = sib.nextSibling)) {
        if (!WhiteSpace.IsIgnorable(sib)) return sib;
    }
    return null;
},

LastChild: function(par) {
    var res = par.lastChild;
    while (res) {
        if (!WhiteSpace.IsIgnorable(res)) return res;
        res = res.previousSibling;
    }
    return null;
},

FirstChild: function WhiteSpace.IsIgnorable(par) {
    var res = par.firstChild;
    while (res) {
        if (!is_ignorable(res)) return res;
        res = res.nextSibling;
    }
    return null;
},

// Extracts data that doesn't include whitespace at the beginning and end and normalizes all whitespace to a single space. 
DataOf: function(txt)
{
    var data = txt.data;
    data = data.replace(/[\t\n\r ]+/g, " ");
    if (data.charAt(0) == " ") data = data.substring(1, data.length);
    if (data.charAt(data.length - 1) == " ") data = data.substring(0, data.length - 1);
    
    return data;
}

};
*/

var Nifty = {

Rounded: function (selector, bk, color, size) {
	var i;
	var v = Util.Gets(selector);
	var l = v.length;
	for(i = 0; i < l; i ++) {
		Nifty.AddTop(v[i],bk,color,size);
		Nifty.AddBottom(v[i],bk,color,size);
    }
},

RoundedTop: function (selector,bk,color,size) {
	var i;
	var v = Util.Gets(selector);
	for(i = 0; i < v.length; i ++)
		Nifty.AddTop(v[i], bk, color, size);
},

RoundedBottom: function (selector,bk,color,size) {
	var i;
	var v = Util.Gets(selector);
	for(i = 0; i < v.length; i ++)
		Nifty.AddBottom(v[i],bk,color,size);
},

AddTop: function (el,bk,color,size) {
	var i;
	var d = document.createElement("b");
	var cn = "r";
	var lim = 4;
	
	if(size && size=="small") {
		cn = "rs";
		lim = 2;
	}
	
	d.className="rtop";
	d.style.backgroundColor = bk;
	
	for(i = 1; i <= lim; i ++) {
		var x = document.createElement("b");
		x.className = cn + i;
		x.style.backgroundColor = color;
		d.appendChild(x);
	}
	
	el.insertBefore(d,el.firstChild);
},

AddBottom: function (el,bk,color,size) {
	var i;
	var d=document.createElement("b");
	var cn="r";
	var lim=4;
	if(size && size=="small"){ cn="rs"; lim=2}
	d.className="rbottom";
	d.style.backgroundColor=bk;
	for(i=lim;i>0;i--){
		var x=document.createElement("b");
		x.className=cn + i;
		x.style.backgroundColor=color;
		d.appendChild(x);
		}
	el.appendChild(d,el.firstChild);
}

}