// JavaScript Document
var ieff=(((navigator.userAgent.indexOf("MSIE")>-1)||(navigator.userAgent.indexOf("Mozilla/5.0")>-1))&&navigator.userAgent.indexOf("Opera")==-1?true:false);
var ff=(((navigator.userAgent.indexOf("Mozilla/5.0")>-1))&&navigator.userAgent.indexOf("Opera")==-1?true:false);
var ns=(navigator.userAgent.indexOf("Netscape")>-1&&navigator.userAgent.indexOf("Opera")==-1?true:false);

function aguardetela(form, sigla, tela){
	var idmens = sigla+"_mens";
	
	document.getElementById('aguarde').style.display = "block";
	document.getElementById(idmens).style.display = "none";
	document.getElementById(idmens).innerHTML = "";
	
	switch(tela){
		case "ate":
			xajax_ate_cha(pegaform(form), sigla);
		break;
		case "cha":
			xajax_abre_cha(pegaform(form), sigla);
		break;
	}
}

function aguardeman(codpro){
	document.getElementById('aguarde2').style.display = "block";
	document.getElementById('man_mens').style.display = "none";
	document.getElementById('man_mens').innerHTML = "";
	document.getElementById('mandown').innerHTML = "";
	xajax_man_down(codpro);
}

function aguardefrm(logform){
	document.getElementById('aguarde').style.display = "block";
	document.getElementById('log_mens').style.display = "none";
	document.getElementById('log_mens').innerHTML = "";
	xajax_suplogin(xajax.getFormValues(logform));
}

function pegavalor(campo){
	return document.getElementById(campo).value;
}

function poevalor(campo, valor){
	document.getElementById(campo).value = valor;
}

function pegaform(form){
	return xajax.getFormValues(form);
}

function del_campo(campo){
	//document.getElementById(campo).value = 0;
	//document.getElementById(campo).value = "";
	document.getElementById(campo).disabled = true;
}

function ou_campos(idcampo2){
	//document.getElementById(campo).value = 0;
	//document.getElementById(campo).value = "";
	document.getElementById(idcampo2).value = "";
}

function inclui_nf(form, sigla){ //ideia abandonada
	xajax_ins_cli(pegaform(form), sigla);
	xajax_ins_nf(pegaform(form), sigla);
}

function muda_botaoX(tipo, id, form, sigla){ //muda o onclick do botão id
	switch(tipo){
		case "ns":
			document.getElementById(id).onclick = function() {xajax_atu_ns(pegaform(form), sigla);};
		break;
		case "nf":
			document.getElementById(id).onclick = function() {xajax_cnf_atu_nf(pegaform(form), sigla);};
		break;
		case "cli":
			document.getElementById(id).onclick = function() {xajax_atu_cli(pegaform(form), sigla);};
		break;
	}
	/*if (tipo == "ns")
		document.getElementById(id).onclick = function() {xajax_atu_ns(pegaform(form), sigla);};
	else
		document.getElementById(id).onclick = function() {xajax_cnf_atu_nf(pegaform(form), sigla);};*/
}

function cnf_del(tipo, id, form, sigla){ //opção de confirmar a deleção
	nid = sigla+"_"+tipo+"["+tipo+"]";
	num = document.getElementById(nid).value;
	
	if (confirm('Confirma a exclusão da '+tipo+' '+num+' ?')){
		if (tipo == "ns")
			xajax_atu_ns(pegaform(form), sigla, true);
		else
			xajax_atu_nf(pegaform(form), sigla, true);
	}
}

function cnf_ins_ate(url, codcha){ //opção de confirmar a inclusão de atendimento

	if (confirm('Deseja incluir um atendimento?')){
		location.href = 'chamados_ate.php?codcha='+codcha;
	}else{
		//location.href = url;
		history.back();
	}
}

function muda_bdel(tipo, id, form, sigla){ //muda o onclick do botão id
	document.getElementById(id).onclick = function() {cnf_del(tipo, id, form, sigla);};
}

function hist_cha(url, valor, param){
	if (valor=='0')
		location.href=url;
	else
		location.href=url+"?"+param+"="+valor;
}

function faq(num){
	var num2 = pegavalor('faq_ant');
	var dbf = "dbf"+num;
	var ibf = "ibf"+num;
	var dbf2 = "dbf"+num2;
	var ibf2 = "ibf"+num2;
	var imgdir = "images/";

	document.getElementById(dbf).style.display = "block";
	document.getElementById(ibf).src = imgdir+"svd.png";
	poevalor('faq_ant', num);
	
	if (num2 > 0){
		document.getElementById(dbf2).style.display = "none";
		document.getElementById(ibf2).src = imgdir+"sv.gif";
	}
	
	if (num2==num) poevalor('faq_ant', '');
}

function inslostfocus(campo, alvo){
	//alert(campo+" "+alvo);
	if (campo==alvo) return false;
	
	document.getElementById(campo).onclick = function(){};
	document.getElementById(campo).onfocus = function(){document.getElementById(alvo).focus();};
}

function pular_campo(input, evento, id, tam) {
	 var BACKSPACE=  8; 
	 var DEL=  46; 
	 var FRENTE=  39; 
	 var TRAS=  37;          
	 var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
	 if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)) {
		 return true; 
		 }
	 if ( tecla == 13 )     return false; 

	if (ff){
		tam=tam-1;
	}
	//alert(tam);
	//alert(input.value.length);
	
	if ((tecla<48)||(tecla>57)){
		evento.returnValue =false;
		return false;
	} else { 
		if(input.value.length==tam) {
			document.getElementById(id).focus();
			//input.value=input.value + "-" ;		  
		}
	}
    return true;		  		
}

function poe_zeros(input, evento, tam) {
	 var BACKSPACE=  8; 
	 var DEL=  46; 
	 var FRENTE=  39; 
	 var TRAS=  37;          
	 var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
	 if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)) {
		 return true; 
		 }
	 if ( tecla == 13 )     return false; 

	if ((tecla<48)||(tecla>57)){
		evento.returnValue =false;
		return false;
	} else { 
		var tmp = "";
		var clen = input.value.length;
		
		if(clen!=tam && clen!=0) {
			for (var i=1; i<=tam-clen; i++){
				tmp += "0";
			}
			
			//alert(tmp+input.value);
			input.value=tmp+input.value;		  
		}
	}
    return true;		  		
}

