
function save_reproval_bonus( oForm, dv ) { 
	postForm( 'do.carta.bonus.php',''+dv+'',oForm ) ; 
}

function save_approval_bonus( oForm, dv ) { 
	postForm( 'do.carta.bonus.php',''+dv+'',oForm ) ; 
}

function change_beneficiary( n ) { 
	html_content = document.getElementById('beneficiario_info_'+n).innerHTML ; 
	document.getElementById('beneficiario_info').innerHTML = html_content ; 
	document.getElementById('beneficiario_info').style.display='block' ; 
}

function save_beneficiary( fn, dv ) { 
	postForm( 'do.meus.beneficiarios.php',''+dv+'',document.forms[''+fn+''] ) ; 
}

function save_new_resp_rh( oForm, dv ) { 
	postForm( 'do.novo.responsavel.rh.php', ''+dv+'', oForm ) ; 
}

function save_new_visit( oForm, dv ) { 
	postForm( 'do.nova.visita.php', ''+dv+'', oForm ) ; 
}

function show_new_beneficiary_form(e,u) { 
	if( e.pageY ) ypos = e.pageY ; 
	else if (e.clientY) ypos = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) ; 
	else ypos = 0 ; 
	document.getElementById('novo_benef').style.display='block';
	document.getElementById('novo_benef').style.position='absolute';
	document.getElementById('novo_benef').style.top=(ypos-220)+'px';
	
	document.forms['fnewbenef'].reset() ; 
	document.forms['fnewbenef'].u.value = u ; 
	document.forms['fnewbenef'].b.value = '0' ; 
	if( document.getElementById('benef_post_back').innerHTML != '' )
		document.getElementById('benef_post_back').innerHTML = '' ; 
	//loadBeneficiaryForm() ;
	disapearBenefForm = window.setInterval('div_beneficiary_watch()',1000) ; 
}

function div_beneficiary_watch() {
	var str = document.getElementById('benef_post_back').innerHTML.toString().substring(0,10) ; 
	if( str == "<!--COK-->" || str == "<!--UOK-->" ) {
		document.getElementById('novo_benef').style.display='none';
		clearInterval(disapearBenefForm) ; 
	}
}

function div_new_beneficiary_close() { 
	document.getElementById('novo_benef').style.display='none';
}

function setInnerHTML(element, html) {
	var newElement = element.cloneNode(false);
	newElement.innerHTML = html;
	element.parentNode.replaceChild(newElement, element);
}
	
function loadBeneficiaryForm() {
	var myNode = document.getElementById('novo_benef').cloneNode(true) ; 		
	var myHtml = myNode.innerHTML ; 
	setInnerHTML(document.getElementById('d_novo_beneficiario'),myHtml);
}

function show_table_d( n ) { 
	document.getElementById('table_d_'+n).style.display = 'block' ; 
}

function hide_table_d( n ) { 
	document.getElementById('table_d_'+n).style.display = 'none' ; 
}

function set_active_status( oForm, v ) { 
	oForm.ativo.value = v ; 
	oForm.submit() ; 
}

function bonus_renew( c ) { 
	window.top.location = 'carta.bonus.renova.php?c='+c ; 
}

function change_carpic( s ) { 
	s = 'img/carros/' + s.replace(/\s+/g,'_').toLowerCase() + '.jpg' ;
	document.getElementById('carpic').src = s ; 	
}

function change_carpic_pensioner( s ) { 
	s = '../img/carros/' + s.replace(/\s+/g,'_').toLowerCase() + '.jpg' ;
	document.getElementById('carpic').src = s ; 	
}

function set_bonus_value(s){
	prices = vehicles[s.toLowerCase()];
	if(prices == null)
		prices = "0,00";

	document.getElementById('bonus_value').innerHTML = prices;
	document.getElementById('valor_bonus').value = prices;
}

function set_concessionaria(s){
	aConcessionaria = s.split(",");
	document.getElementById('conc_codigo').innerHTML = aConcessionaria[1];
	document.getElementById('conc_cnpj').innerHTML = aConcessionaria[2];
	document.getElementById('conc_id').value = aConcessionaria[0];
}


function getValues() {
	// Limpa a array de carros, desconto, combo box de carros e a div de valor do desconto.
	checkVehicles = false;
	vehicles = "";
	vehicles = new Array();
	$("#veiculo_nome").removeOption(/./);
	$("#veiculo_nome").addOption("0", "Selecione");
	$("#veiculo_nome").addOption("Carro nao definido", "Ainda não tenho o carro definido");
	$("#bonus_value").text("R$ 0,00");
	
	//captura todos os campos do formulario e 'serializa'
	var str = $("#nota_fiscal_data_emissao_dia").serialize()+"&";
	str += $("#nota_fiscal_data_emissao_mes").serialize()+"&";
	str += $("#nota_fiscal_data_emissao_ano").serialize()+"&";
	str += $("#grupo").serialize();
	//parser do xml
	$.ajax({
	type: "GET",
	url: "carta.bonus.veiculos.php?" + str,
	dataType: "xml",
	success: function(xml) {
		$(xml).find('carro').each(function(){
			checkVehicles = true;
			var nome_text = $(this).find('nome').text();
			var desconto_text = $(this).find('desconto').text();
			
			vehicles[nome_text.toLowerCase()] = desconto_text;
			$("#veiculo_nome").addOption(nome_text, nome_text);
		});
		$("#veiculo_nome").selectOptions("0",false);
		if(!checkVehicles){
			showInlineThickbox('erro_vehicles_not_found','400','250');
		}
	},
	error: function(xml){
		alert('Ocorreu um erro ao carregar os veiculos');
	}
	}); 
}


