// JavaScript Document
// DJM WEB AGENCY
// info@djmweb.be
// version : 1.01
// author :	Régis Thérer
// 			regis@djmweb.be

// confirmation de la suppression
/*************** Attention le paramètre vSelect doit être entre quote (apostrophe) / action onblur ***********************/
function fctConfirm(vSelect)
{
if (confirm('Voulez vous vraiment supprimer ce projet : ' + document.getElementById(vSelect).options[document.getElementById(vSelect).selectedIndex].text + ' ?'))
	{
	return true;
	}
		else 
		{
		document.getElementById(vSelect).selectedIndex = 0;
		return false;
		}
}


//Redirection vers une autre page
/*************** le paramètre doir être entre quote / action onclick **********************/
function urlRedirect(vUrl)
{
document.location.href = vUrl;	
}

//Verification plus redirection
/***************** le paramètre est l'id à faire passer et le nom de la page de suppression et la troisieme, c'est le nom du paramètre; le quatrième est le titre du contenu *********************/
function verif(id_cont, vurl, vparam, vTitre)
{
if(confirm("Etes-vous sûr de vouloir supprimer ce contenu : "+vTitre+" ?"))
	{
	document.location.href=vurl+"?"+vparam+"="+id_cont;
	}
else{
	}
}

//Précédent
/***************** Imite le btn précédent *****************/
function precedent()
{
	history.go(-1);
	}
	
//temps
/**********************Declenche une fonction au cour du temp / fct entre quote**********************/
function actionTime(vfct, vtemp)
{
	setTimeout(vfct,vtemp);
	}

//Limite Charactère
/********************Oblige le nbre de charactère (fomulaire=nom form, champ=nom champ à traiter, nbre= nbre de lettre)************************/
function submitForm(formulaire, champ, nbre) { 
	if (document.forms[formulaire].elements[champ].value.length >= nbre) {
		document.forms[formulaire].submit() ;
		}
		else {
		alert("Il faut au moins "+nbre+" lettre(s) dans le nom recherché!");
		document.forms[formulaire].elements[champ].focus();
		}

}

//Roll Over Et out
/***************Mettre les param entre '.  Le premier c'est l'id de l'image et le second, c'est l'url de l'image.**************/
function rollOver(vId, vUrl) {
	
		document.getElementById(vId).src=vUrl;
	
}

//Onglet en mouvement vers le haut et le bas
/**************Attention car ceci ne fonctionne qu'avec des styles particulier*****************/
function btnHover(letter, pos, end) {

var vId = letter;

if (pos<end) {
document.getElementById(vId).style.bottom=(pos)+'px';
pos=pos+1;
setTimeout("btnHover('"+vId+"', "+pos+", "+end+")",1);
}
return pos;
};

function btnOut(letter, pos, end) {

var vId = letter;

if (pos>end) {
document.getElementById(vId).style.bottom=(pos)+'px';
pos=pos-1;
setTimeout("btnOut('"+vId+"', "+pos+", "+end+")",1);
}
return pos;
};

//Roll/over changement de class
/****************paramètre 1 = id de l'item, paramètre 2 = class****************/
function changeClass(varId, vClass) {
document.getElementById(varId).className=vClass;
}

//taille d'un div max pour une fenêtre (div full)
/***paramètre : id du div****/
function putSize(vId) {
	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;
  }
document.getElementById(vId).style.width=(myWidth)+"px";
document.getElementById(vId).style.height=(myHeight)+"px";
	}
	
// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------
	
//taille de la fenêtre
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;
}
	
//Centrer element
/******Paramètre : id du div******/
function windowCenter(myId) {
	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";
}

/************************************************************************************************/
/*																							 	*/
/*                                 Gestion de pop-up Ajax										*/
/*																								*/
/************************************************************************************************/

//initialiser les pop-up
function popUpIniat(vFond) {
	styleBlocFond(vFond);
	var arrayPageSize = getPageSize();
	document.getElementById(vFond).style.width=(vFond, arrayPageSize[0])+'px';
	document.getElementById(vFond).style.height=(vFond, arrayPageSize[1])+'px';
	for (var i=1; i < popUpIniat.arguments.length; i++) {
		styleBloc(popUpIniat.arguments[i]);
	}
	}

