﻿// JScript File

function ShowHideObject(oID)
{
    var o;
    o = window.document.getElementById(oID);
    if (o != null)
    {
        if (o.style.display != 'none') { o.style.display = 'none'; }
        else { o.style.display = 'inline'; }
    }
}



function DoDocDownload(sUrlParameter)// iDoc, iDocFileNItem)
{
    var url, o;
    //url = 'DocDownload.aspx?iDoc=' + iDoc +'&iDocFileNItem=' + iDocFileNItem;
    url = '/DocDownload.aspx?' + sUrlParameter;
    o = window.open(url,null,'menubar=no,resizable=no,status=yes,scrollbars=no,top=350,left=350,width=100,height=50');
    if (o != null) o.focus();
}


var oldScrollHandler=null;
function lockPage()
{
	try 
	{
		var o;
		o = window.document.getElementById('lgxGBLLayer');
		


		//alert('window.innerHeight=' + window.innerHeight);
		//alert('window.screen.width=' + window.screen.width);
		
		//alert('o.style.height=' + o.style.height);
		//alert('o.style.width=' + o.style.width);

		//o.style.height = (window.screen.height /*+ 1500*/) + 'px';
		//o.style.width = window.screen.width + 'px';
		
		//alert('o.style.height=' + o.style.height);
		//alert('o.style.width=' + o.style.width);
		
		//window.document.body.scroll = 'no';
		//window.document.body.style.overflow = 'hidden'; // for Firefox
		o.style.display = 'block';
		
		// Captura evento de scroll da janela
		oldScrollHandler = window.onscroll;
		window.onscroll = SetLayerToFitWindow;
		
		// por disabled + Esconder as combos
		var ol, i, iMax;
		ol = window.document.getElementsByTagName('select');
		iMax = ol.length;
		for (i=0; i < iMax; i++) 
		{ 
			ol[i].setAttribute('preLockDisabledVal', ol[i].disabled, 0);
			ol[i].disabled = true; 
			ol[i].setAttribute('preLockVisibledVal', ol[i].style.display, 0);
			ol[i].style.display = 'none'; 
		}
		/*
		// Esconder todos os elementos marcados com o atributo HideWhenLocked=1
		var iMax; iMax = window.document.all.length;
		for (i=0; i < iMax; i++) {
			o = window.document.all(i);
			if (o.getAttribute('HideWhenLocked') == '1') 
			{
				o.setAttribute('preLockVisibledVal', o.style.display, 0);
				o.style.display = 'none'; 
			}
		}
		*/
		if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
		{	// Este passo não é necessário para firefox!
			ol = window.document.getElementsByTagName('iframe');
			iMax = ol.length;
			for (i=0; i < iMax; i++) 
			{
				try{
					ol[i].contentWindow.lockPage();
				}catch(e) { 
					//alert('lockPage: ' + e.message); 
			}
		}
		
		var htmlheight = document.body.parentNode.scrollHeight;  
        var windowheight = window.innerHeight;  
        
        if ( htmlheight < windowheight ) { 
            //document.body.style.height = windowheight + "px"; 
            o.style.height = windowheight + "px"; 
        }  
        else { 
            //document.body.style.height = htmlheight + "px"; 
            o.style.height = htmlheight + "px"; 
        }  
	}
	}catch(e) { 
		alert('lockPage: ' + e.message); 
	} 
}


function SetLayerToFitWindow()
{
//    alert('SetLayerToFitWindow');
    var frame = document.getElementById("lgxGBLLayer");  
    var htmlheight = document.body.parentNode.scrollHeight;  
    var windowheight = window.innerHeight;  
    
    if ( htmlheight < windowheight ) { 
        //document.body.style.height = windowheight + "px"; 
        frame.style.height = windowheight + "px"; 
    }  
    else { 
        //document.body.style.height = htmlheight + "px"; 
        frame.style.height = htmlheight + "px"; 
    }  
}


