var msg1 = 'msg1';
var msg2 = 'msg2' ;
var msg3 = 'msg3';
dwr.engine.setAsync(false);


function listarAgentesArrc(combo){
        codAgrup = combo.value;
        str = combo.id.replace('codAgrup', 'codAgenteArrc');
        
		InfoPgtoFat.getAgenteArrc(codAgrup, function(dados){
			DWRUtil.removeAllOptions(str);
			var opt = document.createElement("option");
			opt.value = '';
			opt.text = 'Selecione...';	
			try{
				document.getElementById(str).add(opt, null);
			}catch(e){
				document.getElementById(str).add(opt);
			}
			DWRUtil.addOptions(str, dados, 'codPresServ', 'nomeComp' );
			}
		
		);
}
function onloadValidar(){
	var elems = document.getElementsByTagName('input');
	
	for(idx = 0; idx < elems.length; idx++){
		if(elems[idx].type == 'checkbox' && elems[idx].checked){
			exibirCampo(elems[idx]);
		}
	}	
}
function exibirCampo(check){
    var tr = new Array(); 
	tr[1] = check.id.replace('selecionado_', 'tr-1-');
	tr[2] = check.id.replace('selecionado_', 'tr-2-');
	tr[3] = check.id.replace('selecionado_', 'tr-3-');

	if(check.checked){
	    for(idx = 1; idx < tr.length; idx++){
			document.getElementById(tr[idx]).style.display = '';
		}
	} else {
	    for(idx = 1; idx < tr.length;idx++)
		document.getElementById(tr[idx]).style.display = 'none';
	}
}

/**
	Valida o preenchimento	
*/

function valida(form){
	
	var elems = document.getElementsByTagName('input');
	
	for(idx = 0; idx < elems.length; idx++){
		if(elems[idx].type == 'checkbox' && elems[idx].checked){
			id = elems[idx].id.replace('selecionado_','');
			
			if(document.getElementById('dataPgto_' + id).value == ''){
				alert('Informe o campo data do pagamento');
				document.getElementById('dataPgto_' + id).focus();
			    return false;	
			} else if(document.getElementById('codAgrup_'  + id).options[document.getElementById('codAgrup_'  + id).options.selectedIndex].value == ''){
				alert('Informe o campo código do agrupador pessoa F/J');
				document.getElementById('codAgrup_'  + id).focus();
				return false;
			} else if(document.getElementById('codAgenteArrc_'  + id).options[document.getElementById('codAgenteArrc_'  + id).options.selectedIndex].value == ''){
				alert('Informe o campo agente arrecadador');
				document.getElementById('codAgenteArrc_'  + id).focus();
				return false;
			}
		}
	} 
	
	return true;
}
