var popupWin = null;
var alwaysOnTop = null;

function openAnyWindow(url, name) {
  //if (popupWin != null && popupWin.open) popupWin.close();

  // store number of arguments passed in
  var l = openAnyWindow.arguments.length;

  // initialize w (width)
  var w = "";
  // initialize h (height)
  var h = "";
  // initialize features (comma-delineated list of window features)
  var features = "";

  // loop through array of arguments to build list of features
  // begin loop with 2 (third element of array) to skip url and name
  for (i=2; i<l; i++) {

    // store current argument in variable param
    var param = openAnyWindow.arguments[i];

    // if param isn't a number, it's not width or height
    // in that case, append to features with comma
    if ( (parseInt(param) == 0) || (isNaN(parseInt(param))) ) {
		if(param == "scrollbars"){
	  		features += param + '=yes,';
		}else{
	      features += param + ',';
		}
    // else param is a number; must be width or height
    } else {

      // if w hasn't been set yet, param must be the width
      // otherwise, w has been set, so param must be the height
      (w == "") ? w = "width=" + param + "," : h = "height=" + param;
    }
  }

  // append width and height strings to list of features
  features += w + h;

  // begin building statement to open window
  if (name == "alwaysontop") {
    var code = "alwaysOnTop = window.open(url, name";
  }
  else {
    var code = "popupWin = window.open(url, name";
  }

  // if l>2, there were more than two arguments
  // in that case, append comma, parenthesis, and list of features
  if (l > 2) code += ", '" + features;

  // finish building statement to open window
  code += "')";
  //alert(String(code));	

  // execute statement to open window
  //alert(code);
  eval(code);
}

function blowOut() {
  if (popupWin != null && popupWin.open) popupWin.close();
}

window.onfocus=blowOut;

function GotoWithReturn (url) {

  openAnyWindow("retour.html","alwaysontop",175,40);
  self.location = url;

}

function GotoAndClose (url){
 self.opener.location = url;
 self.close();
}

function setOpener() {
 self.opener = self.opener.top;
}

//-------------------------------------------------------------------------------------------------
//--fonction contrôlant les cookies
//-------------------------------------------------------------------------------------------------
function Set_expireDate(days){
	var todays_date = new Date();
	var expires_date = new Date(todays_date.getTime() + (days * 86400000));
	return expires_date;
}
function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}
//==============================================================================================================================================================================
//=====fonctions=diverses=pour=le=module=fiches=================================================================================================================================
//==============================================================================================================================================================================
//-------------------------------------------------------------------------------------------------
//--fonction création du cookies fiches
//-------------------------------------------------------------------------------------------------
function SetCookieFiches(data){
	var exDate = Set_expireDate(1);
	Set_Cookie("fiches",data,exDate,"/");
}
function GetCookieFiches(){
	return Get_Cookie("fiches");
}
function CompareSetCookieFiches(id,set){
	id -= 1;
	var cookie = GetCookieFiches();
	if(cookie == null){
		InitCookieFiches();
		return null;
	}else{
		var tab = cookie.split(",");
		var view = tab[id];
		if(set == true){
			tab[id] = "1";
			var Data = tab.join(",");
			SetCookieFiches(Data);
		}
		return view;
	}
}
function InitCookieFiches(){
	var Data = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0";
	SetCookieFiches(Data);
}
//==============================================================================================================================================================================
//=====fonctions=diverses=pour=le=module=inoubliables===========================================================================================================================
//==============================================================================================================================================================================
//-----------------------------------------------------------------------------------------------------
// function for loading index page in full screen
//-----------------------------------------------------------------------------------------------------
var scw = 0;
var sch = 0;
function bigOpen(URL) {	
	heavyFullLauncher(URL, "big");
}
var a = new Array(URL);
var d = new Date();
var m = d.getMilliseconds();
var num = m % a.length;
var URL = a[num];
function heavyFullLauncher(link, name) {	
	var windowName = (name == "heavy_TV") ? name : "heavyhq";
	if (navigator.appName == 'Microsoft Internet Explorer' && (navigator.platform.substring(0,3) == 'Win')) {
		var scw=screen.Width-10;
		var sch=screen.Height-52;
		HeavyWindow=window.open (link, windowName, "fullscreen,left=0,top=0,width=" + scw + ",height=" + sch);
	}else if (navigator.appName == 'Netscape' || navigator.platform == 'MacPPC') {
		var scw=screen.width;
		var sch=screen.height;
		HeavyWindow=window.open (link, windowName, "screenX=0,screenY=0,outerWidth=" + scw + ",outerHeight=" + sch);
	}else{
		var scw=screen.width;
		var sch=screen.height;
		HeavyWindow=window.open (link, windowName, "screenX=0,screenY=0,outerWidth=" + scw + ",outerHeight=" + sch);
	}
}
//-------------------------------------------------------------------------------------------------
//--fonction qui ouvre l'inoubliable en fullscreen ou dans la même fenêtre à partir du pop-up
//-------------------------------------------------------------------------------------------------
function openChoixPop(choix){	
	switch(choix){
		case "fullscreen":
				//window.opener.caller();
				window.opener.bigOpen("../inoubliables_full.html")
				//bigOpen("../inoubliables_full.html")
			break;
		case "self":
				window.opener.location="../inoubliables.html";
			break;
	}
}
//-------------------------------------------------------------------------------------------------
//--fonction qui ouvre l'inoubliable en fullscreen ou dans la même fenêtre à partir d'une page
//-------------------------------------------------------------------------------------------------
function openChoix(choix){
	switch(choix){
		case "fullscreen":
				bigOpen("inoubliables_full.html")
			break;
		case "self":
				window.location="inoubliables.html";
			break;
	}
}
//-------------------------------------------------------------------------------------------------
//--validation de l'existance du cookie et ouverture de la page en conséquence
//-------------------------------------------------------------------------------------------------
function checkCookie(){
	var MyCookie = Get_Cookie("inoubMode");
	if(MyCookie!=null){
		openChoix(MyCookie);
	}else{
		popupModeSelect();
	}
}
//-------------------------------------------------------------------------------------------------
//--fonction appelé lors du click sur le lien des -inoubliables-
//-------------------------------------------------------------------------------------------------
function openInoubliables(){
	checkCookie();
}
//-------------------------------------------------------------------------------------------------
//--fonction d'ouverture de la page de choix du mode d'affichage de la page des inoubliables
//-------------------------------------------------------------------------------------------------
function popupModeSelect(){
	window.open("Inoub_full_elem/popInoubMode.html","selecMode","width=275,height=150,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no")
}
//-------------------------------------------------------------------------------------------------
//--fonction qui vérifie si l'utilisateur veux enregistrer sont choix et ouvre l'inoubliable
//-------------------------------------------------------------------------------------------------
function selectMode(choix){
	if(!document.memoire.souvenir.checked){
		openChoixPop(choix);
	}else{
		var MyExpDate = Set_expireDate(90);
		Set_Cookie("inoubMode",choix,MyExpDate,"/");
		openChoixPop(choix);
	}
	window.close();
}