//buscar a cotacao do dolar
function cotacaoDolar(strElmtDestinatario, strPrefixo, strSufixo){
	if(strPrefixo == undefined){
		strPrefixo = '';
	}

	if(strSufixo == undefined){
		strSufixo = '';
	}

	$.post(strBaseUrl + 'sites/coremal/getCotacaoDolar.php',null,function(strResultado){
		if(strResultado == 'false'){
			$(strElmtDestinatario).text('U$: Não disponível');
		}else{
			$(strElmtDestinatario).html(strPrefixo + strResultado + strSufixo);
		}
	});
}

var shownWindow;
var contentLoaded = true;
var janelaProcessos = false;

function openWindow(windowID,cwidth,cheight){
	if (!contentLoaded) return ;
	if (shownWindow != null) hideWindow();

	var loadingDiv = document.getElementById( windowID );

	var pageSize = getPageSize();
	var pageScroll = getPageScroll();
	var ctop = pageScroll.yScroll + ((pageSize.windowHeight - cheight - 26) / 2);
	var cleft = ((pageSize.pageWidth - cwidth - 40) / 2);

	var altura1 = pageSize.windowHeight;
	var altura2 = document.body.scrollHeight;
	if (altura1<=altura2) {
		alturaFade = altura2;
	} else {
		alturaFade = altura1;
	}
	//var alturaFade = document.body.scrollHeight;

	var ver = navigator.appVersion;

	if (ver.indexOf("MSIE") != -1) {
		// Internet Explorer
		document.getElementById('fade').style.setAttribute('visibility','visible');
		document.getElementById('fade').style.setAttribute('display','block');
		document.getElementById('fade').style.setAttribute('width',pageSize.pageWidth);
		//document.getElementById('fade').style.setAttribute('height',pageSize.windowHeight);
		document.getElementById('fade').style.setAttribute('height',alturaFade);
		document.getElementById('fade').style.setAttribute('position','absolute');

		loadingDiv.style.setAttribute('position', 'absolute');
		loadingDiv.style.setAttribute('left', parseInt(cleft));
		loadingDiv.style.setAttribute('top', parseInt(ctop));
		loadingDiv.style.setAttribute('visibility', 'visible');
		loadingDiv.style.setAttribute('display', 'block');

	} else {
		// Outros
		$('#fade').css('height',alturaFade);
		$('#fade').show();
		loadingDiv.setAttribute('style',"position:absolute;left:"+cleft+"px;top:"+ctop+"px;visibility:visible");
	}

	shownWindow = loadingDiv;
}

function hideWindow(){
	if (shownWindow == null) return ;

	var ver = navigator.appVersion;

	if (ver.indexOf("MSIE") != -1) {
		// Internet Explorer
		document.getElementById('fade').style.setAttribute('visibility','hidden');
		document.getElementById('fade').style.setAttribute('display','none');
		shownWindow.style.setAttribute( "display" , "none" );
		shownWindow.style.setAttribute( "visibility" , "hidden" );

	} else {
		// Outros
		shownWindow.setAttribute("style","visibility:hidden;position:absolute;display:none;");
		document.getElementById('fade').setAttribute("style","display:none;");

	}

	shownWindow = null;
}

function getScreenSize(){
	var screenW = 0, screenH = 0;
	if (parseInt(navigator.appVersion)>3) {
	 screenW = screen.width;
	 screenH = screen.height;
	}
	else if (navigator.appName == "Netscape"
	    && parseInt(navigator.appVersion)==3
    	&& navigator.javaEnabled()
	   )
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenW = jScreenSize.width;
	 screenH = jScreenSize.height;
	}
	retval={screenW:0,screenH:0};
	retval.screenW = screenW;
	retval.screenH = screenH;
	return retval;
}

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){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
	return arrayPageSize;
	//alert('pageWidth:'+pageWidth+' pageHeight:'+pageHeight+' windowWidth:'+windowWidth+' windowHeight:'+windowHeight);
}

function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = {yScroll:yScroll};
	return arrayPageScroll;
}

function findPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
      while(1)
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}