function unlockPage()
{
	try 
	{
		var o;
		o = window.document.getElementById('lgxGBLLayer');
		o.style.display = 'none';
		o.style.height = 1;
		o.style.width = 1;
		window.document.body.scroll = 'yes';
		window.document.body.style.overflow = 'auto'; // for Firefox

		window.onscroll = oldScrollHandler;
		oldScrollHandler = null;

		// Repor as combos
		var ol, i, iMax;
		ol = window.document.getElementsByTagName('select');
		iMax = ol.length;
		for (i=0; i < iMax; i++) 
		{ 
			ol[i].disabled = (ol[i].getAttribute('preLockDisabledVal').toLowerCase == 'true'); 
			ol[i].style.display = ol[i].getAttribute('preLockVisibledVal');
		}
	/*	
		// Repor todos os elementos marcados com o atributo HideWhenLocked=1
		var iMax; iMax = window.document.all.length;
		for (i=0; i < iMax; i++) {
			o = window.document.all(i);
			if (o.getAttribute('HideWhenLocked') == '1') o.style.display = o.getAttribute('preLockVisibledVal');
		}
	*/
		if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
		{	// Este passo não é necessário para firefox!
			ol = window.document.getElementsByTagName('iframe');
			iMax = ol.length;
			for (i=0; i < iMax; i++) 
			{
				try{
					ol[i].contentWindow.unlockPage();
				}catch(e) { 
					//alert('unlockPage(1): ' + e.message); 
					//alert('ol[i]: ' + ol[i] + ' - ol[i].id: ' + ol[i].id);
					//alert('ol[i].contentWindow: ' + ol[i].contentWindow + '  - Name: ' + ol[i].contentWindow.name);
					//alert('ol[i].contentWindow.unlockPage(): ' + ol[i].contentWindow.unlockPage());
				}
			}
		}
	}catch(e) { 
		//alert('unlockPage: ' + e.message); 
	} 
}

function ValidateNumeric(evt, Ctrl) {
    evt = (evt) ? evt : ((window.event) ? window.event : "")

    var ic = evt.keyCode ? evt.keyCode :
                       evt.charCode ? evt.charCode :
                       evt.which ? evt.which : void 0;

    window.status = 'event.keyCode :: ' + ic;

    // . (dot) e , (virgula)
    if ((ic == 188) /*|| (ic == 190) || (ic == 110)*/ ) // so deixa 1
    {
        if (Ctrl.value.indexOf(".") >= 0 || Ctrl.value.indexOf(",") >= 0) {
            if (evt.returnValue) {
                evt.returnValue = false;
                //evt.cancelBubble = true;
            }
            if (evt.preventDefault) {
                evt.preventDefault();
                evt.stopPropagation();
            }
            return false;
        }

        // converte para (dot)
/*        evt.keyCode = 188;
        if (evt.keyCode) evt.keyCode = 188;
        else if (evt.charCode) evt.charCode = 188;
        else if (evt.which) evt.which = 188;
  */
        return true;
    }

    // - (minus)
    if (evt.ctrlKey == false && evt.shiftKey == false && evt.altKey == false && (ic == 189 || ic == 109)) {
        if (Ctrl.value.indexOf("-") >= 0) {
            if (evt.returnValue) {
                evt.returnValue = false;
                //evt.cancelBubble = true;
            }
            if (evt.preventDefault) {
                evt.preventDefault();
                evt.stopPropagation();
            }
            return false;
        }

        return true;
    }

    if (evt.ctrlKey && (ic == 67 || ic == 45)) // ctrl C ou Ctrl Ins
    {
        return false;
    }

    if ((evt.ctrlKey && ic == 86) || (evt.shiftKey && ic == 45)) // ctrl V ou shift Ins
    {
        return false;
    }

    if (((ic <= 57) || ((ic >= 96) && (ic <= 105))) == false) {

/*        if (evt.returnValue) {
            evt.returnValue = false;
            //evt.cancelBubble = true;
        }
        if (evt.preventDefault) {
            evt.preventDefault();
            evt.stopPropagation();
            return false;
        }*/
        return false;

    }

    if (evt.shiftKey && (ic >= 35 && ic <= 40)) // SHIFT + ARROWS OR HOME OR END
    {
        return true;
    }

    if (evt.ctrlKey == false && evt.shiftKey == false && evt.altKey == false) {
        //window.status = 'ctrls = false ';
        return true;
    }
    else {
        //window.status = 'ctrls = true';
        return false;
    }
}



function toFixed2(v)
{
    var aux = v.toFixed(2);
    return aux.replace('.', ',');
}
