
function log(str){
	console.log(str);
}

//calendrier
var effect=null;
function verifDateAndLoad(url,date){
	var url = url;
	var pars = 'verifDateAjax=verif';
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onComplete: function(originalRequest){
				if (originalRequest.responseText=='ok'){
					window.location = url;
				}else{
					$('calendar_info').show();
					if(!!effect)effect.cancel();
					effect=new Effect.Fade('calendar_info',{ duration: 5.0, from: 1, to: 0 });
				}
			}
		});
}

  function dateChanged(calendar) {
    // Beware that this function is called even if the end-user only
    // changed the month/year.  In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    if (calendar.dateClicked) {
      // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
      var y = calendar.date.getFullYear();
      var m = calendar.date.getMonth();     // integer, 0..11
      var d = calendar.date.getDate();      // integer, 1..31
      // redirect...
      verifDateAndLoad("/actualites/tous-les-evenements/" + str_pad(d,2,'0','STR_PAD_LEFT') + "/" + str_pad(parseInt(parseInt(m)+1),2,'0','STR_PAD_LEFT') + "/" + y + "/","/" + str_pad(d,2,'0','STR_PAD_LEFT') + "/" + str_pad(parseInt(parseInt(m)+1),2,'0','STR_PAD_LEFT') + "/" + y + "/");
      //window.location = "/actualites/tous-les-evenements/" + str_pad(d,2,'0','STR_PAD_LEFT') + "/" + str_pad(parseInt(parseInt(m)+1),2,'0','STR_PAD_LEFT') + "/" + y + "/";
    }
  };

function afficherMenu(e) {
	e.childNodes[1].style.display='block';
}
function cacherMenu(e) {
	e.childNodes[1].style.display='none';
}

function afficherSousMenu(e) {
	e.childNodes[0].style.display='block';
}
function cacherSousMenu(e) {
	e.childNodes[0].style.display='none';
}

function str_pad (input, pad_length, pad_string, pad_type)
{
  input = String (input);
  pad_string = pad_string != null ? pad_string : " ";
  if (pad_string.length > 0)
  {
    var padi = 0;
    pad_type = pad_type != null ? pad_type : "STR_PAD_RIGHT";
    pad_length = parseInt (pad_length);
    switch (pad_type)
    {
      case "STR_PAD_BOTH":
        input = str_pad (input
                       , input.length + Math.ceil ((pad_length - input.length) / 2.0)
                       , pad_string, "STR_PAD_RIGHT");
     // break;  // kein break!
      case "STR_PAD_LEFT":
        var buffer = "";
        for (var i = 0, z = pad_length - input.length; i < z; ++i)
        {
          buffer += pad_string.charAt(padi); // [padi] IE 6.x bug
          if (++padi == pad_string.length)
            padi = 0;
        }
        input = buffer + input;
        break;
      default:
        for (var i = 0, z = pad_length - input.length; i < z; ++i)
        {
          input += pad_string.charAt(padi);
          if (++padi == pad_string.length)
            padi = 0;
        }
        break;
    }
  }
  return input;
}

// ajoute automatiquement la classe focus et mouseover aux �l�ments de formulaires submit
function autofocus()
{
	$$('input[type=submit]').each(function(f){
		Event.observe(f, 'mouseover', function() {
			f.removeClassName('focus');
			f.addClassName('mouseover');
			//f.hasClassName('fruit');
		});
		Event.observe(f, 'mouseout', function() {
			f.removeClassName('mouseover');
			f.removeClassName('focus');
		});
		Event.observe(f, 'blur', function() {
			f.removeClassName('mouseover');
			f.addClassName('focus');
		});
     });
}
Event.observe(window, 'load',autofocus);

