//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;

	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll()
	{
	var xScroll, yScroll;

	if (self.pageXOffset)
		xScroll = self.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft)	 // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;
	else if (document.body) // all other Explorers
		xScroll = document.body.scrollLeft;

	if (self.pageYOffset)
		yScroll = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	else if (document.body) // all other Explorers
		yScroll = document.body.scrollTop;

	arrayPageScroll = new Array(xScroll, yScroll);
	
	return arrayPageScroll;
	}

//
// 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;
	}

// Determina posição X do mouse
function getMouseX(evt) 
	{
	if (!evt) evt = window.event; 

	if (evt.pageX)
		return evt.pageX;
	else if (evt.clientX)
		return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	else
		return 0;
	}

// Determina posição X do mouse
function getMouseY(evt) 
	{
	if (!evt) evt = window.event;

	if (evt.pageY)
		return evt.pageY; 
	else if (evt.clientY)
		return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	else
		return 0;
	}

function getQueryString(Texto)
	{
	var Objeto = new Object();

	Texto.replace(new RegExp( "([^?=&]+)(=([^&]*))?", "g" ), function( $0, $1, $2, $3 ) { Objeto[$1] = $3; });

	return Objeto;
	}

// Seleciona o checkbox de acordo com o critério e tipo
function EWM_Checkbox_Seleciona(Formulario, Criterio, Tipo)
	{
	var Expressao = new RegExp(Criterio);

	for (var Posicao = 0; Posicao < Formulario.elements.length; Posicao++)
		{
		if (Formulario.elements[Posicao].type == 'checkbox')
			{
			// Remove seleção
			if (Tipo == 0 && (Expressao.test(Formulario.elements[Posicao].name) || Formulario.elements[Posicao].value == Criterio))
				Formulario.elements[Posicao].checked = false;
			// Busca pelo valor
			else if ((Tipo == 3 || Tipo == 4) && Formulario.elements[Posicao].value == Criterio)
				Formulario.elements[Posicao].checked = (Tipo == 4 ? !Formulario.elements[Posicao].checked : true);
			// Expressão regular
			else if ((Tipo == 1 || Tipo == 2) && Expressao.test(Formulario.elements[Posicao].name))
				Formulario.elements[Posicao].checked = (Tipo == 2 ? !Formulario.elements[Posicao].checked : true);
			}
		}
	}