//Mettre les syle pour le bloc fond
function styleBlocFond() {
	for (var i=0; i < styleBlocFond.arguments.length; i++) {
		document.getElementById(styleBlocFond.arguments[i]).style.display='none';
		document.getElementById(styleBlocFond.arguments[i]).style.position='absolute';
		document.getElementById(styleBlocFond.arguments[i]).style.backgroundColor='#000000';
		document.getElementById(styleBlocFond.arguments[i]).style.zIndex='15000';
		document.getElementById(styleBlocFond.arguments[i]).style.top='0px';
		document.getElementById(styleBlocFond.arguments[i]).style.left='0px';
		document.getElementById(styleBlocFond.arguments[i]).style.opacity='0.30';
		document.getElementById(styleBlocFond.arguments[i]).style.filter='alpha(opacity=30)';
		}	
	}

//Mettre les styles pour le bloc pop-up
function styleBloc() {
	for (var i=0; i < styleBloc.arguments.length; i++) {
		document.getElementById(styleBloc.arguments[i]).style.display='none';
		document.getElementById(styleBloc.arguments[i]).style.position='absolute';
		document.getElementById(styleBloc.arguments[i]).style.color='#000000';
		document.getElementById(styleBloc.arguments[i]).style.backgroundColor='#FFFFFF';
		document.getElementById(styleBloc.arguments[i]).style.padding='10px';
		document.getElementById(styleBloc.arguments[i]).style.width='450px';
		document.getElementById(styleBloc.arguments[i]).style.zIndex='15001';
		document.getElementById(styleBloc.arguments[i]).style.top='50%';
		document.getElementById(styleBloc.arguments[i]).style.left='50%';
		document.getElementById(styleBloc.arguments[i]).style.marginTop='-200px';
		document.getElementById(styleBloc.arguments[i]).style.marginBottom='0px';
		document.getElementById(styleBloc.arguments[i]).style.marginRight='0px';
		document.getElementById(styleBloc.arguments[i]).style.marginLeft='-225px';
		document.getElementById(styleBloc.arguments[i]).style.border='1px solid #000000';
		}	
	}


//enlever ou faire apparaître
/***Maitre comme paramètre les id désirés**/
function clearBox() {
	for (var i=0; i < clearBox.arguments.length; i++) {
		document.getElementById(clearBox.arguments[i]).style.display='none';
		//document.getElementById(clearBox.arguments[i]).style.visibility='hidden';
	}
}
function showBox() {
	for (i=0; i<showBox.arguments.length; i++) {
		document.getElementById(showBox.arguments[i]).style.display='block';
		//document.getElementById(showBox.arguments[i]).style.visibility='visible';
		
	}
}


/************************************************************************************************/
/*									End Gestion pop-up Ajax										*/
/************************************************************************************************/



/******Param : getTop(document.getElementById('ID'))********/
function getTop(MyObject)
//Fonction permettant de connaître la position d'un objet
//par rapport au bord haut de la page.
//Cet objet peut être à l'intérieur d'un autre objet.
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
        return (MyObject.offsetTop);
    }
	
//Popup
/*
__________________________________________________________________________________________
||	Propriétés	||					Effets						||	Valeurs possibles	||
------------------------------------------------------------------------------------------
||	directories	||	Affichage de la barre de liens				||		yes | no 		||
||	menubar		||	Affichage de la barre de menu				||		yes | no		|| 
||	status		|| Affichage de la barre de statut				|| 		yes | no		||  
||	location	|| Affichage de la zone d'adresse				|| 		yes | no 		|| 
||	scrollbars	|| Affichage des barres de scrolling			|| 	  yes | no | auto 	||
||	resizable	|| Autorise le redimensionnement du popup		|| 		yes | no 		|| 
||	height		|| Hauteur en pixels							|| 	  nombre entier 	||
||	width		|| Largeur en pixels							|| 	  nombre entier 	||
||	left		|| Position horizontale en pixels sur l'écran	|| 	  nombre entier 	||
||	top			|| Position verticale en pixels sur l'écran		|| 	  nombre entier 	||
||	fullscreen	|| Popup en plein écran (version 5 et +)		|| 		yes | no 		|| 
__________________________________________________________________________________________


Position fixe en haut à gauche
OuvrirPopup('popup.html','','top=10,left=10')

Aucune barre de menu, non redimensionnable, taille fixe
OuvrirPopup('popup.html', '', 'resizable=no, location=no, width=200, height=100, menubar=no, status=no, scrollbars=no, menubar=no')

Page en plein écran (version 5 et +). Faire un ALT [F4] pour fermer la fenêtre 
OuvrirPopup('popup.html','','fullscreen=yes')


*/
function OuvrirPopup(page,nom,option) {
       window.open(page,nom,option);
    }
