// AJAX Calendar
function loadCal(month, year) {
  var xmlhttp;
  if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
  else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
  xmlhttp.onreadystatechange=function() {
    if(xmlhttp.readyState==4 && xmlhttp.status==200) document.getElementById("calendario").innerHTML=xmlhttp.responseText;
  }
  xmlhttp.open("GET","calendario.php?month="+month+"&year="+year,true);
  xmlhttp.send();
}

// Lightbox
$(function() {
  $('a.lightbox').lightBox();
});

$(document).ready(function() {
  $("a.toggleLink").prepend('<img src="images/icons/control_down_blue.png" class="toggleLink" alt="show"/> ');
  $(".toggle").hide();
  $("a.toggleLink").click(function() {
    $(this).parent().next(".toggle").toggle("slow");
    return false;
  });
});

//$(document).ready(function() {
//  var showText='<img src="images/icons/control_down_blue.png" alt="show"/>';
//  var hideText='<img src="images/icons/control_up_blue.png" alt="hide"/>';
//  var is_invisible=true;
//  $('.toggle').prev().prepend('<a class="toggleLink">'+showText+'</a> ');
//  $('.toggle').hide();
//  $('a.toggleLink').click(function() {
//    $(this).parent().prev().html((is_invisible) ? showText : hideText);
//    $(this).parent().next('.toggle').toggle('slow');
//    return false;
//  });
//});



// Modal Window Functions
function OpenModalWindow() {
  $(".ModalBkg").css({"opacity": "0.7"});
  $(".ModalBkg").fadeIn("slow");
  $(".Modal").fadeIn("slow");
  return true;
}
function CloseModalWindow() {
  $(".ModalBkg").fadeOut("slow");
  $(".Modal").fadeOut("slow");
  return false;
}

// Modal Window
$(document).ready(function() {
  $("a.OpenModal").prepend('<a class="OpenModal"><img src="images/icons/add.png" alt="add"/></a> ');
  var IsOpen=(document.URL.search("edit")>=0) ? true : false;
  // Default
  if(IsOpen) {
    OpenModalWindow();
  }
  // Open Window
  $("a.OpenModal").click(function() {
    if(!IsOpen) {
      IsOpen=OpenModalWindow();
    }
  });
  // Close Window
  $("a.CloseModal").click(function() {
    if(IsOpen) {
      IsOpen=CloseModalWindow();
    }
  });
  // Close Clicking Background
  $(".ModalBkg").click(function() {
    if(IsOpen) {
      IsOpen=CloseModalWindow();
    }
  });
});


