// JavaScript Document
$(function(){$("#fecha_inicio").datepicker({minDate:0,maxDate:"+2Y",changeMonth:true,changeYear:true,showButtonPanel:true,dateFormat:"dd/mm/yy",onSelect:function(date){document.getElementById("fecha_fin").value=''}})});$(function(){$("#fecha_fin").datepicker({beforeShow:function(){if(document.getElementById("fecha_inicio").value){var type=document.getElementById("tipo").value;var minMonth=3;var maxMonth=8;var ONE_DAY=1000*60*60*24;var today=new Date();var selectedStartDate=document.getElementById("fecha_inicio").value;var selectedStartDateArray=document.getElementById("fecha_inicio").value.split("/");var selectedStartYear=parseInt(selectedStartDateArray[2],10);var selectedStartMonth=parseInt(selectedStartDateArray[1],10);var selectedStartDay=parseInt(selectedStartDateArray[0],10);var selectedStartDateMili=new Date(selectedStartYear,selectedStartMonth-1,selectedStartDay);var min_days=Math.round(((selectedStartDateMili-today)/ONE_DAY)+2)}else{min_days=1}return{minDate:"+"+min_days+"D",maxDate:"+2Y +"+min_days+"D"}},minDate:"+1D",maxDate:"+2Y",changeMonth:true,changeYear:true,showButtonPanel:true,dateFormat:"dd/mm/yy",onSelect:function(date){if(document.getElementById("fecha_inicio").value){var type=document.getElementById("tipo").value;var minMonth=3;var maxMonth=8;var ONE_DAY=1000*60*60*24;var selectedStartDate=document.getElementById("fecha_inicio").value;var selectedStartDateArray=document.getElementById("fecha_inicio").value.split("/");var selectedStartYear=parseInt(selectedStartDateArray[2],10);var selectedStartMonth=parseInt(selectedStartDateArray[1],10);var selectedStartDay=parseInt(selectedStartDateArray[0],10);var selectedStartDateMili=new Date(selectedStartYear,selectedStartMonth-1,selectedStartDay);var selectedStopDate=date;var selectedStopDateArray=selectedStopDate.split("/");var selectedStopYear=parseInt(selectedStopDateArray[2],10);var selectedStopMonth=parseInt(selectedStopDateArray[1],10);var selectedStopDay=parseInt(selectedStopDateArray[0],10);var selectedStopDateMili=new Date(selectedStopYear,selectedStopMonth-1,selectedStopDay);var selectedPeriod=Math.round(((selectedStopDateMili-selectedStartDateMili)/ONE_DAY)+1);var sistemaLastMinute=false;var sistemaLastMinuteDos=false;var today=new Date();var todayMonth=today.getMonth()+1;var todayYear=today.getFullYear();var todayDay=today.getDate();var inicioCritico=new Date(todayYear,9,15);var finCritico=new Date(todayYear+1,0,15);if(todayMonth==1){var inicioCritico=new Date(todayYear,0,1);var finCritico=new Date(todayYear,0,15)}var inicioCriticoDos=new Date(todayYear,1,15);var finCriticoDos=new Date(todayYear,2,1);if(today>inicioCritico&&today<finCritico&&selectedStartDateMili>inicioCritico&&selectedStartDateMili<finCritico){sistemaLastMinute=true}if(today>inicioCriticoDos&&today<finCriticoDos&&selectedStartDateMili>inicioCriticoDos&&selectedStartDateMili<finCriticoDos){sistemaLastMinuteDos=true}if(sistemaLastMinute==false&&sistemaLastMinuteDos==false&&(((selectedStartMonth>maxMonth||selectedStartMonth<minMonth)&&selectedPeriod<85)||((selectedStopMonth<minMonth||selectedStopMonth>maxMonth)&&selectedPeriod<85))){if(type=="%"||type=="Apa"){alert(mensajeWrongPeriod);document.getElementById("fecha_fin").value=''}else if(selectedPeriod<28){alert(mensajeLessDays);document.getElementById("fecha_fin").value=''}}else{if(selectedPeriod<28){alert(mensajeLessDays);document.getElementById("fecha_fin").value=''}}}}})});


