function openModalDiv(objDiv, addValue)
{
	var div = document.getElementById(objDiv);
	
	var documentBody = document.body;
	documentBody.style.overflow = "hidden";
	
	hideSelectBoxes("true");

	var popMask = document.createElement("div");
	popMask.id = "popup-mask";
	popMask.style.display = "block";
	setMaskSize(popMask);
	documentBody.appendChild(popMask);

	hideSelectBoxes("false", div);

	centerWindow(div, addValue);
	
	div.style.display = "block";
}

function closeModalDiv(objDiv)
{
	var documentBody = document.body;
	documentBody.style.overflow = "auto";
	
	var div = document.getElementById(objDiv);
	
	hideSelectBoxes("false");
	
	var popMask = document.getElementById("popup-mask");
	documentBody.removeChild(popMask);
	
	div.style.display = "none";	
}

function setMaskSize(objMask)
{
	var documentBody = document.body;
		
	var popHeight;
	var popWidth;

	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();

	if (fullHeight > documentBody.scrollHeight)
	{
		popHeight = fullHeight;	
	}
	else
	{
		popHeight = documentBody.offsetHeight;	
	}

	if (fullWidth > documentBody.scrollWidth)
	{
		popWidth = fullWidth;	
	}
	else
	{
		popWidth = documentBody.scrollWidth;	
	}

	objMask.style.height = popHeight + 1500 + "px";
	objMask.style.width = popWidth + "px";
}


function centerWindow(objDiv, addValue)
{
	addValue = addValue == undefined ? 0 : addValue;
	
	scrollYPosition = getScrollYPosition();
	
	pageWidth = getPageWidth();
	pageHeight = getPageHeight();

	topPosition = parseInt(scrollYPosition + (pageHeight - objDiv.offsetHeight) / 2) + addValue;
	
	objDiv.style.top = topPosition + "px";
	objDiv.style.zIndex = 150000;
}

function getViewportHeight() 
{
	if (window.innerHeight != window.undefined) return window.innerHeight;
	if (document.compatMode == 'CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}

function getViewportWidth() 
{
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

function hideSelectBoxes(boolValue, obj) 
{
	if (obj == undefined)
	{
		obj = document;
	}
	
	var arrSelectBoxes = obj.getElementsByTagName("select");

	for(var i = 0; i < arrSelectBoxes.length; i++) 
	{
		if (boolValue == "true")
		{
			arrSelectBoxes[i].style.visibility = "hidden";	
		}
		else
		{
			arrSelectBoxes[i].style.visibility = "visible";	
		}
	}
}

/*
*************************************************
AUXILIAR FUNCTIONS
*************************************************
*/

function getScrollYPosition()
{
	var aux;
	var agt = new getBrowser();
	
	if (agt.browser == "Firefox")
	{ 
		aux = window.pageYOffset;
	}
	else if (agt.browser == "Explorer")
	{
		aux = document.documentElement.scrollTop;	
	}
	else
	{
		aux = document.body.scrollTop;	
	}

	return aux;
}

function getPageWidth()
{
	var aux;
	var agt = new getBrowser();
	
	if (agt.browser == "Firefox")
	{ 
		aux = self.innerWidth;
	}
	else
	{
		aux = document.body.offsetWidth;
	}

	return aux;
}


function getPageHeight()
{
	var aux;
	
	var agt = new getBrowser();
	
	if (agt.browser == "Firefox")
	{ 
		aux = self.innerHeight;
	}
	else if (agt.browser == "Explorer")
	{
		aux = document.documentElement.offsetHeight;
	}
	else
	{
		aux = self.innerHeight;
	}
	
	return aux;
}


function getBrowser()
{
	BrowserDetect.init();
	
	this.browser = BrowserDetect.browser;
	this.version = BrowserDetect.version;
	this.os = BrowserDetect.OS;
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
