//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// dimension et positionnement du faux popup
function sizePopup(opaque,popup) { 
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	// taille div opaque
	divO = document.getElementById(opaque);
	divO.style.height = (arrayPageSize[1] + 'px');
	
	// taille div popup
	divP = document.getElementById(popup);	
	boxHeight = divP.style.height;
	boxWidth = divP.style.width;
	ch1 = parseFloat(arrayPageScroll[1]);
	ch2 = parseFloat(arrayPageSize[3]);
	ch3 = parseFloat(boxHeight);
	ch4 = parseFloat(arrayPageSize[0]);
	ch5 = parseFloat(boxWidth);
	ca1 = parseFloat(ch2 - 35 - ch3);
	ca2 = parseFloat(ca1 / 2);
	ca3 = parseFloat(ch1 + ca2);
	ca4 = parseFloat(ch4 - 20 - ch5);
	ca5 = parseFloat(ca4 / 2);
	if(ca3<=10){ca3 = 10;}
	if(ca5<=10){ca5 = 10;}
	divP.style.top = ca3 + 'px';
	divP.style.left = ca5 + 'px';
}

// cacher la popup
function cacherPopup(opaque,popup) { 
	document.getElementById(opaque).className='undisplay';
	document.getElementById(popup).className='undisplay';
}

// voir la popup
function voirPopup(opaque,popup) { 
	sizePopup(opaque,popup);
	document.getElementById(opaque).className='display';
	document.getElementById(popup).className='display';
}

//////////////////////////////////////////////////////////////////////
// NOUVELLES POPUPS (AVEC IFRAME)

// demarrer le loader
function startLoader() {
	voirPopup('divOpaque','divPopupLoad');
}
function stopLoader() {
	cacherPopup('divOpaque','divPopupLoad');
}

// ouvrir une popup
function ouvrirPopup(page,parametres) {
	switch(page){
		case 'choix-recette' :
			width = 880;
			height = 660;
			src = 'popups/pop.choix-recette.php';
		break;
		case 'choix-recette-a-imprimer' :
			width = 880;
			height = 660;
			src = 'popups/pop.choix-recette-a-imprimer.php';
		break;
		case 'recette' :
			width = 670;
			height = 270;
			src = 'popups/pop.recette.php';
		break;
		case 'imprimer' :
			width = 670;
			height = 270;
			src = 'popups/pop.imprimer.php';
		break;
		case 'enregistrer' :
			width = 420;
			height = 250;
			src = 'popups/pop.enregistrer.php';
		break;
		case 'enregistrerSuite' :
			width = 420;
			height = 250;
			src = 'popups/pop.enregistrer-suite.php';
		break;
		case 'valider' :
			width = 420;
			height = 250;
			src = 'popups/pop.valider.php';
		break;
		case 'creer-planicook' :
			width = 420;
			height = 250;
			src = 'popups/pop.creer-planicook.php';
		break;
		case 'creer-planicook-2' :
			width = 420;
			height = 250;
			src = 'popups/pop.creer-planicook-2.php';
		break;
		case 'alert-calcul' :
			width = 420;
			height = 250;
			src = 'popups/pop.alert-calcul.php';
		break;
	}
	
	if(parametres){
		src += parametres;
	}
	
	document.getElementById('popup').src=src;
	
	document.getElementById('divPopup').style.height=height + 'px';
	document.getElementById('divPopup').style.width=width + 'px';
	document.getElementById('popup').style.height=height + 'px';
	document.getElementById('popup').style.width=width + 'px';
	
	voirPopup('divOpaque','divPopup');
}

// fermer la popup
function fermerPopup() {
	window.parent.document.getElementById('divOpaque').className='undisplay';
	window.parent.document.getElementById('divPopup').className='undisplay';
	
	document.location.href="pop.vide.php";
}
function fermerPopupSite() {
	document.getElementById('divOpaque').className='undisplay';
	document.getElementById('divPopup').className='undisplay';
}