function scaleIsotropically(inpHeight, inpWidth, maxOutHeight, maxOutWidth)
{
	var scaleX = inpWidth/maxOutWidth;
	var scaleY = inpHeight/maxOutHeight;

	if(maxOutWidth < inpWidth)
	{
		scaleX = maxOutWidth/inpWidth;
		scaleY = maxOutHeight/inpHeight;
	}

	var scale  = (scaleY < scaleX) ? (scaleX) : (scaleY);
	var h = inpHeight * scale;
	var w = inpWidth * scale;
	return new imgOutputDim(h, w);
}

function imgOutputDim(height, width)
{
	this.height = height;
	this.width  = width;
}

function padZeros(value, strLength)
{
	var vStr = value.toString();
	
	while(vStr.length < strLength)
	{vStr= '0' + vStr;}
	
	return vStr;
}

function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function popUpWindow(URLStr, left, top, width, height)
{
  popUpWin = open(URLStr, '', 'toolbar=no,location=no,directories=no,statusbar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function loadingDiv(pos, pLeft, pTop, pWidth, pHeight, isLoading, msg)
{
	var objLoad  = objById('loadingInfo');
	var strHTML  = "";
	var styleVis = 'hidden'; 
	
	isLoading = (isLoading == null) ? ('true') : isLoading;
	
	if(isLoading)
	{	
		styleVis = 'visible';
		pos = (pos == null) ? ('absolute') : pos;
		l   = (pLeft == null) ? (100) : pLeft;
		t   = (pTop == null) ? (100) : pTop;
		w   = (pWidth == null) ? (100) : pWidth;
		h   = (pHeight == null) ? (40) : pHeight;
		msg = (msg == null) ? ('A carregar ...') : msg;
		
		strHTML += "<table id='tblLoad' width='150' border='0' cellpadding='0' cellspacing='0' background='/export/imagens/loadingBck.gif'>";
		strHTML += "<tr><td height='30' align='center' valign='middle'>" + msg + "</td></tr>";
		strHTML += "<tr><td height='10' align='center' valign='middle'></td></tr>";
		strHTML += "<tr><td align='center' valign='middle'><img name='imgLoad' border='0' src='/export/imagens/loading.gif' width='100px' height='22px' alt='A carregar ...'></td></tr>";
		strHTML += "<tr><td height='10' align='center' valign='middle'></td></tr>";
		strHTML += "<tr><td height='5' align='center' valign='middle'></td></tr>";
		strHTML += "</table>";		
		
		objLoad.style.position = pos;
		objLoad.style.left     = l;
		objLoad.style.top      = t;
		objLoad.style.width    = w;
		objLoad.style.height   = h;		
	}
	else
	{
		styleVis = 'hidden';
	}
	
	objLoad.style.position   = pos;
	objLoad.style.visibility = styleVis;
	objLoad.innerHTML        = strHTML;
}

function objById(objId)
{
	return document.getElementById(objId);
}

function msgErro(msg)
{
	msg = (msg == null) ? 'Lamentamos, mas por motivos técnicos não é possivel carregar a sua imagem.' : msg;
	alert(msg);
}

function loadStyleSheet (doc, sheetURL, mediaTypes) {
  var link;
  if (doc.createElement && (link = doc.createElement('link'))) {
    link.rel = 'stylesheet';
    link.href = sheetURL;
    link.type = 'text/css';
    if (mediaTypes) {
      link.media = mediaTypes;
    }
    var head = doc.getElementsByTagName('head')[0];
    if (head) {
      head.appendChild(link);
    }
  }
}

function perguntar(texto){
	return window.confirm(texto);
}

function browserSimpleDetection(){
	if(document.all) return 'ie'; //Internet Explorer
	if(document.layers) return 'ns'; //Netscape
	if(document.getElementById && !document.all) return 'ot'; //Other
}

function MousePos(x,y){this.x=x;this.y=y;}
function captureMousePosition() {
	var mouse = new MousePos(-5000,-5000);
	mouse.x   = window.event.x;
	mouse.y   = window.event.y;	
			
	return mouse;
}

function getRoundDec(decVal,precisionDigits){
	return decVal.toFixed(precisionDigits);
}
