
	function disable_regreso()
	{
		document.getElementById("DiaRegresoDropDownList").disabled = true;
		document.getElementById("MesRegresoDropDownList").disabled = true;				
		document.getElementById("AnoRegresoDropDownList").disabled = true;				
	}			
	function enable_regreso()
	{
		document.getElementById("DiaRegresoDropDownList").disabled = false;
		document.getElementById("MesRegresoDropDownList").disabled = false;	
		document.getElementById("AnoRegresoDropDownList").disabled = false;							
	}
	function isDate(dateStr){

		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?

		if (matchArray == null) {
			//alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
			return false;
		}

		month = matchArray[1]; // p@rse date into variables
		day = matchArray[3];
		year = matchArray[5];

		if (month < 1 || month > 12) { // check month range
			//alert("Month must be between 1 and 12.");
			return false;
		}

		if (day < 1 || day > 31) {
			//alert("El día dbee must be between 1 and 31.");
			return false;
		}

		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			//alert("Month "+month+" doesn`t have 31 days!")
			return false;
		}

		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
				//alert("February " + year + " doesn`t have " + day + " days!");
				return false;
			}
		}
		return true; // La fecha es valida
	}
	function validar_campos()
	{
		var ok = 1, CampoError="";
		
		if(document.getElementById("OrigenTextBox").value.length == 0) {ok=0;CampoError="· El campo 'Origen' está vacío\n";}
		if(document.getElementById("DestinoTextBox").value.length == 0){ok=0;CampoError+="· El campo 'Destino' está vacío\n";} 
						
		// Compruebo si la fecha es correcta
		var sAno = document.getElementById("AnoSalidaDropDownList").value;
		var sDia = document.getElementById("DiaSalidaDropDownList").value;
		var sMes = document.getElementById("MesSalidaDropDownList").value;
		var rAno = document.getElementById("AnoRegresoDropDownList").value;
		var rDia = document.getElementById("DiaRegresoDropDownList").value;
		var rMes = document.getElementById("MesRegresoDropDownList").value;
		
		var sFecha = sMes+"-"+sDia+"-"+sAno;//Fecha salida usuario
		var rFecha = rMes+"-"+rDia+"-"+rAno;//Fecha regreso usuario
		
		//Compruebo si la fecha es correcta
		if(!isDate(sFecha))	{ok=0;CampoError+="· El día introducido en la fecha de salida no existe\n";}  
		if(!isDate(rFecha))	{ok=0;CampoError+="· El día introducido en la fecha de regreso no existe\n";}  
										
		var hoy = new Date();
		var salida = new Date();
		var regreso = new Date();
				
		salida.setFullYear(
		parseInt(document.getElementById("AnoSalidaDropDownList").value,10),
		parseInt(document.getElementById("MesSalidaDropDownList").value,10)-1,
		parseInt(document.getElementById("DiaSalidaDropDownList").value,10));
		
		regreso.setFullYear(
		parseInt(document.getElementById("AnoRegresoDropDownList").value,10),
		parseInt(document.getElementById("MesRegresoDropDownList").value,10)-1,
		parseInt(document.getElementById("DiaRegresoDropDownList").value,10));		
		
		//Compruebo que las fechas están bien introducidas
		if(hoy>salida){ok=0;CampoError+="· La fecha de salida no puede ser anterior a la fecha actual\n";} 
		if(!document.getElementById("SoloIdaRadioButton").checked)					
			if(salida>regreso){ok=0;CampoError+="· El regreso no puede ser anterior a la salida\n";} 
			
		
									
		if(ok == 0){
			alert(CampoError);
			return false;
		}
	}	
