// 3-12-2003 W. de Zeeuw, LogicaCMG
// file scripts.js
// wordt geinclude in elke pagina, zodat de printversie van de pagina
// dynamisch tijdens clicken wordt opgebouwd.
// 14-7-2004 Jeroen Dolmans/Ger-Jan te Dorsthorst, RIVM
// sectie toegevoegd met functionaliteit t.b.v. exit poll zomer 2004
// zoek naar 'Start section exit poll' en 'End section exit poll'
// --------------------------------------------------------------------
 
function printContent(content, stylesheetnr) 
{

 var endScript = "ipt"
 var contents = " <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">";

 contents = contents + "<html>";
 contents = contents + "<head>";
 contents = contents + "<title>Printbare versie</title>";
 contents = contents + "<meta http-equiv=\"Pragma\" content=\"no-cache\" />";
 contents = contents + "<meta http-equiv=\"Expires\" content=\"-1\" />";
 contents = contents + "<scr" + endScript + " language=\"JavaScript1.2\" type=\"text/javascript\" src=\"/include/scripts.js\"></scr" + endScript + ">";

 // insert StyleSheet afhankelijk van de 2-de parameter
 // 0 = default, 1= Volksgezondheid en 2 = Milieu
 if (stylesheetnr == 1){
 	 stylesheetnaam = 'volksgezondheid.css'
 } else {
 	 if (stylesheetnr == 2){
 	   stylesheetnaam = 'milieu.css'
 	 } else {
 	   stylesheetnaam = 'default.css'
 	 }
 }
 contents = contents + "<link href=\"/Stylesheets/" + stylesheetnaam + "\" rel=\"stylesheet\" type=\"text/css\">"

 
 contents = contents + "</head>";
 contents = contents + "<body style=\"background:#FFFFFF\">";
 
 // nieuwe toevoeging
 contents = contents + "<table width=\"581\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
 contents = contents + "<tr align=\"left\">"
// blauwe zijlijn weg contents = contents + "<td width=\"1\" rowspan=\"6\" class=\"border\"><img src=\"/Images/pixel.gif\" width=\"1\" height=\"1\" /></td>" 
 contents = contents + "<td height=\"90\" colspan=\"3\"><img src=\"/Images/print/print_middle_top.gif\" alt=\"Print window\" width=\"581\" height=\"90\" border=\"0\" /></td>"
// blauwe zijlijn weg contents = contents + "<td width=\"1\" rowspan=\"6\" class=\"border\"><img src=\"/Images/pixel.gif\" width=\"1\" height=\"1\" /></td>"
 contents = contents + "</tr>"
 contents = contents + "<tr><td>&nbsp;</td></tr>"		// forceer lege regel tussen kop en body
 contents = contents + "<tr>"
 contents = contents + "<td width=\"20\">&nbsp;</td>"
 contents = contents + "<td>"

   // start oude inhoud
   contents = contents + "<table id=\"ContentDivider\" width=\"561\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
   contents = contents + "<tr><td id=\"Main\" width=\"480\" valign=\"top\">" + content + "</td></tr>"
   contents = contents + "</table>";
   // einde oude inhoud

 contents = contents + "</td>"
 contents = contents + "</tr>"
 
 //  <!-- Bottom -->
 contents = contents + "<tr>"
 contents = contents + "<td class=\"bottomLeft\" height=\"35\" colspan=\"3\"><img src=\"/Images/print/print_middle_bottom.gif\" width=\"581\" height=\"35\"></td>"
 contents = contents + "</tr>"
 
 contents = contents + "</table>";
 
 contents = contents + "</body>";
 contents = contents + "</html>";

 //nu nog even de anchor tags eraf knippen:
 re2 = /<A /i;
 re3 = />/i;
 re4 = /<\/A>/i;

 while (contents.search(re2) > 0 )
 {
  startlinks = contents.search(re2);
  string1 = contents.substring(0, startlinks); // content tot anchortags
  string2 = ((contents.substring(startlinks)).substring((contents.substring(startlinks)).search(re3) + 1)).substring(0,((contents.substring(startlinks)).substring((contents.substring(startlinks)).search(re3) + 1)).search(re4)) + ((contents.substring(startlinks)).substring((contents.substring(startlinks)).search(re3) + 1)).substring(((contents.substring(startlinks)).substring((contents.substring(startlinks)).search(re3) + 1)).search(re4),((contents.substring(startlinks)).substring((contents.substring(startlinks)).search(re3) + 1)).search(re4)) ; // content binnen anchor tags
  string3 = contents.substring(contents.search(re4)+4);
  contents = string1 + string2 + string3;
 }
 
 var printwindow = window.open("","","");
 printwindow.document.write(contents);

 printwindow.document.close();
 // print box activeren :
 printwindow.print();
}

