

var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0) ;
if (! isIE) 
{
 HTMLElement.prototype.__defineGetter__("innerText", function () { return(this.textContent); });
 HTMLElement.prototype.__defineSetter__("innerText",function (txt) { this.textContent = txt; });
}

var av_miniNumber = -999999999999 ;
function trim(str) { if (str.length > 0) return str.replace(/^\s*|\s*$/g, '') ; return str ; }


function getRadioValue(o_rb)
{
 if (typeof(o_rb) == 'string') o_rb = document.getElementsByName(o_rb) ;
 var r ;
 for ( r = 0 ; r < o_rb.length && ! o_rb[r].checked ; r++) ;
 return o_rb[r].value ;
}

function getOffset (obj)
{
 var o = { y : 0 , x : 0 } ;
 var el ;

 for (el = obj ; el != null ; el = el.offsetParent ) 
  {
  o.y += el.offsetTop  ;
  o.x += el.offsetLeft ;

  if (! isIE && el.tagName == 'TABLE' && el.getElementsByTagName('CAPTION').length > 0) o.y += el.getElementsByTagName('CAPTION')[0].offsetHeight ;
  }

 for (el = obj ; el.tagName != 'BODY' ; el = el.parentNode )
  {
  o.y -= el.scrollTop ;
  o.x -= el.scrollLeft ;
  }

 return o ;
}


function posit_div(oDiv, y, x)
{
 var tot_h, tot_l ;
 if (isIE)
  {
  tot_h = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
  tot_l = document.documentElement.clientWidth ;
  }
 else { tot_h = window.innerHeight ; tot_l = window.innerWidth }

 if (y + oDiv.offsetHeight > tot_h) y = tot_h - oDiv.offsetHeight ;
 if (x + oDiv.offsetWidth > tot_l)  x = tot_l - oDiv.offsetWidth ;

 oDiv.style.top  = y + "px" ;
 oDiv.style.left = x + "px" ;
}






function addButton(toObj, typ)
{
 var o ;
 if (isIE) o = toObj.appendChild(document.createElement('<input type="' + typ + '">')) ;
 else { o = toObj.appendChild(document.createElement('input')) ; o.type = typ ; }
 return o ;
}


function ajuste_height(oDv)
{
 if (! oDv) return ;
 var y0 = getOffset(oDv).y ;
 var tot_h ;
 if (isIE)
  tot_h = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
 else tot_h = window.innerHeight ;

 var new_size = (tot_h - y0 ) + "px" ;
 oDv.style.height = new_size ;
}

function ajuste_height4lst_news(oDv)
{
 if (! oDv) return ;
 var y0 = getOffset(oDv).y ;
 var tot_h ;
 if (isIE)
  tot_h = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
 else tot_h = window.innerHeight ;

 var new_size = (tot_h - y0 - 10 ) + "px" ;
 oDv.style.height = new_size ;
}





// ==========================================
function setCookie(name, value, expire) 
{
 strCookie = name + "=" + escape(value);
 if (expire) strCookie += "; expires=" + expire.toGMTString();
 document.cookie = strCookie;
}
// ==========================================
function getCookie(Name) 
{
 var search = Name + "="
 if (document.cookie.length > 0) 
  { 
  // if there are any cookies
  offset = document.cookie.indexOf(search);
  if (offset != -1) 
   { 
   // if cookie exists
   offset += search.length ;

   // set index of beginning of value
   end = document.cookie.indexOf(";", offset) ;

   // set index of end of cookie value
   if (end == -1)
       end = document.cookie.length ;

   return unescape(document.cookie.substring(offset, end)) ;
   }
  }
}



/* FONCTIONS POUR SORT TABLE (AV SOLUTIONS) ============================================= */
function _pF(val)
{
 if (typeof(val)=='number') return val ;
		  
 var str = val.replace(/\s|,/gi, '') ; 
 var fl ;
 var reg = /^(-|\d)+[.]?\d*$/ ;   
 if ( (fl = reg.exec(str)) == null ) return av_miniNumber ;
 return parseFloat(fl) ;
}

