function trim(v)
{
	while(v.length>0 && v.charAt(v.length-1) == ' ') v = v.substr(0, v.length-1);
	while(v.length>0 && v.charAt(0) == ' ') v = v.substr(1);
	return v;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function findFirstNode(node, name)
{
	if (node == null) return null;
	var n = node.firstChild;
	while(n != null)
	{
		if (n.nodeName == name) break;
		n = n.nextSibling;
	}
	return n;
}

function getXmlHttp()
{
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function t_over(elem)
{
	if (elem.btnEnabled)
	{
		if (buttons[elem.id].bToggled)
			elem.src = "gmap/d_" + elem.id + ".gif";
		else
			elem.src = "gmap/h_" + elem.id + ".gif";
	}
}

function t_out(elem)
{
	if (elem.btnEnabled)
	{
		if (buttons[elem.id].bToggled)
			elem.src = "gmap/d_" + elem.id + ".gif";
		else
			elem.src = "gmap/n_" + elem.id + ".gif";
	}
}

function t_down(elem)
{
	if (elem.btnEnabled)
	{
		elem.src = "gmap/d_" + elem.id + ".gif";
	}
}

function t_upall()
{
	for(var i in buttons)
		if (buttons[i].update != null)
			buttons[i].update();
}

function t_up(elem)
{
	if (buttons[elem.id].bToggle == true)
		buttons[elem.id].bToggled = (buttons[elem.id].bToggled == true ? false : true);
	t_out(elem);
	if (elem.btnEnabled)
	{
		if (buttons[elem.id].onClick != null)
			buttons[elem.id].onClick();
	}
}

function t_isToggled(id)
{
	return buttons[id].bToggled == true;
}

function setButtonEnabled(id, isEnabled)
{
	var elem = document.getElementById(id);
	if (elem != null && elem.btnEnabled != isEnabled)
	{
		elem.btnEnabled = isEnabled;
		if (isEnabled)
			elem.src = "gmap/n_" + id + ".gif";
		else
			elem.src = "gmap/x_" + id + ".gif";
	}
}
