function tracinho(obj){
	
	if(obj.value.length == 2){
		
		obj.value += "-";
		
	}
	
}

function asd(){
	location.href="http://www.google.com.br";
}

function habilitaDatas(obj, dt_ini, dt_fin){
	
	if(obj.options[obj.selectedIndex].value == 0){
		
		dt_ini.disabled = true;
		
		dt_fin.disabled = true;
		
	}else{
		
		dt_ini.disabled = false;
		
		dt_fin.disabled = false;
		
	}
	
}

//Pop-up
function popup(url,janela,w,h,scrol){
	window.open(url,janela,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrol + ',resizable=yes,width=' + w + ',height=' + h + ''); return false;
}

function calcula() {
	intCaracteres = 136 - document.dmsparte4.funcaobanco.value.length;
	if (intCaracteres > 0) {
		document.dmsparte4.chars.value = intCaracteres;
		return true;
	} else {
		intMensagem = 136;
		document.dmsparte4.chars.value = 0;
		document.dmsparte4.funcaobanco.value = document.dmsparte4.funcaobanco.value.substr(0,intMensagem);
		return false;
	}
}

function calcISS(aliq, valorbase, iss){
	iss.value = "" + (aliq * valorbase) / 100;
}

function pCampo(obj, valor){
	if(obj.value.length == 0){
		obj.value = valor;
	}
}


function hrefb(url){
	window.open(url,"print");
	return false;
}

function red(url, target){
	eval(target+".location='"+url+"'");
}

//Verifica se o campo está vazio
function campoBlanco(campo){
	if(campo.value = "")
		return true;
	else
		return false;
}

function newReg(obj, popName, Action, popWidth, popHeight, popScroll){
	vaObj = obj.value;
	popup(popName, "assistente.php?action=" + Action + "&serv=" + vaObj, popWidth, popHeight, popScroll);
}

function trocaOpcao(valor, objSel) {
    for (i=0; i < objSel.length; i++){
    qtd = valor.length;
        if (objSel.options[i].text.substring(0, qtd).toUpperCase() == valor.toUpperCase()) {
        objSel.selectedIndex = i;
            break;
        }
    }
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function jump(targ,selObj){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}
function exc(file, msg, idserv, d){
	c = confirm(msg);
	if(c){
		location.href= file + "?idserv=" + idserv + "&d=" + d;
	}
}
function select_all(e, status){
	for(x=0; x < document.forms['consulta'].elements[e].length; x++){
		document.forms['consulta'].elements[e][x].checked = status;
	}
}

function preencheCampo(obj, valor){
	if(obj.value.length == ""){
		obj.value = valor;
	}
}

function limpaCampo(obj){
	if(obj.value.length == 0 || obj.value.length >= 2){
		obj.value = "";
	}
}

function confirma_opener(msg,link_sim,link_nao)
{
	var text=confirm("" + msg);
	if(text==true)
	{
		opener.location.href = "" + link_sim;
	}else if(text==false){
		opener.location.href = "" + link_nao;
	}
}

function confirma(msg,link_sim,link_nao)
{
	var text=confirm("" + msg);
	if(text==true)
	{
		location.href = "" + link_sim;
	}else if(text==false){
		location.href = "" + link_nao;
	}
}

function confirma_form(msg,form)
{
	var text=confirm("" + msg);
	if(text==true)
	{
		form.submit();
	}
}

function popupTemp(name, url)
{
		window.open(url,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no'); 
		return false;
}


function popup1(name, url, width, height, scrol)
{
		window.open(url,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrol+',resizable=yes,width='+width+',height='+height); 
		return false;
}

function redSel(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function verData(campoData){
	var data = new Date();
	var dia = data.getDate();
	var mes = data.getMonth()+1 ;
	if(campoData.value == ""){
		if(dia < 10){dia = "0" + data.getDate();}
		if(mes < 10){mes = "0" + (data.getMonth() + 1);}
		campoData.value = dia + "/" + mes + "/" + data.getFullYear();
	}
}

function moveFoco (length, focoAtual, proximoFoco) {
		if(focoAtual.value.length == length){
				proximoFoco.focus();
				proximoFoco.select();
		}
}

function maskData(campoData, campoRed){
	if(campoData.value.length == 2){
		campoData.value += "/";
	}
	if(campoData.value.length == 5){
		campoData.value += "/";
	}
	if(campoData.value.length == 10){
		campoRed.focus();
		campoRed.select();
	}
}

function move(id){
  if(id)
    id = numero;
	var tecla=window.event.keyCode;
	if (tecla==65) {
	  elemento = document.getElementById(id);
	  elemento.style.background='#eeeeee';
	  }
	}

function fncMoveFoco(qtd ,campo1, campo2)
{
	if (campo1.value.length == qtd){
	    campo2.focus();
	    campo2.select();
	}
}

function see(i)
{
  i = document.getElementById(i);
  if(!i)
  {
	return false;

  }else{
	if(i.style.display=='' || i.style.display=='none')
    {
		i.style.display = 'block';
 	}else{
		i.style.display = 'none';
  	}
  }
}

function sumir(i)
{
  i = document.getElementById(i);
  if(!i)
  {
	return false;
  }else{
	if(i.style.display == 'block')
    {
		i.style.display = 'none';
 	}
  }
}

function aparecer(i)
{
  i = document.getElementById(i);
  if(!i)
  {
	return false;
  }else{
	if(i.style.display == 'none')
    {
		i.style.display = 'block';
 	}
  }
}
function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}

function formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

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 <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.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 ) ;}
}

}
