  var DateFromformat = 'dd/mm/yyyy'; //Set the dateformat
  // returns array with days in the months
    function DateFromarrayOfDaysInMonths(adm_isLeapYear) {
      this[0] = 31;
      this[1] = 28;
      // if Leap Year there is 29 days in Feb
        if (adm_isLeapYear)
          this[1] = 29;
      this[2] = 31;
      this[3] = 30;
      this[4] = 31;
      this[5] = 30;
      this[6] = 31;
      this[7] = 31;
      this[8] = 30;
      this[9] = 31;
      this[10] = 30;
      this[11] = 31;
    }
 
 // _________________________________________________________
 // The next two functions handle the formatting of the date.
 // To add a new mask you only need to added the conversion
 // to the next two functions respectively
 // _________________________________________________________
 
 // Split the date based on format
    function DateFromSplitDate(stDate){
  		arryDate = stDate.split('/');
      arryNewDate = new Array(3);
      if (DateFromformat == 'mm/dd/yyyy')
        arryNewDate = new Array(arryDate[0]-0,arryDate[1]-0,arryDate[2]-0);
      else if(DateFromformat == 'dd/mm/yyyy')
        arryNewDate = new Array(arryDate[1]-0,arryDate[0]-0,arryDate[2]-0);
      return arryNewDate; //Return date array: [0] = month, [1] = day, [2] = year
    }
 // Join the date based on format 
    function DateFromJoinDate(arryDate){ //arryDate: [0] = month, [1] = day, [2] = year
      if (DateFromformat == 'mm/dd/yyyy')
        var stDate = (arryDate[0]<10?'0'+arryDate[0]:arryDate[0]) + '/' + (arryDate[1]<10?'0'+arryDate[1]:arryDate[1]) + '/' + arryDate[2];
      else if(DateFromformat == 'dd/mm/yyyy')
        var stDate = (arryDate[1]<10?'0'+arryDate[1]:arryDate[1]) + '/' + (arryDate[0]<10?'0'+arryDate[0]:arryDate[0]) + '/' + arryDate[2];
      return stDate      
    }  
    
 // Returns the days in the given month and year
   function DateFromdaysInMonth(dim_month,dim_year) {
     // Check for leap year
       var dim_isLeapYear = (((dim_year % 4 == 0) && ( dim_year % 100 != 0)) || (dim_year % 400 == 0));
     // Create array of days in each month
       var dim_monthDays = new DateFromarrayOfDaysInMonths(dim_isLeapYear);
     // Return the days in month
       return dim_monthDays[dim_month];
   }
	
  	// Validates date on onBlur of date field
	function DateFromValidateDate(strDate) {
		arryDate = DateFromSplitDate(strDate);	// Split the date up into a month day year array
		if (strDate.length && (isNaN(parseInt(arryDate[2])) || isNaN(parseInt(arryDate[0])) || arryDate[0] > 12 || isNaN(parseInt(arryDate[1])) || arryDate[1] > DateFromdaysInMonth(arryDate[0] - 1,arryDate[2]))) {
			arryDate[0] = 4;
			arryDate[1] = 24;
			arryDate[2] = 2005;
		}
    document.forma.DateFrom.value = DateFromJoinDate(arryDate);
	}			
  
	// Make sure date being processed is valid if not, set date to today
	function DateFromisValidDate(dateObj) {
		if (isNaN(parseInt(dateObj[0])) || isNaN(parseInt(dateObj[1])) || isNaN(parseInt(dateObj[2]))) {
			dateObj[0] = 4;
			dateObj[1] = 24;
			dateObj[2] = 2005;
		}
		return (dateObj);
	}				
		
  function DateFromnextDay(n) {
		currDate = document.forma.DateFrom.value;
		arryDate = DateFromSplitDate(currDate);		// Split the date up into a month day year array
		arryDate = DateFromisValidDate(arryDate);
		daysinCurrMonth = DateFromdaysInMonth(parseInt(arryDate[0])-1,parseInt(arryDate[2]));		// Get the number of days in the current month
		arryDate[1] = parseInt(arryDate[1]) + n;		// Add one to the day
		// Check for day value to be more than days in the month
		if (arryDate[1] > daysinCurrMonth) {
			nextMonth = parseInt(arryDate[0]) + 1;
			if (nextMonth > 12) {
				arryDate[0] = 1;
				arryDate[2] = parseInt(arryDate[2]) + 1;
			}
			else
				arryDate[0] = nextMonth;
			arryDate[1] = 1;
		}
		document.forma.DateFrom.value = DateFromJoinDate(arryDate);
  }    
  function DateFrompreviousDay(n) {
		currDate = document.forma.DateFrom.value;
		arryDate = DateFromSplitDate(currDate);
		arryDate = DateFromisValidDate(arryDate);
		daysinPrevMonth = DateFromdaysInMonth(parseInt(arryDate[0])-2,parseInt(arryDate[2]));
		arryDate[1] = parseInt(arryDate[1]) - n;
		// Check for day of zero
		if (arryDate[1] < 1) {
			prevMonth = parseInt(arryDate[0]) - 1;
			if(prevMonth == 0) {
				arryDate[0] = 12;
				arryDate[2] = parseInt(arryDate[2]) - 1;
				arryDate[1] = 31;
			}
			else {
				arryDate[0] = prevMonth;
				arryDate[1] = daysinPrevMonth;
			}
		}
		document.forma.DateFrom.value = DateFromJoinDate(arryDate);
  }

  function y2k(number)    { return (number < 1000) ? number + 1900 : number; }
  
  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = y2k(today.getYear());
  var activeDateField;
  