/* FONCTIONS DATES */
var _moiMonth = "jan:1;fev:2;mar:3;avr:4;apr:4;mai:5;may:5;jun:6;jui:7;aou:8;aug:8;Sep:9;oct:a;nov:B;dec:C" ;

function arDates(reg, i0, i1, i2) { this.reg = reg ; this.i = new Array(3); this.i[0] = i0 ; this.i[1] = i1 ; this.i[2] = i2 ; }
var rgDates = new Array(3) ;
rgDates[0] = new arDates(/^([012]?[0-9]|3[01])[ -\x2E\x2F](0?[1-9]|[1|2][0-9]|3[01])[ -\x2E\x2F]([1-2]?[0-9]?[0-9][0-9])/   , 3, 2, 1) ;
rgDates[1] = new arDates(/^([1-2][0-9][0-9][0-9])[ -\x2E\x2F](0?[1-9]|[1|2][0-9]|3[01])[ -\x2E\x2F]([012]?[0-9]|3[01])/     , 1, 2, 3) ;
rgDates[2] = new arDates(/^(0?[1-9]|[1|2][0-9]|3[01])[ -\x2E\x2F]([1-2][0-9][0-9][0-9])[ -\x2E\x2F]([1-2]?[0-9]?[0-9][0-9])/, 3, 1, 2) ;


function date2ansi(i_frm, strDate)
{
 var fl ;
 fl = rgDates[i_frm].reg.exec(strDate) ; 
 if (fl != null)  return 10000*fl[rgDates[i_frm].i[0]] + 100 * fl[rgDates[i_frm].i[1]] + 1 *fl[rgDates[i_frm].i[2]] ;
 return av_miniNumber ;
}

function ifrmDate(strDate) 
{
 for ( var i = 0; i < 3 && (fl = rgDates[i].reg.exec(strDate)) == null ; i++ ) ;
 if ( i < 3 ) return i ;
 return null ;
}


function percent_value(str, indic)
{
 var k ;
 if ( str.indexOf(indic) >= 0 )  return str.substr(indic.length) ;
 return str ; 
}


function guessSortColType(ar_data)
{
 var r, f ;
 for ( r = 0 ; r < ar_data.length && trim(ar_data[r].value).length == 0; r++ ) ;
 if ( r == ar_data.length) return 's' ;
 var v = ar_data[r].value ;
 if ((f = ifrmDate(v)) != null) return f ;
 if (_pF(v) > av_miniNumber ) return 'N' ; 
 return 's' ;
}



function sortTbody(oTbody, c, frm_c, sens)
{
 var nbRows = oTbody.rows.length ;
 var data = new Array(nbRows) ;
 var i, j, gap, swd, r ;

 var frm_col="S" ;

 for ( r = 0 ; r < nbRows ; r++ ) 
  {
  v = oTbody.rows[r].cells[c].innerText ;
  v = trim(v) ;
  switch(v) 
   {
   case "Filiale" : v = 50.0 ; break ;
   case "Solde"   : v =  sens == 1 ?  -av_miniNumber : av_miniNumber ; break ;
   case "Indetermine" : v =  9.99 ; break ;
   case "Important"  : v =  33.00 ; break ;
   case "Majoritaire"  : v =  33.00 ; break ;
   case "Minoritaire"  : v =  9.98 ; break ;
   case "Controle"  : v =  40.00 ; break ;
   default :
    {
    v = percent_value(v, "Superieur a" ) ;
    v = percent_value(v, "Inferieur a" ) ;
    v = percent_value(v, "Environ" ) ;
    break ;
    }

   }
  data[r] = {r:r, value:v, oTR:oTbody.rows[r]} ;
  }


 if (frm_c==null) frm_c = guessSortColType(data) ;

 switch (frm_c)
  {
  case 's' : for (r = 0 ; r < nbRows ; r++ ) data[r].value = data[r].value.toLowerCase() ;	break ;
  case 'N' : for (r = 0 ; r < nbRows ; r++ ) data[r].value = _pF(data[r].value) ; break ;

  case 0 :
  case 1 :
  case 2 : for (r = 0 ; r < nbRows ; r++ ) data[r].value = date2ansi(frm_c,data[r].value)  ;
   break ;
  }

 if (sens == null) sens = 1 ;

 for ( gap = (nbRows >> 1) ; gap > 0 ; gap >>= 1)
  {
  for( i = gap ; i < nbRows ; i++)
   for ( j = i - gap ; j >= 0 && (data[j].value > data[j+gap].value) == sens ; j -= gap )
     { swd = data[j] ; data[j] = data[j+gap] ; data[j+gap] = swd ; }
  }
  
 for ( r = 0 ; r < nbRows ; r++)
  oTbody.insertBefore(data[r].oTR, oTbody.rows[r] ) ;
}


