/**
 * Stringbuffer object.
 * @return
 */
function StringBuffer() 
{ 
   this.buffer = []; 
 } 

 StringBuffer.prototype.append = function append(string) 
 { 
   this.buffer.push(string); 
   return this; 
 }; 

 StringBuffer.prototype.toString = function toString() 
 { 
   return this.buffer.join(""); 
 }; 

/**
 * TOOLTIP API.
 * There are two methods, tootip_show and tooltip_hide that do as their names
 * suggest. In both cases the element id of the tooltip div (which must be
 * setup on the page that wants to use it) must be passed in.
 * 
 * Example Usage: Mouseover event will cause the div to appear. The mouse out
 * will make it disapear. Send the content of the div (text/html) as
 * the parameter of the tooltip_show method.
 * 
 * <pre>
 *  GEvent.addListener(shotPolyline, 'mouseover', function() 
	{ 
		tooltip_show(divId, shotPolyline.getLength());
	});
	
	GEvent.addListener(shotPolyline, 'mouseout', function() 
	{ 
		tooltip_hide(divId);
	});
 * </pre>
 */
function tooltip_show(msg)
{
	var div = document.getElementById(divId);
	div.style.top  = (tmpY) + 'px';   
	div.style.left = (tmpX) + 'px';   
	  
	div.innerHTML = '<p style="background-color:white;">' + msg + '</p>';   
	div.style.visibility = 'visible';   
}   
	  
function tooltip_hide(divId)
{   
	var div = document.getElementById(divId);
	div.style.visibility = 'hidden';   
}

/**
 * Sets the tmpX and tmpY coordinates for the mouse cursor location.
 * 
 * Usage: on a page that requires it:
 *
 * Global access to the current mouse cursor position on the page.
	var IE = document.all ? true : false;
	if (!IE) document.captureEvents(Event.MOUSEMOVE);

	document.onmousemove = getXY;

	var tmpX = 0;
	var tmpY = 0;
 * 
 * @param e event
 * @return
 */
function getXY(e) 
{
	if (IE) 
	{ 
		tmpX = event.clientX + document.body.scrollLeft;
		tmpY = event.clientY + document.body.scrollTop;
	}
	else
	{  
		tmpX = e.pageX;
		tmpY = e.pageY;
	}  
    if (tmpX < 0)
    {
    	tmpX = 0;
    }
    if (tmpY < 0)
    {
    	tmpY = 0;
    }

    return true;
 }

/**
 * Returns true if the obj is
 * 	null
 * 	undefined
 * 	"null"
 * 
 * @param obj
 * @return
 */
function isNull(obj)
{
	return (obj == undefined || obj == null || obj == "null" || obj == "undefined" || obj.length == 0);
}

function marshallDate(yyyymmdd)
{
	var da = yyyymmdd.split("-");
	
	var now = new Date(da[0],da[1]-1,da[2]);

	return now;
}

function unmarshallDate(aDate)
{
	return aDate.getDate()+ "/" + (aDate.getMonth() + 1) + "/" + aDate.getFullYear();
}

/**
 * Round a number to a specific number of decimal places.
 */
function roundNumber(num, numOfDecimalPlaces)
{
	var result = Math.round(num*Math.pow(10,numOfDecimalPlaces))/Math.pow(10,numOfDecimalPlaces);
	return result;
};
