// fonction qui redimensionne proportieonnellement une image 
function redimImage(inImg, inMW, inMH)
{
  // Cette function recoit 3 parametres
  // inImg : Chemin relatif de l'image
  // inMW  : Largeur maximale
  // inMH   : Hauteur maximale
  var maxWidth = inMW;
  var maxHeight = inMH;
  // Declarations des variables "Nouvelle Taille"
  var dW = 0;
  var dH = 0;
  // Declaration d'un objet Image
  var oImg = new Image();
  // Affectation du chemin de l'image a l'objet
  oImg.src = inImg;
  // On recupere les tailles reelles
  var h = dH = oImg.height;
  var w = dW = oImg.width;
  // Si la largeur ou la hauteur depasse la taille maximale
  if ((h >= maxHeight) || (w >= maxWidth)) {
    // Si la largeur et la hauteur depasse la taille maximale
    if ((h >= maxHeight) && (w >= maxWidth)) {
      // On cherche la plus grande valeur
      if (h > w) {
        dH = maxHeight;
        // On recalcule la taille proportionnellement
        dW = parseInt((w * dH) / h, 10);
      } else {
        dW = maxWidth;
        // On recalcule la taille proportionnellement
        dH = parseInt((h * dW) / w, 10);
      }
    } else if ((h > maxHeight) && (w < maxWidth)) {
      // Si la hauteur depasse la taille maximale
      dH = maxHeight;
        // On recalcule la taille proportionnellement
      dW = parseInt((w * dH) / h, 10);
    } else if ((h < maxHeight) && (w > maxWidth)) {
      // Si la largeur depasse la taille maximale
      dW = maxWidth;
        // On recalcule la taille proportionnellement
      dH = parseInt((h * dW) / w, 10);
    }
  }
  // On ecrit l'image dans le document
  document.writeln("<img src=\"" + inImg + "\" width=\"" + dW + "\" height=\"" + dH + "\" border=\"0\">");
}


// JavaScript Document
function confirmDelete()
{
        reponse=confirm('Etes-vous sur de vouloir supprimer l\'enregistrement ?');
        if(reponse) return true;
        else return false;
}

// confirmation avant suppression
function delConfirm()
{
        reponse=confirm('Confirmez vous la suppression ?');
        if(reponse) return true;
        else return false;
}

