// JavaScript Document

var xmlhttp = false ;


if (!xmlhttp && typeof XMLHttpRequest != "undefined")
{
try {
xmlhttp = new XMLHttpRequest ();
}
catch (e) {
xmlhttp = false}
}

function setAnneesHd()
{
	document.getElementById('hd_year').value = document.frm_cal_nav.cbo_annees.options[document.frm_cal_nav.cbo_annees.selectedIndex].value;
	document.getElementById('hd_month').value = document.frm_cal_nav.cbo_mois.options[document.frm_cal_nav.cbo_mois.selectedIndex].value;
}

function setAnneesCbo(myIndex)
{
	alert(myIndex);
	document.frm_cal_nav.cbo_annees.selectedIndex = myIndex;
}

function setMoisCbo(myIndex)
{
	
	/*alert(myIndex);
	 document.frm_cal_nav.cbo_mois.selectedIndex = myIndex;
	*/
	document.getElementById(myIndex).selected = 'selected';
}


function setMoisHd()
{
	document.getElementById('hd_month').value = document.frm_cal_nav.cbo_mois.options[document.frm_cal_nav.cbo_mois.selectedIndex].value;
	document.getElementById('hd_year').value = document.frm_cal_nav.cbo_annees.options[document.frm_cal_nav.cbo_annees.selectedIndex].value;
}

function updateCal()
{
	//alert('Year : '+ document.getElementById('hd_year').value + "  Month : " + document.getElementById('hd_month').value );
	setAnneesHd();
	myStr =  "hd_year="+document.getElementById('hd_year').value+"&hd_month="+document.getElementById('hd_month').value;
	ajax_update("cal.php", myStr);
}

function setSelectListToValue(value, selectId){
	var i, si, v, args=setSelectListToValue.arguments;
	if ((obj=document.getElementById(args[1])) != null){
		v = args[0];
		for(i=0; i<obj.length; i++){
			if(obj.options[i].value == v){
				si = i;
			}
		}
		obj.selectedIndex = si;
	}
}

function next_month()
{
	month = parseInt(document.frm_cal_nav.cbo_mois.options[document.frm_cal_nav.cbo_mois.selectedIndex].value,10) ;
	
	
	if(month < 12)
	{
		if(month < 9)
		{
			document.getElementById('hd_year').value = document.frm_cal_nav.cbo_annees.options[document.frm_cal_nav.cbo_annees.selectedIndex].value;
			document.getElementById('hd_month').value = '0'+((month+1).toString()) ; 
			//alert(document.getElementById('hd_month').value);
		}
		else
		{
			document.getElementById('hd_month').value = (month+1).toString() ; 
			//alert(document.getElementById('hd_month').value);
		}
	}
	else
	{
			document.getElementById('hd_year').value = parseInt(document.frm_cal_nav.cbo_annees.options[document.frm_cal_nav.cbo_annees.selectedIndex].value)+1;
			document.getElementById('hd_month').value = '01' ;
			
	}
	
	//alert('month : '+document.getElementById('hd_month').value+' <br /> year : '+document.getElementById('hd_year').value);
	shiftBigCal();
	setSelectListToValue(document.getElementById("hd_year").value,'cbo_annees');
	setSelectListToValue(document.getElementById("hd_month").value,'cbo_mois');
}

function prev_month()
{
	month = parseInt(document.frm_cal_nav.cbo_mois.options[document.frm_cal_nav.cbo_mois.selectedIndex].value,10) ;
	//alert(month);
	if(month > 1)
	{
		if(month < 11)
		{
			document.getElementById('hd_year').value = document.frm_cal_nav.cbo_annees.options[document.frm_cal_nav.cbo_annees.selectedIndex].value;
			document.getElementById('hd_month').value = '0'+(month-1).toString() ; 
		}
		else
		{
			document.getElementById('hd_month').value = (month-1).toString() ; 
		}
		
	}
	else
	{
			document.getElementById('hd_year').value = parseInt(document.frm_cal_nav.cbo_annees.options[document.frm_cal_nav.cbo_annees.selectedIndex].value)-1;
			document.getElementById('hd_month').value = '12' ;
			//alert(month)
	}
	//alert('month : '+document.getElementById('hd_month').value+' <br /> year : '+document.getElementById('hd_year').value);
	
	shiftBigCal();
	setSelectListToValue(document.getElementById("hd_year").value,'cbo_annees');
	setSelectListToValue(document.getElementById("hd_month").value,'cbo_mois');	
}

function updateBigCal()
{
	//alert('Year : '+ document.getElementById('hd_year').value + "  Month : " + document.getElementById('hd_month').value );
	setAnneesHd();
	myStr =  "hd_year="+document.getElementById('hd_year').value+"&hd_month="+document.getElementById('hd_month').value;
	ajax_update("bigcal_content.php", myStr);
}

function shiftBigCal()
{
	myStr =  "hd_year="+document.getElementById('hd_year').value+"&hd_month="+document.getElementById('hd_month').value;
	ajax_update("bigcal_content.php", myStr);
}


function myXMLHttpRequest ()
{
var xmlhttplocal;
try {
xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
catch (e) {
try {
xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
catch (E) {
xmlhttplocal = false;
}
}

if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
try {
var xmlhttplocal = new XMLHttpRequest ();
}
catch (e) {
var xmlhttplocal = false;
}
}
return (xmlhttplocal);
}

var mnmxmlhttp = Array ();
var mnmString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;

var i=0;
var ii = 0;
function ajax_update(myFile,myPost)
{
url = myFile;
target2 = document.getElementById ('content');
ii = i++;

var content = myPost ;

mnmxmlhttp = new myXMLHttpRequest ();
if (mnmxmlhttp) {
/*mnmxmlhttp.open ("POST", url, true);*/
mnmxmlhttp.open ("GET", url+"?"+myPost, true);
mnmxmlhttp.setRequestHeader ('Content-Type',
'application/x-www-form-urlencoded');

/*mnmxmlhttp.send (content);*/
mnmxmlhttp.send (content);
errormatch = new RegExp ("^ERROR:");

target2 = document.getElementById ('content');

mnmxmlhttp.onreadystatechange = function () {
if (mnmxmlhttp.readyState == 4) {
mnmString = mnmxmlhttp.responseText;

if (mnmString.match (errormatch)) {
mnmString = mnmString.substring (6, mnmString.length);

target = document.getElementById ('content');
target2.innerHTML = mnmString;

} else {
target = document.getElementById ('content');

target2.innerHTML = mnmString;


}
}
}
}
 /*setTimeout('ajax_update()', 20000);*/
}