﻿function OpenDialog(ascx, params)
{	
	// Ouvre la fenêtre PopUP
	var wResult = window.open( 'frmPopup.aspx?ctrl=' + ascx + params, "PopUpFilter", 'height=360,width=400');
	return false;
}

function OpenDialogAvecDim(ascx, params, height, width)
{	
	// Ouvre la fenêtre PopUP avec les dimensions spécifiées
	//var wResult = window.open( 'frmPopup.aspx?ctrl=' + ascx + params, "PopUpFilter", 'height=' + height + ',width=' + width);
	var wResult = window.open( 'frmPopup.aspx?ctrl=' + ascx + params, "PopUpFilter", 'scrollbars=yes, height=' + screen.height + ',width=' + screen.width);
	return false;
}

function OpenDialogInvisible(ascx, params, height, width)
{	
	// Ouvre la fenêtre PopUP avec les dimensions spécifiées	
	var wResult = window.open( 'frmPopup.aspx?ctrl=' + ascx + params, "PopUpFilter", 'visible=no, height=' + screen.height + ',width=' + screen.width);
	return false;
}

//Permet de récupérer la largeur d'un écran
function GetScreenWidth()
{
return screen.width;
}
//Permet de récupérer la hauteur d'un écran
function GetScreenHeight()
{
return screen.height;
}

//Permet de trouver un control sur la page
function 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=FindObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//Permet de changer la propriete d'un controle
function ChangeProp(objName,x,theProp,theValue) { //v6.0
  var obj = FindObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

//Recupere la selection et ajoute la valeur dans un controle de la page qui a ouvert le popup
function ChangeParentProp(ctrlSource, idTarget) {
    
    var selectedValue = ctrlSource.options[ctrlSource.options.selectedIndex].value;
    	
	obj = window.opener.document.forms[0].elements[idTarget];
    obj.value=selectedValue;
    
    //obj.disabled=true;
    
    window.close();
}

//Met à jour la page qui a ouvert le popup et ferme celui-ci
function RefreshParent() {    
        	
    //window.opener.reload();
    opener.location = opener.location;
       
    window.close();
}

function AddParentProp(newVal, newLabel, idTarget) {
    
    
    obj = window.opener.document.forms[0].elements[idTarget];
    
    var elOptNew = window.opener.document.createElement('option');
    elOptNew.text = newLabel;
    elOptNew.value = newVal;
    elOptNew.selected = true;
  
      try {
        obj.add(elOptNew, null); // standards compliant; doesn't work in IE
      }
      catch(ex) {
        obj.add(elOptNew); // IE only
      }

    
    //obj.disabled=true;
    
    window.close();
}

//Recupere un parametre de l'url
function GetUrlValue(param) 
{
    var chaine=window.location.search;
    chaine=chaine.substring(1);
    var dz=chaine.indexOf("#",0);
    if(dz!=-1) {
    chaine=chaine.substring(0,dz);}
    chaine=chaine+"&";
    if(chaine.indexOf(param,0)!=-1){
    var pos=chaine.indexOf(param,0);
    var pos2=chaine.indexOf("=",pos);
    var pos3=chaine.indexOf("&",pos);
    contenu=chaine.substring(pos2+1,pos3);}
    return contenu;
}

//alerte affichée à l'utilisateur
function Confirmation(msg) {
	// pose une question au visiteur
	if (confirm(msg)) {
		return true;
	} else {	
		return false;
	}
}

// Browser sniffing en JS
function Browser(){
    var IE = window.ActiveXObject ? true : false;
    var MOZ = window.sidebar ? true : false;
    if(MOZ){return true;}
    if(IE){return false;}
}

function IsDatesValid(date1, date2, button)
{
    var but=document.getElementById(button);
    var dat1=document.getElementById(date1);
    var dat2=document.getElementById(date2);
    if (CheckDate(dat1.value))
    {
        if (CheckDate(dat2.value))
        {
            but.disabled=false;
        }
        else
        {
            but.disabled=true;
        }
    }
    else
    {
        but.disabled=true;
    }
}

function CheckDate(d) {
      // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
      // Le séparateur est défini dans la variable separateur
      var amin=1900; // année mini
      var amax=2100; // année maxi
      var separateur="/"; // separateur entre jour/mois/annee
      var j=(d.substring(0,2))-1+1;
      var m=(d.substring(3,5))-1+1;
      var a=(d.substring(6))-1+1;
      var ok=1;
      if ( ( (isNaN(j)) || (j<1) || (j>31) ) && (ok==1) && (d!="")) {
         alert("Le jour n'est pas correct."); ok=0;
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) && (d!="")) {
         alert("Le mois n'est pas correct."); ok=0;
      }
      if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) && (d!="")) {
         alert("L'année n'est pas correcte."); ok=0;
      }
      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) && (d!="")) {
         alert("Les séparateurs doivent être des "+separateur); ok=0;
      }
      if (ok==1 && (d!="")) {
         var d2=new Date(a,m-1,j);
         j2=d2.getDate();
         m2=d2.getMonth()+1;
         a2=d2.getYear();
         if (a2<=1000 ) {a2=1900+a2}
         if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
            alert("La date "+d+" n'existe pas !");
            ok=0;
         }
      }
      
      return ok;
   }
