﻿var w3c=document.getElementById && !document.all;
var ie=document.all;

if (ie||w3c) {
 // déclaration des variables uniquement pour IE vive microsoft ?!!
 var overlay;
 var my_window;
}


function affiche_overlay_window(image_fond_overlay,adresse_page){
	// creation de l'overlay et affichage de l'image
	image_overlay = '';
	if (image_fond_overlay != '') image_overlay = "<table class = 'image_calque ' valign = 'center' border = '0' align = 'center'><tr><td> <IMG  SRC='"+image_fond_overlay+"'></td></tr>";
	montreoverlay(image_overlay);
	// creation de la fenêtre
	montrefenetre(adresse_page);


}
function returnSize() {
  var myWidth = 0, myHeight = 0 ;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    
    
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    
    
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    
  }
  var result = new Array(myWidth,myHeight);
  return result;
}


function windowCenter(myId) {
	var result=returnSize();
	var myWidth=result[0];
	var myHeight=result[1];
	var elementWidth=document.getElementById(myId).offsetWidth;
	var elementHeight=document.getElementById(myId).offsetHeight;
        var myScrollLeft=document.documentElement.scrollLeft;
	var myScrollTop=document.documentElement.scrollTop;
	var posX=myScrollLeft+myWidth-myWidth/2-elementWidth/2
	var posY=myScrollTop+myHeight-myHeight/2-elementHeight/2;
	document.getElementById(myId).style.left=posX+"px";
	document.getElementById(myId).style.top=posY+"px";
}


function montreoverlay(text) {
  if (w3c||ie){
	
	 var arrayPageSize = this.getPageSize();
	 
	 
    overlay = document.all ? document.all["overlay"] : document.getElementById ? document.getElementById("overlay") : ""
		overlay.style.width = arrayPageSize[0]+'px';
		overlay.style.height =arrayPageSize[1]+'px';
		overlay.innerHTML = text; // fixe le code HTML dans l'overlay balise (div)
    overlay.style.display = "block"; // modification du style
		
		
  }
}

function montrefenetre(html) {
  if (w3c||ie){
  	
  	
    //affichage de la fenetre
	my_window = document.all ? document.all['window'] : document.getElementById ? document.getElementById('window') : ""
    my_window.style.display = "block";
windowCenter('window');
	
	// affichage du corps de la fenêtre (balise iframe)
    my_window = document.all ? document.all['contempwindow'] : document.getElementById ? document.getElementById('contempwindow') : ""
    my_window.style.display = "block";
    frames['contempwindow'].location.href= html ;

  }
}




function cachetout() {
	if (w3c||ie){

	// masque la fenetre (balise div [window] )
	
	
	my_window = parent.document.getElementById('window');
	my_window.style.display = "none";

	// masque le contenu (balise iframe [contempwindow])
	my_window = parent.document.getElementById('contempwindow');
	my_window.style.display = "none";

	// masque l'overlay (balise div [overlay])
	my_window = document.all ? parent.document.all['overlay'] : parent.document.getElementById ? parent.document.getElementById('overlay') : ""
	my_window.style.display = "none";

	}


}

function addcachetout(_action, urlScript, opt1, opt2){
	
	switch(_action){
		case 'go':
		window.parent.supp_photos ( '' ,opt1 ,opt2,'', urlScript );
		break;
		case 'refresh':
		var uriCourant = window.parent.location.href;
		
		window.parent.location.href = uriCourant;
		break;
	}
	cachetout()
}

function reloadpage(){
	location.reload();
}



 function  getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}