function getParentTag(obj, parTag)
{
 for (oPar = obj.parentNode ; oPar != null && oPar.tagName != parTag ; 	oPar = oPar.parentNode ) ;
 return oPar ;
}



function OnClickHeadSort(e)
{
 var oCol ;

 if (e.target) oCol = e.target ; else oCol =  e.srcElement ;
 if ( oCol.getAttribute("_av_nosort") != null ) return ;

 var oTable = getParentTag(oCol, "TABLE") ;
 var oThead = oTable.tHead ;
 var c, sens ;
 var ix_c ;



 for (c = 0 ; c < oThead.rows[0].cells.length ; c++ )
  {
  /* A REVOIR */
  /*  if ( oCol.cellIndex == c ) sens = oCol.getAttribute("_av_sort") == 1 ? 0 : 1 ;  */
  if ( oCol.innerText == oThead.rows[0].cells[c].innerText ) { sens = oCol.getAttribute("_av_sort") == 1 ? 0 : 1 ; ix_c = c ; }
  else { sens = null ;oThead.rows[0].cells[c].style.color='black' ; }
  oThead.rows[0].cells[c].setAttribute("_av_sort", sens) ; 
  }

 sens = oCol.getAttribute("_av_sort") ;
 sortTbody(oTable.tBodies[0], ix_c, null, sens) ;

 oCol.style.color= sens == 0 ? 'red' : 'green' ;
}




// ===FONCTIONS VERIF DES FORMULAIRES AVANT ENVOIS =======================================
function chk_lgpsw(F) 
{
 var errorsout="";

 if (trim(F['Username'].value).length == 0) 
  errorsout += 'Vous devez renseigner le login\n';
 if (trim(F['Password'].value).length == 0) 
  errorsout += 'Vous devez renseigner le password\n';

 if (errorsout.length > 0) 
  {
  alert(errorsout);
  return false ;
  } 



 return true;
}



function chk_srh_pm(F) 
{
 var errorsout="";
 if (trim(F['pm2srch'].value).length < 2) 
  {
  alert('Saisir au moins deux caractères\n') ;
  return false ;
  }

 // NEW
 F['pm2srch'].value = trim(F['pm2srch'].value) ;
 window.setTimeout("please_wait(true, 'i_no_match', -60, -8)", 10) ;

 return true;
}


function chk_srh_pp(F) 
{
 var errorsout="";
 if (trim(F['txt_name'].value).length < 2) 
  errorsout += 'Saisir au moins deux caractères\n';

 if (errorsout.length > 0) 
  {
  alert(errorsout);
  return false ;
  } 

 window.setTimeout("please_wait(true, 'id_rch_pp', 0, 0)", 10) ;

 return true;
}







// === FONCTIONS POUR LE BANDO (LEON) ====================================================

function right(str, n)
{
 if ( n < 0 ) return "" ;
 var lns = str.length ;
 if (n > lns) return str ;
 else return str.substring(lns - n) ;
}



