var is_IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
var is_Chrome = (navigator.appVersion.indexOf("Chrome")!=-1 )? 1:0;

//------------------------------------------------------------------------------
/*
     Renvoie result.height et result.width
*/
function getFrameSize(frameName) {
    var result = {height:0, width:0};
    if (document.getElementById) {
        var frame = parent.document.getElementById(frameName);
        if (frame.scrollWidth) {
            result.height = frame.scrollHeight;
            result.width = frame.scrollWidth;
        }
    }
    return result;
}

//------------------------------------------------------------------------------
/*
     Renvoie result.height et result.width
*/
function getWindowSize() {
  var result = {height:0, width:0};
  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;
  }
  result.height = myHeight;
  result.width = myWidth;
  /*
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
  */
  return result;
}

//------------------------------------------------------------------------------
function sleep(time){   d=new Date();   diff=0;    while(diff < time)    {      n=new Date();      diff=n-d;     }   }




//------------------------------------------------------------------------------
/*
    Permet l'usage de la variable PHP $_GET dans les scripts javascript
*/
try
{
    var $_GET = new Object();
    var $qry_str = location.search.substring(1);
    var $k = 0;
    if( $qry_str.split("=")[0].replace(/&/, "")!='' )
    {
        do {
            $_GET[$qry_str.split("=")[0].replace(/&/, "")] = $qry_str.split("=")[1].split(/&|$/)[0];
            $qry_str = $qry_str.split($qry_str.split("=")[1].split(/&|$/)[0])[1];
            $k ++;
        } while($k < (location.search.split("=").length - 1));
    }
    /*
    for(key in $_GET){
        alert("Variable: " + key + "\nValue: " + $_GET[key]);
    }
    */
}catch(e)
{}






//------------------------------------------------------------------------------
/*
    Permet l'usage de la variable PHP _GET dans les scripts javascript
    sans le dollard cette fois [ajouté en v131]
*/
try
{
    var _GET = new Object();
    var $qry_str = location.search.substring(1);
    var $k = 0;
    if( $qry_str.split("=")[0].replace(/&/, "")!='' )
    {
        do {
            _GET[$qry_str.split("=")[0].replace(/&/, "")] = $qry_str.split("=")[1].split(/&|$/)[0];
            $qry_str = $qry_str.split($qry_str.split("=")[1].split(/&|$/)[0])[1];
            $k ++;
        } while($k < (location.search.split("=").length - 1));
    }
    /*
    for(key in _GET){
        alert("Variable: " + key + "\nValue: " + _GET[key]);
    }
    */
}catch(e)
{}






//------------------------------------------------------------------------------
/*
function str_replace(search,replace,haystack)
{
    var reg=new RegExp( '('+search+')', "g" );
    haystack = haystack.replace( reg,replace );
    return haystack;
}
*/







//------------------------------------------------------------------------------

if( $_GET['lg']!=undefined )
for(i=0;i<parent.frames.length;i++)
{
    if( i!=2 )//on ne rafraichie pas le treeview
    {
        url = ""+parent.frames[i].location; //transtypage
        url = str_replace('lg='+$_GET['lg'],'',url);
        if( $_GET['lg']!=undefined )parent.frames[i].location.replace(url);
    }
}




//------------------------------------------------------------------------------
/*
function limite_saisie_nblignes()
Exemple:
<textarea cols="40" rows="15" name="projet_name_rules" style="overflow:hidden" wrap=off onKeyUp="limite_saisie_nblignes(this,5);" onKeyDown="limite_saisie_nblignes(this,5);" ></textarea>
*/
function limite_saisie_nblignes(obj,nombre_de_lignes_max)
{
    try
    {
        var total_nb_lignes = 0;
        val = obj.value.match(/\n/g);
        nbre_rn = val.length;
        for(i=0;i<obj.value.length;i++)
        {
            if( obj.value.charAt(i)=="\n" )total_nb_lignes++;
            if( total_nb_lignes>nombre_de_lignes_max - 1 )
            {
                length_ligne_en_trop = obj.value.length - i;
                i = obj.value.length; //on sort
            }
        }
        
        max = obj.value.length - length_ligne_en_trop;
        if(total_nb_lignes>=nombre_de_lignes_max)
        {
            obj.value=obj.value.substring(0,max);
        }
    }
    catch (e) 
    {
        //ras
    }

}







//------------------------------------------------------------------------------
function checkUncheckAll(theElement) 
{
    /*
    Pour select/unselect tous les checkboxes d'un formulaire
    Exemple : <input type="checkbox" name="checkall" onclick="checkUncheckAll(this);">select/unselect
    */
    var theForm = theElement.form, z = 0;
  	for(z=0; z<theForm.length;z++)
    {
        if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
        {
  	         theForm[z].checked = theElement.checked;
  	    }
     }
}







//------------------------------------------------------------------------------

    /*Rafraichissement d'un frame*/
    function refresh (name, lien) { parent.frames[name].location = lien; }







//------------------------------------------------------------------------------
/*
    function addslashes(haystack)
    {
        //pour remplacer " en \"
        haystack = haystack.replace(/\"/g,"\\\"");
      
        //et pour remplacer ' en \'
        haystack = haystack.replace(/\'/g,"\\\'"); 
        return haystack;
    }
*/   




//------------------------------------------------------------------------------
/*
Utilison la fonction CSS ZOOM de IE ainsi
<input type="button" value="zoom +" onclick="zoomin();">
<input type="button"  value="zoom -" onclick="zoomout();">
<input type="button" value="restore" onclick="zoomreset();">
*/
    function zoomin()
    {
      if(parent.parent.document.body.style.zoom != 0) parent.parent.document.body.style.zoom *= 1.1; 
      else parent.parent.document.body.style.zoom = 1.1;
    }
    function zoomout()
    {
      if(parent.parent.document.body.style.zoom !=0 ) parent.parent.document.body.style.zoom *= 0.9; 
      else parent.parent.document.body.style.zoom = 0.9;
    }
    function zoomreset()
    {
      if(parent.parent.document.body.style.zoom !=0 )parent.parent.document.body.style.zoom *= 0; 
      else parent.parent.document.body.style.zoom =0;
    }







//------------------------------------------------------------------------------

/*
  function GetElementByClass()
  exemple:
  afficherMasquer_class("dir_name","masquer");
*/
function afficherMasquer_class(divName,property)
{
  var val="";
  for (i=0; i<document.getElementsByTagName("*").length; i++) 
  {
    if (document.getElementsByTagName("*").item(i).className == divName)
    {
        ( property == "masquer" || property == 0 ) ? val = "hidden" : val = "show";
        document.getElementsByTagName("*").item(i).style.visibility = val;
    }
  }
}







//------------------------------------------------------------------------------

//CHANGER LE TEXTE D'UN OBJET HTML D' <id=...>
//compatible IE
function objet_str_replace( search, replace , objet_id ) {
  var reg=new RegExp("("+search+")", "g");
  document.all[objet_id].outerHTML  = document.all[objet_id].innerHTML.replace(reg,replace);
  return true;
}



//------------------------------------------------------------------------------
/*
function string2cell( index, haystack, needle )
  Manipulons une chaine "haystack" comme un tableau. Chaque cellule étant séparée par "needle".
*/
function string2cell( index, haystack, needle )
{
    var result='';
    if( haystack!='' && strpos(':'+haystack, needle)>0 )
    {
        var t=explode(needle,haystack);
        var max=count(t);
        if(index<max)
        {
            result=t[index];
        }else result='';
    }else if(index==0) result=haystack;
    else result='';
    return result;
}


