$(document).ready(function(){
		$("#busFiltroFechaRango #DESDE").focus(function(){
			if (this.value=="dd/mm/aaaa"){
				this.value="";
			}
		});
		$("#busFiltroFechaRango #DESDE").blur(function(){
			if (this.value==""){
				this.value="dd/mm/aaaa";
			}
		});
		$("#busFiltroFechaRango #HASTA").focus(function(){
			if (this.value=="dd/mm/aaaa"){
				this.value="";
			}
		});
		$("#busFiltroFechaRango #HASTA").blur(function(){
			if (this.value==""){
				this.value="dd/mm/aaaa";
			}
		});


		$("#busFiltroFechaRango").submit(function(){
			var re=/([0-3][0-9])[\-\/]([0-1][0-9])[\-\/]([1-2][0-9]{3})/gim;
			var res;
			var url="";

			var fecha = $("#busFiltroFechaRango #DESDE").attr("value");
			var fecha2 = $("#busFiltroFechaRango #HASTA").attr("value");

			if (Date.fromString(fecha2)<Date.fromString(fecha)){
				$("#busFiltroFechaRango #DESDE").attr("value",fecha2);
				$("#busFiltroFechaRango #HASTA").attr("value",fecha);
				fecha=fecha2;
			}

			if (fecha!=""&&fecha!=undefined&&fecha!='dd/mm/aaaa'&&fecha!= new Date().addYears(-1).asString('dd/mm/yyyy')){
				res=re.exec(fecha);

				if (!res){
					alert("El formato de la fecha 'desde' debe ser dd/mm/aaaa ");
					return false;
				}
				url+="/desde_"+res[1]+"-"+res[2]+"-"+res[3];
			}

			fecha = $("#busFiltroFechaRango #HASTA").attr("value");
			if (fecha!=""&&fecha!=undefined&&fecha!='dd/mm/aaaa'&&fecha!= new Date().asString('dd/mm/yyyy')){
				var re=/([0-3][0-9])[\-\/]([0-1][0-9])[\-\/]([1-2][0-9]{3})/gim;
				res=re.exec(fecha);
				if (!res){
					alert("El formato de la fecha 'hasta' debe ser dd/mm/aaaa ");
					return false;
				}

				url+="/hasta_"+res[1]+"-"+res[2]+"-"+res[3];
			}


//			if(url){
				accion=this.action.split("?");
				var loc="";
				for(var i=0;i<accion.length;i++){
					if (i==0){
						loc+=accion[i];
						loc+=url;
					}else{
						loc+="?"+accion[i];
					}
				}

				document.location=loc;
//			}else
//				alert("Debe seleccionar al menos una fecha.");
			return false;
			});
		});