function og_mouseover(e) 
{ 
 var lm ; if (!e) lm = window.event.srcElement ; else lm = e.target ;
 lm.style.cursor = "pointer" ;

 // if (lm.getAttribute("cible") && lm.src.indexOf("_on.png") < 0 ) lm.src = lm.name + "_roll" + right(lm.src, 4) ;
 if (lm.getAttribute("cible") && lm.src.indexOf("_on.") < 0 ) lm.src = lm.name + "_roll" + right(lm.src, 4) ;
}


function og_mouseout(e) 
{ 
 var lm ; if (!e) lm = window.event.srcElement ; else lm = e.target ;
 lm.style.cursor = "default" ;
// if (lm.getAttribute("cible") && lm.src.indexOf("_on.png") < 0 ) lm.src = lm.name + "_off" + right(lm.src, 4) ;
 if (lm.getAttribute("cible") && lm.src.indexOf("_on.") < 0 ) lm.src = lm.name + "_off" + right(lm.src, 4) ;
}


function og_locDiv(oBtn)
{
 var oC = oBtn.parentNode ;
 var oTable = oBtn.parentNode.parentNode.parentNode.parentNode ;

 var c ;
 var lm ;
 var oR = oTable.rows[0] ;
 var cbl ;
 var o ;

 for (c = 0 ; c < oR.cells.length ; c++) 
  {
  lm = oR.cells[c].getElementsByTagName('IMG')[0] ;

  if (lm)
   {                                     
   if (lm == oBtn) 
    { 
    lm.src = lm.name + "_on" + right(lm.src, 4) ; 
    if (  (cbl = lm.getAttribute("cible")) && (o = document.getElementById(cbl.substr(1))) ) o.style.display="" ;
    }
   else if(lm.src.indexOf("_on") >= 0) 
    {
    lm.src = lm.name + "_off" + right(lm.src, 4) ;
    if (  (cbl = lm.getAttribute("cible")) && (o = document.getElementById(cbl.substr(1))) ) o.style.display="none" ;
    }
   }
  }


}




function og_click(e) 
{
 var lm ; if (!e) lm = window.event.srcElement ; else lm = e.target ;


 var cbl ;
 if (  (cbl = lm.getAttribute("cible")) )
  {
  if (cbl.charAt(0) == '.') return og_locDiv(lm) ;

  var wm ;
  if ( (wm = lm.getAttribute("tgt")) )  
   {
   if (wm == "_top") top.location.href = cbl ; 
   else if (wm == "_self") self.location.href = cbl ;
   else if (wm == "_parent") parent.location.href = cbl ;
   else top.frames[wm].location.href = cbl ; 
   }
  else document.location = cbl ;
  }

}


function bando_leon(aBtn, obj, img_ext, bando_class, i_on, o_ins_bef )
{
 if (!obj || obj == null) return false ;

 var oTable = document.createElement("table") ;
 oTable.border = "0" ; oTable.cellSpacing = "0" ; oTable.cellPadding = "0" ;

 if (bando_class) oTable.className = "no_print " + bando_class ;

 var oR = oTable.insertRow(-1) ;

 oR.onmouseover = og_mouseover;
 oR.onmouseout  = og_mouseout  ;
 oR.onclick     = og_click  ;

 var v, oC, oI ;
 for(v = 0; v < aBtn.length ; v++ )
  {
  oC = oR.insertCell(-1) ;
  oC.align = "center" ;

  oI = document.createElement("IMG") ;
  oI.border = "0" ;

  oI.name = aBtn[v].n ;
  oI.src = oI.name + (v == i_on ? "_on" : "_off") + img_ext ;

 
  oI.setAttribute("cible", aBtn[v].u) ;

  if (aBtn[v].tgt || 0 ) oI.setAttribute("tgt", aBtn[v].tgt) ; 

  oC.style.width = (oI.width + 2) + "px" ;

  oC.style.textAlign = "left";
  oC.appendChild(oI) ;

/*
  if (v == i_on && aBtn[v].u.charAt(0) == '.') 
   { oC = document.getElementById(aBtn[v].u.substr(1)) ; oC.style.display="" ; }
*/

  }


 /* Si pas d'aditionnelle */
 oC = oR.insertCell(-1) ;
 oC.innerHTML = "&nbsp;" ;  // pour IE

 /* Adittionnal TD */
 for ( v = 6 ; v < arguments.length ; v++)
  {
  oC = oR.insertCell(-1) ;
  oC.align="right" ;

  if (arguments[v].indexOf("(style)") == 0)
   {
   oC.style.cssText = arguments[v].substr(7) ;
   oC.innerHTML = "&nbsp;" ;
   }
  else oC.innerHTML = arguments[v] ;    
  }

 obj.insertBefore(oTable, o_ins_bef) ;   

     
}



