//Currency Format*************************************

function currencyFormat(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '-0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

//---------------------------------------------------------------------------------------------
function ShowDialog(sPage,iWidth,iHeight){
 if (window.showModalDialog) {
  resp = window.showModalDialog(sPage, window, "dialogWidth:" + iWidth + "px;dialogHeight:" + iHeight + "px; status:no; help:no; resizable:no;scroll:no;center:yes");
  return resp;
  }
 else
     {
  posx = (screen.width/4)
  posy = (screen.height/4)-30

  window.open(sPage,"Dialog", "height=" + iHeight + ",width=" + iWidth + ",top=" + posy + ",left=" + posx + ",toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,modal=yes");
  
  }
 
}

//*************************************
function txtBoxFormat(strField, sMask, evtKeyPress) {

var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
	nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
	nTecla = evtKeyPress.which;
}

sValue = strField.value;

// Limpa todos os caracteres de formatação que já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( ":", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
bolMask = bolMask || ((sMask.charAt(i) == ":"))

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

strField.value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}

        function showHideContent(id, show, left)
            {
            var elem = document.getElementById(id);
            if (elem) 
            {
            if (show) 
               {
                tela = ((screen.availheight)-220);
                altura = parseInt(elem.style.height); 
                elem.style.top = (tela - altura) + "px";
                elem.style.left = parseInt(left+20) +  "px";
                elem.style.visibility = 'visible';
                } 
            else
            {
            elem.style.visibility = 'hidden';
        }
        }   
        }        


        function showHideContentFix(id, show)
            {
            var elem = document.getElementById(id);
            if (elem) 
            {
            if (show) 
               {
                elem.style.visibility = 'visible';
                } 
            else
            {
            elem.style.visibility = 'hidden';
        }
        }   
        }        

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}


        var children=Array(); 
        
        function janela(caminho,largura, altura)
         {
            var esquerda = (screen.availwidth - largura)/2;
            var topo = (screen.availheight - altura)/2;
            children[children.length]= window.open(caminho,'_blank', 'width = ' + largura + ', height = ' + altura + ', top = ' + topo  + ' ,  left = ' + esquerda  + ' , toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scroll+",resizable=no,copyhistory=no;dependent=yes ');
         } 


        function janela1(caminho,largura, altura)
         {
            var esquerda = (screen.availwidth - largura)/2;
            var topo = (screen.availheight - altura)/2;
            children[children.length]= window.open(caminho,'_blank', 'width = ' + largura + ', height = ' + altura + ', top = ' + topo  + ' ,  left = ' + esquerda  + ' , toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no;dependent=yes ');
         } 
 