/* Code to be executed at document ready */

$(document).ready(function() {

/*
     $("[id*=globalprayer]").live("click", function () {
      $("[id*=calprayer]").toggle();
    });
*/   
        $("#prayerid").change(function() {
        var $p = $("#prayerid option:selected").val();
        if ($p != "00"){
           $("#Reply").removeAttr("disabled");
        } else{
        $("#Reply").attr("disabled", "disabled");
        }
    });

     $("[id*=img-]").hover(function() {
		$(this).attr("src","assets/js/database/rightarraw16x16.png");
			}, function() {
		$(this).attr("src","assets/js/database/arrawdown16x16.png");
	  }); 
    $("[id*=img-]").click(function()
     {
       var $pos=$(this).attr("id").split("-");
       $("#pry-"+$pos[1]).toggle();
     });
     $("[id*=print-]").hover(function() {
		$(this).attr("src","assets/js/database/pdf2.gif");
			}, function() {
		$(this).attr("src","assets/js/database/pdf.png");
	  }); 
    $("[id*=print-]").click(function()  {
       var pos=$(this).attr("id").split("-");
      // alert ("pdf: " + pos[1] + " click ");
       var answer = confirm("您真的要列印這代禱事項?");
        if (answer == true) {
            //window.location="1882?mid="+pos[1]; 
           window.location="index.php?id=1882&mid="+pos[1]; 
        }       
     });
    
    $('#prayertime').each(function () {
    var tt = new Date().getTimezoneOffset();  
    $.ajax({
              url: "460?act=localtime&offset=" + tt,
              //data: $datastr,
              cache: false,
              success: function(html) {
              /*
                  $time = html.replace("<p>", "").replace("</p>","").split("*");
                  //alert ($time);
                  $('#cal').text($time[1]);
                  $('#cal2').text($time[0]);
                  $('#cal3').text($time[2]);
                  */
                  //alert (html);
                  $("#prayertime").empty().append(html);
              }
    });
  });
  
     $('"[id*=tcal-]"').live("click", function () { 
     var tt = new Date().getTimezoneOffset();  
     var b = $(this).attr("id").split("-");
     var p = $(this).parent().find('td').eq(0).html().substring(0,5);
     var dt = b[1]-1;
     //alert ("time slot: " + p + "*" + dt + "*" + tt + " click!");
     $.ajax({
              url: "460?act=insertpry&offset=" + tt+"&p="+p+"&d="+dt,
              //data: $datastr,
              cache: false,
              success: function(html) {
              $.ajax({
              url: "460?act=localtime&offset=" + tt,
              cache: false,
              success: function(html) {
                  $("#prayertime").empty().append(html);
              }
      });
              }
     }); 
 
    }); 

});
