function validaFormatoFecha(fecha){var patron1=new RegExp("^[0-9]{1,2}-{1}[0-9]{1,2}-{1}[0-9]{4}$","gi");var patron2=new RegExp("^[0-9]{1,2}/{1}[0-9]{1,2}/{1}[0-9]{4}$","gi");fecha=jQuery.trim(fecha);if(patron1.test(fecha)||patron2.test(fecha))return true;return false}function formateaFecha(f){fecha=jQuery.trim(f);if(!validaFormatoFecha(fecha))return false;var fecha=f.split("/").join("-");var a=fecha.split("-");if(a.length!=3)return false;for(y=0;y<a.length;y++){a[y]=String(parseInt(a[y],10));if(a[y].length<2)a[y]="0".concat(a[y])}return a.join("-")}function isValidDate(d){if(Object.prototype.toString.call(d)!=="[object Date]")return false;return!isNaN(d.getTime())}function validaFecha(params){fechaR=params.fecha;horaR=typeof params.horaR!='undefined'?params.horaR:'';hObligatoria=typeof params.hObligatoria!='undefined'?params.hObligatoria:0;tipoResposta=typeof params.tipoResposta!='undefined'?1:0;if(!(fechaF=formateaFecha(fechaR)))return false;var fecha=fechaF.split("-");fechaTest=new Date();fechaTest.setFullYear(fecha[2],fecha[1]-1,fecha[0]);if(hObligatoria!=0&&!horaR)return false;if(horaR){h=new Array();h=horaR.split(":");for(x=0;x<4;x++)if(typeof h[x]=='undefined')h[x]=0;fechaTest.setHours(h[0],h[1],h[2],h[3])}else fechaTest.setHours(0,0,0,0);if(!isValidDate(fechaTest))return false;else if(fecha[2]!=fechaTest.getFullYear()||fecha[1]!=fechaTest.getMonth()+1||fecha[0]!=fechaTest.getDate())return false;else{if(tipoResposta==1)return true;else return fechaTest}}function validaDateTime(dateTimeR){try{datetimeR=jQuery.trim(dateTimeR);var dateTime=dateTimeR.split(" ");fecha=dateTime[0].split('-');hora=dateTime[1].split(':');fechaTest=new Date();fechaTest.setFullYear(fecha[0],fecha[1]-1,fecha[2]);fechaTest.setHours(hora[0],hora[1],0,0);if(!isValidDate(fechaTest))return false;else return fechaTest}catch(e){return false}}function strtotime(dato){foo=new Date();var gmtMiliSeconds=-foo.getTimezoneOffset()*60*1000;if((res=validaDateTime(dato))||(res=validaFecha({fecha:dato}))||(isValidDate(dato)&&(res=dato))){return Math.floor((res.getTime()+gmtMiliSeconds)/1000)}return false}function comparaFecha(fecha1,fecha2){f1=strtotime(fecha1);f2=strtotime(fecha2);if(f1>f2)return 1;else if(f2>f1)return 2;else return 0}function date2FMysql(obj){resp=new Array(obj.getFullYear(),obj.getMonth()+1,obj.getDate());return resp.join("-")}function date2FH(obj){try{resp=new Array(obj.getDate(),obj.getMonth()+1,obj.getFullYear());f=resp.join("-");return formateaFecha(f)}catch(e){return false}}function date2HoraH(obj){try{resp=new Array(obj.getHours(),obj.getMinutes());f=resp.join(":");return formateaHora(f)}catch(e){return false}}function date2dateTimeMysql(obj){try{f=new Array(obj.getFullYear(),obj.getMonth()+1,obj.getDate());h=new Array(obj.getHours(),obj.getMinutes(),obj.getSeconds());f1=f.join("-");h1=h.join(":");return f1+" "+h1}catch(e){return false}}function date2dateTimeH(obj){try{f=new Array(obj.getDate(),obj.getMonth()+1,obj.getFullYear());h=new Array(obj.getHours(),obj.getMinutes(),0);f1=f.join("-");h1=h.join(":");return formateaFecha(f1)+" "+formateaHora(h1)}catch(e){return false}}function validaFormatoHora(hora){var patron1=new RegExp("^([0-9]|[0-1][0-9]|[2][0-3]):([0-5][0-9])$","gi");hora=jQuery.trim(hora);if(patron1.test(hora))return true;return false}function validaNumHoras(hora){var patron1=new RegExp("^([0-9]{1,}):([0-5][0-9])$","gi");hora=jQuery.trim(hora);if(patron1.test(hora))return true;return false}function validaHora(horaR){if(!validaFormatoHora(horaR))return false;h=horaR.split(":");fechaTest=new Date();fechaTest.setHours(h[0],h[1],0,0);if(fechaTest.getHours()!=h[0]||fechaTest.getMinutes()!=h[1])return false;else return true}function formateaHora(hora){hora=jQuery.trim(hora);var tmp=hora.split(":");h=str_pad({str:tmp[0],lonx:2});m=str_pad({str:(typeof tmp[1]!='undefined'?tmp[1]:""),lonx:2});r=h+":"+m;return r}function Hora2Time(hora){hora=formateaHora(hora);var tmp=hora.split(":");var hora=tmp[0]*3600+tmp[1];return hora}function comparaHoras(h1,h2){h1=Hora2Time(h1);h2=Hora2Time(h2);if(h1>h2)return 1;else if(h1<h2)return 2;else return 0;}