function dsp_autres_sites(oImg)
{
 var oDv ;

 if ( !(oDv = document.getElementById("id_dv_autres_sites")) ) return false ;

 if (oDv.style.display != "none") { oDv.style.display = "none" ; return ; }

 var xy = getOffset(oImg) ;
 oDv.style.display = "" ;
 oDv.style.position="absolute" ;
 oDv.style.top   = (xy.y + oImg.offsetHeight - 21) + "px"  ;
 oDv.style.left  = (xy.x + 13) + "px"  ;
 oDv.style.width=(oImg.offsetWidth - 26) + "px" ;
}



// ======================================================================================



function please_wait(on_off, o_posit, left, top)
{
 var o ; 

 // http://ajaxload.info/
 if ( window.top.__o_plizouette == null)
  {
  window.top.__o_plizouette = document.createElement("IMG") ;
  window.top.__o_plizouette.border = "0" ;
  window.top.__o_plizouette.src = "images/wait.gif" ;
  window.top.__o_plizouette.style.zIndex = 100000 ;
  window.top.__o_plizouette.style.position = "absolute" ;

  document.body.appendChild(window.top.__o_plizouette) ;
  }
 if ( !(o = window.top.__o_plizouette) ) return false ;

 if (!on_off) o.style.display = "none" ;
 else 
  {
  document.body.appendChild(o);
  if (! left) left = 0 ;  if (! top) top = 0 ;
  if (o_posit) 
   {
   if ( typeof(o_posit) != 'object') o_posit = document.getElementById(o_posit) ;
   var xy = getOffset(o_posit) ;
   top += xy.y  ; left += xy.x ;
   }
  o.style.top = top +"px" ; o.style.left = left + "px" ; 
  o.style.display = "" ;
  }

}





// ======================================================================================
function chk_pop_srh_pm(F) 
{
 var errorsout="";

 if (trim(F[1].value).length < 2)     /* IE refuse F['TxtString'] */
  {
  alert('Saisir au moins deux caractères')
  return false ;
  }

 // NEW
 F[1].value = trim(F[1].value) ;

 F.frame_lst.style.display='';

 F.frame_lst.contentWindow.document.body.innerHTML = "" ;

 please_wait(true, 'id_pop_srch_dafsa', 40, 110) ;

 return true;
}