function restart() {
    arryDate = new Array((parseInt(month)+1),day,year)
    //alert(activeDateField.value);
    activeResetFunction = eval(activeDateField.name+'JoinDate');
    activeDateField.value = activeResetFunction(arryDate);
    mywindow.close();
}
  
  function DateFromnewWindow(DateField) {
      if (DateField.value != ''){
    		arryDate = DateFromSplitDate(DateField.value);
        month = arryDate[0]-1;
        year = arryDate[2];
        day = arryDate[1];
      }
      activeDateField = DateField;
      mywindow=open('../Includes/cal.htm','myname','resizable=no,width=230,height=160');
      mywindow.location.href = '../Includes/cal.htm';
      if (mywindow.opener == null) mywindow.opener = self;
  }
  var DateToformat = 'dd/mm/yyyy'; //Set the dateformat
  // returns array with days in the months
    function DateToarrayOfDaysInMonths(adm_isLeapYear) {
      this[0] = 31;
      this[1] = 28;
      // if Leap Year there is 29 days in Feb
        if (adm_isLeapYear)
          this[1] = 29;
      this[2] = 31;
      this[3] = 30;
      this[4] = 31;
      this[5] = 30;
      this[6] = 31;
      this[7] = 31;
      this[8] = 30;
      this[9] = 31;
      this[10] = 30;
      this[11] = 31;
    }
 
 // _________________________________________________________
 // The next two functions handle the formatting of the date.
 // To add a new mask you only need to added the conversion
 // to the next two functions respectively
 // _________________________________________________________
 
 // Split the date based on format
    function DateToSplitDate(stDate){
  		arryDate = stDate.split('/');
      arryNewDate = new Array(3);
      if (DateToformat == 'mm/dd/yyyy')
        arryNewDate = new Array(arryDate[0]-0,arryDate[1]-0,arryDate[2]-0);
      else if(DateToformat == 'dd/mm/yyyy')
        arryNewDate = new Array(arryDate[1]-0,arryDate[0]-0,arryDate[2]-0);
      return arryNewDate; //Return date array: [0] = month, [1] = day, [2] = year
    }
 // Join the date based on format 
    function DateToJoinDate(arryDate){ //arryDate: [0] = month, [1] = day, [2] = year
      if (DateToformat == 'mm/dd/yyyy')
        var stDate = (arryDate[0]<10?'0'+arryDate[0]:arryDate[0]) + '/' + (arryDate[1]<10?'0'+arryDate[1]:arryDate[1]) + '/' + arryDate[2];
      else if(DateToformat == 'dd/mm/yyyy')
        var stDate = (arryDate[1]<10?'0'+arryDate[1]:arryDate[1]) + '/' + (arryDate[0]<10?'0'+arryDate[0]:arryDate[0]) + '/' + arryDate[2];
      return stDate      
    }  
    
 // Returns the days in the given month and year
   function DateTodaysInMonth(dim_month,dim_year) {
     // Check for leap year
       var dim_isLeapYear = (((dim_year % 4 == 0) && ( dim_year % 100 != 0)) || (dim_year % 400 == 0));
     // Create array of days in each month
       var dim_monthDays = new DateToarrayOfDaysInMonths(dim_isLeapYear);
     // Return the days in month
       return dim_monthDays[dim_month];
   }
	
  	// Validates date on onBlur of date field
	function DateToValidateDate(strDate) {
		arryDate = DateToSplitDate(strDate);	// Split the date up into a month day year array
		if (strDate.length && (isNaN(parseInt(arryDate[2])) || isNaN(parseInt(arryDate[0])) || arryDate[0] > 12 || isNaN(parseInt(arryDate[1])) || arryDate[1] > DateTodaysInMonth(arryDate[0] - 1,arryDate[2]))) {
			arryDate[0] = 4;
			arryDate[1] = 24;
			arryDate[2] = 2005;
		}
    document.forma.DateTo.value = DateToJoinDate(arryDate);
	}			
  
	// Make sure date being processed is valid if not, set date to today
	function DateToisValidDate(dateObj) {
		if (isNaN(parseInt(dateObj[0])) || isNaN(parseInt(dateObj[1])) || isNaN(parseInt(dateObj[2]))) {
			dateObj[0] = 4;
			dateObj[1] = 24;
			dateObj[2] = 2005;
		}
		return (dateObj);
	}				
		
  function DateTonextDay(n) {
		currDate = document.forma.DateTo.value;
		arryDate = DateToSplitDate(currDate);		// Split the date up into a month day year array
		arryDate = DateToisValidDate(arryDate);
		daysinCurrMonth = DateTodaysInMonth(parseInt(arryDate[0])-1,parseInt(arryDate[2]));		// Get the number of days in the current month
		arryDate[1] = parseInt(arryDate[1]) + n;		// Add one to the day
		// Check for day value to be more than days in the month
		if (arryDate[1] > daysinCurrMonth) {
			nextMonth = parseInt(arryDate[0]) + 1;
			if (nextMonth > 12) {
				arryDate[0] = 1;
				arryDate[2] = parseInt(arryDate[2]) + 1;
			}
			else
				arryDate[0] = nextMonth;
			arryDate[1] = 1;
		}
		document.forma.DateTo.value = DateToJoinDate(arryDate);
  }    
  function DateTopreviousDay(n) {
		currDate = document.forma.DateTo.value;
		arryDate = DateToSplitDate(currDate);
		arryDate = DateToisValidDate(arryDate);
		daysinPrevMonth = DateTodaysInMonth(parseInt(arryDate[0])-2,parseInt(arryDate[2]));
		arryDate[1] = parseInt(arryDate[1]) - n;
		// Check for day of zero
		if (arryDate[1] < 1) {
			prevMonth = parseInt(arryDate[0]) - 1;
			if(prevMonth == 0) {
				arryDate[0] = 12;
				arryDate[2] = parseInt(arryDate[2]) - 1;
				arryDate[1] = 31;
			}
			else {
				arryDate[0] = prevMonth;
				arryDate[1] = daysinPrevMonth;
			}
		}
		document.forma.DateTo.value = DateToJoinDate(arryDate);
  }

  function y2k(number)    { return (number < 1000) ? number + 1900 : number; }
  
  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = y2k(today.getYear());
  var activeDateField;
  
