var childWindowHandles = new Array(); //pt a putea inchide pe urma toate pop-up-urile
   



function getXmlHttpRequest() { // Furnizeaza obiectul XMLHttpRequest
  try { 
    var request = new XMLHttpRequest(); // Mozila, Firefox, Netscape, Opera etc.
  } catch (e) { 
    try {
      request = new ActiveXObject('MSXML2.XMLHTTP'); // Microsoft IE
    } catch (e) { 
      try {
        request = new ActiveXObject('Microsoft.XMLHTTP'); // Microsoft IE
      } catch (e) { 
        alert("Browserul nu poate lucra cu AJAX: "+e);
        request = false;
      }
    }
  }
  return request;
}





function generateTable(id)
{
   window.document.getElementById("lunaSel").innerHTML=" ";

   var sel=id;

   if(sel == 1)
   {
     window.document.getElementById("lunaSel").innerHTML = "Ianuarie";
   }

   if(sel == 2)
   {
     window.document.getElementById("lunaSel").innerHTML = "Februarie";
   }

   if(sel == 3)
   {
     window.document.getElementById("lunaSel").innerHTML = "Martie";
   }

   if(sel == 4)
   {
     window.document.getElementById("lunaSel").innerHTML = "Aprilie";
   }

   if(sel == 5)
   {
     window.document.getElementById("lunaSel").innerHTML = "Mai";
   }

   if(sel == 6)
   {
     window.document.getElementById("lunaSel").innerHTML = "Iunie";
   }

   if(sel == 7)
   {
     window.document.getElementById("lunaSel").innerHTML = "Iulie";
   }

   if(sel == 8)
   {
     window.document.getElementById("lunaSel").innerHTML = "August";
   }

   if(sel == 9)
   {
     window.document.getElementById("lunaSel").innerHTML = "Septembrie";
   }

   if(sel == 10)
   {
     window.document.getElementById("lunaSel").innerHTML = "Octombrie";
   }

   if(sel == 11)
   {
     window.document.getElementById("lunaSel").innerHTML = "Noiembrie";
   }

   if(sel == 12)
   {
     window.document.getElementById("lunaSel").innerHTML = "Decembrie";
   }

   var req = getXmlHttpRequest();
   req.open("GET", "/APLICATII/biblia/biblia-plancitire/generatetable.php?id="+id, false);
   req.send(null);  
   var rasp = req.responseText; 
   //alert("rasp " + rasp );
  
   window.document.getElementById("zi").innerHTML = rasp;

/*
   var req = getXmlHttpRequest();
   req.open("GET", "dinamicTOstatic.php?rasp="+rasp, false);
   req.send(null);  
   var rasp = req.responseText; 
   alert("rasp : " + rasp);
*/
}


function popupBibliaText(id2)
{
   var req = getXmlHttpRequest();
   req.open("GET", "/APLICATII/biblia/biblia-plancitire/getsession.php?id=1", false);
   req.send(null);  
   var rasp = req.responseText;
   var luna = rasp;


   //var req = getXmlHttpRequest();
   //req.open("GET", "getsession.php?id=2", false);
   //req.send(null);  
   //var rasp = req.responseText;
   //var id = rasp;

   var url = "/APLICATII/biblia/biblia-plancitire/bibliatextsel.html?id=" + id2 + "&luna=" + luna;



//window.open('http://www.yahoo.com.ro','window','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,width=600,height=300');


//window.open( "http://www.onysoft.ro", "myWindow", 
//"status = 1, height = 300, width = 300, resizable = 0" )



   
   // window.open(url, "_blank" ,"status=no,width=700,height=480,scrollbars=yes"); --> @@@@@PT A DESCHIDE CATE O PAGINA NOUA@@@@@


   //window.open(url, "_blank" ,"status=no,width=700,height=480,scrollbars=yes");

   childWindowHandles[childWindowHandles.length] = window.open(url, "_blank" ,"status=no,width=800,height=700,scrollbars=yes");
   
   //window.close();




//window.open(url, '_blank', 'toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,width=600,height=300')
}

function preluareText()
{
   var aux = window.location.search.substr(1).split("&");
  
   var id, luna;
   var idAux, lunaAux;
   var ind = 0;

   for(i = 0; i < aux.length; i++ )
   {
      if(ind == 1) // preluam luna
      {
         lunaAux = aux[i].split("=");
	 luna = lunaAux[1];	
      }
	
      if(ind == 0) // preluam id
      {
	 idAux = aux[i].split("=");
	 id = idAux[1];	
	 ind = 1;
      }
   }

   //alert("id: " + id);
   //alert("luna: " + luna);

   if(luna==13)
   {
      var d = new Date();
      var month = d.getMonth();
      luna = month + 1; 
   }   

   var req = getXmlHttpRequest();
   req.open("GET", "/APLICATII/biblia/biblia-plancitire/getText.php?id=" + id + "&luna=" + luna, false);
   req.send(null);  
   var rasp = req.responseText;
   //alert("rasp " + rasp);

   window.document.getElementById("text").innerHTML = rasp;
}

function init() //afiseaza doar textele pt ziua respectiva
{

   //window.document.getElementById("lunaSel").innerHTML=" ";
   var req = getXmlHttpRequest();
   req.open("GET", "/APLICATII/biblia/biblia-plancitire/generatetable.php?id=13", false);
   req.send(null);  
   var rasp = req.responseText;
   //alert("rasp " + rasp);
   window.document.getElementById("zi").innerHTML = rasp; 

   var d = new Date();
   var month = d.getMonth();
   var sel = month + 1; //in js lunile is de la 0 la 11

   if(sel == 1)
   {
     window.document.getElementById("lunaSel").innerHTML = "Ianuarie";
   }

   if(sel == 2)
   {
     window.document.getElementById("lunaSel").innerHTML = "Februarie";
   }

   if(sel == 3)
   {
     window.document.getElementById("lunaSel").innerHTML = "Martie";
   }

   if(sel == 4)
   {
     window.document.getElementById("lunaSel").innerHTML = "Aprilie";
   }

   if(sel == 5)
   {
     window.document.getElementById("lunaSel").innerHTML = "Mai";
   }

   if(sel == 6)
   {
     window.document.getElementById("lunaSel").innerHTML = "Iunie";
   }

   if(sel == 7)
   {
     window.document.getElementById("lunaSel").innerHTML = "Iulie";
   }

   if(sel == 8)
   {
     window.document.getElementById("lunaSel").innerHTML = "August";
   }

   if(sel == 9)
   {
     window.document.getElementById("lunaSel").innerHTML = "Septembrie";
   }

   if(sel == 10)
   {
     window.document.getElementById("lunaSel").innerHTML = "Octombrie";
   }

   if(sel == 11)
   {
     window.document.getElementById("lunaSel").innerHTML = "Noiembrie";
   }

   if(sel == 12)
   {
     window.document.getElementById("lunaSel").innerHTML = "Decembrie";
   }

}


function exitpop()
{

    for(var loop=0; loop<childWindowHandles.length; loop++) 
       if(!childWindowHandles[loop].closed) 
          childWindowHandles[loop].close();

    //alert("Bye-Bye!");

    //var url = 'bibliatextsel.html';
    //var win = 'toolbar=0,directories=0,menubar=0,scrollbars=0,
     //     resizable=0,width=250,height=300';

    //open(url,'WindowName',win); 

    //window.close();
    //my_window = window.open("", "mywindow1", "status=1,width=350,height=150");
    //my_window.document.write('<h1>Popup Test!</h1>');
}

