﻿function openWindow(anchor, options) {


 
	var args = '';
 
	if (typeof(options) == 'undefined') { var options = new Object(); }
	if (typeof(options.name) == 'undefined') { options.name = 'win' + Math.round(Math.random()*100000); }
 
	if (typeof(options.height) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
		args += "height=" + options.height + ",";
	}
 
	if (typeof(options.width) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
		args += "width=" + options.width + ",";
	}
 
	if (typeof(options.fullscreen) != 'undefined') {
		args += "width=" + screen.availWidth + ",";
		args += "height=" + screen.availHeight + ",";
	}
 
	if (typeof(options.center) == 'undefined') {
		options.x = 0;
		options.y = 0;
		args += "screenx=" + options.x + ",";
		args += "screeny=" + options.y + ",";
		args += "left=" + options.x + ",";
		args += "top=" + options.y + ",";
	}
 
	if (typeof(options.center) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
		options.y=Math.floor((screen.availHeight-(options.height || screen.height))/2)-(screen.height-screen.availHeight);
		options.x=Math.floor((screen.availWidth-(options.width || screen.width))/2)-(screen.width-screen.availWidth);
		args += "screenx=" + options.x + ",";
		args += "screeny=" + options.y + ",";
		args += "left=" + options.x + ",";
		args += "top=" + options.y + ",";
	}
 
 
	if (typeof(options.scrollbars) == 'undefined') { args += "scrollbars=1,"; } 
	    else { args += "scrollbars=" + options.scrollbars +  ","; }
	if (typeof(options.menubar) == 'undefined') { args += "menubar=1,"; }
	    else { args += "menubar=" + options.menubar +  ","; }
	if (typeof(options.locationbar) == 'undefined') { args += "location=1,"; }  
	    else { args += "locationbar=" + options.locationbar +  ","; }
	if (typeof(options.resizable) == 'undefined') { args += "resizable=1,"; }
	    else { args += "resizable=" + options.resizable +  ","; }
	if (typeof(options.toolbar) == 'undefined') { args += "toolbar=1,"; }
	    else { args += "toolbar=" + options.toolbar +  ","; }
 
 
	var win = window.open(anchor, options.name, args);
	return false;
 
}

function random_bg_accuiel()
{
    // Math.ceil(x*Math.random() : x étant la dernière image, x.jpg dans le répertoire.
    var rand_no = Math.ceil(9*Math.random())
    

    var body = document.getElementById("container");
    body.style.backgroundImage = "url(\../../_img/bg_cndf/" + rand_no + ".jpg\)";
    
}


function resize_window_max()
{
    window.moveTo(0,0);
    
    if (document.all)
    {
      top.window.resizeTo(screen.availWidth,screen.availHeight);
    }

    else if (document.layers||document.getElementById)
    {
      if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
      {
        top.window.outerHeight = screen.availHeight;
        top.window.outerWidth = screen.availWidth;
      }
    }
}




/* FONCTION TIMER */

// USE :
/*
<body onload="InitializeTimer(3)">
<form id="form1" runat="server">
    ....
</form>
</body>
*/

var secs
var timerID = null
var timerRunning = false
var delay = 1000
function InitializeTimer(seconds)
{
    // Set the length of the timer,
    secs = seconds

    StopTheClock()
    StartTheTimer()
}
function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}
function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()

        //Generate a Postback to the server with the 1st form encountered
        //document.forms[0].submit()  

        //Try to Redirect to another page
        window.location.href = "/";

     
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
        document.getElementById("time_div").innerHTML =" Retour automatique dans : " + secs.toString() + " secondes...";
    }
}

/* END FONCTION TIMER */