function restart() {
    arryDate = new Array((parseInt(month)+1),day,year)
    //alert(activeDateField.value);
    activeResetFunction = eval(activeDateField.name+'JoinDate');
    activeDateField.value = activeResetFunction(arryDate);
    mywindow.close();
}
  
  function DateTonewWindow(DateField) {
      if (DateField.value != ''){
    		arryDate = DateToSplitDate(DateField.value);
        month = arryDate[0]-1;
        year = arryDate[2];
        day = arryDate[1];
      }
      activeDateField = DateField;
      mywindow=open('../Includes/cal.htm','myname','resizable=no,width=230,height=160');
      mywindow.location.href = '../Includes/cal.htm';
      if (mywindow.opener == null) mywindow.opener = self;
  }
function cambia(St)
  { return St.replace(/(\d+)\/(\d+)\/(\d+)/, "$2/$1/$3") }

function revisarfechas(fecha1,fecha2) {
revisado=1;
date1= cambia(fecha1);
date2= cambia(fecha2);
var df= Date.parse(date1);
var dt= Date.parse(date2);
days = Math.round( (dt-df) / 86400000 );
if (days<0) {alert("La fecha de SALIDA no puede ser menor a la fecha de Entrada"); revisado=0}
hoy="04/23/2005";
var dh= Date.parse(hoy);
diash= Math.round( (df-dh) /864e5);
if (diash<1) {alert("La fecha de ENTRADA tiene que ser mayor a la fecha de hoy"); revisado=0}
if (fecha1==fecha2) { alert("La fecha de ENTRADA no puede ser igual a la fecha de SALIDA"); revisado=0}
return revisado;
}
function submit_query() {
	f1=document.forma.DateFrom.value;
	f2=document.forma.DateTo.value;
	ok= revisarfechas(f1,f2);
	if (ok>0) {	
	document.forma.submit(); } 
}
function deshabilita_opciones(valor) {
return true;
}

function cambia(St)
  { return St.replace(/(\d+)\/(\d+)\/(\d+)/, "$2/$1/$3") }

function actualiza_fechaTo() {
cc=document.forma.DateFrom.value
f1=cambia(cc);
fecham=Date.parse(f1);
fechas= new Date( fecham+864e5);
xdia= fechas.getDate();
xmes= fechas.getMonth()+1;
xano= fechas.getYear();
if (xdia < 10) { xdia="0"+xdia} ;
if (xmes < 10) { xmes="0"+xmes} ;
xfecha=xdia+"/"+xmes+"/"+xano;
document.forma.DateTo.value=xfecha;
}