$(document).ready(function(){if($("#SG_presupuesto_privacy_extended").size()>0){$("#SG_privacy_acepto").click(function(){$("#SG_presupuesto_privacy :checkbox").attr("checked",true)});if($("#SGF_privacy_Open").val()=="0"){$("#SG_presupuesto_privacy_extended").hide();$("#SG_privacy_toggle").toggle(function(){if($("#SG_presupuesto_privacy_small span").hasClass("wrong")){$("#SG_presupuesto_privacy_small span").hide("fast")}$("#SGF_privacy_Open").val(1);$("#SG_presupuesto_privacy_extended").show("slow")},function(){if($("#SG_presupuesto_privacy_small span").hasClass("wrong")){$("#SG_presupuesto_privacy_small span").show("slow")}$("#SGF_privacy_Open").val(0);$("#SG_presupuesto_privacy_extended").hide("slow")})}else{if($("#SG_presupuesto_privacy_small span").hasClass("wrong")){$("#SG_presupuesto_privacy_small span").hide("fast")}$("#SG_privacy_toggle").toggle(function(){if($("#SG_presupuesto_privacy_small span").hasClass("wrong")){$("#SG_presupuesto_privacy_small span").show("slow")}$("#SGF_privacy_Open").val(0);$("#SG_presupuesto_privacy_extended").hide("slow")},function(){if($("#SG_presupuesto_privacy_small span").hasClass("wrong")){$("#SG_presupuesto_privacy_small span").hide("slow")}$("#SGF_privacy_Open").val(1);$("#SG_presupuesto_privacy_extended").show("slow")})}$("#SGF_privacy_Gen:checkbox").click(function(){$("#SGF_privacy_1:checkbox,#SGF_privacy_2:checkbox,#SGF_privacy_3:checkbox,#SGF_privacy_4:checkbox,#SGF_privacy_5:checkbox,#SGF_privacy_6:checkbox").attr("checked",$(this).attr("checked"))})}if($("#SG_data_decorrenza_pick").size()>0){$("#SG_data_decorrenza_pick").datepicker({defaultDate:0,numberOfMonths:2,minDate:0,maxDate:"1Y",showOn:"button",buttonImage:"http://s.seguros.es/img_1202201249/icons/cal.png",buttonImageOnly:true,onSelect:function(c,b){$("#SGF_insurance_day").val(c.split(/\//)[0]);$("#SGF_insurance_month").val(c.split(/\//)[1]);$("#SGF_insurance_year").val(c.split(/\//)[2])}})}var a=Array("blur","click","change");for(n in a){$("[id^='SGF_']").each(function(){var c=$(this).attr("id").replace("SGF_","");x=c+"_"+a[n];if(typeof SGF[x]=="function"){var b={fName:x,id:"#SGF_"+c};$(this).bind(a[n],b,SGF.call)}})}$("input[type=text]").each(function(){$(this).focus(function(){$(this).removeClass("wrong").addClass("focus");$(this).parent().removeClass("wrong");$(this).parent().children("span[class~=wrong]").removeClass("wrong")});$(this).blur(function(){$(this).removeClass("focus")})});$("select").each(function(){$(this).focus(function(){$(this).removeClass("wrong").addClass("focus");$(this).parent().removeClass("wrong");$(this).parent().children("span[class~=wrong]").removeClass("wrong")});$(this).blur(function(){$(this).removeClass("focus")})})});function print_r(a){if(a.constructor==Array||a.constructor==Object){document.write("<ul>");for(var b in a){if(a[b].constructor==Array||a[b].constructor==Object){document.write("<li>["+b+"] => "+typeof(a)+"</li>");document.write("<ul>");print_r(a[b]);document.write("</ul>")}else{document.write("<li>["+b+"] => "+a[b]+"</li>")}}document.write("</ul>")}}SGF={call:function(b){var a=SGF[b.data.fName](b.data.id);if(a!=true){$(this).parent().addClass("wrong");$(this).next("span.err").addClass("wrong").animate({opacity:0.2},400).animate({opacity:1},400);$(this).next("span.err").html(a)}else{$(this).parent().removeClass("wrong");$(this).next("span.err").removeClass("wrong");$(this).next("span.err").html("")}},previous_insurance_change:function(a){if($(a).val()=="-1"||$(a).val()==""){$("#SG_Box2, #SG_Box3").hide();$("#SGF_years_without_incident").val("-1")}else{$("#SG_Box2").show();$("#SGF_years_without_incident").change()}if($(a).find("option:selected").hasClass("disable_selection")){$(a).find("option:eq(0)").attr("selected",true)}return true},years_without_incident_change:function(b){var a=false;if($(b).val()=="-1"){$("#SG_Box3").hide();$("#SGF_incident_2years, #SGF_incident_12months, #SGF_incident_previousyear").val("0").change();$("#SGF_previous_insurance_age").val("1");a=true}else{if(parseInt($(b).val())==0){$("#SG_Box3").show();$("#SGF_incident_12months").parent(".field").show();$("#SGF_incident_previousyear").parent(".field").show();$("#SGF_incident_2years").parent(".field").show();a=true}else{if(parseInt($(b).val())==1){$("#SG_Box3").show();$("#SGF_incident_12months").parent(".field").hide();$("#SGF_incident_12months option[value='0']").attr("selected","selected");$("#SGF_incident_12months").change();$("#SGF_incident_previousyear").parent(".field").show();$("#SGF_incident_2years").parent(".field").show();a=true}else{if(parseInt($(b).val())>=2){$("#SG_Box3").show();$("#SGF_incident_12months").parent(".field").hide();$("#SGF_incident_12months option[value='0']").attr("selected","selected");$("#SGF_incident_12months").change();$("#SGF_incident_previousyear").parent(".field").hide();$("#SGF_incident_previousyear option[value='0']").attr("selected","selected");$("#SGF_incident_previousyear").change();$("#SGF_incident_2years").parent(".field").show();a=true}}}}if(a){$("#SG_Box3 .field").removeClass("SG_last");$("#SG_Box3 .field:visible:last").addClass("SG_last");return true}return"Por favor, elige un valor"},incident_12months_change:function(c){var a=parseInt($(c).val());for(var b=1;b<=a;b++){$("#SGF_incident_12months_details_"+b).parent(".field").show()}for(var b=a+1;b<=5;b++){$("#SGF_incident_12months_details_"+b).val("").parent(".field").hide()}$("#SG_Box3 .field").removeClass("SG_last");$("#SG_Box3 .field:visible:last").addClass("SG_last");return true},incident_previousyear_change:function(c){var a=parseInt($(c).val());for(var b=1;b<=a;b++){$("#SGF_incident_previousyear_details_"+b).parent(".field").show()}for(var b=a+1;b<=5;b++){$("#SGF_incident_previousyear_details_"+b).val("").parent(".field").hide()}$("#SG_Box3 .field").removeClass("SG_last");$("#SG_Box3 .field:visible:last").addClass("SG_last");return true},incident_2years_change:function(c){var a=parseInt($(c).val());for(var b=1;b<=a;b++){$("#SGF_incident_2years_details_"+b).parent(".field").show()}for(var b=a+1;b<=5;b++){$("#SGF_incident_2years_details_"+b).val("").parent(".field").hide()}$("#SG_Box3 .field").removeClass("SG_last");$("#SG_Box3 .field:visible:last").addClass("SG_last");return true},birth_year_blur:function(c){var a=$(c).val();if(a.length==2&&parseInt(a)<=30){$(c).val("20"+a)}if(a.length==2&&parseInt(a)>30){$(c).val("19"+a)}if($("#SGF_licence_type").size()>0){return true}if($("#SGF_licence_year").val()==""&&$("#SGF_birth_year").val()!=""&&$("#SGF_licence_month").val()==""&&$("#SGF_birth_month").val()!=""&&$("#SGF_birth_year").val()>1900){$("#SGF_licence_year").val(parseInt($("#SGF_birth_year").val())+($("#SGF_licence_type").size()>0?20:18)+parseInt((parseInt($("#SGF_birth_month").val())+2)/13));var b=$("#SGF_birth_month").val().charAt(0)=="0"?parseInt($("#SGF_birth_month").val().charAt(1)):parseInt($("#SGF_birth_month").val());$("#SGF_licence_month").val(b+2==12?12:(b+2)%12);var a=$("#SGF_licence_month").val();if(a.length==1){$("#SGF_licence_month").val("0"+a)}}return true},birth_month_blur:function(b){var a=$(b).val();if(a.length==1){$(b).val("0"+a)}$("#SGF_birth_year").blur();return true},birth_day_blur:function(b){var a=$(b).val();if(a.length==1){$(b).val("0"+a)}return true},licence_year_blur:function(b){var a=$(b).val();if(a.length==2&&parseInt(a)<=30){$(b).val("20"+a)}if(a.length==2&&parseInt(a)>30){$(b).val("19"+a)}return true},licence_month_blur:function(b){var a=$(b).val();if(a.length==1){$(b).val("0"+a)}return true},other_driver_licence_month_blur:function(b){var a=$(b).val();if(a.length==1){$(b).val("0"+a)}return true},other_driver_licence_year_blur:function(b){var a=$(b).val();if(a.length==2&&parseInt(a)<=30){$(b).val("20"+a)}if(a.length==2&&parseInt(a)>30){$(b).val("19"+a)}return true},name_blurx:function(f){var e=false;var d=$(f).val();var c=Array("([a-zA-Z])\\1\\1+","[aeiouAEIOU]","[0-9]","^[ A-Za-z������'?]*$");var b=Array();for(i=0;i<4;i++){var a=new RegExp(c[i]);b[i]=a.exec(d)}if(d.length==0){e="Por favor, introduzca el nombre"}if(e==false&&b[0]==null&&b[1]!=null&&b[2]==null&&b[3]!=null&&d.length>=3){e=false}else{if(e==false){e="Por favor, introduce un nombre correcto"}}if(e!=false){return e}else{return true}},cap_blur:function(a){$("#SGF_cap ~ span.loading").css("visibility","visible");jQuery.get("ajax/codigoPostal?cod="+$(a).val(),"",function(b){if(b==""){b="Incorrecto"}$("#SGF_cap ~ span.loading").css("visibility","hidden");$("#SGF_location").val(b)});return true},unique_Y_click:function(a){$("#SG_Box2").css("display","none");$("#SGF_other_driver_rel, #SGF_other_driver_age, #SGF_other_driver_licence_month, #SGF_other_driver_licence_year").val("");$(".SGF_other_driver_sex").attr("checked",false);return true},unique_N_click:function(a){$("#SG_Box2").css("display","block");return true},first_registration_month_blur:function(b){var a=$(b).val();if(a.length==1){$(b).val("0"+a)}if($("#SGF_brand").val()!=""){$("#SGF_brand").change()}if($("#SGF_brand_moto").val()!=""){$("#SGF_brand_moto").change()}return true},purchase_month_blur:function(b){var a=$(b).val();if(a.length==1){$(b).val("0"+a)}return true},first_registration_year_blur:function(b){var a=$(b).val();if(a.length==2&&parseInt(a)<=30){$(b).val("20"+a)}if(a.length==2&&parseInt(a)>30){$(b).val("19"+a)}if($("#SGF_brand").val()!=""){$("#SGF_brand").change()}if($("#SGF_brand_moto").val()!=""){$("#SGF_brand_moto").change()}return true},purchase_year_blur:function(b){var a=$(b).val();if(a.length==2&&parseInt(a)<=30){$(b).val("20"+a)}if(a.length==2&&parseInt(a)>30){$(b).val("19"+a)}return true},nif_blur:function(a){$(a).val($(a).val().split(".").join(""));$(a).val($(a).val().split(" ").join(""));$(a).val($(a).val().split("-").join(""));return true},new_car_change:function(b){if($(b).val()==""||$(b).val()=="1"){var a=(new Date().getMonth()+1);if(a<10){a="0"+a.toString()}$("#SGF_purchase_month,#SGF_first_registration_month").val(a);$("#SGF_purchase_year,#SGF_first_registration_year").val(""+(new Date().getFullYear()));$("#SGF_purchase_month,#SGF_first_registration_month").parent().hide();if($(b).val()=="1"){if($("#SGF_brand").val()!=""){$("#SGF_brand").change()}if($("#SGF_brand_moto").val()!=""){$("#SGF_brand_moto").change()}}}else{$("#SGF_purchase_month,#SGF_first_registration_month").val("");$("#SGF_purchase_year,#SGF_first_registration_year").val("");if($(b).val()=="2"){var a=(new Date().getMonth()+1);if(a<10){a="0"+a.toString()}$("#SGF_purchase_month").val(a);$("#SGF_purchase_year").val(""+(new Date().getFullYear()))}$("#SGF_purchase_month,#SGF_first_registration_month").parent().show()}return true},brand_change:function(b){$("#SGF_model,#SGF_version").html("");var a=$("#SGF_first_registration_year").val()+"-"+$("#SGF_first_registration_month").val();$("#SGF_model ~ span.loading").css("visibility","visible");jQuery.get("/ajax/cars",{op:"models",date:a,brand:$(b).val(),rand:Math.random()},function(c){$("#SGF_model").html(c);$("#SGF_model ~ span.loading").css("visibility","hidden")});return true},model_change:function(b){$("#SGF_version").html("");var a=$("#SGF_first_registration_year").val()+"-"+$("#SGF_first_registration_month").val();$("#SGF_version ~ span.loading").css("visibility","visible");jQuery.get("/ajax/cars",{op:"version",date:a,brand:$("#SGF_brand").val(),model:$(b).val(),rand:Math.random()},function(c){$("#SGF_version").html(c);$("#SGF_version ~ span.loading").css("visibility","hidden")});return true},brand_moto_change:function(b){$("#SGF_model_moto,#SGF_version_moto").html("");var a=$("#SGF_first_registration_year").val()+"-"+$("#SGF_first_registration_month").val();$("#SGF_model_moto ~ span.loading").css("visibility","visible");jQuery.get("/ajax/moto",{op:"models",date:a,brand:$(b).val(),rand:Math.random()},function(c){$("#SGF_model_moto").html(c);$("#SGF_model_moto ~ span.loading").css("visibility","hidden")});return true},model_moto_change:function(b){$("#SGF_version_moto").html("");var a=$("#SGF_first_registration_year").val()+"-"+$("#SGF_first_registration_month").val();$("#SGF_version_moto ~ span.loading").css("visibility","visible");jQuery.get("/ajax/moto",{op:"version",date:a,brand:$("#SGF_brand_moto").val(),model:$(b).val(),rand:Math.random()},function(c){$("#SGF_version_moto").html(c);$("#SGF_version_moto ~ span.loading").css("visibility","hidden")});return true}};
