$(document).ready(function(){
var page = 0;
var max_page = 3;
var bar = new ProgressBar.Line(container, {
strokeWidth: 4,
easing: 'easeInOut',
duration: 1400,
color: color_bar,
trailColor: '#eee',
trailWidth: 1,
svgStyle: {width: '100%', height: '100%'}
});
var family = $("#family option:selected").val();
var activity = $("#activity option:selected").val();
var subactivity = $("#subactivity option:selected").val();
var id = $("#activity_id").val();
if(family != "" && activity != ""){
select_activity(family,activity,subactivity,id);
}
$("#bar_0").click(function(){
change_page(0,bar,true);
});
$("#bar_1").click(function(){
change_page(1,bar,true);
});
$("#bar_2").click(function(){
change_page(2,bar,true);
});
$("#bar_3").click(function(){
change_page(3,bar,true);
});
$("#tenant_type").change(function(){
var tenant_type = $(this).val();
$("#first_risk_value").hide();
$("#total_reform_div").hide();
$("#total_value_div").show();
if(tenant_type != "" && tenant_type == 2){
$("#first_risk_value").show();
$("#total_reform_div").show();
$("#total_value_div").hide();
}
});
$("#edification_type").change(function(){
var edification = $(this).val();
var activity = $("#activity option:selected").val();
$(".opt_edif").hide();
if(edification == 0 || edification == 1){
$("#oficina_edificio_div").show();
}
if(activity == "Hotel" || activity == "Hostal" || activity == "Apartahotel"){
$("#oficina_edificio_div").hide();
$(".hotel_div").show();
}
if(edification == 2){
$("#nave_div").show();
}
});
$('input[name*=cake_shop_service]').change(function(){
$("#pasteleria_div").hide();
if($(this).prop('checked')){
$("#pasteleria_div").show();
}
});
$("#percent_bakery").change(function(){
$("#percent_cake_shop").val(100-$(this).val());
});
$("#percent_cake_shop").change(function(){
$("#percent_bakery").val(100-$(this).val());
});
$("#next_page").click(function(){
if(page != max_page){
page++;
change_page(page,bar,true);
window.scrollTo(0, 0);
}
});
$("#prev_page").click(function(){
page--;
change_page(page,bar,true);
window.scrollTo(0, 0);
});
$("#end_page").click(function(){
if($("#SGF_privacy_Gen").prop('checked')){
setFormSubmitting();
$("#form_comercio").submit();
}
else{
$("#conditions_error").html("Se deben aceptar las condiciones");
}
});
$("#SGF_privacy_Gen").change(function(){
if($(this).prop('checked')){
$("#conditions_error").html("");
}
});
$('.m-info-mini').click(function(){
if($(this).next().is(":visible")){
$(this).next().hide(250);
}else{
$('.info-mini-text').hide(250);
$(this).next().show(250);
}
});
$('#risk_direction').keyup(function(){
var address = $(this).val();
if(address.length > 4){
address = address.replace(' ','+');
$.ajax({
type: "GET",
url: document.location.protocol+"//maps.google.com/maps/api/geocode/json?address=" + address + "+españa&sensor=true",
data: "",
dataType: "json",
success: function(data) {
if(data.status == "OK"){
var html_result = "";
$.each(data.results, function( index, result ) {
var zip = "";
$.each(result.address_components,function( index2 , component ){
if($.inArray("postal_code",component.types) != -1){
zip = component.long_name;
}
});
zip = 'document.getElementById("zip").value = "'+ zip +'";$("#suggestions").html("").hide();$("#risk_direction").val("' + result.formatted_address + '");';
html_result = html_result + "
" + result.formatted_address + "";
});
html_result = "";
$('#suggestions').html(html_result).show();
}
else{
$('#suggestions').html("No se han encontrado resultados").show();
}
}
});
}
else{
$('#suggestions').html("").hide();
}
});
$('.predictive_input').click(function(){$(this).trigger("keyup");});
$(window).click(function() {
$('#suggestions').html("").hide();
$('#activities').html("").hide();
});
$('#profesional_activity').keyup(function(){
var text = $(this).val();
if(text.length > 3){
$.ajax({
type: "POST",
url: "/ajax/predict_com_act",
data: {data: text},
dataType: "json",
success: function(data) {
if(data.status == 1){
var html_result = "";
$.each(data.data, function( index, result ) {
click = 'select_activity("'+ result.family +'","'+ result.activity +'","'+ result.subactivity +'","'+ result.id +'");';
if(result.subactivity != ""){
html_result = html_result + "" + replace_word(result.subactivity,text) + "
" + replace_word(result.family,text) + ' | ' + replace_word(result.activity,text) + '';
}
else{
html_result = html_result + "" + replace_word(result.activity,text) + "
" + replace_word(result.family,text) + '';
}
});
html_result = "";
$('#activities').html(html_result).show();
}
else{
$('#activities').html(data.info).show();
}
}
});
}
else{
$('#activities').html("").hide();
}
});
bar.animate(page/max_page);
$('.star_rating').rating();
/*$('#date_contract_calendar').monthly({
mode: 'picker',
target: '#date_contract',
setWidth: '222px',
startHidden: true,
showTrigger: '#date_contract',
stylePast: true,
disablePast: true,
useIsoDateFormat: false
});*/
var currentTime = new Date()
var CMonth = currentTime.getMonth() + 1
var CDay = currentTime.getDate()
var CYear = currentTime.getFullYear()
var NextYear = CYear + 1
var rangeYears = [];
for (var i = (CYear-100); i < (CYear-17); i++) {
rangeYears.push(i);
}
$('#date_contract').glDatePicker({
allowMonthSelect: true,
allowYearSelect: true,
cssName: 'flatwhite',
selectedDate: new Date(),
selectableYears:[CYear,NextYear],
selectableDateRange: [{ from: new Date(), to: new Date(NextYear, 12, 31) }],
monthNames:['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre']
});
$('#birthdate').glDatePicker({
allowMonthSelect: true,
allowYearSelect: true,
cssName: 'flatwhite',
selectedDate: new Date(1980, 1, 1),
selectableYears:rangeYears,
monthNames:['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre']
});
function replace_word(frase,search){
var capital = search.substr(0,1).toUpperCase()+search.substr(1);
var lower = search.toLowerCase();
text = frase.replace(search,'' + search + '');
text = text.replace(capital,'' + capital + '');
text = text.replace(lower,'' + lower + '');
return text;
}
$("#family").change(function(){
get_activities($(this).val(),"");
$('#subactivity_div').hide();
$("#profesional_activity").val("");
});
$("#activity").change(function(){
get_subactivities($(this).val(),"");
$("#profesional_activity").val("");
var family = $("#family option:selected").val();
var activity = $("#activity option:selected").val();
var subactivity = $("#subactivity option:selected").val();
var id = $("#activity_id").val();
if(family != "" && activity != ""){
select_activity(family,activity,subactivity,id);
}
});
$("#subactivity").change(function(){
$("#profesional_activity").val("");
var family = $("#family option:selected").val();
var activity = $("#activity option:selected").val();
var subactivity = $("#subactivity option:selected").val();
var id = $("#activity_id").val();
if(family != "" && activity != ""){
select_activity(family,activity,subactivity,id);
}
});
$('[name*=indemnity_limit]').change(function(e){
if($("[name='indemnity_limit[]']:checked").length == 3){
$(this).prop('checked',false);
alert("Por favor seleccione una o 2 opciones. Si desea cambiar una selección, desmarque previamente una de las casillas marcadas.");
}
});
$('input[name*=no_need_edification]').change(function(){
if($(this).prop('checked')){
$("#edification_div").hide();
}
else{
$("#edification_div").show();
}
});
$('input[name*=no_need_content]').change(function(){
if($(this).prop('checked')){
$("#content_div").hide();
}
else{
$("#content_div").show();
}
});
$(".ancla").click(function(e){
e.preventDefault();
page = $(this).attr('rel') -1;
var name = $(this).attr('href');
change_page(page ,bar,true);
$('html, body').animate({
scrollTop: ($('[name*=' + name + ']').offset().top - 25)
}, 1000);
});
var sw = 0;
$(".ancla").each(function (index){
var name = $(this).attr('href');
if(sw == 0){
$(this).click();
sw = 1;
}
$('[name*=' + name + ']').addClass("error_field");
});
$(".error_field").change(function(){
$(this).removeClass("error_field");
$('[href*=' + $(this).attr("name") + ']').hide();
});
$('#secundary_door').change(function(){
var secundary_door = $("#secundary_door option:selected").val();
if(secundary_door == "" || secundary_door == "0"){
$("#type_protection_secundary_door_div").hide();
}
else{
$("#type_protection_secundary_door_div").show();
}
});
$('#windows_and_others').change(function(){
var windows_and_others = $("#windows_and_others option:selected").val();
if(windows_and_others == "" || windows_and_others == "0"){
$("#type_protection_window_and_others_div").hide();
}
else{
$("#type_protection_window_and_others_div").show();
}
if($(this).val() == "0" || $(this).val() == ""){
$("#4_metros_div").hide();
}
else{
$("#4_metros_div").show();
}
});
$('#shop_windows').change(function(){
var shop_windows = $("#shop_windows option:selected").val();
if(shop_windows == "" || shop_windows == "0"){
$("#type_protection_shop_windows_div").hide();
}
else{
$("#type_protection_shop_windows_div").show();
}
});
$("#tenant_type").change();
$("#edification_type").change();
$("#windows_and_others").change();
$('input[name*=cake_shop_service]').change();
$('input[name*=no_need_edification]').change();
$('input[name*=no_need_content]').change();
$('#secundary_door').change();
$('#windows_and_others').change();
$('#shop_windows').change();
});
function get_activities(family,activity){
$.ajax({
type: "POST",
url: "/ajax/get_activities",
data: {data: family},
dataType: "json",
success: function(data) {
if(data.status == 1){
var html_result = '';
$.each(data.data, function( index, result ) {
html_result = html_result + "";
});
$('#activity').html(html_result);
$('#activity_div').show();
if(activity && activity != ""){
$("#activity").val(activity);
}
}
else{
$('#activity').html("");
$('#activity_div').show();
}
}
});
}
function get_subactivities(activity,subactivity){
$.ajax({
type: "POST",
url: "/ajax/get_subactivities",
data: {data: activity},
dataType: "json",
success: function(data) {
if(data.status == 1){
var html_result = '';
$.each(data.data, function( index, result ) {
html_result = html_result + "";
});
$('#subactivity').html(html_result);
$('#subactivity_div').show();
if(subactivity && subactivity != ""){
$("#subactivity").val(subactivity);
}
}
else{
$('#subactivity').html("");
$('#subactivity_div').hide();
}
}
});
}
function change_page(page,bar,tracker){
var max_page = 3;
bar.animate(page/max_page);
$(".form_page").hide();
$(".formulario_" + page).show();
if(page == max_page){
$("#prev_page").show();
$("#end_page").show();
$("#next_page").hide();
}
else if(page == 0){
$("#prev_page").hide();
$("#end_page").hide();
$("#next_page").show();
}
else{
$("#prev_page").show();
$("#end_page").hide();
$("#next_page").show();
}
$("#bar_0").removeClass( "bar_on bar_current bar_off" );
$("#bar_1").removeClass( "bar_on bar_current bar_off" );
$("#bar_2").removeClass( "bar_on bar_current bar_off" );
$("#bar_3").removeClass( "bar_on bar_current bar_off" );
$("#bar_" + page).addClass( "bar_current" );
switch(page){
case 0:
case "0":
$("#bar_1").addClass( "bar_off" );
$("#bar_2").addClass( "bar_off" );
$("#bar_3").addClass( "bar_off" );
break;
case 1:
case "1":
$("#bar_0").addClass( "bar_on" );
$("#bar_2").addClass( "bar_off" );
$("#bar_3").addClass( "bar_off" );
break;
case 2:
case "2":
$("#bar_0").addClass( "bar_on" );
$("#bar_1").addClass( "bar_on" );
$("#bar_3").addClass( "bar_off" );
break;
case 3:
case "3":
$("#bar_0").addClass( "bar_on" );
$("#bar_1").addClass( "bar_on" );
$("#bar_2").addClass( "bar_on" );
break;
}
if(tracker){
var section = page + 1;
SaveTracker('sg.commerce.section' + section + '.index');
}
}
function select_activity(family,activity,subactivity,id){
$("#family").val(family);
get_activities(family,activity);
get_subactivities(activity,subactivity);
$("#activity_id").val(id);
$("#activities").html("").hide();
$("#pasteleria_div").hide();
$(".opt_prof").hide();
$("#edificacion_div").show();
var edification = 0;
if(activity == "Panadería / Pastelería"){
if($('input[name*=cake_shop_service]').prop('checked')){
$("#pasteleria_div").show();
}
$("#panaderia_div").show();
}
if(family == "Enseñanza, educación" || subactivity == "Club de fitness / gimnasio y saunas"){
$("#empleados_ensenanza_gimnasio").show();
}
if(activity == "Residencia de animales, protectora o asociación"){
$("#residencia_canina_div").show();
}
if(activity == "Hotel" || activity == "Hostal" || activity == "Apartahotel" || activity == "Fondas y pensiones (menos de 6 habitaciones)" || activity == "Residencia" ){
$('#estrellas').hide();
if(activity == "Hotel" || activity == "Apartahotel" || activity == "Fondas y pensiones (menos de 6 habitaciones)"){
$('#estrellas').show();
}
$(".hotel_div").show();
if(activity != "Fondas y pensiones (menos de 6 habitaciones)"){
edification = 1;
}
}
/*
Residencia de animales, protectora o asociación,
Hotel,
Apartahotel,
Fondas y pensiones (menos de 6 habitaciones),
Hostal,
Residencia,
Camping
*/
if(family == "Hostelería y Restauración"){
if(activity == "Camping"){
$("#camping_div").show();
$("#edificacion_div").hide();
}
else{
if(activity != "Residencia de animales, protectora o asociación"
&& activity != "Hotel"
&& activity != "Apartahotel"
&& activity != "Fondas y pensiones (menos de 6 habitaciones)"
&& activity != "Hostal"
&& activity != "Residencia"){
$("#hosteleria_div").show();
}
}
}
if(activity == "Consultorio o gabinete médico (sin hospitalización)"
|| activity == "Consultorio o gabinete médico (sin hospitalización)"
|| activity == "Gabinete de Psicología, pedagogía o logopedía"
|| activity == "Clínica de podólogos, callistas y/o pedicuros"
|| activity == "Clínica de fisioterapia, rehabilitación y/o masajes terapéuticos en general"
|| activity == "Clínica de oftalmología"
|| activity == "Clínica dental (excluido oro, platino y marfil)"
|| activity == "Taller protésico-dental (excluido oro, platino y marfil)"
|| activity == "Residencia"
|| activity == "Residencia de animales, protectora o asociación"
|| activity == "Clínica veterinaria"
|| (activity == "Centro de belleza y/o estética, masajes no terapéuticos" && subactivity == "Con tratamiento láser, UVA")
){
$("#empleados_sin_residencia").show();
}
else{
$("#empleados_sin_residencia").hide();
}
var val_edification = $('#edification_type option:selected').val();
$('#edification_type').children('option:not(:first)').remove();
if(edification == 0){
$('#edification_type').append('');
$("#edification_type option[value="+ val_edification +"]").attr("selected",true);
$("#oficina_edificio_div").show();
}else{
$('#edification_type').append('');
$("#oficina_edificio_div").hide();
$("#edification_type option[value="+ val_edification +"]").attr("selected",true);
}
}
var formSubmitting = false;
var setFormSubmitting = function() { formSubmitting = true; };
window.onload = function() {
window.addEventListener("beforeunload", function (e) {
if (formSubmitting) {
return undefined;
}
var confirmationMessage = '¿Estás seguro de que no quieres ahorrar en tu póliza? ¡Quédate y compruébalo!';
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
});
};
function PopupWindowFromPrivacy(theURL,winName,features){window.open(theURL,winName,features)}