

function date_time_picker(id,interval)
{

	var theinput=document.getElementById(id);
	var thedate=new Date(theinput.value*1000);

	var theday=document.createElement('select');
	var days=daysInMonth(thedate.getMonth()+1,thedate.getYear())+1;
	for(i=1;i<days;i++)
	{		
		theday.options[theday.length]=new Option(PadDigits(i,2),i );
	}
	theday.value=thedate.getDate();
	theday.onchange=function()
	{
		thedate=new Date(theyear.value,themonth.value-1,theday.value,thehour.value,themin.value,0);
		theinput.value=Math.round(thedate.getTime()/1000+7200)
	};
	theinput.parentNode.appendChild(theday);

	var themonth=document.createElement('select');
	
	
	themonth.options[themonth.length]=new Option("Jan",1 );
	themonth.options[themonth.length]=new Option("Feb",2 );
	themonth.options[themonth.length]=new Option("Mar",3 );
	themonth.options[themonth.length]=new Option("Apr", 4);
	themonth.options[themonth.length]=new Option("May",5 );
	themonth.options[themonth.length]=new Option("Jun",6 );
	themonth.options[themonth.length]=new Option("Jul",7 );
	themonth.options[themonth.length]=new Option("Aug",8 );
	themonth.options[themonth.length]=new Option("Sep",9 );
	themonth.options[themonth.length]=new Option("Oct",10 );
	themonth.options[themonth.length]=new Option("Nov",11 );
	themonth.options[themonth.length]=new Option("Dec",12 );
	
	
	themonth.selectedIndex=thedate.getMonth();
	themonth.onchange=function()
	{
		var d=parseInt(theday.value);
		theday.options.length=0;
		var dm=daysInMonth(themonth.value,theyear.value)+1;		
		
		for(i=1;i<dm;i++)
		{			
			theday.options[theday.length]=new Option(PadDigits(i,2),i );
		}
		if(dm>(d+1))
		{
			theday.value=d;
			
		}else{
			
			theday.value=dm-1
		}
		thedate=new Date(theyear.value,themonth.value-1,theday.value,thehour.value,themin.value,0);
		theinput.value=Math.round(thedate.getTime()/1000+7200)
	};
	
	theinput.parentNode.appendChild(themonth);

	var theyear=document.createElement('select');

	for(i=1900;i<2100;i++)
	{		
		theyear.options[theyear.length]=new Option(i,i );		
	}
	
	var y=0;
	if(thedate.getYear()<1000)
	{
		y=thedate.getYear()+1900;
	}else{
		y=thedate.getYear();
	}
	theyear.value=y;
	theyear.onchange=function()
	{
		var d=parseInt(theday.value);
		theday.options.length=0;
		var dm=daysInMonth(themonth.value,theyear.value)+1;		
		
		for(i=1;i<dm;i++)
		{
			theday.options[theday.length]=new Option(PadDigits(i,2),i );			
		}
		if(dm>(d+1))
		{
			theday.value=d;
			
		}else{
			
			theday.value=dm-1
		}
		thedate=new Date(theyear.value,themonth.value-1,theday.value,thehour.value,themin.value,0);
		theinput.value=Math.round(thedate.getTime()/1000+7200)
	};
	
   theinput.parentNode.appendChild(theyear);
   
   var thehour=document.createElement('select');
   for(i=0;i<24;i++)
   {						
		thehour.options[thehour.length]=new Option(PadDigits(i,2),i );		
   }
   thehour.value=thedate.getHours();
   thehour.onchange=function()
	{
		thedate=new Date(theyear.value,themonth.value-1,theday.value,thehour.value,themin.value,0);
		theinput.value=Math.round(thedate.getTime()/1000+7200)
	};  
   
   theinput.parentNode.appendChild(thehour);

   var themin=document.createElement('select');
   for(i=0;i<60;i+=interval)
   {		
		themin.options[themin.length]=new Option(PadDigits(i,2),i );
   }
   for(i=0;i<60;i+=interval)
   {
		if(thedate.getMinutes()>=i)
		{
			themin.value=i;
		}
   }
   themin.onchange=function()
	{
		thedate=new Date(theyear.value,themonth.value-1,theday.value,thehour.value,themin.value,0);
		theinput.value=Math.round(thedate.getTime()/1000+7200)
	};
   theinput.parentNode.appendChild(themin);   
  
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

function date_picker(id)
{

	var theinput=document.getElementById(id);
	
	var thedate=new Date(theinput.value*1000);
	
	var theday=document.createElement('select');
	
	var days=daysInMonth(thedate.getMonth()+1,thedate.getYear())+1;
	
	for(i=1;i<days;i++)
	{
		theday.options[theday.length]=new Option(PadDigits(i,2),i );
	}
	theday.value=thedate.getDate();
	theday.onchange=function()
	{
		thedate=new Date(theyear.value,themonth.value-1,theday.value);
		theinput.value=Math.round(thedate.getTime()/1000+7200)
	};
	theinput.parentNode.appendChild(theday);

	var themonth=document.createElement('select');
	
	themonth.options[themonth.length]=new Option("Jan",1 );
	themonth.options[themonth.length]=new Option("Feb",2 );
	themonth.options[themonth.length]=new Option("Mar",3 );
	themonth.options[themonth.length]=new Option("Apr", 4);
	themonth.options[themonth.length]=new Option("May",5 );
	themonth.options[themonth.length]=new Option("Jun",6 );
	themonth.options[themonth.length]=new Option("Jul",7 );
	themonth.options[themonth.length]=new Option("Aug",8 );
	themonth.options[themonth.length]=new Option("Sep",9 );
	themonth.options[themonth.length]=new Option("Oct",10 );
	themonth.options[themonth.length]=new Option("Nov",11 );
	themonth.options[themonth.length]=new Option("Dec",12 );
	
	themonth.selectedIndex=thedate.getMonth();
	themonth.onchange=function()
	{
		var d=parseInt(theday.value);
		theday.options.length=0;
		var dm=daysInMonth(themonth.value,theyear.value)+1;		
		
		for(i=1;i<dm;i++)
		{
			theday.options[theday.length]=new Option(PadDigits(i,2),i );
		}
		if(dm>(d+1))
		{
			theday.value=d;
			
		}else{
			
			theday.value=dm-1
		}
		thedate=new Date(theyear.value,themonth.value-1,theday.value);
		theinput.value=Math.round(thedate.getTime()/1000+7200) 
	};
	
	theinput.parentNode.appendChild(themonth);

	var theyear=document.createElement('select');

	for(i=1900;i<2100;i++)
	{
		theyear.options[theyear.length]=new Option(i,i );
		
	}
	var y=0;
	if(thedate.getYear()<1000)
	{
		y=thedate.getYear()+1900;
	}else{
		y=thedate.getYear();
	}
	theyear.value=y;
	theyear.onchange=function()
	{
		var d=parseInt(theday.value);
		theday.options.length=0;
		var dm=daysInMonth(themonth.value,theyear.value)+1;		
		
		for(i=1;i<dm;i++)
		{			
			theday.options[theday.length]=new Option(PadDigits(i,2),i );
		}
		if(dm>(d+1))
		{
			theday.value=d;
			
		}else{
			
			theday.value=dm-1
		}
		thedate=new Date(theyear.value,themonth.value-1,theday.value);
		theinput.value=Math.round(thedate.getTime()/1000+7200)
	};
	
   theinput.parentNode.appendChild(theyear);
  
}
function daysInMonth(month,year) {
	var m = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (month != 2) return m[month - 1];
	if (year%4 != 0) return m[1];
	if (year%100 == 0 && year%400 != 0) return m[1];
	return m[1] + 1;
}
function PadDigits(n, totalDigits) 
{ 
	n = n.toString(); 
	var pd = ''; 
	if (totalDigits > n.length) 
	{ 		
		for (z=0; z < (totalDigits-n.length); z++) 
		{ 
			pd += '0'; 
		} 
	} 
	return pd + n.toString(); 
} 
