var calabierto=false;



function timeDifference(laterdate,earlierdate,cual)
{

	laterdate = new Date(laterdate);
	earlierdate = new Date(earlierdate);
    var difference = laterdate.getTime() - earlierdate.getTime();
	if (difference<0)
		{
		alert("La fecha final debe ser mayor que la fecha inicial.")
		if (cual==1)
			{
			window.document.formulario.date.value="";
			}
		if (cual==2)
			{
			window.document.formulario.date2.value="";
			}
		}
 }

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 ventanaempresa=false;

 function padout(number) { return (number < 10) ? '0' + number : number; }

 function restart(tipo)
 {
 	 if (tipo==1)
	 	{ 
	     document.formulario.date.value = '' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year;
    	 mywindow.close();
		 if (document.formulario.date2.value!="")
			{
			timeDifference(window.document.formulario.date2.value,window.document.formulario.date.value,1)
			}
		}
	if (tipo==2)
	 	{ 
	     document.formulario.date2.value = '' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year;
    	 mywindow.close();
	     if (document.formulario.date.value!="")
	  	 	{
			timeDifference(window.document.formulario.date2.value,window.document.formulario.date.value,2)
			}
		}
	if (tipo==0)
	 	{ 
	     document.formulario.date.value = '' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year;
    	 mywindow.close();
		}
 }

 function newWindow(tipo) {

	 calabierto=true;
     mywindow=open('cal.asp','myname','resizable=no,width=350,height=270');
   	 mywindow.location.href = 'cal.asp?tipo=' + tipo;
   	 if (mywindow.opener == null) mywindow.opener = self;
 }
 
 function borrafecha(cual)
{

var forma=document.formulario;
if (cual==1 || cual==0)
	{
		forma.date.value=""
	}
if (cual==2)
	{
		forma.date2.value=""
	}
}

