******************************************************

	A simple popup javascript date-picker 

	Author : Alain Bruguieres (bruguier@free.fr)
 
 	License: GPL; you may use this code freely, provided 
	you don't sell it.
 	Provided as is, without any warranty.
 	Feel free to use this code, but don't remove this 
 	disclaimer please.
 	If you to use my code, please listen to a Bach Cantata 
 	(if you don't know which one, why not try BWV 49 ?) and 
 	send me an e-mail.  

*********************************************************



PURPOSE : insert a date-picker control in you page.
The date-picker control is the combination of an ordinary text input control
and a clickable icon which opens a popup calendar; when you select a date in the 
calendar pop-up, the text input control receives it.

FEATURES : multilingual, accepts virtually infinitely many date formats defined by a 
template such as DD/MM/YYYY, DD-MM-YY, MM-DD-YYYY, etc... The code is short, simple,
robust and easily adaptable (or is meant so, anyways).

HOW DO I USE IT 

The following code must be inserted in the head section of your html file :

	<script type="text/javascript" src="cal.js"></script>

Now somewhere in the body of your page define a text input control like this:

       <input id="My_Date_Control" size="10" maxlength="10" type="text"> 


then add the following to invoke the date-picker :

       <img src="calendar_icon.png" align=center onClick="javascript:open_cal('My_Date_Control');">

Of course you can modify freely this html code; the only thing that matters is the onClick property!



The main function is open_cal; its arguments are invoker, [Language], [Template] where

- invoker is the name of the text input control;

- Language is one of "FR" (french, the default), "EN" (english), "SP" (spanish), "DE" (german); of course 
you may add burushaski, esperanto or proto-khuzdul to this list if you feel like it.

- Template is the date format, e. g. "DD/MM/YYYY" (the default), "DD/MM/YY", "MM-DD-YYYY", or any string 
containing the substrings "DD", "MM", and either "YYYY" or "YY".   




If you want to use the date-picker in a php-generated code, the following php function will create both 
the text input and the date-picker link inside a form; the arguments are the name of the date variable 
to be returned by the form, and the initial value for the text input.

function saisie_date($VarDate,$JOUR) {	
	$control="ZSD_".$VarDate;   //id of the text input control
	$onClick="javascript:open_cal('".$control."');";
	echo "<input type=text id='$control' name='$VarDate'  value='$JOUR' 
	style='background: white;' size='9' maxlength='10'>
	<img src='images/calendar_icon.png' width=20 height=18 border=0 
	align='center' onClick=\"$onClick\" alt='Cal.' title='ouvrir un calendrier'><br>";
	}

ACKNOWLEDGEMENTS

I am aware of the remarkable work of Kedar R. Bhave and Hugo Ortega_Hernandez
(and I have borrowed the latter's icon). However the present code was written 
entirely from scratch; the aim being to have a very straightforward code. 

In particular, all date input are converted from the format "DD/MM/YYYY" 
(or any other format defined by the global variable Template) to date objects; 
then the standard javascript functions on date objects are used. We don't have to
manage oddities such as february 29th's...
The treatment of various date formats is also simplified: it is just a matter
of search-and-replace. 

You may easily customize the code by editing the GENERAL SETTINGS section of cal.js. 