function search_and_get_a_dafsa(poum, callBack, x, y)
{
 var o_pop ;
 var id_box = "id_pop_srch_dafsa" ;
 if ( !(o_pop = document.getElementById(id_box)) )
  {
  var o, o_div, oForm ;

  o_pop = document.createElement("div")  ;

  o_pop.id = id_box ;
  o_pop.style.cssText = "text-align:center;width:450px;position:absolute;background-color:#BCD8EB;border:3px groove inactivecaptiontext;z_index=1000" ;

  o = document.createElement("div") ;
  o.style.cssText = "font:bold 17px Verdana;color: #6E6E6E" ;
  o.innerText = "Trouver" ;
  o_pop.trouver = o_pop.appendChild(o) ;

  oForm = document.createElement("form") ;
  oForm.style.cssText = "margin:0px" ;
  oForm.action = "srch_cplk.vsp" ;
  oForm.target = "nm_lst" ;
/*
  oForm.onsubmit = function(){this.frame_lst.style.display='';return true;}
*/
  oForm.onsubmit =  function(){ return chk_pop_srh_pm(this) ; }


  o_pop.poum = addButton(oForm, "hidden");
  o_pop.poum.name = "poum" ;

  o = addButton(oForm, "text");
  o.style.fontWeight="bold" ;
  o.name = "TxtString" ; o.value = '' ;  o.id = "_id_i_text_" ; o.size = "40" ; o.onfocus=function(){this.select();} ;

  o_pop.prenom = o = addButton(oForm, "text");
  o.style.fontWeight="bold" ;
  o.name = "txt_surname" ; o.value = '' ;  o.size = "15" ; o.onfocus=function(){this.select();} ;


  o_div = document.createElement("div")  ;

  o_div.innerHTML = '<input type="radio" value="0"  name="S_CRIT">Commençant par &nbsp;&nbsp;' ;
  o_div.innerHTML += '<input type="radio" value="1" name="S_CRIT" checked="true">Contenant les mots' ;
  o_div.style.cssText = "font:normal 11px Verdana" ;
  o_pop.typsrch = oForm.appendChild(o_div) ;

  o_div = document.createElement("div")  ;
  o_div.style.cssText = "padding-bottom:6px;" ;

  o = addButton(o_div, "button") ; o.value = "close" ; o.style.cssText = "width:20%" ; o.onclick = function(){this.form.parentNode.style.display='none';} ;
  o = addButton(o_div, "submit") ; o.value = "chercher" ; o.style.cssText = "width:65%" ;

  oForm.appendChild(o_div) ;
  o_pop.appendChild(oForm) ;


  if (isIE) o = document.createElement('<iframe name="nm_lst">') ;
  else { o = document.createElement("iframe") ;   o.name = "nm_lst" ;  }
  o.id = "id_frame" ;
//  o.style.cssText = "width:100%;max-height:250px;height:expression(scrollHeight > 250 ? '250px' : scrollHeight < 60 ? '60px' : 'auto');display:none;border:0px;background-color:white;margin:0px" ;
  o.style.cssText = "width:100%;max-height:250px;height:expression(scrollHeight > 250 ? '250' : scrollHeight < 60 ? '60' : 'auto');display:none;border:0px;background-color:white;margin:0px" ;
  oForm.frame_lst = o_pop.appendChild(o) ;


  o_pop.lst_ifrm = oForm.frame_lst ;

  document.body.appendChild(o_pop) ;
  o_pop.style.position = "absolute" ;
  }


 if(arguments.length == 3)   // se caler sur l'objet
  {
  if (x.tagName == "INPUT")
   {
   var o = document.getElementById("_id_i_text_") ; 
   o.value = x.value ;
   }

  var xy = getOffset(x) ;
  y = xy.y + 5  ;
  x = xy.x + 7  ;
  }
 

 o_pop.lst_ifrm.style.display = 'none' ;
 o_pop.style.display = '' ;

 o_pop.lst_ifrm.callBack = callBack ;

 if (poum == 'PM' || poum == 'pm')
  {
  o_pop.trouver.innerHTML = "<span class='v_title_box'>Trouver une société</span><br><span style='font:normal 10px Verdana;color:black'>RS de la société ou Nº SIREN</span>" ;
  o_pop.prenom.style.display = 'none' ;
  o_pop.typsrch.style.display = '' ;
  o_pop.poum.value = 'M' ;
  }
 else
  {
  o_pop.typsrch.style.display = 'none' ;
  o_pop.trouver.innerHTML = "<span class='v_title_box'>Trouver une personne</span><br><span style='font:normal 10px Verdana;color:black'>Nom</span>" ;
  o_pop.prenom.style.display = '' ;
  o_pop.poum.value = 'P' ;
  }

/*
 o_pop.style.top  = y + "px"  ;
 o_pop.style.left = x + "px"  ;
*/
 posit_div(o_pop, y, x) ;


 o_pop.getElementsByTagName('INPUT')[1].focus() ;
}






