function fvalidateError(elemnt,proc){switch(proc){case'error':$(elemnt).addClass("has-error");break;default:$(elemnt).removeClass("has-error");}}
function cleanCommas(value){var regex=/,/;var valor=regex.test(value);if(valor){return value.replace(/,/g,'');}else{return value;}}
function valPrima(iValorVeh,iPrima,sPrima){var respuesta;var primaPercent=cleanCommas(iValorVeh)*(parseInt(sPrima)/100);if(primaPercent<=cleanCommas(iPrima)){respuesta={"exito":true,"primaMin":primaPercent};}else{respuesta={"exito":false,"primaMin":primaPercent};}
return respuesta;}
function formatNumber(num){return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,'$1,');}
$("li.tabs-dMenu").click(function(){var tab=$(this).attr("id");if(tab=="dPersonas"){sessionStorage.setItem('dPersonas','dPersonas');sessionStorage.removeItem('dEmpresas')}else{sessionStorage.setItem('dEmpresas','dEmpresas');sessionStorage.removeItem('dPersonas')}
adminTabsDesk(tab);});function adminTabsDesk(dataD){if(dataD!=null||dataD=='dEmpresas'){$("#dEmpresas").addClass("is-active");$("#menu-empresas-2-label").attr("aria-selected","true");$("#menu-empresas-2").addClass("is-active");$('#dPersonas').removeClass('is-active');$("#menu-personas-1").removeClass("is-active");$("#menu-personas-1-label").attr("aria-selected","false");}else{$("#dPersonas").addClass("is-active");$("#menu-personas-1").addClass("is-active");$("#menu-personas-1-label").attr("aria-selected","true");$('#dEmpresas').removeClass('is-active');$("#menu-empresas-2").removeClass("is-active");$("#menu-empresas-2-label").attr("aria-selected","false");}}
$(".btn-moneda").click(function(){var btnMoneda=$(this);if(!$(this).hasClass("is-green-active")){calcularTasa(btnMoneda);}});function calcularTasa(btnMoneda){var monedaSelec=btnMoneda.val();if(monedaSelec=="exchange-1"){btnMoneda.addClass("is-green-active");$(".btn-moneda[value='exchange-2']").removeClass("is-green-active");}else{btnMoneda.addClass("is-green-active");$(".btn-moneda[value='exchange-1']").removeClass("is-green-active");}
if($(".tabs-converter[id='converter-2']").hasClass("is-active")==true){showConverter();tipoConversion();calculo_conversion();}else{showTabsCoin();}}
$("#btn-tasa").click(function(){showTabsCoin();});$("#btn-convertidor").click(function(){showConverter();calculo_conversion();});$("a[id='change-converter'").click(function(){tipoConversion();calculo_conversion();});$("input[id='currency-amount'").keyup(function(){calculo_conversion();});function tipoConversion(){var monedaSelec=$(".btn-moneda.is-green-active").val();if(monedaSelec=="exchange-1"){if($("#icon-moneda").text()=='$'){$("#icon-moneda").text('L');$("#icon-moneda2").text('$');$("#moneda-type").val('vusd');}else{$("#icon-moneda").text('$');$("#icon-moneda2").text('L');$("#moneda-type").val('cusd');}}else{if($("#icon-moneda").text()=='€'){$("#icon-moneda").text('L');$("#icon-moneda2").text('€');$("#moneda-type").val('veur');}else{$("#icon-moneda").text('€');$("#icon-moneda2").text('L');$("#moneda-type").val('ceur');}}}
function calculo_conversion(){var total=0;var moneda_tipo=$("#moneda-type").val();var value_tipo=$("#"+moneda_tipo).text();if(moneda_tipo=='cusd'||moneda_tipo=='ceur'){total=($("input[id='currency-amount'").val()*value_tipo).toFixed(2);}else{total=($("input[id='currency-amount'").val()/value_tipo).toFixed(2);}
$("#total-converter").text(total);}
function showTabsCoin(){var monedaSelec=$(".btn-moneda.is-green-active").val();if($(".tabs-converter[id='"+monedaSelec+"']").hasClass("is-active")==false){setTimeout(function(){$(".tabs-converter").removeClass("is-active");$(".tabs-converter[id='"+monedaSelec+"']").addClass("is-active");$("#btn-tasa").attr("href","#"+monedaSelec).data("data-tabs-target",monedaSelec);},10);}}
function showConverter(){var monedaSelec=$(".btn-moneda.is-green-active").val();var iconMoneda='';switch(monedaSelec){case"exchange-1":iconMoneda='$';$("#moneda-type").val('cusd');$("#convertir-a").val(1);break;default:iconMoneda='€';$("#moneda-type").val('ceur');$("#convertir-a").val(2);}
setTimeout(function(){$(".tabs-converter").removeClass("is-active");$(".tabs-converter[id='converter-2']").addClass("is-active");$("#icon-moneda").text(iconMoneda);$("#icon-moneda2").text('L');},10);}
$(document).ready(function(){var dataD=sessionStorage.getItem('dEmpresas');adminTabsDesk(dataD);$(".operator-btn").on("click",function(){var input=$(this).data("for");var value=cleanCommas($("#"+input).val());if($(this).attr("name")=="btn-plus"){value=parseInt(value)+1;}else{if(value!=0){value=parseInt(value)-1;}}
if(input=="iMeses"){getResultado();}
$("#"+input).val(formatNumber(value));});$('.formatCoins').toArray().forEach(function(field){new Cleave(field,{numeral:true,numeralThousandsGroupStyle:'thousand'});});$(".btn-back").on("click",function(){var step=$(this).attr("name");fSteps(step,"");scroolDown();});$(".btn-back-step").on("click",function(){var step=$(this).attr("name");fSteps(step,"");scroolDown();});$(".li-step").on("click",function(){if(!$(this).hasClass("disabled")){$(".li-step").each(function(){if($(this).hasClass("current")){$(this).removeClass("current");}});$(this).addClass("current");var _this=$(this).attr("name");navStep(_this);}});});function scroolTop(){$("html, body").animate({scrollTop:"500"});}
function scroolDown(){$("html, body").animate({scrollTop:"500"});}
function fback(step){$(".btn-back").attr("name",step);}
function fSteps(step,done){for(var i=0;i<=5;i++){if(i!=step){$("#step"+i).addClass("hide");$(".title-step"+i).addClass("hide");$(".li-step[name=li-step"+i+"]").removeClass("current");}else{$("#step"+i).removeClass("hide");$(".title-step"+i).removeClass("hide");$(".li-step[name=li-step"+i+"]").removeClass("disabled").addClass("current");var stepDone=i-1;$(".li-step[name=li-step"+stepDone+"]").addClass(done);fback(stepDone);}}}
function navStep(item){if(!$(".li-step[name=li-step"+item).hasClass("disabled")){var step=$(".li-step[name="+item+"]").attr("name").split("p");fSteps(step[1],"");}}