function showCalendar (o, y, m)
{
	if (document.getElementById('calendar').style.display == 'none')
	{
		document.getElementById('calendar').style.display = 'block';

		calendar (o,y,m);
	}
	else
	{
		document.getElementById('calendar').style.display =  'none';
	}
}

function calendar (o, y, m)
{
	if ((document.getElementById(o).value) && (!y))
	{
		var data = document.getElementById(o).value.split('-');

		if (data.length > 0)
		{
			var myint = /d+/;
 
			if (myint.exec(data[2])) y = parseInt(data[2]);

			if (myint.exec(data[1]))
			{
				m = parseInt(data[1]);

				if (m < 0) m = 1;

				if (m > 12) m = 12;
			}

			if (myint.exec(data[0])) var today = data[0];
		}
	}

	var x = new Date();

	if (!y)
	{
		y = x.getFullYear();

		var today = x.getDate();
	}

	if (!m) m = x.getMonth() + 1;



	w = 0;

	d = 1;

	var cal;

	cal =  '<div style="position:absolute;"><iframe style="border:1px;position:absolute;z-index:-1;width:160px;height:140px;float:left;" src="javascript:false;" frameBorder="0" scrolling="no"></iframe></div>';

	if (document.all) cal += '<div style="position:absolute;">';

	cal += '<table border="1" cellpadding="0" cellspacing="0" bordercolor="#e6e6dd" style="z-index:1px;font:8px Verdana; border-collapse: collapse; background-color:#ffffff; border:1px solid #aca899;cursor:pointer;width:160px;height:140px;">';
	cal += '<tr><td align="center" style="font:12px;padding:4px;background-color:#aca899;color:#ffffff">';

	cal += ' <table border="0" cellpadding="0" cellspacing="0" style="display:inline;">';
	cal += '  <td>';
	cal += '   <select id="m" onchange="calendar(\''+o+'\', document.getElementById(\'y\').value, this.value)">';
	cal += '    <option value="1">Janvier</option>';
	cal += '    <option value="2">Février</option>';
	cal += '    <option value="3">Mars</option>';
	cal += '    <option value="4">Avril</option>';
	cal += '    <option value="5">Mai</option>';
	cal += '    <option value="6">Juin</option>';
	cal += '    <option value="7">Juillet</option>';
	cal += '    <option value="8">Août</option>';
	cal += '    <option value="9">Septembre</option>';
	cal += '    <option value="10">Octobre</option>';
	cal += '    <option value="11">Novembre</option>';
	cal += '    <option value="12">Décembre</option>';
	cal += '   </select>';
	cal += '  </td>';
	cal += ' </table>';
        cal += ' <table border="0" cellpadding="0" cellspacing="0" style="display:inline;"><td><select id="y" onchange="calendar(\''+o+'\', this.value, document.getElementById(\'m\').value)">';

	for (i = 1970; i < 2070; i++) cal += '<option value='+i+'>'+i+'</option>';

	cal += ' </select></td></table>';

	cal += '</td></tr><tr><td>';

	cal += '<table border="1" bordercolor="#e6e6dd" cellpadding="4" cellspacing="0" style="font-size:9px; border-collapse: collapse; cursor:pointer;">';
	cal += '<tr align="center" style=" font-size:10px">';
	cal += '<td>D</td>';
	cal += '<td>S</td>';
	cal += '<td>T</td>';
	cal += '<td>Q</td>';
	cal += '<td>Q</td>';
	cal += '<td>S</td>';
	cal += '<td>S</td>';
	cal += '</tr>';

	for (i=0; i<6; i++)
	{
		cal += '<tr align="center">';

		for (j=0; j<7; j++)
		{
			x = new Date (y, m-1, w+1);

			if ((d > x.getUTCDay()) && (m-1 == x.getMonth()))
			{
				w++;

				data = w.toString() + '-' + m.toString() + '-' + y.toString();

				if (today == w) cal += '<td bgcolor="#cfcfcf" onclick="document.getElementById(\''+o+'\').value = \''+data+'\';  document.getElementById(\'calendar\').style.display = \'none\';" class="">'+w+'</td>';
				else
				{
					cal += '<td bgcolor="#ffffff" onclick="document.getElementById(\''+o+'\').value = \''+data+'\';  document.getElementById(\'calendar\').style.display = \'none\';" class="">'+w+'</td>';
				}
			}
			else
			{
				cal += '<td bgcolor="#ffffff" onclick="" class=""></td>';
			}

			d++;
		}

		cal += '</tr>';
	}

	cal += '</table>';
	cal += '</td></tr></table>';

	if (document.all) cal += '</div>';

	document.getElementById('calendar').innerHTML =  cal;

	document.getElementById('y').value = x.getFullYear();

	document.getElementById('m').value = m;
}

function doOrder (i)
{
	XSLSort = document.XSLDocument.documentElement.selectNodes("//xsl:sort");
 
	if (XSLSort[0].attributes(0).text == i.toString())
	{
		if ( XSLSort[0].attributes(1).text == "ascending")
		{
			XSLSort[0].attributes(1).text = "descending";
		}
		else
		{
			XSLSort[0].attributes(1).text = "ascending";
		}
	}
	else
	{
		XSLSort[0].attributes(1).text = "ascending";
	}

	XSLSort[0].attributes(0).text = i.toString();

	document.body.innerHTML =  document.XMLDocument.transformNode(document.XSLDocument);
}

function openFlag (o)
{
	j = document.getElementById('h').getElementsByTagName("div");

	for (var i = 0; i < j.length; i++)
	{
		if (document.getElementById('c'+j[i].id)) document.getElementById('c'+j[i].id).style.display = 'none';

		j[i].style.top = '0px';
		j[i].style.left = '0px';
		j[i].style.zIndex = '1';

		if (o == j[i].id)
		{
			if (document.getElementById('c'+j[i].id)) document.getElementById('c'+j[i].id).style.display = 'inline';

			j[i].style.top = '1px';
			j[i].style.zIndex = '2';
		}

		if (j[i].id >= o) j[i].style.left = '-1px';
	}

	if (!document.all)
	{
		if (iframeObj = document.getElementById('c'+o).getElementsByTagName("iframe"))
		{
			if (iframeObj[0])
			{
				iframeName = iframeObj[0].name;

				iframeId = eval(iframeName+".document");

				iframeId.form1.submit();
			}
		}
	}
}

function openMenu (o)
{
	j = document.getElementById('menu').getElementsByTagName("div");

	for (var i = 0; i < j.length; i++)
	{
		if (document.getElementById('c'+j[i].id)) document.getElementById('c'+j[i].id).style.display = 'none';
	}

	document.getElementById('c'+o).style.display = 'block';
}

function selectRecord (o)
{
	if (o.style.backgroundColor == '#f8f6ec') o.style.backgroundColor = '#ffffff';
	else
	{
		o.style.backgroundColor = '#f8f6ec';
	}
}

function today (i)
{
	y = new Date();

	m = y.getMonth() + 1;

	i.value = y.getFullYear() + '-' + m + '-' + y.getDate();
}

	function urlencode (str)
	{
		var SAFECHARS = "0123456789" +					// Numeric
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
						"abcdefghijklmnopqrstuvwxyz" +
						"-_.!~*'()";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";

		var plaintext = str;
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
		    if (ch == " ") {
			    encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
			    encoded += ch;
			} else {
			    var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
				    alert( "Unicode Character '" 
        	                + ch 
	                        + "' cannot be encoded using standard URL encoding.\n" +
				        	  "(URL encoding only supports 8-bit characters.)\n" +
							  "A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		}

		return encoded;
	}
