var NS		= (document.layers)?true:false;
var IE		= (document.all)?true:false;
var __NS	= (document.layers)?true:false;
var __IE	= (document.all)?true:false;


function formatar(src, mask){
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida){
		src.value += texto.substring(0,1);
	}
};

function SomenteNum(e){	
	var evt;
	if (document.all){
		evt=e.keyCode; 
		
			if (evt != 8 ){
				if (evt < 48 || evt > 57){
					e.returnValue = false;
				}
			}
		}
        else{
			evt = e.which;	
				
			if (evt != 8  ){
				if (evt < 48 || evt > 57){
				e.preventDefault();
				}
			}		
		} 
		
};




function verifyEnter() {	
	if (document.all){
		var tecla = event.keyCode;
	}
	else{
		var tecla = event.which;
	}		
	if ((tecla == 13)) { 
		return false;
	}
	return true;
}



function toMaiuscula(e, obj){			
	var agt = navigator.userAgent.toLowerCase();			
	if ( agt.indexOf("msie") == -1 ){
		var tecla = e.charCode;
		if ( tecla > 96 && tecla < 123  ){
			obj.value += String.fromCharCode( tecla ).toUpperCase();
			return false; 
		}
	}
	else{
		var tecla = event.keyCode;
		event.keyCode = String.fromCharCode( tecla ).toUpperCase().charCodeAt( 0 ); 
	}			
	return true;
};



var sAgent = navigator.userAgent;
var ie = sAgent.indexOf("MSIE") > -1;

function MudarCor(CB){
	if (CB.checked){
		hL(CB);
	} else {
		dL(CB);
	}
}

function hL(E){
	if (ie) {
		while (E.tagName!="TR") {E=E.parentElement;}
	}
	else {
		while (E.tagName!="TR"){E=E.parentNode;}
	}
	E.className = "cinzaColunaSel";
}

function dL(E){
	if (ie){
		while (E.tagName!="TR") {E=E.parentElement;}
	}
	else{
		while (E.tagName!="TR"){E=E.parentNode;}
	}
	E.className = "cinzaColuna";
}

function CheckAll(){
	for (var i=0;i<document.formulario.elements.length;i++){
		var e = document.formulario.elements[i];		
		if (e.name != 'allbox')
		e.checked = document.formulario.allbox.checked;
	}
}


function showAguarde(){
	var messageElement = document.getElementById("MessageWait").innerHTML; 
	
	$.blockUI({message: $('#MessageWait'), css: { width: '275px' } });	
}

function hideAguarde(){
	$().ajaxStop($.unblockUI);	
}

function getDataForm(myForm) {
	if(myForm != "" && myForm.action != undefined){
		action = myForm.action;
		method = myForm.method;
		conteudoRequisicao = "";
		for(i = 0; i < myForm.elements.length; i++){
			elementos = myForm.elements[i];
				
			if(elementos.name != ""){
				conteudoRequisicao += elementos.name + "=" + escape(elementos.value) + "&";
			}
			/*caso tenha este campo a action do form muda*/
			if(elementos.name =='actionForm'){
				if (escape(elementos.value) != ""){					
					action = elementos.value;
				}
				
			}

		}
		conteudoRequisicao = conteudoRequisicao.substring(0, conteudoRequisicao.length -1);
		return conteudoRequisicao;
	} 
	else {
		alert("Form Invalido.");		
	}
}



function stringToDoc(s) {
   var doc;
   if (window.ActiveXObject) {
       doc = new ActiveXObject('Microsoft.XMLDOM');
       doc.async = 'false';
       doc.loadXML(s);
   }
   else
       doc = (new DOMParser()).parseFromString(s, 'text/xml');
   return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
}


function msgInformeHide(){
	$.unblockUI(); 
}

function msgInforme(div){	
	var msg = document.getElementById(div).innerHTML; 
	 $.blockUI(msg,{ width: '300px' });
}




function FormataValor(id,tammax,teclapres) {

	if(window.event) { // Internet Explorer
		var tecla = teclapres.keyCode; }
		else if(teclapres.which) { // Nestcape / firefox
		var tecla = teclapres.which;
	}

	vr = document.getElementById(id).value;
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( ",", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1; }

	if (tecla == 8 ){ tam = tam - 1; }

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= 2 ){
	document.getElementById(id).value = vr; }
	if ( (tam > 2) && (tam <= 5) ){
	document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 6) && (tam <= 8) ){
	document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 9) && (tam <= 11) ){
	document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 12) && (tam <= 14) ){
	document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 15) && (tam <= 17) ){
	document.getElementById(id).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}



function selecionaSelect(campo,valor){
    var select = document.getElementById(campo);
    for(var i = 0; i < select.options.length;i++){
        if(select.options[i].value == valor) {
            select.options[i].selected = true;
            break;
        }
    }
}


function questExclusao(pag){
	var agree=confirm(' Atenção \n Confirma a exclusão ?');
	if (agree)
	location.href = pag;
}


function CallPrint(strid){
	var strOldOne= "";
	var prtContent = document.getElementById(strid);
	var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
	WinPrint.document.write(prtContent.innerHTML);
	WinPrint.document.close();
	WinPrint.focus();
	WinPrint.print();
	WinPrint.close();
	prtContent.innerHTML=prtContent.innerHTML;
}



 var intContaTam = 1;
 var vetFonte = new Array ();
 vetFonte [0] = "9px";
 vetFonte [1] = "11px";
 vetFonte [2] = "13px";
 vetFonte [3] = "15px";
 vetFonte [4] = "17px";
 
 function tamTexto (strAD) { 
  if (strAD=="A") {
   if (intContaTam<4) {
    if (intContaTam<0)
     intContaTam=0;
    intContaTam++;
    if( document.all.spanTexto.length > 0){
     for ( i=0;i<=document.all.spanTexto.length-1;i++ ){
      document.all.spanTexto[i].style.fontSize = vetFonte[intContaTam];
     }
    }else{
     document.all.spanTexto.style.fontSize = vetFonte[intContaTam];
    } 
   
   }
  } else {
   if (intContaTam>4)
     intContaTam=2;
 
   intContaTam--;
   if (intContaTam>=0) {
   for ( i=0;i<=document.all.spanTexto.length-1;i++ ){
    document.all.spanTexto[i].style.fontSize = vetFonte[intContaTam];
   }
 
    var nodeObj = document.getElementById('spanTexto')
    nodeObj.style.fontSize = vetFonte[intContaTam];
 
   }
  }
 }
 function doprint() {
	document.all("printbtn").style.visibility = 'hidden';
	self.print()
	document.all("printbtn").style.visibility = 'visible';
}

function popup(pag,tit,w,h){
	window.open(pag,tit,'width='+h+',height='+h+',top='+screen.width*0.3+',left='+screen.height*0.3);
}