//Fonction pour vérifier que le formulaire est correctement rempli avec en paramètre les champs obligatoires
function verify_form(formulaire)
{

 //On parcourt le formulaire pour tester et détecter si ils sont vides ou non
 for(i=1;i<arguments.length;i++)
 {
  if(formulaire.elements[arguments[i]].value=='')
  {
   alert('Merci de remplir tous les champs suivis d\'une étoile.');
   return;
  }
 }
 formulaire.submit();
}
//
//Fonction pour retailler la fenêtre (IE only)
function ensureSize(image,wnd,xPadding,yPadding){
 if (navigator.userAgent.indexOf('MSIE')!=-1) {
  var rX=image.clientWidth+xPadding+20;
  var rY=image.clientHeight+yPadding+28;
  if(rX<200)
    rX=200;
  if(rY<100)
    rY=100;
  if(rY>(screen.height-50))
    rY=screen.height-100;
  wnd.resizeTo(rX,rY);
 }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/*function open_close(id){
	if( eval('d'+id+'.style.display') == "block" ) {
		eval('d'+id+'.style.display = "none"');
	}
	else {
		eval('d'+id+'.style.display = "block"');
	}
}*/
//
function open_close(id) 
{
	id = "d"+id;
	if (document.getElementById) 
	{
		if(document.getElementById(id).style.display=="none") document.getElementById(id).style.display="block";
		else document.getElementById(id).style.display="none";
	} 
	else if (document.all) 
	{
		if(document.all[id].style.display=="none") document.all[id].style.display="block";
		else document.all[id].style.display="none";
	} 
	else if (document.layers) 
	{
		if(document.layers[id].display=="none") document.layers[id].display="block";
		else document.layers[id].display="none";
	} 
} 


//Fonctions du menu
function montre(id) 
{
	if (document.getElementById) 
	{
		if(document.getElementById(id).style.display=="none") document.getElementById(id).style.display="block";
		else document.getElementById(id).style.display="none";
	} 
	else if (document.all) 
	{
		if(document.all[id].style.display=="none") document.all[id].style.display="block";
		else document.all[id].style.display="none";
	} 
	else if (document.layers) 
	{
		if(document.layers[id].display=="none") document.layers[id].display="block";
		else document.layers[id].display="none";
	} 
} 
//Fonctions du menu EOF

var cadre=0;

function on(id) 
{
	document.getElementById(id).style.display="block";
}
function off(id)
{
	document.getElementById(id).style.display="none"; 
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*function open_close(id){
alert(d01.name);
	if( eval('d'+id+'.style.display') == "block" ) {
									eval('d'+id+'.style.display = "none"');
	}
	else {
									eval('d'+id+'.style.display = "block"');
	}
}*/

function goto_action(id,idTheme){
//        document.gotoaction.num_action.value = id;
	document.gotoaction.idTheme.value = idTheme;
	document.gotoaction.idaction.value = id;
	document.gotoaction.submit();
}
function go_to(sens,step)
{
        if(sens!=0)
                document.filtre.page.value = step + sens;
        else
                document.filtre.page.value = 1;
        document.filtre.submit();
}

function go_to_page(page){
        document.filtre.page.value = page;
        document.filtre.submit();
}

function switch_to_equipement(id,from){
        document.location = "rechercher_equipement.jsp?page=1&id="+id+"&from="+from;
}

function switch_to_action(id,from){
        document.location = "rechercher_action.jsp?page=1&id="+id+"&from="+from;
}

function switch_to_acteur(id,from){
        document.location = "rechercher_acteur.jsp?page=1&id="+id+"&from="+from;
}

function switch_to_lieu(id,from){
        document.location = "rechercher_lieu.jsp?page=1&id="+id+"&from="+from;
}

function switch_to_materiel(id,from){
        document.location = "rechercher_materiel.jsp?page=1&id="+id+"&from="+from;
}

function switch_to_all(id,from){
        var winall = window.open("rechercher_all.jsp?id="+id+"&from="+from,'all','width=740,height=400,resizable=1,scrollbars=1');
        winall.focus();
}

function openFenetre(url,name,params)
{
        fen=window.open(url,name,params);
        fen.focus();
}
function login_func(){
        if(document.login_form.mot_passe.value != "" && document.login_form.login_name.value != "" )
        {
                document.login_form.todo.value = "login";
                document.login_form.submit();
        }
        else alert("Merci de saisir votre nom d\'utilisateur et votre mot de passe.");
}

function logout_func(){
        document.login_form.todo.value = "logout";
        document.login_form.submit();
}

function valid_identify()
{
        if(window.identifyForm.profil.value=="" || window.identifyForm.localisation.value=="")
        {
                alert('Merci de choisir un profil et une localisation.');
                return false;
        }
        else
        {
                return true;
        }
}



function PopupCentrer(page,largeur,hauteur,options)
{
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  winName = window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
  winName.focus();
}

function PopMod()
{
  PopupCentrer("pass_remembering.jsp",'400','150','');
}

function validConfirmOuvCompte()
{
  valid = true;
  textErreur = '';
 //Test des champs obligatoires
 if(document.personForm.givenName.value=="")
 {
  textErreur = 'Prénom\n';
  valid = false;
 }
 if(document.personForm.sn.value=="")
 {
  textErreur += 'Nom\n';
  valid = false;
 }
 if(document.personForm.mail.value=="")
 {
  textErreur += 'Courriel\n';
  valid = false;
 }
 if(document.personForm.description.value.length == 0)
 {
  textErreur += 'Vos attentes\n';
  valid = false;
 }

 //Affichage du message d'erreur
 if(valid == false)
 {
  alert('Les champs suivants sont obligatoires : \n'+textErreur);
  return false
 }
 else
 {
  return true;
 }
}


function resume_action(idaction)
{
 fenetre = window.open('fiche_action.jsp?top=2&num_action=&titre=&idTheme=&idaction='+idaction,'rapportAction','width=420,height=420,scrollbars=yes');
 fenetre.focus();
}

function consulter_doc(){
        document.menuForm.action = "consulter_doc.jsp";
        document.menuForm.submit();
}

function confirm_delete(){
   	reponse=confirm('Vous confirmez la suppression ?');
    if(reponse) return true;
    else return false;
}

//Fonctions Globale permettant de changer d'image au click
function images_plus_moins(id,id_image,nom_image,nom_image2) 
{
	if (document.getElementById(id_image) && document.getElementById(id)) 
	{
		if(document.getElementById(id).style.display=="none")
			document.getElementById(id_image).src=nom_image;
		else 
			document.getElementById(id_image).src=nom_image2;
	} 
} 