/////////////////////////////
// Start section exit poll //
/////////////////////////////
function init_enquete() {
	return;
}

//Check cookies if the survey should be shown, or if the cookies should be set
//function init_enquete() {
//
  ////Check if survey hasn't been entered already and the survey hasn't been cancelled today
  //if (getCookie("enquete-ingevuld") == null && getCookie("enquete-dag") == null && getCookie("enquete-aantal") < 2)
  //{
    ////If this isn't the first RIVM page, check the time the visitor has been on the RIVM site
    //if (getCookie("enquete-tijd") != null)
    //{
      ////Check time-difference between setting of cookie and now
      //var startTime = getCookie("enquete-tijd");
      //var huidigeDatum = new Date;
      //var nowTime = ( huidigeDatum.getHours() * 3600 ) + ( huidigeDatum.getMinutes() * 60 ) + huidigeDatum.getSeconds();
     // 
      ////Check of the one minute wait time was exceeded, then set cookie for day (expires at midnight)
      //if (nowTime - startTime >= 60)
      //{
        //var vervalDatum = new Date;
        //vervalDatum.setHours(23);
        //vervalDatum.setMinutes(59);
        //vervalDatum.setSeconds(59);
        //setCookie("enquete-dag", "dag", vervalDatum, "/");
       // 
        ////Add another cookie that stores the number of times the survey has been shown 
        //var vervalDatum2 = new Date;
        //vervalDatum2.setYear(2004);
        //vervalDatum2.setMonth(12);
        //vervalDatum2.setDate(31);       
        //if (getCookie("enquete-aantal") != null) {
          //setCookie("enquete-aantal", parseInt(getCookie("enquete-aantal")) + 1, vervalDatum2, "/");
        //} else {
          //setCookie("enquete-aantal", 1, vervalDatum2, "/");
        //}
       // 
        ////Open window
        //window.open('/enquete/rivm-enquete-1.html','RIVMenquete','location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,height=320,width=530');
      //}
    //}
    //else
    //{
      ////Calculate expiry date after 15 minutes
      //var huidigeDatum = new Date;
      //var vervalDatum = new Date;
      //if (vervalDatum.getMinutes()+15 >= 60) {
        //vervalDatum.setHours(vervalDatum.getHours()+1);
        //vervalDatum.setMinutes(vervalDatum.getMinutes()+15-60);
      //} else {
        //vervalDatum.setHours(vervalDatum.getHours());
        //vervalDatum.setMinutes(vervalDatum.getMinutes()+15);
      //}
      //
      ////Set the cookie with the start time in seconds
      //var startTime = ( huidigeDatum.getHours() * 3600 ) + ( huidigeDatum.getMinutes() * 60 ) + huidigeDatum.getSeconds();
      //setCookie("enquete-tijd", startTime, vervalDatum, "/");
    //}
  //}
//}

// Get cookies (returns string containing value of specified cookie or null if cookie does not exist)
function getCookie(name)
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// Set cookies (name, value, expires, path, domain, secure) - an argument defaults when it is
// assigned null as a placeholder, a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure)
{
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

///////////////////////////
// End section exit poll //
///////////////////////////
